[原创] 【NUCLEO-F410RB】2.给nucleo移植上ucos-ii,用信号量实现led闪烁

caizhiwei   2015-12-6 17:15 楼主
虽然管理员寄过来的板子不能用,但是还得完成任务。所以抽出时间把ucos-ii移植上另外一块Nucleo板子上,奉上工程源码,供大家享用~~
  1. int main(void)
  2. {
  3. CPU_INT08U os_err;
  4. #if (CPU_CFG_NAME_ERR == DEF_ENABLED)
  5. CPU_ERR cpu_err;
  6. #endif
  7. //CPU_Init();
  8. BSP_IntDisAll(); /* Disable all interrupts. */
  9. OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
  10. OSTaskCreateExt((void (*)(void *)) AppTaskStart, /* Create the start task */
  11. (void *) 0,
  12. (OS_STK *)&AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE - 1],
  13. (INT8U ) APP_CFG_TASK_START_PRIO,
  14. (INT16U ) APP_CFG_TASK_START_PRIO,
  15. (OS_STK *)&AppTaskStartStk[0],
  16. (INT32U ) APP_CFG_TASK_START_STK_SIZE,
  17. (void *) 0,
  18. (INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
  19. #if (OS_TASK_NAME_EN > 0)
  20. OSTaskNameSet((INT8U )APP_CFG_TASK_START_PRIO,
  21. (INT8U *)"Start_Task",
  22. (INT8U *)&os_err);
  23. #endif
  24. OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
  25. return (1);
  26. }
  27. /*
  28. *********************************************************************************************************
  29. * STARTUP TASK
  30. *
  31. * Description : This is an example of a startup task. As mentioned in the book's text, you MUST
  32. * initialize the ticker only once multitasking has started.
  33. *
  34. * Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
  35. *
  36. * Returns : none
  37. *
  38. * Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
  39. * used. The compiler should not generate any code for this statement.
  40. *********************************************************************************************************
  41. */
  42. void AppTaskStart (void *p_arg)
  43. {
  44. (void)p_arg; /* Note #1 */
  45. OS_CPU_SysTickInit(OS_TICKS_PER_SEC); /* Initialize tick counter */
  46. Bsp_Init(); /* Initialize BSP functions */
  47. CPU_Init(); /* Initialize the uC/CPU services */
  48. BSP_Tick_Init(); /* Start Tick Initialization */
  49. #if (OS_TASK_STAT_EN > 0)
  50. OSStatInit(); /* Determine CPU capacity */
  51. #endif
  52. AppEventCreate(); /* Create Application Events */
  53. AppTaskCreate(); /* Create application tasks */
  54. while (1) /* Task body, always written as an infinite loop. */
  55. {
  56. OSSemPost(Led3_SEM);
  57. OSTimeDlyHMSM(0, 0,0,800);
  58. OSSemPost(Led4_SEM);
  59. OSTimeDlyHMSM(0, 0,0,800);
  60. }
  61. }
  62. /*
  63. *********************************************************************************************************
  64. * AppTaskEventCreate()
  65. *
  66. * Description : Create the application Events
  67. *
  68. * Argument(s) : none.
  69. *
  70. * Return(s) : none.
  71. *
  72. * Caller(s) : App_TaskStart()
  73. *
  74. * Note(s) : none.
  75. *********************************************************************************************************
  76. */
  77. void AppEventCreate (void)
  78. {
  79. Led3_SEM=OSSemCreate(0);
  80. Led4_SEM=OSSemCreate(0);
  81. }
  82. /*
  83. *********************************************************************************************************
  84. * AppTaskCreate()
  85. *
  86. * Description : Create the application tasks.
  87. *
  88. * Argument(s) : none.
  89. *
  90. * Return(s) : none.
  91. *
  92. * Caller(s) : App_TaskStart()
  93. *
  94. * Note(s) : none.
  95. *********************************************************************************************************
  96. */
  97. void AppTaskCreate (void)
  98. {
  99. #if (OS_TASK_NAME_EN > 0)
  100. CPU_INT08U os_err;
  101. #endif
  102. OSTaskCreateExt((void (*)(void *))AppTaskLED3, /* Create the task for LED3 semaphore blinking */
  103. (void *) 0,
  104. (OS_STK *)&AppTaskLED3Stk[APP_CFG_TASK_LED3_STK_SIZE - 1],
  105. (INT8U ) APP_CFG_TASK_LED3_PRIO,
  106. (INT16U ) APP_CFG_TASK_LED3_PRIO,
  107. (OS_STK *)&AppTaskLED3Stk[0],
  108. (INT32U ) APP_CFG_TASK_LED3_STK_SIZE,
  109. (void *) 0,
  110. (INT16U )OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
  111. #if (OS_TASK_NAME_EN > 0)
  112. OSTaskNameSet((INT8U )APP_CFG_TASK_LED3_PRIO,
  113. (INT8U *)"App Task LED3",
  114. (INT8U *)&os_err);
  115. #endif
  116. OSTaskCreateExt((void (*)(void *))AppTaskLED4, /* Task creation for LED 4 queue control with LED 3 too */
  117. (void *) 0,
  118. (OS_STK *)&AppTaskLED4Stk[APP_CFG_TASK_LED4_STK_SIZE - 1],
  119. (INT8U ) APP_CFG_TASK_LED4_PRIO,
  120. (INT16U ) APP_CFG_TASK_LED4_PRIO,
  121. (OS_STK *)&AppTaskLED4Stk[0],
  122. (INT32U ) APP_CFG_TASK_LED4_STK_SIZE,
  123. (void *) 0,
  124. (INT16U ) OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
  125. #if (OS_TASK_NAME_EN > 0)
  126. OSTaskNameSet((INT8U )APP_CFG_TASK_LED4_PRIO,
  127. (INT8U *)"App Task LED4",
  128. (INT8U *)&os_err);
  129. #endif
  130. }
  131. /*
  132. *********************************************************************************************************
  133. * AppTaskLED3()
  134. *
  135. * Description : Task to activate and toggle LED2 after timer tick system expires.
  136. *
  137. * Argument(s) : p_arg is the argument passed to 'AppTaskLED2()' by 'OSTaskCreate()'.
  138. *
  139. * Return(s) : none.
  140. *
  141. * Caller(s) : none.
  142. *
  143. * Note(s) : none.
  144. *********************************************************************************************************
  145. */
  146. void AppTaskLED3(void *p_arg)
  147. {
  148. CPU_INT08U err;
  149. (void)p_arg;
  150. while(1)
  151. {
  152. OSSemPend(Led3_SEM,0,&err);
  153. Bsp_Led_On(3);
  154. Bsp_Led_Off(4);
  155. OSTimeDly(500);
  156. OSTimeDly(500);
  157. }
  158. }
  159. /*
  160. *********************************************************************************************************
  161. * AppTaskLED4()
  162. *
  163. * Description : Toggle LED3 using semaphore services.
  164. *
  165. * Argument(s) : p_arg is the argument passed to 'AppTaskLED3()' by 'OSTaskCreate()'.
  166. *
  167. * Return(s) : none.
  168. *
  169. * Caller(s) : none.
  170. *
  171. * Note(s) : Calls the LED function to activate LED 3.
  172. *********************************************************************************************************
  173. */
  174. void AppTaskLED4(void *p_arg)
  175. {
  176. CPU_INT08U err;
  177. (void)p_arg;
  178. while (1)
  179. {
  180. OSSemPend(Led4_SEM,0,&err);
  181. Bsp_Led_On(4);
  182. Bsp_Led_Off(3);
  183. OSTimeDly(500);
  184. OSTimeDly(500);
  185. }
  186. }
哈哈,,用MDK5编译的哦! QQ截图20151206170545.png QQ图片20151206165244.jpg 最后附上源代码:
f030r8_ucosii_demo.zip (2.22 MB)
(下载次数: 8, 2015-12-6 17:15 上传)
本帖最后由 caizhiwei 于 2015-12-6 17:17 编辑
gitee/casy

回复评论 (3)

66666点赞!
点赞  2015-12-6 18:17
谢谢分享。。。
点赞  2015-12-6 22:18
非常感谢分享
点赞  2018-12-1 16:38
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复