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/>.
23 #include </usr/include/stdio.h>
25 #include "sim_core_declare.h"
26 #include "avr_eeprom.h"
27 #include "avr_watchdog.h"
28 #include "avr_extint.h"
29 #include "avr_ioport.h"
30 #include "avr_timer.h"
34 #include "avr/iotn13.h"
36 static void init(struct avr_t * avr);
37 static void reset(struct avr_t * avr);
40 static const struct mcu_t {
43 avr_watchdog_t watchdog;
52 * tiny13 has no extended fuse byte, so can not use DEFAULT_CORE macro
58 // Disable signature for now, for ubuntu, gentoo and other using old avr toolchain
60 .signature = { SIGNATURE_0,SIGNATURE_1,SIGNATURE_2 },
61 .fuse = { LFUSE_DEFAULT, HFUSE_DEFAULT },
66 AVR_EEPROM_DECLARE_8BIT(EE_RDY_vect),
67 // tiny13 has different names for these...
70 AVR_WATCHDOG_DECLARE(WDTCR, WDT_vect),
72 AVR_EXTINT_TINY_DECLARE(0, 'B', 1, GIFR),
75 .name = 'B', .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
77 .enable = AVR_IO_REGBIT(GIMSK, PCIE),
78 .raised = AVR_IO_REGBIT(GIFR, PCIF),
79 .vector = PCINT0_vect,
85 .wgm = { AVR_IO_REGBIT(TCCR0A, WGM00), AVR_IO_REGBIT(TCCR0A, WGM01), AVR_IO_REGBIT(TCCR0B, WGM02) },
87 [0] = AVR_TIMER_WGM_NORMAL8(),
88 [2] = AVR_TIMER_WGM_CTC(),
89 [3] = AVR_TIMER_WGM_FASTPWM8(),
90 [7] = AVR_TIMER_WGM_OCPWM(),
92 .cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
93 .cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */ },
98 .enable = AVR_IO_REGBIT(TIMSK0, TOIE0),
99 .raised = AVR_IO_REGBIT(TIFR0, TOV0),
100 .vector = TIM0_OVF_vect,
103 [AVR_TIMER_COMPA] = {
106 .enable = AVR_IO_REGBIT(TIMSK0, OCIE0A),
107 .raised = AVR_IO_REGBIT(TIFR0, OCF0A),
108 .vector = TIM0_COMPA_vect,
111 [AVR_TIMER_COMPB] = {
114 .enable = AVR_IO_REGBIT(TIMSK0, OCIE0B),
115 .raised = AVR_IO_REGBIT(TIFR0, OCF0B),
116 .vector = TIM0_COMPB_vect,
123 static avr_t * make()
125 return avr_core_allocate(&mcu.core, sizeof(struct mcu_t));
128 avr_kind_t tiny13 = {
129 .names = { "attiny13", "attiny13a" },
133 static void init(struct avr_t * avr)
135 struct mcu_t * mcu = (struct mcu_t*)avr;
137 printf("%s init\n", avr->mmcu);
139 avr_eeprom_init(avr, &mcu->eeprom);
140 avr_watchdog_init(avr, &mcu->watchdog);
141 avr_extint_init(avr, &mcu->extint);
142 avr_ioport_init(avr, &mcu->portb);
143 avr_timer_init(avr, &mcu->timer0);
146 static void reset(struct avr_t * avr)
148 // struct mcu_t * mcu = (struct mcu_t*)avr;