0
0
ARM Architectureknowledge~10 mins

Sleep mode (WFI instruction) in ARM Architecture - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Sleep mode (WFI instruction)
CPU executes WFI
CPU checks for interrupts
Enter sleep
Wait for interrupt
Interrupt occurs
CPU wakes up and resumes execution
The CPU executes the WFI instruction, checks for interrupts, and if none are pending, it enters sleep mode until an interrupt wakes it up.
Execution Sample
ARM Architecture
WFI  ; Wait For Interrupt
// CPU sleeps until an interrupt occurs
// Then resumes execution after waking up
This code puts the CPU into sleep mode until an interrupt wakes it up.
Analysis Table
StepActionInterrupt Pending?CPU StateResult
1Execute WFI instructionNoCheck interruptsCPU checks if any interrupt is pending
2Interrupt checkNoEnter sleep modeCPU goes to sleep waiting for interrupt
3WaitNoSleepingCPU remains in low power state
4Interrupt occursYesWake upCPU wakes up from sleep
5Resume executionYesRunningCPU continues normal operation after interrupt
6Execute next instructionDependsRunningCPU processes interrupt or next code
7EndN/ARunningWFI cycle complete
💡 CPU wakes up when an interrupt occurs, ending sleep mode and resuming execution
State Tracker
VariableStartAfter Step 2After Step 4Final
CPU StateRunningSleepingWaking upRunning
Interrupt PendingNoNoYesDepends
Key Insights - 3 Insights
Why does the CPU not sleep if an interrupt is already pending when WFI is executed?
Because at Step 2 in the execution_table, the CPU checks for pending interrupts before sleeping. If an interrupt is pending, it skips sleep and immediately wakes up to handle it.
What happens if no interrupt occurs after WFI is executed?
As shown in Step 3, the CPU stays in sleep mode indefinitely, waiting for an interrupt to wake it up.
Does WFI clear the interrupt or just wait for it?
WFI only waits for an interrupt; it does not clear it. The interrupt is handled after the CPU wakes up, as seen in Step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the CPU state immediately after executing the WFI instruction if no interrupt is pending?
ASleeping
BRunning
CWaking up
DHalted
💡 Hint
Refer to Step 2 and Step 3 in the execution_table where CPU enters sleep mode when no interrupt is pending.
At which step does the CPU wake up from sleep mode?
AStep 2
BStep 4
CStep 3
DStep 1
💡 Hint
Check the 'CPU State' and 'Result' columns in the execution_table for when the CPU changes from sleeping to running.
If an interrupt is pending before WFI executes, what will the CPU do?
AEnter sleep mode anyway
BIgnore the interrupt and continue running
CWake up immediately without sleeping
DReset the interrupt
💡 Hint
Look at Step 2 in the execution_table where the CPU checks for interrupts before sleeping.
Concept Snapshot
WFI (Wait For Interrupt) puts the CPU into low power sleep mode.
CPU checks for pending interrupts before sleeping.
If interrupt pending, CPU wakes immediately.
CPU stays asleep until an interrupt occurs.
After waking, CPU resumes normal execution.
Full Transcript
The WFI instruction causes the CPU to enter sleep mode to save power. When the CPU executes WFI, it first checks if any interrupt is pending. If yes, it wakes immediately without sleeping. If no interrupt is pending, the CPU enters sleep mode and waits. The CPU stays asleep until an interrupt occurs. When an interrupt happens, the CPU wakes up and resumes normal execution. This process helps reduce power consumption during idle times.