这很奇怪。
OSInit();
OSTimeDly(10);
OSTaskCreate(start_task,(void *)0,(OS_STK *)&START_TASK_STK[TASK_STK_SIZE-1],START_TASK_PRIO);
OSStart();
在OSTimeDly(10)中,有OS_Enter_CRITICAL()和OS_Exit_Critical(),当代码运行到OS_Exit_Critical()时,会发生HardFault。
void OSTimeDly (INT32U ticks)
{
INT8U y;
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0u;
#endif
if (OSIntNesting > 0u) { /* See if trying to call from an ISR */
return;
}
if (OSLockNesting > 0u) { /* See if called with scheduler locked */
return;
}
if (ticks > 0u) { /* 0 means no delay! */
OS_ENTER_CRITICAL();
y = OSTCBCur->OSTCBY; /* Delay current task */
OSRdyTbl[y] &= (OS_PRIO)~OSTCBCur->OSTCBBitX;
if (OSRdyTbl[y] == 0u) {
OSRdyGrp &= (OS_PRIO)~OSTCBCur->OSTCBBitY;
}
OSTCBCur->OSTCBDly = ticks; /* Load ticks in TCB */
OS_EXIT_CRITICAL();
OS_Sched(); /* Find next task to run! */
}
}
但是,如果我将代码更改为:
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0u;
#endif
INT8U y;
...
OSInit();
OS_ENTER_CRITICAL();
y = OSTCBCur->OSTCBY; /* Delay current task */
OSRdyTbl[y] &= (OS_PRIO)~OSTCBCur->OSTCBBitX;
if (OSRdyTbl[y] == 0u) {
OSRdyGrp &= (OS_PRIO)~OSTCBCur->OSTCBBitY;
}
OS_EXIT_CRITICAL();
//OSTimeDly(10);
OSTaskCreate(start_task,(void *)0,(OS_STK *)&START_TASK_STK[TASK_STK_SIZE-1],START_TASK_PRIO);
OSStart();
还有OS_ENTER_CRITICAL()和OS_EXIT_CRITICAL(),但是当代码运行到OS_EXIT_CRITICAL()时,没有发生HardFault。为什么?我不认为有什么不同。