Upload
dau-den
View
213
Download
0
Embed Size (px)
Citation preview
8/18/2019 8. chibios_07KT
1/32
BKTP.HCM
2010
e
ChibiOS/RT
A Real-time OSwww.chibios.org
by Hoàng Ngọc Tuấn Anh 5!"#
an$ Nguy%n &uang 'inh 5!()!"
http://www.chibios.org/http://www.chibios.org/
8/18/2019 8. chibios_07KT
2/32
2010
e
O*er*iew
– Authur : Giovanni Di Sirio.
– ChibiOS/RT (ちびOS/RT) means small Real Time Operating System.
– Designe !or realtime appli"ations.
–
#reemptive s"heuling. – $%& priority levels. 'ultiple threas at the
same priority level are alloe.
– Roun Robin s"heuling !or threas at the
same priority level.
2Embedded system
8/18/2019 8. chibios_07KT
3/32
2010
e
O*er*iew
• An embee real time OS hi"h is: – igh portability* "ompa"t si+e* e,"ient
"onte-t sit"hing
– Stati" ar"hite"ture
–
Dynami" e-tensions* ynami" obe"t – 'any obe"ts : threas* semaphores*
mute-es
– Support many harare abstra"t rivers
– Support ar"hite"ture: AR'0* AR' Corte-1'2* Corte-1'3* A4R* 'S#532* S'T&
3Embedded system
8/18/2019 8. chibios_07KT
4/32
2010
e
O*er*iew
– #rogramming language : C
– Coe si+e ( "ompile) about 678 9 $278• 'inimal buil "an reu"e "oe si+e to about
$*678
– Conte-t sit"h time: %S 9 $2S
– ;-tensive test suite ith ben"hmar7s
4Embedded system
8/18/2019 8. chibios_07KT
5/32
2010
e
+icense,
5Embedded system
• ultile licensing otions e/ist 0or 1hibiOS2RT, – 3ure 43+ license.
• 6or unstable 7alha8 beta9: release
– 43+ license with +in;ing chibios,commercial
8/18/2019 8. chibios_07KT
6/32
2010
e
System state,
6Embedded system
8/18/2019 8. chibios_07KT
7/32
2010
e
?ernel subsystem
7Embedded system
• 4ersion numbers an
8/18/2019 8. chibios_07KT
8/32
2010
e
'ersion an$ @n$enti0ication
8Embedded system
• De=ne 7ernel relate in!o – #defne _CHIBIOS_RT_ – ChibiOS/RT ienti="ation ma"ro.
– #defne CH_KERNEL_VERSION"2.3.2unstable"
– >ernel version string. – #defne CH_KERNEL_M!OR 2
– >ernel version maor number.
– #defne CH_KERNEL_MINOR 3
– >ernel version minor number.
– #defne CH_KERNEL_TCH 2
– >ernel version pat"h number.
8/18/2019 8. chibios_07KT
9/32
2010
e
1on0iguration
9Embedded system
• De=ne 7ernel settings an hoo7s
8/18/2019 8. chibios_07KT
10/32
2010
e
Tyes
10Embedded system
• De=ne system types an ma"ros
8/18/2019 8. chibios_07KT
11/32
2010
e
ase ;ernel ser*ices
11Embedded system
8/18/2019 8. chibios_07KT
12/32
2010
e
ase ;ernel ser*ices
12Embedded system
• System anagementchSysIni 7*oi$:
chSysTi!"#H$n%&"#I 7*oi$:
'ORKI()*+R,+ 7Bi$leBthrea$Bwa8@C+
8/18/2019 8. chibios_07KT
13/32
2010
e
ase ;ernel ser*ices
13Embedded system
• Sche$uler *sch"%-&"#*ini 7*oi$:chSchR"$%yI 7Threa$ Et:
chSch)S&""Ti!"-S 7tstateBt newstate8
systimeBt time:chSch'$"-S 7Threa$ Ent8 msgBt msg:
chSchR"sch"%-&"I 7*oi$:
chSchR"sch"%-&"S 7*oi$:
chSchIsR"scR"-i#"%,I 7*oi$:
8/18/2019 8. chibios_07KT
14/32
2010
e
Threa$ state,
14Embedded system
8/18/2019 8. chibios_07KT
15/32
2010
e
ase ;ernel ser*ices
15Embedded system
• Threa$schTh%C#"$"S$ic 7*oi$ Ews8 siFeBt siFe8 trioBt
rio8 t0uncBt 08 *oi$ Earg:
chTh%S"P#i#iy 7trioBt newrio:
chTh%R"s-!" 7Threa$ Et:chTh%T"#!in$" 7Threa$ Et:
chTh%S&"" 7systimeBt time:
chTh%,i 7msgBt msg:
chTh%'$i 7Threa$ Et:
8/18/2019 8. chibios_07KT
16/32
2010
e
ase ;ernel ser*ices
16Embedded system
• Time an$ 'irtual timerschTS"I 7'irtualTimer E*t8 systimeBt time8 *t0uncBt
*t0unc8 *oi$ Ear:
chTR"s"I 7'irtualTimer E*t:
boolBt chTi!"Is'ihin 7systimeBt start8 systimeBten$:
8/18/2019 8. chibios_07KT
17/32
2010
e
SynchroniFation
17Embedded system
8/18/2019 8. chibios_07KT
18/32
2010
e
1ounting Semahores
18Embedded system
• S$nal% The semaphore "ounter is in"rease
an i! the result is non1positive then a aitingthrea is remove !rom the semaphore ?ueuean mae reay !or e-e"ution.
• &at% The semaphore "ounter is e"rease
an i! the result be"omes negative the threais ?ueue in the semaphore an suspene.
• Reset% The semaphore "ounter is reset to anon1negative value an all the threas in the
?ueue are release.
1 S
8/18/2019 8. chibios_07KT
19/32
2010
e
1ounting Semahores
19Embedded system
• voi '(Se)Int (Semaphore @sp* "ntt n)
• voi '(Se)Reset (Semaphore @sp* "ntt n)• voi '(Se)ResetI (Semaphore @sp* "ntt n)
• msgt '(Se)&at (Semaphore @sp)
•
msgt '(Se)&atT)e*ut (Semaphore @sp*systimet time)
• voi '(Se)S$nal (Semaphore @sp)
• voi '(Se)S$nalI (Semaphore @sp)
1 ti S h
8/18/2019 8. chibios_07KT
20/32
2010
e
1ounting Semahores
20Embedded system
• msgt :
–RDBO>
–RDBR;S;T
–RDBT
8/18/2019 8. chibios_07KT
21/32
2010
e
inary Semahores
21Embedded system
• se the e-isting "ounting semaphores
• Counter o! binary semaphores is notalloe to gro above the value $
• ot implement the priority proto"ol.
• ave only to e=ne states : – Ta7en
–ot ta7en
t S h
8/18/2019 8. chibios_07KT
22/32
2010
e
ute/s Semahores
22Embedded system
• Same as T7ernel
• De=ne states :
–Fo"7
–nlo"7
e
< t 6l
8/18/2019 8. chibios_07KT
23/32
2010
8/18/2019 8. chibios_07KT
24/32
2010
8/18/2019 8. chibios_07KT
25/32
2010 emory anagement
25Embedded system
• 1ore emory anager • Heas• emory ools• Cynamic threa$s
2010
e
1ore emory anager
8/18/2019 8. chibios_07KT
26/32
2010 1ore emory anager
26Embedded system
• The "ore memory manager is a
simpli=e allo"ator that only allos toallo"ate memory blo"7s ithout thepossibility to !ree them'emory pools
2010
e
Hea
8/18/2019 8. chibios_07KT
27/32
2010 Hea
27Embedded system
• mallo"()
• !ree()
2010
e
emory 3ools
8/18/2019 8. chibios_07KT
28/32
2010 emory 3ools
28Embedded system
• allo"ate/!ree =-e si+e obe"ts in
'*nstant t)e an reliably ithoutmemory !ragmentation problems
2010
e
@2O anagement
8/18/2019 8. chibios_07KT
29/32
0 0 @2O anagement
29Embedded system
• Abstra"t Se?uential Streams – Can be use as base "lass !or high level
obe"t types su"h as =les* so"7ets* serialports* pipes et".
•
Abstra"t Eile Streams• Abstra"t
8/18/2019 8. chibios_07KT
30/32
Registry
30Embedded system
• The Threas Registry is a ouble lin7e
list that hols all the a"tive threas inthe system.
• Threa @ "hRegEirstThrea (voi)
• Threa @ "hRege-tThrea (Threa @ tp)
• Je=ne R;GR;'O4; (tp)
• Je=ne R;G
8/18/2019 8. chibios_07KT
31/32
Cebug
31Embedded system
• Tra"e buKer.
• #arameters "he"7.• >ernel assertions.
2010
e
@nternals
8/18/2019 8. chibios_07KT
32/32
@nternals
32Embedded system
• Eun"tions manage ThreasLueue an
ThreasFist• Are not OS A#