虽然管理员寄过来的板子不能用,但是还得完成任务。所以抽出时间把ucos-ii移植上另外一块Nucleo板子上,奉上工程源码,供大家享用~~
- int main(void)
- {
-
- CPU_INT08U os_err;
- #if (CPU_CFG_NAME_ERR == DEF_ENABLED)
- CPU_ERR cpu_err;
- #endif
-
- //CPU_Init();
-
- BSP_IntDisAll(); /* Disable all interrupts. */
-
- OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
-
- OSTaskCreateExt((void (*)(void *)) AppTaskStart, /* Create the start task */
- (void *) 0,
- (OS_STK *)&AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE - 1],
- (INT8U ) APP_CFG_TASK_START_PRIO,
- (INT16U ) APP_CFG_TASK_START_PRIO,
- (OS_STK *)&AppTaskStartStk[0],
- (INT32U ) APP_CFG_TASK_START_STK_SIZE,
- (void *) 0,
- (INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
-
- #if (OS_TASK_NAME_EN > 0)
- OSTaskNameSet((INT8U )APP_CFG_TASK_START_PRIO,
- (INT8U *)"Start_Task",
- (INT8U *)&os_err);
- #endif
-
- OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
-
- return (1);
- }
-
- /*
- *********************************************************************************************************
- * STARTUP TASK
- *
- * Description : This is an example of a startup task. As mentioned in the book's text, you MUST
- * initialize the ticker only once multitasking has started.
- *
- * Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
- *
- * Returns : none
- *
- * Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
- * used. The compiler should not generate any code for this statement.
- *********************************************************************************************************
- */
-
- void AppTaskStart (void *p_arg)
- {
- (void)p_arg; /* Note #1 */
-
-
- OS_CPU_SysTickInit(OS_TICKS_PER_SEC); /* Initialize tick counter */
-
-
- Bsp_Init(); /* Initialize BSP functions */
- CPU_Init(); /* Initialize the uC/CPU services */
-
- BSP_Tick_Init(); /* Start Tick Initialization */
-
- #if (OS_TASK_STAT_EN > 0)
- OSStatInit(); /* Determine CPU capacity */
- #endif
-
-
-
- AppEventCreate(); /* Create Application Events */
-
-
- AppTaskCreate(); /* Create application tasks */
-
-
- while (1) /* Task body, always written as an infinite loop. */
- {
-
- OSSemPost(Led3_SEM);
- OSTimeDlyHMSM(0, 0,0,800);
- OSSemPost(Led4_SEM);
-
- OSTimeDlyHMSM(0, 0,0,800);
-
- }
- }
-
- /*
- *********************************************************************************************************
- * AppTaskEventCreate()
- *
- * Description : Create the application Events
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : App_TaskStart()
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- void AppEventCreate (void)
- {
- Led3_SEM=OSSemCreate(0);
- Led4_SEM=OSSemCreate(0);
-
- }
-
- /*
- *********************************************************************************************************
- * AppTaskCreate()
- *
- * Description : Create the application tasks.
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : App_TaskStart()
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
-
- void AppTaskCreate (void)
- {
- #if (OS_TASK_NAME_EN > 0)
- CPU_INT08U os_err;
- #endif
-
- OSTaskCreateExt((void (*)(void *))AppTaskLED3, /* Create the task for LED3 semaphore blinking */
- (void *) 0,
- (OS_STK *)&AppTaskLED3Stk[APP_CFG_TASK_LED3_STK_SIZE - 1],
- (INT8U ) APP_CFG_TASK_LED3_PRIO,
- (INT16U ) APP_CFG_TASK_LED3_PRIO,
- (OS_STK *)&AppTaskLED3Stk[0],
- (INT32U ) APP_CFG_TASK_LED3_STK_SIZE,
- (void *) 0,
- (INT16U )OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
-
- #if (OS_TASK_NAME_EN > 0)
- OSTaskNameSet((INT8U )APP_CFG_TASK_LED3_PRIO,
- (INT8U *)"App Task LED3",
- (INT8U *)&os_err);
- #endif
-
- OSTaskCreateExt((void (*)(void *))AppTaskLED4, /* Task creation for LED 4 queue control with LED 3 too */
- (void *) 0,
- (OS_STK *)&AppTaskLED4Stk[APP_CFG_TASK_LED4_STK_SIZE - 1],
- (INT8U ) APP_CFG_TASK_LED4_PRIO,
- (INT16U ) APP_CFG_TASK_LED4_PRIO,
- (OS_STK *)&AppTaskLED4Stk[0],
- (INT32U ) APP_CFG_TASK_LED4_STK_SIZE,
- (void *) 0,
- (INT16U ) OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
-
- #if (OS_TASK_NAME_EN > 0)
- OSTaskNameSet((INT8U )APP_CFG_TASK_LED4_PRIO,
- (INT8U *)"App Task LED4",
- (INT8U *)&os_err);
- #endif
- }
-
- /*
- *********************************************************************************************************
- * AppTaskLED3()
- *
- * Description : Task to activate and toggle LED2 after timer tick system expires.
- *
- * Argument(s) : p_arg is the argument passed to 'AppTaskLED2()' by 'OSTaskCreate()'.
- *
- * Return(s) : none.
- *
- * Caller(s) : none.
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
-
- void AppTaskLED3(void *p_arg)
- {
- CPU_INT08U err;
- (void)p_arg;
-
- while(1)
- {
- OSSemPend(Led3_SEM,0,&err);
- Bsp_Led_On(3);
- Bsp_Led_Off(4);
- OSTimeDly(500);
- OSTimeDly(500);
- }
- }
-
- /*
- *********************************************************************************************************
- * AppTaskLED4()
- *
- * Description : Toggle LED3 using semaphore services.
- *
- * Argument(s) : p_arg is the argument passed to 'AppTaskLED3()' by 'OSTaskCreate()'.
- *
- * Return(s) : none.
- *
- * Caller(s) : none.
- *
- * Note(s) : Calls the LED function to activate LED 3.
- *********************************************************************************************************
- */
-
- void AppTaskLED4(void *p_arg)
- {
- CPU_INT08U err;
- (void)p_arg;
-
- while (1)
- {
- OSSemPend(Led4_SEM,0,&err);
- Bsp_Led_On(4);
- Bsp_Led_Off(3);
- OSTimeDly(500);
- OSTimeDly(500);
- }
- }
哈哈,,用MDK5编译的哦!
最后附上源代码:
本帖最后由 caizhiwei 于 2015-12-6 17:17 编辑