Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
|
#include <assert.h>
#include <dlfcn.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "hidapi/hidapi.h"
#include "ca821x-generic-exchange.h"
#include "ca821x-posix-util-internal.h"
#include "ca821x-queue.h"
#include "ca821x_api.h"
#include "usb-exchange.h"
Classes | |
struct | usb_exchange_priv |
The usb exchange private-data struct representing a single device. More... | |
Macros | |
#define | USB_VID 0x0416 |
#define | USB_PID 0x5020 |
#define | MAX_FRAG_SIZE 64 |
Maximum USB fragment size. More... | |
#define | POLL_DELAY 2 |
Max time to wait on rx data in milliseconds. More... | |
#define | FRAG_LEN_MASK 0x3F |
#define | FRAG_LAST_MASK (1 << 7) |
#define | FRAG_FIRST_MASK (1 << 6) |
#define | ARRAY_LENGTH(array) (sizeof((array)) / sizeof((array)[0])) |
#define | NO_CONST_CHAR(x) (((char *)(x))) |
Functions | |
void | test_frag_loopback () |
Run to test fragmentation. More... | |
void | usb_apply_raspi_workaround (struct ca821x_dev *pDeviceRef) |
This function applies a workaround that is necessary on the Raspberry pi for reliable USB communications. More... | |
ssize_t | usb_try_read (struct ca821x_dev *pDeviceRef, uint8_t *buf) |
ca_error | usb_try_write (const uint8_t *buffer, size_t len, struct ca821x_dev *pDeviceRef) |
void | flush_unread_usb (struct ca821x_dev *pDeviceRef) |
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... | |
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... | |
int | usb_exchange_reset (unsigned long resettime, struct ca821x_dev *pDeviceRef) |
Send a hard reset to the ca821x. More... | |
#define ARRAY_LENGTH | ( | array | ) | (sizeof((array)) / sizeof((array)[0])) |
#define FRAG_FIRST_MASK (1 << 6) |
#define FRAG_LAST_MASK (1 << 7) |
#define FRAG_LEN_MASK 0x3F |
#define MAX_FRAG_SIZE 64 |
Maximum USB fragment size.
#define NO_CONST_CHAR | ( | x | ) | (((char *)(x))) |
#define POLL_DELAY 2 |
Max time to wait on rx data in milliseconds.
#define USB_PID 0x5020 |
#define USB_VID 0x0416 |
void flush_unread_usb | ( | struct ca821x_dev * | pDeviceRef | ) |
void test_frag_loopback | ( | ) |
Run to test fragmentation.
Crashes upon fail.
void usb_apply_raspi_workaround | ( | struct ca821x_dev * | pDeviceRef | ) |
This function applies a workaround that is necessary on the Raspberry pi for reliable USB communications.
Essentially, on the raspberry pi, if there is not regular USB transmission to the OUT endpoint, the next OUT transmission will take up to 1000ms to complete. This behaviour has only been observed on the Raspberry pi. The hotfix for this is to send a USB transmission every 1 second on the raspi platform.
void usb_exchange_deinit | ( | struct ca821x_dev * | pDeviceRef | ) |
Deinitialise the usb exchange, so that it can be reinitialised by another process, or reopened later.
pDeviceRef | Pointer to initialised ca821x_device_ref struct |
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.
aCallback | The callback to call with each result |
aContext | The generic void pointer to provide to the callback when it is called |
CA_ERROR_SUCCESS | Enumeration successful |
CA_ERROR_NOT_FOUND | No devices found |
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.
[in] | callback | Function pointer to an error-handling callback (can be NULL) |
[in] | path | String representing an exchange & system specific path to a device (can be NULL) |
[in] | pDeviceRef | Pointer to initialised ca821x_device_ref struct |
[in] | serial_num | Serial number of the target device (can be NULL) |
CA_ERROR_SUCCESS | success |
CA_ERROR_NOT_FOUND | No available devices found (or device at path not found) |
CA_ERROR_NO_ACCESS | The specified path cannot be opened (e.g. no permissions, already in use) |
CA_ERROR_ALREADY | The pDeviceRef is already initialised |
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.
[in] | resettime | The length of time (in ms) to hold the reset pin active for. 1ms is usually a suitable value for this. |
[in] | pDeviceRef | Pointer to initialised ca821x_device_ref struct |
ssize_t usb_try_read | ( | struct ca821x_dev * | pDeviceRef, |
uint8_t * | buf | ||
) |
ca_error usb_try_write | ( | const uint8_t * | buffer, |
size_t | len, | ||
struct ca821x_dev * | pDeviceRef | ||
) |