stm32/samv7: Update SysTick drivers to new up_adjtime() API.

This commit is contained in:
Petteri Aimonen 2023-11-14 13:58:12 +02:00 committed by Xiang Xiao
parent 1825f9534c
commit 6dabcd567e
2 changed files with 26 additions and 77 deletions

View file

@ -64,7 +64,8 @@
* will fit in the reload register.
*/
#if SYSTICK_RELOAD > 0x00ffffff
#define SYSTICK_MAX 0x00ffffff
#if SYSTICK_RELOAD > SYSTICK_MAX
# error SYSTICK_RELOAD exceeds the range of the RELOAD register
#endif
@ -93,67 +94,41 @@ static int sam_timerisr(int irq, uint32_t *regs, void *arg)
* Public Functions
****************************************************************************/
#ifdef CONFIG_CLOCK_ADJTIME
/****************************************************************************
* Function: up_adj_timer_period
* Function: up_adjtime
*
* Description:
* Adjusts timer period. This call is used when adjusting timer period as
* defined in adjtime() function.
*
* Input Parameters:
* period_inc_usec - period adjustment in usec (reset to default value
* if 0)
* ppb - Adjustment in parts per billion (nanoseconds per second).
* Zero is default rate, positive value makes clock run faster
* and negative value slower.
*
* Assumptions:
* Called from within critical section or interrupt context.
****************************************************************************/
void up_adj_timer_period(long long period_inc_usec)
#ifdef CONFIG_CLOCK_ADJTIME
void up_adjtime(long ppb)
{
uint32_t period;
long long period_inc;
uint32_t period = SYSTICK_RELOAD;
if (period_inc_usec == 0)
if (ppb != 0)
{
period_inc = 0;
period -= (long long)ppb * SYSTICK_RELOAD / 1000000000;
}
else
{
period_inc = (SAM_SYSTICK_CLOCK / 1000000) * period_inc_usec - 1;
}
period = SYSTICK_RELOAD + period_inc;
/* Check whether period is at maximum value. */
if (period > 0x00ffffff)
if (period > SYSTICK_MAX)
{
period = 0x00ffffff;
period = SYSTICK_MAX;
}
putreg32(period, NVIC_SYSTICK_RELOAD);
}
/****************************************************************************
* Function: up_get_timer_period
*
* Description:
* This function returns the timer period in usec.
*
* Input Parameters:
* period_usec - returned timer period in usec
*
****************************************************************************/
void up_get_timer_period(long long *period_usec)
{
uint32_t period;
period = getreg32(NVIC_SYSTICK_RELOAD);
*period_usec = ((period + 1) / (SAM_SYSTICK_CLOCK / 1000000));
}
#endif
/****************************************************************************

View file

@ -101,36 +101,31 @@ static int stm32_timerisr(int irq, uint32_t *regs, void *arg)
* Public Functions
****************************************************************************/
#ifdef CONFIG_CLOCK_ADJTIME
/****************************************************************************
* Function: up_adj_timer_period
* Function: up_adjtime
*
* Description:
* Adjusts timer period. This call is used when adjusting timer period as
* defined in adjtime() function.
*
* Input Parameters:
* period_inc_usec - period adjustment in usec (reset to default value
* if 0)
* ppb - Adjustment in parts per billion (nanoseconds per second).
* Zero is default rate, positive value makes clock run faster
* and negative value slower.
*
* Assumptions:
* Called from within critical section or interrupt context.
****************************************************************************/
void up_adj_timer_period(long long period_inc_usec)
#ifdef CONFIG_CLOCK_ADJTIME
void up_adjtime(long ppb)
{
uint32_t period;
long long period_inc;
uint32_t period = SYSTICK_RELOAD;
if (period_inc_usec == 0)
if (ppb != 0)
{
period_inc = 0;
period -= (long long)ppb * SYSTICK_RELOAD / 1000000000;
}
else
{
period_inc = (SYSTICK_CLOCK / 1000000) * period_inc_usec - 1;
}
period = SYSTICK_RELOAD + period_inc;
/* Check whether period is at maximum value. */
@ -141,27 +136,6 @@ void up_adj_timer_period(long long period_inc_usec)
putreg32(period, NVIC_SYSTICK_RELOAD);
}
/****************************************************************************
* Function: up_get_timer_period
*
* Description:
* This function returns the timer period in usec.
*
* Input Parameters:
* period_usec - returned timer period in usec
*
****************************************************************************/
void up_get_timer_period(long long *period_usec)
{
uint32_t period;
period = getreg32(NVIC_SYSTICK_RELOAD);
*period_usec = ((period + 1) / (SYSTICK_CLOCK / 1000000));
}
#endif
/****************************************************************************