硬汉嵌入式论坛

 找回密码
 立即注册
查看: 6537|回复: 7
收起左侧

[μCOS-III] 【uCOS-III教程】第8章 μCOS-III系统移植过程详解

[复制链接]

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
发表于 2014-12-17 19:26:29 | 显示全部楼层 |阅读模式
特别说明:
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的调试组件。如下图所示:
8.1.png


        考虑到初学μCOS-III的同学中使用MDK的比较多,而且μCOS-III有相关的调试工具μC/Probe,功能也比较的强大。我们今后的教程以使用MDK为主,IAR相关的知识也会跟大家讲解。
        下面开始说一下如何从官网下载μCOS-III源码代码以及为STM32配套好的工程代码。先说如何下载源代码:
l 打开Micrium的官方网站:www.micrium.com,并点击下面的图标:
8.2.png


l 进入分版块以后,在最上面会有Download的链接:
8.3.png


点击进入后,在网页的最下面可以看到源代码的下载地址:
8.4.png


大家可能已经注意到了左侧是Login,这个的意思是大家需要注册一个账号才可以下载,注册很简单,点击Login弹出下面的界面注册就行。
8.5.png

        注册并登陆后上面的截图就会变成下面这样:
8.6.png


        这种情况下就可以下载源码了,咱们要下载的是最下面的那个,不过日期有点早,是2012年的了。将这个源码下载下来解压后会看到里面的文件如下(路径:\Micrium\Software\uCOS-III):
8.7.png

        这里咱们重点看一下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 has nowa 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() wherenumber of 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
     on OS_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标记后,点击进入
8.8.png


        进入后看到各IC厂商的地址链接:
8.9.png

        我们点击进入意法半导体的链接,可以看到很多已经建立好的工程模板(这里只贴了部分工程):
8.10.png


        咱们要下载的是下面的这个工程:
8.11.png


        下载好以后,打开此路径:\Micrium\Software,内容如下:
8.12.png

        这几个文件就是咱们移植要用到的,本期教程移植代码是使用的这个里面的文件,而没有使用上面下载的源码,主要是因为现在的源码和uC-CPU,uC-LIB有一定的关联性,咱们主要移植的也是uC-OSIII,uC-CPU,uC-LIB这三个文件。
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2014-12-17 19:47:49 | 显示全部楼层
8.2  源代码移植-MDK
下面开始讲解源代码的移植,这里咱们不一步一步的建立工程了,显得太罗嗦。咱们直接在一个现成的MDK和IAR工程上面建立。工程就使用V5开发板基础篇中的例子:V5-001a_GPIO实验_跑马灯。MDK使用4.54版本,其它高版本的也可以,不过要注意这个问题:http://www.armbbs.cn/forum.php?mod=viewthread&tid=2567

8.2.1      建立工程


       现在开始移植讲解:
l 第一步:在跑马灯工程里面建立文件夹uCOS-III。
8.13.png

并将下面四个文件复制到uCOS-III文件夹里面:
8.14.png


l 第二步:把官方工程此路径下Micrium\\Software\\EvalBoards\\ST\\STM3240G-EVAL\\uCOS-III的8个文件
8.15.png

以及此路径下Micrium\\Software\\EvalBoards\\ST\\STM3240G-EVAL\\uCOS-III\\KeilMDK的两个文件
8.16.png

复制到跑马灯工程里面的此路径下:V5-001a_GPIO实验_跑马灯\\User。
8.17.png

工程中需要的文件已经都复制到工程中了,下一步就是将这些文件添加到工程里面,并添加头文件路径。
l 第三步:在工程的左侧再建立四个组用于添加相应文件。
8.18.png

Ø uC/CPU中添加如下6个文件,这6个文件位于路径:V5-001a_GPIO实验_跑马灯\\uCOS-III\\uC-LIB和路径V5-001a_GPIO实验_跑马灯\\uCOS-III\\uC-LIB\\Ports\\ARM-Cortex-M4\\RealView下面
8.19.png

Ø uC/Lib中添加如下10个文件,这10个文件位于路径V5-001a_GPIO实验_跑马灯\\uCOS-III\\uC-CPU和路径V5-001a_GPIO实验_跑马灯\\uCOS-III\\uC-CPU\\ARM-Cortex-M4\\RealView 下面
8.20.png

Ø uC/OS-III Source中添加如下20个文件,这20个文件位于路径:V5-001a_GPIO实验_跑马灯\\uCOS-III\\uCOS-III\\Source 下面
8.21.png

Ø uC/OS-III Port中添加如下3个文件,这3个文件位于路径:V5-001a_GPIO实验_跑马灯\\uCOS-III\\uCOS-III\\Ports\\ARM-Cortex-M4\\Generic\\RealView 下面
8.22.png

Ø User中添加如下8个文件,这8个文件位于路径:V5-001a_GPIO实验_跑马灯\\User 下面
8.23.png

        上面这些文件添加完以后,一个完整的工程就算建立了,下面需要添加一下头文件的路径:
8.24.png
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2014-12-17 19:52:46 | 显示全部楼层
8.2.2      文件修改
    上面的工程建立好以后,修改部分文件后就可以下载到V5开发板运行了,需要修改的主要有以下几个文件:
l main.c文件,用下面的内容覆盖原有内容,这里主要是建立4个LED闪烁的任务。
  1. /*
  2. *********************************************************************************************************
  3. *                                    
  4. *    模块名称 : 主程序模块
  5. *    文件名称 : main.c
  6. *    版    本 : V1.0
  7. *    说    明 : 例程
  8. *    修改记录 :
  9. *        版本号   日期         作者          说明
  10. *       v1.0    2014-02-27  Eric2013   ST固件库V1.3.0版本
  11. *                                      uCOS-III版本3.03.01
  12. *
  13. *   Copyright (C), 2013-2014, 安富莱电子 www.armfly.com
  14. *
  15. *********************************************************************************************************
  16. */
  17. #include  <includes.h>
  18. /*
  19. *********************************************************************************************************
  20. *                                       LOCAL GLOBAL VARIABLES
  21. *********************************************************************************************************
  22. */
  23.                                                               
  24. static  OS_TCB   AppTaskStartTCB;
  25. static  CPU_STK  AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE];
  26. static  OS_TCB   AppTaskUpdateTCB;
  27. static  CPU_STK  AppTaskUpdateStk[APP_CFG_TASK_UPDATE_STK_SIZE];
  28. static  OS_TCB   AppTaskCOMTCB;
  29. static  CPU_STK  AppTaskCOMStk[APP_CFG_TASK_COM_STK_SIZE];
  30. static  OS_TCB   AppTaskUserIFTCB;
  31. static  CPU_STK  AppTaskUserIFStk[APP_CFG_TASK_USER_IF_STK_SIZE];
  32. /*
  33. *********************************************************************************************************
  34. *                                         FUNCTION PROTOTYPES
  35. *********************************************************************************************************
  36. */
  37. static  void  AppTaskCreate         (void);
  38. static  void  AppTaskStart          (void     *p_arg);
  39. static void   AppTaskUserIF         (void     *p_arg);
  40. static void   AppTaskCOM             (void     *p_arg);
  41. /*
  42. *********************************************************************************************************
  43. *    函 数 名: main
  44. *    功能说明: 标准c程序入口。
  45. *    形    参:无
  46. *    返 回 值: 无
  47. *********************************************************************************************************
  48. */
  49. int main(void)
  50. {
  51.     OS_ERR  err;
  52. //    BSP_IntDisAll();                                          /* Disable all interrupts.                              */
  53.    
  54.     OSInit(&err);                                         /* Init uC/OS-III.          */
  55.      OSTaskCreate((OS_TCB       *)&AppTaskStartTCB,       /* Create the start task         */
  56.                  (CPU_CHAR     *)"App Task Start",
  57.                  (OS_TASK_PTR   )AppTaskStart,
  58.                  (void         *)0,
  59.                  (OS_PRIO       )APP_CFG_TASK_START_PRIO,
  60.                  (CPU_STK      *)&AppTaskStartStk[0],
  61.                  (CPU_STK_SIZE  )APP_CFG_TASK_START_STK_SIZE / 10,
  62.                  (CPU_STK_SIZE  )APP_CFG_TASK_START_STK_SIZE,
  63.                  (OS_MSG_QTY    )0,
  64.                  (OS_TICK       )0,
  65.                  (void         *)0,
  66.                  (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  67.                  (OS_ERR       *)&err);
  68.     OSStart(&err);                                 /* Start multitasking (i.e. give control to uC/OS-III). */
  69.    
  70.     (void)&err;
  71.    
  72.     return (0);
  73. }
  74. /*
  75. *********************************************************************************************************
  76. *    函 数 名: AppTaskStart
  77. *    功能说明: 这是一个启动任务,在多任务系统启动后,必须初始化滴答计数器(在BSP_Init中实现)
  78. *    形    参:p_arg 是在创建该任务时传递的形参
  79. *    返 回 值: 无
  80.      优 先 级:2
  81. *********************************************************************************************************
  82. */
  83. static  void  AppTaskStart (void *p_arg)
  84. {
  85.      OS_ERR      err;
  86.    (void)p_arg;
  87.      bsp_Init();
  88.      CPU_Init();
  89.      BSP_Tick_Init();
  90. //   Mem_Init();                           
  91. //  Math_Init();                        
  92. #if OS_CFG_STAT_TASK_EN > 0u
  93.      OSStatTaskCPUUsageInit(&err);  
  94. #endif
  95. #ifdef CPU_CFG_INT_DIS_MEAS_EN
  96.     CPU_IntDisMeasMaxCurReset();
  97. #endif
  98.                                        
  99.     AppTaskCreate();                                          
  100.     while (1)
  101.      {                                       
  102.          bsp_LedToggle(1);
  103.          OSTimeDly(100, OS_OPT_TIME_DLY, &err);
  104.     }
  105. }
  106. /*
  107. *********************************************************************************************************
  108. *    函 数 名: AppTaskGUIUpdate
  109. *    功能说明: LED2闪烁   
  110. *    形    参:p_arg 是在创建该任务时传递的形参
  111. *    返 回 值: 无
  112.      优 先 级:3
  113. *********************************************************************************************************
  114. */
  115. static void AppTaskGUIUpdate(void *p_arg)
  116. {
  117.      OS_ERR      err;
  118.    
  119.      (void)p_arg;
  120.          
  121.      while(1)
  122.      {   
  123.          bsp_LedToggle(2);
  124.          OSTimeDly(200, OS_OPT_TIME_DLY, &err);                                                                                                         
  125.      }  
  126. }
  127. /*
  128. *********************************************************************************************************
  129. *    函 数 名: AppTaskCom
  130. *    功能说明: LED3闪烁   
  131. *    形    参:p_arg 是在创建该任务时传递的形参
  132. *    返 回 值: 无
  133.      优 先 级:3
  134. *********************************************************************************************************
  135. */
  136. static void AppTaskCOM(void *p_arg)
  137. {   
  138.      OS_ERR      err;
  139.      (void)p_arg;
  140.       
  141.      while(1)
  142.      {
  143.          bsp_LedToggle(3);
  144.          OSTimeDly(300, OS_OPT_TIME_DLY, &err);   
  145.      }
  146.                                                                                                       
  147.   
  148. }
  149. /*
  150. *********************************************************************************************************
  151. *    函 数 名: AppTaskUserIF
  152. *    功能说明: LED4闪烁
  153. *    形    参:p_arg 是在创建该任务时传递的形参
  154. *    返 回 值: 无
  155.      优 先 级:2
  156. *********************************************************************************************************
  157. */
  158. static void AppTaskUserIF(void *p_arg)
  159. {
  160.      OS_ERR      err;
  161.      while (1)
  162.      {      
  163.         bsp_LedToggle(4);
  164.          OSTimeDly(100, OS_OPT_TIME_DLY, &err);   
  165.      }
  166. }
  167. /*
  168. *********************************************************************************************************
  169. *    函 数 名: AppTaskCreate
  170. *    功能说明: 创建应用任务
  171. *    形    参:p_arg 是在创建该任务时传递的形参
  172. *    返 回 值: 无
  173. *********************************************************************************************************
  174. */
  175. static  void  AppTaskCreate (void)
  176. {
  177.      OS_ERR      err;
  178.    
  179.      /***********************************/
  180.      OSTaskCreate((OS_TCB       *)&AppTaskUpdateTCB,            
  181.                  (CPU_CHAR     *)"App Task Update",
  182.                  (OS_TASK_PTR   )AppTaskGUIUpdate,
  183.                  (void         *)0,
  184.                  (OS_PRIO       )APP_CFG_TASK_UPDATE_PRIO,
  185.                  (CPU_STK      *)&AppTaskUpdateStk[0],
  186.                  (CPU_STK_SIZE  )APP_CFG_TASK_UPDATE_STK_SIZE / 10,
  187.                  (CPU_STK_SIZE  )APP_CFG_TASK_UPDATE_STK_SIZE,
  188.                  (OS_MSG_QTY    )1,
  189.                  (OS_TICK       )0,
  190.                  (void         *)0,
  191.                  (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  192.                  (OS_ERR       *)&err);
  193.    
  194.      /***********************************/
  195.      OSTaskCreate((OS_TCB       *)&AppTaskCOMTCB,           
  196.                  (CPU_CHAR     *)"App Task COM",
  197.                  (OS_TASK_PTR   )AppTaskCOM,
  198.                  (void         *)0,
  199.                  (OS_PRIO       )APP_CFG_TASK_COM_PRIO,
  200.                  (CPU_STK      *)&AppTaskCOMStk[0],
  201.                  (CPU_STK_SIZE  )APP_CFG_TASK_COM_STK_SIZE / 10,
  202.                  (CPU_STK_SIZE  )APP_CFG_TASK_COM_STK_SIZE,
  203.                  (OS_MSG_QTY    )2,
  204.                  (OS_TICK       )0,
  205.                  (void         *)0,
  206.                  (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  207.                  (OS_ERR       *)&err);
  208.    
  209.      /***********************************/
  210.      OSTaskCreate((OS_TCB       *)&AppTaskUserIFTCB,            
  211.                  (CPU_CHAR     *)"App Task UserIF",
  212.                  (OS_TASK_PTR   )AppTaskUserIF,
  213.                  (void         *)0,
  214.                  (OS_PRIO       )APP_CFG_TASK_USER_IF_PRIO,
  215.                  (CPU_STK      *)&AppTaskUserIFStk[0],
  216.                  (CPU_STK_SIZE  )APP_CFG_TASK_USER_IF_STK_SIZE / 10,
  217.                  (CPU_STK_SIZE  )APP_CFG_TASK_USER_IF_STK_SIZE,
  218.                  (OS_MSG_QTY    )0,
  219.                  (OS_TICK       )0,
  220.                  (void         *)0,
  221.                  (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  222.                  (OS_ERR       *)&err);
  223.                     
  224. }
  225. /***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
复制代码
l includes文件,主要是添加必要的头文件,用下面的内容覆盖原有内容
  1. /*
  2. *********************************************************************************************************
  3. *                                              EXAMPLE CODE
  4. *
  5. *                             (c) Copyright 2013; Micrium, Inc.; Weston, FL
  6. *
  7. *                   All rights reserved.  Protected by international copyright laws.
  8. *                   Knowledge of the source code may not be used to write a similar
  9. *                   product.  This file may only be used in accordance with a license
  10. *                   and should not be redistributed in any way.
  11. *********************************************************************************************************
  12. */
  13. #ifndef  INCLUDES_PRESENT
  14. #define  INCLUDES_PRESENT
  15. /*
  16. *********************************************************************************************************
  17. *                                         STANDARD LIBRARIES
  18. *********************************************************************************************************
  19. */
  20. #include  <stdarg.h>
  21. #include  <stdio.h>
  22. #include  <stdlib.h>
  23. #include  <math.h>
  24. /*
  25. *********************************************************************************************************
  26. *                                              LIBRARIES
  27. *********************************************************************************************************
  28. */
  29. #include  <cpu.h>
  30. #include  <lib_def.h>
  31. #include  <lib_ascii.h>
  32. #include  <lib_math.h>
  33. #include  <lib_mem.h>
  34. #include  <lib_str.h>
  35. /*
  36. *********************************************************************************************************
  37. *                                                 OS
  38. *********************************************************************************************************
  39. */
  40. #include  <os.h>
  41. /*
  42. *********************************************************************************************************
  43. *                                              APP / BSP
  44. *********************************************************************************************************
  45. */
  46. #include  <bsp.h>
  47. #include  "app_cfg.h"
  48. /*
  49. *********************************************************************************************************
  50. *                                               SERIAL
  51. *********************************************************************************************************
  52. */
  53. #if (APP_CFG_SERIAL_EN == DEF_ENABLED)
  54. #include  <app_serial.h>
  55. #endif
  56. /*
  57. *********************************************************************************************************
  58. *                                            INCLUDES END
  59. *********************************************************************************************************
  60. */
  61. #endif
复制代码

努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2014-12-17 19:56:36 | 显示全部楼层
(续)8.2.2      文件修改

l 修改bps.c和bsp.h文件。这个文件主要是初始化相关的驱动,用下面的内容覆盖原有内容
  1. /*
  2. *********************************************************************************************************
  3. *
  4. *    模块名称 : BSP模块(For STM32F4XX)
  5. *    文件名称 : bsp.c
  6. *    版    本 : V1.1
  7. *    说    明 : 这是硬件底层驱动程序的主文件。每个c文件可以 #include "bsp.h" 来包含所有的外设驱动模块。
  8. *                bsp = Borad surport packet 板级支持包
  9. *    修改记录 :
  10. *        版本号  日期        作者     说明
  11. *        V1.0    2013-03-01  armfly   正式发布
  12. *        V1.1    2013-06-20  armfly   规范注释,添加必要说明
  13. *
  14. *    Copyright (C), 2013-2014, 安富莱电子 www.armfly.com
  15. *
  16. *********************************************************************************************************
  17. */
  18. #include  <includes.h>
  19. void NVIC_Configuration(void);
  20. /*
  21. *********************************************************************************************************
  22. *                                             REGISTERS
  23. *********************************************************************************************************
  24. */
  25. #define  BSP_REG_DEM_CR                       (*(CPU_REG32 *)0xE000EDFC)
  26. #define  BSP_REG_DWT_CR                       (*(CPU_REG32 *)0xE0001000)
  27. #define  BSP_REG_DWT_CYCCNT                   (*(CPU_REG32 *)0xE0001004)
  28. #define  BSP_REG_DBGMCU_CR                    (*(CPU_REG32 *)0xE0042004)
  29. /*
  30. *********************************************************************************************************
  31. *                                            REGISTER BITS
  32. *********************************************************************************************************
  33. */
  34. #define  BSP_DBGMCU_CR_TRACE_IOEN_MASK                   0x10
  35. #define  BSP_DBGMCU_CR_TRACE_MODE_ASYNC                  0x00
  36. #define  BSP_DBGMCU_CR_TRACE_MODE_SYNC_01                0x40
  37. #define  BSP_DBGMCU_CR_TRACE_MODE_SYNC_02                0x80
  38. #define  BSP_DBGMCU_CR_TRACE_MODE_SYNC_04                0xC0
  39. #define  BSP_DBGMCU_CR_TRACE_MODE_MASK                   0xC0
  40. #define  BSP_BIT_DEM_CR_TRCENA                    DEF_BIT_24
  41. #define  BSP_BIT_DWT_CR_CYCCNTENA                 DEF_BIT_00
  42. /*
  43. *********************************************************************************************************
  44. *    函 数 名: bsp_Init
  45. *    功能说明: 初始化硬件设备
  46. *    形    参:无
  47. *    返 回 值: 无
  48. *********************************************************************************************************
  49. */
  50. void bsp_Init(void)
  51. {
  52.      NVIC_Configuration();  /* 中断优先级分组配置 */
  53.    
  54.      bsp_InitUart();       /* 初始化串口 */
  55.      bsp_InitLed();            /* 初始LED指示灯端口 */
  56. //   bsp_InitKey();            /* 按键初始化 */
  57. #ifdef TRACE_EN                                                 /* See project / compiler preprocessor options.         */
  58.     BSP_CPU_REG_DBGMCU_CR |=  BSP_DBGMCU_CR_TRACE_IOEN_MASK;    /* Enable tracing (see Note #2).                        */
  59.     BSP_CPU_REG_DBGMCU_CR &= ~BSP_DBGMCU_CR_TRACE_MODE_MASK;    /* Clr trace mode sel bits.                             */
  60.     BSP_CPU_REG_DBGMCU_CR |=  BSP_DBGMCU_CR_TRACE_MODE_SYNC_04; /* Cfg trace mode to synch 4-bit.                       */
  61. #endif
  62. }
  63. /*
  64. *********************************************************************************************************
  65. *    函 数 名: NVIC_Configuration
  66. *    功能说明: 中断优先级配置,这里先把优先级分组分配好,然后在
  67. *               具体的模块里面实现优先级配置
  68. *    形    参:无
  69. *    返 回 值: 无
  70. *********************************************************************************************************
  71. */
  72. void NVIC_Configuration(void)
  73. {            
  74.      /* 设置NVIC优先级分组为Group2:0-3抢占式优先级,0-3的响应式优先级 */
  75.      NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
  76. }
  77. /*
  78. *********************************************************************************************************
  79. *                                            BSP_CPU_ClkFreq()
  80. *
  81. * Description : Read CPU registers to determine the CPU clock frequency of the chip.
  82. *
  83. * Argument(s) : none.
  84. *
  85. * Return(s)   : The CPU clock frequency, in Hz.
  86. *
  87. * Caller(s)   : Application.
  88. *
  89. * Note(s)     : none.
  90. *********************************************************************************************************
  91. */
  92. CPU_INT32U  BSP_CPU_ClkFreq (void)
  93. {
  94.     RCC_ClocksTypeDef  rcc_clocks;
  95.     RCC_GetClocksFreq(&rcc_clocks);
  96.     return ((CPU_INT32U)rcc_clocks.HCLK_Frequency);
  97. }
  98. /*
  99. *********************************************************************************************************
  100. *                                            BSP_Tick_Init()
  101. *
  102. * Description : Initialize all the peripherals that required OS Tick services (OS initialized)
  103. *
  104. * Argument(s) : none.
  105. *
  106. * Return(s)   : none.
  107. *
  108. * Caller(s)   : Application.
  109. *
  110. * Note(s)     : none.
  111. *********************************************************************************************************
  112. */
  113. void BSP_Tick_Init (void)
  114. {
  115.     CPU_INT32U  cpu_clk_freq;
  116.     CPU_INT32U  cnts;
  117.    
  118.     cpu_clk_freq = BSP_CPU_ClkFreq();                           /* Determine SysTick reference freq.                    */
  119.    
  120. #if (OS_VERSION >= 30000u)
  121.     cnts  = cpu_clk_freq / (CPU_INT32U)OSCfg_TickRate_Hz;       /* Determine nbr SysTick increments.                    */
  122. #else
  123.     cnts  = cpu_clk_freq / (CPU_INT32U)OS_TICKS_PER_SEC;        /* Determine nbr SysTick increments.                    */
  124. #endif
  125.    
  126.     OS_CPU_SysTickInit(cnts);                                 /* 这里默认的是最高优先级,根据实际情况修改             */
  127. //   SysTick_Config(cnts);   //这里默认的是最低优先级
  128. }
  129. /*
  130. *********************************************************************************************************
  131. *                                          CPU_TS_TmrInit()
  132. *
  133. * Description : Initialize & start CPU timestamp timer.
  134. *
  135. * Argument(s) : none.
  136. *
  137. * Return(s)   : none.
  138. *
  139. * Caller(s)   : CPU_TS_Init().
  140. *
  141. *               This function is an INTERNAL CPU module function & MUST be implemented by application/
  142. *               BSP function(s) [see Note #1] but MUST NOT be called by application function(s).
  143. *
  144. * Note(s)     : (1) CPU_TS_TmrInit() is an application/BSP function that MUST be defined by the developer
  145. *                   if either of the following CPU features is enabled :
  146. *
  147. *                   (a) CPU timestamps
  148. *                   (b) CPU interrupts disabled time measurements
  149. *
  150. *                   See 'cpu_cfg.h  CPU TIMESTAMP CONFIGURATION  Note #1'
  151. *                     & 'cpu_cfg.h  CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION  Note #1a'.
  152. *
  153. *               (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
  154. *                       data type.
  155. *
  156. *                       (1) If timer has more bits, truncate timer values' higher-order bits greater
  157. *                           than the configured 'CPU_TS_TMR' timestamp timer data type word size.
  158. *
  159. *                       (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
  160. *                           timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
  161. *                           configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
  162. *
  163. *                           In other words, if timer size is not a binary-multiple of 8-bit octets
  164. *                           (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
  165. *                           octet word size SHOULD be configured (e.g. to 16-bits).  However, the
  166. *                           minimum supported word size for CPU timestamp timers is 8-bits.
  167. *
  168. *                       See also 'cpu_cfg.h   CPU TIMESTAMP CONFIGURATION  Note #2'
  169. *                              & 'cpu_core.h  CPU TIMESTAMP DATA TYPES     Note #1'.
  170. *
  171. *                   (b) Timer SHOULD be an 'up'  counter whose values increase with each time count.
  172. *
  173. *                   (c) When applicable, timer period SHOULD be less than the typical measured time
  174. *                       but MUST be less than the maximum measured time; otherwise, timer resolution
  175. *                       inadequate to measure desired times.
  176. *
  177. *                   See also 'CPU_TS_TmrRd()  Note #2'.
  178. *********************************************************************************************************
  179. */
  180. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  181. void  CPU_TS_TmrInit (void)
  182. {
  183.     CPU_INT32U  fclk_freq;
  184.     fclk_freq = BSP_CPU_ClkFreq();
  185.     BSP_REG_DEM_CR     |= (CPU_INT32U)BSP_BIT_DEM_CR_TRCENA;    /* Enable Cortex-M4's DWT CYCCNT reg.                   */
  186.     BSP_REG_DWT_CYCCNT  = (CPU_INT32U)0u;
  187.     BSP_REG_DWT_CR     |= (CPU_INT32U)BSP_BIT_DWT_CR_CYCCNTENA;
  188.     CPU_TS_TmrFreqSet((CPU_TS_TMR_FREQ)fclk_freq);
  189. }
  190. #endif
  191. /*
  192. *********************************************************************************************************
  193. *                                           CPU_TS_TmrRd()
  194. *
  195. * Description : Get current CPU timestamp timer count value.
  196. *
  197. * Argument(s) : none.
  198. *
  199. * Return(s)   : Timestamp timer count (see Notes #2a & #2b).
  200. *
  201. * Caller(s)   : CPU_TS_Init(),
  202. *               CPU_TS_Get32(),
  203. *               CPU_TS_Get64(),
  204. *               CPU_IntDisMeasStart(),
  205. *               CPU_IntDisMeasStop().
  206. *
  207. *               This function is an INTERNAL CPU module function & MUST be implemented by application/
  208. *               BSP function(s) [see Note #1] but SHOULD NOT be called by application function(s).
  209. *
  210. * Note(s)     : (1) CPU_TS_TmrRd() is an application/BSP function that MUST be defined by the developer
  211. *                   if either of the following CPU features is enabled :
  212. *
  213. *                   (a) CPU timestamps
  214. *                   (b) CPU interrupts disabled time measurements
  215. *
  216. *                   See 'cpu_cfg.h  CPU TIMESTAMP CONFIGURATION  Note #1'
  217. *                     & 'cpu_cfg.h  CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION  Note #1a'.
  218. *
  219. *               (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
  220. *                       data type.
  221. *
  222. *                       (1) If timer has more bits, truncate timer values' higher-order bits greater
  223. *                           than the configured 'CPU_TS_TMR' timestamp timer data type word size.
  224. *
  225. *                       (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
  226. *                           timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
  227. *                           configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
  228. *
  229. *                           In other words, if timer size is not a binary-multiple of 8-bit octets
  230. *                           (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
  231. *                           octet word size SHOULD be configured (e.g. to 16-bits).  However, the
  232. *                           minimum supported word size for CPU timestamp timers is 8-bits.
  233. *
  234. *                       See also 'cpu_cfg.h   CPU TIMESTAMP CONFIGURATION  Note #2'
  235. *                              & 'cpu_core.h  CPU TIMESTAMP DATA TYPES     Note #1'.
  236. *
  237. *                   (b) Timer SHOULD be an 'up'  counter whose values increase with each time count.
  238. *
  239. *                       (1) If timer is a 'down' counter whose values decrease with each time count,
  240. *                           then the returned timer value MUST be ones-complemented.
  241. *
  242. *                   (c) (1) When applicable, the amount of time measured by CPU timestamps is
  243. *                           calculated by either of the following equations :
  244. *
  245. *                           (A) Time measured  =  Number timer counts  *  Timer period
  246. *
  247. *                                   where
  248. *
  249. *                                       Number timer counts     Number of timer counts measured
  250. *                                       Timer period            Timer's period in some units of
  251. *                                                                   (fractional) seconds
  252. *                                       Time measured           Amount of time measured, in same
  253. *                                                                   units of (fractional) seconds
  254. *                                                                   as the Timer period
  255. *
  256. *                                                  Number timer counts
  257. *                           (B) Time measured  =  ---------------------
  258. *                                                    Timer frequency
  259. *
  260. *                                   where
  261. *
  262. *                                       Number timer counts     Number of timer counts measured
  263. *                                       Timer frequency         Timer's frequency in some units
  264. *                                                                   of counts per second
  265. *                                       Time measured           Amount of time measured, in seconds
  266. *
  267. *                       (2) Timer period SHOULD be less than the typical measured time but MUST be less
  268. *                           than the maximum measured time; otherwise, timer resolution inadequate to
  269. *                           measure desired times.
  270. *********************************************************************************************************
  271. */
  272. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  273. CPU_TS_TMR  CPU_TS_TmrRd (void)
  274. {
  275.     CPU_TS_TMR  ts_tmr_cnts;
  276.                                                                
  277.     ts_tmr_cnts = (CPU_TS_TMR)BSP_REG_DWT_CYCCNT;
  278.     return (ts_tmr_cnts);
  279. }
  280. #endif
  281. /*
  282. *********************************************************************************************************
  283. *                                         CPU_TSxx_to_uSec()
  284. *
  285. * Description : Convert a 32-/64-bit CPU timestamp from timer counts to microseconds.
  286. *
  287. * Argument(s) : ts_cnts   CPU timestamp (in timestamp timer counts [see Note #2aA]).
  288. *
  289. * Return(s)   : Converted CPU timestamp (in microseconds           [see Note #2aD]).
  290. *
  291. * Caller(s)   : Application.
  292. *
  293. *               This function is an (optional) CPU module application programming interface (API)
  294. *               function which MAY be implemented by application/BSP function(s) [see Note #1] &
  295. *               MAY be called by application function(s).
  296. *
  297. * Note(s)     : (1) CPU_TS32_to_uSec()/CPU_TS64_to_uSec() are application/BSP functions that MAY be
  298. *                   optionally defined by the developer when either of the following CPU features is
  299. *                   enabled :
  300. *
  301. *                   (a) CPU timestamps
  302. *                   (b) CPU interrupts disabled time measurements
  303. *
  304. *                   See 'cpu_cfg.h  CPU TIMESTAMP CONFIGURATION  Note #1'
  305. *                     & 'cpu_cfg.h  CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION  Note #1a'.
  306. *
  307. *               (2) (a) The amount of time measured by CPU timestamps is calculated by either of
  308. *                       the following equations :
  309. *
  310. *                                                                        10^6 microseconds
  311. *                       (1) Time measured  =   Number timer counts   *  -------------------  *  Timer period
  312. *                                                                            1 second
  313. *
  314. *                                              Number timer counts       10^6 microseconds
  315. *                       (2) Time measured  =  ---------------------  *  -------------------
  316. *                                                Timer frequency             1 second
  317. *
  318. *                               where
  319. *
  320. *                                   (A) Number timer counts     Number of timer counts measured
  321. *                                   (B) Timer frequency         Timer's frequency in some units
  322. *                                                                   of counts per second
  323. *                                   (C) Timer period            Timer's period in some units of
  324. *                                                                   (fractional)  seconds
  325. *                                   (D) Time measured           Amount of time measured,
  326. *                                                                   in microseconds
  327. *
  328. *                   (b) Timer period SHOULD be less than the typical measured time but MUST be less
  329. *                       than the maximum measured time; otherwise, timer resolution inadequate to
  330. *                       measure desired times.
  331. *
  332. *                   (c) Specific implementations may convert any number of CPU_TS32 or CPU_TS64 bits
  333. *                       -- up to 32 or 64, respectively -- into microseconds.
  334. *********************************************************************************************************
  335. */
  336. #if (CPU_CFG_TS_32_EN == DEF_ENABLED)
  337. CPU_INT64U  CPU_TS32_to_uSec (CPU_TS32  ts_cnts)
  338. {
  339.     CPU_INT64U  ts_us;
  340.     CPU_INT64U  fclk_freq;
  341.    
  342.     fclk_freq = BSP_CPU_ClkFreq();   
  343.     ts_us     = ts_cnts / (fclk_freq / DEF_TIME_NBR_uS_PER_SEC);
  344.     return (ts_us);
  345. }
  346. #endif
  347. #if (CPU_CFG_TS_64_EN == DEF_ENABLED)
  348. CPU_INT64U  CPU_TS64_to_uSec (CPU_TS64  ts_cnts)
  349. {
  350.     CPU_INT64U  ts_us;
  351.     CPU_INT64U  fclk_freq;
  352.    
  353.     fclk_freq = BSP_CPU_ClkFreq();   
  354.     ts_us     = ts_cnts / (fclk_freq / DEF_TIME_NBR_uS_PER_SEC);
  355.     return (ts_us);
  356. }
  357. #endif
  358. /***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
  359. /*
  360. *********************************************************************************************************
  361. *
  362. *    模块名称 : BSP模块
  363. *    文件名称 : bsp.h
  364. *    说    明 : 这是底层驱动模块所有的h文件的汇总文件。 应用程序只需 #include bsp.h 即可,
  365. *               不需要#include 每个模块的 h 文件
  366. *
  367. *    Copyright (C), 2013-2014, 安富莱电子 www.armfly.com
  368. *
  369. *********************************************************************************************************
  370. */
  371. #ifndef _BSP_H_
  372. #define _BSP_H
  373. #define STM32_V5
  374. //#define STM32_X3
  375. /* 检查是否定义了开发板型号 */
  376. #if !defined (STM32_V5) && !defined (STM32_X3)
  377.      #error "Please define the board model : STM32_X3 or STM32_V5"
  378. #endif
  379. /* 定义 BSP 版本号 */
  380. #define __STM32F1_BSP_VERSION        "1.1"
  381. /* 开关全局中断的宏 */
  382. #define ENABLE_INT()   __set_PRIMASK(0)   /* 使能全局中断 */
  383. #define DISABLE_INT()  __set_PRIMASK(1)   /* 禁止全局中断 */
  384. /* 这个宏仅用于调试阶段排错 */
  385. #define BSP_Printf     printf
  386. //#define BSP_Printf(...)
  387. #include "stm32f4xx.h"
  388. #include <stdio.h>
  389. #include <string.h>
  390. #ifndef TRUE
  391.      #define TRUE  1
  392. #endif
  393. #ifndef FALSE
  394.      #define FALSE 0
  395. #endif
  396. /* 通过取消注释或者添加注释的方式控制是否包含底层驱动模块 */
  397. #include "bsp_uart_fifo.h"
  398. #include "bsp_led.h"
  399. #include "bsp_timer.h"
  400. #include "bsp_key.h"
  401. #include "bsp_dwt.h"
  402. //#include "bsp_spi_flash.h"
  403. //#include "bsp_cpu_flash.h"
  404. //#include "bsp_sdio_sd.h"
  405. //#include "bsp_i2c_gpio.h"
  406. //#include "bsp_eeprom_24xx.h"
  407. //#include "bsp_si4730.h"
  408. //#include "bsp_hmc5883l.h"
  409. //#include "bsp_mpu6050.h"
  410. //#include "bsp_bh1750.h"
  411. //#include "bsp_bmp085.h"
  412. //#include "bsp_wm8978.h"
  413. //#include "bsp_fsmc_sram.h"
  414. //#include "bsp_nand_flash.h"
  415. //#include "bsp_nor_flash.h"
  416. //#include "LCD_RA8875.h"
  417. //#include "LCD_SPFD5420.h"
  418. //#include "bsp_touch.h"
  419. //#include "bsp_camera.h"
  420. //#include "bsp_ad7606.h"
  421. //#include "bsp_gps.h"
  422. //#include "bsp_oled.h"
  423. //#include "bsp_mg323.h"
  424. /* 提供给其他C文件调用的函数 */
  425. void bsp_Init(void);
  426. void bsp_Idle(void);
  427. void BSP_Tick_Init (void);
  428. #endif
  429. /***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
复制代码
l startup_stm32f40_41xxx.s文件,修改这个文件中Systick和PendSV中断入口名,以便于和μCOS-III中命名统一。
  1. DCD     OS_CPU_PendSVHandler
  2.                 DCD     OS_CPU_SysTickHandler
  3. OS_CPU_PendSVHandler  PROC
  4.                 EXPORT  OS_CPU_PendSVHandler       [WEAK]
  5.                 B       .
  6.                 ENDP
  7. OS_CPU_SysTickHandler PROC
  8.                 EXPORT  OS_CPU_SysTickHandler      [WEAK]
  9.                 B       .
  10.                 ENDP
复制代码
l 最后一步是去掉BSP文件组中的bsp_timer.c文件,因为这个文件是SysTick的驱动和μCOS-III中的驱动冲突了。同时要关闭FPU,因为咱们移植的port文件里面没有做FPU的支持。
8.25.png



上面这几步完成后,编译,链接,下载程序到开发板上,可以看到4个LED闪烁。至此μCOS-III的简单移植就完成了。
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2014-12-17 19:58:29 | 显示全部楼层
8.3  源代码移植-IAR
    官方移植的IAR版本代码中加入了FPU的支持,不过加入的代码完全不符合浮点寄存器的入栈和出栈,也就是说他们提供的代码不适合在Cortex-M4F内核的微控制器中使用。所以我们需要删除并修改部分的代码,要删除并修改的代码如下:
l os_cpu_a.asm 文件中下面的代码要删除
#ifdef __ARMVFP__
    PUBLIC  OS_CPU_FP_Reg_Push
    PUBLIC  OS_CPU_FP_Reg_Pop
#endif
;********************************************************************************************************
;                                              EQUATES
;********************************************************************************************************
NVIC_INT_CTRL   EQU     0xE000ED04                              ; Interruptcontrol state register.
NVIC_SYSPRI14   EQU     0xE000ED22                              ; System priorityregister (priority 14).
NVIC_PENDSV_PRI EQU           0xFF                              ; PendSV priorityvalue (lowest).
NVIC_PENDSVSET  EQU     0x10000000                              ; Value totrigger PendSV exception.
;********************************************************************************************************
;                                    CODE GENERATION DIRECTIVES
;********************************************************************************************************
    RSEG CODE:CODE:NOROOT(2)
    THUMB
#ifdef __ARMVFP__
;********************************************************************************************************
;                                  FLOATING POINT REGISTERS PUSH
;                            void  OS_CPU_FP_Reg_Push(CPU_STK  *stkPtr)
;
; Note(s) : 1) This function saves S0-S31, and FPSCR registers of theFloating Point Unit.
;
;           2) Pseudo-code is:
;              a) Get FPSCR registervalue;
;              b) Push value onprocess stack;
;              c) Push remainingregs S0-S31 on process stack;
;              d) UpdateOSTCBCurPtr->StkPtr;
;********************************************************************************************************
OS_CPU_FP_Reg_Push
    MRS     R1, PSP                                             SP is process stack pointer
    CBZ     R1, OS_CPU_FP_nosave                                ; Skip FPregister save the first time
    VMRS    R1, FPSCR
    STR R1, [R0, #-4]!
    VSTMDB  R0!, {S0-S31}
    LDR     R1, =OSTCBCurPtr
    LDR     R2, [R1]
    STR     R0, [R2]
OS_CPU_FP_nosave
    BX      LR
;********************************************************************************************************
;                                  FLOATING POINT REGISTERS POP
;                            void  OS_CPU_FP_Reg_Pop(CPU_STK  *stkPtr)
;
; Note(s) : 1) This function restores S0-S31, and FPSCR registers of theFloating Point Unit.
;
;           2) Pseudo-code is:
;              a) Restore regsS0-S31 of new process stack;
;              b) Restore FPSCR regvalue
;              c) UpdateOSTCBHighRdyPtr->StkPtr pointer of new proces stack;
;********************************************************************************************************
OS_CPU_FP_Reg_Pop
    VLDMIA  R0!, {S0-S31}
    LDMIA   R0!, {R1}
   VMSR    FPSCR, R1
    LDR     R1, =OSTCBHighRdyPtr
    LDR     R2, [R1]
    STR     R0, [R2]
    BX      LR
#endif

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 ifauto-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不断的闪烁。
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2014-12-17 20:00:21 | 显示全部楼层

8.4  总结
μCOS-III的移植过程并不难,希望初学的同学一定要动手移植一下,过程中出现问题了解决一下,以后新版本升级了,自己就可以动手升级了。





参考资料:
1.       www.micrium.com
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

6

主题

90

回帖

108

积分

初级会员

积分
108
QQ
发表于 2014-12-20 08:46:24 | 显示全部楼层
这里的大师都很厉害,但是为嘛老是我在坐沙发
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2014-12-20 13:58:43 | 显示全部楼层

回 第九度 的帖子

第九度:这里的大师都很厉害,但是为嘛老是我在坐沙发 (2014-12-20 08:46) 
嘻嘻,谢谢支持
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-6-4 19:20 , Processed in 0.318816 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表