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