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 "sim_core_declare.h"
23
#include "avr_eeprom.h"
24
#include "avr_watchdog.h"
25
#include "avr_extint.h"
26
#include "avr_ioport.h"
28
#include "avr_timer.h"
29
#include "avr_acomp.h"
31
static void init(struct avr_t * avr);
32
static void reset(struct avr_t * avr);
36
#include "avr/iotn2313.h"
39
* This is a template for all of the tinyx5 devices, hopefully
41
static const struct mcu_t {
44
avr_watchdog_t watchdog;
46
avr_ioport_t porta, portb, portd;
48
avr_timer_t timer0,timer1;
58
AVR_EEPROM_DECLARE_8BIT(EEPROM_READY_vect),
59
AVR_WATCHDOG_DECLARE(WDTCSR, WDT_OVERFLOW_vect),
61
AVR_EXTINT_TINY_DECLARE(0, 'D', 2, EIFR),
62
AVR_EXTINT_TINY_DECLARE(1, 'D', 3, EIFR),
64
AVR_IOPORT_DECLARE(a, 'A', A), // port A has no PCInts..
66
.name = 'B', .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
68
.enable = AVR_IO_REGBIT(GIMSK, PCIE),
69
.raised = AVR_IO_REGBIT(EIFR, PCIF),
74
AVR_IOPORT_DECLARE(d, 'D', D), // port D has no PCInts..
76
//no PRUSART, upe=UPE, no reg/bit name index, no 'C' in RX/TX vector names
77
AVR_UART_DECLARE(0, 0, UPE, , ),
81
.wgm = { AVR_IO_REGBIT(TCCR0A, WGM00), AVR_IO_REGBIT(TCCR0A, WGM01), AVR_IO_REGBIT(TCCR0B, WGM02) },
86
[3] = WGM_FASTPWM_8(),
88
[7] = WGM_FASTPWM_OC(),
90
.cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
91
.cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */, EXTCLK_CHOOSE, EXTCLK_CHOOSE },
92
.ext_clock_pin = AVR_IO_REGBIT(PORTD, 4), /* External clock pin */
97
.enable = AVR_IO_REGBIT(TIMSK, TOIE0),
98
.raised = AVR_IO_REGBIT(TIFR, TOV0),
99
.vector = TIMER0_OVF_vect,
102
[AVR_TIMER_COMPA] = {
104
.com = AVR_IO_REGBITS(TCCR0A, COM0A0, 0x3),
105
.com_pin = AVR_IO_REGBIT(PORTB, 2),
107
.enable = AVR_IO_REGBIT(TIMSK, OCIE0A),
108
.raised = AVR_IO_REGBIT(TIFR, OCF0A),
109
.vector = TIMER0_COMPA_vect,
112
[AVR_TIMER_COMPB] = {
114
.com = AVR_IO_REGBITS(TCCR0A, COM0B0, 0x3),
115
.com_pin = AVR_IO_REGBIT(PORTD, 5),
117
.enable = AVR_IO_REGBIT(TIMSK, OCIE0B),
118
.raised = AVR_IO_REGBIT(TIFR, OCF0B),
119
.vector = TIMER0_COMPB_vect,
126
// .disabled = AVR_IO_REGBIT(PRR,PRTIM1),
127
.wgm = { AVR_IO_REGBIT(TCCR1A, WGM10), AVR_IO_REGBIT(TCCR1A, WGM11),
128
AVR_IO_REGBIT(TCCR1B, WGM12), AVR_IO_REGBIT(TCCR1B, WGM13) },
130
[0] = WGM_NORMAL16(),
133
[3] = WGM_FCPWM_10(),
134
[4] = WGM_FASTPWM_8(),
135
[6] = WGM_FASTPWM_9(),
136
[7] = WGM_FASTPWM_10(),
137
[8] = WGM_FCPWM_IC(),
138
[9] = WGM_FCPWM_OC(),
139
[10] = WGM_FCPWM_IC(),
140
[11] = WGM_FCPWM_OC(),
142
[14] = WGM_FASTPWM_IC(),
143
[15] = WGM_FASTPWM_OC(),
145
.cs = { AVR_IO_REGBIT(TCCR1B, CS10), AVR_IO_REGBIT(TCCR1B, CS11), AVR_IO_REGBIT(TCCR1B, CS12) },
146
.cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */, EXTCLK_CHOOSE, EXTCLK_CHOOSE },
147
.ext_clock_pin = AVR_IO_REGBIT(PORTD, 5), /* External clock pin */
154
.ices = AVR_IO_REGBIT(TCCR1B, ICES1),
155
.icp = AVR_IO_REGBIT(PORTD, 6),
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, ICIE1),
164
.raised = AVR_IO_REGBIT(TIFR, ICF1),
165
.vector = TIMER1_CAPT_vect,
168
[AVR_TIMER_COMPA] = {
170
.r_ocrh = OCR1AH, // 16 bits timers have two bytes of it
171
.com = AVR_IO_REGBITS(TCCR1A, COM1A0, 0x3),
172
.com_pin = AVR_IO_REGBIT(PORTB, 3),
174
.enable = AVR_IO_REGBIT(TIMSK, OCIE1A),
175
.raised = AVR_IO_REGBIT(TIFR, OCF1A),
176
.vector = TIMER1_COMPA_vect,
179
[AVR_TIMER_COMPB] = {
182
.com = AVR_IO_REGBITS(TCCR1A, COM1A0, 0x3),
183
.com_pin = AVR_IO_REGBIT(PORTB, 4),
185
.enable = AVR_IO_REGBIT(TIMSK, OCIE1B),
186
.raised = AVR_IO_REGBIT(TIFR, OCF1B),
187
.vector = TIMER1_COMPB_vect,
195
.acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) },
196
.acic = AVR_IO_REGBIT(ACSR, ACIC),
197
.aco = AVR_IO_REGBIT(ACSR, ACO),
198
.acbg = AVR_IO_REGBIT(ACSR, ACBG),
199
.disabled = AVR_IO_REGBIT(ACSR, ACD),
204
.enable = AVR_IO_REGBIT(ACSR, ACIE),
205
.raised = AVR_IO_REGBIT(ACSR, ACI),
206
.vector = ANA_COMP_vect,
212
static avr_t * make()
214
return avr_core_allocate(&mcu.core, sizeof(struct mcu_t));
217
avr_kind_t tiny2313 = {
218
.names = { "attiny2313", "attiny2313v" },
222
static void init(struct avr_t * avr)
224
struct mcu_t * mcu = (struct mcu_t*)avr;
226
avr_eeprom_init(avr, &mcu->eeprom);
227
avr_watchdog_init(avr, &mcu->watchdog);
228
avr_extint_init(avr, &mcu->extint);
229
avr_ioport_init(avr, &mcu->porta);
230
avr_ioport_init(avr, &mcu->portb);
231
avr_ioport_init(avr, &mcu->portd);
232
avr_uart_init(avr, &mcu->uart);
233
avr_timer_init(avr, &mcu->timer0);
234
avr_timer_init(avr, &mcu->timer1);
235
avr_acomp_init(avr, &mcu->acomp);
238
static void reset(struct avr_t * avr)
240
// struct mcu_t * mcu = (struct mcu_t*)avr;