[previous] [index] [next]

Example 4: FIFO Communication Between RTL and Linux

This example shows how to set up a first-in, first out (FIFO) data queue for sharing data between real-time tasks and user-level applications. FIFOs are often used to connect a non-realtime human-machine interface to a real-time application, or to log messages to disk files. These FIFOs are analogous to normal Unix FIFOs, i.e., those that use a fifo special file created with the Unix command 'mkfifo'.

FIFOs are simple queues of raw bytes. Typically, fixed-sized data structures are written to a FIFO, so that the reader doesn't need to worry about message boundaries. In some cases variable-sized messages are written, in which case the reader must search for the message boundary, often a special character. In this example we used fixed-size messages.

Refer to the commented real-time source code and the commented application source code for the details.

Principle of Operation

Creating a FIFO

Accessing a FIFO

FIFO Handlers

Blocking v. Non-Blocking Reads

FIFO Uses

FIFOs can be used for all communication between real-time tasks and Linux processes, but their queued nature makes them best suited for ordered streams of data, such as

FIFOs are not well suited for repeatedly transferring large data structures whose contents only change sparsely. Shared memory is a better solution.

Running the Demo

To run the demo, change to the 'ex04_fifo' subdirectory of the top-level tutorial directory, and run the 'run' script by typing
./run
Alternatively, change to the top-level tutorial directory and run the 'runall' script there by typing
./runall
and selecting the "FIFOs" button.

You'll hear a continuously varying tone for about 10 seconds.

See the Real-Time Task Code

See the Linux Application Code


Next: Example 5, Interrupt Service Routines

Back: Example 3, Variable-Period Scheduling of a Single Task