From 1c046f30a62c4b0359b5dd4d2f4243fb7a94328e Mon Sep 17 00:00:00 2001 From: Daniel Campora Date: Sat, 8 Jul 2017 20:47:55 +0200 Subject: [PATCH] freertos: Make the tick/idle hooks dual core compatible The way these hooks are implemented at the moment, once you register a tick or idle task hook, it is run by both cores, leading to intermittent crashes that are difficult to explain (and debug). One solution is to register the hook with the core that is currently running, which is what this patch attempts to do. Merges https://github.com/espressif/esp-idf/pull/781 --- components/esp32/freertos_hooks.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/components/esp32/freertos_hooks.c b/components/esp32/freertos_hooks.c index d59a20363..6cea80b9d 100644 --- a/components/esp32/freertos_hooks.c +++ b/components/esp32/freertos_hooks.c @@ -16,6 +16,7 @@ #include #include #include +#include "freertos/FreeRTOS.h" #include "esp_attr.h" #include "esp_freertos_hooks.h" @@ -23,15 +24,16 @@ //an idle or tick hook. #define MAX_HOOKS 8 -static esp_freertos_idle_cb_t idle_cb[MAX_HOOKS]={0}; -static esp_freertos_tick_cb_t tick_cb[MAX_HOOKS]={0}; +static esp_freertos_idle_cb_t idle_cb[portNUM_PROCESSORS][MAX_HOOKS]={0}; +static esp_freertos_tick_cb_t tick_cb[portNUM_PROCESSORS][MAX_HOOKS]={0}; void IRAM_ATTR esp_vApplicationTickHook() { int n; + int core = xPortGetCoreID(); for (n=0; n