SimAVR
AVR Simulator
sim_tinyx5.h
Go to the documentation of this file.
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_watchdog.h"
30 #include "avr_extint.h"
31 #include "avr_ioport.h"
32 #include "avr_adc.h"
33 #include "avr_timer.h"
34 
35 void tx5_init(struct avr_t * avr);
36 void tx5_reset(struct avr_t * avr);
37 
38 /*
39  * This is a template for all of the tinyx5 devices, hopefully
40  */
41 struct mcu_t {
42  avr_t core;
47  avr_adc_t adc;
49 };
50 
51 #ifdef SIM_CORENAME
52 
53 #ifndef SIM_VECTOR_SIZE
54 #error SIM_VECTOR_SIZE is not declared
55 #endif
56 #ifndef SIM_MMCU
57 #error SIM_MMCU is not declared
58 #endif
59 
60 const struct mcu_t SIM_CORENAME = {
61  .core = {
62  .mmcu = SIM_MMCU,
64 
65  .init = tx5_init,
66  .reset = tx5_reset,
67  },
68  AVR_EEPROM_DECLARE(EE_RDY_vect),
69  AVR_WATCHDOG_DECLARE(WDTCR, WDT_vect),
70  .extint = {
71  AVR_EXTINT_TINY_DECLARE(0, 'B', PB2, GIFR),
72  },
73  .portb = {
74  .name = 'B', .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
75  .pcint = {
76  .enable = AVR_IO_REGBIT(GIMSK, PCIE),
77  .raised = AVR_IO_REGBIT(GIFR, PCIF),
78  .vector = PCINT0_vect,
79  },
80  .r_pcint = PCMSK,
81  },
82  .adc = {
83  .r_admux = ADMUX,
84  .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1),
85  AVR_IO_REGBIT(ADMUX, MUX2), AVR_IO_REGBIT(ADMUX, MUX3),},
86  .ref = { AVR_IO_REGBIT(ADMUX, REFS0), AVR_IO_REGBIT(ADMUX, REFS1), AVR_IO_REGBIT(ADMUX, REFS2), },
87  .ref_values = {
88  [0] = ADC_VREF_VCC, [1] = ADC_VREF_AVCC,
89  [2] = ADC_VREF_V110, [5] = ADC_VREF_V256,
90  [6] = ADC_VREF_V256,
91  },
92 
93  .adlar = AVR_IO_REGBIT(ADMUX, ADLAR),
94  .r_adcsra = ADCSRA,
95  .aden = AVR_IO_REGBIT(ADCSRA, ADEN),
96  .adsc = AVR_IO_REGBIT(ADCSRA, ADSC),
97  .adate = AVR_IO_REGBIT(ADCSRA, ADATE),
98  .adps = { AVR_IO_REGBIT(ADCSRA, ADPS0), AVR_IO_REGBIT(ADCSRA, ADPS1), AVR_IO_REGBIT(ADCSRA, ADPS2),},
99 
100  .r_adch = ADCH,
101  .r_adcl = ADCL,
102 
103  .r_adcsrb = ADCSRB,
104  .adts = { AVR_IO_REGBIT(ADCSRB, ADTS0), AVR_IO_REGBIT(ADCSRB, ADTS1), AVR_IO_REGBIT(ADCSRB, ADTS2),},
105  .adts_op = {
106  [0] = avr_adts_free_running,
113  },
114 
115  .bin = AVR_IO_REGBIT(ADCSRB, BIN),
116  .ipr = AVR_IO_REGBIT(ADCSRA, IPR),
117 
118  .muxmode = {
119  [0] = AVR_ADC_SINGLE(0), [1] = AVR_ADC_SINGLE(1),
120  [2] = AVR_ADC_SINGLE(2), [3] = AVR_ADC_SINGLE(3),
121 
122  [ 4] = AVR_ADC_DIFF(2, 2, 1), [ 5] = AVR_ADC_DIFF(2, 2, 20),
123  [ 6] = AVR_ADC_DIFF(2, 3, 1), [ 7] = AVR_ADC_DIFF(2, 3, 20),
124  [ 8] = AVR_ADC_DIFF(0, 0, 1), [ 9] = AVR_ADC_DIFF(0, 0, 20),
125  [10] = AVR_ADC_DIFF(0, 1, 1), [11] = AVR_ADC_DIFF(0, 1, 20),
126  [12] = AVR_ADC_REF(1100), // Vbg
127  [13] = AVR_ADC_REF(0), // GND
128  [15] = AVR_ADC_TEMP(),
129  },
130 
131  .adc = {
132  .enable = AVR_IO_REGBIT(ADCSRA, ADIE),
133  .raised = AVR_IO_REGBIT(ADCSRA, ADIF),
134  .vector = ADC_vect,
135  },
136  },
137  .timer0 = {
138  .name = '0',
139  .wgm = { AVR_IO_REGBIT(TCCR0A, WGM00), AVR_IO_REGBIT(TCCR0A, WGM01), AVR_IO_REGBIT(TCCR0B, WGM02) },
140  .wgm_op = {
141  [0] = AVR_TIMER_WGM_NORMAL8(),
142  [2] = AVR_TIMER_WGM_CTC(),
143  [3] = AVR_TIMER_WGM_FASTPWM8(),
144  [7] = AVR_TIMER_WGM_OCPWM(),
145  },
146  .cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
147  .cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */ },
148 
149  .r_tcnt = TCNT0,
150 
151  .overflow = {
152  .enable = AVR_IO_REGBIT(TIMSK, TOIE0),
153  .raised = AVR_IO_REGBIT(TIFR, TOV0),
154  .vector = TIMER0_OVF_vect,
155  },
156  .comp = {
157  [AVR_TIMER_COMPA] = {
158  .r_ocr = OCR0A,
159  .com = AVR_IO_REGBITS(TCCR0A, COM0A0, 0x3),
160  .com_pin = AVR_IO_REGBIT(PORTB, 0),
161  .interrupt = {
162  .enable = AVR_IO_REGBIT(TIMSK, OCIE0A),
163  .raised = AVR_IO_REGBIT(TIFR, OCF0A),
164  .vector = TIMER0_COMPA_vect,
165  },
166  },
167  [AVR_TIMER_COMPB] = {
168  .r_ocr = OCR0B,
169  .com = AVR_IO_REGBITS(TCCR0A, COM0B0, 0x3),
170  .com_pin = AVR_IO_REGBIT(PORTB, 1),
171  .interrupt = {
172  .enable = AVR_IO_REGBIT(TIMSK, OCIE0B),
173  .raised = AVR_IO_REGBIT(TIFR, OCF0B),
174  .vector = TIMER0_COMPB_vect,
175  },
176  },
177  },
178  },
179  .timer1 = {
180  .name = '1',
181  // no wgm bits
182  .cs = { AVR_IO_REGBIT(TCCR1, CS10), AVR_IO_REGBIT(TCCR1, CS11), AVR_IO_REGBIT(TCCR1, CS12), AVR_IO_REGBIT(TCCR1, CS13) },
183  .cs_div = { 0, 0, 1 /* 2 */, 2 /* 4 */, 3 /* 8 */, 4 /* 16 */ },
184 
185  .r_tcnt = TCNT1,
186 
187  .overflow = {
188  .enable = AVR_IO_REGBIT(TIMSK, TOIE1),
189  .raised = AVR_IO_REGBIT(TIFR, TOV1),
190  .vector = TIMER1_OVF_vect,
191  },
192  .comp = {
193  [AVR_TIMER_COMPA] = {
194  .r_ocr = OCR1A,
195  .com = AVR_IO_REGBITS(TCCR1, COM1A0, 0x3),
196  .com_pin = AVR_IO_REGBIT(PORTB, 1),
197  .interrupt = {
198  .enable = AVR_IO_REGBIT(TIMSK, OCIE1A),
199  .raised = AVR_IO_REGBIT(TIFR, OCF1A),
200  .vector = TIMER1_COMPA_vect,
201  },
202  },
203  [AVR_TIMER_COMPB] = {
204  .r_ocr = OCR1B,
205  .com = AVR_IO_REGBITS(GTCCR, COM1B0, 0x3),
206  .com_pin = AVR_IO_REGBIT(PORTB, 4),
207  .interrupt = {
208  .enable = AVR_IO_REGBIT(TIMSK, OCIE1B),
209  .raised = AVR_IO_REGBIT(TIFR, OCF1B),
210  .vector = TIMER1_COMPB_vect,
211  },
212  },
213  [AVR_TIMER_COMPC] = {
214  .r_ocr = OCR1C,
215  },
216  },
217  },
218 };
219 #endif /* SIM_CORENAME */
220 
221 #endif /* __SIM_TINYX5_H__ */
Definition: avr_adc.h:81
Definition: avr_adc.h:97
#define AVR_TIMER_WGM_NORMAL8()
Definition: avr_timer.h:87
Definition: avr_watchdog.h:35
avr_eeprom_t eeprom
Definition: sim_90usb162.c:42
#define SIM_MMCU
Definition: sim_mega324.c:24
#define SIM_CORENAME
Definition: sim_mega324.c:25
#define AVR_EXTINT_TINY_DECLARE(_index, _portname, _portpin, _IFR)
Definition: avr_extint.h:115
Definition: avr_adc.h:102
void tx5_init(struct avr_t *avr)
Definition: sim_tinyx5.c:27
avr_ioport_t portb
Definition: sim_90usb162.c:46
#define AVR_ADC_REF(_t)
Definition: avr_adc.h:166
Definition: avr_adc.h:90
avr_t * avr
Definition: run_avr.c:54
#define AVR_ADC_SINGLE(_chan)
Definition: avr_adc.h:154
Definition: avr_adc.h:91
#define AVR_TIMER_WGM_FASTPWM8()
Definition: avr_timer.h:91
default mode
Definition: avr_adc.h:80
Definition: avr_timer.h:39
Definition: avr_adc.h:95
#define AVR_ADC_TEMP()
Definition: avr_adc.h:171
Definition: avr_adc.h:83
This module is just a "relay" for the pin change IRQ in the IO port module.
Definition: avr_extint.h:56
avr_adc_t adc
Definition: sim_mega128.c:53
#define AVR_TIMER_WGM_CTC()
Definition: avr_timer.h:89
avr_watchdog_t watchdog
Definition: sim_90usb162.c:44
Definition: sim_90usb162.c:40
Definition: avr_eeprom.h:35
avr_t core
Definition: sim_90usb162.c:41
#define DEFAULT_CORE(_vector_size)
Definition: sim_core_declare.h:52
Definition: avr_timer.h:37
Definition: avr_timer.h:111
avr_timer_t timer0
Definition: sim_90usb162.c:48
#define AVR_IO_REGBITS(_io, _bit, _mask)
Definition: sim_regbit.h:153
#define AVR_EEPROM_DECLARE(_vector)
The eeprom block seems to be very similar across AVRs, so here is a macro to declare a "typical" one ...
Definition: avr_eeprom.h:70
avr_timer_t timer1
Definition: sim_90usb162.c:48
Definition: avr_adc.h:108
#define AVR_TIMER_WGM_OCPWM()
Definition: avr_timer.h:97
Definition: avr_adc.h:98
Definition: avr_timer.h:38
#define SIM_VECTOR_SIZE
Definition: sim_mega16.c:26
#define AVR_WATCHDOG_DECLARE(_WDSR, _vec)
This helps declare a watchdog block into a core.
Definition: avr_watchdog.h:66
Definition: avr_adc.h:96
Main AVR instance.
Definition: sim_avr.h:142
avr_extint_t extint
Definition: sim_90usb162.c:45
#define AVR_ADC_DIFF(_a, _b, _g)
Definition: avr_adc.h:159
#define AVR_IO_REGBIT(_io, _bit)
Definition: sim_regbit.h:150
Definition: avr_adc.h:82
void tx5_reset(struct avr_t *avr)
Definition: sim_tinyx5.c:40
Definition for an IO port.
Definition: avr_ioport.h:97