Short background: I'm working on a CAN-Bus adapter based on the ESP32C6 (later ESP32S3). I'm sending a lot of data to the CAN-Bus, however I'm not allowed to send the can frames without any delay. The shortest delay I can achieve using FreeRTOS is 1ms (I have set `CONFIG_FREERTOS_HZ=1000` and it works fine so far), which is way to long, since I need e.g., 350µs.
I tried using a busy waiting loop with code such as
Code: Select all
static inline void delayMicrosecondsBusyWaiting(uint32_t us) {
uint32_t m = (unsigned long)esp_timer_get_time();
if (us) {
uint32_t e = (m + us);
if (m > e) { // overflow
while ((unsigned long)esp_timer_get_time() > e) {
asm volatile("nop");
}
}
while ((unsigned long)esp_timer_get_time()) {
asm volatile("nop");
}
}
}
Code: Select all
E (784675) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (784675) task_wdt: - IDLE (CPU 0)
E (784675) task_wdt: Tasks currently running:
E (784675) task_wdt: CPU 0: TwaiReceiver
E (784675) task_wdt: Print CPU 0 (current core) registers
Is there another way to achieve a delay with microsecond granularity when sending out CAN frames? Or will I have to patch the Twai driver itself?