Skip to content

Commit a50edad

Browse files
rawalexeaggarg
andauthored
fix: Add MPU wrapper for xTimerDelete API (#1412)
When using MPU wrappers v2, xTimerDelete needs to be a real function rather than a macro so that the kernel object pool index can be freed after the timer is successfully deleted. Without this, deleting a timer leaks the kernel object pool entry. Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
1 parent ae46383 commit a50edad

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

include/mpu_prototypes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ BaseType_t MPU_xTimerGenericCommandFromISR( TimerHandle_t xTimer,
369369
BaseType_t * const pxHigherPriorityTaskWoken,
370370
const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
371371

372+
BaseType_t MPU_xTimerDelete( TimerHandle_t xTimer,
373+
TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
374+
372375
/* MPU versions of event_group.h API functions. */
373376
EventBits_t MPU_xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
374377
const EventBits_t uxBitsToWaitFor,

include/mpu_wrappers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
#define xTimerCreateStatic MPU_xTimerCreateStatic
191191
#define xTimerGetStaticBuffer MPU_xTimerGetStaticBuffer
192192
#define xTimerGenericCommandFromISR MPU_xTimerGenericCommandFromISR
193+
#define xTimerDelete MPU_xTimerDelete
193194
#endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
194195

195196
/* Map standard event_group.h API functions to the MPU equivalents. */

include/timers.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,13 @@ TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) PRIVILEGED_FUNCTION;
667667
*
668668
* See the xTimerChangePeriod() API function example usage scenario.
669669
*/
670-
#define xTimerDelete( xTimer, xTicksToWait ) \
670+
#if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
671+
BaseType_t xTimerDelete( TimerHandle_t xTimer,
672+
TickType_t xTicksToWait );
673+
#else
674+
#define xTimerDelete( xTimer, xTicksToWait ) \
671675
xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
676+
#endif
672677

673678
/**
674679
* BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );

portable/Common/mpu_wrappers_v2.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3890,6 +3890,40 @@
38903890
#endif /* if ( configUSE_TIMERS == 1 ) */
38913891
/*-----------------------------------------------------------*/
38923892

3893+
#if ( configUSE_TIMERS == 1 )
3894+
3895+
BaseType_t MPU_xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
3896+
{
3897+
BaseType_t xReturn = pdFALSE;
3898+
TimerHandle_t xInternalTimerHandle = NULL;
3899+
int32_t lIndex;
3900+
3901+
lIndex = ( int32_t ) xTimer;
3902+
3903+
if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3904+
{
3905+
xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3906+
3907+
if( xInternalTimerHandle != NULL )
3908+
{
3909+
xReturn = xTimerGenericCommandFromTask( xInternalTimerHandle,
3910+
tmrCOMMAND_DELETE,
3911+
0U, /* xOptionalValue */
3912+
NULL, /* pxHigherPriorityTaskWoken */
3913+
xTicksToWait );
3914+
if( xReturn != pdFALSE )
3915+
{
3916+
MPU_SetIndexFreeInKernelObjectPool( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3917+
}
3918+
}
3919+
}
3920+
3921+
return xReturn;
3922+
}
3923+
3924+
#endif /* if ( configUSE_TIMERS == 1 ) */
3925+
/*-----------------------------------------------------------*/
3926+
38933927
/*-----------------------------------------------------------*/
38943928
/* MPU wrappers for event group APIs. */
38953929
/*-----------------------------------------------------------*/

0 commit comments

Comments
 (0)