4 Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
8 simavr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 simavr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with simavr. If not, see <http://www.gnu.org/licenses/>.
22 #include </usr/include/stdio.h>
23 #include "sim_core_declare.h"
24 #include "avr_eeprom.h"
25 #include "avr_extint.h"
26 #include "avr_ioport.h"
28 #include "avr_timer.h"
30 static void init(struct avr_t * avr);
31 static void reset(struct avr_t * avr);
35 #include "avr/iotn2313.h"
38 * This is a template for all of the tinyx5 devices, hopefully
44 avr_ioport_t portb, portd;
46 avr_timer_t timer0,timer1;
55 AVR_EEPROM_DECLARE_8BIT(EEPROM_READY_vect),
57 AVR_EXTINT_TINY_DECLARE(0, 'D', 2, EIFR),
58 AVR_EXTINT_TINY_DECLARE(1, 'D', 3, EIFR),
61 .name = 'B', .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
63 .enable = AVR_IO_REGBIT(GIMSK, PCIE),
64 .raised = AVR_IO_REGBIT(EIFR, PCIF),
69 .portd = { // port D has no PCInts..
70 .name = 'D', .r_port = PORTD, .r_ddr = DDRD, .r_pin = PIND,
73 // no PRR register on the 2313
74 //.disabled = AVR_IO_REGBIT(PRR,PRUSART0),
78 .txen = AVR_IO_REGBIT(UCSRB, TXEN),
79 .rxen = AVR_IO_REGBIT(UCSRB, RXEN),
87 .enable = AVR_IO_REGBIT(UCSRB, RXCIE),
88 .raised = AVR_IO_REGBIT(UCSRA, RXC),
89 .vector = USART_RX_vect,
92 .enable = AVR_IO_REGBIT(UCSRB, TXCIE),
93 .raised = AVR_IO_REGBIT(UCSRA, TXC),
94 .vector = USART_TX_vect,
97 .enable = AVR_IO_REGBIT(UCSRB, UDRIE),
98 .raised = AVR_IO_REGBIT(UCSRA, UDRE),
99 .vector = USART_UDRE_vect,
104 .wgm = { AVR_IO_REGBIT(TCCR0A, WGM00), AVR_IO_REGBIT(TCCR0A, WGM01), AVR_IO_REGBIT(TCCR0B, WGM02) },
106 [0] = AVR_TIMER_WGM_NORMAL8(),
107 [2] = AVR_TIMER_WGM_CTC(),
108 [3] = AVR_TIMER_WGM_FASTPWM(),
109 [7] = AVR_TIMER_WGM_FASTPWM(),
111 .cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
112 .cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */ },
119 .enable = AVR_IO_REGBIT(TIMSK, TOIE0),
120 .raised = AVR_IO_REGBIT(TIFR, TOV0),
121 .vector = TIMER0_OVF_vect,
124 .enable = AVR_IO_REGBIT(TIMSK, OCIE0A),
125 .raised = AVR_IO_REGBIT(TIFR, OCF0A),
126 .vector = TIMER0_COMPA_vect,
129 .enable = AVR_IO_REGBIT(TIMSK, OCIE0B),
130 .raised = AVR_IO_REGBIT(TIFR, OCF0B),
131 .vector = TIMER0_COMPB_vect,
136 // .disabled = AVR_IO_REGBIT(PRR,PRTIM1),
137 .wgm = { AVR_IO_REGBIT(TCCR1A, WGM10), AVR_IO_REGBIT(TCCR1A, WGM11),
138 AVR_IO_REGBIT(TCCR1B, WGM12), AVR_IO_REGBIT(TCCR1B, WGM13) },
140 [0] = AVR_TIMER_WGM_NORMAL16(),
141 [4] = AVR_TIMER_WGM_CTC(),
142 [5] = AVR_TIMER_WGM_FASTPWM(),
143 [6] = AVR_TIMER_WGM_FASTPWM(),
144 [7] = AVR_TIMER_WGM_FASTPWM(),
146 .cs = { AVR_IO_REGBIT(TCCR1B, CS10), AVR_IO_REGBIT(TCCR1B, CS11), AVR_IO_REGBIT(TCCR1B, CS12) },
147 .cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */ /* External clock T1 is not handled */},
153 .r_ocrah = OCR1AH, // 16 bits timers have two bytes of it
158 .enable = AVR_IO_REGBIT(TIMSK, TOIE1),
159 .raised = AVR_IO_REGBIT(TIFR, TOV1),
160 .vector = TIMER1_OVF_vect,
163 .enable = AVR_IO_REGBIT(TIMSK, OCIE1A),
164 .raised = AVR_IO_REGBIT(TIFR, OCF1A),
165 .vector = TIMER1_COMPA_vect,
168 .enable = AVR_IO_REGBIT(TIMSK, OCIE1B),
169 .raised = AVR_IO_REGBIT(TIFR, OCF1B),
170 .vector = TIMER1_COMPB_vect,
173 .enable = AVR_IO_REGBIT(TIMSK, ICIE1),
174 .raised = AVR_IO_REGBIT(TIFR, ICF1),
175 .vector = TIMER1_CAPT_vect,
180 static avr_t * make()
185 avr_kind_t tiny2313 = {
186 .names = { "attiny2313", "attiny2313v" },
190 static void init(struct avr_t * avr)
192 struct mcu_t * mcu = (struct mcu_t*)avr;
194 printf("%s init\n", avr->mmcu);
196 avr_eeprom_init(avr, &mcu->eeprom);
197 avr_ioport_init(avr, &mcu->portb);
198 avr_ioport_init(avr, &mcu->portd);
199 avr_uart_init(avr, &mcu->uart);
200 avr_timer_init(avr, &mcu->timer0);
201 avr_timer_init(avr, &mcu->timer1);
204 static void reset(struct avr_t * avr)
206 // struct mcu_t * mcu = (struct mcu_t*)avr;