diff --git a/api/SonoPcieDevice.cpp b/api/SonoPcieDevice.cpp index bb3168a..b22a9dc 100644 --- a/api/SonoPcieDevice.cpp +++ b/api/SonoPcieDevice.cpp @@ -52,25 +52,25 @@ void SonoPcieDevice::initDmaBuffers() } } - void SonoPcieDevice::writeByte(uint32_t bar, uint8_t data, uint32_t offset) + void SonoPcieDevice::writeByte(uint32_t bar, uint32_t offset, uint8_t data) { uint8_t* temp = (uint8_t*)bars[bar].ptr; temp[offset] = data; } - void SonoPcieDevice::writeShort(uint32_t bar, uint16_t data, uint32_t offset) + void SonoPcieDevice::writeShort(uint32_t bar, uint32_t offset, uint16_t data) { uint16_t* temp = (uint16_t*)bars[bar].ptr; temp[offset / 2] = data; } - void SonoPcieDevice::writeWord(uint32_t bar, uint32_t data, uint32_t offset) + void SonoPcieDevice::writeWord(uint32_t bar, uint32_t offset, uint32_t data) { uint32_t* temp = (uint32_t*)bars[bar].ptr; temp[offset / 4] = data; } - void SonoPcieDevice::writeLong(uint32_t bar, uint64_t data, uint32_t offset) + void SonoPcieDevice::writeLong(uint32_t bar, uint32_t offset, uint64_t data) { uint64_t* temp = (uint64_t*)bars[bar].ptr; temp[offset / 8] = data; diff --git a/api/SonoPcieDevice.h b/api/SonoPcieDevice.h index f1e24a6..83b0ecf 100644 --- a/api/SonoPcieDevice.h +++ b/api/SonoPcieDevice.h @@ -26,10 +26,10 @@ public: void init(); - void writeByte(uint32_t bar, uint8_t data, uint32_t offset); - void writeShort(uint32_t bar, uint16_t data, uint32_t offset); - void writeWord(uint32_t bar, uint32_t data, uint32_t offset); - void writeLong(uint32_t bar, uint64_t data, uint32_t offset); + void writeByte(uint32_t bar, uint32_t offset, uint8_t data); + void writeShort(uint32_t bar, uint32_t offset, uint16_t data); + void writeWord(uint32_t bar, uint32_t offset, uint32_t data); + void writeLong(uint32_t bar, uint32_t offset, uint64_t data); uint8_t readByte(uint32_t bar, uint32_t offset); uint16_t readShort(uint32_t bar, uint32_t offset); diff --git a/app/Test/MainWindow.cpp b/app/Test/MainWindow.cpp old mode 100644 new mode 100755 index ec12972..6904fca --- a/app/Test/MainWindow.cpp +++ b/app/Test/MainWindow.cpp @@ -1,15 +1,76 @@ #include "MainWindow.h" #include "ui_MainWindow.h" -MainWindow::MainWindow(QWidget *parent) +#include + +MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); + sd = new SonoDevice(); + sd->init(); + _counter = 0; } MainWindow::~MainWindow() { delete ui; + delete sd; +} + +void MainWindow::on_pushButton_clicked() +{ + sd->setRamOffsetAddress(0); + sd->setTransferLength(1024 * 1024); + sd->setOptions(false); + sd->setMode(true); + sd->setTransferRate(8.4f); + sd->startTransfer(); + + _counter = sd->getCounter(); + int buffersTransferred = 0; + + while(true) + { + auto cnt = sd->getCounter(); + if(cnt == 0) + { + continue; + } + if(_counter != cnt) + { + _counter++; + if(_counter == 17) + { + _counter = 1; + } + qDebug() << _counter << " --- " << cnt; + sd->copy(_counter - 1); + buffersTransferred++; + } + if(buffersTransferred == 16) + { +//buffersTransferred = 0; +//sd->startTransfer(); + break; + } + } + sd->stopTransfer(); + + for(auto i = 0; i < 16; i++) + { + qDebug() << i << " ----------------------------- "; + sd->show(i); + } +} + +void MainWindow::on_pushButton_2_clicked() +{ + sd->stopTransfer(); } +void MainWindow::on_pushButton_3_clicked() +{ + sd->fillRam(); +} diff --git a/app/Test/MainWindow.h b/app/Test/MainWindow.h old mode 100644 new mode 100755 index 274dd1b..657e5ea --- a/app/Test/MainWindow.h +++ b/app/Test/MainWindow.h @@ -3,8 +3,11 @@ #include +#include "SonoDevice.h" + QT_BEGIN_NAMESPACE -namespace Ui { class MainWindow; } +namespace Ui { class MainWindow; +} QT_END_NAMESPACE class MainWindow : public QMainWindow @@ -12,10 +15,23 @@ class MainWindow : public QMainWindow Q_OBJECT public: - MainWindow(QWidget *parent = nullptr); + MainWindow(QWidget* parent = nullptr); ~MainWindow(); +//uncrustify off +private slots: +//uncrustify on + void on_pushButton_clicked(); + + void on_pushButton_2_clicked(); + + void on_pushButton_3_clicked(); + private: - Ui::MainWindow *ui; + Ui::MainWindow* ui; + + SonoDevice* sd; + int _counter; }; -#endif // MAINWINDOW_H + +#endif //MAINWINDOW_H diff --git a/app/Test/MainWindow.ui b/app/Test/MainWindow.ui old mode 100644 new mode 100755 index b232854..9970922 --- a/app/Test/MainWindow.ui +++ b/app/Test/MainWindow.ui @@ -13,8 +13,57 @@ MainWindow - - + + + + + 40 + 70 + 89 + 25 + + + + Start + + + + + + 270 + 190 + 89 + 25 + + + + Stop + + + + + + 650 + 120 + 80 + 23 + + + + PushButton + + + + + + + 0 + 0 + 800 + 20 + + + diff --git a/app/Test/SonoConfig.h b/app/Test/SonoConfig.h new file mode 100755 index 0000000..802edc3 --- /dev/null +++ b/app/Test/SonoConfig.h @@ -0,0 +1,30 @@ +#ifndef SONOADDRESS_H +#define SONOADDRESS_H + +#define BAR 2 + +#define BUFFER_NUM 20 +#define BUFFER_SIZE 4 * 1024 * 1024 + +#define COUNTER_REG 0x00002020 +#define RAM_OFFSET_REG 0x00002024 +#define XFER_OPT_REG 0x00002028 +#define XFER_RATE_REG 0x0000202C +#define CONTROL_REG 0x00002030 + +#define START_COMMAND 0x00000001 +#define STOP_COMMAND 0x00000000 + +#define COUNTER_MASK 0x0000001F + +#define RAM_OFFSET_MASK 0x00FFFFFF + +#define XFER_LEN_MASK 0x007FFFFF + +#define AUTO_INC_COMMAND 0x40000000 + +#define PERF_MODE_COMMAND 0x80000000 + +#define XFER_RATE_MASK 0x003FFFFF + +#endif //SONOADDRESS_H diff --git a/app/Test/SonoDevice.cpp b/app/Test/SonoDevice.cpp new file mode 100755 index 0000000..d8b4ebc --- /dev/null +++ b/app/Test/SonoDevice.cpp @@ -0,0 +1,134 @@ +#include "SonoDevice.h" + +#include +#include + +SonoDevice::SonoDevice() +{ +} + +SonoDevice::~SonoDevice() +{ + for(auto i = 0; i < BUFFER_NUM; i++) + { + delete[] _buffers[i]; + } +} + +void SonoDevice::init() +{ + _device.init(); + + for(auto i = 0; i < BUFFER_NUM; i++) + { + _buffers[i] = new quint8[BUFFER_SIZE]; + memset(_buffers[i], 0, BUFFER_SIZE); + } +} + +void SonoDevice::startTransfer() +{ + _device.writeWord(BAR, CONTROL_REG, START_COMMAND); +} + +void SonoDevice::stopTransfer() +{ + _device.writeWord(BAR, CONTROL_REG, 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 i) +{ + auto src = _device.getBufferPtr(i); + auto dst = _buffers[i]; + memcpy(dst, src, BUFFER_SIZE); +} + +void SonoDevice::show(int i) +{ + auto tmp = _buffers[i]; + for(auto j = 0; j < 40; j += 4) + { + quint32 res = 0; + res = tmp[j] | (tmp[j + 1] << 8) | (tmp[j + 2] << 16) | (tmp[j + 3] << 24); + qDebug() << QString::number(res, 16); + } +} + +void SonoDevice::fillRam() +{ + QFile file( + "/home/hasis/Desktop/Hardware/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.close(); + + for(auto i = 0; i < temp.length(); i++) + { + _device.writeByte(1, i, temp[i]); + } +} diff --git a/app/Test/SonoDevice.h b/app/Test/SonoDevice.h new file mode 100755 index 0000000..969f3df --- /dev/null +++ b/app/Test/SonoDevice.h @@ -0,0 +1,34 @@ +#ifndef SONODEVICE_H +#define SONODEVICE_H + +#include + +#include "SonoPcieDevice.h" +#include "SonoConfig.h" + +class SonoDevice +{ +private: + quint8* _buffers[BUFFER_NUM]; + +public: + SonoPcieDevice device; + + SonoDevice(); + ~SonoDevice(); + + void init(); + void startTransfer(); + void stopTransfer(); + int getCounter(); + void setRamOffsetAddress(qint32 offset); + void setTransferLength(qint32 length); + void setTransferRate(float rate); + void setOptions(bool performanceMode); + void setMode(bool dynamicMode); + void copy(int i); + void show(int i); + void fillRam(); +}; + +#endif //SONODEVICE_H diff --git a/app/Test/Test.pro b/app/Test/Test.pro old mode 100644 new mode 100755 index b6fdfca..8b18920 --- a/app/Test/Test.pro +++ b/app/Test/Test.pro @@ -16,11 +16,14 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + SonoDevice.cpp \ main.cpp \ MainWindow.cpp HEADERS += \ - MainWindow.h + MainWindow.h \ + SonoConfig.h \ + SonoDevice.h FORMS += \ MainWindow.ui @@ -29,3 +32,10 @@ FORMS += \ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +unix:!macx: LIBS += -L$$PWD/../../api/ -lSonoPcieDevice + +INCLUDEPATH += $$PWD/../../api +DEPENDPATH += $$PWD/../../api + +unix:!macx: PRE_TARGETDEPS += $$PWD/../../api/libSonoPcieDevice.a diff --git a/app/Test/main.cpp b/app/Test/main.cpp old mode 100644 new mode 100755