Académique Documents
Professionnel Documents
Culture Documents
TO
REAL-TIME PROGRAMMING
IN RT-LINUX
Sections
1. RT-Linux overview
2. Introduction to Real Time Program
3. RT-Linux API
– Thread Programming
– Time Measurement
– FPU
1. Inter-Processes Communication
2. Memory Access
3. Interrupt Programming
4. Sample RT- Program
5. RT-Linux Command Overview
RT-Linux Overview
RT-Linux Concepts
• RT-Task
– Don’t use virtual memory.
– Don’t execute Linux system calls.
– Privileged
– Don’t have access to FPU.
– Error can bring the system down.
Linux Kernel Architecture
Priorities Task
•
Scheduling based purely on priority
•
Runs Linux processes as low priority task.
•
Unpredictability avoided by its simple size and limited operations
•
Introduction to Real Time Program
Real Time Program concepts
• Thread programming
• Time Facilities
int pthread_create(pthread_t *
thread,pthread_attr_t * attr,
void *(*start_routine)(void *),void * arg);
• int pthread_suspend_np(void);
– Suspends the thread.
– Should be called from within the thread.
Mutual Exclusion
• POSIX semaphores.
API Calls for RT-Linux Thread programming
• CLOCK MONOTONIC:
– This POSIX clock runs at a steady rate, and is
never adjusted or reset.
• CLOCK REALTIME:
– This is the standard POSIX RT clock. Currently,it is the same as CLOCK
MONOTONIC. It is planned that in future versions of RTLinux this clock will give
the world time.
• CLOCK RTL SCHED:
– The clock that the scheduler uses for task scheduling.
API Calls for Time Measurement in RT-Linux
• Communication Methods:
– Real Time FIFO.
– Shared Memory.
Real-Time FIFO
Accessing RT-FIFO:
• Hard Interrupts
– Lower latency.
– Very limited set of kernel functions may be called
from the hard interrupt handlers.
• Soft Interrupts.
– Normal Linux kernel interrupts.
– Can call some Linux kernel functions.
– Do not provide hard real time performance.
Hard Interrupts
pthread_t thread;
void * start_routine(void *arg);
int init_module(void)
{
return pthread_create (&thread, NULL, start_routine, 0);
}
void cleanup_module(void)
{
pthread_cancel (thread);
pthread_join (thread, NULL);
}
Code (continues..,)
void * start_routine(void *arg)
{
struct sched_param p;
p . sched_priority = 1;
pthread_setschedparam (pthread_self(), SCHED_FIFO, &p);
pthread_make_periodic_np (pthread_self(), gethrtime(),
500000000);
while (1)
{
pthread_wait_np();
rtl_printf("I’m here; my arg is %x\n", (unsigned) arg);
}
return 0;
}
Essential RT-Linux Commands Overview
RT-Linux Commands
• rtlinux start
– To insert rtlinux only
• rtlinux start mymodule
– To insert rtlinux and mymodule.o module
• rtlinux stop
– To remove rtlinux module only
• rtlinux stop mymodule
– To remove rtlinux and mymodule.o module.
• rtlinux status
– To check status of rtlinux only
• rtlinux status mymodule
– To check status of rtlinux and mymodule
RT-Linux Commands
• insmod mymodule.o
– To insert the module mymodule.o
• modprobe mymodule.o
– To insert the module mymodule.o
– Inserts module intelligently
• rtl-config
--modules
--module_dir
--docs
--linux
--prefix
--arch
--version
--rtlversion
--linuxversion
--cc
RT-Linux Commands