RTAI API 5.1
|
RTAI FIFO communication functions. More...
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) |
Suspend a process for some time. More... | |
int | rtf_open_sized (const char *dev, int perm, int size) |
Create a real-time FIFO. More... | |
int | rtf_read_all_at_once (int fd, void *buf, int count) |
Read data from FIFO in user space, waiting for all of them. More... | |
int | rtf_read_timed (int fd, void *buf, int count, int ms_delay) |
Read data from FIFO in user space, with timeout. More... | |
int | rtf_write_timed (int fd, void *buf, int count, int ms_delay) |
Write data to FIFO in user space, with timeout. More... | |
int | rtf_set_async_sig (int fd, int signum) |
Activate asynchronous notification of data availability. More... | |
RTAI_SYSCALL_MODE int | rtf_reset (unsigned int minor) |
Reset a real-time FIFO. More... | |
RTAI_SYSCALL_MODE int | rtf_resize (unsigned int minor, int size) |
Resize a real-time FIFO. More... | |
RTAI_SYSCALL_MODE int | rtf_create (unsigned int minor, int size) |
Create a real-time FIFO. More... | |
RTAI_SYSCALL_MODE int | rtf_destroy (unsigned int minor) |
Close a real-time FIFO. More... | |
int | rtf_create_handler (unsigned int minor, void *handler) |
Install a FIFO handler function. More... | |
RTAI_SYSCALL_MODE int | rtf_put (unsigned int minor, void *buf, int count) |
Write data to FIFO. More... | |
RTAI_SYSCALL_MODE int | rtf_get (unsigned int minor, void *buf, int count) |
Read data from FIFO. More... | |
RTAI FIFO communication functions.
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>
where <x> is the minor device number, from 0 to 63; thus on the Linux side RTL fifos can be used as standard character devices. As it was said above to use standard IO operations on such devices there is no need to explain anything, go directly to Linux man pages. RTAI fifos specific services available in kernel and user space are instead explained here.
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,...)
to the integer xx
you will use in kernel space.
It is far better and flexible, and if you really like it the fifos way mailboxes are a one to one, more effective, substitute. After all RTAI fifos are implemented on top of them.
RTAI_SYSCALL_MODE int rtf_create | ( | unsigned int | minor, |
int | size | ||
) |
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.
minor | is a positive integer that identifies the fifo on further operations. It has to be less than RTF_NO. |
size | is the requested size for the fifo. |
fifo may refer to an existing RT-FIFO. In this case the size is adjusted if necessary.
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.
0 | on success |
ENODEV | if fifo is greater than or equal to RTF_NO |
ENOMEM | if the necessary size could not be allocated for the RT-FIFO. |
References rtf_resize().
int rtf_create_handler | ( | unsigned int | minor, |
void * | handler | ||
) |
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.
minor | is an RT-FIFO that must have previously been created with a call to rtf_create(). |
handler | is a pointer on a function wich will be called whenever a Linux process accesses that fifo. |
rtf_create_handler is often used in conjunction with rtf_get() to process data acquired asynchronously from a Linux process. The installed handler calls rtf_get() when data is present. Because the handler is only executed when there is activity on the fifo, polling is not necessary.
0 | on success. |
EINVAL | if fifo is greater than or equal to RTF_NO, or handler is NULL . |
RTAI_SYSCALL_MODE int rtf_destroy | ( | unsigned int | minor | ) |
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.
ENODEV | if fifo is greater than or equal to RTF_NO. |
EINVAL | if fifo refers to a not opened fifo. |
RTAI_SYSCALL_MODE int rtf_get | ( | unsigned int | minor, |
void * | buf, | ||
int | count | ||
) |
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().
minor | is the ID with which the RT-FIFO was created. |
buf | points a buffer provided by the caller. |
count | is the size of buf in bytes. |
This mechanism is available only to real-time tasks; Linux processes use a read from the corresponding fifo device to dequeue data from a fifo. Similarly, Linux processes use write or similar functions to write the data to be read via rtf_put() by a real-time task.
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.
ENODEV | if fifo is greater than or equal to RTF_NO. |
EINVAL | if fifo refers to a not opened fifo. |
int rtf_open_sized | ( | const char * | dev, |
int | perm, | ||
int | size | ||
) |
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.
size | is the requested size for the fifo. |
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.
-ENOMEM | if the necessary size could not be allocated for the RT-FIFO. |
RTAI_SYSCALL_MODE int rtf_put | ( | unsigned int | minor, |
void * | buf, | ||
int | count | ||
) |
Write data to FIFO.
rtf_put tries to write a block of data to a real-time fifo previously created with rtf_create().
minor | is the ID with which the RT-FIFO was created. |
buf | points the block of data to be written. |
count | is the size of the block in bytes. |
This mechanism is available only in kernel space, i.e. either in real-time tasks or handlers; Linux processes use a write to the corresponding /dev/fifo<n> device to enqueue data to a fifo. Similarly, Linux processes use read or similar functions to read the data previously written via rtf_put by a real-time task.
ENODEV | if fifo is greater than or equal to RTF_NO. |
EINVAL | if fifo refers to a not opened fifo. |
int rtf_read_all_at_once | ( | int | fd, |
void * | buf, | ||
int | count | ||
) |
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.
fd | is the file descriptor returned at fifo open. |
buf | points the block of data to be written. |
count | is the size in bytes of the buffer. |
-EINVAL | if fd refers to a not opened fifo. |
int rtf_read_timed | ( | int | fd, |
void * | buf, | ||
int | count, | ||
int | ms_delay | ||
) |
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.
fd | is the file descriptor returned at fifo open. |
buf | points the block of data to be written. |
count | is the size of the block in bytes. |
ms_delay | is the timeout time in milliseconds. |
-EINVAL | if fd refers to a not opened fifo. |
RTAI_SYSCALL_MODE int rtf_reset | ( | unsigned int | minor | ) |
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.
minor | is a file descriptor returned by standard UNIX open in user space while it is directly the chosen fifo number in kernel space. |
0 | on succes. |
ENODEV | if fd_fifo is greater than or equal to RTF_NO. |
EINVAL | if fd_fifo refers to a not opened fifo. |
EFAULT | if the operation was unsuccessful. |
RTAI_SYSCALL_MODE int rtf_resize | ( | unsigned int | minor, |
int | size | ||
) |
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.
minor | is a file descriptor returned by standard UNIX open in user space while it is directly the chosen fifo number in kernel space. |
size | is the requested new size. |
size | on success. |
-ENODEV | if fifo is greater than or equal to RTF_NO. |
-EINVAL | if fifo refers to a not opened fifo. |
-ENOMEM | if size bytes could not be allocated for the RT-FIFO. Fifo |
-EBUSY | if size is smaller than actual content size is unchanged. |
Referenced by rtf_create().
int rtf_set_async_sig | ( | int | fd, |
int | signum | ||
) |
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.
signum | is a user chosen signal number to be used, default is SIGIO. |
-EINVAL | if fd refers to a not opened fifo. |
int rtf_suspend_timed | ( | int | fd, |
int | ms_delay | ||
) |
Suspend a process for some time.
rtf_suspend_timed suspends a Linux process according to delay.
fd | is the file descriptor returned at fifo open, rtf_suspend_timed needs a fifo support. |
ms_delay | is the timeout time in milliseconds. |
int rtf_write_timed | ( | int | fd, |
void * | buf, | ||
int | count, | ||
int | ms_delay | ||
) |
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.
fd | is the file descriptor returned at fifo open. |
buf | points the block of data to be written. |
count | is the size of the block in bytes. |
ms_delay | is the timeout time in milliseconds. |
-EINVAL | if fd refers to a not opened fifo. |