Real-Time Applications with RTLinux

RTLinux gives you a hard real-time, low-level environment when you need it--and all the power and flexibility of Linux when you don't.
Listing 2. Using the rtlinux_sigaction Function
.
.
.
#include <rtlinux_signal.h>
#define IRQ 7
void my_handler(int);
struct rtlinux_sigaction sig, oldsig;
float old_time=0.0;
float new_time=0.0;
float omega=10.0;
        /* spin speed */
int main(void)
{
     old_time = <sampleclock>;
     /* capture IRQ 7 and execute my_handler
        each time that IRQ 7 arrives: */
     sig.sa_handler = my_handler;
     sig.sa_flags = RTLINUX_SA_PERIODIC;
     rtlinux_sigaction( irq, & sig, & oldsig )
                                                      
    /* the main part of our program: we wish to
       plot information as long as the rotor is
       still spinning */
    while(omega>1.0){
        sleep(1);
        printf("Omega = %.1f\n",omega); 
              /* to stdout */
        plot(old_time,omega);
             /* via fancy plotting package*/
    }
    /* We are no longer spinning,
       let's clean up after ourselves... */
    /* free the irq: */
    sig.sa_handler = RTLINUX_SIG_IGN;
    rtlinux_sigaction( IRQ, & sig, & oldsig );
    /* exit gracefully */
    return 0;
}
void my_handler(int argument)
{
     /* calculate spin speed here */
new_time= <sampleclock>;
     omega = 1.0/(new_time - old_time);
     old_time = new_time;
}

Function

rtlinux_sigaction(), identifies the function my_handler() as the function that we wish to execute each time that IRQ 7 is triggered. Note that ``RTLINUX_SA_PERIODIC'' tells rtlinux_sigaction() to reset itself and wait for the next signal over and over again--otherwise the signal handler would be executed exactly once. Then the while() loop in our program both prints out and plots the latest spin speed. Finally, when the spin speed drops to below 1Hz, the program begins the shutdown process, which involves the deregistering my_handler() as our signal handler.

The job of my_handler() is straightforward: calculate the spin speed. The accuracy of this calculation should be quite high because each time that IRQ 7 is triggered, the handler is called as quickly as the underlying hardware allows.

Regardless of which scheme we use to implement Task 2, the most important thing to note is the amazing versatility and elegance that the RTLinux programming environment provides.

Conclusion

The design compromises that make Linux such a powerful general-purpose OS render it less than ideal for hard and even soft real-time applications. By decoupling real-time and non-real-time processes, RTLinux harnesses the best of both worlds: on the one hand, it offers a high-performance, strictly deterministic real-time application environment, while on the other, it offers the rich programming environment, large application and user base, and powerful networking power of Linux. Most importantly, all improvements made to Linux by its huge development community become instantly available to RTLinux users.

RTLinux is open-source software distributed under the GPL. Further information is available at the FSMLabs web site (http://www.fsmlabs.com/downloads.html) and the software is freely available for download from the FSMLabs ftp server (ftp://ftp.fsmlabs.com/pub/rtlinux/v3/). There are working versions for x86 (uni-processor and SMP), Alpha, PowerPC (uni-processor only), and PC-104 (via miniRTL). Both source and RPM packages are available.

______________________

White Paper
Fabric-Based Computing Enables Optimized Hyperscale Data Centers

Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.

Learn More

Sponsored by AMD

White Paper
Red Hat White Paper: Using an Open Source Framework to Catch the Bad Guy

Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6

Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.

Learn more about catching the bad guy in this free white paper.

Learn More

Sponsored by DLT Solutions