rtos tutorial
Post on 04-Jun-2018
277 Views
Preview:
TRANSCRIPT
-
8/13/2019 RTOS Tutorial
1/22
Real-Time Operating Systems
Suzanne Rivoire
November 20, 2002
http://www.stanford.edu/~skrufi/rtospres.ppt
-
8/13/2019 RTOS Tutorial
2/22
Motivating Example
void main() {
do forever{
check keypad;measure temperature;
control oven power;
decrement timer;
update display;wait for clock tick;
}
}
-
8/13/2019 RTOS Tutorial
3/22
Motivating Example - 2
void main() {
do forever{
check keypad;measure temperature;
check keypad;
control oven;
check keypad;}
}
-
8/13/2019 RTOS Tutorial
4/22
-
8/13/2019 RTOS Tutorial
5/22
What isreal-time?
Correctness of output depends on timing as
well as result
Hard vs. soft real-time
Are Windows and Linux real-time?
-
8/13/2019 RTOS Tutorial
6/22
In a Hard RTOS
Thread priorities can be set by the client
Threads always run according to priority
Kernel must be preemptible or bounded
Interrupts must be bounded
No virtual memory
-
8/13/2019 RTOS Tutorial
7/22
In a Soft RTOS
Like a hard RTOS: Priority scheduling, with no degradation
Low dispatch latency Preemptible system calls
No virtual memory (or allow pages to be locked)
Linux: guarantees about relative timing of
tasks, no guarantees about syscalls
-
8/13/2019 RTOS Tutorial
8/22
Basic RTOS References
http://www.dedicated-
systems.com/encyc/publications/faq/rtfaq.htm
http://www.steroidmicros.com/mtkernel.html
http://www.qnx.com/developer/articles/dec1200b/
Silberschatz and Galvin, Operating System
Concepts.
-
8/13/2019 RTOS Tutorial
9/22
Example RTOSs
Micrium c-OS II
http://www.ucos-ii.com/
AvrXhttp://www.barello.net/avrx/
RTLinuxhttp://fsmlabs.com/developers/man_pages/
QNX Neutrino
http://www.qnx.com/
-
8/13/2019 RTOS Tutorial
10/22
c-OS II
Features
Sample main()function
Calling OSTaskCreate()
Creating a task
-
8/13/2019 RTOS Tutorial
11/22
C-OS II
Ports to the AVR, ATmega103
Comes with book:Micro-C OS: The Real-Time
Kernelby Jean Labrosse ($52)
Features
Semaphores and mutexes
Event flags
Message mailboxes and queues
Task management (priority settings)
-
8/13/2019 RTOS Tutorial
12/22
void main (void) {
/* Perform Initializations */
...OSInit();
...
/* Create at least one task by
calling OSTaskCreate() */
OSStart();
}
C-OS Sample Code
-
8/13/2019 RTOS Tutorial
13/22
INT8U OSTaskCreate (
void (*task)(void *pd),
void *pdata,
OS_STK *ptos,INT8U prio);
C-OS Sample Code
-
8/13/2019 RTOS Tutorial
14/22
void UserTask (void *pdata) {
pdata = pdata;
/* User task initialization */
while (1) {/* User code goes here */
/* You MUST invoke a serviceprovided by C/OS-II to: */
/* ... a) Delay the task for nticks */
/* ... b) Wait on a semaphore */
/* ... c) Wait for a message from atask or an ISR */
/* ... d) Suspend execution of this
C-OS Sample Code
-
8/13/2019 RTOS Tutorial
15/22
AvrX
Specs
Internal structures
Sample code: task creation
-
8/13/2019 RTOS Tutorial
16/22
AvrX Specs
Code size: 500-700 words (2x bigger with
debug monitor)
16 priority levels
Overhead: 20% of CPU
Version 2.3 for assembly code, 2.6 for C
interface
-
8/13/2019 RTOS Tutorial
17/22
AvrX Internals
Routine _Prologsaves state, _Epilog
restores it
Task info stored in a PID block and a task
control block
Modules for timers, semaphores, etc.
-
8/13/2019 RTOS Tutorial
18/22
An AvrX Task
AVRX_TASKDEF(myTask, 10, 3){TimerControlBlock MyTimer;while (1){
AvrXDelay(&MyTimer, 10);// 10ms delay
AvrXSetSemaphore(&Timeout)
;}}
Arguments: task name, additional stack bytes, priority
-
8/13/2019 RTOS Tutorial
19/22
RTLinux
Additional layer between Linux kernel and
hardware
Worst-case dispatch latency on x86: 15 s
-
8/13/2019 RTOS Tutorial
20/22
RTLinux: Basic Idea
-
8/13/2019 RTOS Tutorial
21/22
QNX Neutrino
Powerful hard RTOS
Includes GUI
Memory protection and fault tolerance
-
8/13/2019 RTOS Tutorial
22/22
Summary
Hard real-time, soft real-time
Characteristics of an RTOS
Example RTOSs
Specs
Internal structure/ideas
Sample code
top related