我开始熟悉 MicroC/OS-II 内核和多任务处理。我编写了以下两个使用信号量的任务:
#define TASK1_PRIORITY 6 // highest priority
#define TASK2_PRIORITY 7
void task1(void* pdata)
{
while (1)
{
INT8U err;
OSSemPend(aSemaphore_task1, 0, &err);
int i;
if (sharedAddress >= 0)
{
printText(text1);
printDigit(++sharedAddress);
}
else
{
printText(text2);
printDigit(sharedAddress);
}
OSTimeDlyHMSM(0, 0, 0, 11);
OSSemPost(aSemaphore_task2);
}
}
void task2(void* pdata)
{
while (1)
{
INT8U err;
OSSemPend(aSemaphore_task2, 0, &err);
sharedAddress *= -1;
OSTimeDlyHMSM(0, 0, 0, 4);
OSSemPost(aSemaphore_task1);
}
}
现在我想测量上下文切换时间,即处理器在这两个任务之间切换所需的时间。
这是否仅通过使用以下函数来完成timer()
:
void task1(void* pdata)
{
while (1)
{
INT8U err;
OSSemPend(aSemaphore_task1, 0, &err);
int i;
if (sharedAddress >= 0)
{
printText(text1);
printDigit(++sharedAddress);
}
else
{
printText(text2);
printDigit(sharedAddress);
}
OSTimeDlyHMSM(0, 0, 0, 11);
OSSemPost(aSemaphore_task2);
timer(start);
}
}
void task2(void* pdata)
{
while (1)
{
timer(stop):
INT8U err;
OSSemPend(aSemaphore_task2, 0, &err);
sharedAddress *= -1;
OSTimeDlyHMSM(0, 0, 0, 4);
OSSemPost(aSemaphore_task1);
}
}
还是我完全错了?