simulavr  1.1.0
at8515.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 "at8515.h"
27 
28 #include "hweeprom.h"
29 #include "irqsystem.h"
30 #include "hwstack.h"
31 #include "hwwado.h"
32 #include "hwsreg.h"
33 #include "avrfactory.h"
34 
36 
38  AvrDevice(64, 512, 0xfda0, 8192),
39  portx(this, "X"),
40  porta(this, "A"),
41  portb(this, "B"),
42  portc(this, "C"),
43  portd(this, "D"),
44  ocr1b(portx.GetPin(0)),
45  prescaler(this, "01"),
46  premux0(&prescaler, PinAtPort(&portb, 0)),
47  premux1(&prescaler, PinAtPort(&portb, 1))
48 {
49  flagJMPInstructions = false;
50  flagMULInstructions = false;
51  flagMOVWInstruction = false;
52  fuses->SetFuseConfiguration(2, 0xdf);
53  irqSystem = new HWIrqSystem(this, 2, 13);
54  eeprom= new HWEeprom(this, NULL, 512, 0, HWEeprom::DEVMODE_AT90S); // no irq available
55  stack = new HWStackSram(this, 16);
56 
57  // portx is internaly used for ocr1b and icp, this 2 pins are not gpio!
58  // set DDR Bit 0 to output: ocr1b
59  // set DDT Bit 1 to input: icp
60  portx.SetDdr(0x01);
61 
62  spi= new HWSpi(this, irqSystem, PinAtPort(&portb, 5), PinAtPort(&portb, 6), PinAtPort(&portb, 7), PinAtPort(&portb, 4),/*irqvec*/ 8, false);
63 
64  uart= new HWUart(this, irqSystem, PinAtPort(&portd,1), PinAtPort(&portd, 0),9,10,11) ;
65 
66  wado= new HWWado(this);
67 
68  timer01irq = new TimerIRQRegister(this, irqSystem);
69  timer01irq->registerLine(1, IRQLine("TOV0", 7));
70  timer01irq->registerLine(3, IRQLine("ICF1", 3));
71  timer01irq->registerLine(5, IRQLine("OCF1B", 5));
72  timer01irq->registerLine(6, IRQLine("OCF1A", 4));
73  timer01irq->registerLine(7, IRQLine("TOV1", 6));
74  timer0 = new HWTimer8_0C(this,
75  &premux0,
76  0,
77  timer01irq->getLine("TOV0"));
78  inputCapture1 = new ICaptureSource(PinAtPort(&portx, 1));
79  timer1 = new HWTimer16_2C2(this,
80  &premux1,
81  1,
82  timer01irq->getLine("TOV1"),
83  timer01irq->getLine("OCF1A"),
84  PinAtPort(&portd, 5),
85  timer01irq->getLine("OCF1B"),
86  PinAtPort(&portx, 0),
87  timer01irq->getLine("ICF1"),
88  inputCapture1,
89  true);
90 
91  // analog comparator: no bandgap, no ADC-connection
92  acomp = new HWAcomp(this, irqSystem, PinAtPort(&portb,2), PinAtPort(&portb, 3), 12, NULL, timer1, NULL, NULL, false);
93 
94  gimsk_reg = new IOSpecialReg(&coreTraceGroup, "GIMSK");
95  gifr_reg = new IOSpecialReg(&coreTraceGroup, "GIFR");
96  mcucr_reg = new IOSpecialReg(&coreTraceGroup, "MCUCR");
97  extirq = new ExternalIRQHandler(this, irqSystem, gimsk_reg, gifr_reg);
98  extirq->registerIrq(1, 6, new ExternalIRQSingle(mcucr_reg, 0, 2, GetPin("D2"), true));
99  extirq->registerIrq(2, 7, new ExternalIRQSingle(mcucr_reg, 2, 2, GetPin("D3"), true));
100 
101  rw[0x5f]= statusRegister;
102  rw[0x5e]= & ((HWStackSram *)stack)->sph_reg;
103  rw[0x5d]= & ((HWStackSram *)stack)->spl_reg;
104  // 0x5c reserved
105  rw[0x5b]= gimsk_reg;
106  rw[0x5a]= gifr_reg;
107  rw[0x59]= & timer01irq->timsk_reg;
108  rw[0x58]= & timer01irq->tifr_reg;
109 
110  rw[0x55]= mcucr_reg;
111 
112  rw[0x53]= & timer0->tccr_reg;
113  rw[0x52]= & timer0->tcnt_reg;
114 
115  rw[0x4f]= & timer1->tccra_reg;
116  rw[0x4e]= & timer1->tccrb_reg;
117  rw[0x4d]= & timer1->tcnt_h_reg;
118  rw[0x4c]= & timer1->tcnt_l_reg;
119  rw[0x4b]= & timer1->ocra_h_reg;
120  rw[0x4a]= & timer1->ocra_l_reg;
121  rw[0x49]= & timer1->ocrb_h_reg;
122  rw[0x48]= & timer1->ocrb_l_reg;
123 
124  rw[0x45]= & timer1->icr_h_reg;
125  rw[0x44]= & timer1->icr_l_reg;
126 
127  rw[0x41]= & wado->wdtcr_reg;
128 
129  rw[0x3f]= & eeprom->eearh_reg;
130  rw[0x3e]= & eeprom->eearl_reg;
131  rw[0x3d]= & eeprom->eedr_reg;
132  rw[0x3c]= & eeprom->eecr_reg;
133 
134  rw[0x3b]= & porta.port_reg;
135  rw[0x3a]= & porta.ddr_reg;
136  rw[0x39]= & porta.pin_reg;
137 
138  rw[0x38]= & portb.port_reg;
139  rw[0x37]= & portb.ddr_reg;
140  rw[0x36]= & portb.pin_reg;
141 
142  rw[0x35]= & portc.port_reg;
143  rw[0x34]= & portc.ddr_reg;
144  rw[0x33]= & portc.pin_reg;
145 
146  rw[0x32]= & portd.port_reg;
147  rw[0x31]= & portd.ddr_reg;
148  rw[0x30]= & portd.pin_reg;
149 
150  rw[0x2f]= & spi->spdr_reg;
151  rw[0x2e]= & spi->spsr_reg;
152  rw[0x2d]= & spi->spcr_reg;
153 
154  rw[0x2c]= & uart->udr_reg;
155  rw[0x2b]= & uart->usr_reg;
156  rw[0x2a]= & uart->ucr_reg;
157  rw[0x29]= & uart->ubrr_reg;
158 
159  rw[0x28]= & acomp->acsr_reg;
160 
161  Reset();
162 }
163 
165  delete extirq;
166  delete mcucr_reg;
167  delete gifr_reg;
168  delete gimsk_reg;
169  delete acomp;
170  delete timer1;
171  delete inputCapture1;
172  delete timer0;
173  delete timer01irq;
174  delete wado;
175  delete uart;
176  delete spi;
177  delete stack;
178  delete irqSystem;
179  delete eeprom;
180 }
181 
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
HWTimer16_2C2 * timer1
timer 1 unit
Definition: at8515.h:59
AVRDevice class for AT90S8515.
Definition: at8515.h:39
HWIrqSystem * irqSystem
Definition: avrdevice.h:104
Implements a stack with stack register using RAM as stackarea.
Definition: hwstack.h:131
IOSpecialReg * gimsk_reg
GIMSK IO register.
Definition: at8515.h:61
Definition: hwwado.h:38
ExternalIRQHandler * extirq
external interrupt support
Definition: at8515.h:60
IOSpecialReg * mcucr_reg
MCUCR IO register.
Definition: at8515.h:63
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
IOSpecialReg * gifr_reg
GIFR IO register.
Definition: at8515.h:62
TimerIRQRegister * timer01irq
timer interrupt unit for timer
Definition: at8515.h:56
HWTimer8_0C * timer0
timer 0 unit
Definition: at8515.h:57
HWAcomp * acomp
Definition: at8515.h:52
Timer unit with 16Bit counter and 2 output compare units and 2 config registers.
Definition: hwtimer.h:528
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
#define AVR_REGISTER(name, class)
Definition: avrfactory.h:69
Timer unit with 8Bit counter and no output compare unit.
Definition: hwtimer.h:347
HWSpi * spi
spi unit
Definition: at8515.h:50
HWUart * uart
uart unit
Definition: at8515.h:51
HWStack * stack
Definition: avrdevice.h:131
Class, which provides input capture source for 16bit timers.
Definition: icapturesrc.h:34
ICaptureSource * inputCapture1
input capture source for timer1
Definition: at8515.h:58
HWWado * wado
WDT timer.
Definition: avrdevice.h:134
Implements the I/O hardware necessary to do UART transfers.
Definition: hwuart.h:38
Analog comparator peripheral.
Definition: hwacomp.h:42
External interrupt (INT0, INT1...) on a single pin, one and 2 bit configuration.
Definition: externalirq.h:110