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 @addtogroup Plat_SDK Platform SDK 43 @{ 44 @brief Definitions and prototypes for the Platform SDK 45 */ 46 47 #ifndef _PLATFORM_SDK_H 48 #define _PLATFORM_SDK_H 49 50 #include <stdint.h> 51 #include <stdbool.h> 52 #include <stdio.h> 53 #include "system_gr55xx.h" 54 #include "gr55xx_hal_def.h" 55 56 /** @addtogroup PlAT_SDK_ENUM Enumerations 57 * @{ */ 58 59 /** @brief system clock and run mode. */ 60 typedef enum { 61 XIP_64M = 0, /**< XIP 64M. */ 62 XIP_48M, /**< XIP 48M. */ 63 XIP_XO16M, /**< XIP XO 16M. */ 64 XIP_24M, /**< XIP 24M. */ 65 XIP_16M, /**< XIP 16M. */ 66 XIP_32M, /**< XIP 32M. */ 67 MIRROR_64M, /**< MIRROR 64M. */ 68 MIRROR_48M, /**< MIRROR 48M. */ 69 MIRROR_XO16M, /**< MIRROR X) 16M. */ 70 MIRROR_24M, /**< MIRROR 24M. */ 71 MIRROR_16M, /**< MIRROR 16M. */ 72 MIRROR_32M, /**< MIRROR 32M. */ 73 } run_mode_t; 74 75 /** @brief sdk clock type. */ 76 typedef enum { 77 RNG_OSC_CLK = 0, /**< RNG OSC CLOCK. */ 78 RTC_OSC_CLK, /**< RTC OSC CLOCK. */ 79 RNG_OSC_CLK2, /**< RNG OSC CLOCK2. */ 80 } sdk_clock_type_t; 81 82 83 /** @brief memory power setting mode. */ 84 typedef enum { 85 MEM_POWER_FULL_MODE = 0, /**< Full mode. */ 86 MEM_POWER_AUTO_MODE, /**< Auto mode. */ 87 } mem_power_t; 88 /** @} */ 89 90 /** @addtogroup PLAT_SDK_FUNCTIONS Functions 91 * @{ */ 92 93 /** 94 **************************************************************************************** 95 * @brief platform sdk init function. 96 * @retval : void 97 **************************************************************************************** 98 */ 99 void platform_sdk_init(void); 100 101 /** 102 **************************************************************************************** 103 * @brief set the memory power state to full. This function is mainly used in some 104 * scenarios where all SRAMs need to be powered on 105 * @retval : void 106 **************************************************************************************** 107 */ 108 void mem_pwr_mgmt_full_power_set(void); 109 110 /** 111 **************************************************************************************** 112 * @brief Control the memory power supply by specifying start address and length. 113 * @param[in] start_addr : the start address of memory that user want to config 114 * @param[in] size : the size of memory that user want to config 115 * @retval : void 116 **************************************************************************************** 117 */ 118 void mem_pwr_mgmt_mode_set_from(uint32_t start_addr, uint32_t size); 119 120 /** 121 **************************************************************************************** 122 * @brief memory check process 123 * @retval : void 124 **************************************************************************************** 125 */ 126 void mem_pwr_mgmt_init(void); 127 128 /** 129 **************************************************************************************** 130 * @brief update the counter A and counter B. 131 * @param[in] cnt_a : DCDC Stable Time. 132 * @param[in] cnt_b : Oscillator Stable Time. 133 * @retval : void 134 **************************************************************************************** 135 */ 136 void system_lp_counter_set(uint8_t cnt_a, uint8_t cnt_b); 137 138 /** 139 **************************************************************************************** 140 * @brief : Set Time to wakeup oscillator before BLE Act-ivity. 141 * @param[in] run_mode : run mode. 142 * @param[in] osc_us : Time Reserved for wakeup oscillator(unit: us). 143 * @retval : void 144 **************************************************************************************** 145 */ 146 void ble_wakeup_osc_time_set(run_mode_t run_mode, uint16_t osc_us); 147 148 /** 149 **************************************************************************************** 150 * @brief : Get Time to wakeup oscillator before BLE Act-ivity. 151 * @param[in] run_mode : run mode. 152 * @retval : osc_us : Time Reserved for wakeup oscillator(unit: us). 153 **************************************************************************************** 154 */ 155 uint16_t ble_wakeup_osc_time_get(run_mode_t run_mode); 156 157 /** 158 **************************************************************************************** 159 * @brief Get NVDS Start Address. 160 * 161 * @retval : address : The NVDS Start Address. 162 **************************************************************************************** 163 */ 164 uint32_t nvds_get_start_addr(void); 165 166 /** 167 **************************************************************************************** 168 * @brief Set BLE Program Delay. 169 * @param[in] run_mode : run mode. 170 * @param[in] hslot : program delay in half slot(unit: 312.5us). 171 * @retval : void 172 **************************************************************************************** 173 */ 174 void ble_program_delay_set(run_mode_t run_mode, uint8_t hslot); 175 176 /** 177 **************************************************************************************** 178 * @brief Set BLE Sleep Algorithm Duration. 179 * @param[in] run_mode : run mode. 180 * @param[in] dur_hus : BLE Sleep Algorithm Duration(unit: 0.5us). 181 * @retval : void 182 **************************************************************************************** 183 */ 184 void ble_sleep_algo_dur_set(run_mode_t run_mode, uint16_t dur_hus); 185 186 /** 187 **************************************************************************************** 188 * @brief Set Maximum BLE Pushing Frame Time. 189 * @param[in] run_mode : run mode. 190 * @param[in] max_push_hus : maximum pushing frame time(unit: hus). 191 * @retval : void 192 **************************************************************************************** 193 */ 194 void ble_max_push_frame_time_set(run_mode_t run_mode, uint16_t max_push_hus); 195 196 /** 197 **************************************************************************************** 198 * @brief Set Minimum System Sleep Time. 199 * @param[in] run_mode : run mode. 200 * @param[in] min_sleep_us : Minimum Time Allowed For Sleep(unit: us). 201 * @retval : void 202 **************************************************************************************** 203 */ 204 void sys_min_sleep_threshold_set(run_mode_t run_mode, uint32_t min_sleep_us); 205 206 /** 207 **************************************************************************************** 208 * @brief Platform low power clock init function. 209 * @param[in] sys_clock: System clock. 210 * @param[in] clock : External RTC setting. 211 * @param[in] accuracy : Low speed clock accuracy. 212 * @param[in] xo_offset : Clock calibration parameter. 213 * @retval : void 214 **************************************************************************************** 215 */ 216 void platform_clock_init(mcu_clock_type_t sys_clock, sdk_clock_type_t clock, uint16_t accuracy, uint16_t xo_offset); 217 218 /** 219 **************************************************************************************** 220 * @brief Platform low power clock init function. 221 * @param[in] sys_clock: System clock. 222 * @param[in] clock : Internal RNG/RNG2 setting. 223 * @param[in] accuracy : Low speed clock accuracy. 224 * @param[in] xo_offset : Clock calibration parameter. 225 * @retval : void 226 **************************************************************************************** 227 */ 228 void platform_clock_init_rng(mcu_clock_type_t sys_clock, sdk_clock_type_t clock, 229 uint16_t accuracy, uint16_t xo_offset); 230 231 /** 232 **************************************************************************************** 233 * @brief Start RNG2 OSC calibration. 234 * @retval : void 235 **************************************************************************************** 236 */ 237 void platform_rng2_calibration_start(void); 238 239 /** 240 **************************************************************************************** 241 * @brief Stop RNG2 OSC calibration. 242 * @param[in] wait : True will wait calibration register is cleared 243 * @retval : void 244 **************************************************************************************** 245 */ 246 void platform_rng2_calibration_stop(bool wait); 247 248 /** 249 **************************************************************************************** 250 * @brief Check whether RNG2 OSC calibration is on going. 251 * 252 * @retval : bool : true calibration is on going, false calibration is not started or done 253 **************************************************************************************** 254 */ 255 bool platform_rng2_calibration_is_busy(void); 256 257 /** 258 **************************************************************************************** 259 * @brief Get RNG2 OSC calibration result. 260 * @param[in] wait_result : true will wait calibration done to get RNG2 OSC frequency 261 * @param[in] allow_cached : true will using previous RNG2 OSC calibration frequency 262 * @retval : uint32_t : RNG2 OSC frequency in HZ 263 **************************************************************************************** 264 */ 265 uint32_t platform_rng2_calibration_get(bool wait_result, bool allow_cached); 266 267 /** 268 **************************************************************************************** 269 * @brief Platform init function. 270 * @retval : void 271 **************************************************************************************** 272 */ 273 void platform_init(void); 274 275 /** 276 **************************************************************************************** 277 * @brief the first warm boot stage. 278 * @retval : void 279 **************************************************************************************** 280 */ 281 void warm_boot_first(void); 282 283 /** 284 **************************************************************************************** 285 * @brief the second warm boot stage.. 286 * @retval : void 287 **************************************************************************************** 288 */ 289 void warm_boot_second(void); 290 291 /** 292 **************************************************************************************** 293 * @brief PMU init function. 294 * @param[in] clock_type : clock type to be configured. 295 * @retval : void 296 **************************************************************************************** 297 */ 298 void system_pmu_init(mcu_clock_type_t clock_type); 299 300 /** 301 **************************************************************************************** 302 * @brief PMU deinit function. 303 * @retval : void 304 **************************************************************************************** 305 */ 306 void system_pmu_deinit(void); 307 308 /** 309 **************************************************************************************** 310 * @brief Warm boot process. 311 * @retval : void 312 **************************************************************************************** 313 */ 314 void warm_boot(void); 315 316 /** 317 **************************************************************************************** 318 * @brief Set delay time between flash wakeup and read chip id in warm boot. 319 * Please referrent the time of Flash Deep Power- down to Stand-by mode. 320 * @param[in] delay_us: uinit :us 321 * @retval : void 322 **************************************************************************************** 323 */ 324 void warm_boot_set_exflash_readid_delay(uint32_t delay_us); 325 326 /** 327 **************************************************************************************** 328 * @brief Get delay time between flash wakeup and read chip id in warm boot. 329 * @retval : delay time: uinit :us 330 **************************************************************************************** 331 */ 332 uint32_t warm_boot_get_exflash_readid_delay(void); 333 334 /** 335 **************************************************************************************** 336 * @brief PMU calibration handler. 337 * @param[in] p_arg : no args. 338 * @retval : void 339 **************************************************************************************** 340 */ 341 void pmu_calibration_handler(uint8_t* p_arg); 342 343 344 /** 345 **************************************************************************************** 346 * @brief protection platform timeout through watchdog. 347 * @retval : hal status 348 **************************************************************************************** 349 */ 350 void platform_init_push(void); 351 352 /** 353 **************************************************************************************** 354 * @brief protection platform timeout through watchdog. 355 * @retval : hal status 356 **************************************************************************************** 357 */ 358 void platform_init_pop(void); 359 360 /** 361 **************************************************************************************** 362 * @brief write flash QE 363 * @retval : hal status 364 **************************************************************************************** 365 */ 366 hal_status_t platform_flash_enable_quad(void); 367 368 /** 369 **************************************************************************************** 370 * @brief During Flash erase/write operation, Disable external interrupts with a priority less 371 * than or equal to base_priority in the system. 372 * @param[in] base_priority: Base Priority value to set. 373 * @retval : hal status 374 **************************************************************************************** 375 */ 376 hal_status_t platform_flash_protection(uint32_t base_priority); 377 378 /** 379 **************************************************************************************** 380 * @brief protection interrupt handler during writing/erasing flash. 381 * @retval : hal status 382 **************************************************************************************** 383 */ 384 hal_status_t platform_interrupt_protection_push(void); 385 386 /** 387 **************************************************************************************** 388 * @brief protection interrupt handler during writing/erasing flash. 389 * @retval : hal status 390 **************************************************************************************** 391 */ 392 hal_status_t platform_interrupt_protection_pop(void); 393 394 /** 395 **************************************************************************************** 396 * @brief Power Management warm boot. 397 * @retval : void 398 **************************************************************************************** 399 */ 400 void pwr_mgmt_warm_boot(void); 401 402 /** @} */ 403 404 #endif 405 406 /** @} */ 407 /** @} */ 408 409