added eive specific max31865 handler
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
#include <linux/devices/Max31865RtdReader.h>
|
||||
|
||||
Max31865RtdReader::Max31865RtdReader(object_id_t objectId, SpiComIF* comIF)
|
||||
: SystemObject(objectId), rtds(NUM_RTDS), comIF(comIF) {
|
||||
: SystemObject(objectId), rtds(EiveMax31855::NUM_RTDS), comIF(comIF) {
|
||||
readerMutex = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
@ -32,8 +32,8 @@ void Max31865RtdReader::rtdMainLoop() {
|
||||
periodicReadHandling();
|
||||
}
|
||||
|
||||
bool Max31865RtdReader::rtdCanBeUsed(uint8_t idx) {
|
||||
if (rtds[idx]->active and rtds[idx]->configured) {
|
||||
bool Max31865RtdReader::rtdIsActive(uint8_t idx) {
|
||||
if (rtds[idx]->on and rtds[idx]->active and rtds[idx]->configured) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -48,24 +48,26 @@ bool Max31865RtdReader::periodicInitHandling() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool someRtdActive = false;
|
||||
bool someRtdOn = false;
|
||||
for (auto& rtd : rtds) {
|
||||
if (rtd == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (rtd->active and not rtd->configured) {
|
||||
someRtdActive = true;
|
||||
uint8_t cfg = (Bias::OFF << CfgBitPos::BIAS_SEL) | (Wires::FOUR_WIRE << CfgBitPos::WIRE_SEL) |
|
||||
(ConvMode::NORM_OFF << CfgBitPos::CONV_MODE) |
|
||||
(1 << CfgBitPos::FAULTY_STATUS_CLEAR);
|
||||
result = writeCfgReg(rtd->spiCookie, cfg);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
// TODO: Check retval
|
||||
if (rtd->on and not rtd->configured) {
|
||||
if (rtd->cd.hasTimedOut()) {
|
||||
uint8_t cfg =
|
||||
(Bias::OFF << CfgBitPos::BIAS_SEL) | (Wires::FOUR_WIRE << CfgBitPos::WIRE_SEL) |
|
||||
(ConvMode::NORM_OFF << CfgBitPos::CONV_MODE) | (1 << CfgBitPos::FAULTY_STATUS_CLEAR);
|
||||
result = writeCfgReg(rtd->spiCookie, cfg);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
// TODO: Check retval
|
||||
}
|
||||
someRtdOn = true;
|
||||
rtd->configured = true;
|
||||
}
|
||||
rtd->configured = true;
|
||||
}
|
||||
}
|
||||
if (not someRtdActive) {
|
||||
if (not someRtdOn) {
|
||||
return false;
|
||||
}
|
||||
bool someRtdUsable = false;
|
||||
@ -73,7 +75,7 @@ bool Max31865RtdReader::periodicInitHandling() {
|
||||
if (rtd == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (rtdCanBeUsed(rtd->idx)) {
|
||||
if (rtdIsActive(rtd->idx)) {
|
||||
someRtdUsable = true;
|
||||
result = biasSel(Bias::ON, rtd->spiCookie);
|
||||
}
|
||||
@ -93,7 +95,7 @@ void Max31865RtdReader::periodicReadReqHandling() {
|
||||
if (rtd == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (rtd->active) {
|
||||
if (rtdIsActive(rtd->idx)) {
|
||||
uint8_t currentCfg = 0;
|
||||
auto result = readCfgReg(rtd->spiCookie, currentCfg);
|
||||
if (result != RETURN_OK) {
|
||||
@ -119,7 +121,7 @@ void Max31865RtdReader::periodicReadHandling() {
|
||||
if (rtd == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (rtd->active) {
|
||||
if (rtdIsActive(rtd->idx)) {
|
||||
uint16_t rtdVal = 0;
|
||||
bool faultBitSet = false;
|
||||
result = readRtdVal(rtd->spiCookie, rtdVal, faultBitSet);
|
||||
@ -137,7 +139,9 @@ void Max31865RtdReader::periodicReadHandling() {
|
||||
if (rtd == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (rtd->active) {
|
||||
// Even if a device was made inactive, turn off the bias here. If it was turned off, not
|
||||
// necessary anymore..
|
||||
if (rtd->on) {
|
||||
result = biasSel(Bias::OFF, rtd->spiCookie);
|
||||
}
|
||||
}
|
||||
@ -152,7 +156,7 @@ ReturnValue_t Max31865RtdReader::initializeInterface(CookieIF* cookie) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
if (rtdCookie->idx > NUM_RTDS) {
|
||||
if (rtdCookie->idx > EiveMax31855::NUM_RTDS) {
|
||||
throw std::invalid_argument("Invalid RTD index");
|
||||
}
|
||||
rtds[rtdCookie->idx] = rtdCookie;
|
||||
@ -178,21 +182,40 @@ ReturnValue_t Max31865RtdReader::sendMessage(CookieIF* cookie, const uint8_t* se
|
||||
// TODO: Emit warning, invalid command
|
||||
return RETURN_OK;
|
||||
}
|
||||
auto cmd = static_cast<RtdCommands>(sendData[0]);
|
||||
auto cmd = static_cast<EiveMax31855::RtdCommands>(sendData[0]);
|
||||
switch (cmd) {
|
||||
case (RtdCommands::ON): {
|
||||
if (not rtdCookie->active) {
|
||||
rtdCookie->active = true;
|
||||
case (EiveMax31855::RtdCommands::ON): {
|
||||
if (not rtdCookie->on) {
|
||||
rtdCookie->cd.setTimeout(MAX31865::WARMUP_MS);
|
||||
rtdCookie->cd.resetTimer();
|
||||
rtdCookie->on = true;
|
||||
rtdCookie->active = false;
|
||||
rtdCookie->configured = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (RtdCommands::OFF): {
|
||||
case (EiveMax31855::RtdCommands::ACTIVE): {
|
||||
if (not rtdCookie->on) {
|
||||
rtdCookie->cd.setTimeout(MAX31865::WARMUP_MS);
|
||||
rtdCookie->cd.resetTimer();
|
||||
rtdCookie->on = true;
|
||||
rtdCookie->active = true;
|
||||
rtdCookie->configured = false;
|
||||
} else {
|
||||
rtdCookie->active = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (EiveMax31855::RtdCommands::OFF): {
|
||||
rtdCookie->on = false;
|
||||
rtdCookie->active = false;
|
||||
rtdCookie->configured = false;
|
||||
break;
|
||||
}
|
||||
case (RtdCommands::CFG): {
|
||||
case (EiveMax31855::RtdCommands::HIGH_TRESHOLD):
|
||||
case (EiveMax31855::RtdCommands::LOW_THRESHOLD):
|
||||
case (EiveMax31855::RtdCommands::CFG):
|
||||
default: {
|
||||
// TODO: Only implement if needed
|
||||
break;
|
||||
}
|
||||
|
@ -9,32 +9,6 @@
|
||||
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
||||
#include "mission/devices/devicedefinitions/Max31865Definitions.h"
|
||||
|
||||
static constexpr uint8_t NUM_RTDS = 16;
|
||||
|
||||
enum RtdCommands : uint8_t { ON = 0, OFF = 1, CFG = 2 };
|
||||
|
||||
class ReadOutStruct : public SerialLinkedListAdapter<SerializeIF> {
|
||||
public:
|
||||
ReadOutStruct() { setLinks(); }
|
||||
ReadOutStruct(uint32_t spiErrCnt, bool faultBitSet, uint8_t faultVal, uint16_t rtdVal)
|
||||
: spiErrorCount(spiErrCnt), faultBitSet(faultBitSet), faultValue(faultVal), rtdVal(rtdVal) {
|
||||
setLinks();
|
||||
}
|
||||
|
||||
SerializeElement<uint32_t> spiErrorCount = 0;
|
||||
SerializeElement<bool> faultBitSet = false;
|
||||
SerializeElement<uint8_t> faultValue = 0;
|
||||
SerializeElement<uint16_t> rtdVal = 0;
|
||||
|
||||
private:
|
||||
void setLinks() {
|
||||
setStart(&spiErrorCount);
|
||||
spiErrorCount.setNext(&faultBitSet);
|
||||
faultBitSet.setNext(&faultValue);
|
||||
faultValue.setNext(&rtdVal);
|
||||
};
|
||||
};
|
||||
|
||||
struct Max31865ReaderCookie {
|
||||
Max31865ReaderCookie(){};
|
||||
Max31865ReaderCookie(object_id_t handlerId_, uint8_t idx_, const std::string& locString_,
|
||||
@ -46,14 +20,14 @@ struct Max31865ReaderCookie {
|
||||
|
||||
std::string locString = "";
|
||||
std::array<uint8_t, 12> exchangeBuf{};
|
||||
bool active = false;
|
||||
|
||||
Countdown cd = Countdown(MAX31865::WARMUP_MS);
|
||||
bool on = false;
|
||||
bool configured = false;
|
||||
|
||||
bool active = false;
|
||||
SpiCookie* spiCookie = nullptr;
|
||||
|
||||
// Exchange data buffer struct
|
||||
ReadOutStruct db;
|
||||
EiveMax31855::ReadOutStruct db;
|
||||
};
|
||||
|
||||
class Max31865RtdReader : public SystemObject,
|
||||
@ -74,7 +48,7 @@ class Max31865RtdReader : public SystemObject,
|
||||
void periodicReadReqHandling();
|
||||
void periodicReadHandling();
|
||||
|
||||
bool rtdCanBeUsed(uint8_t idx);
|
||||
bool rtdIsActive(uint8_t idx);
|
||||
ReturnValue_t writeCfgReg(SpiCookie* cookie, uint8_t cfg);
|
||||
ReturnValue_t biasSel(MAX31865::Bias bias, SpiCookie* cookie);
|
||||
ReturnValue_t readCfgReg(SpiCookie* cookie, uint8_t& cfg);
|
||||
|
Reference in New Issue
Block a user