@@ -100,11 +100,11 @@ configuration register. */
100
100
#ifndef configSYSTICK_CLOCK_HZ
101
101
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
102
102
/* Ensure the SysTick is clocked at the same frequency as the core. */
103
- #define portNVIC_SYSTICK_CLK_BIT_SETTING ( portNVIC_SYSTICK_CLK_BIT )
103
+ #define portNVIC_SYSTICK_CLK_BIT_CONFIG ( portNVIC_SYSTICK_CLK_BIT )
104
104
#else
105
105
/* Select the option to clock SysTick not at the same frequency as the core.
106
106
The clock used is often a divided version of the core clock. */
107
- #define portNVIC_SYSTICK_CLK_BIT_SETTING ( 0 )
107
+ #define portNVIC_SYSTICK_CLK_BIT_CONFIG ( 0 )
108
108
#endif
109
109
110
110
/* Let the user override the pre-loading of the initial LR with the address of
@@ -544,12 +544,13 @@ void xPortSysTickHandler( void )
544
544
is accounted for as best it can be, but using the tickless mode will
545
545
inevitably result in some tiny drift of the time maintained by the
546
546
kernel with respect to calendar time. */
547
- portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_SETTING | portNVIC_SYSTICK_INT_BIT );
547
+ portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
548
548
549
549
/* Use the SysTick current-value register to determine the number of
550
550
SysTick decrements remaining until the next tick interrupt. If the
551
551
current-value register is zero, then there are actually
552
- ulTimerCountsForOneTick decrements remaining, not zero. */
552
+ ulTimerCountsForOneTick decrements remaining, not zero, because the
553
+ SysTick requests the interrupt when counting from 1 to 0.*/
553
554
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG ;
554
555
if ( ulSysTickDecrementsLeft == 0 )
555
556
{
@@ -620,7 +621,7 @@ void xPortSysTickHandler( void )
620
621
be, but using the tickless mode will inevitably result in some tiny
621
622
drift of the time maintained by the kernel with respect to calendar
622
623
time*/
623
- portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_SETTING | portNVIC_SYSTICK_INT_BIT );
624
+ portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
624
625
625
626
/* Determine whether the SysTick has already counted to zero. */
626
627
if ( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
@@ -656,7 +657,7 @@ void xPortSysTickHandler( void )
656
657
number of SysTick decrements remaining until the expected idle
657
658
time would have ended. */
658
659
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG ;
659
- #if ( portNVIC_SYSTICK_CLK_BIT_SETTING != portNVIC_SYSTICK_CLK_BIT )
660
+ #if ( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
660
661
{
661
662
/* If the SysTick is not using the core clock, the current-
662
663
value register might still be zero here. In that case, the
@@ -667,7 +668,7 @@ void xPortSysTickHandler( void )
667
668
ulSysTickDecrementsLeft = ulReloadValue + 1UL ;
668
669
}
669
670
}
670
- #endif /* portNVIC_SYSTICK_CLK_BIT_SETTING */
671
+ #endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
671
672
672
673
/* Work out how long the sleep lasted rounded to complete tick
673
674
periods (not the ulReload value which accounted for part
@@ -693,11 +694,13 @@ void xPortSysTickHandler( void )
693
694
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL ;
694
695
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT ;
695
696
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL ;
696
- #if ( portNVIC_SYSTICK_CLK_BIT_SETTING != portNVIC_SYSTICK_CLK_BIT )
697
+ #if ( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
697
698
{
698
- portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_SETTING | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT ;
699
+ /* The temporary usage of the core clock has served its purpose,
700
+ as described above. Resume usage of the other clock. */
701
+ portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT ;
699
702
}
700
- #endif /* portNVIC_SYSTICK_CLK_BIT_SETTING */
703
+ #endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
701
704
702
705
/* Step the tick to account for any tick periods that elapsed. */
703
706
vTaskStepTick ( ulCompleteTickPeriods );
@@ -731,7 +734,7 @@ __attribute__(( weak )) void vPortSetupTimerInterrupt( void )
731
734
732
735
/* Configure SysTick to interrupt at the requested rate. */
733
736
portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL ;
734
- portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_SETTING | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );
737
+ portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );
735
738
}
736
739
/*-----------------------------------------------------------*/
737
740
0 commit comments