Fork for kernel 5.18 API change.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

134 lines
2.3 KiB

#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]);
}
}