




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
CS4101嵌入式系統概論
DesignsUsingRTOS0SpecificationBeforewecandesignandimplementasystem,weneedtospecifyitaharderissueSpecifyinganembeddedsystemisharderWhatmustthesystemdo?Howfastmustitdoit?Howcriticaliseachtiming?Hardorsoftreal-time?Knowledgeofsystemhardwareneedede.g.ifaserialportreceives1Kcharacters/secandeachcharactercausesaninterrupt,HWcanhandle?SoftwareengineeringknowledgeneededStructure,modularity,encapsulation,maintainability1UndergroundTankMonitoringMonitorupto8
underground
tanksbyreading
thermometers
andlevelsof
floatsinthem2UndergroundTankMonitoringReadingfloatlevel:periodicallySendacommandtohardwaretoreadfromatank;hardwareobtainsthelevelandinterruptsmicroprocessorforlaterreadingReadingtemperature:atanytimeAlarming:Setflagandturnonalarmwhenleveldroppingconsistently(leak)orrisingrapidlyduringrefueling3UndergroundTankMonitoringUserInterface:16-buttonkeypad,20-charLCD,thermalprinterKeypad:givecommandslikedisplayinglevels,requestreports,historiesetc.andbuttonsinterruptthemicroprocessorPrinter:interruptsafterprintingeachline,indicatingitisreadyforthenextDisplayshowsmostrecentdata.RetainsdataonscreenuntilchangedbytheprocessorAconnectortoanalarmbelltowarnaboutsystemleaksoroverflows.Turnedoffthroughoneofthekeypadbuttons4MoreDetailedSpecificationsMainlyontimingandthisisoftenmostdifficultpart,particularlywhenyoutalktocustomers:Whenafloatinatankisrisingrapidly,howoftendoweneedtoreadit?
severaltimespersecondHowquicklyshouldrespondonpushingbuttons?
0.1secondWhatmicroprocessortouse?8-bitHowmuchtimeforcalculatinggasquantity?
mayneedexperiments;say,4~5sec5ThereisaTimingProblem!Ourrequirementsare:MustcheckeachtankinwhichthefloatisrisingseveraltimesasecondBut,ittakesa4or5secondstocalculatethequantityofgasolineinatankAnd,wecanonlyuse8-bitmicroprocessorCanyoubuiltsuchasystemandsatisfythetimingconstraints?Workaround:Detectoverflowsbasedonfloatlevelsaloneandnotcalculatinggasolinevolume6DoWeNeedanRTOS?4-5secgasquantitycalculationisthemosttimeconsumingandmustbepre-emptedwhenotherprocessing(mostlyinteractionwithusersoroperationsinemergence)isrequiredtobedoneWithoutanRTOS,ISRsrequiredtodotasks.PossibletomanagewithISRsincurrentcasebutRTOSisabetteroptionNow,wearereadyto“design”thesystem7DividingWorkintoTasksLevelcalculationtaskCalculatesgasolinevolumeineachtankbasedontemperatureandfloatlevelTakes4-5sec,henceasalowprioritytaskOnetaskforalltanksoronetaskforeachtank?OverflowdetectiontaskHigherprioritythanlevelcalculation&leakdetectionFloathardwaretaskSchedulerequestsfromlevel-calculationandoverflow-detectionformutualexclusivelyaccessingthelevelhardwareneedtomanagerequestqueueAlternatively,canusesemaphoretoprotectlevelHW8DividingWorkintoTasksButtonhandlingtaskNeedastatemachinetokeeptrackofsequenceofbuttonspressedputinISR?DisplaytaskNeedtopreventtasksfrominterferingwitheachother’sdisplaycan’tdowithsemaphore(nextpage)AlarmbelltaskmaynotneededSharedhardwareasseveraltaskscanturniton/off.PrintformattingtaskLowerprioritythanbuttonhandlingtasksinceitmighttakemorethan1/10thofasecondtoformatreportswhichmustnotinterferewithbuttonresponse9SemaphoreCannotProtectDisplay10SummaryofTaskedNeeded11DealingwithSharedDataGasolinelevelissharedbyseveraltasks(levelcalculation,display,printformatting)CanbedealtwitheitherbyhavingasemaphoreoraseparatetaskwithrequestqueueTwoconsiderationsfortheabovedecision:Whatisthelongesttimethatanytaskwillholdontothesemaphore?Caneveryothertaskwaitthatlong?Foroursystem,semaphoremaybesufficient12FinalDesign13ImplementationUsinguC/OSuC/OSAtinyopen-sourcereal-timekernelMemoryfootprintisabout20kforafullyfunctionalkernelSupportingpreemptivepriority-drivenreal-timeschedulingSupportingmanyplatforms:x86,68x,ARM,MIPS…Samplecodeforundergroundtankmonitoring:RunsunderDOS,usesuC/OSservices,andiscompiledwithBorlandC14OnHardwarevsOnDOSTankcode+uC/OScodeHardwareTankcode+uC/OScodePCDOSNeedtosimulateHW
andpresentaDOSinterface15StartupDBGMAIN.C:allofDOSscreenandkeyboardinterfacevoidmain(void){/*Settimer&uC/OSinterruptonDOS*/ .../*Starttherealsystem*/
vEmbeddedMain();}16StartupMAIN.C:mainroutineofHWindependentcodevoidvEmbeddedMain(void){OSInit();/*initializeuC/OS*/vTankDataInit();vTimerInit();vDisplaySystemInit();vFloatInit();
vButtonSystemInit();
vLevelsSystemInit();vPrinterSystemInit();vHardwareInit();vOverflowSystemInit();
OSStart();/*startuC/OS*/}17InsideuC/OS-OSinit()InitinternalstructuresofuC/OSTaskreadylistPrioritytableTaskcontrolblocks(TCB)EventcontrolblocksQueuecontrolblocksCreatehousekeepingtasksTheidletask
OSTaskCreate(OSTaskIdle,(void*)0,
(void*)&OSTaskIdleStk[OS_TASK_IDLE_STK_TOP],
OS_LO_PRIO);18InsideuC/OS-OSinit()OSTaskCreate(): OSTaskCreate( OSTaskIdel, (void*)0, &TaskStartStk[TASK_STK_SIZE-1], 0 );Entrypointofthetask(apointertofunction)ParameterofthetaskStackofthetaskPriority(0=highest)19InternalStructureofuC/OS-II20TaskControlBlock(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.CvLevelsSystemInit()ThetaskthatinitializesthelevelstaskvoidvLevelsSystemInit(void){/*Initializethequeueforthistask*/QLevelsTask=OSQCreate(&a_pvQData[0],Q_SIZE);/*Startthetaskthatcalculatesthetanklevels*/OSTaskCreate(vLevelsTask,NULLP,(void*)&LevelsTaskStk[STK_SIZE],TASK_PRIORITY_LEVELS);}23InsideuC/OS-OSstart()StartmultitaskingofuC/OSNeverreturnstomain()NeedtocreateatleastonetaskbeforecallingOSstart()ThatisthereasonwhyweneedtocreateOSTaskIdel()Runthehighest-priorityreadytaskWehavealreadyhadtaskssuchasOSTaskIdel(),vButtonTask(),vLevelsTask(),...readytorun24vButtonTaskThetaskthathandlesthebuttonstatemachinestaticvoidvButtonTask(){...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;
...Taskblockedwaitingforrequestsinqueue25vButtonInterruptThisisthebuttoninterruptroutinevoidvButtonInterrupt(void){/*GotoHW,seewhatbuttonwaspushed*/wButton=wHardwareButtonFetch();/*Putbuttononthetask’squeue*/OSQPost(QButtonTask,(void*)wButton);}WakeupvButtonTask()26vLevelsTaskThetaskthatcalculatesthetanklevelsstaticvoidfarvLevelsTask(){/*Startwiththefirsttank*/iTank=0;while(TRUE){/*Getfloatsandfindlevelintank*/
vReadFloats(iTank,vFloatCallback);/*Waitfortheresult.*/wFloatLevel=(WORD)OSQPend(QLevelsTask,WAIT_FOREVER,&byErr)-MSG_LEVEL_VALUE;/*Dothe"calculation"–looong*/27vLevelsTask/*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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年监理考试各科复习试题及答案
- 电商设计师情境模拟试题及答案
- 投资咨询工程师如何处理客户关系试题及答案
- 信息化物流师行业机会试题及答案
- 全媒体运营师的持续学习计划试题及答案
- 小刘固农场农产品网络营销方案设计
- 2024监理工程师考试复习建议试题及答案
- 2025年二月份跨国宠物监护权在邴雅薛含协议中的体现
- 黑龙江民族职业学院《数学模型及应用》2023-2024学年第二学期期末试卷
- 黑龙江省伊春市五营区2024-2025学年数学三下期末考试试题含解析
- 紧急采购申请单
- 小学道德与法治学科高级(一级)教师职称考试试题(有答案)
- 复旦大学英语水平测试大纲9300词汇表讲义
- (课件)肝性脑病
- DB63-T 1675-2018+建筑消防设施维护保养技术规范
- 西师版数学四年级下册全册教案
- DB11T 1894-2021 10kV及以下配电网设施配置技术规范
- 零星材料明细单
- 施工现场安全检查记录表(周)以及详细记录
- 2022专升本无机化学试卷答案
- 电子课件《英语(第一册)(第三版)》A013820英语第一册第三版Unit6
评论
0/150
提交评论