From d143ec0bcbca1d161cec6ecdcfee037fc05c0c3e Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Tue, 17 May 2022 09:12:06 +0200 Subject: [PATCH 1/2] Fix timerAttachInterrupt() and timerDetachInterrupt() for migration to IDF 4.4 --- cores/esp32/esp32-hal-timer.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/cores/esp32/esp32-hal-timer.c b/cores/esp32/esp32-hal-timer.c index c2dc5e1f04d..f6cbd547bfd 100644 --- a/cores/esp32/esp32-hal-timer.c +++ b/cores/esp32/esp32-hal-timer.c @@ -32,13 +32,6 @@ typedef union { #define NUM_OF_TIMERS SOC_TIMER_GROUP_TOTAL_TIMERS -typedef struct { - int timer_group; - int timer_idx; - int alarm_interval; - bool auto_reload; -} timer_info_t; - typedef struct hw_timer_s { uint8_t group; @@ -194,7 +187,7 @@ static void _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp){ if(num >= NUM_OF_TIMERS) { - log_e("Timer dont have that timer number."); + log_e("'num' exceeds available number of Timers."); return NULL; } @@ -220,24 +213,23 @@ void timerEnd(hw_timer_t *timer){ timer_deinit(timer->group, timer->num); } +bool IRAM_ATTR timerFnWrapper(void *arg){ + void (*fn)(void) = arg; + fn(); + + // some additional logic or handling may be required here to approriately yield or not + return false; +} + void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){ if(edge){ - log_w("EDGE timer interrupt is not supported! Setting to LEVEL..."); - edge = false; + log_w("EDGE timer interrupt is not supported!"); } - timer_enable_intr(timer->group, timer->num); - - timer_info_t *timer_info = calloc(1, sizeof(timer_info_t)); - timer_info->timer_group = timer->group; - timer_info->timer_idx = timer->num; - timer_info->auto_reload = timerGetAutoReload(timer); - timer_info->alarm_interval = timerAlarmRead(timer); - - timer_isr_callback_add(timer->group, timer->num, (timer_isr_t)fn, timer_info, 0); + timer_isr_callback_add(timer->group, timer->num, timerFnWrapper, fn, 0); } void timerDetachInterrupt(hw_timer_t *timer){ - timerAttachInterrupt(timer, NULL, false); + timer_isr_callback_remove(timer->group, timer->num); } uint64_t timerReadMicros(hw_timer_t *timer){ From a9ee853c4327909e33390e771f64f9a988d43fd9 Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Thu, 26 May 2022 19:27:49 +0200 Subject: [PATCH 2/2] Fixing log messages as per request --- cores/esp32/esp32-hal-timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-timer.c b/cores/esp32/esp32-hal-timer.c index f6cbd547bfd..e0cfda10222 100644 --- a/cores/esp32/esp32-hal-timer.c +++ b/cores/esp32/esp32-hal-timer.c @@ -187,7 +187,7 @@ static void _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp){ if(num >= NUM_OF_TIMERS) { - log_e("'num' exceeds available number of Timers."); + log_e("Timer number %u exceeds available number of Timers.", num); return NULL; } @@ -223,7 +223,7 @@ bool IRAM_ATTR timerFnWrapper(void *arg){ void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){ if(edge){ - log_w("EDGE timer interrupt is not supported!"); + log_w("EDGE timer interrupt is not supported! Setting to LEVEL..."); } timer_isr_callback_add(timer->group, timer->num, timerFnWrapper, fn, 0); }