forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpower.h
327 lines (290 loc) · 8.97 KB
/
power.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_POWER_POWER_H_
#define ZEPHYR_INCLUDE_POWER_POWER_H_
#include <zephyr/types.h>
#include <power/power_state.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup power_management_api Power Management
* @{
* @}
*/
/**
* @brief System power states.
*/
enum power_states {
SYS_POWER_STATE_AUTO = (-2),
SYS_POWER_STATE_ACTIVE = (-1),
#ifdef CONFIG_SYS_POWER_SLEEP_STATES
# ifdef CONFIG_HAS_SYS_POWER_STATE_SLEEP_1
SYS_POWER_STATE_SLEEP_1,
# endif
# ifdef CONFIG_HAS_SYS_POWER_STATE_SLEEP_2
SYS_POWER_STATE_SLEEP_2,
# endif
# ifdef CONFIG_HAS_SYS_POWER_STATE_SLEEP_3
SYS_POWER_STATE_SLEEP_3,
# endif
#endif /* CONFIG_SYS_POWER_SLEEP_STATES */
#ifdef CONFIG_SYS_POWER_DEEP_SLEEP_STATES
# ifdef CONFIG_HAS_SYS_POWER_STATE_DEEP_SLEEP_1
SYS_POWER_STATE_DEEP_SLEEP_1,
# endif
# ifdef CONFIG_HAS_SYS_POWER_STATE_DEEP_SLEEP_2
SYS_POWER_STATE_DEEP_SLEEP_2,
# endif
# ifdef CONFIG_HAS_SYS_POWER_STATE_DEEP_SLEEP_3
SYS_POWER_STATE_DEEP_SLEEP_3,
# endif
#endif /* CONFIG_SYS_POWER_DEEP_SLEEP_STATES */
SYS_POWER_STATE_MAX
};
#ifdef CONFIG_SYS_POWER_MANAGEMENT
extern unsigned char sys_pm_idle_exit_notify;
/**
* @brief System Power Management API
*
* @defgroup system_power_management_api System Power Management API
* @ingroup power_management_api
* @{
*/
/**
* @brief Check if particular power state is a sleep state.
*
* This function returns true if given power state is a sleep state.
*/
static inline bool sys_pm_is_sleep_state(enum power_states state)
{
bool ret = true;
switch (state) {
#ifdef CONFIG_SYS_POWER_SLEEP_STATES
# ifdef CONFIG_HAS_SYS_POWER_STATE_SLEEP_1
case SYS_POWER_STATE_SLEEP_1:
break;
# endif
# ifdef CONFIG_HAS_SYS_POWER_STATE_SLEEP_2
case SYS_POWER_STATE_SLEEP_2:
break;
# endif
# ifdef CONFIG_HAS_SYS_POWER_STATE_SLEEP_3
case SYS_POWER_STATE_SLEEP_3:
break;
# endif
#endif /* CONFIG_SYS_POWER_SLEEP_STATES */
default:
ret = false;
break;
}
return ret;
}
/**
* @brief Check if particular power state is a deep sleep state.
*
* This function returns true if given power state is a deep sleep state.
*/
static inline bool sys_pm_is_deep_sleep_state(enum power_states state)
{
bool ret = true;
switch (state) {
#ifdef CONFIG_SYS_POWER_DEEP_SLEEP_STATES
# ifdef CONFIG_HAS_SYS_POWER_STATE_DEEP_SLEEP_1
case SYS_POWER_STATE_DEEP_SLEEP_1:
break;
# endif
# ifdef CONFIG_HAS_SYS_POWER_STATE_DEEP_SLEEP_2
case SYS_POWER_STATE_DEEP_SLEEP_2:
break;
# endif
# ifdef CONFIG_HAS_SYS_POWER_STATE_DEEP_SLEEP_3
case SYS_POWER_STATE_DEEP_SLEEP_3:
break;
# endif
#endif /* CONFIG_SYS_POWER_DEEP_SLEEP_STATES */
default:
ret = false;
break;
}
return ret;
}
/**
* @brief Function to disable power management idle exit notification
*
* The _sys_resume() would be called from the ISR of the event that caused
* exit from kernel idling after PM operations. For some power operations,
* this notification may not be necessary. This function can be called in
* _sys_suspend to disable the corresponding _sys_resume notification.
*
*/
static inline void _sys_pm_idle_exit_notification_disable(void)
{
sys_pm_idle_exit_notify = 0U;
}
/**
* @brief Force usage of given power state.
*
* This function overrides decision made by PM policy forcing
* usage of given power state in the ongoing suspend operation.
* And before the end of suspend, the state of forced_pm_state
* is cleared with interrupt disabled.
*
* If enabled SYS_PM_DIRECT_FORCE_MODE, this function can only
* run in thread context.
*
* @param state Power state which should be used in the ongoing
* suspend operation or SYS_POWER_STATE_AUTO.
*/
void sys_pm_force_power_state(enum power_states state);
/**
* @brief Put processor into a power state.
*
* This function implements the SoC specific details necessary
* to put the processor into available power states.
*/
void sys_set_power_state(enum power_states state);
#ifdef CONFIG_SYS_PM_DEBUG
/**
* @brief Dump Low Power states related debug info
*
* Dump Low Power states debug info like LPS entry count and residencies.
*/
void sys_pm_dump_debug_info(void);
#endif /* CONFIG_SYS_PM_DEBUG */
#ifdef CONFIG_SYS_PM_STATE_LOCK
/**
* @brief Disable particular power state
*
* @details Disabled state cannot be selected by the Zephyr power
* management policies. Application defined policy should
* use the @ref sys_pm_ctrl_is_state_enabled function to
* check if given state could is enabled and could be used.
*
* @param [in] state Power state to be disabled.
*/
void sys_pm_ctrl_disable_state(enum power_states state);
/**
* @brief Enable particular power state
*
* @details Enabled state can be selected by the Zephyr power
* management policies. Application defined policy should
* use the @ref sys_pm_ctrl_is_state_enabled function to
* check if given state could is enabled and could be used.
* By default all power states are enabled.
*
* @param [in] state Power state to be enabled.
*/
void sys_pm_ctrl_enable_state(enum power_states state);
/**
* @brief Check if particular power state is enabled
*
* This function returns true if given power state is enabled.
*
* @param [in] state Power state.
*/
bool sys_pm_ctrl_is_state_enabled(enum power_states state);
#endif /* CONFIG_SYS_PM_STATE_LOCK */
/**
* @}
*/
/**
* @brief Power Management Hooks
*
* @defgroup power_management_hook_interface Power Management Hooks
* @ingroup power_management_api
* @{
*/
/**
* @brief Restore context to the point where system entered the deep sleep
* state.
*
* This function is optionally called when exiting from deep sleep if the SOC
* interface does not have bootloader support to handle resume from deep sleep.
* This function should restore context to the point where system entered
* the deep sleep state.
*
* If the function is called at cold boot it should return immediately.
*
* @note This function is not supported on all architectures.
*/
void _sys_resume_from_deep_sleep(void);
/**
* @brief Notify exit from kernel idling after PM operations
*
* This function would notify exit from kernel idling if a corresponding
* _sys_suspend() notification was handled and did not return
* SYS_POWER_STATE_ACTIVE.
*
* This function would be called from the ISR context of the event
* that caused the exit from kernel idling. This will be called immediately
* after interrupts are enabled. This is called to give a chance to do
* any operations before the kernel would switch tasks or processes nested
* interrupts. This is required for cpu low power states that would require
* interrupts to be enabled while entering low power states. e.g. C1 in x86. In
* those cases, the ISR would be invoked immediately after the event wakes up
* the CPU, before code following the CPU wait, gets a chance to execute. This
* can be ignored if no operation needs to be done at the wake event
* notification. Alternatively _sys_pm_idle_exit_notification_disable() can
* be called in _sys_suspend to disable this notification.
*/
void _sys_resume(void);
/**
* @brief Allow entry to power state
*
* When the kernel is about to go idle, it calls this function to notify the
* power management subsystem, that the kernel is ready to enter the idle state.
*
* At this point, the kernel has disabled interrupts and computed the maximum
* time the system can remain idle. The function passes the time that the system
* can remain idle. The SOC interface performs power operations that can be done
* in the available time. The power management operations must halt execution of
* the CPU.
*
* This function assumes that a wake up event has already been set up by the
* application.
*
* This function is entered with interrupts disabled. It should re-enable
* interrupts if it had entered a power state.
*
* @param ticks The upcoming kernel idle time.
*
* @return Power state which was entered or SYS_POWER_STATE_ACTIVE if SoC was
* kept in the active state.
*/
enum power_states _sys_suspend(int32_t ticks);
/**
* @brief Do any SoC or architecture specific post ops after sleep state exits.
*
* This function is a place holder to do any operations that may
* be needed to be done after sleep state exits. Currently it enables
* interrupts after resuming from sleep state. In future, the enabling
* of interrupts may be moved into the kernel.
*/
void _sys_pm_power_state_exit_post_ops(enum power_states state);
/**
* @brief Application defined function for power state entry
*
* Application defined function for doing any target specific operations
* for power state entry.
*/
void sys_pm_notify_power_state_entry(enum power_states state);
/**
* @brief Application defined function for sleep state exit
*
* Application defined function for doing any target specific operations
* for sleep state exit.
*/
void sys_pm_notify_power_state_exit(enum power_states state);
/**
* @}
*/
#endif /* CONFIG_SYS_POWER_MANAGEMENT */
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_INCLUDE_POWER_POWER_H_ */