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_CALLBACK_STRUCTURES Callback Structures
145  * @{
146  */
147 
148 /** @defgroup PWR_MGMT_Callback PWR_MGMT Callback
149  * @{
150  */
151 
152 /**
153  * @brief Peripheral suspend callback definition
154  */
155 typedef hal_status_t (*p_device_suspend_func)(void *p_dev_handle);
156 
157 /**
158  * @brief Peripheral resume callback definition
159  */
160 typedef hal_status_t (*p_device_resume_func)(void *p_dev_handle);
161 
162 /** @} */
163 
164 /** @} */
165 
166 
167 /* Exported variable --------------------------------------------------------*/
168 /** @addtogroup HAL_PWR_MGMT_VARIABLE Variables
169  * @{
170  */
171 
172 extern volatile uint32_t g_devices_state; /**< All peripheral status.When all are idle, the system can sleep */
173 extern volatile uint32_t g_devices_renew; /**< Peripheral updata flag.If peripherals have been used, they need to be backed up */
174 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 */
175 extern p_device_suspend_func devices_suspend_cb[MAX_PERIPH_DEVICE_NUM]; /**< Store the suspend function of all peripherals */
176 extern p_device_resume_func devices_resume_cb[MAX_PERIPH_DEVICE_NUM]; /**< Store the resume function of all peripherals */
177 extern void* devices_handle[MAX_PERIPH_DEVICE_NUM]; /**<Store the handle addresses of all peripheral instances */
178 
179 extern volatile uint32_t g_extra_devices_state; /**< All extra devices status.When all are idle, the system can sleep */
180 extern volatile uint32_t g_extra_devices_renew; /**< Extra devices updata flag.If extra devices have been used, they need to be backed up */
181 extern p_device_suspend_func extra_devices_suspend_cb[MAX_EXTRA_DEVICE_NUM]; /**< Store the suspend function of all extra devices */
182 extern p_device_resume_func extra_devices_resume_cb[MAX_EXTRA_DEVICE_NUM]; /**< Store the resume function of all extra devices */
183 extern void* extra_devices_handle[MAX_EXTRA_DEVICE_NUM]; /**<Store the handle addresses of all extra devices instances */
184 
185 /** @} */
186 
187 /* Exported functions --------------------------------------------------------*/
188 /** @addtogroup HAL_PWR_MGMT_DRIVER_FUNCTIONS Functions
189  * @{
190  */
191 
192 /**
193  ****************************************************************************************
194  * @brief Set peripheral suspend function
195  *
196  * @param[in] dev_num: Peripheral device ID definition.
197  * @param[in] my_device_suspend_function: Peripheral suspend callback function.
198 
199  * @retval void.
200  ****************************************************************************************
201  */
203 
204 /**
205  ****************************************************************************************
206  * @brief Release peripheral suspend function
207  *
208  * @param[in] dev_num: Peripheral device ID definition.
209 
210  * @retval void.
211  ****************************************************************************************
212  */
214 
215 /**
216  ****************************************************************************************
217  * @brief Set peripheral resume function
218  *
219  * @param[in] dev_num: Peripheral device ID definition.
220  * @param[in] my_device_resume_function: Peripheral resume callback function.
221 
222  * @retval void.
223  ****************************************************************************************
224  */
226 
227 /**
228  ****************************************************************************************
229  * @brief Release peripheral resume function
230  *
231  * @param[in] dev_num: Peripheral device ID definition.
232 
233  * @retval void.
234  ****************************************************************************************
235  */
237 
238 /**
239  ****************************************************************************************
240  * @brief Store the specified peripheral handle
241  *
242  * @param[in] dev_num: Peripheral device ID definition.
243  * @param[in] p_dev: Pointer to the specified peripheral handle.
244 
245  * @retval void.
246  ****************************************************************************************
247  */
249 
250 /**
251  ****************************************************************************************
252  * @brief Clear the specified peripheral handle
253  *
254  * @param[in] dev_num: Peripheral device ID definition.
255 
256  * @retval void.
257  ****************************************************************************************
258  */
260 
261 /**
262  ****************************************************************************************
263  * @brief Store the specified peripheral state
264  *
265  * @param[in] dev_num: Peripheral device ID definition.
266  * @param[in] state: the specified peripheral state.
267 
268  * @retval void.
269  ****************************************************************************************
270  */
272 
273 /**
274  ****************************************************************************************
275  * @brief Store the specified peripheral backup flag
276  *
277  * @param[in] dev_num: Peripheral device ID definition.
278 
279  * @retval void.
280  ****************************************************************************************
281  */
283 
284 /**
285  ****************************************************************************************
286  * @brief Store the specified peripheral sleep flag
287  *
288  * @param[in] dev_num: Peripheral device ID definition.
289 
290  * @retval void.
291  ****************************************************************************************
292  */
294 
295 /**
296  ****************************************************************************************
297  * @brief Set extra device suspend function
298  *
299  * @param[in] dev_num: extra device ID definition.
300  * @param[in] my_device_suspend_function: extra suspend callback function.Set NULL to release
301  * @param[in] p_dev_handle: Pointer to the specified extra device handle.
302  * @retval void.
303  ****************************************************************************************
304  */
305 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);
306 
307 /**
308  ****************************************************************************************
309  * @brief Set extra resume function
310  *
311  * @param[in] dev_num: extra device ID definition.
312  * @param[in] my_device_resume_function: extra resume callback function.Set NULL to release
313  * @param[in] p_dev_handle: Pointer to the specified extra device handle.
314 
315  * @retval void.
316  ****************************************************************************************
317  */
318 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);
319 
320 /**
321  ****************************************************************************************
322  * @brief set the specified extra device state
323  *
324  * @param[in] dev_num: extra device ID definition.
325  * @param[in] state: the specified extra device state.
326 
327  * @retval void.
328  ****************************************************************************************
329  */
331 
332 /**
333  ****************************************************************************************
334  * @brief set the specified extra device updata flag
335  *
336  * @param[in] dev_num: extra device ID definition.
337 
338  * @retval void.
339  ****************************************************************************************
340  */
342 
343 /** @} */
344 
345 #endif /*__GR55xx_HAL_PWR_MGMT_H__*/
346 
347 /** @} */
348 
349 /** @} */
350 
351 /** @} */
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_number_t
extra_device_number_t
Extra Device ID definition.
Definition: gr55xx_hal_pwr_mgmt.h:126
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
PERIPH_DEVICE_NUM_UNUSED0
@ PERIPH_DEVICE_NUM_UNUSED0
Definition: gr55xx_hal_pwr_mgmt.h:89
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.
PERIPH_DEVICE_NUM_UNUSED5
@ PERIPH_DEVICE_NUM_UNUSED5
Definition: gr55xx_hal_pwr_mgmt.h:118
PERIPH_DEVICE_NUM_UNUSED3
@ PERIPH_DEVICE_NUM_UNUSED3
Definition: gr55xx_hal_pwr_mgmt.h:107
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_UNUSED1
@ PERIPH_DEVICE_NUM_UNUSED1
Definition: gr55xx_hal_pwr_mgmt.h:101
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_DEVICE_NUM_UNUSED2
@ EXTRA_DEVICE_NUM_UNUSED2
Definition: gr55xx_hal_pwr_mgmt.h:130
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
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:155
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
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.
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_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]
EXTRA_DEVICE_NUM_UNUSED1
@ EXTRA_DEVICE_NUM_UNUSED1
Definition: gr55xx_hal_pwr_mgmt.h:129
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
EXTRA_DEVICE_NUM_UNUSED0
@ EXTRA_DEVICE_NUM_UNUSED0
Definition: gr55xx_hal_pwr_mgmt.h:128
g_extra_devices_renew
volatile uint32_t g_extra_devices_renew
g_devices_state
volatile uint32_t g_devices_state
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_UNUSED4
@ PERIPH_DEVICE_NUM_UNUSED4
Definition: gr55xx_hal_pwr_mgmt.h:108
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_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
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:160
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
PERIPH_DEVICE_NUM_UNUSED2
@ PERIPH_DEVICE_NUM_UNUSED2
Definition: gr55xx_hal_pwr_mgmt.h:102
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
g_devices_renew
volatile uint32_t g_devices_renew