arch: riscv: disable interrupts before wfi
According to RISC-V Instruction Set Manual Chapter 3.3.2: "The operation of WFI must be unaffected by the global interrupt bits in mstatus [...] WFI is also required to resume execution for locally enabled interrupts pending at any privilege level, regardless of the global interrupt enable at each privilege level." Disabling interrupts before executing `wfi` prevents a corner case where an IRQ is presented just before executing `wfi`, which would cause it to return directly into `wfi` and potentially get stuck in sleep, instead of continuing to background processing. When execution is resumed, interrupts are reenabled and appropriate IRQ Handlers should be executed. Signed-off-by: Marcin Szymczyk <marcin.szymczyk@nordicsemi.no>
This commit is contained in:
parent
2396b01b1e
commit
292aafef5a
1 changed files with 2 additions and 2 deletions
|
@ -10,13 +10,13 @@
|
|||
void __weak arch_cpu_idle(void)
|
||||
{
|
||||
sys_trace_idle();
|
||||
irq_unlock(MSTATUS_IEN);
|
||||
__asm__ volatile("wfi");
|
||||
irq_unlock(MSTATUS_IEN);
|
||||
}
|
||||
|
||||
void __weak arch_cpu_atomic_idle(unsigned int key)
|
||||
{
|
||||
sys_trace_idle();
|
||||
irq_unlock(key);
|
||||
__asm__ volatile("wfi");
|
||||
irq_unlock(key);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue