esp_pm.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // Copyright 2016-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. #pragma once
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "esp_err.h"
  18. // Include SoC-specific definitions. Only ESP32 supported for now.
  19. #include "esp32/pm.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /**
  24. * @brief Power management constraints
  25. */
  26. typedef enum {
  27. /**
  28. * Require CPU frequency to be at the maximum value set via esp_pm_configure.
  29. * Argument is unused and should be set to 0.
  30. */
  31. ESP_PM_CPU_FREQ_MAX,
  32. /**
  33. * Require APB frequency to be at the maximum value supported by the chip.
  34. * Argument is unused and should be set to 0.
  35. */
  36. ESP_PM_APB_FREQ_MAX,
  37. /**
  38. * Prevent the system from going into light sleep.
  39. * Argument is unused and should be set to 0.
  40. */
  41. ESP_PM_NO_LIGHT_SLEEP,
  42. } esp_pm_lock_type_t;
  43. /**
  44. * @brief Set implementation-specific power management configuration
  45. * @param config pointer to implementation-specific configuration structure (e.g. esp_pm_config_esp32)
  46. * @return
  47. * - ESP_OK on success
  48. * - ESP_ERR_INVALID_ARG if the configuration values are not correct
  49. * - ESP_ERR_NOT_SUPPORTED if certain combination of values is not supported,
  50. * or if CONFIG_PM_ENABLE is not enabled in sdkconfig
  51. */
  52. esp_err_t esp_pm_configure(const void* config);
  53. /**
  54. * @brief Opaque handle to the power management lock
  55. */
  56. typedef struct esp_pm_lock* esp_pm_lock_handle_t;
  57. /**
  58. * @brief Initialize a lock handle for certain power management parameter
  59. *
  60. * When lock is created, initially it is not taken.
  61. * Call esp_pm_lock_acquire to take the lock.
  62. *
  63. * This function must not be called from an ISR.
  64. *
  65. * @param lock_type Power management constraint which the lock should control
  66. * @param arg argument, value depends on lock_type, see esp_pm_lock_type_t
  67. * @param name arbitrary string identifying the lock (e.g. "wifi" or "spi").
  68. * Used by the esp_pm_dump_locks function to list existing locks.
  69. * May be set to NULL. If not set to NULL, must point to a string which is valid
  70. * for the lifetime of the lock.
  71. * @param[out] out_handle handle returned from this function. Use this handle when calling
  72. * esp_pm_lock_delete, esp_pm_lock_acquire, esp_pm_lock_release.
  73. * Must not be NULL.
  74. * @return
  75. * - ESP_OK on success
  76. * - ESP_ERR_NO_MEM if the lock structure can not be allocated
  77. * - ESP_ERR_INVALID_ARG if out_handle is NULL or type argument is not valid
  78. * - ESP_ERR_NOT_SUPPORTED if CONFIG_PM_ENABLE is not enabled in sdkconfig
  79. */
  80. esp_err_t esp_pm_lock_create(esp_pm_lock_type_t lock_type, int arg,
  81. const char* name, esp_pm_lock_handle_t* out_handle);
  82. /**
  83. * @brief Take a power management lock
  84. *
  85. * Once the lock is taken, power management algorithm will not switch to the
  86. * mode specified in a call to esp_pm_lock_create, or any of the lower power
  87. * modes (higher numeric values of 'mode').
  88. *
  89. * The lock is recursive, in the sense that if esp_pm_lock_acquire is called
  90. * a number of times, esp_pm_lock_release has to be called the same number of
  91. * times in order to release the lock.
  92. *
  93. * This function may be called from an ISR.
  94. *
  95. * This function is not thread-safe w.r.t. calls to other esp_pm_lock_*
  96. * functions for the same handle.
  97. *
  98. * @param handle handle obtained from esp_pm_lock_create function
  99. * @return
  100. * - ESP_OK on success
  101. * - ESP_ERR_INVALID_ARG if the handle is invalid
  102. * - ESP_ERR_NOT_SUPPORTED if CONFIG_PM_ENABLE is not enabled in sdkconfig
  103. */
  104. esp_err_t esp_pm_lock_acquire(esp_pm_lock_handle_t handle);
  105. /**
  106. * @brief Release the lock taken using esp_pm_lock_acquire.
  107. *
  108. * Call to this functions removes power management restrictions placed when
  109. * taking the lock.
  110. *
  111. * Locks are recursive, so if esp_pm_lock_acquire is called a number of times,
  112. * esp_pm_lock_release has to be called the same number of times in order to
  113. * actually release the lock.
  114. *
  115. * This function may be called from an ISR.
  116. *
  117. * This function is not thread-safe w.r.t. calls to other esp_pm_lock_*
  118. * functions for the same handle.
  119. *
  120. * @param handle handle obtained from esp_pm_lock_create function
  121. * @return
  122. * - ESP_OK on success
  123. * - ESP_ERR_INVALID_ARG if the handle is invalid
  124. * - ESP_ERR_INVALID_STATE if lock is not acquired
  125. * - ESP_ERR_NOT_SUPPORTED if CONFIG_PM_ENABLE is not enabled in sdkconfig
  126. */
  127. esp_err_t esp_pm_lock_release(esp_pm_lock_handle_t handle);
  128. /**
  129. * @brief Delete a lock created using esp_pm_lock
  130. *
  131. * The lock must be released before calling this function.
  132. *
  133. * This function must not be called from an ISR.
  134. *
  135. * @param handle handle obtained from esp_pm_lock_create function
  136. * @return
  137. * - ESP_OK on success
  138. * - ESP_ERR_INVALID_ARG if the handle argument is NULL
  139. * - ESP_ERR_INVALID_STATE if the lock is still acquired
  140. * - ESP_ERR_NOT_SUPPORTED if CONFIG_PM_ENABLE is not enabled in sdkconfig
  141. */
  142. esp_err_t esp_pm_lock_delete(esp_pm_lock_handle_t handle);
  143. /**
  144. * Dump the list of all locks to stderr
  145. *
  146. * This function dumps debugging information about locks created using
  147. * esp_pm_lock_create to an output stream.
  148. *
  149. * This function must not be called from an ISR. If esp_pm_lock_acquire/release
  150. * are called while this function is running, inconsistent results may be
  151. * reported.
  152. *
  153. * @param stream stream to print information to; use stdout or stderr to print
  154. * to the console; use fmemopen/open_memstream to print to a
  155. * string buffer.
  156. * @return
  157. * - ESP_OK on success
  158. * - ESP_ERR_NOT_SUPPORTED if CONFIG_PM_ENABLE is not enabled in sdkconfig
  159. */
  160. esp_err_t esp_pm_dump_locks(FILE* stream);
  161. #ifdef __cplusplus
  162. }
  163. #endif