Introduction
Idle mode helps save power by stopping the CPU when it has nothing to do.
Idle mode helps save power by stopping the CPU when it has nothing to do.
void enter_idle_mode(void) {
// Set CPU to idle mode
// Wait for interrupt to wake up
__asm__("WFI");
}WFI stands for 'Wait For Interrupt'. It stops the CPU until an interrupt happens.
This is often used in microcontrollers to save power.
void enter_idle_mode(void) {
__asm__("WFI");
}void enter_idle_mode(void) {
// Prepare peripherals before idle
disable_unused_peripherals();
__asm__("WFI");
}This program shows entering idle mode and waking up after an interrupt (simulated here).
#include <stdio.h> void enter_idle_mode(void) { // Simulate idle mode with WFI instruction printf("Entering idle mode...\n"); __asm__("WFI"); printf("Woke up from idle mode.\n"); } int main(void) { printf("System running.\n"); enter_idle_mode(); printf("System resumed work.\n"); return 0; }
Idle mode stops the CPU but keeps peripherals running.
Interrupts like timers or buttons can wake the CPU from idle.
Using idle mode helps extend battery life in embedded devices.
Idle mode pauses the CPU to save power when idle.
Use the WFI instruction to enter idle mode.
Interrupts wake the CPU to resume work.
__asm__("WFI");
// CPU is idle here until interrupt occursvoid enter_idle() {
__asm__("WFI");
__disable_irq();
}if (no_tasks_pending()) {
__disable_irq();
if (no_tasks_pending()) {
__asm__("WFI");
}
__enable_irq();
}Pass the test and this pattern moves unknown