eive-obsw/linux/acs/AcsBoardPolling.h

95 lines
3.1 KiB
C
Raw Normal View History

2023-02-26 14:55:33 +01:00
#ifndef LINUX_DEVICES_ACSBOARDPOLLING_H_
#define LINUX_DEVICES_ACSBOARDPOLLING_H_
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
#include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/tasks/ExecutableObjectIF.h>
#include <fsfw/tasks/SemaphoreIF.h>
2023-02-26 21:26:49 +01:00
#include <fsfw_hal/devicehandlers/devicedefinitions/mgmRm3100Helpers.h>
2023-02-26 14:55:33 +01:00
#include <fsfw_hal/linux/spi/SpiComIF.h>
2023-03-24 20:50:33 +01:00
#include <mission/acs/acsBoardPolling.h>
#include <mission/acs/gyroAdisHelpers.h>
2023-02-26 14:55:33 +01:00
class AcsBoardPolling : public SystemObject,
public ExecutableObjectIF,
public DeviceCommunicationIF {
public:
AcsBoardPolling(object_id_t objectId, SpiComIF& lowLevelComIF, GpioIF& gpioIF);
ReturnValue_t performOperation(uint8_t operationCode) override;
ReturnValue_t initialize() override;
private:
2023-03-24 01:01:29 +01:00
enum class InternalState { IDLE, IS_BUSY } state = InternalState::IDLE;
2023-02-26 14:55:33 +01:00
MutexIF* ipcLock;
2023-03-02 15:32:12 +01:00
static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING;
static constexpr uint32_t LOCK_TIMEOUT = 20;
static constexpr char LOCK_CTX[] = "AcsBoardPolling";
2023-02-26 14:55:33 +01:00
SemaphoreIF* semaphore;
std::array<uint8_t, 32> cmdBuf;
2023-02-26 21:26:49 +01:00
struct DevBase {
2023-02-26 14:55:33 +01:00
SpiCookie* cookie = nullptr;
2023-02-26 21:26:49 +01:00
bool performStartup = false;
2023-02-26 14:55:33 +01:00
acs::SimpleSensorMode mode = acs::SimpleSensorMode::OFF;
2023-02-28 01:25:25 +01:00
ReturnValue_t replyResult = returnvalue::OK;
2023-02-26 21:26:49 +01:00
};
struct GyroAdis : public DevBase {
adis1650x::Type type;
2023-06-06 16:02:11 +02:00
uint16_t decRate;
2023-02-26 21:26:49 +01:00
Countdown countdown;
2023-02-26 14:55:33 +01:00
acs::Adis1650XReply ownReply;
acs::Adis1650XReply readerReply;
};
GyroAdis gyro0Adis{};
GyroAdis gyro2Adis{};
2023-02-26 21:26:49 +01:00
struct GyroL3g : public DevBase {
2023-02-26 14:55:33 +01:00
uint8_t sensorCfg[5];
acs::GyroL3gReply ownReply;
acs::GyroL3gReply readerReply;
};
GyroL3g gyro1L3g{};
GyroL3g gyro3L3g{};
2023-02-26 21:26:49 +01:00
struct MgmRm3100 : public DevBase {
uint8_t tmrcValue = mgmRm3100::TMRC_DEFAULT_37HZ_VALUE;
acs::MgmRm3100Reply ownReply;
acs::MgmRm3100Reply readerReply;
};
MgmRm3100 mgm1Rm3100;
MgmRm3100 mgm3Rm3100;
struct MgmLis3 : public DevBase {
uint8_t cfg[5]{};
acs::MgmLis3Reply ownReply;
acs::MgmLis3Reply readerReply;
};
MgmLis3 mgm0Lis3;
MgmLis3 mgm2Lis3;
2023-02-26 14:55:33 +01:00
uint8_t* rawReply = nullptr;
size_t dummy = 0;
SpiComIF& spiComIF;
GpioIF& gpioIF;
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;
void gyroL3gHandler(GyroL3g& l3g);
void gyroAdisHandler(GyroAdis& gyro);
2023-02-26 21:26:49 +01:00
void mgmLis3Handler(MgmLis3& mgm);
void mgmRm3100Handler(MgmRm3100& mgm);
2023-06-06 16:02:11 +02:00
// This fumction configures the register as specified on p.21 of the datasheet.
ReturnValue_t writeAdisReg(SpiCookie& cookie);
2023-02-26 14:55:33 +01:00
// Special readout: 16us stall time between small 2 byte transfers.
ReturnValue_t readAdisCfg(SpiCookie& spiCookie, size_t transferLen);
};
#endif /* LINUX_DEVICES_ACSBOARDPOLLING_H_ */