Sistema l'errore da me commesso in fase di conversione...
[bertos.git] / drv / at91 / timer.c
1 /**
2  * \file
3  * <!--
4  * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
5  * This file is part of DevLib - See README.devlib for information.
6  * -->
7  *
8  * \version $Id$
9  *
10  * \author Francesco Sacchi <batt@develer.com>
11  *
12  * \brief Low-level timer module for Atmel AT91 (inplementation).
13  */
14
15 #include <drv/timer_at91.h>
16 #include <cfg/macros.h> // BV()
17
18 #include <cfg/cpu.h>
19
20
21 /** HW dependent timer initialization  */
22 #if (CONFIG_TIMER == TIMER_ON_PIT)
23         #warning Very untested!
24         INLINE static void timer_hw_irq(void)
25         {
26                 /* Reset counters, this is needed to reset timer and interrupt flags */
27                 volatile uint32_t dummy = PIT_PIVR;
28         }
29
30         INLINE static bool timer_hw_triggered(void)
31         {
32                 return PIT_SR & BV(PITS);
33         }
34
35         INLINE static void timer_hw_init(void)
36         {
37                 cpuflags_t flags;
38                 IRQ_SAVE_DISABLE(flags);
39
40                 PIT_MR = CLOCK_FREQ / (16 * TIMER_TICKS_PER_SEC) - 1;
41                 /* Register system interrupt handler. */
42                 sysirq_setHandler(SYSIRQ_PIT, timer_handler);
43
44                 /* Enable interval timer and interval timer interrupts */
45                 PIT_MR |= BV(PIT_PITEN);
46                 sysirq_setEnable(SYSIRQ_PIT, true);
47
48                 /* Reset counters, this is needed to start timer and interrupt flags */
49                 volatile uint32_t dummy = PIT_PIVR;
50
51                 IRQ_RESTORE(flags);
52         }
53
54         INLINE static hptime_t timer_hw_hpread(void)
55         {
56                 /* In the upper part of PIT_PIIR there is unused data */
57                 return PIT_PIIR & 0xfffff;
58         }
59
60 #else
61         #error Unimplemented value for CONFIG_TIMER
62 #endif /* CONFIG_TIMER */