#include "model/hardware/device/SonoDevice.h" #include #include SonoDevice::SonoDevice() { } SonoDevice::~SonoDevice() { for(auto i = 0; i < SW_BUFFER_NUM; i++) { delete[] _buffers[i]; } } void SonoDevice::init() { device.init(); for(auto i = 0; i < SW_BUFFER_NUM; i++) { _buffers[i] = new char[BUFFER_SIZE]; memset(_buffers[i], 0, BUFFER_SIZE); } } void SonoDevice::startTransfer(bool emulatorEn) { if (emulatorEn) device.writeWord(0, 0x8,3);//800, START_COMMAND); else device.writeWord(0, 0x8,1);//800, START_COMMAND); } void SonoDevice::stopTransfer() { device.writeWord(0, 0x8,0);//00, STOP_COMMAND); } int SonoDevice::getCounter() { auto temp = device.readWord(BAR, COUNTER_REG); return temp & COUNTER_MASK; } void SonoDevice::setRamOffsetAddress(qint32 offset) { auto value = offset & RAM_OFFSET_MASK; device.writeWord(BAR, RAM_OFFSET_REG, value); } void SonoDevice::setTransferLength(qint32 length) { auto temp = device.readWord(BAR, XFER_OPT_REG); temp &= ~XFER_LEN_MASK; temp |= (length & XFER_LEN_MASK); device.writeWord(BAR, XFER_OPT_REG, temp); } void SonoDevice::setTransferRate(float rate) { auto value = static_cast(rate * 1E5f) & XFER_RATE_MASK; device.writeWord(BAR, XFER_RATE_REG, value); } void SonoDevice::setOptions(bool performanceMode) { auto temp = device.readWord(BAR, XFER_OPT_REG); if(performanceMode) { temp &= ~PERF_MODE_COMMAND; } else { temp |= PERF_MODE_COMMAND; } device.writeWord(BAR, XFER_OPT_REG, temp); } void SonoDevice::setMode(bool dynamicMode) { auto temp = device.readWord(BAR, XFER_OPT_REG); if(dynamicMode) { temp |= AUTO_INC_COMMAND; } else { temp &= ~AUTO_INC_COMMAND; } device.writeWord(BAR, XFER_OPT_REG, temp); } void SonoDevice::copy(int srcIndex, int dstIndex) { auto src = device.getBufferPtr(srcIndex); auto dst = _buffers[dstIndex]; memcpy(dst, src, BUFFER_SIZE); } void SonoDevice::show(int i) { auto tmp = _buffers[i]; for(auto j = 0; j < 80; j += 8) { //quint32 res = 0; //res = tmp[j] | (tmp[j + 1] << 8) | (tmp[j + 2] << 16) | (tmp[j + 3] << 24); //qDebug() << QString::number(res, 16); quint32 res = 0; quint32 res2 = 0; res = tmp[j] | (tmp[j + 1] << 8) | (tmp[j + 2] << 16) | (tmp[j + 3] << 24); res2 = (tmp[j + 4] << 32) | (tmp[j + 5] << 40) | (tmp[j + 6] << 48) | (tmp[j + 7] << 56); qDebug() << QString("%1 %2").arg(QString::number(res2, 10).rightJustified( 6, '0')).arg(QString::number(res, 10)); } } void SonoDevice::fillRam() { // QFile file( // "/home/hasis/Desktop/PCIE/pcie/PCIe_SGdma_Emulator/PCIe_SGdma_Emulator/_sram_frame_test_data/sram_frame_128x128K/sram_frame.bin"); // file.open(QIODevice::ReadOnly); // auto temp = file.readAll(); // qDebug() << temp.length() << file.errorString(); auto temp=16777216; auto din = 0; qDebug() << "fillRam :: Start"; for(auto i = 0; i < temp; i += 8) // SRAM_DDR3_Counter //for(auto i = 0; i < temp.length(); i++) // DDR3_Frame { device.writeLong(1, i, i / 8); // SRAM_DDR3_Counter //device.writeByte(1, i, temp[i]); // DDR3_Frame } for(auto i = 0; i < temp; i += 8) // SRAM_DDR3_Counter //for(auto i = 0; i < temp.length(); i++) // DDR3_Frame { din = device.readLong(1, i); // SRAM_DDR3_Counter if (din != i / 8) qDebug() << i; //device.writeByte(1, i, temp[i]); // DDR3_Frame } qDebug() << "fillRam :: Done"; } const char* SonoDevice::getBufferPtr(int index) { return _buffers[index]; }