Fifo buffer


Detailed Description

Buffers structures implemented in uSmartX are standard cyclic fifo buffers with some additional features. Basicaly they are very similar to mailboxes with the exception that a tasks could't pend on it when they are requesting or putting data into it. The buffer strucure is not fixed but, it is defined at compile time, particulary the buffer size and the element size. Other parameters of the buffer can be changed in run time, although some default values are entered at compile time.

Buffers have two event functions associated. One of them is invoked when the buffer fills to a certain level and the second one is executed when the buffer contains unread data which is older that the specified timeout.


Defines

#define BUF_CREATE(name, n, data_size)
 Create a cyclic fifo buffer.

Functions

STATUS BUF_Put (HANDLE *ph, void *pdata)
 Put data into the buffer.
STATUS BUF_Get (HANDLE *ph, void *pdata)
 Get data from buffer.
void BUF_Flush (HANDLE *ph)
 Empty buffer.
uint16 BUF_Querry (HANDLE *ph)
 Querry buffer.
void BUF_AppendToutFxn (HANDLE *ph, uint16 timeout, STATUS(*pfxn)(uint8 evt, void *parg1, void *parg2))
 Set buffer timeout.
void BUF_AppendTrgFxn (HANDLE *ph, uint16 trigger, STATUS(*pfxn)(uint8 evt, void *parg1, void *parg2))
 Set buffer trigger level.


Define Documentation

#define BUF_CREATE name,
n,
data_size   ) 
 

Create a cyclic fifo buffer.

This macro creates a cyclic fifo buffer structure and allocates needed memory.

Parameters:
name name of the buffer
n number of data containers
data_size data size of each entry
Examples:
buffer.c.


Function Documentation

void BUF_AppendToutFxn HANDLE *  ph,
uint16  timeout,
STATUS(*)(uint8 evt, void *parg1, void *parg2)  pfxn
 

Set buffer timeout.

By default the buffer structure has no timeout callback function associated. This function appends a timeout callback function that will be fired if the fifo contains data that is older that the timeout period. The handle to the buffer structure is passed thrue the parg1 argument of the callback function. Each read or write access on the buffer re-triggers the timer. Note that the callback funcion is executed from the uSMARTX_Tick() context.

Parameters:
ph handle to buffer
timeout timeout in system ticks
pfxn address of the callback function
Examples:
buffer.c.

void BUF_AppendTrgFxn HANDLE *  ph,
uint16  trigger,
STATUS(*)(uint8 evt, void *parg1, void *parg2)  pfxn
 

Set buffer trigger level.

By default the buffer structure has no trigger callback function associated. This function appends the trigger callback function with a defined trigger level. The function is executed only once and is re-triggered when the buffer is completely emptied out (also BUF_Flush()). The handle to the buffer structure is passed to the function via the parg1 argument.

Parameters:
ph handle to buffer
trigger trigger level
pfxn address of the callback function
Examples:
buffer.c.

void BUF_Flush HANDLE *  ph  ) 
 

Empty buffer.

Parameters:
ph handle to buffer

STATUS BUF_Get HANDLE *  ph,
void *  pdata
 

Get data from buffer.

If there is some data in the buffer this function retrieves it. Each read access on the buffer also reset the associated timeout callback function timeout.

Parameters:
ph handle to buffer
pdata pointer to where the data will be written
Return values:
SYS_OK data was retrived from buffer
SYS_ERROR there was no data in buffer
Examples:
buffer.c.

STATUS BUF_Put HANDLE *  ph,
void *  pdata
 

Put data into the buffer.

This function writes data into the buffer if there is enough free space. If there is a trigger function set and the function has reached the trigger level the trigger callback function is executed. Note the execution context is the same as BUF_Put. Each write access resets the timeout callback function timeout.

Parameters:
ph handle to buffer
pdata pointer to data to write in
Return values:
SYS_OK data was stored into the buffer
SYS_ERROR there was no enough free space
Examples:
buffer.c.

uint16 BUF_Querry HANDLE *  ph  ) 
 

Querry buffer.

Parameters:
ph handle to buffer


Generated on Sun Oct 16 22:23:55 2005 for uSmartX by  doxygen 1.4.3