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. 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. switch (sleep_mode) {
  44. case PM_LIGHT_SLEEP:
  45. cfg.wifi_pd_en = 1;
  46. cfg.dig_dbias_wak = 4;
  47. cfg.dig_dbias_slp = 0;
  48. cfg.rtc_dbias_wak = 0;
  49. cfg.rtc_dbias_slp = 0;
  50. cfg.lslp_meminf_pd = 1;
  51. rtc_sleep_init(cfg);
  52. break;
  53. default:
  54. assert(0 && "unsupported sleep mode");
  55. }
  56. return PM_SW_NOREJECT;
  57. }