0
0
Cnc-programmingConceptBeginner · 3 min read

WFI and WFE Instructions in ARM: What They Are and How They Work

In ARM architecture, the WFI (Wait For Interrupt) instruction puts the processor into a low-power state until an interrupt occurs, while the WFE (Wait For Event) instruction waits for any event, including interrupts or signals from other processors. Both instructions help reduce power consumption by pausing execution until something important happens.
⚙️

How It Works

The WFI instruction tells the ARM processor to pause its work and enter a low-power state until an interrupt happens. Think of it like waiting quietly for a phone call before doing anything else. When the interrupt arrives, the processor wakes up and continues its tasks.

The WFE instruction is similar but more flexible. It waits for any event, which can be an interrupt or a signal from another part of the system. Imagine waiting for a doorbell or a text message; either one will wake you up. This allows the processor to save power while still being responsive to different triggers.

💻

Example

This example shows how to use WFI and WFE in ARM assembly to wait for interrupts or events:

armasm
    MOV R0, #0          ; Clear register
    WFI                 ; Wait for interrupt
    MOV R1, #1          ; Interrupt received, continue
    WFE                 ; Wait for event
    MOV R2, #2          ; Event received, continue
Output
Processor enters low-power state at WFI and WFE instructions and resumes execution when interrupt or event occurs.
🎯

When to Use

Use WFI when your program needs to pause and wait specifically for an interrupt, such as a hardware signal from a timer or input device. This helps save battery life in embedded systems or mobile devices.

Use WFE when you want to wait for a broader range of events, including signals from other processors or software triggers. This is useful in multi-core systems or when coordinating between different parts of a program.

Key Points

  • WFI waits only for interrupts to wake the processor.
  • WFE waits for any event, including interrupts or signals.
  • Both reduce power use by pausing the CPU until needed.
  • Commonly used in embedded and low-power ARM systems.

Key Takeaways

WFI pauses the processor until an interrupt occurs to save power.
WFE pauses the processor until any event or interrupt occurs.
Both instructions help ARM processors reduce energy use during idle times.
Use WFI for interrupt-driven waits and WFE for broader event-driven waits.