platform_sdk.h
Go to the documentation of this file.
1 /**
2  ******************************************************************************
3  *
4  * @file platform_sdk.h
5  *
6  ****************************************************************************************
7  * @attention
8  #####Copyright (c) 2019 GOODIX
9  All rights reserved.
10 
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions are met:
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15  * Redistributions in binary form must reproduce the above copyright
16  notice, this list of conditions and the following disclaimer in the
17  documentation and/or other materials provided with the distribution.
18  * Neither the name of GOODIX nor the names of its contributors may be used
19  to endorse or promote products derived from this software without
20  specific prior written permission.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
26  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  POSSIBILITY OF SUCH DAMAGE.
33  *****************************************************************************************
34  */
35 
36 
37 /**
38  * @addtogroup SYSTEM
39  * @{
40  */
41 
42 /**
43  * @addtogroup Plat_SDK Platform SDK
44  * @{
45  * @brief Definitions and prototypes for the Platform SDK
46  */
47 
48 #ifndef _PLATFORM_SDK_H
49 #define _PLATFORM_SDK_H
50 
51 #include <stdint.h>
52 #include <stdbool.h>
53 #include <stdio.h>
54 #include "system_gr55xx.h"
55 #include "gr55xx_hal_def.h"
56 #include "gr55xx_hal.h"
57 
58 /**
59  * @defgroup PlAT_SDK_MACRO Defines
60  * @{
61  */
62 
63 /** @brief Clock calibration macro. */
64 #define XO_CRYSTAL_FREQ 32000000 //XO 32MHz
65 #define CLK_CAL_STAT_BUSY 0x00
66 #define CLK_CAL_STAT_DONE 0x01
67 #define CLK_CAL_STAT_OVERFLOW 0x100
68 /** @} */
69 
70 /** @addtogroup PlAT_SDK_ENUM Enumerations
71  * @{ */
72 
73 /** @brief system clock and run mode. */
74 typedef enum
75 {
76  XIP_64M = 0, /**< XIP 64M. */
77  XIP_48M, /**< XIP 48M. */
78  XIP_XO16M, /**< XIP XO 16M. */
79  XIP_24M, /**< XIP 24M. */
80  XIP_16M, /**< XIP 16M. */
81  XIP_32M, /**< XIP 32M. */
82  MIRROR_64M, /**< MIRROR 64M. */
83  MIRROR_48M, /**< MIRROR 48M. */
84  MIRROR_XO16M, /**< MIRROR X) 16M. */
85  MIRROR_24M, /**< MIRROR 24M. */
86  MIRROR_16M, /**< MIRROR 16M. */
87  MIRROR_32M, /**< MIRROR 32M. */
88 } table_idx_t;
89 
90 /** @brief sdk clock type. */
91 typedef enum
92 {
93  RNG_OSC_CLK = 0, /**< RNG OSC CLOCK. */
94  RTC_OSC_CLK, /**< RTC OSC CLOCK. */
95  RNG_OSC_CLK2, /**< RNG OSC CLOCK2. */
97 
98 
99 /** @brief memory power setting mode. */
100 typedef enum
101 {
102  MEM_POWER_FULL_MODE = 0, /**< Full mode. */
103  MEM_POWER_AUTO_MODE, /**< Auto mode. */
104 } mem_power_t;
105  /** @} */
106 
107  /**
108  * @defgroup PLAT_SDK_TYPEDEFS Type definitions
109  * @{
110  */
111 
112  /**@brief clock calibration notify callback. */
113  typedef void (*clock_calib_notify_cb_t)(uint16_t SlowClockFreq);
114 
115  /** @} */
116 
117 /** @addtogroup PLAT_SDK_FUNCTIONS Functions
118  * @{ */
119 
120 /**
121  ****************************************************************************************
122  * @brief platform sdk init function.
123  ****************************************************************************************
124  */
125 void platform_sdk_init(void);
126 
127 /**
128  ****************************************************************************************
129  * @brief set the memory power state to full. This function is mainly used in some
130  * scenarios where all SRAMs need to be powered on
131  ****************************************************************************************
132  */
134 
135 /**
136  ****************************************************************************************
137  * @brief Set the memory power management mode, which can be automatic mode or full power on mode.
138  * @param[in] mem_pwr_mode : MEM_POWER_FULL_MODE or MEM_POWER_AUTO_MODE.
139  ****************************************************************************************
140  */
142 
143 /**
144  ****************************************************************************************
145  * @brief Control the memory power supply by specifying start address and length.
146  * @param[in] start_addr : the start address of memory that user want to config
147  * @param[in] size : the size of memory that user want to config
148  ****************************************************************************************
149  */
150 void mem_pwr_mgmt_mode_set_from(uint32_t start_addr, uint32_t size);
151 
152 /**
153  ****************************************************************************************
154  * @brief memory check process
155  ****************************************************************************************
156  */
157 void mem_pwr_mgmt_init(void);
158 
159 /**
160  ****************************************************************************************
161  * @brief Enable patch function.
162  * @param[in] table_idx : Start Index Number.
163  * @param[in] dur_offset : duration setting.
164  * @param[in] ext_offset : ext wakeup setting.
165  * @param[in] osc_offset : pre-wakeup setting.
166  ****************************************************************************************
167  */
168 void system_lp_table_update_twval(table_idx_t table_idx, int16_t dur_offset, int16_t ext_offset, int16_t osc_offset);
169 
170 /**
171  ****************************************************************************************
172  * @brief Leakage Protection for Chip's IO, Only used in Bali A0.
173  ****************************************************************************************
174  */
176 
177 /**
178  ****************************************************************************************
179  * @brief Platform low power clock init function with internal RNG/RNG2 setting.
180  * @param[in] sys_clock System clock.
181  * @param[in] accuracy Low speed clock accuracy.
182  * @param[in] xo_offset Clock calibration parameter.
183  ****************************************************************************************
184  */
185 void platform_clock_init_with_rng2(mcu_clock_type_t sys_clock, uint16_t accuracy, uint16_t xo_offset);
186 
187 /**
188  ****************************************************************************************
189  * @brief Platform low power clock init function with External RTC setting.
190  * @param[in] sys_clock: System clock.
191  * @param[in] accuracy : Low speed clock accuracy.
192  * @param[in] xo_offset : Clock calibration parameter.
193  ****************************************************************************************
194  */
195 void platform_clock_init_with_rtc(mcu_clock_type_t sys_clock, uint16_t accuracy, uint16_t xo_offset);
196 
197 /**
198  ****************************************************************************************
199  * @brief Platform rc calibration function.
200  ****************************************************************************************
201  */
203 
204 /**
205  ****************************************************************************************
206  * @brief Power Management warm boot.
207  ****************************************************************************************
208  */
210 
211 /**
212  ****************************************************************************************
213  * @brief Handle Clock calibration interrupt request.
214  ****************************************************************************************
215  */
217 
218 /**
219  ****************************************************************************************
220  * @brief Platform init function.
221  ****************************************************************************************
222  */
223 void platform_init(void);
224 
225 /**
226  ****************************************************************************************
227  * @brief PMU init function.
228  * @param[in] clock_type : clock type to be configured.
229  ****************************************************************************************
230  */
231 void system_pmu_init(mcu_clock_type_t clock_type);
232 
233 /**
234  ****************************************************************************************
235  * @brief PMU increase function, will increase about 0.35v digcore
236  ****************************************************************************************
237  */
239 
240 /**
241  ****************************************************************************************
242  * @brief PMU restore function.
243  * When wanting to use higher digcore voltage, call system_pmu_increase_for_peripheral(),
244  * when no need use higher voltage anymore, call system_pmu_restore_for_peripheral().
245  ****************************************************************************************
246  */
248 
249 /**
250  ****************************************************************************************
251  * @brief the first warm boot stage.
252  ****************************************************************************************
253  */
254 void warm_boot_first(void);
255 
256  /**
257  ****************************************************************************************
258  * @brief the second warm boot stage.
259  ****************************************************************************************
260  */
261 void warm_boot_second(void);
262 
263 /**
264  ****************************************************************************************
265  * @brief Warm boot process.
266  ****************************************************************************************
267  */
268 void warm_boot(void);
269 
270 /**
271  ****************************************************************************************
272  * @brief PMU calibration handler.
273  * @param[in] p_arg no args.
274  ****************************************************************************************
275  */
276 void pmu_calibration_handler(void* p_arg);
277 
278 /**
279  ****************************************************************************************
280  * @brief Register the clock calibration completion notification interface.
281  * @param[in] calib_notify_cb : Calibration complete callback interface.
282  ****************************************************************************************
283  */
285 
286 #ifdef ENV_USE_FREERTOS
287 /**
288  ****************************************************************************************
289  * @brief start calibration.
290  ****************************************************************************************
291  */
293 #else
294 /**
295  ****************************************************************************************
296  * @brief start calibration.
297  * @param[in] interval : the interval of calibration process.
298  ****************************************************************************************
299  */
300 void system_pmu_calibration_start(uint32_t interval);
301 #endif
302 
303 /**
304  ****************************************************************************************
305  * @brief stop calibration.
306  ****************************************************************************************
307  */
309 
310 /**
311  ****************************************************************************************
312  * @brief write flash QE
313  * @returns hal status
314  ****************************************************************************************
315  */
317 /**
318  ****************************************************************************************
319  * @brief During Flash erase/write operation, Disable external interrupts with a priority less
320  * than or equal to base_priority in the system.
321  * @param[in] base_priority: Base Priority value to set.
322  * @returns hal status
323  ****************************************************************************************
324  */
325 hal_status_t platform_flash_protection(uint32_t base_priority);
326 
327 /**
328  ****************************************************************************************
329  * @brief protection interrupt handler during writing/erasing flash.
330  * @returns hal status
331  ****************************************************************************************
332  */
334 
335 /**
336  ****************************************************************************************
337  * @brief protection interrupt handler during writing/erasing flash.
338  * @returns hal status
339  ****************************************************************************************
340  */
342 
343 /** @} */
344 
345 #endif
346 
347 /** @} */
348 /** @} */
349 
mem_pwr_mgmt_full_power_set
void mem_pwr_mgmt_full_power_set(void)
set the memory power state to full. This function is mainly used in some scenarios where all SRAMs ne...
system_pmu_calibration_stop
void system_pmu_calibration_stop(void)
stop calibration.
XIP_16M
@ XIP_16M
Definition: platform_sdk.h:80
platform_rc_calibration
void platform_rc_calibration(void)
Platform rc calibration function.
RNG_OSC_CLK
@ RNG_OSC_CLK
Definition: platform_sdk.h:93
MIRROR_32M
@ MIRROR_32M
Definition: platform_sdk.h:87
mem_pwr_mgmt_mode_set_from
void mem_pwr_mgmt_mode_set_from(uint32_t start_addr, uint32_t size)
Control the memory power supply by specifying start address and length.
MIRROR_24M
@ MIRROR_24M
Definition: platform_sdk.h:85
platform_interrupt_protection_push
hal_status_t platform_interrupt_protection_push(void)
protection interrupt handler during writing/erasing flash.
MEM_POWER_AUTO_MODE
@ MEM_POWER_AUTO_MODE
Definition: platform_sdk.h:103
XIP_24M
@ XIP_24M
Definition: platform_sdk.h:79
mem_pwr_mgmt_init
void mem_pwr_mgmt_init(void)
memory check process
_ll_xqspi_hp_init_t
XQSPI High Performance mode init structures definition.
Definition: gr55xx_ll_xqspi.h:77
platform_sdk_init
void platform_sdk_init(void)
platform sdk init function.
mem_power_t
mem_power_t
memory power setting mode.
Definition: platform_sdk.h:101
XIP_32M
@ XIP_32M
Definition: platform_sdk.h:81
RNG_OSC_CLK2
@ RNG_OSC_CLK2
Definition: platform_sdk.h:95
system_pmu_calibration_start
void system_pmu_calibration_start(uint32_t interval)
start calibration.
system_pmu_increase_for_peripheral
bool system_pmu_increase_for_peripheral(void)
PMU increase function, will increase about 0.35v digcore.
mem_pwr_mgmt_mode_set
void mem_pwr_mgmt_mode_set(mem_power_t mem_pwr_mode)
Set the memory power management mode, which can be automatic mode or full power on mode.
MIRROR_64M
@ MIRROR_64M
Definition: platform_sdk.h:82
MIRROR_16M
@ MIRROR_16M
Definition: platform_sdk.h:86
table_idx_t
table_idx_t
system clock and run mode.
Definition: platform_sdk.h:75
platform_init
void platform_init(void)
Platform init function.
system_io_leakage_protect
void system_io_leakage_protect(void)
Leakage Protection for Chip's IO, Only used in Bali A0.
platform_clock_init_with_rtc
void platform_clock_init_with_rtc(mcu_clock_type_t sys_clock, uint16_t accuracy, uint16_t xo_offset)
Platform low power clock init function with External RTC setting.
platform_flash_enable_quad
hal_status_t platform_flash_enable_quad(exflash_hp_init_t *hp_init)
write flash QE
system_pmu_init
void system_pmu_init(mcu_clock_type_t clock_type)
PMU init function.
platform_flash_protection
hal_status_t platform_flash_protection(uint32_t base_priority)
During Flash erase/write operation, Disable external interrupts with a priority less than or equal to...
warm_boot_second
void warm_boot_second(void)
the second warm boot stage.
RTC_OSC_CLK
@ RTC_OSC_CLK
Definition: platform_sdk.h:94
clock_calibration_irq_handler
void clock_calibration_irq_handler(void)
Handle Clock calibration interrupt request.
XIP_48M
@ XIP_48M
Definition: platform_sdk.h:77
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
MIRROR_48M
@ MIRROR_48M
Definition: platform_sdk.h:83
clock_calib_notify_cb_t
void(* clock_calib_notify_cb_t)(uint16_t SlowClockFreq)
clock calibration notify callback.
Definition: platform_sdk.h:113
gr55xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
clock_calib_notify_register
void clock_calib_notify_register(clock_calib_notify_cb_t calib_notify_cb)
Register the clock calibration completion notification interface.
MEM_POWER_FULL_MODE
@ MEM_POWER_FULL_MODE
Definition: platform_sdk.h:102
XIP_64M
@ XIP_64M
Definition: platform_sdk.h:76
platform_interrupt_protection_pop
hal_status_t platform_interrupt_protection_pop(void)
protection interrupt handler during writing/erasing flash.
warm_boot_first
void warm_boot_first(void)
the first warm boot stage.
pwr_mgmt_warm_boot
void pwr_mgmt_warm_boot(void)
Power Management warm boot.
warm_boot
void warm_boot(void)
Warm boot process.
system_pmu_restore_for_peripheral
bool system_pmu_restore_for_peripheral(void)
PMU restore function. When wanting to use higher digcore voltage, call system_pmu_increase_for_periph...
MIRROR_XO16M
@ MIRROR_XO16M
Definition: platform_sdk.h:84
xo_offset
uint16_t xo_offset
Definition: gr55xx_efuse_layout.h:5
system_lp_table_update_twval
void system_lp_table_update_twval(table_idx_t table_idx, int16_t dur_offset, int16_t ext_offset, int16_t osc_offset)
Enable patch function.
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
XIP_XO16M
@ XIP_XO16M
Definition: platform_sdk.h:78
platform_clock_init_with_rng2
void platform_clock_init_with_rng2(mcu_clock_type_t sys_clock, uint16_t accuracy, uint16_t xo_offset)
Platform low power clock init function with internal RNG/RNG2 setting.
pmu_calibration_handler
void pmu_calibration_handler(void *p_arg)
PMU calibration handler.
sdk_clock_type_t
sdk_clock_type_t
sdk clock type.
Definition: platform_sdk.h:92