rtc_pm.c 1.8 KB

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