Skip to content

Commit 5971155

Browse files
committed
feat(esp_hw_support): add case to test slow clock switching
1 parent baa4d51 commit 5971155

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

components/esp_hw_support/test_apps/rtc_clk/main/test_rtc_clk.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -24,6 +24,7 @@
2424
#include "esp_rom_sys.h"
2525
#include "esp_rom_uart.h"
2626
#include "test_utils.h"
27+
#include "esp_random.h"
2728
#include "esp_sleep.h"
2829
#include "esp_system.h"
2930
#include "esp_private/esp_clk.h"
@@ -119,6 +120,26 @@ TEST_CASE("RTC_SLOW_CLK sources calibration", "[rtc_clk]")
119120
#endif
120121
}
121122

123+
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
124+
TEST_CASE("Test RTC_SLOW_CLK sources switching", "[rtc_clk]")
125+
{
126+
soc_rtc_slow_clk_src_t clk_src_before_switch = rtc_clk_slow_src_get();
127+
soc_rtc_slow_clk_src_t switching_sources[] = {SOC_RTC_SLOW_CLK_SRC_RC_SLOW, SOC_RTC_SLOW_CLK_SRC_RC_FAST_D256};
128+
129+
for (uint32_t test_cnt = 0; test_cnt < 100; test_cnt++) {
130+
uint32_t src_id = esp_random() % 2;
131+
if (switching_sources[src_id] == SOC_RTC_SLOW_CLK_SRC_RC_FAST_D256) {
132+
rtc_clk_8m_enable(true, true);
133+
}
134+
rtc_clk_slow_src_set(switching_sources[src_id]);
135+
esp_rom_delay_us(10*1000);
136+
TEST_ASSERT_EQUAL(switching_sources[src_id], rtc_clk_slow_src_get());
137+
}
138+
rtc_clk_slow_src_set(clk_src_before_switch);
139+
printf("done\n");
140+
}
141+
#endif
142+
122143
/* The following two are not unit tests, but are added here to make it easy to
123144
* check the frequency of 150k/32k oscillators. The following two "tests" will
124145
* output either 32k or 150k clock to GPIO25.

0 commit comments

Comments
 (0)