h-4nd-h 5 years ago
parent
commit
3113053916
  1. 49
      BaseRegister.cpp
  2. 36
      BaseRegister.h
  3. 6
      BaseRegisterRegion.cpp
  4. 19
      BaseRegisterRegion.h
  5. 14
      HarwareTest.pro
  6. 79
      RegisterField.cpp
  7. 27
      RegisterField.h
  8. 14
      Registers/TestRegister.cpp
  9. 16
      Registers/TestRegister.h
  10. 34
      main.cpp

49
BaseRegister.cpp

@ -0,0 +1,49 @@
#include "BaseRegister.h"
BaseRegister::BaseRegister(quint32 bar, quint32 offset, const UltraSoundDevice& usd)
{
this->_bar = bar;
this->_offset = offset;
this->_usd = usd;
_isSync = false;
}
/*************************************************************************************************/
quint32 BaseRegister::read()
{
auto readValue = _usd.readWord(_offset, _bar);
_isSync = true;
for(auto i = 0; i < _fields.length(); i++)
{
_fields[i].ExtractValue(readValue);
}
return readValue;
}
/*************************************************************************************************/
void BaseRegister::write()
{
_usd.writeWord(_offset, _bar, _value);
_isSync = false;
}
/*************************************************************************************************/
void BaseRegister::appendToList(const RegisterField& registerField)
{
connect(&registerField, &RegisterField::fieldUpdated, this, &BaseRegister::fieldUpdated);
_fields.append(registerField);
}
/*************************************************************************************************/
void BaseRegister::fieldUpdated(quint32 value, quint32 clearMask)
{
if(!_isSync)
{
read();
}
auto temp = _readValue & clearMask;
temp |= value;
}

36
BaseRegister.h

@ -0,0 +1,36 @@
#ifndef BASEREGISTER_H
#define BASEREGISTER_H
#include <QObject>
#include "api.h"
#include "RegisterField.h"
class BaseRegister : public QObject
{
Q_OBJECT
protected:
quint32 _bar;
quint32 _offset;
quint32 _value;
quint32 _readValue;
bool _isSync;
UltraSoundDevice _usd;
QList<RegisterField> _fields;
void appendToList(const RegisterField& registerField);
public:
explicit BaseRegister(quint32 _bar, quint32 _offset, const UltraSoundDevice& _usd);
quint32 read();
void write();
//uncrustify off
public slots:
void fieldUpdated(quint32 _value, quint32 clearMask);
//uncrustify on
};
#endif //BASEREGISTER_H

6
BaseRegisterRegion.cpp

@ -0,0 +1,6 @@
#include "BaseRegisterRegion.h"
BaseRegisterRegion::BaseRegisterRegion()
{
}

19
BaseRegisterRegion.h

@ -0,0 +1,19 @@
#ifndef BASEREGISTERREGION_H
#define BASEREGISTERREGION_H
#include "BaseRegister.h"
class BaseRegisterRegion
{
private:
QList<BaseRegister> _registers;
public:
BaseRegisterRegion();
void writeAll();
void readAll();
void clearAll();
};
#endif //BASEREGISTERREGION_H

14
HarwareTest.pro

@ -16,21 +16,29 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
BaseRegister.cpp \
BaseRegisterRegion.cpp \
RegisterField.cpp \
Registers/TestRegister.cpp \
main.cpp \
mainwindow.cpp \
/home/hasis/Desktop/pcie/pcie_driver/api/api.cpp \
/home/hasis/Desktop/pcie/USPCIeDriver/driver/api/api.cpp \
waitdialog.cpp
HEADERS += \
BaseRegister.h \
BaseRegisterRegion.h \
RegisterField.h \
Registers/TestRegister.h \
mainwindow.h \
/home/hasis/Desktop/pcie/pcie_driver/api/api.h \
/home/hasis/Desktop/pcie/USPCIeDriver/driver/api/api.h \
waitdialog.h
FORMS += \
mainwindow.ui \
waitdialog.ui
INCLUDEPATH += /home/hasis/Desktop/pcie/pcie_driver/api/
INCLUDEPATH += /home/hasis/Desktop/pcie/USPCIeDriver/driver/api/
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin

79
RegisterField.cpp

@ -0,0 +1,79 @@
#include "RegisterField.h"
/*************************************************************************************************/
quint32 RegisterField::getBitPosition()
{
auto bitPosition = 0U;
auto mask = _mask;
while(true)
{
if((mask & 0x01) == 0x01)
{
break;
}
bitPosition++;
mask = mask >> 1;
}
return bitPosition;
}
/*************************************************************************************************/
quint32 RegisterField::getBitLength()
{
auto bitlength = 0U;
auto mask = _mask >> getBitPosition();
while(true)
{
if((mask & 0x01) != 0x01)
{
break;
}
bitlength++;
mask = mask >> 1;
}
return bitlength;
}
/*************************************************************************************************/
RegisterField::RegisterField(quint32 mask, bool isSigned)
{
_mask = mask;
_isSigned = isSigned;
}
/*************************************************************************************************/
void RegisterField::update(quint32 value)
{
if(_value == value)
{
return;
}
_value = value;
quint32 temp = 0;
temp = (_value << getBitPosition()) & _mask;
emit fieldUpdated(_value, ~_mask);
}
/*************************************************************************************************/
quint32 RegisterField::getRawValue()
{
return _value;
}
/*************************************************************************************************/
void RegisterField::ExtractValue(quint32 value)
{
auto temp = (value >> getBitPosition()) & (_mask >> getBitPosition());
if(_isSigned && ((temp >> (getBitLength() - 1)) & 0x01) == 0x01)
{
temp |= (~(_mask >> getBitPosition()));
}
_value = temp;
}

27
RegisterField.h

@ -0,0 +1,27 @@
#ifndef REGISTERFIELD_H
#define REGISTERFIELD_H
#include <QObject>
class RegisterField : public QObject
{
Q_OBJECT
private:
quint32 _mask;
quint32 _value;
bool _isSigned;
quint32 getBitPosition();
quint32 getBitLength();
public:
RegisterField(quint32 mask, bool isSigned);
void update(quint32 value);
quint32 getRawValue();
void ExtractValue(quint32 value);
signals:
void fieldUpdated(quint32 value, quint32 clearMask);
};
#endif //REGISTERFIELD_H

14
Registers/TestRegister.cpp

@ -0,0 +1,14 @@
#include "TestRegister.h"
TestRegister::TestRegister(quint32 offset, quint32 bar, const UltraSoundDevice& usd) : BaseRegister(
offset,
bar,
usd),
fiedl1(0x000000FF, false),
fiedl2(0x0000FF00, false),
fiedl3(0xFFFF0000, false)
{
appendToList(fiedl1);
appendToList(fiedl2);
appendToList(fiedl3);
}

16
Registers/TestRegister.h

@ -0,0 +1,16 @@
#ifndef TESTREGISTER_H
#define TESTREGISTER_H
#include "BaseRegister.h"
class TestRegister : public BaseRegister
{
public:
TestRegister(quint32 _offset, quint32 _bar, const UltraSoundDevice& _usd);
RegisterField fiedl1;
RegisterField fiedl2;
RegisterField fiedl3;
};
#endif //TESTREGISTER_H

34
main.cpp

@ -4,18 +4,26 @@
#include <QStyle>
#include <QDesktopWidget>
int main(int argc, char *argv[])
#include "Registers/TestRegister.h"
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.setGeometry(
QStyle::alignedRect(
Qt::LeftToRight,
Qt::AlignCenter,
w.size(),
qApp->desktop()->availableGeometry()
)
);
w.show();
return a.exec();
QApplication a(argc, argv);
MainWindow w;
w.setGeometry(
QStyle::alignedRect(
Qt::LeftToRight,
Qt::AlignCenter,
w.size(),
qApp->desktop()->availableGeometry()
)
);
UltraSoundDevice usd;
TestRegister t(0, 0, usd);
t.fiedl1.update(2);
w.show();
return a.exec();
}

Loading…
Cancel
Save