tiny25/45 cores added
[simavr] / simavr / cores / sim_tinyx5.h
1 /*
2         sim_tinyx5.h
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
24 #ifndef __SIM_TINYX5_H__
25 #define __SIM_TINYX5_H__
26
27 #include "sim_core_declare.h"
28 #include "avr_eeprom.h"
29 #include "avr_ioport.h"
30 #include "avr_timer8.h"
31
32 void tx5_init(struct avr_t * avr);
33 void tx5_reset(struct avr_t * avr);
34
35 /*
36  * This is a template for all of the tinyx5 devices, hopefully
37  */
38 struct mcu_t {
39         avr_t core;
40         avr_eeprom_t    eeprom;
41         avr_ioport_t    portb;
42         avr_timer8_t    timer0, timer1;
43 };
44
45 #ifdef SIM_CORENAME
46
47 #ifndef SIM_VECTOR_SIZE
48 #error SIM_VECTOR_SIZE is not declared
49 #endif
50 #ifndef SIM_MMCU
51 #error SIM_MMCU is not declared
52 #endif
53
54 struct mcu_t SIM_CORENAME = {
55         .core = {
56                 .mmcu = SIM_MMCU,
57                 DEFAULT_CORE(SIM_VECTOR_SIZE),
58
59                 .init = tx5_init,
60                 .reset = tx5_reset,
61         },
62         AVR_EEPROM_DECLARE(EE_RDY_vect),
63         .portb = {
64                 .name = 'B',  .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
65                 .pcint = {
66                         .enable = AVR_IO_REGBIT(GIMSK, PCIE),
67                         .raised = AVR_IO_REGBIT(GIFR, PCIF),
68                         .vector = PCINT0_vect,
69                 },
70                 .r_pcint = PCMSK,
71         },
72         .timer0 = {
73                 .name = '0',
74                 .wgm = { AVR_IO_REGBIT(TCCR0A, WGM00), AVR_IO_REGBIT(TCCR0A, WGM01), AVR_IO_REGBIT(TCCR0B, WGM02) },
75                 .cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
76                 .cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */ },
77
78                 .r_ocra = OCR0A,
79                 .r_ocrb = OCR0B,
80                 .r_tcnt = TCNT0,
81
82                 .overflow = {
83                         .enable = AVR_IO_REGBIT(TIMSK, TOIE0),
84                         .raised = AVR_IO_REGBIT(TIFR, TOV0),
85                         .vector = TIMER0_OVF_vect,
86                 },
87                 .compa = {
88                         .enable = AVR_IO_REGBIT(TIMSK, OCIE0A),
89                         .raised = AVR_IO_REGBIT(TIFR, OCF0A),
90                         .vector = TIMER0_COMPA_vect,
91                 },
92                 .compb = {
93                         .enable = AVR_IO_REGBIT(TIMSK, OCIE0B),
94                         .raised = AVR_IO_REGBIT(TIFR, OCF0B),
95                         .vector = TIMER0_COMPB_vect,
96                 },
97         },
98         .timer1 = {
99                 .name = '1',
100                 // no wgm bits
101                 .cs = { AVR_IO_REGBIT(TCCR1, CS10), AVR_IO_REGBIT(TCCR1, CS11), AVR_IO_REGBIT(TCCR1, CS12), AVR_IO_REGBIT(TCCR1, CS13) },
102                 .cs_div = { 0, 0, 1 /* 2 */, 2 /* 4 */, 3 /* 8 */, 4 /* 16 */ },
103
104                 .r_ocra = OCR1A,
105                 .r_ocrb = OCR1B,
106                 .r_ocrc = OCR1C,
107                 .r_tcnt = TCNT1,
108
109                 .overflow = {
110                         .enable = AVR_IO_REGBIT(TIMSK, TOIE1),
111                         .raised = AVR_IO_REGBIT(TIFR, TOV1),
112                         .vector = TIMER1_OVF_vect,
113                 },
114                 .compa = {
115                         .enable = AVR_IO_REGBIT(TIMSK, OCIE1A),
116                         .raised = AVR_IO_REGBIT(TIFR, OCF1A),
117                         .vector = TIMER1_COMPA_vect,
118                 },
119                 .compb = {
120                         .enable = AVR_IO_REGBIT(TIMSK, OCIE1B),
121                         .raised = AVR_IO_REGBIT(TIFR, OCF1B),
122                         .vector = TIMER1_COMPB_vect,
123                 },
124         },
125
126
127 };
128 #endif /* SIM_CORENAME */
129
130 #endif /* __SIM_TINYX5_H__ */