2021-11-21 18:07:05 +01:00
|
|
|
#include "PtmeRateSetter.h"
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2021-11-21 18:07:05 +01:00
|
|
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
|
|
|
|
2022-01-24 07:43:14 +01:00
|
|
|
PtmeRateSetter::PtmeRateSetter(object_id_t objectId, PtmeAxiConfig* ptmeAxiConfig)
|
|
|
|
: SystemObject(objectId), ptmeAxiConfig(ptmeAxiConfig) {}
|
2021-11-21 18:07:05 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
PtmeRateSetter::~PtmeRateSetter() {}
|
2021-11-21 18:07:05 +01:00
|
|
|
|
2022-01-24 07:43:14 +01:00
|
|
|
ReturnValue_t PtmeRateSetter::initialize() {
|
2022-01-25 18:55:52 +01:00
|
|
|
if (ptmeAxiConfig == nullptr) {
|
|
|
|
sif::warning << "PtmeRateSetter::initialize: Invalid PtmeAxiConfig object" << std::endl;
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2022-01-24 07:43:14 +01:00
|
|
|
}
|
|
|
|
|
2022-01-25 18:55:52 +01:00
|
|
|
ReturnValue_t PtmeRateSetter::setRate(uint32_t bitRate) {
|
|
|
|
if (bitRate == 0) {
|
|
|
|
return BAD_BIT_RATE;
|
|
|
|
}
|
|
|
|
uint32_t rateVal = PtmeConfig::BIT_CLK_FREQ / bitRate - 1;
|
|
|
|
if (rateVal > 0xFF) {
|
|
|
|
return RATE_NOT_SUPPORTED;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-01-25 18:55:52 +01:00
|
|
|
return ptmeAxiConfig->writeCaduRateReg(static_cast<uint8_t>(rateVal));
|
2021-11-21 18:07:05 +01:00
|
|
|
}
|