4
Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
5
Jon Escombe <lists@dresco.co.uk>
7
This file is part of simavr.
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.
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.
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/>.
24
#include "sim_core_declare.h"
25
#include "avr_eeprom.h"
26
#include "avr_watchdog.h"
27
#include "avr_extint.h"
28
#include "avr_ioport.h"
29
#include "avr_timer.h"
31
#include "avr_acomp.h"
35
#include "avr/iotn13.h"
37
static void init(struct avr_t * avr);
38
static void reset(struct avr_t * avr);
41
static const struct mcu_t {
44
avr_watchdog_t watchdog;
55
* tiny13 has no extended fuse byte, so can not use DEFAULT_CORE macro
61
// Disable signature when using an old avr toolchain
63
.signature = { SIGNATURE_0,SIGNATURE_1,SIGNATURE_2 },
64
.fuse = { LFUSE_DEFAULT, HFUSE_DEFAULT },
69
AVR_EEPROM_DECLARE_8BIT(EE_RDY_vect),
70
// tiny13 has different names for these...
73
AVR_WATCHDOG_DECLARE(WDTCR, WDT_vect),
75
AVR_EXTINT_TINY_DECLARE(0, 'B', 1, GIFR),
78
.name = 'B', .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
80
.enable = AVR_IO_REGBIT(GIMSK, PCIE),
81
.raised = AVR_IO_REGBIT(GIFR, PCIF),
82
.vector = PCINT0_vect,
88
.wgm = { AVR_IO_REGBIT( TCCR0A, WGM00 )
89
, AVR_IO_REGBIT( TCCR0A, WGM01 )
90
, AVR_IO_REGBIT( TCCR0B, WGM02 ) },
95
[3] = WGM_FASTPWM_8(),
97
[7] = WGM_FASTPWM_OC(),
99
.cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
100
.cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */ },
105
.enable = AVR_IO_REGBIT(TIMSK0, TOIE0),
106
.raised = AVR_IO_REGBIT(TIFR0, TOV0),
107
.vector = TIM0_OVF_vect,
110
[AVR_TIMER_COMPA] = {
112
.com = AVR_IO_REGBITS(TCCR0A, COM0A0, 0x3),
113
.com_pin = AVR_IO_REGBIT(PORTB, 0),
115
.enable = AVR_IO_REGBIT(TIMSK0, OCIE0A),
116
.raised = AVR_IO_REGBIT(TIFR0, OCF0A),
117
.vector = TIM0_COMPA_vect,
120
[AVR_TIMER_COMPB] = {
122
.com = AVR_IO_REGBITS(TCCR0A, COM0B0, 0x3),
123
.com_pin = AVR_IO_REGBIT(PORTB, 1),
125
.enable = AVR_IO_REGBIT(TIMSK0, OCIE0B),
126
.raised = AVR_IO_REGBIT(TIFR0, OCF0B),
127
.vector = TIM0_COMPB_vect,
135
.mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1) },
136
.aden = AVR_IO_REGBIT(ADCSRA, ADEN),
137
.acme = AVR_IO_REGBIT(ADCSRB, ACME),
140
.acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) },
141
.aco = AVR_IO_REGBIT(ACSR, ACO),
142
.acbg = AVR_IO_REGBIT(ACSR, ACBG),
143
.disabled = AVR_IO_REGBIT(ACSR, ACD),
146
.enable = AVR_IO_REGBIT(ACSR, ACIE),
147
.raised = AVR_IO_REGBIT(ACSR, ACI),
148
.vector = ANA_COMP_vect,
154
.mux = { AVR_IO_REGBIT(ADMUX, MUX0),
155
AVR_IO_REGBIT(ADMUX, MUX1), },
156
.ref = { AVR_IO_REGBIT(ADMUX, REFS0), },
158
[0] = ADC_VREF_VCC, [1] = ADC_VREF_V110,
161
.adlar = AVR_IO_REGBIT(ADMUX, ADLAR),
163
.aden = AVR_IO_REGBIT(ADCSRA, ADEN),
164
.adsc = AVR_IO_REGBIT(ADCSRA, ADSC),
165
.adate = AVR_IO_REGBIT(ADCSRA, ADATE),
166
.adps = { AVR_IO_REGBIT(ADCSRA, ADPS0),
167
AVR_IO_REGBIT(ADCSRA, ADPS1),
168
AVR_IO_REGBIT(ADCSRA, ADPS2),},
174
.adts = { AVR_IO_REGBIT(ADCSRB, ADTS0),
175
AVR_IO_REGBIT(ADCSRB, ADTS1),
176
AVR_IO_REGBIT(ADCSRB, ADTS2),},
178
[0] = avr_adts_free_running,
179
[1] = avr_adts_analog_comparator_0,
180
[2] = avr_adts_external_interrupt_0,
181
[3] = avr_adts_timer_0_compare_match_a,
182
[4] = avr_adts_timer_0_overflow,
183
[5] = avr_adts_timer_0_compare_match_b,
184
[6] = avr_adts_pin_change_interrupt,
187
[0] = AVR_ADC_SINGLE(0), [1] = AVR_ADC_SINGLE(1),
188
[2] = AVR_ADC_SINGLE(2), [3] = AVR_ADC_SINGLE(3),
192
.enable = AVR_IO_REGBIT(ADCSRA, ADIE),
193
.raised = AVR_IO_REGBIT(ADCSRA, ADIF),
199
static avr_t * make()
201
return avr_core_allocate(&mcu.core, sizeof(struct mcu_t));
204
avr_kind_t tiny13 = {
205
.names = { "attiny13", "attiny13a" },
209
static void init(struct avr_t * avr)
211
struct mcu_t * mcu = (struct mcu_t*)avr;
213
avr_eeprom_init(avr, &mcu->eeprom);
214
avr_watchdog_init(avr, &mcu->watchdog);
215
avr_extint_init(avr, &mcu->extint);
216
avr_ioport_init(avr, &mcu->portb);
217
avr_timer_init(avr, &mcu->timer0);
218
avr_acomp_init(avr, &mcu->acomp);
219
avr_adc_init(avr, &mcu->adc);
222
static void reset(struct avr_t * avr)
224
// struct mcu_t * mcu = (struct mcu_t*)avr;