circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

November 1998, Issue 100

Embedded RT-Linux (Part 1):
General Introduction


INSTALLING LINUX

Obtaining Linux is easy. As I said, you can get most Linux distributions from the ’Net for free. All you need is patience while downloading it. You can also purchase a CD-ROM of various distributions. Most commonly available distributions have enough of the basic components necessary to allow you to embed Linux.

Once you have an installation, you should build a desktop system to serve as your development platform. This process is relatively painless and there are a lot of resources on the ’Net. If your target system is capable enough to serve as a development environment, you can install it ther

RT EXTENSION OF LINUX

The standard Linux kernel doesn’t pretend to be real time in the traditional way. Like many Unix kernels, the kernel is not preemptive and thus can’t be relied on for predictable interrupt response. But, some clever people developed a real-time extender for Linux that turns it into RT-Linux.

RT-Linux has a layer added between the Linux kernel and the hardware timer interface. After installing the RT extension, the Linux kernel and its processes turn into a single real-time task that always runs at the lowest priority.

Real-time applications are loaded into the kernel memory space using the Linux module facility. Once the application has loaded and started real-time tasks, the tasks have control of all the hardware and memory in the system. RT-Linux provides calls to start, suspend, and destroy tasks. There’s also a timer facility to set up timers with real-time responses.

A FIFO is used for real-time tasks to communicate with regular user processes. The FIFOs appear as standard Unix character devices that a user process opens and then reads and writes to. Table 2 shows the basic API available in the RT extender.

Table 2—The real-time extension to Linux (RT-Linux) provides this API for programs that are written to run in this mode. Most of the services are pretty standard interfaces you’d see in a bigger RTOS. But, the FIFO interface can be used to communicate with non-real-time threads.
rtf_create(unsigned int fifo, int size) create a FIFO
rtf_destroy(unsigned int fifo) get rid of the FIFO
rtf_resize(unsigned int minor, int size) change the size of the FIFO
rt_fifo_put(unsigned int fifo, char * buf, int count) write to FIFO
rt_fifo_get(unsigned int fifo, char * buf, int count) read from FIFO
rtf_create_handler(unsigned int fifo, int (*handler)(unsigned int fifo)) create a handler that is called when a user process reads or writes to a FIFO device
rt_task_init(RT_TASK *task, void (*fn)
(int data), int data, int stack_size, int priority);
create a task
rt_task_make_periodic(RT_TASK *task, RTIME start_time, RTIME period); (int data), int data, int stack_size, int priority);
rt_task_delete(RT_TASK *task); arrange so that the task is called at a periodic interrupt
rt_task_wait(void); get rid of task
rt_task_suspend(RT_TASK *task); give up time slice, wait until next time slice suspend any task
rt_get_time(void); read the current time
rt_request_timer(void (*fn)(void)); allocate a timer, which will call a handler when it expires
rt_free_timer(void); return timer
rt_set_timer(RTIME time); set the timer to go off at a specific time
rt_no_timer(void); clear timer

Although, RT-Linux is rather primitive in its implementation, it has the essentials you need to implement real-time applications.