refactor(driver/gptimer): replace vTaskDelay

with esp_rom_delay_us in test_apps

This commit replaces vTaskDelay with esp_rom_delay_us in the gptimer
driver. The former function can introduce millisecond jitter due to
OS task switching, while the latter has less jitter because of the
polling delay. Therefore this commit reduces the delta values for
various timer tests.

Changes made in this commit include:
- Replacing vTaskDelay with esp_rom_delay_us
- Adjusting delta values for various timer tests
This commit is contained in:
Chen Jichang
2023-06-27 11:15:06 +08:00
parent c221ce331a
commit 001a16ea6e

View File

@ -84,44 +84,44 @@ TEST_CASE("gptimer_wallclock_with_various_clock_sources", "[gptimer]")
for (int i = 0; i < SOC_TIMER_GROUP_TOTAL_TIMERS; i++) {
TEST_ESP_OK(gptimer_start(timers[i]));
}
vTaskDelay(pdMS_TO_TICKS(20)); // 20ms = 20_000 ticks
esp_rom_delay_us(20 * 1000); // 20ms = 20_000 ticks
uint64_t value = 0;
for (int i = 0; i < SOC_TIMER_GROUP_TOTAL_TIMERS; i++) {
TEST_ESP_OK(gptimer_get_raw_count(timers[i], &value));
// convert the raw count to us
value = value * 1000000 / timer_resolution_hz[i];
TEST_ASSERT_UINT_WITHIN(1100, 20000, value);
TEST_ASSERT_UINT_WITHIN(200, 20000, value);
}
printf("stop timers\r\n");
for (int i = 0; i < SOC_TIMER_GROUP_TOTAL_TIMERS; i++) {
TEST_ESP_OK(gptimer_stop(timers[i]));
}
printf("check whether timers have stopped\r\n");
vTaskDelay(pdMS_TO_TICKS(20));
esp_rom_delay_us(20 * 1000);
for (int i = 0; i < SOC_TIMER_GROUP_TOTAL_TIMERS; i++) {
TEST_ESP_OK(gptimer_get_raw_count(timers[i], &value));
printf("get raw count of gptimer %d: %llu\r\n", i, value);
// convert the raw count to us
value = value * 1000000 / timer_resolution_hz[i];
TEST_ASSERT_UINT_WITHIN(1000, 20000, value);
TEST_ASSERT_UINT_WITHIN(200, 20000, value);
}
printf("restart timers\r\n");
for (int i = 0; i < SOC_TIMER_GROUP_TOTAL_TIMERS; i++) {
TEST_ESP_OK(gptimer_start(timers[i]));
}
vTaskDelay(pdMS_TO_TICKS(20));
esp_rom_delay_us(20 * 1000);
printf("stop timers again\r\n");
for (int i = 0; i < SOC_TIMER_GROUP_TOTAL_TIMERS; i++) {
TEST_ESP_OK(gptimer_stop(timers[i]));
}
printf("check whether timers have stopped\r\n");
vTaskDelay(pdMS_TO_TICKS(20));
esp_rom_delay_us(20 * 1000);
for (int i = 0; i < SOC_TIMER_GROUP_TOTAL_TIMERS; i++) {
TEST_ESP_OK(gptimer_get_raw_count(timers[i], &value));
printf("get raw count of gptimer %d: %llu\r\n", i, value);
// convert the raw count to us
value = value * 1000000 / timer_resolution_hz[i];
TEST_ASSERT_UINT_WITHIN(2500, 40000, value);
TEST_ASSERT_UINT_WITHIN(400, 40000, value);
}
printf("disable timers\r\n");
for (int i = 0; i < SOC_TIMER_GROUP_TOTAL_TIMERS; i++) {
@ -141,7 +141,7 @@ TEST_CASE("gptimer_wallclock_with_various_clock_sources", "[gptimer]")
#if CONFIG_PM_ENABLE
#define GPTIMER_STOP_ON_ALARM_COUNT_DELTA 150
#else
#define GPTIMER_STOP_ON_ALARM_COUNT_DELTA 50
#define GPTIMER_STOP_ON_ALARM_COUNT_DELTA 30
#endif // CONFIG_PM_ENABLE
TEST_ALARM_CALLBACK_ATTR static bool test_gptimer_alarm_stop_callback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_data)
@ -226,7 +226,7 @@ TEST_CASE("gptimer_stop_on_alarm", "[gptimer]")
#if CONFIG_PM_ENABLE
#define GPTIMER_AUTO_RELOAD_ON_ALARM_COUNT_DELTA 200
#else
#define GPTIMER_AUTO_RELOAD_ON_ALARM_COUNT_DELTA 30
#define GPTIMER_AUTO_RELOAD_ON_ALARM_COUNT_DELTA 20
#endif // CONFIG_PM_ENABLE
TEST_ALARM_CALLBACK_ATTR static bool test_gptimer_alarm_reload_callback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_data)