PROVIDE ( ets_timer_setfn = 0x40008350 );
PROVIDE ( ets_unpack_flash_code = 0x40007018 );
PROVIDE ( ets_unpack_flash_code_legacy = 0x4000694c );
-PROVIDE ( ets_update_cpu_frequency = 0x40008550 );
+/* PROVIDE ( ets_update_cpu_frequency = 0x40008550 ); */ /* Updates g_ticks_per_us on the current CPU only; not on the other core */
PROVIDE ( ets_waiti0 = 0x400067d8 );
PROVIDE ( exc_cause_table = 0x3ff991d0 );
PROVIDE ( _exit_r = 0x4000bd28 );
PROVIDE ( xthal_set_ccompare = 0x4000c058 );
PROVIDE ( xthal_set_intclear = 0x4000c1ec );
PROVIDE ( _xtos_set_intlevel = 0x4000bfdc );
+PROVIDE ( g_ticks_per_us_pro = 0x3ffe01e0 );
+PROVIDE ( g_ticks_per_us_app = 0x3ffe40f0 );
/*
These functions are xtos-related (or call xtos-related functions) and do not play well
with multicore FreeRTOS. Where needed, we provide alternatives that are multicore
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include "unity.h"
+#include "rom/ets_sys.h"
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+
+typedef struct {
+ int delay_us;
+ int method;
+} delay_test_arg_t;
+
+static void test_delay_task(void* p)
+{
+ const delay_test_arg_t* arg = (delay_test_arg_t*) p;
+ struct timeval tv_start, tv_stop;
+ gettimeofday(&tv_start, NULL);
+ switch (arg->method) {
+ case 0:
+ ets_delay_us(arg->delay_us);
+ break;
+ case 1:
+ vTaskDelay(arg->delay_us / portTICK_PERIOD_MS / 1000);
+ break;
+ default:
+ TEST_FAIL();
+ }
+ gettimeofday(&tv_stop, NULL);
+ int real_delay_us = (tv_stop.tv_sec - tv_start.tv_sec) * 1000000 +
+ tv_stop.tv_usec - tv_start.tv_usec;
+ printf("%s core=%d expected=%d actual=%d\n", arg->method ? "vTaskDelay" : "ets_delay_us",
+ xPortGetCoreID(), arg->delay_us, real_delay_us);
+ TEST_ASSERT_TRUE(abs(real_delay_us - arg->delay_us) < 1000);
+ vTaskDelay(1);
+ vTaskDelete(NULL);
+}
+
+TEST_CASE("ets_delay produces correct delay on both CPUs", "[delay]")
+{
+ int delay_ms = 50;
+ const delay_test_arg_t args = { .delay_us = delay_ms * 1000, .method = 0 };
+ xTaskCreatePinnedToCore(test_delay_task, "", 2048, (void*) &args, 3, NULL, 0);
+ vTaskDelay(delay_ms / portTICK_PERIOD_MS + 1);
+ xTaskCreatePinnedToCore(test_delay_task, "", 2048, (void*) &args, 3, NULL, 1);
+ vTaskDelay(delay_ms / portTICK_PERIOD_MS + 1);
+}
+
+TEST_CASE("vTaskDelay produces correct delay on both CPUs", "[delay]")
+{
+ int delay_ms = 50;
+ const delay_test_arg_t args = { .delay_us = delay_ms * 1000, .method = 1 };
+ xTaskCreatePinnedToCore(test_delay_task, "", 2048, (void*) &args, 3, NULL, 0);
+ vTaskDelay(delay_ms / portTICK_PERIOD_MS + 1);
+ xTaskCreatePinnedToCore(test_delay_task, "", 2048, (void*) &args, 3, NULL, 1);
+ vTaskDelay(delay_ms / portTICK_PERIOD_MS + 1);
+}