2022-05-09 21:29:54 +02:00
|
|
|
#ifndef LINUX_DEVICES_MAX31865RTDREADER_H_
|
|
|
|
#define LINUX_DEVICES_MAX31865RTDREADER_H_
|
|
|
|
|
|
|
|
#include <fsfw/ipc/MutexIF.h>
|
|
|
|
#include <fsfw/tasks/ExecutableObjectIF.h>
|
|
|
|
#include <fsfw_hal/linux/spi/SpiComIF.h>
|
|
|
|
#include <fsfw_hal/linux/spi/SpiCookie.h>
|
|
|
|
|
|
|
|
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
|
|
|
#include "mission/devices/devicedefinitions/Max31865Definitions.h"
|
|
|
|
|
2022-05-12 12:12:47 +02:00
|
|
|
struct Max31865ReaderCookie : public CookieIF {
|
2022-05-09 21:29:54 +02:00
|
|
|
Max31865ReaderCookie(){};
|
|
|
|
Max31865ReaderCookie(object_id_t handlerId_, uint8_t idx_, const std::string& locString_,
|
|
|
|
SpiCookie* spiCookie_)
|
|
|
|
: idx(idx_), handlerId(handlerId_), locString(locString_), spiCookie(spiCookie_) {}
|
|
|
|
|
|
|
|
uint8_t idx = 0;
|
|
|
|
object_id_t handlerId = objects::NO_OBJECT;
|
|
|
|
|
|
|
|
std::string locString = "";
|
|
|
|
std::array<uint8_t, 12> exchangeBuf{};
|
2022-05-12 09:48:41 +02:00
|
|
|
Countdown cd = Countdown(MAX31865::WARMUP_MS);
|
2022-05-14 17:04:51 +02:00
|
|
|
// 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);
|
2022-05-12 09:48:41 +02:00
|
|
|
bool on = false;
|
2022-05-09 21:29:54 +02:00
|
|
|
bool configured = false;
|
2022-05-12 09:48:41 +02:00
|
|
|
bool active = false;
|
2022-05-12 11:27:30 +02:00
|
|
|
bool writeLowThreshold = false;
|
|
|
|
bool writeHighThreshold = false;
|
|
|
|
uint16_t lowThreshold = 0;
|
|
|
|
uint16_t highThreshold = 0;
|
2022-05-09 21:29:54 +02:00
|
|
|
SpiCookie* spiCookie = nullptr;
|
|
|
|
|
|
|
|
// Exchange data buffer struct
|
2022-05-12 09:48:41 +02:00
|
|
|
EiveMax31855::ReadOutStruct db;
|
2022-05-09 21:29:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class Max31865RtdReader : public SystemObject,
|
|
|
|
public ExecutableObjectIF,
|
|
|
|
public DeviceCommunicationIF {
|
|
|
|
public:
|
2022-05-14 11:34:25 +02:00
|
|
|
Max31865RtdReader(object_id_t objectId, SpiComIF* lowLevelComIF, GpioIF* gpioIF);
|
2022-05-09 21:29:54 +02:00
|
|
|
|
|
|
|
[[noreturn]] ReturnValue_t performOperation(uint8_t operationCode) override;
|
2022-05-14 11:34:25 +02:00
|
|
|
ReturnValue_t initialize() override;
|
2022-05-09 21:29:54 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Max31865ReaderCookie*> rtds;
|
2022-05-12 11:27:30 +02:00
|
|
|
std::array<uint8_t, 4> cmdBuf = {};
|
2022-05-14 09:41:28 +02:00
|
|
|
size_t dbLen = 0;
|
2022-05-09 21:29:54 +02:00
|
|
|
MutexIF* readerMutex;
|
|
|
|
|
2022-05-14 11:34:25 +02:00
|
|
|
SpiComIF* comIF;
|
|
|
|
GpioIF* gpioIF;
|
|
|
|
MutexIF::TimeoutType csTimeoutType = MutexIF::TimeoutType::BLOCKING;
|
|
|
|
uint32_t csTimeoutMs = 0;
|
|
|
|
MutexIF* csLock = nullptr;
|
|
|
|
|
2022-05-09 21:29:54 +02:00
|
|
|
void rtdMainLoop();
|
|
|
|
bool periodicInitHandling();
|
2022-05-14 17:04:51 +02:00
|
|
|
ReturnValue_t periodicReadReqHandling();
|
|
|
|
ReturnValue_t periodicReadHandling();
|
2022-05-09 21:29:54 +02:00
|
|
|
|
2022-05-12 09:48:41 +02:00
|
|
|
bool rtdIsActive(uint8_t idx);
|
2022-05-09 21:29:54 +02:00
|
|
|
ReturnValue_t writeCfgReg(SpiCookie* cookie, uint8_t cfg);
|
2022-05-14 17:04:51 +02:00
|
|
|
ReturnValue_t writeBiasSel(MAX31865::Bias bias, SpiCookie* cookie, uint8_t baseCfg);
|
2022-05-09 21:29:54 +02:00
|
|
|
ReturnValue_t readCfgReg(SpiCookie* cookie, uint8_t& cfg);
|
|
|
|
ReturnValue_t readRtdVal(SpiCookie* cookie, uint16_t& val, bool& faultBitSet);
|
2022-05-12 11:27:30 +02:00
|
|
|
ReturnValue_t writeLowThreshold(SpiCookie* cookie, uint16_t val);
|
|
|
|
ReturnValue_t writeHighThreshold(SpiCookie* cookie, uint16_t val);
|
|
|
|
ReturnValue_t readLowThreshold(SpiCookie* cookie, uint16_t& val);
|
|
|
|
ReturnValue_t readHighThreshold(SpiCookie* cookie, uint16_t& val);
|
|
|
|
ReturnValue_t clearFaultStatus(SpiCookie* cookie);
|
|
|
|
|
|
|
|
ReturnValue_t readNFromReg(SpiCookie* cookie, uint8_t reg, size_t n, uint8_t** reply);
|
|
|
|
ReturnValue_t writeNToReg(SpiCookie* cookie, uint8_t reg, size_t n, uint8_t* cmd,
|
|
|
|
uint8_t** reply);
|
2022-05-09 21:29:54 +02:00
|
|
|
|
|
|
|
ReturnValue_t initializeInterface(CookieIF* cookie) override;
|
|
|
|
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
|
|
|
|
ReturnValue_t getSendSuccess(CookieIF* cookie) override;
|
|
|
|
ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
|
|
|
|
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
|
|
|
|
|
2022-05-12 11:27:30 +02:00
|
|
|
ReturnValue_t handleSpiError(Max31865ReaderCookie* cookie, ReturnValue_t result, const char* ctx);
|
2022-05-09 21:29:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* LINUX_DEVICES_MAX31865RTDREADER_H_ */
|