From ed6eea82c5e5929aff615ec2e3efd8d26f3e6891 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 29 Apr 2021 10:40:11 +0200 Subject: [PATCH 01/21] max1227 wip --- mission/devices/IMTQHandler.cpp | 4 +- mission/devices/Max1227Handler.cpp | 145 ++++++++++++++++++ mission/devices/Max1227Handler.h | 64 ++++++++ .../devicedefinitions/Max1227Definitions.h | 47 ++++++ tmtc | 2 +- 5 files changed, 260 insertions(+), 2 deletions(-) create mode 100644 mission/devices/Max1227Handler.cpp create mode 100644 mission/devices/Max1227Handler.h create mode 100644 mission/devices/devicedefinitions/Max1227Definitions.h diff --git a/mission/devices/IMTQHandler.cpp b/mission/devices/IMTQHandler.cpp index 2051849f..3111c39d 100644 --- a/mission/devices/IMTQHandler.cpp +++ b/mission/devices/IMTQHandler.cpp @@ -33,7 +33,9 @@ ReturnValue_t IMTQHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { switch (communicationStep) { case CommunicationStep::SELF_TEST: - *id = IMTQ::SELF_TEST; +// *id = IMTQ::SELF_TEST; +//TODO: Implementing self test command. On-hold because of issue with humidity in clean +// room communicationStep = CommunicationStep::GET_ENG_HK_DATA; break; case CommunicationStep::GET_ENG_HK_DATA: diff --git a/mission/devices/Max1227Handler.cpp b/mission/devices/Max1227Handler.cpp new file mode 100644 index 00000000..2ecfce9c --- /dev/null +++ b/mission/devices/Max1227Handler.cpp @@ -0,0 +1,145 @@ +#include +#include +#include + +Max1227Handler::Max1227Handler(object_id_t objectId, object_id_t comIF, + CookieIF * comCookie) : + DeviceHandlerBase(objectId, comIF, comCookie), dataset( + this) { + if (comCookie == NULL) { + sif::error << "Max1227Handler: Invalid com cookie" << std::endl; + } +} + +Max1227Handler::~Max1227Handler() { +} + + +void Max1227Handler::doStartUp(){ + if(mode == _MODE_START_UP){ + setMode(MODE_ON); + } +} + +void Max1227Handler::doShutDown(){ + +} + +ReturnValue_t Max1227Handler::buildNormalDeviceCommand( + DeviceCommandId_t * id) { + + if(communicationStep == CommunicationStep::START_ADC_CONVERSION) { + *id = TMP1075::START_ADC_CONVERSION; + communicationStep = CommunicationStep::GET_TEMPERATURE; + return buildCommandFromCommand(*id, NULL, 0); + } + else { + *id = TMP1075::GET_TEMP; + communicationStep = CommunicationStep::START_ADC_CONVERSION; + return buildCommandFromCommand(*id, NULL, 0); + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t Max1227Handler::buildTransitionDeviceCommand( + DeviceCommandId_t * id){ + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t Max1227Handler::buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t * commandData, + size_t commandDataLen) { + switch(deviceCommand) { + case(TMP1075::START_ADC_CONVERSION): { + std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); + prepareAdcConversionCommand(); + rawPacket = cmdBuffer; + rawPacketLen = TMP1075::CFGR_CMD_SIZE; + return RETURN_OK; + } + case(TMP1075::GET_TEMP): { + std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); + prepareGetTempCommand(); + rawPacket = cmdBuffer; + rawPacketLen = TMP1075::POINTER_REG_SIZE; + rememberCommandId = TMP1075::GET_TEMP; + return RETURN_OK; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; +} + +void Max1227Handler::fillCommandAndReplyMap(){ + this->insertInCommandMap(TMP1075::START_ADC_CONVERSION); + this->insertInCommandAndReplyMap(TMP1075::GET_TEMP, 1, &dataset, + TMP1075::GET_TEMP_REPLY_SIZE); +} + +ReturnValue_t Max1227Handler::scanForReply(const uint8_t *start, + size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) { + switch(rememberCommandId) { + case(TMP1075::GET_TEMP): + *foundId = TMP1075::GET_TEMP; + *foundLen = TMP1075::GET_TEMP_REPLY_SIZE; + rememberCommandId = TMP1075::NONE; + break; + default: + return IGNORE_REPLY_DATA; + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t Max1227Handler::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) { + switch (id) { + case TMP1075::GET_TEMP: { + int16_t tempValueRaw = 0; + tempValueRaw = packet[0] << 4 | packet[1] >> 4; + float tempValue = ((static_cast(tempValueRaw)) * 0.0625); +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "Tmp1075 with object id: 0x" << std::hex << getObjectId() + << ": Temperature: " << tempValue<< " °C" + << std::endl; +#endif + ReturnValue_t result = dataset.read(); + if(result == HasReturnvaluesIF::RETURN_OK) { + dataset.temperatureCelcius = tempValue; + dataset.commit(); + } + break; + } + + default: { + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } + + } + return HasReturnvaluesIF::RETURN_OK; +} + +void Max1227Handler::setNormalDatapoolEntriesInvalid(){ + +} + +void Max1227Handler::prepareAdcConversionCommand(){ + cmdBuffer[0] = TMP1075::CFGR_ADDR; + cmdBuffer[1] = TMP1075::ONE_SHOT_MODE >> 8; + cmdBuffer[2] = TMP1075::ONE_SHOT_MODE & 0xFF; +} + +void Max1227Handler::prepareGetTempCommand(){ + cmdBuffer[0] = TMP1075::TEMP_REG_ADDR; +} + +uint32_t Max1227Handler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ + return 500; +} + +ReturnValue_t Max1227Handler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) { + localDataPoolMap.emplace(TMP1075::TEMPERATURE_C_TMP1075_1, new PoolEntry( { 0.0 })); + return HasReturnvaluesIF::RETURN_OK; +} + diff --git a/mission/devices/Max1227Handler.h b/mission/devices/Max1227Handler.h new file mode 100644 index 00000000..76584559 --- /dev/null +++ b/mission/devices/Max1227Handler.h @@ -0,0 +1,64 @@ +#ifndef MISSION_DEVICES_MAX1227HANDLER_H_ +#define MISSION_DEVICES_MAX1227HANDLER_H_ + +#include +#include + +/** + * @brief This is the device handler class for the MAX1227 ADC converter. + * + * @details Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf + * + * @author J. Meier + */ +class Max1227Handler: public DeviceHandlerBase { +public: + + Max1227Handler(object_id_t objectId, object_id_t comIF, + CookieIF * comCookie); + virtual ~Max1227Handler(); + +protected: + void doStartUp() override; + void doShutDown() override; + ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) override; + ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) override; + void fillCommandAndReplyMap() override; + ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, + const uint8_t * commandData,size_t commandDataLen) override; + ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, + DeviceCommandId_t *foundId, size_t *foundLen) override; + ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) override; + void setNormalDatapoolEntriesInvalid() override; + uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) override; + +private: + + /** + * @brief Function fills cmdBuffer with command to start the adc + * conversion for a new temperature value. + */ + void prepareAdcConversionCommand(); + + void prepareGetTempCommand(); + + enum class CommunicationStep { + START_ADC_CONVERSION, + GET_TEMPERATURE + }; + + TMP1075::Tmp1075Dataset dataset; + + static const uint8_t MAX_CMD_LEN = 3; + + uint8_t rememberRequestedSize = 0; + uint8_t rememberCommandId = TMP1075::NONE; + uint8_t cmdBuffer[MAX_CMD_LEN]; + CommunicationStep communicationStep = + CommunicationStep::START_ADC_CONVERSION; +}; + +#endif /* MISSION_DEVICES_MAX1227HANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/Max1227Definitions.h b/mission/devices/devicedefinitions/Max1227Definitions.h new file mode 100644 index 00000000..49d83cf3 --- /dev/null +++ b/mission/devices/devicedefinitions/Max1227Definitions.h @@ -0,0 +1,47 @@ +#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ +#define MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ + +namespace MAX1227 { + static const uint8_t TEMP_REG_ADDR = 0x0; + static const uint8_t CFGR_ADDR = 0x1; + + /* Writing this information to the configuration register sets the tmp1075 + * to shutdown mode and starts a single temperature conversion */ + static const uint16_t ONE_SHOT_MODE = 0x8100; + + static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending + static const DeviceCommandId_t GET_TEMP = 0x1; + static const DeviceCommandId_t START_ADC_CONVERSION = 0x2; + + static const uint8_t GET_TEMP_REPLY_SIZE = 2; + static const uint8_t CFGR_CMD_SIZE = 3; + static const uint8_t POINTER_REG_SIZE = 1; + + static const uint32_t TMP1075_DATA_SET_ID = GET_TEMP; + + static const uint8_t MAX_REPLY_LENGTH = GET_TEMP_REPLY_SIZE; + + enum Tmp1075PoolIds: lp_id_t { + TEMPERATURE_C_TMP1075_1, + TEMPERATURE_C_TMP1075_2 + }; + +class Tmp1075Dataset: + public StaticLocalDataSet { +public: + + Tmp1075Dataset(HasLocalDataPoolIF* owner): + StaticLocalDataSet(owner, TMP1075_DATA_SET_ID) { + } + + Tmp1075Dataset(object_id_t objectId): + StaticLocalDataSet(sid_t(objectId, TMP1075_DATA_SET_ID)) { + } + + lp_var_t temperatureCelcius = lp_var_t(sid.objectId, + TEMPERATURE_C_TMP1075_1, this); +}; +} + + +#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ */ diff --git a/tmtc b/tmtc index e23bc116..06750809 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit e23bc116088fc673aaec45768c7a07c20d75a2f6 +Subproject commit 06750809cb52044392e0683896538a652f11a512 From b87383164509a51a7f2654b0b5e477f65a85b6fa Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 2 May 2021 13:48:39 +0200 Subject: [PATCH 02/21] spi decoder callbacks wip --- README.md | 2 +- bsp_q7s/ObjectFactory.cpp | 19 +- bsp_q7s/boardconfig/q7s_config.h | 2 +- bsp_q7s/gpio/gpioCallbacks.cpp | 204 ++++++++++-------- bsp_q7s/gpio/gpioCallbacks.h | 34 +++ fsfwconfig/OBSWConfig.h | 3 +- fsfwconfig/devices/addresses.h | 2 + fsfwconfig/devices/gpioIds.h | 4 +- fsfwconfig/devices/spi.h | 3 + fsfwconfig/objects/systemObjectList.h | 2 + .../pollingSequenceFactory.cpp | 8 + mission/devices/CMakeLists.txt | 1 + mission/devices/Max1227Handler.cpp | 145 ------------- mission/devices/RadiationSensorHandler.cpp | 158 ++++++++++++++ ...1227Handler.h => RadiationSensorHandler.h} | 46 ++-- .../devicedefinitions/Max1227Definitions.h | 47 ---- .../devicedefinitions/RadSensorDefinitions.h | 79 +++++++ 17 files changed, 447 insertions(+), 312 deletions(-) delete mode 100644 mission/devices/Max1227Handler.cpp create mode 100644 mission/devices/RadiationSensorHandler.cpp rename mission/devices/{Max1227Handler.h => RadiationSensorHandler.h} (53%) delete mode 100644 mission/devices/devicedefinitions/Max1227Definitions.h create mode 100644 mission/devices/devicedefinitions/RadSensorDefinitions.h diff --git a/README.md b/README.md index 44d699d1..ec32a2bb 100644 --- a/README.md +++ b/README.md @@ -266,7 +266,7 @@ To transfer files from the local machine to the Q7S, use port forwarding ssh -L 1535:192.168.133.10:22 eive@2001:7c0:2018:1099:babe:0:e1fe:f1a5 ``` -Then you can copy an `example` file like this +An `example` file can be copied like this ```sh scp -P 1535 example root@localhost:/tmp diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 77148be8..9d0b9ecb 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -20,16 +20,18 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #include +#include +#include #include #include @@ -428,12 +430,27 @@ void ObjectFactory::produce(){ std::string("/dev/i2c-0")); IMTQHandler* imtqHandler = new IMTQHandler(objects::IMTQ_HANDLER, objects::I2C_COM_IF, imtqI2cCookie); // imtqHandler->setStartUpImmediately(); + (void) imtqHandler; UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyUL3"), 115200, PLOC::MAX_REPLY_SIZE); PlocHandler* plocHandler = new PlocHandler(objects::PLOC_HANDLER, objects::UART_COM_IF, plocUartCookie); // 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 */ diff --git a/bsp_q7s/boardconfig/q7s_config.h b/bsp_q7s/boardconfig/q7s_config.h index 3d1bc8ad..782ecf4f 100644 --- a/bsp_q7s/boardconfig/q7s_config.h +++ b/bsp_q7s/boardconfig/q7s_config.h @@ -5,7 +5,7 @@ /* Only one of those 2 should be enabled! */ /* Add code for ACS board */ -#define OBSW_ADD_ACS_BOARD 1 +#define OBSW_ADD_ACS_BOARD 0 #define Q7S_ADD_SPI_TEST 0 diff --git a/bsp_q7s/gpio/gpioCallbacks.cpp b/bsp_q7s/gpio/gpioCallbacks.cpp index 086e6469..afdc90b6 100644 --- a/bsp_q7s/gpio/gpioCallbacks.cpp +++ b/bsp_q7s/gpio/gpioCallbacks.cpp @@ -22,19 +22,20 @@ void initTcsBoardDecoder(GpioIF* gpioComIF) { gpioComInterface = gpioComIF; GpioCookie* spiMuxGpios = new GpioCookie; - /** - * Initial values of the spi mux gpios can all be set to an arbitrary value expect for spi mux - * bit 1. Setting spi mux bit 1 to high will pull all decoder outputs to high voltage level. - */ + + /** Setting mux bit 1 to low will disable IC21 on the interface board */ GpiodRegular* spiMuxBit1 = new GpiodRegular(std::string("gpiochip7"), 13, - std::string("SPI Mux Bit 1"), gpio::OUT, 1); + std::string("SPI Mux Bit 1"), gpio::OUT, 0); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, spiMuxBit1); + /** Setting mux bit 2 to low disables IC1 on the TCS board */ GpiodRegular* spiMuxBit2 = new GpiodRegular(std::string("gpiochip7"), 14, std::string("SPI Mux Bit 2"), gpio::OUT, 0); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_2, spiMuxBit2); + /** Setting mux bit 3 to low disables IC2 on the TCS board and IC22 on the interface board */ GpiodRegular* spiMuxBit3 = new GpiodRegular(std::string("gpiochip7"), 15, std::string("SPI Mux Bit 3"), gpio::OUT, 0); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_3, spiMuxBit3); + /** The following gpios can take arbitrary initial values */ GpiodRegular* spiMuxBit4 = new GpiodRegular(std::string("gpiochip7"), 16, std::string("SPI Mux Bit 4"), gpio::OUT, 0); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_4, spiMuxBit4); @@ -74,136 +75,93 @@ void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int va else if (value == 0) { switch (gpioId) { case(gpioIds::RTD_IC3): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY7(); break; } case(gpioIds::RTD_IC4): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY6(); break; } case(gpioIds::RTD_IC5): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY5(); break; } case(gpioIds::RTD_IC6): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY4(); break; } case(gpioIds::RTD_IC7): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY3(); break; } case(gpioIds::RTD_IC8): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY2(); break; } case(gpioIds::RTD_IC9): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY1(); break; } case(gpioIds::RTD_IC10): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY0(); break; } case(gpioIds::RTD_IC11): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY7(); break; } case(gpioIds::RTD_IC12): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY6(); break; } case(gpioIds::RTD_IC13): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY5(); break; } case(gpioIds::RTD_IC14): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY4(); break; } case(gpioIds::RTD_IC15): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY3(); break; } case(gpioIds::RTD_IC16): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY2(); break; } case(gpioIds::RTD_IC17): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY1(); break; } case(gpioIds::RTD_IC18): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); + enableDecoderTcsIc2(); + selectY0(); + break; + } + case(gpioIds::CS_SUS_1): { + enableDecoderInterfaceBoardIc21(); + selectY0(); + break; + } + case(gpioIds::CS_SUS_2): { + enableDecoderInterfaceBoardIc21(); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); @@ -218,4 +176,70 @@ void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int va } } +void enableDecoderTcsIc1() { + +} + +void enableDecoderTcsIc2() { + +} + +void enableDecoderInterfaceBoardIc21() { + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); +} + +void enableDecoderInterfaceBoardIc22() { + +} + +void selectY0() { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); +} + +void selectY1() { + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); +} + +void selectY2() { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); +} + +void selectY3() { + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); +} + +void selectY4() { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); +} + +void selectY5() { + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); +} + +void selectY6() { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); +} + +void selectY7() { + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); +} + } diff --git a/bsp_q7s/gpio/gpioCallbacks.h b/bsp_q7s/gpio/gpioCallbacks.h index 845127fb..3cfd4884 100644 --- a/bsp_q7s/gpio/gpioCallbacks.h +++ b/bsp_q7s/gpio/gpioCallbacks.h @@ -18,6 +18,40 @@ namespace gpioCallbacks { * chips SN74LVC138APWR on the TCS board. */ void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args); + + /** + * @brief This function sets mux bits 1-3 to a state which will only enable the decoder + * on the TCS board which is named to IC1 in the schematic. + */ + void enableDecoderTcsIc1(); + + /** + * @brief This function sets mux bits 1-3 to a state which will only enable the decoder + * on the TCS board which is named to IC2 in the schematic. + */ + void enableDecoderTcsIc2(); + + /** + * @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(); + + /** + * @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(); + + /** The following functions enable the appropriate channel of the currently enabled decoder */ + void selectY0(); + void selectY1(); + void selectY2(); + void selectY3(); + void selectY4(); + void selectY5(); + void selectY6(); + void selectY7(); } #endif /* LINUX_GPIO_GPIOCALLBACKS_H_ */ diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 0b9320e1..be770ad1 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -29,7 +29,8 @@ debugging. */ #define PDU2_DEBUG 0 #define ACU_DEBUG 0 #define SYRLINKS_DEBUG 0 -#define IMQT_DEBUG 1 +#define IMQT_DEBUG 0 +#define DEBUG_RAD_SENSOR 1 #include "OBSWVersion.h" diff --git a/fsfwconfig/devices/addresses.h b/fsfwconfig/devices/addresses.h index 4974834d..26a86b2a 100644 --- a/fsfwconfig/devices/addresses.h +++ b/fsfwconfig/devices/addresses.h @@ -19,6 +19,8 @@ namespace addresses { GYRO_1_L3G = objects::GYRO_1_L3G_HANDLER, GYRO_2_L3G = objects::GYRO_2_L3G_HANDLER, + RAD_SENSOR = objects::RAD_SENSOR, + /* Dummy and Test Addresses */ DUMMY_ECHO = 129, DUMMY_GPS0 = 130, diff --git a/fsfwconfig/devices/gpioIds.h b/fsfwconfig/devices/gpioIds.h index ac999152..8b9edffc 100644 --- a/fsfwconfig/devices/gpioIds.h +++ b/fsfwconfig/devices/gpioIds.h @@ -49,7 +49,9 @@ namespace gpioIds { SPI_MUX_BIT_3, SPI_MUX_BIT_4, SPI_MUX_BIT_5, - SPI_MUX_BIT_6 + SPI_MUX_BIT_6, + + CS_RAD_SENSOR }; } diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index 55271a40..eb17786b 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -20,6 +20,9 @@ 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 spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; + } diff --git a/fsfwconfig/objects/systemObjectList.h b/fsfwconfig/objects/systemObjectList.h index 72dcfc21..1249b862 100644 --- a/fsfwconfig/objects/systemObjectList.h +++ b/fsfwconfig/objects/systemObjectList.h @@ -82,6 +82,8 @@ namespace objects { RTD_IC17 = 0x5400003F, RTD_IC18 = 0x5400004F, + RAD_SENSOR = 0x54000050, + /* 0x54 ('T') for test handlers */ TEST_TASK = 0x54694269, LIBGPIOD_TEST = 0x54123456, diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 01f47b39..a54d70ba 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -142,6 +142,14 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) thisSequence->addSlot(objects::IMTQ_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); + + /* 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); + if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; } diff --git a/mission/devices/CMakeLists.txt b/mission/devices/CMakeLists.txt index 7d34aac9..4088d98b 100644 --- a/mission/devices/CMakeLists.txt +++ b/mission/devices/CMakeLists.txt @@ -14,6 +14,7 @@ target_sources(${TARGET_NAME} PUBLIC Max31865PT1000Handler.cpp IMTQHandler.cpp PlocHandler.cpp + RadiationSensorHandler.cpp ) diff --git a/mission/devices/Max1227Handler.cpp b/mission/devices/Max1227Handler.cpp deleted file mode 100644 index 2ecfce9c..00000000 --- a/mission/devices/Max1227Handler.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include -#include -#include - -Max1227Handler::Max1227Handler(object_id_t objectId, object_id_t comIF, - CookieIF * comCookie) : - DeviceHandlerBase(objectId, comIF, comCookie), dataset( - this) { - if (comCookie == NULL) { - sif::error << "Max1227Handler: Invalid com cookie" << std::endl; - } -} - -Max1227Handler::~Max1227Handler() { -} - - -void Max1227Handler::doStartUp(){ - if(mode == _MODE_START_UP){ - setMode(MODE_ON); - } -} - -void Max1227Handler::doShutDown(){ - -} - -ReturnValue_t Max1227Handler::buildNormalDeviceCommand( - DeviceCommandId_t * id) { - - if(communicationStep == CommunicationStep::START_ADC_CONVERSION) { - *id = TMP1075::START_ADC_CONVERSION; - communicationStep = CommunicationStep::GET_TEMPERATURE; - return buildCommandFromCommand(*id, NULL, 0); - } - else { - *id = TMP1075::GET_TEMP; - communicationStep = CommunicationStep::START_ADC_CONVERSION; - return buildCommandFromCommand(*id, NULL, 0); - } - return HasReturnvaluesIF::RETURN_OK; -} - -ReturnValue_t Max1227Handler::buildTransitionDeviceCommand( - DeviceCommandId_t * id){ - return HasReturnvaluesIF::RETURN_OK; -} - -ReturnValue_t Max1227Handler::buildCommandFromCommand( - DeviceCommandId_t deviceCommand, const uint8_t * commandData, - size_t commandDataLen) { - switch(deviceCommand) { - case(TMP1075::START_ADC_CONVERSION): { - std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - prepareAdcConversionCommand(); - rawPacket = cmdBuffer; - rawPacketLen = TMP1075::CFGR_CMD_SIZE; - return RETURN_OK; - } - case(TMP1075::GET_TEMP): { - std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - prepareGetTempCommand(); - rawPacket = cmdBuffer; - rawPacketLen = TMP1075::POINTER_REG_SIZE; - rememberCommandId = TMP1075::GET_TEMP; - return RETURN_OK; - } - default: - return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; - } - return HasReturnvaluesIF::RETURN_FAILED; -} - -void Max1227Handler::fillCommandAndReplyMap(){ - this->insertInCommandMap(TMP1075::START_ADC_CONVERSION); - this->insertInCommandAndReplyMap(TMP1075::GET_TEMP, 1, &dataset, - TMP1075::GET_TEMP_REPLY_SIZE); -} - -ReturnValue_t Max1227Handler::scanForReply(const uint8_t *start, - size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) { - switch(rememberCommandId) { - case(TMP1075::GET_TEMP): - *foundId = TMP1075::GET_TEMP; - *foundLen = TMP1075::GET_TEMP_REPLY_SIZE; - rememberCommandId = TMP1075::NONE; - break; - default: - return IGNORE_REPLY_DATA; - } - return HasReturnvaluesIF::RETURN_OK; -} - -ReturnValue_t Max1227Handler::interpretDeviceReply(DeviceCommandId_t id, - const uint8_t *packet) { - switch (id) { - case TMP1075::GET_TEMP: { - int16_t tempValueRaw = 0; - tempValueRaw = packet[0] << 4 | packet[1] >> 4; - float tempValue = ((static_cast(tempValueRaw)) * 0.0625); -#if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "Tmp1075 with object id: 0x" << std::hex << getObjectId() - << ": Temperature: " << tempValue<< " °C" - << std::endl; -#endif - ReturnValue_t result = dataset.read(); - if(result == HasReturnvaluesIF::RETURN_OK) { - dataset.temperatureCelcius = tempValue; - dataset.commit(); - } - break; - } - - default: { - return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; - } - - } - return HasReturnvaluesIF::RETURN_OK; -} - -void Max1227Handler::setNormalDatapoolEntriesInvalid(){ - -} - -void Max1227Handler::prepareAdcConversionCommand(){ - cmdBuffer[0] = TMP1075::CFGR_ADDR; - cmdBuffer[1] = TMP1075::ONE_SHOT_MODE >> 8; - cmdBuffer[2] = TMP1075::ONE_SHOT_MODE & 0xFF; -} - -void Max1227Handler::prepareGetTempCommand(){ - cmdBuffer[0] = TMP1075::TEMP_REG_ADDR; -} - -uint32_t Max1227Handler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ - return 500; -} - -ReturnValue_t Max1227Handler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, - LocalDataPoolManager& poolManager) { - localDataPoolMap.emplace(TMP1075::TEMPERATURE_C_TMP1075_1, new PoolEntry( { 0.0 })); - return HasReturnvaluesIF::RETURN_OK; -} - diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp new file mode 100644 index 00000000..64391c79 --- /dev/null +++ b/mission/devices/RadiationSensorHandler.cpp @@ -0,0 +1,158 @@ +#include +#include +#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; + } +} + +RadiationSensorHandler::~RadiationSensorHandler() { +} + + +void RadiationSensorHandler::doStartUp(){ + if (internalState == InternalState::CONFIGURED) { +#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 + setMode(MODE_NORMAL); +#else + setMode(_MODE_TO_ON); +#endif + } +} + +void RadiationSensorHandler::doShutDown(){ + setMode(_MODE_POWER_DOWN); +} + +ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( + 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; + communicationStep = CommunicationStep::READ_CONVERSIONS; + 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){ + if (internalState == InternalState::SETUP) { + *id = RAD_SENSOR::WRITE_SETUP; + } + else { + return HasReturnvaluesIF::RETURN_OK; + } + 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::START_CONVERSION): { + cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = 1; + 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; + cmdBuffer[6] = RAD_SENSOR::DUMMY_BYTE; + 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->insertInCommandMap(RAD_SENSOR::START_CONVERSION); + this->insertInCommandAndReplyMap(RAD_SENSOR::READ_CONVERSIONS, 1, &dataset, + RAD_SENSOR::READ_SIZE); +} + +ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, + size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) { + *foundId = this->getPendingCommand(); + *foundLen = remainingSize; + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) { + 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; + sif::info << "Radiation sensor temperature ADC value channel 0: " << dataset.channel0 + << std::endl; + 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; + } + + } + return HasReturnvaluesIF::RETURN_OK; +} + +void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){ + +} + +uint32_t RadiationSensorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ + return 5000; +} + +ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) { + localDataPoolMap.emplace(RAD_SENSOR::TEMPERATURE_C, new PoolEntry( { 0.0 })); + localDataPoolMap.emplace(RAD_SENSOR::CHANNEL_0, new PoolEntry( { 0 })); + localDataPoolMap.emplace(RAD_SENSOR::CHANNEL_1, new PoolEntry( { 0 })); + return HasReturnvaluesIF::RETURN_OK; +} + diff --git a/mission/devices/Max1227Handler.h b/mission/devices/RadiationSensorHandler.h similarity index 53% rename from mission/devices/Max1227Handler.h rename to mission/devices/RadiationSensorHandler.h index 76584559..5612a1e0 100644 --- a/mission/devices/Max1227Handler.h +++ b/mission/devices/RadiationSensorHandler.h @@ -1,22 +1,23 @@ -#ifndef MISSION_DEVICES_MAX1227HANDLER_H_ -#define MISSION_DEVICES_MAX1227HANDLER_H_ +#ifndef MISSION_DEVICES_RADIATIONSENSORHANDLER_H_ +#define MISSION_DEVICES_RADIATIONSENSORHANDLER_H_ #include -#include +#include /** - * @brief This is the device handler class for the MAX1227 ADC converter. + * @brief This is the device handler class for radiation sensor on the OBC IF Board. The sensor + * is based on the MAX1227 ADC converter. * - * @details Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf + * @details Datasheet of MAX1227: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf * * @author J. Meier */ -class Max1227Handler: public DeviceHandlerBase { +class RadiationSensorHandler: public DeviceHandlerBase { public: - Max1227Handler(object_id_t objectId, object_id_t comIF, + RadiationSensorHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie); - virtual ~Max1227Handler(); + virtual ~RadiationSensorHandler(); protected: void doStartUp() override; @@ -37,28 +38,23 @@ protected: private: - /** - * @brief Function fills cmdBuffer with command to start the adc - * conversion for a new temperature value. - */ - void prepareAdcConversionCommand(); - - void prepareGetTempCommand(); - enum class CommunicationStep { - START_ADC_CONVERSION, - GET_TEMPERATURE + START_CONVERSION, + READ_CONVERSIONS }; - TMP1075::Tmp1075Dataset dataset; + enum class InternalState { + SETUP, + CONFIGURED + }; - static const uint8_t MAX_CMD_LEN = 3; + RAD_SENSOR::RadSensorDataset dataset; + + static const uint8_t MAX_CMD_LEN = RAD_SENSOR::READ_SIZE; - uint8_t rememberRequestedSize = 0; - uint8_t rememberCommandId = TMP1075::NONE; uint8_t cmdBuffer[MAX_CMD_LEN]; - CommunicationStep communicationStep = - CommunicationStep::START_ADC_CONVERSION; + InternalState internalState = InternalState::SETUP; + CommunicationStep communicationStep = CommunicationStep::START_CONVERSION; }; -#endif /* MISSION_DEVICES_MAX1227HANDLER_H_ */ +#endif /* MISSION_DEVICES_RADIATIONSENSORHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/Max1227Definitions.h b/mission/devices/devicedefinitions/Max1227Definitions.h deleted file mode 100644 index 49d83cf3..00000000 --- a/mission/devices/devicedefinitions/Max1227Definitions.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ -#define MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ - -namespace MAX1227 { - static const uint8_t TEMP_REG_ADDR = 0x0; - static const uint8_t CFGR_ADDR = 0x1; - - /* Writing this information to the configuration register sets the tmp1075 - * to shutdown mode and starts a single temperature conversion */ - static const uint16_t ONE_SHOT_MODE = 0x8100; - - static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending - static const DeviceCommandId_t GET_TEMP = 0x1; - static const DeviceCommandId_t START_ADC_CONVERSION = 0x2; - - static const uint8_t GET_TEMP_REPLY_SIZE = 2; - static const uint8_t CFGR_CMD_SIZE = 3; - static const uint8_t POINTER_REG_SIZE = 1; - - static const uint32_t TMP1075_DATA_SET_ID = GET_TEMP; - - static const uint8_t MAX_REPLY_LENGTH = GET_TEMP_REPLY_SIZE; - - enum Tmp1075PoolIds: lp_id_t { - TEMPERATURE_C_TMP1075_1, - TEMPERATURE_C_TMP1075_2 - }; - -class Tmp1075Dataset: - public StaticLocalDataSet { -public: - - Tmp1075Dataset(HasLocalDataPoolIF* owner): - StaticLocalDataSet(owner, TMP1075_DATA_SET_ID) { - } - - Tmp1075Dataset(object_id_t objectId): - StaticLocalDataSet(sid_t(objectId, TMP1075_DATA_SET_ID)) { - } - - lp_var_t temperatureCelcius = lp_var_t(sid.objectId, - TEMPERATURE_C_TMP1075_1, this); -}; -} - - -#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ */ diff --git a/mission/devices/devicedefinitions/RadSensorDefinitions.h b/mission/devices/devicedefinitions/RadSensorDefinitions.h new file mode 100644 index 00000000..46e5be40 --- /dev/null +++ b/mission/devices/devicedefinitions/RadSensorDefinitions.h @@ -0,0 +1,79 @@ +#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ +#define MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ + +namespace RAD_SENSOR { + + 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 START_CONVERSION = 0x2; + static const DeviceCommandId_t READ_CONVERSIONS = 0x3; + + static const uint32_t MAX1227_DATA_SET_ID = READ_CONVERSIONS; + + /** + * @brief This is the configuration byte which will be written to the setup register after + * power on. + * + * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, no data follows the setup byte + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b01, external reference single ended + * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, MAX1227 uses internal oscillator for timing + * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register + * + */ + static const uint8_t SETUP_DEFINITION = 0b01101000; + + /** + * @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) + * Bit6 - Bit3 defines N: 0b0001 (N = 1) + * Bit7: Always 1. Tells the ADC that this is the conversion register. + */ + static const uint8_t CONVERSION_DEFINITION = 0b10001001; + + /** + * Unipolar only required for differential measurement. Unipolar or dipolar determines the + * voltage range. + */ + static const uint8_t UNIPOLAR_SETUP = 0b10000000; + + static const uint8_t DUMMY_BYTE = 0xFF; + + static const uint8_t RAD_SENSOR_DATA_SET_ID = READ_CONVERSIONS; + + /** + * One temperature value, conversion of channel 0 and conversion of channel 1 + */ + static const uint8_t READ_SIZE = 6; + + enum Max1227PoolIds: lp_id_t { + TEMPERATURE_C, + CHANNEL_0, + CHANNEL_1, + }; + +class RadSensorDataset: public StaticLocalDataSet { +public: + + RadSensorDataset(HasLocalDataPoolIF* owner) : + StaticLocalDataSet(owner, RAD_SENSOR_DATA_SET_ID) { + } + + RadSensorDataset(object_id_t objectId) : + StaticLocalDataSet(sid_t(objectId, RAD_SENSOR_DATA_SET_ID)) { + } + + lp_var_t temperatureCelcius = lp_var_t(sid.objectId, TEMPERATURE_C, this); + lp_var_t channel0 = lp_var_t(sid.objectId, CHANNEL_0, this); + lp_var_t channel1 = lp_var_t(sid.objectId, CHANNEL_1, this); +}; +} + + +#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ */ From f708a67fa8b305c0b2d97d1d65b84dd6ef15e6fd Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 3 May 2021 11:59:33 +0200 Subject: [PATCH 03/21] rad sensor change wip --- bsp_q7s/ObjectFactory.cpp | 137 ++++++++++++--- bsp_q7s/gpio/gpioCallbacks.cpp | 84 +++++++-- bsp_q7s/gpio/gpioCallbacks.h | 10 +- fsfwconfig/OBSWConfig.h | 3 +- fsfwconfig/devices/addresses.h | 14 ++ fsfwconfig/devices/gpioIds.h | 14 ++ fsfwconfig/objects/systemObjectList.h | 14 ++ .../pollingSequenceFactory.cpp | 7 + mission/devices/CMakeLists.txt | 1 + mission/devices/RadiationSensorHandler.cpp | 51 ++---- mission/devices/SusHandler.cpp | 165 ++++++++++++++++++ mission/devices/SusHandler.h | 61 +++++++ .../devicedefinitions/RadSensorDefinitions.h | 11 +- .../devicedefinitions/SusDefinitions.h | 83 +++++++++ 14 files changed, 563 insertions(+), 92 deletions(-) create mode 100644 mission/devices/SusHandler.cpp create mode 100644 mission/devices/SusHandler.h create mode 100644 mission/devices/devicedefinitions/SusDefinitions.h diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 9d0b9ecb..776a3e4b 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -26,11 +26,13 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -106,14 +108,8 @@ void ObjectFactory::produce(){ #endif /* Temperature sensors */ - Tmp1075Handler* tmp1075Handler_1 = new Tmp1075Handler( - objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, - i2cCookieTmp1075tcs1); -// tmp1075Handler_1->setStartUpImmediately(); - Tmp1075Handler* tmp1075Handler_2 = new Tmp1075Handler( - objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, - i2cCookieTmp1075tcs2); -// tmp1075Handler_2->setStartUpImmediately(); + 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; @@ -151,6 +147,98 @@ void ObjectFactory::produce(){ (void) pdu2handler; (void) acuhandler; + /* Adding gpios for chip select decoding to the gpioComIf */ + gpioCallbacks::initSpiCsDecoder(gpioComIF); + + GpioCookie* gpioCookieSus = new GpioCookie(); + + GpioCallback* susgpio = new GpioCallback(std::string("Chip select SUS 1"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_1, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 2"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_2, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 3"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_3, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 4"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_4, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 5"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_5, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 6"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_6, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 7"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_7, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 8"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_8, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 9"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_9, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 10"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_10, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 11"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_11, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 12"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_12, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 13"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_13, susgpio); + + 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, + 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(); + + 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); + 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); + new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12); + new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13); + #if OBSW_ADD_ACS_BOARD == 1 GpioCookie* gpioCookieAcsBoard = new GpioCookie(); GpiodRegular* gpio = nullptr; @@ -287,54 +375,53 @@ void ObjectFactory::produce(){ #if Q7S_ADD_RTD_DEVICES == 1 GpioCookie* rtdGpioCookie = new GpioCookie; - gpioCallbacks::initTcsBoardDecoder(gpioComIF); GpioCallback* gpioRtdIc3 = new GpioCallback(std::string("Chip select RTD IC3"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC3, gpioRtdIc3); GpioCallback* gpioRtdIc4 = new GpioCallback(std::string("Chip select RTD IC4"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC4, gpioRtdIc4); GpioCallback* gpioRtdIc5 = new GpioCallback(std::string("Chip select RTD IC5"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC5, gpioRtdIc5); GpioCallback* gpioRtdIc6 = new GpioCallback(std::string("Chip select RTD IC6"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC6, gpioRtdIc6); GpioCallback* gpioRtdIc7 = new GpioCallback(std::string("Chip select RTD IC7"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC7, gpioRtdIc7); GpioCallback* gpioRtdIc8 = new GpioCallback(std::string("Chip select RTD IC8"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC8, gpioRtdIc8); GpioCallback* gpioRtdIc9 = new GpioCallback(std::string("Chip select RTD IC9"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC9, gpioRtdIc9); GpioCallback* gpioRtdIc10 = new GpioCallback(std::string("Chip select RTD IC10"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC10, gpioRtdIc10); GpioCallback* gpioRtdIc11 = new GpioCallback(std::string("Chip select RTD IC11"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC11, gpioRtdIc11); GpioCallback* gpioRtdIc12 = new GpioCallback(std::string("Chip select RTD IC12"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC12, gpioRtdIc12); GpioCallback* gpioRtdIc13 = new GpioCallback(std::string("Chip select RTD IC13"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC13, gpioRtdIc13); GpioCallback* gpioRtdIc14 = new GpioCallback(std::string("Chip select RTD IC14"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC14, gpioRtdIc14); GpioCallback* gpioRtdIc15 = new GpioCallback(std::string("Chip select RTD IC15"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC15, gpioRtdIc15); GpioCallback* gpioRtdIc16 = new GpioCallback(std::string("Chip select RTD IC16"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC16, gpioRtdIc16); GpioCallback* gpioRtdIc17 = new GpioCallback(std::string("Chip select RTD IC17"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC17, gpioRtdIc17); GpioCallback* gpioRtdIc18 = new GpioCallback(std::string("Chip select RTD IC18"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC18, gpioRtdIc18); gpioComIF->addGpios(rtdGpioCookie); diff --git a/bsp_q7s/gpio/gpioCallbacks.cpp b/bsp_q7s/gpio/gpioCallbacks.cpp index afdc90b6..a40f6ba4 100644 --- a/bsp_q7s/gpio/gpioCallbacks.cpp +++ b/bsp_q7s/gpio/gpioCallbacks.cpp @@ -10,12 +10,12 @@ namespace gpioCallbacks { GpioIF* gpioComInterface; -void initTcsBoardDecoder(GpioIF* gpioComIF) { +void initSpiCsDecoder(GpioIF* gpioComIF) { ReturnValue_t result; if (gpioComIF == nullptr) { - sif::debug << "initTcsBoardDecoder: Invalid gpioComIF" << std::endl; + sif::debug << "initSpiCsDecoder: Invalid gpioComIF" << std::endl; return; } @@ -48,13 +48,13 @@ void initTcsBoardDecoder(GpioIF* gpioComIF) { result = gpioComInterface->addGpios(spiMuxGpios); if (result != HasReturnvaluesIF::RETURN_OK) { - sif::error << "initTcsBoardDecoder: Failed to add mux bit gpios to gpioComIF" + sif::error << "initSpiCsDecoder: Failed to add mux bit gpios to gpioComIF" << std::endl; return; } } -void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, +void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args) { if (gpioComInterface == nullptr) { @@ -161,27 +161,83 @@ void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int va } case(gpioIds::CS_SUS_2): { enableDecoderInterfaceBoardIc21(); - - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + 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(); + selectY0(); + break; + } + case(gpioIds::CS_SUS_9): { + enableDecoderInterfaceBoardIc22(); + selectY1(); + break; + } + case(gpioIds::CS_SUS_10): { + enableDecoderInterfaceBoardIc22(); + selectY2(); + break; + } + case(gpioIds::CS_SUS_11): { + enableDecoderInterfaceBoardIc22(); + selectY3(); + break; + } + case(gpioIds::CS_SUS_12): { + enableDecoderInterfaceBoardIc22(); + selectY4(); + break; + } + case(gpioIds::CS_SUS_13): { + enableDecoderInterfaceBoardIc22(); + selectY5(); break; } default: - sif::debug << "tcsBoardDecoderCallback: Invalid gpioid " << gpioId << std::endl; + sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl; } } else { - sif::debug << "tcsBoardDecoderCallback: Invalid value. Must be 0 or 1" << std::endl; + sif::debug << "spiCsDecoderCallback: Invalid value. Must be 0 or 1" << std::endl; } } void enableDecoderTcsIc1() { - + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); } void enableDecoderTcsIc2() { - + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); } void enableDecoderInterfaceBoardIc21() { @@ -191,7 +247,9 @@ void enableDecoderInterfaceBoardIc21() { } void enableDecoderInterfaceBoardIc22() { - + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); } void selectY0() { diff --git a/bsp_q7s/gpio/gpioCallbacks.h b/bsp_q7s/gpio/gpioCallbacks.h index 3cfd4884..67ae4dc2 100644 --- a/bsp_q7s/gpio/gpioCallbacks.h +++ b/bsp_q7s/gpio/gpioCallbacks.h @@ -9,15 +9,15 @@ namespace gpioCallbacks { /** * @brief This function initializes the GPIOs used to control the SN74LVC138APWR decoders on - * the TCS Board. + * the TCS Board and the interface board. */ - void initTcsBoardDecoder(GpioIF* gpioComIF); + void initSpiCsDecoder(GpioIF* gpioComIF); /** - * @brief This function implements the decoding to multiply gpios by using the two decoder - * chips SN74LVC138APWR on the TCS board. + * @brief This function implements the decoding to multiply gpios by using the decoder + * chips SN74LVC138APWR on the TCS board and the interface board. */ - void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args); + void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args); /** * @brief This function sets mux bits 1-3 to a state which will only enable the decoder diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index be770ad1..d6a059e6 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -30,7 +30,8 @@ debugging. */ #define ACU_DEBUG 0 #define SYRLINKS_DEBUG 0 #define IMQT_DEBUG 0 -#define DEBUG_RAD_SENSOR 1 +#define DEBUG_RAD_SENSOR 1 +#define DEBUG_SUS 1 #include "OBSWVersion.h" diff --git a/fsfwconfig/devices/addresses.h b/fsfwconfig/devices/addresses.h index 26a86b2a..3de3a105 100644 --- a/fsfwconfig/devices/addresses.h +++ b/fsfwconfig/devices/addresses.h @@ -21,6 +21,20 @@ namespace addresses { RAD_SENSOR = objects::RAD_SENSOR, + SUS_1 = objects::SUS_1, + SUS_2 = objects::SUS_2, + SUS_3 = objects::SUS_3, + SUS_4 = objects::SUS_4, + SUS_5 = objects::SUS_5, + SUS_6 = objects::SUS_6, + SUS_7 = objects::SUS_7, + SUS_8 = objects::SUS_8, + SUS_9 = objects::SUS_9, + SUS_10 = objects::SUS_10, + SUS_11 = objects::SUS_11, + SUS_12 = objects::SUS_12, + SUS_13 = objects::SUS_13, + /* Dummy and Test Addresses */ DUMMY_ECHO = 129, DUMMY_GPS0 = 130, diff --git a/fsfwconfig/devices/gpioIds.h b/fsfwconfig/devices/gpioIds.h index 8b9edffc..3221c613 100644 --- a/fsfwconfig/devices/gpioIds.h +++ b/fsfwconfig/devices/gpioIds.h @@ -44,6 +44,20 @@ namespace gpioIds { RTD_IC17, RTD_IC18, + CS_SUS_1, + CS_SUS_2, + CS_SUS_3, + CS_SUS_4, + CS_SUS_5, + CS_SUS_6, + CS_SUS_7, + CS_SUS_8, + CS_SUS_9, + CS_SUS_10, + CS_SUS_11, + CS_SUS_12, + CS_SUS_13, + SPI_MUX_BIT_1, SPI_MUX_BIT_2, SPI_MUX_BIT_3, diff --git a/fsfwconfig/objects/systemObjectList.h b/fsfwconfig/objects/systemObjectList.h index 1249b862..c1f792eb 100644 --- a/fsfwconfig/objects/systemObjectList.h +++ b/fsfwconfig/objects/systemObjectList.h @@ -84,6 +84,20 @@ 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 a54d70ba..31b56865 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -150,6 +150,13 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) 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); + if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; } diff --git a/mission/devices/CMakeLists.txt b/mission/devices/CMakeLists.txt index 4088d98b..9965fedc 100644 --- a/mission/devices/CMakeLists.txt +++ b/mission/devices/CMakeLists.txt @@ -15,6 +15,7 @@ target_sources(${TARGET_NAME} PUBLIC IMTQHandler.cpp PlocHandler.cpp RadiationSensorHandler.cpp + SusHandler.cpp ) diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 64391c79..8d44ea9a 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -31,25 +31,7 @@ void RadiationSensorHandler::doShutDown(){ ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( 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; - communicationStep = CommunicationStep::READ_CONVERSIONS; - break; - } - default: { - sif::debug << "RadiationSensorHandler::buildNormalDeviceCommand: Unknwon communication " - << "step" << std::endl; - return HasReturnvaluesIF::RETURN_OK; - } - } + *id = RAD_SENSOR::PERFORM_CONVERSION; return buildCommandFromCommand(*id, nullptr, 0); } @@ -61,7 +43,7 @@ ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand( else { return HasReturnvaluesIF::RETURN_OK; } - buildCommandFromCommand(*id, nullptr, 0); + return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( @@ -75,23 +57,17 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( internalState = InternalState::CONFIGURED; return RETURN_OK; } - case(RAD_SENSOR::START_CONVERSION): { + case(RAD_SENSOR::PERFORM_CONVERSION): { + /* Dummy bytes are written to remove old values from fifo */ cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION; - rawPacket = cmdBuffer; - rawPacketLen = 1; - 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; - cmdBuffer[6] = RAD_SENSOR::DUMMY_BYTE; - rawPacket = cmdBuffer; - rawPacketLen = RAD_SENSOR::READ_SIZE; - return RETURN_OK; + 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; @@ -101,8 +77,7 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( void RadiationSensorHandler::fillCommandAndReplyMap() { this->insertInCommandMap(RAD_SENSOR::WRITE_SETUP); - this->insertInCommandMap(RAD_SENSOR::START_CONVERSION); - this->insertInCommandAndReplyMap(RAD_SENSOR::READ_CONVERSIONS, 1, &dataset, + this->insertInCommandAndReplyMap(RAD_SENSOR::PERFORM_CONVERSION, 1, &dataset, RAD_SENSOR::READ_SIZE); } @@ -116,7 +91,7 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { - case RAD_SENSOR::READ_CONVERSIONS: { + case RAD_SENSOR::PERFORM_CONVERSION: { PoolReadGuard readSet(&dataset); dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3)); diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp new file mode 100644 index 00000000..3339ff26 --- /dev/null +++ b/mission/devices/SusHandler.cpp @@ -0,0 +1,165 @@ +#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() { +} + + +void SusHandler::doStartUp(){ + if (internalState == InternalState::CONFIGURED) { +#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 + setMode(MODE_NORMAL); +#else + setMode(_MODE_TO_ON); +#endif + } +} + +void SusHandler::doShutDown(){ + setMode(_MODE_POWER_DOWN); +} + +ReturnValue_t SusHandler::buildNormalDeviceCommand( + DeviceCommandId_t * id) { + + switch (communicationStep) { + case CommunicationStep::START_CONVERSION: { + *id = SUS::START_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + case CommunicationStep::READ_CONVERSIONS: { + *id = SUS::READ_CONVERSIONS; +// communicationStep = CommunicationStep::START_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + default: { + sif::debug << "SusHandler::buildNormalDeviceCommand: Unknwon communication " + << "step" << std::endl; + return HasReturnvaluesIF::RETURN_OK; + } + } + 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); +} + +ReturnValue_t SusHandler::buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t * commandData, + size_t commandDataLen) { + switch(deviceCommand) { + case(SUS::WRITE_SETUP): { + cmdBuffer[0] = SUS::SETUP_DEFINITION; + cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; + rawPacket = cmdBuffer; + rawPacketLen = 2; + internalState = InternalState::CONFIGURED; + return RETURN_OK; + } + case(SUS::START_CONVERSION): { + cmdBuffer[0] = SUS::CONVERSION_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = 1; + 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; + return RETURN_OK; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; +} + +void SusHandler::fillCommandAndReplyMap() { + this->insertInCommandMap(SUS::WRITE_SETUP); + this->insertInCommandMap(SUS::START_CONVERSION); + this->insertInCommandAndReplyMap(SUS::READ_CONVERSIONS, 1, &dataset, + SUS::READ_SIZE); +} + +ReturnValue_t SusHandler::scanForReply(const uint8_t *start, + size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) { + *foundId = this->getPendingCommand(); + *foundLen = remainingSize; + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) { + switch (id) { + case SUS::READ_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)); +#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; +#endif + break; + } + default: { + sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl; + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } + + } + return HasReturnvaluesIF::RETURN_OK; +} + +void SusHandler::setNormalDatapoolEntriesInvalid(){ + +} + +uint32_t SusHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ + return 5000; +} + +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 })); + return HasReturnvaluesIF::RETURN_OK; +} + diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h new file mode 100644 index 00000000..445722a8 --- /dev/null +++ b/mission/devices/SusHandler.h @@ -0,0 +1,61 @@ +#ifndef MISSION_DEVICES_SUSHANDLER_H_ +#define MISSION_DEVICES_SUSHANDLER_H_ + +#include +#include + +/** + * @brief This is the device handler class for the SUS sensor. The sensor is + * based on the MAX1227 ADC. Details about the SUS electronic can be found at + * https://egit.irs.uni-stuttgart.de/eive/eive_dokumente/src/branch/master/400_Raumsegment/443_SunSensorDocumentation/release + * + * @details Datasheet of MAX1227: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf + * + * @author J. Meier + */ +class SusHandler: public DeviceHandlerBase { +public: + + SusHandler(object_id_t objectId, object_id_t comIF, + CookieIF * comCookie); + virtual ~SusHandler(); + +protected: + void doStartUp() override; + void doShutDown() override; + ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) override; + ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) override; + void fillCommandAndReplyMap() override; + ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, + const uint8_t * commandData,size_t commandDataLen) override; + ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, + DeviceCommandId_t *foundId, size_t *foundLen) override; + ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) override; + void setNormalDatapoolEntriesInvalid() override; + uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) override; + +private: + + enum class CommunicationStep { + START_CONVERSION, + READ_CONVERSIONS + }; + + enum class InternalState { + SETUP, + CONFIGURED + }; + + SUS::SusDataset dataset; + + static const uint8_t MAX_CMD_LEN = SUS::READ_SIZE; + + uint8_t cmdBuffer[MAX_CMD_LEN]; + InternalState internalState = InternalState::SETUP; + CommunicationStep communicationStep = CommunicationStep::START_CONVERSION; +}; + +#endif /* MISSION_DEVICES_SUSHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/RadSensorDefinitions.h b/mission/devices/devicedefinitions/RadSensorDefinitions.h index 46e5be40..c962b2e2 100644 --- a/mission/devices/devicedefinitions/RadSensorDefinitions.h +++ b/mission/devices/devicedefinitions/RadSensorDefinitions.h @@ -10,11 +10,8 @@ namespace RAD_SENSOR { * temperature sensor. */ static const DeviceCommandId_t WRITE_SETUP = 0x1; - static const DeviceCommandId_t START_CONVERSION = 0x2; + static const DeviceCommandId_t PERFORM_CONVERSION = 0x2; static const DeviceCommandId_t READ_CONVERSIONS = 0x3; - - static const uint32_t MAX1227_DATA_SET_ID = READ_CONVERSIONS; - /** * @brief This is the configuration byte which will be written to the setup register after * power on. @@ -37,12 +34,6 @@ namespace RAD_SENSOR { */ static const uint8_t CONVERSION_DEFINITION = 0b10001001; - /** - * Unipolar only required for differential measurement. Unipolar or dipolar determines the - * voltage range. - */ - static const uint8_t UNIPOLAR_SETUP = 0b10000000; - static const uint8_t DUMMY_BYTE = 0xFF; static const uint8_t RAD_SENSOR_DATA_SET_ID = READ_CONVERSIONS; diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h new file mode 100644 index 00000000..efc56959 --- /dev/null +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -0,0 +1,83 @@ +#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_ +#define MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_ + +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 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. + * + * @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 + * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register + * + */ + static const uint8_t SETUP_DEFINITION = 0b01101110; + + /** + * @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; + + /** + * @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) + * 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 DUMMY_BYTE = 0xFF; + + static const uint8_t SUS_DATA_SET_ID = READ_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; + + enum Max1227PoolIds: lp_id_t { + TEMPERATURE_C, + DIFF_SCAN_CHANNEL_0_1, + DIFF_SCAN_CHANNEL_2_3, + DIFF_SCAN_CHANNEL_4_5, + }; + +class SusDataset: public StaticLocalDataSet { +public: + + SusDataset(HasLocalDataPoolIF* owner) : + StaticLocalDataSet(owner, SUS_DATA_SET_ID) { + } + + SusDataset(object_id_t objectId) : + StaticLocalDataSet(sid_t(objectId, SUS_DATA_SET_ID)) { + } + + 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); +}; +} + + +#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_ */ From 31b4246bca2426e3958e480ac1e33db32b22372b Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 3 May 2021 12:05:19 +0200 Subject: [PATCH 04/21] another try to read out the adc --- mission/devices/RadiationSensorHandler.cpp | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 8d44ea9a..38a1f148 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -31,8 +31,29 @@ void RadiationSensorHandler::doShutDown(){ ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { - *id = RAD_SENSOR::PERFORM_CONVERSION; - return buildCommandFromCommand(*id, nullptr, 0); + switch (communicationStep) { + case CommunicationStep::FIRST_CONVERSION: { + *id = RAD_SENSOR::FIRST_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + case CommunicationStep::PERFORM_CONVERSION: { + *id = RAD_SENSOR::PERFORM_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + case CommunicationStep::READ_CONVERSIONS: { + *id = RAD_SENSOR::READ_CONVERSIONS; + communicationStep = CommunicationStep::PERFRORM_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( @@ -57,6 +78,13 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( internalState = InternalState::CONFIGURED; return RETURN_OK; } + case(RAD_SENSOR::FIRST_CONVERSION): { + /* Dummy bytes are written to remove old values from fifo */ + cmdBuffer[0] = RAD_SENSOR::FIRST_CONVERSION_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = RAD_SENSOR::READ_SIZE; + return RETURN_OK; + } case(RAD_SENSOR::PERFORM_CONVERSION): { /* Dummy bytes are written to remove old values from fifo */ cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION; From fd9adee1aee97616822aa88f2bc3a87e1dec875a Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 3 May 2021 12:49:14 +0200 Subject: [PATCH 05/21] rad sensor working --- bsp_q7s/ObjectFactory.cpp | 137 ++++-------------- mission/devices/RadiationSensorHandler.cpp | 121 ++++++++-------- mission/devices/SusHandler.cpp | 6 +- .../devicedefinitions/RadSensorDefinitions.h | 8 +- .../devicedefinitions/SusDefinitions.h | 5 + 5 files changed, 100 insertions(+), 177 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 776a3e4b..9d0b9ecb 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -26,13 +26,11 @@ #include #include #include -#include #include #include #include #include -#include #include #include @@ -108,8 +106,14 @@ void ObjectFactory::produce(){ #endif /* Temperature sensors */ - new Tmp1075Handler(objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, i2cCookieTmp1075tcs1); - new Tmp1075Handler(objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, i2cCookieTmp1075tcs2); + Tmp1075Handler* tmp1075Handler_1 = new Tmp1075Handler( + objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, + i2cCookieTmp1075tcs1); +// tmp1075Handler_1->setStartUpImmediately(); + Tmp1075Handler* tmp1075Handler_2 = new Tmp1075Handler( + objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, + i2cCookieTmp1075tcs2); +// tmp1075Handler_2->setStartUpImmediately(); GpioCookie* heaterGpiosCookie = new GpioCookie; @@ -147,98 +151,6 @@ void ObjectFactory::produce(){ (void) pdu2handler; (void) acuhandler; - /* Adding gpios for chip select decoding to the gpioComIf */ - gpioCallbacks::initSpiCsDecoder(gpioComIF); - - GpioCookie* gpioCookieSus = new GpioCookie(); - - GpioCallback* susgpio = new GpioCallback(std::string("Chip select SUS 1"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_1, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 2"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_2, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 3"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_3, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 4"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_4, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 5"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_5, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 6"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_6, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 7"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_7, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 8"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_8, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 9"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_9, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 10"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_10, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 11"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_11, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 12"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_12, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 13"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_13, susgpio); - - 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, - 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(); - - 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); - 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); - new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12); - new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13); - #if OBSW_ADD_ACS_BOARD == 1 GpioCookie* gpioCookieAcsBoard = new GpioCookie(); GpiodRegular* gpio = nullptr; @@ -375,53 +287,54 @@ void ObjectFactory::produce(){ #if Q7S_ADD_RTD_DEVICES == 1 GpioCookie* rtdGpioCookie = new GpioCookie; + gpioCallbacks::initTcsBoardDecoder(gpioComIF); GpioCallback* gpioRtdIc3 = new GpioCallback(std::string("Chip select RTD IC3"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC3, gpioRtdIc3); GpioCallback* gpioRtdIc4 = new GpioCallback(std::string("Chip select RTD IC4"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC4, gpioRtdIc4); GpioCallback* gpioRtdIc5 = new GpioCallback(std::string("Chip select RTD IC5"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC5, gpioRtdIc5); GpioCallback* gpioRtdIc6 = new GpioCallback(std::string("Chip select RTD IC6"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC6, gpioRtdIc6); GpioCallback* gpioRtdIc7 = new GpioCallback(std::string("Chip select RTD IC7"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC7, gpioRtdIc7); GpioCallback* gpioRtdIc8 = new GpioCallback(std::string("Chip select RTD IC8"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC8, gpioRtdIc8); GpioCallback* gpioRtdIc9 = new GpioCallback(std::string("Chip select RTD IC9"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC9, gpioRtdIc9); GpioCallback* gpioRtdIc10 = new GpioCallback(std::string("Chip select RTD IC10"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC10, gpioRtdIc10); GpioCallback* gpioRtdIc11 = new GpioCallback(std::string("Chip select RTD IC11"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC11, gpioRtdIc11); GpioCallback* gpioRtdIc12 = new GpioCallback(std::string("Chip select RTD IC12"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC12, gpioRtdIc12); GpioCallback* gpioRtdIc13 = new GpioCallback(std::string("Chip select RTD IC13"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC13, gpioRtdIc13); GpioCallback* gpioRtdIc14 = new GpioCallback(std::string("Chip select RTD IC14"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC14, gpioRtdIc14); GpioCallback* gpioRtdIc15 = new GpioCallback(std::string("Chip select RTD IC15"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC15, gpioRtdIc15); GpioCallback* gpioRtdIc16 = new GpioCallback(std::string("Chip select RTD IC16"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC16, gpioRtdIc16); GpioCallback* gpioRtdIc17 = new GpioCallback(std::string("Chip select RTD IC17"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC17, gpioRtdIc17); GpioCallback* gpioRtdIc18 = new GpioCallback(std::string("Chip select RTD IC18"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC18, gpioRtdIc18); gpioComIF->addGpios(rtdGpioCookie); diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 38a1f148..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,21 +30,17 @@ void RadiationSensorHandler::doShutDown(){ } ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( - DeviceCommandId_t * id) { + DeviceCommandId_t * id) { + switch (communicationStep) { - case CommunicationStep::FIRST_CONVERSION: { - *id = RAD_SENSOR::FIRST_CONVERSION; - communicationStep = CommunicationStep::READ_CONVERSIONS; - break; - } - case CommunicationStep::PERFORM_CONVERSION: { - *id = RAD_SENSOR::PERFORM_CONVERSION; + 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::PERFRORM_CONVERSION; + communicationStep = CommunicationStep::START_CONVERSION; break; } default: { @@ -57,55 +53,56 @@ ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( } 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::FIRST_CONVERSION): { - /* Dummy bytes are written to remove old values from fifo */ - cmdBuffer[0] = RAD_SENSOR::FIRST_CONVERSION_DEFINITION; - rawPacket = cmdBuffer; - rawPacketLen = RAD_SENSOR::READ_SIZE; - 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); } @@ -118,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; @@ -132,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(){ @@ -148,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/SusHandler.cpp b/mission/devices/SusHandler.cpp index 3339ff26..69aee06d 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -77,9 +77,11 @@ ReturnValue_t SusHandler::buildCommandFromCommand( return RETURN_OK; } case(SUS::START_CONVERSION): { - cmdBuffer[0] = SUS::CONVERSION_DEFINITION; + /* First the fifo will be reset before a new conversion is initiated */ + cmdBuffer[0] = SUS::RESET_DEFINITION; + cmdBuffer[1] = SUS::CONVERSION_DEFINITION; rawPacket = cmdBuffer; - rawPacketLen = 1; + rawPacketLen = 2; return RETURN_OK; } case(SUS::READ_CONVERSIONS): { 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; diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index efc56959..7d48259b 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -34,6 +34,11 @@ namespace SUS { */ static const uint8_t UNIPOLAR_CONFIG = 0b11100000; + /** + * @brief Writing this value resets the fifo of the MAX1227. + */ + static const uint8_t RESET_DEFINITION = 0b00011000; + /** * @brief This value will always be written to the ADC conversion register to specify the * conversions to perform. From 3c6ec68faa48f05304b24a3113c06fc8c10555d1 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 3 May 2021 13:35:16 +0200 Subject: [PATCH 06/21] 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 07/21] 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 08/21] 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 09/21] 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 10/21] 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 11/21] 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 12/21] 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 13/21] 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 14/21] 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 15/21] 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 16/21] 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 17/21] 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 18/21] 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; From 33c229d08a11e3e985d4b921a51ff0e6a32893d1 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 13 May 2021 13:17:12 +0200 Subject: [PATCH 19/21] all sus initialized --- bsp_q7s/ObjectFactory.cpp | 61 +--- fsfw_hal | 2 +- fsfwconfig/OBSWConfig.h | 2 +- .../pollingSequenceFactory.cpp | 316 +++++++++++++----- 4 files changed, 256 insertions(+), 125 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index c34f847a..4d1a413e 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -163,10 +163,7 @@ void ObjectFactory::produce(){ 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); - (void) radSensor; - + new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); GpioCookie* gpioCookieSus = new GpioCookie(); GpioCallback* susgpio = new GpioCallback(std::string("Chip select SUS 1"), gpio::OUT, 1, @@ -251,49 +248,19 @@ void ObjectFactory::produce(){ std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); - SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, - gpioIds::CS_SUS_1); - (void) sus1; - - SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2, gpioComIF, - gpioIds::CS_SUS_2); - sus2->setStartUpImmediately(); - - SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3, gpioComIF, - gpioIds::CS_SUS_3); - (void) sus3; - - 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); - (void) sus8; - - SusHandler* sus9 = new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9, gpioComIF, - gpioIds::CS_SUS_9); - (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); - (void) sus12; - - SusHandler* sus13 = new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13, gpioComIF, - gpioIds::CS_SUS_13); - (void) sus13; + new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, gpioIds::CS_SUS_1); + new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2, gpioComIF, gpioIds::CS_SUS_2); + new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3, gpioComIF, gpioIds::CS_SUS_3); + 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); + new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8, gpioComIF, gpioIds::CS_SUS_8); + 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); + new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11, gpioComIF, gpioIds::CS_SUS_11); + 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(); diff --git a/fsfw_hal b/fsfw_hal index 425cfd2a..e5da8b19 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit 425cfd2ababe3639355c6681ce3f9b606b893430 +Subproject commit e5da8b194d61aed01fee7b8d6f6b7fe8b01dc547 diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index bfe528c6..9426d01b 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/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 77c5e8ff..1199ae2c 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -166,45 +166,251 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) */ /* Write setup */ - thisSequence->addSlot(objects::SUS_8, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.902, SusHandler::FIRST_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); - - /* 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); + thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.9, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.901, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.902, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::GET_READ); /* Write setup */ - thisSequence->addSlot(objects::SUS_12, length * 0.916, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_12, length * 0.917, SusHandler::FIRST_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); + thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.903, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.904, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.905, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_3, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_3, length * 0.906, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.906, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.906, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_3, length * 0.906, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_3, length * 0.907, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_3, length * 0.907, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.907, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.907, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_3, length * 0.907, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_3, length * 0.908, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_3, length * 0.908, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.908, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.908, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_3, length * 0.908, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_4, length * 0.909, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_4, length * 0.91, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_4, length * 0.911, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_5, length * 0.912, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_5, length * 0.913, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_5, length * 0.914, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_6, length * 0.915, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::GET_READ); /* Start ADC conversions */ - thisSequence->addSlot(objects::SUS_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); + thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::GET_READ); + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::SUS_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.93, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_7, length * 0.918, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::GET_READ); + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.921, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_8, length * 0.922, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.922, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.922, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.922, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.922, DeviceHandlerIF::GET_READ); + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_9, length * 0.924, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::GET_READ); + /* Read ADC conversions */ + thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_10, length * 0.927, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_10, length * 0.928, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_10, length * 0.928, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.928, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.928, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_10, length * 0.928, DeviceHandlerIF::GET_READ); + /* Read ADC conversions */ + thisSequence->addSlot(objects::SUS_10, length * 0.929, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_10, length * 0.929, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.929, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.929, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_10, length * 0.929, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_11, length * 0.93, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_11, length * 0.931, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_11, length * 0.931, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.931, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.931, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_11, length * 0.931, DeviceHandlerIF::GET_READ); + /* Read ADC conversions */ + thisSequence->addSlot(objects::SUS_11, length * 0.932, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_11, length * 0.932, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.932, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.932, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_11, length * 0.932, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.933, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::GET_READ); + /* Read ADC conversions */ + thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_13, length * 0.936, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_13, length * 0.936, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.936, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.936, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_13, length * 0.936, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_13, length * 0.937, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_13, length * 0.937, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.937, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.937, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_13, length * 0.937, DeviceHandlerIF::GET_READ); + /* Read ADC conversions */ + thisSequence->addSlot(objects::SUS_13, length * 0.938, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_13, length * 0.938, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.938, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.938, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_13, length * 0.938, DeviceHandlerIF::GET_READ); if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; @@ -344,48 +550,6 @@ ReturnValue_t pst::gomspacePstInit(FixedTimeslotTaskIF *thisSequence){ return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t pst::pollingSequenceAcsTest(FixedTimeslotTaskIF *thisSequence) { - uint32_t length = thisSequence->getPeriodMs(); - - 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::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); - if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { - sif::error << "Initialization of ACS Board PST failed" << std::endl; - return HasReturnvaluesIF::RETURN_FAILED; - } - return HasReturnvaluesIF::RETURN_OK; -} - ReturnValue_t pst::pollingSequenceTE0720(FixedTimeslotTaskIF *thisSequence) { uint32_t length = thisSequence->getPeriodMs(); From b0c2606e6a2b5e1b63f92cd06318bf7879b3f9f7 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 13 May 2021 13:42:47 +0200 Subject: [PATCH 20/21] updated fsfw_hal --- fsfw_hal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfw_hal b/fsfw_hal index e5da8b19..a0f698ff 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit e5da8b194d61aed01fee7b8d6f6b7fe8b01dc547 +Subproject commit a0f698fffa4dd5c9f86337c5d6170f9321cb8de7 From 8508957f5bf6560ae2965085f02db620d0b7ab5e Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 17 May 2021 13:54:12 +0200 Subject: [PATCH 21/21] added etl and tmtc --- thirdparty/etl | 2 +- tmtc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/thirdparty/etl b/thirdparty/etl index c308dc42..0efecca7 160000 --- a/thirdparty/etl +++ b/thirdparty/etl @@ -1 +1 @@ -Subproject commit c308dc427b7a34e54f33860fb2e244564b2740b4 +Subproject commit 0efecca700c6d0847f91b5540638571ba298c793 diff --git a/tmtc b/tmtc index 06750809..574a3e92 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 06750809cb52044392e0683896538a652f11a512 +Subproject commit 574a3e92074d9d4d0335dad3ddc5962e1369f5d5