10 changed files with 278 additions and 16 deletions
@ -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(®isterField, &RegisterField::fieldUpdated, this, &BaseRegister::fieldUpdated); |
|||
_fields.append(registerField); |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void BaseRegister::fieldUpdated(quint32 value, quint32 clearMask) |
|||
{ |
|||
if(!_isSync) |
|||
{ |
|||
read(); |
|||
} |
|||
|
|||
auto temp = _readValue & clearMask; |
|||
temp |= value; |
|||
} |
@ -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
|
@ -0,0 +1,6 @@ |
|||
#include "BaseRegisterRegion.h" |
|||
|
|||
BaseRegisterRegion::BaseRegisterRegion() |
|||
{ |
|||
|
|||
} |
@ -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
|
@ -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; |
|||
} |
@ -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
|
@ -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); |
|||
} |
@ -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
|
Loading…
Reference in new issue