Sleep Mode Entry Sequence

Medium Assembly Power Asked at Nordic Semiconductor
Solve this problem

Write the correct sequence for entering deep sleep on a Cortex-M part, ensuring no pending interrupt is lost in the race between the check and the WFI.

Constraints

  • Set SLEEPDEEP in the System Control Register.
  • Disable interrupts before checking for pending work.
  • Use WFI with interrupts masked by PRIMASK so a pending IRQ still wakes the core.
  • Re-enable interrupts after waking.
  • Include the required barriers.
  • Clear SLEEPDEEP on exit.
Starter codeAssembly
1.global enter_deep_sleep2enter_deep_sleep:3    @ TODO4    bx lr