Digi XBee(R) ANSI C Host Library
|
Circular buffer data type used by the OTA (Over-The-Air) firmware update client and transparent serial cluster. More...
Files | |
file | cbuf.h |
file | xbee_cbuf.c |
Circular buffer data type used by the OTA (Over-The-Air) firmware update client and transparent serial cluster. | |
Data Structures | |
struct | xbee_cbuf_t |
Circular buffer used by transparent serial cluster handler. More... | |
Macros | |
#define | XBEE_CBUF_OVERHEAD sizeof(xbee_cbuf_t) |
XBEE_CBUF_OVERHEAD is used when allocating memory for a circular buffer. More... | |
#define | xbee_cbuf_length(cbuf) ((cbuf)->mask) |
Returns the capacity of the circular buffer. More... | |
Functions | |
int | xbee_cbuf_init (xbee_cbuf_t FAR *cbuf, unsigned int datasize) |
Initialize the fields of the circular buffer. More... | |
int | xbee_cbuf_putch (xbee_cbuf_t FAR *cbuf, uint_fast8_t ch) |
Append a single byte to the circular buffer (if not full). More... | |
int | xbee_cbuf_getch (xbee_cbuf_t FAR *cbuf) |
Remove and return the first byte of the circular buffer. More... | |
unsigned int | xbee_cbuf_used (xbee_cbuf_t FAR *cbuf) |
Returns the number of bytes stored in the circular buffer. More... | |
unsigned int | xbee_cbuf_free (xbee_cbuf_t FAR *cbuf) |
Returns the number of additional bytes that can be stored in the circular buffer. More... | |
void | xbee_cbuf_flush (xbee_cbuf_t FAR *cbuf) |
Flush the contents of the circular buffer. More... | |
unsigned int | xbee_cbuf_put (xbee_cbuf_t FAR *cbuf, const void FAR *buffer, unsigned int length) |
Append multiple bytes to the end of a circular buffer. More... | |
unsigned int | xbee_cbuf_get (xbee_cbuf_t *cbuf, void FAR *buffer, unsigned int length) |
Read (and remove) multiple bytes from circular buffer. More... | |
Circular buffer data type used by the OTA (Over-The-Air) firmware update client and transparent serial cluster.
#define xbee_cbuf_length | ( | cbuf | ) | ((cbuf)->mask) |
Returns the capacity of the circular buffer.
[in] | cbuf | Pointer to circular buffer. |
#define XBEE_CBUF_OVERHEAD sizeof(xbee_cbuf_t) |
XBEE_CBUF_OVERHEAD is used when allocating memory for a circular buffer.
For a cbuf that can hold X bytes, you need (X + CBUF_OVERHEAD) bytes of memory.
XBEE_CBUF_OVERHEAD includes a header, plus a separator byte in the buffered data.
For example, to set up a 31-byte circular buffer:
void xbee_cbuf_flush | ( | xbee_cbuf_t FAR * | cbuf | ) |
Flush the contents of the circular buffer.
[in,out] | cbuf | Pointer to circular buffer. |
Referenced by xbee_ser_rx_flush(), and xbee_ser_tx_flush().
unsigned int xbee_cbuf_free | ( | xbee_cbuf_t FAR * | cbuf | ) |
Returns the number of additional bytes that can be stored in the circular buffer.
[in] | cbuf | Pointer to circular buffer. |
Referenced by xbee_cbuf_put(), xbee_ser_flowcontrol(), xbee_ser_getchar(), xbee_ser_read(), xbee_ser_rx_free(), xbee_ser_tx_free(), and xbee_ser_write().
unsigned int xbee_cbuf_get | ( | xbee_cbuf_t * | cbuf, |
void FAR * | buffer, | ||
unsigned int | length | ||
) |
Read (and remove) multiple bytes from circular buffer.
[in,out] | cbuf | circular buffer |
[out] | buffer | destination to copy data from circular buffer |
[in] | length | number of bytes to copy |
References FAR, and xbee_cbuf_used().
Referenced by _pxbee_ota_xmodem_read(), and xbee_ser_read().
int xbee_cbuf_getch | ( | xbee_cbuf_t FAR * | cbuf | ) |
Remove and return the first byte of the circular buffer.
[in] | cbuf | Pointer to circular buffer. |
-1 | buffer is empty |
0-255 | byte removed from the head of the buffer |
Referenced by xbee_ser_getchar(), and xbee_ser_write().
int xbee_cbuf_init | ( | xbee_cbuf_t FAR * | cbuf, |
unsigned int | datasize | ||
) |
Initialize the fields of the circular buffer.
[in,out] | cbuf | Address of buffer to use for the circular buffer. This buffer must be (datasize + CBUF_OVEREAD) bytes long to hold the locks, head, tail, size and buffered bytes. |
[in] | datasize | Maximum number of bytes to store in the circular buffer. This size must be at least 3 and a power of 2 minus 1 (2^n - 1). |
0 | success |
-EINVAL | invalid parameter |
References EINVAL.
Referenced by pxbee_ota_init(), and xbee_ser_open().
unsigned int xbee_cbuf_put | ( | xbee_cbuf_t FAR * | cbuf, |
const void FAR * | buffer, | ||
unsigned int | length | ||
) |
Append multiple bytes to the end of a circular buffer.
[in,out] | cbuf | circular buffer |
[in] | buffer | data to copy into circular buffer |
[in] | length | number of bytes to copy |
References FAR, and xbee_cbuf_free().
Referenced by _pxbee_ota_transparent_rx(), and xbee_ser_write().
int xbee_cbuf_putch | ( | xbee_cbuf_t FAR * | cbuf, |
uint_fast8_t | ch | ||
) |
Append a single byte to the circular buffer (if not full).
[in,out] | cbuf | Pointer to circular buffer. |
[in] | ch | Byte to append. |
0 | buffer is full |
1 | the byte was appended |
Referenced by xbee_ser_baudrate(), and xbee_ser_putchar().
unsigned int xbee_cbuf_used | ( | xbee_cbuf_t FAR * | cbuf | ) |
Returns the number of bytes stored in the circular buffer.
[in] | cbuf | Pointer to circular buffer. |
Referenced by xbee_cbuf_get(), xbee_ser_read(), xbee_ser_rx_used(), and xbee_ser_tx_used().