Bare Metal Programming Tool Kit
|
waitable data queue More...
#include <rtos.h>
Public Member Functions | |
channel (task *t, const char *name="") | |
constructor, specify stored type, number of entries, and name | |
void | write (T item) |
write an item to the queue | |
T | read () |
read an item from the queue | |
void | clear (void) |
empty the queue | |
waitable data queue
The (communication) channel is a template class that stores a queue of values. Values can be written at the tail of the queue, up to the number of entries for which the channel was created. It is an error to write to a channel that is full. Writes are not blocking. Any task can write to a channel.
A channel is created for a particular task. Only this owner task can read from the channel. A read will block until an entry is available. Reads are from the head of the queue.
A channel is a waitable, so the task that owns the channel can wait for the channel to be non-empty, after which a read from a channel will be non-blocking (because the channel is not empty). After a wait() that returns the channel's event, the channel will set itself again (because the wait did not cause it to become empty). Only a read that results in an empty queue will clear the channel.
The example below shows how writing to cout can be buffered by first writing to a 2kB channel, and reading from that channel at a maximum of one character per 2 MS. The UART hardware in the LPC2148 chip buffers one character, which at default baudrate (38k4) takes ~ 1 MS to write. So by writing at a maximum rate of one character per 2 MS no blocking will occur.
|
inline |