Skip to content

Commit 0481c81

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 7d3c250 commit 0481c81

1 file changed

Lines changed: 55 additions & 12 deletions

File tree

timers.c

Lines changed: 55 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( &xTimerTaskSpinlock, &xTimerISRSpinlock )
87+
#define tmrEXIT_CRITICAL() taskDATA_GROUP_EXIT_CRITICAL( &xTimerTaskSpinlock, &xTimerISRSpinlock )
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
{
@@ -582,7 +593,7 @@
582593
traceENTER_vTimerSetReloadMode( xTimer, xAutoReload );
583594

584595
configASSERT( xTimer );
585-
taskENTER_CRITICAL();
596+
tmrENTER_CRITICAL();
586597
{
587598
if( xAutoReload != pdFALSE )
588599
{
@@ -593,7 +604,7 @@
593604
pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_AUTORELOAD );
594605
}
595606
}
596-
taskEXIT_CRITICAL();
607+
tmrEXIT_CRITICAL();
597608

598609
traceRETURN_vTimerSetReloadMode();
599610
}
@@ -607,7 +618,15 @@
607618
traceENTER_xTimerGetReloadMode( xTimer );
608619

609620
configASSERT( xTimer );
610-
portBASE_TYPE_ENTER_CRITICAL();
621+
#if ( ( configNUMBER_OF_CORES > 1 ) )
622+
{
623+
tmrENTER_CRITICAL();
624+
}
625+
#else
626+
{
627+
portBASE_TYPE_ENTER_CRITICAL();
628+
}
629+
#endif
611630
{
612631
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0U )
613632
{
@@ -620,7 +639,15 @@
620639
xReturn = pdTRUE;
621640
}
622641
}
623-
portBASE_TYPE_EXIT_CRITICAL();
642+
#if ( ( configNUMBER_OF_CORES > 1 ) )
643+
{
644+
tmrEXIT_CRITICAL();
645+
}
646+
#else
647+
{
648+
portBASE_TYPE_EXIT_CRITICAL();
649+
}
650+
#endif
624651

625652
traceRETURN_xTimerGetReloadMode( xReturn );
626653

@@ -1126,7 +1153,7 @@
11261153
/* Check that the list from which active timers are referenced, and the
11271154
* queue used to communicate with the timer service, have been
11281155
* initialised. */
1129-
taskENTER_CRITICAL();
1156+
tmrENTER_CRITICAL();
11301157
{
11311158
if( xTimerQueue == NULL )
11321159
{
@@ -1168,7 +1195,7 @@
11681195
mtCOVERAGE_TEST_MARKER();
11691196
}
11701197
}
1171-
taskEXIT_CRITICAL();
1198+
tmrEXIT_CRITICAL();
11721199
}
11731200
/*-----------------------------------------------------------*/
11741201

@@ -1182,7 +1209,15 @@
11821209
configASSERT( xTimer );
11831210

11841211
/* Is the timer in the list of active timers? */
1185-
portBASE_TYPE_ENTER_CRITICAL();
1212+
#if ( ( configNUMBER_OF_CORES > 1 ) )
1213+
{
1214+
tmrENTER_CRITICAL();
1215+
}
1216+
#else
1217+
{
1218+
portBASE_TYPE_ENTER_CRITICAL();
1219+
}
1220+
#endif
11861221
{
11871222
if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0U )
11881223
{
@@ -1193,7 +1228,15 @@
11931228
xReturn = pdTRUE;
11941229
}
11951230
}
1196-
portBASE_TYPE_EXIT_CRITICAL();
1231+
#if ( ( configNUMBER_OF_CORES > 1 ) )
1232+
{
1233+
tmrEXIT_CRITICAL();
1234+
}
1235+
#else
1236+
{
1237+
portBASE_TYPE_EXIT_CRITICAL();
1238+
}
1239+
#endif
11971240

11981241
traceRETURN_xTimerIsTimerActive( xReturn );
11991242

@@ -1210,11 +1253,11 @@
12101253

12111254
configASSERT( xTimer );
12121255

1213-
taskENTER_CRITICAL();
1256+
tmrENTER_CRITICAL();
12141257
{
12151258
pvReturn = pxTimer->pvTimerID;
12161259
}
1217-
taskEXIT_CRITICAL();
1260+
tmrEXIT_CRITICAL();
12181261

12191262
traceRETURN_pvTimerGetTimerID( pvReturn );
12201263

@@ -1231,11 +1274,11 @@
12311274

12321275
configASSERT( xTimer );
12331276

1234-
taskENTER_CRITICAL();
1277+
tmrENTER_CRITICAL();
12351278
{
12361279
pxTimer->pvTimerID = pvNewID;
12371280
}
1238-
taskEXIT_CRITICAL();
1281+
tmrEXIT_CRITICAL();
12391282

12401283
traceRETURN_vTimerSetTimerID();
12411284
}

0 commit comments

Comments
 (0)