You are on page 1of 22

COMP595EA

BasicDesignusingRTOS

EmbeddedDesign
Hasas many exceptionsas itdoesrules
ingenuityandexperienceareimportantfa
ctors
forthe
successofembeddeddesigns.
Morequestionsneedtobeaddressed:
Whatmustthesystemdo?
Howfastmustitdoit?
Howshouldfailuresbehandled?
Howcriticalaretimingissues?

EffortManagement
Timingissues?
Canwetoleratedecenttiming99%ofthetime?

Ordoweneedrapidresponse100%ofthetime?
Importantbecauseitmaynotbeworththe
heroic
designeffortstoachievethelatterisitisnot
necessary.

RTOStypes
Hardreal-timesystems
Systemsthatrequirethatabsolutedeadlin
esmustbemet.
Softrealtimesystems
Allowsomefudgeindeadlines.

Bothbenefitfromsimilardesigntechnique
s.

ClassicResources
Debuggers,Interactivedevelopment
environments,compilers
Theseandallotherclassictoolstoassistin
applicationsoftwaredesignsarejustasusefulin
assistingwithembeddeddesigns
Thetechniquesforembeddeddesignarein
additiontotheseclassicaltools.
LearntoloveyourdebuggerandeditorJ.W.

Testingand Debugging
Manyapplicationsoftwaredesignsview
testing
anddebuggingasanuisanceleftuntilthe
lastminute

Whendesigningembeddedapplicationsm
ake
surethatyourdesignsincludetestingand
debuggingaspartoftheoveralldesign,pr

WriteShortInterruptRoutines
Fortwo reasons:
Eventhelowestpriorityinterruptroutineis
executedinpreferencetothehighestprio
ritytask.

Longinterruptroutinestranslatedirectlyto
slow
respondingtaskcode.
Interruptroutinestendtobemorebug
proneand
hardertodebugthantaskcode.

InterruptRoutineTradeoff
Althoughinterruptroutinesshouldbe shortthey
shouldn'tbetooshort.

InterruptroutinesusuallycauseacalltosomeRTOS
routinestopassmessagesoractivatesemaphores.
RTOSroutinesaregenerallycostlytoexecute.
Exceedinglysmallinterruptroutinescantherefore
consumetoomuchcomputationalpowerbycausing
toomanyRTOScalls.
Tryforthebalanceofthistradeoff

Howmany tasks
shouldIhave?
Createa large numberof tasks has the following
advantages:
moretasksyieldsbettercontrolofresponse
times
moretasksallowsadesigntobemoremodular
-moretasksallowfordatatobeencapsulated
moreeffectively.

Disadvantages

Thedisadvantagesare:
moretasksare likely to have more shareddata
moretasksrequiremoremessagepassing
moretaskswillrequiremorememory(stacks)
moretasksrequiremorecontextswitching
moretasksmeanmoreRTOSroutinecalls
RTOSroutinesdon'tdoanythingthecustomer
caresabout

SystemsrunfasterWITHOUTRTOScalls

StateMachines
Tasksin RTOSdesignsare often
modeledas
statemachines.

Creatingand DeletingTasks
SomeRTOSwillallowyou to createand destroy
tasksduringexecution.
Thisshouldbeavoided.

create/destroyRTOSroutinesaretypicallyexpensive
Itcanbedifficulttodestroytaskswithoutleaving
thingsinamess.
Createallthetasksatstartup.Tasksthatwantto
beDestroyedshouldsimplyblockandneverwake
up.

TimeSlicing
ManyRTOSwilltime slicebetweentasks of
equalpriority.
Thisshouldalsobeavoidedandturnedoffif
possible
contextswitcheswastetime.
Fairisnotanissueinembeddedsystems
tasksaretypicallynotofequalurgency

Iftheyareyoutypicallydon'tcarewhichfinishesfir
st.
ifyoucan'tpinpointareasonwhy,don'tuseit.

EncapsulatingSemaphores
Theactofputting Give and Getsemaphore
routinesthroughoutyourcodecausesan
increasedprobabilityofmistakesbeingmade.

EncapsulateSemaphoreroutinessothattasksthat
wanttoexecutesomebehaviorinvolvingthe
semaphoremakeacalltoasingleroutine

TheGetandGivecallsareinsidethisencapsulated
routine.

EncapsulatingQueues
Similarlymistakesdealingwith queuescan be
reducedbyencapsulation.

queuestypicallyhaveaprotocolorformatassocia
ted
with.
multiplemessagepassingcallsincreasethe
probabilityofacommunicationmistake.
encapsulatingsuchcallsintofunctionsthattake
specificargumentsreducestheseerrors.

EncapsulatingConsideration
Whenencapsulatingsemaphoresor
queues:
routinesaresharedbymanytasks

Caremustbetakentoavoidsharedd
ata
problems
routinesmustbereentrant.

SavingMemory Space
Embeddedsystemshave limited memory
ROM(code)andRAM(data)areseparate.

Packingdatatightlyandneatlyusuallycons
umes
morecodespace.
Itisoftennecessarytosavespacetoget
everythingtofit.
Howmuchspacedoyouneed?

TwoMethods
Twomethodsfor determiningspace requirements:
tracethedeepestfunctionalcallspossible.Addallthe
localvariables,parametersandinterruptroutine
needs.
accuratebutverydifficulttocarryout.
Fillstackswithaknownpattern.Runtheprogramfor
awhileseewhatgotused

easybutnotsoaccurate.Mighthavemissedtheworstca
se.

MethodsforReducingSpace
Makesureyouaren't using twofunctionsto dothesame
thing
Checkthatdevelopmenttoolsaren'tsabotagingyoubut
pullinginlargelibrariesorothergarbage.
ConfiguretheRTOStocontainonlythosefunctionsthat
youneed.
Lookattheassemblylanguagetoverifythecompileris
producingoptimizedcode
Considerusingstaticvariablesinsteadoflocals.
Considerusingcharinsteadofint
Writeitinassembly(ugh)

SavingPower
Manyembeddedsystemsrun on
batterypower
Batterylifeisabigissue

methodforconservingpowerincludingturning
offcomponents,includingthemicroprocessor

Mostembeddedmicroprocessorshaveatleast
onepowersavingmode

Onboardperipherals
Somesystemsconservepowerby
halting
executioninstructionbutleaveon
board
peripherals(timers,interrupts,etc)r
unning

Interruptcausesexecutiontoresume
codecontinueswhereitleftoff.

Turnitalloff

Somedevicesturn everythingoff
Savesthemostpower
requireshardware
Mustbemanuallyturnedonagain
notsuitableforsomesituations

You might also like