From b6f3b838b7657aca9babf5cb78847d88c918acb1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Feb 2022 12:46:28 +0100 Subject: [PATCH] sun sensors working in test class --- linux/boardtest/SpiTestClass.cpp | 117 +++++++++++++++++++++---------- linux/boardtest/SpiTestClass.h | 37 +++++++--- 2 files changed, 106 insertions(+), 48 deletions(-) diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index 4d35fa10..60abbe67 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -16,7 +16,6 @@ #include #include "busConf.h" -#include "devices/gpioIds.h" #include "mission/devices/max1227.h" SpiTestClass::SpiTestClass(object_id_t objectId, GpioIF *gpioIF) @@ -291,27 +290,51 @@ void SpiTestClass::performL3gTest(uint8_t l3gId) { void SpiTestClass::performOneShotMax1227Test() { using namespace max1227; - testRadSensorExtConvWithDelay = false; - testRadSensorIntConv = false; + adcCfg.testRadSensorExtConvWithDelay = false; + adcCfg.testRadSensorIntConv = false; - susExtConversion = false; - susIntConversion = false; + adcCfg.testSus[0].doTest = true; + adcCfg.testSus[0].intConv = true; + adcCfg.testSus[6].doTest = true; + adcCfg.testSus[6].intConv = true; - plPcduAdcExtConv = false; - plPcduAdcIntConv = true; + adcCfg.testSus[1].doTest = 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(); } void SpiTestClass::performPeriodicMax1227Test() { using namespace max1227; - testRadSensorExtConvWithDelay = false; - testRadSensorIntConv = false; + adcCfg.testRadSensorExtConvWithDelay = false; + adcCfg.testRadSensorIntConv = false; - susExtConversion = false; - susIntConversion = false; - - plPcduAdcExtConv = true; - plPcduAdcIntConv = false; + adcCfg.plPcduAdcExtConv = false; + adcCfg.plPcduAdcIntConv = false; performMax1227Test(); } @@ -333,13 +356,25 @@ void SpiTestClass::performMax1227Test() { setSpiSpeedAndMode(fd, spiMode, spiSpeed); 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); } void SpiTestClass::max1227RadSensorTest(int fd) { using namespace max1227; - if (testRadSensorExtConvWithDelay) { + if (adcCfg.testRadSensorExtConvWithDelay) { sendBuffer[0] = max1227::buildResetByte(true); spiTransferStruct[0].len = 1; transfer(fd, gpioIds::CS_RAD_SENSOR); @@ -381,7 +416,7 @@ void SpiTestClass::max1227RadSensorTest(int fd) { float temp = max1227::getTemperature(tempRaw); sif::info << "Temperature: " << temp << std::endl; } - if (testRadSensorIntConv) { + if (adcCfg.testRadSensorIntConv) { sendBuffer[0] = max1227::buildResetByte(false); spiTransferStruct[0].len = 1; 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; - if (susExtConversion) { + if (cfg.extConv) { sendBuffer[0] = max1227::buildResetByte(false); spiTransferStruct[0].len = 1; - transfer(fd, gpio::NO_GPIO); + transfer(fd, cfg.gpioId); usleep(65); sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0); spiTransferStruct[0].len = 1; - transfer(fd, gpio::NO_GPIO); + transfer(fd, cfg.gpioId); max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len); - transfer(fd, gpio::NO_GPIO); + transfer(fd, cfg.gpioId); uint16_t adcRaw[6] = {}; adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2]; adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4]; @@ -443,35 +478,38 @@ void SpiTestClass::max1227SusTest(int fd) { adcRaw[3] = (recvBuffer[7] << 8) | recvBuffer[8]; adcRaw[4] = (recvBuffer[9] << 8) | recvBuffer[10]; adcRaw[5] = (recvBuffer[11] << 8) | recvBuffer[12]; - arrayprinter::print(recvBuffer.data(), 13, OutputType::HEX); - for (int idx = 0; idx < 6; idx++) { - sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; + sif::info << "Ext Conv [" << std::hex << std::setw(3); + for (int idx = 0; idx < 5; idx++) { + 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); spiTransferStruct[0].len = 1; - transfer(fd, gpio::NO_GPIO); + transfer(fd, cfg.gpioId); usleep(65); // Now use internal conversion sendBuffer[0] = max1227::buildSetupByte(ClkSel::INT_CONV_INT_TIMED_CNVST_AS_AIN, RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0); spiTransferStruct[0].len = 1; - transfer(fd, gpio::NO_GPIO); + transfer(fd, cfg.gpioId); usleep(10); sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 5, true); spiTransferStruct[0].len = 1; - transfer(fd, gpio::NO_GPIO); + transfer(fd, cfg.gpioId); usleep(65); spiTransferStruct[0].len = 14; // Shift out zeros shiftOutZeros(); - transfer(fd, gpio::NO_GPIO); + transfer(fd, cfg.gpioId); setSendBuffer(); - arrayprinter::print(recvBuffer.data(), 14); + // arrayprinter::print(recvBuffer.data(), 14); float temp = static_cast(((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]) * 0.125; - sif::info << "Temperature: " << temp << " C" << std::endl; uint16_t adcRaw[6] = {}; adcRaw[0] = (recvBuffer[2] << 8) | recvBuffer[3]; adcRaw[1] = (recvBuffer[4] << 8) | recvBuffer[5]; @@ -479,15 +517,20 @@ void SpiTestClass::max1227SusTest(int fd) { adcRaw[3] = (recvBuffer[8] << 8) | recvBuffer[9]; adcRaw[4] = (recvBuffer[10] << 8) | recvBuffer[11]; adcRaw[5] = (recvBuffer[12] << 8) | recvBuffer[13]; + sif::info << "Int Conv [" << std::hex << std::setw(3); 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) { using namespace max1227; - if ((plPcduAdcExtConv or plPcduAdcIntConv) and vbatSwitch) { + if ((adcCfg.plPcduAdcExtConv or adcCfg.plPcduAdcIntConv) and adcCfg.vbatSwitch) { // This enables the ADC ReturnValue_t result = gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -497,11 +540,11 @@ void SpiTestClass::max1227PlPcduTest(int fd) { if (result != HasReturnvaluesIF::RETURN_OK) { return; } - vbatSwitch = false; + adcCfg.vbatSwitch = false; // Takes a bit of time until the ADC is usable TaskFactory::delayTask(50); } - if (plPcduAdcExtConv) { + if (adcCfg.plPcduAdcExtConv) { sendBuffer[0] = max1227::buildResetByte(false); spiTransferStruct[0].len = 1; transfer(fd, gpioIds::PLPCDU_ADC_CS); @@ -527,7 +570,7 @@ void SpiTestClass::max1227PlPcduTest(int fd) { float temp = max1227::getTemperature(tempRaw); sif::info << "Temperature: " << temp << std::endl; } - if (plPcduAdcIntConv) { + if (adcCfg.plPcduAdcIntConv) { sendBuffer[0] = max1227::buildResetByte(true); spiTransferStruct[0].len = 1; transfer(fd, gpioIds::PLPCDU_ADC_CS); diff --git a/linux/boardtest/SpiTestClass.h b/linux/boardtest/SpiTestClass.h index adf63e6e..d48d6655 100644 --- a/linux/boardtest/SpiTestClass.h +++ b/linux/boardtest/SpiTestClass.h @@ -6,13 +6,36 @@ #if defined(XIPHOS_Q7S) #include "busConf.h" #endif - #include #include #include #include +#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 { public: enum TestModes { NONE, MGM_LIS3MDL, MGM_RM3100, GYRO_L3GD20H, MAX1227 }; @@ -26,6 +49,7 @@ class SpiTestClass : public TestTask { private: GpioIF* gpioIF; + Max1227TestCfg adcCfg = {}; std::array recvBuffer; std::array sendBuffer; @@ -53,15 +77,6 @@ class SpiTestClass : public TestTask { uint8_t gyro2AdisChipSelect = gpio::GYRO_2_BCM_PIN; uint8_t gyro3L3gd20ChipSelect = gpio::GYRO_3_BCM_PIN; #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 mgm1Rm3100ChipSelect = 0; @@ -81,7 +96,7 @@ class SpiTestClass : public TestTask { void setSendBuffer(); void max1227RadSensorTest(int fd); - void max1227SusTest(int fd); + void max1227SusTest(int fd, SusTestCfg& cfg); void max1227PlPcduTest(int fd); void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed);