Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
ca821x-generic-exchange.c File Reference
#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include "ca821x-posix/ca821x-posix.h"
#include "ca821x-generic-exchange.h"
#include "ca821x-posix-evbme-internal.h"
#include "ca821x-queue.h"
#include "ca821x_api.h"
Include dependency graph for ca821x-generic-exchange.c:

Enumerations

enum  { SYNC_TIMEOUT_S = 5 }
 

Functions

ca_error ca821x_util_dispatch_poll ()
 Generic function to poll the receive queue and call callbacks for received commands. More...
 
ca_error ca821x_util_start_upstream_dispatch_worker ()
 Start the upstream_dispatch worker, which asynchronously calls the message callbacks (such as MCPS_DATA_indication) as they are received. More...
 
ca_error ca821x_util_stop_upstream_dispatch_worker ()
 Stop the upstream_dispatch worker, so callbacks will no longer be triggered from a separate thread. More...
 
ca_error init_generic (struct ca821x_dev *pDeviceRef)
 Initialise the generic part of a pDeviceRef. More...
 
ca_error deinit_generic (struct ca821x_dev *pDeviceRef)
 Deinitialise an initialised pDeviceRef struct. More...
 
ca_error exchange_register_user_callback (exchange_user_callback callback, struct ca821x_dev *pDeviceRef)
 Registers the callback to call for any non-ca821x commands that are sent over the interface. More...
 
ca_error exchange_wait_send_complete (time_t timeout_s, struct ca821x_dev *pDeviceRef)
 Query whether the given exchange has any messages pending being sent in its send queue. More...
 
ca_error exchange_user_command (uint8_t cmdid, uint8_t cmdlen, uint8_t *payload, struct ca821x_dev *pDeviceRef)
 Sends a user-defined command over the connected interface. More...
 
ca_error exchange_handle_error (ca_error error, struct ca821x_dev *pDeviceRef)
 Attempt to recover from an exchange error silently. More...
 
void * ca821x_io_worker (void *arg)
 io worker thread function. More...
 
ca_error ca821x_exchange_commands (const uint8_t *buf, size_t len, uint8_t *response, struct ca821x_dev *pDeviceRef)
 Handle an exchange with the ca821x. More...
 
ca_error ca821x_api_downstream (const uint8_t *buf, uint8_t *response, struct ca821x_dev *pDeviceRef)
 Function for downstream api interface. More...
 

Variables

void(* wake_hw_worker )(void)
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SYNC_TIMEOUT_S 

Function Documentation

◆ ca821x_exchange_commands()

ca_error ca821x_exchange_commands ( const uint8_t *  buf,
size_t  len,
uint8_t *  response,
struct ca821x_dev pDeviceRef 
)

Handle an exchange with the ca821x.

Used as the downstream function for ca821x-api.

Parameters
bufThe buffer to send
lenThe length of the buffer to send, including header bytes
responseThe buffer to use for the response message to synchronous messages
pDeviceRefan initialised pDeviceRef struct.
Returns
status
Return values
CA_ERROR_SUCCESSSuccess
CA_ERROR_INVALID_STATEInvalid state, such as uninitialised.
CA_ERROR_TIMEOUTResponse was not received to synchronous command in reasonable timeframe.

◆ ca821x_io_worker()

void* ca821x_io_worker ( void *  arg)

io worker thread function.

Handles reads/writes to the exchange, buffering and debuffering messages as required.

Parameters
argan initialised pDeviceRef struct.
Returns
0

◆ deinit_generic()

ca_error deinit_generic ( struct ca821x_dev pDeviceRef)

Deinitialise an initialised pDeviceRef struct.

Parameters
pDeviceRefan initialised pDeviceRef struct.
Returns
CA_ERROR_SUCCESS upon success, error upon failure

◆ exchange_handle_error()

ca_error exchange_handle_error ( ca_error  error,
struct ca821x_dev pDeviceRef 
)

Attempt to recover from an exchange error silently.

Parameters
errorThe error code that caused the crash
pDeviceRefThe initialised pDeviceRef struct related to the error.
Returns
CA_ERROR_SUCCESS

◆ init_generic()

ca_error init_generic ( struct ca821x_dev pDeviceRef)

Initialise the generic part of a pDeviceRef.

Parameters
pDeviceRefAn allocated and partially initialised pDeviceRef struct
Returns
CA_ERROR_SUCCESS upon success, error upon failure

Variable Documentation

◆ wake_hw_worker

void(* wake_hw_worker) (void) ( void  )