Skip to content

Commit fcdbb0d

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 locking macros such as taskENTER/EXIT_CRITICAL() with tmrENTER/EXIT_CRITICAL(). Co-authored-by: Sudeep Mohanty <[email protected]>
1 parent 550a488 commit fcdbb0d

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

timers.c

+28-12
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() portENTER_CRITICAL_DATA_GROUP( ( portSPINLOCK_TYPE * ) &xTaskSpinlock, ( portSPINLOCK_TYPE * ) &xISRSpinlock )
87+
#define tmrEXIT_CRITICAL() portEXIT_CRITICAL_DATA_GROUP( ( portSPINLOCK_TYPE * ) &xTaskSpinlock, ( portSPINLOCK_TYPE * ) &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
/*
@@ -576,7 +592,7 @@
576592
traceENTER_vTimerSetReloadMode( xTimer, xAutoReload );
577593

578594
configASSERT( xTimer );
579-
taskENTER_CRITICAL();
595+
tmrENTER_CRITICAL();
580596
{
581597
if( xAutoReload != pdFALSE )
582598
{
@@ -587,7 +603,7 @@
587603
pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_AUTORELOAD );
588604
}
589605
}
590-
taskEXIT_CRITICAL();
606+
tmrEXIT_CRITICAL();
591607

592608
traceRETURN_vTimerSetReloadMode();
593609
}
@@ -601,7 +617,7 @@
601617
traceENTER_xTimerGetReloadMode( xTimer );
602618

603619
configASSERT( xTimer );
604-
portBASE_TYPE_ENTER_CRITICAL();
620+
tmrENTER_CRITICAL();
605621
{
606622
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0U )
607623
{
@@ -614,7 +630,7 @@
614630
xReturn = pdTRUE;
615631
}
616632
}
617-
portBASE_TYPE_EXIT_CRITICAL();
633+
tmrEXIT_CRITICAL();
618634

619635
traceRETURN_xTimerGetReloadMode( xReturn );
620636

@@ -1113,7 +1129,7 @@
11131129
/* Check that the list from which active timers are referenced, and the
11141130
* queue used to communicate with the timer service, have been
11151131
* initialised. */
1116-
taskENTER_CRITICAL();
1132+
tmrENTER_CRITICAL();
11171133
{
11181134
if( xTimerQueue == NULL )
11191135
{
@@ -1155,7 +1171,7 @@
11551171
mtCOVERAGE_TEST_MARKER();
11561172
}
11571173
}
1158-
taskEXIT_CRITICAL();
1174+
tmrEXIT_CRITICAL();
11591175
}
11601176
/*-----------------------------------------------------------*/
11611177

@@ -1169,7 +1185,7 @@
11691185
configASSERT( xTimer );
11701186

11711187
/* Is the timer in the list of active timers? */
1172-
portBASE_TYPE_ENTER_CRITICAL();
1188+
tmrENTER_CRITICAL();
11731189
{
11741190
if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0U )
11751191
{
@@ -1180,7 +1196,7 @@
11801196
xReturn = pdTRUE;
11811197
}
11821198
}
1183-
portBASE_TYPE_EXIT_CRITICAL();
1199+
tmrEXIT_CRITICAL();
11841200

11851201
traceRETURN_xTimerIsTimerActive( xReturn );
11861202

@@ -1197,11 +1213,11 @@
11971213

11981214
configASSERT( xTimer );
11991215

1200-
taskENTER_CRITICAL();
1216+
tmrENTER_CRITICAL();
12011217
{
12021218
pvReturn = pxTimer->pvTimerID;
12031219
}
1204-
taskEXIT_CRITICAL();
1220+
tmrEXIT_CRITICAL();
12051221

12061222
traceRETURN_pvTimerGetTimerID( pvReturn );
12071223

@@ -1218,11 +1234,11 @@
12181234

12191235
configASSERT( xTimer );
12201236

1221-
taskENTER_CRITICAL();
1237+
tmrENTER_CRITICAL();
12221238
{
12231239
pxTimer->pvTimerID = pvNewID;
12241240
}
1225-
taskEXIT_CRITICAL();
1241+
tmrEXIT_CRITICAL();
12261242

12271243
traceRETURN_vTimerSetTimerID();
12281244
}

0 commit comments

Comments
 (0)