Skip to content

Commit 7ffc6a7

Browse files
chinglee-iotkar-rahul-awsaggarg
authored
Add base priority get APIs (#818)
* Add base priority get APIs * Add MPU changes --------- Signed-off-by: Gaurav Aggarwal <[email protected]> Co-authored-by: kar-rahul-aws <[email protected]> Co-authored-by: Gaurav Aggarwal <[email protected]>
1 parent 631ae9e commit 7ffc6a7

File tree

6 files changed

+188
-0
lines changed

6 files changed

+188
-0
lines changed

include/FreeRTOS.h

+16
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,22 @@
17141714
#define traceRETURN_uxTaskPriorityGetFromISR( uxReturn )
17151715
#endif
17161716

1717+
#ifndef traceENTER_uxTaskBasePriorityGet
1718+
#define traceENTER_uxTaskBasePriorityGet( xTask )
1719+
#endif
1720+
1721+
#ifndef traceRETURN_uxTaskBasePriorityGet
1722+
#define traceRETURN_uxTaskBasePriorityGet( uxReturn )
1723+
#endif
1724+
1725+
#ifndef traceENTER_uxTaskBasePriorityGetFromISR
1726+
#define traceENTER_uxTaskBasePriorityGetFromISR( xTask )
1727+
#endif
1728+
1729+
#ifndef traceRETURN_uxTaskBasePriorityGetFromISR
1730+
#define traceRETURN_uxTaskBasePriorityGetFromISR( uxReturn )
1731+
#endif
1732+
17171733
#ifndef traceENTER_vTaskPrioritySet
17181734
#define traceENTER_vTaskPrioritySet( xTask, uxNewPriority )
17191735
#endif

include/mpu_prototypes.h

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ BaseType_t MPU_xTaskGetStaticBuffers( TaskHandle_t xTask,
128128
StackType_t ** ppuxStackBuffer,
129129
StaticTask_t ** ppxTaskBuffer ) PRIVILEGED_FUNCTION;
130130
UBaseType_t MPU_uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
131+
UBaseType_t MPU_uxTaskBasePriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
132+
UBaseType_t MPU_uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
131133
BaseType_t MPU_xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
132134
TaskHookFunction_t MPU_xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
133135
BaseType_t MPU_xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,

include/mpu_wrappers.h

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
#define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions
100100
#define xTaskGetStaticBuffers MPU_xTaskGetStaticBuffers
101101
#define uxTaskPriorityGetFromISR MPU_uxTaskPriorityGetFromISR
102+
#define uxTaskBasePriorityGet MPU_uxTaskBasePriorityGet
103+
#define uxTaskBasePriorityGetFromISR MPU_uxTaskBasePriorityGetFromISR
102104
#define xTaskResumeFromISR MPU_xTaskResumeFromISR
103105
#define xTaskGetApplicationTaskTagFromISR MPU_xTaskGetApplicationTaskTagFromISR
104106
#define xTaskGenericNotifyFromISR MPU_xTaskGenericNotifyFromISR

include/task.h

+31
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,37 @@ UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
10211021
*/
10221022
UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
10231023

1024+
/**
1025+
* task. h
1026+
* @code{c}
1027+
* UBaseType_t uxTaskBasePriorityGet( const TaskHandle_t xTask );
1028+
* @endcode
1029+
*
1030+
* INCLUDE_uxTaskPriorityGet and configUSE_MUTEXES must be defined as 1 for this
1031+
* function to be available. See the configuration section for more information.
1032+
*
1033+
* Obtain the base priority of any task.
1034+
*
1035+
* @param xTask Handle of the task to be queried. Passing a NULL
1036+
* handle results in the base priority of the calling task being returned.
1037+
*
1038+
* @return The base priority of xTask.
1039+
*
1040+
* \defgroup uxTaskPriorityGet uxTaskBasePriorityGet
1041+
* \ingroup TaskCtrl
1042+
*/
1043+
UBaseType_t uxTaskBasePriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1044+
1045+
/**
1046+
* task. h
1047+
* @code{c}
1048+
* UBaseType_t uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask );
1049+
* @endcode
1050+
*
1051+
* A version of uxTaskBasePriorityGet() that can be used from an ISR.
1052+
*/
1053+
UBaseType_t uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1054+
10241055
/**
10251056
* task. h
10261057
* @code{c}

portable/Common/mpu_wrappers_v2.c

+66
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,72 @@
18941894
#endif /* #if ( INCLUDE_uxTaskPriorityGet == 1 ) */
18951895
/*-----------------------------------------------------------*/
18961896

1897+
#if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) )
1898+
1899+
UBaseType_t MPU_uxTaskBasePriorityGet( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
1900+
{
1901+
UBaseType_t uxReturn = configMAX_PRIORITIES;
1902+
int32_t lIndex;
1903+
TaskHandle_t xInternalTaskHandle = NULL;
1904+
1905+
if( xTask == NULL )
1906+
{
1907+
uxReturn = uxTaskBasePriorityGet( xTask );
1908+
}
1909+
else
1910+
{
1911+
lIndex = ( int32_t ) xTask;
1912+
1913+
if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1914+
{
1915+
xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1916+
1917+
if( xInternalTaskHandle != NULL )
1918+
{
1919+
uxReturn = uxTaskBasePriorityGet( xInternalTaskHandle );
1920+
}
1921+
}
1922+
}
1923+
1924+
return uxReturn;
1925+
}
1926+
1927+
#endif /* #if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) ) */
1928+
/*-----------------------------------------------------------*/
1929+
1930+
#if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) )
1931+
1932+
UBaseType_t MPU_uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
1933+
{
1934+
UBaseType_t uxReturn = configMAX_PRIORITIES;
1935+
int32_t lIndex;
1936+
TaskHandle_t xInternalTaskHandle = NULL;
1937+
1938+
if( xTask == NULL )
1939+
{
1940+
uxReturn = uxTaskBasePriorityGetFromISR( xTask );
1941+
}
1942+
else
1943+
{
1944+
lIndex = ( int32_t ) xTask;
1945+
1946+
if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1947+
{
1948+
xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1949+
1950+
if( xInternalTaskHandle != NULL )
1951+
{
1952+
uxReturn = uxTaskBasePriorityGetFromISR( xInternalTaskHandle );
1953+
}
1954+
}
1955+
}
1956+
1957+
return uxReturn;
1958+
}
1959+
1960+
#endif /* #if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) ) */
1961+
/*-----------------------------------------------------------*/
1962+
18971963
#if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )
18981964

18991965
BaseType_t MPU_xTaskResumeFromISR( TaskHandle_t xTaskToResume ) /* PRIVILEGED_FUNCTION */

tasks.c

+71
Original file line numberDiff line numberDiff line change
@@ -2669,6 +2669,77 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
26692669
#endif /* INCLUDE_uxTaskPriorityGet */
26702670
/*-----------------------------------------------------------*/
26712671

2672+
#if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) )
2673+
2674+
UBaseType_t uxTaskBasePriorityGet( const TaskHandle_t xTask )
2675+
{
2676+
TCB_t const * pxTCB;
2677+
UBaseType_t uxReturn;
2678+
2679+
traceENTER_uxTaskBasePriorityGet( xTask );
2680+
2681+
taskENTER_CRITICAL();
2682+
{
2683+
/* If null is passed in here then it is the base priority of the task
2684+
* that called uxTaskBasePriorityGet() that is being queried. */
2685+
pxTCB = prvGetTCBFromHandle( xTask );
2686+
uxReturn = pxTCB->uxBasePriority;
2687+
}
2688+
taskEXIT_CRITICAL();
2689+
2690+
traceRETURN_uxTaskBasePriorityGet( uxReturn );
2691+
2692+
return uxReturn;
2693+
}
2694+
2695+
#endif /* #if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) ) */
2696+
/*-----------------------------------------------------------*/
2697+
2698+
#if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) )
2699+
2700+
UBaseType_t uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask )
2701+
{
2702+
TCB_t const * pxTCB;
2703+
UBaseType_t uxReturn;
2704+
UBaseType_t uxSavedInterruptStatus;
2705+
2706+
traceENTER_uxTaskBasePriorityGetFromISR( xTask );
2707+
2708+
/* RTOS ports that support interrupt nesting have the concept of a
2709+
* maximum system call (or maximum API call) interrupt priority.
2710+
* Interrupts that are above the maximum system call priority are keep
2711+
* permanently enabled, even when the RTOS kernel is in a critical section,
2712+
* but cannot make any calls to FreeRTOS API functions. If configASSERT()
2713+
* is defined in FreeRTOSConfig.h then
2714+
* portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
2715+
* failure if a FreeRTOS API function is called from an interrupt that has
2716+
* been assigned a priority above the configured maximum system call
2717+
* priority. Only FreeRTOS functions that end in FromISR can be called
2718+
* from interrupts that have been assigned a priority at or (logically)
2719+
* below the maximum system call interrupt priority. FreeRTOS maintains a
2720+
* separate interrupt safe API to ensure interrupt entry is as fast and as
2721+
* simple as possible. More information (albeit Cortex-M specific) is
2722+
* provided on the following link:
2723+
* https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
2724+
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
2725+
2726+
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
2727+
{
2728+
/* If null is passed in here then it is the base priority of the calling
2729+
* task that is being queried. */
2730+
pxTCB = prvGetTCBFromHandle( xTask );
2731+
uxReturn = pxTCB->uxBasePriority;
2732+
}
2733+
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
2734+
2735+
traceRETURN_uxTaskBasePriorityGetFromISR( uxReturn );
2736+
2737+
return uxReturn;
2738+
}
2739+
2740+
#endif /* #if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) ) */
2741+
/*-----------------------------------------------------------*/
2742+
26722743
#if ( INCLUDE_vTaskPrioritySet == 1 )
26732744

26742745
void vTaskPrioritySet( TaskHandle_t xTask,

0 commit comments

Comments
 (0)