版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年“新九論”學習心得體會例文(3篇)
- 2025年湖南貨運從業(yè)資格證新政
- 2025年濰坊b2貨運資格證多少道題
- 二零二五版籃球場地租賃及賽事門票銷售合同3篇
- 2025版體檢服務信息化建設合作合同協(xié)議2篇
- 2024跨國公司研發(fā)中心合作合同
- 二零二五年度城市綜合體消防安全管理代理服務合同3篇
- 二零二五年度合同擔保制度標準合同范本匯編3篇
- 2025版天然氣發(fā)電機組購銷合同范本3篇
- 2025年度個人對公司借款及稅收優(yōu)惠合同規(guī)范4篇
- 無人化農場項目可行性研究報告
- 《如何存款最合算》課件
- 社區(qū)團支部工作計劃
- 拖欠工程款上訪信范文
- 2024屆上海市金山區(qū)高三下學期二模英語試題(原卷版)
- 《wifi協(xié)議文庫》課件
- 《好東西》:女作者電影的話語建構與烏托邦想象
- 一年級下冊數學口算題卡打印
- 2024年中科院心理咨詢師新教材各單元考試題庫大全-下(多選題部分)
- 真人cs基于信號發(fā)射的激光武器設計
- 2024年國信證券招聘筆試參考題庫附帶答案詳解
評論
0/150
提交評論