摘抄一段原文:
The code for the idle task is shown below. Interrupts are disabled then
enabled around the increment because on 8-bit and most 16-bit processors, a 32-bit increment requires multiple
instructions which must be protected from being accessed by higher priority tasks or an ISR. The idle task can never
be deleted by application software.
void OSTaskIdle (void *pdata)
{
pdata = pdata;
for (;;) {
OS_ENTER_CRITICAL();
OSIdleCtr++;
OS_EXIT_CRITICAL();
}
}
这段论述需要关注一下,在我们c写的一条累加代码可能会是几条汇编才能执行完毕,这之间是可能被中断打断的,所以对一些关键的变量值在改变时要做中端屏蔽,这个在嵌入式开发我想要多注意培养这个意识。
本文探讨了在嵌入式系统中如何通过中断禁用和启用来保护关键任务的执行,特别是在累加操作期间避免高优先级任务或中断服务例程的干扰。
387

被折叠的 条评论
为什么被折叠?



