Better consistency checking in xPortSysTickHandler

* For Cortex-M ports it's crucial that the SysTick has the lowest
(logical) priority otherwise very strange things will happen when the
SysTick interrupts a critical section. Therefor a consistency check has
been added to the xPortSysTickHandler to make sure that a critical
section was not interrupted.

* Added comment in list.c to point in the right direction if the SysTick
has wrong interrupt priority. It's usually here you end up when
interrupting a critical section with the SysTick.
This commit is contained in:
Anton Lagerholm 2020-11-06 14:16:04 +01:00
parent ebbe2cf854
commit 6362bc7dcf
14 changed files with 40 additions and 0 deletions

1
list.c
View file

@ -158,6 +158,7 @@ void vListInsert( List_t * const pxList,
* 4) Using a queue or semaphore before it has been initialised or * 4) Using a queue or semaphore before it has been initialised or
* before the scheduler has been started (are interrupts firing * before the scheduler has been started (are interrupts firing
* before vTaskStartScheduler() has been called?). * before vTaskStartScheduler() has been called?).
* 5) Misconfigured SysTick priority? Must be lowest (logical) priority.
**********************************************************************/ **********************************************************************/
for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */ for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */

View file

@ -331,6 +331,9 @@ void vPortExitCritical( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -356,6 +356,9 @@ void vPortExitCritical( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -431,6 +431,9 @@ void xPortPendSVHandler( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -493,6 +493,9 @@ void xPortPendSVHandler( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -483,6 +483,9 @@ void xPortPendSVHandler( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -334,6 +334,9 @@ void vPortExitCritical( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -371,6 +371,9 @@ void vPortExitCritical( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -483,6 +483,9 @@ void vPortExitCritical( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -359,6 +359,9 @@ void vPortExitCritical( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -485,6 +485,9 @@ void xPortPendSVHandler( void ) iv IVT_INT_PendSV ics ICS_OFF
void xPortSysTickHandler( void ) iv IVT_INT_SysTick ics ICS_AUTO void xPortSysTickHandler( void ) iv IVT_INT_SysTick ics ICS_AUTO
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -424,6 +424,9 @@ __asm void xPortPendSVHandler( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -516,6 +516,9 @@ __asm void xPortPendSVHandler( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already

View file

@ -503,6 +503,9 @@ __asm void xPortPendSVHandler( void )
void xPortSysTickHandler( void ) void xPortSysTickHandler( void )
{ {
/* The SysTick is not allowed to interrupt a critical section. */
configAssert( uxCriticalNesting == 0 )
/* The SysTick runs at the lowest interrupt priority, so when this interrupt /* The SysTick runs at the lowest interrupt priority, so when this interrupt
* executes all interrupts must be unmasked. There is therefore no need to * executes all interrupts must be unmasked. There is therefore no need to
* save and then restore the interrupt mask value as its value is already * save and then restore the interrupt mask value as its value is already