4d6d1e1f45abea093284486ab29243ce0d0e5bd8
[bertos.git] / drv / at91 / timer.h
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 (interface).
13  */
14
15 #ifndef DRV_AT91_TIMER_H
16 #define DRV_AT91_TIMER_H
17
18 #include <appconfig.h>     /* CONFIG_TIMER */
19 #include <cfg/compiler.h>  /* uint8_t */
20 #include <hw_cpu.h>        /* CLOCK_FREQ */
21
22 /**
23  * \name Values for CONFIG_TIMER.
24  *
25  * Select which hardware timer interrupt to use for system clock and softtimers.
26  *
27  * \{
28  */
29 #define TIMER_ON_PIT 1  ///< System timer on Periodic interval timer
30
31 #define TIMER_DEFAULT TIMER_ON_PIT  ///< Default system timer
32 /* \} */
33
34 /*
35  * Hardware dependent timer initialization.
36  */
37 #if (CONFIG_TIMER == TIMER_ON_PIT)
38
39         void timer_handler(void);
40
41         #define DEFINE_TIMER_ISR     void timer_handler(void)
42         #define TIMER_TICKS_PER_SEC  1000
43         #define TIMER_HW_CNT         (CLOCK_FREQ / (16 * TIMER_TICKS_PER_SEC) - 1)
44
45         /** Frequency of the hardware high-precision timer. */
46         #define TIMER_HW_HPTICKS_PER_SEC (CLOCK_FREQ / 16)
47
48         /// Type of time expressed in ticks of the hardware high-precision timer
49         typedef uint32_t hptime_t;
50 #else
51
52         #error Unimplemented value for CONFIG_TIMER
53 #endif /* CONFIG_TIMER */
54
55
56 #endif /* DRV_TIMER_AT91_H */