本帖最后由 Eric2013 于 2014-12-20 16:45 编辑
特别说明:
1. 本教程是安富莱电子原创。
2. 安富莱STM32F407开发板资料已经全部开源,开源地址:地址链接
3. 当前共配套300多个实例,4套用户手册。
第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 进入分版块以后,在最上面会有Download的链接:
点击进入后,在网页的最下面可以看到源代码的下载地址:
大家可能已经注意到了左侧是Login,这个的意思是大家需要注册一个账号才可以下载,注册很简单,点击Login弹出下面的界面注册就行。
注册并登陆后上面的截图就会变成下面这样:
这种情况下就可以下载源码了,咱们要下载的是最下面的那个,不过日期有点早,是2012年的了。将这个源码下载下来解压后会看到里面的文件如下(路径:\Micrium\Software\uCOS-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 hasbeen 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标记后,点击进入
进入后看到各IC厂商的地址链接:
我们点击进入意法半导体的链接,可以看到很多已经建立好的工程模板(这里只贴了部分工程):
咱们要下载的是下面的这个工程:
下载好以后,打开此路径:\Micrium\Software,内容如下:
这几个文件就是咱们移植要用到的,本期教程移植代码是使用的这个里面的文件,而没有使用上面下载的源码,主要是因为现在的源码和uC-CPU,uC-LIB有一定的关联性,咱们主要移植的也是uC-OSIII,uC-CPU,uC-LIB这三个文件。 |