sun sensors working in test class

This commit is contained in:
Robin Müller 2022-02-18 12:46:28 +01:00
parent 6326ac71ca
commit b6f3b838b7
2 changed files with 106 additions and 48 deletions

View File

@ -16,7 +16,6 @@
#include <bitset> #include <bitset>
#include "busConf.h" #include "busConf.h"
#include "devices/gpioIds.h"
#include "mission/devices/max1227.h" #include "mission/devices/max1227.h"
SpiTestClass::SpiTestClass(object_id_t objectId, GpioIF *gpioIF) SpiTestClass::SpiTestClass(object_id_t objectId, GpioIF *gpioIF)
@ -291,27 +290,51 @@ void SpiTestClass::performL3gTest(uint8_t l3gId) {
void SpiTestClass::performOneShotMax1227Test() { void SpiTestClass::performOneShotMax1227Test() {
using namespace max1227; using namespace max1227;
testRadSensorExtConvWithDelay = false; adcCfg.testRadSensorExtConvWithDelay = false;
testRadSensorIntConv = false; adcCfg.testRadSensorIntConv = false;
susExtConversion = false; adcCfg.testSus[0].doTest = true;
susIntConversion = false; adcCfg.testSus[0].intConv = true;
adcCfg.testSus[6].doTest = true;
adcCfg.testSus[6].intConv = true;
plPcduAdcExtConv = false; adcCfg.testSus[1].doTest = true;
plPcduAdcIntConv = true; adcCfg.testSus[1].intConv = true;
adcCfg.testSus[7].doTest = true;
adcCfg.testSus[7].intConv = true;
adcCfg.testSus[10].doTest = true;
adcCfg.testSus[10].intConv = true;
adcCfg.testSus[4].doTest = true;
adcCfg.testSus[4].intConv = true;
adcCfg.testSus[1].doTest = true;
adcCfg.testSus[1].intConv = true;
adcCfg.testSus[5].doTest = true;
adcCfg.testSus[5].intConv = true;
adcCfg.testSus[2].doTest = true;
adcCfg.testSus[2].intConv = true;
adcCfg.testSus[3].doTest = true;
adcCfg.testSus[3].intConv = true;
adcCfg.testSus[8].doTest = true;
adcCfg.testSus[8].intConv = true;
adcCfg.testSus[9].doTest = true;
adcCfg.testSus[9].intConv = true;
adcCfg.plPcduAdcExtConv = false;
adcCfg.plPcduAdcIntConv = true;
performMax1227Test(); performMax1227Test();
} }
void SpiTestClass::performPeriodicMax1227Test() { void SpiTestClass::performPeriodicMax1227Test() {
using namespace max1227; using namespace max1227;
testRadSensorExtConvWithDelay = false; adcCfg.testRadSensorExtConvWithDelay = false;
testRadSensorIntConv = false; adcCfg.testRadSensorIntConv = false;
susExtConversion = false; adcCfg.plPcduAdcExtConv = false;
susIntConversion = false; adcCfg.plPcduAdcIntConv = false;
plPcduAdcExtConv = true;
plPcduAdcIntConv = false;
performMax1227Test(); performMax1227Test();
} }
@ -333,13 +356,25 @@ void SpiTestClass::performMax1227Test() {
setSpiSpeedAndMode(fd, spiMode, spiSpeed); setSpiSpeedAndMode(fd, spiMode, spiSpeed);
max1227RadSensorTest(fd); max1227RadSensorTest(fd);
max1227SusTest(fd); int idx = 0;
bool firstTest = true;
for (auto &susCfg : adcCfg.testSus) {
if (susCfg.doTest) {
if (firstTest) {
firstTest = false;
sif::info << "---------- SUS ADC Values -----------" << std::endl;
}
sif::info << "SUS " << std::setw(2) << idx << ": ";
max1227SusTest(fd, susCfg);
}
idx++;
}
max1227PlPcduTest(fd); max1227PlPcduTest(fd);
} }
void SpiTestClass::max1227RadSensorTest(int fd) { void SpiTestClass::max1227RadSensorTest(int fd) {
using namespace max1227; using namespace max1227;
if (testRadSensorExtConvWithDelay) { if (adcCfg.testRadSensorExtConvWithDelay) {
sendBuffer[0] = max1227::buildResetByte(true); sendBuffer[0] = max1227::buildResetByte(true);
spiTransferStruct[0].len = 1; spiTransferStruct[0].len = 1;
transfer(fd, gpioIds::CS_RAD_SENSOR); transfer(fd, gpioIds::CS_RAD_SENSOR);
@ -381,7 +416,7 @@ void SpiTestClass::max1227RadSensorTest(int fd) {
float temp = max1227::getTemperature(tempRaw); float temp = max1227::getTemperature(tempRaw);
sif::info << "Temperature: " << temp << std::endl; sif::info << "Temperature: " << temp << std::endl;
} }
if (testRadSensorIntConv) { if (adcCfg.testRadSensorIntConv) {
sendBuffer[0] = max1227::buildResetByte(false); sendBuffer[0] = max1227::buildResetByte(false);
spiTransferStruct[0].len = 1; spiTransferStruct[0].len = 1;
transfer(fd, gpioIds::CS_RAD_SENSOR); transfer(fd, gpioIds::CS_RAD_SENSOR);
@ -421,21 +456,21 @@ void SpiTestClass::max1227RadSensorTest(int fd) {
} }
} }
void SpiTestClass::max1227SusTest(int fd) { void SpiTestClass::max1227SusTest(int fd, SusTestCfg &cfg) {
using namespace max1227; using namespace max1227;
if (susExtConversion) { if (cfg.extConv) {
sendBuffer[0] = max1227::buildResetByte(false); sendBuffer[0] = max1227::buildResetByte(false);
spiTransferStruct[0].len = 1; spiTransferStruct[0].len = 1;
transfer(fd, gpio::NO_GPIO); transfer(fd, cfg.gpioId);
usleep(65); usleep(65);
sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP,
DiffSel::NONE_0); DiffSel::NONE_0);
spiTransferStruct[0].len = 1; spiTransferStruct[0].len = 1;
transfer(fd, gpio::NO_GPIO); transfer(fd, cfg.gpioId);
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len); max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len);
transfer(fd, gpio::NO_GPIO); transfer(fd, cfg.gpioId);
uint16_t adcRaw[6] = {}; uint16_t adcRaw[6] = {};
adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2]; adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2];
adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4]; adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4];
@ -443,35 +478,38 @@ void SpiTestClass::max1227SusTest(int fd) {
adcRaw[3] = (recvBuffer[7] << 8) | recvBuffer[8]; adcRaw[3] = (recvBuffer[7] << 8) | recvBuffer[8];
adcRaw[4] = (recvBuffer[9] << 8) | recvBuffer[10]; adcRaw[4] = (recvBuffer[9] << 8) | recvBuffer[10];
adcRaw[5] = (recvBuffer[11] << 8) | recvBuffer[12]; adcRaw[5] = (recvBuffer[11] << 8) | recvBuffer[12];
arrayprinter::print(recvBuffer.data(), 13, OutputType::HEX); sif::info << "Ext Conv [" << std::hex << std::setw(3);
for (int idx = 0; idx < 6; idx++) { for (int idx = 0; idx < 5; idx++) {
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; sif::info << adcRaw[idx];
if (idx < 6) {
sif::info << ",";
}
} }
sif::info << std::dec << "]" << std::endl; // | Temperature: " << temp << " C" << std::endl;
} }
if (susIntConversion) { if (cfg.intConv) {
sendBuffer[0] = max1227::buildResetByte(false); sendBuffer[0] = max1227::buildResetByte(false);
spiTransferStruct[0].len = 1; spiTransferStruct[0].len = 1;
transfer(fd, gpio::NO_GPIO); transfer(fd, cfg.gpioId);
usleep(65); usleep(65);
// Now use internal conversion // Now use internal conversion
sendBuffer[0] = max1227::buildSetupByte(ClkSel::INT_CONV_INT_TIMED_CNVST_AS_AIN, sendBuffer[0] = max1227::buildSetupByte(ClkSel::INT_CONV_INT_TIMED_CNVST_AS_AIN,
RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0); RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0);
spiTransferStruct[0].len = 1; spiTransferStruct[0].len = 1;
transfer(fd, gpio::NO_GPIO); transfer(fd, cfg.gpioId);
usleep(10); usleep(10);
sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 5, true); sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 5, true);
spiTransferStruct[0].len = 1; spiTransferStruct[0].len = 1;
transfer(fd, gpio::NO_GPIO); transfer(fd, cfg.gpioId);
usleep(65); usleep(65);
spiTransferStruct[0].len = 14; spiTransferStruct[0].len = 14;
// Shift out zeros // Shift out zeros
shiftOutZeros(); shiftOutZeros();
transfer(fd, gpio::NO_GPIO); transfer(fd, cfg.gpioId);
setSendBuffer(); setSendBuffer();
arrayprinter::print(recvBuffer.data(), 14); // arrayprinter::print(recvBuffer.data(), 14);
float temp = static_cast<int16_t>(((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]) * 0.125; float temp = static_cast<int16_t>(((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]) * 0.125;
sif::info << "Temperature: " << temp << " C" << std::endl;
uint16_t adcRaw[6] = {}; uint16_t adcRaw[6] = {};
adcRaw[0] = (recvBuffer[2] << 8) | recvBuffer[3]; adcRaw[0] = (recvBuffer[2] << 8) | recvBuffer[3];
adcRaw[1] = (recvBuffer[4] << 8) | recvBuffer[5]; adcRaw[1] = (recvBuffer[4] << 8) | recvBuffer[5];
@ -479,15 +517,20 @@ void SpiTestClass::max1227SusTest(int fd) {
adcRaw[3] = (recvBuffer[8] << 8) | recvBuffer[9]; adcRaw[3] = (recvBuffer[8] << 8) | recvBuffer[9];
adcRaw[4] = (recvBuffer[10] << 8) | recvBuffer[11]; adcRaw[4] = (recvBuffer[10] << 8) | recvBuffer[11];
adcRaw[5] = (recvBuffer[12] << 8) | recvBuffer[13]; adcRaw[5] = (recvBuffer[12] << 8) | recvBuffer[13];
sif::info << "Int Conv [" << std::hex << std::setw(3);
for (int idx = 0; idx < 6; idx++) { for (int idx = 0; idx < 6; idx++) {
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; sif::info << adcRaw[idx];
if (idx < 5) {
sif::info << ",";
}
} }
sif::info << std::dec << "] | T[C] " << temp << std::endl;
} }
} }
void SpiTestClass::max1227PlPcduTest(int fd) { void SpiTestClass::max1227PlPcduTest(int fd) {
using namespace max1227; using namespace max1227;
if ((plPcduAdcExtConv or plPcduAdcIntConv) and vbatSwitch) { if ((adcCfg.plPcduAdcExtConv or adcCfg.plPcduAdcIntConv) and adcCfg.vbatSwitch) {
// This enables the ADC // This enables the ADC
ReturnValue_t result = gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); ReturnValue_t result = gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
@ -497,11 +540,11 @@ void SpiTestClass::max1227PlPcduTest(int fd) {
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return; return;
} }
vbatSwitch = false; adcCfg.vbatSwitch = false;
// Takes a bit of time until the ADC is usable // Takes a bit of time until the ADC is usable
TaskFactory::delayTask(50); TaskFactory::delayTask(50);
} }
if (plPcduAdcExtConv) { if (adcCfg.plPcduAdcExtConv) {
sendBuffer[0] = max1227::buildResetByte(false); sendBuffer[0] = max1227::buildResetByte(false);
spiTransferStruct[0].len = 1; spiTransferStruct[0].len = 1;
transfer(fd, gpioIds::PLPCDU_ADC_CS); transfer(fd, gpioIds::PLPCDU_ADC_CS);
@ -527,7 +570,7 @@ void SpiTestClass::max1227PlPcduTest(int fd) {
float temp = max1227::getTemperature(tempRaw); float temp = max1227::getTemperature(tempRaw);
sif::info << "Temperature: " << temp << std::endl; sif::info << "Temperature: " << temp << std::endl;
} }
if (plPcduAdcIntConv) { if (adcCfg.plPcduAdcIntConv) {
sendBuffer[0] = max1227::buildResetByte(true); sendBuffer[0] = max1227::buildResetByte(true);
spiTransferStruct[0].len = 1; spiTransferStruct[0].len = 1;
transfer(fd, gpioIds::PLPCDU_ADC_CS); transfer(fd, gpioIds::PLPCDU_ADC_CS);

View File

@ -6,13 +6,36 @@
#if defined(XIPHOS_Q7S) #if defined(XIPHOS_Q7S)
#include "busConf.h" #include "busConf.h"
#endif #endif
#include <fsfw_hal/common/gpio/GpioIF.h> #include <fsfw_hal/common/gpio/GpioIF.h>
#include <fsfw_hal/linux/spi/SpiCookie.h> #include <fsfw_hal/linux/spi/SpiCookie.h>
#include <test/testtasks/TestTask.h> #include <test/testtasks/TestTask.h>
#include <vector> #include <vector>
#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;
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},
};
};
class SpiTestClass : public TestTask { class SpiTestClass : public TestTask {
public: public:
enum TestModes { NONE, MGM_LIS3MDL, MGM_RM3100, GYRO_L3GD20H, MAX1227 }; enum TestModes { NONE, MGM_LIS3MDL, MGM_RM3100, GYRO_L3GD20H, MAX1227 };
@ -26,6 +49,7 @@ class SpiTestClass : public TestTask {
private: private:
GpioIF* gpioIF; GpioIF* gpioIF;
Max1227TestCfg adcCfg = {};
std::array<uint8_t, 128> recvBuffer; std::array<uint8_t, 128> recvBuffer;
std::array<uint8_t, 128> sendBuffer; std::array<uint8_t, 128> sendBuffer;
@ -53,15 +77,6 @@ class SpiTestClass : public TestTask {
uint8_t gyro2AdisChipSelect = gpio::GYRO_2_BCM_PIN; uint8_t gyro2AdisChipSelect = gpio::GYRO_2_BCM_PIN;
uint8_t gyro3L3gd20ChipSelect = gpio::GYRO_3_BCM_PIN; uint8_t gyro3L3gd20ChipSelect = gpio::GYRO_3_BCM_PIN;
#else #else
bool testRadSensorExtConvWithDelay = false;
bool testRadSensorIntConv = false;
bool susExtConversion = false;
bool susIntConversion = false;
bool plPcduAdcExtConv = false;
bool plPcduAdcIntConv = false;
bool vbatSwitch = true;
uint8_t mgm0Lis3mdlChipSelect = 0; uint8_t mgm0Lis3mdlChipSelect = 0;
uint8_t mgm1Rm3100ChipSelect = 0; uint8_t mgm1Rm3100ChipSelect = 0;
@ -81,7 +96,7 @@ class SpiTestClass : public TestTask {
void setSendBuffer(); void setSendBuffer();
void max1227RadSensorTest(int fd); void max1227RadSensorTest(int fd);
void max1227SusTest(int fd); void max1227SusTest(int fd, SusTestCfg& cfg);
void max1227PlPcduTest(int fd); void max1227PlPcduTest(int fd);
void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed); void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed);