eive-obsw/linux/obc/AxiPtmeConfig.cpp

120 lines
3.9 KiB
C++
Raw Normal View History

#include "AxiPtmeConfig.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw_hal/linux/uio/UioMapper.h"
AxiPtmeConfig::AxiPtmeConfig(object_id_t objectId, std::string axiUio, int mapNum)
2022-10-27 14:02:34 +02:00
: SystemObject(objectId), axiUio(std::move(axiUio)), mapNum(mapNum) {
mutex = MutexFactory::instance()->createMutex();
if (mutex == nullptr) {
sif::warning << "Failed to create mutex" << std::endl;
}
}
AxiPtmeConfig::~AxiPtmeConfig() {}
ReturnValue_t AxiPtmeConfig::initialize() {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
UioMapper uioMapper(axiUio, mapNum);
result = uioMapper.getMappedAdress(&baseAddress, UioMapper::Permissions::READ_WRITE);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t AxiPtmeConfig::writeCaduRateReg(uint8_t rateVal) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
result = mutex->lockMutex(timeoutType, mutexTimeout);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::warning << "AxiPtmeConfig::writeCaduRateReg: Failed to lock mutex" << std::endl;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
}
*(baseAddress + CADU_BITRATE_REG) = static_cast<uint32_t>(rateVal);
result = mutex->unlockMutex();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::warning << "AxiPtmeConfig::writeCaduRateReg: Failed to unlock mutex" << std::endl;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t AxiPtmeConfig::enableTxclockManipulator() {
ReturnValue_t result = writeBit(COMMON_CONFIG_REG, true, BitPos::EN_TX_CLK_MANIPULATOR);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t AxiPtmeConfig::disableTxclockManipulator() {
ReturnValue_t result = writeBit(COMMON_CONFIG_REG, false, BitPos::EN_TX_CLK_MANIPULATOR);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t AxiPtmeConfig::enableTxclockInversion() {
ReturnValue_t result = writeBit(COMMON_CONFIG_REG, true, BitPos::INVERT_CLOCK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t AxiPtmeConfig::disableTxclockInversion() {
ReturnValue_t result = writeBit(COMMON_CONFIG_REG, false, BitPos::INVERT_CLOCK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t AxiPtmeConfig::writeReg(uint32_t regOffset, uint32_t writeVal) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
result = mutex->lockMutex(timeoutType, mutexTimeout);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::warning << "AxiPtmeConfig::readReg: Failed to lock mutex" << std::endl;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
}
*(baseAddress + regOffset / ADRESS_DIVIDER) = writeVal;
result = mutex->unlockMutex();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::warning << "AxiPtmeConfig::readReg: Failed to unlock mutex" << std::endl;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t AxiPtmeConfig::readReg(uint32_t regOffset, uint32_t* readVal) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
result = mutex->lockMutex(timeoutType, mutexTimeout);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::warning << "AxiPtmeConfig::readReg: Failed to lock mutex" << std::endl;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
}
*readVal = *(baseAddress + regOffset / ADRESS_DIVIDER);
result = mutex->unlockMutex();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::warning << "AxiPtmeConfig::readReg: Failed to unlock mutex" << std::endl;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t AxiPtmeConfig::writeBit(uint32_t regOffset, bool bitVal, BitPos bitPos) {
uint32_t readVal = 0;
ReturnValue_t result = readReg(regOffset, &readVal);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
2022-01-31 08:09:58 +01:00
uint32_t writeVal =
(readVal & ~(1 << static_cast<uint32_t>(bitPos))) | bitVal << static_cast<uint32_t>(bitPos);
result = writeReg(regOffset, writeVal);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}