diff --git a/tests/ets_timers/Makefile b/tests/ets_timers/Makefile new file mode 100644 index 0000000..585f471 --- /dev/null +++ b/tests/ets_timers/Makefile @@ -0,0 +1,10 @@ +PROGRAM=ets_timers_test + +EXTRA_COMPONENTS = extras/test + +include ../../common.mk + +run_test: + python ../../extras/test/run_test.py $(ESPPORT) + +.PHONY: run_test diff --git a/tests/ets_timers/timers.c b/tests/ets_timers/timers.c new file mode 100644 index 0000000..2ec1e58 --- /dev/null +++ b/tests/ets_timers/timers.c @@ -0,0 +1,53 @@ +#include +#include +#include "FreeRTOS.h" +#include "task.h" +#include "etstimer.h" + +#include "test/test.h" + +static ETSTimer test_timer_0; + +static int timer_0_counter = 0; + +static uint32_t test_start_time; + + +static uint32_t get_current_time() +{ + return timer_get_count(FRC2) / 5000; // to get roughly 1ms resolution +} + +static void timer_0_cb(void *arg) +{ + uint32_t v = (uint32_t)arg; + uint32_t delay = get_current_time() - test_start_time; + + TEST_CHECK(v == 0xAA, "Timer 0 argument invalid"); + TEST_CHECK(timer_0_counter == 0, "Timer 0 repeat error"); + + // Timer should fire in 100ms + TEST_CHECK(delay > 80, "Timer 0 time wrong"); + TEST_CHECK(delay < 120, "Timer 0 time wrong"); + + timer_0_counter++; +} + +void test_task(void *pvParameters) +{ + test_start_time = get_current_time(); + + sdk_ets_timer_disarm(&test_timer_0); + sdk_ets_timer_setfn(&test_timer_0, timer_0_cb, (void*)0xAA); + sdk_ets_timer_arm(&test_timer_0, 100, false); + + // Finish the test and report the result + TEST_FINISH(); +} + +void user_init(void) +{ + TEST_INIT(10); // 10 seconds timeout + + xTaskCreate(test_task, (signed char *)"test_task", 256, NULL, 2, NULL); +}