diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 7507b5e6..8229536b 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -582,12 +582,26 @@ void ObjectFactory::produce(void* args){ auto rw1SpiCookie = new SpiCookie(addresses::RW1, gpioIds::CS_RW1, "/dev/spidev2.0", RwDefinitions::MAX_REPLY_SIZE, spi::RW_MODE, spi::RW_SPEED, &rwSpiCallback, nullptr); + auto rw2SpiCookie = new SpiCookie(addresses::RW2, gpioIds::CS_RW2, "/dev/spidev2.0", + RwDefinitions::MAX_REPLY_SIZE, spi::RW_MODE, spi::RW_SPEED, &rwSpiCallback, nullptr); + auto rw3SpiCookie = new SpiCookie(addresses::RW3, gpioIds::CS_RW3, "/dev/spidev2.0", + RwDefinitions::MAX_REPLY_SIZE, spi::RW_MODE, spi::RW_SPEED, &rwSpiCallback, nullptr); + auto rw4SpiCookie = new SpiCookie(addresses::RW4, gpioIds::CS_RW4, "/dev/spidev2.0", + RwDefinitions::MAX_REPLY_SIZE, spi::RW_MODE, spi::RW_SPEED, &rwSpiCallback, nullptr); + (void) rw3SpiCookie; + (void) rw4SpiCookie; auto rwHandler1 = new RwHandler(objects::RW1, objects::SPI_COM_IF, rw1SpiCookie, gpioComIF, gpioIds::EN_RW1); - rwHandler1->setStartUpImmediately(); + (void) rwHandler1; +// rwHandler1->setStartUpImmediately(); rw1SpiCookie->setCallbackArgs(rwHandler1); + auto rwHandler2 = new RwHandler(objects::RW2, objects::SPI_COM_IF, rw2SpiCookie, gpioComIF, + gpioIds::EN_RW1); + rwHandler2->setStartUpImmediately(); + rw2SpiCookie->setCallbackArgs(rwHandler2); + #endif /* TE0720 == 0 */ new UdpTmTcBridge(objects::UDP_BRIDGE, objects::CCSDS_PACKET_DISTRIBUTOR); diff --git a/bsp_q7s/spiCallbacks/rwSpiCallback.cpp b/bsp_q7s/spiCallbacks/rwSpiCallback.cpp index 41ba70d9..bfb1892c 100644 --- a/bsp_q7s/spiCallbacks/rwSpiCallback.cpp +++ b/bsp_q7s/spiCallbacks/rwSpiCallback.cpp @@ -93,7 +93,7 @@ ReturnValue_t rwSpiCallback(SpiComIF* comIf, SpiCookie *cookie, const uint8_t *s idx++; } - /** Sending frame start sign */ + /** Sending frame end sign */ writeBuffer[0] = 0x7E; writeSize = 1; @@ -155,7 +155,7 @@ ReturnValue_t rwSpiCallback(SpiComIF* comIf, SpiCookie *cookie, const uint8_t *s /** Reached end of frame */ break; } - else if (byteRead == 0xD) { + else if (byteRead == 0x7D) { if(read(fileDescriptor, &byteRead, 1) != 1) { sif::error << "rwSpiCallback: Read failed" << std::endl; result = RwHandler::SPI_READ_FAILURE; diff --git a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 9bb73857..35f38919 100644 --- a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -407,6 +407,12 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { thisSequence->addSlot(objects::RW1, length * 0.6, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::RW1, length * 0.8, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::RW2, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::RW2, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::RW2, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::RW2, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::RW2, length * 0.8, DeviceHandlerIF::GET_READ); + if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { sif::error << "SPI PST initialization failed" << std::endl; return HasReturnvaluesIF::RETURN_FAILED; diff --git a/mission/devices/RwHandler.cpp b/mission/devices/RwHandler.cpp index 7d84bfcf..c789fb64 100644 --- a/mission/devices/RwHandler.cpp +++ b/mission/devices/RwHandler.cpp @@ -20,12 +20,19 @@ RwHandler::~RwHandler() { } void RwHandler::doStartUp() { - if (!startupPerformed) { - return; - } - if(gpioComIF->pullHigh(enableGpio) != RETURN_OK) { - sif::debug << "RwHandler::doStartUp: Failed to pull enable gpio to high"; + switch (startupStep) { + case StartupStep::ENABLE_RW: { + if(gpioComIF->pullHigh(enableGpio) != RETURN_OK) { + sif::debug << "RwHandler::doStartUp: Failed to pull enable gpio to high"; + } + return; } + case StartupStep::STARTUP_COMPLETE: + break; + default: + return; + } + #if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 setMode(MODE_NORMAL); #else @@ -37,7 +44,8 @@ void RwHandler::doShutDown() { if(gpioComIF->pullLow(enableGpio) != RETURN_OK) { sif::debug << "RwHandler::doStartUp: Failed to pull enable gpio to low"; } - startupPerformed = false; + /** Reset startup step for next doStartUp routine */ + startupStep = StartupStep::ENABLE_RW; } ReturnValue_t RwHandler::buildNormalDeviceCommand(DeviceCommandId_t * id) { @@ -64,7 +72,7 @@ ReturnValue_t RwHandler::buildNormalDeviceCommand(DeviceCommandId_t * id) { ReturnValue_t RwHandler::buildTransitionDeviceCommand(DeviceCommandId_t * id) { switch (startupStep) { - case StartupStep::GET_RESET_STATUS: + case StartupStep::ENABLE_RW: *id = RwDefinitions::GET_LAST_RESET_STATUS; startupStep = StartupStep::CLEAR_RESET_STATUS; break; @@ -74,9 +82,10 @@ ReturnValue_t RwHandler::buildTransitionDeviceCommand(DeviceCommandId_t * id) { break; case StartupStep::INIT_RW: *id = RwDefinitions::INIT_RW_CONTROLLER; - startupStep = StartupStep::GET_RESET_STATUS; - startupPerformed = true; + startupStep = StartupStep::STARTUP_COMPLETE; break; + case StartupStep::STARTUP_COMPLETE: + break; default: sif::debug << "RwHandler::buildTransitionDeviceCommand: Invalid startup step" << std::endl; @@ -136,17 +145,19 @@ ReturnValue_t RwHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand } void RwHandler::fillCommandAndReplyMap() { - this->insertInCommandMap(RwDefinitions::RESET_MCU); - this->insertInCommandAndReplyMap(RwDefinitions::GET_LAST_RESET_STATUS, 1, &lastResetStatusSet, - RwDefinitions::SIZE_GET_RESET_STATUS); - this->insertInCommandMap(RwDefinitions::CLEAR_LAST_RESET_STATUS); - this->insertInCommandAndReplyMap(RwDefinitions::GET_RW_STATUS, 1, &statusSet, - RwDefinitions::SIZE_GET_RW_STATUS); - this->insertInCommandMap(RwDefinitions::INIT_RW_CONTROLLER); - this->insertInCommandAndReplyMap(RwDefinitions::GET_TEMPERATURE, 1, &temperatureSet, - RwDefinitions::SIZE_GET_TEMPERATURE_REPLY); - this->insertInCommandAndReplyMap(RwDefinitions::SET_SPEED, 1, nullptr, - RwDefinitions::SIZE_SET_SPEED_REPLY); + this->insertInCommandMap(RwDefinitions::RESET_MCU); + this->insertInCommandAndReplyMap(RwDefinitions::GET_LAST_RESET_STATUS, 1, &lastResetStatusSet, + RwDefinitions::SIZE_GET_RESET_STATUS); + this->insertInCommandAndReplyMap(RwDefinitions::CLEAR_LAST_RESET_STATUS, 1, nullptr, + RwDefinitions::SIZE_CLEAR_RESET_STATUS); + this->insertInCommandAndReplyMap(RwDefinitions::GET_RW_STATUS, 1, &statusSet, + RwDefinitions::SIZE_GET_RW_STATUS); + this->insertInCommandAndReplyMap(RwDefinitions::INIT_RW_CONTROLLER, 1, nullptr, + RwDefinitions::SIZE_INIT_RW); + this->insertInCommandAndReplyMap(RwDefinitions::GET_TEMPERATURE, 1, &temperatureSet, + RwDefinitions::SIZE_GET_TEMPERATURE_REPLY); + this->insertInCommandAndReplyMap(RwDefinitions::SET_SPEED, 1, nullptr, + RwDefinitions::SIZE_SET_SPEED_REPLY); } ReturnValue_t RwHandler::scanForReply(const uint8_t *start, size_t remainingSize, @@ -158,11 +169,21 @@ ReturnValue_t RwHandler::scanForReply(const uint8_t *start, size_t remainingSize *foundId = RwDefinitions::GET_LAST_RESET_STATUS; break; } + case (static_cast(RwDefinitions::CLEAR_LAST_RESET_STATUS)): { + *foundLen = RwDefinitions::SIZE_CLEAR_RESET_STATUS; + *foundId = RwDefinitions::CLEAR_LAST_RESET_STATUS; + break; + } case (static_cast(RwDefinitions::GET_RW_STATUS)): { *foundLen = RwDefinitions::SIZE_GET_RW_STATUS; *foundId = RwDefinitions::GET_RW_STATUS; break; } + case (static_cast(RwDefinitions::INIT_RW_CONTROLLER)): { + *foundLen = RwDefinitions::SIZE_INIT_RW; + *foundId = RwDefinitions::INIT_RW_CONTROLLER; + break; + } case (static_cast(RwDefinitions::SET_SPEED)): { *foundLen = RwDefinitions::SIZE_SET_SPEED_REPLY; *foundId = RwDefinitions::SET_SPEED; @@ -189,6 +210,8 @@ ReturnValue_t RwHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_ /** Check result code */ if (*(packet + 1) == RwDefinitions::ERROR) { + sif::error << "RwHandler::interpretDeviceReply: Command execution failed. Command id: " + << id << std::endl; return EXECUTION_FAILED; } @@ -209,6 +232,8 @@ ReturnValue_t RwHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_ handleGetRwStatusReply(packet); break; } + case (RwDefinitions::CLEAR_LAST_RESET_STATUS): + case (RwDefinitions::INIT_RW_CONTROLLER): case (RwDefinitions::SET_SPEED): // no reply data expected break; @@ -230,7 +255,7 @@ void RwHandler::setNormalDatapoolEntriesInvalid() { } uint32_t RwHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { - return 5000; + return 15000; } ReturnValue_t RwHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, diff --git a/mission/devices/RwHandler.h b/mission/devices/RwHandler.h index 9521034c..a3d9ff1c 100644 --- a/mission/devices/RwHandler.h +++ b/mission/devices/RwHandler.h @@ -98,17 +98,16 @@ private: CommunicationStep communicationStep = CommunicationStep::READ_TEMPERATURE; enum class StartupStep { - GET_RESET_STATUS, + ENABLE_RW, CLEAR_RESET_STATUS, - INIT_RW + INIT_RW, + STARTUP_COMPLETE }; - StartupStep startupStep = StartupStep::GET_RESET_STATUS; + StartupStep startupStep = StartupStep::ENABLE_RW; size_t sizeOfReply = 0; - bool startupPerformed = false; - /** * @brief This function prepares the command to request the last reset status */ diff --git a/mission/devices/devicedefinitions/RwDefinitions.h b/mission/devices/devicedefinitions/RwDefinitions.h index 73de0e57..e383920e 100644 --- a/mission/devices/devicedefinitions/RwDefinitions.h +++ b/mission/devices/devicedefinitions/RwDefinitions.h @@ -41,6 +41,8 @@ static const uint32_t STATUS_SET_ID = GET_RW_STATUS; static const uint32_t LAST_RESET_ID = GET_LAST_RESET_STATUS; static const size_t SIZE_GET_RESET_STATUS = 5; +static const size_t SIZE_CLEAR_RESET_STATUS = 4; +static const size_t SIZE_INIT_RW = 4; static const size_t SIZE_GET_RW_STATUS = 14; static const size_t SIZE_SET_SPEED_REPLY = 4; static const size_t SIZE_GET_TEMPERATURE_REPLY = 8; diff --git a/tmtc b/tmtc index 899cd942..19b76d96 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 899cd942ce7136f371e93d270a6c6c149c0698cb +Subproject commit 19b76d961c61966a0093d3768f62d99196e1c9b2