Skip to content

Commit

Permalink
Merge branch 'main' into detect-startup-config-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jefftenney authored Oct 19, 2023
2 parents a7588dc + 4ada1d7 commit 519d77a
Show file tree
Hide file tree
Showing 7 changed files with 341 additions and 49 deletions.
14 changes: 10 additions & 4 deletions cmake_example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];

void exampleTask( void * parameters )
{
/* Unused parameters. */
( void ) parameters;

for( ; ; )
{
/* Example Task Code */
vTaskDelay( 100 ); /* delay 100 ticks */
}
}

int main( void )
void main( void )
{
printf( "Example FreeRTOS Project\n" );

Expand All @@ -71,19 +74,22 @@ int main( void )
exampleTaskStack,
&exampleTaskTCB );

/* Start the scheduler. */
vTaskStartScheduler();

/* should never get here. */
for( ; ; )
{
/* Should not reach here. */
}

return 0;
}

void vApplicationStackOverflowHook( TaskHandle_t xTask,
char * pcTaskName )
{
/* Check pcTaskName for the name of the offending task,
* or pxCurrentTCB if pcTaskName has itself been corrupted. */
( void ) xTask;
( void ) pcTaskName;
}

void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
Expand Down
16 changes: 16 additions & 0 deletions include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,22 @@
#define traceRETURN_uxTaskPriorityGetFromISR( uxReturn )
#endif

#ifndef traceENTER_uxTaskBasePriorityGet
#define traceENTER_uxTaskBasePriorityGet( xTask )
#endif

#ifndef traceRETURN_uxTaskBasePriorityGet
#define traceRETURN_uxTaskBasePriorityGet( uxReturn )
#endif

#ifndef traceENTER_uxTaskBasePriorityGetFromISR
#define traceENTER_uxTaskBasePriorityGetFromISR( xTask )
#endif

#ifndef traceRETURN_uxTaskBasePriorityGetFromISR
#define traceRETURN_uxTaskBasePriorityGetFromISR( uxReturn )
#endif

#ifndef traceENTER_vTaskPrioritySet
#define traceENTER_vTaskPrioritySet( xTask, uxNewPriority )
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/mpu_prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ BaseType_t MPU_xTaskGetStaticBuffers( TaskHandle_t xTask,
StackType_t ** ppuxStackBuffer,
StaticTask_t ** ppxTaskBuffer ) PRIVILEGED_FUNCTION;
UBaseType_t MPU_uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
UBaseType_t MPU_uxTaskBasePriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
UBaseType_t MPU_uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
BaseType_t MPU_xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
TaskHookFunction_t MPU_xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
BaseType_t MPU_xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
Expand Down
2 changes: 2 additions & 0 deletions include/mpu_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
#define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions
#define xTaskGetStaticBuffers MPU_xTaskGetStaticBuffers
#define uxTaskPriorityGetFromISR MPU_uxTaskPriorityGetFromISR
#define uxTaskBasePriorityGet MPU_uxTaskBasePriorityGet
#define uxTaskBasePriorityGetFromISR MPU_uxTaskBasePriorityGetFromISR
#define xTaskResumeFromISR MPU_xTaskResumeFromISR
#define xTaskGetApplicationTaskTagFromISR MPU_xTaskGetApplicationTaskTagFromISR
#define xTaskGenericNotifyFromISR MPU_xTaskGenericNotifyFromISR
Expand Down
31 changes: 31 additions & 0 deletions include/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,37 @@ UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
*/
UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;

/**
* task. h
* @code{c}
* UBaseType_t uxTaskBasePriorityGet( const TaskHandle_t xTask );
* @endcode
*
* INCLUDE_uxTaskPriorityGet and configUSE_MUTEXES must be defined as 1 for this
* function to be available. See the configuration section for more information.
*
* Obtain the base priority of any task.
*
* @param xTask Handle of the task to be queried. Passing a NULL
* handle results in the base priority of the calling task being returned.
*
* @return The base priority of xTask.
*
* \defgroup uxTaskPriorityGet uxTaskBasePriorityGet
* \ingroup TaskCtrl
*/
UBaseType_t uxTaskBasePriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;

/**
* task. h
* @code{c}
* UBaseType_t uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask );
* @endcode
*
* A version of uxTaskBasePriorityGet() that can be used from an ISR.
*/
UBaseType_t uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;

/**
* task. h
* @code{c}
Expand Down
107 changes: 93 additions & 14 deletions portable/Common/mpu_wrappers_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@
*/
#define CONVERT_TO_INTERNAL_INDEX( lIndex ) ( ( lIndex ) - INDEX_OFFSET )

/**
* @brief Max value that fits in a size_t type.
*/
#define mpuSIZE_MAX ( ~( ( size_t ) 0 ) )

/**
* @brief Check if multiplying a and b will result in overflow.
*/
#define mpuMULTIPLY_WILL_OVERFLOW( a, b ) ( ( ( a ) > 0 ) && ( ( b ) > ( mpuSIZE_MAX / ( a ) ) ) )

/**
* @brief Get the index of a free slot in the kernel object pool.
*
Expand Down Expand Up @@ -1035,25 +1045,28 @@
UBaseType_t uxArraySize,
configRUN_TIME_COUNTER_TYPE * pulTotalRunTime ) /* PRIVILEGED_FUNCTION */
{
UBaseType_t uxReturn = pdFALSE;
UBaseType_t uxReturn = 0;
UBaseType_t xIsTaskStatusArrayWriteable = pdFALSE;
UBaseType_t xIsTotalRunTimeWriteable = pdFALSE;

xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray,
sizeof( TaskStatus_t ) * uxArraySize,
tskMPU_WRITE_PERMISSION );

if( pulTotalRunTime != NULL )
if( mpuMULTIPLY_WILL_OVERFLOW( sizeof( TaskStatus_t ), uxArraySize ) == 0 )
{
xIsTotalRunTimeWriteable = xPortIsAuthorizedToAccessBuffer( pulTotalRunTime,
sizeof( configRUN_TIME_COUNTER_TYPE ),
tskMPU_WRITE_PERMISSION );
}
xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray,
sizeof( TaskStatus_t ) * uxArraySize,
tskMPU_WRITE_PERMISSION );

if( ( xIsTaskStatusArrayWriteable == pdTRUE ) &&
( ( pulTotalRunTime == NULL ) || ( xIsTotalRunTimeWriteable == pdTRUE ) ) )
{
uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime );
if( pulTotalRunTime != NULL )
{
xIsTotalRunTimeWriteable = xPortIsAuthorizedToAccessBuffer( pulTotalRunTime,
sizeof( configRUN_TIME_COUNTER_TYPE ),
tskMPU_WRITE_PERMISSION );
}

if( ( xIsTaskStatusArrayWriteable == pdTRUE ) &&
( ( pulTotalRunTime == NULL ) || ( xIsTotalRunTimeWriteable == pdTRUE ) ) )
{
uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime );
}
}

return uxReturn;
Expand Down Expand Up @@ -1894,6 +1907,72 @@
#endif /* #if ( INCLUDE_uxTaskPriorityGet == 1 ) */
/*-----------------------------------------------------------*/

#if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) )

UBaseType_t MPU_uxTaskBasePriorityGet( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
{
UBaseType_t uxReturn = configMAX_PRIORITIES;
int32_t lIndex;
TaskHandle_t xInternalTaskHandle = NULL;

if( xTask == NULL )
{
uxReturn = uxTaskBasePriorityGet( xTask );
}
else
{
lIndex = ( int32_t ) xTask;

if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
{
xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );

if( xInternalTaskHandle != NULL )
{
uxReturn = uxTaskBasePriorityGet( xInternalTaskHandle );
}
}
}

return uxReturn;
}

#endif /* #if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) ) */
/*-----------------------------------------------------------*/

#if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) )

UBaseType_t MPU_uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
{
UBaseType_t uxReturn = configMAX_PRIORITIES;
int32_t lIndex;
TaskHandle_t xInternalTaskHandle = NULL;

if( xTask == NULL )
{
uxReturn = uxTaskBasePriorityGetFromISR( xTask );
}
else
{
lIndex = ( int32_t ) xTask;

if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
{
xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );

if( xInternalTaskHandle != NULL )
{
uxReturn = uxTaskBasePriorityGetFromISR( xInternalTaskHandle );
}
}
}

return uxReturn;
}

#endif /* #if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) ) */
/*-----------------------------------------------------------*/

#if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )

BaseType_t MPU_xTaskResumeFromISR( TaskHandle_t xTaskToResume ) /* PRIVILEGED_FUNCTION */
Expand Down
Loading

0 comments on commit 519d77a

Please sign in to comment.