mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2026-10-10 08:02:57 -04:00
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>
This commit is contained in:
parent
27eae2464f
commit
586414f848
1 changed files with 49 additions and 19 deletions
68
timers.c
68
timers.c
|
|
@ -55,6 +55,16 @@
|
|||
* configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
|
||||
#if ( configUSE_TIMERS == 1 )
|
||||
|
||||
/*
|
||||
* Some kernel aware debuggers require the data the debugger needs access to be
|
||||
* global, rather than file scope.
|
||||
*/
|
||||
#ifdef portREMOVE_STATIC_QUALIFIER
|
||||
#define STATIC
|
||||
#else
|
||||
#define STATIC static
|
||||
#endif
|
||||
|
||||
/* Misc definitions. */
|
||||
#define tmrNO_DELAY ( ( TickType_t ) 0U )
|
||||
#define tmrMAX_TIME_BEFORE_OVERFLOW ( ( TickType_t ) -1 )
|
||||
|
|
@ -79,6 +89,31 @@
|
|||
#define tmrSTATUS_IS_STATICALLY_ALLOCATED ( 0x02U )
|
||||
#define tmrSTATUS_IS_AUTORELOAD ( 0x04U )
|
||||
|
||||
/*
|
||||
* Macros to mark the start and end of a critical code region.
|
||||
*/
|
||||
#if ( portUSING_GRANULAR_LOCKS == 1 )
|
||||
#define tmrENTER_CRITICAL() taskDATA_GROUP_ENTER_CRITICAL( &xTimerTaskSpinlock, &xTimerISRSpinlock )
|
||||
#define tmrEXIT_CRITICAL() taskDATA_GROUP_EXIT_CRITICAL( &xTimerTaskSpinlock, &xTimerISRSpinlock )
|
||||
#else /* #if ( portUSING_GRANULAR_LOCKS == 1 ) */
|
||||
#define tmrENTER_CRITICAL() taskENTER_CRITICAL()
|
||||
#define tmrEXIT_CRITICAL() taskEXIT_CRITICAL()
|
||||
#endif /* #if ( portUSING_GRANULAR_LOCKS == 1 ) */
|
||||
|
||||
/*
|
||||
* Macros to mark the start and end of a critical code region that only reads a
|
||||
* single BaseType_t sized timer member. Ports that can read such a member
|
||||
* atomically define portBASE_TYPE_ENTER_CRITICAL() away, so that path must be
|
||||
* preserved wherever a data group critical section is not required.
|
||||
*/
|
||||
#if ( configNUMBER_OF_CORES > 1 )
|
||||
#define tmrBASE_TYPE_ENTER_CRITICAL() tmrENTER_CRITICAL()
|
||||
#define tmrBASE_TYPE_EXIT_CRITICAL() tmrEXIT_CRITICAL()
|
||||
#else
|
||||
#define tmrBASE_TYPE_ENTER_CRITICAL() portBASE_TYPE_ENTER_CRITICAL()
|
||||
#define tmrBASE_TYPE_EXIT_CRITICAL() portBASE_TYPE_EXIT_CRITICAL()
|
||||
#endif /* #if ( configNUMBER_OF_CORES > 1 ) */
|
||||
|
||||
/* The definition of the timers themselves. */
|
||||
typedef struct tmrTimerControl /* The old naming convention is used to prevent breaking kernel aware debuggers. */
|
||||
{
|
||||
|
|
@ -150,13 +185,8 @@
|
|||
PRIVILEGED_DATA static TaskHandle_t xTimerTaskHandle = NULL;
|
||||
|
||||
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
|
||||
#ifdef portREMOVE_STATIC_QUALIFIER
|
||||
PRIVILEGED_DATA portSPINLOCK_TYPE xTimerTaskSpinlock = portINIT_SPINLOCK_STATIC;
|
||||
PRIVILEGED_DATA portSPINLOCK_TYPE xTimerISRSpinlock = portINIT_SPINLOCK_STATIC;
|
||||
#else
|
||||
PRIVILEGED_DATA static portSPINLOCK_TYPE xTimerTaskSpinlock = portINIT_SPINLOCK_STATIC;
|
||||
PRIVILEGED_DATA static portSPINLOCK_TYPE xTimerISRSpinlock = portINIT_SPINLOCK_STATIC;
|
||||
#endif
|
||||
PRIVILEGED_DATA STATIC portSPINLOCK_TYPE xTimerTaskSpinlock = portINIT_SPINLOCK_STATIC;
|
||||
PRIVILEGED_DATA STATIC portSPINLOCK_TYPE xTimerISRSpinlock = portINIT_SPINLOCK_STATIC;
|
||||
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -584,7 +614,7 @@
|
|||
traceENTER_vTimerSetReloadMode( xTimer, xAutoReload );
|
||||
|
||||
configASSERT( xTimer );
|
||||
taskENTER_CRITICAL();
|
||||
tmrENTER_CRITICAL();
|
||||
{
|
||||
if( xAutoReload != pdFALSE )
|
||||
{
|
||||
|
|
@ -595,7 +625,7 @@
|
|||
pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_AUTORELOAD );
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
tmrEXIT_CRITICAL();
|
||||
|
||||
traceRETURN_vTimerSetReloadMode();
|
||||
}
|
||||
|
|
@ -609,7 +639,7 @@
|
|||
traceENTER_xTimerGetReloadMode( xTimer );
|
||||
|
||||
configASSERT( xTimer );
|
||||
portBASE_TYPE_ENTER_CRITICAL();
|
||||
tmrBASE_TYPE_ENTER_CRITICAL();
|
||||
{
|
||||
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0U )
|
||||
{
|
||||
|
|
@ -622,7 +652,7 @@
|
|||
xReturn = pdTRUE;
|
||||
}
|
||||
}
|
||||
portBASE_TYPE_EXIT_CRITICAL();
|
||||
tmrBASE_TYPE_EXIT_CRITICAL();
|
||||
|
||||
traceRETURN_xTimerGetReloadMode( xReturn );
|
||||
|
||||
|
|
@ -1128,7 +1158,7 @@
|
|||
/* Check that the list from which active timers are referenced, and the
|
||||
* queue used to communicate with the timer service, have been
|
||||
* initialised. */
|
||||
taskENTER_CRITICAL();
|
||||
tmrENTER_CRITICAL();
|
||||
{
|
||||
if( xTimerQueue == NULL )
|
||||
{
|
||||
|
|
@ -1170,7 +1200,7 @@
|
|||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
tmrEXIT_CRITICAL();
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
|
@ -1184,7 +1214,7 @@
|
|||
configASSERT( xTimer );
|
||||
|
||||
/* Is the timer in the list of active timers? */
|
||||
portBASE_TYPE_ENTER_CRITICAL();
|
||||
tmrBASE_TYPE_ENTER_CRITICAL();
|
||||
{
|
||||
if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0U )
|
||||
{
|
||||
|
|
@ -1195,7 +1225,7 @@
|
|||
xReturn = pdTRUE;
|
||||
}
|
||||
}
|
||||
portBASE_TYPE_EXIT_CRITICAL();
|
||||
tmrBASE_TYPE_EXIT_CRITICAL();
|
||||
|
||||
traceRETURN_xTimerIsTimerActive( xReturn );
|
||||
|
||||
|
|
@ -1212,11 +1242,11 @@
|
|||
|
||||
configASSERT( xTimer );
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
tmrENTER_CRITICAL();
|
||||
{
|
||||
pvReturn = pxTimer->pvTimerID;
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
tmrEXIT_CRITICAL();
|
||||
|
||||
traceRETURN_pvTimerGetTimerID( pvReturn );
|
||||
|
||||
|
|
@ -1233,11 +1263,11 @@
|
|||
|
||||
configASSERT( xTimer );
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
tmrENTER_CRITICAL();
|
||||
{
|
||||
pxTimer->pvTimerID = pvNewID;
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
tmrEXIT_CRITICAL();
|
||||
|
||||
traceRETURN_vTimerSetTimerID();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue