esp_deepsleep.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright 2015-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_DEEPSLEEP_H__
  14. #define __ESP_DEEPSLEEP_H_
  15. #include <stdint.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /** \defgroup Deep_Sleep_API Deep Sleep API
  20. * @brief API for putting device into deep sleep
  21. */
  22. /** @addtogroup Deep_Sleep_API
  23. * @{
  24. */
  25. /**
  26. * @brief Set the chip to deep-sleep mode.
  27. *
  28. * The device will automatically wake up after the deep-sleep time set
  29. * by the users. Upon waking up, the device boots up from user_init.
  30. *
  31. * @attention The parameter time_in_us to be "uint64" is for further development.
  32. * Only the low 32 bits of parameter time_in_us are avalable now.
  33. *
  34. * @param uint64 time_in_us : deep-sleep time, only the low 32bits are avalable now. unit: microsecond
  35. *
  36. * @return null
  37. */
  38. void system_deep_sleep(uint64_t time_in_us);
  39. /**
  40. * @brief Default stub to run on wake from deep sleep.
  41. *
  42. * Allows for executing code immediately on wake from sleep, before
  43. * the software bootloader or esp-idf app has started up.
  44. *
  45. * This function is weak-linked, so you can implement your own version
  46. * to run code immediately when the chip wakes from
  47. * sleep.
  48. *
  49. * For example:
  50. * @code
  51. * void RTC_IRAM_ATTR esp_wake_deep_sleep(void) {
  52. * esp_default_wake_deep_sleep();
  53. * // Add additional functionality here
  54. * }
  55. *
  56. * (Implementing this function is not required for normal operation,
  57. * in the usual case your app will start normally when waking from
  58. * deep sleep.)
  59. *
  60. * esp_wake_deep_sleep() functionality is limited:
  61. *
  62. * - Runs immediately on wake, so most of the SoC is freshly reset -
  63. * flash is unmapped and hardware is otherwise uninitialised.
  64. *
  65. * - Can only call functions implemented in ROM, or marked RTC_IRAM_ATTR.
  66. *
  67. * - Static variables marked RTC_DATA_ATTR will have initial values on
  68. * cold boot, and maintain these values between sleep/wake cycles.
  69. *
  70. * - Read-only data should be marked RTC_RODATA_ATTR. Strings must be
  71. * declared as variables also using RTC_RODATA_ATTR, like this:
  72. * RTC_RODATA_ATTR const char message[] = "Hello from very early boot!\n";
  73. *
  74. * - Any other static memory will not be initialised (either to zero,
  75. * or to any predefined value).
  76. *
  77. *
  78. * - If you implement your own stub, the first call the stub makes
  79. should be to esp_default_wake_deep_sleep().
  80. */
  81. void esp_wake_deep_sleep(void);
  82. /**
  83. * @brief Function type for stub to run on wake from sleep.
  84. *
  85. */
  86. typedef void (*esp_deep_sleep_wake_stub_fn_t)(void);
  87. /**
  88. * @brief Install a new stub at runtime to run on wake from deep sleep
  89. *
  90. * If implementing esp_wake_deep_sleep() then it is not necessary to
  91. * call this function.
  92. *
  93. * However, it is possible to call this function to substitute a
  94. * different deep sleep stub. Any function used as a deep sleep stub
  95. * must be marked RTC_IRAM_ATTR, and must obey the same rules given
  96. * for esp_wake_deep_sleep().
  97. */
  98. void esp_set_deep_sleep_wake_stub(esp_deep_sleep_wake_stub_fn_t new_stub);
  99. /**
  100. * @brief Return current wake from deep sleep stub, or NULL if
  101. * no stub is installed.
  102. */
  103. esp_deep_sleep_wake_stub_fn_t esp_get_deep_sleep_wake_stub(void);
  104. /* The default esp-idf-provided esp_wake_deep_sleep() stub.
  105. If you replace esp_wake_deep_sleep() in your program, or use
  106. esp_set_deep_sleep_wake_stub(), then it is recommended you call
  107. esp_default_wake_deep_sleep() as the first function in your stub.
  108. */
  109. void esp_default_wake_deep_sleep(void);
  110. /**
  111. * @}
  112. */
  113. /**
  114. * @}
  115. */
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119. #endif /* __ESP_SYSTEM_H__ */