4 * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
10 * \author Francesco Sacchi <batt@develer.com>
12 * \brief Low-level timer module for Atmel AT91 (inplementation).
15 #include <drv/timer_at91.h>
16 #include <cfg/macros.h> // BV()
21 /** HW dependent timer initialization */
22 #if (CONFIG_TIMER == TIMER_ON_PIT)
23 #warning Very untested!
24 INLINE static void timer_hw_irq(void)
26 /* Reset counters, this is needed to reset timer and interrupt flags */
27 volatile uint32_t dummy = PIT_PIVR;
30 INLINE static bool timer_hw_triggered(void)
32 return PIT_SR & BV(PITS);
35 INLINE static void timer_hw_init(void)
38 IRQ_SAVE_DISABLE(flags);
40 PIT_MR = CLOCK_FREQ / (16 * TIMER_TICKS_PER_SEC) - 1;
41 /* Register system interrupt handler. */
42 sysirq_setHandler(SYSIRQ_PIT, timer_handler);
44 /* Enable interval timer and interval timer interrupts */
45 PIT_MR |= BV(PIT_PITEN);
46 sysirq_setEnable(SYSIRQ_PIT, true);
48 /* Reset counters, this is needed to start timer and interrupt flags */
49 volatile uint32_t dummy = PIT_PIVR;
54 INLINE static hptime_t timer_hw_hpread(void)
56 /* In the upper part of PIT_PIIR there is unused data */
57 return PIT_PIIR & 0xfffff;
61 #error Unimplemented value for CONFIG_TIMER
62 #endif /* CONFIG_TIMER */