cores: Updated for 16 bits timers and ADCs
[simavr] / simavr / cores / sim_tiny13.c
1 /*
2         sim_tiny13.c
3
4         Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
5                              Jon Escombe <lists@dresco.co.uk>
6
7         This file is part of simavr.
8
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.
13
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.
18
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/>.
21  */
22
23 #include </usr/include/stdio.h>
24 #include "sim_avr.h"
25 #include "sim_core_declare.h"
26 #include "avr_eeprom.h"
27 #include "avr_ioport.h"
28 #include "avr_timer.h"
29
30 #define _AVR_IO_H_
31 #define __ASSEMBLER__
32 #include "avr/iotn13.h"
33
34 static void init(struct avr_t * avr);
35 static void reset(struct avr_t * avr);
36
37
38 static struct mcu_t {
39         avr_t core;
40         avr_eeprom_t    eeprom;
41         avr_ioport_t    portb;
42         avr_timer_t             timer0;
43 } mcu = {
44         .core = {
45                 .mmcu = "attiny13",
46
47                 /*
48                  * tiny13 has no extended fuse byte, so can not use DEFAULT_CORE macro
49                  */
50                 .ramend = RAMEND,
51                 .flashend = FLASHEND,
52                 .e2end = E2END,
53                 .vector_size = 2,
54                 .signature = { SIGNATURE_0,SIGNATURE_1,SIGNATURE_2 },
55                 .fuse = { LFUSE_DEFAULT, HFUSE_DEFAULT },
56
57                 .init = init,
58                 .reset = reset,
59         },
60         AVR_EEPROM_DECLARE_8BIT(EE_RDY_vect),
61         .portb = {
62                 .name = 'B',  .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
63                 .pcint = {
64                         .enable = AVR_IO_REGBIT(GIMSK, PCIE),
65                         .raised = AVR_IO_REGBIT(GIFR, PCIF),
66                         .vector = PCINT0_vect,
67                 },
68                 .r_pcint = PCMSK,
69         },
70         .timer0 = {
71                 .name = '0',
72                 .wgm = { AVR_IO_REGBIT(TCCR0A, WGM00), AVR_IO_REGBIT(TCCR0A, WGM01), AVR_IO_REGBIT(TCCR0B, WGM02) },
73                 .wgm_op = {
74                         [0] = AVR_TIMER_WGM_NORMAL8(),
75                         [2] = AVR_TIMER_WGM_CTC(),
76                         [3] = AVR_TIMER_WGM_FASTPWM(),
77                         [7] = AVR_TIMER_WGM_FASTPWM(),
78                 },
79                 .cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
80                 .cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */ },
81
82                 .r_ocra = OCR0A,
83                 .r_ocrb = OCR0B,
84                 .r_tcnt = TCNT0,
85
86                 .overflow = {
87                         .enable = AVR_IO_REGBIT(TIMSK0, TOIE0),
88                         .raised = AVR_IO_REGBIT(TIFR0, TOV0),
89                         .vector = TIM0_OVF_vect,
90                 },
91                 .compa = {
92                         .enable = AVR_IO_REGBIT(TIMSK0, OCIE0A),
93                         .raised = AVR_IO_REGBIT(TIFR0, OCF0A),
94                         .vector = TIM0_COMPA_vect,
95                 },
96                 .compb = {
97                         .enable = AVR_IO_REGBIT(TIMSK0, OCIE0B),
98                         .raised = AVR_IO_REGBIT(TIFR0, OCF0B),
99                         .vector = TIM0_COMPB_vect,
100                 },
101         },
102 };
103
104 static avr_t * make()
105 {
106         return &mcu.core;
107 }
108
109 avr_kind_t tiny13 = {
110         .names = { "attiny13", "attiny13a" },
111         .make = make
112 };
113
114 static void init(struct avr_t * avr)
115 {
116         struct mcu_t * mcu = (struct mcu_t*)avr;
117
118         printf("%s init\n", avr->mmcu);
119
120         avr_eeprom_init(avr, &mcu->eeprom);
121         avr_ioport_init(avr, &mcu->portb);
122         avr_timer_init(avr, &mcu->timer0);
123 }
124
125 static void reset(struct avr_t * avr)
126 {
127 //      struct mcu_t * mcu = (struct mcu_t*)avr;
128 }