Low-power states the CPU idles in, provided by the SoC.
More...
Low-power states the CPU idles in, provided by the SoC.
When nothing is runnable, the kernel picks the deepest state that no driver blocks and is worth entering for the time until the next timeout, programs the system clock event device to wake the CPU up early enough, enters the state, and accounts for the time spent in it from the system clock source. The SoC only puts the CPU to sleep.
Idle states need CONFIG_CPU_IDLE. Without it the kernel only calls pbl_cpu_idle(), a tick at a time, pbl_idle_state_block() and pbl_idle_state_release() do nothing, and nothing else here is available.
};
const struct pbl_idle_state pbl_soc_idle_states[]
Idle states, shallowest first.
const size_t pbl_soc_num_idle_states
Number of entries in pbl_soc_idle_states.
static void pbl_cpu_idle(void)
Wait for an interrupt.
Definition idle.h:65
#define PBL_ARRAY_SIZE(array)
Get the number of elements of an array.
Definition size.h:40
Idle state.
Definition idle.h:45
const char * name
Name, for statistics.
Definition idle.h:47
◆ pbl_idle_hook_times
| struct pbl_idle_hook_times |
Times of an idle hook, see pbl_idle_hook_set_times().
| Data Fields |
|
pbl_tick_t |
exit_ticks |
Time the exit function takes, in ticks; the CPU is woken up this much earlier. |
|
pbl_tick_t |
min_ticks |
Shortest time until the next timeout worth calling the hook for, in ticks; 0 until set, and the hook is not called meanwhile. |
◆ pbl_idle_latency_request
| struct pbl_idle_latency_request |
◆ PBL_IDLE_HOOK
| #define PBL_IDLE_HOOK |
( |
|
_name | ) |
(&pbl_idle_hook_##_name) |
◆ PBL_IDLE_HOOK_DEFINE
| #define PBL_IDLE_HOOK_DEFINE |
( |
|
_name, |
|
|
|
_enter, |
|
|
|
_exit, |
|
|
|
_arg |
|
) |
| |
Value:
.arg = (_arg), \
.
times = &pbl_idle_hook_times_##_name, \
}
Times of an idle hook, see pbl_idle_hook_set_times().
Definition idle.h:90
#define PBL_ITERABLE_SECTION(type, tag, key)
Add the object to an iterable section, a table gathered at link time from any file.
Definition section.h:124
Idle hook, see PBL_IDLE_HOOK_DEFINE.
Definition idle.h:101
void(* enter)(pbl_idle_state_id_t state, void *arg)
Called before the CPU enters a state, may be NULL.
Definition idle.h:103
struct pbl_idle_hook_times * times
Times, NULL for a late hook.
Definition idle.h:109
void(* exit)(pbl_idle_state_id_t state, void *arg)
Called after the CPU left a state, may be NULL.
Definition idle.h:105
Define a hook, for a driver to act before the CPU idles and after.
The kernel calls the hooks around the idle states once their times are set with pbl_idle_hook_set_times(), when the time until the next timeout is at least the hook's minimum, and wakes the CPU up earlier by the time its exit function takes. It tells the state in state, an index in pbl_soc_idle_states, for a hook that only acts around some. Hooks run with every interrupt masked: they must be short and cannot block. On the way out they run in the opposite order.
prv_power_down(arg);
}
static int prv_init(void) {
return 0;
}
void pbl_idle_hook_set_times(const struct pbl_idle_hook *hook, uint32_t min_us, uint32_t exit_us)
Set the times of a hook, rounded up to ticks.
#define PBL_IDLE_HOOK_DEFINE(_name, _enter, _exit, _arg)
Define a hook, for a driver to act before the CPU idles and after.
Definition idle.h:154
#define PBL_IDLE_HOOK(_name)
Get a hook defined with PBL_IDLE_HOOK_DEFINE in the same file.
Definition idle.h:173
uint8_t pbl_idle_state_id_t
Index of an idle state in pbl_soc_idle_states.
Definition idle.h:42
Hooks are not called without CONFIG_CPU_IDLE.
- Parameters
-
| _name | Identifier unique among hooks. |
| _enter | Function called before entering a state, or NULL. |
| _exit | Function called after leaving a state, or NULL. |
| _arg | Argument of the functions. |
◆ PBL_IDLE_HOOK_LATE_DEFINE
| #define PBL_IDLE_HOOK_LATE_DEFINE |
( |
|
_name, |
|
|
|
_enter, |
|
|
|
_exit, |
|
|
|
_arg |
|
) |
| |
Value:
#_name) = {.
enter = (_enter), .
exit = (_exit), .arg = (_arg)}
Define a hook the SoC calls last before the CPU idles and first after.
For what must happen once the SoC took down what code needs to run from flash, where a state does. The SoC calls late hooks from the innermost part of such states. The functions, and all they call, must be PBL_SECTION_RAM or inline. Otherwise as PBL_IDLE_HOOK_DEFINE, without times: they belong to the state.
◆ PBL_IDLE_STATES_MAX
| #define PBL_IDLE_STATES_MAX 4 |
Maximum number of idle states.
◆ pbl_idle_state_id_t
◆ pbl_cpu_idle()
| static void pbl_cpu_idle |
( |
void |
| ) |
|
|
static |
Wait for an interrupt.
The shallowest idle state; deeper ones wrap it. Returns once an interrupt is pending, even a masked one. Always inlined, so it can run while the flash is powered down.
◆ pbl_cpu_idle_deep()
| static void pbl_cpu_idle_deep |
( |
void |
| ) |
|
|
static |
Wait for an interrupt in the CPU's deep sleep.
What deep sleep stops is up to the SoC. Always inlined, like pbl_cpu_idle().
◆ pbl_idle_hook_set_times()
| void pbl_idle_hook_set_times |
( |
const struct pbl_idle_hook * |
hook, |
|
|
uint32_t |
min_us, |
|
|
uint32_t |
exit_us |
|
) |
| |
Set the times of a hook, rounded up to ticks.
A driver sets them once it knows them, e.g. from the part it found; the hook is not called before.
- Parameters
-
| hook | Hook, see PBL_IDLE_HOOK. |
| min_us | Shortest time until the next timeout worth calling the hook for, in microseconds. |
| exit_us | Time the exit function takes, in microseconds. |
◆ pbl_idle_hooks_late_enter()
Call the enter function of every late hook.
Runs from RAM.
- Parameters
-
◆ pbl_idle_hooks_late_exit()
Call the exit function of every late hook.
Runs from RAM.
- Parameters
-
◆ pbl_idle_latency_request_add()
Keep the CPU out of the idle states, and off the hooks, that take longer to wake up from.
For code that must run within some time of an interrupt, whatever the state the CPU idles in, as opposed to a peripheral that does not work in a state, see pbl_idle_state_block(). The shortest request applies. Can be called from ISRs. Does nothing without CONFIG_CPU_IDLE.
prv_radio_event();
Request on the time the CPU takes to wake up, see pbl_idle_latency_request_add().
Definition idle.h:240
static void pbl_idle_latency_request_remove(struct pbl_idle_latency_request *req)
Remove a request added with pbl_idle_latency_request_add().
Definition idle.h:282
static void pbl_idle_latency_request_add(struct pbl_idle_latency_request *req, uint32_t us)
Keep the CPU out of the idle states, and off the hooks, that take longer to wake up from.
Definition idle.h:268
- Parameters
-
| req | Request, not added yet. Must stay valid until removed. |
| us | Longest time to wake up tolerated, in microseconds. |
◆ pbl_idle_latency_request_remove()
◆ pbl_idle_residency_us()
Get the time spent in an idle state since boot.
- Parameters
-
- Returns
- Microseconds.
◆ pbl_idle_set_enabled()
| void pbl_idle_set_enabled |
( |
bool |
enable | ) |
|
Allow the CPU to idle or keep it running, e.g.
while measuring.
Idle is allowed at boot.
- Parameters
-
| enable | False to keep the CPU out of every idle state. |
◆ pbl_idle_state_block()
Keep the CPU out of an idle state and of every deeper one.
For a peripheral that does not work in the state, while it is busy. SoCs name their states, so that the call reads like the datasheet:
prv_receive();
static void pbl_idle_state_block(pbl_idle_state_id_t state)
Keep the CPU out of an idle state and of every deeper one.
Definition idle.h:221
static void pbl_idle_state_release(pbl_idle_state_id_t state)
Release a block taken with pbl_idle_state_block().
Definition idle.h:234
Counted: balance each call with pbl_idle_state_release(). Can be called from ISRs. Does nothing without CONFIG_CPU_IDLE.
- Parameters
-
◆ pbl_idle_state_release()
◆ pbl_soc_idle_states
Idle states, shallowest first.
Defined by SoCs that select CONFIG_SOC_HAS_IDLE_STATES; for the others the kernel defines a single state that calls pbl_cpu_idle().
◆ pbl_soc_num_idle_states
| const size_t pbl_soc_num_idle_states |
|
extern |