RTAI fifos maintain full compatibility with those available in NMT_RTLinux while adding many other useful services that avoid the clumsiness of Unix/Linux calls. So if you need portability you should bent yourself to the use of select for timing out IO operations, while if you have not to satisfy such constraints use the available simpler, and more direct, RTAI fifos specific services.
In the table below the standard Unix/Linux services in user space are enclosed in []. See standard Linux man pages if you want to use them, they need not be explained here.
Called from RT task | Called from Linux process |
rtf_create | rtf_open_sized [open] |
rtf_destroy | [close] |
rtf_reset | rtf_reset |
rtf_resize | rtf_resize |
rtf_get | [read] rtf_read_timed rtf_read_all_at_once |
rtf_put | [write] rtf_write_timed |
rtf_create_handler | |
rtf_suspend_timed | |
rtf_set_async_sig |
In Linux, fifos have to be created by :
$ mknod /dev/rtf<x> c 150 <x>
What is important to remember is that in the user space side you address fifos through the file descriptor you get at fifo device opening while in kernel space you directly address them by their minor number. So you will mate the fd you get in user space by using
open(/dev/rtfxx,...)
xx
you will use in kernel space.
Files | |
file | rtai_fifos.h |
Interface of the RTAI FIFO module. | |
file | fifos.c |
Implementation of the RTAI FIFO module. | |
Functions | |
int | rtf_suspend_timed (int fd, int ms_delay) |
int | rtf_open_sized (const char *dev, int perm, int size) |
int | rtf_read_all_at_once (int fd, void *buf, int count) |
int | rtf_read_timed (int fd, void *buf, int count, int ms_delay) |
int | rtf_write_timed (int fd, void *buf, int count, int ms_delay) |
int | rtf_set_async_sig (int fd, int signum) |
int | rtf_reset (unsigned int minor) |
int | rtf_resize (unsigned int minor, int size) |
int | rtf_create (unsigned int minor, int size) |
int | rtf_destroy (unsigned int minor) |
int | rtf_create_handler (unsigned int minor, int(*handler)(unsigned int fifo)) |
int | rtf_put (unsigned int minor, void *buf, int count) |
int | rtf_get (unsigned int minor, void *buf, int count) |
|
Create a real-time FIFO rtf_create creates a real-time fifo (RT-FIFO) of initial size size and assigns it the identifier fifo. It must be used only in kernel space.
The RT-FIFO is a character based mechanism to communicate among real-time tasks and ordinary Linux processes. The rtf_* functions are used by the real-time tasks; Linux processes use standard character device access functions such as read, write, and select. If this function finds an existing fifo of lower size it resizes it to the larger new size. Note that the same condition apply to the standard Linux device open, except that when it does not find any already existing fifo it creates it with a default size of 1K bytes. It must be remarked that practically any fifo size can be asked for. In fact if size is within the constraint allowed by kmalloc such a function is used, otherwise vmalloc is called, thus allowing any size that can fit into the available core memory. Multiple calls of this function are allowed, a counter is kept internally to track their number, and avoid destroying/closing a fifo that is still used.
References rt_fifo_struct::asynq, atomic_cmpxchg, atomic_inc(), do_nothing(), fifo, rt_fifo_struct::handler, rt_fifo_struct::malloc_type, MAX_FIFOS, rt_fifo_struct::mbx, mbx_init(), mbx_sem_init(), rt_fifo_struct::opncnt, rt_fifo_struct::pol_asyn_pended, rtf_resize(), lx_mailbox::size, and TRACE_RTAI_FIFO. Referenced by init_module(), rtf_ioctl(), rtf_named_create(), and rtf_open(). Here is the call graph for this function: ![]() |
|
Install a FIFO handler function. rtf_create_handler installs a handler which is executed when data is written to or read from a real-time fifo.
References fifo, rt_fifo_struct::handler, handler, MAX_FIFOS, and TRACE_RTAI_FIFO. |
|
Close a real-time FIFO rtf_destroy closes, in kernel space, a real-time fifo previously created or reopened with rtf_create() or rtf_open_sized(). An internal mechanism counts how many times a fifo was opened. Opens and closes must be in pair. rtf_destroy should be called as many times as rtf_create was. After the last close the fifo is really destroyed. No need for any particular function for the same service in user space, simply use the standard Unix close.
References rt_fifo_struct::asynq, atomic_dec_and_test, do_nothing(), fifo, rt_fifo_struct::handler, rt_fifo_struct::malloc_type, mbx_delete(), rt_fifo_struct::name, rt_fifo_struct::opncnt, rt_fifo_struct::pol_asyn_pended, TRACE_RTAI_FIFO, and VALID_FIFO. Referenced by cleanup_module(), and rtf_release(). Here is the call graph for this function: ![]() |
|
Read data from FIFO rtf_get tries to read a block of data from a real-time fifo previously created with a call to rtf_create().
rtf_get is often used in conjunction with rtf_create_handler() to process data received asynchronously from a Linux process. A handler is installed via rtf_create_handler(); this handler calls rtf_get to receive any data present in the RT-FIFO as it becomes available. In this way, polling is not necessary; the handler is called only when data is present in the fifo.
References count, fifo, mbx_receive_wp(), TRACE_RTAI_FIFO, and VALID_FIFO. Here is the call graph for this function: ![]() |
|
Create a real-time FIFO rtf_open_sized is the equivalent of rtf_create() in user space; it creates a real-time fifo (RT-FIFO) of initial size size.
If this function finds an existing fifo of lower size it resizes it to the larger new size. Note that the same condition apply to the standard Linux device open, except that when it does not find any already existing fifo it creates it with a default size of 1K bytes. It must be remarked that practically any fifo size can be asked for. In fact if size is within the constraint allowed by kmalloc such a function is used, otherwise vmalloc is called, thus allowing any size that can fit into the available core memory. Multiple calls of this function are allowed, a counter is kept internally to track their number, and avoid destroying/closing a fifo that is still used.
|
|
Write data to FIFO rtf_put tries to write a block of data to a real-time fifo previously created with rtf_create().
References count, fifo, mbx_send_wp(), TRACE_RTAI_FIFO, and VALID_FIFO. Referenced by calibrate(), rt_timer_tick_ext(), spv(), and user_srq(). Here is the call graph for this function: ![]() |
|
Read data from FIFO in user space, waiting for all of them rtf_read_all_at_once reads a block of data from a real-time fifo identified by the file descriptor fd blocking till all waiting at most count bytes are available, whichever option was used at the related device opening.
References count, errno, and READ_ALL_AT_ONCE. |
|
Read data from FIFO in user space, with timeout. rtf_read_timed reads a block of data from a real-time fifo identified by the file descriptor fd waiting at most delay milliseconds to complete the operation.
References count, errno, and READ_TIMED. |
|
Reset a real-time FIFO rtf_reset resets RT-FIFO fd_fifo by setting its buffer pointers to zero, so that any existing data is discarded and the fifo started anew like at its creations. It can be used both in kernel and user space.
References lx_mailbox::avbs, F_MBX, lx_mailbox::fbyte, FIFO, fifo, lx_mailbox::frbs, lx_mailbox::lbyte, rt_fifo_struct::mbx, mbx_sem_signal(), mbx_sem_wait(), mbx_sem_wait_if(), mbx_signal(), lx_mailbox::rcvsem, lx_mailbox::size, lx_mailbox::sndsem, TRACE_RTAI_FIFO, VALID_FIFO, and lx_mailbox::waiting_task. Referenced by rtf_ioctl(), and rtf_llseek(). Here is the call graph for this function: ![]() |
|
Resize a real-time FIFO rtf_resize modifies the real-time fifo fifo, previously created with, rtf_create(), to have a new size of size. Any data in the fifo is discarded.
References lx_mailbox::avbs, lx_mailbox::bufadr, F_MBX, lx_mailbox::fbyte, FIFO, fifo, lx_mailbox::frbs, lx_mailbox::lbyte, rt_fifo_struct::malloc_type, rt_fifo_struct::mbx, mbx_get(), mbx_sem_signal(), mbx_sem_wait(), mbx_sem_wait_if(), mbx_signal(), lx_mailbox::rcvsem, lx_mailbox::size, lx_mailbox::sndsem, TRACE_RTAI_FIFO, VALID_FIFO, and lx_mailbox::waiting_task. Referenced by rtf_create(), and rtf_ioctl(). Here is the call graph for this function: ![]() |
|
Activate asynchronous notification of data availability rtf_set_async_sig activate an asynchronous signals to notify data availability by catching a user set signal signum.
References errno, and SET_ASYNC_SIG. |
|
Suspend a process for some time rtf_suspend_timed suspends a Linux process according to delay.
References errno, and RTF_SUSPEND_TIMED. |
|
Write data to FIFO in user space, with timeout. rtf_write_timed writes a block of data to a real-time fifo identified by the file descriptor fd waiting at most @æ delay milliseconds to complete the operation.
References count, errno, and WRITE_TIMED. |