I’m updating my last post because it won’t work. The info here is tested on an ESP32.
The Espressif API modified the FreeRTOS hooks to be compatible with multicore CPUs, allowing you to specify a separate idle task for each core. Under this system, you have to register your idle task function. The original idle hook has been modified to call the hooks you register, and you can not write:
void vApplicationIdleHook(void)
If you do, when you compile you’ll get an error indication that this function has been redefined by your code. This example is written for the idle hook, but the tick hook has similar changes.
All this is (mostly) explained here:
https://demo-dijiudu.readthedocs.io/en/latest/api-reference/system/hooks.html
I tested this, and here is what you need to do to make this work:
In your mos.yml file:
build_vars:
ESP_IDF_SDKCONFIG_OPTS: >
"${build_vars.ESP_IDF_SDKCONFIG_OPTS}"
CONFIG_FREERTOS_LEGACY_HOOKS=1
In your code, you’ll need these header files:
#include "FreeRTOS.h"
#include "esp_freertos_hooks.h"
Then you’ll need to write your idle hook callback:
static long int ctr;
bool myTestIdleHook(void)
{
ctr++;
return true;
}
The callback should return true if it should be called by the idle hook once per interrupt (or FreeRTOS tick), and return false if it should be called repeatedly as fast as possible by the idle hook.
Finally, register the idle task callback. There are a bunch of functions available for this, see the link above for complete details. This function registers the callback for the core on which it is called:
if(esp_register_freertos_idle_hook(myTestIdleHook) == ESP_OK)
LOG(LL_INFO, ("Idle hook successfully registered."));
else
LOG(LL_INFO, ("Idle hook registration failed."));
Check the link above for return information. It took a bit of research to figure this out, so I hope its useful to someone.
Cheers!