A FIFO is special type of variable which allows data to be queued. Data read from a FIFO is always read in the same order in which it was writen to the FIFO. FIFO actually stands for First In First Out.FIFOs are great for allowing asynchronous processes to talk to eash other with very little additional overhead. Using a FIFO to communicate between a task and an interrupt service routine allows you to do so without needing to lock memory or disable interrupts (sometimes refered to as serialising access). The greatest drawback to using FIFOs is that you need to allocate precious RAM for them.
A FIFO is declared like as array, but it cannot be indexed like an array. It is also not possible to create a constant FIFO.
Pointers to FIFOs are allowed.
Declaring a FIFO
A fifo is declared as:
FIFO fred[10]Note that here the [10] component of the declaration indicates the size of the FIFO buffer. Because of the way the FIFO works a buffer of size 10 actually means that the FIFO can queue a maximum of 9 bytes before it gets full and unable to queue any more data.
A pointer to a FIFO is declared as
FIFO *bertFIFOs are initialised at runtime by XCSB at the start of the scope in which they are declared. This means that if you declare a FIFO as global, it will be initialised before the first statement of any of your tasks (including main and intserv) are executed. If you declare a FIFO in any other function it will be initialised by XCSB when that function is entered and before any other statement in that function is executed. It is very important that a FIFO is not used outside the scope in which it is declared otherwise the effect is undefined.
Invoking a function which declares a FIFO, exiting the function and expecting the FIFO to remain valid once the function has exited is seriously bad. It is like expecting a function varible to remain valid after the function has exited.
Data is read from and written to a FIFO using the FIFO library. Using this library it is also possible to check to see if a FIFO is empty or full.
The task_wait statement is FIFO aware and can be given wait conditions that specify the status of one or more FIFOs