大家好
我的代码中有一个临界区(CS)。 我需要在启动 CS 之前禁用所有中断、并且需要在 CS 之后重新启用它们。 在 simplelink SDK 中、是否有任何方法可以全局禁用和启用中断?
另外、是否还有其他方法可以做到这一点?
谢谢
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
大家好
我的代码中有一个临界区(CS)。 我需要在启动 CS 之前禁用所有中断、并且需要在 CS 之后重新启用它们。 在 simplelink SDK 中、是否有任何方法可以全局禁用和启用中断?
另外、是否还有其他方法可以做到这一点?
谢谢
您是否正在使用无线电堆栈? 默认情况下、它将包含在这些工程中。 它最终是对 HwiP_disable (HwiP_tirtos)或 Hwi_disable (Hwi)的调用
/* Enter critical section */
#define HAL_ENTER_CRITICAL_SECTION(x) \
do { x = HwiP_disable(); } while (0)
/* Exit critical section */
#define HAL_EXIT_CRITICAL_SECTION(x) \
do { HwiP_restore(x); } while (0)
BLE5-Stack 使用 ICall 实现
/* For now critical sections completely disable hardware interrupts
* because they are used from ISRs in MAC layer implementation.
* If MAC layer implementation changes, critical section
* implementation may change to reduce overall interrupt latency.
*/
/* Enter critical section implementation. See header file for comment. */
ICall_CSState ICall_enterCSImpl(void)
{
ICall_CSStateUnion cu;
cu.each.swikey = (uint_least16_t) Swi_disable();
cu.each.hwikey = (uint_least16_t) Hwi_disable();
return cu.state;
}
/* See header file for comment */
ICall_EnterCS ICall_enterCriticalSection = ICall_enterCSImpl;
/* leave critical section implementation. See header file for comment */
void ICall_leaveCSImpl(ICall_CSState key)
{
ICall_CSStateUnion *cu = (ICall_CSStateUnion *) &key;
Hwi_restore((UInt) cu->each.hwikey);
Swi_restore((UInt) cu->each.swikey);
}
您可以在 TI-RTOS7内核文档 和 SimpleLink MCU SDK 用户指南中找到更多信息。 我必须小心关键段的使用、这会阻止其它应用程序活动在预期时间内完成。
此致、
Ryan