Skip to content

Commit

Permalink
Add configCHECK_HANDLER_INSTALLATION
Browse files Browse the repository at this point in the history
  • Loading branch information
jefftenney committed Oct 16, 2023
1 parent 5c08b83 commit fde7256
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 34 deletions.
36 changes: 20 additions & 16 deletions portable/ARMv8M/non_secure/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -1693,11 +1693,30 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO

BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
{
#if ( configCHECK_HANDLER_INSTALLATION == 1 )
{
const portISR_t * const pxVectorTable = portSCB_VTOR_REG;

/* Verify correct installation of the FreeRTOS handlers for SVCall and
* PendSV. Do not check the installation of the SysTick handler because
* the application may provide the OS tick without using the SysTick
* timer by overriding the weak function vPortSetupTimerInterrupt().
*
* Assertion failures here can be caused by incorrect installation of
* the FreeRTOS handlers. For help installing the handlers, see
* https://www.FreeRTOS.org/FAQHelp.html
*
* Systems with a configurable address for the interrupt vector table
* can also encounter assertion failures or even system faults here if
* VTOR is not set correctly to point to the application's vector table. */
configASSERT( pxVectorTable[ portVECTOR_INDEX_SVC ] == SVC_Handler );
configASSERT( pxVectorTable[ portVECTOR_INDEX_PENDSV ] == PendSV_Handler );
} /* configCHECK_HANDLER_INSTALLATION */

#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) )
{
volatile uint32_t ulImplementedPrioBits = 0;
volatile uint8_t ucMaxPriorityValue;
const portISR_t * const pxVectorTable = portSCB_VTOR_REG;

/* Determine the maximum priority from which ISR safe FreeRTOS API
* functions can be called. ISR safe functions are those that end in
Expand Down Expand Up @@ -1765,21 +1784,6 @@ BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
* register. */
ulMaxPRIGROUPValue <<= portPRIGROUP_SHIFT;
ulMaxPRIGROUPValue &= portPRIORITY_GROUP_MASK;

/* Verify correct installation of the FreeRTOS handlers for SVCall and
* PendSV. Do not check the installation of the SysTick handler because
* the application may provide the OS tick without using the SysTick
* timer by overriding the weak function vPortSetupTimerInterrupt().
*
* Assertion failures here can be caused by incorrect installation of
* the FreeRTOS handlers. For help installing the handlers, see
* https://www.FreeRTOS.org/FAQHelp.html
*
* Systems with a configurable address for the interrupt vector table
* can also encounter assertion failures or even system faults here if
* VTOR is not set correctly to point to the application's vector table. */
configASSERT( pxVectorTable[ portVECTOR_INDEX_SVC ] == SVC_Handler );
configASSERT( pxVectorTable[ portVECTOR_INDEX_PENDSV ] == PendSV_Handler );
}
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) ) */

Expand Down
14 changes: 14 additions & 0 deletions portable/ARMv8M/non_secure/portmacrocommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,20 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P
#define portEXIT_CRITICAL() vPortExitCritical()
/*-----------------------------------------------------------*/

/* Runtime Checks on Port Configuration */
#ifndef configCHECK_HANDLER_INSTALLATION
#if ( configASSERT_DEFINED == 1 )
#define configCHECK_HANDLER_INSTALLATION 1
#else
#define configCHECK_HANDLER_INSTALLATION 0
#endif
#else
#if ( configCHECK_HANDLER_INSTALLATION == 1 && configASSERT_DEFINED == 0 )
#error You must define configASSERT() when configCHECK_HANDLER_INSTALLATION is 1.
#endif
#endif
/*-----------------------------------------------------------*/

/**
* @brief Tickless idle/low power functionality.
*/
Expand Down
4 changes: 2 additions & 2 deletions portable/GCC/ARM_CM0/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void vPortStartFirstTask( void )
*/
BaseType_t xPortStartScheduler( void )
{
#if ( configASSERT_DEFINED == 1 )
#if ( configCHECK_HANDLER_INSTALLATION == 1 )
{
/* Point pxVectorTable at the interrupt vector table. Systems without
* a VTOR register provide the value zero in place of the VTOR register
Expand All @@ -259,7 +259,7 @@ BaseType_t xPortStartScheduler( void )
* VTOR is not set correctly to point to the application's vector table. */
configASSERT( pxVectorTable[ portVECTOR_INDEX_PENDSV ] == xPortPendSVHandler );
}
#endif /* configASSERT_DEFINED */
#endif /* configCHECK_HANDLER_INSTALLATION */

/* Make PendSV and SysTick the lowest priority interrupt. */
portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI;
Expand Down
14 changes: 14 additions & 0 deletions portable/GCC/ARM_CM0/portmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ extern void vClearInterruptMaskFromISR( uint32_t ulMask ) __attribute__( ( nake

/*-----------------------------------------------------------*/

/* Runtime Checks on Port Configuration */
#ifndef configCHECK_HANDLER_INSTALLATION
#if ( configASSERT_DEFINED == 1 )
#define configCHECK_HANDLER_INSTALLATION 1
#else
#define configCHECK_HANDLER_INSTALLATION 0
#endif
#else
#if ( configCHECK_HANDLER_INSTALLATION == 1 && configASSERT_DEFINED == 0 )
#error You must define configASSERT() when configCHECK_HANDLER_INSTALLATION is 1.
#endif
#endif
/*-----------------------------------------------------------*/

portFORCE_INLINE static BaseType_t xPortIsInsideInterrupt( void )
{
uint32_t ulCurrentInterrupt;
Expand Down
36 changes: 20 additions & 16 deletions portable/GCC/ARM_CM4F/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,33 @@ BaseType_t xPortStartScheduler( void )
* /source/portable/GCC/ARM_CM7/r0p1 directory. */
configASSERT( portCPUID != portCORTEX_M7_r0p1_ID );
configASSERT( portCPUID != portCORTEX_M7_r0p0_ID );

#if ( configCHECK_HANDLER_INSTALLATION == 1 )
{
const portISR_t * const pxVectorTable = portSCB_VTOR_REG;

/* Verify correct installation of the FreeRTOS handlers for SVCall and
* PendSV. Do not check the installation of the SysTick handler because
* the application may provide the OS tick without using the SysTick
* timer by overriding the weak function vPortSetupTimerInterrupt().
*
* Assertion failures here can be caused by incorrect installation of
* the FreeRTOS handlers. For help installing the handlers, see
* https://www.FreeRTOS.org/FAQHelp.html
*
* Systems with a configurable address for the interrupt vector table
* can also encounter assertion failures or even system faults here if
* VTOR is not set correctly to point to the application's vector table. */
configASSERT( pxVectorTable[ portVECTOR_INDEX_SVC ] == vPortSVCHandler );
configASSERT( pxVectorTable[ portVECTOR_INDEX_PENDSV ] == xPortPendSVHandler );
} /* configCHECK_HANDLER_INSTALLATION */

#if ( configASSERT_DEFINED == 1 )
{
volatile uint8_t ucOriginalPriority;
volatile uint32_t ulImplementedPrioBits = 0;
volatile uint8_t * const pucFirstUserPriorityRegister = ( volatile uint8_t * const ) ( portNVIC_IP_REGISTERS_OFFSET_16 + portFIRST_USER_INTERRUPT_NUMBER );
volatile uint8_t ucMaxPriorityValue;
const portISR_t * const pxVectorTable = portSCB_VTOR_REG;

/* Determine the maximum priority from which ISR safe FreeRTOS API
* functions can be called. ISR safe functions are those that end in
Expand Down Expand Up @@ -393,21 +412,6 @@ BaseType_t xPortStartScheduler( void )
/* Restore the clobbered interrupt priority register to its original
* value. */
*pucFirstUserPriorityRegister = ucOriginalPriority;

/* Verify correct installation of the FreeRTOS handlers for SVCall and
* PendSV. Do not check the installation of the SysTick handler because
* the application may provide the OS tick without using the SysTick
* timer by overriding the weak function vPortSetupTimerInterrupt().
*
* Assertion failures here can be caused by incorrect installation of
* the FreeRTOS handlers. For help installing the handlers, see
* https://www.FreeRTOS.org/FAQHelp.html
*
* Systems with a configurable address for the interrupt vector table
* can also encounter assertion failures or even system faults here if
* VTOR is not set correctly to point to the application's vector table. */
configASSERT( pxVectorTable[ portVECTOR_INDEX_SVC ] == vPortSVCHandler );
configASSERT( pxVectorTable[ portVECTOR_INDEX_PENDSV ] == xPortPendSVHandler );
}
#endif /* configASSERT_DEFINED */

Expand Down
14 changes: 14 additions & 0 deletions portable/GCC/ARM_CM4F/portmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ extern void vPortExitCritical( void );
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
/*-----------------------------------------------------------*/

/* Runtime Checks on Port Configuration */
#ifndef configCHECK_HANDLER_INSTALLATION
#if ( configASSERT_DEFINED == 1 )
#define configCHECK_HANDLER_INSTALLATION 1
#else
#define configCHECK_HANDLER_INSTALLATION 0
#endif
#else
#if ( configCHECK_HANDLER_INSTALLATION == 1 && configASSERT_DEFINED == 0 )
#error You must define configASSERT() when configCHECK_HANDLER_INSTALLATION is 1.
#endif
#endif
/*-----------------------------------------------------------*/

/* Tickless idle/low power functionality. */
#ifndef portSUPPRESS_TICKS_AND_SLEEP
extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime );
Expand Down

0 comments on commit fde7256

Please sign in to comment.