1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
/*
sim_tiny2313a.c
Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
This file is part of simavr.
simavr is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
simavr is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with simavr. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sim_core_declare.h"
#include "avr_eeprom.h"
#include "avr_watchdog.h"
#include "avr_extint.h"
#include "avr_ioport.h"
#include "avr_uart.h"
#include "avr_timer.h"
#include "avr_acomp.h"
static void init(struct avr_t * avr);
static void reset(struct avr_t * avr);
#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iotn2313a.h"
/*
* This is a template for all of the tinyx5 devices, hopefully
*/
static const struct mcu_t {
avr_t core;
avr_eeprom_t eeprom;
avr_watchdog_t watchdog;
avr_extint_t extint;
avr_ioport_t porta, portb, portd;
avr_uart_t uart;
avr_timer_t timer0,timer1;
avr_acomp_t acomp;
} mcu = {
.core = {
.mmcu = "attiny2313a",
DEFAULT_CORE(2),
.init = init,
.reset = reset,
},
AVR_EEPROM_DECLARE_8BIT(EEPROM_Ready_vect),
AVR_WATCHDOG_DECLARE(WDTCR, WDT_OVERFLOW_vect),
.extint = {
AVR_EXTINT_TINY_DECLARE(0, 'D', 2, GIFR),
AVR_EXTINT_TINY_DECLARE(1, 'D', 3, GIFR),
},
.porta = {
.name = 'A', .r_port = PORTA, .r_ddr = DDRA, .r_pin = PINA,
.pcint = {
.enable = AVR_IO_REGBIT(GIMSK, PCIE1),
.raised = AVR_IO_REGBIT(GIFR, PCIF1),
.vector = PCINT1_vect,
},
.r_pcint = PCMSK1,
},
.portb = {
.name = 'B', .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
.pcint = {
.enable = AVR_IO_REGBIT(GIMSK, PCIE0),
.raised = AVR_IO_REGBIT(GIFR, PCIF0),
.vector = PCINT0_vect,
},
.r_pcint = PCMSK0,
},
.portd = {
.name = 'D', .r_port = PORTD, .r_ddr = DDRD, .r_pin = PIND,
.pcint = {
.enable = AVR_IO_REGBIT(GIMSK, PCIE2),
.raised = AVR_IO_REGBIT(GIFR, PCIF2),
.vector = PCINT2_vect,
},
.r_pcint = PCMSK2,
},
//PRUSART, upe=UPE, no reg/bit name index, no 'C' in RX/TX vector names
AVR_UART_DECLARE(PRR, PRUSART, UPE, , ),
.timer0 = {
.name = '0',
.disabled = AVR_IO_REGBIT(PRR,PRTIM0),
.wgm = { AVR_IO_REGBIT( TCCR0A, WGM00 )
, AVR_IO_REGBIT( TCCR0A, WGM01 )
, AVR_IO_REGBIT( TCCR0B, WGM02 ) },
.wgm_op = {
[0] = WGM_NORMAL8(),
[1] = WGM_FCPWM_8(),
[2] = WGM_CTC_OC(),
[3] = WGM_FASTPWM_8(),
[5] = WGM_FCPWM_OC(),
[7] = WGM_FASTPWM_OC(),
},
.cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
.cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */, EXTCLK_CHOOSE, EXTCLK_CHOOSE },
.ext_clock_pin = AVR_IO_REGBIT(PORTD, 4), /* External clock pin */
.r_tcnt = TCNT0,
.overflow = {
.enable = AVR_IO_REGBIT(TIMSK, TOIE0),
.raised = AVR_IO_REGBIT(TIFR, TOV0),
.vector = TIMER0_OVF_vect,
},
.comp = {
[AVR_TIMER_COMPA] = {
.r_ocr = OCR0A,
.com = AVR_IO_REGBITS(TCCR0A, COM0A0, 0x3),
.com_pin = AVR_IO_REGBIT(PORTB, 2),
.interrupt = {
.enable = AVR_IO_REGBIT(TIMSK, OCIE0A),
.raised = AVR_IO_REGBIT(TIFR, OCF0A),
.vector = TIMER0_COMPA_vect,
},
},
[AVR_TIMER_COMPB] = {
.r_ocr = OCR0B,
.com = AVR_IO_REGBITS(TCCR0A, COM0B0, 0x3),
.com_pin = AVR_IO_REGBIT(PORTD, 5),
.interrupt = {
.enable = AVR_IO_REGBIT(TIMSK, OCIE0B),
.raised = AVR_IO_REGBIT(TIFR, OCF0B),
.vector = TIMER0_COMPB_vect,
}
}
},
},
.timer1 = {
.name = '1',
.disabled = AVR_IO_REGBIT(PRR,PRTIM1),
.wgm = { AVR_IO_REGBIT( TCCR1A, WGM10 )
, AVR_IO_REGBIT( TCCR1A, WGM11 )
, AVR_IO_REGBIT( TCCR1B, WGM12 )
, AVR_IO_REGBIT( TCCR1B, WGM13 ) },
.wgm_op = {
[0] = WGM_NORMAL16(),
[1] = WGM_FCPWM_8(),
[2] = WGM_FCPWM_9(),
[3] = WGM_FCPWM_10(),
[4] = WGM_FASTPWM_8(),
[6] = WGM_FASTPWM_9(),
[7] = WGM_FASTPWM_10(),
[8] = WGM_FCPWM_IC(),
[9] = WGM_FCPWM_OC(),
[10] = WGM_FCPWM_IC(),
[11] = WGM_FCPWM_OC(),
[12] = WGM_CTC_IC(),
[14] = WGM_FASTPWM_IC(),
[15] = WGM_FASTPWM_OC(),
},
.cs = { AVR_IO_REGBIT(TCCR1B, CS10), AVR_IO_REGBIT(TCCR1B, CS11), AVR_IO_REGBIT(TCCR1B, CS12) },
.cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */, EXTCLK_CHOOSE, EXTCLK_CHOOSE },
.ext_clock_pin = AVR_IO_REGBIT(PORTD, 5), /* External clock pin */
.r_tcnt = TCNT1L,
.r_icr = ICR1L,
.r_icrh = ICR1H,
.r_tcnth = TCNT1H,
.ices = AVR_IO_REGBIT(TCCR1B, ICES1),
.icp = AVR_IO_REGBIT(PORTD, 6),
.overflow = {
.enable = AVR_IO_REGBIT(TIMSK, TOIE1),
.raised = AVR_IO_REGBIT(TIFR, TOV1),
.vector = TIMER1_OVF_vect,
},
.icr = {
.enable = AVR_IO_REGBIT(TIMSK, ICIE1),
.raised = AVR_IO_REGBIT(TIFR, ICF1),
.vector = TIMER1_CAPT_vect,
},
.comp = {
[AVR_TIMER_COMPA] = {
.r_ocr = OCR1AL,
.r_ocrh = OCR1AH, // 16 bits timers have two bytes of it
.com = AVR_IO_REGBITS(TCCR1A, COM1A0, 0x3),
.com_pin = AVR_IO_REGBIT(PORTB, 3),
.interrupt = {
.enable = AVR_IO_REGBIT(TIMSK, OCIE1A),
.raised = AVR_IO_REGBIT(TIFR, OCF1A),
.vector = TIMER1_COMPA_vect,
},
},
[AVR_TIMER_COMPB] = {
.r_ocr = OCR1BL,
.r_ocrh = OCR1BH,
.com = AVR_IO_REGBITS(TCCR1A, COM1A0, 0x3),
.com_pin = AVR_IO_REGBIT(PORTB, 4),
.interrupt = {
.enable = AVR_IO_REGBIT(TIMSK, OCIE1B),
.raised = AVR_IO_REGBIT(TIFR, OCF1B),
.vector = TIMER1_COMPB_vect,
}
}
}
},
.acomp = {
.r_acsr = ACSR,
.acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) },
.acic = AVR_IO_REGBIT(ACSR, ACIC),
.aco = AVR_IO_REGBIT(ACSR, ACO),
.acbg = AVR_IO_REGBIT(ACSR, ACBG),
.disabled = AVR_IO_REGBIT(ACSR, ACD),
.timer_name = '1',
.ac = {
.enable = AVR_IO_REGBIT(ACSR, ACIE),
.raised = AVR_IO_REGBIT(ACSR, ACI),
.vector = ANA_COMP_vect,
}
},
};
static avr_t * make()
{
return avr_core_allocate(&mcu.core, sizeof(struct mcu_t));
}
avr_kind_t tiny2313a = {
.names = { "attiny2313a" },
.make = make
};
static void init(struct avr_t * avr)
{
struct mcu_t * mcu = (struct mcu_t*)avr;
avr_eeprom_init(avr, &mcu->eeprom);
avr_watchdog_init(avr, &mcu->watchdog);
avr_extint_init(avr, &mcu->extint);
avr_ioport_init(avr, &mcu->porta);
avr_ioport_init(avr, &mcu->portb);
avr_ioport_init(avr, &mcu->portd);
avr_uart_init(avr, &mcu->uart);
avr_timer_init(avr, &mcu->timer0);
avr_timer_init(avr, &mcu->timer1);
avr_acomp_init(avr, &mcu->acomp);
}
static void reset(struct avr_t * avr)
{
// struct mcu_t * mcu = (struct mcu_t*)avr;
}
|