您的位置:首页 > 其它

使用UC/OS-II创建任务出错

2015-04-29 09:00 288 查看
开发环境STM32F107VC+keil4.6+UC/OS-II+LWIP

在硬件调试过程中发现程序到了OSTaskCreate这一行后没有正确的创建任务。

<pre name="code" class="html">OSTaskCreate(start_task,(void *)0,(OS_STK *)&START_TASK_STK[START_STK_SIZE-1],START_TASK_PRIO );//
OSStart();




单步调试,原来是

OS_ENTER_CRITICAL();
if (OSIntNesting > 0u) {                 /* Make sure we don't create the task from within an ISR  */
OS_EXIT_CRITICAL();
return (OS_ERR_TASK_CREATE_ISR);
}
if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
OSTCBPrioTbl[prio] = OS_TCB_RESERVED;/* Reserve the priority to prevent others from doing ...  */
/* ... the same thing until task is created.              */
OS_EXIT_CRITICAL();
psp = OSTaskStkInit(task, p_arg, ptos, 0u);             /* Initialize the task's stack         */
err = OS_TCBInit(prio, psp, (OS_STK *)0, 0u, 0u, (void *)0, 0u);
if (err == OS_ERR_NONE) {
if (OSRunning == OS_TRUE) {      /* Find highest priority task if multitasking has started */
OS_Sched();
}
} else {
OS_ENTER_CRITICAL();
OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others                 */
OS_EXIT_CRITICAL();
}
return (err);


运行到第232行if(OSIntNesting>0u)是进入了条件语句直接返回了。分析应该是系统中断的问题,果不其然。原来的系统时钟中断是这样的:

void SysTick_Handler(void)

{
OS_CPU_SR  cpu_sr;

OS_ENTER_CRITICAL();                                        // Tell uC/OS-II that we are starting an ISR
OSIntNesting++;
OS_EXIT_CRITICAL();

OSTimeTick();                                               // Call uC/OS-II's OSTimeTick()
OSIntExit();                                                // Tell uC/OS-II that we are leaving the ISR

}
改为:
void SysTick_Handler(void)
{

OSIntEnter();
OSTimeTick();
OSIntExit();            // Tell uC/OS-II that we are leaving the ISR

}


就好了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: