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