Skip to content

Commit 1c3a751

Browse files
committed
Improve comments and name of preprocessor symbol
_CONFIG suffix seems more descriptive than _SETTING as a suffix. The code relies on *both* of these preprocessor symbols: portNVIC_SYSTICK_CLK_BIT portNVIC_SYSTICK_CLK_BIT_CONFIG A meaningful suffix is really helpful to distinguish the two symbols.
1 parent 316b656 commit 1c3a751

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

portable/GCC/ARM_CM4F/port.c

+14-11
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ configuration register. */
100100
#ifndef configSYSTICK_CLOCK_HZ
101101
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
102102
/* 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 )
104104
#else
105105
/* Select the option to clock SysTick not at the same frequency as the core.
106106
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 )
108108
#endif
109109

110110
/* Let the user override the pre-loading of the initial LR with the address of
@@ -544,12 +544,13 @@ void xPortSysTickHandler( void )
544544
is accounted for as best it can be, but using the tickless mode will
545545
inevitably result in some tiny drift of the time maintained by the
546546
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 );
548548

549549
/* Use the SysTick current-value register to determine the number of
550550
SysTick decrements remaining until the next tick interrupt. If the
551551
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.*/
553554
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
554555
if( ulSysTickDecrementsLeft == 0 )
555556
{
@@ -620,7 +621,7 @@ void xPortSysTickHandler( void )
620621
be, but using the tickless mode will inevitably result in some tiny
621622
drift of the time maintained by the kernel with respect to calendar
622623
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 );
624625

625626
/* Determine whether the SysTick has already counted to zero. */
626627
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
@@ -656,7 +657,7 @@ void xPortSysTickHandler( void )
656657
number of SysTick decrements remaining until the expected idle
657658
time would have ended. */
658659
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 )
660661
{
661662
/* If the SysTick is not using the core clock, the current-
662663
value register might still be zero here. In that case, the
@@ -667,7 +668,7 @@ void xPortSysTickHandler( void )
667668
ulSysTickDecrementsLeft = ulReloadValue + 1UL;
668669
}
669670
}
670-
#endif /* portNVIC_SYSTICK_CLK_BIT_SETTING */
671+
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
671672

672673
/* Work out how long the sleep lasted rounded to complete tick
673674
periods (not the ulReload value which accounted for part
@@ -693,11 +694,13 @@ void xPortSysTickHandler( void )
693694
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
694695
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
695696
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 )
697698
{
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;
699702
}
700-
#endif /* portNVIC_SYSTICK_CLK_BIT_SETTING */
703+
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
701704

702705
/* Step the tick to account for any tick periods that elapsed. */
703706
vTaskStepTick( ulCompleteTickPeriods );
@@ -731,7 +734,7 @@ __attribute__(( weak )) void vPortSetupTimerInterrupt( void )
731734

732735
/* Configure SysTick to interrupt at the requested rate. */
733736
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 );
735738
}
736739
/*-----------------------------------------------------------*/
737740

0 commit comments

Comments
 (0)