February 1, 2012 Jack Ganssle The RTOS The kernel the multitasker The kernel handles tasking It also has resources to pass data between tasks safely, and to synchronize tasking. An RTOS also has resources like communications, a GUI, a file system, and debugging tools. Polled Loop Wait for something Do something Polled Loop With Interrupts Wait for something Do something Wait for interrupt signal Handle Interrupt Interrupt event Signal main loop Enter the RTOS Handle Interrupt Interrupt event Signal RTOS Handle screen Handle TCP/IP Process data Kernel When Do You Need an RTOS? Multiple independent activities Communications File system GUIs An Infusion Pump What About Linux? Memory needs Real-time response Reliability, validation and security Licensing issues Porting Linux is hard! Multitasking and Tasks void App_TaskADC (void *p_arg) { while (1) { ADC_Read(); OSTimeDly(10); } }
Multitasking and Tasks void App_TaskLowFluid (void *p_arg) {
TCBs and Stacks Stack pointer Registers Other task data Rest of stack Task Priority Task state Task Control Block Stack Task States Scheduling Preemption The suspension of one task and start of another Context switching The process of switching from one task to another Round robin The giving of equal time to all same-priority tasks Round-Robin Scheduling Priorities Scheduling Points When a task decides to wait for time to expire When a task sends a message or a signal to another task When an ISR sends a message or a signal to a task When a kernel object is deleted When the priority of a task is changed Other places
I/O Perils Task 1 Task 2 Hi There Howdy Terminal HHio wTdhyere The Mutex Acquire_mutex; Access_device; Release_mutex; Semaphores AtoD_Read (uint16 *result) { start ADC conversion wait for semaphore Read A/D return result }
Message Queues Rx ISR Serial Stream Rx Task Message queue Roll Your Own? Consider the cost of buying vs. cost to write Cost to validate Messaging and synchronization Modularity Rate Monotonic Scheduling If tasks are periodic, and do not share resources or sync with each other, then RMA says: if: E 1 /T 1 + E 2 /T 2 + E 3 /T 3 <= n(2 1/n - 1)
all hard real time deadlines will be met. n Time 1 1.000 2 0.828 3 0.780 4 0.757 5 0.743 10000 0.693 // Task A if angle> 90 swap modes void a (void){ int raw; float angle; float scale=2*pi;