void Interface::load(unsigned id, const stream& stream) { if(id == ID::SystemManifest) { system.information.manifest = stream.text(); } if(id == ID::Manifest) { cartridge.information.markup = stream.text(); } if(id == ID::ProgramROM) { stream.read(cartridge.board->prgrom.data, min(cartridge.board->prgrom.size, stream.size())); } if(id == ID::ProgramRAM) { stream.read(cartridge.board->prgram.data, min(cartridge.board->prgram.size, stream.size())); } if(id == ID::CharacterROM) { stream.read(cartridge.board->chrrom.data, min(cartridge.board->chrrom.size, stream.size())); } if(id == ID::CharacterRAM) { stream.read(cartridge.board->chrram.data, min(cartridge.board->chrram.size, stream.size())); } }
void writeConverter(stream<memCtrlWord> &memWrCmd, stream<ap_uint<memBusWidth> > &memWrData, stream<datamoverCtrlWord> &dmWrCmd, stream<axiWord> &dmWrData, stream<ap_uint<8> > &dmWrStatus) { #pragma HLS INTERFACE ap_ctrl_none port=return #pragma HLS DATA_PACK variable=memWrCmd #pragma HLS DATA_PACK variable=dmWrCmd #pragma HLS DATA_PACK variable=dmWrData #pragma HLS RESOURCE variable=memWrCmd core=AXI4Stream #pragma HLS RESOURCE variable=memWrData core=AXI4Stream #pragma HLS RESOURCE variable=dmWrCmd core=AXI4Stream #pragma HLS RESOURCE variable=dmWrData core=AXI4Stream #pragma HLS RESOURCE variable=dmWrStatus core=AXI4Stream static ap_uint<4> tagCounter = 0; static ap_uint<16> noOfBytesToWrite = 0; static ap_uint<16> byteCount = 0; static enum wcState{WRC_IDLE = 0, WRC_FWD, WRC_STATUS} writeConverterState; switch(writeConverterState) { case WRC_IDLE: if (!memWrCmd.empty() && !dmWrCmd.full()) { memCtrlWord writeTemp = memWrCmd.read(); ap_uint<32> convertedAddress = writeTemp.address * 64; datamoverCtrlWord writeCtrlWord = {(writeTemp.count*(memBusWidth/8)), 1, 0, 1, 0, convertedAddress, tagCounter, 0}; noOfBytesToWrite = writeTemp.count; dmWrCmd.write(writeCtrlWord); tagCounter++; writeConverterState = WRC_FWD; } break; case WRC_FWD: if (!memWrData.empty() && !dmWrData.full()) { axiWord writeTemp2 = {0, 0xFFFFFFFFFFFFFFFF, 0}; memWrData.read(writeTemp2.data); if (byteCount == noOfBytesToWrite - 1) { writeTemp2.last = 1; writeConverterState = WRC_STATUS; byteCount = 0; } else byteCount++; dmWrData.write(writeTemp2); } break; case WRC_STATUS: if (!dmWrStatus.empty()) { ap_uint<8> tempVariable = dmWrStatus.read(); writeConverterState = WRC_IDLE; } break; } }
void simulateTxBuffer(stream<mmCmd>& command, stream<axiWord>& dataOut) { static mmCmd cmd; static ap_uint<1> fsmState = 0; static ap_uint<16> wordCount = 0; axiWord memWord; switch (fsmState) { case 0: if (!command.empty()) { command.read(cmd); fsmState = 1; } break; case 1: memWord.data = 0x3031323334353637; memWord.keep = 0xff; memWord.last = 0x0; wordCount += 8; if (wordCount >= cmd.bbt) { memWord.last = 0x1; fsmState = 0; wordCount = 0; } dataOut.write(memWord); break; } }
void MappedRAM::copy(const stream& memory) { if(data_) delete[] data_; //round size up to multiple of 256-bytes size_ = (memory.size() & ~255) + ((bool)(memory.size() & 255) << 8); data_ = new uint8[size_](); memory.read(data_, memory.size()); }
void readConverter(stream<memCtrlWord> &memRdCmd, stream<ap_uint<memBusWidth> > &memRdData, stream<datamoverCtrlWord> &dmRdCmd, stream<axiWord> &dmRdData, stream<ap_uint<8> > &dmRdStatus) { #pragma HLS INTERFACE ap_ctrl_none port=return #pragma HLS pipeline II=1 enable_flush #pragma HLS DATA_PACK variable=memRdCmd #pragma HLS DATA_PACK variable=dmRdCmd #pragma HLS DATA_PACK variable=dmRdData #pragma HLS RESOURCE variable=dmRdStatus core=AXI4Stream #pragma HLS RESOURCE variable=memRdData core=AXI4Stream #pragma HLS RESOURCE variable=dmRdCmd core=AXI4Stream #pragma HLS RESOURCE variable=dmRdData core=AXI4Stream #pragma HLS RESOURCE variable=memRdCmd core=AXI4Stream static ap_uint<4> tagCounter = 0; //static enum rcState{RDC_IDLE = 0, RDC_FWD, RDC_STATUS} readConverterState; //switch(readConverterState) { //case RDC_IDLE: if (!memRdCmd.empty() && !dmRdCmd.full()) { memCtrlWord readTemp = memRdCmd.read(); ap_uint<32> convertedAddress = readTemp.address * 64; datamoverCtrlWord readCtrlWord = {(readTemp.count * (memBusWidth/8)), 1, 0, 1, 0, convertedAddress, tagCounter, 0}; //ap_uint<16> readCtrlWord = readTemp.address.range(15, 0); dmRdCmd.write(readCtrlWord); tagCounter++; //readConverterState = RDC_FWD; } //break; //case RDC_FWD: if (!dmRdData.empty() && !memRdData.full()) { axiWord readTemp = dmRdData.read(); memRdData.write(readTemp.data); //if (readTemp.last) //readConverterState = RDC_STATUS; } //break; //case RDC_STATUS: if (!dmRdStatus.empty()) { ap_uint<8> tempVariable = dmRdStatus.read(); //readConverterState = RDC_IDLE; } //break; }
GameCard::GameCard(const stream& memory, uint32 esize, uint32 id) { rom.size = esize; rom.data = new uint8[rom.size]; memset(rom.data, 0xff, rom.size); memory.read(rom.data, min(memory.size(), rom.size)); size = bit::round(rom.size); sha256 = nall::sha256(rom.data, rom.size); chipId = id; spi = nullptr; }
void Interface::load(unsigned id, const stream &stream, const string &markup) { if(id == ID::ROM) { cartridge.load(markup, stream); system.power(); input.connect(0, Input::Device::Joypad); input.connect(1, Input::Device::Joypad); } if(id == ID::RAM) { stream.read(cartridge.ram_data(), min(stream.size(), cartridge.ram_size())); } }
sBool streamM::open(stream &f, sS32 len) { sS32 maxlen=f.size()-f.tell(); if (len>=0 && len<maxlen) maxlen=len; if (!openNew(maxlen)) return sFALSE; flen=f.read(fbuf,flen); return sTRUE; }
gzipstream(const stream& stream) { unsigned size = stream.size(); uint8_t *data = new uint8_t[size]; stream.read(data, size); Decode::GZIP archive; bool result = archive.decompress(data, size); delete[] data; if(result == false) return; psize = archive.size; pdata = new uint8_t[psize]; memcpy(pdata, archive.data, psize); }
void simulateSARtables( stream<rxSarEntry>& rxSar2txEng_upd_rsp, stream<txSarEntry>& txSar2txEng_upd_rsp, stream<ap_uint<16> >& txEng2rxSar_upd_req, stream<txTxSarQuery>& txEng2txSar_upd_req) { ap_uint<16> addr; txTxSarQuery in_txaccess; if (!txEng2rxSar_upd_req.empty()) { txEng2rxSar_upd_req.read(addr); rxSar2txEng_upd_rsp.write((rxSarEntry) {0x0023, 0xadbd}); } if (!txEng2txSar_upd_req.empty()) { txEng2txSar_upd_req.read(in_txaccess); if (in_txaccess.write == 0) { txSar2txEng_upd_rsp.write(((txSarEntry) {3, 5, 0xffff, 5, 1})); } //omit write } }
void simulateRevSLUP(stream<ap_uint<16> >& txEng2sLookup_rev_req, stream<fourTuple>& sLookup2txEng_rev_rsp) { fourTuple tuple; tuple.dstIp = 0x0101010a; tuple.dstPort = 0x5001; tuple.srcIp = 0x01010101; tuple.srcPort = 0xaffff; if (!txEng2sLookup_rev_req.empty()) { txEng2sLookup_rev_req.read(); sLookup2txEng_rev_rsp.write(tuple); } }
void Interface::load(unsigned id, const stream& stream) { if(id == ID::GameBoyBootROM) { stream.read(system.bootROM.dmg, min( 256u, stream.size())); } if(id == ID::SuperGameBoyBootROM) { stream.read(system.bootROM.sgb, min( 256u, stream.size())); } if(id == ID::GameBoyColorBootROM) { stream.read(system.bootROM.cgb, min(2048u, stream.size())); } if(id == ID::Manifest) cartridge.information.markup = stream.text(); if(id == ID::ROM) { stream.read(cartridge.romdata, min(cartridge.romsize, stream.size())); } if(id == ID::RAM) { stream.read(cartridge.ramdata, min(stream.size(), cartridge.ramsize)); } }
void Interface::load(unsigned id, const stream& stream) { if(id == ID::BIOS) { stream.read(bios.data, min(bios.size, stream.size())); } if(id == ID::Manifest) cartridge.information.markup = stream.text(); if(id == ID::ROM) { stream.read(cartridge.rom.data, min(cartridge.rom.size, stream.size())); } if(id == ID::RAM) { stream.read(cartridge.ram.data, min(cartridge.ram.size, stream.size())); } if(id == ID::EEPROM) { stream.read(cartridge.eeprom.data, min(cartridge.eeprom.size, stream.size())); } if(id == ID::FlashROM) { stream.read(cartridge.flashrom.data, min(cartridge.flashrom.size, stream.size())); } }
int main() { static stream<ap_uint<16> > clearTimerFifo; static stream<ap_uint<16> > setTimerFifo; static stream<event> eventFifo; event ev; int count = 0; //for (int i=0; i < 10; i++) //{ setTimerFifo.write(7); //} while (count < 50000) { /*if (count < 100) { setTimerFifo.write(count); std::cout << "set Timer for: " << count << std::endl; }*/ if (count == 9 || count == 12) { //for (int i=0; i < 10; i++) //{ setTimerFifo.write(7); //try 33 //} } if (count == 21) { clearTimerFifo.write(22); setTimerFifo.write(22); } probe_timer(clearTimerFifo, setTimerFifo, eventFifo); if (!eventFifo.empty()) { eventFifo.read(ev); std::cout << "ev happened, ID: " << ev.sessionID;// << std::endl; std::cout << "\t\tcount: " << count << std::endl; } count++; } return 0; }
void ad_window(stream<axiInIndex> &inData, stream<axiIndex> &outData) { #pragma HLS pipeline II=1 enable_flush // Current Word axiInIndex currWord = {0}; // Score axiIndex currIndex = {0, 0, 0, 0, 0, 0}; // Read Data inData.read(currWord); // DET SHIFT REGISTER static INDEXTYPE det_window[DET_W]; #pragma HLS ARRAY_PARTITION variable=det_window complete dim=0 for (int i = 0; i < DET_W-1; i++) { #pragma HLS unroll det_window[i] = det_window[i+1]; } det_window[DET_W-1] = currWord.ind; // REF SHIFT REGISTER static INDEXTYPE ref_window[REF_W]; #pragma HLS ARRAY_PARTITION variable=ref_window complete dim=0 for (int i = 0; i < REF_W-1; i++) { #pragma HLS unroll ref_window[i] = ref_window[i+1]; } ref_window[REF_W-1] = currWord.ind; currIndex.a = det_window[0]; currIndex.b = det_window[1]; currIndex.c = ref_window[0]; currIndex.d = ref_window[1]; currIndex.e = det_window[DET_W-2]; currIndex.f = currWord.ind; outData.write(currIndex); }
zipstream(const stream& stream, const string& filter = "*") { unsigned size = stream.size(); uint8_t* data = new uint8_t[size]; stream.read(data, size); Decode::ZIP archive; if(archive.open(data, size) == false) return; delete[] data; for(auto& file : archive.file) { if(file.name.match(filter)) { auto buffer = archive.extract(file); psize = buffer.size(); pdata = buffer.move(); return; } } }
sS32 stream::copy(stream &src, sS32 cnt) { sS32 copied=0; sBool readOk=sTRUE; sS32 maxlen=-1; if (cnt>0 && cnt<maxlen) maxlen=cnt; sU8 *buf=new sU8[65536]; while (readOk) { sS32 bsize; if (maxlen!=-1) bsize=(maxlen<65536)?maxlen:65536; else bsize=65536; sS32 bread=src.read(buf, bsize); sS32 bwritten=write(buf, bread); if (maxlen!=-1) { maxlen-=bread; if (maxlen<=0) { src.seekcur(-maxlen); readOk=sTRUE; } } copied+=bwritten; if (!bread || bwritten!=bread) break; } delete[] buf; return copied; }
void sub(stream<CMD> &io_cmd, stream<RESP> &io_resp){ #pragma HLS data_pack variable=io_cmd #pragma HLS data_pack variable=io_resp CMD cmd_token; RESP resp_token; cmd_token = io_cmd.read(); ap_uint<64> a = cmd_token.rs1; ap_uint<64> b = cmd_token.rs2; // martin's module a = a - b; resp_token.io_busy = 0; resp_token.io_interrupt = 0; resp_token.io_autl_acquire_ready = 0; resp_token.io_autl_acquire_valid = 0; resp_token.io_mem_req_valid = 0; resp_token.rd = cmd_token.inst_rd; resp_token.data = a; io_resp.write(resp_token); }
void MappedRAM::read(const stream& memory) { memory.read(data_, min(memory.size(), size_)); }
EEPROM::EEPROM(const stream& memory, uint32 esize, uint32 psize) { data = new uint8[size = esize]; pageSize = psize; memset(data, 0xff, size); memory.read(data, min(memory.size(), size)); }
void Interface::load(unsigned id, const stream& stream) { if(id == ID::IPLROM) { stream.read(smp.iplrom, min(64u, stream.size())); } if(id == ID::Manifest) cartridge.information.markup.cartridge = stream.text(); if(id == ID::ROM) cartridge.rom.read(stream); if(id == ID::RAM) cartridge.ram.read(stream); if(id == ID::EventROM0) event.rom[0].read(stream); if(id == ID::EventROM1) event.rom[1].read(stream); if(id == ID::EventROM2) event.rom[2].read(stream); if(id == ID::EventROM3) event.rom[3].read(stream); if(id == ID::EventRAM) event.ram.read(stream); if(id == ID::SA1ROM) sa1.rom.read(stream); if(id == ID::SA1IRAM) sa1.iram.read(stream); if(id == ID::SA1BWRAM) sa1.bwram.read(stream); if(id == ID::SuperFXROM) superfx.rom.read(stream); if(id == ID::SuperFXRAM) superfx.ram.read(stream); if(id == ID::ArmDSPPROM) { for(unsigned n = 0; n < 128 * 1024; n++) armdsp.programROM[n] = stream.read(); } if(id == ID::ArmDSPDROM) { for(unsigned n = 0; n < 32 * 1024; n++) armdsp.dataROM[n] = stream.read(); } if(id == ID::ArmDSPRAM) { for(unsigned n = 0; n < 16 * 1024; n++) armdsp.programRAM[n] = stream.read(); } if(id == ID::HitachiDSPROM) hitachidsp.rom.read(stream); if(id == ID::HitachiDSPRAM) hitachidsp.ram.read(stream); if(id == ID::HitachiDSPDROM) { for(unsigned n = 0; n < 1024; n++) hitachidsp.dataROM[n] = stream.readl(3); } if(id == ID::HitachiDSPDRAM) { for(unsigned n = 0; n < 3072; n++) hitachidsp.dataRAM[n] = stream.readl(1); } if(id == ID::Nec7725DSPPROM) { for(unsigned n = 0; n < 2048; n++) necdsp.programROM[n] = stream.readl(3); } if(id == ID::Nec7725DSPDROM) { for(unsigned n = 0; n < 1024; n++) necdsp.dataROM[n] = stream.readl(2); } if(id == ID::Nec7725DSPRAM) { for(unsigned n = 0; n < 256; n++) necdsp.dataRAM[n] = stream.readl(2); } if(id == ID::Nec96050DSPPROM) { for(unsigned n = 0; n < 16384; n++) necdsp.programROM[n] = stream.readl(3); } if(id == ID::Nec96050DSPDROM) { for(unsigned n = 0; n < 2048; n++) necdsp.dataROM[n] = stream.readl(2); } if(id == ID::Nec96050DSPRAM) { for(unsigned n = 0; n < 2048; n++) necdsp.dataRAM[n] = stream.readl(2); } if(id == ID::EpsonRTC) { uint8 data[16] = {0}; stream.read(data, min(stream.size(), sizeof data)); epsonrtc.load(data); } if(id == ID::SharpRTC) { uint8 data[16] = {0}; stream.read(data, min(stream.size(), sizeof data)); sharprtc.load(data); } if(id == ID::SPC7110PROM) spc7110.prom.read(stream); if(id == ID::SPC7110DROM) spc7110.drom.read(stream); if(id == ID::SPC7110RAM) spc7110.ram.read(stream); if(id == ID::SDD1ROM) sdd1.rom.read(stream); if(id == ID::SDD1RAM) sdd1.ram.read(stream); if(id == ID::OBC1RAM) obc1.ram.read(stream); if(id == ID::SuperGameBoyBootROM) { stream.read(GameBoy::system.bootROM.sgb, min(stream.size(), 256u)); } if(id == ID::BsxROM) bsxcartridge.rom.read(stream); if(id == ID::BsxRAM) bsxcartridge.ram.read(stream); if(id == ID::BsxPSRAM) bsxcartridge.psram.read(stream); if(id == ID::SuperGameBoyManifest) cartridge.information.markup.gameBoy = stream.text(); if(id == ID::SuperGameBoyROM) { stream.read(GameBoy::cartridge.romdata, min(GameBoy::cartridge.romsize, stream.size())); } if(id == ID::SuperGameBoyRAM) { stream.read(GameBoy::cartridge.ramdata, min(GameBoy::cartridge.ramsize, stream.size())); } if(id == ID::SatellaviewManifest) cartridge.information.markup.satellaview = stream.text(); if(id == ID::SatellaviewROM) satellaviewcartridge.memory.read(stream); if(id == ID::SufamiTurboSlotAManifest) cartridge.information.markup.sufamiTurboA = stream.text(); if(id == ID::SufamiTurboSlotAROM) sufamiturboA.rom.read(stream); if(id == ID::SufamiTurboSlotBROM) sufamiturboB.rom.read(stream); if(id == ID::SufamiTurboSlotBManifest) cartridge.information.markup.sufamiTurboB = stream.text(); if(id == ID::SufamiTurboSlotARAM) sufamiturboA.ram.read(stream); if(id == ID::SufamiTurboSlotBRAM) sufamiturboB.ram.read(stream); }
void ad_grid(stream<axiRawValues> &inData, stream<axiValues> &outData){ #pragma HLS pipeline II=1 enable_flush // Current Raw Values axiRawValues currRawValues = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Current Values axiValues currValues = {0, 0, 0, 0, 0, 0}; // Read In Values inData.read(currRawValues); MATHTYPE det_det_prev = currRawValues.det_det_prev; MATHTYPE det_ref_prev = currRawValues.det_ref_prev; MATHTYPE det_curr_prev = currRawValues.det_curr_prev; MATHTYPE ref_det_prev = currRawValues.ref_det_prev; MATHTYPE ref_ref_prev = currRawValues.ref_ref_prev; MATHTYPE ref_curr_prev = currRawValues.ref_curr_prev; MATHTYPE det_det_curr = currRawValues.det_det_curr; MATHTYPE det_ref_curr = currRawValues.det_ref_curr; MATHTYPE det_curr_curr = currRawValues.det_curr_curr; MATHTYPE ref_det_curr = currRawValues.ref_det_curr; MATHTYPE ref_ref_curr = currRawValues.ref_ref_curr; MATHTYPE ref_curr_curr = currRawValues.ref_curr_curr; // Remove det_window[0], det_window[1] MATHTYPE det_rm; #pragma HLS RESOURCE variable=det_rm core=AddSubnS det_rm = (det_det_prev - ref_det_prev); // Remove ref_window[0], ref_window[1] MATHTYPE ref_rm; #pragma HLS RESOURCE variable=ref_rm core=AddSubnS ref_rm = (det_ref_prev - ref_ref_prev); // Remove currWord.data, det_window[DET_W-2] MATHTYPE curr_rm; #pragma HLS RESOURCE variable=curr_rm core=AddSubnS curr_rm = (det_curr_prev - ref_curr_prev); // Add det_window[0], det_window[1] MATHTYPE det_add; #pragma HLS RESOURCE variable=det_add core=AddSubnS det_add = (det_det_curr - ref_det_curr); // Add ref_window[0], ref_window[1] MATHTYPE ref_add; #pragma HLS RESOURCE variable=ref_add core=AddSubnS ref_add = (det_ref_curr - ref_ref_curr); // Add currWord.data, det_window[DET_W-2] MATHTYPE curr_add; #pragma HLS RESOURCE variable=curr_add core=AddSubnS curr_add = (det_curr_curr - ref_curr_curr); currValues.det_rm = det_rm; currValues.ref_rm = ref_rm; currValues.curr_rm = curr_rm; currValues.det_add = det_add; currValues.ref_add = ref_add; currValues.curr_add = curr_add; outData.write(currValues); }