rtos training
TRANSCRIPT
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 1/34
Real Time Operating Systems
Michael Thomas
Date:
Rev. 1.00Date
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 2/34
2
Objective
Ienti!y embee programming moels
"nerstan basic RTOS e!initions an concepts#oints to consier $hen yo% &'%y or roll yo%r o$n(
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 3/34
)
De!ining application re*%irements
Real time: +omp%ting $ith a ealine , re*%ire level o! service has to be provie in a bo%ne response
time
+onse*%ence o! missing ealines: &-arness( o! theproblemapplication-ar real/time / absol%te ealines m%st be met
irm real/time / lo$ occ%rrence o! missing a ealine can be tolerate
So!t real/time / tolerance in the orer o! h%man reaction time 0ms3
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 4/34
4
'asic concepts an e!initions
Tas5: Sel! containe coe that hanles a sing%lar!%nctionality or semi/inepenent portion o! theapplication that hanles a speci!ic %ty.
Threas: ,ccess to entire memory space
#rocesses: Memory access area limite base on process
creation parameters
#riority
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 5/34
'asic concepts an e!initions
Real-time Scheduling
Hard
Preemptive
Dynamic Static
Preemptive Non-preemptiveNon-preemptive
Soft
Sche%ler Implements the sche%ling policy
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 6/34
6
'asic concepts an e!initions
Determinism
78act time ta5en !or each threa to e8ec%te is a constant
9ernel
Sche%ler Memory management I#+ Synchroni;ation3
primitives
9ernel latency micro5ernel< pico5ernel etc3
9ernel space
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 7/34=
Other In!o
Tas5 ID
#riority
Tas5 Stat%s
Register +ontents
#rogram +o%nter
+onte8t
Typical T+'
+onte8t s$itch time
c%rrent +#" tas5
Save conte8t to T+'1 Save conte8t to T+'2
>oa conte8t from T+'2 >oa conte8t from T+'1
+onte8t S$itch an Tas5 +ontrol 'loc5
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 8/34?
-?S Stac5 !rames %ring a conte8t s$itch
task1 task2
task1 ready
task1 running
task2 ready
Contet S!itchtask2 running
"#C$"
%$R&$'"(S
"#C$"
%$R&$'"(S
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 9/34@
+loc5 Interr%pts occ%r every A10 ms allo$ OS to r%n3OS chec5s to see i! any higher priority process availablein reay *%e%eI! so< s%spen c%rrent process an s$itch to ne$ process
#reemption
# r i o r i t y R)#S Contet-S!itch service
&SR
Time
+onte8t S$itch
task 2
task 1
R*NN&N+
,$&)&N+
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 10/3410
7mbee programming moels
System esigne aro%n tas5 sche%ling policy
7nless loop
Simple cyclic e8ec%tive
Time riven cyclic
M%lti/rate cyclic
M%lti/rate cyclic !or perioic tas5s
M%lti/rate cyclic $ith interr%pts bg!g programming3
#riority base pre/emptive
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 11/3411
Tas51
Tas52
Tas5
Tas54
Tas5)
Simple cyclic
Tas51
Tas52
Tas5
Tas54
Tas5)
Timer Interr%pt
)ime driven cyclic
Timer Interr%pt
Tas51
Tas51
Tas51
Tas52
Tas5)
ulti-rate cyclic
Tas51
Tas51
Tas51
Tas52
Tas5)
Timer Interr%pt
ulti-r ate cyclic for periodic
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 12/3412
Bhere oes an RTOS !it inC
Tas5 management vie$point:
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 13/341)
RTOS Services
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 14/3414
Tas5 Management Sche%ling
Tas5 is consiere as a sche%ling %nit $hichimplements a !%nction
OS services that collectively move tas5s !rom one stateto another
#rovie conte8t s$itching services
Tas5 parameters li5e ealine< perio< priority etc nee tobe speci!ie
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 15/341
Tas5 Management
Tas5 states in a typical RTOS:
Dormant
BaitingReay
R%nning
Interr%pte
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 16/3416
Tas5 Management
State transitions o! a tas5 in a typical RTOS
Baiting !or
reso%rcesReso%rces
availableInterr%pt
ISR one
Tas5 res%me
Tas5 preempte
tas5
elete
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 17/341=
Sche%ler an Sche%ling #olicy
Sche%ling algorithms generate a !easible e8ec%tionse*%ence base on
tas5 priority
tas5 ealines
reso%rce re*%irements
Ro%n Robin
7arliest ealine irst 7D3
Ma8im%m "rgency irst M"3
#riority +eiling #rotocol Reso%rce base3
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 18/341?
Interr%pt -anling
RTOS Inepenent Interr%ptsISR preempts the RTOS an r%ns
"se !or events that re*%ire acc%rate timing
E RTOS Depenant Interr%pts:
ISR is r%n !ithin the RTOS
E RTOS sho%l allo$ lo$er level ISR to be pre/empte byhigher level ISR RTOS Depenant Interr%pts3
E ISR m%st complete as *%ic5ly as possible.
E 'oth Depenant an Inepenent ISRs can e8ist in onesystem
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 19/341@
+loc5s an Timers
Tic5 timer Decies gran%larity o! system.
System response time limite by tic5 timer
7g: 0 microsec motor control interr%pt cannot be hanle by a 1 millisec
tic5 timer OS.
Timer primitives
,llo$ %ser to speci!y &R%n tas5 every 8 %nit o! time( %ring tas5
creation. eg: scan 5eyboar
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 20/3420
Synchroni;ation
Synchroni;ation primitive %se to provie:M%t%al e8cl%sion: +ritical sections not accesse sim%ltaneo%sly
+onitional synchroni;ation: 7ns%re tas5s r%n in a speci!ic orer
E Synchroni;ation constr%cts:
M%te8 'inary semaphore3
Semaphore +o%nting semaphore3
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 21/3421
Synchroni;ation an Semaphores
T$o tas5s an single b%!!er
#ro%cer tas5 an cons%mer tas5
+ons%mer tas5 to $ait till pro%cer tas5 is one $ith b%!!er.
Synchroni;ation an ata integrity achieve by %sing a
semaphore to loc5 access to b%!!er.
Iss%es:
Dealoc5s
#riority Inversion: >o$ priority threa obtains a loc5 that bloc5s a
higher priority threa
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 22/3422
#riority Inversion
Tas5s > - both nee access to reso%rce F
Tas5 > has loc5e this reso%rce an hence elays -.
Tas5 M preempts > ca%sing !%rther elay to -G this is priority inversion
Reay to r%n
R%nning
time
preemption
#reemption a!ter
reso%rce . release
High priority task H
"o! priority task "
edium priority task
.
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 23/342)
Inter Tas5 +omm%nication
#rimary re*%irementscharacteristics:Hon/bloc5ing comm%nication
'o%ne latency
,synchrono%s comm%nication
Share Memory
Mailbo8Message %e%es
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 24/3424
Mailbo8Message %e%e
)ask 1
)ask /
)ask 2
Mailbo8 1
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 25/34
2
Memory Management
Memory Management "nit MM"3-anles Jirt%al memory operations.
Memory protection esp. in process base OS
Dynamic memory allocation
-eapG non/!ragmenting memory allocation techni*%es&#ool( allocation mechanism
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 26/34
26
Dynamic Memory allocation: RTOS heap
/1 02 12 2 11 'uffer si3e
4ree 5uffer list
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 27/34
2=
RTOS classi!ication base on architect%re
So!t< irm an -ar real/time
#re/emptive< Hon pre/emptive
Threa base< #rocess base
Sche%ling policy: RM< 7D< RR< M" etc
Dynamic< Static
+ost str%ct%re
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 28/34
2?
RTOS a$are eb%gging
Stanar so%rce level eb%gging not s%!!icient inm%ltithreaem%ltitas5ing environment.
#otential b%gs:Data corr%ption %e to improper synchroni;ation
Dealoc5Starvation
Stac5 Over!lo$
Memory lea5s
RTOS/a$are eb%ggers provie tools that help etects%ch conitions !or *%ic5er eb%gging.78tra $ino$s sho$ing state o! all tas5s r%nning< $aiting etc3< incl%ing
b%!!ers c%rrently %se by each tas5< semaphores %se etc.
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 29/34
2@
'%y vs Roll yo%r O$n
actors:+ost Str%ct%re.
S%pport an oc%mentation
Scalability
#ortability
Deb%gging tools
Testing
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 30/34
)0
'%y vs Roll yo%r O$n
+ost Str%ct%re.Royalty per pro%ct one time payment
Overall evelopment< eb%gging< testing an s%pport reso%rces
!or in/ho%se tool %s%ally !ar o%t$eigh investing in a commercial
RTOS
S%pport an oc%mentation
Ins%!!icient oc%mentation
Small team responsible !or RD an maintenance
+ommercial RTOSes are $ell oc%mente $ith goo s%pport
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 31/34
)1
'%y vs Roll yo%r O$n
ScalabilityIn/ho%se tools are %s%ally esigne to meet e8act speci!ications
so it might be a goo !it
+ommercial venors allo$ signi!icant c%stomi;ation o! the 5ernel
in some cases a K"I !or this p%rpose3< so the notion o! too m%ch
overhea coe is %n!o%neSome commercial venors also provie so%rce coe to allay
engineer !ears o! &I cant see the coe so I onLt 5no$ $hatLs
going on(
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 32/34
)2
'%y vs Roll yo%r O$n
#ortability#orting an in/ho%se sol%tion to i!!erent har$are $ill re*%ire
signi!icant re/investment o! time an reso%rces
+ommercial venors have ports !or all major har$are targets
an $ill %s%ally port to others as $ell
Deb%gging tools
Deb%gging tools have to be evelopeporte !or in ho%se
RTOSG %s%ally ta5es 48 time neee to evelop the RTOS
+ommercial venors have reaily available eb%ggers an $ill
port over esire !eat%res in most cases
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 33/34
))
'%y vs Roll yo%r O$n
TestingIn/ho%se testingG ta5es 108 evelopment time to properly test
RTOS
+ommercial RTOSes are s%!!iciently teste an have also been
%se by many c%stomers so most b%gs $ill have been irone
o%t.
7/23/2019 RTOS Training
http://slidepdf.com/reader/full/rtos-training 34/34
Objectives: Recap
Ienti!y embee programming moels
"nerstan basic RTOS e!initions an concepts
#oints to consier $hen yo% &'%y or roll yo%r o$n(