samv7: add support for adjtime() interface

This commit adds deifiniton of get_timer_period() and adj_timer_period()
functions used by adjtime() interface.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
Michal Lenc 2023-04-24 14:38:38 +02:00 committed by Alan Carvalho de Assis
parent 360e938fa6
commit 40d07760f6
2 changed files with 64 additions and 0 deletions

View File

@ -383,6 +383,7 @@ config ARCH_CHIP_SAMV7
select ARCH_HAVE_SPI_CS_CONTROL
select ARM_HAVE_MPU_UNIFIED
select ARMV7M_HAVE_STACKCHECK
select ARCH_HAVE_ADJTIME
---help---
Atmel SAMV7 (ARM Cortex-M7) architectures

View File

@ -93,6 +93,69 @@ static int sam_timerisr(int irq, uint32_t *regs, void *arg)
* Public Functions
****************************************************************************/
#ifdef CONFIG_CLOCK_ADJTIME
/****************************************************************************
* Function: up_adj_timer_period
*
* 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)
*
****************************************************************************/
void up_adj_timer_period(long long period_inc_usec)
{
uint32_t period;
long long period_inc;
if (period_inc_usec == 0)
{
period_inc = 0;
}
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)
{
period = 0x00ffffff;
}
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
/****************************************************************************
* Function: up_timer_initialize
*