1 #include <stdio.h> 2 #include "unity.h" 3 4 #include "esp_private/system_internal.h" 5 6 #if CONFIG_IDF_TARGET_ESP32 7 #include "esp32/clk.h" 8 #elif CONFIG_IDF_TARGET_ESP32S2 9 #include "esp32s2/clk.h" 10 #elif CONFIG_IDF_TARGET_ESP32S3 11 #include "esp32s3/clk.h" 12 #elif CONFIG_IDF_TARGET_ESP32C3 13 #include "esp32c3/clk.h" 14 #elif CONFIG_IDF_TARGET_ESP32H2 15 #include "esp32h2/clk.h" 16 #endif 17 18 TEST_CASE("Test effect of rtc clk calibration compensation on system time", "[esp_system]") 19 { 20 uint32_t prev_cal = esp_clk_slowclk_cal_get(); 21 int64_t t1 = esp_system_get_time(); 22 23 // Modify calibration value 24 esp_clk_slowclk_cal_set(prev_cal/2); 25 26 // Internally, the origin point of rtc clk has been adjusted 27 // so that t2 > t1 remains true 28 int64_t t2 = esp_system_get_time(); 29 30 TEST_ASSERT_GREATER_THAN(t1, t2); 31 32 // Restore calibration value 33 esp_clk_slowclk_cal_set(prev_cal); 34 35 t2 = esp_system_get_time(); 36 37 TEST_ASSERT_GREATER_THAN(t1, t2); 38 } 39