merge
[aversive.git] / modules / hardware / timer / timer_init.c
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2006)
3  * 
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: timer_init.c,v 1.1.2.4 2009-01-30 20:18:36 zer0 Exp $
19  *
20  */
21
22 #include <aversive/timers.h>
23 #include <timer.h>
24 #include <timer_intr.h>
25 #include <timer_prescaler.h>
26
27 #include <timer_config.h>
28
29 /** Init of all timers with static configutaion (see timer_config.h) */
30 void timer_init(void)
31 {
32         uint8_t flags;
33         
34         IRQ_LOCK(flags);
35         timer_intr_init();
36
37 #if defined TIMER0_ENABLED && defined TIMER0_AVAILABLE
38         CS00_REG = __timer0_div_to_reg(TIMER0_PRESCALER_DIV) << CS00 ;
39         TCNT0 = 0;
40 #endif
41 #if defined TIMER1_ENABLED && defined TIMER1_AVAILABLE
42         CS10_REG = __timer1_div_to_reg(TIMER1_PRESCALER_DIV) << CS10 ;
43         TCNT1 = 0;
44 #endif
45 #if defined TIMER2_ENABLED && defined TIMER2_AVAILABLE
46         CS20_REG = __timer2_div_to_reg(TIMER2_PRESCALER_DIV) << CS20 ;
47         TCNT2 = 0;
48 #endif
49 #if defined TIMER3_ENABLED && defined TIMER3_AVAILABLE
50         CS30_REG = __timer3_div_to_reg(TIMER3_PRESCALER_DIV) << CS30 ;
51         TCNT3 = 0;
52 #endif
53 #if defined TIMER4_ENABLED && defined TIMER4_AVAILABLE
54         CS40_REG = __timer4_div_to_reg(TIMER4_PRESCALER_DIV) << CS40 ;
55         TCNT4 = 0;
56 #endif
57 #if defined TIMER5_ENABLED && defined TIMER5_AVAILABLE
58         CS50_REG = __timer5_div_to_reg(TIMER5_PRESCALER_DIV) << CS50 ;
59         TCNT5 = 0;
60 #endif
61         IRQ_UNLOCK(flags);
62 }