嵌入式系统概论_第1页
嵌入式系统概论_第2页
嵌入式系统概论_第3页
嵌入式系统概论_第4页
嵌入式系统概论_第5页
已阅读5页,还剩26页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论