Skip to content

Commit b9f0507

Browse files
AlessandroLuokartben
authored andcommitted
drivers: timer: Add support for Apollo510 SoC system timer (STIMER)
This commit adds support for Apollo510 SoC in ambiq stimer driver Signed-off-by: Hao Luo <hluo@ambiq.com>
1 parent 1e8fb26 commit b9f0507

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

drivers/timer/ambiq_stimer.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@
2727
#define CYC_PER_TICK (sys_clock_hw_cycles_per_sec() / CONFIG_SYS_CLOCK_TICKS_PER_SEC)
2828
#define MAX_TICKS ((k_ticks_t)(COUNTER_MAX / CYC_PER_TICK) - 1)
2929
#define MAX_CYCLES (MAX_TICKS * CYC_PER_TICK)
30-
#if defined(CONFIG_SOC_SERIES_APOLLO3X)
30+
#if defined(CONFIG_SOC_SERIES_APOLLO3X) || defined(CONFIG_SOC_SERIES_APOLLO5X)
3131
#define MIN_DELAY 1
32-
#elif defined(CONFIG_SOC_SERIES_APOLLO4X)
32+
#else
3333
#define MIN_DELAY 4
3434
#endif
3535

36+
#if defined(CONFIG_SOC_SERIES_APOLLO5X)
37+
#define COMPARE_INTERRUPT AM_HAL_STIMER_INT_COMPAREA
38+
#else
39+
/* A Possible clock glitch could rarely cause the Stimer interrupt to be lost.
40+
* Set up a backup comparator to handle this case
41+
*/
3642
#define COMPARE_INTERRUPT (AM_HAL_STIMER_INT_COMPAREA | AM_HAL_STIMER_INT_COMPAREB)
43+
#endif
3744

3845
#define COMPAREA_IRQ (DT_INST_IRQN(0))
3946
#define COMPAREB_IRQ (COMPAREA_IRQ + 1)
@@ -82,7 +89,9 @@ static void update_tick_counter(void)
8289
static void ambiq_stimer_delta_set(uint32_t ui32Delta)
8390
{
8491
am_hal_stimer_compare_delta_set(0, ui32Delta);
92+
#if !defined(CONFIG_SOC_SERIES_APOLLO5X)
8593
am_hal_stimer_compare_delta_set(1, ui32Delta + 1);
94+
#endif
8695
}
8796

8897
static void stimer_isr(const void *arg)
@@ -201,23 +210,28 @@ static int stimer_init(void)
201210
am_hal_stimer_config((oldCfg & ~(AM_HAL_STIMER_CFG_FREEZE | CTIMER_STCFG_CLKSEL_Msk)) |
202211
TIMER_CLKSRC | AM_HAL_STIMER_CFG_COMPARE_A_ENABLE |
203212
AM_HAL_STIMER_CFG_COMPARE_B_ENABLE);
204-
#else
213+
#elif defined(CONFIG_SOC_SERIES_APOLLO4X)
205214
am_hal_stimer_config((oldCfg & ~(AM_HAL_STIMER_CFG_FREEZE | STIMER_STCFG_CLKSEL_Msk)) |
206215
TIMER_CLKSRC | AM_HAL_STIMER_CFG_COMPARE_A_ENABLE |
207216
AM_HAL_STIMER_CFG_COMPARE_B_ENABLE);
217+
#elif defined(CONFIG_SOC_SERIES_APOLLO5X)
218+
/* No need for backup comparator any more */
219+
am_hal_stimer_config((oldCfg & ~(AM_HAL_STIMER_CFG_FREEZE | STIMER_STCFG_CLKSEL_Msk)) |
220+
TIMER_CLKSRC | AM_HAL_STIMER_CFG_COMPARE_A_ENABLE);
208221
#endif
209222
g_last_time_stamp = am_hal_stimer_counter_get();
210223

211224
/* A Possible clock glitch could rarely cause the Stimer interrupt to be lost.
212225
* Set up a backup comparator to handle this case
213226
*/
214227
NVIC_ClearPendingIRQ(COMPAREA_IRQ);
215-
NVIC_ClearPendingIRQ(COMPAREB_IRQ);
216228
IRQ_CONNECT(COMPAREA_IRQ, 0, stimer_isr, 0, 0);
217-
IRQ_CONNECT(COMPAREB_IRQ, 0, stimer_isr, 0, 0);
218229
irq_enable(COMPAREA_IRQ);
230+
#if !defined(CONFIG_SOC_SERIES_APOLLO5X)
231+
NVIC_ClearPendingIRQ(COMPAREB_IRQ);
232+
IRQ_CONNECT(COMPAREB_IRQ, 0, stimer_isr, 0, 0);
219233
irq_enable(COMPAREB_IRQ);
220-
234+
#endif
221235
am_hal_stimer_int_enable(COMPARE_INTERRUPT);
222236
/* Start timer with period CYC_PER_TICK if tickless is not enabled */
223237
if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) {

0 commit comments

Comments
 (0)