Skip to content

Commit 567b674

Browse files
change(freertos/smp): Update timers.c locking
Updated timers.c to use granular locking - Added xTaskSpinlock and xISRSpinlock - Replaced critical section macros with data group critical section macros such as taskENTER/EXIT_CRITICAL() with tmrENTER/EXIT_CRITICAL(). - Added vTimerEnterCritical() and vTimerExitCritical() to map to the data group critical section macros. Co-authored-by: Sudeep Mohanty <[email protected]>
1 parent ab42ca9 commit 567b674

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

timers.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@
7979
#define tmrSTATUS_IS_STATICALLY_ALLOCATED ( 0x02U )
8080
#define tmrSTATUS_IS_AUTORELOAD ( 0x04U )
8181

82+
/*
83+
* Macros to mark the start and end of a critical code region.
84+
*/
85+
#if ( portUSING_GRANULAR_LOCKS == 1 )
86+
#define tmrENTER_CRITICAL() taskDATA_GROUP_ENTER_CRITICAL( &xTaskSpinlock, &xISRSpinlock )
87+
#define tmrEXIT_CRITICAL() taskDATA_GROUP_EXIT_CRITICAL( &xTaskSpinlock, &xISRSpinlock )
88+
#else /* #if ( portUSING_GRANULAR_LOCKS == 1 ) */
89+
#define tmrENTER_CRITICAL() taskENTER_CRITICAL()
90+
#define tmrEXIT_CRITICAL() taskEXIT_CRITICAL()
91+
#endif /* #if ( portUSING_GRANULAR_LOCKS == 1 ) */
92+
8293
/* The definition of the timers themselves. */
8394
typedef struct tmrTimerControl /* The old naming convention is used to prevent breaking kernel aware debuggers. */
8495
{
@@ -149,6 +160,11 @@
149160
PRIVILEGED_DATA static QueueHandle_t xTimerQueue = NULL;
150161
PRIVILEGED_DATA static TaskHandle_t xTimerTaskHandle = NULL;
151162

163+
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
164+
PRIVILEGED_DATA static portSPINLOCK_TYPE xTaskSpinlock = portINIT_SPINLOCK_STATIC;
165+
PRIVILEGED_DATA static portSPINLOCK_TYPE xISRSpinlock = portINIT_SPINLOCK_STATIC;
166+
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
167+
152168
/*-----------------------------------------------------------*/
153169

154170
/*
@@ -572,7 +588,7 @@
572588
traceENTER_vTimerSetReloadMode( xTimer, xAutoReload );
573589

574590
configASSERT( xTimer );
575-
taskENTER_CRITICAL();
591+
tmrENTER_CRITICAL();
576592
{
577593
if( xAutoReload != pdFALSE )
578594
{
@@ -583,7 +599,7 @@
583599
pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_AUTORELOAD );
584600
}
585601
}
586-
taskEXIT_CRITICAL();
602+
tmrEXIT_CRITICAL();
587603

588604
traceRETURN_vTimerSetReloadMode();
589605
}
@@ -597,7 +613,7 @@
597613
traceENTER_xTimerGetReloadMode( xTimer );
598614

599615
configASSERT( xTimer );
600-
portBASE_TYPE_ENTER_CRITICAL();
616+
tmrENTER_CRITICAL();
601617
{
602618
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0U )
603619
{
@@ -610,7 +626,7 @@
610626
xReturn = pdTRUE;
611627
}
612628
}
613-
portBASE_TYPE_EXIT_CRITICAL();
629+
tmrEXIT_CRITICAL();
614630

615631
traceRETURN_xTimerGetReloadMode( xReturn );
616632

@@ -1116,7 +1132,7 @@
11161132
/* Check that the list from which active timers are referenced, and the
11171133
* queue used to communicate with the timer service, have been
11181134
* initialised. */
1119-
taskENTER_CRITICAL();
1135+
tmrENTER_CRITICAL();
11201136
{
11211137
if( xTimerQueue == NULL )
11221138
{
@@ -1158,7 +1174,7 @@
11581174
mtCOVERAGE_TEST_MARKER();
11591175
}
11601176
}
1161-
taskEXIT_CRITICAL();
1177+
tmrEXIT_CRITICAL();
11621178
}
11631179
/*-----------------------------------------------------------*/
11641180

@@ -1172,7 +1188,7 @@
11721188
configASSERT( xTimer );
11731189

11741190
/* Is the timer in the list of active timers? */
1175-
portBASE_TYPE_ENTER_CRITICAL();
1191+
tmrENTER_CRITICAL();
11761192
{
11771193
if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0U )
11781194
{
@@ -1183,7 +1199,7 @@
11831199
xReturn = pdTRUE;
11841200
}
11851201
}
1186-
portBASE_TYPE_EXIT_CRITICAL();
1202+
tmrEXIT_CRITICAL();
11871203

11881204
traceRETURN_xTimerIsTimerActive( xReturn );
11891205

@@ -1200,11 +1216,11 @@
12001216

12011217
configASSERT( xTimer );
12021218

1203-
taskENTER_CRITICAL();
1219+
tmrENTER_CRITICAL();
12041220
{
12051221
pvReturn = pxTimer->pvTimerID;
12061222
}
1207-
taskEXIT_CRITICAL();
1223+
tmrEXIT_CRITICAL();
12081224

12091225
traceRETURN_pvTimerGetTimerID( pvReturn );
12101226

@@ -1221,11 +1237,11 @@
12211237

12221238
configASSERT( xTimer );
12231239

1224-
taskENTER_CRITICAL();
1240+
tmrENTER_CRITICAL();
12251241
{
12261242
pxTimer->pvTimerID = pvNewID;
12271243
}
1228-
taskEXIT_CRITICAL();
1244+
tmrEXIT_CRITICAL();
12291245

12301246
traceRETURN_vTimerSetTimerID();
12311247
}

0 commit comments

Comments
 (0)