From 5e1437deb84ff7c3becc836a58e45c089e9e3c32 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Sat, 16 Jul 2022 09:01:52 +0200 Subject: [PATCH] freertos: Fixed a bug where xTimerIsTimerActive incorrectly returns pdTRUE from callback This commit fixes the following: - Fixes a bug wherein the timer status is active for oneshot timers that expire before they are started. - Callback calls for periodic timers where made before the timers were auto-reloaded. - Timer expiry trace was being set after the timer callback is called. Closes https://github.com/espressif/esp-idf/issues/8014 --- components/freertos/FreeRTOS-Kernel/timers.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/freertos/FreeRTOS-Kernel/timers.c b/components/freertos/FreeRTOS-Kernel/timers.c index dfdba57138..1356f7853f 100644 --- a/components/freertos/FreeRTOS-Kernel/timers.c +++ b/components/freertos/FreeRTOS-Kernel/timers.c @@ -856,9 +856,6 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED; { /* The timer expired before it was added to the active * timer list. Process it now. */ - pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); - traceTIMER_EXPIRED( pxTimer ); - if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 ) { xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY ); @@ -867,8 +864,12 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED; } else { - mtCOVERAGE_TEST_MARKER(); + pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE ); } + + /* Call the timer callback. */ + traceTIMER_EXPIRED( pxTimer ); + pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); } else {