15. WFI/WFE Low-Power Mechanism
The Nuclei processor core can support sleep mode for lower power consumption.
15.1. Enter the Sleep Mode
The Nuclei processor core can enter sleep mode by executing the WFI instruction. When the core executes the WFI instruction, it will perform following operations:
Stop executing the current instruction stream immediately.
Waiting for the core to complete any outstanding transactions, such as fetching instructions, load or store operations, to ensure that all the transactions sent to the bus are completed.
If a memory access error exception occurs while waiting for a bus operation to complete, the core will enter the exception handling mode rather than sleep mode.
When all of the outstanding transactions are completed, the core safely enters an idle state, which is called the sleep mode.
When entered the sleep mode:
The clocks of the main units inside the core will be gated off to save dynamic power consumption.
The output signal core_wfi_mode of the core will be asserted to indicate that this core is in the sleep mode after executing the WFI instruction.
The output signal core_sleep_value of the core will output the value of the CSR register sleepvalue (Note: this signal is valid only when the core_wfi_mode is asserted; if the signal core_wfi_mode is 0, then the value of core_sleep_value must be 0). The software can indicate different sleep modes (0 as shallow sleep or 1 as deep sleep) by set the CSR register sleepvalue in advance.
The Nuclei processor core behaves exactly the same for different sleep modes. These sleep modes only provide different output value (via output signal core_sleep_value) for different controlling scheme to the Power Management Unit (PMU) at the SoC system level.
When entering to the deep sleep mode, the processor core will no longer be able to be debugged by JTAG interface.
15.2. Wait for Interrupt
The Wait for Interrupt mechanism refers to make the core enter the sleep mode, and the core keeps waiting for an interrupt to wake up.
15.3. Wait for Event
The Wait for Event mechanism refers to make the core enter the sleep mode, and the core keeps waiting for an event to wake up. When the core wakes up by the event, it continues to execute the previously interrupted instruction stream.
As mentioned in Enter the Sleep Mode, the Wait for Event mechanism can be implemented by executing the WFI instruction combined with the following sequence of instructions:
15.4. Exit the Sleep Mode
The key points of the Nuclei processor core exiting the sleep mode are as follows:
The output signal core_wfi_mode of the core is cleared to 0.
The core can be woken up in four ways:
These will be described in detail next.
15.4.1. Wake Up by NMI
NMI can always wake up the core. When the core detects a rising edge of the input signal nmi, the core is woken up and jumps to the NMI service routine.
15.4.2. Wake Up by Interrupt
Interrupts can wake up the core as well:
If the value of wfe.WFE is set to 0, t he core will be waited for the interrupt to wake up. In this case, the behavior of WFI wake up is just following the RISC-V standard architecture. This document will not repeat its content here, please refer to RISC-V standard privileged architecture specification for more details.
If the value of wfe.WFE is set to 1, the core will be waited for an event to wake up. Please see the detailed description in the next section.
15.4.3. Wake Up by Event
Event can wake up the processor core when the following conditions are met:
If the value of wfe.WFE is set to 1, then:
When the core detects that the input signal rx_evt (called the event signal) is asserted, the core will be woken up and continue to execute the previously interrupted instruction stream. Please refer to the specific datasheet of the Nuclei processor core for details about the signal rx_evt.
15.4.4. Wake Up by Debug Request
Debug requests can always wake up the core. If the debugger is connected, it will also wake up the core and enter the debug mode.