|
|
|
#include "model/hardware/device/SonoDevice.h"
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
|
|
|
|
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::startDma()
|
|
|
|
{
|
|
|
|
quint32 dmaCtrl = device.readWord(BAR_REG, DMA_CTRL_REG);
|
|
|
|
device.writeWord(BAR_REG, DMA_CTRL_REG, START_COMMAND|dmaCtrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SonoDevice::stopDma()
|
|
|
|
{
|
|
|
|
quint32 dmaCtrl = device.readWord(BAR_REG, DMA_CTRL_REG);
|
|
|
|
device.writeWord(BAR_REG, DMA_CTRL_REG, STOP_COMMAND&dmaCtrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SonoDevice::getCounter()
|
|
|
|
{
|
|
|
|
auto temp = device.readWord(BAR_BRAM, COUNTER_REG);
|
|
|
|
|
|
|
|
return temp & COUNTER_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SonoDevice::resetCounter()
|
|
|
|
{
|
|
|
|
device.writeWord(BAR_BRAM, COUNTER_REG, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SonoDevice::isDmaBusy()
|
|
|
|
{
|
|
|
|
auto temp = device.readWord(BAR_BRAM, COUNTER_REG);
|
|
|
|
|
|
|
|
return ((temp & BUSY_MASK) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SonoDevice::copy(int srcIndex, int dstIndex)
|
|
|
|
{
|
|
|
|
auto src = device.getBufferPtr(srcIndex);
|
|
|
|
auto dst = _buffers[dstIndex];
|
|
|
|
memcpy(dst, src, BUFFER_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* SonoDevice::getBufferPtr(int index)
|
|
|
|
{
|
|
|
|
return _buffers[index];
|
|
|
|
}
|