From 3c6ec68faa48f05304b24a3113c06fc8c10555d1 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 3 May 2021 13:35:16 +0200 Subject: [PATCH 01/13] rad sensor working --- mission/devices/RadiationSensorHandler.cpp | 123 +++++++++++------- .../devicedefinitions/RadSensorDefinitions.h | 8 +- 2 files changed, 81 insertions(+), 50 deletions(-) diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 8d44ea9a..bd16ddaf 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -3,12 +3,12 @@ #include RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t comIF, - CookieIF * comCookie) : - DeviceHandlerBase(objectId, comIF, comCookie), dataset( - this) { - if (comCookie == NULL) { - sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl; - } + CookieIF * comCookie) : + DeviceHandlerBase(objectId, comIF, comCookie), dataset( + this) { + if (comCookie == NULL) { + sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl; + } } RadiationSensorHandler::~RadiationSensorHandler() { @@ -30,54 +30,79 @@ void RadiationSensorHandler::doShutDown(){ } ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( - DeviceCommandId_t * id) { - *id = RAD_SENSOR::PERFORM_CONVERSION; - return buildCommandFromCommand(*id, nullptr, 0); + DeviceCommandId_t * id) { + + switch (communicationStep) { + case CommunicationStep::START_CONVERSION: { + *id = RAD_SENSOR::START_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + case CommunicationStep::READ_CONVERSIONS: { + *id = RAD_SENSOR::READ_CONVERSIONS; + communicationStep = CommunicationStep::START_CONVERSION; + break; + } + default: { + sif::debug << "RadiationSensorHandler::buildNormalDeviceCommand: Unknwon communication " + << "step" << std::endl; + return HasReturnvaluesIF::RETURN_OK; + } + } + return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand( - DeviceCommandId_t * id){ + DeviceCommandId_t * id){ if (internalState == InternalState::SETUP) { *id = RAD_SENSOR::WRITE_SETUP; } else { return HasReturnvaluesIF::RETURN_OK; } - return buildCommandFromCommand(*id, nullptr, 0); + return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( - DeviceCommandId_t deviceCommand, const uint8_t * commandData, - size_t commandDataLen) { - switch(deviceCommand) { - case(RAD_SENSOR::WRITE_SETUP): { - cmdBuffer[0] = RAD_SENSOR::SETUP_DEFINITION; - rawPacket = cmdBuffer; - rawPacketLen = 1; - internalState = InternalState::CONFIGURED; - return RETURN_OK; - } - case(RAD_SENSOR::PERFORM_CONVERSION): { - /* Dummy bytes are written to remove old values from fifo */ - cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION; - cmdBuffer[1] = RAD_SENSOR::DUMMY_BYTE; + DeviceCommandId_t deviceCommand, const uint8_t * commandData, + size_t commandDataLen) { + switch(deviceCommand) { + case(RAD_SENSOR::WRITE_SETUP): { + cmdBuffer[0] = RAD_SENSOR::SETUP_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = 1; + internalState = InternalState::CONFIGURED; + return RETURN_OK; + } + case(RAD_SENSOR::START_CONVERSION): { + /* First the fifo will be reset here */ + cmdBuffer[0] = RAD_SENSOR::RESET_DEFINITION; + cmdBuffer[1] = RAD_SENSOR::CONVERSION_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = 2; + return RETURN_OK; + } + case(RAD_SENSOR::READ_CONVERSIONS): { + cmdBuffer[0] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[1] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[2] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[3] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[4] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[5] = RAD_SENSOR::DUMMY_BYTE; - rawPacket = cmdBuffer; - rawPacketLen = RAD_SENSOR::READ_SIZE; - return RETURN_OK; - } - default: - return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; - } - return HasReturnvaluesIF::RETURN_FAILED; + rawPacket = cmdBuffer; + rawPacketLen = RAD_SENSOR::READ_SIZE; + return RETURN_OK; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; } void RadiationSensorHandler::fillCommandAndReplyMap() { this->insertInCommandMap(RAD_SENSOR::WRITE_SETUP); - this->insertInCommandAndReplyMap(RAD_SENSOR::PERFORM_CONVERSION, 1, &dataset, + this->insertInCommandMap(RAD_SENSOR::START_CONVERSION); + this->insertInCommandAndReplyMap(RAD_SENSOR::READ_CONVERSIONS, 1, &dataset, RAD_SENSOR::READ_SIZE); } @@ -90,12 +115,12 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { - switch (id) { - case RAD_SENSOR::PERFORM_CONVERSION: { - PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; - dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3)); - dataset.channel1 = (*(packet + 4) << 8 | *(packet + 5)); + switch (id) { + case RAD_SENSOR::READ_CONVERSIONS: { + PoolReadGuard readSet(&dataset); + dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; + dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3)); + dataset.channel1 = (*(packet + 4) << 8 | *(packet + 5)); #if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_RAD_SENSOR sif::info << "Radiation sensor temperature: " << dataset.temperatureCelcius << " °C" << std::endl; @@ -104,15 +129,15 @@ ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, sif::info << "Radiation sensor temperature ADC value channel 1: " << dataset.channel1 << std::endl; #endif - break; - } - default: { - sif::debug << "RadiationSensorHandler::interpretDeviceReply: Unknown reply id" << std::endl; - return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; - } + break; + } + default: { + sif::debug << "RadiationSensorHandler::interpretDeviceReply: Unknown reply id" << std::endl; + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } - } - return HasReturnvaluesIF::RETURN_OK; + } + return HasReturnvaluesIF::RETURN_OK; } void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){ @@ -120,7 +145,7 @@ void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){ } uint32_t RadiationSensorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ - return 5000; + return 5000; } ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, diff --git a/mission/devices/devicedefinitions/RadSensorDefinitions.h b/mission/devices/devicedefinitions/RadSensorDefinitions.h index c962b2e2..db105495 100644 --- a/mission/devices/devicedefinitions/RadSensorDefinitions.h +++ b/mission/devices/devicedefinitions/RadSensorDefinitions.h @@ -10,8 +10,9 @@ namespace RAD_SENSOR { * temperature sensor. */ static const DeviceCommandId_t WRITE_SETUP = 0x1; - static const DeviceCommandId_t PERFORM_CONVERSION = 0x2; + static const DeviceCommandId_t START_CONVERSION = 0x2; static const DeviceCommandId_t READ_CONVERSIONS = 0x3; + /** * @brief This is the configuration byte which will be written to the setup register after * power on. @@ -34,6 +35,11 @@ namespace RAD_SENSOR { */ static const uint8_t CONVERSION_DEFINITION = 0b10001001; + /** + * @brief Writing this value resets the fifo of the MAX1227. + */ + static const uint8_t RESET_DEFINITION = 0b00011000; + static const uint8_t DUMMY_BYTE = 0xFF; static const uint8_t RAD_SENSOR_DATA_SET_ID = READ_CONVERSIONS; From 5ce0a63ad6bd8f3c0848ed0538ce77e113556f2c Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 6 May 2021 18:00:58 +0200 Subject: [PATCH 02/13] save before implementing SusHandler with chip select --- bsp_q7s/ObjectFactory.cpp | 147 ++++++++++++------ fsfwconfig/OBSWConfig.h | 13 +- fsfwconfig/devices/spi.h | 3 +- fsfwconfig/objects/systemObjectList.h | 29 ++-- .../pollingSequenceFactory.cpp | 56 +++++-- mission/devices/SusHandler.cpp | 94 ++++++----- mission/devices/SusHandler.h | 10 +- .../devicedefinitions/SusDefinitions.h | 34 ++-- 8 files changed, 246 insertions(+), 140 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 776a3e4b..a0c6e964 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -150,6 +150,23 @@ void ObjectFactory::produce(){ /* Adding gpios for chip select decoding to the gpioComIf */ gpioCallbacks::initSpiCsDecoder(gpioComIF); + GpioCookie* gpioCookieRadSensor = new GpioCookie; + GpiodRegular* chipSelectRadSensor = new GpiodRegular(std::string("gpiochip5"), 19, + std::string("Chip Select Radiation Sensor"), gpio::OUT, 1); + gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); + gpioComIF->addGpios(gpioCookieRadSensor); + +// SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, +// std::string("/dev/spidev2.0"), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, +// spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); +// RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, +// objects::SPI_COM_IF, spiCookieRadSensor); +// (void) radSensor; +// radSensor->setStartUpImmediately(); + GpioCookie* gpioCookieSus = new GpioCookie(); GpioCallback* susgpio = new GpioCallback(std::string("Chip select SUS 1"), gpio::OUT, 1, @@ -195,47 +212,70 @@ void ObjectFactory::produce(){ gpioComIF->addGpios(gpioCookieSus); SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, - std::string("/dev/spidev2.0"), SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1); - (void) sus1; // sus1->setStartUpImmediately(); + (void) sus1; + + SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2); +// sus2->setStartUpImmediately(); + (void) sus2; + + SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3); + sus3->setStartUpImmediately(); + (void) sus3; - new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2); - new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3); new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4); new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookieSus5); new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookieSus6); new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookieSus7); - new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8); + SusHandler* sus8 = new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8); +// sus8->setStartUpImmediately(); + (void) sus8; + new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9); new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10); - new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11); + SusHandler* sus11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieRadSensor); + sus11->setStartUpImmediately(); + new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12); new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13); @@ -526,19 +566,6 @@ void ObjectFactory::produce(){ // plocHandler->setStartUpImmediately(); (void) plocHandler; - GpioCookie* gpioCookieRadSensor = new GpioCookie; - GpiodRegular* chipSelectRadSensor = new GpiodRegular(std::string("gpiochip5"), 19, - std::string("Chip Select Radiation Sensor"), gpio::OUT, 1); - gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); - gpioComIF->addGpios(gpioCookieRadSensor); - - SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, - std::string("/dev/spidev2.0"), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); - RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, - objects::SPI_COM_IF, spiCookieRadSensor); - radSensor->setStartUpImmediately(); - #endif /* TE0720 == 0 */ new UdpTmTcBridge(objects::UDP_BRIDGE, objects::CCSDS_PACKET_DISTRIBUTOR, objects::TM_STORE, @@ -552,8 +579,40 @@ void ObjectFactory::produce(){ GpioCookie* gpioCookie = new GpioCookie; gpioCookie->addGpio(gpioIds::TEST_ID_0, gpioConfigMio0); new LibgpiodTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie); -#elif TE0720 == 1 +#endif +#if TE0720 == 1 && TEST_SUS_HANDLER == 1 + GpioCookie* gpioCookieSus = new GpioCookie; + GpiodRegular* chipSelectSus = new GpiodRegular(std::string("gpiochip0"), 9, + std::string("Chip Select Sus Sensor"), gpio::OUT, 1); + gpioCookieSus->addGpio(gpioIds::CS_SUS_1, chipSelectSus); + gpioComIF->addGpios(gpioCookieSus); + + SpiCookie* spiCookieSus = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, + std::string("/dev/spidev1.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + + SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus); + sus1->setStartUpImmediately(); +#endif + +#if TE0720 == 1 && TEST_RADIATION_SENSOR_HANDLER == 1 + GpioCookie* gpioCookieRadSensor = new GpioCookie; + GpiodRegular* chipSelectRadSensor = new GpiodRegular(std::string("gpiochip0"), 9, + std::string("Chip select radiation sensor"), gpio::OUT, 1); + gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); + gpioComIF->addGpios(gpioCookieRadSensor); + + SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, + std::string("/dev/spidev1.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + + RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, + objects::SPI_COM_IF, spiCookieRadSensor); + radSensor->setStartUpImmediately(); +#endif + +#if TE0720 == 1 && TEST_PLOC_HANDLER == 1 UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyPS1"), 115200, PLOC::MAX_REPLY_SIZE); /* Testing PlocHandler on TE0720-03-1CFA */ diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index d6a059e6..ea73eb1c 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -16,12 +16,15 @@ /* These defines should be disabled for mission code but are useful for debugging. */ -#define OBSW_VERBOSE_LEVEL 1 -#define OBSW_PRINT_MISSED_DEADLINES 1 -#define OBSW_ADD_TEST_CODE 1 -#define TEST_LIBGPIOD 0 +#define OBSW_VERBOSE_LEVEL 1 +#define OBSW_PRINT_MISSED_DEADLINES 1 +#define OBSW_ADD_TEST_CODE 1 +#define TEST_LIBGPIOD 0 +#define TEST_RADIATION_SENSOR_HANDLER 0 +#define TEST_SUS_HANDLER 1 +#define TEST_PLOC_HANDLER 0 -#define TE0720 0 +#define TE0720 1 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index eb17786b..29a345d4 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -20,7 +20,8 @@ static constexpr spi::SpiModes DEFAULT_RM3100_MODE = spi::SpiModes::MODE_3; static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; -static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; +//static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 2'900'000; static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; } diff --git a/fsfwconfig/objects/systemObjectList.h b/fsfwconfig/objects/systemObjectList.h index c1f792eb..746e83cf 100644 --- a/fsfwconfig/objects/systemObjectList.h +++ b/fsfwconfig/objects/systemObjectList.h @@ -54,6 +54,21 @@ namespace objects { IMTQ_HANDLER = 0x44000014, PLOC_HANDLER = 0x44000015, + + SUS_1 = 0x44000016, + SUS_2 = 0x44000017, + SUS_3 = 0x44000018, + SUS_4 = 0x44000019, + SUS_5 = 0x4400001A, + SUS_6 = 0x4400001B, + SUS_7 = 0x4400001C, + SUS_8 = 0x4400001D, + SUS_9 = 0x4400001E, + SUS_10 = 0x4400001F, + SUS_11 = 0x44000021, + SUS_12 = 0x44000022, + SUS_13 = 0x44000023, + /* Custom device handler */ PCDU_HANDLER = 0x44001000, SOLAR_ARRAY_DEPL_HANDLER = 0x44001001, @@ -84,20 +99,6 @@ namespace objects { RAD_SENSOR = 0x54000050, - SUS_1 = 0x54000051, - SUS_2 = 0x54000052, - SUS_3 = 0x54000053, - SUS_4 = 0x54000054, - SUS_5 = 0x54000055, - SUS_6 = 0x54000056, - SUS_7 = 0x54000057, - SUS_8 = 0x54000058, - SUS_9 = 0x54000059, - SUS_10 = 0x5400005A, - SUS_11 = 0x5400005B, - SUS_12 = 0x5400005C, - SUS_13 = 0x5400005D, - /* 0x54 ('T') for test handlers */ TEST_TASK = 0x54694269, LIBGPIOD_TEST = 0x54123456, diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 31b56865..5667ef12 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -144,11 +144,11 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) /* Radiation sensor */ - thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); +// thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); /* Sun sensor 1 */ thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); @@ -157,6 +157,18 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_1, length * 0.8, 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); + +// thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_11, length * 0.2, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_11, length * 0.4, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_11, length * 0.6, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_11, length * 0.8, DeviceHandlerIF::GET_READ); + if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; } @@ -340,16 +352,30 @@ ReturnValue_t pst::pollingSequenceAcsTest(FixedTimeslotTaskIF *thisSequence) { ReturnValue_t pst::pollingSequenceTE0720(FixedTimeslotTaskIF *thisSequence) { uint32_t length = thisSequence->getPeriodMs(); - thisSequence->addSlot(objects::PLOC_HANDLER, length * 0, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.2, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.4, - DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.6, - DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.8, - DeviceHandlerIF::GET_READ); +#if TEST_PLOC_HANDLER == 1 + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); +#endif + +#if TEST_SUS_HANDLER == 1 + thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); +#endif + +#if TEST_RADIATION_SENSOR_HANDLER == 1 + thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); +#endif + if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { sif::error << "Initialization of TE0720 PST failed" << std::endl; diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 3339ff26..d4b91650 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) : @@ -31,26 +32,16 @@ void SusHandler::doShutDown(){ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { - - switch (communicationStep) { - case CommunicationStep::START_CONVERSION: { - *id = SUS::START_CONVERSION; - communicationStep = CommunicationStep::READ_CONVERSIONS; - break; + if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { + *id = SUS::PERFORM_CONVERSIONS; +// communicationStep = CommunicationStep::READ_TEMP; + communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } - case CommunicationStep::READ_CONVERSIONS: { - *id = SUS::READ_CONVERSIONS; -// communicationStep = CommunicationStep::START_CONVERSION; - communicationStep = CommunicationStep::READ_CONVERSIONS; - break; + else if (communicationStep == CommunicationStep::READ_TEMP) { + *id = SUS::READ_TEMP; + communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } - default: { - sif::debug << "SusHandler::buildNormalDeviceCommand: Unknwon communication " - << "step" << std::endl; - return HasReturnvaluesIF::RETURN_OK; - } - } - return buildCommandFromCommand(*id, nullptr, 0); + return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t SusHandler::buildTransitionDeviceCommand( @@ -76,24 +67,44 @@ ReturnValue_t SusHandler::buildCommandFromCommand( internalState = InternalState::CONFIGURED; return RETURN_OK; } - case(SUS::START_CONVERSION): { - cmdBuffer[0] = SUS::CONVERSION_DEFINITION; + case(SUS::PERFORM_CONVERSIONS): { + std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); + /** + * The sun sensor ADC is shutdown when CS is pulled high so each time requesting a + * measurement the setup has to be rewritten + */ + cmdBuffer[0] = SUS::SETUP_DEFINITION; + cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; + // wirte one dummy byte here +// cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; + cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; +// struct timeval startOfDelay; +// gettimeofday(&startOfDelay, NULL); +// struct timeval currentTime; +// gettimeofday(¤tTime, NULL); +// while (currentTime.tv_usec - startOfDelay.tv_usec < 1000) { +// gettimeofday(¤tTime, NULL); +// } + +// cmdBuffer[27] = SUS::CONVERT_DIFF_CHANNEL_0_1; +// cmdBuffer[29] = SUS::CONVERT_DIFF_CHANNEL_2_3; +// cmdBuffer[31] = SUS::CONVERT_DIFF_CHANNEL_4_5; + +// cmdBuffer[0] = SUS::SETUP_DEFINITION; +// cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; +// cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; +// cmdBuffer[26] = SUS::CONVERT_DIFF_CHANNEL_0_1; +// cmdBuffer[28] = SUS::CONVERT_DIFF_CHANNEL_2_3; +// cmdBuffer[30] = SUS::CONVERT_DIFF_CHANNEL_4_5; rawPacket = cmdBuffer; - rawPacketLen = 1; +// rawPacketLen = SUS::SIZE_PERFORM_CONVERSIONS; + rawPacketLen = 7; return RETURN_OK; } - case(SUS::READ_CONVERSIONS): { - cmdBuffer[0] = SUS::DUMMY_BYTE; - cmdBuffer[1] = SUS::DUMMY_BYTE; - cmdBuffer[2] = SUS::DUMMY_BYTE; - cmdBuffer[3] = SUS::DUMMY_BYTE; - cmdBuffer[4] = SUS::DUMMY_BYTE; - cmdBuffer[5] = SUS::DUMMY_BYTE; - cmdBuffer[6] = SUS::DUMMY_BYTE; - cmdBuffer[7] = SUS::DUMMY_BYTE; - cmdBuffer[8] = SUS::DUMMY_BYTE; - rawPacket = cmdBuffer; - rawPacketLen = SUS::READ_SIZE; + case(SUS::READ_TEMP): { + std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); + rawPacket = cmdBuffer; + rawPacketLen = 26; return RETURN_OK; } default: @@ -104,9 +115,10 @@ ReturnValue_t SusHandler::buildCommandFromCommand( void SusHandler::fillCommandAndReplyMap() { this->insertInCommandMap(SUS::WRITE_SETUP); - this->insertInCommandMap(SUS::START_CONVERSION); - this->insertInCommandAndReplyMap(SUS::READ_CONVERSIONS, 1, &dataset, - SUS::READ_SIZE); + this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); +// this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, +// SUS::SIZE_PERFORM_CONVERSIONS); + this->insertInCommandMap(SUS::PERFORM_CONVERSIONS); } ReturnValue_t SusHandler::scanForReply(const uint8_t *start, @@ -119,12 +131,12 @@ ReturnValue_t SusHandler::scanForReply(const uint8_t *start, ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { - case SUS::READ_CONVERSIONS: { + case SUS::PERFORM_CONVERSIONS: { PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; - dataset.diffScanChannel0_1 = (*(packet + 2) << 8 | *(packet + 3)); - dataset.diffScanChannel2_3 = (*(packet + 2) << 8 | *(packet + 3)); - dataset.diffScanChannel4_5 = (*(packet + 2) << 8 | *(packet + 3)); + dataset.temperatureCelcius = (*(packet + 25) << 8 | *(packet + 26)) * 0.125; + dataset.diffScanChannel0_1 = (*(packet + 29) << 8 | *(packet + 30)); + dataset.diffScanChannel2_3 = (*(packet + 31) << 8 | *(packet + 32)); + dataset.diffScanChannel4_5 = (*(packet + 33) << 8 | *(packet + 34)); #if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", temperature: " << dataset.temperatureCelcius << " °C" << std::endl; diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 445722a8..2780556f 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -40,8 +40,8 @@ protected: private: enum class CommunicationStep { - START_CONVERSION, - READ_CONVERSIONS + PERFORM_CONVERSIONS, + READ_TEMP }; enum class InternalState { @@ -51,11 +51,9 @@ private: SUS::SusDataset dataset; - static const uint8_t MAX_CMD_LEN = SUS::READ_SIZE; - - uint8_t cmdBuffer[MAX_CMD_LEN]; + uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; InternalState internalState = InternalState::SETUP; - CommunicationStep communicationStep = CommunicationStep::START_CONVERSION; + CommunicationStep communicationStep = CommunicationStep::PERFORM_CONVERSIONS; }; #endif /* MISSION_DEVICES_SUSHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index efc56959..98ea7589 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -10,8 +10,8 @@ namespace SUS { * temperature sensor. */ static const DeviceCommandId_t WRITE_SETUP = 0x1; - static const DeviceCommandId_t START_CONVERSION = 0x2; - static const DeviceCommandId_t READ_CONVERSIONS = 0x3; + static const DeviceCommandId_t PERFORM_CONVERSIONS = 0x2; + static const DeviceCommandId_t READ_TEMP = 0x3; /** * @brief This is the configuration byte which will be written to the setup register after @@ -19,12 +19,15 @@ namespace SUS { * * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b10, following byte will be written to the * unipolar register to perform differential conversion - * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b11, external reference differential (AIN6 is REF-) - * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, MAX1227 uses internal oscillator for timing + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference differential (AIN6 is REF-) + * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b11, MAX1227 clocked through SPI SCLK * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register * */ - static const uint8_t SETUP_DEFINITION = 0b01101110; +// static const uint8_t SETUP_DEFINITION = 0b0111110; + + // Internal reference 0b10 + static const uint8_t SETUP_DEFINITION = 0b0111010; /** * @brief This byte will be written to the unipolar register @@ -38,21 +41,24 @@ namespace SUS { * @brief This value will always be written to the ADC conversion register to specify the * conversions to perform. * @details Bit0: 1 - Enables temperature conversion - * Bit2 (SCAN1) and Bit1 (SCAN0): 0b00 (channel conversion from 0 to N) + * Bit2 (SCAN1) and Bit1 (SCAN0): 0b11, No scan, converts channel N once only. + * Scanning is not supported in spi clock mode. * Bit6 - Bit3 defines N: 0b0001 (N = 4) * Bit7: Always 1. Tells the ADC that this is the conversion register. */ - static const uint8_t CONVERSION_DEFINITION = 0b10100001; +// static const uint8_t CONVERT_TEMPERATURE = 0b10000111; + static const uint8_t CONVERT_TEMPERATURE = 0b10000110; + static const uint8_t CONVERT_DIFF_CHANNEL_0_1 = 0b10000110; + static const uint8_t CONVERT_DIFF_CHANNEL_2_3 = 0b10010110; + static const uint8_t CONVERT_DIFF_CHANNEL_4_5 = 0b10100110; - static const uint8_t DUMMY_BYTE = 0xFF; + static const uint8_t DUMMY_BYTE = 0x0; - static const uint8_t SUS_DATA_SET_ID = READ_CONVERSIONS; + static const uint8_t SUS_DATA_SET_ID = PERFORM_CONVERSIONS; - /** - * One temperature value, one differential conversion for channels 0/1, one for channels 2/3 and - * one for channels 3/4 - */ - static const uint8_t READ_SIZE = 8; + static const uint8_t SIZE_PERFORM_CONVERSIONS = 34; + + static const uint8_t MAX_CMD_SIZE = SIZE_PERFORM_CONVERSIONS; enum Max1227PoolIds: lp_id_t { TEMPERATURE_C, From 1eb99093774b9dfbb156f441a0af71a88ad57575 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Fri, 7 May 2021 18:48:42 +0200 Subject: [PATCH 03/13] save before making change in spicomif --- bsp_q7s/ObjectFactory.cpp | 59 +++++++----- bsp_q7s/gpio/gpioCallbacks.cpp | 93 ++++++++++--------- bsp_q7s/gpio/gpioCallbacks.h | 9 +- fsfwconfig/OBSWConfig.h | 2 +- fsfwconfig/devices/spi.h | 4 +- .../pollingSequenceFactory.cpp | 20 ++-- mission/devices/SusHandler.cpp | 44 +++++---- mission/devices/SusHandler.h | 7 +- .../devicedefinitions/SusDefinitions.h | 24 ++--- 9 files changed, 142 insertions(+), 120 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index a0c6e964..6af5921b 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -156,16 +156,12 @@ void ObjectFactory::produce(){ gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); gpioComIF->addGpios(gpioCookieRadSensor); -// SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, -// std::string("/dev/spidev2.0"), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, -// spi::DEFAULT_MAX_1227_SPEED); SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, - std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + std::string("/dev/spidev2.0"), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); -// RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, -// objects::SPI_COM_IF, spiCookieRadSensor); -// (void) radSensor; -// radSensor->setStartUpImmediately(); + RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, + objects::SPI_COM_IF, spiCookieRadSensor); + (void) radSensor; GpioCookie* gpioCookieSus = new GpioCookie(); @@ -251,33 +247,45 @@ void ObjectFactory::produce(){ std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1); + SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, + gpioIds::CS_SUS_1); // sus1->setStartUpImmediately(); (void) sus1; - SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2); -// sus2->setStartUpImmediately(); + SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2, gpioComIF, + gpioIds::CS_SUS_2); + sus2->setStartUpImmediately(); (void) sus2; - SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3); + SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3, gpioComIF, + gpioIds::CS_SUS_3); sus3->setStartUpImmediately(); (void) sus3; - new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4); - new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookieSus5); - new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookieSus6); - new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookieSus7); - SusHandler* sus8 = new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8); -// sus8->setStartUpImmediately(); - (void) sus8; + new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4, gpioComIF, + gpioIds::CS_SUS_4); + new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookieSus5, gpioComIF, + gpioIds::CS_SUS_5); + new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookieSus6, gpioComIF, + gpioIds::CS_SUS_6); + new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookieSus7, gpioComIF, + gpioIds::CS_SUS_7); + SusHandler* sus8 = new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8, gpioComIF, + gpioIds::CS_SUS_8); + sus8->setStartUpImmediately(); - new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9); - new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10); - SusHandler* sus11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieRadSensor); + new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9, gpioComIF, + gpioIds::CS_SUS_9); + new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10, gpioComIF, + gpioIds::CS_SUS_10); + SusHandler* sus11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11, + gpioComIF, gpioIds::CS_SUS_11); sus11->setStartUpImmediately(); - new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12); - new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13); + new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12, gpioComIF, + gpioIds::CS_SUS_12); + new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13, gpioComIF, + gpioIds::CS_SUS_13); #if OBSW_ADD_ACS_BOARD == 1 GpioCookie* gpioCookieAcsBoard = new GpioCookie(); @@ -592,7 +600,8 @@ void ObjectFactory::produce(){ std::string("/dev/spidev1.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus); + SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus, gpioComIF, + gpioIds::CS_SUS_1); sus1->setStartUpImmediately(); #endif diff --git a/bsp_q7s/gpio/gpioCallbacks.cpp b/bsp_q7s/gpio/gpioCallbacks.cpp index a40f6ba4..2f59cb0e 100644 --- a/bsp_q7s/gpio/gpioCallbacks.cpp +++ b/bsp_q7s/gpio/gpioCallbacks.cpp @@ -58,19 +58,18 @@ void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value void* args) { if (gpioComInterface == nullptr) { - sif::debug << "tcsBoardDecoderCallback: No gpioComIF specified. Call initTcsBoardDecoder " + sif::debug << "spiCsDecoderCallback: No gpioComIF specified. Call initSpiCsDecoder " << "to specify gpioComIF" << std::endl; return; } - /* Read is not supported by the callback function */ + /* Reading is not supported by the callback function */ if (gpioOp == gpio::GpioOperation::READ) { return; } if (value == 1) { - /* This will pull all 16 decoder outputs to high */ - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); + disableAllDecoder(); } else if (value == 0) { switch (gpioId) { @@ -155,70 +154,70 @@ void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value break; } case(gpioIds::CS_SUS_1): { - enableDecoderInterfaceBoardIc21(); + enableDecoderInterfaceBoardIc1(); selectY0(); break; } case(gpioIds::CS_SUS_2): { - enableDecoderInterfaceBoardIc21(); + enableDecoderInterfaceBoardIc1(); selectY1(); break; } case(gpioIds::CS_SUS_3): { - enableDecoderInterfaceBoardIc21(); - selectY2(); - break; - } - case(gpioIds::CS_SUS_4): { - enableDecoderInterfaceBoardIc21(); - selectY3(); - break; - } - case(gpioIds::CS_SUS_5): { - enableDecoderInterfaceBoardIc21(); - selectY4(); - break; - } - case(gpioIds::CS_SUS_6): { - enableDecoderInterfaceBoardIc21(); - selectY5(); - break; - } - case(gpioIds::CS_SUS_7): { - enableDecoderInterfaceBoardIc21(); - selectY6(); - break; - } - case(gpioIds::CS_SUS_8): { - enableDecoderInterfaceBoardIc22(); + enableDecoderInterfaceBoardIc2(); selectY0(); break; } - case(gpioIds::CS_SUS_9): { - enableDecoderInterfaceBoardIc22(); + case(gpioIds::CS_SUS_4): { + enableDecoderInterfaceBoardIc2(); selectY1(); break; } - case(gpioIds::CS_SUS_10): { - enableDecoderInterfaceBoardIc22(); + case(gpioIds::CS_SUS_5): { + enableDecoderInterfaceBoardIc2(); selectY2(); break; } - case(gpioIds::CS_SUS_11): { - enableDecoderInterfaceBoardIc22(); + case(gpioIds::CS_SUS_6): { + enableDecoderInterfaceBoardIc1(); + selectY2(); + break; + } + case(gpioIds::CS_SUS_7): { + enableDecoderInterfaceBoardIc1(); selectY3(); break; } - case(gpioIds::CS_SUS_12): { - enableDecoderInterfaceBoardIc22(); + case(gpioIds::CS_SUS_8): { + enableDecoderInterfaceBoardIc2(); + selectY3(); + break; + } + case(gpioIds::CS_SUS_9): { + enableDecoderInterfaceBoardIc1(); selectY4(); break; } - case(gpioIds::CS_SUS_13): { - enableDecoderInterfaceBoardIc22(); + case(gpioIds::CS_SUS_10): { + enableDecoderInterfaceBoardIc1(); selectY5(); break; } + case(gpioIds::CS_SUS_11): { + enableDecoderInterfaceBoardIc2(); + selectY4(); + break; + } + case(gpioIds::CS_SUS_12): { + enableDecoderInterfaceBoardIc2(); + selectY5(); + break; + } + case(gpioIds::CS_SUS_13): { + enableDecoderInterfaceBoardIc1(); + selectY6(); + break; + } default: sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl; } @@ -240,13 +239,13 @@ void enableDecoderTcsIc2() { gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); } -void enableDecoderInterfaceBoardIc21() { +void enableDecoderInterfaceBoardIc1() { gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); } -void enableDecoderInterfaceBoardIc22() { +void enableDecoderInterfaceBoardIc2() { gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); @@ -300,4 +299,10 @@ void selectY7() { gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); } +void disableAllDecoder() { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); +} + } diff --git a/bsp_q7s/gpio/gpioCallbacks.h b/bsp_q7s/gpio/gpioCallbacks.h index 67ae4dc2..4a0c73cb 100644 --- a/bsp_q7s/gpio/gpioCallbacks.h +++ b/bsp_q7s/gpio/gpioCallbacks.h @@ -35,13 +35,18 @@ namespace gpioCallbacks { * @brief This function sets mux bits 1-3 to a state which will only enable the decoder * on the inteface board board which is named to IC21 in the schematic. */ - void enableDecoderInterfaceBoardIc21(); + void enableDecoderInterfaceBoardIc1(); /** * @brief This function sets mux bits 1-3 to a state which will only enable the decoder * on the inteface board board which is named to IC22 in the schematic. */ - void enableDecoderInterfaceBoardIc22(); + void enableDecoderInterfaceBoardIc2(); + + /** + * @brief This function disables all decoder. + */ + void disableAllDecoder(); /** The following functions enable the appropriate channel of the currently enabled decoder */ void selectY0(); diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index ea73eb1c..5db2e7d0 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -24,7 +24,7 @@ debugging. */ #define TEST_SUS_HANDLER 1 #define TEST_PLOC_HANDLER 0 -#define TE0720 1 +#define TE0720 0 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index 29a345d4..9558fb89 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -21,8 +21,8 @@ static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; //static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; -static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 2'900'000; -static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 1'000'000; +static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0; } diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 5667ef12..76571fc9 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -151,17 +151,17 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) // thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); /* Sun sensor 1 */ - thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); +// thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_1, length * 0.8, 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); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.8, DeviceHandlerIF::GET_READ); // thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_11, length * 0.2, DeviceHandlerIF::SEND_WRITE); diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index d4b91650..2ebe1858 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -1,15 +1,14 @@ #include #include #include -#include -SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, - CookieIF * comCookie) : - DeviceHandlerBase(objectId, comIF, comCookie), dataset( - this) { - if (comCookie == NULL) { - sif::error << "SusHandler: Invalid com cookie" << std::endl; - } +SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie, + LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId) : + DeviceHandlerBase(objectId, comIF, comCookie), gpioComIF(gpioComIF), chipSelectId( + chipSelectId), dataset(this) { + if (comCookie == NULL) { + sif::error << "SusHandler: Invalid com cookie" << std::endl; + } } SusHandler::~SusHandler() { @@ -34,8 +33,8 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { *id = SUS::PERFORM_CONVERSIONS; -// communicationStep = CommunicationStep::READ_TEMP; - communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + communicationStep = CommunicationStep::READ_TEMP; +// communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } else if (communicationStep == CommunicationStep::READ_TEMP) { *id = SUS::READ_TEMP; @@ -61,23 +60,23 @@ ReturnValue_t SusHandler::buildCommandFromCommand( switch(deviceCommand) { case(SUS::WRITE_SETUP): { cmdBuffer[0] = SUS::SETUP_DEFINITION; - cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; rawPacket = cmdBuffer; - rawPacketLen = 2; + rawPacketLen = 0; internalState = InternalState::CONFIGURED; return RETURN_OK; } case(SUS::PERFORM_CONVERSIONS): { + gpioComIF->pullLow(chipSelectId); std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); /** * The sun sensor ADC is shutdown when CS is pulled high so each time requesting a * measurement the setup has to be rewritten */ - cmdBuffer[0] = SUS::SETUP_DEFINITION; - cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; + cmdBuffer[0] = SUS::RESET_FIFO; + cmdBuffer[1] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; + cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_0_1; // struct timeval startOfDelay; // gettimeofday(&startOfDelay, NULL); // struct timeval currentTime; @@ -98,13 +97,16 @@ ReturnValue_t SusHandler::buildCommandFromCommand( // cmdBuffer[30] = SUS::CONVERT_DIFF_CHANNEL_4_5; rawPacket = cmdBuffer; // rawPacketLen = SUS::SIZE_PERFORM_CONVERSIONS; - rawPacketLen = 7; + rawPacketLen = 5; return RETURN_OK; } case(SUS::READ_TEMP): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); + cmdBuffer[0] = SUS::RESET_FIFO; + cmdBuffer[1] = SUS::SETUP_DEFINITION; + cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; rawPacket = cmdBuffer; - rawPacketLen = 26; + rawPacketLen = 27; return RETURN_OK; } default: @@ -115,7 +117,9 @@ ReturnValue_t SusHandler::buildCommandFromCommand( void SusHandler::fillCommandAndReplyMap() { this->insertInCommandMap(SUS::WRITE_SETUP); - this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); +// this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); + this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); + this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, nullptr, SUS::SIZE_PERFORM_CONVERSIONS); // this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, // SUS::SIZE_PERFORM_CONVERSIONS); this->insertInCommandMap(SUS::PERFORM_CONVERSIONS); @@ -149,6 +153,10 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, #endif break; } + case SUS::READ_TEMP: { + gpioComIF->pullHigh(chipSelectId); + break; + } default: { sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl; return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 2780556f..e5cc68ae 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -3,6 +3,7 @@ #include #include +#include /** * @brief This is the device handler class for the SUS sensor. The sensor is @@ -17,7 +18,7 @@ class SusHandler: public DeviceHandlerBase { public: SusHandler(object_id_t objectId, object_id_t comIF, - CookieIF * comCookie); + CookieIF * comCookie, LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId); virtual ~SusHandler(); protected: @@ -49,6 +50,10 @@ private: CONFIGURED }; + LinuxLibgpioIF* gpioComIF = nullptr; + + gpioId_t chipSelectId = gpio::NO_GPIO; + SUS::SusDataset dataset; uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 98ea7589..1b3cbe70 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -17,25 +17,13 @@ namespace SUS { * @brief This is the configuration byte which will be written to the setup register after * power on. * - * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b10, following byte will be written to the - * unipolar register to perform differential conversion - * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference differential (AIN6 is REF-) + * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, No byte is following the setup byte + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b00, internal reference, needs wake-up delay * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b11, MAX1227 clocked through SPI SCLK * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register * */ -// static const uint8_t SETUP_DEFINITION = 0b0111110; - - // Internal reference 0b10 - static const uint8_t SETUP_DEFINITION = 0b0111010; - - /** - * @brief This byte will be written to the unipolar register - * - * @details Setting bits 7 - 5 to will configure channels 0/1, 2/3 and 4/5 as differential - * pairs. - */ - static const uint8_t UNIPOLAR_CONFIG = 0b11100000; + static const uint8_t SETUP_DEFINITION = 0b01110000; /** * @brief This value will always be written to the ADC conversion register to specify the @@ -46,12 +34,13 @@ namespace SUS { * Bit6 - Bit3 defines N: 0b0001 (N = 4) * Bit7: Always 1. Tells the ADC that this is the conversion register. */ -// static const uint8_t CONVERT_TEMPERATURE = 0b10000111; - static const uint8_t CONVERT_TEMPERATURE = 0b10000110; + static const uint8_t CONVERT_TEMPERATURE = 0b10000001; static const uint8_t CONVERT_DIFF_CHANNEL_0_1 = 0b10000110; static const uint8_t CONVERT_DIFF_CHANNEL_2_3 = 0b10010110; static const uint8_t CONVERT_DIFF_CHANNEL_4_5 = 0b10100110; + static const uint8_t RESET_FIFO = 0b00011000; + static const uint8_t DUMMY_BYTE = 0x0; static const uint8_t SUS_DATA_SET_ID = PERFORM_CONVERSIONS; @@ -60,6 +49,7 @@ namespace SUS { static const uint8_t MAX_CMD_SIZE = SIZE_PERFORM_CONVERSIONS; + enum Max1227PoolIds: lp_id_t { TEMPERATURE_C, DIFF_SCAN_CHANNEL_0_1, From be29d0e71fdacb673ffbd56529f9dc62ffd7c44f Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sat, 8 May 2021 22:49:21 +0200 Subject: [PATCH 04/13] some tries to get data from max1227 in externally clocked mode --- bsp_q7s/ObjectFactory.cpp | 2 +- fsfwconfig/OBSWConfig.h | 2 +- fsfwconfig/devices/spi.h | 2 +- mission/devices/SusHandler.cpp | 41 ++++++++++--------- mission/devices/SusHandler.h | 1 + .../devicedefinitions/SusDefinitions.h | 9 ++-- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 6af5921b..5dae58db 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -228,7 +228,7 @@ void ObjectFactory::produce(){ SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, + SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 5db2e7d0..ea73eb1c 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -24,7 +24,7 @@ debugging. */ #define TEST_SUS_HANDLER 1 #define TEST_PLOC_HANDLER 0 -#define TE0720 0 +#define TE0720 1 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index 9558fb89..18b91c6f 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -21,7 +21,7 @@ static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; //static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; -static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 1'000'000; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 1000000; static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0; } diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 2ebe1858..0469f60c 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -33,9 +33,13 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { *id = SUS::PERFORM_CONVERSIONS; - communicationStep = CommunicationStep::READ_TEMP; + communicationStep = CommunicationStep::REQUEST_TEMP; // communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } + else if (communicationStep == CommunicationStep::REQUEST_TEMP) { + *id = SUS::RQUEST_TEMP; + communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + } else if (communicationStep == CommunicationStep::READ_TEMP) { *id = SUS::READ_TEMP; communicationStep = CommunicationStep::PERFORM_CONVERSIONS; @@ -66,7 +70,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( return RETURN_OK; } case(SUS::PERFORM_CONVERSIONS): { - gpioComIF->pullLow(chipSelectId); +// gpioComIF->pullLow(chipSelectId); std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); /** * The sun sensor ADC is shutdown when CS is pulled high so each time requesting a @@ -76,18 +80,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( cmdBuffer[1] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_0_1; -// struct timeval startOfDelay; -// gettimeofday(&startOfDelay, NULL); -// struct timeval currentTime; -// gettimeofday(¤tTime, NULL); -// while (currentTime.tv_usec - startOfDelay.tv_usec < 1000) { -// gettimeofday(¤tTime, NULL); -// } - -// cmdBuffer[27] = SUS::CONVERT_DIFF_CHANNEL_0_1; -// cmdBuffer[29] = SUS::CONVERT_DIFF_CHANNEL_2_3; -// cmdBuffer[31] = SUS::CONVERT_DIFF_CHANNEL_4_5; + cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_2; // cmdBuffer[0] = SUS::SETUP_DEFINITION; // cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; @@ -100,13 +93,20 @@ ReturnValue_t SusHandler::buildCommandFromCommand( rawPacketLen = 5; return RETURN_OK; } + case(SUS::RQUEST_TEMP): { +// gpioComIF->pullLow(chipSelectId); + std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); +// cmdBuffer[0] = SUS::RESET_FIFO; +// cmdBuffer[1] = SUS::SETUP_DEFINITION; + cmdBuffer[0] = SUS::CONVERT_TEMPERATURE; + rawPacket = cmdBuffer; + rawPacketLen = 25; + return RETURN_OK; + } case(SUS::READ_TEMP): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - cmdBuffer[0] = SUS::RESET_FIFO; - cmdBuffer[1] = SUS::SETUP_DEFINITION; - cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; rawPacket = cmdBuffer; - rawPacketLen = 27; + rawPacketLen = 0; return RETURN_OK; } default: @@ -122,7 +122,7 @@ void SusHandler::fillCommandAndReplyMap() { this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, nullptr, SUS::SIZE_PERFORM_CONVERSIONS); // this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, // SUS::SIZE_PERFORM_CONVERSIONS); - this->insertInCommandMap(SUS::PERFORM_CONVERSIONS); + this->insertInCommandMap(SUS::RQUEST_TEMP); } ReturnValue_t SusHandler::scanForReply(const uint8_t *start, @@ -136,6 +136,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { case SUS::PERFORM_CONVERSIONS: { +// gpioComIF->pullHigh(chipSelectId); PoolReadGuard readSet(&dataset); dataset.temperatureCelcius = (*(packet + 25) << 8 | *(packet + 26)) * 0.125; dataset.diffScanChannel0_1 = (*(packet + 29) << 8 | *(packet + 30)); @@ -154,7 +155,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, break; } case SUS::READ_TEMP: { - gpioComIF->pullHigh(chipSelectId); +// gpioComIF->pullHigh(chipSelectId); break; } default: { diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index e5cc68ae..2fb2a6a8 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -42,6 +42,7 @@ private: enum class CommunicationStep { PERFORM_CONVERSIONS, + REQUEST_TEMP, READ_TEMP }; diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 1b3cbe70..6e795775 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -12,6 +12,7 @@ namespace SUS { static const DeviceCommandId_t WRITE_SETUP = 0x1; static const DeviceCommandId_t PERFORM_CONVERSIONS = 0x2; static const DeviceCommandId_t READ_TEMP = 0x3; + static const DeviceCommandId_t RQUEST_TEMP = 0x4; /** * @brief This is the configuration byte which will be written to the setup register after @@ -35,9 +36,11 @@ namespace SUS { * Bit7: Always 1. Tells the ADC that this is the conversion register. */ static const uint8_t CONVERT_TEMPERATURE = 0b10000001; - static const uint8_t CONVERT_DIFF_CHANNEL_0_1 = 0b10000110; - static const uint8_t CONVERT_DIFF_CHANNEL_2_3 = 0b10010110; - static const uint8_t CONVERT_DIFF_CHANNEL_4_5 = 0b10100110; + static const uint8_t CONVERT_DIFF_CHANNEL_0 = 0b10000110; + static const uint8_t CONVERT_DIFF_CHANNEL_1 = 0b10001110; + static const uint8_t CONVERT_DIFF_CHANNEL_2 = 0b10010110; + static const uint8_t CONVERT_DIFF_CHANNEL_3 = 0b10011110; + static const uint8_t CONVERT_DIFF_CHANNEL_4 = 0b10100110; static const uint8_t RESET_FIFO = 0b00011000; From eeb8167cdc937749b769132727828d189680fb9f Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 10:06:36 +0200 Subject: [PATCH 05/13] this worked with the prototype SUS --- mission/devices/SusHandler.cpp | 10 +++++----- mission/devices/devicedefinitions/SusDefinitions.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 0469f60c..15062148 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -38,7 +38,7 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( } else if (communicationStep == CommunicationStep::REQUEST_TEMP) { *id = SUS::RQUEST_TEMP; - communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + communicationStep = CommunicationStep::READ_TEMP; } else if (communicationStep == CommunicationStep::READ_TEMP) { *id = SUS::READ_TEMP; @@ -65,7 +65,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( case(SUS::WRITE_SETUP): { cmdBuffer[0] = SUS::SETUP_DEFINITION; rawPacket = cmdBuffer; - rawPacketLen = 0; + rawPacketLen = 1; internalState = InternalState::CONFIGURED; return RETURN_OK; } @@ -80,7 +80,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( cmdBuffer[1] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_2; + cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; // cmdBuffer[0] = SUS::SETUP_DEFINITION; // cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; @@ -100,13 +100,13 @@ ReturnValue_t SusHandler::buildCommandFromCommand( // cmdBuffer[1] = SUS::SETUP_DEFINITION; cmdBuffer[0] = SUS::CONVERT_TEMPERATURE; rawPacket = cmdBuffer; - rawPacketLen = 25; + rawPacketLen = 1; return RETURN_OK; } case(SUS::READ_TEMP): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); rawPacket = cmdBuffer; - rawPacketLen = 0; + rawPacketLen = 24; return RETURN_OK; } default: diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 6e795775..438d761d 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -24,7 +24,7 @@ namespace SUS { * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register * */ - static const uint8_t SETUP_DEFINITION = 0b01110000; + static const uint8_t SETUP_DEFINITION = 0b01111000; /** * @brief This value will always be written to the ADC conversion register to specify the From 950eab2373e83689fa22caa139b6594e9d60f1b7 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 12:09:39 +0200 Subject: [PATCH 06/13] this works with the old SUS --- fsfwconfig/OBSWConfig.h | 2 +- mission/devices/SusHandler.cpp | 18 ++++++++++++------ mission/devices/SusHandler.h | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index ea73eb1c..5db2e7d0 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -24,7 +24,7 @@ debugging. */ #define TEST_SUS_HANDLER 1 #define TEST_PLOC_HANDLER 0 -#define TE0720 1 +#define TE0720 0 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 15062148..b351ff43 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -31,9 +31,14 @@ void SusHandler::doShutDown(){ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { - if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { - *id = SUS::PERFORM_CONVERSIONS; + if (communicationStep == CommunicationStep::WRITE_SETUP) { + *id = SUS::WRITE_SETUP; communicationStep = CommunicationStep::REQUEST_TEMP; +// communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + } + else if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { + *id = SUS::PERFORM_CONVERSIONS; + communicationStep = CommunicationStep::WRITE_SETUP; // communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } else if (communicationStep == CommunicationStep::REQUEST_TEMP) { @@ -63,6 +68,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( size_t commandDataLen) { switch(deviceCommand) { case(SUS::WRITE_SETUP): { + gpioComIF->pullLow(chipSelectId); cmdBuffer[0] = SUS::SETUP_DEFINITION; rawPacket = cmdBuffer; rawPacketLen = 1; @@ -76,11 +82,11 @@ ReturnValue_t SusHandler::buildCommandFromCommand( * The sun sensor ADC is shutdown when CS is pulled high so each time requesting a * measurement the setup has to be rewritten */ - cmdBuffer[0] = SUS::RESET_FIFO; - cmdBuffer[1] = SUS::SETUP_DEFINITION; +// cmdBuffer[0] = SUS::RESET_FIFO; +// cmdBuffer[1] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; + cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_1; // cmdBuffer[0] = SUS::SETUP_DEFINITION; // cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; @@ -90,7 +96,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( // cmdBuffer[30] = SUS::CONVERT_DIFF_CHANNEL_4_5; rawPacket = cmdBuffer; // rawPacketLen = SUS::SIZE_PERFORM_CONVERSIONS; - rawPacketLen = 5; + rawPacketLen = 3; return RETURN_OK; } case(SUS::RQUEST_TEMP): { diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 2fb2a6a8..aabecac1 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -43,7 +43,8 @@ private: enum class CommunicationStep { PERFORM_CONVERSIONS, REQUEST_TEMP, - READ_TEMP + READ_TEMP, + WRITE_SETUP }; enum class InternalState { From 98387a6d24eb4684290d2781c6fc4cddd952b8fd Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 14:39:56 +0200 Subject: [PATCH 07/13] this works with q7s and new sus --- mission/devices/SusHandler.cpp | 19 +++++++++++++++---- mission/devices/SusHandler.h | 2 +- .../devicedefinitions/SusDefinitions.h | 3 ++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index b351ff43..25c01c87 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -86,8 +86,19 @@ ReturnValue_t SusHandler::buildCommandFromCommand( // cmdBuffer[1] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_1; - + cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_0; + cmdBuffer[1] = SUS::DUMMY_BYTE; + cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; + cmdBuffer[3] = SUS::DUMMY_BYTE; + cmdBuffer[4] = SUS::CONVERT_DIFF_CHANNEL_2; + cmdBuffer[5] = SUS::DUMMY_BYTE; + cmdBuffer[6] = SUS::CONVERT_DIFF_CHANNEL_3; + cmdBuffer[7] = SUS::DUMMY_BYTE; + cmdBuffer[9] = SUS::CONVERT_DIFF_CHANNEL_4; + cmdBuffer[10] = SUS::DUMMY_BYTE; + cmdBuffer[11] = SUS::CONVERT_DIFF_CHANNEL_5; + cmdBuffer[12] = SUS::DUMMY_BYTE; + cmdBuffer[13] = SUS::DUMMY_BYTE; // cmdBuffer[0] = SUS::SETUP_DEFINITION; // cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; @@ -96,7 +107,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( // cmdBuffer[30] = SUS::CONVERT_DIFF_CHANNEL_4_5; rawPacket = cmdBuffer; // rawPacketLen = SUS::SIZE_PERFORM_CONVERSIONS; - rawPacketLen = 3; + rawPacketLen = 14; return RETURN_OK; } case(SUS::RQUEST_TEMP): { @@ -142,7 +153,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { case SUS::PERFORM_CONVERSIONS: { -// gpioComIF->pullHigh(chipSelectId); + gpioComIF->pullHigh(chipSelectId); PoolReadGuard readSet(&dataset); dataset.temperatureCelcius = (*(packet + 25) << 8 | *(packet + 26)) * 0.125; dataset.diffScanChannel0_1 = (*(packet + 29) << 8 | *(packet + 30)); diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index aabecac1..fdc4b28a 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -60,7 +60,7 @@ private: uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; InternalState internalState = InternalState::SETUP; - CommunicationStep communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + CommunicationStep communicationStep = CommunicationStep::WRITE_SETUP; }; #endif /* MISSION_DEVICES_SUSHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 438d761d..0985ce99 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -19,7 +19,7 @@ namespace SUS { * power on. * * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, No byte is following the setup byte - * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b00, internal reference, needs wake-up delay + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference, no wake-up delay * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b11, MAX1227 clocked through SPI SCLK * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register * @@ -41,6 +41,7 @@ namespace SUS { static const uint8_t CONVERT_DIFF_CHANNEL_2 = 0b10010110; static const uint8_t CONVERT_DIFF_CHANNEL_3 = 0b10011110; static const uint8_t CONVERT_DIFF_CHANNEL_4 = 0b10100110; + static const uint8_t CONVERT_DIFF_CHANNEL_5 = 0b10101110; static const uint8_t RESET_FIFO = 0b00011000; From 261f16f15b10b90d1b972833cee0be8779d2ed24 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 14:46:42 +0200 Subject: [PATCH 08/13] write setup byte and conversions --- mission/devices/SusHandler.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 25c01c87..3468d113 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -83,17 +83,17 @@ ReturnValue_t SusHandler::buildCommandFromCommand( * measurement the setup has to be rewritten */ // cmdBuffer[0] = SUS::RESET_FIFO; -// cmdBuffer[1] = SUS::SETUP_DEFINITION; + cmdBuffer[0] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_0; - cmdBuffer[1] = SUS::DUMMY_BYTE; - cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; - cmdBuffer[3] = SUS::DUMMY_BYTE; - cmdBuffer[4] = SUS::CONVERT_DIFF_CHANNEL_2; - cmdBuffer[5] = SUS::DUMMY_BYTE; - cmdBuffer[6] = SUS::CONVERT_DIFF_CHANNEL_3; - cmdBuffer[7] = SUS::DUMMY_BYTE; + cmdBuffer[1] = SUS::CONVERT_DIFF_CHANNEL_0; + cmdBuffer[2] = SUS::DUMMY_BYTE; + cmdBuffer[3] = SUS::CONVERT_DIFF_CHANNEL_1; + cmdBuffer[4] = SUS::DUMMY_BYTE; + cmdBuffer[5] = SUS::CONVERT_DIFF_CHANNEL_2; + cmdBuffer[6] = SUS::DUMMY_BYTE; + cmdBuffer[7] = SUS::CONVERT_DIFF_CHANNEL_3; + cmdBuffer[8] = SUS::DUMMY_BYTE; cmdBuffer[9] = SUS::CONVERT_DIFF_CHANNEL_4; cmdBuffer[10] = SUS::DUMMY_BYTE; cmdBuffer[11] = SUS::CONVERT_DIFF_CHANNEL_5; From fab28904de17c21ad941a3a1ee9c7a683d678ef5 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 16:48:55 +0200 Subject: [PATCH 09/13] working SUS in externally clocked mode --- bsp_q7s/ObjectFactory.cpp | 26 +-- fsfwconfig/devices/spi.h | 3 +- .../pollingSequenceFactory.cpp | 46 ++++- mission/devices/SusHandler.cpp | 168 +++++++++--------- mission/devices/SusHandler.h | 14 +- .../devicedefinitions/SusDefinitions.h | 42 +++-- 6 files changed, 170 insertions(+), 129 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 5dae58db..af880406 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -209,43 +209,43 @@ void ObjectFactory::produce(){ SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, gpioIds::CS_SUS_1); diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index 18b91c6f..2d6a01ba 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -20,8 +20,7 @@ static constexpr spi::SpiModes DEFAULT_RM3100_MODE = spi::SpiModes::MODE_3; static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; -//static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; -static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 1000000; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0; } diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 76571fc9..fe2eaf65 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -157,11 +157,47 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) // thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); // thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.8, DeviceHandlerIF::GET_READ); + if (length != 3) { + sif::waring << "pollingSequenceInitDefault: Frequency changed. Make sure timing critical " + << "SUS sensors still produce correct values" << std::endl; + } + + /** + * 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 + * device handler cycles is that some ADC conversions need a small delay before the results can + * be read. + * One sun sensor communication sequence also blocks the SPI bus. So other devices can not be + * inserted between the device handler cycles of one SUS. + */ + + /* Write setup */ + thisSequence->addSlot(objects::SUS_8, length * 0.991, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.992, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.993, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.994, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.995, DeviceHandlerIF::GET_READ); + + /* Request temperature */ + thisSequence->addSlot(objects::SUS_8, length * 0.996, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.997, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.998, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.999, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.9, DeviceHandlerIF::GET_READ); + + /* Read temperature */ + thisSequence->addSlot(objects::SUS_8, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.902, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.903, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.904, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.905, DeviceHandlerIF::GET_READ); + + /* Request and read ADC conversions */ + thisSequence->addSlot(objects::SUS_8, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.907, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.908, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.909, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.91, DeviceHandlerIF::GET_READ); // thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_11, length * 0.2, DeviceHandlerIF::SEND_WRITE); diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 3468d113..4f3dc834 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -9,6 +9,9 @@ SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCo if (comCookie == NULL) { sif::error << "SusHandler: Invalid com cookie" << std::endl; } + if (gpioComIF == NULL) { + sif::error << "SusHandler: Invalid GpioComIF" << std::endl; + } } SusHandler::~SusHandler() { @@ -16,13 +19,11 @@ SusHandler::~SusHandler() { void SusHandler::doStartUp(){ - if (internalState == InternalState::CONFIGURED) { #if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 - setMode(MODE_NORMAL); + setMode(MODE_NORMAL); #else - setMode(_MODE_TO_ON); + setMode(_MODE_TO_ON); #endif - } } void SusHandler::doShutDown(){ @@ -33,34 +34,26 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { if (communicationStep == CommunicationStep::WRITE_SETUP) { *id = SUS::WRITE_SETUP; - communicationStep = CommunicationStep::REQUEST_TEMP; -// communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + communicationStep = CommunicationStep::REQUEST_TEMPERATURE; } - else if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { - *id = SUS::PERFORM_CONVERSIONS; + else if (communicationStep == CommunicationStep::REQUEST_TEMPERATURE) { + *id = SUS::REQUEST_TEMPERATURE; + communicationStep = CommunicationStep::READ_TEMPERATURE; + } + else if (communicationStep == CommunicationStep::READ_TEMPERATURE) { + *id = SUS::READ_TEMPERATURE; + communicationStep = CommunicationStep::READ_CHANNELS; + } + else if (communicationStep == CommunicationStep::READ_CHANNELS) { + *id = SUS::READ_CHANNELS; communicationStep = CommunicationStep::WRITE_SETUP; -// communicationStep = CommunicationStep::PERFORM_CONVERSIONS; - } - else if (communicationStep == CommunicationStep::REQUEST_TEMP) { - *id = SUS::RQUEST_TEMP; - communicationStep = CommunicationStep::READ_TEMP; - } - else if (communicationStep == CommunicationStep::READ_TEMP) { - *id = SUS::READ_TEMP; - communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t SusHandler::buildTransitionDeviceCommand( DeviceCommandId_t * id){ - if (internalState == InternalState::SETUP) { - *id = SUS::WRITE_SETUP; - } - else { - return HasReturnvaluesIF::RETURN_OK; - } - return buildCommandFromCommand(*id, nullptr, 0); + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t SusHandler::buildCommandFromCommand( @@ -68,59 +61,46 @@ ReturnValue_t SusHandler::buildCommandFromCommand( size_t commandDataLen) { switch(deviceCommand) { case(SUS::WRITE_SETUP): { + /** + * The sun sensor ADC is shutdown when CS is pulled high, so each time requesting a + * measurement the setup has to be rewritten. There must also be a little delay between + * the transmission of the setup byte and the first conversion. Thus the conversion + * will be performed in an extra step. + */ + //TODO: Protect spi bus with mutex gpioComIF->pullLow(chipSelectId); cmdBuffer[0] = SUS::SETUP_DEFINITION; rawPacket = cmdBuffer; rawPacketLen = 1; - internalState = InternalState::CONFIGURED; return RETURN_OK; } - case(SUS::PERFORM_CONVERSIONS): { -// gpioComIF->pullLow(chipSelectId); + case(SUS::READ_CHANNELS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - /** - * The sun sensor ADC is shutdown when CS is pulled high so each time requesting a - * measurement the setup has to be rewritten - */ -// cmdBuffer[0] = SUS::RESET_FIFO; - cmdBuffer[0] = SUS::SETUP_DEFINITION; - // wirte one dummy byte here -// cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[1] = SUS::CONVERT_DIFF_CHANNEL_0; - cmdBuffer[2] = SUS::DUMMY_BYTE; - cmdBuffer[3] = SUS::CONVERT_DIFF_CHANNEL_1; - cmdBuffer[4] = SUS::DUMMY_BYTE; - cmdBuffer[5] = SUS::CONVERT_DIFF_CHANNEL_2; - cmdBuffer[6] = SUS::DUMMY_BYTE; - cmdBuffer[7] = SUS::CONVERT_DIFF_CHANNEL_3; - cmdBuffer[8] = SUS::DUMMY_BYTE; - cmdBuffer[9] = SUS::CONVERT_DIFF_CHANNEL_4; - cmdBuffer[10] = SUS::DUMMY_BYTE; - cmdBuffer[11] = SUS::CONVERT_DIFF_CHANNEL_5; + cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_0; + cmdBuffer[1] = SUS::DUMMY_BYTE; + cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; + cmdBuffer[3] = SUS::DUMMY_BYTE; + cmdBuffer[4] = SUS::CONVERT_DIFF_CHANNEL_2; + cmdBuffer[5] = SUS::DUMMY_BYTE; + cmdBuffer[6] = SUS::CONVERT_DIFF_CHANNEL_3; + cmdBuffer[7] = SUS::DUMMY_BYTE; + cmdBuffer[8] = SUS::CONVERT_DIFF_CHANNEL_4; + cmdBuffer[9] = SUS::DUMMY_BYTE; + cmdBuffer[10] = SUS::CONVERT_DIFF_CHANNEL_5; + cmdBuffer[11] = SUS::DUMMY_BYTE; cmdBuffer[12] = SUS::DUMMY_BYTE; - cmdBuffer[13] = SUS::DUMMY_BYTE; -// cmdBuffer[0] = SUS::SETUP_DEFINITION; -// cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; -// cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; -// cmdBuffer[26] = SUS::CONVERT_DIFF_CHANNEL_0_1; -// cmdBuffer[28] = SUS::CONVERT_DIFF_CHANNEL_2_3; -// cmdBuffer[30] = SUS::CONVERT_DIFF_CHANNEL_4_5; rawPacket = cmdBuffer; -// rawPacketLen = SUS::SIZE_PERFORM_CONVERSIONS; - rawPacketLen = 14; + rawPacketLen = SUS::SIZE_READ_CHANNELS; return RETURN_OK; } - case(SUS::RQUEST_TEMP): { -// gpioComIF->pullLow(chipSelectId); + case(SUS::REQUEST_TEMPERATURE): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); -// cmdBuffer[0] = SUS::RESET_FIFO; -// cmdBuffer[1] = SUS::SETUP_DEFINITION; cmdBuffer[0] = SUS::CONVERT_TEMPERATURE; rawPacket = cmdBuffer; rawPacketLen = 1; return RETURN_OK; } - case(SUS::READ_TEMP): { + case(SUS::READ_TEMPERATURE): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); rawPacket = cmdBuffer; rawPacketLen = 24; @@ -134,12 +114,10 @@ ReturnValue_t SusHandler::buildCommandFromCommand( void SusHandler::fillCommandAndReplyMap() { this->insertInCommandMap(SUS::WRITE_SETUP); -// this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); - this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); - this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, nullptr, SUS::SIZE_PERFORM_CONVERSIONS); -// this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, -// SUS::SIZE_PERFORM_CONVERSIONS); - this->insertInCommandMap(SUS::RQUEST_TEMP); + this->insertInCommandMap(SUS::REQUEST_TEMPERATURE); + this->insertInCommandAndReplyMap(SUS::READ_CHANNELS, 1, &dataset, SUS::SIZE_READ_CHANNELS); + this->insertInCommandAndReplyMap(SUS::READ_TEMPERATURE, 1, nullptr, + SUS::SIZE_READ_TEMPERATURE); } ReturnValue_t SusHandler::scanForReply(const uint8_t *start, @@ -152,27 +130,42 @@ ReturnValue_t SusHandler::scanForReply(const uint8_t *start, ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { - case SUS::PERFORM_CONVERSIONS: { - gpioComIF->pullHigh(chipSelectId); + case SUS::READ_CHANNELS: { PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet + 25) << 8 | *(packet + 26)) * 0.125; - dataset.diffScanChannel0_1 = (*(packet + 29) << 8 | *(packet + 30)); - dataset.diffScanChannel2_3 = (*(packet + 31) << 8 | *(packet + 32)); - dataset.diffScanChannel4_5 = (*(packet + 33) << 8 | *(packet + 34)); + dataset.ain0 = (*(packet + 1) << 8 | *(packet + 2)); + dataset.ain1 = (*(packet + 3) << 8 | *(packet + 4)); + dataset.ain2 = (*(packet + 5) << 8 | *(packet + 6)); + dataset.ain3 = (*(packet + 7) << 8 | *(packet + 8)); + dataset.ain4 = (*(packet + 9) << 8 | *(packet + 10)); + dataset.ain5 = (*(packet + 11) << 8 | *(packet + 12)); #if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS - sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", temperature: " - << dataset.temperatureCelcius << " °C" << std::endl; - sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 0/1: " - << dataset.diffScanChannel0_1 << std::endl; - sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 2/3: " - << dataset.diffScanChannel2_3 << std::endl; - sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 4/5: " - << dataset.diffScanChannel4_5 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN0: " + << std::dec << dataset.ain0 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN1: " + << std::dec << dataset.ain1 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN2: " + << std::dec << dataset.ain2 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN3: " + << std::dec << dataset.ain3 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN4: " + << std::dec << dataset.ain4 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN5: " + << std::dec << dataset.ain5 << std::endl; #endif + /** + * Reading the channel conversion results is the last communication step in one SUS + * sequence. SPI bus can now be released again. + */ + gpioComIF->pullHigh(chipSelectId); break; } - case SUS::READ_TEMP: { -// gpioComIF->pullHigh(chipSelectId); + case SUS::READ_TEMPERATURE: { + PoolReadGuard readSet(&dataset); + dataset.temperatureCelcius = (*(packet + 22) << 8 | *(packet + 23)) * 0.125; +#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", temperature: " + << dataset.temperatureCelcius << " °C" << std::endl; +#endif break; } default: { @@ -189,15 +182,18 @@ void SusHandler::setNormalDatapoolEntriesInvalid(){ } uint32_t SusHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ - return 5000; + return 1000; } ReturnValue_t SusHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { localDataPoolMap.emplace(SUS::TEMPERATURE_C, new PoolEntry( { 0.0 })); - localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_0_1, new PoolEntry( { 0 })); - localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_2_3, new PoolEntry( { 0 })); - localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_4_5, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN0, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN1, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN2, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN3, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN4, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN5, new PoolEntry( { 0 })); return HasReturnvaluesIF::RETURN_OK; } diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index fdc4b28a..5ef7ec32 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -41,15 +41,10 @@ protected: private: enum class CommunicationStep { - PERFORM_CONVERSIONS, - REQUEST_TEMP, - READ_TEMP, - WRITE_SETUP - }; - - enum class InternalState { - SETUP, - CONFIGURED + WRITE_SETUP, + REQUEST_TEMPERATURE, + READ_TEMPERATURE, + READ_CHANNELS }; LinuxLibgpioIF* gpioComIF = nullptr; @@ -59,7 +54,6 @@ private: SUS::SusDataset dataset; uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; - InternalState internalState = InternalState::SETUP; CommunicationStep communicationStep = CommunicationStep::WRITE_SETUP; }; diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 0985ce99..fc46f75f 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -3,6 +3,12 @@ namespace SUS { + /** + * The MAX1227 in externally clocked mode did not properly work with frequencies higher than + * 1 MHz. + */ + static const uint32_t SUS_MAX_1227_SPEED = 1000000; + static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending /** @@ -10,9 +16,9 @@ namespace SUS { * temperature sensor. */ static const DeviceCommandId_t WRITE_SETUP = 0x1; - static const DeviceCommandId_t PERFORM_CONVERSIONS = 0x2; - static const DeviceCommandId_t READ_TEMP = 0x3; - static const DeviceCommandId_t RQUEST_TEMP = 0x4; + static const DeviceCommandId_t READ_CHANNELS = 0x2; + static const DeviceCommandId_t READ_TEMPERATURE = 0x3; + static const DeviceCommandId_t REQUEST_TEMPERATURE = 0x4; /** * @brief This is the configuration byte which will be written to the setup register after @@ -47,21 +53,28 @@ namespace SUS { static const uint8_t DUMMY_BYTE = 0x0; - static const uint8_t SUS_DATA_SET_ID = PERFORM_CONVERSIONS; + static const uint8_t SUS_DATA_SET_ID = READ_CHANNELS; - static const uint8_t SIZE_PERFORM_CONVERSIONS = 34; + /** Size of data replies */ + static const uint8_t SIZE_READ_CHANNELS = 13; + static const uint8_t SIZE_READ_TEMPERATURE = 25; - static const uint8_t MAX_CMD_SIZE = SIZE_PERFORM_CONVERSIONS; + static const uint8_t MAX_CMD_SIZE = SIZE_READ_TEMPERATURE; + + static const uint8_t POOL_ENTRIES = 7; enum Max1227PoolIds: lp_id_t { TEMPERATURE_C, - DIFF_SCAN_CHANNEL_0_1, - DIFF_SCAN_CHANNEL_2_3, - DIFF_SCAN_CHANNEL_4_5, + AIN0, + AIN1, + AIN2, + AIN3, + AIN4, + AIN5, }; -class SusDataset: public StaticLocalDataSet { +class SusDataset: public StaticLocalDataSet { public: SusDataset(HasLocalDataPoolIF* owner) : @@ -73,9 +86,12 @@ public: } lp_var_t temperatureCelcius = lp_var_t(sid.objectId, TEMPERATURE_C, this); - lp_var_t diffScanChannel0_1 = lp_var_t(sid.objectId, DIFF_SCAN_CHANNEL_0_1, this); - lp_var_t diffScanChannel2_3 = lp_var_t(sid.objectId, DIFF_SCAN_CHANNEL_2_3, this); - lp_var_t diffScanChannel4_5 = lp_var_t(sid.objectId, DIFF_SCAN_CHANNEL_4_5, this); + lp_var_t ain0 = lp_var_t(sid.objectId, AIN0, this); + lp_var_t ain1 = lp_var_t(sid.objectId, AIN1, this); + lp_var_t ain2 = lp_var_t(sid.objectId, AIN2, this); + lp_var_t ain3 = lp_var_t(sid.objectId, AIN3, this); + lp_var_t ain4 = lp_var_t(sid.objectId, AIN4, this); + lp_var_t ain5 = lp_var_t(sid.objectId, AIN5, this); }; } From a6465c42ba116cb50529f8ef61a7dc48d48a80a2 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 18:18:27 +0200 Subject: [PATCH 10/13] save before changing to internally clocked mode --- bsp_q7s/ObjectFactory.cpp | 42 ++++--- fsfwconfig/devices/spi.h | 2 +- .../pollingSequenceFactory.cpp | 112 +++++++++++++----- 3 files changed, 105 insertions(+), 51 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index af880406..6524c64b 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -161,7 +161,8 @@ void ObjectFactory::produce(){ spi::DEFAULT_MAX_1227_SPEED); RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); - (void) radSensor; +// (void) radSensor; + radSensor->setStartUpImmediately(); GpioCookie* gpioCookieSus = new GpioCookie(); @@ -207,59 +208,56 @@ void ObjectFactory::produce(){ gpioComIF->addGpios(gpioCookieSus); - SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, + SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, + SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, + SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, + SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, + SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, + SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, + SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, + SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, + SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, + SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12, + SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13, + SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, gpioIds::CS_SUS_1); -// sus1->setStartUpImmediately(); (void) sus1; SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2, gpioComIF, gpioIds::CS_SUS_2); - sus2->setStartUpImmediately(); (void) sus2; SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3, gpioComIF, gpioIds::CS_SUS_3); - sus3->setStartUpImmediately(); (void) sus3; new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4, gpioComIF, @@ -272,6 +270,7 @@ void ObjectFactory::produce(){ gpioIds::CS_SUS_7); SusHandler* sus8 = new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8, gpioComIF, gpioIds::CS_SUS_8); +// (void) sus8; sus8->setStartUpImmediately(); new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9, gpioComIF, @@ -280,12 +279,17 @@ void ObjectFactory::produce(){ gpioIds::CS_SUS_10); SusHandler* sus11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11, gpioComIF, gpioIds::CS_SUS_11); - sus11->setStartUpImmediately(); + (void) sus11; - new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12, gpioComIF, + SusHandler* sus12 = new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12, gpioComIF, gpioIds::CS_SUS_12); - new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13, gpioComIF, +// sus12->setStartUpImmediately(); + (void) sus12; + + SusHandler* sus13 = new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13, gpioComIF, gpioIds::CS_SUS_13); +// sus13->setStartUpImmediately(); + (void) sus13; #if OBSW_ADD_ACS_BOARD == 1 GpioCookie* gpioCookieAcsBoard = new GpioCookie(); diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index 2d6a01ba..eb17786b 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -21,7 +21,7 @@ static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; -static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0; +static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; } diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index fe2eaf65..2412921f 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -157,8 +157,8 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) // thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); // thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); - if (length != 3) { - sif::waring << "pollingSequenceInitDefault: Frequency changed. Make sure timing critical " + if (length != 3000) { + sif::warning << "pollingSequenceInitDefault: Frequency changed. Make sure timing critical " << "SUS sensors still produce correct values" << std::endl; } @@ -172,38 +172,88 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) */ /* Write setup */ - thisSequence->addSlot(objects::SUS_8, length * 0.991, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.992, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.993, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.994, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.995, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.8, DeviceHandlerIF::GET_READ); /* Request temperature */ - thisSequence->addSlot(objects::SUS_8, length * 0.996, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.997, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.998, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.999, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.9, DeviceHandlerIF::GET_READ); +// thisSequence->addSlot(objects::SUS_8, 2905, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_8, 2906, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2907, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2908, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_8, 2909, DeviceHandlerIF::GET_READ); +// +// /* Read temperature */ +// thisSequence->addSlot(objects::SUS_8, 2910, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_8, 2911, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2912, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2913, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_8, 2914, DeviceHandlerIF::GET_READ); +// +// /* Request and read ADC conversions */ +// thisSequence->addSlot(objects::SUS_8, 2915, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_8, 2916, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2917, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2918, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_8, 2919, DeviceHandlerIF::GET_READ); - /* Read temperature */ - thisSequence->addSlot(objects::SUS_8, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.902, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.903, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.904, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.905, DeviceHandlerIF::GET_READ); - - /* Request and read ADC conversions */ - thisSequence->addSlot(objects::SUS_8, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.907, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.908, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.909, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.91, DeviceHandlerIF::GET_READ); - -// thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_11, length * 0.2, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_11, length * 0.4, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_11, length * 0.6, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_11, length * 0.8, DeviceHandlerIF::GET_READ); + /* Write setup */ +// thisSequence->addSlot(objects::SUS_12, length * 0.92, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_12, length * 0.921, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.922, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.923, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_12, length * 0.924, DeviceHandlerIF::GET_READ); +// +// /* Request temperature */ +// thisSequence->addSlot(objects::SUS_12, length * 0.925, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_12, length * 0.926, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.927, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.928, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_12, length * 0.929, DeviceHandlerIF::GET_READ); +// +// /* Read temperature */ +// thisSequence->addSlot(objects::SUS_12, length * 0.93, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_12, length * 0.931, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.932, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::GET_READ); +// +// /* Request and read ADC conversions */ +// thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_12, length * 0.936, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.937, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.938, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_12, length * 0.939, DeviceHandlerIF::GET_READ); +// +// /* Write setup */ +// thisSequence->addSlot(objects::SUS_13, length * 0.94, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_13, length * 0.941, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.942, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.943, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_13, length * 0.945, DeviceHandlerIF::GET_READ); +// +// /* Request temperature */ +// thisSequence->addSlot(objects::SUS_13, length * 0.946, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_13, length * 0.947, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.948, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.949, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_13, length * 0.95, DeviceHandlerIF::GET_READ); +// +// /* Read temperature */ +// thisSequence->addSlot(objects::SUS_13, length * 0.95, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_13, length * 0.951, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.952, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.953, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_13, length * 0.954, DeviceHandlerIF::GET_READ); +// +// /* Request and read ADC conversions */ +// thisSequence->addSlot(objects::SUS_13, length * 0.955, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_13, length * 0.956, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.957, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.958, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_13, length * 0.959, DeviceHandlerIF::GET_READ); if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; From e1e69539cacb523e76d5987f89c017956227cc0e Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 10 May 2021 11:13:39 +0200 Subject: [PATCH 11/13] changed SusHandler MAX1227 to internal clock mode --- mission/devices/SusHandler.cpp | 84 ++++++------------- mission/devices/SusHandler.h | 5 +- .../devicedefinitions/RadSensorDefinitions.h | 2 +- .../devicedefinitions/SusDefinitions.h | 51 ++++++----- 4 files changed, 52 insertions(+), 90 deletions(-) diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 4f3dc834..8d80322c 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -34,18 +34,14 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { if (communicationStep == CommunicationStep::WRITE_SETUP) { *id = SUS::WRITE_SETUP; - communicationStep = CommunicationStep::REQUEST_TEMPERATURE; + communicationStep = CommunicationStep::START_CONVERSIONS; } - else if (communicationStep == CommunicationStep::REQUEST_TEMPERATURE) { - *id = SUS::REQUEST_TEMPERATURE; - communicationStep = CommunicationStep::READ_TEMPERATURE; + else if (communicationStep == CommunicationStep::START_CONVERSIONS) { + *id = SUS::START_CONVERSIONS; + communicationStep = CommunicationStep::READ_CONVERSIONS; } - else if (communicationStep == CommunicationStep::READ_TEMPERATURE) { - *id = SUS::READ_TEMPERATURE; - communicationStep = CommunicationStep::READ_CHANNELS; - } - else if (communicationStep == CommunicationStep::READ_CHANNELS) { - *id = SUS::READ_CHANNELS; + else if (communicationStep == CommunicationStep::READ_CONVERSIONS) { + *id = SUS::READ_CONVERSIONS; communicationStep = CommunicationStep::WRITE_SETUP; } return buildCommandFromCommand(*id, nullptr, 0); @@ -69,41 +65,22 @@ ReturnValue_t SusHandler::buildCommandFromCommand( */ //TODO: Protect spi bus with mutex gpioComIF->pullLow(chipSelectId); - cmdBuffer[0] = SUS::SETUP_DEFINITION; + cmdBuffer[0] = SUS::SETUP; rawPacket = cmdBuffer; rawPacketLen = 1; return RETURN_OK; } - case(SUS::READ_CHANNELS): { + case(SUS::START_CONVERSIONS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_0; - cmdBuffer[1] = SUS::DUMMY_BYTE; - cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; - cmdBuffer[3] = SUS::DUMMY_BYTE; - cmdBuffer[4] = SUS::CONVERT_DIFF_CHANNEL_2; - cmdBuffer[5] = SUS::DUMMY_BYTE; - cmdBuffer[6] = SUS::CONVERT_DIFF_CHANNEL_3; - cmdBuffer[7] = SUS::DUMMY_BYTE; - cmdBuffer[8] = SUS::CONVERT_DIFF_CHANNEL_4; - cmdBuffer[9] = SUS::DUMMY_BYTE; - cmdBuffer[10] = SUS::CONVERT_DIFF_CHANNEL_5; - cmdBuffer[11] = SUS::DUMMY_BYTE; - cmdBuffer[12] = SUS::DUMMY_BYTE; + cmdBuffer[0] = SUS::CONVERSION; rawPacket = cmdBuffer; - rawPacketLen = SUS::SIZE_READ_CHANNELS; + rawPacketLen = 1; return RETURN_OK; } - case(SUS::REQUEST_TEMPERATURE): { - std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - cmdBuffer[0] = SUS::CONVERT_TEMPERATURE; - rawPacket = cmdBuffer; - rawPacketLen = 1; - return RETURN_OK; - } - case(SUS::READ_TEMPERATURE): { + case(SUS::READ_CONVERSIONS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); rawPacket = cmdBuffer; - rawPacketLen = 24; + rawPacketLen = SUS::SIZE_READ_CONVERSIONS; return RETURN_OK; } default: @@ -114,10 +91,8 @@ ReturnValue_t SusHandler::buildCommandFromCommand( void SusHandler::fillCommandAndReplyMap() { this->insertInCommandMap(SUS::WRITE_SETUP); - this->insertInCommandMap(SUS::REQUEST_TEMPERATURE); - this->insertInCommandAndReplyMap(SUS::READ_CHANNELS, 1, &dataset, SUS::SIZE_READ_CHANNELS); - this->insertInCommandAndReplyMap(SUS::READ_TEMPERATURE, 1, nullptr, - SUS::SIZE_READ_TEMPERATURE); + this->insertInCommandMap(SUS::START_CONVERSIONS); + this->insertInCommandAndReplyMap(SUS::READ_CONVERSIONS, 1, &dataset, SUS::SIZE_READ_CONVERSIONS); } ReturnValue_t SusHandler::scanForReply(const uint8_t *start, @@ -130,15 +105,18 @@ ReturnValue_t SusHandler::scanForReply(const uint8_t *start, ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { - case SUS::READ_CHANNELS: { + case SUS::READ_CONVERSIONS: { PoolReadGuard readSet(&dataset); - dataset.ain0 = (*(packet + 1) << 8 | *(packet + 2)); - dataset.ain1 = (*(packet + 3) << 8 | *(packet + 4)); - dataset.ain2 = (*(packet + 5) << 8 | *(packet + 6)); - dataset.ain3 = (*(packet + 7) << 8 | *(packet + 8)); - dataset.ain4 = (*(packet + 9) << 8 | *(packet + 10)); - dataset.ain5 = (*(packet + 11) << 8 | *(packet + 12)); + dataset.temperatureCelcius = (*(packet) << 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)); + dataset.ain3 = (*(packet + 8) << 8 | *(packet + 9)); + dataset.ain4 = (*(packet + 10) << 8 | *(packet + 11)); + dataset.ain5 = (*(packet + 12) << 8 | *(packet + 13)); #if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", Temperature: " + << dataset.temperatureCelcius << " °C" << std::endl; sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN0: " << std::dec << dataset.ain0 << std::endl; sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN1: " @@ -152,22 +130,10 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN5: " << std::dec << dataset.ain5 << std::endl; #endif - /** - * Reading the channel conversion results is the last communication step in one SUS - * sequence. SPI bus can now be released again. - */ + /** SUS can now be shutdown and thus the SPI bus released again */ gpioComIF->pullHigh(chipSelectId); break; } - case SUS::READ_TEMPERATURE: { - PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet + 22) << 8 | *(packet + 23)) * 0.125; -#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS - sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", temperature: " - << dataset.temperatureCelcius << " °C" << std::endl; -#endif - break; - } default: { sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl; return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 5ef7ec32..14685dd9 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -42,9 +42,8 @@ private: enum class CommunicationStep { WRITE_SETUP, - REQUEST_TEMPERATURE, - READ_TEMPERATURE, - READ_CHANNELS + START_CONVERSIONS, + READ_CONVERSIONS }; LinuxLibgpioIF* gpioComIF = nullptr; diff --git a/mission/devices/devicedefinitions/RadSensorDefinitions.h b/mission/devices/devicedefinitions/RadSensorDefinitions.h index db105495..7d434d04 100644 --- a/mission/devices/devicedefinitions/RadSensorDefinitions.h +++ b/mission/devices/devicedefinitions/RadSensorDefinitions.h @@ -18,7 +18,7 @@ namespace RAD_SENSOR { * power on. * * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, no data follows the setup byte - * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b01, external reference single ended + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference, no wake-up delay * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, MAX1227 uses internal oscillator for timing * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register * diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index fc46f75f..6cc8aa65 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -11,55 +11,52 @@ namespace SUS { static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending - /** - * This command initiates the ADC conversion for all channels including the internal - * temperature sensor. - */ static const DeviceCommandId_t WRITE_SETUP = 0x1; - static const DeviceCommandId_t READ_CHANNELS = 0x2; - static const DeviceCommandId_t READ_TEMPERATURE = 0x3; - static const DeviceCommandId_t REQUEST_TEMPERATURE = 0x4; + /** + * This command initiates the ADC conversion for all channels including the internal + * temperature sensor. + */ + static const DeviceCommandId_t START_CONVERSIONS = 0x2; + /** + * This command reads the internal fifo which holds the temperature and the channel + * conversions. + */ + static const DeviceCommandId_t READ_CONVERSIONS = 0x3; /** * @brief This is the configuration byte which will be written to the setup register after * power on. * * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, No byte is following the setup byte - * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference, no wake-up delay - * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b11, MAX1227 clocked through SPI SCLK - * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, Internal reference, no wake-up delay + * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, Internally clocked + * Bit7 - Bit6: 0b01, Tells MAX1227 that this byte should be + * written to the setup register * */ - static const uint8_t SETUP_DEFINITION = 0b01111000; + static const uint8_t SETUP = 0b01101000; /** - * @brief This value will always be written to the ADC conversion register to specify the + * @brief This values will always be written to the ADC conversion register to specify the * conversions to perform. * @details Bit0: 1 - Enables temperature conversion - * Bit2 (SCAN1) and Bit1 (SCAN0): 0b11, No scan, converts channel N once only. - * Scanning is not supported in spi clock mode. - * Bit6 - Bit3 defines N: 0b0001 (N = 4) + * Bit2 (SCAN1) and Bit1 (SCAN0): 0b00, Scans channels 0 through N + * Bit6 - Bit3 defines N: 0b0101 (N = 5) * Bit7: Always 1. Tells the ADC that this is the conversion register. */ - static const uint8_t CONVERT_TEMPERATURE = 0b10000001; - static const uint8_t CONVERT_DIFF_CHANNEL_0 = 0b10000110; - static const uint8_t CONVERT_DIFF_CHANNEL_1 = 0b10001110; - static const uint8_t CONVERT_DIFF_CHANNEL_2 = 0b10010110; - static const uint8_t CONVERT_DIFF_CHANNEL_3 = 0b10011110; - static const uint8_t CONVERT_DIFF_CHANNEL_4 = 0b10100110; - static const uint8_t CONVERT_DIFF_CHANNEL_5 = 0b10101110; + static const uint8_t CONVERSION = 0b10101001; + /** Writing this value resets the fifo */ static const uint8_t RESET_FIFO = 0b00011000; static const uint8_t DUMMY_BYTE = 0x0; - static const uint8_t SUS_DATA_SET_ID = READ_CHANNELS; + static const uint8_t SUS_DATA_SET_ID = READ_CONVERSIONS; - /** Size of data replies */ - static const uint8_t SIZE_READ_CHANNELS = 13; - static const uint8_t SIZE_READ_TEMPERATURE = 25; + /** Size of data replies. Temperature and 6 channel convesions (AIN0 - AIN5) */ + static const uint8_t SIZE_READ_CONVERSIONS = 14; - static const uint8_t MAX_CMD_SIZE = SIZE_READ_TEMPERATURE; + static const uint8_t MAX_CMD_SIZE = SIZE_READ_CONVERSIONS; static const uint8_t POOL_ENTRIES = 7; From 2d170a1f6199620c19ef73e310dadbd5165501eb Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Wed, 12 May 2021 13:06:56 +0200 Subject: [PATCH 12/13] sus delay implementation --- bsp_q7s/InitMission.cpp | 8 +- bsp_q7s/ObjectFactory.cpp | 59 ++-- fsfw_hal | 2 +- fsfwconfig/OBSWConfig.h | 4 +- .../pollingSequenceFactory.cpp | 334 +++++++++--------- fsfwconfig/returnvalues/classIds.h | 3 +- mission/devices/RadiationSensorHandler.cpp | 2 +- mission/devices/SusHandler.cpp | 39 +- mission/devices/SusHandler.h | 13 + .../devicedefinitions/SusDefinitions.h | 12 +- 10 files changed, 269 insertions(+), 207 deletions(-) diff --git a/bsp_q7s/InitMission.cpp b/bsp_q7s/InitMission.cpp index a8ba7d1d..534cb2ee 100644 --- a/bsp_q7s/InitMission.cpp +++ b/bsp_q7s/InitMission.cpp @@ -158,10 +158,10 @@ void initmission::initTasks() { } #else - FixedTimeslotTaskIF * pollingSequenceTableTE0720 = factory->createFixedTimeslotTask( - "PST_TASK_TE0720", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 3.0, + FixedTimeslotTaskIF * pollingSequenceTaskTE0720 = factory->createFixedTimeslotTask( + "PST_TASK_TE0720", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE * 8, 5.0, missedDeadlineFunc); - result = pst::pollingSequenceTE0720(pollingSequenceTableTE0720); + result = pst::pollingSequenceTE0720(pollingSequenceTaskTE0720); if (result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: Creating TE0720 PST failed!" << std::endl; } @@ -198,7 +198,7 @@ void initmission::initTasks() { gomSpacePstTask->startTask(); pollingSequenceTableTaskDefault->startTask(); #elif TE0720 == 1 && Q7S_ADD_SPI_TEST == 0 - pollingSequenceTableTE0720->startTask(); + pollingSequenceTaskTE0720->startTask(); #endif pusVerification->startTask(); diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 6524c64b..62cf46d2 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -105,14 +105,12 @@ void ObjectFactory::produce(){ new UartComIF(objects::UART_COM_IF); #if Q7S_ADD_SPI_TEST == 0 new SpiComIF(objects::SPI_COM_IF, gpioComIF); -#endif +#endif /* Q7S_ADD_SPI_TEST == 0 */ /* Temperature sensors */ new Tmp1075Handler(objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, i2cCookieTmp1075tcs1); new Tmp1075Handler(objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, i2cCookieTmp1075tcs2); - GpioCookie* heaterGpiosCookie = new GpioCookie; - #if TE0720 == 0 CspCookie* p60DockCspCookie = new CspCookie(P60Dock::MAX_REPLY_LENGTH, addresses::P60DOCK); @@ -161,8 +159,7 @@ void ObjectFactory::produce(){ spi::DEFAULT_MAX_1227_SPEED); RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); -// (void) radSensor; - radSensor->setStartUpImmediately(); + (void) radSensor; GpioCookie* gpioCookieSus = new GpioCookie(); @@ -210,43 +207,43 @@ void ObjectFactory::produce(){ SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, gpioIds::CS_SUS_1); @@ -254,7 +251,7 @@ void ObjectFactory::produce(){ SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2, gpioComIF, gpioIds::CS_SUS_2); - (void) sus2; + sus2->setStartUpImmediately(); SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3, gpioComIF, gpioIds::CS_SUS_3); @@ -270,25 +267,26 @@ void ObjectFactory::produce(){ gpioIds::CS_SUS_7); SusHandler* sus8 = new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8, gpioComIF, gpioIds::CS_SUS_8); -// (void) sus8; - sus8->setStartUpImmediately(); + (void) sus8; - new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9, gpioComIF, + SusHandler* sus9 = new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9, gpioComIF, gpioIds::CS_SUS_9); - new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10, gpioComIF, + (void) sus9; + + SusHandler* sus10 = new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10, gpioComIF, gpioIds::CS_SUS_10); + (void) sus10; + SusHandler* sus11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11, gpioComIF, gpioIds::CS_SUS_11); (void) sus11; SusHandler* sus12 = new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12, gpioComIF, gpioIds::CS_SUS_12); -// sus12->setStartUpImmediately(); (void) sus12; SusHandler* sus13 = new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13, gpioComIF, gpioIds::CS_SUS_13); -// sus13->setStartUpImmediately(); (void) sus13; #if OBSW_ADD_ACS_BOARD == 1 @@ -364,6 +362,8 @@ void ObjectFactory::produce(){ gyroL3gHandler->setStartUpImmediately(); #endif + GpioCookie* heaterGpiosCookie = new GpioCookie; + /* Pin H2-11 on stack connector */ GpiodRegular* gpioConfigHeater0 = new GpiodRegular(std::string("gpiochip7"), 6, std::string("Heater0"), gpio::OUT, 0); @@ -595,14 +595,13 @@ void ObjectFactory::produce(){ #if TE0720 == 1 && TEST_SUS_HANDLER == 1 GpioCookie* gpioCookieSus = new GpioCookie; - GpiodRegular* chipSelectSus = new GpiodRegular(std::string("gpiochip0"), 9, + GpiodRegular* chipSelectSus = new GpiodRegular(std::string("gpiochip1"), 9, std::string("Chip Select Sus Sensor"), gpio::OUT, 1); gpioCookieSus->addGpio(gpioIds::CS_SUS_1, chipSelectSus); gpioComIF->addGpios(gpioCookieSus); - SpiCookie* spiCookieSus = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, - std::string("/dev/spidev1.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus = new SpiCookie(addresses::SUS_1, std::string("/dev/spidev1.0"), + SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus, gpioComIF, gpioIds::CS_SUS_1); @@ -611,7 +610,7 @@ void ObjectFactory::produce(){ #if TE0720 == 1 && TEST_RADIATION_SENSOR_HANDLER == 1 GpioCookie* gpioCookieRadSensor = new GpioCookie; - GpiodRegular* chipSelectRadSensor = new GpiodRegular(std::string("gpiochip0"), 9, + GpiodRegular* chipSelectRadSensor = new GpiodRegular(std::string("gpiochip1"), 0, std::string("Chip select radiation sensor"), gpio::OUT, 1); gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); gpioComIF->addGpios(gpioCookieRadSensor); diff --git a/fsfw_hal b/fsfw_hal index a85c0146..425cfd2a 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit a85c01465bc8687773676f05c5e7eb8af54b25ff +Subproject commit 425cfd2ababe3639355c6681ce3f9b606b893430 diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 5db2e7d0..bfe528c6 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -20,11 +20,11 @@ debugging. */ #define OBSW_PRINT_MISSED_DEADLINES 1 #define OBSW_ADD_TEST_CODE 1 #define TEST_LIBGPIOD 0 -#define TEST_RADIATION_SENSOR_HANDLER 0 +#define TEST_RADIATION_SENSOR_HANDLER 1 #define TEST_SUS_HANDLER 1 #define TEST_PLOC_HANDLER 0 -#define TE0720 0 +#define TE0720 1 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 2412921f..ffa22fdc 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -144,18 +144,11 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) /* Radiation sensor */ -// thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); - - /* Sun sensor 1 */ -// thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); if (length != 3000) { sif::warning << "pollingSequenceInitDefault: Frequency changed. Make sure timing critical " @@ -165,95 +158,74 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) /** * 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 - * device handler cycles is that some ADC conversions need a small delay before the results can - * be read. + * device handler cycles is that the ADC conversions take some time. Thus first the ADC + * conversions are initiated and in a next step the results can be read from the internal FIFO. * One sun sensor communication sequence also blocks the SPI bus. So other devices can not be * inserted between the device handler cycles of one SUS. */ /* Write setup */ - thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.8, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.902, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.903, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.904, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.905, DeviceHandlerIF::GET_READ); - /* Request temperature */ -// thisSequence->addSlot(objects::SUS_8, 2905, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_8, 2906, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2907, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2908, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_8, 2909, DeviceHandlerIF::GET_READ); -// -// /* Read temperature */ -// thisSequence->addSlot(objects::SUS_8, 2910, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_8, 2911, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2912, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2913, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_8, 2914, DeviceHandlerIF::GET_READ); -// -// /* Request and read ADC conversions */ -// thisSequence->addSlot(objects::SUS_8, 2915, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_8, 2916, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2917, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2918, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_8, 2919, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_8, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.907, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.908, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.909, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.91, DeviceHandlerIF::GET_READ); + + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_8, length * 0.911, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.912, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.913, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.914, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.915, DeviceHandlerIF::GET_READ); /* Write setup */ -// thisSequence->addSlot(objects::SUS_12, length * 0.92, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_12, length * 0.921, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.922, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.923, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_12, length * 0.924, DeviceHandlerIF::GET_READ); -// -// /* Request temperature */ -// thisSequence->addSlot(objects::SUS_12, length * 0.925, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_12, length * 0.926, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.927, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.928, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_12, length * 0.929, DeviceHandlerIF::GET_READ); -// -// /* Read temperature */ -// thisSequence->addSlot(objects::SUS_12, length * 0.93, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_12, length * 0.931, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.932, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::GET_READ); -// -// /* Request and read ADC conversions */ -// thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_12, length * 0.936, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.937, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.938, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_12, length * 0.939, DeviceHandlerIF::GET_READ); -// -// /* Write setup */ -// thisSequence->addSlot(objects::SUS_13, length * 0.94, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_13, length * 0.941, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.942, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.943, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_13, length * 0.945, DeviceHandlerIF::GET_READ); -// -// /* Request temperature */ -// thisSequence->addSlot(objects::SUS_13, length * 0.946, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_13, length * 0.947, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.948, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.949, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_13, length * 0.95, DeviceHandlerIF::GET_READ); -// -// /* Read temperature */ -// thisSequence->addSlot(objects::SUS_13, length * 0.95, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_13, length * 0.951, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.952, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.953, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_13, length * 0.954, DeviceHandlerIF::GET_READ); -// -// /* Request and read ADC conversions */ -// thisSequence->addSlot(objects::SUS_13, length * 0.955, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_13, length * 0.956, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.957, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.958, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_13, length * 0.959, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.916, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.917, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.918, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.919, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.920, DeviceHandlerIF::GET_READ); + + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_12, length * 0.921, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.922, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.923, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.924, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.925, DeviceHandlerIF::GET_READ); + + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_12, length * 0.926, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.927, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.928, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.929, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.930, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_2, length * 0.931, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.932, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.933, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.934, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.935, DeviceHandlerIF::GET_READ); + + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_2, length * 0.936, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.937, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.938, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.939, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.94, DeviceHandlerIF::GET_READ); + + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_2, length * 0.941, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.942, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.943, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.944, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.945, DeviceHandlerIF::GET_READ); if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; @@ -315,62 +287,62 @@ ReturnValue_t pst::gomspacePstInit(FixedTimeslotTaskIF *thisSequence){ length * 0.8, DeviceHandlerIF::GET_READ); #if OBSW_ADD_ACS_BOARD == 1 -// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0, -// DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.2, -// DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.4, -// DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.6, -// DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.8, -// DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0, -// DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.2, -// DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.4, -// DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.6, -// DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.8, -// DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); -// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0, -// DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.2, -// DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.4, -// DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.6, -// DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.8, -// DeviceHandlerIF::GET_READ); -// -// -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0, -// DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.2, -// DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.4, -// DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.6, -// DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.8, -// DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); -// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0, -// DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.2, -// DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.4, -// DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.6, -// DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.8, -// DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); + + + thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0, @@ -446,22 +418,68 @@ ReturnValue_t pst::pollingSequenceTE0720(FixedTimeslotTaskIF *thisSequence) { thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); #endif -#if TEST_SUS_HANDLER == 1 - thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); -#endif - #if TEST_RADIATION_SENSOR_HANDLER == 1 - thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); +// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::GET_READ); #endif +#if TEST_SUS_HANDLER == 1 + /* Write setup */ +// thisSequence->addSlot(objects::SUS_1, 1000, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_1, 1010, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_1, 1020, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_1, 1030, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_1, 1040, DeviceHandlerIF::GET_READ); +// +// /* Start ADC conversions */ +// thisSequence->addSlot(objects::SUS_1, 1050, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_1, 1060, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_1, 1070, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_1, 1080, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_1, 1090, DeviceHandlerIF::GET_READ); +// +// /* Read ADC conversions from inernal FIFO */ +// thisSequence->addSlot(objects::SUS_1, 2000, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_1, 2010, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_1, 2020, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_1, 2030, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_1, 2040, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::GET_READ); + + /* Cycle 1 */ + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::GET_READ); + + /* Cycl2 */ + thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::GET_READ); + + /* Cycle 3 */ + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::PERFORM_OPERATION); + 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); + +// 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); +#endif if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { sif::error << "Initialization of TE0720 PST failed" << std::endl; diff --git a/fsfwconfig/returnvalues/classIds.h b/fsfwconfig/returnvalues/classIds.h index 22bb0457..50bb3cea 100644 --- a/fsfwconfig/returnvalues/classIds.h +++ b/fsfwconfig/returnvalues/classIds.h @@ -20,7 +20,8 @@ enum { SA_DEPL_HANDLER, SYRLINKS_HANDLER, IMTQ_HANDLER, - PLOC_HANDLER + PLOC_HANDLER, + SUS_HANDLER }; } diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index bd16ddaf..c8e7b6b4 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -145,7 +145,7 @@ void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){ } uint32_t RadiationSensorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ - return 5000; + return 500; } ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 8d80322c..f8886d8f 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie, LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId) : @@ -17,6 +18,24 @@ SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCo SusHandler::~SusHandler() { } +ReturnValue_t SusHandler::initialize() { + ReturnValue_t result = RETURN_OK; + result = DeviceHandlerBase::initialize(); + if (result != RETURN_OK) { + return result; + } + auto spiComIF = dynamic_cast(communicationInterface); + if (spiComIF == nullptr) { + sif::debug << "SusHandler::initialize: Invalid communication interface" << std::endl; + return ObjectManagerIF::CHILD_INIT_FAILED; + } + spiMutex = spiComIF->getMutex(); + if (spiMutex == nullptr) { + sif::debug << "SusHandler::initialize: Failed to get spi mutex" << std::endl; + return ObjectManagerIF::CHILD_INIT_FAILED; + } + return RETURN_OK; +} void SusHandler::doStartUp(){ #if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 @@ -62,8 +81,20 @@ ReturnValue_t SusHandler::buildCommandFromCommand( * measurement the setup has to be rewritten. There must also be a little delay between * the transmission of the setup byte and the first conversion. Thus the conversion * will be performed in an extra step. + * Because the chip select is driven manually by the SusHandler the SPI bus must be + * protected with a mutex here. */ - //TODO: Protect spi bus with mutex + ReturnValue_t result = spiMutex->lockMutex(timeoutType, timeoutMs); + if(result == MutexIF::MUTEX_TIMEOUT) { + sif::error << "SusHandler::buildCommandFromCommand: Mutex timeout" << std::endl; + return ERROR_LOCK_MUTEX; + } + else if(result != HasReturnvaluesIF::RETURN_OK) { + sif::error << "SusHandler::buildCommandFromCommand: Failed to lock spi mutex" + << std::endl; + return ERROR_LOCK_MUTEX; + } + gpioComIF->pullLow(chipSelectId); cmdBuffer[0] = SUS::SETUP; rawPacket = cmdBuffer; @@ -132,6 +163,12 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, #endif /** SUS can now be shutdown and thus the SPI bus released again */ gpioComIF->pullHigh(chipSelectId); + ReturnValue_t result = spiMutex->unlockMutex(); + if (result != RETURN_OK) { + sif::error << "SusHandler::interpretDeviceReply: Failed to unlock spi mutex" + << std::endl; + return ERROR_UNLOCK_MUTEX; + } break; } default: { diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 14685dd9..4adb15fa 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -4,6 +4,7 @@ #include #include #include +#include /** * @brief This is the device handler class for the SUS sensor. The sensor is @@ -21,6 +22,8 @@ public: CookieIF * comCookie, LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId); virtual ~SusHandler(); + virtual ReturnValue_t initialize(); + protected: void doStartUp() override; void doShutDown() override; @@ -40,6 +43,11 @@ protected: private: + static const uint8_t INTERFACE_ID = CLASS_ID::SUS_HANDLER; + + static const ReturnValue_t ERROR_UNLOCK_MUTEX = MAKE_RETURN_CODE(0xA0); + static const ReturnValue_t ERROR_LOCK_MUTEX = MAKE_RETURN_CODE(0xA1); + enum class CommunicationStep { WRITE_SETUP, START_CONVERSIONS, @@ -54,6 +62,11 @@ private: uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; CommunicationStep communicationStep = CommunicationStep::WRITE_SETUP; + + MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; + uint32_t timeoutMs = 20; + + MutexIF* spiMutex = nullptr; }; #endif /* MISSION_DEVICES_SUSHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 6cc8aa65..18f33e0d 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -4,10 +4,10 @@ namespace SUS { /** - * The MAX1227 in externally clocked mode did not properly work with frequencies higher than - * 1 MHz. + * 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_MAX_1227_SPEED = 1000000; + static const uint32_t MAX1227_SPI_FREQ = 1000000; static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending @@ -46,11 +46,6 @@ namespace SUS { */ static const uint8_t CONVERSION = 0b10101001; - /** Writing this value resets the fifo */ - static const uint8_t RESET_FIFO = 0b00011000; - - static const uint8_t DUMMY_BYTE = 0x0; - static const uint8_t SUS_DATA_SET_ID = READ_CONVERSIONS; /** Size of data replies. Temperature and 6 channel convesions (AIN0 - AIN5) */ @@ -60,7 +55,6 @@ namespace SUS { static const uint8_t POOL_ENTRIES = 7; - enum Max1227PoolIds: lp_id_t { TEMPERATURE_C, AIN0, From 65d0c1fabf2e58a4600e8e691722a3720c50c873 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Wed, 12 May 2021 16:38:20 +0200 Subject: [PATCH 13/13] Sus handler complete --- bsp_q7s/InitMission.cpp | 2 +- .../pollingSequenceFactory.cpp | 77 ++++++------------- mission/devices/SusHandler.cpp | 29 ++++++- mission/devices/SusHandler.h | 13 +++- 4 files changed, 63 insertions(+), 58 deletions(-) diff --git a/bsp_q7s/InitMission.cpp b/bsp_q7s/InitMission.cpp index 534cb2ee..797c5e71 100644 --- a/bsp_q7s/InitMission.cpp +++ b/bsp_q7s/InitMission.cpp @@ -159,7 +159,7 @@ void initmission::initTasks() { #else FixedTimeslotTaskIF * pollingSequenceTaskTE0720 = factory->createFixedTimeslotTask( - "PST_TASK_TE0720", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE * 8, 5.0, + "PST_TASK_TE0720", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE * 8, 3.0, missedDeadlineFunc); result = pst::pollingSequenceTE0720(pollingSequenceTaskTE0720); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index ffa22fdc..957f22a4 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -6,6 +6,7 @@ #include #include #include +#include ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) @@ -419,66 +420,34 @@ ReturnValue_t pst::pollingSequenceTE0720(FixedTimeslotTaskIF *thisSequence) { #endif #if TEST_RADIATION_SENSOR_HANDLER == 1 -// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); #endif #if TEST_SUS_HANDLER == 1 /* Write setup */ -// thisSequence->addSlot(objects::SUS_1, 1000, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_1, 1010, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_1, 1020, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_1, 1030, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_1, 1040, DeviceHandlerIF::GET_READ); -// -// /* Start ADC conversions */ -// thisSequence->addSlot(objects::SUS_1, 1050, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_1, 1060, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_1, 1070, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_1, 1080, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_1, 1090, DeviceHandlerIF::GET_READ); -// -// /* Read ADC conversions from inernal FIFO */ -// thisSequence->addSlot(objects::SUS_1, 2000, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_1, 2010, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_1, 2020, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_1, 2030, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_1, 2040, DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.902, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.903, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.904, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.905, DeviceHandlerIF::GET_READ); - /* Cycle 1 */ - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::GET_READ); + /* Start conversion*/ + thisSequence->addSlot(objects::SUS_1, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.907, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.908, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.909, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.91, DeviceHandlerIF::GET_READ); - /* Cycl2 */ - thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::GET_READ); - - /* Cycle 3 */ - thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::PERFORM_OPERATION); - 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); - -// 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); + /* Read conversions */ + thisSequence->addSlot(objects::SUS_1, length * 0.911, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.912, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.913, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.914, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.915, DeviceHandlerIF::GET_READ); #endif if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index f8886d8f..662323cf 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -18,6 +18,28 @@ SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCo SusHandler::~SusHandler() { } +ReturnValue_t SusHandler::performOperation(uint8_t counter) { + + if (counter != FIRST_WRITE) { + DeviceHandlerBase::performOperation(counter); + return RETURN_OK; + } + + if (mode != MODE_NORMAL) { + DeviceHandlerBase::performOperation(DeviceHandlerIF::SEND_WRITE); + return RETURN_OK; + } + + /* If device is in normale mode the communication sequence is initiated here */ + if (communicationStep == CommunicationStep::IDLE) { + communicationStep = CommunicationStep::WRITE_SETUP; + } + + DeviceHandlerBase::performOperation(DeviceHandlerIF::SEND_WRITE); + + return RETURN_OK; +} + ReturnValue_t SusHandler::initialize() { ReturnValue_t result = RETURN_OK; result = DeviceHandlerBase::initialize(); @@ -51,6 +73,11 @@ void SusHandler::doShutDown(){ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { + + if (communicationStep == CommunicationStep::IDLE) { + return NOTHING_TO_SEND; + } + if (communicationStep == CommunicationStep::WRITE_SETUP) { *id = SUS::WRITE_SETUP; communicationStep = CommunicationStep::START_CONVERSIONS; @@ -61,7 +88,7 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( } else if (communicationStep == CommunicationStep::READ_CONVERSIONS) { *id = SUS::READ_CONVERSIONS; - communicationStep = CommunicationStep::WRITE_SETUP; + communicationStep = CommunicationStep::IDLE; } return buildCommandFromCommand(*id, nullptr, 0); } diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 4adb15fa..c73cee97 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -13,16 +13,24 @@ * * @details Datasheet of MAX1227: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf * + * @note When adding a SusHandler to the polling sequence table make sure to add a slot with + * the executionStep FIRST_WRITE. Otherwise the communication sequence will never be + * started. + * * @author J. Meier */ class SusHandler: public DeviceHandlerBase { public: + static const uint8_t FIRST_WRITE = 7; + SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie, LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId); virtual ~SusHandler(); - virtual ReturnValue_t initialize(); + virtual ReturnValue_t performOperation(uint8_t counter) override; + + virtual ReturnValue_t initialize() override; protected: void doStartUp() override; @@ -49,6 +57,7 @@ private: static const ReturnValue_t ERROR_LOCK_MUTEX = MAKE_RETURN_CODE(0xA1); enum class CommunicationStep { + IDLE, WRITE_SETUP, START_CONVERSIONS, READ_CONVERSIONS @@ -61,7 +70,7 @@ private: SUS::SusDataset dataset; uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; - CommunicationStep communicationStep = CommunicationStep::WRITE_SETUP; + CommunicationStep communicationStep = CommunicationStep::IDLE; MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; uint32_t timeoutMs = 20;