版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
CS4101嵌入式系統概論
DesignsUsingRTOS0CS4101嵌入式系統概論
DesignsUsingSpecificationBeforewecandesignandimplementasystem,weneedtospecifyit
aharderissueSpecifyinganembeddedsystemisharderWhatmustthesystemdo?Howfastmustitdoit?Howcriticaliseachtiming?Hardorsoftreal-time?Knowledgeofsystemhardwareneedede.g.ifaserialportreceives1Kcharacters/secandeachcharactercausesaninterrupt,HWcanhandle?SoftwareengineeringknowledgeneededStructure,modularity,encapsulation,maintainability1SpecificationBeforewecandesUndergroundTankMonitoringMonitorupto8
underground
tanksbyreading
thermometers
andlevelsof
floatsinthem2UndergroundTankMonitoringMonUndergroundTankMonitoringReadingfloatlevel:periodicallySendacommandtohardwaretoreadfromatank;hardwareobtainsthelevelandinterruptsmicroprocessorforlaterreadingReadingtemperature:atanytimeAlarming:Setflagandturnonalarmwhenleveldroppingconsistently(leak)orrisingrapidlyduringrefueling3UndergroundTankMonitoringReaUndergroundTankMonitoringUserInterface:16-buttonkeypad,20-charLCD,thermalprinterKeypad:givecommandslikedisplayinglevels,requestreports,historiesetc.andbuttonsinterruptthemicroprocessorPrinter:interruptsafterprintingeachline,indicatingitisreadyforthenextDisplayshowsmostrecentdata.RetainsdataonscreenuntilchangedbytheprocessorAconnectortoanalarmbelltowarnaboutsystemleaksoroverflows.Turnedoffthroughoneofthekeypadbuttons4UndergroundTankMonitoringUseMoreDetailedSpecificationsMainlyontimingandthisisoftenmostdifficultpart,particularlywhenyoutalktocustomers:Whenafloatinatankisrisingrapidly,howoftendoweneedtoreadit?
severaltimespersecondHowquicklyshouldrespondonpushingbuttons?
0.1secondWhatmicroprocessortouse?8-bitHowmuchtimeforcalculatinggasquantity?
mayneedexperiments;say,4~5sec5MoreDetailedSpecificationsMaThereisaTimingProblem!Ourrequirementsare:MustcheckeachtankinwhichthefloatisrisingseveraltimesasecondBut,ittakesa4or5secondstocalculatethequantityofgasolineinatankAnd,wecanonlyuse8-bitmicroprocessorCanyoubuiltsuchasystemandsatisfythetimingconstraints?Workaround:Detectoverflowsbasedonfloatlevelsaloneandnotcalculatinggasolinevolume6ThereisaTimingProblem!OurDoWeNeedanRTOS?4-5secgasquantitycalculationisthemosttimeconsumingandmustbepre-emptedwhenotherprocessing(mostlyinteractionwithusersoroperationsinemergence)isrequiredtobedoneWithoutanRTOS,ISRsrequiredtodotasks.PossibletomanagewithISRsincurrentcasebutRTOSisabetteroptionNow,wearereadyto“design”thesystem7DoWeNeedanRTOS?4-5secgasDividingWorkintoTasksLevelcalculationtaskCalculatesgasolinevolumeineachtankbasedontemperatureandfloatlevelTakes4-5sec,henceasalowprioritytaskOnetaskforalltanksoronetaskforeachtank?OverflowdetectiontaskHigherprioritythanlevelcalculation&leakdetectionFloathardwaretaskSchedulerequestsfromlevel-calculationandoverflow-detectionformutualexclusivelyaccessingthelevelhardwareneedtomanagerequestqueueAlternatively,canusesemaphoretoprotectlevelHW8DividingWorkintoTasksLevelDividingWorkintoTasksButtonhandlingtaskNeedastatemachinetokeeptrackofsequenceofbuttonspressedputinISR?DisplaytaskNeedtopreventtasksfrominterferingwitheachother’sdisplaycan’tdowithsemaphore(nextpage)AlarmbelltaskmaynotneededSharedhardwareasseveraltaskscanturniton/off.PrintformattingtaskLowerprioritythanbuttonhandlingtasksinceitmighttakemorethan1/10thofasecondtoformatreportswhichmustnotinterferewithbuttonresponse9DividingWorkintoTasksButtonSemaphoreCannotProtectDisplay10SemaphoreCannotProtectDisplSummaryofTaskedNeeded11SummaryofTaskedNeeded11DealingwithSharedDataGasolinelevelissharedbyseveraltasks(levelcalculation,display,printformatting)CanbedealtwitheitherbyhavingasemaphoreoraseparatetaskwithrequestqueueTwoconsiderationsfortheabovedecision:Whatisthelongesttimethatanytaskwillholdontothesemaphore?Caneveryothertaskwaitthatlong?Foroursystem,semaphoremaybesufficient12DealingwithSharedDataGasoliFinalDesign13FinalDesign13ImplementationUsinguC/OSuC/OSAtinyopen-sourcereal-timekernelMemoryfootprintisabout20kforafullyfunctionalkernelSupportingpreemptivepriority-drivenreal-timeschedulingSupportingmanyplatforms:x86,68x,ARM,MIPS…Samplecodeforundergroundtankmonitoring:RunsunderDOS,usesuC/OSservices,andiscompiledwithBorlandC14ImplementationUsinguC/OSuC/OOnHardwarevsOnDOSTankcode+uC/OScodeHardwareTankcode+uC/OScodePCDOSNeedtosimulateHW
andpresentaDOSinterface15OnHardwarevsOnDOSTankcodeStartupDBGMAIN.C:allofDOSscreenandkeyboardinterfacevoidmain(void){/*Settimer&uC/OSinterruptonDOS*/ .../*Starttherealsystem*/
vEmbeddedMain();}16StartupDBGMAIN.C:allofDOSsStartupMAIN.C:mainroutineofHWindependentcodevoidvEmbeddedMain(void){OSInit();/*initializeuC/OS*/vTankDataInit();vTimerInit();vDisplaySystemInit();vFloatInit();
vButtonSystemInit();
vLevelsSystemInit();vPrinterSystemInit();vHardwareInit();vOverflowSystemInit();
OSStart();/*startuC/OS*/}17StartupMAIN.C:mainroutineofInsideuC/OS-OSinit()InitinternalstructuresofuC/OSTaskreadylistPrioritytableTaskcontrolblocks(TCB)EventcontrolblocksQueuecontrolblocksCreatehousekeepingtasksTheidletask
OSTaskCreate(OSTaskIdle,(void*)0,
(void*)&OSTaskIdleStk[OS_TASK_IDLE_STK_TOP],
OS_LO_PRIO);18InsideuC/OS-OSinit()InitinInsideuC/OS-OSinit()OSTaskCreate(): OSTaskCreate( OSTaskIdel, (void*)0, &TaskStartStk[TASK_STK_SIZE-1], 0 );Entrypointofthetask(apointertofunction)ParameterofthetaskStackofthetaskPriority(0=highest)19InsideuC/OS-OSinit()OSTaskCInternalStructureofuC/OS-II20InternalStructureofuC/OS-IITaskControlBlock(TCB)21TaskControlBlock(TCB)21BacktoMAIN.CvButtonSystemInit()ThetaskthatinitializesthebuttontaskvoidvButtonSystemInit(void){/*Initializethequeueforthistask*/QButtonTask=OSQCreate(&a_pvQData[0],Q_SIZE);/*Startthetaskthathandlesbuttonstatemachine*/OSTaskCreate(vButtonTask,NULLP,(void*)&ButtonTaskStk[STK_SIZE],TASK_PRIORITY_BUTTON);}22BacktoMAIN.CvButtonSystemIniBacktoMAIN.CvLevelsSystemInit()ThetaskthatinitializesthelevelstaskvoidvLevelsSystemInit(void){/*Initializethequeueforthistask*/QLevelsTask=OSQCreate(&a_pvQData[0],Q_SIZE);/*Startthetaskthatcalculatesthetanklevels*/OSTaskCreate(vLevelsTask,NULLP,(void*)&LevelsTaskStk[STK_SIZE],TASK_PRIORITY_LEVELS);}23BacktoMAIN.CvLevelsSystemIniInsideuC/OS-OSstart()StartmultitaskingofuC/OSNeverreturnstomain()NeedtocreateatleastonetaskbeforecallingOSstart()ThatisthereasonwhyweneedtocreateOSTaskIdel()Runthehighest-priorityreadytaskWehavealreadyhadtaskssuchasOSTaskIdel(),vButtonTask(),vLevelsTask(),...readytorun24InsideuC/OS-OSstart()StartvButtonTaskThetaskthathandlesthebuttonstatemachinestaticvoidvButtonTask(){...while(TRUE){/*Waitforabuttonpress*/wMsg=(int)OSQPend(QButtonTask,WAIT_FOREVER,&byErr);switch(iCmdState){caseCMD_NONE:switch(wMsg){case'1':case'2':case'3':vDisplayTankLevel(wMsg-'1');break;
...Taskblockedwaitingforrequestsinqueue25vButtonTaskThetaskthathandlvButtonInterruptThisisthebuttoninterruptroutinevoidvButtonInterrupt(void){/*GotoHW,seewhatbuttonwaspushed*/wButton=wHardwareButtonFetch();/*Putbuttononthetask’squeue*/OSQPost(QButtonTask,(void*)wButton);}WakeupvButtonTask()26vButtonInterruptThisisthebuvLevelsTaskThetaskthatcalculatesthetanklevelsstaticvoidfarvLevelsTask(){/*Startwiththefirsttank*/iTank=0;while(TRUE){/*Getfloatsandfindlevelintank*/
vReadFloats(iTank,vFloatCallback);/*Waitfortheresult.*/wFloatLevel=(WORD)OSQPend(QLevelsTask,WAIT_FOREVER,&byErr)-MSG_LEVEL_VALUE;/*Dothe"calculation"–looong*/27vLevelsTaskThetaskthatcalcuvLevelsTask/*Adddatatothedatabank*/vTankDataAdd(iTank,wFloatLevel);/*Nowtestforleaks*/if(iTankDataGet(iTank,a_iLevels,NULLP,3)…{if/*thelevelsgodownconsistently.*/{
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 意外情况紧急救援合同范本
- 商场和商户之间的合同范本
- 尾矿渣购销合同范本
- 空运合同范本模板
- 公开考核招聘引进高层次人才报名表
- 个人信息登记表
- 工程装饰装修施工合同范本
- 公路工程合同管理履职思路
- 购还建房合同范本
- 园区道路改造合同范本
- 适用于新高考新教材备战2025届高考英语一轮总复习教材知识复习Unit2Alifeswork课件外研版选择性必修第三册
- 2024年“学宪法、讲宪法、用宪法”全民宪 法教育知识竞赛题库(含答案)
- 低视力的康复及护理
- 道路车辆 局域互联网络(LIN) 第4部分:12V24V电气物理层规范
- 反有组织犯罪法知识考试题及答案
- 部编版小学语文四年级下册教材解读
- 神农尝百草神话故事
- 人口老龄化对医疗资源配置的影响分析
- Unit 3 What would you like A Let's learn(教学设计)人教PEP版英语五年级上册
- 写作:说明的关键在说得“明”+教学设计-【中职专用】高一语文(高教版2023基础模块下册)
- 新概念英语第2册课文(完整版)
评论
0/150
提交评论