simulavr  1.1.0
at4433.cpp
Go to the documentation of this file.
1  /*
2  ****************************************************************************
3  *
4  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
5  * Copyright (C) 2001, 2002, 2003 Klaus Rudolph
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  ****************************************************************************
22  *
23  * $Id$
24  */
25 
26 #include "at4433.h"
27 
28 #include "irqsystem.h"
29 #include "hweeprom.h"
30 #include "hwstack.h"
31 #include "pinatport.h"
32 #include "hwacomp.h"
33 #include "hwwado.h"
34 #include "avrfactory.h"
35 #include "hwsreg.h"
36 
38 
40  AvrDevice(64, 128, 0, 4*1024),
41  portb(this, "B"),
42  portc(this, "C"),
43  portd(this, "D"),
44  prescaler(this, "01"),
45  premux0(&prescaler, PinAtPort(&portd, 4)),
46  premux1(&prescaler, PinAtPort(&portd, 5))
47 {
48  flagJMPInstructions = false;
49  flagMULInstructions = false;
50  flagMOVWInstruction = false;
51  fuses->SetFuseConfiguration(6, 0xda);
52  v_bandgap.SetAnalogValue(1.22); // reference voltage is 1.22V!
53  irqSystem = new HWIrqSystem(this, 2, 14);
54  eeprom= new HWEeprom(this, irqSystem, 256, 12, HWEeprom::DEVMODE_AT90S);
55  stack = new HWStackSram(this, 8);
56 
57  admux = new HWAdmux6(this, &portc.GetPin(0), &portc.GetPin(1), &portc.GetPin(2),
58  &portc.GetPin(3), &portc.GetPin(4), &portc.GetPin(5));
59  aref = new HWARefPin(this);
60  ad = new HWAd(this, HWAd::AD_4433, irqSystem, 11, admux, aref); // vec 11 ADConversion Complete
61 
62  spi= new HWSpi(this, irqSystem, PinAtPort(&portb, 3), PinAtPort(&portb, 4), PinAtPort(&portb, 5), PinAtPort(&portb, 2),/*irqvec*/ 7, false);
63 
64  uart= new HWUart( this, irqSystem, PinAtPort(&portd,1), PinAtPort(&portd, 0),8,9,10) ;
65 
66  wado= new HWWado(this);
67 
68  timer01irq = new TimerIRQRegister(this, irqSystem);
69  timer01irq->registerLine(1, IRQLine("TOV0", 6));
70  timer01irq->registerLine(3, IRQLine("ICF1", 3));
71  timer01irq->registerLine(6, IRQLine("OCF1", 4));
72  timer01irq->registerLine(7, IRQLine("TOV1", 5));
73  timer0 = new HWTimer8_0C(this,
74  &premux0,
75  0,
76  timer01irq->getLine("TOV0"));
77  inputCapture1 = new ICaptureSource(PinAtPort(&portb, 0));
78  timer1 = new HWTimer16_1C(this,
79  &premux1,
80  1,
81  timer01irq->getLine("TOV1"),
82  timer01irq->getLine("OCF1"),
83  PinAtPort(&portb, 1),
84  timer01irq->getLine("ICF1"),
85  inputCapture1);
86 
87  // analog comparator: no ADC-connection
88  acomp = new HWAcomp(this, irqSystem, PinAtPort(&portd, 6), PinAtPort(&portd, 7), 13, NULL, timer1);
89 
90  gimsk_reg = new IOSpecialReg(&coreTraceGroup, "GIMSK");
91  gifr_reg = new IOSpecialReg(&coreTraceGroup, "GIFR");
92  mcucr_reg = new IOSpecialReg(&coreTraceGroup, "MCUCR");
93  extirq = new ExternalIRQHandler(this, irqSystem, gimsk_reg, gifr_reg);
94  extirq->registerIrq(1, 6, new ExternalIRQSingle(mcucr_reg, 0, 2, GetPin("D2")));
95  extirq->registerIrq(2, 7, new ExternalIRQSingle(mcucr_reg, 2, 2, GetPin("D3")));
96 
97  rw[0x5f]= statusRegister;
98  rw[0x5e]= & ((HWStackSram *)stack)->sph_reg; // TODO datasheet: doesn't exist!
99  rw[0x5d]= & ((HWStackSram *)stack)->spl_reg;
100 
101  rw[0x5b]= gimsk_reg;
102  rw[0x5a]= gifr_reg;
103  rw[0x59]= & timer01irq->timsk_reg;
104  rw[0x58]= & timer01irq->tifr_reg;
105 
106  rw[0x55]= mcucr_reg;
107 
108  //0x54: MCUSR reset status flag (reset, wado, brown out...) //TODO XXX
109 
110  rw[0x53]= & timer0->tccr_reg;
111  rw[0x52]= & timer0->tcnt_reg;
112 
113  rw[0x4f]= & timer1->tccra_reg;
114  rw[0x4e]= & timer1->tccrb_reg;
115  rw[0x4d]= & timer1->tcnt_h_reg;
116  rw[0x4c]= & timer1->tcnt_l_reg;
117  rw[0x4b]= & timer1->ocra_h_reg;
118  rw[0x4a]= & timer1->ocra_l_reg;
119  // 0x49, 0x48 reserved
120  rw[0x47]= & timer1->icr_h_reg;
121  rw[0x46]= & timer1->icr_l_reg;
122 
123  rw[0x41]= & wado->wdtcr_reg;
124 
125  rw[0x3f]= & eeprom->eearh_reg; // register normally reserved, but used by avr-libc!
126  rw[0x3e]= & eeprom->eearl_reg;
127  rw[0x3d]= & eeprom->eedr_reg;
128  rw[0x3c]= & eeprom->eecr_reg;
129 
130  // 0x3b-0x39: no port a here
131 
132  rw[0x38]= & portb.port_reg;
133  rw[0x37]= & portb.ddr_reg;
134  rw[0x36]= & portb.pin_reg;
135 
136  rw[0x35]= & portc.port_reg;
137  rw[0x34]= & portc.ddr_reg;
138  rw[0x33]= & portc.pin_reg;
139 
140  rw[0x32]= & portd.port_reg;
141  rw[0x31]= & portd.ddr_reg;
142  rw[0x30]= & portd.pin_reg;
143 
144  rw[0x2f]= & spi->spdr_reg;
145  rw[0x2e]= & spi->spsr_reg;
146  rw[0x2d]= & spi->spcr_reg;
147 
148  rw[0x2c]= & uart->udr_reg;
149  rw[0x2b]= & uart->usr_reg;
150  rw[0x2a]= & uart->ucr_reg;
151  rw[0x29]= & uart->ubrr_reg;
152 
153  rw[0x28]= & acomp->acsr_reg;
154 
155  rw[0x27]= & ad->admux_reg;
156  rw[0x26]= & ad->adcsra_reg;
157  rw[0x25]= & ad->adch_reg;
158  rw[0x24]= & ad->adcl_reg;
159 
160  rw[0x23]= & uart->ubrrhi_reg;
161 
162  Reset();
163 }
164 
166  delete extirq;
167  delete mcucr_reg;
168  delete gifr_reg;
169  delete gimsk_reg;
170  delete acomp;
171  delete timer1;
172  delete inputCapture1;
173  delete timer0;
174  delete timer01irq;
175  delete wado;
176  delete uart;
177  delete spi;
178  delete ad;
179  delete aref;
180  delete admux;
181  delete stack;
182  delete eeprom;
183  delete irqSystem;
184 }
185 
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
HWARef * aref
adc reference unit
Definition: at4433.h:48
HWSpi * spi
spi unit
Definition: at4433.h:50
IOSpecialReg * gifr_reg
GIFR IO register.
Definition: at4433.h:62
HWAcomp * acomp
Definition: at4433.h:52
HWIrqSystem * irqSystem
Definition: avrdevice.h:104
Implements a stack with stack register using RAM as stackarea.
Definition: hwstack.h:131
ADC reference is taken from special ADREF pin (no port pin)
Definition: hwad.h:48
HWUart * uart
uart unit
Definition: at4433.h:51
Definition: hwwado.h:38
Handler for external IRQ's to communicate with IRQ system and mask/flag registers.
Definition: externalirq.h:41
Represents a timer interrupt line, Frontend for timer interrupts.
Definition: timerirq.h:42
HWAd * ad
adc unit
Definition: at4433.h:49
HWTimer8_0C * timer0
timer 0 unit
Definition: at4433.h:57
HWAdmux * admux
adc multiplexer unit
Definition: at4433.h:47
IOSpecialReg * gimsk_reg
GIMSK IO register.
Definition: at4433.h:61
Provices flag and mask register for timer interrupts and connects irq lines to irqsystem.
Definition: timerirq.h:61
HWEeprom * eeprom
Definition: avrdevice.h:102
Definition: hwspi.h:38
Definition: hwad.h:118
ADC type 4433: ADC on at90s/l4433.
Definition: hwad.h:258
IOSpecialReg * mcucr_reg
MCUCR IO register.
Definition: at4433.h:63
#define AVR_REGISTER(name, class)
Definition: avrfactory.h:69
HWTimer16_1C * timer1
timer 1 unit
Definition: at4433.h:59
ExternalIRQHandler * extirq
external interrupt support
Definition: at4433.h:60
Timer unit with 16Bit counter and one output compare unit.
Definition: hwtimer.h:470
Timer unit with 8Bit counter and no output compare unit.
Definition: hwtimer.h:347
HWStack * stack
Definition: avrdevice.h:131
Class, which provides input capture source for 16bit timers.
Definition: icapturesrc.h:34
HWWado * wado
WDT timer.
Definition: avrdevice.h:134
Definition: hwad.h:204
Implements the I/O hardware necessary to do UART transfers.
Definition: hwuart.h:38
AVRDevice class for AT90S4433.
Definition: at4433.h:41
Analog comparator peripheral.
Definition: hwacomp.h:42
TimerIRQRegister * timer01irq
timer interrupt unit for timer
Definition: at4433.h:56
External interrupt (INT0, INT1...) on a single pin, one and 2 bit configuration.
Definition: externalirq.h:110
ICaptureSource * inputCapture1
input capture source for timer1
Definition: at4433.h:58