cores: Updated comparators
[simavr] / simavr / cores / sim_tinyx5.h
1 /*
2         sim_tinyx5.h
3
4         Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
5                              Jon Escombe <lists@dresco.co.uk>
6
7         This file is part of simavr.
8
9         simavr is free software: you can redistribute it and/or modify
10         it under the terms of the GNU General Public License as published by
11         the Free Software Foundation, either version 3 of the License, or
12         (at your option) any later version.
13
14         simavr is distributed in the hope that it will be useful,
15         but WITHOUT ANY WARRANTY; without even the implied warranty of
16         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17         GNU General Public License for more details.
18
19         You should have received a copy of the GNU General Public License
20         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23
24 #ifndef __SIM_TINYX5_H__
25 #define __SIM_TINYX5_H__
26
27 #include "sim_core_declare.h"
28 #include "avr_eeprom.h"
29 #include "avr_watchdog.h"
30 #include "avr_extint.h"
31 #include "avr_ioport.h"
32 #include "avr_adc.h"
33 #include "avr_timer.h"
34
35 void tx5_init(struct avr_t * avr);
36 void tx5_reset(struct avr_t * avr);
37
38 /*
39  * This is a template for all of the tinyx5 devices, hopefully
40  */
41 struct mcu_t {
42         avr_t core;
43         avr_eeprom_t    eeprom;
44         avr_watchdog_t  watchdog;
45         avr_extint_t    extint;
46         avr_ioport_t    portb;
47         avr_adc_t               adc;
48         avr_timer_t     timer0, timer1;
49 };
50
51 #ifdef SIM_CORENAME
52
53 #ifndef SIM_VECTOR_SIZE
54 #error SIM_VECTOR_SIZE is not declared
55 #endif
56 #ifndef SIM_MMCU
57 #error SIM_MMCU is not declared
58 #endif
59
60 struct mcu_t SIM_CORENAME = {
61         .core = {
62                 .mmcu = SIM_MMCU,
63                 DEFAULT_CORE(SIM_VECTOR_SIZE),
64
65                 .init = tx5_init,
66                 .reset = tx5_reset,
67         },
68         AVR_EEPROM_DECLARE(EE_RDY_vect),
69         AVR_WATCHDOG_DECLARE(WDTCR, WDT_vect),
70         .extint = {
71                 AVR_EXTINT_TINY_DECLARE(0, 'B', PB2, GIFR),
72         },
73         .portb = {
74                 .name = 'B',  .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
75                 .pcint = {
76                         .enable = AVR_IO_REGBIT(GIMSK, PCIE),
77                         .raised = AVR_IO_REGBIT(GIFR, PCIF),
78                         .vector = PCINT0_vect,
79                 },
80                 .r_pcint = PCMSK,
81         },
82         .adc = {
83                 .r_admux = ADMUX,
84                 .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1),
85                                         AVR_IO_REGBIT(ADMUX, MUX2), AVR_IO_REGBIT(ADMUX, MUX3),},
86                 .ref = { AVR_IO_REGBIT(ADMUX, REFS0), AVR_IO_REGBIT(ADMUX, REFS1), AVR_IO_REGBIT(ADMUX, REFS2), },
87                 .adlar = AVR_IO_REGBIT(ADMUX, ADLAR),
88                 .r_adcsra = ADCSRA,
89                 .aden = AVR_IO_REGBIT(ADCSRA, ADEN),
90                 .adsc = AVR_IO_REGBIT(ADCSRA, ADSC),
91                 .adate = AVR_IO_REGBIT(ADCSRA, ADATE),
92                 .adps = { AVR_IO_REGBIT(ADCSRA, ADPS0), AVR_IO_REGBIT(ADCSRA, ADPS1), AVR_IO_REGBIT(ADCSRA, ADPS2),},
93
94                 .r_adch = ADCH,
95                 .r_adcl = ADCL,
96
97                 .r_adcsrb = ADCSRB,
98                 .adts = { AVR_IO_REGBIT(ADCSRB, ADTS0), AVR_IO_REGBIT(ADCSRB, ADTS1), AVR_IO_REGBIT(ADCSRB, ADTS2),},
99                 .bin = AVR_IO_REGBIT(ADCSRB, BIN),
100                 .ipr = AVR_IO_REGBIT(ADCSRA, IPR),
101
102                 .adc = {
103                         .enable = AVR_IO_REGBIT(ADCSRA, ADIE),
104                         .raised = AVR_IO_REGBIT(ADCSRA, ADIF),
105                         .vector = ADC_vect,
106                 },
107         },
108         .timer0 = {
109                 .name = '0',
110                 .wgm = { AVR_IO_REGBIT(TCCR0A, WGM00), AVR_IO_REGBIT(TCCR0A, WGM01), AVR_IO_REGBIT(TCCR0B, WGM02) },
111                 .wgm_op = {
112                         [0] = AVR_TIMER_WGM_NORMAL8(),
113                         [2] = AVR_TIMER_WGM_CTC(),
114                         [3] = AVR_TIMER_WGM_FASTPWM8(),
115                         [7] = AVR_TIMER_WGM_OCPWM(),
116                 },
117                 .cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
118                 .cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */ },
119
120                 .r_tcnt = TCNT0,
121
122                 .overflow = {
123                         .enable = AVR_IO_REGBIT(TIMSK, TOIE0),
124                         .raised = AVR_IO_REGBIT(TIFR, TOV0),
125                         .vector = TIMER0_OVF_vect,
126                 },
127                 .comp = {
128                         [AVR_TIMER_COMPA] = {
129                                 .r_ocr = OCR0A,
130                                 .com = AVR_IO_REGBITS(TCCR0A, COM0A0, 0x3),
131                                 .com_pin = AVR_IO_REGBIT(PORTB, 0),
132                                 .interrupt = {
133                                         .enable = AVR_IO_REGBIT(TIMSK, OCIE0A),
134                                         .raised = AVR_IO_REGBIT(TIFR, OCF0A),
135                                         .vector = TIMER0_COMPA_vect,
136                                 },
137                         },
138                         [AVR_TIMER_COMPB] = {
139                                 .r_ocr = OCR0B,
140                                 .com = AVR_IO_REGBITS(TCCR0A, COM0B0, 0x3),
141                                 .com_pin = AVR_IO_REGBIT(PORTB, 1),
142                                 .interrupt = {
143                                         .enable = AVR_IO_REGBIT(TIMSK, OCIE0B),
144                                         .raised = AVR_IO_REGBIT(TIFR, OCF0B),
145                                         .vector = TIMER0_COMPB_vect,
146                                 },
147                         },
148                 },
149         },
150         .timer1 = {
151                 .name = '1',
152                 // no wgm bits
153                 .cs = { AVR_IO_REGBIT(TCCR1, CS10), AVR_IO_REGBIT(TCCR1, CS11), AVR_IO_REGBIT(TCCR1, CS12), AVR_IO_REGBIT(TCCR1, CS13) },
154                 .cs_div = { 0, 0, 1 /* 2 */, 2 /* 4 */, 3 /* 8 */, 4 /* 16 */ },
155
156                 .r_tcnt = TCNT1,
157
158                 .overflow = {
159                         .enable = AVR_IO_REGBIT(TIMSK, TOIE1),
160                         .raised = AVR_IO_REGBIT(TIFR, TOV1),
161                         .vector = TIMER1_OVF_vect,
162                 },
163                 .comp = {
164                         [AVR_TIMER_COMPA] = {
165                                 .r_ocr = OCR1A,
166                                 .com = AVR_IO_REGBITS(TCCR1, COM1A0, 0x3),
167                                 .com_pin = AVR_IO_REGBIT(PORTB, 1),
168                                 .interrupt = {
169                                         .enable = AVR_IO_REGBIT(TIMSK, OCIE1A),
170                                         .raised = AVR_IO_REGBIT(TIFR, OCF1A),
171                                         .vector = TIMER1_COMPA_vect,
172                                 },
173                         },
174                         [AVR_TIMER_COMPB] = {
175                                 .r_ocr = OCR1B,
176                                 .com = AVR_IO_REGBITS(GTCCR, COM1B0, 0x3),
177                                 .com_pin = AVR_IO_REGBIT(PORTB, 4),
178                                 .interrupt = {
179                                         .enable = AVR_IO_REGBIT(TIMSK, OCIE1B),
180                                         .raised = AVR_IO_REGBIT(TIFR, OCF1B),
181                                         .vector = TIMER1_COMPB_vect,
182                                 },
183                         },
184                         [AVR_TIMER_COMPC] = {
185                                 .r_ocr = OCR1C,
186                         },
187                 },
188         },
189 };
190 #endif /* SIM_CORENAME */
191
192 #endif /* __SIM_TINYX5_H__ */