Thursday, October 23, 2008

Controlling the devices in Hard Real Time through PC's Parallel port

Parallel port is the most commonly used port for interfacing the devices such as printers, scanners and modems. Parallel port has easy implementation and has fast data transmission. Nowadays most machines come with advanced modes like ECP and EPP along with SPP. Here you can get clear idea about Parallel ports and their modes.
Devices, which are connected through the parallel port can be monitored by a kernel module in hard Real-time. When devices make interrupts according to their status,we can serve them in Real
time.

Time Scheduling
To get hard Real time performance in Linux the RTAI flavor can be used. When connecting multiple devices through a single port, there a need arises, to schedule those tasks. For this, real time kernels have timing algorithms,which can be used to schedule multiple tasks.

Interrupt Service Routine(ISR)
It is simply a function that takes no arguments & returns no value, and mediates the interaction of a hardware device with the real time application. Most Parallel ports use irq 7 which we can find from BIOS setup.
Communication
When the real time task needs to inform the user process that an event has taken place, it puts a message into a real time FIFO. Each FIFO can transfer data in one direction;either from the real time task to a user process or the reverse. Thus we need to use two FIFOs for duplex communications. From the application side, the FIFO behaves like a regular file.
From Linux user space, device nodes must be created for the FIFOs before making use of the
RT-FIFO driver. This needs to be done only once.

RTAI Modules
To run any application four RTAI key modules are needed. These modules should be
loaded before running any program.
  • insmod rtai_hal.o
  • insmod rtai_ksched.o
  • insmod rtai_fifos.o
  • insmod rtai_sem.o
Note:However, when we connect devices with parallel port we need to take much care about the connections. For easiness, there is an application(parapin) available to set pins and their modes, from user application.

Real Time versions in Linux

Standard Linux can be used for Soft Real-time applications where the sample time is relatively long,say tens of milliseconds which missed timing schedules the application could tolerate.
Hard Real-time applications require rigid determinism and fast timing. Real-time variants of Linux are suitable for such applications. Real-time versions of Linux offer important advantages to control Engineers in providing an open source operating system that rivals the performance of the proprietary Real-time kernels.
Linux offers two flavors to implement Real-time tasks,
  • RealTime Linux(RTLinux)
  • RealTime Application Interface(RTAI)
To implement Hard Real-time tasks, not like standard Linux kernel, here we need special methods to handle interrupts and timing performance. I feel RTAI is easier to install and configure than RTLinux. You could find the better and the easiest guide to install and configure the RTAI with the standard Linux kernel here.