From c06ef5d6b597aad4bde10d5760fe0ae2ab6d1341 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 16 Feb 2022 18:56:38 +0100 Subject: [PATCH 01/19] added more max1227 tests --- bsp_q7s/boardconfig/busConf.h | 12 +- bsp_q7s/core/ObjectFactory.cpp | 7 +- common/config/devConf.h | 2 +- fsfw | 2 +- linux/boardtest/SpiTestClass.cpp | 183 ++++++++++++++++++++- linux/boardtest/SpiTestClass.h | 2 +- mission/devices/RadiationSensorHandler.cpp | 14 +- mission/devices/RadiationSensorHandler.h | 2 + mission/devices/max1227.cpp | 19 +++ mission/devices/max1227.h | 22 +++ 10 files changed, 242 insertions(+), 23 deletions(-) diff --git a/bsp_q7s/boardconfig/busConf.h b/bsp_q7s/boardconfig/busConf.h index 9c4b142b..324d741f 100644 --- a/bsp_q7s/boardconfig/busConf.h +++ b/bsp_q7s/boardconfig/busConf.h @@ -57,12 +57,12 @@ static constexpr char HEATER_6[] = "heater6"; static constexpr char HEATER_7[] = "heater7"; static constexpr char SA_DPL_PIN_0[] = "sa_dpl_0"; static constexpr char SA_DPL_PIN_1[] = "sa_dpl_1"; -static constexpr char SPI_MUX_BIT_0_PIN[] = "spi_mux_bit_1"; -static constexpr char SPI_MUX_BIT_1_PIN[] = "spi_mux_bit_2"; -static constexpr char SPI_MUX_BIT_2_PIN[] = "spi_mux_bit_3"; -static constexpr char SPI_MUX_BIT_3_PIN[] = "spi_mux_bit_4"; -static constexpr char SPI_MUX_BIT_4_PIN[] = "spi_mux_bit_5"; -static constexpr char SPI_MUX_BIT_5_PIN[] = "spi_mux_bit_6"; +static constexpr char SPI_MUX_BIT_0_PIN[] = "spi_mux_bit_0"; +static constexpr char SPI_MUX_BIT_1_PIN[] = "spi_mux_bit_1"; +static constexpr char SPI_MUX_BIT_2_PIN[] = "spi_mux_bit_2"; +static constexpr char SPI_MUX_BIT_3_PIN[] = "spi_mux_bit_3"; +static constexpr char SPI_MUX_BIT_4_PIN[] = "spi_mux_bit_4"; +static constexpr char SPI_MUX_BIT_5_PIN[] = "spi_mux_bit_5"; static constexpr char EN_RW_CS[] = "en_rw_cs"; static constexpr char EN_RW_1[] = "enable_rw_1"; static constexpr char EN_RW_2[] = "enable_rw_2"; diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index cac198af..290411c6 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -303,7 +303,12 @@ void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { SpiCookie* spiCookieRadSensor = new SpiCookie( addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, std::string(q7s::SPI_DEFAULT_DEV), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); + auto radSensor = + new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); +#if OBSW_TEST_RADIATION_SENSOR_HANDLER == 1 + radSensor->setStartUpImmediately(); + radSensor->setToGoToNormalModeImmediately(); +#endif } void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF) { diff --git a/common/config/devConf.h b/common/config/devConf.h index 7d489679..deea6aa2 100644 --- a/common/config/devConf.h +++ b/common/config/devConf.h @@ -27,7 +27,7 @@ static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; * Some MAX1227 could not be reached with frequencies around 4 MHz. Maybe this is caused by * the decoder and buffer circuits. Thus frequency is here defined to 1 MHz. */ -static const uint32_t SUS_MAX1227_SPI_FREQ = 1'000'000; +static const uint32_t SUS_MAX1227_SPI_FREQ = 976'000; static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 976'000; static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; diff --git a/fsfw b/fsfw index 0d6d44f7..9e92afbf 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 0d6d44f72fb28ba480482f5d8b2eee6f78d664ce +Subproject commit 9e92afbf076b57df843a1ee526bd63c3303995a5 diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index 4d909d10..14c69577 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -24,7 +24,7 @@ SpiTestClass::SpiTestClass(object_id_t objectId, GpioIF *gpioIF) if (gpioIF == nullptr) { sif::error << "SpiTestClass::SpiTestClass: Invalid GPIO ComIF!" << std::endl; } - testMode = TestModes::MGM_LIS3MDL; + testMode = TestModes::SUS_0; spiTransferStruct[0].rx_buf = reinterpret_cast<__u64>(recvBuffer.data()); spiTransferStruct[0].tx_buf = reinterpret_cast<__u64>(sendBuffer.data()); } @@ -47,7 +47,7 @@ ReturnValue_t SpiTestClass::performOneShotAction() { break; } case (TestModes::SUS_0): { - performSusTest(); + performMax1227Test(); break; } } @@ -279,14 +279,19 @@ void SpiTestClass::performL3gTest(uint8_t l3gId) { sif::info << "Z: " << angVelocZ << std::endl; } -void SpiTestClass::performSusTest() { +void SpiTestClass::performMax1227Test() { + using namespace max1227; + bool testRadSensor = false; + bool extConversion = true; + bool intConversion = false; #ifdef XIPHOS_Q7S std::string deviceName = q7s::SPI_DEFAULT_DEV; #elif defined(RASPBERRY_PI) std::string deviceName = ""; #endif - int fileDescriptor = 0; - UnixFileGuard fileHelper(deviceName, &fileDescriptor, O_RDWR, "SpiComIF::initializeInterface"); + int fd = 0; + int retval = 0; + UnixFileGuard fileHelper(deviceName, &fd, O_RDWR, "SpiComIF::initializeInterface"); if (fileHelper.getOpenResult()) { sif::error << "SpiTestClass::performLis3Mdl3100Test: File descriptor could not be opened!" << std::endl; @@ -294,9 +299,152 @@ void SpiTestClass::performSusTest() { } uint32_t spiSpeed = 1'000'000; spi::SpiModes spiMode = spi::SpiModes::MODE_3; - setSpiSpeedAndMode(fileDescriptor, spiMode, spiSpeed); + setSpiSpeedAndMode(fd, spiMode, spiSpeed); + + if (testRadSensor) { + sendBuffer[0] = max1227::buildResetByte(true); + sendBuffer[1] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, + DiffSel::NONE_0); + spiTransferStruct[0].len = 2; + ReturnValue_t result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + + result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + max1227::prepareExternallyClockedSingleChannelRead(sendBuffer.data(), 0, + spiTransferStruct[0].len); + result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + arrayprinter::print(recvBuffer.data(), 3); + result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + + max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len); + result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + arrayprinter::print(recvBuffer.data(), 13., OutputType::DEC); + } + if (extConversion) { + sendBuffer[0] = max1227::buildResetByte(false); + spiTransferStruct[0].len = 1; + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + + usleep(65); + sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, + DiffSel::NONE_0); + spiTransferStruct[0].len = 1; + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + + // usleep(4); + // max1227::prepareExternallyClockedSingleChannelRead(sendBuffer.data(), 0, + // spiTransferStruct[0].len); + // retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + // if (retval < 0) { + // utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + // } + // arrayprinter::print(recvBuffer.data(), 3); + + max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len); + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + uint16_t adcRaw[6] = {}; + adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2]; + adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4]; + adcRaw[2] = (recvBuffer[5] << 8) | recvBuffer[6]; + 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; + } + } + if (intConversion) { + sendBuffer[0] = max1227::buildResetByte(false); + spiTransferStruct[0].len = 1; + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + + 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; + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + usleep(10); + sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 5, true); + spiTransferStruct[0].len = 1; + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + + usleep(65); + spiTransferStruct[0].len = 14; + // Shift out zeros + spiTransferStruct[0].tx_buf = 0; + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + arrayprinter::print(recvBuffer.data(), 14); + } } +/* + * sendBuffer[0] = buildConvByte(ScanModes::N_ONCE, 0, false); + spiTransferStruct[0].len = 1; + uint8_t reply0 = 0x00; + uint8_t reply1 = 0x00; + spiTransferStruct[1].tx_buf = 0; + spiTransferStruct[1].rx_buf = reinterpret_cast<__u64>(&reply0); + spiTransferStruct[1].len = 1; + // Shift out zeros + spiTransferStruct[2].tx_buf = 0; + spiTransferStruct[2].rx_buf = reinterpret_cast<__u64>(&reply1); + spiTransferStruct[2].len = 1; + retval = ioctl(fd, SPI_IOC_MESSAGE(3), spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + recvBuffer[1] = reply0; + recvBuffer[2] = reply1; + arrayprinter::print(recvBuffer.data(), 3); + */ + void SpiTestClass::acsInit() { GpioCookie *gpioCookie = new GpioCookie(); @@ -372,8 +520,27 @@ void SpiTestClass::acsInit() { } void SpiTestClass::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed) { - int mode_test = SPI_MODE_3; - int retval = ioctl(spiFd, SPI_IOC_WR_MODE, &mode_test); // reinterpret_cast(&mode)); + int modeUnix = 0; + switch (mode) { + case (spi::SpiModes::MODE_0): { + modeUnix = SPI_MODE_0; + break; + } + case (spi::SpiModes::MODE_1): { + modeUnix = SPI_MODE_1; + break; + } + case (spi::SpiModes::MODE_2): { + modeUnix = SPI_MODE_2; + break; + } + case (spi::SpiModes::MODE_3): { + modeUnix = SPI_MODE_3; + break; + } + } + + int retval = ioctl(spiFd, SPI_IOC_WR_MODE, &modeUnix); // reinterpret_cast(&mode)); if (retval != 0) { utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI mode failed!"); } diff --git a/linux/boardtest/SpiTestClass.h b/linux/boardtest/SpiTestClass.h index f0274919..c8a96471 100644 --- a/linux/boardtest/SpiTestClass.h +++ b/linux/boardtest/SpiTestClass.h @@ -34,7 +34,7 @@ class SpiTestClass : public TestTask { void performRm3100Test(uint8_t mgmId); void performLis3MdlTest(uint8_t lis3Id); void performL3gTest(uint8_t l3gId); - void performSusTest(); + void performMax1227Test(); /* ACS board specific code which pulls all GPIOs high */ void acsInit(); diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 83720b53..92d2c311 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -14,11 +14,13 @@ RadiationSensorHandler::~RadiationSensorHandler() {} void RadiationSensorHandler::doStartUp() { if (internalState == InternalState::CONFIGURED) { -#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 - setMode(MODE_NORMAL); -#else - setMode(_MODE_TO_ON); -#endif + if (goToNormalMode) { + setMode(MODE_NORMAL); + } + + else { + setMode(_MODE_TO_ON); + } } } @@ -175,3 +177,5 @@ ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPoo localDataPoolMap.emplace(RAD_SENSOR::AIN7, new PoolEntry({0})); return HasReturnvaluesIF::RETURN_OK; } + +void RadiationSensorHandler::setToGoToNormalModeImmediately() { this->goToNormalMode = true; } diff --git a/mission/devices/RadiationSensorHandler.h b/mission/devices/RadiationSensorHandler.h index fe4e4264..0fed2c83 100644 --- a/mission/devices/RadiationSensorHandler.h +++ b/mission/devices/RadiationSensorHandler.h @@ -16,6 +16,7 @@ class RadiationSensorHandler : public DeviceHandlerBase { public: RadiationSensorHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie); virtual ~RadiationSensorHandler(); + void setToGoToNormalModeImmediately(); protected: void doStartUp() override; @@ -42,6 +43,7 @@ class RadiationSensorHandler : public DeviceHandlerBase { static const uint8_t MAX_CMD_LEN = RAD_SENSOR::READ_SIZE; + bool goToNormalMode = false; uint8_t cmdBuffer[MAX_CMD_LEN]; InternalState internalState = InternalState::SETUP; CommunicationStep communicationStep = CommunicationStep::START_CONVERSION; diff --git a/mission/devices/max1227.cpp b/mission/devices/max1227.cpp index e8b33cbe..f00e532e 100644 --- a/mission/devices/max1227.cpp +++ b/mission/devices/max1227.cpp @@ -7,3 +7,22 @@ uint8_t max1227::buildConvByte(ScanModes scanMode, uint8_t channel, bool readTem uint8_t max1227::buildSetupByte(ClkSel clkSel, RefSel refSel, DiffSel diffSel) { return (1 << 6) | (clkSel << 4) | (refSel << 2) | diffSel; } + +void max1227::prepareExternallyClockedSingleChannelRead(uint8_t *spiBuf, uint8_t channel, + size_t &sz) { + spiBuf[0] = buildConvByte(ScanModes::N_ONCE, channel, false); + spiBuf[1] = 0x00; + spiBuf[2] = 0x00; + sz = 3; +} + +uint8_t max1227::buildResetByte(bool fifoOnly) { return (1 << 4) | (fifoOnly << 3); } + +void max1227::prepareExternallyClockedRead0ToN(uint8_t *spiBuf, uint8_t n, size_t &sz) { + for (uint8_t idx = 0; idx <= n; idx++) { + spiBuf[idx * 2] = buildConvByte(ScanModes::N_ONCE, idx, false); + spiBuf[idx * 2 + 1] = 0x00; + } + spiBuf[(n + 1) * 2] = 0x00; + sz = (n + 1) * 2 + 1; +} diff --git a/mission/devices/max1227.h b/mission/devices/max1227.h index 2a92c28b..35a49c45 100644 --- a/mission/devices/max1227.h +++ b/mission/devices/max1227.h @@ -1,6 +1,7 @@ #ifndef MISSION_DEVICES_MAX1227_H_ #define MISSION_DEVICES_MAX1227_H_ +#include #include namespace max1227 { @@ -38,9 +39,30 @@ enum DiffSel : uint8_t { // One bipolar config byte follows the setup byte BIPOLAR_CFG = 0b11 }; + +uint8_t buildResetByte(bool fifoOnly); uint8_t buildConvByte(ScanModes scanMode, uint8_t channel, bool readTemp); uint8_t buildSetupByte(ClkSel clkSel, RefSel refSel, DiffSel diffSel); +/** + * If there is a wakeup delay, there needs to be a 65 us delay between sending + * the first byte (conversion byte) and the the rest of the SPI buffer. + * The raw ADC value will be located in the first and second reply byte. + * @param spiBuf + * @param n + * @param sz + */ +void prepareExternallyClockedSingleChannelRead(uint8_t* spiBuf, uint8_t channel, size_t& sz); + +/** + * If there is a wakeup delay, there needs to be a 65 us delay between sending + * the first byte (first conversion byte) the the rest of the SPI buffer. + * @param spiBuf + * @param n + * @param sz + */ +void prepareExternallyClockedRead0ToN(uint8_t* spiBuf, uint8_t n, size_t& sz); + } // namespace max1227 #endif /* MISSION_DEVICES_MAX1227_H_ */ From 25b4af1921341bd609913f20de6f93946de21163 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 16 Feb 2022 20:08:10 +0100 Subject: [PATCH 02/19] more test code --- common/config/devConf.h | 4 +- linux/boardtest/SpiTestClass.cpp | 117 +++++++++++++++++++++++++------ 2 files changed, 98 insertions(+), 23 deletions(-) diff --git a/common/config/devConf.h b/common/config/devConf.h index deea6aa2..b3848225 100644 --- a/common/config/devConf.h +++ b/common/config/devConf.h @@ -29,8 +29,8 @@ static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; */ static const uint32_t SUS_MAX1227_SPI_FREQ = 976'000; -static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 976'000; -static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 4'000'000; +static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0; static constexpr uint32_t DEFAULT_ADIS16507_SPEED = 976'000; static constexpr spi::SpiModes DEFAULT_ADIS16507_MODE = spi::SpiModes::MODE_3; diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index 14c69577..f35300fa 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -281,9 +281,10 @@ void SpiTestClass::performL3gTest(uint8_t l3gId) { void SpiTestClass::performMax1227Test() { using namespace max1227; - bool testRadSensor = false; - bool extConversion = true; - bool intConversion = false; + bool testRadSensorExtConv = false; + bool testRadSensorIntConv = false; + bool extConversion = false; + bool intConversion = true; #ifdef XIPHOS_Q7S std::string deviceName = q7s::SPI_DEFAULT_DEV; #elif defined(RASPBERRY_PI) @@ -301,7 +302,7 @@ void SpiTestClass::performMax1227Test() { spi::SpiModes spiMode = spi::SpiModes::MODE_3; setSpiSpeedAndMode(fd, spiMode, spiSpeed); - if (testRadSensor) { + if (testRadSensorExtConv) { sendBuffer[0] = max1227::buildResetByte(true); sendBuffer[1] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0); @@ -314,11 +315,64 @@ void SpiTestClass::performMax1227Test() { utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); } - result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } - max1227::prepareExternallyClockedSingleChannelRead(sendBuffer.data(), 0, - spiTransferStruct[0].len); + max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 7, spiTransferStruct[0].len); + result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + arrayprinter::print(recvBuffer.data(), 13, OutputType::HEX); + uint16_t adcRaw[8] = {}; + adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2]; + adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4]; + adcRaw[2] = (recvBuffer[5] << 8) | recvBuffer[6]; + adcRaw[3] = (recvBuffer[7] << 8) | recvBuffer[8]; + adcRaw[4] = (recvBuffer[9] << 8) | recvBuffer[10]; + adcRaw[5] = (recvBuffer[11] << 8) | recvBuffer[12]; + adcRaw[6] = (recvBuffer[13] << 8) | recvBuffer[14]; + adcRaw[7] = (recvBuffer[15] << 8) | recvBuffer[16]; + arrayprinter::print(recvBuffer.data(), 17, OutputType::HEX); + for (int idx = 0; idx < 8; idx++) { + sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; + } + } + if (testRadSensorIntConv) { + sendBuffer[0] = max1227::buildResetByte(false); + spiTransferStruct[0].len = 1; + ReturnValue_t result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + 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; + result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + } + result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + } + usleep(10); + sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 7, true); + spiTransferStruct[0].len = 1; result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); if (result != HasReturnvaluesIF::RETURN_OK) { } @@ -326,12 +380,14 @@ void SpiTestClass::performMax1227Test() { if (retval < 0) { utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); } - arrayprinter::print(recvBuffer.data(), 3); result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); if (result != HasReturnvaluesIF::RETURN_OK) { } - max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len); + usleep(65); + spiTransferStruct[0].len = 18; + // Shift out zeros + spiTransferStruct[0].tx_buf = 0; result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); if (result != HasReturnvaluesIF::RETURN_OK) { } @@ -342,7 +398,23 @@ void SpiTestClass::performMax1227Test() { result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); if (result != HasReturnvaluesIF::RETURN_OK) { } - arrayprinter::print(recvBuffer.data(), 13., OutputType::DEC); + + arrayprinter::print(recvBuffer.data(), 14); + uint16_t adcRaw[8] = {}; + int16_t tempRaw = ((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]; + + sif::info << "Temperature: " << tempRaw * 0.125 << " C" << std::endl; + adcRaw[0] = (recvBuffer[2] << 8) | recvBuffer[3]; + adcRaw[1] = (recvBuffer[4] << 8) | recvBuffer[5]; + adcRaw[2] = (recvBuffer[6] << 8) | recvBuffer[7]; + adcRaw[3] = (recvBuffer[8] << 8) | recvBuffer[9]; + adcRaw[4] = (recvBuffer[10] << 8) | recvBuffer[11]; + adcRaw[5] = (recvBuffer[12] << 8) | recvBuffer[13]; + adcRaw[6] = (recvBuffer[14] << 8) | recvBuffer[15]; + adcRaw[7] = (recvBuffer[16] << 8) | recvBuffer[17]; + for (int idx = 0; idx < 8; idx++) { + sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; + } } if (extConversion) { sendBuffer[0] = max1227::buildResetByte(false); @@ -361,15 +433,6 @@ void SpiTestClass::performMax1227Test() { utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); } - // usleep(4); - // max1227::prepareExternallyClockedSingleChannelRead(sendBuffer.data(), 0, - // spiTransferStruct[0].len); - // retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - // if (retval < 0) { - // utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - // } - // arrayprinter::print(recvBuffer.data(), 3); - max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len); retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); if (retval < 0) { @@ -421,6 +484,18 @@ void SpiTestClass::performMax1227Test() { utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); } 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]; + adcRaw[2] = (recvBuffer[6] << 8) | recvBuffer[7]; + adcRaw[3] = (recvBuffer[8] << 8) | recvBuffer[9]; + adcRaw[4] = (recvBuffer[10] << 8) | recvBuffer[11]; + adcRaw[5] = (recvBuffer[12] << 8) | recvBuffer[13]; + for (int idx = 0; idx < 6; idx++) { + sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; + } } } From effe461380e9972680e3cdc1c778da3d6272e38c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 16 Feb 2022 21:29:37 +0100 Subject: [PATCH 03/19] nothing works --- bsp_q7s/core/ObjectFactory.cpp | 1 + common/config/devConf.h | 4 +- linux/devices/SusHandler.cpp | 15 ++-- linux/devices/SusHandler.h | 2 +- .../pollingSequenceFactory.cpp | 72 +++++++++++-------- 5 files changed, 54 insertions(+), 40 deletions(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 290411c6..eae4eb46 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -305,6 +305,7 @@ void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); + static_cast(radSensor); #if OBSW_TEST_RADIATION_SENSOR_HANDLER == 1 radSensor->setStartUpImmediately(); radSensor->setToGoToNormalModeImmediately(); diff --git a/common/config/devConf.h b/common/config/devConf.h index b3848225..deea6aa2 100644 --- a/common/config/devConf.h +++ b/common/config/devConf.h @@ -29,8 +29,8 @@ static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; */ static const uint32_t SUS_MAX1227_SPI_FREQ = 976'000; -static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 4'000'000; -static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 976'000; +static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; static constexpr uint32_t DEFAULT_ADIS16507_SPEED = 976'000; static constexpr spi::SpiModes DEFAULT_ADIS16507_MODE = spi::SpiModes::MODE_3; diff --git a/linux/devices/SusHandler.cpp b/linux/devices/SusHandler.cpp index 8959cf1b..3b7d996d 100644 --- a/linux/devices/SusHandler.cpp +++ b/linux/devices/SusHandler.cpp @@ -102,9 +102,10 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman } case (SUS::START_INT_TIMED_CONVERSIONS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); + //cmdBuffer[0] = max1227::buildResetByte(true); cmdBuffer[0] = SUS::CONVERSION; rawPacket = cmdBuffer; - rawPacketLen = 2; + rawPacketLen = 1; break; } case (SUS::READ_INT_TIMED_CONVERSIONS): { @@ -116,13 +117,12 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman case (SUS::READ_EXT_TIMED_CONVERSIONS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); rawPacket = cmdBuffer; - for (uint8_t idx = 0; idx < 1; idx++) { + for (uint8_t idx = 0; idx < 6; idx++) { cmdBuffer[idx * 2] = buildConvByte(ScanModes::N_ONCE, idx, false); cmdBuffer[idx * 2 + 1] = 0; } - cmdBuffer[2] = 0x00; - // cmdBuffer[12] = 0x00; - rawPacketLen = 3; // SUS::SIZE_READ_EXT_CONVERSIONS; + cmdBuffer[12] = 0x00; + rawPacketLen = SUS::SIZE_READ_EXT_CONVERSIONS; break; } case (SUS::READ_EXT_TIMED_TEMPS): { @@ -168,7 +168,8 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8 } case SUS::READ_INT_TIMED_CONVERSIONS: { PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; + + dataset.temperatureCelcius = static_cast((packet[0] << 8) | packet[1]) * 0.125; dataset.ain0 = (*(packet + 2) << 8 | *(packet + 3)); dataset.ain1 = (*(packet + 4) << 8 | *(packet + 5)); dataset.ain2 = (*(packet + 6) << 8 | *(packet + 7)); @@ -195,7 +196,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8 } case (SUS::READ_EXT_TIMED_TEMPS): { PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (packet[23] << 8) | packet[24]; + dataset.temperatureCelcius = static_cast(((packet[23] & 0x0f) << 8) | packet[24]) * 0.125; comState = ComStates::EXT_CLOCKED_CONVERSIONS; break; } diff --git a/linux/devices/SusHandler.h b/linux/devices/SusHandler.h index d2f5f9ce..04fd3032 100644 --- a/linux/devices/SusHandler.h +++ b/linux/devices/SusHandler.h @@ -77,7 +77,7 @@ class SusHandler : public DeviceHandlerBase { SUS::SusDataset dataset; // Read temperature in each alternating communication step when using // externally clocked mode - ClkModes clkMode = ClkModes::EXT_CLOCKED; + ClkModes clkMode = ClkModes::INT_CLOCKED; uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; ComStates comState = ComStates::IDLE; diff --git a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 6e0194e3..b43e8632 100644 --- a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -161,7 +161,7 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { #if OBSW_ADD_SUN_SENSORS == 1 - bool addSus0 = true; + bool addSus0 = false; bool addSus1 = false; bool addSus2 = false; bool addSus3 = false; @@ -169,7 +169,7 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { bool addSus5 = false; bool addSus6 = false; bool addSus7 = false; - bool addSus8 = false; + bool addSus8 = true; bool addSus9 = false; bool addSus10 = false; bool addSus11 = false; @@ -186,9 +186,14 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { thisSequence->addSlot(objects::SUS_0, length * 0, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_0, length * 0.933, SusHandler::FIRST_WRITE); thisSequence->addSlot(objects::SUS_0, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_0, length * 0.2, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_0, length * 0.2, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_0, length * 0.2, DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::SUS_0, length * 0.4, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_0, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_0, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_0, length * 0.8, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_0, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_0, length * 0.4, DeviceHandlerIF::GET_READ); /* Start ADC conversions */ // thisSequence->addSlot(objects::SUS_0, length * 0.934, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_0, length * 0.94, DeviceHandlerIF::SEND_WRITE); @@ -225,11 +230,11 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { } if (addSus2) { /* Write setup */ - thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_2, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.8, DeviceHandlerIF::GET_READ); // /* Write setup */ // thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_2, length * 0.904, SusHandler::SEND_WRITE); @@ -245,11 +250,11 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { } if (addSus3) { /* Write setup */ - thisSequence->addSlot(objects::SUS_3, length * 0.8, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_3, length * 0.8, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_3, length * 0.8, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_3, length * 0.8, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_3, length * 0.8, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_3, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_3, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_3, length * 0.8, DeviceHandlerIF::GET_READ); // /* Write setup */ // thisSequence->addSlot(objects::SUS_3, length * 0.91, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_3, length * 0.91, SusHandler::SEND_WRITE); @@ -265,12 +270,12 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { } if (addSus4) { /* Write setup */ - thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_4, length * 0, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_4, length * 0.909, SusHandler::FIRST_WRITE); - thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_4, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_4, length * 0.8, DeviceHandlerIF::GET_READ); /* Write setup */ // thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_4, length * 0.91, SusHandler::FIRST_WRITE); @@ -349,12 +354,16 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { if (addSus8) { /* Write setup */ - thisSequence->addSlot(objects::SUS_8, length * 0.9, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_8, length * 0.921, SusHandler::FIRST_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.925, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.93, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.95, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.96, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::GET_READ); /* Start ADC conversions */ // thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::SEND_WRITE); @@ -372,12 +381,15 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { if (addSus9) { /* Write setup */ - thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_9, length * 0.924, SusHandler::FIRST_WRITE); - thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_9, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::GET_READ); // /* Start ADC conversions */ // // thisSequence->addSlot(objects::SUS_9, length * 0.925, // DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::SUS_9, length * 0.925, From ae4d1e6db3e3eed4c61da3ba48e543f16434b417 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Feb 2022 10:17:46 +0100 Subject: [PATCH 04/19] update spi test task for PL PCDU --- linux/boardtest/SpiTestClass.cpp | 178 ++++++++++++------------------- linux/boardtest/SpiTestClass.h | 1 + mission/devices/max1227.h | 2 +- 3 files changed, 68 insertions(+), 113 deletions(-) diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index f35300fa..537baffb 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -283,15 +283,15 @@ void SpiTestClass::performMax1227Test() { using namespace max1227; bool testRadSensorExtConv = false; bool testRadSensorIntConv = false; - bool extConversion = false; - bool intConversion = true; + bool susExtConversion = false; + bool susIntConversion = false; + bool plPcduAdcExtConv = false; #ifdef XIPHOS_Q7S std::string deviceName = q7s::SPI_DEFAULT_DEV; #elif defined(RASPBERRY_PI) std::string deviceName = ""; #endif int fd = 0; - int retval = 0; UnixFileGuard fileHelper(deviceName, &fd, O_RDWR, "SpiComIF::initializeInterface"); if (fileHelper.getOpenResult()) { sif::error << "SpiTestClass::performLis3Mdl3100Test: File descriptor could not be opened!" @@ -307,25 +307,10 @@ void SpiTestClass::performMax1227Test() { sendBuffer[1] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0); spiTransferStruct[0].len = 2; - ReturnValue_t result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } + transfer(fd, gpioIds::CS_RAD_SENSOR); max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 7, spiTransferStruct[0].len); - result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } - result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } + transfer(fd, gpioIds::CS_RAD_SENSOR); arrayprinter::print(recvBuffer.data(), 13, OutputType::HEX); uint16_t adcRaw[8] = {}; adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2]; @@ -344,60 +329,24 @@ void SpiTestClass::performMax1227Test() { if (testRadSensorIntConv) { sendBuffer[0] = max1227::buildResetByte(false); spiTransferStruct[0].len = 1; - ReturnValue_t result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } - result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } + transfer(fd, gpioIds::CS_RAD_SENSOR); 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; - result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } - result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } + transfer(fd, gpioIds::CS_RAD_SENSOR); usleep(10); sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 7, true); spiTransferStruct[0].len = 1; - result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } - result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } + transfer(fd, gpioIds::CS_RAD_SENSOR); usleep(65); spiTransferStruct[0].len = 18; // Shift out zeros spiTransferStruct[0].tx_buf = 0; - result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } - result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); - if (result != HasReturnvaluesIF::RETURN_OK) { - } + transfer(fd, gpioIds::CS_RAD_SENSOR); arrayprinter::print(recvBuffer.data(), 14); uint16_t adcRaw[8] = {}; @@ -416,28 +365,19 @@ void SpiTestClass::performMax1227Test() { sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; } } - if (extConversion) { + if (susExtConversion) { sendBuffer[0] = max1227::buildResetByte(false); spiTransferStruct[0].len = 1; - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } + transfer(fd, gpio::NO_GPIO); usleep(65); sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0); spiTransferStruct[0].len = 1; - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } + transfer(fd, gpio::NO_GPIO); max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len); - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } + transfer(fd, gpio::NO_GPIO); uint16_t adcRaw[6] = {}; adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2]; adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4]; @@ -450,39 +390,26 @@ void SpiTestClass::performMax1227Test() { sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; } } - if (intConversion) { + if (susIntConversion) { sendBuffer[0] = max1227::buildResetByte(false); spiTransferStruct[0].len = 1; - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } - + transfer(fd, gpio::NO_GPIO); 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; - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } + transfer(fd, gpio::NO_GPIO); usleep(10); sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 5, true); spiTransferStruct[0].len = 1; - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } + transfer(fd, gpio::NO_GPIO); usleep(65); spiTransferStruct[0].len = 14; // Shift out zeros spiTransferStruct[0].tx_buf = 0; - retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); - } + transfer(fd, gpio::NO_GPIO); arrayprinter::print(recvBuffer.data(), 14); float temp = static_cast(((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]) * 0.125; sif::info << "Temperature: " << temp << " C" << std::endl; @@ -497,28 +424,30 @@ void SpiTestClass::performMax1227Test() { sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; } } -} - -/* - * sendBuffer[0] = buildConvByte(ScanModes::N_ONCE, 0, false); - spiTransferStruct[0].len = 1; - uint8_t reply0 = 0x00; - uint8_t reply1 = 0x00; - spiTransferStruct[1].tx_buf = 0; - spiTransferStruct[1].rx_buf = reinterpret_cast<__u64>(&reply0); - spiTransferStruct[1].len = 1; - // Shift out zeros - spiTransferStruct[2].tx_buf = 0; - spiTransferStruct[2].rx_buf = reinterpret_cast<__u64>(&reply1); - spiTransferStruct[2].len = 1; - retval = ioctl(fd, SPI_IOC_MESSAGE(3), spiTransferStruct); - if (retval < 0) { - utility::handleIoctlError("SpiTestClass::writeRegister: Write failed"); + if (plPcduAdcExtConv) { + // This enables the ADC + gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); + gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1); + sendBuffer[0] = max1227::buildResetByte(true); + spiTransferStruct[0].len = 1; + transfer(fd, gpioIds::PLPCDU_ADC_CS); + sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, + DiffSel::NONE_0); + spiTransferStruct[0].len = 1; + transfer(fd, gpioIds::PLPCDU_ADC_CS); + uint8_t n = 11; + max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), n, spiTransferStruct[0].len); + transfer(fd, gpioIds::PLPCDU_ADC_CS); + uint16_t adcRaw[n + 1] = {}; + for(uint8_t idx = 0; idx < n + 1; idx++) { + adcRaw[idx] = (recvBuffer[idx * 2 + 1] << 8) | recvBuffer[idx * 2 + 2]; + } + arrayprinter::print(recvBuffer.data(), spiTransferStruct[0].len, OutputType::HEX); + for (int idx = 0; idx < n + 1; idx++) { + sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; + } } - recvBuffer[1] = reply0; - recvBuffer[2] = reply1; - arrayprinter::print(recvBuffer.data(), 3); - */ +} void SpiTestClass::acsInit() { GpioCookie *gpioCookie = new GpioCookie(); @@ -747,3 +676,28 @@ uint8_t SpiTestClass::readRegister(int fd, gpioId_t chipSelect, uint8_t reg) { } return recvBuffer[1]; } + +ReturnValue_t SpiTestClass::transfer(int fd, gpioId_t chipSelect = gpio::NO_GPIO) { + int retval = 0; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + if(chipSelect != gpio::NO_GPIO) { + result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + } + + retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct); + if (retval < 0) { + utility::handleIoctlError("SpiTestClass::transfer: ioctl failed"); + return HasReturnvaluesIF::RETURN_FAILED; + } + + if(chipSelect != gpio::NO_GPIO) { + result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + } + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/linux/boardtest/SpiTestClass.h b/linux/boardtest/SpiTestClass.h index c8a96471..3c9c159e 100644 --- a/linux/boardtest/SpiTestClass.h +++ b/linux/boardtest/SpiTestClass.h @@ -74,6 +74,7 @@ class SpiTestClass : public TestTask { 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); + ReturnValue_t transfer(int fd, gpioId_t chipSelect); uint8_t readRm3100Register(int fd, gpioId_t chipSelect, uint8_t reg); uint8_t readStmRegister(int fd, gpioId_t chipSelect, uint8_t reg, bool autoIncrement); diff --git a/mission/devices/max1227.h b/mission/devices/max1227.h index 35a49c45..d081cf39 100644 --- a/mission/devices/max1227.h +++ b/mission/devices/max1227.h @@ -58,7 +58,7 @@ void prepareExternallyClockedSingleChannelRead(uint8_t* spiBuf, uint8_t channel, * If there is a wakeup delay, there needs to be a 65 us delay between sending * the first byte (first conversion byte) the the rest of the SPI buffer. * @param spiBuf - * @param n + * @param n Channel number. Example: If the ADC has 6 channels, n will be 5 * @param sz */ void prepareExternallyClockedRead0ToN(uint8_t* spiBuf, uint8_t n, size_t& sz); From 49decb8e9a9cd47878d26a47fef6ba2502ed73a1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Feb 2022 20:42:53 +0100 Subject: [PATCH 05/19] added new max1227 helper functions --- mission/devices/max1227.cpp | 10 ++++++++++ mission/devices/max1227.h | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/mission/devices/max1227.cpp b/mission/devices/max1227.cpp index f00e532e..88cab185 100644 --- a/mission/devices/max1227.cpp +++ b/mission/devices/max1227.cpp @@ -1,5 +1,7 @@ #include "max1227.h" +#include + uint8_t max1227::buildConvByte(ScanModes scanMode, uint8_t channel, bool readTemp) { return (1 << 7) | (channel << 3) | (scanMode << 1) | readTemp; } @@ -26,3 +28,11 @@ void max1227::prepareExternallyClockedRead0ToN(uint8_t *spiBuf, uint8_t n, size_ spiBuf[(n + 1) * 2] = 0x00; sz = (n + 1) * 2 + 1; } + +void max1227::prepareExternallyClockedTemperatureRead(uint8_t *spiBuf, size_t &sz) { + spiBuf[0] = buildConvByte(ScanModes::N_ONCE, 0, true); + std::memset(spiBuf + 1, 0, 24); + sz = 25; +} + +float max1227::getTemperature(int16_t temp) { return static_cast(temp) * 0.125; } diff --git a/mission/devices/max1227.h b/mission/devices/max1227.h index d081cf39..bf76a81b 100644 --- a/mission/devices/max1227.h +++ b/mission/devices/max1227.h @@ -63,6 +63,16 @@ void prepareExternallyClockedSingleChannelRead(uint8_t* spiBuf, uint8_t channel, */ void prepareExternallyClockedRead0ToN(uint8_t* spiBuf, uint8_t n, size_t& sz); +/** + * Prepare an externally clocked temperature read. 25 bytes have to be sent + * and the raw temperature value will appear on the last 2 bytes of the reply. + * @param spiBuf + * @param sz + */ +void prepareExternallyClockedTemperatureRead(uint8_t* spiBuf, size_t& sz); + +float getTemperature(int16_t temp); + } // namespace max1227 #endif /* MISSION_DEVICES_MAX1227_H_ */ From 64b4ab324928fe4b9d1b0b48eb5ced53acacdb1b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Feb 2022 20:51:20 +0100 Subject: [PATCH 06/19] added rad sensor enable, obj factory fixes --- bsp_q7s/boardconfig/busConf.h | 1 + bsp_q7s/core/ObjectFactory.cpp | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bsp_q7s/boardconfig/busConf.h b/bsp_q7s/boardconfig/busConf.h index 324d741f..eba4fb36 100644 --- a/bsp_q7s/boardconfig/busConf.h +++ b/bsp_q7s/boardconfig/busConf.h @@ -70,6 +70,7 @@ static constexpr char EN_RW_3[] = "enable_rw_3"; static constexpr char EN_RW_4[] = "enable_rw_4"; static constexpr char RAD_SENSOR_CHIP_SELECT[] = "rad_sensor_chip_select"; +static constexpr char ENABLE_RADFET[] = "enable_radfet"; static constexpr char PAPB_BUSY_SIGNAL_VC0[] = "papb_busy_signal_vc0"; static constexpr char PAPB_EMPTY_SIGNAL_VC0[] = "papb_empty_signal_vc0"; static constexpr char PAPB_BUSY_SIGNAL_VC1[] = "papb_busy_signal_vc1"; diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index eae4eb46..b248dbb3 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -140,13 +140,11 @@ void ObjectFactory::produce(void* args) { createHeaterComponents(); createSolarArrayDeploymentComponents(); + createPlPcduComponents(gpioComIF, spiComIF); #if OBSW_ADD_SYRLINKS == 1 createSyrlinksComponents(); #endif /* OBSW_ADD_SYRLINKS == 1 */ - -#if OBSW_ADD_RTD_DEVICES == 1 createRtdComponents(gpioComIF); -#endif /* OBSW_ADD_RTD_DEVICES == 1 */ #if OBSW_ADD_MGT == 1 I2cCookie* imtqI2cCookie = @@ -254,9 +252,7 @@ void ObjectFactory::createCommunicationInterfaces(LinuxLibgpioIF** gpioComIF, Ua new CspComIF(objects::CSP_COM_IF); *i2cComIF = new I2cComIF(objects::I2C_COM_IF); *uartComIF = new UartComIF(objects::UART_COM_IF); -#if OBSW_ADD_SPI_TEST_CODE == 0 *spiComIF = new SpiComIF(objects::SPI_COM_IF, *gpioComIF); -#endif /* Q7S_ADD_SPI_TEST_CODE == 0 */ #if BOARD_TE0720 == 0 /* Adding gpios for chip select decoding to the gpioComIf */ @@ -298,6 +294,9 @@ void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { GpiodRegularByLineName* gpio = new GpiodRegularByLineName( q7s::gpioNames::RAD_SENSOR_CHIP_SELECT, consumer.str(), gpio::DIR_OUT, gpio::HIGH); gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, gpio); + gpio = new GpiodRegularByLineName(q7s::gpioNames::ENABLE_RADFET, consumer.str(), gpio::DIR_OUT, + gpio::LOW); + gpioCookieRadSensor->addGpio(gpioIds::ENABLE_RADFET, gpio); gpioComIF->addGpios(gpioCookieRadSensor); SpiCookie* spiCookieRadSensor = new SpiCookie( @@ -355,6 +354,7 @@ void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComI gpioComIF->addGpios(gpioCookieSus); +#if OBSW_ADD_SUN_SENSORS == 1 SpiCookie* spiCookie = new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); @@ -464,6 +464,8 @@ void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComI susHandler10->setToGoToNormalMode(true); susHandler11->setToGoToNormalMode(true); #endif + +#endif /* OBSW_ADD_SUN_SENSORS == 1 */ } void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComIF* uartComIF) { @@ -793,6 +795,7 @@ void ObjectFactory::createRtdComponents(LinuxLibgpioIF* gpioComIF) { gpioComIF->addGpios(rtdGpioCookie); +#if OBSW_ADD_RTD_DEVICES == 1 SpiCookie* spiRtdIc0 = new SpiCookie(addresses::RTD_IC_3, gpioIds::RTD_IC_3, q7s::SPI_DEFAULT_DEV, Max31865Definitions::MAX_REPLY_SIZE, spi::RTD_MODE, spi::RTD_SPEED); @@ -900,6 +903,7 @@ void ObjectFactory::createRtdComponents(LinuxLibgpioIF* gpioComIF) { static_cast(rtdIc13); static_cast(rtdIc14); static_cast(rtdIc15); +#endif } void ObjectFactory::createReactionWheelComponents(LinuxLibgpioIF* gpioComIF) { @@ -941,6 +945,7 @@ void ObjectFactory::createReactionWheelComponents(LinuxLibgpioIF* gpioComIF) { gpioComIF->addGpios(gpioCookieRw); +#if OBSW_ADD_RW == 1 auto rw1SpiCookie = new SpiCookie(addresses::RW1, gpioIds::CS_RW1, q7s::SPI_RW_DEV, RwDefinitions::MAX_REPLY_SIZE, spi::RW_MODE, spi::RW_SPEED, &rwSpiCallback::spiCallback, nullptr); @@ -982,6 +987,8 @@ void ObjectFactory::createReactionWheelComponents(LinuxLibgpioIF* gpioComIF) { rwHandler4->setStartUpImmediately(); #endif rw4SpiCookie->setCallbackArgs(rwHandler4); + +#endif /* OBSW_ADD_RW == 1 */ } void ObjectFactory::createCcsdsComponents(LinuxLibgpioIF* gpioComIF) { @@ -1103,7 +1110,7 @@ void ObjectFactory::createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* gpio::Levels::LOW); plPcduGpios->addGpio(gpioIds::PLPCDU_ENB_VBAT0, gpio); consumer = "PLPCDU_ENB_VBAT_1"; - gpio = new GpiodRegularByLineName(q7s::gpioNames::PL_PCDU_ENABLE_VBAT0, consumer, gpio::DIR_OUT, + gpio = new GpiodRegularByLineName(q7s::gpioNames::PL_PCDU_ENABLE_VBAT1, consumer, gpio::DIR_OUT, gpio::Levels::LOW); plPcduGpios->addGpio(gpioIds::PLPCDU_ENB_VBAT1, gpio); consumer = "PLPCDU_ENB_DRO"; From ce57f0b0f7216a4736468d32580077255ab6d3b3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Feb 2022 20:53:06 +0100 Subject: [PATCH 07/19] update spi test class --- linux/boardtest/SpiTestClass.cpp | 160 ++++++++++++++++++++++++------- linux/boardtest/SpiTestClass.h | 16 ++++ 2 files changed, 143 insertions(+), 33 deletions(-) diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index 537baffb..3804bff9 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -26,7 +26,7 @@ SpiTestClass::SpiTestClass(object_id_t objectId, GpioIF *gpioIF) } testMode = TestModes::SUS_0; spiTransferStruct[0].rx_buf = reinterpret_cast<__u64>(recvBuffer.data()); - spiTransferStruct[0].tx_buf = reinterpret_cast<__u64>(sendBuffer.data()); + setSendBuffer(); } ReturnValue_t SpiTestClass::performOneShotAction() { @@ -281,11 +281,14 @@ void SpiTestClass::performL3gTest(uint8_t l3gId) { void SpiTestClass::performMax1227Test() { using namespace max1227; - bool testRadSensorExtConv = false; - bool testRadSensorIntConv = false; - bool susExtConversion = false; - bool susIntConversion = false; - bool plPcduAdcExtConv = false; + testRadSensorExtConvWithDelay = false; + testRadSensorIntConv = false; + + susExtConversion = false; + susIntConversion = false; + + plPcduAdcExtConv = false; + plPcduAdcIntConv = true; #ifdef XIPHOS_Q7S std::string deviceName = q7s::SPI_DEFAULT_DEV; #elif defined(RASPBERRY_PI) @@ -302,36 +305,60 @@ void SpiTestClass::performMax1227Test() { spi::SpiModes spiMode = spi::SpiModes::MODE_3; setSpiSpeedAndMode(fd, spiMode, spiSpeed); - if (testRadSensorExtConv) { - sendBuffer[0] = max1227::buildResetByte(true); - sendBuffer[1] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, - DiffSel::NONE_0); - spiTransferStruct[0].len = 2; - transfer(fd, gpioIds::CS_RAD_SENSOR); + max1227RadSensorTest(fd); + max1227SusTest(fd); + max1227PlPcduTest(fd); +} +void SpiTestClass::max1227RadSensorTest(int fd) { + using namespace max1227; + if (testRadSensorExtConvWithDelay) { + sendBuffer[0] = max1227::buildResetByte(true); + spiTransferStruct[0].len = 1; + transfer(fd, gpioIds::CS_RAD_SENSOR); + usleep(200); + sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_WITH_WAKEUP, + DiffSel::NONE_0); + spiTransferStruct[0].len = 1; + transfer(fd, gpioIds::CS_RAD_SENSOR); max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 7, spiTransferStruct[0].len); + size_t tmpLen = spiTransferStruct[0].len; + spiTransferStruct[0].len = 1; + transfer(fd, gpioIds::CS_RAD_SENSOR); + std::memcpy(sendBuffer.data(), sendBuffer.data() + 1, tmpLen - 1); + spiTransferStruct[0].len = tmpLen - 1; + usleep(65); transfer(fd, gpioIds::CS_RAD_SENSOR); arrayprinter::print(recvBuffer.data(), 13, OutputType::HEX); uint16_t adcRaw[8] = {}; - adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2]; - adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4]; - adcRaw[2] = (recvBuffer[5] << 8) | recvBuffer[6]; - adcRaw[3] = (recvBuffer[7] << 8) | recvBuffer[8]; - adcRaw[4] = (recvBuffer[9] << 8) | recvBuffer[10]; - adcRaw[5] = (recvBuffer[11] << 8) | recvBuffer[12]; - adcRaw[6] = (recvBuffer[13] << 8) | recvBuffer[14]; - adcRaw[7] = (recvBuffer[15] << 8) | recvBuffer[16]; + adcRaw[0] = (recvBuffer[0] << 8) | recvBuffer[1]; + adcRaw[1] = (recvBuffer[2] << 8) | recvBuffer[3]; + adcRaw[2] = (recvBuffer[4] << 8) | recvBuffer[5]; + adcRaw[3] = (recvBuffer[6] << 8) | recvBuffer[7]; + adcRaw[4] = (recvBuffer[8] << 8) | recvBuffer[9]; + adcRaw[5] = (recvBuffer[10] << 8) | recvBuffer[11]; + adcRaw[6] = (recvBuffer[12] << 8) | recvBuffer[13]; + adcRaw[7] = (recvBuffer[14] << 8) | recvBuffer[15]; arrayprinter::print(recvBuffer.data(), 17, OutputType::HEX); for (int idx = 0; idx < 8; idx++) { sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; } + max1227::prepareExternallyClockedTemperatureRead(sendBuffer.data(), spiTransferStruct[0].len); + spiTransferStruct[0].len = 1; + transfer(fd, gpioIds::CS_RAD_SENSOR); + usleep(65); + spiTransferStruct[0].len = 24; + std::memcpy(sendBuffer.data(), sendBuffer.data() + 1, 24); + transfer(fd, gpioIds::CS_RAD_SENSOR); + int16_t tempRaw = ((recvBuffer[22] & 0x0f) << 8) | recvBuffer[23]; + float temp = max1227::getTemperature(tempRaw); + sif::info << "Temperature: " << temp << std::endl; } if (testRadSensorIntConv) { sendBuffer[0] = max1227::buildResetByte(false); spiTransferStruct[0].len = 1; transfer(fd, gpioIds::CS_RAD_SENSOR); - usleep(65); - + usleep(5); // Now use internal conversion sendBuffer[0] = max1227::buildSetupByte(ClkSel::INT_CONV_INT_TIMED_CNVST_AS_AIN, RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0); @@ -345,13 +372,13 @@ void SpiTestClass::performMax1227Test() { usleep(65); spiTransferStruct[0].len = 18; // Shift out zeros - spiTransferStruct[0].tx_buf = 0; + shiftOutZeros(); transfer(fd, gpioIds::CS_RAD_SENSOR); + setSendBuffer(); arrayprinter::print(recvBuffer.data(), 14); uint16_t adcRaw[8] = {}; int16_t tempRaw = ((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]; - sif::info << "Temperature: " << tempRaw * 0.125 << " C" << std::endl; adcRaw[0] = (recvBuffer[2] << 8) | recvBuffer[3]; adcRaw[1] = (recvBuffer[4] << 8) | recvBuffer[5]; @@ -365,6 +392,10 @@ void SpiTestClass::performMax1227Test() { sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; } } +} + +void SpiTestClass::max1227SusTest(int fd) { + using namespace max1227; if (susExtConversion) { sendBuffer[0] = max1227::buildResetByte(false); spiTransferStruct[0].len = 1; @@ -408,8 +439,9 @@ void SpiTestClass::performMax1227Test() { usleep(65); spiTransferStruct[0].len = 14; // Shift out zeros - spiTransferStruct[0].tx_buf = 0; + shiftOutZeros(); transfer(fd, gpio::NO_GPIO); + setSendBuffer(); arrayprinter::print(recvBuffer.data(), 14); float temp = static_cast(((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]) * 0.125; sif::info << "Temperature: " << temp << " C" << std::endl; @@ -424,11 +456,22 @@ void SpiTestClass::performMax1227Test() { sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; } } +} + +void SpiTestClass::max1227PlPcduTest(int fd) { + using namespace max1227; if (plPcduAdcExtConv) { // This enables the ADC - gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); - gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1); - sendBuffer[0] = max1227::buildResetByte(true); + ReturnValue_t result = gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); + if (result != HasReturnvaluesIF::RETURN_OK) { + return; + } + result = gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1); + if (result != HasReturnvaluesIF::RETURN_OK) { + return; + } + usleep(1000); + sendBuffer[0] = max1227::buildResetByte(false); spiTransferStruct[0].len = 1; transfer(fd, gpioIds::PLPCDU_ADC_CS); sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, @@ -439,11 +482,56 @@ void SpiTestClass::performMax1227Test() { max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), n, spiTransferStruct[0].len); transfer(fd, gpioIds::PLPCDU_ADC_CS); uint16_t adcRaw[n + 1] = {}; - for(uint8_t idx = 0; idx < n + 1; idx++) { + for (uint8_t idx = 0; idx < n + 1; idx++) { adcRaw[idx] = (recvBuffer[idx * 2 + 1] << 8) | recvBuffer[idx * 2 + 2]; } arrayprinter::print(recvBuffer.data(), spiTransferStruct[0].len, OutputType::HEX); + sif::info << "PL PCDU ADC values:" << std::endl; for (int idx = 0; idx < n + 1; idx++) { + sif::info << "Raw Value " << idx << ": " << adcRaw[idx] << std::endl; + } + max1227::prepareExternallyClockedTemperatureRead(sendBuffer.data(), spiTransferStruct[0].len); + transfer(fd, gpioIds::PLPCDU_ADC_CS); + int16_t tempRaw = ((recvBuffer[23] & 0x0f) << 8) | recvBuffer[24]; + float temp = max1227::getTemperature(tempRaw); + sif::info << "Temperature: " << temp << std::endl; + } + if (plPcduAdcIntConv) { + // This enables the ADC + ReturnValue_t result = gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); + if (result != HasReturnvaluesIF::RETURN_OK) { + return; + } + result = gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1); + if (result != HasReturnvaluesIF::RETURN_OK) { + return; + } + usleep(1000); + sendBuffer[0] = max1227::buildResetByte(false); + spiTransferStruct[0].len = 1; + transfer(fd, gpioIds::PLPCDU_ADC_CS); + // 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, gpioIds::PLPCDU_ADC_CS); + usleep(10); + uint8_t n = 11; + sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, n, true); + spiTransferStruct[0].len = 1; + transfer(fd, gpioIds::PLPCDU_ADC_CS); + + usleep(65); + spiTransferStruct[0].len = 26; + // Shift out zeros + shiftOutZeros(); + transfer(fd, gpioIds::PLPCDU_ADC_CS); + setSendBuffer(); + uint16_t adcRaw[n + 1] = {}; + int16_t tempRaw = ((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]; + sif::info << "Temperature: " << tempRaw * 0.125 << " C" << std::endl; + for (int idx = 0; idx < n + 1; idx++) { + adcRaw[idx] = (recvBuffer[idx * 2 + 2] << 8) | recvBuffer[idx * 2 + 3]; sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl; } } @@ -624,6 +712,12 @@ void SpiTestClass::readMultipleStmRegisters(int fd, gpioId_t chipSelect, uint8_t readMultipleRegisters(fd, chipSelect, reg, reply, len); } +void SpiTestClass::shiftOutZeros() { spiTransferStruct[0].tx_buf = 0; } + +void SpiTestClass::setSendBuffer() { + spiTransferStruct[0].tx_buf = reinterpret_cast<__u64>(sendBuffer.data()); +} + void SpiTestClass::readMultipleRegisters(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t *reply, size_t len) { if (reply == nullptr) { @@ -680,8 +774,8 @@ uint8_t SpiTestClass::readRegister(int fd, gpioId_t chipSelect, uint8_t reg) { ReturnValue_t SpiTestClass::transfer(int fd, gpioId_t chipSelect = gpio::NO_GPIO) { int retval = 0; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - if(chipSelect != gpio::NO_GPIO) { - result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR); + if (chipSelect != gpio::NO_GPIO) { + result = gpioIF->pullLow(chipSelect); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } @@ -693,8 +787,8 @@ ReturnValue_t SpiTestClass::transfer(int fd, gpioId_t chipSelect = gpio::NO_GPIO return HasReturnvaluesIF::RETURN_FAILED; } - if(chipSelect != gpio::NO_GPIO) { - result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR); + if (chipSelect != gpio::NO_GPIO) { + result = gpioIF->pullHigh(chipSelect); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/linux/boardtest/SpiTestClass.h b/linux/boardtest/SpiTestClass.h index 3c9c159e..adf94739 100644 --- a/linux/boardtest/SpiTestClass.h +++ b/linux/boardtest/SpiTestClass.h @@ -51,6 +51,15 @@ 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; + uint8_t mgm0Lis3mdlChipSelect = 0; uint8_t mgm1Rm3100ChipSelect = 0; uint8_t gyro0AdisResetLine = 0; @@ -65,6 +74,13 @@ class SpiTestClass : public TestTask { static constexpr uint8_t RM3100_READ_MASK = STM_READ_MASK; static constexpr uint8_t STM_AUTO_INCR_MASK = 0b0100'0000; + void shiftOutZeros(); + void setSendBuffer(); + + void max1227RadSensorTest(int fd); + void max1227SusTest(int fd); + void max1227PlPcduTest(int fd); + void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed); void writeStmRegister(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t value, From 029ed7de9b36808d4b6906350f5f201d2ae5f11f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Feb 2022 20:53:28 +0100 Subject: [PATCH 08/19] small tweak --- mission/devices/RadiationSensorHandler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 92d2c311..c5148c84 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -126,7 +126,8 @@ ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, case RAD_SENSOR::READ_CONVERSIONS: { uint8_t offset = 0; PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet + offset) << 8 | *(packet + offset + 1)) * 0.125; + int16_t tempRaw = ((packet[offset] & 0x0f) << 8) | packet[offset + 1]; + dataset.temperatureCelcius = tempRaw * 0.125; offset += 2; dataset.ain0 = (*(packet + offset) << 8 | *(packet + offset + 1)); offset += 2; From ec7d624ccabb325498a1c44aaeb5ab4faa7b3f59 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Feb 2022 20:53:45 +0100 Subject: [PATCH 09/19] added missing gpioID --- linux/fsfwconfig/devices/gpioIds.h | 1 + 1 file changed, 1 insertion(+) diff --git a/linux/fsfwconfig/devices/gpioIds.h b/linux/fsfwconfig/devices/gpioIds.h index 2863bb50..e6f42eb4 100644 --- a/linux/fsfwconfig/devices/gpioIds.h +++ b/linux/fsfwconfig/devices/gpioIds.h @@ -75,6 +75,7 @@ enum gpioId_t { SPI_MUX_BIT_5, CS_RAD_SENSOR, + ENABLE_RADFET, PAPB_BUSY_N, PAPB_EMPTY, From 151621b49a21e6c8960280759d847aac10146371 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Feb 2022 21:17:40 +0100 Subject: [PATCH 10/19] added periodic test capability --- linux/boardtest/SpiTestClass.cpp | 38 +++++++++++++++++++++++++++----- linux/boardtest/SpiTestClass.h | 4 +++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index 3804bff9..1d48d01e 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -24,7 +24,7 @@ SpiTestClass::SpiTestClass(object_id_t objectId, GpioIF *gpioIF) if (gpioIF == nullptr) { sif::error << "SpiTestClass::SpiTestClass: Invalid GPIO ComIF!" << std::endl; } - testMode = TestModes::SUS_0; + testMode = TestModes::MAX1227; spiTransferStruct[0].rx_buf = reinterpret_cast<__u64>(recvBuffer.data()); setSendBuffer(); } @@ -46,15 +46,25 @@ ReturnValue_t SpiTestClass::performOneShotAction() { performL3gTest(gyro1L3gd20ChipSelect); break; } - case (TestModes::SUS_0): { - performMax1227Test(); + case (TestModes::MAX1227): { + performOneShotMax1227Test(); break; } } return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t SpiTestClass::performPeriodicAction() { return HasReturnvaluesIF::RETURN_OK; } +ReturnValue_t SpiTestClass::performPeriodicAction() { + switch (testMode) { + case (TestModes::MAX1227): { + performPeriodicMax1227Test(); + break; + } + default: + break; + } + return HasReturnvaluesIF::RETURN_OK; +} void SpiTestClass::performRm3100Test(uint8_t mgmId) { /* Configure all SPI chip selects and pull them high */ @@ -279,7 +289,7 @@ void SpiTestClass::performL3gTest(uint8_t l3gId) { sif::info << "Z: " << angVelocZ << std::endl; } -void SpiTestClass::performMax1227Test() { +void SpiTestClass::performOneShotMax1227Test() { using namespace max1227; testRadSensorExtConvWithDelay = false; testRadSensorIntConv = false; @@ -289,6 +299,23 @@ void SpiTestClass::performMax1227Test() { plPcduAdcExtConv = false; plPcduAdcIntConv = true; + performMax1227Test(); +} + +void SpiTestClass::performPeriodicMax1227Test() { + using namespace max1227; + testRadSensorExtConvWithDelay = false; + testRadSensorIntConv = false; + + susExtConversion = false; + susIntConversion = false; + + plPcduAdcExtConv = false; + plPcduAdcIntConv = true; + performMax1227Test(); +} + +void SpiTestClass::performMax1227Test() { #ifdef XIPHOS_Q7S std::string deviceName = q7s::SPI_DEFAULT_DEV; #elif defined(RASPBERRY_PI) @@ -527,6 +554,7 @@ void SpiTestClass::max1227PlPcduTest(int fd) { shiftOutZeros(); transfer(fd, gpioIds::PLPCDU_ADC_CS); setSendBuffer(); + arrayprinter::print(recvBuffer.data(), 26, OutputType::HEX); uint16_t adcRaw[n + 1] = {}; int16_t tempRaw = ((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]; sif::info << "Temperature: " << tempRaw * 0.125 << " C" << std::endl; diff --git a/linux/boardtest/SpiTestClass.h b/linux/boardtest/SpiTestClass.h index adf94739..29df9a45 100644 --- a/linux/boardtest/SpiTestClass.h +++ b/linux/boardtest/SpiTestClass.h @@ -15,7 +15,7 @@ class SpiTestClass : public TestTask { public: - enum TestModes { NONE, MGM_LIS3MDL, MGM_RM3100, GYRO_L3GD20H, SUS_0 }; + enum TestModes { NONE, MGM_LIS3MDL, MGM_RM3100, GYRO_L3GD20H, MAX1227 }; TestModes testMode; @@ -34,6 +34,8 @@ class SpiTestClass : public TestTask { void performRm3100Test(uint8_t mgmId); void performLis3MdlTest(uint8_t lis3Id); void performL3gTest(uint8_t l3gId); + void performOneShotMax1227Test(); + void performPeriodicMax1227Test(); void performMax1227Test(); /* ACS board specific code which pulls all GPIOs high */ From 6326ac71ca6f976ac176ca25ff756691c0fe1c84 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Feb 2022 11:29:51 +0100 Subject: [PATCH 11/19] this delay seems to do the job --- linux/boardtest/SpiTestClass.cpp | 24 +++++++++--------------- linux/boardtest/SpiTestClass.h | 1 + 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index 1d48d01e..4d35fa10 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -310,8 +310,8 @@ void SpiTestClass::performPeriodicMax1227Test() { susExtConversion = false; susIntConversion = false; - plPcduAdcExtConv = false; - plPcduAdcIntConv = true; + plPcduAdcExtConv = true; + plPcduAdcIntConv = false; performMax1227Test(); } @@ -487,7 +487,7 @@ void SpiTestClass::max1227SusTest(int fd) { void SpiTestClass::max1227PlPcduTest(int fd) { using namespace max1227; - if (plPcduAdcExtConv) { + if ((plPcduAdcExtConv or plPcduAdcIntConv) and vbatSwitch) { // This enables the ADC ReturnValue_t result = gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -497,7 +497,11 @@ void SpiTestClass::max1227PlPcduTest(int fd) { if (result != HasReturnvaluesIF::RETURN_OK) { return; } - usleep(1000); + vbatSwitch = false; + // Takes a bit of time until the ADC is usable + TaskFactory::delayTask(50); + } + if (plPcduAdcExtConv) { sendBuffer[0] = max1227::buildResetByte(false); spiTransferStruct[0].len = 1; transfer(fd, gpioIds::PLPCDU_ADC_CS); @@ -524,17 +528,7 @@ void SpiTestClass::max1227PlPcduTest(int fd) { sif::info << "Temperature: " << temp << std::endl; } if (plPcduAdcIntConv) { - // This enables the ADC - ReturnValue_t result = gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); - if (result != HasReturnvaluesIF::RETURN_OK) { - return; - } - result = gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1); - if (result != HasReturnvaluesIF::RETURN_OK) { - return; - } - usleep(1000); - sendBuffer[0] = max1227::buildResetByte(false); + sendBuffer[0] = max1227::buildResetByte(true); spiTransferStruct[0].len = 1; transfer(fd, gpioIds::PLPCDU_ADC_CS); // Now use internal conversion diff --git a/linux/boardtest/SpiTestClass.h b/linux/boardtest/SpiTestClass.h index 29df9a45..adf63e6e 100644 --- a/linux/boardtest/SpiTestClass.h +++ b/linux/boardtest/SpiTestClass.h @@ -61,6 +61,7 @@ class SpiTestClass : public TestTask { bool plPcduAdcExtConv = false; bool plPcduAdcIntConv = false; + bool vbatSwitch = true; uint8_t mgm0Lis3mdlChipSelect = 0; uint8_t mgm1Rm3100ChipSelect = 0; From b6f3b838b7657aca9babf5cb78847d88c918acb1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Feb 2022 12:46:28 +0100 Subject: [PATCH 12/19] 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); From 16680663fd4a9fb07030c370b41fcf193031dd4b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Feb 2022 12:46:58 +0100 Subject: [PATCH 13/19] sus handler update --- linux/devices/SusHandler.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/linux/devices/SusHandler.cpp b/linux/devices/SusHandler.cpp index 3b7d996d..bf33e4d7 100644 --- a/linux/devices/SusHandler.cpp +++ b/linux/devices/SusHandler.cpp @@ -102,10 +102,10 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman } case (SUS::START_INT_TIMED_CONVERSIONS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - //cmdBuffer[0] = max1227::buildResetByte(true); - cmdBuffer[0] = SUS::CONVERSION; + cmdBuffer[0] = max1227::buildResetByte(true); + cmdBuffer[1] = SUS::CONVERSION; rawPacket = cmdBuffer; - rawPacketLen = 1; + rawPacketLen = 2; break; } case (SUS::READ_INT_TIMED_CONVERSIONS): { @@ -196,7 +196,8 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8 } case (SUS::READ_EXT_TIMED_TEMPS): { PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = static_cast(((packet[23] & 0x0f) << 8) | packet[24]) * 0.125; + dataset.temperatureCelcius = + static_cast(((packet[23] & 0x0f) << 8) | packet[24]) * 0.125; comState = ComStates::EXT_CLOCKED_CONVERSIONS; break; } From a01ddf6a5b5791e358ca0066aad9a6f1a64fdad3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Feb 2022 13:10:06 +0100 Subject: [PATCH 14/19] updated PST --- .../pollingSequenceFactory.cpp | 350 ++++++------------ 1 file changed, 115 insertions(+), 235 deletions(-) diff --git a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index b43e8632..b43c403f 100644 --- a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -161,18 +161,18 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { #if OBSW_ADD_SUN_SENSORS == 1 - bool addSus0 = false; - bool addSus1 = false; - bool addSus2 = false; - bool addSus3 = false; - bool addSus4 = false; - bool addSus5 = false; - bool addSus6 = false; - bool addSus7 = false; + bool addSus0 = true; + bool addSus1 = true; + bool addSus2 = true; + bool addSus3 = true; + bool addSus4 = true; + bool addSus5 = true; + bool addSus6 = true; + bool addSus7 = true; bool addSus8 = true; - bool addSus9 = false; - bool addSus10 = false; - bool addSus11 = false; + bool addSus9 = true; + bool addSus10 = true; + bool addSus11 = true; /** * The sun sensor will be shutdown as soon as the chip select is pulled high. Thus all * requests to a sun sensor must be performed consecutively. Another reason for calling multiple @@ -184,272 +184,152 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { if (addSus0) { /* Write setup */ thisSequence->addSlot(objects::SUS_0, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_0, length * 0.933, SusHandler::FIRST_WRITE); - thisSequence->addSlot(objects::SUS_0, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_0, length * 0.2, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_0, length * 0.2, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_0, length * 0.2, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_0, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_0, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_0, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_0, length * 0, DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_0, length * 0.4, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_0, length * 0.4, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SUS_0, length * 0.4, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_0, length * 0.4, DeviceHandlerIF::GET_READ); - /* Start ADC conversions */ - // thisSequence->addSlot(objects::SUS_0, length * 0.934, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_0, length * 0.94, DeviceHandlerIF::SEND_WRITE); - // thisSequence->addSlot(objects::SUS_0, length * 0.94, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_0, length * 0.94, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_0, length * 0.94, DeviceHandlerIF::GET_READ); - // /* Read ADC conversions */ - // // thisSequence->addSlot(objects::SUS_0, length * 0.935, - // DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::SUS_0, length * 0.935, - // DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_0, length * 0.935, - // DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SUS_0, length * 0.935, - // DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_0, length * 0.935, - // DeviceHandlerIF::GET_READ); } if (addSus1) { - /* Write setup */ - thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::GET_READ); - // /* Write setup */ - // thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_1, length * 0.901, SusHandler::FIRST_WRITE); - // thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::GET_READ); - // /* Write setup */ - // thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_1, length * 0.902, SusHandler::FIRST_WRITE); - // thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_READ); } if (addSus2) { - /* Write setup */ thisSequence->addSlot(objects::SUS_2, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_2, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0, DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::SUS_2, length * 0.4, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_2, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_2, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_2, length * 0.8, DeviceHandlerIF::GET_READ); - // /* Write setup */ - // thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_2, length * 0.904, SusHandler::SEND_WRITE); - // thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::GET_READ); - // /* Write setup */ - // thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_2, length * 0.905, SusHandler::SEND_WRITE); - // thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.4, DeviceHandlerIF::GET_READ); } if (addSus3) { - /* Write setup */ - thisSequence->addSlot(objects::SUS_3, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_3, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_3, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_3, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_3, length * 0.8, DeviceHandlerIF::GET_READ); - // /* Write setup */ - // thisSequence->addSlot(objects::SUS_3, length * 0.91, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_3, length * 0.91, SusHandler::SEND_WRITE); - // thisSequence->addSlot(objects::SUS_3, length * 0.91, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_3, length * 0.91, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_3, length * 0.91, DeviceHandlerIF::GET_READ); - // /* Write setup */ - // thisSequence->addSlot(objects::SUS_3, length * 0.93, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_3, length * 0.93, SusHandler::SEND_WRITE); - // thisSequence->addSlot(objects::SUS_3, length * 0.93, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_3, length * 0.93, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_3, length * 0.93, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_3, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_3, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_3, length * 0, DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::SUS_3, length * 0.4, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_3, length * 0.4, DeviceHandlerIF::GET_READ); } if (addSus4) { - /* Write setup */ thisSequence->addSlot(objects::SUS_4, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_4, length * 0.909, SusHandler::FIRST_WRITE); - thisSequence->addSlot(objects::SUS_4, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_4, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_4, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_4, length * 0.8, DeviceHandlerIF::GET_READ); - /* Write setup */ - // thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_4, length * 0.91, SusHandler::FIRST_WRITE); - // thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::GET_READ); - // /* Write setup */ - // thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_4, length * 0.911, SusHandler::FIRST_WRITE); - // thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_4, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_4, length * 0, DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::SUS_4, length * 0.4, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_4, length * 0.4, DeviceHandlerIF::GET_READ); } if (addSus5) { - /* Write setup */ - thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::GET_READ); - // /* Write setup */ - // thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_5, length * 0.913, SusHandler::FIRST_WRITE); - // thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::GET_READ); - // /* Write setup */ - // thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_5, length * 0.914, SusHandler::FIRST_WRITE); - // thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_5, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_5, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_5, length * 0, DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::SUS_5, length * 0.4, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_5, length * 0.4, DeviceHandlerIF::GET_READ); } if (addSus6) { - /* Write setup */ - thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::GET_READ); - // /* Start ADC conversions */ - // thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::SEND_WRITE); - // thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::GET_READ); - // /* Read ADC conversions from inernal FIFO */ - // thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::SEND_WRITE); - // thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_6, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_6, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_6, length * 0, DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::SUS_6, length * 0.4, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_6, length * 0.4, DeviceHandlerIF::GET_READ); } if (addSus7) { - /* Write setup */ - thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::GET_READ); - // /* Start ADC conversions */ - // thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::SEND_WRITE); - // thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::GET_READ); - // /* Read ADC conversions from inernal FIFO */ - // thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::SEND_WRITE); - // thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_7, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_7, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_7, length * 0, DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::SUS_7, length * 0.4, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_7, length * 0.4, DeviceHandlerIF::GET_READ); } if (addSus8) { - /* Write setup */ thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_8, length * 0.921, SusHandler::FIRST_WRITE); thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::GET_READ); - /* Start ADC conversions */ - // thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::PERFORM_OPERATION); - // thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::SEND_WRITE); - // thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::GET_WRITE); - // thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::SEND_READ); - // thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::GET_READ); - // /* Read ADC conversions from internal FIFO */ - // // thisSequence->addSlot(objects::SUS_8, length * 0.925, - // DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::SUS_8, length * 0.925, - // DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_8, length * 0.925, - // DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SUS_8, length * 0.925, - // DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_8, length * 0.925, - // DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::GET_READ); } if (addSus9) { - /* Write setup */ thisSequence->addSlot(objects::SUS_9, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::GET_READ); - // /* Start ADC conversions */ - // // thisSequence->addSlot(objects::SUS_9, length * 0.925, - // DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::SUS_9, length * 0.925, - // DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_9, length * 0.925, - // DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SUS_9, length * 0.925, - // DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_9, length * 0.925, - // DeviceHandlerIF::GET_READ); - // /* Read ADC conversions */ - // // thisSequence->addSlot(objects::SUS_9, length * 0.926, - // DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::SUS_9, length * 0.926, - // DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_9, length * 0.926, - // DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SUS_9, length * 0.926, - // DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_9, length * 0.926, - // DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_9, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_9, length * 0, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_9, length * 0.4, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_9, length * 0.4, DeviceHandlerIF::GET_READ); } if (addSus10) { - /* Write setup */ - thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::GET_READ); - // /* Start ADC conversions */ - // thisSequence->addSlot(objects::SUS_10, length * 0.928, - // DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::SUS_10, length * - // 0.928, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_10, length * - // 0.928, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SUS_10, length * 0.928, - // DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_10, length * 0.928, - // DeviceHandlerIF::GET_READ); - // /* Read ADC conversions */ - // thisSequence->addSlot(objects::SUS_10, length * 0.929, - // DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::SUS_10, length * - // 0.929, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_10, length * - // 0.929, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SUS_10, length * 0.929, - // DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_10, length * 0.929, - // DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_10, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_10, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_10, length * 0, DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::SUS_10, length * 0.4, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_10, length * 0.4, DeviceHandlerIF::GET_READ); } if (addSus11) { - /* Write setup */ - thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::GET_READ); - // /* Start ADC conversions */ - // thisSequence->addSlot(objects::SUS_11, length * 0.931, - // DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::SUS_11, length * - // 0.931, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_11, length * - // 0.931, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SUS_11, length * 0.931, - // DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_11, length * 0.931, - // DeviceHandlerIF::GET_READ); - // /* Read ADC conversions */ - // thisSequence->addSlot(objects::SUS_11, length * 0.932, - // DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::SUS_11, length * - // 0.932, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SUS_11, length * - // 0.932, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SUS_11, length * 0.932, - // DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_11, length * 0.932, - // DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::SUS_11, length * 0.4, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_11, length * 0.4, DeviceHandlerIF::GET_READ); } #endif /* OBSW_ADD_SUN_SENSORS == 1 */ From 9cae806dd9b642fb6f668ba7afdb260f9f4e6b92 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Feb 2022 13:10:24 +0100 Subject: [PATCH 15/19] pass SUS idx to dev handler --- bsp_q7s/core/ObjectFactory.cpp | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index b248dbb3..80e5d242 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -358,73 +358,73 @@ void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComI SpiCookie* spiCookie = new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler0 = - new SusHandler(objects::SUS_0, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_0); + SusHandler* susHandler0 = new SusHandler(objects::SUS_0, 0, objects::SPI_COM_IF, spiCookie, + gpioComIF, gpioIds::CS_SUS_0); spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler1 = - new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_1); + SusHandler* susHandler1 = new SusHandler(objects::SUS_1, 1, objects::SPI_COM_IF, spiCookie, + gpioComIF, gpioIds::CS_SUS_1); spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler2 = - new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_2); + SusHandler* susHandler2 = new SusHandler(objects::SUS_2, 2, objects::SPI_COM_IF, spiCookie, + gpioComIF, gpioIds::CS_SUS_2); spiCookie = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string(q7s::SPI_DEFAULT_DEV), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler3 = - new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_3); + SusHandler* susHandler3 = new SusHandler(objects::SUS_3, 3, objects::SPI_COM_IF, spiCookie, + gpioComIF, gpioIds::CS_SUS_3); spiCookie = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string(q7s::SPI_DEFAULT_DEV), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler4 = - new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_4); + SusHandler* susHandler4 = new SusHandler(objects::SUS_4, 4, objects::SPI_COM_IF, spiCookie, + gpioComIF, gpioIds::CS_SUS_4); spiCookie = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string(q7s::SPI_DEFAULT_DEV), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler5 = - new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_5); + SusHandler* susHandler5 = new SusHandler(objects::SUS_5, 5, objects::SPI_COM_IF, spiCookie, + gpioComIF, gpioIds::CS_SUS_5); spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler6 = - new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_6); + SusHandler* susHandler6 = new SusHandler(objects::SUS_6, 6, objects::SPI_COM_IF, spiCookie, + gpioComIF, gpioIds::CS_SUS_6); spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler7 = - new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_7); + SusHandler* susHandler7 = new SusHandler(objects::SUS_7, 7, objects::SPI_COM_IF, spiCookie, + gpioComIF, gpioIds::CS_SUS_7); spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler8 = - new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_8); + SusHandler* susHandler8 = new SusHandler(objects::SUS_8, 8, objects::SPI_COM_IF, spiCookie, + gpioComIF, gpioIds::CS_SUS_8); spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler9 = - new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_9); + SusHandler* susHandler9 = new SusHandler(objects::SUS_9, 9, objects::SPI_COM_IF, spiCookie, + gpioComIF, gpioIds::CS_SUS_9); spiCookie = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler10 = new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookie, + SusHandler* susHandler10 = new SusHandler(objects::SUS_10, 10, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_10); spiCookie = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - SusHandler* susHandler11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookie, + SusHandler* susHandler11 = new SusHandler(objects::SUS_11, 11, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_11); static_cast(susHandler0); static_cast(susHandler1); From bbb07dd459efc06d9a3338ad3f97b7269f002481 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Feb 2022 13:10:39 +0100 Subject: [PATCH 16/19] sus dev handler update --- fsfw | 2 +- linux/boardtest/SpiTestClass.cpp | 4 ++-- linux/devices/SusHandler.cpp | 21 +++++++++++---------- linux/devices/SusHandler.h | 3 ++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/fsfw b/fsfw index 9e92afbf..bd05afbd 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 9e92afbf076b57df843a1ee526bd63c3303995a5 +Subproject commit bd05afbddd7e2da43b19b8ceafb6272e73d5464d diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index 60abbe67..5d0fd229 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -308,8 +308,8 @@ void SpiTestClass::performOneShotMax1227Test() { adcCfg.testSus[4].doTest = true; adcCfg.testSus[4].intConv = true; - adcCfg.testSus[1].doTest = true; - adcCfg.testSus[1].intConv = true; + adcCfg.testSus[11].doTest = true; + adcCfg.testSus[11].intConv = true; adcCfg.testSus[5].doTest = true; adcCfg.testSus[5].intConv = true; diff --git a/linux/devices/SusHandler.cpp b/linux/devices/SusHandler.cpp index bf33e4d7..7303c356 100644 --- a/linux/devices/SusHandler.cpp +++ b/linux/devices/SusHandler.cpp @@ -6,9 +6,9 @@ #include "OBSWConfig.h" -SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie, +SusHandler::SusHandler(object_id_t objectId, uint8_t susIdx, object_id_t comIF, CookieIF *comCookie, LinuxLibgpioIF *gpioComIF, gpioId_t chipSelectId) - : DeviceHandlerBase(objectId, comIF, comCookie), divider(5), dataset(this) {} + : DeviceHandlerBase(objectId, comIF, comCookie), divider(5), dataset(this), susIdx(susIdx) {} SusHandler::~SusHandler() {} @@ -228,14 +228,15 @@ void SusHandler::setToGoToNormalMode(bool enable) { this->goToNormalModeImmediat void SusHandler::printDataset() { #if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_SUS == 1 if (divider.checkAndIncrement()) { - sif::info << "SUS Object ID 0x" << std::hex << this->getObjectId() << ":" << std::endl; - sif::info << "Temperature: " << dataset.temperatureCelcius << " C" << std::endl; - sif::info << "AIN0: " << std::dec << dataset.ain0 << std::endl; - sif::info << "AIN1: " << std::dec << dataset.ain1 << std::endl; - sif::info << "AIN2: " << std::dec << dataset.ain2 << std::endl; - sif::info << "AIN3: " << std::dec << dataset.ain3 << std::endl; - sif::info << "AIN4: " << std::dec << dataset.ain4 << std::endl; - sif::info << "AIN5: " << std::dec << dataset.ain5 << std::endl; + sif::info << "SUS " << std::setw(2) << std::dec << static_cast(susIdx) << " ID " << std::hex + << this->getObjectId() << " [" << std::hex << std::setw(3); + sif::info << dataset.ain0 << ","; + sif::info << dataset.ain1 << ","; + sif::info << dataset.ain2 << ","; + sif::info << dataset.ain3 << ","; + sif::info << dataset.ain4 << ","; + sif::info << dataset.ain5 << "] "; + sif::info << "T[C] " << dataset.temperatureCelcius << " C" << std::endl; } #endif } diff --git a/linux/devices/SusHandler.h b/linux/devices/SusHandler.h index 04fd3032..4088bd0a 100644 --- a/linux/devices/SusHandler.h +++ b/linux/devices/SusHandler.h @@ -28,7 +28,7 @@ class SusHandler : public DeviceHandlerBase { static const uint8_t FIRST_WRITE = 7; - SusHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, + SusHandler(object_id_t objectId, uint8_t susIdx, object_id_t comIF, CookieIF* comCookie, LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId); virtual ~SusHandler(); @@ -79,6 +79,7 @@ class SusHandler : public DeviceHandlerBase { // externally clocked mode ClkModes clkMode = ClkModes::INT_CLOCKED; + uint8_t susIdx = 0; uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; ComStates comState = ComStates::IDLE; From a6f3b6fc830eb80b5e999f2953425523cba1d39b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Feb 2022 13:40:20 +0100 Subject: [PATCH 17/19] print event listeners --- bsp_q7s/core/CoreController.cpp | 5 +++++ fsfw | 2 +- linux/devices/SusHandler.cpp | 2 +- mission/core/GenericFactory.cpp | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index bdbd51cc..a979548b 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -1,3 +1,4 @@ +#include #include "CoreController.h" #include "OBSWConfig.h" @@ -99,6 +100,10 @@ ReturnValue_t CoreController::initializeAfterTaskCreation() { setenv("PATH", updatedEnvPath.c_str(), true); updateProtInfo(); initPrint(); + auto eventManager = ObjectManager::instance()->get(objects::EVENT_MANAGER); + if(eventManager != nullptr) { + eventManager->printListeners(); + } return result; } diff --git a/fsfw b/fsfw index bd05afbd..a12e98d9 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit bd05afbddd7e2da43b19b8ceafb6272e73d5464d +Subproject commit a12e98d9481e224a30a1150e9dfd0a48501f410f diff --git a/linux/devices/SusHandler.cpp b/linux/devices/SusHandler.cpp index 7303c356..fc2b92a1 100644 --- a/linux/devices/SusHandler.cpp +++ b/linux/devices/SusHandler.cpp @@ -229,7 +229,7 @@ void SusHandler::printDataset() { #if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_SUS == 1 if (divider.checkAndIncrement()) { sif::info << "SUS " << std::setw(2) << std::dec << static_cast(susIdx) << " ID " << std::hex - << this->getObjectId() << " [" << std::hex << std::setw(3); + << "0x" << this->getObjectId() << " [" << std::hex << std::setw(3); sif::info << dataset.ain0 << ","; sif::info << dataset.ain1 << ","; sif::info << dataset.ain2 << ","; diff --git a/mission/core/GenericFactory.cpp b/mission/core/GenericFactory.cpp index b17812e6..bc2eebad 100644 --- a/mission/core/GenericFactory.cpp +++ b/mission/core/GenericFactory.cpp @@ -79,7 +79,7 @@ void ObjectFactory::produceGenericObjects() { new Service3Housekeeping(objects::PUS_SERVICE_3_HOUSEKEEPING, apid::EIVE_OBSW, pus::PUS_SERVICE_3); new Service5EventReporting(objects::PUS_SERVICE_5_EVENT_REPORTING, apid::EIVE_OBSW, - pus::PUS_SERVICE_5, 50); + pus::PUS_SERVICE_5, 120); new Service8FunctionManagement(objects::PUS_SERVICE_8_FUNCTION_MGMT, apid::EIVE_OBSW, pus::PUS_SERVICE_8, 3, 60); new Service9TimeManagement(objects::PUS_SERVICE_9_TIME_MGMT, apid::EIVE_OBSW, pus::PUS_SERVICE_9); From 2bc717caa05f3ca597840d4ea6de345152d4e8bb Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Feb 2022 14:08:31 +0100 Subject: [PATCH 18/19] increase tm funnel queue depth --- fsfw | 2 +- mission/core/GenericFactory.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fsfw b/fsfw index a12e98d9..0d665696 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit a12e98d9481e224a30a1150e9dfd0a48501f410f +Subproject commit 0d66569687eac9fb5a1ae7eaad8a4c9fbe187b14 diff --git a/mission/core/GenericFactory.cpp b/mission/core/GenericFactory.cpp index bc2eebad..f2449271 100644 --- a/mission/core/GenericFactory.cpp +++ b/mission/core/GenericFactory.cpp @@ -69,7 +69,7 @@ void ObjectFactory::produceGenericObjects() { objects::CCSDS_PACKET_DISTRIBUTOR); // Every TM packet goes through this funnel - new TmFunnel(objects::TM_FUNNEL); + new TmFunnel(objects::TM_FUNNEL, 50); // PUS service stack new Service1TelecommandVerification(objects::PUS_SERVICE_1_VERIFICATION, apid::EIVE_OBSW, From 1e3311f63583c040cda8a8ac73a416f356b2ea41 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Feb 2022 14:52:40 +0100 Subject: [PATCH 19/19] first mq args test --- bsp_q7s/devices/startracker/StarTrackerHandler.cpp | 4 +++- fsfw | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bsp_q7s/devices/startracker/StarTrackerHandler.cpp b/bsp_q7s/devices/startracker/StarTrackerHandler.cpp index 71df6b0b..ec762551 100644 --- a/bsp_q7s/devices/startracker/StarTrackerHandler.cpp +++ b/bsp_q7s/devices/startracker/StarTrackerHandler.cpp @@ -44,7 +44,9 @@ StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF, if (strHelper == nullptr) { sif::error << "StarTrackerHandler: Invalid str image loader" << std::endl; } - eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5); + auto mqArgs = MqArgs(this->getObjectId()); + eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5, + MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs); } StarTrackerHandler::~StarTrackerHandler() {} diff --git a/fsfw b/fsfw index 0d665696..508979d3 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 0d66569687eac9fb5a1ae7eaad8a4c9fbe187b14 +Subproject commit 508979d32d4e5910259bfb52b8fe16d1bb4f1cdb