esp_wake_stub.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include "esp_log.h"
  9. #include "esp_sleep.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #define RTC_STR(str) (__extension__({static const RTC_RODATA_ATTR char _fmt[] = (str); (const char *)&_fmt;}))
  14. #define RTC_LOG_FORMAT(letter, format) LOG_COLOR_ ## letter format LOG_RESET_COLOR "\n"
  15. #define ESP_RTC_LOG( level, format, ... ) if (LOG_LOCAL_LEVEL >= level) { esp_rom_printf(RTC_STR(format), ##__VA_ARGS__); \
  16. esp_wake_stub_uart_tx_wait_idle(0); }
  17. #define ESP_RTC_LOGE( format, ... ) ESP_RTC_LOG(ESP_LOG_ERROR, RTC_LOG_FORMAT(E, format), ##__VA_ARGS__)
  18. #define ESP_RTC_LOGW( format, ... ) ESP_RTC_LOG(ESP_LOG_WARN, RTC_LOG_FORMAT(W, format), ##__VA_ARGS__)
  19. #define ESP_RTC_LOGI( format, ... ) ESP_RTC_LOG(ESP_LOG_INFO, RTC_LOG_FORMAT(I, format), ##__VA_ARGS__)
  20. #define ESP_RTC_LOGD( format, ... ) ESP_RTC_LOG(ESP_LOG_DEBUG, RTC_LOG_FORMAT(D, format), ##__VA_ARGS__)
  21. #define ESP_RTC_LOGV( format, ... ) ESP_RTC_LOG(ESP_LOG_VERBOSE, RTC_LOG_FORMAT(V, format), ##__VA_ARGS__)
  22. /**
  23. * @brief Enter deep-sleep mode from deep sleep wake stub code
  24. *
  25. * This should be called from the wake stub code.
  26. *
  27. * @param new_stub new wake stub function will be set
  28. */
  29. void esp_wake_stub_sleep(esp_deep_sleep_wake_stub_fn_t new_stub);
  30. /**
  31. * @brief Wait while uart transmission is in progress
  32. *
  33. * This function is waiting while uart transmission is not completed,
  34. * and this function should be called from the wake stub code.
  35. *
  36. * @param uart_no UART port to wait idle
  37. */
  38. void esp_wake_stub_uart_tx_wait_idle(uint8_t uart_no);
  39. /**
  40. * @brief Set wakeup time from deep sleep stub.
  41. *
  42. * This should be called from the wake stub code.
  43. *
  44. * @param time_in_us wakeup time in us
  45. */
  46. void esp_wake_stub_set_wakeup_time(uint64_t time_in_us);
  47. /**
  48. * @brief Get wakeup cause from deep sleep stub.
  49. *
  50. * This should be called from the wake stub code.
  51. *
  52. * @return wakeup casue value
  53. */
  54. uint32_t esp_wake_stub_get_wakeup_cause(void);
  55. #ifdef __cplusplus
  56. }
  57. #endif