用一个多任务的流水灯程序做验证,很简单。为什么灯不亮。
UCOS的内核是在官网下载对应的
求解释
int main(void)
{
#if (OS_TASK_NAME_EN > 0)
CPU_INT08U err;
#endif
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(APP_CFG_TASK_START_PRIO, "Start", &err);
#endif
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
return (1);
}
static void AppTaskStart (void *p_arg)
{
CPU_INT32U cpu_clk_freq;
CPU_INT32U cnts;
(void)p_arg;
BSP_Init(); /* Initialize BSP functions */
CPU_Init(); /* Initialize the uC/CPU services */
cpu_clk_freq = BSP_CPU_ClkFreq(); /* Determine SysTick reference freq. */
cnts = cpu_clk_freq /* Determine nbr SysTick increments */
/ (CPU_INT32U)OS_TICKS_PER_SEC;
OS_CPU_SysTickInit(cnts); /* Init uC/OS periodic time src (SysTick). */
Mem_Init(); /* Initialize memory managment module */
Math_Init(); /* Initialize mathematical module */
#if (OS_TASK_STAT_EN > 0)
OSStatInit(); /* Determine CPU capacity */
#endif
APP_TRACE_DBG(("
"));
APP_TRACE_INFO(("Creating Application Events...
"));
AppEventCreate(); /* Create Application Events */
APP_TRACE_INFO(("Creating Application Tasks...
"));
AppTaskCreate(); /* Create application tasks */
OSTaskCreate( Task0, //任务1
(void * ) 0, //不带参数
(OS_STK * )&Task0Stk[128 - 1], //堆栈指针
(INT8U ) 5 //优先级
);
OSTaskCreate( Task1, //任务2
(void * ) 0, //不带参数
(OS_STK * )&Task1Stk[128 - 1],
(INT8U ) 6 //优先级
);
for(;;)
{
BSP_LED_On(2);
OSTimeDlyHMSM(0, 0, 0, 500); /* Delay for 100 milliseconds */
BSP_LED_Off(2);
OSTimeDlyHMSM(0, 0, 0, 500); /* Delay for 100 milliseconds */
}
}
void Task0(void *p_arg)
{
for(;;)
{
BSP_LED_On(3);
OSTimeDlyHMSM(0, 0, 0, 100); /* Delay for 100 milliseconds */
BSP_LED_Off(3);
OSTimeDlyHMSM(0, 0, 0, 100); /* Delay for 100 milliseconds */
}
}
void Task1(void *p_arg)
{
for(;;)
{
BSP_LED_On(4);
OSTimeDlyHMSM(0, 0, 0, 200); /* Delay for 100 milliseconds */
BSP_LED_Off(4);
OSTimeDlyHMSM(0, 0, 0, 200); /* Delay for 100 milliseconds */
}
}
[
本帖最后由 小小小小菜鸟 于 2013-4-8 10:51 编辑 ]
此帖出自
小平头技术问答
一周热门 更多>