Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
uart-exchange.c File Reference
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <termios.h>
#include <unistd.h>
#include "ca821x-generic-exchange.h"
#include "ca821x-posix-util-internal.h"
#include "ca821x-queue.h"
#include "ca821x_api.h"
#include "uart-exchange.h"
Include dependency graph for uart-exchange.c:

Classes

struct  uart_exchange_priv
 Private data for the UART Exchange. More...
 
struct  uart_device
 struct for representing the contents of CASCODA_UART environment variable More...
 

Functions

ca_error uart_exchange_init (ca821x_errorhandler callback, const char *path, struct ca821x_dev *pDeviceRef)
 Initialise the uart exchange, using the supplied errorhandling callback to report any errors back to the application, which can react as required (i.e. More...
 
void uart_exchange_deinit (struct ca821x_dev *pDeviceRef)
 Deinitialise the uart exchange, so that it can be reinitialised by another process, or reopened later. More...
 
ca_error uart_exchange_enumerate (util_device_found aCallback, void *aContext)
 Function to enumerate all of the UART devices configured (in the CASCODA_UART environment variable), calling aCallback with a struct describing each one. More...
 
int uart_exchange_reset (unsigned long resettime, struct ca821x_dev *pDeviceRef)
 Send a hard reset to the ca821x. More...
 

Function Documentation

◆ uart_exchange_deinit()

void uart_exchange_deinit ( struct ca821x_dev pDeviceRef)

Deinitialise the uart exchange, so that it can be reinitialised by another process, or reopened later.

Parameters
pDeviceRefPointer to initialised ca821x_device_ref struct

◆ uart_exchange_enumerate()

ca_error uart_exchange_enumerate ( util_device_found  aCallback,
void *  aContext 
)

Function to enumerate all of the UART devices configured (in the CASCODA_UART environment variable), calling aCallback with a struct describing each one.

The struct passed to aCallback will only be valid for the duration that the function is called. This function will not return until every callback has been called.

Parameters
aCallbackThe callback to call with each result
aContextThe generic void pointer to provide to the callback when it is called
Return values
CA_ERROR_SUCCESSEnumeration successful
CA_ERROR_NOT_FOUNDNo devices found

◆ uart_exchange_init()

ca_error uart_exchange_init ( ca821x_errorhandler  callback,
const char *  path,
struct ca821x_dev pDeviceRef 
)

Initialise the uart exchange, using the supplied errorhandling callback to report any errors back to the application, which can react as required (i.e.

crash gracefully or attempt to reset the ca821x)

Regarding the path argument, it can be manually selected, or obtained from calling uart_exchange enumerate. The string is a colon-delimited list of comma delimited 'device,baud' pairs. Unlike the USB version of this function, the path argument can be used to specify devices that wouldn't otherwise be available (i.e. they don't need to exist in the CASCODA_UART environment variable).

Parameters
[in]callbackFunction pointer to an error-handling callback (can be NULL)
[in]pathString representing possible UART devices and baud rates in the form "/dev/ttyS0,115200:/dev/ttyS1,9600:/dev/ttyS2,6000000"
[in]pDeviceRefPointer to initialised ca821x_device_ref struct
Return values
CA_ERROR_SUCCESSfor success
CA_ERROR_NOT_FOUNDfor error
CA_ERROR_ALREADYif the device was already initialised

◆ uart_exchange_reset()

int uart_exchange_reset ( unsigned long  resettime,
struct ca821x_dev pDeviceRef 
)

Send a hard reset to the ca821x.

This should not be necessary, but is provided in case the ca821x becomes unresponsive to spi.

Parameters
[in]resettimeThe length of time (in ms) to hold the reset pin active for. 1ms is usually a suitable value for this.
[in]pDeviceRefPointer to initialised ca821x_device_ref struct