microprocesors, advanced w hat you need to know about rtoses february 1, 2012 jack ganssle
TRANSCRIPT
![Page 1: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/1.jpg)
Microprocesors, AdvancedWhat You Need to Know About RTOSes
February 1, 2012Jack Ganssle
![Page 2: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/2.jpg)
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.
![Page 3: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/3.jpg)
Polled Loop
Wait for something
Do something
![Page 4: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/4.jpg)
Polled Loop With Interrupts
Wait for something
Do something
Wait for interruptsignal
Handle Interrupt
Interrupt event
Signal main loop
![Page 5: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/5.jpg)
Enter the RTOS
Handle Interrupt
Interrupt event
Signal RTOS
Handle screen Handle TCP/IP Process data
Kernel
![Page 6: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/6.jpg)
When Do You Need an RTOS?
• Multiple independent activities• Communications• File system• GUIs
![Page 7: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/7.jpg)
An Infusion Pump
![Page 8: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/8.jpg)
What About Linux?
• Memory needs• Real-time response• Reliability, validation and security• Licensing issues• Porting Linux is hard!
![Page 9: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/9.jpg)
Multitasking and Tasks
void App_TaskADC (void *p_arg){ while (1) { ADC_Read(); OSTimeDly(10); }}
![Page 10: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/10.jpg)
Multitasking and Tasks
void App_TaskLowFluid (void *p_arg){ code to handle low fluid; OSTaskDel(. . .);}
![Page 11: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/11.jpg)
Task Creation
void main (void){ OSInit(); /* Kernel initialization */
OSTaskCreate(...); /* Task creation */ OSTaskCreate(...);
OSStart(); /* Start multitasking */}
![Page 12: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/12.jpg)
TCBs and Stacks
Stack pointer Registers
Other task data
Rest of stackTask Priority
Task state
Task Control Block Stack
![Page 13: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/13.jpg)
Task States
![Page 14: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/14.jpg)
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
![Page 15: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/15.jpg)
Round-Robin Scheduling
![Page 16: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/16.jpg)
Priorities
![Page 17: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/17.jpg)
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
![Page 18: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/18.jpg)
I/O Perils
Task 1
Task 2
“Hi There”
“Howdy”
Terminal
“HHio wTdhyere”
![Page 19: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/19.jpg)
The Mutex
Acquire_mutex;Access_device;Release_mutex;
![Page 20: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/20.jpg)
Semaphores
AtoD_Read (uint16 *result){
start ADC conversionwait for semaphoreRead A/Dreturn result
}
ADC_ISR (void){ release semaphore
clear interrupt}
![Page 21: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/21.jpg)
Message Queues
Rx ISR
Serial Stream
Rx Task
Message queue
![Page 22: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/22.jpg)
Roll Your Own?
• Consider the cost of buying vs. cost to write• Cost to validate• Messaging and synchronization• Modularity
![Page 23: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/23.jpg)
Rate Monotonic Scheduling
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.
n Time
1 1.0002 0.8283 0.7804 0.7575 0.743
10000 0.693
![Page 24: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/24.jpg)
// Task A – if angle> 90 swap modesvoid a (void){ int raw; float angle; float scale=2*pi; raw=inport(encoder); angle=(float)raw * scale; if(angle>90)swap_mode;}
![Page 25: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/25.jpg)
0013DA 9A 00 00 CALL ddload0013DF 83 C4 04 ADD SP,40013E2 9A 00 00 CALL dpush0013E7 FF 76 FC PUSH WORD PTR [BP-4]0013EA 9A 00 00 CALL dicvt0013EF 83 C4 02 ADD SP,20013F2 9A 00 00 CALL dpush0013F7 9A 00 00 CALL drmul0013FC 83 C4 10 ADD SP,160013FF 9A 00 00 CALL dpush
![Page 26: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/26.jpg)
k=(l1>l2);
000E8A 8B 56 CA MOV DX,[BP-54]000E8D 8B 46 C8 MOV AX,[BP-56]000E90 3B 56 D6 CMP DX,[BP-42]000E93 7F 07 JG SHORT L42000E95 7C 0A JL SHORT L40000E97 3B 46 D4 CMP AX,[BP-44]000E9A 76 05 JBE SHORT L40000E9C B8 01 00 L42 MOV AX,1000E9F EB 02 JMP L41 000EA1 2B C0 L40 SUB AX,AX000EA3 89 46 F6 L41 MOV BP-10],AX000EA6 FF 46 FE INC [BP-2]
![Page 27: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/27.jpg)
Talk to the vendors
We’re mad as hell and we’re not gonna take it anymore!
![Page 28: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/28.jpg)
Software Selection
• CPU/Language/Tool compatibility• Pricing model• Source or object?• Size and performance• Debugging tools• Services, drivers• Other software components
• Reputation/Tech Support• Reliability
![Page 29: Microprocesors, Advanced W hat You Need to Know About RTOSes February 1, 2012 Jack Ganssle](https://reader036.vdocuments.us/reader036/viewer/2022062517/56649f1b5503460f94c30054/html5/thumbnails/29.jpg)
Questions?