Skip to content

Commit 6faa6e2

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 <sudeep.mohanty@espressif.com>
1 parent 2f2b7e5 commit 6faa6e2

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

timers.c

Lines changed: 36 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( &xTimerDataGroupLocks )
87+
#define tmrEXIT_CRITICAL() taskDATA_GROUP_EXIT_CRITICAL( &xTimerDataGroupLocks )
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,19 @@
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 struct
165+
{
166+
portSPINLOCK_TYPE xTaskSpinlock;
167+
portSPINLOCK_TYPE xISRSpinlock;
168+
}
169+
xTimerDataGroupLocks =
170+
{
171+
.xTaskSpinlock = portINIT_SPINLOCK_STATIC,
172+
.xISRSpinlock = portINIT_SPINLOCK_STATIC
173+
};
174+
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
175+
152176
/*-----------------------------------------------------------*/
153177

154178
/*
@@ -572,7 +596,7 @@
572596
traceENTER_vTimerSetReloadMode( xTimer, xAutoReload );
573597

574598
configASSERT( xTimer );
575-
taskENTER_CRITICAL();
599+
tmrENTER_CRITICAL();
576600
{
577601
if( xAutoReload != pdFALSE )
578602
{
@@ -583,7 +607,7 @@
583607
pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_AUTORELOAD );
584608
}
585609
}
586-
taskEXIT_CRITICAL();
610+
tmrEXIT_CRITICAL();
587611

588612
traceRETURN_vTimerSetReloadMode();
589613
}
@@ -597,7 +621,7 @@
597621
traceENTER_xTimerGetReloadMode( xTimer );
598622

599623
configASSERT( xTimer );
600-
portBASE_TYPE_ENTER_CRITICAL();
624+
tmrENTER_CRITICAL();
601625
{
602626
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0U )
603627
{
@@ -610,7 +634,7 @@
610634
xReturn = pdTRUE;
611635
}
612636
}
613-
portBASE_TYPE_EXIT_CRITICAL();
637+
tmrEXIT_CRITICAL();
614638

615639
traceRETURN_xTimerGetReloadMode( xReturn );
616640

@@ -1116,7 +1140,7 @@
11161140
/* Check that the list from which active timers are referenced, and the
11171141
* queue used to communicate with the timer service, have been
11181142
* initialised. */
1119-
taskENTER_CRITICAL();
1143+
tmrENTER_CRITICAL();
11201144
{
11211145
if( xTimerQueue == NULL )
11221146
{
@@ -1158,7 +1182,7 @@
11581182
mtCOVERAGE_TEST_MARKER();
11591183
}
11601184
}
1161-
taskEXIT_CRITICAL();
1185+
tmrEXIT_CRITICAL();
11621186
}
11631187
/*-----------------------------------------------------------*/
11641188

@@ -1172,7 +1196,7 @@
11721196
configASSERT( xTimer );
11731197

11741198
/* Is the timer in the list of active timers? */
1175-
portBASE_TYPE_ENTER_CRITICAL();
1199+
tmrENTER_CRITICAL();
11761200
{
11771201
if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0U )
11781202
{
@@ -1183,7 +1207,7 @@
11831207
xReturn = pdTRUE;
11841208
}
11851209
}
1186-
portBASE_TYPE_EXIT_CRITICAL();
1210+
tmrEXIT_CRITICAL();
11871211

11881212
traceRETURN_xTimerIsTimerActive( xReturn );
11891213

@@ -1200,11 +1224,11 @@
12001224

12011225
configASSERT( xTimer );
12021226

1203-
taskENTER_CRITICAL();
1227+
tmrENTER_CRITICAL();
12041228
{
12051229
pvReturn = pxTimer->pvTimerID;
12061230
}
1207-
taskEXIT_CRITICAL();
1231+
tmrEXIT_CRITICAL();
12081232

12091233
traceRETURN_pvTimerGetTimerID( pvReturn );
12101234

@@ -1221,11 +1245,11 @@
12211245

12221246
configASSERT( xTimer );
12231247

1224-
taskENTER_CRITICAL();
1248+
tmrENTER_CRITICAL();
12251249
{
12261250
pxTimer->pvTimerID = pvNewID;
12271251
}
1228-
taskEXIT_CRITICAL();
1252+
tmrEXIT_CRITICAL();
12291253

12301254
traceRETURN_vTimerSetTimerID();
12311255
}

0 commit comments

Comments
 (0)