mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
Update Cortex-M55 and Cortex-M85 ports (#579)
These were missed when PR #59 was merged. Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
parent
d7b712668d
commit
44e02bff31
|
@ -78,20 +78,13 @@
|
||||||
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
||||||
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
||||||
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
||||||
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_SET_BIT ( 1UL << 26UL )
|
||||||
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
||||||
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
||||||
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
||||||
#ifndef configSYSTICK_CLOCK_HZ
|
|
||||||
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
|
||||||
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* The way the SysTick is clocked is not modified in case it is not the
|
|
||||||
* same a the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 0 )
|
|
||||||
#endif
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +192,7 @@
|
||||||
* have occurred while the SysTick counter is stopped during tickless idle
|
* have occurred while the SysTick counter is stopped during tickless idle
|
||||||
* calculations.
|
* calculations.
|
||||||
*/
|
*/
|
||||||
#define portMISSED_COUNTS_FACTOR ( 45UL )
|
#define portMISSED_COUNTS_FACTOR ( 94UL )
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,6 +251,20 @@
|
||||||
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
||||||
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Let the user override the default SysTick clock rate. If defined by the
|
||||||
|
* user, this symbol must equal the SysTick clock rate when the CLK bit is 0 in the
|
||||||
|
* configuration register.
|
||||||
|
*/
|
||||||
|
#ifndef configSYSTICK_CLOCK_HZ
|
||||||
|
#define configSYSTICK_CLOCK_HZ ( configCPU_CLOCK_HZ )
|
||||||
|
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
#else
|
||||||
|
/* Select the option to clock SysTick not at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( 0 )
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Let the user override the pre-loading of the initial LR with the
|
* @brief Let the user override the pre-loading of the initial LR with the
|
||||||
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
||||||
|
@ -386,7 +393,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
#if ( configUSE_TICKLESS_IDLE == 1 )
|
#if ( configUSE_TICKLESS_IDLE == 1 )
|
||||||
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
||||||
{
|
{
|
||||||
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft;
|
||||||
TickType_t xModifiableIdleTime;
|
TickType_t xModifiableIdleTime;
|
||||||
|
|
||||||
/* Make sure the SysTick reload value does not overflow the counter. */
|
/* Make sure the SysTick reload value does not overflow the counter. */
|
||||||
|
@ -395,22 +402,6 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop the SysTick momentarily. The time the SysTick is stopped for 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
|
|
||||||
* kernel with respect to calendar time. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Calculate the reload value required to wait xExpectedIdleTime
|
|
||||||
* tick periods. -1 is used because this code will execute part way
|
|
||||||
* through one of the tick periods. */
|
|
||||||
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
|
||||||
|
|
||||||
if( ulReloadValue > ulStoppedTimerCompensation )
|
|
||||||
{
|
|
||||||
ulReloadValue -= ulStoppedTimerCompensation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
||||||
* method as that will mask interrupts that should exit sleep mode. */
|
* method as that will mask interrupts that should exit sleep mode. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
|
@ -418,26 +409,52 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* If a context switch is pending or a task is waiting for the scheduler
|
/* If a context switch is pending or a task is waiting for the scheduler
|
||||||
* to be un-suspended then abandon the low power entry. */
|
* to be unsuspended then abandon the low power entry. */
|
||||||
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
||||||
{
|
{
|
||||||
/* Restart from whatever is left in the count register to complete
|
/* Re-enable interrupts - see comments above the cpsid instruction
|
||||||
* this tick period. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
|
||||||
|
|
||||||
/* Restart SysTick. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Reset the reload register to the value required for normal tick
|
|
||||||
* periods. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
|
||||||
|
|
||||||
/* Re-enable interrupts - see comments above the cpsid instruction()
|
|
||||||
* above. */
|
* above. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Stop the SysTick momentarily. The time the SysTick is stopped for
|
||||||
|
* 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
|
||||||
|
* kernel with respect to calendar time. */
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
|
/* Use the SysTick current-value register to determine the number of
|
||||||
|
* SysTick decrements remaining until the next tick interrupt. If the
|
||||||
|
* current-value register is zero, then there are actually
|
||||||
|
* ulTimerCountsForOneTick decrements remaining, not zero, because the
|
||||||
|
* SysTick requests the interrupt when decrementing from 1 to 0. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the reload value required to wait xExpectedIdleTime
|
||||||
|
* tick periods. -1 is used because this code normally executes part
|
||||||
|
* way through the first tick period. But if the SysTick IRQ is now
|
||||||
|
* pending, then clear the IRQ, suppressing the first tick, and correct
|
||||||
|
* the reload value to reflect that the second tick period is already
|
||||||
|
* underway. The expected idle time is always at least two ticks. */
|
||||||
|
ulReloadValue = ulSysTickDecrementsLeft + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
||||||
|
|
||||||
|
if( ( portNVIC_INT_CTRL_REG & portNVIC_PEND_SYSTICK_SET_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
portNVIC_INT_CTRL_REG = portNVIC_PEND_SYSTICK_CLEAR_BIT;
|
||||||
|
ulReloadValue -= ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ulReloadValue > ulStoppedTimerCompensation )
|
||||||
|
{
|
||||||
|
ulReloadValue -= ulStoppedTimerCompensation;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the new reload value. */
|
/* Set the new reload value. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
||||||
|
|
||||||
|
@ -449,11 +466,10 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
|
||||||
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
||||||
* set its parameter to 0 to indicate that its implementation
|
* set its parameter to 0 to indicate that its implementation contains
|
||||||
* contains its own wait for interrupt or wait for event
|
* its own wait for interrupt or wait for event instruction, and so wfi
|
||||||
* instruction, and so wfi should not be executed again. However,
|
* should not be executed again. However, the original expected idle
|
||||||
* the original expected idle time variable must remain unmodified,
|
* time variable must remain unmodified, so a copy is taken. */
|
||||||
* so a copy is taken. */
|
|
||||||
xModifiableIdleTime = xExpectedIdleTime;
|
xModifiableIdleTime = xExpectedIdleTime;
|
||||||
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
||||||
|
|
||||||
|
@ -474,41 +490,37 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable interrupts again because the clock is about to be stopped
|
/* Disable interrupts again because the clock is about to be stopped
|
||||||
* and interrupts that execute while the clock is stopped will
|
* and interrupts that execute while the clock is stopped will increase
|
||||||
* increase any slippage between the time maintained by the RTOS and
|
* any slippage between the time maintained by the RTOS and calendar
|
||||||
* calendar time. */
|
* time. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
__asm volatile ( "dsb" );
|
__asm volatile ( "dsb" );
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable the SysTick clock without reading the
|
/* Disable the SysTick clock without reading the
|
||||||
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
||||||
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set.
|
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again,
|
||||||
* Again, the time the SysTick is stopped for is accounted for as
|
* the time the SysTick is stopped for is accounted for as best it can
|
||||||
* best it can be, but using the tickless mode will inevitably
|
* be, but using the tickless mode will inevitably result in some tiny
|
||||||
* result in some tiny drift of the time maintained by the kernel
|
* drift of the time maintained by the kernel with respect to calendar
|
||||||
* with respect to calendar time*/
|
* time*/
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT );
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
/* Determine if the SysTick clock has already counted to zero and
|
/* Determine whether the SysTick has already counted to zero. */
|
||||||
* been set back to the current reload value (the reload back being
|
|
||||||
* correct for the entire expected idle time) or if the SysTick is
|
|
||||||
* yet to count to zero (in which case an interrupt other than the
|
|
||||||
* SysTick must have brought the system out of sleep mode). */
|
|
||||||
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
{
|
{
|
||||||
uint32_t ulCalculatedLoadValue;
|
uint32_t ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* The tick interrupt is already pending, and the SysTick count
|
/* The tick interrupt ended the sleep (or is now pending), and
|
||||||
* reloaded with ulReloadValue. Reset the
|
* a new tick period has started. Reset portNVIC_SYSTICK_LOAD_REG
|
||||||
* portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick
|
* with whatever remains of the new tick period. */
|
||||||
* period. */
|
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
||||||
|
|
||||||
/* Don't allow a tiny value, or values that have somehow
|
/* Don't allow a tiny value, or values that have somehow
|
||||||
* underflowed because the post sleep hook did something
|
* underflowed because the post sleep hook did something
|
||||||
* that took too long. */
|
* that took too long or because the SysTick current-value register
|
||||||
if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
* is zero. */
|
||||||
|
if( ( ulCalculatedLoadValue <= ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
||||||
{
|
{
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
||||||
}
|
}
|
||||||
|
@ -516,17 +528,36 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* As the pending tick will be processed as soon as this
|
/* As the pending tick will be processed as soon as this
|
||||||
* function exits, the tick value maintained by the tick is
|
* function exits, the tick value maintained by the tick is stepped
|
||||||
* stepped forward by one less than the time spent waiting. */
|
* forward by one less than the time spent waiting. */
|
||||||
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Something other than the tick interrupt ended the sleep.
|
/* Something other than the tick interrupt ended the sleep. */
|
||||||
* Work out how long the sleep lasted rounded to complete tick
|
|
||||||
|
/* Use the SysTick current-value register to determine the
|
||||||
|
* number of SysTick decrements remaining until the expected idle
|
||||||
|
* time would have ended. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
|
/* If the SysTick is not using the core clock, the current-
|
||||||
|
* value register might still be zero here. In that case, the
|
||||||
|
* SysTick didn't load from the reload register, and there are
|
||||||
|
* ulReloadValue decrements remaining in the expected idle
|
||||||
|
* time, not zero. */
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulReloadValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* 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
|
||||||
* ticks). */
|
* ticks). */
|
||||||
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - ulSysTickDecrementsLeft;
|
||||||
|
|
||||||
/* How many complete tick periods passed while the processor
|
/* How many complete tick periods passed while the processor
|
||||||
* was waiting? */
|
* was waiting? */
|
||||||
|
@ -537,13 +568,39 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
|
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG again,
|
||||||
* again, then set portNVIC_SYSTICK_LOAD_REG back to its standard
|
* then set portNVIC_SYSTICK_LOAD_REG back to its standard value. If
|
||||||
* value. */
|
* the SysTick is not using the core clock, temporarily configure it to
|
||||||
|
* use the core clock. This configuration forces the SysTick to load
|
||||||
|
* from portNVIC_SYSTICK_LOAD_REG immediately instead of at the next
|
||||||
|
* cycle of the other clock. Then portNVIC_SYSTICK_LOAD_REG is ready
|
||||||
|
* to receive the standard value immediately. */
|
||||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
vTaskStepTick( ulCompleteTickPeriods );
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG == portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
/* 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 | portNVIC_SYSTICK_INT_BIT;
|
||||||
|
|
||||||
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
/* The partial tick period already ended. Be sure the SysTick
|
||||||
|
* counts it only once. */
|
||||||
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* Step the tick to account for any tick periods that elapsed. */
|
||||||
|
vTaskStepTick( ulCompleteTickPeriods );
|
||||||
|
|
||||||
/* Exit with interrupts enabled. */
|
/* Exit with interrupts enabled. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
|
@ -569,7 +626,7 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU
|
||||||
|
|
||||||
/* 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 | 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;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -833,6 +890,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case portSVC_FREE_SECURE_CONTEXT:
|
case portSVC_FREE_SECURE_CONTEXT:
|
||||||
|
|
||||||
/* R0 contains TCB being freed and R1 contains the secure
|
/* R0 contains TCB being freed and R1 contains the secure
|
||||||
* context handle to be freed. */
|
* context handle to be freed. */
|
||||||
ulR0 = pulCallerStackAddress[ 0 ];
|
ulR0 = pulCallerStackAddress[ 0 ];
|
||||||
|
|
|
@ -78,20 +78,13 @@
|
||||||
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
||||||
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
||||||
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
||||||
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_SET_BIT ( 1UL << 26UL )
|
||||||
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
||||||
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
||||||
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
||||||
#ifndef configSYSTICK_CLOCK_HZ
|
|
||||||
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
|
||||||
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* The way the SysTick is clocked is not modified in case it is not the
|
|
||||||
* same a the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 0 )
|
|
||||||
#endif
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +192,7 @@
|
||||||
* have occurred while the SysTick counter is stopped during tickless idle
|
* have occurred while the SysTick counter is stopped during tickless idle
|
||||||
* calculations.
|
* calculations.
|
||||||
*/
|
*/
|
||||||
#define portMISSED_COUNTS_FACTOR ( 45UL )
|
#define portMISSED_COUNTS_FACTOR ( 94UL )
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,6 +251,20 @@
|
||||||
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
||||||
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Let the user override the default SysTick clock rate. If defined by the
|
||||||
|
* user, this symbol must equal the SysTick clock rate when the CLK bit is 0 in the
|
||||||
|
* configuration register.
|
||||||
|
*/
|
||||||
|
#ifndef configSYSTICK_CLOCK_HZ
|
||||||
|
#define configSYSTICK_CLOCK_HZ ( configCPU_CLOCK_HZ )
|
||||||
|
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
#else
|
||||||
|
/* Select the option to clock SysTick not at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( 0 )
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Let the user override the pre-loading of the initial LR with the
|
* @brief Let the user override the pre-loading of the initial LR with the
|
||||||
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
||||||
|
@ -386,7 +393,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
#if ( configUSE_TICKLESS_IDLE == 1 )
|
#if ( configUSE_TICKLESS_IDLE == 1 )
|
||||||
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
||||||
{
|
{
|
||||||
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft;
|
||||||
TickType_t xModifiableIdleTime;
|
TickType_t xModifiableIdleTime;
|
||||||
|
|
||||||
/* Make sure the SysTick reload value does not overflow the counter. */
|
/* Make sure the SysTick reload value does not overflow the counter. */
|
||||||
|
@ -395,22 +402,6 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop the SysTick momentarily. The time the SysTick is stopped for 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
|
|
||||||
* kernel with respect to calendar time. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Calculate the reload value required to wait xExpectedIdleTime
|
|
||||||
* tick periods. -1 is used because this code will execute part way
|
|
||||||
* through one of the tick periods. */
|
|
||||||
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
|
||||||
|
|
||||||
if( ulReloadValue > ulStoppedTimerCompensation )
|
|
||||||
{
|
|
||||||
ulReloadValue -= ulStoppedTimerCompensation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
||||||
* method as that will mask interrupts that should exit sleep mode. */
|
* method as that will mask interrupts that should exit sleep mode. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
|
@ -418,26 +409,52 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* If a context switch is pending or a task is waiting for the scheduler
|
/* If a context switch is pending or a task is waiting for the scheduler
|
||||||
* to be un-suspended then abandon the low power entry. */
|
* to be unsuspended then abandon the low power entry. */
|
||||||
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
||||||
{
|
{
|
||||||
/* Restart from whatever is left in the count register to complete
|
/* Re-enable interrupts - see comments above the cpsid instruction
|
||||||
* this tick period. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
|
||||||
|
|
||||||
/* Restart SysTick. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Reset the reload register to the value required for normal tick
|
|
||||||
* periods. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
|
||||||
|
|
||||||
/* Re-enable interrupts - see comments above the cpsid instruction()
|
|
||||||
* above. */
|
* above. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Stop the SysTick momentarily. The time the SysTick is stopped for
|
||||||
|
* 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
|
||||||
|
* kernel with respect to calendar time. */
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
|
/* Use the SysTick current-value register to determine the number of
|
||||||
|
* SysTick decrements remaining until the next tick interrupt. If the
|
||||||
|
* current-value register is zero, then there are actually
|
||||||
|
* ulTimerCountsForOneTick decrements remaining, not zero, because the
|
||||||
|
* SysTick requests the interrupt when decrementing from 1 to 0. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the reload value required to wait xExpectedIdleTime
|
||||||
|
* tick periods. -1 is used because this code normally executes part
|
||||||
|
* way through the first tick period. But if the SysTick IRQ is now
|
||||||
|
* pending, then clear the IRQ, suppressing the first tick, and correct
|
||||||
|
* the reload value to reflect that the second tick period is already
|
||||||
|
* underway. The expected idle time is always at least two ticks. */
|
||||||
|
ulReloadValue = ulSysTickDecrementsLeft + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
||||||
|
|
||||||
|
if( ( portNVIC_INT_CTRL_REG & portNVIC_PEND_SYSTICK_SET_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
portNVIC_INT_CTRL_REG = portNVIC_PEND_SYSTICK_CLEAR_BIT;
|
||||||
|
ulReloadValue -= ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ulReloadValue > ulStoppedTimerCompensation )
|
||||||
|
{
|
||||||
|
ulReloadValue -= ulStoppedTimerCompensation;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the new reload value. */
|
/* Set the new reload value. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
||||||
|
|
||||||
|
@ -449,11 +466,10 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
|
||||||
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
||||||
* set its parameter to 0 to indicate that its implementation
|
* set its parameter to 0 to indicate that its implementation contains
|
||||||
* contains its own wait for interrupt or wait for event
|
* its own wait for interrupt or wait for event instruction, and so wfi
|
||||||
* instruction, and so wfi should not be executed again. However,
|
* should not be executed again. However, the original expected idle
|
||||||
* the original expected idle time variable must remain unmodified,
|
* time variable must remain unmodified, so a copy is taken. */
|
||||||
* so a copy is taken. */
|
|
||||||
xModifiableIdleTime = xExpectedIdleTime;
|
xModifiableIdleTime = xExpectedIdleTime;
|
||||||
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
||||||
|
|
||||||
|
@ -474,41 +490,37 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable interrupts again because the clock is about to be stopped
|
/* Disable interrupts again because the clock is about to be stopped
|
||||||
* and interrupts that execute while the clock is stopped will
|
* and interrupts that execute while the clock is stopped will increase
|
||||||
* increase any slippage between the time maintained by the RTOS and
|
* any slippage between the time maintained by the RTOS and calendar
|
||||||
* calendar time. */
|
* time. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
__asm volatile ( "dsb" );
|
__asm volatile ( "dsb" );
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable the SysTick clock without reading the
|
/* Disable the SysTick clock without reading the
|
||||||
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
||||||
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set.
|
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again,
|
||||||
* Again, the time the SysTick is stopped for is accounted for as
|
* the time the SysTick is stopped for is accounted for as best it can
|
||||||
* best it can be, but using the tickless mode will inevitably
|
* be, but using the tickless mode will inevitably result in some tiny
|
||||||
* result in some tiny drift of the time maintained by the kernel
|
* drift of the time maintained by the kernel with respect to calendar
|
||||||
* with respect to calendar time*/
|
* time*/
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT );
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
/* Determine if the SysTick clock has already counted to zero and
|
/* Determine whether the SysTick has already counted to zero. */
|
||||||
* been set back to the current reload value (the reload back being
|
|
||||||
* correct for the entire expected idle time) or if the SysTick is
|
|
||||||
* yet to count to zero (in which case an interrupt other than the
|
|
||||||
* SysTick must have brought the system out of sleep mode). */
|
|
||||||
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
{
|
{
|
||||||
uint32_t ulCalculatedLoadValue;
|
uint32_t ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* The tick interrupt is already pending, and the SysTick count
|
/* The tick interrupt ended the sleep (or is now pending), and
|
||||||
* reloaded with ulReloadValue. Reset the
|
* a new tick period has started. Reset portNVIC_SYSTICK_LOAD_REG
|
||||||
* portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick
|
* with whatever remains of the new tick period. */
|
||||||
* period. */
|
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
||||||
|
|
||||||
/* Don't allow a tiny value, or values that have somehow
|
/* Don't allow a tiny value, or values that have somehow
|
||||||
* underflowed because the post sleep hook did something
|
* underflowed because the post sleep hook did something
|
||||||
* that took too long. */
|
* that took too long or because the SysTick current-value register
|
||||||
if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
* is zero. */
|
||||||
|
if( ( ulCalculatedLoadValue <= ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
||||||
{
|
{
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
||||||
}
|
}
|
||||||
|
@ -516,17 +528,36 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* As the pending tick will be processed as soon as this
|
/* As the pending tick will be processed as soon as this
|
||||||
* function exits, the tick value maintained by the tick is
|
* function exits, the tick value maintained by the tick is stepped
|
||||||
* stepped forward by one less than the time spent waiting. */
|
* forward by one less than the time spent waiting. */
|
||||||
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Something other than the tick interrupt ended the sleep.
|
/* Something other than the tick interrupt ended the sleep. */
|
||||||
* Work out how long the sleep lasted rounded to complete tick
|
|
||||||
|
/* Use the SysTick current-value register to determine the
|
||||||
|
* number of SysTick decrements remaining until the expected idle
|
||||||
|
* time would have ended. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
|
/* If the SysTick is not using the core clock, the current-
|
||||||
|
* value register might still be zero here. In that case, the
|
||||||
|
* SysTick didn't load from the reload register, and there are
|
||||||
|
* ulReloadValue decrements remaining in the expected idle
|
||||||
|
* time, not zero. */
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulReloadValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* 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
|
||||||
* ticks). */
|
* ticks). */
|
||||||
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - ulSysTickDecrementsLeft;
|
||||||
|
|
||||||
/* How many complete tick periods passed while the processor
|
/* How many complete tick periods passed while the processor
|
||||||
* was waiting? */
|
* was waiting? */
|
||||||
|
@ -537,13 +568,39 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
|
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG again,
|
||||||
* again, then set portNVIC_SYSTICK_LOAD_REG back to its standard
|
* then set portNVIC_SYSTICK_LOAD_REG back to its standard value. If
|
||||||
* value. */
|
* the SysTick is not using the core clock, temporarily configure it to
|
||||||
|
* use the core clock. This configuration forces the SysTick to load
|
||||||
|
* from portNVIC_SYSTICK_LOAD_REG immediately instead of at the next
|
||||||
|
* cycle of the other clock. Then portNVIC_SYSTICK_LOAD_REG is ready
|
||||||
|
* to receive the standard value immediately. */
|
||||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
vTaskStepTick( ulCompleteTickPeriods );
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG == portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
/* 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 | portNVIC_SYSTICK_INT_BIT;
|
||||||
|
|
||||||
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
/* The partial tick period already ended. Be sure the SysTick
|
||||||
|
* counts it only once. */
|
||||||
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* Step the tick to account for any tick periods that elapsed. */
|
||||||
|
vTaskStepTick( ulCompleteTickPeriods );
|
||||||
|
|
||||||
/* Exit with interrupts enabled. */
|
/* Exit with interrupts enabled. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
|
@ -569,7 +626,7 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU
|
||||||
|
|
||||||
/* 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 | 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;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -833,6 +890,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case portSVC_FREE_SECURE_CONTEXT:
|
case portSVC_FREE_SECURE_CONTEXT:
|
||||||
|
|
||||||
/* R0 contains TCB being freed and R1 contains the secure
|
/* R0 contains TCB being freed and R1 contains the secure
|
||||||
* context handle to be freed. */
|
* context handle to be freed. */
|
||||||
ulR0 = pulCallerStackAddress[ 0 ];
|
ulR0 = pulCallerStackAddress[ 0 ];
|
||||||
|
|
|
@ -78,20 +78,13 @@
|
||||||
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
||||||
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
||||||
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
||||||
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_SET_BIT ( 1UL << 26UL )
|
||||||
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
||||||
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
||||||
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
||||||
#ifndef configSYSTICK_CLOCK_HZ
|
|
||||||
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
|
||||||
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* The way the SysTick is clocked is not modified in case it is not the
|
|
||||||
* same a the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 0 )
|
|
||||||
#endif
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +192,7 @@
|
||||||
* have occurred while the SysTick counter is stopped during tickless idle
|
* have occurred while the SysTick counter is stopped during tickless idle
|
||||||
* calculations.
|
* calculations.
|
||||||
*/
|
*/
|
||||||
#define portMISSED_COUNTS_FACTOR ( 45UL )
|
#define portMISSED_COUNTS_FACTOR ( 94UL )
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,6 +251,20 @@
|
||||||
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
||||||
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Let the user override the default SysTick clock rate. If defined by the
|
||||||
|
* user, this symbol must equal the SysTick clock rate when the CLK bit is 0 in the
|
||||||
|
* configuration register.
|
||||||
|
*/
|
||||||
|
#ifndef configSYSTICK_CLOCK_HZ
|
||||||
|
#define configSYSTICK_CLOCK_HZ ( configCPU_CLOCK_HZ )
|
||||||
|
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
#else
|
||||||
|
/* Select the option to clock SysTick not at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( 0 )
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Let the user override the pre-loading of the initial LR with the
|
* @brief Let the user override the pre-loading of the initial LR with the
|
||||||
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
||||||
|
@ -386,7 +393,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
#if ( configUSE_TICKLESS_IDLE == 1 )
|
#if ( configUSE_TICKLESS_IDLE == 1 )
|
||||||
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
||||||
{
|
{
|
||||||
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft;
|
||||||
TickType_t xModifiableIdleTime;
|
TickType_t xModifiableIdleTime;
|
||||||
|
|
||||||
/* Make sure the SysTick reload value does not overflow the counter. */
|
/* Make sure the SysTick reload value does not overflow the counter. */
|
||||||
|
@ -395,22 +402,6 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop the SysTick momentarily. The time the SysTick is stopped for 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
|
|
||||||
* kernel with respect to calendar time. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Calculate the reload value required to wait xExpectedIdleTime
|
|
||||||
* tick periods. -1 is used because this code will execute part way
|
|
||||||
* through one of the tick periods. */
|
|
||||||
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
|
||||||
|
|
||||||
if( ulReloadValue > ulStoppedTimerCompensation )
|
|
||||||
{
|
|
||||||
ulReloadValue -= ulStoppedTimerCompensation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
||||||
* method as that will mask interrupts that should exit sleep mode. */
|
* method as that will mask interrupts that should exit sleep mode. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
|
@ -418,26 +409,52 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* If a context switch is pending or a task is waiting for the scheduler
|
/* If a context switch is pending or a task is waiting for the scheduler
|
||||||
* to be un-suspended then abandon the low power entry. */
|
* to be unsuspended then abandon the low power entry. */
|
||||||
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
||||||
{
|
{
|
||||||
/* Restart from whatever is left in the count register to complete
|
/* Re-enable interrupts - see comments above the cpsid instruction
|
||||||
* this tick period. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
|
||||||
|
|
||||||
/* Restart SysTick. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Reset the reload register to the value required for normal tick
|
|
||||||
* periods. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
|
||||||
|
|
||||||
/* Re-enable interrupts - see comments above the cpsid instruction()
|
|
||||||
* above. */
|
* above. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Stop the SysTick momentarily. The time the SysTick is stopped for
|
||||||
|
* 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
|
||||||
|
* kernel with respect to calendar time. */
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
|
/* Use the SysTick current-value register to determine the number of
|
||||||
|
* SysTick decrements remaining until the next tick interrupt. If the
|
||||||
|
* current-value register is zero, then there are actually
|
||||||
|
* ulTimerCountsForOneTick decrements remaining, not zero, because the
|
||||||
|
* SysTick requests the interrupt when decrementing from 1 to 0. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the reload value required to wait xExpectedIdleTime
|
||||||
|
* tick periods. -1 is used because this code normally executes part
|
||||||
|
* way through the first tick period. But if the SysTick IRQ is now
|
||||||
|
* pending, then clear the IRQ, suppressing the first tick, and correct
|
||||||
|
* the reload value to reflect that the second tick period is already
|
||||||
|
* underway. The expected idle time is always at least two ticks. */
|
||||||
|
ulReloadValue = ulSysTickDecrementsLeft + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
||||||
|
|
||||||
|
if( ( portNVIC_INT_CTRL_REG & portNVIC_PEND_SYSTICK_SET_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
portNVIC_INT_CTRL_REG = portNVIC_PEND_SYSTICK_CLEAR_BIT;
|
||||||
|
ulReloadValue -= ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ulReloadValue > ulStoppedTimerCompensation )
|
||||||
|
{
|
||||||
|
ulReloadValue -= ulStoppedTimerCompensation;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the new reload value. */
|
/* Set the new reload value. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
||||||
|
|
||||||
|
@ -449,11 +466,10 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
|
||||||
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
||||||
* set its parameter to 0 to indicate that its implementation
|
* set its parameter to 0 to indicate that its implementation contains
|
||||||
* contains its own wait for interrupt or wait for event
|
* its own wait for interrupt or wait for event instruction, and so wfi
|
||||||
* instruction, and so wfi should not be executed again. However,
|
* should not be executed again. However, the original expected idle
|
||||||
* the original expected idle time variable must remain unmodified,
|
* time variable must remain unmodified, so a copy is taken. */
|
||||||
* so a copy is taken. */
|
|
||||||
xModifiableIdleTime = xExpectedIdleTime;
|
xModifiableIdleTime = xExpectedIdleTime;
|
||||||
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
||||||
|
|
||||||
|
@ -474,41 +490,37 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable interrupts again because the clock is about to be stopped
|
/* Disable interrupts again because the clock is about to be stopped
|
||||||
* and interrupts that execute while the clock is stopped will
|
* and interrupts that execute while the clock is stopped will increase
|
||||||
* increase any slippage between the time maintained by the RTOS and
|
* any slippage between the time maintained by the RTOS and calendar
|
||||||
* calendar time. */
|
* time. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
__asm volatile ( "dsb" );
|
__asm volatile ( "dsb" );
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable the SysTick clock without reading the
|
/* Disable the SysTick clock without reading the
|
||||||
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
||||||
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set.
|
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again,
|
||||||
* Again, the time the SysTick is stopped for is accounted for as
|
* the time the SysTick is stopped for is accounted for as best it can
|
||||||
* best it can be, but using the tickless mode will inevitably
|
* be, but using the tickless mode will inevitably result in some tiny
|
||||||
* result in some tiny drift of the time maintained by the kernel
|
* drift of the time maintained by the kernel with respect to calendar
|
||||||
* with respect to calendar time*/
|
* time*/
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT );
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
/* Determine if the SysTick clock has already counted to zero and
|
/* Determine whether the SysTick has already counted to zero. */
|
||||||
* been set back to the current reload value (the reload back being
|
|
||||||
* correct for the entire expected idle time) or if the SysTick is
|
|
||||||
* yet to count to zero (in which case an interrupt other than the
|
|
||||||
* SysTick must have brought the system out of sleep mode). */
|
|
||||||
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
{
|
{
|
||||||
uint32_t ulCalculatedLoadValue;
|
uint32_t ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* The tick interrupt is already pending, and the SysTick count
|
/* The tick interrupt ended the sleep (or is now pending), and
|
||||||
* reloaded with ulReloadValue. Reset the
|
* a new tick period has started. Reset portNVIC_SYSTICK_LOAD_REG
|
||||||
* portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick
|
* with whatever remains of the new tick period. */
|
||||||
* period. */
|
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
||||||
|
|
||||||
/* Don't allow a tiny value, or values that have somehow
|
/* Don't allow a tiny value, or values that have somehow
|
||||||
* underflowed because the post sleep hook did something
|
* underflowed because the post sleep hook did something
|
||||||
* that took too long. */
|
* that took too long or because the SysTick current-value register
|
||||||
if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
* is zero. */
|
||||||
|
if( ( ulCalculatedLoadValue <= ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
||||||
{
|
{
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
||||||
}
|
}
|
||||||
|
@ -516,17 +528,36 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* As the pending tick will be processed as soon as this
|
/* As the pending tick will be processed as soon as this
|
||||||
* function exits, the tick value maintained by the tick is
|
* function exits, the tick value maintained by the tick is stepped
|
||||||
* stepped forward by one less than the time spent waiting. */
|
* forward by one less than the time spent waiting. */
|
||||||
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Something other than the tick interrupt ended the sleep.
|
/* Something other than the tick interrupt ended the sleep. */
|
||||||
* Work out how long the sleep lasted rounded to complete tick
|
|
||||||
|
/* Use the SysTick current-value register to determine the
|
||||||
|
* number of SysTick decrements remaining until the expected idle
|
||||||
|
* time would have ended. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
|
/* If the SysTick is not using the core clock, the current-
|
||||||
|
* value register might still be zero here. In that case, the
|
||||||
|
* SysTick didn't load from the reload register, and there are
|
||||||
|
* ulReloadValue decrements remaining in the expected idle
|
||||||
|
* time, not zero. */
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulReloadValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* 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
|
||||||
* ticks). */
|
* ticks). */
|
||||||
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - ulSysTickDecrementsLeft;
|
||||||
|
|
||||||
/* How many complete tick periods passed while the processor
|
/* How many complete tick periods passed while the processor
|
||||||
* was waiting? */
|
* was waiting? */
|
||||||
|
@ -537,13 +568,39 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
|
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG again,
|
||||||
* again, then set portNVIC_SYSTICK_LOAD_REG back to its standard
|
* then set portNVIC_SYSTICK_LOAD_REG back to its standard value. If
|
||||||
* value. */
|
* the SysTick is not using the core clock, temporarily configure it to
|
||||||
|
* use the core clock. This configuration forces the SysTick to load
|
||||||
|
* from portNVIC_SYSTICK_LOAD_REG immediately instead of at the next
|
||||||
|
* cycle of the other clock. Then portNVIC_SYSTICK_LOAD_REG is ready
|
||||||
|
* to receive the standard value immediately. */
|
||||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
vTaskStepTick( ulCompleteTickPeriods );
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG == portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
/* 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 | portNVIC_SYSTICK_INT_BIT;
|
||||||
|
|
||||||
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
/* The partial tick period already ended. Be sure the SysTick
|
||||||
|
* counts it only once. */
|
||||||
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* Step the tick to account for any tick periods that elapsed. */
|
||||||
|
vTaskStepTick( ulCompleteTickPeriods );
|
||||||
|
|
||||||
/* Exit with interrupts enabled. */
|
/* Exit with interrupts enabled. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
|
@ -569,7 +626,7 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU
|
||||||
|
|
||||||
/* 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 | 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;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -833,6 +890,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case portSVC_FREE_SECURE_CONTEXT:
|
case portSVC_FREE_SECURE_CONTEXT:
|
||||||
|
|
||||||
/* R0 contains TCB being freed and R1 contains the secure
|
/* R0 contains TCB being freed and R1 contains the secure
|
||||||
* context handle to be freed. */
|
* context handle to be freed. */
|
||||||
ulR0 = pulCallerStackAddress[ 0 ];
|
ulR0 = pulCallerStackAddress[ 0 ];
|
||||||
|
|
|
@ -78,20 +78,13 @@
|
||||||
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
||||||
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
||||||
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
||||||
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_SET_BIT ( 1UL << 26UL )
|
||||||
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
||||||
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
||||||
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
||||||
#ifndef configSYSTICK_CLOCK_HZ
|
|
||||||
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
|
||||||
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* The way the SysTick is clocked is not modified in case it is not the
|
|
||||||
* same a the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 0 )
|
|
||||||
#endif
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +192,7 @@
|
||||||
* have occurred while the SysTick counter is stopped during tickless idle
|
* have occurred while the SysTick counter is stopped during tickless idle
|
||||||
* calculations.
|
* calculations.
|
||||||
*/
|
*/
|
||||||
#define portMISSED_COUNTS_FACTOR ( 45UL )
|
#define portMISSED_COUNTS_FACTOR ( 94UL )
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,6 +251,20 @@
|
||||||
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
||||||
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Let the user override the default SysTick clock rate. If defined by the
|
||||||
|
* user, this symbol must equal the SysTick clock rate when the CLK bit is 0 in the
|
||||||
|
* configuration register.
|
||||||
|
*/
|
||||||
|
#ifndef configSYSTICK_CLOCK_HZ
|
||||||
|
#define configSYSTICK_CLOCK_HZ ( configCPU_CLOCK_HZ )
|
||||||
|
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
#else
|
||||||
|
/* Select the option to clock SysTick not at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( 0 )
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Let the user override the pre-loading of the initial LR with the
|
* @brief Let the user override the pre-loading of the initial LR with the
|
||||||
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
||||||
|
@ -386,7 +393,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
#if ( configUSE_TICKLESS_IDLE == 1 )
|
#if ( configUSE_TICKLESS_IDLE == 1 )
|
||||||
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
||||||
{
|
{
|
||||||
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft;
|
||||||
TickType_t xModifiableIdleTime;
|
TickType_t xModifiableIdleTime;
|
||||||
|
|
||||||
/* Make sure the SysTick reload value does not overflow the counter. */
|
/* Make sure the SysTick reload value does not overflow the counter. */
|
||||||
|
@ -395,22 +402,6 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop the SysTick momentarily. The time the SysTick is stopped for 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
|
|
||||||
* kernel with respect to calendar time. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Calculate the reload value required to wait xExpectedIdleTime
|
|
||||||
* tick periods. -1 is used because this code will execute part way
|
|
||||||
* through one of the tick periods. */
|
|
||||||
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
|
||||||
|
|
||||||
if( ulReloadValue > ulStoppedTimerCompensation )
|
|
||||||
{
|
|
||||||
ulReloadValue -= ulStoppedTimerCompensation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
||||||
* method as that will mask interrupts that should exit sleep mode. */
|
* method as that will mask interrupts that should exit sleep mode. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
|
@ -418,26 +409,52 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* If a context switch is pending or a task is waiting for the scheduler
|
/* If a context switch is pending or a task is waiting for the scheduler
|
||||||
* to be un-suspended then abandon the low power entry. */
|
* to be unsuspended then abandon the low power entry. */
|
||||||
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
||||||
{
|
{
|
||||||
/* Restart from whatever is left in the count register to complete
|
/* Re-enable interrupts - see comments above the cpsid instruction
|
||||||
* this tick period. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
|
||||||
|
|
||||||
/* Restart SysTick. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Reset the reload register to the value required for normal tick
|
|
||||||
* periods. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
|
||||||
|
|
||||||
/* Re-enable interrupts - see comments above the cpsid instruction()
|
|
||||||
* above. */
|
* above. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Stop the SysTick momentarily. The time the SysTick is stopped for
|
||||||
|
* 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
|
||||||
|
* kernel with respect to calendar time. */
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
|
/* Use the SysTick current-value register to determine the number of
|
||||||
|
* SysTick decrements remaining until the next tick interrupt. If the
|
||||||
|
* current-value register is zero, then there are actually
|
||||||
|
* ulTimerCountsForOneTick decrements remaining, not zero, because the
|
||||||
|
* SysTick requests the interrupt when decrementing from 1 to 0. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the reload value required to wait xExpectedIdleTime
|
||||||
|
* tick periods. -1 is used because this code normally executes part
|
||||||
|
* way through the first tick period. But if the SysTick IRQ is now
|
||||||
|
* pending, then clear the IRQ, suppressing the first tick, and correct
|
||||||
|
* the reload value to reflect that the second tick period is already
|
||||||
|
* underway. The expected idle time is always at least two ticks. */
|
||||||
|
ulReloadValue = ulSysTickDecrementsLeft + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
||||||
|
|
||||||
|
if( ( portNVIC_INT_CTRL_REG & portNVIC_PEND_SYSTICK_SET_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
portNVIC_INT_CTRL_REG = portNVIC_PEND_SYSTICK_CLEAR_BIT;
|
||||||
|
ulReloadValue -= ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ulReloadValue > ulStoppedTimerCompensation )
|
||||||
|
{
|
||||||
|
ulReloadValue -= ulStoppedTimerCompensation;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the new reload value. */
|
/* Set the new reload value. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
||||||
|
|
||||||
|
@ -449,11 +466,10 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
|
||||||
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
||||||
* set its parameter to 0 to indicate that its implementation
|
* set its parameter to 0 to indicate that its implementation contains
|
||||||
* contains its own wait for interrupt or wait for event
|
* its own wait for interrupt or wait for event instruction, and so wfi
|
||||||
* instruction, and so wfi should not be executed again. However,
|
* should not be executed again. However, the original expected idle
|
||||||
* the original expected idle time variable must remain unmodified,
|
* time variable must remain unmodified, so a copy is taken. */
|
||||||
* so a copy is taken. */
|
|
||||||
xModifiableIdleTime = xExpectedIdleTime;
|
xModifiableIdleTime = xExpectedIdleTime;
|
||||||
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
||||||
|
|
||||||
|
@ -474,41 +490,37 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable interrupts again because the clock is about to be stopped
|
/* Disable interrupts again because the clock is about to be stopped
|
||||||
* and interrupts that execute while the clock is stopped will
|
* and interrupts that execute while the clock is stopped will increase
|
||||||
* increase any slippage between the time maintained by the RTOS and
|
* any slippage between the time maintained by the RTOS and calendar
|
||||||
* calendar time. */
|
* time. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
__asm volatile ( "dsb" );
|
__asm volatile ( "dsb" );
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable the SysTick clock without reading the
|
/* Disable the SysTick clock without reading the
|
||||||
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
||||||
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set.
|
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again,
|
||||||
* Again, the time the SysTick is stopped for is accounted for as
|
* the time the SysTick is stopped for is accounted for as best it can
|
||||||
* best it can be, but using the tickless mode will inevitably
|
* be, but using the tickless mode will inevitably result in some tiny
|
||||||
* result in some tiny drift of the time maintained by the kernel
|
* drift of the time maintained by the kernel with respect to calendar
|
||||||
* with respect to calendar time*/
|
* time*/
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT );
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
/* Determine if the SysTick clock has already counted to zero and
|
/* Determine whether the SysTick has already counted to zero. */
|
||||||
* been set back to the current reload value (the reload back being
|
|
||||||
* correct for the entire expected idle time) or if the SysTick is
|
|
||||||
* yet to count to zero (in which case an interrupt other than the
|
|
||||||
* SysTick must have brought the system out of sleep mode). */
|
|
||||||
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
{
|
{
|
||||||
uint32_t ulCalculatedLoadValue;
|
uint32_t ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* The tick interrupt is already pending, and the SysTick count
|
/* The tick interrupt ended the sleep (or is now pending), and
|
||||||
* reloaded with ulReloadValue. Reset the
|
* a new tick period has started. Reset portNVIC_SYSTICK_LOAD_REG
|
||||||
* portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick
|
* with whatever remains of the new tick period. */
|
||||||
* period. */
|
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
||||||
|
|
||||||
/* Don't allow a tiny value, or values that have somehow
|
/* Don't allow a tiny value, or values that have somehow
|
||||||
* underflowed because the post sleep hook did something
|
* underflowed because the post sleep hook did something
|
||||||
* that took too long. */
|
* that took too long or because the SysTick current-value register
|
||||||
if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
* is zero. */
|
||||||
|
if( ( ulCalculatedLoadValue <= ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
||||||
{
|
{
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
||||||
}
|
}
|
||||||
|
@ -516,17 +528,36 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* As the pending tick will be processed as soon as this
|
/* As the pending tick will be processed as soon as this
|
||||||
* function exits, the tick value maintained by the tick is
|
* function exits, the tick value maintained by the tick is stepped
|
||||||
* stepped forward by one less than the time spent waiting. */
|
* forward by one less than the time spent waiting. */
|
||||||
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Something other than the tick interrupt ended the sleep.
|
/* Something other than the tick interrupt ended the sleep. */
|
||||||
* Work out how long the sleep lasted rounded to complete tick
|
|
||||||
|
/* Use the SysTick current-value register to determine the
|
||||||
|
* number of SysTick decrements remaining until the expected idle
|
||||||
|
* time would have ended. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
|
/* If the SysTick is not using the core clock, the current-
|
||||||
|
* value register might still be zero here. In that case, the
|
||||||
|
* SysTick didn't load from the reload register, and there are
|
||||||
|
* ulReloadValue decrements remaining in the expected idle
|
||||||
|
* time, not zero. */
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulReloadValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* 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
|
||||||
* ticks). */
|
* ticks). */
|
||||||
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - ulSysTickDecrementsLeft;
|
||||||
|
|
||||||
/* How many complete tick periods passed while the processor
|
/* How many complete tick periods passed while the processor
|
||||||
* was waiting? */
|
* was waiting? */
|
||||||
|
@ -537,13 +568,39 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
|
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG again,
|
||||||
* again, then set portNVIC_SYSTICK_LOAD_REG back to its standard
|
* then set portNVIC_SYSTICK_LOAD_REG back to its standard value. If
|
||||||
* value. */
|
* the SysTick is not using the core clock, temporarily configure it to
|
||||||
|
* use the core clock. This configuration forces the SysTick to load
|
||||||
|
* from portNVIC_SYSTICK_LOAD_REG immediately instead of at the next
|
||||||
|
* cycle of the other clock. Then portNVIC_SYSTICK_LOAD_REG is ready
|
||||||
|
* to receive the standard value immediately. */
|
||||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
vTaskStepTick( ulCompleteTickPeriods );
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG == portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
/* 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 | portNVIC_SYSTICK_INT_BIT;
|
||||||
|
|
||||||
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
/* The partial tick period already ended. Be sure the SysTick
|
||||||
|
* counts it only once. */
|
||||||
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* Step the tick to account for any tick periods that elapsed. */
|
||||||
|
vTaskStepTick( ulCompleteTickPeriods );
|
||||||
|
|
||||||
/* Exit with interrupts enabled. */
|
/* Exit with interrupts enabled. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
|
@ -569,7 +626,7 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU
|
||||||
|
|
||||||
/* 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 | 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;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -833,6 +890,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case portSVC_FREE_SECURE_CONTEXT:
|
case portSVC_FREE_SECURE_CONTEXT:
|
||||||
|
|
||||||
/* R0 contains TCB being freed and R1 contains the secure
|
/* R0 contains TCB being freed and R1 contains the secure
|
||||||
* context handle to be freed. */
|
* context handle to be freed. */
|
||||||
ulR0 = pulCallerStackAddress[ 0 ];
|
ulR0 = pulCallerStackAddress[ 0 ];
|
||||||
|
|
|
@ -78,20 +78,13 @@
|
||||||
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
||||||
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
||||||
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
||||||
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_SET_BIT ( 1UL << 26UL )
|
||||||
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
||||||
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
||||||
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
||||||
#ifndef configSYSTICK_CLOCK_HZ
|
|
||||||
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
|
||||||
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* The way the SysTick is clocked is not modified in case it is not the
|
|
||||||
* same a the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 0 )
|
|
||||||
#endif
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +192,7 @@
|
||||||
* have occurred while the SysTick counter is stopped during tickless idle
|
* have occurred while the SysTick counter is stopped during tickless idle
|
||||||
* calculations.
|
* calculations.
|
||||||
*/
|
*/
|
||||||
#define portMISSED_COUNTS_FACTOR ( 45UL )
|
#define portMISSED_COUNTS_FACTOR ( 94UL )
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,6 +251,20 @@
|
||||||
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
||||||
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Let the user override the default SysTick clock rate. If defined by the
|
||||||
|
* user, this symbol must equal the SysTick clock rate when the CLK bit is 0 in the
|
||||||
|
* configuration register.
|
||||||
|
*/
|
||||||
|
#ifndef configSYSTICK_CLOCK_HZ
|
||||||
|
#define configSYSTICK_CLOCK_HZ ( configCPU_CLOCK_HZ )
|
||||||
|
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
#else
|
||||||
|
/* Select the option to clock SysTick not at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( 0 )
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Let the user override the pre-loading of the initial LR with the
|
* @brief Let the user override the pre-loading of the initial LR with the
|
||||||
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
||||||
|
@ -386,7 +393,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
#if ( configUSE_TICKLESS_IDLE == 1 )
|
#if ( configUSE_TICKLESS_IDLE == 1 )
|
||||||
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
||||||
{
|
{
|
||||||
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft;
|
||||||
TickType_t xModifiableIdleTime;
|
TickType_t xModifiableIdleTime;
|
||||||
|
|
||||||
/* Make sure the SysTick reload value does not overflow the counter. */
|
/* Make sure the SysTick reload value does not overflow the counter. */
|
||||||
|
@ -395,22 +402,6 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop the SysTick momentarily. The time the SysTick is stopped for 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
|
|
||||||
* kernel with respect to calendar time. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Calculate the reload value required to wait xExpectedIdleTime
|
|
||||||
* tick periods. -1 is used because this code will execute part way
|
|
||||||
* through one of the tick periods. */
|
|
||||||
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
|
||||||
|
|
||||||
if( ulReloadValue > ulStoppedTimerCompensation )
|
|
||||||
{
|
|
||||||
ulReloadValue -= ulStoppedTimerCompensation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
||||||
* method as that will mask interrupts that should exit sleep mode. */
|
* method as that will mask interrupts that should exit sleep mode. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
|
@ -418,26 +409,52 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* If a context switch is pending or a task is waiting for the scheduler
|
/* If a context switch is pending or a task is waiting for the scheduler
|
||||||
* to be un-suspended then abandon the low power entry. */
|
* to be unsuspended then abandon the low power entry. */
|
||||||
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
||||||
{
|
{
|
||||||
/* Restart from whatever is left in the count register to complete
|
/* Re-enable interrupts - see comments above the cpsid instruction
|
||||||
* this tick period. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
|
||||||
|
|
||||||
/* Restart SysTick. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Reset the reload register to the value required for normal tick
|
|
||||||
* periods. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
|
||||||
|
|
||||||
/* Re-enable interrupts - see comments above the cpsid instruction()
|
|
||||||
* above. */
|
* above. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Stop the SysTick momentarily. The time the SysTick is stopped for
|
||||||
|
* 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
|
||||||
|
* kernel with respect to calendar time. */
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
|
/* Use the SysTick current-value register to determine the number of
|
||||||
|
* SysTick decrements remaining until the next tick interrupt. If the
|
||||||
|
* current-value register is zero, then there are actually
|
||||||
|
* ulTimerCountsForOneTick decrements remaining, not zero, because the
|
||||||
|
* SysTick requests the interrupt when decrementing from 1 to 0. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the reload value required to wait xExpectedIdleTime
|
||||||
|
* tick periods. -1 is used because this code normally executes part
|
||||||
|
* way through the first tick period. But if the SysTick IRQ is now
|
||||||
|
* pending, then clear the IRQ, suppressing the first tick, and correct
|
||||||
|
* the reload value to reflect that the second tick period is already
|
||||||
|
* underway. The expected idle time is always at least two ticks. */
|
||||||
|
ulReloadValue = ulSysTickDecrementsLeft + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
||||||
|
|
||||||
|
if( ( portNVIC_INT_CTRL_REG & portNVIC_PEND_SYSTICK_SET_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
portNVIC_INT_CTRL_REG = portNVIC_PEND_SYSTICK_CLEAR_BIT;
|
||||||
|
ulReloadValue -= ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ulReloadValue > ulStoppedTimerCompensation )
|
||||||
|
{
|
||||||
|
ulReloadValue -= ulStoppedTimerCompensation;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the new reload value. */
|
/* Set the new reload value. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
||||||
|
|
||||||
|
@ -449,11 +466,10 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
|
||||||
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
||||||
* set its parameter to 0 to indicate that its implementation
|
* set its parameter to 0 to indicate that its implementation contains
|
||||||
* contains its own wait for interrupt or wait for event
|
* its own wait for interrupt or wait for event instruction, and so wfi
|
||||||
* instruction, and so wfi should not be executed again. However,
|
* should not be executed again. However, the original expected idle
|
||||||
* the original expected idle time variable must remain unmodified,
|
* time variable must remain unmodified, so a copy is taken. */
|
||||||
* so a copy is taken. */
|
|
||||||
xModifiableIdleTime = xExpectedIdleTime;
|
xModifiableIdleTime = xExpectedIdleTime;
|
||||||
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
||||||
|
|
||||||
|
@ -474,41 +490,37 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable interrupts again because the clock is about to be stopped
|
/* Disable interrupts again because the clock is about to be stopped
|
||||||
* and interrupts that execute while the clock is stopped will
|
* and interrupts that execute while the clock is stopped will increase
|
||||||
* increase any slippage between the time maintained by the RTOS and
|
* any slippage between the time maintained by the RTOS and calendar
|
||||||
* calendar time. */
|
* time. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
__asm volatile ( "dsb" );
|
__asm volatile ( "dsb" );
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable the SysTick clock without reading the
|
/* Disable the SysTick clock without reading the
|
||||||
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
||||||
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set.
|
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again,
|
||||||
* Again, the time the SysTick is stopped for is accounted for as
|
* the time the SysTick is stopped for is accounted for as best it can
|
||||||
* best it can be, but using the tickless mode will inevitably
|
* be, but using the tickless mode will inevitably result in some tiny
|
||||||
* result in some tiny drift of the time maintained by the kernel
|
* drift of the time maintained by the kernel with respect to calendar
|
||||||
* with respect to calendar time*/
|
* time*/
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT );
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
/* Determine if the SysTick clock has already counted to zero and
|
/* Determine whether the SysTick has already counted to zero. */
|
||||||
* been set back to the current reload value (the reload back being
|
|
||||||
* correct for the entire expected idle time) or if the SysTick is
|
|
||||||
* yet to count to zero (in which case an interrupt other than the
|
|
||||||
* SysTick must have brought the system out of sleep mode). */
|
|
||||||
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
{
|
{
|
||||||
uint32_t ulCalculatedLoadValue;
|
uint32_t ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* The tick interrupt is already pending, and the SysTick count
|
/* The tick interrupt ended the sleep (or is now pending), and
|
||||||
* reloaded with ulReloadValue. Reset the
|
* a new tick period has started. Reset portNVIC_SYSTICK_LOAD_REG
|
||||||
* portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick
|
* with whatever remains of the new tick period. */
|
||||||
* period. */
|
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
||||||
|
|
||||||
/* Don't allow a tiny value, or values that have somehow
|
/* Don't allow a tiny value, or values that have somehow
|
||||||
* underflowed because the post sleep hook did something
|
* underflowed because the post sleep hook did something
|
||||||
* that took too long. */
|
* that took too long or because the SysTick current-value register
|
||||||
if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
* is zero. */
|
||||||
|
if( ( ulCalculatedLoadValue <= ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
||||||
{
|
{
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
||||||
}
|
}
|
||||||
|
@ -516,17 +528,36 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* As the pending tick will be processed as soon as this
|
/* As the pending tick will be processed as soon as this
|
||||||
* function exits, the tick value maintained by the tick is
|
* function exits, the tick value maintained by the tick is stepped
|
||||||
* stepped forward by one less than the time spent waiting. */
|
* forward by one less than the time spent waiting. */
|
||||||
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Something other than the tick interrupt ended the sleep.
|
/* Something other than the tick interrupt ended the sleep. */
|
||||||
* Work out how long the sleep lasted rounded to complete tick
|
|
||||||
|
/* Use the SysTick current-value register to determine the
|
||||||
|
* number of SysTick decrements remaining until the expected idle
|
||||||
|
* time would have ended. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
|
/* If the SysTick is not using the core clock, the current-
|
||||||
|
* value register might still be zero here. In that case, the
|
||||||
|
* SysTick didn't load from the reload register, and there are
|
||||||
|
* ulReloadValue decrements remaining in the expected idle
|
||||||
|
* time, not zero. */
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulReloadValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* 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
|
||||||
* ticks). */
|
* ticks). */
|
||||||
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - ulSysTickDecrementsLeft;
|
||||||
|
|
||||||
/* How many complete tick periods passed while the processor
|
/* How many complete tick periods passed while the processor
|
||||||
* was waiting? */
|
* was waiting? */
|
||||||
|
@ -537,13 +568,39 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
|
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG again,
|
||||||
* again, then set portNVIC_SYSTICK_LOAD_REG back to its standard
|
* then set portNVIC_SYSTICK_LOAD_REG back to its standard value. If
|
||||||
* value. */
|
* the SysTick is not using the core clock, temporarily configure it to
|
||||||
|
* use the core clock. This configuration forces the SysTick to load
|
||||||
|
* from portNVIC_SYSTICK_LOAD_REG immediately instead of at the next
|
||||||
|
* cycle of the other clock. Then portNVIC_SYSTICK_LOAD_REG is ready
|
||||||
|
* to receive the standard value immediately. */
|
||||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
vTaskStepTick( ulCompleteTickPeriods );
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG == portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
/* 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 | portNVIC_SYSTICK_INT_BIT;
|
||||||
|
|
||||||
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
/* The partial tick period already ended. Be sure the SysTick
|
||||||
|
* counts it only once. */
|
||||||
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* Step the tick to account for any tick periods that elapsed. */
|
||||||
|
vTaskStepTick( ulCompleteTickPeriods );
|
||||||
|
|
||||||
/* Exit with interrupts enabled. */
|
/* Exit with interrupts enabled. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
|
@ -569,7 +626,7 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU
|
||||||
|
|
||||||
/* 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 | 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;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -833,6 +890,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case portSVC_FREE_SECURE_CONTEXT:
|
case portSVC_FREE_SECURE_CONTEXT:
|
||||||
|
|
||||||
/* R0 contains TCB being freed and R1 contains the secure
|
/* R0 contains TCB being freed and R1 contains the secure
|
||||||
* context handle to be freed. */
|
* context handle to be freed. */
|
||||||
ulR0 = pulCallerStackAddress[ 0 ];
|
ulR0 = pulCallerStackAddress[ 0 ];
|
||||||
|
|
|
@ -78,20 +78,13 @@
|
||||||
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
||||||
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
||||||
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
||||||
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_SET_BIT ( 1UL << 26UL )
|
||||||
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
||||||
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
||||||
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
||||||
#ifndef configSYSTICK_CLOCK_HZ
|
|
||||||
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
|
||||||
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* The way the SysTick is clocked is not modified in case it is not the
|
|
||||||
* same a the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 0 )
|
|
||||||
#endif
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +192,7 @@
|
||||||
* have occurred while the SysTick counter is stopped during tickless idle
|
* have occurred while the SysTick counter is stopped during tickless idle
|
||||||
* calculations.
|
* calculations.
|
||||||
*/
|
*/
|
||||||
#define portMISSED_COUNTS_FACTOR ( 45UL )
|
#define portMISSED_COUNTS_FACTOR ( 94UL )
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,6 +251,20 @@
|
||||||
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
||||||
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Let the user override the default SysTick clock rate. If defined by the
|
||||||
|
* user, this symbol must equal the SysTick clock rate when the CLK bit is 0 in the
|
||||||
|
* configuration register.
|
||||||
|
*/
|
||||||
|
#ifndef configSYSTICK_CLOCK_HZ
|
||||||
|
#define configSYSTICK_CLOCK_HZ ( configCPU_CLOCK_HZ )
|
||||||
|
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
#else
|
||||||
|
/* Select the option to clock SysTick not at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( 0 )
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Let the user override the pre-loading of the initial LR with the
|
* @brief Let the user override the pre-loading of the initial LR with the
|
||||||
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
||||||
|
@ -386,7 +393,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
#if ( configUSE_TICKLESS_IDLE == 1 )
|
#if ( configUSE_TICKLESS_IDLE == 1 )
|
||||||
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
||||||
{
|
{
|
||||||
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft;
|
||||||
TickType_t xModifiableIdleTime;
|
TickType_t xModifiableIdleTime;
|
||||||
|
|
||||||
/* Make sure the SysTick reload value does not overflow the counter. */
|
/* Make sure the SysTick reload value does not overflow the counter. */
|
||||||
|
@ -395,22 +402,6 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop the SysTick momentarily. The time the SysTick is stopped for 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
|
|
||||||
* kernel with respect to calendar time. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Calculate the reload value required to wait xExpectedIdleTime
|
|
||||||
* tick periods. -1 is used because this code will execute part way
|
|
||||||
* through one of the tick periods. */
|
|
||||||
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
|
||||||
|
|
||||||
if( ulReloadValue > ulStoppedTimerCompensation )
|
|
||||||
{
|
|
||||||
ulReloadValue -= ulStoppedTimerCompensation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
||||||
* method as that will mask interrupts that should exit sleep mode. */
|
* method as that will mask interrupts that should exit sleep mode. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
|
@ -418,26 +409,52 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* If a context switch is pending or a task is waiting for the scheduler
|
/* If a context switch is pending or a task is waiting for the scheduler
|
||||||
* to be un-suspended then abandon the low power entry. */
|
* to be unsuspended then abandon the low power entry. */
|
||||||
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
||||||
{
|
{
|
||||||
/* Restart from whatever is left in the count register to complete
|
/* Re-enable interrupts - see comments above the cpsid instruction
|
||||||
* this tick period. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
|
||||||
|
|
||||||
/* Restart SysTick. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Reset the reload register to the value required for normal tick
|
|
||||||
* periods. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
|
||||||
|
|
||||||
/* Re-enable interrupts - see comments above the cpsid instruction()
|
|
||||||
* above. */
|
* above. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Stop the SysTick momentarily. The time the SysTick is stopped for
|
||||||
|
* 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
|
||||||
|
* kernel with respect to calendar time. */
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
|
/* Use the SysTick current-value register to determine the number of
|
||||||
|
* SysTick decrements remaining until the next tick interrupt. If the
|
||||||
|
* current-value register is zero, then there are actually
|
||||||
|
* ulTimerCountsForOneTick decrements remaining, not zero, because the
|
||||||
|
* SysTick requests the interrupt when decrementing from 1 to 0. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the reload value required to wait xExpectedIdleTime
|
||||||
|
* tick periods. -1 is used because this code normally executes part
|
||||||
|
* way through the first tick period. But if the SysTick IRQ is now
|
||||||
|
* pending, then clear the IRQ, suppressing the first tick, and correct
|
||||||
|
* the reload value to reflect that the second tick period is already
|
||||||
|
* underway. The expected idle time is always at least two ticks. */
|
||||||
|
ulReloadValue = ulSysTickDecrementsLeft + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
||||||
|
|
||||||
|
if( ( portNVIC_INT_CTRL_REG & portNVIC_PEND_SYSTICK_SET_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
portNVIC_INT_CTRL_REG = portNVIC_PEND_SYSTICK_CLEAR_BIT;
|
||||||
|
ulReloadValue -= ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ulReloadValue > ulStoppedTimerCompensation )
|
||||||
|
{
|
||||||
|
ulReloadValue -= ulStoppedTimerCompensation;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the new reload value. */
|
/* Set the new reload value. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
||||||
|
|
||||||
|
@ -449,11 +466,10 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
|
||||||
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
||||||
* set its parameter to 0 to indicate that its implementation
|
* set its parameter to 0 to indicate that its implementation contains
|
||||||
* contains its own wait for interrupt or wait for event
|
* its own wait for interrupt or wait for event instruction, and so wfi
|
||||||
* instruction, and so wfi should not be executed again. However,
|
* should not be executed again. However, the original expected idle
|
||||||
* the original expected idle time variable must remain unmodified,
|
* time variable must remain unmodified, so a copy is taken. */
|
||||||
* so a copy is taken. */
|
|
||||||
xModifiableIdleTime = xExpectedIdleTime;
|
xModifiableIdleTime = xExpectedIdleTime;
|
||||||
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
||||||
|
|
||||||
|
@ -474,41 +490,37 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable interrupts again because the clock is about to be stopped
|
/* Disable interrupts again because the clock is about to be stopped
|
||||||
* and interrupts that execute while the clock is stopped will
|
* and interrupts that execute while the clock is stopped will increase
|
||||||
* increase any slippage between the time maintained by the RTOS and
|
* any slippage between the time maintained by the RTOS and calendar
|
||||||
* calendar time. */
|
* time. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
__asm volatile ( "dsb" );
|
__asm volatile ( "dsb" );
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable the SysTick clock without reading the
|
/* Disable the SysTick clock without reading the
|
||||||
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
||||||
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set.
|
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again,
|
||||||
* Again, the time the SysTick is stopped for is accounted for as
|
* the time the SysTick is stopped for is accounted for as best it can
|
||||||
* best it can be, but using the tickless mode will inevitably
|
* be, but using the tickless mode will inevitably result in some tiny
|
||||||
* result in some tiny drift of the time maintained by the kernel
|
* drift of the time maintained by the kernel with respect to calendar
|
||||||
* with respect to calendar time*/
|
* time*/
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT );
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
/* Determine if the SysTick clock has already counted to zero and
|
/* Determine whether the SysTick has already counted to zero. */
|
||||||
* been set back to the current reload value (the reload back being
|
|
||||||
* correct for the entire expected idle time) or if the SysTick is
|
|
||||||
* yet to count to zero (in which case an interrupt other than the
|
|
||||||
* SysTick must have brought the system out of sleep mode). */
|
|
||||||
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
{
|
{
|
||||||
uint32_t ulCalculatedLoadValue;
|
uint32_t ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* The tick interrupt is already pending, and the SysTick count
|
/* The tick interrupt ended the sleep (or is now pending), and
|
||||||
* reloaded with ulReloadValue. Reset the
|
* a new tick period has started. Reset portNVIC_SYSTICK_LOAD_REG
|
||||||
* portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick
|
* with whatever remains of the new tick period. */
|
||||||
* period. */
|
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
||||||
|
|
||||||
/* Don't allow a tiny value, or values that have somehow
|
/* Don't allow a tiny value, or values that have somehow
|
||||||
* underflowed because the post sleep hook did something
|
* underflowed because the post sleep hook did something
|
||||||
* that took too long. */
|
* that took too long or because the SysTick current-value register
|
||||||
if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
* is zero. */
|
||||||
|
if( ( ulCalculatedLoadValue <= ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
||||||
{
|
{
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
||||||
}
|
}
|
||||||
|
@ -516,17 +528,36 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* As the pending tick will be processed as soon as this
|
/* As the pending tick will be processed as soon as this
|
||||||
* function exits, the tick value maintained by the tick is
|
* function exits, the tick value maintained by the tick is stepped
|
||||||
* stepped forward by one less than the time spent waiting. */
|
* forward by one less than the time spent waiting. */
|
||||||
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Something other than the tick interrupt ended the sleep.
|
/* Something other than the tick interrupt ended the sleep. */
|
||||||
* Work out how long the sleep lasted rounded to complete tick
|
|
||||||
|
/* Use the SysTick current-value register to determine the
|
||||||
|
* number of SysTick decrements remaining until the expected idle
|
||||||
|
* time would have ended. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
|
/* If the SysTick is not using the core clock, the current-
|
||||||
|
* value register might still be zero here. In that case, the
|
||||||
|
* SysTick didn't load from the reload register, and there are
|
||||||
|
* ulReloadValue decrements remaining in the expected idle
|
||||||
|
* time, not zero. */
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulReloadValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* 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
|
||||||
* ticks). */
|
* ticks). */
|
||||||
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - ulSysTickDecrementsLeft;
|
||||||
|
|
||||||
/* How many complete tick periods passed while the processor
|
/* How many complete tick periods passed while the processor
|
||||||
* was waiting? */
|
* was waiting? */
|
||||||
|
@ -537,13 +568,39 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
|
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG again,
|
||||||
* again, then set portNVIC_SYSTICK_LOAD_REG back to its standard
|
* then set portNVIC_SYSTICK_LOAD_REG back to its standard value. If
|
||||||
* value. */
|
* the SysTick is not using the core clock, temporarily configure it to
|
||||||
|
* use the core clock. This configuration forces the SysTick to load
|
||||||
|
* from portNVIC_SYSTICK_LOAD_REG immediately instead of at the next
|
||||||
|
* cycle of the other clock. Then portNVIC_SYSTICK_LOAD_REG is ready
|
||||||
|
* to receive the standard value immediately. */
|
||||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
vTaskStepTick( ulCompleteTickPeriods );
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG == portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
/* 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 | portNVIC_SYSTICK_INT_BIT;
|
||||||
|
|
||||||
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
/* The partial tick period already ended. Be sure the SysTick
|
||||||
|
* counts it only once. */
|
||||||
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* Step the tick to account for any tick periods that elapsed. */
|
||||||
|
vTaskStepTick( ulCompleteTickPeriods );
|
||||||
|
|
||||||
/* Exit with interrupts enabled. */
|
/* Exit with interrupts enabled. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
|
@ -569,7 +626,7 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU
|
||||||
|
|
||||||
/* 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 | 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;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -833,6 +890,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case portSVC_FREE_SECURE_CONTEXT:
|
case portSVC_FREE_SECURE_CONTEXT:
|
||||||
|
|
||||||
/* R0 contains TCB being freed and R1 contains the secure
|
/* R0 contains TCB being freed and R1 contains the secure
|
||||||
* context handle to be freed. */
|
* context handle to be freed. */
|
||||||
ulR0 = pulCallerStackAddress[ 0 ];
|
ulR0 = pulCallerStackAddress[ 0 ];
|
||||||
|
|
|
@ -78,20 +78,13 @@
|
||||||
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
||||||
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
||||||
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
||||||
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_SET_BIT ( 1UL << 26UL )
|
||||||
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
||||||
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
||||||
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
||||||
#ifndef configSYSTICK_CLOCK_HZ
|
|
||||||
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
|
||||||
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* The way the SysTick is clocked is not modified in case it is not the
|
|
||||||
* same a the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 0 )
|
|
||||||
#endif
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +192,7 @@
|
||||||
* have occurred while the SysTick counter is stopped during tickless idle
|
* have occurred while the SysTick counter is stopped during tickless idle
|
||||||
* calculations.
|
* calculations.
|
||||||
*/
|
*/
|
||||||
#define portMISSED_COUNTS_FACTOR ( 45UL )
|
#define portMISSED_COUNTS_FACTOR ( 94UL )
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,6 +251,20 @@
|
||||||
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
||||||
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Let the user override the default SysTick clock rate. If defined by the
|
||||||
|
* user, this symbol must equal the SysTick clock rate when the CLK bit is 0 in the
|
||||||
|
* configuration register.
|
||||||
|
*/
|
||||||
|
#ifndef configSYSTICK_CLOCK_HZ
|
||||||
|
#define configSYSTICK_CLOCK_HZ ( configCPU_CLOCK_HZ )
|
||||||
|
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
#else
|
||||||
|
/* Select the option to clock SysTick not at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( 0 )
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Let the user override the pre-loading of the initial LR with the
|
* @brief Let the user override the pre-loading of the initial LR with the
|
||||||
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
||||||
|
@ -386,7 +393,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
#if ( configUSE_TICKLESS_IDLE == 1 )
|
#if ( configUSE_TICKLESS_IDLE == 1 )
|
||||||
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
||||||
{
|
{
|
||||||
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft;
|
||||||
TickType_t xModifiableIdleTime;
|
TickType_t xModifiableIdleTime;
|
||||||
|
|
||||||
/* Make sure the SysTick reload value does not overflow the counter. */
|
/* Make sure the SysTick reload value does not overflow the counter. */
|
||||||
|
@ -395,22 +402,6 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop the SysTick momentarily. The time the SysTick is stopped for 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
|
|
||||||
* kernel with respect to calendar time. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Calculate the reload value required to wait xExpectedIdleTime
|
|
||||||
* tick periods. -1 is used because this code will execute part way
|
|
||||||
* through one of the tick periods. */
|
|
||||||
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
|
||||||
|
|
||||||
if( ulReloadValue > ulStoppedTimerCompensation )
|
|
||||||
{
|
|
||||||
ulReloadValue -= ulStoppedTimerCompensation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
||||||
* method as that will mask interrupts that should exit sleep mode. */
|
* method as that will mask interrupts that should exit sleep mode. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
|
@ -418,26 +409,52 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* If a context switch is pending or a task is waiting for the scheduler
|
/* If a context switch is pending or a task is waiting for the scheduler
|
||||||
* to be un-suspended then abandon the low power entry. */
|
* to be unsuspended then abandon the low power entry. */
|
||||||
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
||||||
{
|
{
|
||||||
/* Restart from whatever is left in the count register to complete
|
/* Re-enable interrupts - see comments above the cpsid instruction
|
||||||
* this tick period. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
|
||||||
|
|
||||||
/* Restart SysTick. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Reset the reload register to the value required for normal tick
|
|
||||||
* periods. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
|
||||||
|
|
||||||
/* Re-enable interrupts - see comments above the cpsid instruction()
|
|
||||||
* above. */
|
* above. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Stop the SysTick momentarily. The time the SysTick is stopped for
|
||||||
|
* 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
|
||||||
|
* kernel with respect to calendar time. */
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
|
/* Use the SysTick current-value register to determine the number of
|
||||||
|
* SysTick decrements remaining until the next tick interrupt. If the
|
||||||
|
* current-value register is zero, then there are actually
|
||||||
|
* ulTimerCountsForOneTick decrements remaining, not zero, because the
|
||||||
|
* SysTick requests the interrupt when decrementing from 1 to 0. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the reload value required to wait xExpectedIdleTime
|
||||||
|
* tick periods. -1 is used because this code normally executes part
|
||||||
|
* way through the first tick period. But if the SysTick IRQ is now
|
||||||
|
* pending, then clear the IRQ, suppressing the first tick, and correct
|
||||||
|
* the reload value to reflect that the second tick period is already
|
||||||
|
* underway. The expected idle time is always at least two ticks. */
|
||||||
|
ulReloadValue = ulSysTickDecrementsLeft + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
||||||
|
|
||||||
|
if( ( portNVIC_INT_CTRL_REG & portNVIC_PEND_SYSTICK_SET_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
portNVIC_INT_CTRL_REG = portNVIC_PEND_SYSTICK_CLEAR_BIT;
|
||||||
|
ulReloadValue -= ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ulReloadValue > ulStoppedTimerCompensation )
|
||||||
|
{
|
||||||
|
ulReloadValue -= ulStoppedTimerCompensation;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the new reload value. */
|
/* Set the new reload value. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
||||||
|
|
||||||
|
@ -449,11 +466,10 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
|
||||||
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
||||||
* set its parameter to 0 to indicate that its implementation
|
* set its parameter to 0 to indicate that its implementation contains
|
||||||
* contains its own wait for interrupt or wait for event
|
* its own wait for interrupt or wait for event instruction, and so wfi
|
||||||
* instruction, and so wfi should not be executed again. However,
|
* should not be executed again. However, the original expected idle
|
||||||
* the original expected idle time variable must remain unmodified,
|
* time variable must remain unmodified, so a copy is taken. */
|
||||||
* so a copy is taken. */
|
|
||||||
xModifiableIdleTime = xExpectedIdleTime;
|
xModifiableIdleTime = xExpectedIdleTime;
|
||||||
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
||||||
|
|
||||||
|
@ -474,41 +490,37 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable interrupts again because the clock is about to be stopped
|
/* Disable interrupts again because the clock is about to be stopped
|
||||||
* and interrupts that execute while the clock is stopped will
|
* and interrupts that execute while the clock is stopped will increase
|
||||||
* increase any slippage between the time maintained by the RTOS and
|
* any slippage between the time maintained by the RTOS and calendar
|
||||||
* calendar time. */
|
* time. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
__asm volatile ( "dsb" );
|
__asm volatile ( "dsb" );
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable the SysTick clock without reading the
|
/* Disable the SysTick clock without reading the
|
||||||
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
||||||
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set.
|
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again,
|
||||||
* Again, the time the SysTick is stopped for is accounted for as
|
* the time the SysTick is stopped for is accounted for as best it can
|
||||||
* best it can be, but using the tickless mode will inevitably
|
* be, but using the tickless mode will inevitably result in some tiny
|
||||||
* result in some tiny drift of the time maintained by the kernel
|
* drift of the time maintained by the kernel with respect to calendar
|
||||||
* with respect to calendar time*/
|
* time*/
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT );
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
/* Determine if the SysTick clock has already counted to zero and
|
/* Determine whether the SysTick has already counted to zero. */
|
||||||
* been set back to the current reload value (the reload back being
|
|
||||||
* correct for the entire expected idle time) or if the SysTick is
|
|
||||||
* yet to count to zero (in which case an interrupt other than the
|
|
||||||
* SysTick must have brought the system out of sleep mode). */
|
|
||||||
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
{
|
{
|
||||||
uint32_t ulCalculatedLoadValue;
|
uint32_t ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* The tick interrupt is already pending, and the SysTick count
|
/* The tick interrupt ended the sleep (or is now pending), and
|
||||||
* reloaded with ulReloadValue. Reset the
|
* a new tick period has started. Reset portNVIC_SYSTICK_LOAD_REG
|
||||||
* portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick
|
* with whatever remains of the new tick period. */
|
||||||
* period. */
|
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
||||||
|
|
||||||
/* Don't allow a tiny value, or values that have somehow
|
/* Don't allow a tiny value, or values that have somehow
|
||||||
* underflowed because the post sleep hook did something
|
* underflowed because the post sleep hook did something
|
||||||
* that took too long. */
|
* that took too long or because the SysTick current-value register
|
||||||
if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
* is zero. */
|
||||||
|
if( ( ulCalculatedLoadValue <= ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
||||||
{
|
{
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
||||||
}
|
}
|
||||||
|
@ -516,17 +528,36 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* As the pending tick will be processed as soon as this
|
/* As the pending tick will be processed as soon as this
|
||||||
* function exits, the tick value maintained by the tick is
|
* function exits, the tick value maintained by the tick is stepped
|
||||||
* stepped forward by one less than the time spent waiting. */
|
* forward by one less than the time spent waiting. */
|
||||||
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Something other than the tick interrupt ended the sleep.
|
/* Something other than the tick interrupt ended the sleep. */
|
||||||
* Work out how long the sleep lasted rounded to complete tick
|
|
||||||
|
/* Use the SysTick current-value register to determine the
|
||||||
|
* number of SysTick decrements remaining until the expected idle
|
||||||
|
* time would have ended. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
|
/* If the SysTick is not using the core clock, the current-
|
||||||
|
* value register might still be zero here. In that case, the
|
||||||
|
* SysTick didn't load from the reload register, and there are
|
||||||
|
* ulReloadValue decrements remaining in the expected idle
|
||||||
|
* time, not zero. */
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulReloadValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* 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
|
||||||
* ticks). */
|
* ticks). */
|
||||||
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - ulSysTickDecrementsLeft;
|
||||||
|
|
||||||
/* How many complete tick periods passed while the processor
|
/* How many complete tick periods passed while the processor
|
||||||
* was waiting? */
|
* was waiting? */
|
||||||
|
@ -537,13 +568,39 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
|
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG again,
|
||||||
* again, then set portNVIC_SYSTICK_LOAD_REG back to its standard
|
* then set portNVIC_SYSTICK_LOAD_REG back to its standard value. If
|
||||||
* value. */
|
* the SysTick is not using the core clock, temporarily configure it to
|
||||||
|
* use the core clock. This configuration forces the SysTick to load
|
||||||
|
* from portNVIC_SYSTICK_LOAD_REG immediately instead of at the next
|
||||||
|
* cycle of the other clock. Then portNVIC_SYSTICK_LOAD_REG is ready
|
||||||
|
* to receive the standard value immediately. */
|
||||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
vTaskStepTick( ulCompleteTickPeriods );
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG == portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
/* 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 | portNVIC_SYSTICK_INT_BIT;
|
||||||
|
|
||||||
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
/* The partial tick period already ended. Be sure the SysTick
|
||||||
|
* counts it only once. */
|
||||||
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* Step the tick to account for any tick periods that elapsed. */
|
||||||
|
vTaskStepTick( ulCompleteTickPeriods );
|
||||||
|
|
||||||
/* Exit with interrupts enabled. */
|
/* Exit with interrupts enabled. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
|
@ -569,7 +626,7 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU
|
||||||
|
|
||||||
/* 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 | 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;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -833,6 +890,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case portSVC_FREE_SECURE_CONTEXT:
|
case portSVC_FREE_SECURE_CONTEXT:
|
||||||
|
|
||||||
/* R0 contains TCB being freed and R1 contains the secure
|
/* R0 contains TCB being freed and R1 contains the secure
|
||||||
* context handle to be freed. */
|
* context handle to be freed. */
|
||||||
ulR0 = pulCallerStackAddress[ 0 ];
|
ulR0 = pulCallerStackAddress[ 0 ];
|
||||||
|
|
|
@ -78,20 +78,13 @@
|
||||||
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
|
||||||
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
|
||||||
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
||||||
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL )
|
||||||
|
#define portNVIC_PEND_SYSTICK_SET_BIT ( 1UL << 26UL )
|
||||||
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
|
||||||
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
|
||||||
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
|
||||||
#ifndef configSYSTICK_CLOCK_HZ
|
|
||||||
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
|
|
||||||
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* The way the SysTick is clocked is not modified in case it is not the
|
|
||||||
* same a the core. */
|
|
||||||
#define portNVIC_SYSTICK_CLK_BIT ( 0 )
|
|
||||||
#endif
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +192,7 @@
|
||||||
* have occurred while the SysTick counter is stopped during tickless idle
|
* have occurred while the SysTick counter is stopped during tickless idle
|
||||||
* calculations.
|
* calculations.
|
||||||
*/
|
*/
|
||||||
#define portMISSED_COUNTS_FACTOR ( 45UL )
|
#define portMISSED_COUNTS_FACTOR ( 94UL )
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,6 +251,20 @@
|
||||||
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
#define portINITIAL_CONTROL_UNPRIVILEGED ( 0x3 )
|
||||||
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
#define portINITIAL_CONTROL_PRIVILEGED ( 0x2 )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Let the user override the default SysTick clock rate. If defined by the
|
||||||
|
* user, this symbol must equal the SysTick clock rate when the CLK bit is 0 in the
|
||||||
|
* configuration register.
|
||||||
|
*/
|
||||||
|
#ifndef configSYSTICK_CLOCK_HZ
|
||||||
|
#define configSYSTICK_CLOCK_HZ ( configCPU_CLOCK_HZ )
|
||||||
|
/* Ensure the SysTick is clocked at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
#else
|
||||||
|
/* Select the option to clock SysTick not at the same frequency as the core. */
|
||||||
|
#define portNVIC_SYSTICK_CLK_BIT_CONFIG ( 0 )
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Let the user override the pre-loading of the initial LR with the
|
* @brief Let the user override the pre-loading of the initial LR with the
|
||||||
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
* address of prvTaskExitError() in case it messes up unwinding of the stack
|
||||||
|
@ -386,7 +393,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
#if ( configUSE_TICKLESS_IDLE == 1 )
|
#if ( configUSE_TICKLESS_IDLE == 1 )
|
||||||
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
||||||
{
|
{
|
||||||
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft;
|
||||||
TickType_t xModifiableIdleTime;
|
TickType_t xModifiableIdleTime;
|
||||||
|
|
||||||
/* Make sure the SysTick reload value does not overflow the counter. */
|
/* Make sure the SysTick reload value does not overflow the counter. */
|
||||||
|
@ -395,22 +402,6 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop the SysTick momentarily. The time the SysTick is stopped for 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
|
|
||||||
* kernel with respect to calendar time. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Calculate the reload value required to wait xExpectedIdleTime
|
|
||||||
* tick periods. -1 is used because this code will execute part way
|
|
||||||
* through one of the tick periods. */
|
|
||||||
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
|
||||||
|
|
||||||
if( ulReloadValue > ulStoppedTimerCompensation )
|
|
||||||
{
|
|
||||||
ulReloadValue -= ulStoppedTimerCompensation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
||||||
* method as that will mask interrupts that should exit sleep mode. */
|
* method as that will mask interrupts that should exit sleep mode. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
|
@ -418,26 +409,52 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* If a context switch is pending or a task is waiting for the scheduler
|
/* If a context switch is pending or a task is waiting for the scheduler
|
||||||
* to be un-suspended then abandon the low power entry. */
|
* to be unsuspended then abandon the low power entry. */
|
||||||
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
||||||
{
|
{
|
||||||
/* Restart from whatever is left in the count register to complete
|
/* Re-enable interrupts - see comments above the cpsid instruction
|
||||||
* this tick period. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
|
||||||
|
|
||||||
/* Restart SysTick. */
|
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
|
||||||
|
|
||||||
/* Reset the reload register to the value required for normal tick
|
|
||||||
* periods. */
|
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
|
||||||
|
|
||||||
/* Re-enable interrupts - see comments above the cpsid instruction()
|
|
||||||
* above. */
|
* above. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Stop the SysTick momentarily. The time the SysTick is stopped for
|
||||||
|
* 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
|
||||||
|
* kernel with respect to calendar time. */
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
|
/* Use the SysTick current-value register to determine the number of
|
||||||
|
* SysTick decrements remaining until the next tick interrupt. If the
|
||||||
|
* current-value register is zero, then there are actually
|
||||||
|
* ulTimerCountsForOneTick decrements remaining, not zero, because the
|
||||||
|
* SysTick requests the interrupt when decrementing from 1 to 0. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the reload value required to wait xExpectedIdleTime
|
||||||
|
* tick periods. -1 is used because this code normally executes part
|
||||||
|
* way through the first tick period. But if the SysTick IRQ is now
|
||||||
|
* pending, then clear the IRQ, suppressing the first tick, and correct
|
||||||
|
* the reload value to reflect that the second tick period is already
|
||||||
|
* underway. The expected idle time is always at least two ticks. */
|
||||||
|
ulReloadValue = ulSysTickDecrementsLeft + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );
|
||||||
|
|
||||||
|
if( ( portNVIC_INT_CTRL_REG & portNVIC_PEND_SYSTICK_SET_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
portNVIC_INT_CTRL_REG = portNVIC_PEND_SYSTICK_CLEAR_BIT;
|
||||||
|
ulReloadValue -= ulTimerCountsForOneTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ulReloadValue > ulStoppedTimerCompensation )
|
||||||
|
{
|
||||||
|
ulReloadValue -= ulStoppedTimerCompensation;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the new reload value. */
|
/* Set the new reload value. */
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
||||||
|
|
||||||
|
@ -449,11 +466,10 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
|
||||||
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
||||||
* set its parameter to 0 to indicate that its implementation
|
* set its parameter to 0 to indicate that its implementation contains
|
||||||
* contains its own wait for interrupt or wait for event
|
* its own wait for interrupt or wait for event instruction, and so wfi
|
||||||
* instruction, and so wfi should not be executed again. However,
|
* should not be executed again. However, the original expected idle
|
||||||
* the original expected idle time variable must remain unmodified,
|
* time variable must remain unmodified, so a copy is taken. */
|
||||||
* so a copy is taken. */
|
|
||||||
xModifiableIdleTime = xExpectedIdleTime;
|
xModifiableIdleTime = xExpectedIdleTime;
|
||||||
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
|
||||||
|
|
||||||
|
@ -474,41 +490,37 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable interrupts again because the clock is about to be stopped
|
/* Disable interrupts again because the clock is about to be stopped
|
||||||
* and interrupts that execute while the clock is stopped will
|
* and interrupts that execute while the clock is stopped will increase
|
||||||
* increase any slippage between the time maintained by the RTOS and
|
* any slippage between the time maintained by the RTOS and calendar
|
||||||
* calendar time. */
|
* time. */
|
||||||
__asm volatile ( "cpsid i" ::: "memory" );
|
__asm volatile ( "cpsid i" ::: "memory" );
|
||||||
__asm volatile ( "dsb" );
|
__asm volatile ( "dsb" );
|
||||||
__asm volatile ( "isb" );
|
__asm volatile ( "isb" );
|
||||||
|
|
||||||
/* Disable the SysTick clock without reading the
|
/* Disable the SysTick clock without reading the
|
||||||
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
* portNVIC_SYSTICK_CTRL_REG register to ensure the
|
||||||
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set.
|
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again,
|
||||||
* Again, the time the SysTick is stopped for is accounted for as
|
* the time the SysTick is stopped for is accounted for as best it can
|
||||||
* best it can be, but using the tickless mode will inevitably
|
* be, but using the tickless mode will inevitably result in some tiny
|
||||||
* result in some tiny drift of the time maintained by the kernel
|
* drift of the time maintained by the kernel with respect to calendar
|
||||||
* with respect to calendar time*/
|
* time*/
|
||||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT );
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT );
|
||||||
|
|
||||||
/* Determine if the SysTick clock has already counted to zero and
|
/* Determine whether the SysTick has already counted to zero. */
|
||||||
* been set back to the current reload value (the reload back being
|
|
||||||
* correct for the entire expected idle time) or if the SysTick is
|
|
||||||
* yet to count to zero (in which case an interrupt other than the
|
|
||||||
* SysTick must have brought the system out of sleep mode). */
|
|
||||||
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
{
|
{
|
||||||
uint32_t ulCalculatedLoadValue;
|
uint32_t ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* The tick interrupt is already pending, and the SysTick count
|
/* The tick interrupt ended the sleep (or is now pending), and
|
||||||
* reloaded with ulReloadValue. Reset the
|
* a new tick period has started. Reset portNVIC_SYSTICK_LOAD_REG
|
||||||
* portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick
|
* with whatever remains of the new tick period. */
|
||||||
* period. */
|
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );
|
||||||
|
|
||||||
/* Don't allow a tiny value, or values that have somehow
|
/* Don't allow a tiny value, or values that have somehow
|
||||||
* underflowed because the post sleep hook did something
|
* underflowed because the post sleep hook did something
|
||||||
* that took too long. */
|
* that took too long or because the SysTick current-value register
|
||||||
if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
* is zero. */
|
||||||
|
if( ( ulCalculatedLoadValue <= ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
||||||
{
|
{
|
||||||
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
|
||||||
}
|
}
|
||||||
|
@ -516,17 +528,36 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;
|
||||||
|
|
||||||
/* As the pending tick will be processed as soon as this
|
/* As the pending tick will be processed as soon as this
|
||||||
* function exits, the tick value maintained by the tick is
|
* function exits, the tick value maintained by the tick is stepped
|
||||||
* stepped forward by one less than the time spent waiting. */
|
* forward by one less than the time spent waiting. */
|
||||||
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Something other than the tick interrupt ended the sleep.
|
/* Something other than the tick interrupt ended the sleep. */
|
||||||
* Work out how long the sleep lasted rounded to complete tick
|
|
||||||
|
/* Use the SysTick current-value register to determine the
|
||||||
|
* number of SysTick decrements remaining until the expected idle
|
||||||
|
* time would have ended. */
|
||||||
|
ulSysTickDecrementsLeft = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||||
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG != portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
|
/* If the SysTick is not using the core clock, the current-
|
||||||
|
* value register might still be zero here. In that case, the
|
||||||
|
* SysTick didn't load from the reload register, and there are
|
||||||
|
* ulReloadValue decrements remaining in the expected idle
|
||||||
|
* time, not zero. */
|
||||||
|
if( ulSysTickDecrementsLeft == 0 )
|
||||||
|
{
|
||||||
|
ulSysTickDecrementsLeft = ulReloadValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* 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
|
||||||
* ticks). */
|
* ticks). */
|
||||||
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - ulSysTickDecrementsLeft;
|
||||||
|
|
||||||
/* How many complete tick periods passed while the processor
|
/* How many complete tick periods passed while the processor
|
||||||
* was waiting? */
|
* was waiting? */
|
||||||
|
@ -537,13 +568,39 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
|
||||||
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
|
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG again,
|
||||||
* again, then set portNVIC_SYSTICK_LOAD_REG back to its standard
|
* then set portNVIC_SYSTICK_LOAD_REG back to its standard value. If
|
||||||
* value. */
|
* the SysTick is not using the core clock, temporarily configure it to
|
||||||
|
* use the core clock. This configuration forces the SysTick to load
|
||||||
|
* from portNVIC_SYSTICK_LOAD_REG immediately instead of at the next
|
||||||
|
* cycle of the other clock. Then portNVIC_SYSTICK_LOAD_REG is ready
|
||||||
|
* to receive the standard value immediately. */
|
||||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||||
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
vTaskStepTick( ulCompleteTickPeriods );
|
#if ( portNVIC_SYSTICK_CLK_BIT_CONFIG == portNVIC_SYSTICK_CLK_BIT )
|
||||||
|
{
|
||||||
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
/* 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 | portNVIC_SYSTICK_INT_BIT;
|
||||||
|
|
||||||
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||||
|
{
|
||||||
|
/* The partial tick period already ended. Be sure the SysTick
|
||||||
|
* counts it only once. */
|
||||||
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;
|
||||||
|
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
|
||||||
|
}
|
||||||
|
#endif /* portNVIC_SYSTICK_CLK_BIT_CONFIG */
|
||||||
|
|
||||||
|
/* Step the tick to account for any tick periods that elapsed. */
|
||||||
|
vTaskStepTick( ulCompleteTickPeriods );
|
||||||
|
|
||||||
/* Exit with interrupts enabled. */
|
/* Exit with interrupts enabled. */
|
||||||
__asm volatile ( "cpsie i" ::: "memory" );
|
__asm volatile ( "cpsie i" ::: "memory" );
|
||||||
|
@ -569,7 +626,7 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU
|
||||||
|
|
||||||
/* 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 | 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;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -833,6 +890,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case portSVC_FREE_SECURE_CONTEXT:
|
case portSVC_FREE_SECURE_CONTEXT:
|
||||||
|
|
||||||
/* R0 contains TCB being freed and R1 contains the secure
|
/* R0 contains TCB being freed and R1 contains the secure
|
||||||
* context handle to be freed. */
|
* context handle to be freed. */
|
||||||
ulR0 = pulCallerStackAddress[ 0 ];
|
ulR0 = pulCallerStackAddress[ 0 ];
|
||||||
|
|
Loading…
Reference in a new issue