Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
ca821x-queue.c File Reference

Queue manipulation for ca821x-posix data exchange. More...

#include <errno.h>
#include <string.h>
#include <time.h>
#include "ca821x-queue.h"
Include dependency graph for ca821x-queue.c:

Functions

void add_to_queue (struct buffer_queue *buffer_queue, const uint8_t *buf, size_t len, struct ca821x_dev *pDeviceRef)
 Add a buffer onto the end of a queue. More...
 
void flush_queue (struct buffer_queue *buffer_queue)
 Empty a queue into nothing. More...
 
size_t pop_from_queue (struct buffer_queue *buffer_queue, uint8_t *destBuf, size_t maxlen, struct ca821x_dev **pDeviceRef_out)
 Pop a buffer off a queue. More...
 
size_t peek_queue (struct buffer_queue *buffer_queue)
 Non-blocking function returning the length of the next buffer on the queue (or 0 if nothing) More...
 
size_t wait_on_queue (struct buffer_queue *buffer_queue, time_t timeout_s)
 Wait on a queue, blocking until there is something available. More...
 
ca_error wait_on_queue_empty (struct buffer_queue *buffer_queue, time_t timeout_s)
 Wait on a queue, blocking until it is empty. More...
 

Detailed Description

Queue manipulation for ca821x-posix data exchange.

Function Documentation

◆ add_to_queue()

void add_to_queue ( struct buffer_queue buffer_queue,
const uint8_t *  buf,
size_t  len,
struct ca821x_dev pDeviceRef 
)

Add a buffer onto the end of a queue.

Parameters
buffer_queueA pointer to the queue
bufThe buffer to queue
lenThe length in bytes of the buffer
pDeviceRefThe pDeviceRef that the buffer is relevant to

◆ flush_queue()

void flush_queue ( struct buffer_queue buffer_queue)

Empty a queue into nothing.

Parameters
buffer_queueA pointer to the head of a queue

◆ peek_queue()

size_t peek_queue ( struct buffer_queue buffer_queue)

Non-blocking function returning the length of the next buffer on the queue (or 0 if nothing)

Parameters
buffer_queueA pointer to the queue
Returns
The length of the peeked buffer, or 0 if there is no buffer in queue

◆ pop_from_queue()

size_t pop_from_queue ( struct buffer_queue buffer_queue,
uint8_t *  destBuf,
size_t  maxlen,
struct ca821x_dev **  pDeviceRef_out 
)

Pop a buffer off a queue.

Parameters
buffer_queueA pointer to the queue
[out]destBufA pointer to a buffer to accept the dequeued data
maxlenThe max size of the destBuf
[out]pDeviceRef_outOutput parameter to store the pDeviceRef of the buffer
Returns
The length of the popped buffer

◆ wait_on_queue()

size_t wait_on_queue ( struct buffer_queue buffer_queue,
time_t  timeout_s 
)

Wait on a queue, blocking until there is something available.

Parameters
buffer_queueA pointer to the queue
timeout_sThe wait timeout in seconds, or 0 for no timeout
Returns
The length of the next item in the queue, 0 on timeout, or -1 on error

◆ wait_on_queue_empty()

ca_error wait_on_queue_empty ( struct buffer_queue buffer_queue,
time_t  timeout_s 
)

Wait on a queue, blocking until it is empty.

Parameters
buffer_queueA pointer to the queue
timeout_sThe wait timeout in seconds, or 0 for no timeout
Returns
CA_ERROR_SUCCESS upon success, CA_ERROR_TIMEOUT if operation timed out