ESP32-core in which file is delay() declared?

Hi Everybody,

I'm interested in the ESP32-core what are the lines of code for function delay() inside the core for ESP32

So I tried a find-text in files search in the path
C:\Users\dipl-\AppData\Local\Arduino15\packages\esp32

but with no success.
As the function delay() can be used in ESP32-code it must be defined / declared somewhere

How would you start searching for it?
extension filter *.cpp?
what folder-paths?

is this so special that it is just a precompiled hex-file whcih means I can't find the character-sequence "delay("?

best regards Stefan

I don't know but you might want to broaden your search. Perhaps "delay()" is not unique to the ESP32.

I use the "Gnu ID tools"
They say:

Users/westf/AppData/Local/Arduino15/packages/esp32/hardware/esp32/2.0.7/cores/esp32$ gid delay
esp32-hal.h:134:void delay(uint32_t);
esp32-hal-misc.c:176:void delay(uint32_t ms)
esp32-hal-time.c:93:        delay(10);
esp32-hal-touch.c:182:    delay(20);  //delay needed before reading from touch channel after config
FirmwareMSC.cpp:361:      delay(100);
FirmwareMSC.cpp:364:    delay(100);
HWCDC.cpp:82:                // Otherwise, USB is still unplugged and the timeout will be kept as Zero in order to avoid any delay in the
HWCDC.cpp:210:    // used for the workaround with unplugged USB and TX Queue Full that causes a delay on every write()
HWCDC.cpp:309:        delay(5);
HardwareSerial.cpp:394:            delay(100); // Give some time...
HardwareSerial.cpp:452:    delay(10);
Tone.cpp:38:          delay(tone_msg.duration);
westfw@ww-gaming:/mnt/c/Users/westf/AppData/Local/Arduino15/packages/esp32/hardware/esp32/2.0.7/cores/esp32

(for an index built in that "cores" directory. If you search from further up, there are a lot more occurrences.)

The definition is that one in esp32-hal-misc.c
It might not be very useful. Since the esp32 core builds on freertos, you get:

void delay(uint32_t ms)
{
    vTaskDelay(ms / portTICK_PERIOD_MS);
}

and vTaskDelay is defined off in the depths of FreeRTOS somewhere (source for freertos is not included in the Arduino distribution, although it is open source.) At least it's probably well documented!

And it is a non-blocking implementation in a multi-tasking system. I.e. the calling task is suspended for that time, leaving the core for other tasks. In this case delay() is preferable to polling time().

Hi @westfw and @DrDiettrich,

ah !
it is a *.c-file not *.cpp

so through executing a delay() on an ESP32 the arduino-code is suspended but WiFi and other tasks including softwarewatchdog-timer are continued which means using a delay() will block my own arduino-code but will not trigger the softwarewatchdog?

best regards Stefan

I only know of an example where polling time() instead of using delay() has triggered the watchdog. Perhaps a too long delay should be splitted for insertion of watchdog care?

delay() works as vTaskDelay() on a ESP32 when using a freeRTOS task. If, on a esp32, no tasks are being used and delay() is in loop() then delay stops execution of the code.

Aren’t all arduino sketches run as freertos tasks on esp32?

loop() is indeed run as a freeRTOS task. How loop() is used will be dependent on whether it has any code in loop(). If loop() is the only task running on core1 and delay() is called on core1, core1 comes to a halt. If using freeRTOS tasks and loop() is empty then vTaskDelay() will cause the freeRTOS task switcher to switch to another task for the duration of the vTaskDelay(). If using freeRTOS tasks and loop() is not empty, loop() is not guaranteed to run as loop() has the lowest priority of all tasks.

Core0 runs independently of core1.

The FreeRTOS Idle Task will likely run and take care housekeeping chores.

Only if another task is in the Ready To Run state.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.