GDB working, some more source massaging
[simavr] / simavr / cores / sim_megax8.h
1 /*
2         sim_megax8.h
3
4         Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
5
6         This file is part of simavr.
7
8         simavr is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 3 of the License, or
11         (at your option) any later version.
12
13         simavr is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #ifndef __SIM_MEGAX8_H__
24 #define __SIM_MEGAX8_H__
25
26 #include "sim_core_declare.h"
27 #include "avr_eeprom.h"
28 #include "avr_ioport.h"
29 #include "avr_uart.h"
30 #include "avr_timer8.h"
31 #include "avr_spi.h"
32
33 void mx8_init(struct avr_t * avr);
34 void mx8_reset(struct avr_t * avr);
35
36 /*
37  * This is a template for all of the x8 devices, hopefuly
38  */
39 struct mcu_t {
40         avr_t core;
41         avr_eeprom_t    eeprom;
42         avr_ioport_t    portb,portc,portd;
43         avr_uart_t              uart;
44         avr_timer8_t    timer0,timer2;
45         avr_spi_t               spi;
46 };
47
48 #ifdef SIM_CORENAME
49
50 #ifndef SIM_VECTOR_SIZE
51 #error SIM_VECTOR_SIZE is not declared
52 #endif
53 #ifndef SIM_MMCU
54 #error SIM_MMCU is not declared
55 #endif
56
57 struct mcu_t SIM_CORENAME = {
58         .core = {
59                 .mmcu = SIM_MMCU,
60                 DEFAULT_CORE(SIM_VECTOR_SIZE),
61
62                 .init = mx8_init,
63                 .reset = mx8_reset,
64         },
65         AVR_EEPROM_DECLARE(EE_READY_vect),
66         .portb = {
67                 .name = 'B', .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
68                 .pcint = {
69                         .enable = AVR_IO_REGBIT(PCICR, PCIE0),
70                         .raised = AVR_IO_REGBIT(PCIFR, PCIF0),
71                         .vector = PCINT0_vect,
72                 },
73                 .r_pcint = PCMSK0,
74         },
75         .portc = {
76                 .name = 'C', .r_port = PORTC, .r_ddr = DDRC, .r_pin = PINC,
77                 .pcint = {
78                         .enable = AVR_IO_REGBIT(PCICR, PCIE1),
79                         .raised = AVR_IO_REGBIT(PCIFR, PCIF1),
80                         .vector = PCINT1_vect,
81                 },
82                 .r_pcint = PCMSK1,
83         },
84         .portd = {
85                 .name = 'D', .r_port = PORTD, .r_ddr = DDRD, .r_pin = PIND,
86                 .pcint = {
87                         .enable = AVR_IO_REGBIT(PCICR, PCIE2),
88                         .raised = AVR_IO_REGBIT(PCIFR, PCIF2),
89                         .vector = PCINT2_vect,
90                 },
91                 .r_pcint = PCMSK2,
92         },
93
94         .uart = {
95                 .disabled = AVR_IO_REGBIT(PRR,PRUSART0),
96                 .name = '0',
97                 .r_udr = UDR0,
98
99                 .txen = AVR_IO_REGBIT(UCSR0B, TXEN0),
100                 .rxen = AVR_IO_REGBIT(UCSR0B, RXEN0),
101
102                 .r_ucsra = UCSR0A,
103                 .r_ucsrb = UCSR0B,
104                 .r_ucsrc = UCSR0C,
105                 .r_ubrrl = UBRR0L,
106                 .r_ubrrh = UBRR0H,
107                 .rxc = {
108                         .enable = AVR_IO_REGBIT(UCSR0B, RXCIE0),
109                         .raised = AVR_IO_REGBIT(UCSR0A, RXC0),
110                         .vector = USART_RX_vect,
111                 },
112                 .txc = {
113                         .enable = AVR_IO_REGBIT(UCSR0B, TXCIE0),
114                         .raised = AVR_IO_REGBIT(UCSR0A, TXC0),
115                         .vector = USART_TX_vect,
116                 },
117                 .udrc = {
118                         .enable = AVR_IO_REGBIT(UCSR0B, UDRIE0),
119                         .raised = AVR_IO_REGBIT(UCSR0A, UDRE0),
120                         .vector = USART_UDRE_vect,
121                 },
122         },
123
124         .timer0 = {
125                 .name = '0',
126                 .disabled = AVR_IO_REGBIT(PRR,PRTIM0),
127                 .wgm = { AVR_IO_REGBIT(TCCR0A, WGM00), AVR_IO_REGBIT(TCCR0A, WGM01), AVR_IO_REGBIT(TCCR0B, WGM02) },
128                 .cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
129                 .cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */ },
130
131                 .r_ocra = OCR0A,
132                 .r_ocrb = OCR0B,
133                 .r_tcnt = TCNT0,
134
135                 .overflow = {
136                         .enable = AVR_IO_REGBIT(TIMSK0, TOIE0),
137                         .raised = AVR_IO_REGBIT(TIFR0, TOV0),
138                         .vector = TIMER0_OVF_vect,
139                 },
140                 .compa = {
141                         .enable = AVR_IO_REGBIT(TIMSK0, OCIE0A),
142                         .raised = AVR_IO_REGBIT(TIFR0, OCF0A),
143                         .vector = TIMER0_COMPA_vect,
144                 },
145                 .compb = {
146                         .enable = AVR_IO_REGBIT(TIMSK0, OCIE0B),
147                         .raised = AVR_IO_REGBIT(TIFR0, OCF0B),
148                         .vector = TIMER0_COMPB_vect,
149                 },
150         },
151         .timer2 = {
152                 .name = '2',
153                 .disabled = AVR_IO_REGBIT(PRR,PRTIM2),
154                 .wgm = { AVR_IO_REGBIT(TCCR2A, WGM20), AVR_IO_REGBIT(TCCR2A, WGM21), AVR_IO_REGBIT(TCCR2B, WGM22) },
155                 .cs = { AVR_IO_REGBIT(TCCR2B, CS20), AVR_IO_REGBIT(TCCR2B, CS21), AVR_IO_REGBIT(TCCR2B, CS22) },
156                 .cs_div = { 0, 0, 3 /* 8 */, 5 /* 32 */, 6 /* 64 */, 7 /* 128 */, 8 /* 256 */, 10 /* 1024 */ },
157
158                 .r_ocra = OCR2A,
159                 .r_ocrb = OCR2B,
160                 .r_tcnt = TCNT2,
161                 
162                 // asynchronous timer source bit.. if set, use 32khz frequency
163                 .as2 = AVR_IO_REGBIT(ASSR, AS2),
164                 
165                 .overflow = {
166                         .enable = AVR_IO_REGBIT(TIMSK2, TOIE2),
167                         .raised = AVR_IO_REGBIT(TIFR2, TOV2),
168                         .vector = TIMER2_OVF_vect,
169                 },
170                 .compa = {
171                         .enable = AVR_IO_REGBIT(TIMSK2, OCIE2A),
172                         .raised = AVR_IO_REGBIT(TIFR2, OCF2A),
173                         .vector = TIMER2_COMPA_vect,
174                 },
175                 .compb = {
176                         .enable = AVR_IO_REGBIT(TIMSK2, OCIE2B),
177                         .raised = AVR_IO_REGBIT(TIFR2, OCF2B),
178                         .vector = TIMER2_COMPB_vect,
179                 },
180         },
181         
182         .spi = {
183                 .disabled = AVR_IO_REGBIT(PRR,PRSPI),
184
185                 .r_spdr = SPDR,
186                 .r_spcr = SPCR,
187                 .r_spsr = SPSR,
188
189                 .spe = AVR_IO_REGBIT(SPCR, SPE),
190                 .mstr = AVR_IO_REGBIT(SPCR, MSTR),
191
192                 .spr = { AVR_IO_REGBIT(SPCR, SPR0), AVR_IO_REGBIT(SPCR, SPR1), AVR_IO_REGBIT(SPSR, SPI2X) },
193                 .spi = {
194                         .enable = AVR_IO_REGBIT(SPCR, SPIE),
195                         .raised = AVR_IO_REGBIT(SPSR, SPIF),
196                         .vector = SPI_STC_vect,
197                 },
198         },
199 };
200 #endif /* SIM_CORENAME */
201
202 #endif /* __SIM_MEGAX8_H__ */