XBee Firmware Library  1.6.0
Files | Data Structures | Typedefs | Functions | Variables
Circular Buffer

Files

file  cbuf.h
 
file  xbee_cbuf.c
 

Data Structures

struct  xbee_cbuf_t
 

Typedefs

typedef XBEE_BEGIN_DECLS struct xbee_cbuf_t xbee_cbuf_t
 

Functions

void xbee_cbuf_flush (xbee_cbuf_t FAR *cbuf)
 Flush the contents of the circular buffer. More...
 
uint_fast8_t xbee_cbuf_free (xbee_cbuf_t FAR *cbuf)
 Returns the number of additional bytes that can be stored in the circular buffer. More...
 
uint_fast8_t xbee_cbuf_get (xbee_cbuf_t *cbuf, void FAR *buffer, uint_fast8_t length)
 Read (and remove) multiple bytes from circular buffer. More...
 
int xbee_cbuf_getch (xbee_cbuf_t FAR *cbuf)
 Remove and return the first byte of the circular buffer. More...
 
int xbee_cbuf_init (xbee_cbuf_t FAR *cbuf, uint_fast8_t datasize)
 Initialize the fields of the circular buffer. More...
 
uint_fast8_t xbee_cbuf_put (xbee_cbuf_t FAR *cbuf, const void FAR *buffer, uint_fast8_t length)
 Append multiple bytes to the end of a 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...
 
uint_fast8_t xbee_cbuf_used (xbee_cbuf_t FAR *cbuf)
 Returns the number of bytes stored in the circular buffer. More...
 

Variables

uint8_t data [1]
 
uint8_t head
 
uint8_t lock
 
uint8_t mask
 
uint8_t tail
 

Detailed Description

Typedef Documentation

typedef XBEE_BEGIN_DECLS struct xbee_cbuf_t xbee_cbuf_t

Circular buffer used by transparent serial cluster handler. Buffer is empty when head == tail and full when head == (tail - 1).

Function Documentation

void xbee_cbuf_flush ( xbee_cbuf_t FAR *  cbuf)

Flush the contents of the circular buffer.

Parameters
[in,out]cbufPointer to circular buffer.
uint_fast8_t xbee_cbuf_free ( xbee_cbuf_t FAR *  cbuf)

Returns the number of additional bytes that can be stored in the circular buffer.

Parameters
[in]cbufPointer to circular buffer.
Return values
0-255Number of unused bytes in the circular buffer.
See also
xbee_cbuf_length, xbee_cbuf_free
uint_fast8_t xbee_cbuf_get ( xbee_cbuf_t cbuf,
void FAR *  buffer,
uint_fast8_t  length 
)

Read (and remove) multiple bytes from circular buffer.

Parameters
[in,out]cbufcircular buffer
[out]bufferdestination to copy data from circular buffer
[in]lengthnumber of bytes to copy
Return values
0-255number of bytes copied (may be less than length if buffer is empty)
int xbee_cbuf_getch ( xbee_cbuf_t FAR *  cbuf)

Remove and return the first byte of the circular buffer.

Parameters
[in]cbufPointer to circular buffer.
Return values
-1buffer is empty
0-255byte removed from the head of the buffer
See also
xbee_cbuf_putch, xbee_cbuf_get, xbee_cbuf_put
int xbee_cbuf_init ( xbee_cbuf_t FAR *  cbuf,
uint_fast8_t  datasize 
)

Initialize the fields of the circular buffer.

Note
You must initialize the xbee_cbuf_t structure before using it with any other xbee_cbuf_xxx() functions. If you have ISRs pushing data into the buffer, don't enable them until AFTER you've called xbee_cbuf_init.
Parameters
[in,out]cbufAddress 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]datasizeMaximum number of bytes to store in the circular buffer. This size must be at least 3, no more than 255, and a power of 2 minus 1 (2^n - 1).
Return values
0success
-EINVALinvalid parameter
uint_fast8_t xbee_cbuf_put ( xbee_cbuf_t FAR *  cbuf,
const void FAR *  buffer,
uint_fast8_t  length 
)

Append multiple bytes to the end of a circular buffer.

Parameters
[in,out]cbufcircular buffer
[in]bufferdata to copy into circular buffer
[in]lengthnumber of bytes to copy
Return values
0-255number of bytes copied (may be less than length if buffer is full)
int xbee_cbuf_putch ( xbee_cbuf_t FAR *  cbuf,
uint_fast8_t  ch 
)

Append a single byte to the circular buffer (if not full).

Parameters
[in,out]cbufPointer to circular buffer.
[in]chByte to append.
Return values
0buffer is full
1the byte was appended
See also
xbee_cbuf_getch, xbee_cbuf_get, xbee_cbuf_put
uint_fast8_t xbee_cbuf_used ( xbee_cbuf_t FAR *  cbuf)

Returns the number of bytes stored in the circular buffer.

Parameters
[in]cbufPointer to circular buffer.
Return values
0-255Number of bytes stored in the circular buffer.
See also
xbee_cbuf_length, xbee_cbuf_free

Variable Documentation

uint8_t data[1]
uint8_t head
uint8_t lock
uint8_t mask
uint8_t tail