Cortex-M0 关闭所有中断
#define portDISABLE_INTERRUPTS() __disable_irq()
#define portENABLE_INTERRUPTS() __enable_irq()


/** \brief Enable IRQ Interrupts
This function enables IRQ interrupts by clearing the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
{
__ASM volatile ("cpsie i");
}
/** \brief Disable IRQ Interrupts
This function disables IRQ interrupts by setting the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
{
__ASM volatile ("cpsid i");
}
需要关闭总中断时,用户代码里直接放置__disable_irq()
需要开启总的中断时,用户代码里直接放置__enable_irq()
目前各编译工具都把与内核相关ARM指令根据指令功能将其中某一条或几条汇编指令封装为C函数,函数名相对更为直观、好记,方便用户需要时拿来使用。比方在ARM MDK环境下,上面两个开关总中断的指令封装成如下2个内嵌函数。
CPSID i; // Disable all interrupts except NMI(includes a non-maskable interrupt).set PRIMASK
CPSIE i; // Enable interrupts.clear PRIMASK
CPS(Change Processor State)改变的是PRIMASK(Interrupt mask register)寄存器值。CPSID通过PRIMASK置1中断disable,CPSID通过PRIMASK清0操作中断enable。
(稍后补充)
本文详细介绍了在Cortex-M0处理器上如何使用内联汇编指令__disable_irq()和__enable_irq()来关闭和开启所有中断。这些函数通过设置CPSR寄存器中的I位来控制中断的启用与禁用,适用于特权模式下。此外,文章还提到了在ARM MDK环境下,这些功能被封装为CPSIDi和CPSIEi函数。
2489

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



