sleep_modem.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include "sdkconfig.h"
  10. #include "esp_err.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /**
  15. * @file sleep_modem.h
  16. *
  17. * This file contains declarations of MAC and baseband power consumption related functions in light sleep mode.
  18. */
  19. #if CONFIG_MAC_BB_PD
  20. /**
  21. * @brief A callback function completes MAC and baseband power down operation
  22. *
  23. * In light sleep mode, execute Wi-Fi and Bluetooth module MAC and baseband
  24. * power down and backup register configuration information operations.
  25. */
  26. void mac_bb_power_down_cb_execute(void);
  27. /**
  28. * @brief A callback function completes MAC and baseband power up operation
  29. *
  30. * In light sleep mode, execute Wi-Fi and Bluetooth module MAC and baseband
  31. * power up and restore register configuration information operations.
  32. */
  33. void mac_bb_power_up_cb_execute(void);
  34. #endif // CONFIG_MAC_BB_PD
  35. #if SOC_PM_SUPPORT_PMU_MODEM_STATE
  36. /**
  37. * @brief The retention action in the modem state of WiFi PHY module
  38. *
  39. * @param restore true for restore the PHY context, false for backup the PHY context
  40. */
  41. void sleep_modem_wifi_do_phy_retention(bool restore);
  42. /**
  43. * @brief Get WiFi modem state
  44. *
  45. * @return true or false for WiFi modem state is enabled or disabled
  46. */
  47. bool sleep_modem_wifi_modem_state_enabled(void);
  48. /**
  49. * @brief Get WiFi modem link done state
  50. *
  51. * @return true or false for WiFi modem link can be used to enable RF by REGDMA or can not be used
  52. */
  53. bool sleep_modem_wifi_modem_link_done(void);
  54. #endif /* SOC_PM_SUPPORT_PMU_MODEM_STATE */
  55. /**
  56. * @brief Whether the current target allows Modem or the TOP power domain to be powered off during light sleep
  57. *
  58. * During light sleep on some targets, it is possible to power OFF the Modem or TOP
  59. * power domains in order to further lower power power consumption. However, this
  60. * can only occur on targets that support REGDMA for modem (WiFi, Bluetooth,
  61. * IEEE802.15.4) retention.
  62. */
  63. bool modem_domain_pd_allowed(void);
  64. /**
  65. * @brief Get the reject trigger signal of Modem system
  66. *
  67. * @return the reject trigger signal of Modem system.
  68. */
  69. uint32_t sleep_modem_reject_triggers(void);
  70. /**
  71. * @brief Configure the parameters of the modem subsytem during the sleep process
  72. *
  73. * In light sleep mode, the wake-up early time of the WiFi module and the TBTT
  74. * interrupt early time (trigger enabling RF) are determined by the maximum and
  75. * minimum frequency of system (higher system frequency means less time to wake
  76. * up and enable RF).
  77. * For the esp32c6 SOC, the modem state is strongly dependent on the light sleep
  78. * mode, and the modem state will be enabled only when light sleep is enabled
  79. * and the `CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP` is configured in menuconfig.
  80. *
  81. * @param max_freq_mhz the maximum frequency of system
  82. * @param min_freq_mhz the minimum frequency of system
  83. * @param light_sleep_enable ture or false for enable or disable light sleep mode, respectively
  84. *
  85. * @return
  86. * - ESP_OK on success
  87. */
  88. esp_err_t sleep_modem_configure(int max_freq_mhz, int min_freq_mhz, bool light_sleep_enable);
  89. /**
  90. * @brief Callback function type for peripherals to know light sleep wakeup overhead.
  91. *
  92. */
  93. typedef void (* inform_out_light_sleep_overhead_cb_t)(uint32_t);
  94. /**
  95. * @brief Register informing peripherals light sleep wakeup overhead time callback
  96. *
  97. * This function allows you to register a callback that informs the peripherals of
  98. * the wakeup overhead time of light sleep.
  99. * @param cb function to inform time
  100. * @return
  101. * - ESP_OK on success
  102. * - ESP_ERR_NO_MEM if no more callback slots are available
  103. */
  104. esp_err_t esp_pm_register_inform_out_light_sleep_overhead_callback(inform_out_light_sleep_overhead_cb_t cb);
  105. /**
  106. * @brief Unregister informing peripherals light sleep wakeup overhead time callback
  107. *
  108. * This function allows you to unregister a callback that informs the peripherals of
  109. * the wakeup overhead time of light sleep.
  110. * @param cb function to inform time
  111. * @return
  112. * - ESP_OK on success
  113. * - ESP_ERR_INVALID_STATE if the given callback hasn't been registered before
  114. */
  115. esp_err_t esp_pm_unregister_inform_out_light_sleep_overhead_callback(inform_out_light_sleep_overhead_cb_t cb);
  116. /**
  117. * @brief A callback that informs the peripherals of the wakeup overhead time of light sleep
  118. *
  119. * @param out_light_sleep_time wakeup overhead time of light sleep
  120. */
  121. void periph_inform_out_light_sleep_overhead(uint32_t out_light_sleep_time);
  122. /**
  123. * @brief Callback function type for peripherals to know light sleep default parameters
  124. */
  125. typedef void (* update_light_sleep_default_params_config_cb_t)(int, int);
  126. /**
  127. * @brief Register peripherals light sleep default parameters configure callback
  128. *
  129. * This function allows you to register a callback that configure the peripherals
  130. * of default parameters of light sleep
  131. * @param cb function to update default parameters
  132. */
  133. void esp_pm_register_light_sleep_default_params_config_callback(update_light_sleep_default_params_config_cb_t cb);
  134. /**
  135. * @brief Unregister peripherals light sleep default parameters configure Callback
  136. *
  137. * This function allows you to unregister a callback that configure the peripherals
  138. * of default parameters of light sleep
  139. */
  140. void esp_pm_unregister_light_sleep_default_params_config_callback(void);
  141. #if SOC_PM_SUPPORT_PMU_MODEM_STATE
  142. /**
  143. * @brief Init Wi-Fi modem state.
  144. *
  145. * This function init wifi modem state.
  146. * @return
  147. * - ESP_OK on success
  148. * - ESP_ERR_NO_MEM if no memory for link
  149. */
  150. esp_err_t sleep_modem_wifi_modem_state_init(void);
  151. /**
  152. * @brief Deinit Wi-Fi modem state.
  153. *
  154. * This function deinit wifi modem state.
  155. */
  156. void sleep_modem_wifi_modem_state_deinit(void);
  157. /**
  158. * @brief Function to check Wi-Fi modem state to skip light sleep.
  159. *
  160. * This function is to check if light sleep should skip by Wi-Fi modem state .
  161. * @return
  162. * - true skip light sleep
  163. * - false not skip light sleep
  164. */
  165. bool sleep_modem_wifi_modem_state_skip_light_sleep(void);
  166. #endif
  167. #ifdef __cplusplus
  168. }
  169. #endif