Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
usb-exchange.h File Reference

Cascoda posix exchange for communicating with ca821x via usb. More...

Include dependency graph for usb-exchange.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TEST_ENABLE   1
 

Enumerations

enum  usb_exchange_errors { usb_exchange_err_usb = 1 , usb_exchange_err_ca821x , usb_exchange_err_generic }
 

Functions

ca_error usb_exchange_init (ca821x_errorhandler callback, const char *path, struct ca821x_dev *pDeviceRef, char *serial_num)
 Initialise the usb exchange. More...
 
void usb_exchange_deinit (struct ca821x_dev *pDeviceRef)
 Deinitialise the usb exchange, so that it can be reinitialised by another process, or reopened later. More...
 
int usb_exchange_reset (unsigned long resettime, struct ca821x_dev *pDeviceRef)
 Send a hard reset to the ca821x. More...
 
ca_error usb_exchange_enumerate (util_device_found aCallback, void *aContext)
 Function to enumerate all of the USB connected devices, calling aCallback with a struct describing each one. More...
 
void test_frag_loopback ()
 Run to test fragmentation. More...
 

Detailed Description

Cascoda posix exchange for communicating with ca821x via usb.

Macro Definition Documentation

◆ TEST_ENABLE

#define TEST_ENABLE   1

Enumeration Type Documentation

◆ usb_exchange_errors

Enumerator
usb_exchange_err_usb 

Usb error - probably device removed and going to have to crash safely.

usb_exchange_err_ca821x 

ca821x error - ca821x has been reset

usb_exchange_err_generic 

Function Documentation

◆ test_frag_loopback()

void test_frag_loopback ( )

Run to test fragmentation.

Crashes upon fail.

◆ usb_exchange_deinit()

void usb_exchange_deinit ( struct ca821x_dev pDeviceRef)

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

Parameters
pDeviceRefPointer to initialised ca821x_device_ref struct

◆ usb_exchange_enumerate()

ca_error usb_exchange_enumerate ( util_device_found  aCallback,
void *  aContext 
)

Function to enumerate all of the USB connected devices, 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

◆ usb_exchange_init()

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

Initialise the usb exchange.

If callback is specified, then it will be used to report any fatal errors back to the application, which can react as required (i.e. crash gracefully or attempt to reset the ca821x)

If path is specified, then the exchange will attempt to open that device, and fail if it cannot. The path of a device can be obtained with usb_exchange_enumerate.

If serial_num is specified, then the exchange will run an additional check when iterating through all devices, looking for one with matching serial number; Otherwise it will carry out the normal iteration and try to open the first available device.

Parameters
[in]callbackFunction pointer to an error-handling callback (can be NULL)
[in]pathString representing an exchange & system specific path to a device (can be NULL)
[in]pDeviceRefPointer to initialised ca821x_device_ref struct
[in]serial_numSerial number of the target device (can be NULL)
Return values
CA_ERROR_SUCCESSsuccess
CA_ERROR_NOT_FOUNDNo available devices found (or device at path not found)
CA_ERROR_NO_ACCESSThe specified path cannot be opened (e.g. no permissions, already in use)
CA_ERROR_ALREADYThe pDeviceRef is already initialised

◆ usb_exchange_reset()

int usb_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