now supports auto mode as well
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
This commit is contained in:
parent
036024db7e
commit
a92024a858
@ -4,6 +4,19 @@
|
||||
#include <fsfw/timemanager/Stopwatch.h>
|
||||
#include <fsfw_hal/linux/spi/ManualCsLockGuard.h>
|
||||
|
||||
#define OBSW_RTD_AUTO_MODE 1
|
||||
|
||||
#if OBSW_RTD_AUTO_MODE == 1
|
||||
static constexpr uint8_t BASE_CFG = (MAX31865::Bias::ON << MAX31865::CfgBitPos::BIAS_SEL) |
|
||||
(MAX31865::Wires::FOUR_WIRE << MAX31865::CfgBitPos::WIRE_SEL) |
|
||||
(MAX31865::ConvMode::AUTO << MAX31865::CfgBitPos::CONV_MODE);
|
||||
#else
|
||||
static constexpr uint8_t BASE_CFG =
|
||||
(MAX31865::Bias::OFF << MAX31865::CfgBitPos::BIAS_SEL) |
|
||||
(MAX31865::Wires::FOUR_WIRE << MAX31865::CfgBitPos::WIRE_SEL) |
|
||||
(MAX31865::ConvMode::NORM_OFF << MAX31865::CfgBitPos::CONV_MODE);
|
||||
#endif
|
||||
|
||||
Max31865RtdReader::Max31865RtdReader(object_id_t objectId, SpiComIF* lowLevelComIF, GpioIF* gpioIF)
|
||||
: SystemObject(objectId), rtds(EiveMax31855::NUM_RTDS), comIF(lowLevelComIF), gpioIF(gpioIF) {
|
||||
readerMutex = MutexFactory::instance()->createMutex();
|
||||
@ -12,21 +25,26 @@ Max31865RtdReader::Max31865RtdReader(object_id_t objectId, SpiComIF* lowLevelCom
|
||||
ReturnValue_t Max31865RtdReader::performOperation(uint8_t operationCode) {
|
||||
using namespace MAX31865;
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
static_cast<void>(result);
|
||||
// Stopwatch watch;
|
||||
if (periodicInitHandling()) {
|
||||
#if OBSW_RTD_AUTO_MODE == 0
|
||||
// 10 ms delay for VBIAS startup
|
||||
TaskFactory::delayTask(10);
|
||||
#endif
|
||||
} else {
|
||||
// No devices usable (e.g. TCS board off)
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
#if OBSW_RTD_AUTO_MODE == 0
|
||||
result = periodicReadReqHandling();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
// After requesting, 65 milliseconds delay required
|
||||
TaskFactory::delayTask(65);
|
||||
#endif
|
||||
|
||||
return periodicReadHandling();
|
||||
}
|
||||
@ -57,8 +75,7 @@ bool Max31865RtdReader::periodicInitHandling() {
|
||||
sif::error << "Max31865RtdReader::periodicInitHandling: Manual CS lock failed" << std::endl;
|
||||
break;
|
||||
}
|
||||
uint8_t cfg = rtd->defCfg;
|
||||
result = writeCfgReg(rtd->spiCookie, cfg);
|
||||
result = writeCfgReg(rtd->spiCookie, BASE_CFG);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
handleSpiError(rtd, result, "writeCfgReg");
|
||||
}
|
||||
@ -94,8 +111,10 @@ bool Max31865RtdReader::periodicInitHandling() {
|
||||
continue;
|
||||
}
|
||||
if (rtdIsActive(rtd->idx)) {
|
||||
#if OBSW_RTD_AUTO_MODE == 0
|
||||
someRtdUsable = true;
|
||||
result = writeBiasSel(Bias::ON, rtd->spiCookie, rtd->defCfg);
|
||||
result = writeBiasSel(Bias::ON, rtd->spiCookie, BASE_CFG);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return someRtdUsable;
|
||||
@ -114,7 +133,7 @@ ReturnValue_t Max31865RtdReader::periodicReadReqHandling() {
|
||||
continue;
|
||||
}
|
||||
if (rtdIsActive(rtd->idx)) {
|
||||
ReturnValue_t result = writeCfgReg(rtd->spiCookie, rtd->defCfg | (1 << CfgBitPos::ONE_SHOT));
|
||||
ReturnValue_t result = writeCfgReg(rtd->spiCookie, BASE_CFG | (1 << CfgBitPos::ONE_SHOT));
|
||||
if (result != RETURN_OK) {
|
||||
handleSpiError(rtd, result, "writeCfgReg");
|
||||
// Release mutex ASAP
|
||||
@ -152,6 +171,7 @@ ReturnValue_t Max31865RtdReader::periodicReadHandling() {
|
||||
rtd->db.adcCode = rtdVal;
|
||||
}
|
||||
}
|
||||
#if OBSW_RTD_AUTO_MODE == 0
|
||||
for (auto& rtd : rtds) {
|
||||
if (rtd == nullptr) {
|
||||
continue;
|
||||
@ -159,9 +179,10 @@ ReturnValue_t Max31865RtdReader::periodicReadHandling() {
|
||||
// Even if a device was made inactive, turn off the bias here. If it was turned off, not
|
||||
// necessary anymore..
|
||||
if (rtd->on) {
|
||||
result = writeBiasSel(Bias::OFF, rtd->spiCookie, rtd->defCfg);
|
||||
result = writeBiasSel(Bias::OFF, rtd->spiCookie, BASE_CFG);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,7 @@ struct Max31865ReaderCookie : public CookieIF {
|
||||
std::string locString = "";
|
||||
std::array<uint8_t, 12> exchangeBuf{};
|
||||
Countdown cd = Countdown(MAX31865::WARMUP_MS);
|
||||
// I'd prefer if we could use the NORM_OFF mode, but it does not work for some reason..
|
||||
uint8_t defCfg = (MAX31865::Bias::ON << MAX31865::CfgBitPos::BIAS_SEL) |
|
||||
(MAX31865::Wires::FOUR_WIRE << MAX31865::CfgBitPos::WIRE_SEL) |
|
||||
(MAX31865::ConvMode::AUTO << MAX31865::CfgBitPos::CONV_MODE);
|
||||
|
||||
bool on = false;
|
||||
bool configured = false;
|
||||
bool active = false;
|
||||
|
Loading…
Reference in New Issue
Block a user