mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-09-12 00:57:44 -04:00
Improve comments and name of preprocessor symbol
Add a note in the code comments that SysTick requests an interrupt when decrementing from 1 to 0, so that's why stopping SysTick on zero is a special case. Readers might unknowingly assume that SysTick requests an interrupt when wrapping from 0 back to the load-register value. Reconsider new "_SETTING" suffix since "_CONFIG" suffix seems more descriptive. The code relies on *both* of these preprocessor symbols: portNVIC_SYSTICK_CLK_BIT portNVIC_SYSTICK_CLK_BIT_CONFIG **new** A meaningful suffix is really helpful to distinguish the two symbols.
This commit is contained in:
parent
316b656326
commit
18222af90a
1 changed files with 14 additions and 11 deletions
|
@ -100,11 +100,11 @@ configuration register. */
|
||||||
#ifndef configSYSTICK_CLOCK_HZ
|
#ifndef configSYSTICK_CLOCK_HZ
|
||||||
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
||||||
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
||||||
#define portNVIC_SYSTICK_CLK_BIT_SETTING ( portNVIC_SYSTICK_CLK_BIT )
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( portNVIC_SYSTICK_CLK_BIT )
|
||||||
#else
|
#else
|
||||||
/* Select the option to clock SysTick not at the same frequency as the core.
|
/* Select the option to clock SysTick not at the same frequency as the core.
|
||||||
The clock used is often a divided version of the core clock. */
|
The clock used is often a divided version of the core clock. */
|
||||||
#define portNVIC_SYSTICK_CLK_BIT_SETTING ( 0 )
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( 0 )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Let the user override the pre-loading of the initial LR with the address of
|
/* Let the user override the pre-loading of the initial LR with the address of
|
||||||
|
@ -544,12 +544,13 @@ void xPortSysTickHandler( void )
|
||||||
is accounted for as best it can be, but using the tickless mode will
|
is accounted for as best it can be, but using the tickless mode will
|
||||||
inevitably result in some tiny drift of the time maintained by the
|
inevitably result in some tiny drift of the time maintained by the
|
||||||
kernel with respect to calendar time. */
|
kernel with respect to calendar time. */
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_SETTING | portNVIC_SYSTICK_INT_BIT );
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
/* Use the SysTick current-value register to determine the number of
|
/* Use the SysTick current-value register to determine the number of
|
||||||
SysTick decrements remaining until the next tick interrupt. If the
|
SysTick decrements remaining until the next tick interrupt. If the
|
||||||
current-value register is zero, then there are actually
|
current-value register is zero, then there are actually
|
||||||
ulTimerCountsForOneTick decrements remaining, not zero. */
|
ulTimerCountsForOneTick decrements remaining, not zero, because the
|
||||||
|
SysTick requests the interrupt when decrementing from 1 to 0. */
|
||||||
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
if( ulSysTickDecrementsLeft == 0 )
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
{
|
{
|
||||||
|
@ -620,7 +621,7 @@ void xPortSysTickHandler( void )
|
||||||
be, but using the tickless mode will inevitably result in some tiny
|
be, but using the tickless mode will inevitably result in some tiny
|
||||||
drift of the time maintained by the kernel with respect to calendar
|
drift of the time maintained by the kernel with respect to calendar
|
||||||
time*/
|
time*/
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_SETTING | portNVIC_SYSTICK_INT_BIT );
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
/* Determine whether the SysTick has already counted to zero. */
|
/* Determine whether the SysTick has already counted to zero. */
|
||||||
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
|
@ -656,7 +657,7 @@ void xPortSysTickHandler( void )
|
||||||
number of SysTick decrements remaining until the expected idle
|
number of SysTick decrements remaining until the expected idle
|
||||||
time would have ended. */
|
time would have ended. */
|
||||||
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
#if( portNVIC_SYSTICK_CLK_BIT_SETTING != portNVIC_SYSTICK_CLK_BIT )
|
#if( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
|
||||||
{
|
{
|
||||||
/* If the SysTick is not using the core clock, the current-
|
/* If the SysTick is not using the core clock, the current-
|
||||||
value register might still be zero here. In that case, the
|
value register might still be zero here. In that case, the
|
||||||
|
@ -667,7 +668,7 @@ void xPortSysTickHandler( void )
|
||||||
ulSysTickDecrementsLeft = ulReloadValue + 1UL;
|
ulSysTickDecrementsLeft = ulReloadValue + 1UL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* portNVIC_SYSTICK_CLK_BIT_SETTING */
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
/* Work out how long the sleep lasted rounded to complete tick
|
/* Work out how long the sleep lasted rounded to complete tick
|
||||||
periods (not the ulReload value which accounted for part
|
periods (not the ulReload value which accounted for part
|
||||||
|
@ -693,11 +694,13 @@ void xPortSysTickHandler( void )
|
||||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||||
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
#if( portNVIC_SYSTICK_CLK_BIT_SETTING != portNVIC_SYSTICK_CLK_BIT )
|
#if( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
|
||||||
{
|
{
|
||||||
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_SETTING | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
/* The temporary usage of the core clock has served its purpose,
|
||||||
|
as described above. Resume usage of the other clock. */
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
}
|
}
|
||||||
#endif /* portNVIC_SYSTICK_CLK_BIT_SETTING */
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
/* Step the tick to account for any tick periods that elapsed. */
|
/* Step the tick to account for any tick periods that elapsed. */
|
||||||
vTaskStepTick( ulCompleteTickPeriods );
|
vTaskStepTick( ulCompleteTickPeriods );
|
||||||
|
@ -731,7 +734,7 @@ __attribute__(( weak )) void vPortSetupTimerInterrupt( void )
|
||||||
|
|
||||||
/* Configure SysTick to interrupt at the requested rate. */
|
/* Configure SysTick to interrupt at the requested rate. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
|
portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_SETTING | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue