资料中说:在armcc编译器中,__enable_irq();__enable_fault_irq();__disable_irq();__disable_fault_irq();为内在函数,且只能在特权模式下才能执行成功。但我实际测试时发现在用户模式也能正确执行,但在频繁开关全局中断时,会有关掉后不再打开的情况发生。但是在 特权模式下很长时间频繁开关全局中断也没出现此情况。我用的芯片型号是STM32F103CBT6-GH21090-CHN321和GD32F103CBT6-D-DP3179-DH1328
正确执行的意思是: 确实PRIMASK的值改变了? 还是只是这个代码执行了而已?
__enable_irq() 对应的汇编代码是 : CPSIE I
这是个特权级的指令,如果在用户态执行,将被忽略(不起作用)
CPS<effect><q> <iflags>
where:
<effect> Specifies the effect required on PRIMASK and FAULTMASK. This is one of:
IE Interrupt Enable. This sets the specified bits to 0.
ID Interrupt Disable. This sets the specified bits to 1.
<q> See Standard assembler syntax fields on page A7-207. A CPS instruction must be
unconditional.
<iflags> Is a sequence of one or more of the following, specifying which masks are affected:
i PRIMASK. Raises the execution priority to 0 when set to 1. This is a 1-bit
register, that supports privileged access only.
f FAULTMASK. Raises the execution priority to -1 (the same as HardFault)
when it is set to 1.
Operation
EncodingSpecificOperations();
if CurrentModeIsPrivileged() then
if enable then
if affectPRI then PRIMASK<0> = ‘0’;
if affectFAULT then FAULTMASK<0> = ‘0’;
if disable then
if affectPRI then PRIMASK<0> = ‘1’;
if affectFAULT && ExecutionPriority() > -1 then FAULTMASK<0> = ‘1’;
Exceptions
None.
Notes
Privilege Any unprivileged code attempt to write the masks is ignored.
|