gr55xx_hal_pwr_mgmt.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file gr55xx_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 __GR55xx_HAL_PWR_MGMT_H__
54 #define __GR55xx_HAL_PWR_MGMT_H__
55 
56 /* Includes ------------------------------------------------------------------*/
57 #include "gr55xx_hal_def.h"
58 #include <stdio.h>
59 #include <stdbool.h>
60 
61 /**
62  * @defgroup HAL_PWR_MGMT_MACRO Defines
63  * @{
64  */
65 
66 /* Exported constants --------------------------------------------------------*/
67 /** @defgroup PWR_MGMT_Exported_Constants PWR_MGMT Exported Constants
68  * @{
69  */
70 #define ALL_DEVICES_SLEEP (0xFFFFFFFFU) /**< All peripherals sleep */
71 #define ALL_DEVICES_BACKUP (0x00000000U) /**< All peripherals backed up*/
72 /** @} */
73 
74 /** @} */
75 
76 /* Exported types ------------------------------------------------------------*/
77 /** @addtogroup HAL_PWR_MGMT_ENUMERATIONS Enumerations
78  * @{
79  */
80 
81 /**
82  * @brief Peripheral Device ID definition
83  * NOTE:The order of enumeration is the order of recovery
84  */
85 typedef enum
86 {
121 
122 /**
123  * @brief Extra Device ID definition
124  */
125 typedef enum
126 {
133 
134 /**
135  * @brief Peripheral Device State definition
136  */
137 typedef enum
138 {
139  IDLE = 0,
140  ACTIVE
142 /** @} */
143 
144 /** @addtogroup HAL_PWR_MGMT_TYPEDEFS Type defintions
145  * @{
146  */
147 
148 /**
149  * @brief Peripheral suspend callback definition
150  */
151 typedef hal_status_t (*p_device_suspend_func)(void *p_dev_handle);
152 
153 /**
154  * @brief Peripheral resume callback definition
155  */
156 typedef hal_status_t (*p_device_resume_func)(void *p_dev_handle);
157 
158 /** @} */
159 
160 
161 /* Exported variable --------------------------------------------------------*/
162 /** @addtogroup HAL_PWR_MGMT_VARIABLE Variables
163  * @{
164  */
165 
166 extern volatile uint32_t g_devices_state; /**< All peripheral status.When all are idle, the system can sleep */
167 extern volatile uint32_t g_devices_renew; /**< Peripheral updata flag.If peripherals have been used, they need to be backed up */
168 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 */
169 extern p_device_suspend_func devices_suspend_cb[MAX_PERIPH_DEVICE_NUM]; /**< Store the suspend function of all peripherals */
170 extern p_device_resume_func devices_resume_cb[MAX_PERIPH_DEVICE_NUM]; /**< Store the resume function of all peripherals */
171 extern void* devices_handle[MAX_PERIPH_DEVICE_NUM]; /**<Store the handle addresses of all peripheral instances */
172 
173 extern volatile uint32_t g_extra_devices_state; /**< All extra devices status.When all are idle, the system can sleep */
174 extern volatile uint32_t g_extra_devices_renew; /**< Extra devices updata flag.If extra devices have been used, they need to be backed up */
175 extern p_device_suspend_func extra_devices_suspend_cb[MAX_EXTRA_DEVICE_NUM]; /**< Store the suspend function of all extra devices */
176 extern p_device_resume_func extra_devices_resume_cb[MAX_EXTRA_DEVICE_NUM]; /**< Store the resume function of all extra devices */
177 extern void* extra_devices_handle[MAX_EXTRA_DEVICE_NUM]; /**<Store the handle addresses of all extra devices instances */
178 
179 /** @} */
180 
181 /* Exported functions --------------------------------------------------------*/
182 /** @addtogroup HAL_PWR_MGMT_DRIVER_FUNCTIONS Functions
183  * @{
184  */
185 
186 /**
187  ****************************************************************************************
188  * @brief Set peripheral suspend function
189  *
190  * @param[in] dev_num: Peripheral device ID definition.
191  * @param[in] my_device_suspend_function: Peripheral suspend callback function.
192 
193  * @retval void.
194  ****************************************************************************************
195  */
197 
198 /**
199  ****************************************************************************************
200  * @brief Release peripheral suspend function
201  *
202  * @param[in] dev_num: Peripheral device ID definition.
203 
204  * @retval void.
205  ****************************************************************************************
206  */
208 
209 /**
210  ****************************************************************************************
211  * @brief Set peripheral resume function
212  *
213  * @param[in] dev_num: Peripheral device ID definition.
214  * @param[in] my_device_resume_function: Peripheral resume callback function.
215 
216  * @retval void.
217  ****************************************************************************************
218  */
220 
221 /**
222  ****************************************************************************************
223  * @brief Release peripheral resume function
224  *
225  * @param[in] dev_num: Peripheral device ID definition.
226 
227  * @retval void.
228  ****************************************************************************************
229  */
231 
232 /**
233  ****************************************************************************************
234  * @brief Store the specified peripheral handle
235  *
236  * @param[in] dev_num: Peripheral device ID definition.
237  * @param[in] p_dev: Pointer to the specified peripheral handle.
238 
239  * @retval void.
240  ****************************************************************************************
241  */
243 
244 /**
245  ****************************************************************************************
246  * @brief Clear the specified peripheral handle
247  *
248  * @param[in] dev_num: Peripheral device ID definition.
249 
250  * @retval void.
251  ****************************************************************************************
252  */
254 
255 /**
256  ****************************************************************************************
257  * @brief Store the specified peripheral state
258  *
259  * @param[in] dev_num: Peripheral device ID definition.
260  * @param[in] state: the specified peripheral state.
261 
262  * @retval void.
263  ****************************************************************************************
264  */
266 
267 /**
268  ****************************************************************************************
269  * @brief Store the specified peripheral backup flag
270  *
271  * @param[in] dev_num: Peripheral device ID definition.
272 
273  * @retval void.
274  ****************************************************************************************
275  */
277 
278 /**
279  ****************************************************************************************
280  * @brief Store the specified peripheral sleep flag
281  *
282  * @param[in] dev_num: Peripheral device ID definition.
283 
284  * @retval void.
285  ****************************************************************************************
286  */
288 
289 /**
290  ****************************************************************************************
291  * @brief Set extra device suspend function
292  *
293  * @param[in] dev_num: extra device ID definition.
294  * @param[in] my_device_suspend_function: extra suspend callback function.Set NULL to release
295  * @param[in] p_dev_handle: Pointer to the specified extra device handle.
296  * @retval void.
297  ****************************************************************************************
298  */
299 void hal_pwr_mgmt_extra_device_suspend_register(extra_device_number_t dev_num, p_device_suspend_func my_device_suspend_function, void* p_dev_handle);
300 
301 /**
302  ****************************************************************************************
303  * @brief Set extra resume function
304  *
305  * @param[in] dev_num: extra device ID definition.
306  * @param[in] my_device_resume_function: extra resume callback function.Set NULL to release
307  * @param[in] p_dev_handle: Pointer to the specified extra device handle.
308 
309  * @retval void.
310  ****************************************************************************************
311  */
312 void hal_pwr_mgmt_extra_device_resume_register(extra_device_number_t dev_num, p_device_resume_func my_device_resume_function, void* p_dev_handle);
313 
314 /**
315  ****************************************************************************************
316  * @brief set the specified extra device state
317  *
318  * @param[in] dev_num: extra device ID definition.
319  * @param[in] state: the specified extra device state.
320 
321  * @retval void.
322  ****************************************************************************************
323  */
325 
326 /**
327  ****************************************************************************************
328  * @brief set the specified extra device updata flag
329  *
330  * @param[in] dev_num: extra device ID definition.
331 
332  * @retval void.
333  ****************************************************************************************
334  */
336 
337 /** @} */
338 
339 #endif /*__GR55xx_HAL_PWR_MGMT_H__*/
340 
341 /** @} */
342 
343 /** @} */
344 
345 /** @} */
PERIPH_DEVICE_NUM_UART1
@ PERIPH_DEVICE_NUM_UART1
Definition: gr55xx_hal_pwr_mgmt.h:104
PERIPH_DEVICE_NUM_PDM
@ PERIPH_DEVICE_NUM_PDM
Definition: gr55xx_hal_pwr_mgmt.h:111
EXTRA_DEVICE_NUM_OSPI
@ EXTRA_DEVICE_NUM_OSPI
Definition: gr55xx_hal_pwr_mgmt.h:130
EXTRA_DEVICE_NUM_DC
@ EXTRA_DEVICE_NUM_DC
Definition: gr55xx_hal_pwr_mgmt.h:129
extra_device_number_t
extra_device_number_t
Extra Device ID definition.
Definition: gr55xx_hal_pwr_mgmt.h:126
PERIPH_DEVICE_NUM_I2C5
@ PERIPH_DEVICE_NUM_I2C5
Definition: gr55xx_hal_pwr_mgmt.h:102
devices_resume_cb
p_device_resume_func devices_resume_cb[MAX_PERIPH_DEVICE_NUM]
PERIPH_DEVICE_NUM_RNG
@ PERIPH_DEVICE_NUM_RNG
Definition: gr55xx_hal_pwr_mgmt.h:113
hal_pwr_mgmt_clear_device_handle
void hal_pwr_mgmt_clear_device_handle(periph_device_number_t dev_num)
Clear the specified peripheral handle.
MAX_EXTRA_DEVICE_NUM
@ MAX_EXTRA_DEVICE_NUM
Definition: gr55xx_hal_pwr_mgmt.h:131
g_devices_sleep
volatile uint32_t g_devices_sleep
IDLE
@ IDLE
Definition: gr55xx_hal_pwr_mgmt.h:139
PERIPH_DEVICE_NUM_QSPI2
@ PERIPH_DEVICE_NUM_QSPI2
Definition: gr55xx_hal_pwr_mgmt.h:93
EXTRA_DEVICE_NUM_GPU
@ EXTRA_DEVICE_NUM_GPU
Definition: gr55xx_hal_pwr_mgmt.h:128
PERIPH_DEVICE_NUM_USB
@ PERIPH_DEVICE_NUM_USB
Definition: gr55xx_hal_pwr_mgmt.h:118
PERIPH_DEVICE_NUM_I2C3
@ PERIPH_DEVICE_NUM_I2C3
Definition: gr55xx_hal_pwr_mgmt.h:100
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.
hal_pwr_mgmt_set_extra_device_state
void hal_pwr_mgmt_set_extra_device_state(extra_device_number_t dev_num, periph_state_t state)
set the specified extra device state
devices_handle
void * devices_handle[MAX_PERIPH_DEVICE_NUM]
hal_pwr_mgmt_extra_device_resume_register
void hal_pwr_mgmt_extra_device_resume_register(extra_device_number_t dev_num, p_device_resume_func my_device_resume_function, void *p_dev_handle)
Set extra resume function.
EXTRA_DEVICE_NUM_CLK_CALIB
@ EXTRA_DEVICE_NUM_CLK_CALIB
Definition: gr55xx_hal_pwr_mgmt.h:127
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: gr55xx_hal_pwr_mgmt.h:97
PERIPH_DEVICE_NUM_I2C2
@ PERIPH_DEVICE_NUM_I2C2
Definition: gr55xx_hal_pwr_mgmt.h:99
PERIPH_DEVICE_NUM_PKC
@ PERIPH_DEVICE_NUM_PKC
Definition: gr55xx_hal_pwr_mgmt.h:90
PERIPH_DEVICE_NUM_I2S_M
@ PERIPH_DEVICE_NUM_I2S_M
Definition: gr55xx_hal_pwr_mgmt.h:109
PERIPH_DEVICE_NUM_SPIM
@ PERIPH_DEVICE_NUM_SPIM
Definition: gr55xx_hal_pwr_mgmt.h:94
PERIPH_DEVICE_NUM_ISO7816
@ PERIPH_DEVICE_NUM_ISO7816
Definition: gr55xx_hal_pwr_mgmt.h:89
hal_pwr_mgmt_set_extra_device_renew_flag
void hal_pwr_mgmt_set_extra_device_renew_flag(extra_device_number_t dev_num)
set the specified extra device updata flag
extra_devices_resume_cb
p_device_resume_func extra_devices_resume_cb[MAX_EXTRA_DEVICE_NUM]
extra_devices_suspend_cb
p_device_suspend_func extra_devices_suspend_cb[MAX_EXTRA_DEVICE_NUM]
hal_pwr_mgmt_extra_device_suspend_register
void hal_pwr_mgmt_extra_device_suspend_register(extra_device_number_t dev_num, p_device_suspend_func my_device_suspend_function, void *p_dev_handle)
Set extra device suspend function.
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.
PERIPH_DEVICE_NUM_QSPI1
@ PERIPH_DEVICE_NUM_QSPI1
Definition: gr55xx_hal_pwr_mgmt.h:92
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.
PERIPH_DEVICE_NUM_HMAC
@ PERIPH_DEVICE_NUM_HMAC
Definition: gr55xx_hal_pwr_mgmt.h:112
p_device_suspend_func
hal_status_t(* p_device_suspend_func)(void *p_dev_handle)
Peripheral suspend callback definition.
Definition: gr55xx_hal_pwr_mgmt.h:151
ACTIVE
@ ACTIVE
Definition: gr55xx_hal_pwr_mgmt.h:140
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_resume_func
hal_status_t(* p_device_resume_func)(void *p_dev_handle)
Peripheral resume callback definition.
Definition: gr55xx_hal_pwr_mgmt.h:156
PERIPH_DEVICE_NUM_QSPI0
@ PERIPH_DEVICE_NUM_QSPI0
Definition: gr55xx_hal_pwr_mgmt.h:91
PERIPH_DEVICE_NUM_UART0
@ PERIPH_DEVICE_NUM_UART0
Definition: gr55xx_hal_pwr_mgmt.h:103
PERIPH_DEVICE_NUM_UART3
@ PERIPH_DEVICE_NUM_UART3
Definition: gr55xx_hal_pwr_mgmt.h:106
PERIPH_DEVICE_NUM_UART5
@ PERIPH_DEVICE_NUM_UART5
Definition: gr55xx_hal_pwr_mgmt.h:108
PERIPH_DEVICE_NUM_PWM0
@ PERIPH_DEVICE_NUM_PWM0
Definition: gr55xx_hal_pwr_mgmt.h:115
PERIPH_DEVICE_NUM_I2S_S
@ PERIPH_DEVICE_NUM_I2S_S
Definition: gr55xx_hal_pwr_mgmt.h:110
PERIPH_DEVICE_NUM_DMA1
@ PERIPH_DEVICE_NUM_DMA1
Definition: gr55xx_hal_pwr_mgmt.h:88
extra_devices_handle
void * extra_devices_handle[MAX_EXTRA_DEVICE_NUM]
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
g_extra_devices_renew
volatile uint32_t g_extra_devices_renew
g_devices_state
volatile uint32_t g_devices_state
PERIPH_DEVICE_NUM_I2C4
@ PERIPH_DEVICE_NUM_I2C4
Definition: gr55xx_hal_pwr_mgmt.h:101
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_UART2
@ PERIPH_DEVICE_NUM_UART2
Definition: gr55xx_hal_pwr_mgmt.h:105
PERIPH_DEVICE_NUM_DSPI
@ PERIPH_DEVICE_NUM_DSPI
Definition: gr55xx_hal_pwr_mgmt.h:96
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: gr55xx_hal_pwr_mgmt.h:119
PERIPH_DEVICE_NUM_UART4
@ PERIPH_DEVICE_NUM_UART4
Definition: gr55xx_hal_pwr_mgmt.h:107
PERIPH_DEVICE_NUM_I2C1
@ PERIPH_DEVICE_NUM_I2C1
Definition: gr55xx_hal_pwr_mgmt.h:98
g_extra_devices_state
volatile uint32_t g_extra_devices_state
PERIPH_DEVICE_NUM_SPIS
@ PERIPH_DEVICE_NUM_SPIS
Definition: gr55xx_hal_pwr_mgmt.h:95
PERIPH_DEVICE_NUM_PWM1
@ PERIPH_DEVICE_NUM_PWM1
Definition: gr55xx_hal_pwr_mgmt.h:116
PERIPH_DEVICE_NUM_AES
@ PERIPH_DEVICE_NUM_AES
Definition: gr55xx_hal_pwr_mgmt.h:114
PERIPH_DEVICE_NUM_SNSADC
@ PERIPH_DEVICE_NUM_SNSADC
Definition: gr55xx_hal_pwr_mgmt.h:117
devices_suspend_cb
p_device_suspend_func devices_suspend_cb[MAX_PERIPH_DEVICE_NUM]
periph_state_t
periph_state_t
Peripheral Device State definition.
Definition: gr55xx_hal_pwr_mgmt.h:138
periph_device_number_t
periph_device_number_t
Peripheral Device ID definition NOTE:The order of enumeration is the order of recovery.
Definition: gr55xx_hal_pwr_mgmt.h:86
PERIPH_DEVICE_NUM_DMA0
@ PERIPH_DEVICE_NUM_DMA0
Definition: gr55xx_hal_pwr_mgmt.h:87
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
g_devices_renew
volatile uint32_t g_devices_renew