pwrmgr.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @file pwrmgr.c
  3. * @author chipsea
  4. * @brief
  5. * @version 0.1
  6. * @date 2020-11-30
  7. * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
  8. * @note
  9. */
  10. #ifndef _HAL_PWRMGR_HD
  11. #define _HAL_PWRMGR_HD
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include "cst92f2x.h"
  16. #include "gpio.h"
  17. #define PWR_MODE_NO_SLEEP 1
  18. #define PWR_MODE_SLEEP 2
  19. #define PWR_MODE_PWROFF_NO_SLEEP 4
  20. #define WAKEUP_PIN_MAX 3
  21. #define HAL_PWRMGR_TASK_MAX_NUM 10
  22. #define RET_SRAM0 BIT(0) /*32K, 0x1fff0000~0x1fff7fff*/
  23. #define RET_SRAM1 BIT(1) /*16K, 0x1fff8000~0x1fffbfff*/
  24. #define RET_SRAM2 BIT(2) /*16K, 0x1fffc000~0x1fffffff*/
  25. #define DEF_CLKG_CONFIG_0 (_CLK_IOMUX|_CLK_UART0|_CLK_GPIO|_CLK_SPIF)
  26. #define DEF_CLKG_CONFIG_1 (_CLK_M0_CPU | _CLK_BB |_CLK_TIMER |_CLK_BBREG \
  27. |_CLK_TIMER1|_CLK_TIMER2|_CLK_TIMER3|_CLK_TIMER4|_CLK_COM)
  28. typedef struct{
  29. GpioPin_t pin;
  30. gpio_polarity_e type;
  31. uint16_t on_time;
  32. }pwroff_cfg_t;
  33. extern uint32_t g_system_reset_cause;
  34. typedef void (*pwrmgr_Hdl_t)(void);
  35. int hal_pwrmgr_init(void);
  36. bool hal_pwrmgr_is_lock(MODULE_e mod);
  37. int hal_pwrmgr_lock(MODULE_e mod);
  38. int hal_pwrmgr_unlock(MODULE_e mod);
  39. ErrCode_t hal_pwrmgr_register(MODULE_e mod, pwrmgr_Hdl_t sleepHandle, pwrmgr_Hdl_t wakeupHandle);
  40. int hal_pwrmgr_unregister(MODULE_e mod);
  41. int hal_pwrmgr_wakeup_process(void) __attribute__((weak));
  42. int hal_pwrmgr_sleep_process(void) __attribute__((weak));
  43. int hal_pwrmgr_RAM_retention(uint32_t sram);
  44. int hal_pwrmgr_clk_gate_config(MODULE_e module);
  45. int hal_pwrmgr_RAM_retention_clr(void);
  46. int hal_pwrmgr_RAM_retention_set(void);
  47. int hal_pwrmgr_LowCurrentLdo_enable(void);
  48. int hal_pwrmgr_LowCurrentLdo_disable(void);
  49. __attribute__((section("_section_standby_code_"))) void hal_pwrmgr_poweroff(pwroff_cfg_t* pcfg, uint8_t wakeup_pin_num);
  50. __attribute__((section("_section_standby_code_"))) void hal_pwrmgr_enter_sleep_rtc_reset(uint32_t sleepRtcTick);
  51. __attribute__((section("_section_standby_code_"))) void hal_pwrmgr_enter_standby(pwroff_cfg_t* pcfg,uint8_t wakeup_pin_num) ;
  52. #ifdef __cplusplus
  53. }
  54. #endif
  55. #endif