The getting started examples in Espressif's esp-idf are hello-world and blink. Hello-world outputs prints then calls esp_restart();
- so it is in it's own special infinite loop.
The blink example (with comments removed) has this app_main, which is also an infinite loop:
void app_main(void)
{
gpio_pad_select_gpio(BLINK_GPIO);
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
while(1) {
printf("Turning off the LED\n");
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
printf("Turning on the LED\n");
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
I copied the blink example to my ~/esp folder, did NOT run makeconfig (so just with the defaults), build, flash and monitor it, and it works - the monitor just shows 'Turning off the LED' and 'Turning on the LED'. No mention of watchdog timers.
I wrote my own, most simple application I could, without the vTaskDelay() call:
void app_main(void) {
long timeSinceBoot;
while (1) {
timeSinceBoot = esp_timer_get_time();
printf("Helloooo world %ld\n!",timeSinceBoot);
};
}
This results in the serial monitor showing the following output periodically:
E (20298) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (20298) task_wdt: - IDLE0 (CPU 0)
E (20298) task_wdt: Tasks currently running:
E (20298) task_wdt: CPU 0: main
E (20298) task_wdt: CPU 1: IDLE1
I understand why - I need to call back to the OS for it to do what it needs to do. I have done this with a yield
statement in other systems.
I only want to use one core, and am trying to avoid using xTaskCreate to keep my code simple to understand.
If I don't want to delay (like the blink example does) what is the most efficient way to pass control from app_main back to FreeRTOS so it returns as soon as it can?