NetBurner 3.5.7
PDF Version
OS_FIFO Struct Reference

A linked-list FIFO for passing pointers to user-defined structures between tasks. More...

#include <nbrtos.h>

Inherits OS_TASK_DLY_OBJ.

Public Member Functions

 OS_FIFO ()
 Construct and initialize the FIFO (empty linked list).
 
uint8_t Init ()
 Reset the FIFO to its initial (empty) state.
 
uint8_t Post (OS_FIFO_EL *pToPost)
 Post an element to the tail of the FIFO.
 
uint8_t PostFirst (OS_FIFO_EL *pToPost)
 Post an element to the head of the FIFO (priority insertion).
 
OS_FIFO_ELPend (uint32_t timeoutTicks, uint8_t &result)
 Wait for an element to be posted to the FIFO.
 
OS_FIFO_ELPend (TickTimeout &t, uint8_t &result)
 Wait for an element to be posted to the FIFO, using a TickTimeout.
 
OS_FIFO_ELPend (uint32_t timeoutTicks=WAIT_FOREVER)
 Wait for an element to be posted to the FIFO (no result code).
 
OS_FIFO_ELPendUntil (uint32_t timeoutTime, uint8_t &result)
 Wait until an absolute TimeTick value for an element to be posted.
 
OS_FIFO_ELPendNoWait (uint8_t &result)
 Retrieve an element from the FIFO without waiting.
 
OS_FIFO_ELPendNoWait ()
 Retrieve an element from the FIFO without waiting (no result code).
 

Detailed Description

A linked-list FIFO for passing pointers to user-defined structures between tasks.

Unlike OS_Q (which stores void pointers in a fixed-size array), OS_FIFO uses a linked list so there is no predefined capacity limit. Each element posted must begin with an OS_FIFO_EL-compatible header (a pointer used internally to link elements together). Your application is responsible for allocating the elements, either statically or from the heap.

Elements are extracted in FIFO order (first posted = first retrieved), unless PostFirst() is used to insert at the head.

Note
If you only need to pass simple pointer-sized values, OS_Q may be simpler.
See also
OS_Q, OS_FIFO_EL, TEMPL_FIFO

Expand for Example Usage

Examples

Pass a Structure Between Tasks
struct MyMessage
{
OS_FIFO_EL link; // Must be the first member
int data;
};
OS_FIFO gFifo;
MyMessage gMsg;
void ProducerTask(void *pd)
{
gMsg.data = 42;
gFifo.Post((OS_FIFO_EL *)&gMsg);
}
void ConsumerTask(void *pd)
{
OS_FIFO_EL *pEl = gFifo.Pend(5 * TICKS_PER_SECOND);
if (pEl != NULL)
{
MyMessage *pMsg = (MyMessage *)pEl;
iprintf("Received data: %d\r\n", pMsg->data);
}
}
#define TICKS_PER_SECOND
System clock ticks per second.
Definition constants.h:49
A linked-list FIFO for passing pointers to user-defined structures between tasks.
Definition nbrtos.h:1177
OS_FIFO_EL * Pend(uint32_t timeoutTicks, uint8_t &result)
Wait for an element to be posted to the FIFO.
Definition nbrtos.h:1234
uint8_t Post(OS_FIFO_EL *pToPost)
Post an element to the tail of the FIFO.
Element header for OS_FIFO linked-list entries.
Definition nbrtos.h:1111

Constructor & Destructor Documentation

◆ OS_FIFO()

OS_FIFO::OS_FIFO ( )
inline

Construct and initialize the FIFO (empty linked list).

See also
Init()

Member Function Documentation

◆ Init()

uint8_t OS_FIFO::Init ( )

Reset the FIFO to its initial (empty) state.

Return values
OS_NO_ERRIf successful.
See also
NBRTOS Error Codes

◆ Pend() [1/3]

OS_FIFO_EL * OS_FIFO::Pend ( TickTimeout & t,
uint8_t & result )

Wait for an element to be posted to the FIFO, using a TickTimeout.

Parameters
tTickTimeout controlling the maximum wait duration.
resultReceives OS_NO_ERR on success or OS_TIMEOUT on timeout.
Returns
Pointer to the retrieved OS_FIFO_EL, or NULL on timeout.
See also
PendNoWait(), PendUntil(), NBRTOS Error Codes

◆ Pend() [2/3]

OS_FIFO_EL * OS_FIFO::Pend ( uint32_t timeoutTicks,
uint8_t & result )
inline

Wait for an element to be posted to the FIFO.

Parameters
timeoutTicksMaximum system ticks to wait. A value of 0 waits forever.
resultReceives OS_NO_ERR on success or OS_TIMEOUT on timeout.
Returns
Pointer to the retrieved OS_FIFO_EL, or NULL on timeout.
See also
PendNoWait(), PendUntil(), NBRTOS Error Codes

◆ Pend() [3/3]

OS_FIFO_EL * OS_FIFO::Pend ( uint32_t timeoutTicks = WAIT_FOREVER)
inline

Wait for an element to be posted to the FIFO (no result code).

Parameters
timeoutTicksMaximum system ticks to wait. A value of 0 (default) waits forever.
Returns
Pointer to the retrieved OS_FIFO_EL, or NULL on timeout.
See also
PendNoWait(), PendUntil(), NBRTOS Error Codes

◆ PendNoWait() [1/2]

OS_FIFO_EL * OS_FIFO::PendNoWait ( )
inline

Retrieve an element from the FIFO without waiting (no result code).

Returns
Pointer to the retrieved OS_FIFO_EL, or NULL if the FIFO was empty.
See also
Pend(), PendUntil(), NBRTOS Error Codes

◆ PendNoWait() [2/2]

OS_FIFO_EL * OS_FIFO::PendNoWait ( uint8_t & result)

Retrieve an element from the FIFO without waiting.

Parameters
resultReceives OS_NO_ERR if an element was available, or OS_TIMEOUT if empty.
Returns
Pointer to the retrieved OS_FIFO_EL, or NULL if the FIFO was empty.
See also
Pend(), PendUntil(), NBRTOS Error Codes

◆ PendUntil()

OS_FIFO_EL * OS_FIFO::PendUntil ( uint32_t timeoutTime,
uint8_t & result )
inline

Wait until an absolute TimeTick value for an element to be posted.

Parameters
timeoutTimeAbsolute system TimeTick value at which to stop waiting.
resultReceives OS_NO_ERR on success or OS_TIMEOUT on timeout.
Returns
Pointer to the retrieved OS_FIFO_EL, or NULL on timeout.
See also
Pend(), PendNoWait(), NBRTOS Error Codes

◆ Post()

uint8_t OS_FIFO::Post ( OS_FIFO_EL * pToPost)

Post an element to the tail of the FIFO.

If a higher-priority task is pending on this FIFO, it will be released.

Parameters
pToPostPointer to the element (cast as OS_FIFO_EL) to post.
Return values
OS_NO_ERRIf successful.
See also
PostFirst(), Pend()

◆ PostFirst()

uint8_t OS_FIFO::PostFirst ( OS_FIFO_EL * pToPost)

Post an element to the head of the FIFO (priority insertion).

Parameters
pToPostPointer to the element (cast as OS_FIFO_EL) to post at the head.
Return values
OS_NO_ERRIf successful.
See also
Post(), Pend()

The documentation for this struct was generated from the following file: