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/iotn2313a.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;
52
.mmcu = "attiny2313a",
58
AVR_EEPROM_DECLARE_8BIT(EEPROM_Ready_vect),
59
AVR_WATCHDOG_DECLARE(WDTCR, WDT_OVERFLOW_vect),
61
AVR_EXTINT_TINY_DECLARE(0, 'D', 2, GIFR),
62
AVR_EXTINT_TINY_DECLARE(1, 'D', 3, GIFR),
65
.name = 'A', .r_port = PORTA, .r_ddr = DDRA, .r_pin = PINA,
67
.enable = AVR_IO_REGBIT(GIMSK, PCIE1),
68
.raised = AVR_IO_REGBIT(GIFR, PCIF1),
69
.vector = PCINT1_vect,
74
.name = 'B', .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
76
.enable = AVR_IO_REGBIT(GIMSK, PCIE0),
77
.raised = AVR_IO_REGBIT(GIFR, PCIF0),
78
.vector = PCINT0_vect,
83
.name = 'D', .r_port = PORTD, .r_ddr = DDRD, .r_pin = PIND,
85
.enable = AVR_IO_REGBIT(GIMSK, PCIE2),
86
.raised = AVR_IO_REGBIT(GIFR, PCIF2),
87
.vector = PCINT2_vect,
92
//PRUSART, upe=UPE, no reg/bit name index, no 'C' in RX/TX vector names
93
AVR_UART_DECLARE(PRR, PRUSART, UPE, , ),
97
.disabled = AVR_IO_REGBIT(PRR,PRTIM0),
98
.wgm = { AVR_IO_REGBIT( TCCR0A, WGM00 )
99
, AVR_IO_REGBIT( TCCR0A, WGM01 )
100
, AVR_IO_REGBIT( TCCR0B, WGM02 ) },
105
[3] = WGM_FASTPWM_8(),
106
[5] = WGM_FCPWM_OC(),
107
[7] = WGM_FASTPWM_OC(),
109
.cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
110
.cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */, EXTCLK_CHOOSE, EXTCLK_CHOOSE },
111
.ext_clock_pin = AVR_IO_REGBIT(PORTD, 4), /* External clock pin */
116
.enable = AVR_IO_REGBIT(TIMSK, TOIE0),
117
.raised = AVR_IO_REGBIT(TIFR, TOV0),
118
.vector = TIMER0_OVF_vect,
121
[AVR_TIMER_COMPA] = {
123
.com = AVR_IO_REGBITS(TCCR0A, COM0A0, 0x3),
124
.com_pin = AVR_IO_REGBIT(PORTB, 2),
126
.enable = AVR_IO_REGBIT(TIMSK, OCIE0A),
127
.raised = AVR_IO_REGBIT(TIFR, OCF0A),
128
.vector = TIMER0_COMPA_vect,
131
[AVR_TIMER_COMPB] = {
133
.com = AVR_IO_REGBITS(TCCR0A, COM0B0, 0x3),
134
.com_pin = AVR_IO_REGBIT(PORTD, 5),
136
.enable = AVR_IO_REGBIT(TIMSK, OCIE0B),
137
.raised = AVR_IO_REGBIT(TIFR, OCF0B),
138
.vector = TIMER0_COMPB_vect,
145
.disabled = AVR_IO_REGBIT(PRR,PRTIM1),
146
.wgm = { AVR_IO_REGBIT( TCCR1A, WGM10 )
147
, AVR_IO_REGBIT( TCCR1A, WGM11 )
148
, AVR_IO_REGBIT( TCCR1B, WGM12 )
149
, AVR_IO_REGBIT( TCCR1B, WGM13 ) },
151
[0] = WGM_NORMAL16(),
154
[3] = WGM_FCPWM_10(),
155
[4] = WGM_FASTPWM_8(),
156
[6] = WGM_FASTPWM_9(),
157
[7] = WGM_FASTPWM_10(),
158
[8] = WGM_FCPWM_IC(),
159
[9] = WGM_FCPWM_OC(),
160
[10] = WGM_FCPWM_IC(),
161
[11] = WGM_FCPWM_OC(),
163
[14] = WGM_FASTPWM_IC(),
164
[15] = WGM_FASTPWM_OC(),
166
.cs = { AVR_IO_REGBIT(TCCR1B, CS10), AVR_IO_REGBIT(TCCR1B, CS11), AVR_IO_REGBIT(TCCR1B, CS12) },
167
.cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */, EXTCLK_CHOOSE, EXTCLK_CHOOSE },
168
.ext_clock_pin = AVR_IO_REGBIT(PORTD, 5), /* External clock pin */
175
.ices = AVR_IO_REGBIT(TCCR1B, ICES1),
176
.icp = AVR_IO_REGBIT(PORTD, 6),
179
.enable = AVR_IO_REGBIT(TIMSK, TOIE1),
180
.raised = AVR_IO_REGBIT(TIFR, TOV1),
181
.vector = TIMER1_OVF_vect,
184
.enable = AVR_IO_REGBIT(TIMSK, ICIE1),
185
.raised = AVR_IO_REGBIT(TIFR, ICF1),
186
.vector = TIMER1_CAPT_vect,
189
[AVR_TIMER_COMPA] = {
191
.r_ocrh = OCR1AH, // 16 bits timers have two bytes of it
192
.com = AVR_IO_REGBITS(TCCR1A, COM1A0, 0x3),
193
.com_pin = AVR_IO_REGBIT(PORTB, 3),
195
.enable = AVR_IO_REGBIT(TIMSK, OCIE1A),
196
.raised = AVR_IO_REGBIT(TIFR, OCF1A),
197
.vector = TIMER1_COMPA_vect,
200
[AVR_TIMER_COMPB] = {
203
.com = AVR_IO_REGBITS(TCCR1A, COM1A0, 0x3),
204
.com_pin = AVR_IO_REGBIT(PORTB, 4),
206
.enable = AVR_IO_REGBIT(TIMSK, OCIE1B),
207
.raised = AVR_IO_REGBIT(TIFR, OCF1B),
208
.vector = TIMER1_COMPB_vect,
216
.acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) },
217
.acic = AVR_IO_REGBIT(ACSR, ACIC),
218
.aco = AVR_IO_REGBIT(ACSR, ACO),
219
.acbg = AVR_IO_REGBIT(ACSR, ACBG),
220
.disabled = AVR_IO_REGBIT(ACSR, ACD),
225
.enable = AVR_IO_REGBIT(ACSR, ACIE),
226
.raised = AVR_IO_REGBIT(ACSR, ACI),
227
.vector = ANA_COMP_vect,
233
static avr_t * make()
235
return avr_core_allocate(&mcu.core, sizeof(struct mcu_t));
238
avr_kind_t tiny2313a = {
239
.names = { "attiny2313a" },
243
static void init(struct avr_t * avr)
245
struct mcu_t * mcu = (struct mcu_t*)avr;
247
avr_eeprom_init(avr, &mcu->eeprom);
248
avr_watchdog_init(avr, &mcu->watchdog);
249
avr_extint_init(avr, &mcu->extint);
250
avr_ioport_init(avr, &mcu->porta);
251
avr_ioport_init(avr, &mcu->portb);
252
avr_ioport_init(avr, &mcu->portd);
253
avr_uart_init(avr, &mcu->uart);
254
avr_timer_init(avr, &mcu->timer0);
255
avr_timer_init(avr, &mcu->timer1);
256
avr_acomp_init(avr, &mcu->acomp);
259
static void reset(struct avr_t * avr)
261
// struct mcu_t * mcu = (struct mcu_t*)avr;