rtc_pm.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <stdint.h>
  15. #include <assert.h>
  16. #include "soc/rtc.h"
  17. #include "soc/rtc_cntl_reg.h"
  18. #include "soc/apb_ctrl_reg.h"
  19. typedef enum {
  20. PM_LIGHT_SLEEP = BIT(2), /*!< WiFi PD, memory in light sleep */
  21. } pm_sleep_mode_t;
  22. typedef enum{
  23. PM_SW_NOREJECT = 0,
  24. PM_SW_REJECT = 1
  25. } pm_sw_reject_t;
  26. /* These MAC-related functions are defined in the closed source part of
  27. * RTC library
  28. */
  29. extern void pm_mac_init(void);
  30. extern int pm_check_mac_idle(void);
  31. extern void pm_mac_deinit(void);
  32. /* This sleep-related function is called from the closed source part of RTC
  33. * library.
  34. */
  35. pm_sw_reject_t pm_set_sleep_mode(pm_sleep_mode_t sleep_mode, void(*pmac_save_params)(void))
  36. {
  37. (void) pmac_save_params; /* unused */
  38. pm_mac_deinit();
  39. if (pm_check_mac_idle()) {
  40. pm_mac_init();
  41. return PM_SW_REJECT;
  42. }
  43. rtc_sleep_config_t cfg = { 0 };
  44. switch (sleep_mode) {
  45. case PM_LIGHT_SLEEP:
  46. cfg.wifi_pd_en = 1;
  47. cfg.dig_dbias_wak = 4;
  48. cfg.dig_dbias_slp = 0;
  49. cfg.rtc_dbias_wak = 0;
  50. cfg.rtc_dbias_slp = 0;
  51. rtc_sleep_init(cfg);
  52. break;
  53. default:
  54. assert(0 && "unsupported sleep mode");
  55. }
  56. return PM_SW_NOREJECT;
  57. }