完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
``第8章 μCOS-III系统移植过程详解 本期教程主要教大家如何移植μCOS-III系统,μCOS-III的移植并不难,因为官方已经帮我们把移植代码写好了,我们要做的只是将工程建立起来,编译、链接、运行。如果有什么错误参考官方已经建立好的代码即可。下面就跟大家详细的讲解一下移植过程。 8.1 源代码下载 8.2 源代码移植-MDK 8.3 源代码移植-IAR 8.4 总结 8.1 源代码下载 移植前要从官网下载相关的源代码,一般官方会为IC厂商新推出的评估板配套相应的移植工程,比如去年(2013年)ST公司推出的STM32F429 探索套件。推出后不久Micrium公司就为其配套了自己的μCOS-III工程文件。其实不光Micrium会为其移植相应的工程,其它的RTOS厂商也会移植的,比如SEGGER公司为STM32F429探索套件移植的embOS工程文件。还有一点要和大家说的是,这些RTOS厂商倾向于使用IAR开发环境。为什么使用IAR开发环境?主要是因为IAR中集成了多款RTOS的调试组件。如下图所示: ![]() 考虑到初学μCOS-III的同学中使用MDK的比较多,而且μCOS-III有相关的调试工具μC/Probe,功能也比较的强大。我们今后的教程以使用MDK为主,IAR相关的知识也会跟大家讲解。 下面开始说一下如何从官网下载μCOS-III源码代码以及为STM32配套好的工程代码。先说如何下载源代码: l 打开Micrium的官方网站
![]()
,并点击下面的图标: ![]() l 进入分版块以后,在最上面会有Download的链接: ![]() 点击进入后,在网页的最下面可以看到源代码的下载地址: ![]() 大家可能已经注意到了左侧是Login,这个的意思是大家需要注册一个账号才可以下载,注册很简单,点击Login弹出下面的界面注册就行。 ![]() 注册并登陆后上面的截图就会变成下面这样: ![]() 这种情况下就可以下载源码了,咱们要下载的是最下面的那个,不过日期有点早,是2012年的了。将这个源码下载下来解压后会看到里面的文件如下(路径:MicriumSoftwareuCOS-III): ![]() 这里咱们重点看一下Release文件,这个文件比较的重要,主要记录着μCOS-III的更新内容。内容如下(建议初学的同学把下面的内容读完,脑子里有个印象): -------------------------------------------------------------------------------------------------------- Release V3.03.00 (2012/02/14): -------------------------------------------------------------------------------------------------------- 1) Added Thread Local Storage(TLS) support See chapter 20 of the User'sManual 2) Computation of CPU usage hasnow a resolution of 1/100th of a percent 3) Added OSTaskRegGetID() toassign task register IDs dynamically 4) Now able to Suspend and Resumetasks from ISRs 5) Added option'OS_OPT_TASK_NO_TLS' to OSTaskCreate() to specify that a task will not requireTLS 6) Added and changed some errorcodes 7) Removed OSMsgPoolExtend() sinceit was not documented and not used. 8) Added globalOSStatTaskCPUUsageMax to keep track of peak CPU usage. This value is reset byOSStatReset() 9) Added per task .CPUUsageMaxwhich tracks the peak CPU usage of each task. -------------------------------------------------------------------------------------------------------- Release V3.02.00 (2011/08/01): -------------------------------------------------------------------------------------------------------- 1) Corrected pointer to integercast in OSMemCreate. 2) Corrected invalid typecast onconstant initialization on os_cfg_app.c. 3) Added a "return"statement after each invocation of the OS_SAFETY_CRITICAL_EXCEPTION() macro. 4) Fixed OS_TmrLink() while addingTmr object into middle of spoke linked-list. 5) Corrected OS_TmrResetPeak()reset maximum number of entries (NbrEntriesMax). 6) Added note to clarify use ofOS_OPT_LINK_DLY option on OS_TmrLink() at OSTmrStart(). 7) Adjusted order of operation onTick Wheel during insert (OS_TickListInsert) to first set link pointers on new object, then add it tothe linked-list. 8) Corrected OS_OPT_POST_NO_SCHEDoption for OSFlagPost and OSFlagPendAbort. 9) Initialize Interrupt QueueHandler Task before any other task to prevent usage of OSIntQNbrEntries uninitialized. 10) Corrected use of disabledvariable 'OSCfg_ISRStk'. 11) Changed default OS_CYCLES to32-bits. 12) Corrected per task CPU usagestatistics computation. 13) Adjusted version to new formatVx.yy.zz. 14) Removed OS_TMR_TICK datatype;converted OSTmrTickCtr to OS_TICK to be consistent with other OS_TMR structure fields. 15) Prevent OSSchedLock/Unlock() tobe called from ISR. 16) Re-arranged order of datastructure members on OS_TCB to keep non-optional items at the beginning of the structure. 17) Changed error codes to enum. 18) Converted OS object types touse CPU_TYPE_CREATE. 19) Reworked check to not allow tocreate multiple tasks at idle task priority. 20) Corrected alignment check onOSMemCreate() to handle cases where sizeof(void *) == 1. 21) Added changes to priorityhandling to allow word addressable architectures. 22) Adjusted copyright in fileheaders for source available distribution. -------------------------------------------------------------------------------------------------------- Release V3.01.2 (2010/05/14): -------------------------------------------------------------------------------------------------------- 1) Added error checking for timestamp configuration #defines. 2) Removal of some MISRA C 2004errors. 3) Corrected OS_MEM structuredefinition for field FreeListPtr. 4) Moved OSInitHook() to beginningof OSInit() to be consistent with documentation section about differences between uC/OS-IIand uC/OS-III port functions. 5) Removed duplicate call toOS_TickListRemove() in OS_TickListUpdate(). 6) Corrected OS_TmrLink() where numberof entries in spoke was incremented twice for a particular case, and timer previouspointer was alwyas being cleared before exit the function. 7) Corrected OSTaskChangePrio() toupdate task priority if task is pending on Task Queue, Task Sem, or Flag. 8) Corrected OSTaskDel() TCB cleanup where it could potentially be skipped if context switch happened before OSSched(). 9) Corrected sections of codeconditional on OS_CFG_Q_EN & OS_CFG_TASK_Q_EN. 10) Corrected DbgListRemoveprocedures where it did not clear the DbgPrevPtr of the first object when the head of the list wasremoved. 11) Removed sections whereTimeQuantaCtr was incorrectly reset. 12) Corrected NULL pointerde-reference on OSMutexDel() with OS_OPT_DEL_ALWAYS option when Mutex created and deleted right away. 13) Added OSStatResetFlag intoOS_StatTask to force reset of the computed statistics. 14) Added OSIntQMaxNbrEntries intocomputed statistics. 15) Reordered DbgListAdd/Remove toprevent a still linked object from being cleared. 16) Corrected DbgList removal inOSTmrDel(). 17) Added critical section inOSMemCreate(). 18) Removed access to uninitializedkernel objects (p_obj->Type). 19) Corrected port's OSTaskSwHookwhere OSSchedLockTimeMaxCur was not always cleared between context switch. 20) Corrected NULL pointerde-reference of p_tcb on OS_SchedRoundRobin(), if no TCB in the ready list. 21) Adjusted check for nestinginterrupts on OSSched() by removing conditional compilation based onOS_CFG_CALLED_FROM_ISR_CHK_EN. 22) Adjusted formatting &function descriptions. -------------------------------------------------------------------------------------------------------- Release V3.01.1 (2010/01/11): -------------------------------------------------------------------------------------------------------- 1) Added PERIODIC and MATCH modesto OSTimeDlyHMSM(). 2) Improved the performance of thescheduler lock time measurement. 3) Added OS_CFG_TS_EN in OS_CFG.Hwhich is used to enable/disable time stamping. 4) OSTaskStkChk() now returns thenumber of free and used 'ELEMENTS' instead of 'BYTES'. This is done for consistency. 5) Fixed a bug withOS_PendListRemove1() which removes a task from a wait list. 6) Fixed a bug when pend-aborting aobject where a task has multi-pended on the same object multiple times. 7) Fixed a bug when posting to anevent flag group where there are no task(s) pending on the event flag group. -------------------------------------------------------------------------------------------------------- Release V3.01.0 (2009/12/07): -------------------------------------------------------------------------------------------------------- 1) The API for OSTaskCreate()changed. The seventh argument changedfrom: CPU_STK *p_stk_limit; to CPU_STK_SIZE stk_limit; This argument now represents thenumber of CPU_STK elements left before the stack is empty. This is used when the CPUsupports stack limit checking. 2) As shown above, OS_STK_SIZE ha***een changed to CPU_STK_SIZE and thus, this data type is declared in uC/CPU instead of uC/OS-III. 3) We removed OS_AppInitHookPtrbecause it was impossible to initialize this pointer prior to dereferncing it. OSInit() set the pointer to NULLand didn't allow the user to change its value before using it. 4) Added a new operating mode toOSTimeDly(), i.e. OS_OPT_TIME_PERIODIC 5) Added the functionOSSafetyCriticalStart() which, when called will prevent further kernel objectsfrom being created. In other words, after callingthis function, you will no longer be allowed to create tasks, semaphores,mutexes, etc. In some safety critical systems,it's not allowed to create kernel objects once initialization has completed. 6) Fixed a bug when an object waspend aborted when using OSPendMulti(). 7) Fixed a bug when an object wasdeleted when using OSPendMulti(). 8) Replaced: for (;;) to while (DEF_ON) for tasks to represent that theloop runs while power is applied. 9) Fixed a bug inOSPendMulti(). The scheduler was locked duringa critical region that should have been protected by disabling/enablinginterrupts. 10) The timestamp is now read when a task is created to determine when thetask starts. This is used to compute the pertask CPU usage. 11) Statistics are reset after determining CPU usage capacity. 12) Changed the copyright notice. 其余的四个文件,大家打开看一下就行,下面还会继续的介绍。关于源代码的下载就说这多,下面说一下如何下载建立好的工程文件: l 打开官网进入主界面以后看到下面的Download标记后,点击进入 ![]() |
|
相关推荐
|
|
8.2 源代码移植-MDK 下面开始讲解源代码的移植,这里咱们不一步一步的建立工程了,显得太罗嗦。咱们直接在一个现成的MDK和IAR工程上面建立。工程就使用V5开发板基础篇中的例子:V5-001a_GPIO实验_跑马灯。MDK使用4.54版本,其它高版本的也可以,不过要注意这个问题:
![]() 现在开始移植讲解: l 第一步:在跑马灯工程里面建立文件夹uCOS-III。 ![]() 并将下面四个文件复制到uCOS-III文件夹里面: ![]() l 第二步:把官方工程此路径下MicriumSoftwareEvalBoardsSTSTM3240G-EVALuCOS-III的8个文件 ![]() 以及此路径下MicriumSoftwareEvalBoardsSTSTM3240G-EVALuCOS-IIIKeilMDK的两个文件 ![]() 复制到跑马灯工程里面的此路径下:V5-001a_GPIO实验_跑马灯User。 ![]() 工程中需要的文件已经都复制到工程中了,下一步就是将这些文件添加到工程里面,并添加头文件路径。 l 第三步:在工程的左侧再建立四个组用于添加相应文件。 ![]() Ø uC/CPU中添加如下6个文件,这6个文件位于路径:V5-001a_GPIO实验_跑马灯uCOS-IIIuC-LIB和路径V5-001a_GPIO实验_跑马灯uCOS-IIIuC-LIBPortsARM-Cortex-M4RealView下面 ![]() Ø uC/Lib中添加如下10个文件,这10个文件位于路径V5-001a_GPIO实验_跑马灯uCOS-IIIuC-CPU和路径V5-001a_GPIO实验_跑马灯uCOS-IIIuC-CPUARM-Cortex-M4RealView 下面 ![]() Ø uC/OS-III Source中添加如下20个文件,这20个文件位于路径:V5-001a_GPIO实验_跑马灯uCOS-IIIuCOS-IIISource 下面 ![]() Ø uC/OS-III Port中添加如下3个文件,这3个文件位于路径:V5-001a_GPIO实验_跑马灯uCOS-IIIuCOS-IIIPortsARM-Cortex-M4GenericRealView 下面 ![]() Ø User中添加如下8个文件,这8个文件位于路径:V5-001a_GPIO实验_跑马灯User 下面 ![]() 上面这些文件添加完以后,一个完整的工程就算建立了,下面需要添加一下头文件的路径: ![]() 上面的工程建立好以后,修改部分文件后就可以下载到V5开发板运行了,需要修改的主要有以下几个文件: l main.c文件,用下面的内容覆盖原有内容,这里主要是建立4个LED闪烁的任务。
l includes文件,主要是添加必要的头文件,用下面的内容覆盖原有内容
l 修改bps.c和bsp.h文件。这个文件主要是初始化相关的驱动,用下面的内容覆盖原有内容
l startup_stm32f40_41xxx.s文件,修改这个文件中Systick和PendSV中断入口名,以便于和μCOS-III中命名统一。
l 最后一步是去掉BSP文件组中的bsp_timer.c文件,因为这个文件是SysTick的驱动和μCOS-III中的驱动冲突了。同时要关闭FPU,因为咱们移植的port文件里面没有做FPU的支持。 ![]() |
|
|
|
|
|
本帖最后由 硬汉Eric2013 于 2015-1-10 13:48 编辑 8.3 源代码移植-IAR 官方移植的IAR版本代码中加入了FPU的支持,不过加入的代码完全不符合浮点寄存器的入栈和出栈,也就是说他们提供的代码不适合在Cortex-M4F内核的微控制器中使用。所以我们需要删除并修改部分的代码,要删除并修改的代码如下: l os_cpu_a.asm 文件中下面的代码要删除
l os_cpu_c.c文件中如下的代码得删除,红色字体的地方。 CPU_STK *OSTaskStkInit(OS_TASK_PTR p_task, void *p_arg, CPU_STK *p_stk_base, CPU_STK *p_stk_limit, CPU_STK_SIZE stk_size, OS_OPT opt) { CPU_STK *p_stk; (void)opt; /* Prevent compiler warning */ p_stk =&p_stk_base[stk_size]; /*Load stack pointer */ /* Align the stack to 8-bytes. */ p_stk = (CPU_STK*)((CPU_STK)(p_stk) & 0xFFFFFFF8); /* Registers stacked as if auto-saved on exception */ *--p_stk =(CPU_STK)0x01000000u; /*xPSR */ *--p_stk = (CPU_STK)p_task; /* Entry Point */ *--p_stk =(CPU_STK)OS_TaskReturn; /* R14(LR) */ *--p_stk = (CPU_STK)0x12121212u; /* R12 */ *--p_stk =(CPU_STK)0x03030303u; /* R3 */ *--p_stk =(CPU_STK)0x02020202u; /*R2 */ *--p_stk =(CPU_STK)p_stk_limit; /*R1 */ *--p_stk = (CPU_STK)p_arg; /* R0 : argument */ /* Remaining registers saved on process stack */ *--p_stk =(CPU_STK)0x11111111u; /*R11 */ *--p_stk =(CPU_STK)0x10101010u; /* R10 */ *--p_stk =(CPU_STK)0x09090909u; /*R9 */ *--p_stk =(CPU_STK)0x08080808u; /*R8 */ *--p_stk =(CPU_STK)0x07070707u; /*R7 */ *--p_stk =(CPU_STK)0x06060606u; /*R6 */ *--p_stk =(CPU_STK)0x05050505u; /*R5 */ *--p_stk =(CPU_STK)0x04040404u; /*R4 */ #if (OS_CPU_ARM_FP_EN == DEF_ENABLED) if ((opt &OS_OPT_TASK_SAVE_FP) != (OS_OPT)0) { *--p_stk =(CPU_STK)0x02000000u; /*FPSCR */ /* Initialize S0-S31 floating point registers */ *--p_stk =(CPU_STK)0x41F80000u; /* S31 */ *--p_stk =(CPU_STK)0x41F00000u; /* S30 */ *--p_stk =(CPU_STK)0x41E80000u; /* S29 */ *--p_stk =(CPU_STK)0x41E00000u; /* S28 */ *--p_stk =(CPU_STK)0x41D80000u; /* S27 */ *--p_stk =(CPU_STK)0x41D00000u; /* S26 */ *--p_stk =(CPU_STK)0x41C80000u; /* S25 */ *--p_stk =(CPU_STK)0x41C00000u; /* S24 */ *--p_stk =(CPU_STK)0x41B80000u; /* S23 */ *--p_stk =(CPU_STK)0x41B00000u; /* S22 */ *--p_stk =(CPU_STK)0x41A80000u; /* S21 */ *--p_stk =(CPU_STK)0x41A00000u; /* S20 */ *--p_stk =(CPU_STK)0x41980000u; /* S19 */ *--p_stk =(CPU_STK)0x41900000u; /* S18 */ *--p_stk =(CPU_STK)0x41880000u; /* S17 */ *--p_stk =(CPU_STK)0x41800000u; /* S16 */ *--p_stk =(CPU_STK)0x41700000u; /* S15 */ *--p_stk =(CPU_STK)0x41600000u; /* S14 */ *--p_stk =(CPU_STK)0x41500000u; /* S13 */ *--p_stk =(CPU_STK)0x41400000u; /* S12 */ *--p_stk =(CPU_STK)0x41300000u; /* S11 */ *--p_stk =(CPU_STK)0x41200000u; /* S10 */ *--p_stk =(CPU_STK)0x41100000u; /* S9 */ *--p_stk =(CPU_STK)0x41000000u; /* S8 */ *--p_stk =(CPU_STK)0x40E00000u; /* S7 */ *--p_stk =(CPU_STK)0x40C00000u; /* S6 */ *--p_stk =(CPU_STK)0x40A00000u; /* S5 */ *--p_stk =(CPU_STK)0x40800000u; /* S4 */ *--p_stk =(CPU_STK)0x40400000u; /* S3 */ *--p_stk =(CPU_STK)0x40000000u; /* S2 */ *--p_stk =(CPU_STK)0x3F800000u; /* S1 */ *--p_stk =(CPU_STK)0x00000000u; /* S0 */ } #endif return (p_stk); } l os_cpu_c.c文件中如下的代码需要做修改,注释掉红色字体部分 void OSTaskSwHook (void) { #if OS_CFG_TASK_PROFILE_EN > 0u CPU_TS ts; #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_TS int_dis_time; #endif #if (OS_CPU_ARM_FP_EN == DEF_ENABLED) if ((OSTCBCurPtr->Opt &OS_OPT_TASK_SAVE_FP) != (OS_OPT)0) { OS_CPU_FP_Reg_Push(OSTCBCurPtr->StkPtr); } if ((OSTCBHighRdyPtr->Opt& OS_OPT_TASK_SAVE_FP) != (OS_OPT)0) { OS_CPU_FP_Reg_Pop(OSTCBHighRdyPtr->StkPtr); } #endif #if OS_CFG_APP_HOOKS_EN > 0u if (OS_AppTaskSwHookPtr !=(OS_APP_HOOK_VOID)0) { (*OS_AppTaskSwHookPtr)(); } #endif #if OS_CFG_TASK_PROFILE_EN > 0u ts = OS_TS_GET(); if (OSTCBCurPtr !=OSTCBHighRdyPtr) { OSTCBCurPtr->CyclesDelta = ts- OSTCBCurPtr->CyclesStart; OSTCBCurPtr->CyclesTotal+= (OS_CYCLES)OSTCBCurPtr->CyclesDelta; } OSTCBHighRdyPtr->CyclesStart= ts; #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN int_dis_time =CPU_IntDisMeasMaxCurReset(); /* Keep track of per-task interrupt disable time */ if(OSTCBCurPtr->IntDisTimeMax < int_dis_time) { OSTCBCurPtr->IntDisTimeMax = int_dis_time; } #endif #if OS_CFG_SCHED_LOCK_TIME_MEAS_EN > 0u /* Keep track of per-task scheduler lock time */ if(OSTCBCurPtr->SchedLockTimeMax < OSSchedLockTimeMaxCur) { OSTCBCurPtr->SchedLockTimeMax = OSSchedLockTimeMaxCur; } OSSchedLockTimeMaxCur =(CPU_TS)0; /*Reset the per-task value */ #endif } 上面的三处修改后,按照上面MDK添加的思路把IAR的工程建立起来,一定要记得关闭FPU,因为我们讲浮点寄存器的入栈和出栈功能删除了,然后编译,链接,并下载程序到V5开发板上面,可以看到4个LED不断的闪烁。 8.4 总结 μCOS-III的移植过程并不难,希望初学的同学一定要动手移植一下,过程中出现问题了解决一下,以后新版本升级了,自己就可以动手升级了。 参考资料: 1.
![]() |
|
|
|
|
|
1139 浏览 0 评论
IaaS+on+DPU(IoD)+下一代高性能算力底座技术白皮书
2201 浏览 0 评论
飞凌嵌入式-ELFBOARD 常用的USB接口及其不同版本介绍第1期
1087 浏览 0 评论
【Vision Board创客营连载体验】RA8D1-Vision Board上OSPI-Flash实践
1561 浏览 0 评论
I.MX6ULL-飞凌 ElfBoard ELF1板卡- 应用层更改引脚复用的方法
3774 浏览 0 评论
65498 浏览 21 评论
嵌入式热门DIY项目:智能机器人开源资料合集(原理图、代码、论文)
67869 浏览 22 评论
57960 浏览 32 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-20 12:09 , Processed in 0.707310 second(s), Total 65, Slave 47 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191