Bare Metal Programming Tool Kit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | List of all members
bmptk::rtos::channel< T, SIZE > Class Template Reference

waitable data queue More...

#include <rtos.h>

Inheritance diagram for bmptk::rtos::channel< T, SIZE >:

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
 
read ()
 read an item from the queue
 
void clear (void)
 empty the queue
 

Detailed Description

template<class T, const int SIZE>
class bmptk::rtos::channel< T, SIZE >

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.

class output_class : public task {
public:
channel< char, 2048 > buffer( flags, "buffer" );
timer hartbeat( flags, "hartbeat" );
void main(){
for(;;){
wait( buffer );
cout << buffer.get();
timer.set( 2 MS );
wait( timer );
}
}
}
output_class output;
void print( char *s ){
while( *s != '\0' ){ output.buffer.write( *s++ ); }
}

Definition at line 1252 of file rtos.h.

Constructor & Destructor Documentation

template<class T , const int SIZE>
bmptk::rtos::channel< T, SIZE >::channel ( task t,
const char *  name = "" 
)
inline

constructor, specify stored type, number of entries, and name

The template argument T must be a class that has a non-arguments constructor and supports assignment.

Definition at line 1259 of file rtos.h.


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