better compilation on host
[aversive.git] / include / aversive / timers.h
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: timers.h,v 1.1.2.4 2009-01-23 23:54:16 zer0 Exp $
19  *
20  */
21
22 /*
23  * This file contains definitions used for timer use
24  *
25  * In the future, most of definitions will be added in autogenerated
26  * files from atmel's documentation (aversive/parts.h and
27  * aversive/parts/ATxxxx.h) which are not timer specific.
28  */
29
30 /* XXX won't be needed : use parts.h */
31
32 #ifndef _AVERSIVE_TIMERS_H_
33 #define _AVERSIVE_TIMERS_H_
34
35 // Timer WGM bits
36 #define TIMER_8_MODE_NORMAL      0
37 #define TIMER_8_MODE_PWM_PC      1 // phase correct PWM
38 #define TIMER_8_MODE_CTC         2
39 #define TIMER_8_MODE_PWM         3 // fast PWM
40
41 #define TIMER_16_MODE_NORMAL      0
42 #define TIMER_16_MODE_PWM_PC_8    1 // phase correct PWM 8 bits
43 #define TIMER_16_MODE_PWM_PC_9    2 // phase correct PWM 9 bits
44 #define TIMER_16_MODE_PWM_PC_10   3 // phase correct PWM 10 bits
45 #define TIMER_16_MODE_CTC1        4 // clear on compare, TOP = OCRA
46 #define TIMER_16_MODE_PWM_8       5 // fast PWM 8 bits
47 #define TIMER_16_MODE_PWM_9       6 // fast PWM 9 bits
48 #define TIMER_16_MODE_PWM_10      7 // fast PWM 10 bits
49 #define TIMER_16_MODE_PWM_PFC1    8 // PWM, Phase & Freq Correct
50 #define TIMER_16_MODE_PWM_PFC2    9 // PWM, Phase & Freq Correct
51 #define TIMER_16_MODE_PWM_PC1     10 // PWM, Phase Correct
52 #define TIMER_16_MODE_PWM_PC2     11 // PWM, Phase Correct
53 #define TIMER_16_MODE_CTC2        12 // clear on compare, TOP = ICR
54 #define TIMER_16_MODE_PWM_F1      14 // fast PWM
55 #define TIMER_16_MODE_PWM_F2      15 // fast PWM
56
57
58 // ATMEGA128 ////////////////////////////////////////
59 #if defined (__AVR_ATmega128__)
60
61 // OCR_BITS
62 #define OCR0_DDR DDRB
63 #define OCR0_BIT 4
64 #define OCR1A_DDR DDRB
65 #define OCR1A_BIT 5
66 #define OCR1B_DDR DDRB
67 #define OCR1B_BIT 6
68 #define OCR1C_DDR DDRB
69 #define OCR1C_BIT 7
70 #define OCR2_DDR DDRB
71 #define OCR2_BIT 7
72 #define OCR3A_DDR DDRE
73 #define OCR3A_BIT 3
74 #define OCR3B_DDR DDRE
75 #define OCR3B_BIT 4
76 #define OCR3C_DDR DDRE
77 #define OCR3C_BIT 5
78
79
80
81
82 // ATMEGA1281 ////////////////////////////////////////
83 #elif defined (__AVR_ATmega1281__)
84
85 // OCR_BITS
86 #define OCR0A_DDR DDRB
87 #define OCR0A_BIT 7
88 #define OCR0B_DDR DDRG
89 #define OCR0B_BIT 5
90 #define OCR1A_DDR DDRB
91 #define OCR1A_BIT 5
92 #define OCR1B_DDR DDRB
93 #define OCR1B_BIT 6
94 #define OCR1C_DDR DDRB
95 #define OCR1C_BIT 7
96 #define OCR2A_DDR DDRB
97 #define OCR2A_BIT 4
98 #define OCR3A_DDR DDRE
99 #define OCR3A_BIT 3
100 #define OCR3B_DDR DDRE
101 #define OCR3B_BIT 4
102 #define OCR3C_DDR DDRE
103 #define OCR3C_BIT 5
104
105
106
107 // ATMEGA32 ////////////////////////////////////////
108 #elif defined (__AVR_ATmega32__) || defined (__AVR_ATmega323__)
109
110 #ifdef __AVR_ATmega323__
111
112 // renamed bits
113 #define WGM20 PWM2
114 #define WGM21 CTC2
115
116 #define WGM10 PWM10
117 #define WGM11 PWM11
118 #define WGM12 3//CTC1
119 #define WGM13 4 // reserve bit
120
121 #define WGM00 PWM0
122 #define WGM01 CTC0
123
124 #endif // mega323
125
126
127 // OCR_BITS
128 #define OCR0_DDR DDRB
129 #define OCR0_BIT 3
130 #define OCR1A_DDR DDRD
131 #define OCR1A_BIT 5
132 #define OCR1B_DDR DDRD
133 #define OCR1B_BIT 4
134 #define OCR2_DDR DDRD
135 #define OCR2_BIT 7
136
137
138 // ATMEGA8 ////////////////////////////////////////
139 #elif defined (__AVR_ATmega8__)
140
141 // OCR_BITS
142 #define OCR1A_DDR DDRB
143 #define OCR1A_BIT 1
144 #define OCR1B_DDR DDRB
145 #define OCR1B_BIT 2
146 #define OCR2_DDR DDRB
147 #define OCR2_BIT 3
148
149
150
151 // ATMEGA163 ////////////////////////////////////////
152 #elif defined (__AVR_ATmega163__)
153
154 // renamed bits
155 #define WGM20 PWM2 
156 #define WGM21 CTC2
157
158 #define WGM10 PWM10
159 #define WGM11 PWM11
160 #define WGM12 CTC1
161 #define WGM13 4 // reserve bit
162
163 // OCR_BITS
164 #define OCR1A_DDR DDRD
165 #define OCR1A_BIT 5
166 #define OCR1B_DDR DDRD
167 #define OCR1B_BIT 4
168 #define OCR2_DDR DDRD
169 #define OCR2_BIT 7
170
171
172 // ATMEGAx8 ////////////////////////////////////////
173 #elif defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__)
174
175 // OCR_BITS
176 #define OCR0A_DDR DDRD
177 #define OCR0A_BIT 6
178 #define OCR0B_DDR DDRD
179 #define OCR0B_BIT 5
180
181 #define OCR1A_DDR DDRB
182 #define OCR1A_BIT 1
183 #define OCR1B_DDR DDRB
184 #define OCR1B_BIT 2
185
186 #define OCR2A_DDR DDRB
187 #define OCR2A_BIT 3
188 #define OCR2B_DDR DDRD
189 #define OCR2B_BIT 3
190
191
192 #else
193 //#error No timer/prescaler definitions for your AVR type
194 #endif
195
196 #endif