From 85ce51dad6aef44446c9f289e65f35c318afe015 Mon Sep 17 00:00:00 2001 From: Muneeb Ahmed <54290492+muneebahmed10@users.noreply.github.com> Date: Tue, 8 Feb 2022 15:57:54 -0700 Subject: [PATCH] Add wait to timer_settime (#17) --- FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_timer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_timer.c b/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_timer.c index f790e83..33485ae 100755 --- a/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_timer.c +++ b/FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_timer.c @@ -196,6 +196,7 @@ int timer_settime( timer_t timerid, TimerHandle_t xTimerHandle = timerid; timer_internal_t * pxTimer = ( timer_internal_t * ) pvTimerGetTimerID( xTimerHandle ); TickType_t xNextTimerExpiration = 0, xTimerExpirationPeriod = 0; + BaseType_t xTimerCommandSent = pdFAIL; /* Validate the value argument, but only if the timer isn't being disarmed. */ if( TIMESPEC_IS_NOT_ZERO( value->it_value ) ) @@ -283,7 +284,13 @@ int timer_settime( timer_t timerid, { /* Set the timer to expire at the it_value, then start it. */ ( void ) xTimerChangePeriod( xTimerHandle, xNextTimerExpiration, portMAX_DELAY ); - ( void ) xTimerStart( xTimerHandle, xNextTimerExpiration ); + xTimerCommandSent = xTimerStart( xTimerHandle, xNextTimerExpiration ); + + /* Wait until the timer start command is processed. */ + while( ( xTimerCommandSent != pdFAIL ) && ( xTimerIsTimerActive( xTimerHandle ) == pdFALSE ) ) + { + vTaskDelay( 1 ); + } } }