Download presentation
Presentation is loading. Please wait.
Published byHilary Hampton Modified over 6 years ago
1
Microprocesors, Advanced What You Need to Know About RTOSes
February 1, 2012 Jack Ganssle
2
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.
3
Polled Loop Wait for something Do something
4
Polled Loop With Interrupts
Interrupt event Wait for interrupt signal Wait for something Handle Interrupt Do something Signal main loop
5
Enter the RTOS Kernel Interrupt event Handle Interrupt Handle screen
Handle TCP/IP Process data Signal RTOS
6
When Do You Need an RTOS? Multiple independent activities
Communications File system GUIs
7
An Infusion Pump
8
What About Linux? Memory needs Real-time response
Reliability, validation and security Licensing issues Porting Linux is hard!
9
Multitasking and Tasks
void App_TaskADC (void *p_arg) { while (1) { ADC_Read(); OSTimeDly(10); }
10
Multitasking and Tasks
void App_TaskLowFluid (void *p_arg) { code to handle low fluid; OSTaskDel(. . .); }
11
Task Creation void main (void) { OSInit(); /* Kernel initialization */
OSTaskCreate(...); /* Task creation */ OSTaskCreate(...); OSStart(); /* Start multitasking */ }
12
TCBs and Stacks Task Control Block Stack Stack pointer Registers
Task Priority Rest of stack Task state Other task data
13
Task States
14
Scheduling Preemption Context switching Round robin
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
15
Round-Robin Scheduling
16
Priorities
17
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
18
I/O Perils Task 1 “Hi There” Terminal “HHio wTdhyere” Task 2 “Howdy”
19
The Mutex Acquire_mutex; Access_device; Release_mutex;
20
Semaphores AtoD_Read (uint16 *result) { start ADC conversion
wait for semaphore Read A/D return result } ADC_ISR (void) { release semaphore clear interrupt }
21
Message Queues Rx ISR Message queue Serial Stream Rx Task
22
Roll Your Own? Consider the cost of buying vs. cost to write
Cost to validate Messaging and synchronization Modularity
23
Rate Monotonic Scheduling
(e=execution time, T= execution period) How will you know Ei? Compilers don’t help. Predict and measure. Schedule – highest rate task gets highest priority. May conflict with real time issues If tasks are periodic, and do not share resources or sync with each other, then RMA says: if: E1/T1 + E2/T2 + E3/T3 … <= n(2 1/n - 1) all hard real time deadlines will be met. 23
24
// Task A – if angle> 90 swap modes void a (void){ int raw;
float angle; float scale=2*pi; raw=inport(encoder); angle=(float)raw * scale; if(angle>90)swap_mode; } So here’s an example task. FP FP conversions What’s the execution time? Get a listing, right? 24
25
0013E7 FF 76 FC PUSH WORD PTR [BP-4] 0013EA 9A 00 00 CALL dicvt
Just PART of what was generated Betcha still can’t tell But that’s float; what re ints? 0013DA 9A CALL ddload 0013DF 83 C ADD SP,4 0013E2 9A CALL dpush 0013E7 FF 76 FC PUSH WORD PTR [BP-4] 0013EA 9A CALL dicvt 0013EF 83 C ADD SP,2 0013F2 9A CALL dpush 0013F7 9A CALL drmul 0013FC 83 C ADD SP,16 0013FF 9A CALL dpush 25
26
k=(l1>l2); 000E8A 8B 56 CA MOV DX,[BP-54]
And this is edited for Clarity! Betcha still can’t tell CMSC Change something random and try again? k=(l1>l2); 000E8A 8B 56 CA MOV DX,[BP-54] 000E8D 8B 46 C MOV AX,[BP-56] 000E90 3B 56 D CMP DX,[BP-42] 000E93 7F JG SHORT L42 000E95 7C 0A JL SHORT L40 000E97 3B 46 D CMP AX,[BP-44] 000E9A JBE SHORT L40 000E9C B L42 MOV AX,1 000E9F EB JMP L41 000EA1 2B C0 L40 SUB AX,AX 000EA F6 L41 MOV BP-10],AX 000EA6 FF 46 FE INC [BP-2] 26
27
Talk to the vendors We’re mad as hell and we’re not gonna take it anymore!
28
Software Selection Reputation/Tech Support Reliability
CPU/Language/Tool compatibility Pricing model Source or object? Size and performance Debugging tools Services, drivers Other software components Reputation/Tech Support Reliability
29
Questions?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.