嵌入式系統(tǒng)概論_第1頁
嵌入式系統(tǒng)概論_第2頁
嵌入式系統(tǒng)概論_第3頁
嵌入式系統(tǒng)概論_第4頁
嵌入式系統(tǒng)概論_第5頁
已閱讀5頁,還剩26頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

CS4101嵌入式系統(tǒng)概論

DesignsUsingRTOS0CS4101嵌入式系統(tǒng)概論

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. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論