rtc_pm.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. typedef enum {
  19. PM_LIGHT_SLEEP = BIT(2), /*!< WiFi PD, memory in light sleep */
  20. } pm_sleep_mode_t;
  21. typedef enum{
  22. PM_SW_NOREJECT = 0,
  23. PM_SW_REJECT = 1
  24. } pm_sw_reject_t;
  25. /* These MAC-related functions are defined in the closed source part of
  26. * RTC library
  27. */
  28. extern void pm_mac_init();
  29. extern int pm_check_mac_idle();
  30. extern void pm_mac_deinit();
  31. /* This sleep-related function is called from the closed source part of RTC
  32. * library.
  33. */
  34. pm_sw_reject_t pm_set_sleep_mode(pm_sleep_mode_t sleep_mode, void(*pmac_save_params)())
  35. {
  36. (void) pmac_save_params; /* unused */
  37. pm_mac_deinit();
  38. if (pm_check_mac_idle()) {
  39. pm_mac_init();
  40. return PM_SW_REJECT;
  41. }
  42. rtc_sleep_config_t cfg = { 0 };
  43. cfg.soc_clk_sel = RTC_CNTL_SOC_CLK_SEL_XTL;
  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. cfg.lslp_meminf_pd = 1;
  52. rtc_sleep_init(cfg);
  53. break;
  54. default:
  55. assert(0 && "unsupported sleep mode");
  56. }
  57. return PM_SW_NOREJECT;
  58. }