00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "atmega668base.h"
00024
00025 #include "irqsystem.h"
00026 #include "hwstack.h"
00027 #include "hweeprom.h"
00028 #include "hwwado.h"
00029 #include "hwsreg.h"
00030 #include "avrerror.h"
00031 #include "avrfactory.h"
00032
00033 AVR_REGISTER(atmega48, AvrDevice_atmega48);
00034 AVR_REGISTER(atmega88, AvrDevice_atmega88);
00035 AVR_REGISTER(atmega168, AvrDevice_atmega168);
00036 AVR_REGISTER(atmega328, AvrDevice_atmega328);
00037
00038 AvrDevice_atmega668base::~AvrDevice_atmega668base() {
00039 delete usart0;
00040 delete wado;
00041 delete spi;
00042 delete ad;
00043 delete gpior2_reg;
00044 delete gpior1_reg;
00045 delete gpior0_reg;
00046 delete timer2;
00047 delete timerIrq2;
00048 delete timer1;
00049 delete inputCapture1;
00050 delete timerIrq1;
00051 delete timer0;
00052 delete timerIrq0;
00053 delete extirqpc;
00054 delete pcmsk2_reg;
00055 delete pcmsk1_reg;
00056 delete pcmsk0_reg;
00057 delete pcifr_reg;
00058 delete pcicr_reg;
00059 delete extirq01;
00060 delete eifr_reg;
00061 delete eimsk_reg;
00062 delete eicra_reg;
00063 delete stack;
00064 delete eeprom;
00065 delete irqSystem;
00066 }
00067
00068 AvrDevice_atmega668base::AvrDevice_atmega668base(unsigned ram_bytes,
00069 unsigned flash_bytes,
00070 unsigned ee_bytes ):
00071 AvrDevice(224,
00072 ram_bytes,
00073 0,
00074 flash_bytes),
00075 aref(),
00076 adc6(),
00077 adc7(),
00078 portb(this, "B", true),
00079 portc(this, "C", true, 7),
00080 portd(this, "D", true),
00081 assr_reg(&coreTraceGroup, "ASSR"),
00082 gtccr_reg(&coreTraceGroup, "GTCCR"),
00083 prescaler01(this, "01", >ccr_reg, 0, 7),
00084 prescaler2(this, "2", PinAtPort(&portb, 6), &assr_reg, 5, >ccr_reg, 1, 7),
00085 admux(this,
00086 &portc.GetPin(0),
00087 &portc.GetPin(1),
00088 &portc.GetPin(2),
00089 &portc.GetPin(3),
00090 &portc.GetPin(4),
00091 &portc.GetPin(5),
00092 &adc6,
00093 &adc7)
00094 {
00095 flagJMPInstructions = (flash_bytes > 8U * 1024U) ? true : false;
00096 irqSystem = new HWIrqSystem(this, (flash_bytes > 8U * 1024U) ? 4 : 2, 26);
00097
00098 eeprom = new HWEeprom(this, irqSystem, ee_bytes, 23, HWEeprom::DEVMODE_EXTENDED);
00099 stack = new HWStackSram(this, 16);
00100
00101 RegisterPin("AREF", &aref);
00102 RegisterPin("ADC6", &adc6);
00103 RegisterPin("ADC7", &adc7);
00104
00105 eicra_reg = new IOSpecialReg(&coreTraceGroup, "EICRA");
00106 eimsk_reg = new IOSpecialReg(&coreTraceGroup, "EIMSK");
00107 eifr_reg = new IOSpecialReg(&coreTraceGroup, "EIFR");
00108 extirq01 = new ExternalIRQHandler(this, irqSystem, eimsk_reg, eifr_reg);
00109 extirq01->registerIrq(1, 0, new ExternalIRQSingle(eicra_reg, 0, 2, GetPin("D2")));
00110 extirq01->registerIrq(2, 1, new ExternalIRQSingle(eicra_reg, 2, 2, GetPin("D3")));
00111
00112 pcicr_reg = new IOSpecialReg(&coreTraceGroup, "PCICR");
00113 pcifr_reg = new IOSpecialReg(&coreTraceGroup, "PCIFR");
00114 pcmsk0_reg = new IOSpecialReg(&coreTraceGroup, "PCMSK0");
00115 pcmsk1_reg = new IOSpecialReg(&coreTraceGroup, "PCMSK1");
00116 pcmsk2_reg = new IOSpecialReg(&coreTraceGroup, "PCMSK2");
00117 extirqpc = new ExternalIRQHandler(this, irqSystem, pcicr_reg, pcifr_reg);
00118 extirqpc->registerIrq(3, 0, new ExternalIRQPort(pcmsk0_reg, &portb));
00119 extirqpc->registerIrq(4, 1, new ExternalIRQPort(pcmsk1_reg, &portc));
00120 extirqpc->registerIrq(5, 2, new ExternalIRQPort(pcmsk2_reg, &portd));
00121
00122 timerIrq0 = new TimerIRQRegister(this, irqSystem, 0);
00123 timerIrq0->registerLine(0, new IRQLine("TOV0", 16));
00124 timerIrq0->registerLine(1, new IRQLine("OCF0A", 14));
00125 timerIrq0->registerLine(2, new IRQLine("OCF0B", 15));
00126
00127 timer0 = new HWTimer8_2C(this,
00128 new PrescalerMultiplexerExt(&prescaler01, PinAtPort(&portd, 4)),
00129 0,
00130 timerIrq0->getLine("TOV0"),
00131 timerIrq0->getLine("OCF0A"),
00132 new PinAtPort(&portd, 6),
00133 timerIrq0->getLine("OCF0B"),
00134 new PinAtPort(&portd, 5));
00135
00136 timerIrq1 = new TimerIRQRegister(this, irqSystem, 1);
00137 timerIrq1->registerLine(0, new IRQLine("TOV1", 13));
00138 timerIrq1->registerLine(1, new IRQLine("OCF1A", 11));
00139 timerIrq1->registerLine(2, new IRQLine("OCF1B", 12));
00140 timerIrq1->registerLine(5, new IRQLine("ICF1", 10));
00141
00142 inputCapture1 = new ICaptureSource(PinAtPort(&portb, 0));
00143 timer1 = new HWTimer16_2C3(this,
00144 new PrescalerMultiplexerExt(&prescaler01, PinAtPort(&portd, 5)),
00145 1,
00146 timerIrq1->getLine("TOV1"),
00147 timerIrq1->getLine("OCF1A"),
00148 new PinAtPort(&portb, 1),
00149 timerIrq1->getLine("OCF1B"),
00150 new PinAtPort(&portb, 2),
00151 timerIrq1->getLine("ICF1"),
00152 inputCapture1);
00153
00154 timerIrq2 = new TimerIRQRegister(this, irqSystem, 2);
00155 timerIrq2->registerLine(0, new IRQLine("TOV2", 9));
00156 timerIrq2->registerLine(1, new IRQLine("OCF2A", 7));
00157 timerIrq2->registerLine(2, new IRQLine("OCF2B", 8));
00158
00159 timer2 = new HWTimer8_2C(this,
00160 new PrescalerMultiplexer(&prescaler2),
00161 2,
00162 timerIrq2->getLine("TOV2"),
00163 timerIrq2->getLine("OCF2A"),
00164 new PinAtPort(&portb, 3),
00165 timerIrq2->getLine("OCF2B"),
00166 new PinAtPort(&portd, 3));
00167
00168 gpior0_reg = new GPIORegister(this, &coreTraceGroup, "GPIOR0");
00169 gpior1_reg = new GPIORegister(this, &coreTraceGroup, "GPIOR1");
00170 gpior2_reg = new GPIORegister(this, &coreTraceGroup, "GPIOR2");
00171
00172 ad = new HWAd(this, &admux, irqSystem, aref, 21);
00173 spi = new HWSpi(this,
00174 irqSystem,
00175 PinAtPort(&portb, 3),
00176 PinAtPort(&portb, 4),
00177 PinAtPort(&portb, 5),
00178 PinAtPort(&portb, 2),
00179 17,
00180 true);
00181
00182 wado = new HWWado(this);
00183
00184 usart0 = new HWUsart(this,
00185 irqSystem,
00186 PinAtPort(&portd,1),
00187 PinAtPort(&portd,0),
00188 PinAtPort(&portd, 4),
00189 18,
00190 19,
00191 20);
00192
00193 rw[0xE6]= new NotSimulatedRegister("UDR0 register is placed 0xC6!");
00194 rw[0xE4]= new NotSimulatedRegister("UBRR0L register is placed 0xC4!");
00195 rw[0xE1]= new NotSimulatedRegister("UCSR0B register is placed 0xC1!");
00196 rw[0xE1]= new NotSimulatedRegister("UCSR0A register is placed 0xC0!");
00197 rw[0xC6]= & usart0->udr_reg;
00198 rw[0xC5]= & usart0->ubrrhi_reg;
00199 rw[0xC4]= & usart0->ubrr_reg;
00200
00201 rw[0xC2]= & usart0->ucsrc_reg;
00202 rw[0xC1]= & usart0->ucsrb_reg;
00203 rw[0xC0]= & usart0->ucsra_reg;
00204
00205 rw[0xBD]= new NotSimulatedRegister("TWI register TWAMR not simulated");
00206 rw[0xBC]= new NotSimulatedRegister("TWI register TWCR not simulated");
00207 rw[0xBB]= new NotSimulatedRegister("TWI register TWDR not simulated");
00208 rw[0xBA]= new NotSimulatedRegister("TWI register TWAR not simulated");
00209 rw[0xB9]= new NotSimulatedRegister("TWI register TWSR not simulated");
00210 rw[0xB8]= new NotSimulatedRegister("TWI register TWBR not simulated");
00211
00212 rw[0xb6]= & assr_reg;
00213
00214 rw[0xb4]= & timer2->ocrb_reg;
00215 rw[0xb3]= & timer2->ocra_reg;
00216 rw[0xb2]= & timer2->tcnt_reg;
00217 rw[0xb1]= & timer2->tccrb_reg;
00218 rw[0xb0]= & timer2->tccra_reg;
00219
00220 rw[0x8b]= & timer1->ocrb_h_reg;
00221 rw[0x8a]= & timer1->ocrb_l_reg;
00222 rw[0x89]= & timer1->ocra_h_reg;
00223 rw[0x88]= & timer1->ocra_l_reg;
00224 rw[0x87]= & timer1->icr_h_reg;
00225 rw[0x86]= & timer1->icr_l_reg;
00226 rw[0x85]= & timer1->tcnt_h_reg;
00227 rw[0x84]= & timer1->tcnt_l_reg;
00228
00229 rw[0x82]= & timer1->tccrc_reg;
00230 rw[0x81]= & timer1->tccrb_reg;
00231 rw[0x80]= & timer1->tccra_reg;
00232 rw[0x7F]= new NotSimulatedRegister("ADC register DIDR1 not simulated");
00233 rw[0x7E]= new NotSimulatedRegister("ADC register DIDR0 not simulated");
00234
00235 rw[0x7C]= & admux.admux_reg;
00236 rw[0x7B]= new NotSimulatedRegister("ADC register ADCSRB not simulated");
00237 rw[0x7A]= & ad->adcsr_reg;
00238 rw[0x79]= & ad->adch_reg;
00239 rw[0x78]= & ad->adcl_reg;
00240
00241 rw[0x70]= & timerIrq2->timsk_reg;
00242 rw[0x6F]= & timerIrq1->timsk_reg;
00243 rw[0x6E]= & timerIrq0->timsk_reg;
00244
00245 rw[0x6d]= pcmsk2_reg;
00246 rw[0x6c]= pcmsk1_reg;
00247 rw[0x6b]= pcmsk0_reg;
00248
00249 rw[0x69]= eicra_reg;
00250 rw[0x68]= pcicr_reg;
00251
00252 rw[0x66]= new NotSimulatedRegister("MCU register OSCCAL not simulated");
00253
00254 rw[0x64]= new NotSimulatedRegister("MCU register PRR not simulated");
00255
00256
00257 rw[0x61]= new NotSimulatedRegister("MCU register CLKPR not simulated");
00258 rw[0x60]= new NotSimulatedRegister("MCU register WDTCSR not simulated");
00259 rw[0x5f]= statusRegister;
00260 rw[0x5e]= & ((HWStackSram *)stack)->sph_reg;
00261 rw[0x5d]= & ((HWStackSram *)stack)->spl_reg;
00262
00263 rw[0x57]= new NotSimulatedRegister("Self-programming register SPMCSR not simulated");
00264
00265 rw[0x55]= new NotSimulatedRegister("MCU register MCUCR not simulated");
00266 rw[0x54]= new NotSimulatedRegister("MCU register MCUSR not simulated");
00267 rw[0x53]= new NotSimulatedRegister("MCU register SMCR not simulated");
00268
00269
00270 rw[0x50]= new NotSimulatedRegister("ADC register ADCSRA not simulated");
00271
00272 rw[0x4E]= & spi->spdr_reg;
00273 rw[0x4D]= & spi->spsr_reg;
00274 rw[0x4C]= & spi->spcr_reg;
00275 rw[0x4B]= gpior2_reg;
00276 rw[0x4A]= gpior1_reg;
00277
00278 rw[0x48]= & timer0->ocrb_reg;
00279 rw[0x47]= & timer0->ocra_reg;
00280 rw[0x46]= & timer0->tcnt_reg;
00281 rw[0x45]= & timer0->tccrb_reg;
00282 rw[0x44]= & timer0->tccra_reg;
00283 rw[0x43]= & gtccr_reg;
00284 rw[0x42]= & eeprom->eearh_reg;
00285 rw[0x41]= & eeprom->eearl_reg;
00286 rw[0x40]= & eeprom->eedr_reg;
00287 rw[0x3F]= & eeprom->eecr_reg;
00288 rw[0x3E]= gpior0_reg;
00289 rw[0x3D]= eimsk_reg;
00290 rw[0x3C]= eifr_reg;
00291 rw[0x3b]= pcifr_reg;
00292
00293 rw[0x37]= & timerIrq2->tifr_reg;
00294 rw[0x36]= & timerIrq1->tifr_reg;
00295 rw[0x35]= & timerIrq0->tifr_reg;
00296
00297 rw[0x2B]= & portd.port_reg;
00298 rw[0x2A]= & portd.ddr_reg;
00299 rw[0x29]= & portd.pin_reg;
00300
00301 rw[0x28]= & portc.port_reg;
00302 rw[0x27]= & portc.ddr_reg;
00303 rw[0x26]= & portc.pin_reg;
00304
00305 rw[0x25]= & portb.port_reg;
00306 rw[0x24]= & portb.ddr_reg;
00307 rw[0x23]= & portb.pin_reg;
00308
00309 Reset();
00310 }
00311