The ARM Cortex processor architecture provides two low-power states for reducing power consumption when the processor is idle: Wait For Interrupt (WFI) and Wait For Event (WFE). The key difference between WFI and WFE is that WFI simply puts the processor to sleep until the next interrupt wakes it up, while WFE allows the processor to sleep until a specific event occurs.
WFI – Wait For Interrupt
WFI is the most basic low-power state in ARM Cortex. When the WFI instruction is executed, the processor immediately enters a low-power mode. In this mode, the processor clock is gated off, cutting dynamic power consumption to almost zero. The processor maintains power only to the interrupt detection logic. When an interrupt is asserted, the processor immediately wakes up and exits WFI state to handle the interrupt.
The processor does not need to maintain cache or architectural state when entering WFI. Once the interrupt handler has finished, program execution resumes from the instruction after the WFI with full cache and architectural state restored. This makes WFI very simple to use – the compiler will automatically insert WFI instructions anytime the processor would otherwise be idle.
WFI does have some limitations. The processor can only sleep until the next interrupt occurs. If no interrupts occur for a long time, the processor will remain active and consume power waiting for one. WFI by itself is not sufficient for low duty cycle applications that spend most of their time asleep. Additionally, the processor will immediately wake up on any interrupt, even if the interrupt is not important. These limitations are addressed by the WFE state.
WFE – Wait For Event
WFE gives more control over when the processor wakes up compared to WFI. Instead of waking up on any interrupt, the processor will only exit WFE when one of the “event” signals it is waiting on becomes active. Event signals include interrupts, but can also be simple flags set in hardware by other system components. This allows the processor to sleep until specific conditions are met to wake it up, instead of any interrupt.
When the WFE instruction is executed, the processor enters a low-power state similar to WFI. However, before going to sleep the processor sets internal event register flags for the events it is waiting on. The processor clock is gated off until one of the event flags becomes set. This allows the processor to remain in low power mode until the desired wake up condition occurs, ignoring unimportant interrupts and activity. When hardware signals wake up event, the flag is set, the clock is enabled, and program execution resumes after WFE instruction.
To use WFE, software must properly set the internal event register flags before issuing the WFE instruction. The WFE flags are: – Local timer event – Wake up after preset time expires – Internal debug event – Interrupt pending event – Wake on any interrupt – External debug request – Async external event – Flag set by external HW system logic These flags allow the processor to be woken up by timed sleeps, specific interrupts, external processors, debuggers, and other system events.
WFI vs WFE Key Differences
The key differences between WFI and WFE are:
- WFI will wake up the processor on any interrupt, while WFE wakes up only on events the flags are set for.
- WFE requires programming event flags before sleeping, WFI does not.
- WFI has very little latency to wake up, while WFE wakeup time depends on events programmed.
- WFE maintains architectural state during sleep like caches and buses, WFI does not.
- WFI is purely a processor-centric low power mode, WFE coordinates with external hardware events.
- WFI alone cannot achieve very low duty cycles, WFE can remain asleep for long durations.
In summary, WFE is a more advanced low-power mode than WFI and allows the processor to sleep until specific wake conditions are met, rather than the next interrupt. This allows lower power and longer sleep states by ignoring unnecessary activity.
WFI and WFE Usage
WFI and WFE are complementary low power modes with different use cases:
- WFI is best for simple idle management. The processor immediately sleeps when idle, wakes up on next interrupt quickly for lowest latency. Useful for saving power when waiting for sporadic interrupts.
- WFE is better for low duty cycle applications. Processor can sleep for extended time, waking only when important events occur. Useful when processor needs to sleep most of the time.
Typical usage patterns are:
- Use WFI for simple idle loops. Allow processor to sleep when no work pending.
- Use WFE when sending processor into extended sleep. Set appropriate wake events first.
- Use WFE for timed sleeps. Set timer event flag before WFE.
- Use WFE to wait for specific interrupts rather than any interrupt.
- Use WFE to coordinate with external hardware, waking on events from other processors.
- Combine WFI and WFE as needed for different use cases. WFI for quick idle, WFE for long idle.
Here is example code using WFI and WFE:
// Simple WFI Usage
while(!work_pending){
// Processor sleeps until next interrupt
WFI;
}
// Extended WFE sleep
// Configure Event Register for Timer wakeup in 1ms
SetEventRegister(TIMER_1MS);
// Sleep until timer expires
WFE;
// Wait for I2C interrupt specifically
// Clear all event flags
ClearEventRegister();
// Set I2C interrupt event only
SetEventRegister(I2C_IRQ);
// Sleep until I2C interrupt occurs
WFE;
// Wake after 10ms or on GPIO interrupt
SetEventRegister(TIMER_10MS);
SetEventRegister(GPIO_IRQ);
WFE; // Sleeps for 10ms unless GPIO interrupts
With WFI and WFE, the ARM Cortex architecture provides flexible options for managing idle power consumption. WFI allows simple low latency idle management using interrupts. WFE enables advanced low-power modes coordinated with external hardware events and timers. Using them appropriately allows building systems with very low duty cycles and power consumption.
WFI and WFE Hardware Implementation
The WFI and WFE power modes are enabled by advanced hardware capabilities in ARM Cortex processors:
- Clock gating – Cortex CPUs can instantly gate the clocks to core logic like execution pipelines to reduce power when idle.
- Power gating – Cortex CPUs include power switches to cut power to unused blocks during low power modes.
- Multiple power domains – The processor power domain can be separated from peripheral domains, allowing flexible control.
- Asynchronous wake up logic – External events can wake up the processor independently of the clock.
- Low latency restart – Caches and architecture state can be maintained to quickly restore the processor.
Key hardware involved in WFI/WFE includes:
- The Wait For Event hardware logic – This controls entry and exit from WFE mode based on event flags.
- Event Register – Flags are set here to indicate events to wake-up the processor.
- Core power controller – Power gates the CPU core clocks and logic on WFE.
- CPU and Bus interfaces – Isolate CPU from peripherals while powered down.
- Wakeup Logic – Monitors events and wakes CPU when an event flag is set.
- Interrupt Controller – Signals interrupts to core based on IRQ sources and masking.
By integrating these IP blocks with the core CPU logic, ARM enables advanced low-power modes and efficient system-wide power management in Cortex CPUs.
Differences in WFI/WFE Across Cortex-A, Cortex-R, Cortex-M
The ARM architecture supports WFI/WFE power modes across all Cortex processor families – A, R and M. However there are some differences in implementation between the application processors, real-time processors and microcontrollers:
- Cortex-A Application Processors – Support multiple power states (WFI, WFE, Standby, etc.) for flexibility. Wake up latencies can be long for lowest power. Focus on system coordination for SoC idle.
- Cortex-R Real-time Processors – Rely heavily on WFE for deterministic logic. Require fast, predictable wake up and response. Tightly integrated architecture for real-time performance.
- Cortex-M Microcontrollers – Optimized for lowest static and dynamic power. Support WFE with fast wakeup for low duty cycle operation. Leverage extensive power gating for peripheral domains.
So WFI and WFE are supported across all Cortex CPUs but tailored for the specific performance requirements – flexibility and integration for Cortex-A, deterministic real-time response for Cortex-R, and minimal power for Cortex-M.
Conclusion
In summary, the key differences between WFI and WFE power modes in ARM Cortex CPUs are:
- WFI sleeps until next interrupt, WFE sleeps until configured event wakeup.
- WFI has lower latency, WFE can remain asleep longer.
- WFI manages CPU idle, WFE coordinates with hardware events.
- WFI is purely a CPU low power mode, WFE integrates with system components.
- WFI is optimal for sporadic idle, WFE for extended idle periods.
ARM Cortex processors leverage these advanced low power capabilities to enable both responsiveness for real-time applications and low duty cycle operation for power sensitive devices. The flexible options provided by WFI and WFE allow system designers to optimize idle power behaviour for a wide range of use cases.