RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
pm.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2024 RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2012-06-02 Bernard the first version
9 * 2018-08-02 Tanek split run and sleep modes, support custom mode
10 * 2019-04-28 Zero-Free improve PM mode and device ops interface
11 * 2020-11-23 zhangsz update pm mode select
12 * 2020-11-27 zhangsz update pm 2.0
13 * 2024-07-04 wdfk-prog The device is registered and uninstalled by linked list
14 */
15
16#ifndef __PM_H__
17#define __PM_H__
18
19#include <stdint.h>
20#include <rtthread.h>
21#include <drivers/lptimer.h>
22
23/* All modes used for rt_pm_request() and rt_pm_release() */
24enum
25{
26 /* sleep modes */
34};
35
36enum
37{
38 /* run modes*/
44};
45
46enum
47{
49};
50
51/* The name of all modes used in the msh command "pm_dump" */
52#define PM_SLEEP_MODE_NAMES \
53{ \
54 "None Mode", \
55 "Idle Mode", \
56 "LightSleep Mode", \
57 "DeepSleep Mode", \
58 "Standby Mode", \
59 "Shutdown Mode", \
60}
61
62#define PM_RUN_MODE_NAMES \
63{ \
64 "High Speed", \
65 "Normal Speed", \
66 "Medium Speed", \
67 "Low Mode", \
68}
69
70#ifndef PM_USING_CUSTOM_CONFIG
97
98#else
99
100#include <pm_cfg.h>
101
102#endif /* PM_USING_CUSTOM_CONFIG */
103
104#ifndef RT_PM_DEFAULT_SLEEP_MODE
105#define RT_PM_DEFAULT_SLEEP_MODE PM_SLEEP_MODE_NONE
106#endif
107
108#ifndef RT_PM_DEFAULT_DEEPSLEEP_MODE
109#define RT_PM_DEFAULT_DEEPSLEEP_MODE PM_SLEEP_MODE_DEEP
110#endif
111
112#ifndef RT_PM_DEFAULT_RUN_MODE
113#define RT_PM_DEFAULT_RUN_MODE PM_RUN_MODE_NORMAL_SPEED
114#endif
115
119#define RT_PM_DEVICE_CTRL_RELEASE (RT_DEVICE_CTRL_BASE(PM) + 0x00)
120#define RT_PM_DEVICE_CTRL_REQUEST (RT_DEVICE_CTRL_BASE(PM) + 0x01)
121
122struct rt_pm;
123
128{
129 void (*sleep)(struct rt_pm *pm, rt_uint8_t mode);
130 void (*run)(struct rt_pm *pm, rt_uint8_t mode);
131 void (*timer_start)(struct rt_pm *pm, rt_uint32_t timeout);
132 void (*timer_stop)(struct rt_pm *pm);
134};
135
137{
138 rt_err_t (*suspend)(const struct rt_device *device, rt_uint8_t mode);
139 void (*resume)(const struct rt_device *device, rt_uint8_t mode);
140 rt_err_t (*frequency_change)(const struct rt_device *device, rt_uint8_t mode);
141};
142
144{
145 const struct rt_device *device;
146 const struct rt_device_pm_ops *ops;
148};
149
157
161struct rt_pm
162{
164
165 /* modes */
167 rt_uint8_t sleep_mode; /* current sleep mode */
168 rt_uint8_t run_mode; /* current running mode */
169
170 /* modules request status*/
172
173 /* sleep request table */
175
176 /* the list of device, which has PM feature */
179
180 /* if the mode has timer, the corresponding bit is 1*/
183
184 const struct rt_pm_ops *ops;
185};
186
187enum
188{
191};
192
194{
195 void (*notify)(rt_uint8_t event, rt_uint8_t mode, void *data);
196 void *data;
197};
198
203
204void rt_pm_device_register(struct rt_device *device, const struct rt_device_pm_ops *ops);
206
207void rt_pm_notify_set(void (*notify)(rt_uint8_t event, rt_uint8_t mode, void *data), void *data);
209
210void rt_system_pm_init(const struct rt_pm_ops *ops,
211 rt_uint8_t timer_mask,
212 void *user_data);
213rt_err_t rt_pm_module_request(uint8_t module_id, rt_uint8_t sleep_mode);
214rt_err_t rt_pm_module_release(uint8_t module_id, rt_uint8_t sleep_mode);
215rt_err_t rt_pm_module_release_all(uint8_t module_id, rt_uint8_t sleep_mode);
220
221/* sleep : request or release */
230
231#endif /* __PM_H__ */
@ PM_SLEEP_MODE_STANDBY
定义 pm.h:31
@ PM_SLEEP_MODE_NONE
定义 pm.h:27
@ PM_SLEEP_MODE_LIGHT
定义 pm.h:29
@ PM_SLEEP_MODE_DEEP
定义 pm.h:30
@ PM_SLEEP_MODE_SHUTDOWN
定义 pm.h:32
@ PM_SLEEP_MODE_IDLE
定义 pm.h:28
@ PM_SLEEP_MODE_MAX
定义 pm.h:33
rt_err_t rt_pm_sleep_none_request(rt_uint16_t module_id)
rt_err_t rt_pm_sleep_none_release(rt_uint16_t module_id)
rt_err_t rt_pm_release(rt_uint8_t sleep_mode)
void rt_pm_device_unregister(struct rt_device *device)
void rt_pm_notify_set(void(*notify)(rt_uint8_t event, rt_uint8_t mode, void *data), void *data)
rt_uint32_t rt_pm_module_get_status(void)
@ RT_PM_FREQUENCY_PENDING
定义 pm.h:48
rt_err_t rt_pm_sleep_light_release(rt_uint16_t module_id)
void rt_system_pm_init(const struct rt_pm_ops *ops, rt_uint8_t timer_mask, void *user_data)
rt_err_t rt_pm_module_release_all(uint8_t module_id, rt_uint8_t sleep_mode)
void rt_pm_module_delay_sleep(rt_uint8_t module_id, rt_tick_t timeout)
rt_err_t rt_pm_sleep_release(rt_uint16_t module_id, rt_uint8_t mode)
void rt_pm_default_set(rt_uint8_t sleep_mode)
rt_err_t rt_pm_module_request(uint8_t module_id, rt_uint8_t sleep_mode)
void rt_pm_device_register(struct rt_device *device, const struct rt_device_pm_ops *ops)
rt_err_t rt_pm_sleep_idle_request(rt_uint16_t module_id)
rt_err_t rt_pm_module_release(uint8_t module_id, rt_uint8_t sleep_mode)
pm_module_id
定义 pm.h:77
@ PM_PMC_ID
定义 pm.h:84
@ PM_PMS_ID
定义 pm.h:83
@ PM_LCD_ID
定义 pm.h:92
@ PM_ETH_ID
定义 pm.h:90
@ PM_SPI_ID
定义 pm.h:86
@ PM_KEY_ID
定义 pm.h:93
@ PM_POWER_ID
定义 pm.h:79
@ PM_BSP_ID
定义 pm.h:81
@ PM_MAIN_ID
定义 pm.h:82
@ PM_SENSOR_ID
定义 pm.h:91
@ PM_NONE_ID
定义 pm.h:78
@ PM_I2C_ID
定义 pm.h:87
@ PM_CAN_ID
定义 pm.h:89
@ PM_TASK_ID
定义 pm.h:85
@ PM_UART_ID
定义 pm.h:88
@ PM_MODULE_MAX_ID
定义 pm.h:95
@ PM_BOARD_ID
定义 pm.h:80
@ PM_TP_ID
定义 pm.h:94
rt_err_t rt_pm_request(rt_uint8_t sleep_mode)
rt_err_t rt_pm_sleep_request(rt_uint16_t module_id, rt_uint8_t mode)
rt_err_t rt_pm_sleep_light_request(rt_uint16_t module_id)
@ RT_PM_EXIT_SLEEP
定义 pm.h:190
@ RT_PM_ENTER_SLEEP
定义 pm.h:189
rt_uint8_t rt_pm_get_sleep_mode(void)
rt_err_t rt_pm_release_all(rt_uint8_t sleep_mode)
struct rt_pm * rt_pm_get_handle(void)
rt_err_t rt_pm_sleep_idle_release(rt_uint16_t module_id)
@ PM_RUN_MODE_LOW_SPEED
定义 pm.h:42
@ PM_RUN_MODE_MAX
定义 pm.h:43
@ PM_RUN_MODE_HIGH_SPEED
定义 pm.h:39
@ PM_RUN_MODE_NORMAL_SPEED
定义 pm.h:40
@ PM_RUN_MODE_MEDIUM_SPEED
定义 pm.h:41
rt_err_t rt_pm_run_enter(rt_uint8_t run_mode)
int rt_bool_t
rt_base_t rt_err_t
unsigned char rt_uint8_t
unsigned short rt_uint16_t
rt_uint32_t rt_tick_t
unsigned int rt_uint32_t
struct rt_slist_node rt_slist_t
rt_err_t(* suspend)(const struct rt_device *device, rt_uint8_t mode)
定义 pm.h:138
rt_err_t(* frequency_change)(const struct rt_device *device, rt_uint8_t mode)
定义 pm.h:140
void(* resume)(const struct rt_device *device, rt_uint8_t mode)
定义 pm.h:139
rt_slist_t list
定义 pm.h:147
const struct rt_device_pm_ops * ops
定义 pm.h:146
const struct rt_device * device
定义 pm.h:145
rt_uint32_t timeout
定义 pm.h:154
rt_uint8_t req_status
定义 pm.h:152
rt_bool_t busy_flag
定义 pm.h:153
rt_uint32_t start_time
定义 pm.h:155
void(* notify)(rt_uint8_t event, rt_uint8_t mode, void *data)
定义 pm.h:195
void * data
定义 pm.h:196
rt_tick_t(* timer_get_tick)(struct rt_pm *pm)
定义 pm.h:133
void(* timer_stop)(struct rt_pm *pm)
定义 pm.h:132
void(* timer_start)(struct rt_pm *pm, rt_uint32_t timeout)
定义 pm.h:131
void(* sleep)(struct rt_pm *pm, rt_uint8_t mode)
定义 pm.h:129
void(* run)(struct rt_pm *pm, rt_uint8_t mode)
定义 pm.h:130
rt_slist_t device_list
定义 pm.h:177
rt_uint8_t run_mode
定义 pm.h:168
struct rt_pm_module module_status[PM_MODULE_MAX_ID]
定义 pm.h:171
rt_uint32_t sleep_status[PM_SLEEP_MODE_MAX - 1][(PM_MODULE_MAX_ID+31)/32]
定义 pm.h:174
rt_uint8_t sleep_mode
定义 pm.h:167
rt_uint8_t modes[PM_SLEEP_MODE_MAX]
定义 pm.h:166
struct rt_device_pm * device_pm
定义 pm.h:178
struct rt_device parent
定义 pm.h:163
rt_uint8_t timer_mask
定义 pm.h:181
const struct rt_pm_ops * ops
定义 pm.h:184
rt_uint8_t flags
定义 pm.h:182