2022-01-30 17:16:17 +01:00
|
|
|
#include "AxiPtmeConfig.h"
|
|
|
|
|
2023-04-02 14:22:52 +02:00
|
|
|
#include <fsfw/ipc/MutexGuard.h>
|
|
|
|
|
2022-01-30 17:16:17 +01:00
|
|
|
#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) {
|
2022-01-30 17:16:17 +01:00
|
|
|
mutex = MutexFactory::instance()->createMutex();
|
|
|
|
if (mutex == nullptr) {
|
|
|
|
sif::warning << "Failed to create mutex" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AxiPtmeConfig::~AxiPtmeConfig() {}
|
|
|
|
|
|
|
|
ReturnValue_t AxiPtmeConfig::initialize() {
|
|
|
|
UioMapper uioMapper(axiUio, mapNum);
|
2023-06-29 14:49:57 +02:00
|
|
|
ReturnValue_t result =
|
|
|
|
uioMapper.getMappedAdress(&baseAddress, UioMapper::Permissions::READ_WRITE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-30 17:16:17 +01:00
|
|
|
return result;
|
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-30 17:16:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t AxiPtmeConfig::writeCaduRateReg(uint8_t rateVal) {
|
2023-06-29 14:49:57 +02:00
|
|
|
ReturnValue_t result = mutex->lockMutex(timeoutType, mutexTimeout);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-30 17:16:17 +01:00
|
|
|
sif::warning << "AxiPtmeConfig::writeCaduRateReg: Failed to lock mutex" << std::endl;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-01-30 17:16:17 +01:00
|
|
|
}
|
|
|
|
*(baseAddress + CADU_BITRATE_REG) = static_cast<uint32_t>(rateVal);
|
|
|
|
result = mutex->unlockMutex();
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-30 17:16:17 +01:00
|
|
|
sif::warning << "AxiPtmeConfig::writeCaduRateReg: Failed to unlock mutex" << std::endl;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-01-30 17:16:17 +01:00
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-30 17:16:17 +01:00
|
|
|
}
|
|
|
|
|
2023-06-26 14:39:03 +02:00
|
|
|
uint8_t AxiPtmeConfig::readCaduRateReg() {
|
|
|
|
MutexGuard mg(mutex);
|
|
|
|
return static_cast<uint8_t>(*(baseAddress + CADU_BITRATE_REG));
|
|
|
|
}
|
|
|
|
|
2023-04-02 14:22:52 +02:00
|
|
|
void AxiPtmeConfig::enableTxclockManipulator() {
|
|
|
|
writeBit(COMMON_CONFIG_REG, true, BitPos::EN_TX_CLK_MANIPULATOR);
|
2022-01-30 17:16:17 +01:00
|
|
|
}
|
|
|
|
|
2023-04-02 14:22:52 +02:00
|
|
|
void AxiPtmeConfig::disableTxclockManipulator() {
|
|
|
|
writeBit(COMMON_CONFIG_REG, false, BitPos::EN_TX_CLK_MANIPULATOR);
|
2022-01-30 17:16:17 +01:00
|
|
|
}
|
|
|
|
|
2023-04-02 14:22:52 +02:00
|
|
|
void AxiPtmeConfig::enableTxclockInversion() {
|
|
|
|
writeBit(COMMON_CONFIG_REG, true, BitPos::INVERT_CLOCK);
|
2022-01-30 17:16:17 +01:00
|
|
|
}
|
|
|
|
|
2023-04-02 14:22:52 +02:00
|
|
|
void AxiPtmeConfig::disableTxclockInversion() {
|
|
|
|
writeBit(COMMON_CONFIG_REG, false, BitPos::INVERT_CLOCK);
|
2022-01-30 17:16:17 +01:00
|
|
|
}
|
|
|
|
|
2023-04-02 14:22:52 +02:00
|
|
|
void AxiPtmeConfig::enableBatPriorityBit() {
|
|
|
|
writeBit(COMMON_CONFIG_REG, true, BitPos::EN_BAT_PRIORITY);
|
2023-03-17 14:51:00 +01:00
|
|
|
}
|
|
|
|
|
2023-04-02 14:22:52 +02:00
|
|
|
void AxiPtmeConfig::disableBatPriorityBit() {
|
|
|
|
writeBit(COMMON_CONFIG_REG, false, BitPos::EN_BAT_PRIORITY);
|
2023-03-17 14:51:00 +01:00
|
|
|
}
|
|
|
|
|
2023-04-02 14:22:52 +02:00
|
|
|
void AxiPtmeConfig::writeReg(uint32_t regOffset, uint32_t writeVal) {
|
|
|
|
MutexGuard mg(mutex, timeoutType, mutexTimeout);
|
2022-01-30 17:16:17 +01:00
|
|
|
*(baseAddress + regOffset / ADRESS_DIVIDER) = writeVal;
|
|
|
|
}
|
|
|
|
|
2023-04-02 14:22:52 +02:00
|
|
|
uint32_t AxiPtmeConfig::readReg(uint32_t regOffset) {
|
|
|
|
MutexGuard mg(mutex, timeoutType, mutexTimeout);
|
|
|
|
return *(baseAddress + regOffset / ADRESS_DIVIDER);
|
2022-01-30 17:16:17 +01:00
|
|
|
}
|
|
|
|
|
2023-04-02 14:22:52 +02:00
|
|
|
void AxiPtmeConfig::writePollThreshold(AxiPtmeConfig::IdlePollThreshold pollThreshold) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-04-02 15:32:04 +02:00
|
|
|
void AxiPtmeConfig::writeCommonCfgReg(uint32_t value) { writeReg(COMMON_CONFIG_REG, value); }
|
|
|
|
uint32_t AxiPtmeConfig::readCommonCfgReg() { return readReg(COMMON_CONFIG_REG); }
|
|
|
|
|
2023-04-02 14:22:52 +02:00
|
|
|
void AxiPtmeConfig::writeBit(uint32_t regOffset, bool bitVal, BitPos bitPos) {
|
|
|
|
uint32_t readVal = readReg(regOffset);
|
2022-01-31 08:09:58 +01:00
|
|
|
uint32_t writeVal =
|
|
|
|
(readVal & ~(1 << static_cast<uint32_t>(bitPos))) | bitVal << static_cast<uint32_t>(bitPos);
|
2023-04-02 14:22:52 +02:00
|
|
|
writeReg(regOffset, writeVal);
|
|
|
|
}
|