Skip to content

Commit 40d0776

Browse files
michallencAlan Carvalho de Assis
authored andcommitted
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 <[email protected]>
1 parent 360e938 commit 40d0776

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

arch/arm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ config ARCH_CHIP_SAMV7
383383
select ARCH_HAVE_SPI_CS_CONTROL
384384
select ARM_HAVE_MPU_UNIFIED
385385
select ARMV7M_HAVE_STACKCHECK
386+
select ARCH_HAVE_ADJTIME
386387
---help---
387388
Atmel SAMV7 (ARM Cortex-M7) architectures
388389

arch/arm/src/samv7/sam_timerisr.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,69 @@ static int sam_timerisr(int irq, uint32_t *regs, void *arg)
9393
* Public Functions
9494
****************************************************************************/
9595

96+
#ifdef CONFIG_CLOCK_ADJTIME
97+
98+
/****************************************************************************
99+
* Function: up_adj_timer_period
100+
*
101+
* Description:
102+
* Adjusts timer period. This call is used when adjusting timer period as
103+
* defined in adjtime() function.
104+
*
105+
* Input Parameters:
106+
* period_inc_usec - period adjustment in usec (reset to default value
107+
* if 0)
108+
*
109+
****************************************************************************/
110+
111+
void up_adj_timer_period(long long period_inc_usec)
112+
{
113+
uint32_t period;
114+
long long period_inc;
115+
116+
if (period_inc_usec == 0)
117+
{
118+
period_inc = 0;
119+
}
120+
else
121+
{
122+
period_inc = (SAM_SYSTICK_CLOCK / 1000000) * period_inc_usec - 1;
123+
}
124+
125+
period = SYSTICK_RELOAD + period_inc;
126+
127+
/* Check whether period is at maximum value. */
128+
129+
if (period > 0x00ffffff)
130+
{
131+
period = 0x00ffffff;
132+
}
133+
134+
putreg32(period, NVIC_SYSTICK_RELOAD);
135+
}
136+
137+
/****************************************************************************
138+
* Function: up_get_timer_period
139+
*
140+
* Description:
141+
* This function returns the timer period in usec.
142+
*
143+
* Input Parameters:
144+
* period_usec - returned timer period in usec
145+
*
146+
****************************************************************************/
147+
148+
void up_get_timer_period(long long *period_usec)
149+
{
150+
uint32_t period;
151+
152+
period = getreg32(NVIC_SYSTICK_RELOAD);
153+
154+
*period_usec = ((period + 1) / (SAM_SYSTICK_CLOCK / 1000000));
155+
}
156+
157+
#endif
158+
96159
/****************************************************************************
97160
* Function: up_timer_initialize
98161
*

0 commit comments

Comments
 (0)