add SW IF for manipulating poll threshold
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
#include "AxiPtmeConfig.h"
|
||||
|
||||
#include <fsfw/ipc/MutexGuard.h>
|
||||
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
#include "fsfw_hal/linux/uio/UioMapper.h"
|
||||
|
||||
@ -39,97 +41,62 @@ ReturnValue_t AxiPtmeConfig::writeCaduRateReg(uint8_t rateVal) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t AxiPtmeConfig::enableTxclockManipulator() {
|
||||
ReturnValue_t result = writeBit(COMMON_CONFIG_REG, true, BitPos::EN_TX_CLK_MANIPULATOR);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
void AxiPtmeConfig::enableTxclockManipulator() {
|
||||
writeBit(COMMON_CONFIG_REG, true, BitPos::EN_TX_CLK_MANIPULATOR);
|
||||
}
|
||||
|
||||
ReturnValue_t AxiPtmeConfig::disableTxclockManipulator() {
|
||||
ReturnValue_t result = writeBit(COMMON_CONFIG_REG, false, BitPos::EN_TX_CLK_MANIPULATOR);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
void AxiPtmeConfig::disableTxclockManipulator() {
|
||||
writeBit(COMMON_CONFIG_REG, false, BitPos::EN_TX_CLK_MANIPULATOR);
|
||||
}
|
||||
|
||||
ReturnValue_t AxiPtmeConfig::enableTxclockInversion() {
|
||||
ReturnValue_t result = writeBit(COMMON_CONFIG_REG, true, BitPos::INVERT_CLOCK);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
void AxiPtmeConfig::enableTxclockInversion() {
|
||||
writeBit(COMMON_CONFIG_REG, true, BitPos::INVERT_CLOCK);
|
||||
}
|
||||
|
||||
ReturnValue_t AxiPtmeConfig::disableTxclockInversion() {
|
||||
ReturnValue_t result = writeBit(COMMON_CONFIG_REG, false, BitPos::INVERT_CLOCK);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
void AxiPtmeConfig::disableTxclockInversion() {
|
||||
writeBit(COMMON_CONFIG_REG, false, BitPos::INVERT_CLOCK);
|
||||
}
|
||||
|
||||
ReturnValue_t AxiPtmeConfig::enableBatPriorityBit() {
|
||||
ReturnValue_t result = writeBit(COMMON_CONFIG_REG, true, BitPos::EN_BAT_PRIORITY);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
void AxiPtmeConfig::enableBatPriorityBit() {
|
||||
writeBit(COMMON_CONFIG_REG, true, BitPos::EN_BAT_PRIORITY);
|
||||
}
|
||||
|
||||
ReturnValue_t AxiPtmeConfig::disableBatPriorityBit() {
|
||||
ReturnValue_t result = writeBit(COMMON_CONFIG_REG, false, BitPos::EN_BAT_PRIORITY);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
void AxiPtmeConfig::disableBatPriorityBit() {
|
||||
writeBit(COMMON_CONFIG_REG, false, BitPos::EN_BAT_PRIORITY);
|
||||
}
|
||||
|
||||
ReturnValue_t AxiPtmeConfig::writeReg(uint32_t regOffset, uint32_t writeVal) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
result = mutex->lockMutex(timeoutType, mutexTimeout);
|
||||
if (result != returnvalue::OK) {
|
||||
sif::warning << "AxiPtmeConfig::readReg: Failed to lock mutex" << std::endl;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
void AxiPtmeConfig::writeReg(uint32_t regOffset, uint32_t writeVal) {
|
||||
MutexGuard mg(mutex, timeoutType, mutexTimeout);
|
||||
*(baseAddress + regOffset / ADRESS_DIVIDER) = writeVal;
|
||||
result = mutex->unlockMutex();
|
||||
if (result != returnvalue::OK) {
|
||||
sif::warning << "AxiPtmeConfig::readReg: Failed to unlock mutex" << std::endl;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t AxiPtmeConfig::readReg(uint32_t regOffset, uint32_t* readVal) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
result = mutex->lockMutex(timeoutType, mutexTimeout);
|
||||
if (result != returnvalue::OK) {
|
||||
sif::warning << "AxiPtmeConfig::readReg: Failed to lock mutex" << std::endl;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
*readVal = *(baseAddress + regOffset / ADRESS_DIVIDER);
|
||||
result = mutex->unlockMutex();
|
||||
if (result != returnvalue::OK) {
|
||||
sif::warning << "AxiPtmeConfig::readReg: Failed to unlock mutex" << std::endl;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
uint32_t AxiPtmeConfig::readReg(uint32_t regOffset) {
|
||||
MutexGuard mg(mutex, timeoutType, mutexTimeout);
|
||||
return *(baseAddress + regOffset / ADRESS_DIVIDER);
|
||||
}
|
||||
|
||||
ReturnValue_t AxiPtmeConfig::writeBit(uint32_t regOffset, bool bitVal, BitPos bitPos) {
|
||||
uint32_t readVal = 0;
|
||||
ReturnValue_t result = readReg(regOffset, &readVal);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
void AxiPtmeConfig::writePollThreshold(AxiPtmeConfig::IdlePollThreshold pollThreshold) {
|
||||
MutexGuard mg(mutex, timeoutType, mutexTimeout);
|
||||
uint32_t regVal = readCommonCfgReg();
|
||||
// Clear bits first
|
||||
regVal &= ~(0b111 << 3);
|
||||
regVal |= (static_cast<uint8_t>(pollThreshold) << 3);
|
||||
writeCommonCfgReg(regVal);
|
||||
}
|
||||
|
||||
AxiPtmeConfig::IdlePollThreshold AxiPtmeConfig::readPollThreshold() {
|
||||
uint32_t regVal = readCommonCfgReg();
|
||||
return static_cast<AxiPtmeConfig::IdlePollThreshold>((regVal >> 3) & 0b111);
|
||||
}
|
||||
|
||||
void AxiPtmeConfig::writeBit(uint32_t regOffset, bool bitVal, BitPos bitPos) {
|
||||
uint32_t readVal = readReg(regOffset);
|
||||
uint32_t writeVal =
|
||||
(readVal & ~(1 << static_cast<uint32_t>(bitPos))) | bitVal << static_cast<uint32_t>(bitPos);
|
||||
result = writeReg(regOffset, writeVal);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
writeReg(regOffset, writeVal);
|
||||
}
|
||||
|
||||
uint32_t AxiPtmeConfig::readCommonCfgReg() {
|
||||
MutexGuard mg(mutex, timeoutType, mutexTimeout);
|
||||
return *(baseAddress + COMMON_CONFIG_REG / ADRESS_DIVIDER);
|
||||
}
|
||||
|
Reference in New Issue
Block a user