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>
1 file changed