Skip to content

Commit f2db0b3

Browse files
aggargrawalexe
authored andcommitted
fix: Add MPU wrapper for xTimerDelete API
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>
1 parent 49cec3e commit f2db0b3

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

include/mpu_prototypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ BaseType_t MPU_xTimerGenericCommandFromISR( TimerHandle_t xTimer,
368368
const TickType_t xOptionalValue,
369369
BaseType_t * const pxHigherPriorityTaskWoken,
370370
const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
371+
BaseType_t MPU_xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
371372

372373
/* MPU versions of event_group.h API functions. */
373374
EventBits_t MPU_xEventGroupWaitBits( EventGroupHandle_t xEventGroup,

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,12 @@ TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) PRIVILEGED_FUNCTION;
667667
*
668668
* See the xTimerChangePeriod() API function example usage scenario.
669669
*/
670+
#if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
671+
BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait );
672+
#else
670673
#define xTimerDelete( xTimer, xTicksToWait ) \
671674
xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
675+
#endif
672676

673677
/**
674678
* 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)