00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "atmega8.h"
00023
00024 #include "hardware.h"
00025 #include "irqsystem.h"
00026 #include "hwport.h"
00027 #include "hwstack.h"
00028 #include "hwspi.h"
00029 #include "hweeprom.h"
00030 #include "hwwado.h"
00031 #include "hwsreg.h"
00032 #include "flashprog.h"
00033
00034 #include "avrfactory.h"
00035
00036 AVR_REGISTER(atmega8, AvrDevice_atmega8);
00037
00038 AvrDevice_atmega8::AvrDevice_atmega8() :
00039 AvrDevice(64,
00040 1024,
00041 0,
00042 8 * 1024),
00043 aref()
00044 {
00045 irqSystem = new HWIrqSystem(this, 2, 19);
00046 eeprom = new HWEeprom(this, irqSystem, 512, 15);
00047 HWStackSram * stack_ram = new HWStackSram(this, 11);
00048 stack = stack_ram;
00049 portb = new HWPort(this, "B");
00050 portc = new HWPort(this, "C");
00051 portd = new HWPort(this, "D");
00052
00053 spmRegister = new FlashProgramming(this,
00054 32,
00055 0xC000,
00056 FlashProgramming::SPM_MEGA_MODE);
00057
00058 RegisterPin("AREF", &aref);
00059
00060 admux = new HWAdmux(this,
00061 &portc->GetPin(0),
00062 &portc->GetPin(1),
00063 &portc->GetPin(2),
00064 &portc->GetPin(3),
00065 &portc->GetPin(4),
00066 &portc->GetPin(5),
00067 &portc->GetPin(19),
00068 &portc->GetPin(22));
00069
00070 ad = new HWAd(this,
00071 admux,
00072 irqSystem,
00073 aref,
00074 14);
00075
00076 spi = new HWSpi(this,
00077 irqSystem,
00078 PinAtPort(portb, 3),
00079 PinAtPort(portb, 4),
00080 PinAtPort(portb, 5),
00081 PinAtPort(portb, 2),
00082 10,
00083 true);
00084
00085 gicr_reg = new IOSpecialReg(&coreTraceGroup,
00086 "GICR");
00087
00088 gifr_reg = new IOSpecialReg(&coreTraceGroup,
00089 "GIFR");
00090
00091 mcucr_reg = new IOSpecialReg(&coreTraceGroup,
00092 "MCUCR");
00093
00094 mcucsr_reg = new IOSpecialReg(&coreTraceGroup,
00095 "MCUCSR");
00096
00097 extirq = new ExternalIRQHandler(this,
00098 irqSystem,
00099 gicr_reg,
00100 gifr_reg);
00101
00102 extirq->registerIrq(1,
00103 6,
00104 new ExternalIRQSingle(mcucr_reg,0, 2, GetPin("D2")));
00105
00106 extirq->registerIrq(2,
00107 7,
00108 new ExternalIRQSingle(mcucr_reg, 2, 2, GetPin("D3")));
00109
00110 sfior_reg = new IOSpecialReg(&coreTraceGroup,
00111 "SFIOR");
00112
00113 assr_reg = new IOSpecialReg(&coreTraceGroup,
00114 "ASSR");
00115
00116 prescaler01 = new HWPrescaler(this,
00117 "01",
00118 sfior_reg,
00119 0);
00120
00121 prescaler2 = new HWPrescalerAsync(this,
00122 "2",
00123 PinAtPort(portb, 6),
00124 assr_reg,
00125 3,
00126 sfior_reg,
00127 1);
00128
00129 wado = new HWWado(this);
00130
00131 usart = new HWUsart(this,
00132 irqSystem,
00133 PinAtPort(portd, 1),
00134 PinAtPort(portd, 0),
00135 PinAtPort(portd, 4),
00136 11,
00137 12,
00138 13);
00139
00140 timer012irq = new TimerIRQRegister(this, irqSystem);
00141
00142 timer012irq->registerLine(0, new IRQLine("TOV0", 9));
00143
00144 timer012irq->registerLine(2, new IRQLine("TOV1", 8));
00145
00146 timer012irq->registerLine(3, new IRQLine("OCF1B", 7));
00147
00148 timer012irq->registerLine(4, new IRQLine("OCF1A", 6));
00149
00150 timer012irq->registerLine(5, new IRQLine("ICF1", 5));
00151
00152 timer012irq->registerLine(6, new IRQLine("TOV2", 4));
00153
00154 timer012irq->registerLine(7, new IRQLine("OCF2", 3));
00155
00156 timer0 = new HWTimer8_0C(this,
00157 new PrescalerMultiplexerExt(prescaler01,
00158 PinAtPort(portd, 4)),
00159 0,
00160 timer012irq->getLine("TOV0"));
00161
00162 inputCapture1 = new ICaptureSource(PinAtPort(portb, 0));
00163
00164 timer1 = new HWTimer16_2C2(this,
00165 new PrescalerMultiplexerExt(prescaler01,
00166 PinAtPort(portd, 5)),
00167 1,
00168 timer012irq->getLine("TOV1"),
00169 timer012irq->getLine("OCF1A"),
00170 new PinAtPort(portb, 1),
00171 timer012irq->getLine("OCF1B"),
00172 new PinAtPort(portb, 2),
00173 timer012irq->getLine("ICF1"),
00174 inputCapture1, false);
00175
00176 timer2 = new HWTimer8_1C(this,
00177 new PrescalerMultiplexer(prescaler2),
00178 2,
00179 timer012irq->getLine("TOV2"),
00180 timer012irq->getLine("OCF2"),
00181 new PinAtPort(portb, 3));
00182
00183 rw[0x5f] = statusRegister;
00184 rw[0x5e] = &stack_ram->sph_reg;
00185 rw[0x5d] = &stack_ram->spl_reg;
00186
00187 rw[0x5b] = gicr_reg;
00188 rw[0x5a] = gifr_reg;
00189 rw[0x59] = &timer012irq->timsk_reg;
00190 rw[0x58] = &timer012irq->tifr_reg;
00191 rw[0x57] = &spmRegister->spmcr_reg;
00192
00193 rw[0x55] = mcucr_reg;
00194 rw[0x54] = mcucsr_reg;
00195 rw[0x53] = &timer0->tccr_reg;
00196 rw[0x52] = &timer0->tcnt_reg;
00197
00198 rw[0x50] = sfior_reg;
00199 rw[0x4f] = &timer1->tccra_reg;
00200 rw[0x4e] = &timer1->tccrb_reg;
00201 rw[0x4d] = &timer1->tcnt_h_reg;
00202 rw[0x4c] = &timer1->tcnt_l_reg;
00203 rw[0x4b] = &timer1->ocra_h_reg;
00204 rw[0x4a] = &timer1->ocra_l_reg;
00205 rw[0x49] = &timer1->ocrb_h_reg;
00206 rw[0x48] = &timer1->ocrb_l_reg;
00207 rw[0x47] = &timer1->icr_h_reg;
00208 rw[0x46] = &timer1->icr_l_reg;
00209 rw[0x45] = &timer2->tccr_reg;
00210 rw[0x44] = &timer2->tcnt_reg;
00211 rw[0x43] = &timer2->ocra_reg;
00212 rw[0x42] = assr_reg;
00213 rw[0x41] = &wado->wdtcr_reg;
00214 rw[0x40] = &usart->ucsrc_ubrrh_reg;
00215 rw[0x3f] = &eeprom->eearh_reg;
00216 rw[0x3e] = &eeprom->eearl_reg;
00217 rw[0x3d] = &eeprom->eedr_reg;
00218 rw[0x3c] = &eeprom->eecr_reg;
00219
00220
00221
00222 rw[0x38] = &portb->port_reg;
00223 rw[0x37] = &portb->ddr_reg;
00224 rw[0x36] = &portb->pin_reg;
00225 rw[0x35] = &portc->port_reg;
00226 rw[0x34] = &portc->ddr_reg;
00227 rw[0x33] = &portc->pin_reg;
00228 rw[0x32] = &portd->port_reg;
00229 rw[0x31] = &portd->ddr_reg;
00230 rw[0x30] = &portd->pin_reg;
00231 rw[0x2f] = &spi->spdr_reg;
00232 rw[0x2e] = &spi->spsr_reg;
00233 rw[0x2d] = &spi->spcr_reg;
00234 rw[0x2c] = &usart->udr_reg;
00235 rw[0x2b] = &usart->ucsra_reg;
00236 rw[0x2a] = &usart->ucsrb_reg;
00237 rw[0x29] = &usart->ubrr_reg;
00238
00239 rw[0x27] = &admux->admux_reg;
00240 rw[0x26] = &ad->adcsr_reg;
00241 rw[0x25] = &ad->adch_reg;
00242 rw[0x24] = &ad->adcl_reg;
00243
00244
00245
00246
00247
00248 Reset();
00249 }
00250
00251 AvrDevice_atmega8::~AvrDevice_atmega8() {
00252 delete timer2;
00253 delete timer1;
00254 delete inputCapture1;
00255 delete timer0;
00256 delete usart;
00257 delete wado;
00258 delete prescaler2;
00259 delete prescaler01;
00260 delete assr_reg;
00261 delete sfior_reg;
00262 delete extirq;
00263 delete mcucsr_reg;
00264 delete mcucr_reg;
00265 delete gifr_reg;
00266 delete gicr_reg;
00267 delete spi;
00268 delete ad;
00269 delete admux;
00270 delete spmRegister;
00271 delete portd;
00272 delete portc;
00273 delete portb;
00274 delete stack;
00275 delete eeprom;
00276 delete irqSystem;
00277 }