gr533x_hal_pwr_mgmt.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr533x_hal_pwr_mgmt.h
5 * @author BLE Driver Team
6 * @brief This file contains all the functions prototypes for the HAL
7 * module driver.
8 *
9 ****************************************************************************************
10 * @attention
11 #####Copyright (c) 2019 GOODIX
12 All rights reserved.
13
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions are met:
16 * Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18 * Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21 * Neither the name of GOODIX nor the names of its contributors may be used
22 to endorse or promote products derived from this software without
23 specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
29 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 POSSIBILITY OF SUCH DAMAGE.
36 ****************************************************************************************
37 */
38
39 /** @addtogroup PERIPHERAL Peripheral Driver
40 * @{
41 */
42
43 /** @addtogroup HAL_DRIVER HAL Driver
44 * @{
45 */
46
47 /** @defgroup HAL_PWR_MGMT PWR_MGMT
48 * @brief PWR_MGMT HAL module driver.
49 * @{
50 */
51
52 /* Define to prevent recursive inclusion -------------------------------------*/
53 #ifndef __GR533x_HAL_PWR_MGMT_H__
54 #define __GR533x_HAL_PWR_MGMT_H__
55
56 /* Includes ------------------------------------------------------------------*/
57 #include "gr533x_hal_def.h"
58 #include <stdio.h>
59 #include <stdbool.h>
60
61 /**
62 * @defgroup HAL_MACRO Defines
63 * @{
64 */
65 #define ALL_DEVICES_SLEEP (0xFFFFFFFFU) /**< All devive sleep */
66 #define ALL_DEVICES_BACKUP (0x00000000U) /**< All devive backup */
67 /** @} */
68
69 /** @addtogroup HAL_PWR_MGMT_ENUMERATIONS Enumerations
70 * @{
71 */
72 /**
73 * @brief Peripheral Device ID definition
74 */
75 typedef enum
76 {
77 PERIPH_DEVICE_NUM_SPIM = 0,
78 PERIPH_DEVICE_NUM_SPIS, //NO.=1
79 PERIPH_DEVICE_NUM_I2C0, //NO.=2
80 PERIPH_DEVICE_NUM_I2C1, //NO.=3
81 PERIPH_DEVICE_NUM_UART0, //NO.=4
82 PERIPH_DEVICE_NUM_UART1, //NO.=5
83 PERIPH_DEVICE_NUM_PWM0, //NO.=6
84 PERIPH_DEVICE_NUM_PWM1, //NO.=7
85 PERIPH_DEVICE_NUM_DMA0, //NO.=8
86 PERIPH_DEVICE_NUM_AES, //NO.=9
87 PERIPH_DEVICE_NUM_RNG, //NO.=10
88 PERIPH_DEVICE_NUM_SNSADC, //NO.=11
89 PERIPH_DEVICE_NUM_CLK_CALIB,//NO.=12
90 MAX_PERIPH_DEVICE_NUM
91 } periph_device_number_t;
92
93 /**
94 * @brief Peripheral Device State definition
95 */
96 typedef enum
97 {
98 IDLE = 0,
99 ACTIVE
100 } periph_state_t;
101
102 /** @} */
103
104 /** @addtogroup HAL_PWR_MGMT_Callback Callback
105 * @{
106 */
107 /**
108 * @brief HAL_PWR_SUSPEND Callback function definition
109 */
110 typedef hal_status_t (*p_device_suspend_func)(void *p_dev_handle);
111 /**
112 * @brief HAL_PWR_RESUME Callback function definition
113 */
114 typedef hal_status_t (*p_device_resume_func)(void *p_dev_handle);
115
116 /** @} */
117
118 /* Exported variable --------------------------------------------------------*/
119 extern volatile uint32_t g_devices_state; /**< All peripheral status.When all are idle, the system can sleep */
120 extern volatile uint32_t g_devices_renew; /**< Peripheral backup flag.If peripherals have been used, they need to be backed up */
121 extern volatile uint32_t g_devices_sleep; /**< Peripheral sleep flag.Go to sleep as 0xFFFFFFFF.The corresponding bit is cleared to 0 after wake-up recovery */
122 extern p_device_suspend_func devices_suspend_cb[MAX_PERIPH_DEVICE_NUM]; /**< Store the suspend function of all peripherals */
123 extern p_device_resume_func devices_resume_cb[MAX_PERIPH_DEVICE_NUM]; /**< Store the resume function of all peripherals */
124 extern void* devices_handle[MAX_PERIPH_DEVICE_NUM]; /**<Store the handle addresses of all peripheral instances */
125
126
127 /* Exported functions --------------------------------------------------------*/
128 /** @addtogroup HAL_PWR_MGMT_DRIVER_FUNCTIONS Functions
129 * @{
130 */
131 /**
132 ****************************************************************************************
133 * @brief Set peripheral suspend function
134 *
135 * @param[in] dev_num: Peripheral device ID definition.
136 * @param[in] my_device_suspend_function: Peripheral suspend callback function.
137
138 * @retval void.
139 ****************************************************************************************
140 */
141 void hal_pwr_mgmt_device_suspend_register(periph_device_number_t dev_num, p_device_suspend_func my_device_suspend_function);
142
143 /**
144 ****************************************************************************************
145 * @brief Release peripheral suspend function
146 *
147 * @param[in] dev_num: Peripheral device ID definition.
148
149 * @retval void.
150 ****************************************************************************************
151 */
152 void hal_pwr_mgmt_device_suspend_release(periph_device_number_t dev_num);
153
154 /**
155 ****************************************************************************************
156 * @brief Set peripheral resume function
157 *
158 * @param[in] dev_num: Peripheral device ID definition.
159 * @param[in] my_device_resume_function: Peripheral resume callback function.
160
161 * @retval void.
162 ****************************************************************************************
163 */
164 void hal_pwr_mgmt_device_resume_register(periph_device_number_t dev_num, p_device_resume_func my_device_resume_function);
165
166 /**
167 ****************************************************************************************
168 * @brief Release peripheral resume function
169 *
170 * @param[in] dev_num: Peripheral device ID definition.
171
172 * @retval void.
173 ****************************************************************************************
174 */
175 void hal_pwr_mgmt_device_resume_release(periph_device_number_t dev_num);
176
177 /**
178 ****************************************************************************************
179 * @brief Store the specified peripheral handle
180 *
181 * @param[in] dev_num: Peripheral device ID definition.
182 * @param[in] p_dev: Pointer to the specified peripheral handle.
183
184 * @retval void.
185 ****************************************************************************************
186 */
187 void hal_pwr_mgmt_save_device_handle(periph_device_number_t dev_num,void* p_dev);
188
189 /**
190 ****************************************************************************************
191 * @brief Clear the specified peripheral handle
192 *
193 * @param[in] dev_num: Peripheral device ID definition.
194
195 * @retval void.
196 ****************************************************************************************
197 */
198 void hal_pwr_mgmt_clear_device_handle(periph_device_number_t dev_num);
199
200 /**
201 ****************************************************************************************
202 * @brief Store the specified peripheral state
203 *
204 * @param[in] dev_num: Peripheral device ID definition.
205 * @param[in] state: the specified peripheral state.
206
207 * @retval void.
208 ****************************************************************************************
209 */
210 void hal_pwr_mgmt_set_device_state(periph_device_number_t dev_num, periph_state_t state);
211
212 /**
213 ****************************************************************************************
214 * @brief Store the specified peripheral backup flag
215 *
216 * @param[in] dev_num: Peripheral device ID definition.
217
218 * @retval void.
219 ****************************************************************************************
220 */
221 void hal_pwr_mgmt_set_device_renew_flag(periph_device_number_t dev_num);
222
223 /**
224 ****************************************************************************************
225 * @brief Store the specified peripheral sleep flag
226 *
227 * @param[in] dev_num: Peripheral device ID definition.
228
229 * @retval void.
230 ****************************************************************************************
231 */
232 void hal_pwr_mgmt_clear_device_sleep_flag(periph_device_number_t dev_num);
233
234 /** @} */
235
236 #endif /*__GR533x_HAL_PWR_MGMT_H__*/
237
238 /** @} */
239
240 /** @} */
241
242 /** @} */
PERIPH_DEVICE_NUM_UART1
@ PERIPH_DEVICE_NUM_UART1
Definition: gr533x_hal_pwr_mgmt.h:82
PERIPH_DEVICE_NUM_RNG
@ PERIPH_DEVICE_NUM_RNG
Definition: gr533x_hal_pwr_mgmt.h:87
hal_pwr_mgmt_clear_device_handle
void hal_pwr_mgmt_clear_device_handle(periph_device_number_t dev_num)
Clear the specified peripheral handle.
devices_resume_cb
p_device_resume_func devices_resume_cb[MAX_PERIPH_DEVICE_NUM]
IDLE
@ IDLE
Definition: gr533x_hal_pwr_mgmt.h:98
hal_pwr_mgmt_set_device_state
void hal_pwr_mgmt_set_device_state(periph_device_number_t dev_num, periph_state_t state)
Store the specified peripheral state.
devices_handle
void * devices_handle[MAX_PERIPH_DEVICE_NUM]
hal_pwr_mgmt_device_resume_release
void hal_pwr_mgmt_device_resume_release(periph_device_number_t dev_num)
Release peripheral resume function.
PERIPH_DEVICE_NUM_I2C0
@ PERIPH_DEVICE_NUM_I2C0
Definition: gr533x_hal_pwr_mgmt.h:79
PERIPH_DEVICE_NUM_SPIM
@ PERIPH_DEVICE_NUM_SPIM
Definition: gr533x_hal_pwr_mgmt.h:77
p_device_resume_func
hal_status_t(* p_device_resume_func)(void *p_dev_handle)
HAL_PWR_RESUME Callback function definition.
Definition: gr533x_hal_pwr_mgmt.h:114
hal_pwr_mgmt_set_device_renew_flag
void hal_pwr_mgmt_set_device_renew_flag(periph_device_number_t dev_num)
Store the specified peripheral backup flag.
hal_pwr_mgmt_save_device_handle
void hal_pwr_mgmt_save_device_handle(periph_device_number_t dev_num, void *p_dev)
Store the specified peripheral handle.
g_devices_renew
volatile uint32_t g_devices_renew
ACTIVE
@ ACTIVE
Definition: gr533x_hal_pwr_mgmt.h:99
g_devices_state
volatile uint32_t g_devices_state
hal_pwr_mgmt_device_suspend_register
void hal_pwr_mgmt_device_suspend_register(periph_device_number_t dev_num, p_device_suspend_func my_device_suspend_function)
Set peripheral suspend function.
hal_pwr_mgmt_clear_device_sleep_flag
void hal_pwr_mgmt_clear_device_sleep_flag(periph_device_number_t dev_num)
Store the specified peripheral sleep flag.
p_device_suspend_func
hal_status_t(* p_device_suspend_func)(void *p_dev_handle)
HAL_PWR_SUSPEND Callback function definition.
Definition: gr533x_hal_pwr_mgmt.h:110
PERIPH_DEVICE_NUM_UART0
@ PERIPH_DEVICE_NUM_UART0
Definition: gr533x_hal_pwr_mgmt.h:81
PERIPH_DEVICE_NUM_PWM0
@ PERIPH_DEVICE_NUM_PWM0
Definition: gr533x_hal_pwr_mgmt.h:83
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr533x_hal_def.h:70
hal_pwr_mgmt_device_suspend_release
void hal_pwr_mgmt_device_suspend_release(periph_device_number_t dev_num)
Release peripheral suspend function.
PERIPH_DEVICE_NUM_CLK_CALIB
@ PERIPH_DEVICE_NUM_CLK_CALIB
Definition: gr533x_hal_pwr_mgmt.h:89
hal_pwr_mgmt_device_resume_register
void hal_pwr_mgmt_device_resume_register(periph_device_number_t dev_num, p_device_resume_func my_device_resume_function)
Set peripheral resume function.
MAX_PERIPH_DEVICE_NUM
@ MAX_PERIPH_DEVICE_NUM
Definition: gr533x_hal_pwr_mgmt.h:90
g_devices_sleep
volatile uint32_t g_devices_sleep
PERIPH_DEVICE_NUM_I2C1
@ PERIPH_DEVICE_NUM_I2C1
Definition: gr533x_hal_pwr_mgmt.h:80
PERIPH_DEVICE_NUM_SPIS
@ PERIPH_DEVICE_NUM_SPIS
Definition: gr533x_hal_pwr_mgmt.h:78
PERIPH_DEVICE_NUM_PWM1
@ PERIPH_DEVICE_NUM_PWM1
Definition: gr533x_hal_pwr_mgmt.h:84
PERIPH_DEVICE_NUM_AES
@ PERIPH_DEVICE_NUM_AES
Definition: gr533x_hal_pwr_mgmt.h:86
gr533x_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
PERIPH_DEVICE_NUM_SNSADC
@ PERIPH_DEVICE_NUM_SNSADC
Definition: gr533x_hal_pwr_mgmt.h:88
periph_state_t
periph_state_t
Peripheral Device State definition.
Definition: gr533x_hal_pwr_mgmt.h:97
periph_device_number_t
periph_device_number_t
Peripheral Device ID definition.
Definition: gr533x_hal_pwr_mgmt.h:76
PERIPH_DEVICE_NUM_DMA0
@ PERIPH_DEVICE_NUM_DMA0
Definition: gr533x_hal_pwr_mgmt.h:85
devices_suspend_cb
p_device_suspend_func devices_suspend_cb[MAX_PERIPH_DEVICE_NUM]