00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "atmega128.h"
00027
00028 #include "hardware.h"
00029 #include "irqsystem.h"
00030 #include "hwport.h"
00031 #include "hwstack.h"
00032 #include "hwspi.h"
00033 #include "hweeprom.h"
00034 #include "hwwado.h"
00035 #include "hwsreg.h"
00036
00037 #include "avrfactory.h"
00038
00039 AVR_REGISTER(atmega128, AvrDevice_atmega128);
00040
00041 AvrDevice_atmega128::~AvrDevice_atmega128() {
00042 delete timer3;
00043 delete inputCapture3;
00044 delete timer2;
00045 delete timer1;
00046 delete inputCapture1;
00047 delete timer0;
00048 delete timer3irq;
00049 delete timer012irq;
00050 delete usart1;
00051 delete usart0;
00052 delete wado;
00053 delete prescaler123;
00054 delete prescaler0;
00055 delete assr_reg;
00056 delete sfior_reg;
00057 delete extirq;
00058 delete eifr_reg;
00059 delete eimsk_reg;
00060 delete eicrb_reg;
00061 delete eicra_reg;
00062 delete spi;
00063 delete ad;
00064 delete admux;
00065 delete rampz;
00066 delete portg;
00067 delete portf;
00068 delete porte;
00069 delete portd;
00070 delete portc;
00071 delete portb;
00072 delete porta;
00073 delete stack;
00074 delete eeprom;
00075 delete irqSystem;
00076 }
00077
00078 AvrDevice_atmega128::AvrDevice_atmega128():
00079 AvrDevice(224, 4096, 0xef00, 256*1024),
00080 aref()
00081 {
00082 flagELPMInstructions = true;
00083 irqSystem = new HWIrqSystem(this, 4, 35);
00084 eeprom = new HWEeprom( this, irqSystem, 4096, 22);
00085 stack = new HWStackSram(this, 16);
00086 porta = new HWPort(this, "A");
00087 portb = new HWPort(this, "B");
00088 portc = new HWPort(this, "C");
00089 portd = new HWPort(this, "D");
00090 porte = new HWPort(this, "E");
00091 portf = new HWPort(this, "F");
00092 portg = new HWPort(this, "G");
00093
00094 RegisterPin("AREF", &aref);
00095 rampz = new AddressExtensionRegister(this, "RAMPZ", 1);
00096
00097 admux = new HWAdmux(this,
00098 &portf->GetPin(0), &portf->GetPin(1), &portf->GetPin(2),
00099 &portf->GetPin(3), &portf->GetPin(4), &portf->GetPin(5),
00100 &portf->GetPin(6), &portf->GetPin(7));
00101
00102
00103 ad = new HWAd(this, admux, irqSystem, aref, 21);
00104
00105 spi = new HWSpi(this, irqSystem,
00106 PinAtPort(portb, 2), PinAtPort(portb, 3), PinAtPort(portb, 1),
00107 PinAtPort(portb, 0), 17, true);
00108
00109 eicra_reg = new IOSpecialReg(&coreTraceGroup, "EICRA");
00110 eicrb_reg = new IOSpecialReg(&coreTraceGroup, "EICRB");
00111 eimsk_reg = new IOSpecialReg(&coreTraceGroup, "EIMSK");
00112 eifr_reg = new IOSpecialReg(&coreTraceGroup, "EIFR");
00113 extirq = new ExternalIRQHandler(this, irqSystem, eimsk_reg, eifr_reg);
00114 extirq->registerIrq(1, 0, new ExternalIRQSingle(eicra_reg, 0, 2, GetPin("D0")));
00115 extirq->registerIrq(2, 1, new ExternalIRQSingle(eicra_reg, 2, 2, GetPin("D1")));
00116 extirq->registerIrq(3, 2, new ExternalIRQSingle(eicra_reg, 4, 2, GetPin("D2")));
00117 extirq->registerIrq(4, 3, new ExternalIRQSingle(eicra_reg, 6, 2, GetPin("D3")));
00118 extirq->registerIrq(5, 4, new ExternalIRQSingle(eicrb_reg, 0, 2, GetPin("E4")));
00119 extirq->registerIrq(6, 5, new ExternalIRQSingle(eicrb_reg, 2, 2, GetPin("E5")));
00120 extirq->registerIrq(7, 6, new ExternalIRQSingle(eicrb_reg, 4, 2, GetPin("E6")));
00121 extirq->registerIrq(8, 7, new ExternalIRQSingle(eicrb_reg, 6, 2, GetPin("E7")));
00122
00123 sfior_reg = new IOSpecialReg(&coreTraceGroup, "SFIOR");
00124 assr_reg = new IOSpecialReg(&coreTraceGroup, "ASSR");
00125 prescaler0 = new HWPrescalerAsync(this, "0", PinAtPort(portg, 4), assr_reg, 3, sfior_reg, 1, 7);
00126 prescaler123 = new HWPrescaler(this, "123", sfior_reg, 0, 7);
00127
00128 wado = new HWWado(this);
00129
00130 usart0 = new HWUsart(this, irqSystem,
00131 PinAtPort(porte,1), PinAtPort(porte,0), PinAtPort(porte, 2),
00132 18, 19, 20, 0);
00133 usart1 = new HWUsart(this, irqSystem,
00134 PinAtPort(portd,3), PinAtPort(portd,2), PinAtPort(portd, 5),
00135 30, 31, 32, 1);
00136
00137 timer012irq = new TimerIRQRegister(this, irqSystem);
00138 timer012irq->registerLine(0, new IRQLine("TOV0", 16));
00139 timer012irq->registerLine(1, new IRQLine("OCF0", 15));
00140 timer012irq->registerLine(2, new IRQLine("TOV1", 14));
00141 timer012irq->registerLine(3, new IRQLine("OCF1B", 13));
00142 timer012irq->registerLine(4, new IRQLine("OCF1A", 12));
00143 timer012irq->registerLine(5, new IRQLine("ICF1", 11));
00144 timer012irq->registerLine(6, new IRQLine("TOV2", 10));
00145 timer012irq->registerLine(7, new IRQLine("OCF2", 9));
00146
00147 timer3irq = new TimerIRQRegister(this, irqSystem, -2);
00148 timer3irq->registerLine(0, new IRQLine("OCF1C", 24));
00149 timer3irq->registerLine(1, new IRQLine("OCF3C", 28));
00150 timer3irq->registerLine(2, new IRQLine("TOV3", 29));
00151 timer3irq->registerLine(3, new IRQLine("OCF3B", 27));
00152 timer3irq->registerLine(4, new IRQLine("OCF3A", 26));
00153 timer3irq->registerLine(5, new IRQLine("ICF3", 25));
00154
00155 timer0 = new HWTimer8_1C(this,
00156 new PrescalerMultiplexer(prescaler0),
00157 0,
00158 timer012irq->getLine("TOV0"),
00159 timer012irq->getLine("OCF0"),
00160 new PinAtPort(portb, 4));
00161 inputCapture1 = new ICaptureSource(PinAtPort(portd, 4));
00162 timer1 = new HWTimer16_3C(this,
00163 new PrescalerMultiplexerExt(prescaler123, PinAtPort(portd, 6)),
00164 1,
00165 timer012irq->getLine("TOV1"),
00166 timer012irq->getLine("OCF1A"),
00167 new PinAtPort(portb, 5),
00168 timer012irq->getLine("OCF1B"),
00169 new PinAtPort(portb, 6),
00170 timer3irq->getLine("OCF1C"),
00171 new PinAtPort(portb, 7),
00172 timer012irq->getLine("ICF1"),
00173 inputCapture1);
00174 timer2 = new HWTimer8_1C(this,
00175 new PrescalerMultiplexerExt(prescaler123, PinAtPort(portd, 7)),
00176 2,
00177 timer012irq->getLine("TOV2"),
00178 timer012irq->getLine("OCF2"),
00179 new PinAtPort(portb, 7));
00180 inputCapture3 = new ICaptureSource(PinAtPort(porte, 7));
00181 timer3 = new HWTimer16_3C(this,
00182 new PrescalerMultiplexerExt(prescaler123, PinAtPort(porte, 6)),
00183 3,
00184 timer3irq->getLine("TOV3"),
00185 timer3irq->getLine("OCF3A"),
00186 new PinAtPort(porte, 3),
00187 timer3irq->getLine("OCF3B"),
00188 new PinAtPort(porte, 4),
00189 timer3irq->getLine("OCF3C"),
00190 new PinAtPort(porte, 5),
00191 timer3irq->getLine("ICF3"),
00192 inputCapture3);
00193
00194 rw[0x9d]= & usart1->ucsrc_reg;
00195 rw[0x9c]= & usart1->udr_reg;
00196 rw[0x9b]= & usart1->ucsra_reg;
00197 rw[0x9a]= & usart1->ucsrb_reg;
00198 rw[0x99]= & usart1->ubrr_reg;
00199 rw[0x98]= & usart1->ubrrhi_reg;
00200
00201 rw[0x95]= & usart0->ucsrc_reg;
00202
00203 rw[0x90]= & usart0->ubrrhi_reg;
00204
00205 rw[0x8c]= & timer3->tccrc_reg;
00206 rw[0x8b]= & timer3->tccra_reg;
00207 rw[0x8a]= & timer3->tccrb_reg;
00208 rw[0x89]= & timer3->tcnt_h_reg;
00209 rw[0x88]= & timer3->tcnt_l_reg;
00210 rw[0x87]= & timer3->ocra_h_reg;
00211 rw[0x86]= & timer3->ocra_l_reg;
00212 rw[0x85]= & timer3->ocrb_h_reg;
00213 rw[0x84]= & timer3->ocrb_l_reg;
00214 rw[0x83]= & timer3->ocrc_h_reg;
00215 rw[0x82]= & timer3->ocrc_l_reg;
00216 rw[0x81]= & timer3->icr_h_reg;
00217 rw[0x80]= & timer3->icr_l_reg;
00218
00219 rw[0x7d]= & timer3irq->timsk_reg;
00220 rw[0x7c]= & timer3irq->tifr_reg;
00221
00222 rw[0x7a]= & timer1->tccrc_reg;
00223 rw[0x79]= & timer1->ocrc_h_reg;
00224 rw[0x78]= & timer1->ocrc_l_reg;
00225
00226 rw[0x6a]= eicra_reg;
00227
00228 rw[0x65]= & portg->port_reg;
00229 rw[0x64]= & portg->ddr_reg;
00230 rw[0x63]= & portg->pin_reg;
00231
00232 rw[0x62]= & portf->port_reg;
00233 rw[0x61]= & portf->ddr_reg;
00234
00235 rw[0x5f]= statusRegister;
00236 rw[0x5e]= & ((HWStackSram *)stack)->sph_reg;
00237 rw[0x5d]= & ((HWStackSram *)stack)->spl_reg;
00238
00239 rw[0x5b]= & rampz->ext_reg;
00240
00241 rw[0x5a]= eicrb_reg;
00242 rw[0x59]= eimsk_reg;
00243 rw[0x58]= eifr_reg;
00244 rw[0x57]= & timer012irq->timsk_reg;
00245 rw[0x56]= & timer012irq->tifr_reg;
00246
00247 rw[0x53]= & timer0->tccr_reg;
00248 rw[0x52]= & timer0->tcnt_reg;
00249 rw[0x51]= & timer0->ocra_reg;
00250 rw[0x50]= assr_reg;
00251 rw[0x4f]= & timer1->tccra_reg;
00252 rw[0x4e]= & timer1->tccrb_reg;
00253 rw[0x4d]= & timer1->tcnt_h_reg;
00254 rw[0x4c]= & timer1->tcnt_l_reg;
00255 rw[0x4b]= & timer1->ocra_h_reg;
00256 rw[0x4a]= & timer1->ocra_l_reg;
00257 rw[0x49]= & timer1->ocrb_h_reg;
00258 rw[0x48]= & timer1->ocrb_l_reg;
00259 rw[0x47]= & timer1->icr_h_reg;
00260 rw[0x46]= & timer1->icr_l_reg;
00261 rw[0x45]= & timer2->tccr_reg;
00262 rw[0x44]= & timer2->tcnt_reg;
00263 rw[0x43]= & timer2->ocra_reg;
00264
00265
00266
00267 rw[0x40]= sfior_reg;
00268 rw[0x3f]= & eeprom->eearh_reg;
00269 rw[0x3e]= & eeprom->eearl_reg;
00270 rw[0x3d]= & eeprom->eedr_reg;
00271 rw[0x3c]= & eeprom->eecr_reg;
00272
00273 rw[0x3b]= & porta->port_reg;
00274 rw[0x3a]= & porta->ddr_reg;
00275 rw[0x39]= & porta->pin_reg;
00276
00277 rw[0x38]= & portb->port_reg;
00278 rw[0x37]= & portb->ddr_reg;
00279 rw[0x36]= & portb->pin_reg;
00280
00281 rw[0x35]= & portc->port_reg;
00282 rw[0x34]= & portc->ddr_reg;
00283 rw[0x33]= & portc->pin_reg;
00284
00285 rw[0x32]= & portd->port_reg;
00286 rw[0x31]= & portd->ddr_reg;
00287 rw[0x30]= & portd->pin_reg;
00288
00289 rw[0x2f]= & spi->spdr_reg;
00290 rw[0x2e]= & spi->spcr_reg;
00291 rw[0x2d]= & spi->spsr_reg;
00292
00293 rw[0x2c]= & usart0->udr_reg;
00294 rw[0x2b]= & usart0->ucsra_reg;
00295 rw[0x2a]= & usart0->ucsrb_reg;
00296 rw[0x29]= & usart0->ubrr_reg;
00297
00298 rw[0x27]= & admux->admux_reg;
00299
00300 rw[0x26]= & ad->adcsr_reg;
00301 rw[0x25]= & ad->adch_reg;
00302 rw[0x24]= & ad->adcl_reg;
00303
00304 rw[0x23]= & porte->port_reg;
00305 rw[0x22]= & porte->ddr_reg;
00306 rw[0x21]= & porte->pin_reg;
00307
00308 rw[0x20]= & portf->pin_reg;
00309
00310 Reset();
00311 }
00312