CMSIS-RTOS-Tutorial

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

CMSIS-RTOSTutorialIntroductionThistutorialisanexcerptfrom“TheDesignersGuidetotheCortex-MProcessorFamily”byTrevorMartinandisreproducedwithpermissionofElsevier.FormoredetailspleaseseetheFurtherReadingsectionattheendofthistutorial.InthistutorialwearegoingtolookatusingasmallfootprintRTOSrunningonaCortex-Mbasedmicrocontroller.SpecificallywearegoingtouseanRTOSthatmeetsthe‘CortexMicrocontrollerInterfaceStandard’(CMSIS)RTOSSpecification.ThisspecificationdefinesastandardRTOSAPIforusewithCortex-Mbasedmicrocontrollers.TheCMSIS-RTOSAPIprovidesuswithallthefeatureswewillneedtodevelopwithanRTOS,weonlyneedtolearnitonceandthencanuseitacrossaverywiderangeofdevices.CMSIS-RTOSalsoprovidesastandardinterfaceformorecomplexframeworks(JavaVirtualMachine,UML).Itisalsoastandardinterfaceforanyonewantingtodevelopreusablesoftwarecomponents.IfyouarenewtousinganRTOSittakesabitofpracticetogetusedtoworkingwithanRTOSbutonceyouhavemadetheleaptheadvantagesaresuchthatyouwillnotwanttoreturntowritingbaremetalcode.GettingStarted-InstallingthetoolsToruntheexamplesinthistutorial,itisfirstnecessarytoinstalltheMDK-ARMtoolchain.FirstdownloadtheMDK-CoreVersion5usingtheembeddedURLbelowandruntheinstallationfile.‘DeviceFamilyPack’.Thisisacollectionofsupportfilessuchasstartupcode,flashprogrammingalgorithmsanddebuggersupportthatallowyoutodevelopwithaspecificmicrocontrollerfamily.TheMDK-ARMtoolchainconsistsofaCoreInstallation(IDE,CompilerandDebugger)plusadditionalsoftwarepacksaddedthroughapackinstaller2CMSIS-RTOSTutorialIntheexerciseswearegoingtouseanSTM32F103RBsoweneedtoinstallsupportforthisdeviceusingthe‘PackInstaller’withintheµVisionIDE.WhentheMDK-Corefinishesinstallingthepackinstallerwillstartautomatically,alternativelyyoucanstarttheµVisionIDEandaccessPackInstallerfromthetoolbarbypressingtheiconshownbelowOncethepackinstallerisopenitwillconnecttocloudbasedpackdatabaseanddisplaytheavailabledevicepacks.SelecttheKeil::STM32F1xx_DFPandpresstheinstallbutton.ThiswilltakeafewminutestodownloadandinstalltheSTM32F1xxsupportfiles.IfthepackinstallerhasanyproblemsaccessingtheremotepackyoucandownloaditmanuallyusingtheURLbelow‘CMSIS_RTOS_Tutorial’.OncethepackhasstartedinstallingclicknextHereyoumustacceptthelicenseandagainclicknexttocontinuetheinstallation4CMSIS-RTOSTutorialWhatHardwaredoIneed?Simpleanswer:none!TheKeiltoolchaincontainssimulatorsforeachoftheCortex-Mprocessors.Italsocontainsfullsimulationmodels(CPU+Peripherals)forsomeoftheearlierCortex-Mmicrocontrollers.ThismeanswecanruntheexamplesinthedebuggerusingthesimulationmodelsandexploreeveryaspectofusingtheRTOS.InfactthismethodofworkingisabetterwayoflearninghowtousetheRTOSthangoingstraighttoarealmicrocontroller.OverviewInthistutorialwewillfirstlookatsettingupanintroductoryRTOSprojectforaCortex-Mbasedmicrocontroller.Next,wewillgothrougheachoftheRTOSprimitivesandhowtheyinfluencethedesignofourapplicationcode.Finally,whenwehaveaclearunderstandingoftheRTOSfeatures,wewilltakeacloserlookattheRTOSconfigurationoptions.IfyouareusedtoprogrammingamicrocontrollerwithoutusinganRTOSi.e.baremetal,therearetwokeythingstounderstandasyouworkthroughthistutorial.InthefirstsectionwewillfocusoncreatingandmanagingThreads.Thekeyconcepthereistoconsiderthemrunningasparallelconcurrentobjects.Inthesecondsectionwewilllookathowtocommunicatebetweenthreads.Inthissectionthekeyconceptissynchronizationoftheconcurrentthreads.CMSIS-RTOSTutorialFirststepswithCMSIS-RTOSTheRTOSitselfconsistsofaschedulerwhichsupportsround-robin,pre-emptiveandco-operativemultitaskingofprogramthreads,aswellastimeandmemorymanagementservices.Inter-threadcommunicationissupportedbyadditionalRTOSobjects,includingsignaltriggering,semaphores,mutexandamailboxsystem.Aswewillsee,interrupthandlingcanalsobeaccomplishedbyprioritizedthreadswhicharescheduledbytheRTOSkernel.AccessingtheCMSIS-RTOSAPIToaccessanyoftheCMSIS-RTOSfeaturesinourapplicationcodeitisnecessarytoincludethefollowingheaderfile#includecmsis_os.hThisheaderfileismaintainedbyARMaspartoftheCMSIS-RTOSstandard.FortheCMSIS-RTOSKeilRTXthisisthedefaultAPI.OtherRTOSwillhavetheir

1 / 75
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功