Browse Source

Add api

master
h-4nd-h 3 years ago
parent
commit
7abf5d300d
  1. 8
      api/SonoPcieDevice.cpp
  2. 8
      api/SonoPcieDevice.h
  3. 63
      app/Test/MainWindow.cpp
  4. 24
      app/Test/MainWindow.h
  5. 53
      app/Test/MainWindow.ui
  6. 30
      app/Test/SonoConfig.h
  7. 134
      app/Test/SonoDevice.cpp
  8. 34
      app/Test/SonoDevice.h
  9. 12
      app/Test/Test.pro
  10. 0
      app/Test/main.cpp

8
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;

8
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);

63
app/Test/MainWindow.cpp

@ -1,15 +1,76 @@
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent)
#include <QDebug>
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();
}

24
app/Test/MainWindow.h

@ -3,8 +3,11 @@
#include <QMainWindow>
#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

53
app/Test/MainWindow.ui

@ -13,8 +13,57 @@
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar"/>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>40</x>
<y>70</y>
<width>89</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>270</x>
<y>190</y>
<width>89</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>Stop</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>650</x>
<y>120</y>
<width>80</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>

30
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

134
app/Test/SonoDevice.cpp

@ -0,0 +1,134 @@
#include "SonoDevice.h"
#include <QDebug>
#include <QFile>
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<quint32>(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]);
}
}

34
app/Test/SonoDevice.h

@ -0,0 +1,34 @@
#ifndef SONODEVICE_H
#define SONODEVICE_H
#include <QObject>
#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

12
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

0
app/Test/main.cpp

Loading…
Cancel
Save