fix(esp_hw_support): add timer wakeup sleep duration check

Closes https://github.com/espressif/esp-idf/issues/15255
This commit is contained in:
wuzhenghui
2025-02-07 14:30:40 +08:00
parent beb054baad
commit 5e81eb6cf7
21 changed files with 109 additions and 34 deletions

View File

@@ -19,6 +19,7 @@
#include "soc/rtc.h" // for wakeup trigger defines
#include "soc/rtc_periph.h" // for read rtc registers directly (cause)
#include "soc/soc.h" // for direct register read macros
#include "esp_clk_tree.h"
#include "esp_newlib.h"
#include "test_utils.h"
#include "sdkconfig.h"
@@ -26,6 +27,7 @@
#include "esp_rom_sys.h"
#include "esp_timer.h"
#include "esp_private/esp_clk.h"
#include "esp_private/esp_clk_tree_common.h"
#include "esp_private/uart_private.h"
#include "esp_random.h"
#include "nvs_flash.h"
@@ -57,6 +59,10 @@ static void deep_sleep_task(void *arg)
static void do_deep_sleep_from_app_cpu(void)
{
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_sleep_enable_timer_wakeup(UINT64_MAX));
uint64_t lp_timer_max_allowed_time_in_us = ((BIT64(SOC_LP_TIMER_BIT_WIDTH_LO + SOC_LP_TIMER_BIT_WIDTH_HI) - 1) / esp_clk_tree_lp_slow_get_freq_hz(ESP_CLK_TREE_SRC_FREQ_PRECISION_APPROX)) * MHZ;
TEST_ASSERT_EQUAL(ESP_OK, esp_sleep_enable_timer_wakeup(lp_timer_max_allowed_time_in_us));
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_sleep_enable_timer_wakeup(lp_timer_max_allowed_time_in_us + 1));
esp_sleep_enable_timer_wakeup(2000000);
xTaskCreatePinnedToCore(&deep_sleep_task, "ds", 2048, NULL, 5, NULL, 1);