forked from Sepanta/pcie-driver
h-4nd-h
3 years ago
10 changed files with 350 additions and 16 deletions
@ -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(); |
|||
} |
|||
|
@ -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
|
@ -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]); |
|||
} |
|||
} |
@ -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
|
Loading…
Reference in new issue