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 {
96 
97 /**
98  * @brief Peripheral Device State definition
99  */
100 typedef enum
101 {
102  IDLE = 0,
103  ACTIVE
105 
106 /** @} */
107 
108 /** @addtogroup HAL_PWR_MGMT_Callback Callback
109  * @{
110  */
111 /**
112  * @brief HAL_PWR_SUSPEND Callback function definition
113  */
114 typedef hal_status_t (*p_device_suspend_func)(void *p_dev_handle);
115 /**
116  * @brief HAL_PWR_RESUME Callback function definition
117  */
118 typedef hal_status_t (*p_device_resume_func)(void *p_dev_handle);
119 
120 /** @} */
121 
122 /* Exported variable --------------------------------------------------------*/
123 extern volatile uint32_t g_devices_state; /**< All peripheral status.When all are idle, the system can sleep */
124 extern volatile uint32_t g_devices_renew; /**< Peripheral backup flag.If peripherals have been used, they need to be backed up */
125 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 */
126 extern p_device_suspend_func devices_suspend_cb[MAX_PERIPH_DEVICE_NUM]; /**< Store the suspend function of all peripherals */
127 extern p_device_resume_func devices_resume_cb[MAX_PERIPH_DEVICE_NUM]; /**< Store the resume function of all peripherals */
128 extern void* devices_handle[MAX_PERIPH_DEVICE_NUM]; /**<Store the handle addresses of all peripheral instances */
129 
130 
131 /* Exported functions --------------------------------------------------------*/
132 /** @addtogroup HAL_PWR_MGMT_DRIVER_FUNCTIONS Functions
133  * @{
134  */
135 /**
136  ****************************************************************************************
137  * @brief Set peripheral suspend function
138  *
139  * @param[in] dev_num: Peripheral device ID definition.
140  * @param[in] my_device_suspend_function: Peripheral suspend callback function.
141 
142  * @retval void.
143  ****************************************************************************************
144  */
146 
147 /**
148  ****************************************************************************************
149  * @brief Release peripheral suspend function
150  *
151  * @param[in] dev_num: Peripheral device ID definition.
152 
153  * @retval void.
154  ****************************************************************************************
155  */
157 
158 /**
159  ****************************************************************************************
160  * @brief Set peripheral resume function
161  *
162  * @param[in] dev_num: Peripheral device ID definition.
163  * @param[in] my_device_resume_function: Peripheral resume callback function.
164 
165  * @retval void.
166  ****************************************************************************************
167  */
169 
170 /**
171  ****************************************************************************************
172  * @brief Release peripheral resume function
173  *
174  * @param[in] dev_num: Peripheral device ID definition.
175 
176  * @retval void.
177  ****************************************************************************************
178  */
180 
181 /**
182  ****************************************************************************************
183  * @brief Store the specified peripheral handle
184  *
185  * @param[in] dev_num: Peripheral device ID definition.
186  * @param[in] p_dev: Pointer to the specified peripheral handle.
187 
188  * @retval void.
189  ****************************************************************************************
190  */
192 
193 /**
194  ****************************************************************************************
195  * @brief Clear the specified peripheral handle
196  *
197  * @param[in] dev_num: Peripheral device ID definition.
198 
199  * @retval void.
200  ****************************************************************************************
201  */
203 
204 /**
205  ****************************************************************************************
206  * @brief Store the specified peripheral state
207  *
208  * @param[in] dev_num: Peripheral device ID definition.
209  * @param[in] state: the specified peripheral state.
210 
211  * @retval void.
212  ****************************************************************************************
213  */
215 
216 /**
217  ****************************************************************************************
218  * @brief Store the specified peripheral backup flag
219  *
220  * @param[in] dev_num: Peripheral device ID definition.
221 
222  * @retval void.
223  ****************************************************************************************
224  */
226 
227 /**
228  ****************************************************************************************
229  * @brief Store the specified peripheral sleep flag
230  *
231  * @param[in] dev_num: Peripheral device ID definition.
232 
233  * @retval void.
234  ****************************************************************************************
235  */
237 
238 /** @} */
239 
240 #endif /*__GR533x_HAL_PWR_MGMT_H__*/
241 
242 /** @} */
243 
244 /** @} */
245 
246 /** @} */
PERIPH_DEVICE_NUM_TIM1
@ PERIPH_DEVICE_NUM_TIM1
Definition: gr533x_hal_pwr_mgmt.h:91
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:102
PERIPH_DEVICE_NUM_TIM0
@ PERIPH_DEVICE_NUM_TIM0
Definition: gr533x_hal_pwr_mgmt.h:90
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:118
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:103
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:114
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
PERIPH_DEVICE_NUM_DUAL_TIM0
@ PERIPH_DEVICE_NUM_DUAL_TIM0
Definition: gr533x_hal_pwr_mgmt.h:92
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:94
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_DUAL_TIM1
@ PERIPH_DEVICE_NUM_DUAL_TIM1
Definition: gr533x_hal_pwr_mgmt.h:93
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:101
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]