eive-obsw/linux/boardtest/SpiTestClass.h

128 lines
4.2 KiB
C
Raw Normal View History

2021-02-14 19:22:58 +01:00
#ifndef LINUX_BOARDTEST_SPITESTCLASS_H_
#define LINUX_BOARDTEST_SPITESTCLASS_H_
2021-09-13 18:07:07 +02:00
#include "OBSWConfig.h"
2022-03-30 17:44:07 +02:00
#ifdef XIPHOS_Q7S
2021-09-13 18:07:07 +02:00
#include "busConf.h"
#endif
2022-03-30 17:44:07 +02:00
#ifdef RASPBERRY_PI
#include <bsp_linux_board/definitions.h>
#endif
2021-08-03 15:58:01 +02:00
#include <fsfw_hal/common/gpio/GpioIF.h>
#include <fsfw_hal/linux/spi/SpiCookie.h>
2021-02-14 19:22:58 +01:00
#include <test/testtasks/TestTask.h>
2021-02-23 16:47:34 +01:00
#include <vector>
2022-02-18 12:46:28 +01:00
#include "devices/gpioIds.h"
struct SusTestCfg {
SusTestCfg(bool doTest, gpioId_t gpioId) : gpioId(gpioId) {}
bool doTest = false;
const gpioId_t gpioId;
bool intConv = true;
bool extConv = false;
};
struct Max1227TestCfg {
bool testRadSensorExtConvWithDelay = false;
bool testRadSensorIntConv = false;
bool plPcduAdcExtConv = false;
2022-02-22 16:51:26 +01:00
bool plPcduAdcExtConvAsOne = false;
2022-02-18 12:46:28 +01:00
bool plPcduAdcIntConv = false;
bool vbatSwitch = true;
SusTestCfg testSus[12] = {
{false, gpioIds::CS_SUS_0}, {false, gpioIds::CS_SUS_1}, {false, gpioIds::CS_SUS_2},
{false, gpioIds::CS_SUS_3}, {false, gpioIds::CS_SUS_4}, {false, gpioIds::CS_SUS_5},
{false, gpioIds::CS_SUS_6}, {false, gpioIds::CS_SUS_7}, {false, gpioIds::CS_SUS_8},
{false, gpioIds::CS_SUS_9}, {false, gpioIds::CS_SUS_10}, {false, gpioIds::CS_SUS_11},
};
};
2022-01-17 15:58:27 +01:00
class SpiTestClass : public TestTask {
public:
2022-02-17 21:17:40 +01:00
enum TestModes { NONE, MGM_LIS3MDL, MGM_RM3100, GYRO_L3GD20H, MAX1227 };
2021-02-23 16:47:34 +01:00
2022-01-17 15:58:27 +01:00
TestModes testMode;
2021-02-14 19:22:58 +01:00
2022-01-17 15:58:27 +01:00
SpiTestClass(object_id_t objectId, GpioIF* gpioIF);
2021-02-23 16:47:34 +01:00
2022-01-17 15:58:27 +01:00
ReturnValue_t performOneShotAction() override;
ReturnValue_t performPeriodicAction() override;
2021-02-14 19:22:58 +01:00
2022-01-17 15:58:27 +01:00
private:
GpioIF* gpioIF;
2022-02-18 12:46:28 +01:00
Max1227TestCfg adcCfg = {};
2021-02-23 16:47:34 +01:00
2022-01-17 15:58:27 +01:00
std::array<uint8_t, 128> recvBuffer;
std::array<uint8_t, 128> sendBuffer;
2022-02-16 15:16:36 +01:00
struct spi_ioc_transfer spiTransferStruct[6] = {};
2021-02-23 16:47:34 +01:00
2022-01-17 15:58:27 +01:00
void performRm3100Test(uint8_t mgmId);
void performLis3MdlTest(uint8_t lis3Id);
void performL3gTest(uint8_t l3gId);
2022-02-17 21:17:40 +01:00
void performOneShotMax1227Test();
void performPeriodicMax1227Test();
2022-02-16 18:56:38 +01:00
void performMax1227Test();
2021-02-24 00:24:14 +01:00
2022-01-17 15:58:27 +01:00
/* ACS board specific code which pulls all GPIOs high */
void acsInit();
2021-02-23 16:47:34 +01:00
2022-01-17 15:58:27 +01:00
/* ACS board specific variables */
#ifdef RASPBERRY_PI
2022-01-17 15:58:27 +01:00
uint8_t mgm0Lis3mdlChipSelect = gpio::MGM_0_BCM_PIN;
uint8_t mgm1Rm3100ChipSelect = gpio::MGM_1_BCM_PIN;
uint8_t mgm2Lis3mdlChipSelect = gpio::MGM_2_BCM_PIN;
uint8_t mgm3Rm3100ChipSelect = gpio::MGM_3_BCM_PIN;
uint8_t gyro0AdisChipSelect = gpio::GYRO_0_BCM_PIN;
uint8_t gyro1L3gd20ChipSelect = gpio::GYRO_1_BCM_PIN;
uint8_t gyro2AdisChipSelect = gpio::GYRO_2_BCM_PIN;
uint8_t gyro3L3gd20ChipSelect = gpio::GYRO_3_BCM_PIN;
2021-05-05 22:47:24 +02:00
#else
2022-02-17 20:53:06 +01:00
2022-01-17 15:58:27 +01:00
uint8_t mgm0Lis3mdlChipSelect = 0;
uint8_t mgm1Rm3100ChipSelect = 0;
uint8_t gyro0AdisResetLine = 0;
uint8_t gyro0AdisChipSelect = 0;
uint8_t gyro1L3gd20ChipSelect = 0;
uint8_t gyro2L3gd20ChipSelect = 0;
uint8_t mgm2Lis3mdlChipSelect = 0;
uint8_t mgm3Rm3100ChipSelect = 0;
#endif
2021-02-23 16:47:34 +01:00
2022-01-17 15:58:27 +01:00
static constexpr uint8_t STM_READ_MASK = 0b1000'0000;
static constexpr uint8_t RM3100_READ_MASK = STM_READ_MASK;
static constexpr uint8_t STM_AUTO_INCR_MASK = 0b0100'0000;
2022-02-17 20:53:06 +01:00
void shiftOutZeros();
void setSendBuffer();
void max1227RadSensorTest(int fd);
2022-02-18 12:46:28 +01:00
void max1227SusTest(int fd, SusTestCfg& cfg);
2022-02-17 20:53:06 +01:00
void max1227PlPcduTest(int fd);
2022-01-17 15:58:27 +01:00
void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed);
void writeStmRegister(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t value,
bool autoIncrement);
void writeMultipleStmRegisters(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t* values,
size_t len);
void writeMultipleRegisters(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t* values,
size_t len);
void writeRegister(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t value);
2022-02-17 10:17:46 +01:00
ReturnValue_t transfer(int fd, gpioId_t chipSelect);
2022-01-17 15:58:27 +01:00
uint8_t readRm3100Register(int fd, gpioId_t chipSelect, uint8_t reg);
uint8_t readStmRegister(int fd, gpioId_t chipSelect, uint8_t reg, bool autoIncrement);
uint8_t readRegister(int fd, gpioId_t chipSelect, uint8_t reg);
void readMultipleStmRegisters(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t* reply,
size_t len);
void readMultipleRegisters(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t* reply, size_t len);
2021-02-14 19:22:58 +01:00
};
#endif /* LINUX_BOARDTEST_SPITESTCLASS_H_ */