-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/example_deep_sleep_wake_stub_backport_v4.4' int…
…o 'release/v4.4' example: add deepsleep_wake stub example (backport v4.4) See merge request espressif/esp-idf!23360
- Loading branch information
Showing
32 changed files
with
657 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include "esp_log.h" | ||
#include "esp_sleep.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define RTC_STR(str) (__extension__({static const RTC_RODATA_ATTR char _fmt[] = (str); (const char *)&_fmt;})) | ||
#define RTC_LOG_FORMAT(letter, format) LOG_COLOR_ ## letter format LOG_RESET_COLOR "\n" | ||
|
||
#define ESP_RTC_LOG( level, format, ... ) if (LOG_LOCAL_LEVEL >= level) { esp_rom_printf(RTC_STR(format), ##__VA_ARGS__); \ | ||
esp_wake_stub_uart_tx_wait_idle(0); } | ||
|
||
#define ESP_RTC_LOGE( format, ... ) ESP_RTC_LOG(ESP_LOG_ERROR, RTC_LOG_FORMAT(E, format), ##__VA_ARGS__) | ||
#define ESP_RTC_LOGW( format, ... ) ESP_RTC_LOG(ESP_LOG_WARN, RTC_LOG_FORMAT(W, format), ##__VA_ARGS__) | ||
#define ESP_RTC_LOGI( format, ... ) ESP_RTC_LOG(ESP_LOG_INFO, RTC_LOG_FORMAT(I, format), ##__VA_ARGS__) | ||
#define ESP_RTC_LOGD( format, ... ) ESP_RTC_LOG(ESP_LOG_DEBUG, RTC_LOG_FORMAT(D, format), ##__VA_ARGS__) | ||
#define ESP_RTC_LOGV( format, ... ) ESP_RTC_LOG(ESP_LOG_VERBOSE, RTC_LOG_FORMAT(V, format), ##__VA_ARGS__) | ||
|
||
/** | ||
* @brief Enter deep-sleep mode from deep sleep wake stub code | ||
* | ||
* This should be called from the wake stub code. | ||
* | ||
* @param new_stub new wake stub function will be set | ||
*/ | ||
void esp_wake_stub_sleep(esp_deep_sleep_wake_stub_fn_t new_stub); | ||
|
||
/** | ||
* @brief Wait while uart transmission is in progress | ||
* | ||
* This function is waiting while uart transmission is not completed, | ||
* and this function should be called from the wake stub code. | ||
* | ||
* @param uart_no UART port to wait idle | ||
*/ | ||
void esp_wake_stub_uart_tx_wait_idle(uint8_t uart_no); | ||
|
||
/** | ||
* @brief Set wakeup time from deep sleep stub. | ||
* | ||
* This should be called from the wake stub code. | ||
* | ||
* @param time_in_us wakeup time in us | ||
*/ | ||
void esp_wake_stub_set_wakeup_time(uint64_t time_in_us); | ||
|
||
/** | ||
* @brief Get wakeup cause from deep sleep stub. | ||
* | ||
* This should be called from the wake stub code. | ||
* | ||
* @return wakeup casue value | ||
*/ | ||
uint32_t esp_wake_stub_get_wakeup_cause(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stddef.h> | ||
#include <string.h> | ||
#include <sys/lock.h> | ||
#include <sys/param.h> | ||
|
||
#include "esp_attr.h" | ||
#include "esp_sleep.h" | ||
|
||
#include "soc/soc.h" | ||
#include "soc/rtc.h" | ||
#include "soc/soc_caps.h" | ||
#include "hal/rtc_cntl_ll.h" | ||
#include "hal/uart_ll.h" | ||
|
||
#include "sdkconfig.h" | ||
#include "esp_rom_uart.h" | ||
#include "esp_rom_sys.h" | ||
|
||
#ifdef CONFIG_IDF_TARGET_ESP32 | ||
#include "esp32/rom/rtc.h" | ||
#elif CONFIG_IDF_TARGET_ESP32S2 | ||
#include "esp32s2/rom/rtc.h" | ||
#elif CONFIG_IDF_TARGET_ESP32S3 | ||
#include "esp32s3/rom/rtc.h" | ||
#elif CONFIG_IDF_TARGET_ESP32C3 | ||
#include "esp32c3/rom/rtc.h" | ||
#elif CONFIG_IDF_TARGET_ESP32H2 | ||
#include "esp32h2/rom/rtc.h" | ||
#endif | ||
|
||
void RTC_IRAM_ATTR esp_wake_stub_sleep(esp_deep_sleep_wake_stub_fn_t new_stub) | ||
{ | ||
#if SOC_PM_SUPPORT_DEEPSLEEP_VERIFY_STUB_ONLY | ||
extern char _rtc_text_start[]; | ||
#if CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM | ||
extern char _rtc_noinit_end[]; | ||
size_t rtc_fast_length = (size_t)_rtc_noinit_end - (size_t)_rtc_text_start; | ||
#else | ||
extern char _rtc_force_fast_end[]; | ||
size_t rtc_fast_length = (size_t)_rtc_force_fast_end - (size_t)_rtc_text_start; | ||
#endif // CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM | ||
esp_rom_set_rtc_wake_addr((esp_rom_wake_func_t)new_stub, rtc_fast_length); | ||
#else | ||
// Set the pointer of the wake stub function. | ||
REG_WRITE(RTC_ENTRY_ADDR_REG, (uint32_t)new_stub); | ||
set_rtc_memory_crc(); | ||
#endif // SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_MEM | ||
|
||
// Go to sleep. | ||
rtc_cntl_ll_sleep_enable(); | ||
// A few CPU cycles may be necessary for the sleep to start... | ||
while (true) {}; | ||
// never reaches here. | ||
} | ||
|
||
void RTC_IRAM_ATTR esp_wake_stub_uart_tx_wait_idle(uint8_t uart_no) | ||
{ | ||
while (!uart_ll_is_tx_idle(UART_LL_GET_HW(uart_no))) {}; | ||
} | ||
|
||
void RTC_IRAM_ATTR esp_wake_stub_set_wakeup_time(uint64_t time_in_us) | ||
{ | ||
uint64_t rtc_count_delta = rtc_cntl_ll_time_to_count(time_in_us); | ||
uint64_t rtc_curr_count = rtc_cntl_ll_get_rtc_time(); | ||
rtc_cntl_ll_set_wakeup_timer(rtc_curr_count + rtc_count_delta); | ||
} | ||
|
||
uint32_t RTC_IRAM_ATTR esp_wake_stub_get_wakeup_cause(void) | ||
{ | ||
return rtc_cntl_ll_get_wakeup_cause(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.