|
1 | 1 | /* |
2 | | - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
|
24 | 24 | #include "esp_rom_sys.h" |
25 | 25 | #include "esp_rom_uart.h" |
26 | 26 | #include "test_utils.h" |
| 27 | +#include "esp_random.h" |
27 | 28 | #include "esp_sleep.h" |
28 | 29 | #include "esp_system.h" |
29 | 30 | #include "esp_private/esp_clk.h" |
@@ -119,6 +120,26 @@ TEST_CASE("RTC_SLOW_CLK sources calibration", "[rtc_clk]") |
119 | 120 | #endif |
120 | 121 | } |
121 | 122 |
|
| 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 | + |
122 | 143 | /* The following two are not unit tests, but are added here to make it easy to |
123 | 144 | * check the frequency of 150k/32k oscillators. The following two "tests" will |
124 | 145 | * output either 32k or 150k clock to GPIO25. |
|
0 commit comments