From 23b2d895bb3e35e1bae28b80a5fe04bee434eb5e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Apr 2022 16:40:28 +0200 Subject: [PATCH 01/60] submodule updates --- fsfw | 2 +- tmtc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fsfw b/fsfw index 613dbe95..befaca78 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 613dbe9592c30d9acf4cdb95d81d9f216f07374b +Subproject commit befaca78c660f232c312667202f2bbd5da95c235 diff --git a/tmtc b/tmtc index 45470f8c..28983d38 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 45470f8c05ef214eb41940878ef0bfabf36a4891 +Subproject commit 28983d387b82578a73fbfe052cb53dec1910d021 From afc0f37e8af698c231279106eee14cc1ca0d709a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 21 Apr 2022 16:56:46 +0200 Subject: [PATCH 02/60] rw assembly --- mission/system/CMakeLists.txt | 1 + mission/system/RwAssembly.cpp | 7 +++++++ mission/system/RwAssembly.h | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 mission/system/RwAssembly.cpp create mode 100644 mission/system/RwAssembly.h diff --git a/mission/system/CMakeLists.txt b/mission/system/CMakeLists.txt index 59418a07..b1425512 100644 --- a/mission/system/CMakeLists.txt +++ b/mission/system/CMakeLists.txt @@ -5,6 +5,7 @@ target_sources(${LIB_EIVE_MISSION} PRIVATE PayloadSubsystem.cpp AcsBoardAssembly.cpp + RwAssembly.cpp SusAssembly.cpp DualLanePowerStateMachine.cpp PowerStateMachineBase.cpp diff --git a/mission/system/RwAssembly.cpp b/mission/system/RwAssembly.cpp new file mode 100644 index 00000000..36455c23 --- /dev/null +++ b/mission/system/RwAssembly.cpp @@ -0,0 +1,7 @@ +#include "RwAssembly.h" + +RwAssembly::RwAssembly(object_id_t objectId, object_id_t parentId, PowerSwitchIF* pwrSwitcher, + power::Switch_t switcher, RwHelper helper) + : AssemblyBase(objectId, parentId), helper(helper) { + +} diff --git a/mission/system/RwAssembly.h b/mission/system/RwAssembly.h new file mode 100644 index 00000000..e8705ed1 --- /dev/null +++ b/mission/system/RwAssembly.h @@ -0,0 +1,21 @@ +#ifndef MISSION_SYSTEM_RWASS_H_ +#define MISSION_SYSTEM_RWASS_H_ + +#include + +struct RwHelper { + RwHelper(std::array rwIds) : rwIds(rwIds) {} + + std::array rwIds = {}; +}; + +class RwAssembly: public AssemblyBase { +public: + RwAssembly(object_id_t objectId, object_id_t parentId, PowerSwitchIF* pwrSwitcher, + power::Switch_t switcher, RwHelper helper); +private: + RwHelper helper; + PowerSwitcher pwrSwitcher; +}; + +#endif /* MISSION_SYSTEM_RWASS_H_ */ From 165a4ef814ee659b0eaa57552483da6cbd472a73 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Apr 2022 10:28:29 +0200 Subject: [PATCH 03/60] continued RW Assembly --- linux/devices/GPSHyperionLinuxController.cpp | 15 +- .../devicedefinitions/PlocMPSoCDefinitions.h | 28 +-- linux/devices/ploc/PlocMPSoCHandler.cpp | 7 +- linux/devices/ploc/PlocMPSoCHandler.h | 2 +- mission/system/RwAssembly.cpp | 184 +++++++++++++++++- mission/system/RwAssembly.h | 39 +++- mission/system/TcsBoardAssembly.cpp | 1 - mission/system/TcsBoardAssembly.h | 3 +- 8 files changed, 244 insertions(+), 35 deletions(-) diff --git a/linux/devices/GPSHyperionLinuxController.cpp b/linux/devices/GPSHyperionLinuxController.cpp index 42bc43a6..9c762842 100644 --- a/linux/devices/GPSHyperionLinuxController.cpp +++ b/linux/devices/GPSHyperionLinuxController.cpp @@ -110,12 +110,12 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() { // The data from the device will generally be read all at once. Therefore, we // can set all field here if (not myGpsmm.is_open()) { - if(gpsNotOpenSwitch) { + if (gpsNotOpenSwitch) { // Opening failed - #if FSFW_VERBOSE_LEVEL >= 1 - sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Opening GPSMM failed | " << - "Error " << errno << " | " << gps_errstr(errno) << std::endl; - #endif +#if FSFW_VERBOSE_LEVEL >= 1 + sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Opening GPSMM failed | " + << "Error " << errno << " | " << gps_errstr(errno) << std::endl; +#endif gpsNotOpenSwitch = false; } @@ -124,9 +124,10 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() { gps_data_t *gps = nullptr; gps = myGpsmm.read(); if (gps == nullptr) { - if(gpsReadFailedSwitch) { + if (gpsReadFailedSwitch) { gpsReadFailedSwitch = false; - sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Reading GPS data failed" << std::endl; + sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Reading GPS data failed" + << std::endl; } return; } diff --git a/linux/devices/devicedefinitions/PlocMPSoCDefinitions.h b/linux/devices/devicedefinitions/PlocMPSoCDefinitions.h index fc7fa185..23389208 100644 --- a/linux/devices/devicedefinitions/PlocMPSoCDefinitions.h +++ b/linux/devices/devicedefinitions/PlocMPSoCDefinitions.h @@ -643,24 +643,24 @@ class TcModeIdle : public TcBase { }; class TcCamcmdSend : public TcBase { -public: + public: TcCamcmdSend(uint16_t sequenceCount) : TcBase(apid::TC_CAM_CMD_SEND, sequenceCount) {} -protected: - ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { - if (commandDataLen > MAX_DATA_LENGTH) { - return INVALID_LENGTH; - } - std::memcpy(this->getPacketData(), commandData, commandDataLen); - *(this->getPacketData() + commandDataLen) = CARRIAGE_RETURN; - uint16_t trueLength = commandDataLen + sizeof(CARRIAGE_RETURN) + CRC_SIZE; - this->setPacketDataLength(trueLength - 1); - return HasReturnvaluesIF::RETURN_OK; + protected: + ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { + if (commandDataLen > MAX_DATA_LENGTH) { + return INVALID_LENGTH; } -private: - static const uint8_t MAX_DATA_LENGTH = 10; - static const uint8_t CARRIAGE_RETURN = 0xD; + std::memcpy(this->getPacketData(), commandData, commandDataLen); + *(this->getPacketData() + commandDataLen) = CARRIAGE_RETURN; + uint16_t trueLength = commandDataLen + sizeof(CARRIAGE_RETURN) + CRC_SIZE; + this->setPacketDataLength(trueLength - 1); + return HasReturnvaluesIF::RETURN_OK; + } + private: + static const uint8_t MAX_DATA_LENGTH = 10; + static const uint8_t CARRIAGE_RETURN = 0xD; }; } // namespace mpsoc diff --git a/linux/devices/ploc/PlocMPSoCHandler.cpp b/linux/devices/ploc/PlocMPSoCHandler.cpp index 07a658bf..52fd5812 100644 --- a/linux/devices/ploc/PlocMPSoCHandler.cpp +++ b/linux/devices/ploc/PlocMPSoCHandler.cpp @@ -255,7 +255,7 @@ void PlocMPSoCHandler::fillCommandAndReplyMap() { this->insertInReplyMap(mpsoc::ACK_REPORT, 3, nullptr, mpsoc::SIZE_ACK_REPORT); this->insertInReplyMap(mpsoc::EXE_REPORT, 3, nullptr, mpsoc::SIZE_EXE_REPORT); this->insertInReplyMap(mpsoc::TM_MEMORY_READ_REPORT, 2, nullptr, mpsoc::SIZE_TM_MEM_READ_REPORT); - this->insertInReplyMap(mpsoc::TM_CAM_CMD_RPT, 2, nullptr, SpacePacket::PACKET_MAX_SIZE); + this->insertInReplyMap(mpsoc::TM_CAM_CMD_RPT, 2, nullptr, SpacePacket::PACKET_MAX_SIZE); } ReturnValue_t PlocMPSoCHandler::scanForReply(const uint8_t* start, size_t remainingSize, @@ -653,8 +653,9 @@ ReturnValue_t PlocMPSoCHandler::handleCamCmdRpt(const uint8_t* data) { sif::warning << "PlocMPSoCHandler::handleCamCmdRpt: CRC failure" << std::endl; } const uint8_t* dataFieldPtr = data + mpsoc::SPACE_PACKET_HEADER_SIZE; - std::string camCmdRptMsg(reinterpret_cast( - dataFieldPtr), tmCamCmdRpt.rememberSpacePacketSize - mpsoc::SPACE_PACKET_HEADER_SIZE - 3); + std::string camCmdRptMsg( + reinterpret_cast(dataFieldPtr), + tmCamCmdRpt.rememberSpacePacketSize - mpsoc::SPACE_PACKET_HEADER_SIZE - 3); uint8_t ackValue = *(packet.getPacketData() + packet.getPacketDataLength() - 2); sif::info << "CamCmdRpt message: " << camCmdRptMsg << std::endl; sif::info << "CamCmdRpt Ack value: 0x" << std::hex << static_cast(ackValue) diff --git a/linux/devices/ploc/PlocMPSoCHandler.h b/linux/devices/ploc/PlocMPSoCHandler.h index c4af88d5..d5ea231b 100644 --- a/linux/devices/ploc/PlocMPSoCHandler.h +++ b/linux/devices/ploc/PlocMPSoCHandler.h @@ -4,11 +4,11 @@ #include #include "PlocMPSoCHelper.h" -#include "fsfw/tmtcpacket/SpacePacket.h" #include "fsfw/action/CommandActionHelper.h" #include "fsfw/action/CommandsActionsIF.h" #include "fsfw/devicehandlers/DeviceHandlerBase.h" #include "fsfw/ipc/QueueFactory.h" +#include "fsfw/tmtcpacket/SpacePacket.h" #include "fsfw/tmtcservices/SourceSequenceCounter.h" #include "fsfw_hal/linux/gpio/Gpio.h" #include "fsfw_hal/linux/uart/UartComIF.h" diff --git a/mission/system/RwAssembly.cpp b/mission/system/RwAssembly.cpp index 36455c23..2b99759f 100644 --- a/mission/system/RwAssembly.cpp +++ b/mission/system/RwAssembly.cpp @@ -2,6 +2,186 @@ RwAssembly::RwAssembly(object_id_t objectId, object_id_t parentId, PowerSwitchIF* pwrSwitcher, power::Switch_t switcher, RwHelper helper) - : AssemblyBase(objectId, parentId), helper(helper) { - + : AssemblyBase(objectId, parentId), helper(helper), switcher(pwrSwitcher, switcher) { + ModeListEntry entry; + for (uint8_t idx = 0; idx < NUMBER_RWS; idx++) { + entry.setObject(helper.rwIds[idx]); + entry.setMode(MODE_OFF); + entry.setSubmode(SUBMODE_NONE); + entry.setInheritSubmode(false); + modeTable.insert(entry); + } +} + +void RwAssembly::performChildOperation() { + auto state = switcher.getState(); + if (state != PowerSwitcher::WAIT_OFF and state != PowerSwitcher::WAIT_ON) { + AssemblyBase::performChildOperation(); + return; + } + switcher.doStateMachine(); + if (state == PowerSwitcher::WAIT_OFF and switcher.getState() == PowerSwitcher::SWITCH_IS_OFF) { + // Indicator that a transition to off is finished + AssemblyBase::handleModeReached(); + } else if (state == PowerSwitcher::WAIT_ON and + switcher.getState() == PowerSwitcher::SWITCH_IS_ON) { + // Indicator that mode commanding can be performed now + AssemblyBase::startTransition(targetMode, targetSubmode); + } +} + +ReturnValue_t RwAssembly::commandChildren(Mode_t mode, Submode_t submode) { + ReturnValue_t result = RETURN_OK; + // Initialize the mode table to ensure all devices are in a defined state + for (uint8_t idx = 0; idx < NUMBER_RWS; idx++) { + modeTable[idx].setMode(MODE_OFF); + modeTable[idx].setSubmode(SUBMODE_NONE); + } + if (recoveryState != RecoveryState::RECOVERY_STARTED) { + if (mode == DeviceHandlerIF::MODE_NORMAL or mode == MODE_ON) { + result = handleNormalOrOnModeCmd(mode, submode); + } + } + HybridIterator tableIter(modeTable.begin(), modeTable.end()); + executeTable(tableIter); + return result; +} + +ReturnValue_t RwAssembly::checkChildrenStateOn(Mode_t wantedMode, Submode_t wantedSubmode) { + int devsInCorrectMode = 0; + try { + for (uint8_t idx = 0; idx < NUMBER_RWS; idx++) { + if (childrenMap.at(helper.rwIds[idx]).mode != wantedMode) { + devsInCorrectMode++; + } + } + } catch (const std::out_of_range& e) { + sif::error << "RwAssembly: Invalid children map: " << e.what() << std::endl; + } + if (devsInCorrectMode < 3) { + if (warningSwitch) { + sif::warning << "RwAssembly::checkChildrenStateOn: Only " << devsInCorrectMode + << " devices in correct mode" << std::endl; + warningSwitch = false; + } + return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE; + } + return RETURN_OK; +} + +ReturnValue_t RwAssembly::isModeCombinationValid(Mode_t mode, Submode_t submode) { + if (mode == MODE_ON or mode == MODE_OFF or mode == DeviceHandlerIF::MODE_NORMAL) { + return RETURN_OK; + } + return HasModesIF::INVALID_MODE; +} + +void RwAssembly::startTransition(Mode_t mode, Submode_t submode) { + if (mode != MODE_OFF) { + switcher.turnOn(true); + switcher.doStateMachine(); + if (switcher.getState() == PowerSwitcher::SWITCH_IS_ON) { + AssemblyBase::startTransition(mode, submode); + } else { + // Need to wait with mode commanding until power switcher is done + targetMode = mode; + targetSubmode = submode; + } + } else { + // Perform regular mode commanding first + AssemblyBase::startTransition(mode, submode); + } +} + +void RwAssembly::handleModeReached() { + if (targetMode == MODE_OFF) { + switcher.turnOff(true); + switcher.doStateMachine(); + // Need to wait with call to AssemblyBase::handleModeReached until power switcher is done + if (switcher.getState() == PowerSwitcher::SWITCH_IS_OFF) { + AssemblyBase::handleModeReached(); + } + } else { + AssemblyBase::handleModeReached(); + } +} + +void RwAssembly::handleChildrenLostMode(ReturnValue_t result) { + AssemblyBase::handleChildrenLostMode(result); +} + +ReturnValue_t RwAssembly::handleNormalOrOnModeCmd(Mode_t mode, Submode_t submode) { + ReturnValue_t result = RETURN_OK; + bool needsSecondStep = false; + Mode_t devMode = 0; + object_id_t objId = 0; + try { + for (uint8_t idx = 0; idx < NUMBER_RWS; idx++) { + devMode = childrenMap.at(helper.rwIds[idx]).mode; + objId = helper.rwIds[idx]; + if (mode == devMode) { + modeTable[idx].setMode(mode); + } else if (mode == DeviceHandlerIF::MODE_NORMAL) { + if (isUseable(objId, devMode)) { + if (devMode == MODE_ON) { + modeTable[idx].setMode(mode); + modeTable[idx].setSubmode(SUBMODE_NONE); + } else { + modeTable[idx].setMode(MODE_ON); + modeTable[idx].setSubmode(SUBMODE_NONE); + if (internalState != STATE_SECOND_STEP) { + needsSecondStep = true; + } + } + } + } else if (mode == MODE_ON) { + if (isUseable(objId, devMode)) { + modeTable[idx].setMode(MODE_ON); + modeTable[idx].setSubmode(SUBMODE_NONE); + } + } + } + } catch (const std::out_of_range& e) { + sif::error << "TcsBoardAssembly: Invalid children map: " << e.what() << std::endl; + } + if (needsSecondStep) { + result = NEED_SECOND_STEP; + } + return result; +} + +bool RwAssembly::isUseable(object_id_t object, Mode_t mode) { + if (healthHelper.healthTable->isFaulty(object)) { + return false; + } + + // Check if device is already in target mode + if (childrenMap[object].mode == mode) { + return true; + } + + if (healthHelper.healthTable->isCommandable(object)) { + return true; + } + return false; +} + +ReturnValue_t RwAssembly::initialize() { + ReturnValue_t result = RETURN_OK; + for (const auto& obj : helper.rwIds) { + result = registerChild(obj); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + } + return SubsystemBase::initialize(); +} + +void RwAssembly::handleModeTransitionFailed(ReturnValue_t result) { + if (targetMode == MODE_OFF) { + AssemblyBase::handleModeTransitionFailed(result); + } else { + // To avoid transitioning back to off + triggerEvent(MODE_TRANSITION_FAILED, result); + } } diff --git a/mission/system/RwAssembly.h b/mission/system/RwAssembly.h index e8705ed1..1e94c431 100644 --- a/mission/system/RwAssembly.h +++ b/mission/system/RwAssembly.h @@ -2,6 +2,7 @@ #define MISSION_SYSTEM_RWASS_H_ #include +#include struct RwHelper { RwHelper(std::array rwIds) : rwIds(rwIds) {} @@ -9,13 +10,41 @@ struct RwHelper { std::array rwIds = {}; }; -class RwAssembly: public AssemblyBase { -public: +class RwAssembly : public AssemblyBase { + public: RwAssembly(object_id_t objectId, object_id_t parentId, PowerSwitchIF* pwrSwitcher, - power::Switch_t switcher, RwHelper helper); -private: + power::Switch_t switcher, RwHelper helper); + + private: + static constexpr uint8_t NUMBER_RWS = 4; RwHelper helper; - PowerSwitcher pwrSwitcher; + PowerSwitcher switcher; + bool warningSwitch = true; + FixedArrayList modeTable; + + ReturnValue_t initialize() override; + + ReturnValue_t handleNormalOrOnModeCmd(Mode_t mode, Submode_t submode); + /** + * Check whether it makes sense to send mode commands to the device + * @param object + * @param mode + * @return + */ + bool isUseable(object_id_t object, Mode_t mode); + + // AssemblyBase implementation + void performChildOperation() override; + ReturnValue_t commandChildren(Mode_t mode, Submode_t submode) override; + ReturnValue_t checkChildrenStateOn(Mode_t wantedMode, Submode_t wantedSubmode) override; + ReturnValue_t isModeCombinationValid(Mode_t mode, Submode_t submode) override; + void startTransition(Mode_t mode, Submode_t submode) override; + void handleModeReached() override; + + // These two overrides prevent a transition of the whole assembly back to off just because + // some devices are not working + void handleChildrenLostMode(ReturnValue_t result) override; + void handleModeTransitionFailed(ReturnValue_t result) override; }; #endif /* MISSION_SYSTEM_RWASS_H_ */ diff --git a/mission/system/TcsBoardAssembly.cpp b/mission/system/TcsBoardAssembly.cpp index f011c931..7655603b 100644 --- a/mission/system/TcsBoardAssembly.cpp +++ b/mission/system/TcsBoardAssembly.cpp @@ -32,7 +32,6 @@ void TcsBoardAssembly::performChildOperation() { switcher.getState() == PowerSwitcher::SWITCH_IS_ON) { // Indicator that mode commanding can be performed now AssemblyBase::startTransition(targetMode, targetSubmode); - // AssemblyBase::performChildOperation(); } } diff --git a/mission/system/TcsBoardAssembly.h b/mission/system/TcsBoardAssembly.h index 832f335d..c23fbd7c 100644 --- a/mission/system/TcsBoardAssembly.h +++ b/mission/system/TcsBoardAssembly.h @@ -21,8 +21,6 @@ class TcsBoardAssembly : public AssemblyBase, public ConfirmsFailuresIF { ReturnValue_t initialize() override; - void performChildOperation() override; - private: static constexpr uint8_t NUMBER_RTDS = 16; PowerSwitcher switcher; @@ -44,6 +42,7 @@ class TcsBoardAssembly : public AssemblyBase, public ConfirmsFailuresIF { MessageQueueId_t getEventReceptionQueue() override; // AssemblyBase implementation + void performChildOperation() override; ReturnValue_t commandChildren(Mode_t mode, Submode_t submode) override; ReturnValue_t checkChildrenStateOn(Mode_t wantedMode, Submode_t wantedSubmode) override; ReturnValue_t isModeCombinationValid(Mode_t mode, Submode_t submode) override; From 88249cd5beb5af90bddb2843fd78da68f0d275f1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Apr 2022 11:07:40 +0200 Subject: [PATCH 04/60] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17d29e7b..3e981a75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ list yields a list of all related PRs for each release. # [v1.11.0] +## Added + +- `RwAssembly` added to system components + ## Changed - Update rootfs base of Linux, all related OBSW changes From 106976290324739abab8fbdba0e2a0c2ac4f59cb Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Apr 2022 11:11:04 +0200 Subject: [PATCH 05/60] update config.h.in file --- linux/fsfwconfig/OBSWConfig.h.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linux/fsfwconfig/OBSWConfig.h.in b/linux/fsfwconfig/OBSWConfig.h.in index 55e6e8c5..9b0d26c9 100644 --- a/linux/fsfwconfig/OBSWConfig.h.in +++ b/linux/fsfwconfig/OBSWConfig.h.in @@ -129,6 +129,8 @@ debugging. */ #define OBSW_DEBUG_BPX_BATT 0 #define OBSW_TEST_IMTQ 0 #define OBSW_DEBUG_IMTQ 0 +#define OBSW_TEST_RW 0 +#define OBSW_DEBUG_RW 0 #define OBSW_TEST_LIBGPIOD 0 #define OBSW_TEST_PLOC_HANDLER 0 From d29dd48d1e2fd4f99a519cea1d97ea939abae16c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Apr 2022 11:18:10 +0200 Subject: [PATCH 06/60] update project file: changed default unix sysroot --- bsp_q7s/core/ObjectFactory.cpp | 9 ++++----- linux/obc/PdecHandler.cpp | 1 - misc/eclipse/.cproject | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index ecc88ede..e69f84b2 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -732,29 +732,28 @@ void ObjectFactory::createReactionWheelComponents(LinuxLibgpioIF* gpioComIF) { auto rwHandler1 = new RwHandler(objects::RW1, objects::SPI_COM_IF, rw1SpiCookie, gpioComIF, gpioIds::EN_RW1); -#if OBSW_DEBUG_RW == 1 +#if OBSW_TEST_RW == 1 rwHandler1->setStartUpImmediately(); #endif rw1SpiCookie->setCallbackArgs(rwHandler1); - rwHandler1->setStartUpImmediately(); auto rwHandler2 = new RwHandler(objects::RW2, objects::SPI_COM_IF, rw2SpiCookie, gpioComIF, gpioIds::EN_RW2); -#if OBSW_DEBUG_RW == 1 +#if OBSW_TEST_RW == 1 rwHandler2->setStartUpImmediately(); #endif rw2SpiCookie->setCallbackArgs(rwHandler2); auto rwHandler3 = new RwHandler(objects::RW3, objects::SPI_COM_IF, rw3SpiCookie, gpioComIF, gpioIds::EN_RW3); -#if OBSW_DEBUG_RW == 1 +#if OBSW_TEST_RW == 1 rwHandler3->setStartUpImmediately(); #endif rw3SpiCookie->setCallbackArgs(rwHandler3); auto rwHandler4 = new RwHandler(objects::RW4, objects::SPI_COM_IF, rw4SpiCookie, gpioComIF, gpioIds::EN_RW4); -#if OBSW_DEBUG_RW == 1 +#if OBSW_TEST_RW == 1 rwHandler4->setStartUpImmediately(); #endif rw4SpiCookie->setCallbackArgs(rwHandler4); diff --git a/linux/obc/PdecHandler.cpp b/linux/obc/PdecHandler.cpp index 48816512..4c8beeed 100644 --- a/linux/obc/PdecHandler.cpp +++ b/linux/obc/PdecHandler.cpp @@ -6,7 +6,6 @@ #include #include -#include "OBSWConfig.h" #include "fsfw/ipc/QueueFactory.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" diff --git a/misc/eclipse/.cproject b/misc/eclipse/.cproject index b0f56271..8c58dee8 100644 --- a/misc/eclipse/.cproject +++ b/misc/eclipse/.cproject @@ -589,7 +589,7 @@ - + @@ -603,7 +603,7 @@ - + @@ -868,6 +870,8 @@ + + @@ -1595,7 +1602,8 @@ - + + - + @@ -699,7 +700,8 @@ - + + @@ -699,7 +700,8 @@ - + + @@ -870,6 +871,7 @@ + @@ -870,6 +871,7 @@ + - + @@ -119,7 +119,7 @@ - + @@ -187,7 +187,7 @@ - + @@ -255,7 +255,7 @@ - + @@ -418,7 +418,7 @@ - + @@ -580,7 +580,7 @@ - + @@ -750,7 +750,7 @@ - + @@ -917,7 +917,7 @@ - + @@ -1084,7 +1084,7 @@ - + @@ -1249,7 +1249,7 @@ - + @@ -1415,7 +1415,7 @@ - + @@ -1481,7 +1481,7 @@ - + @@ -1649,7 +1649,7 @@ - + @@ -1718,7 +1718,7 @@ - + From 8ccd55dd067a79897deea98f5adbcc3ee5ef748e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 00:58:19 +0200 Subject: [PATCH 48/60] update .cproject file --- bsp_q7s/fm/fmObjectFactory.cpp | 2 +- misc/eclipse/.cproject | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bsp_q7s/fm/fmObjectFactory.cpp b/bsp_q7s/fm/fmObjectFactory.cpp index 0ebbcb28..1f561430 100644 --- a/bsp_q7s/fm/fmObjectFactory.cpp +++ b/bsp_q7s/fm/fmObjectFactory.cpp @@ -753,7 +753,7 @@ void ObjectFactory::createReactionWheelComponents(LinuxLibgpioIF* gpioComIF, RwHelper rwHelper(rwIds); auto* rwAss = new RwAssembly(objects::RW_ASS, objects::NO_OBJECT, pwrSwitcher, pcdu::Switches::PDU2_CH2_RW_5V, rwHelper); - rwAss-> + static_cast(rwAss); #endif /* OBSW_ADD_RW == 1 */ } diff --git a/misc/eclipse/.cproject b/misc/eclipse/.cproject index ac8f3d9f..47f08a0a 100644 --- a/misc/eclipse/.cproject +++ b/misc/eclipse/.cproject @@ -57,7 +57,7 @@ - + @@ -119,7 +119,7 @@ - + @@ -187,7 +187,7 @@ - + @@ -255,7 +255,7 @@ - + @@ -418,7 +418,7 @@ - + @@ -580,7 +580,7 @@ - + @@ -603,7 +603,7 @@ - + - + @@ -917,7 +917,7 @@ - + @@ -1084,7 +1084,7 @@ - + @@ -1249,7 +1249,7 @@ - + @@ -1415,7 +1415,7 @@ - + @@ -1481,7 +1481,7 @@ - + @@ -1649,7 +1649,7 @@ - + @@ -1718,7 +1718,7 @@ - + From 95fd3238e7e8b74f5b94fb0e1e70be8475d142c5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 01:00:21 +0200 Subject: [PATCH 49/60] another .cproject update --- misc/eclipse/.cproject | 356 ++--------------------------------------- 1 file changed, 12 insertions(+), 344 deletions(-) diff --git a/misc/eclipse/.cproject b/misc/eclipse/.cproject index 47f08a0a..f40535b7 100644 --- a/misc/eclipse/.cproject +++ b/misc/eclipse/.cproject @@ -57,7 +57,7 @@ - + @@ -119,7 +119,7 @@ - + @@ -187,7 +187,7 @@ - + @@ -255,7 +255,7 @@ - + @@ -418,7 +418,7 @@ - + @@ -580,7 +580,7 @@ - + @@ -750,7 +750,7 @@ - + @@ -917,7 +917,7 @@ - + @@ -1084,344 +1084,12 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1481,7 +1149,7 @@ - + @@ -1649,7 +1317,7 @@ - + @@ -1718,7 +1386,7 @@ - + From df7e0007d0b3c2b573b005f5db3f33e8c1c7f299 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 01:02:29 +0200 Subject: [PATCH 50/60] schedule RW ASS --- bsp_q7s/core/InitMission.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bsp_q7s/core/InitMission.cpp b/bsp_q7s/core/InitMission.cpp index 17e390fe..631c89eb 100644 --- a/bsp_q7s/core/InitMission.cpp +++ b/bsp_q7s/core/InitMission.cpp @@ -130,6 +130,12 @@ void initmission::initTasks() { initmission::printAddObjectError("ACS_BOARD_ASS", objects::ACS_BOARD_ASS); } #endif /* OBSW_ADD_ACS_HANDLERS */ +#if OBSW_ADD_RW == 1 + result = sysTask->addComponent(objects::RW_ASS); + if (result != HasReturnvaluesIF::RETURN_OK) { + initmission::printAddObjectError("RW_ASS", objects::RW_ASS); + } +#endif #if OBSW_ADD_SUS_BOARD_ASS == 1 result = sysTask->addComponent(objects::SUS_BOARD_ASS); From 91b69eacf68ec67877ad6168fe154d9266ef33de Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 01:48:26 +0200 Subject: [PATCH 51/60] A lot of stuff - refactored and simplified RW assemblies - create separate SPI Com IF for RWs - Update .cproject file: Fixed to decrease indexer parsing times --- bsp_q7s/CMakeLists.txt | 4 +- bsp_q7s/core/CMakeLists.txt | 1 + .../ObjectFactory.cpp} | 180 ++-- bsp_q7s/core/ObjectFactory.h | 8 +- bsp_q7s/em/emObjectFactory.cpp | 933 +----------------- bsp_q7s/fm/CMakeLists.txt | 3 - bsp_q7s/fmObjectFactory.cpp | 64 ++ linux/ObjectFactory.cpp | 26 +- linux/fsfwconfig/objects/systemObjectList.h | 3 +- mission/system/RwAssembly.cpp | 10 +- mission/system/RwAssembly.h | 1 + unittest/controller/testAcsController.cpp | 18 +- 12 files changed, 192 insertions(+), 1059 deletions(-) rename bsp_q7s/{fm/fmObjectFactory.cpp => core/ObjectFactory.cpp} (93%) delete mode 100644 bsp_q7s/fm/CMakeLists.txt create mode 100644 bsp_q7s/fmObjectFactory.cpp diff --git a/bsp_q7s/CMakeLists.txt b/bsp_q7s/CMakeLists.txt index 34ee8e2a..cf3425c9 100644 --- a/bsp_q7s/CMakeLists.txt +++ b/bsp_q7s/CMakeLists.txt @@ -25,7 +25,9 @@ add_subdirectory(core) if(EIVE_Q7S_EM) add_subdirectory(em) else() - add_subdirectory(fm) + target_sources(${OBSW_NAME} PUBLIC + fmObjectFactory.cpp + ) endif() add_subdirectory(memory) diff --git a/bsp_q7s/core/CMakeLists.txt b/bsp_q7s/core/CMakeLists.txt index e5668acc..344112b6 100644 --- a/bsp_q7s/core/CMakeLists.txt +++ b/bsp_q7s/core/CMakeLists.txt @@ -1,6 +1,7 @@ target_sources(${OBSW_NAME} PRIVATE CoreController.cpp InitMission.cpp + ObjectFactory.cpp ) target_sources(${SIMPLE_OBSW_NAME} PRIVATE diff --git a/bsp_q7s/fm/fmObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp similarity index 93% rename from bsp_q7s/fm/fmObjectFactory.cpp rename to bsp_q7s/core/ObjectFactory.cpp index 1f561430..a3a21b3c 100644 --- a/bsp_q7s/fm/fmObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include "ObjectFactory.h" #include "OBSWConfig.h" #include "bsp_q7s/boardtest/Q7STestTask.h" @@ -9,7 +7,6 @@ #include "bsp_q7s/callbacks/q7sGpioCallbacks.h" #include "bsp_q7s/callbacks/rwSpiCallback.h" #include "bsp_q7s/core/CoreController.h" -#include "bsp_q7s/core/ObjectFactory.h" #include "bsp_q7s/memory/FileSystemHandler.h" #include "busConf.h" #include "ccsdsConfig.h" @@ -39,9 +36,12 @@ #include "linux/obc/PdecHandler.h" #include "linux/obc/Ptme.h" #include "linux/obc/PtmeConfig.h" +#include "mission/system/RwAssembly.h" #include "mission/system/fdir/AcsBoardFdir.h" +#include "mission/system/fdir/GomspacePowerFdir.h" #include "mission/system/fdir/RtdFdir.h" #include "mission/system/fdir/SusFdir.h" +#include "mission/system/fdir/SyrlinksFdir.h" #include "tmtc/apid.h" #include "tmtc/pusIds.h" #if OBSW_TEST_LIBGPIOD == 1 @@ -92,11 +92,10 @@ #include "mission/tmtc/CCSDSHandler.h" #include "mission/tmtc/VirtualChannel.h" #include "mission/utility/TmFunnel.h" + ResetArgs resetArgsGnss0; ResetArgs resetArgsGnss1; -void ObjectFactory::setStatics() { Factory::setStaticFrameworkObjectIds(); } - void Factory::setStaticFrameworkObjectIds() { PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR; PusServiceBase::packetDestination = objects::TM_FUNNEL; @@ -120,86 +119,7 @@ void Factory::setStaticFrameworkObjectIds() { TmPacketBase::timeStamperId = objects::TIME_STAMPER; } -void ObjectFactory::produce(void* args) { - ObjectFactory::setStatics(); - ObjectFactory::produceGenericObjects(); - - LinuxLibgpioIF* gpioComIF = nullptr; - UartComIF* uartComIF = nullptr; - SpiComIF* spiComIF = nullptr; - I2cComIF* i2cComIF = nullptr; - PowerSwitchIF* pwrSwitcher = nullptr; - createCommunicationInterfaces(&gpioComIF, &uartComIF, &spiComIF, &i2cComIF); - createTmpComponents(); - new CoreController(objects::CORE_CONTROLLER); - - gpioCallbacks::disableAllDecoder(gpioComIF); - createPcduComponents(gpioComIF, &pwrSwitcher); - createRadSensorComponent(gpioComIF); - createSunSensorComponents(gpioComIF, spiComIF, pwrSwitcher, q7s::SPI_DEFAULT_DEV); - -#if OBSW_ADD_ACS_BOARD == 1 - createAcsBoardComponents(gpioComIF, uartComIF, pwrSwitcher); -#endif - createHeaterComponents(); - createSolarArrayDeploymentComponents(); - createPlPcduComponents(gpioComIF, spiComIF, pwrSwitcher); -#if OBSW_ADD_SYRLINKS == 1 - createSyrlinksComponents(pwrSwitcher); -#endif /* OBSW_ADD_SYRLINKS == 1 */ - createRtdComponents(q7s::SPI_DEFAULT_DEV, gpioComIF, pwrSwitcher); - createPayloadComponents(gpioComIF); - -#if OBSW_ADD_MGT == 1 - I2cCookie* imtqI2cCookie = - new I2cCookie(addresses::IMTQ, IMTQ::MAX_REPLY_SIZE, q7s::I2C_DEFAULT_DEV); - auto imtqHandler = new IMTQHandler(objects::IMTQ_HANDLER, objects::I2C_COM_IF, imtqI2cCookie, - pcdu::Switches::PDU1_CH3_MGT_5V); - imtqHandler->setPowerSwitcher(pwrSwitcher); - static_cast(imtqHandler); -#if OBSW_TEST_IMTQ == 1 - imtqHandler->setStartUpImmediately(); - imtqHandler->setToGoToNormal(true); -#endif -#if OBSW_DEBUG_IMTQ == 1 - imtqHandler->setDebugMode(true); -#endif -#endif - createReactionWheelComponents(gpioComIF, pwrSwitcher); - -#if OBSW_ADD_BPX_BATTERY_HANDLER == 1 - I2cCookie* bpxI2cCookie = new I2cCookie(addresses::BPX_BATTERY, 100, q7s::I2C_DEFAULT_DEV); - BpxBatteryHandler* bpxHandler = - new BpxBatteryHandler(objects::BPX_BATT_HANDLER, objects::I2C_COM_IF, bpxI2cCookie); - bpxHandler->setStartUpImmediately(); - bpxHandler->setToGoToNormalMode(true); -#if OBSW_DEBUG_BPX_BATT == 1 - bpxHandler->setDebugMode(true); -#endif -#endif - new FileSystemHandler(objects::FILE_SYSTEM_HANDLER); - -#if OBSW_ADD_STAR_TRACKER == 1 - UartCookie* starTrackerCookie = - new UartCookie(objects::STAR_TRACKER, q7s::UART_STAR_TRACKER_DEV, uart::STAR_TRACKER_BAUD, - startracker::MAX_FRAME_SIZE * 2 + 2, UartModes::NON_CANONICAL); - starTrackerCookie->setNoFixedSizeReply(); - StrHelper* strHelper = new StrHelper(objects::STR_HELPER); - auto starTracker = - new StarTrackerHandler(objects::STAR_TRACKER, objects::UART_COM_IF, starTrackerCookie, - strHelper, pcdu::PDU1_CH2_STAR_TRACKER_5V); - starTracker->setPowerSwitcher(pwrSwitcher); - -#endif /* OBSW_ADD_STAR_TRACKER == 1 */ -#if OBSW_USE_CCSDS_IP_CORE == 1 - createCcsdsComponents(gpioComIF); -#endif /* OBSW_USE_CCSDS_IP_CORE == 1 */ - /* Test Task */ -#if OBSW_ADD_TEST_CODE == 1 - createTestComponents(gpioComIF); -#endif /* OBSW_ADD_TEST_CODE == 1 */ - new PlocMemoryDumper(objects::PLOC_MEMORY_DUMPER); -} +void ObjectFactory::setStatics() { Factory::setStaticFrameworkObjectIds(); } void ObjectFactory::createTmpComponents() { I2cCookie* i2cCookieTmp1075tcs1 = @@ -217,8 +137,10 @@ void ObjectFactory::createTmpComponents() { } void ObjectFactory::createCommunicationInterfaces(LinuxLibgpioIF** gpioComIF, UartComIF** uartComIF, - SpiComIF** spiComIF, I2cComIF** i2cComIF) { - if (gpioComIF == nullptr or uartComIF == nullptr or spiComIF == nullptr) { + SpiComIF** spiMainComIF, I2cComIF** i2cComIF, + SpiComIF** spiRWComIF) { + if (gpioComIF == nullptr or uartComIF == nullptr or spiMainComIF == nullptr or + spiRWComIF == nullptr) { sif::error << "ObjectFactory::createCommunicationInterfaces: Invalid passed ComIF pointer" << std::endl; } @@ -228,8 +150,8 @@ void ObjectFactory::createCommunicationInterfaces(LinuxLibgpioIF** gpioComIF, Ua new CspComIF(objects::CSP_COM_IF); *i2cComIF = new I2cComIF(objects::I2C_COM_IF); *uartComIF = new UartComIF(objects::UART_COM_IF); - *spiComIF = new SpiComIF(objects::SPI_COM_IF, *gpioComIF); - + *spiMainComIF = new SpiComIF(objects::SPI_MAIN_COM_IF, *gpioComIF); + *spiRWComIF = new SpiComIF(objects::SPI_RW_COM_IF, *gpioComIF); /* Adding gpios for chip select decoding to the gpioComIf */ q7s::gpioCallbacks::initSpiCsDecoder(*gpioComIF); } @@ -292,7 +214,7 @@ void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { SpiCookie* spiCookieRadSensor = new SpiCookie( addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, std::string(q7s::SPI_DEFAULT_DEV), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, + auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_MAIN_COM_IF, spiCookieRadSensor, gpioComIF); static_cast(radSensor); // The radiation sensor ADC is powered by the 5V stack connector which should always be on @@ -412,7 +334,7 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI SpiCookie* spiCookie = new SpiCookie(addresses::MGM_0_LIS3, gpioIds::MGM_0_LIS3_CS, spiDev, MGMLIS3MDL::MAX_BUFFER_SIZE, spi::DEFAULT_LIS3_MODE, spi::DEFAULT_LIS3_SPEED); - auto mgmLis3Handler = new MgmLIS3MDLHandler(objects::MGM_0_LIS3_HANDLER, objects::SPI_COM_IF, + auto mgmLis3Handler = new MgmLIS3MDLHandler(objects::MGM_0_LIS3_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, spi::LIS3_TRANSITION_DELAY); fdir = new AcsBoardFdir(objects::MGM_0_LIS3_HANDLER); mgmLis3Handler->setCustomFdir(fdir); @@ -427,8 +349,9 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI spiCookie = new SpiCookie(addresses::MGM_1_RM3100, gpioIds::MGM_1_RM3100_CS, spiDev, RM3100::MAX_BUFFER_SIZE, spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED); - auto mgmRm3100Handler = new MgmRM3100Handler(objects::MGM_1_RM3100_HANDLER, objects::SPI_COM_IF, - spiCookie, spi::RM3100_TRANSITION_DELAY); + auto mgmRm3100Handler = + new MgmRM3100Handler(objects::MGM_1_RM3100_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, + spi::RM3100_TRANSITION_DELAY); fdir = new AcsBoardFdir(objects::MGM_1_RM3100_HANDLER); mgmRm3100Handler->setCustomFdir(fdir); mgmRm3100Handler->setParent(objects::ACS_BOARD_ASS); @@ -443,7 +366,7 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI spiCookie = new SpiCookie(addresses::MGM_2_LIS3, gpioIds::MGM_2_LIS3_CS, spiDev, MGMLIS3MDL::MAX_BUFFER_SIZE, spi::DEFAULT_LIS3_MODE, spi::DEFAULT_LIS3_SPEED); - mgmLis3Handler = new MgmLIS3MDLHandler(objects::MGM_2_LIS3_HANDLER, objects::SPI_COM_IF, + mgmLis3Handler = new MgmLIS3MDLHandler(objects::MGM_2_LIS3_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, spi::LIS3_TRANSITION_DELAY); fdir = new AcsBoardFdir(objects::MGM_2_LIS3_HANDLER); mgmLis3Handler->setCustomFdir(fdir); @@ -459,7 +382,7 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI spiCookie = new SpiCookie(addresses::MGM_3_RM3100, gpioIds::MGM_3_RM3100_CS, spiDev, RM3100::MAX_BUFFER_SIZE, spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED); - mgmRm3100Handler = new MgmRM3100Handler(objects::MGM_3_RM3100_HANDLER, objects::SPI_COM_IF, + mgmRm3100Handler = new MgmRM3100Handler(objects::MGM_3_RM3100_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, spi::RM3100_TRANSITION_DELAY); fdir = new AcsBoardFdir(objects::MGM_3_RM3100_HANDLER); mgmRm3100Handler->setCustomFdir(fdir); @@ -476,8 +399,9 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI spiCookie = new SpiCookie(addresses::GYRO_0_ADIS, gpioIds::GYRO_0_ADIS_CS, spiDev, ADIS1650X::MAXIMUM_REPLY_SIZE, spi::DEFAULT_ADIS16507_MODE, spi::DEFAULT_ADIS16507_SPEED); - auto adisHandler = new GyroADIS1650XHandler(objects::GYRO_0_ADIS_HANDLER, objects::SPI_COM_IF, - spiCookie, ADIS1650X::Type::ADIS16505); + auto adisHandler = + new GyroADIS1650XHandler(objects::GYRO_0_ADIS_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, + ADIS1650X::Type::ADIS16505); fdir = new AcsBoardFdir(objects::GYRO_0_ADIS_HANDLER); adisHandler->setCustomFdir(fdir); adisHandler->setParent(objects::ACS_BOARD_ASS); @@ -493,8 +417,8 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI spiCookie = new SpiCookie(addresses::GYRO_1_L3G, gpioIds::GYRO_1_L3G_CS, spiDev, L3GD20H::MAX_BUFFER_SIZE, spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); - auto gyroL3gHandler = new GyroHandlerL3GD20H(objects::GYRO_1_L3G_HANDLER, objects::SPI_COM_IF, - spiCookie, spi::L3G_TRANSITION_DELAY); + auto gyroL3gHandler = new GyroHandlerL3GD20H( + objects::GYRO_1_L3G_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, spi::L3G_TRANSITION_DELAY); fdir = new AcsBoardFdir(objects::GYRO_1_L3G_HANDLER); gyroL3gHandler->setCustomFdir(fdir); gyroL3gHandler->setParent(objects::ACS_BOARD_ASS); @@ -510,7 +434,7 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI spiCookie = new SpiCookie(addresses::GYRO_2_ADIS, gpioIds::GYRO_2_ADIS_CS, spiDev, ADIS1650X::MAXIMUM_REPLY_SIZE, spi::DEFAULT_ADIS16507_MODE, spi::DEFAULT_ADIS16507_SPEED); - adisHandler = new GyroADIS1650XHandler(objects::GYRO_2_ADIS_HANDLER, objects::SPI_COM_IF, + adisHandler = new GyroADIS1650XHandler(objects::GYRO_2_ADIS_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, ADIS1650X::Type::ADIS16505); fdir = new AcsBoardFdir(objects::GYRO_2_ADIS_HANDLER); adisHandler->setCustomFdir(fdir); @@ -523,7 +447,7 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI spiCookie = new SpiCookie(addresses::GYRO_3_L3G, gpioIds::GYRO_3_L3G_CS, spiDev, L3GD20H::MAX_BUFFER_SIZE, spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); - gyroL3gHandler = new GyroHandlerL3GD20H(objects::GYRO_3_L3G_HANDLER, objects::SPI_COM_IF, + gyroL3gHandler = new GyroHandlerL3GD20H(objects::GYRO_3_L3G_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, spi::L3G_TRANSITION_DELAY); fdir = new AcsBoardFdir(objects::GYRO_3_L3G_HANDLER); gyroL3gHandler->setCustomFdir(fdir); @@ -739,8 +663,8 @@ void ObjectFactory::createReactionWheelComponents(LinuxLibgpioIF* gpioComIF, rwCookies[idx] = new SpiCookie(rwCookieParams[idx].first, rwCookieParams[idx].second, q7s::SPI_RW_DEV, RwDefinitions::MAX_REPLY_SIZE, spi::RW_MODE, spi::RW_SPEED, &rwSpiCallback::spiCallback, nullptr); - rws[idx] = - new RwHandler(rwIds[idx], objects::SPI_COM_IF, rwCookies[idx], gpioComIF, rwGpioIds[idx]); + rws[idx] = new RwHandler(rwIds[idx], objects::SPI_RW_COM_IF, rwCookies[idx], gpioComIF, + rwGpioIds[idx]); rwCookies[idx]->setCallbackArgs(rws[idx]); #if OBSW_TEST_RW == 1 rws[idx]->setStartUpImmediately(); @@ -918,8 +842,8 @@ void ObjectFactory::createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spi::DEFAULT_MAX_1227_MODE, spi::PL_PCDU_MAX_1227_SPEED); // Create device handler components auto plPcduHandler = new PayloadPcduHandler( - objects::PLPCDU_HANDLER, objects::SPI_COM_IF, spiCookie, gpioComIF, SdCardManager::instance(), - pwrSwitcher, pcdu::Switches::PDU2_CH1_PL_PCDU_BATT_0_14V8, + objects::PLPCDU_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, gpioComIF, + SdCardManager::instance(), pwrSwitcher, pcdu::Switches::PDU2_CH1_PL_PCDU_BATT_0_14V8, pcdu::Switches::PDU2_CH6_PL_PCDU_BATT_1_14V8, false); spiCookie->setCallbackMode(PayloadPcduHandler::extConvAsTwoCallback, plPcduHandler); // plPcduHandler->enablePeriodicPrintout(true, 5); @@ -946,6 +870,50 @@ void ObjectFactory::createTestComponents(LinuxLibgpioIF* gpioComIF) { #endif } +void ObjectFactory::createStrComponents(PowerSwitchIF* pwrSwitcher) { + UartCookie* starTrackerCookie = + new UartCookie(objects::STAR_TRACKER, q7s::UART_STAR_TRACKER_DEV, uart::STAR_TRACKER_BAUD, + startracker::MAX_FRAME_SIZE * 2 + 2, UartModes::NON_CANONICAL); + starTrackerCookie->setNoFixedSizeReply(); + StrHelper* strHelper = new StrHelper(objects::STR_HELPER); + auto starTracker = + new StarTrackerHandler(objects::STAR_TRACKER, objects::UART_COM_IF, starTrackerCookie, + strHelper, pcdu::PDU1_CH2_STAR_TRACKER_5V); + starTracker->setPowerSwitcher(pwrSwitcher); +} + +void ObjectFactory::createImtqComponents(PowerSwitchIF* pwrSwitcher) { + I2cCookie* imtqI2cCookie = + new I2cCookie(addresses::IMTQ, IMTQ::MAX_REPLY_SIZE, q7s::I2C_DEFAULT_DEV); + auto imtqHandler = new IMTQHandler(objects::IMTQ_HANDLER, objects::I2C_COM_IF, imtqI2cCookie, + pcdu::Switches::PDU1_CH3_MGT_5V); + imtqHandler->setPowerSwitcher(pwrSwitcher); + static_cast(imtqHandler); +#if OBSW_TEST_IMTQ == 1 + imtqHandler->setStartUpImmediately(); + imtqHandler->setToGoToNormal(true); +#endif +#if OBSW_DEBUG_IMTQ == 1 + imtqHandler->setDebugMode(true); +#endif +} + +void ObjectFactory::createBpxBatteryComponent() { + I2cCookie* bpxI2cCookie = new I2cCookie(addresses::BPX_BATTERY, 100, q7s::I2C_DEFAULT_DEV); + BpxBatteryHandler* bpxHandler = + new BpxBatteryHandler(objects::BPX_BATT_HANDLER, objects::I2C_COM_IF, bpxI2cCookie); + bpxHandler->setStartUpImmediately(); + bpxHandler->setToGoToNormalMode(true); +#if OBSW_DEBUG_BPX_BATT == 1 + bpxHandler->setDebugMode(true); +#endif +} + +void ObjectFactory::createMiscComponents() { + new FileSystemHandler(objects::FILE_SYSTEM_HANDLER); + new PlocMemoryDumper(objects::PLOC_MEMORY_DUMPER); +} + void ObjectFactory::testAcsBrdAss(AcsBoardAssembly* acsAss) { CommandMessage msg; ModeMessage::setModeMessage(&msg, ModeMessage::CMD_MODE_COMMAND, DeviceHandlerIF::MODE_NORMAL, diff --git a/bsp_q7s/core/ObjectFactory.h b/bsp_q7s/core/ObjectFactory.h index 69b491f8..e2349f9b 100644 --- a/bsp_q7s/core/ObjectFactory.h +++ b/bsp_q7s/core/ObjectFactory.h @@ -18,7 +18,8 @@ void setStatics(); void produce(void* args); void createCommunicationInterfaces(LinuxLibgpioIF** gpioComIF, UartComIF** uartComIF, - SpiComIF** spiComIF, I2cComIF** i2cComIF); + SpiComIF** spiMainComIF, I2cComIF** i2cComIF, + SpiComIF** spiRwComIF); void createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF** pwrSwitcher); void createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, PowerSwitchIF* pwrSwitcher); @@ -27,11 +28,16 @@ void createRadSensorComponent(LinuxLibgpioIF* gpioComIF); void createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComIF* uartComIF, PowerSwitchIF* pwrSwitcher); void createHeaterComponents(); +void createImtqComponents(PowerSwitchIF* pwrSwitcher); +void createBpxBatteryComponent(); +void createStrComponents(PowerSwitchIF* pwrSwitcher); void createSolarArrayDeploymentComponents(); void createSyrlinksComponents(PowerSwitchIF* pwrSwitcher); void createPayloadComponents(LinuxLibgpioIF* gpioComIF); void createReactionWheelComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF* pwrSwitcher); void createCcsdsComponents(LinuxLibgpioIF* gpioComIF); +void createMiscComponents(); + void createTestComponents(LinuxLibgpioIF* gpioComIF); void testAcsBrdAss(AcsBoardAssembly* assAss); diff --git a/bsp_q7s/em/emObjectFactory.cpp b/bsp_q7s/em/emObjectFactory.cpp index 077bc3d2..561786e8 100644 --- a/bsp_q7s/em/emObjectFactory.cpp +++ b/bsp_q7s/em/emObjectFactory.cpp @@ -1,126 +1,13 @@ -#include -#include - #include "OBSWConfig.h" -#include "bsp_q7s/boardtest/Q7STestTask.h" -#include "bsp_q7s/callbacks/gnssCallback.h" -#include "bsp_q7s/callbacks/pcduSwitchCb.h" -#include "bsp_q7s/callbacks/q7sGpioCallbacks.h" -#include "bsp_q7s/callbacks/rwSpiCallback.h" #include "bsp_q7s/core/CoreController.h" #include "bsp_q7s/core/ObjectFactory.h" -#include "bsp_q7s/memory/FileSystemHandler.h" #include "busConf.h" -#include "ccsdsConfig.h" +#include "commonObjects.h" #include "devConf.h" -#include "devices/addresses.h" -#include "devices/gpioIds.h" -#include "devices/powerSwitcherList.h" -#include "fsfw/ipc/QueueFactory.h" -#include "linux/ObjectFactory.h" -#include "linux/boardtest/I2cTestClass.h" -#include "linux/boardtest/SpiTestClass.h" -#include "linux/boardtest/UartTestClass.h" -#include "linux/callbacks/gpioCallbacks.h" -#include "linux/csp/CspComIF.h" -#include "linux/csp/CspCookie.h" -#include "linux/devices/GPSHyperionLinuxController.h" -#include "linux/devices/devicedefinitions/PlocMPSoCDefinitions.h" -#include "linux/devices/devicedefinitions/StarTrackerDefinitions.h" -#include "linux/devices/ploc/PlocMPSoCHandler.h" -#include "linux/devices/ploc/PlocMPSoCHelper.h" -#include "linux/devices/ploc/PlocMemoryDumper.h" -#include "linux/devices/ploc/PlocSupervisorHandler.h" -#include "linux/devices/ploc/PlocSupvHelper.h" -#include "linux/devices/startracker/StarTrackerHandler.h" -#include "linux/devices/startracker/StrHelper.h" -#include "linux/obc/AxiPtmeConfig.h" -#include "linux/obc/PapbVcInterface.h" -#include "linux/obc/PdecHandler.h" -#include "linux/obc/Ptme.h" -#include "linux/obc/PtmeConfig.h" -#include "mission/system/SusAssembly.h" -#include "mission/system/TcsBoardAssembly.h" -#include "mission/system/fdir/AcsBoardFdir.h" -#include "mission/system/fdir/RtdFdir.h" -#include "mission/system/fdir/SusFdir.h" -#include "tmtc/apid.h" -#include "tmtc/pusIds.h" -#if OBSW_TEST_LIBGPIOD == 1 -#include "linux/boardtest/LibgpiodTest.h" -#endif -#include - -#include "fsfw/datapoollocal/LocalDataPoolManager.h" -#include "fsfw/tmtcpacket/pus/tm.h" -#include "fsfw/tmtcservices/CommandingServiceBase.h" -#include "fsfw/tmtcservices/PusServiceBase.h" -#include "fsfw_hal/common/gpio/GpioCookie.h" -#include "fsfw_hal/common/gpio/gpioDefinitions.h" -#include "fsfw_hal/devicehandlers/GyroL3GD20Handler.h" -#include "fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h" -#include "fsfw_hal/devicehandlers/MgmRM3100Handler.h" #include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h" -#include "fsfw_hal/linux/i2c/I2cComIF.h" -#include "fsfw_hal/linux/i2c/I2cCookie.h" -#include "fsfw_hal/linux/spi/SpiComIF.h" -#include "fsfw_hal/linux/spi/SpiCookie.h" -#include "fsfw_hal/linux/uart/UartComIF.h" -#include "fsfw_hal/linux/uart/UartCookie.h" +#include "linux/ObjectFactory.h" +#include "linux/callbacks/gpioCallbacks.h" #include "mission/core/GenericFactory.h" -#include "mission/devices/ACUHandler.h" -#include "mission/devices/BpxBatteryHandler.h" -#include "mission/devices/GyroADIS1650XHandler.h" -#include "mission/devices/HeaterHandler.h" -#include "mission/devices/IMTQHandler.h" -#include "mission/devices/Max31865PT1000Handler.h" -#include "mission/devices/P60DockHandler.h" -#include "mission/devices/PCDUHandler.h" -#include "mission/devices/PDU1Handler.h" -#include "mission/devices/PDU2Handler.h" -#include "mission/devices/PayloadPcduHandler.h" -#include "mission/devices/RadiationSensorHandler.h" -#include "mission/devices/RwHandler.h" -#include "mission/devices/SolarArrayDeploymentHandler.h" -#include "mission/devices/SyrlinksHkHandler.h" -#include "mission/devices/Tmp1075Handler.h" -#include "mission/devices/devicedefinitions/GomspaceDefinitions.h" -#include "mission/devices/devicedefinitions/Max31865Definitions.h" -#include "mission/devices/devicedefinitions/RadSensorDefinitions.h" -#include "mission/devices/devicedefinitions/RwDefinitions.h" -#include "mission/devices/devicedefinitions/SyrlinksDefinitions.h" -#include "mission/devices/devicedefinitions/payloadPcduDefinitions.h" -#include "mission/system/AcsBoardAssembly.h" -#include "mission/tmtc/CCSDSHandler.h" -#include "mission/tmtc/VirtualChannel.h" -#include "mission/utility/TmFunnel.h" -ResetArgs resetArgsGnss0; -ResetArgs resetArgsGnss1; - -void ObjectFactory::setStatics() { Factory::setStaticFrameworkObjectIds(); } - -void Factory::setStaticFrameworkObjectIds() { - PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR; - PusServiceBase::packetDestination = objects::TM_FUNNEL; - - CommandingServiceBase::defaultPacketSource = objects::PUS_PACKET_DISTRIBUTOR; - CommandingServiceBase::defaultPacketDestination = objects::TM_FUNNEL; - - DeviceHandlerBase::powerSwitcherId = objects::PCDU_HANDLER; - // DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT; -#if OBSW_TM_TO_PTME == 1 - TmFunnel::downlinkDestination = objects::CCSDS_HANDLER; -#else - TmFunnel::downlinkDestination = objects::TMTC_BRIDGE; -#endif /* OBSW_TM_TO_PTME == 1 */ - // No storage object for now. - TmFunnel::storageDestination = objects::NO_OBJECT; - - LocalDataPoolManager::defaultHkDestination = objects::PUS_SERVICE_3_HOUSEKEEPING; - - VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; - TmPacketBase::timeStamperId = objects::TIME_STAMPER; -} void ObjectFactory::produce(void* args) { ObjectFactory::setStatics(); @@ -128,24 +15,25 @@ void ObjectFactory::produce(void* args) { LinuxLibgpioIF* gpioComIF = nullptr; UartComIF* uartComIF = nullptr; - SpiComIF* spiComIF = nullptr; + SpiComIF* spiMainComIF = nullptr; I2cComIF* i2cComIF = nullptr; PowerSwitchIF* pwrSwitcher = nullptr; - createCommunicationInterfaces(&gpioComIF, &uartComIF, &spiComIF, &i2cComIF); + SpiComIF* spiRwComIF = nullptr; + createCommunicationInterfaces(&gpioComIF, &uartComIF, &spiMainComIF, &i2cComIF, &spiRwComIF); createTmpComponents(); new CoreController(objects::CORE_CONTROLLER); gpioCallbacks::disableAllDecoder(gpioComIF); createPcduComponents(gpioComIF, &pwrSwitcher); createRadSensorComponent(gpioComIF); - createSunSensorComponents(gpioComIF, spiComIF, pwrSwitcher, q7s::SPI_DEFAULT_DEV); + createSunSensorComponents(gpioComIF, spiMainComIF, pwrSwitcher, q7s::SPI_DEFAULT_DEV); #if OBSW_ADD_ACS_BOARD == 1 createAcsBoardComponents(gpioComIF, uartComIF, pwrSwitcher); #endif createHeaterComponents(); createSolarArrayDeploymentComponents(); - createPlPcduComponents(gpioComIF, spiComIF, pwrSwitcher); + createPlPcduComponents(gpioComIF, spiMainComIF, pwrSwitcher); #if OBSW_ADD_SYRLINKS == 1 createSyrlinksComponents(pwrSwitcher); #endif /* OBSW_ADD_SYRLINKS == 1 */ @@ -153,45 +41,16 @@ void ObjectFactory::produce(void* args) { createPayloadComponents(gpioComIF); #if OBSW_ADD_MGT == 1 - I2cCookie* imtqI2cCookie = - new I2cCookie(addresses::IMTQ, IMTQ::MAX_REPLY_SIZE, q7s::I2C_DEFAULT_DEV); - auto imtqHandler = new IMTQHandler(objects::IMTQ_HANDLER, objects::I2C_COM_IF, imtqI2cCookie, - pcdu::Switches::PDU1_CH3_MGT_5V); - imtqHandler->setPowerSwitcher(pwrSwitcher); - static_cast(imtqHandler); -#if OBSW_TEST_IMTQ == 1 - imtqHandler->setStartUpImmediately(); - imtqHandler->setToGoToNormal(true); + createImtqComponents(pwrSwitcher); #endif -#if OBSW_DEBUG_IMTQ == 1 - imtqHandler->setDebugMode(true); -#endif -#endif - createReactionWheelComponents(gpioComIF); + createReactionWheelComponents(gpioComIF, pwrSwitcher); #if OBSW_ADD_BPX_BATTERY_HANDLER == 1 - I2cCookie* bpxI2cCookie = new I2cCookie(addresses::BPX_BATTERY, 100, q7s::I2C_DEFAULT_DEV); - BpxBatteryHandler* bpxHandler = - new BpxBatteryHandler(objects::BPX_BATT_HANDLER, objects::I2C_COM_IF, bpxI2cCookie); - bpxHandler->setStartUpImmediately(); - bpxHandler->setToGoToNormalMode(true); -#if OBSW_DEBUG_BPX_BATT == 1 - bpxHandler->setDebugMode(true); + createBpxBatteryComponent(); #endif -#endif - new FileSystemHandler(objects::FILE_SYSTEM_HANDLER); #if OBSW_ADD_STAR_TRACKER == 1 - UartCookie* starTrackerCookie = - new UartCookie(objects::STAR_TRACKER, q7s::UART_STAR_TRACKER_DEV, uart::STAR_TRACKER_BAUD, - startracker::MAX_FRAME_SIZE * 2 + 2, UartModes::NON_CANONICAL); - starTrackerCookie->setNoFixedSizeReply(); - StrHelper* strHelper = new StrHelper(objects::STR_HELPER); - auto starTracker = - new StarTrackerHandler(objects::STAR_TRACKER, objects::UART_COM_IF, starTrackerCookie, - strHelper, pcdu::PDU1_CH2_STAR_TRACKER_5V); - starTracker->setPowerSwitcher(pwrSwitcher); - + createStrComponents(pwrSwitcher); #endif /* OBSW_ADD_STAR_TRACKER == 1 */ #if OBSW_USE_CCSDS_IP_CORE == 1 createCcsdsComponents(gpioComIF); @@ -200,770 +59,6 @@ void ObjectFactory::produce(void* args) { #if OBSW_ADD_TEST_CODE == 1 createTestComponents(gpioComIF); #endif /* OBSW_ADD_TEST_CODE == 1 */ - new PlocMemoryDumper(objects::PLOC_MEMORY_DUMPER); -} - -void ObjectFactory::createTmpComponents() { - I2cCookie* i2cCookieTmp1075tcs1 = - new I2cCookie(addresses::TMP1075_TCS_1, TMP1075::MAX_REPLY_LENGTH, q7s::I2C_DEFAULT_DEV); - I2cCookie* i2cCookieTmp1075tcs2 = - new I2cCookie(addresses::TMP1075_TCS_2, TMP1075::MAX_REPLY_LENGTH, q7s::I2C_DEFAULT_DEV); - - /* Temperature sensors */ - Tmp1075Handler* tmp1075Handler_1 = - new Tmp1075Handler(objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, i2cCookieTmp1075tcs1); - (void)tmp1075Handler_1; - Tmp1075Handler* tmp1075Handler_2 = - new Tmp1075Handler(objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, i2cCookieTmp1075tcs2); - (void)tmp1075Handler_2; -} - -void ObjectFactory::createCommunicationInterfaces(LinuxLibgpioIF** gpioComIF, UartComIF** uartComIF, - SpiComIF** spiComIF, I2cComIF** i2cComIF) { - if (gpioComIF == nullptr or uartComIF == nullptr or spiComIF == nullptr) { - sif::error << "ObjectFactory::createCommunicationInterfaces: Invalid passed ComIF pointer" - << std::endl; - } - *gpioComIF = new LinuxLibgpioIF(objects::GPIO_IF); - - /* Communication interfaces */ - new CspComIF(objects::CSP_COM_IF); - *i2cComIF = new I2cComIF(objects::I2C_COM_IF); - *uartComIF = new UartComIF(objects::UART_COM_IF); - *spiComIF = new SpiComIF(objects::SPI_COM_IF, *gpioComIF); - - /* Adding gpios for chip select decoding to the gpioComIf */ - q7s::gpioCallbacks::initSpiCsDecoder(*gpioComIF); -} - -void ObjectFactory::createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF** pwrSwitcher) { - CspCookie* p60DockCspCookie = new CspCookie(P60Dock::MAX_REPLY_LENGTH, addresses::P60DOCK); - CspCookie* pdu1CspCookie = new CspCookie(PDU::MAX_REPLY_LENGTH, addresses::PDU1); - CspCookie* pdu2CspCookie = new CspCookie(PDU::MAX_REPLY_LENGTH, addresses::PDU2); - CspCookie* acuCspCookie = new CspCookie(ACU::MAX_REPLY_LENGTH, addresses::ACU); - - auto p60Fdir = new GomspacePowerFdir(objects::P60DOCK_HANDLER); - P60DockHandler* p60dockhandler = - new P60DockHandler(objects::P60DOCK_HANDLER, objects::CSP_COM_IF, p60DockCspCookie, p60Fdir); - - auto pdu1Fdir = new GomspacePowerFdir(objects::PDU1_HANDLER); - PDU1Handler* pdu1handler = - new PDU1Handler(objects::PDU1_HANDLER, objects::CSP_COM_IF, pdu1CspCookie, pdu1Fdir); - - auto pdu2Fdir = new GomspacePowerFdir(objects::PDU2_HANDLER); - PDU2Handler* pdu2handler = - new PDU2Handler(objects::PDU2_HANDLER, objects::CSP_COM_IF, pdu2CspCookie, pdu2Fdir); - - auto acuFdir = new GomspacePowerFdir(objects::ACU_HANDLER); - ACUHandler* acuhandler = - new ACUHandler(objects::ACU_HANDLER, objects::CSP_COM_IF, acuCspCookie, acuFdir); - auto pcduHandler = new PCDUHandler(objects::PCDU_HANDLER, 50); - - /** - * Setting PCDU devices to mode normal immediately after start up because PCDU is always - * running. - */ - p60dockhandler->setModeNormal(); - pdu1handler->setModeNormal(); - pdu2handler->setModeNormal(); - acuhandler->setModeNormal(); - if (pwrSwitcher != nullptr) { - *pwrSwitcher = pcduHandler; - } -#if OBSW_DEBUG_P60DOCK == 1 - p60dockhandler->setDebugMode(true); -#endif -#if OBSW_DEBUG_ACU == 1 - acuhandler->setDebugMode(true); -#endif -} - -void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { - using namespace gpio; - GpioCookie* gpioCookieRadSensor = new GpioCookie; - std::stringstream consumer; - consumer << "0x" << std::hex << objects::RAD_SENSOR; - GpiodRegularByLineName* gpio = new GpiodRegularByLineName( - q7s::gpioNames::RAD_SENSOR_CHIP_SELECT, consumer.str(), Direction::OUT, Levels::HIGH); - gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, gpio); - gpio = new GpiodRegularByLineName(q7s::gpioNames::ENABLE_RADFET, consumer.str(), Direction::OUT, - Levels::LOW); - gpioCookieRadSensor->addGpio(gpioIds::ENABLE_RADFET, gpio); - gpioComIF->addGpios(gpioCookieRadSensor); - - SpiCookie* spiCookieRadSensor = new SpiCookie( - addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, std::string(q7s::SPI_DEFAULT_DEV), - RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, - spiCookieRadSensor, gpioComIF); - static_cast(radSensor); - // The radiation sensor ADC is powered by the 5V stack connector which should always be on - radSensor->setStartUpImmediately(); - // It's a simple sensor, so just to to normal mode immediately - radSensor->setToGoToNormalModeImmediately(); -#if OBSW_DEBUG_RAD_SENSOR == 1 - radSensor->enablePeriodicDataPrint(true); -#endif -} - -void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComIF* uartComIF, - PowerSwitchIF* pwrSwitcher) { - using namespace gpio; - GpioCookie* gpioCookieAcsBoard = new GpioCookie(); - - std::stringstream consumer; - GpiodRegularByLineName* gpio = nullptr; - consumer << "0x" << std::hex << objects::GYRO_0_ADIS_HANDLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::GYRO_0_ADIS_CS, consumer.str(), Direction::OUT, - Levels::HIGH); - gpioCookieAcsBoard->addGpio(gpioIds::GYRO_0_ADIS_CS, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::GYRO_1_L3G_HANDLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::GYRO_1_L3G_CS, consumer.str(), Direction::OUT, - Levels::HIGH); - gpioCookieAcsBoard->addGpio(gpioIds::GYRO_1_L3G_CS, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::GYRO_2_ADIS_HANDLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::GYRO_2_ADIS_CS, consumer.str(), Direction::OUT, - Levels::HIGH); - gpioCookieAcsBoard->addGpio(gpioIds::GYRO_2_ADIS_CS, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::GYRO_3_L3G_HANDLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::GYRO_3_L3G_CS, consumer.str(), Direction::OUT, - Levels::HIGH); - gpioCookieAcsBoard->addGpio(gpioIds::GYRO_3_L3G_CS, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::MGM_0_LIS3_HANDLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::MGM_0_CS, consumer.str(), Direction::OUT, - Levels::HIGH); - gpioCookieAcsBoard->addGpio(gpioIds::MGM_0_LIS3_CS, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::MGM_1_RM3100_HANDLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::MGM_1_CS, consumer.str(), Direction::OUT, - Levels::HIGH); - gpioCookieAcsBoard->addGpio(gpioIds::MGM_1_RM3100_CS, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::MGM_2_LIS3_HANDLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::MGM_2_CS, consumer.str(), Direction::OUT, - Levels::HIGH); - gpioCookieAcsBoard->addGpio(gpioIds::MGM_2_LIS3_CS, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::MGM_3_RM3100_HANDLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::MGM_3_CS, consumer.str(), Direction::OUT, - Levels::HIGH); - gpioCookieAcsBoard->addGpio(gpioIds::MGM_3_RM3100_CS, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::GPS_CONTROLLER; - // GNSS reset pins are active low - gpio = new GpiodRegularByLineName(q7s::gpioNames::RESET_GNSS_0, consumer.str(), Direction::OUT, - Levels::HIGH); - gpioCookieAcsBoard->addGpio(gpioIds::GNSS_0_NRESET, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::GPS_CONTROLLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::RESET_GNSS_1, consumer.str(), Direction::OUT, - Levels::HIGH); - gpioCookieAcsBoard->addGpio(gpioIds::GNSS_1_NRESET, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::GYRO_0_ADIS_HANDLER; - // Enable pins must be pulled low for regular operations - gpio = new GpiodRegularByLineName(q7s::gpioNames::GYRO_0_ENABLE, consumer.str(), Direction::OUT, - Levels::LOW); - gpioCookieAcsBoard->addGpio(gpioIds::GYRO_0_ENABLE, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::GYRO_2_ADIS_HANDLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::GYRO_2_ENABLE, consumer.str(), Direction::OUT, - Levels::LOW); - gpioCookieAcsBoard->addGpio(gpioIds::GYRO_2_ENABLE, gpio); - - // Enable pins for GNSS - consumer.str(""); - consumer << "0x" << std::hex << objects::GPS_CONTROLLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::GNSS_0_ENABLE, consumer.str(), Direction::OUT, - Levels::LOW); - gpioCookieAcsBoard->addGpio(gpioIds::GNSS_0_ENABLE, gpio); - - consumer.str(""); - consumer << "0x" << std::hex << objects::GPS_CONTROLLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::GNSS_1_ENABLE, consumer.str(), Direction::OUT, - Levels::LOW); - gpioCookieAcsBoard->addGpio(gpioIds::GNSS_1_ENABLE, gpio); - - // Select pin. 0 for GPS side A, 1 for GPS side B - consumer.str(""); - consumer << "0x" << std::hex << objects::GPS_CONTROLLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::GNSS_SELECT, consumer.str(), Direction::OUT, - Levels::LOW); - gpioCookieAcsBoard->addGpio(gpioIds::GNSS_SELECT, gpio); - gpioComIF->addGpios(gpioCookieAcsBoard); - AcsBoardFdir* fdir = nullptr; - static_cast(fdir); - -#if OBSW_ADD_ACS_HANDLERS == 1 - std::string spiDev = q7s::SPI_DEFAULT_DEV; - SpiCookie* spiCookie = - new SpiCookie(addresses::MGM_0_LIS3, gpioIds::MGM_0_LIS3_CS, spiDev, - MGMLIS3MDL::MAX_BUFFER_SIZE, spi::DEFAULT_LIS3_MODE, spi::DEFAULT_LIS3_SPEED); - auto mgmLis3Handler = new MgmLIS3MDLHandler(objects::MGM_0_LIS3_HANDLER, objects::SPI_COM_IF, - spiCookie, spi::LIS3_TRANSITION_DELAY); - fdir = new AcsBoardFdir(objects::MGM_0_LIS3_HANDLER); - mgmLis3Handler->setCustomFdir(fdir); - static_cast(mgmLis3Handler); -#if OBSW_TEST_ACS == 1 - mgmLis3Handler->setStartUpImmediately(); - mgmLis3Handler->setToGoToNormalMode(true); -#endif -#if OBSW_DEBUG_ACS == 1 - mgmLis3Handler->enablePeriodicPrintouts(true, 10); -#endif - spiCookie = - new SpiCookie(addresses::MGM_1_RM3100, gpioIds::MGM_1_RM3100_CS, spiDev, - RM3100::MAX_BUFFER_SIZE, spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED); - auto mgmRm3100Handler = new MgmRM3100Handler(objects::MGM_1_RM3100_HANDLER, objects::SPI_COM_IF, - spiCookie, spi::RM3100_TRANSITION_DELAY); - fdir = new AcsBoardFdir(objects::MGM_1_RM3100_HANDLER); - mgmRm3100Handler->setCustomFdir(fdir); - mgmRm3100Handler->setParent(objects::ACS_BOARD_ASS); - static_cast(mgmRm3100Handler); -#if OBSW_TEST_ACS == 1 - mgmRm3100Handler->setStartUpImmediately(); - mgmRm3100Handler->setToGoToNormalMode(true); -#endif -#if OBSW_DEBUG_ACS == 1 - mgmRm3100Handler->enablePeriodicPrintouts(true, 10); -#endif - spiCookie = - new SpiCookie(addresses::MGM_2_LIS3, gpioIds::MGM_2_LIS3_CS, spiDev, - MGMLIS3MDL::MAX_BUFFER_SIZE, spi::DEFAULT_LIS3_MODE, spi::DEFAULT_LIS3_SPEED); - mgmLis3Handler = new MgmLIS3MDLHandler(objects::MGM_2_LIS3_HANDLER, objects::SPI_COM_IF, - spiCookie, spi::LIS3_TRANSITION_DELAY); - fdir = new AcsBoardFdir(objects::MGM_2_LIS3_HANDLER); - mgmLis3Handler->setCustomFdir(fdir); - mgmLis3Handler->setParent(objects::ACS_BOARD_ASS); - static_cast(mgmLis3Handler); -#if OBSW_TEST_ACS == 1 - mgmLis3Handler->setStartUpImmediately(); - mgmLis3Handler->setToGoToNormalMode(true); -#endif -#if OBSW_DEBUG_ACS == 1 - mgmLis3Handler->enablePeriodicPrintouts(true, 10); -#endif - spiCookie = - new SpiCookie(addresses::MGM_3_RM3100, gpioIds::MGM_3_RM3100_CS, spiDev, - RM3100::MAX_BUFFER_SIZE, spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED); - mgmRm3100Handler = new MgmRM3100Handler(objects::MGM_3_RM3100_HANDLER, objects::SPI_COM_IF, - spiCookie, spi::RM3100_TRANSITION_DELAY); - fdir = new AcsBoardFdir(objects::MGM_3_RM3100_HANDLER); - mgmRm3100Handler->setCustomFdir(fdir); - mgmRm3100Handler->setParent(objects::ACS_BOARD_ASS); -#if OBSW_TEST_ACS == 1 - mgmRm3100Handler->setStartUpImmediately(); - mgmRm3100Handler->setToGoToNormalMode(true); -#endif -#if OBSW_DEBUG_ACS == 1 - mgmRm3100Handler->enablePeriodicPrintouts(true, 10); -#endif - // Commented until ACS board V2 in in clean room again - // Gyro 0 Side A - spiCookie = new SpiCookie(addresses::GYRO_0_ADIS, gpioIds::GYRO_0_ADIS_CS, spiDev, - ADIS1650X::MAXIMUM_REPLY_SIZE, spi::DEFAULT_ADIS16507_MODE, - spi::DEFAULT_ADIS16507_SPEED); - auto adisHandler = new GyroADIS1650XHandler(objects::GYRO_0_ADIS_HANDLER, objects::SPI_COM_IF, - spiCookie, ADIS1650X::Type::ADIS16505); - fdir = new AcsBoardFdir(objects::GYRO_0_ADIS_HANDLER); - adisHandler->setCustomFdir(fdir); - adisHandler->setParent(objects::ACS_BOARD_ASS); - static_cast(adisHandler); -#if OBSW_TEST_ACS == 1 - adisHandler->setStartUpImmediately(); - adisHandler->setToGoToNormalModeImmediately(); -#endif -#if OBSW_DEBUG_ACS == 1 - adisHandler->enablePeriodicPrintouts(true, 10); -#endif - // Gyro 1 Side A - spiCookie = - new SpiCookie(addresses::GYRO_1_L3G, gpioIds::GYRO_1_L3G_CS, spiDev, L3GD20H::MAX_BUFFER_SIZE, - spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); - auto gyroL3gHandler = new GyroHandlerL3GD20H(objects::GYRO_1_L3G_HANDLER, objects::SPI_COM_IF, - spiCookie, spi::L3G_TRANSITION_DELAY); - fdir = new AcsBoardFdir(objects::GYRO_1_L3G_HANDLER); - gyroL3gHandler->setCustomFdir(fdir); - gyroL3gHandler->setParent(objects::ACS_BOARD_ASS); - static_cast(gyroL3gHandler); -#if OBSW_TEST_ACS == 1 - gyroL3gHandler->setStartUpImmediately(); - gyroL3gHandler->setToGoToNormalMode(true); -#endif -#if OBSW_DEBUG_ACS == 1 - gyroL3gHandler->enablePeriodicPrintouts(true, 10); -#endif - // Gyro 2 Side B - spiCookie = new SpiCookie(addresses::GYRO_2_ADIS, gpioIds::GYRO_2_ADIS_CS, spiDev, - ADIS1650X::MAXIMUM_REPLY_SIZE, spi::DEFAULT_ADIS16507_MODE, - spi::DEFAULT_ADIS16507_SPEED); - adisHandler = new GyroADIS1650XHandler(objects::GYRO_2_ADIS_HANDLER, objects::SPI_COM_IF, - spiCookie, ADIS1650X::Type::ADIS16505); - fdir = new AcsBoardFdir(objects::GYRO_2_ADIS_HANDLER); - adisHandler->setCustomFdir(fdir); - adisHandler->setParent(objects::ACS_BOARD_ASS); -#if OBSW_TEST_ACS == 1 - adisHandler->setStartUpImmediately(); - adisHandler->setToGoToNormalModeImmediately(); -#endif - // Gyro 3 Side B - spiCookie = - new SpiCookie(addresses::GYRO_3_L3G, gpioIds::GYRO_3_L3G_CS, spiDev, L3GD20H::MAX_BUFFER_SIZE, - spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); - gyroL3gHandler = new GyroHandlerL3GD20H(objects::GYRO_3_L3G_HANDLER, objects::SPI_COM_IF, - spiCookie, spi::L3G_TRANSITION_DELAY); - fdir = new AcsBoardFdir(objects::GYRO_3_L3G_HANDLER); - gyroL3gHandler->setCustomFdir(fdir); - gyroL3gHandler->setParent(objects::ACS_BOARD_ASS); -#if OBSW_TEST_ACS == 1 - gyroL3gHandler->setStartUpImmediately(); - gyroL3gHandler->setToGoToNormalMode(true); -#endif -#if OBSW_DEBUG_ACS == 1 - gyroL3gHandler->enablePeriodicPrintouts(true, 10); -#endif - bool debugGps = false; -#if OBSW_DEBUG_GPS == 1 - debugGps = true; -#endif - resetArgsGnss1.gnss1 = true; - resetArgsGnss1.gpioComIF = gpioComIF; - resetArgsGnss1.waitPeriodMs = 100; - resetArgsGnss0.gnss1 = false; - resetArgsGnss0.gpioComIF = gpioComIF; - resetArgsGnss0.waitPeriodMs = 100; - auto gpsHandler0 = - new GPSHyperionLinuxController(objects::GPS_CONTROLLER, objects::NO_OBJECT, debugGps); - gpsHandler0->setResetPinTriggerFunction(gps::triggerGpioResetPin, &resetArgsGnss0); - AcsBoardHelper acsBoardHelper = AcsBoardHelper( - objects::MGM_0_LIS3_HANDLER, objects::MGM_1_RM3100_HANDLER, objects::MGM_2_LIS3_HANDLER, - objects::MGM_3_RM3100_HANDLER, objects::GYRO_0_ADIS_HANDLER, objects::GYRO_1_L3G_HANDLER, - objects::GYRO_2_ADIS_HANDLER, objects::GYRO_3_L3G_HANDLER, objects::GPS_CONTROLLER); - auto acsAss = new AcsBoardAssembly(objects::ACS_BOARD_ASS, objects::NO_OBJECT, pwrSwitcher, - acsBoardHelper, gpioComIF); - static_cast(acsAss); -#endif /* OBSW_ADD_ACS_HANDLERS == 1 */ -} - -void ObjectFactory::createHeaterComponents() { - using namespace gpio; - GpioCookie* heaterGpiosCookie = new GpioCookie; - GpiodRegularByLineName* gpio = nullptr; - - std::stringstream consumer; - consumer << "0x" << std::hex << objects::HEATER_HANDLER; - /* Pin H2-11 on stack connector */ - gpio = new GpiodRegularByLineName(q7s::gpioNames::HEATER_0, consumer.str(), Direction::OUT, - Levels::LOW); - heaterGpiosCookie->addGpio(gpioIds::HEATER_0, gpio); - /* Pin H2-12 on stack connector */ - gpio = new GpiodRegularByLineName(q7s::gpioNames::HEATER_1, consumer.str(), Direction::OUT, - Levels::LOW); - heaterGpiosCookie->addGpio(gpioIds::HEATER_1, gpio); - - /* Pin H2-13 on stack connector */ - gpio = new GpiodRegularByLineName(q7s::gpioNames::HEATER_2, consumer.str(), Direction::OUT, - Levels::LOW); - heaterGpiosCookie->addGpio(gpioIds::HEATER_2, gpio); - - gpio = new GpiodRegularByLineName(q7s::gpioNames::HEATER_3, consumer.str(), Direction::OUT, - Levels::LOW); - heaterGpiosCookie->addGpio(gpioIds::HEATER_3, gpio); - - gpio = new GpiodRegularByLineName(q7s::gpioNames::HEATER_4, consumer.str(), Direction::OUT, - Levels::LOW); - heaterGpiosCookie->addGpio(gpioIds::HEATER_4, gpio); - - gpio = new GpiodRegularByLineName(q7s::gpioNames::HEATER_5, consumer.str(), Direction::OUT, - Levels::LOW); - heaterGpiosCookie->addGpio(gpioIds::HEATER_5, gpio); - - gpio = new GpiodRegularByLineName(q7s::gpioNames::HEATER_6, consumer.str(), Direction::OUT, - Levels::LOW); - heaterGpiosCookie->addGpio(gpioIds::HEATER_6, gpio); - - gpio = new GpiodRegularByLineName(q7s::gpioNames::HEATER_7, consumer.str(), Direction::OUT, - Levels::LOW); - heaterGpiosCookie->addGpio(gpioIds::HEATER_7, gpio); - - new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, heaterGpiosCookie, - objects::PCDU_HANDLER, pcdu::Switches::PDU2_CH3_TCS_BOARD_HEATER_IN_8V); -} - -void ObjectFactory::createSolarArrayDeploymentComponents() { - using namespace gpio; - GpioCookie* solarArrayDeplCookie = new GpioCookie; - GpiodRegularByLineName* gpio = nullptr; - - std::stringstream consumer; - consumer << "0x" << std::hex << objects::SOLAR_ARRAY_DEPL_HANDLER; - gpio = new GpiodRegularByLineName(q7s::gpioNames::SA_DPL_PIN_0, consumer.str(), Direction::OUT, - Levels::LOW); - solarArrayDeplCookie->addGpio(gpioIds::DEPLSA1, gpio); - gpio = new GpiodRegularByLineName(q7s::gpioNames::SA_DPL_PIN_1, consumer.str(), Direction::OUT, - Levels::LOW); - solarArrayDeplCookie->addGpio(gpioIds::DEPLSA2, gpio); - - // TODO: Find out burn time. For now set to 1000 ms. - new SolarArrayDeploymentHandler(objects::SOLAR_ARRAY_DEPL_HANDLER, objects::GPIO_IF, - solarArrayDeplCookie, objects::PCDU_HANDLER, - pcdu::Switches::PDU2_CH5_DEPLOYMENT_MECHANISM_8V, - gpioIds::DEPLSA1, gpioIds::DEPLSA2, 1000); -} - -void ObjectFactory::createSyrlinksComponents(PowerSwitchIF* pwrSwitcher) { - UartCookie* syrlinksUartCookie = - new UartCookie(objects::SYRLINKS_HK_HANDLER, q7s::UART_SYRLINKS_DEV, uart::SYRLINKS_BAUD, - syrlinks::MAX_REPLY_SIZE, UartModes::NON_CANONICAL); - syrlinksUartCookie->setParityEven(); - - auto syrlinksFdir = new SyrlinksFdir(objects::SYRLINKS_HK_HANDLER); - auto syrlinksHandler = - new SyrlinksHkHandler(objects::SYRLINKS_HK_HANDLER, objects::UART_COM_IF, syrlinksUartCookie, - pcdu::PDU1_CH1_SYRLINKS_12V, syrlinksFdir); - syrlinksHandler->setPowerSwitcher(pwrSwitcher); -#if OBSW_DEBUG_SYRLINKS == 1 - syrlinksHandler->setDebugMode(true); -#endif -} - -void ObjectFactory::createPayloadComponents(LinuxLibgpioIF* gpioComIF) { - using namespace gpio; - std::stringstream consumer; -#if OBSW_ADD_PLOC_MPSOC == 1 - consumer << "0x" << std::hex << objects::PLOC_MPSOC_HANDLER; - auto gpioConfigMPSoC = new GpiodRegularByLineName(q7s::gpioNames::ENABLE_MPSOC_UART, - consumer.str(), Direction::OUT, Levels::LOW); - auto mpsocGpioCookie = new GpioCookie; - mpsocGpioCookie->addGpio(gpioIds::ENABLE_MPSOC_UART, gpioConfigMPSoC); - gpioComIF->addGpios(mpsocGpioCookie); - auto mpsocCookie = - new UartCookie(objects::PLOC_MPSOC_HANDLER, q7s::UART_PLOC_MPSOC_DEV, uart::PLOC_MPSOC_BAUD, - mpsoc::MAX_REPLY_SIZE, UartModes::NON_CANONICAL); - mpsocCookie->setNoFixedSizeReply(); - auto plocMpsocHelper = new PlocMPSoCHelper(objects::PLOC_MPSOC_HELPER); - new PlocMPSoCHandler(objects::PLOC_MPSOC_HANDLER, objects::UART_COM_IF, mpsocCookie, - plocMpsocHelper, Gpio(gpioIds::ENABLE_MPSOC_UART, gpioComIF), - objects::PLOC_SUPERVISOR_HANDLER); -#endif /* OBSW_ADD_PLOC_MPSOC == 1 */ -#if OBSW_ADD_PLOC_SUPERVISOR == 1 - consumer << "0x" << std::hex << objects::PLOC_SUPERVISOR_HANDLER; - auto gpioConfigSupv = new GpiodRegularByLineName(q7s::gpioNames::ENABLE_SUPV_UART, consumer.str(), - Direction::OUT, Levels::LOW); - auto supvGpioCookie = new GpioCookie; - supvGpioCookie->addGpio(gpioIds::ENABLE_SUPV_UART, gpioConfigSupv); - gpioComIF->addGpios(supvGpioCookie); - auto supervisorCookie = - new UartCookie(objects::PLOC_SUPERVISOR_HANDLER, q7s::UART_PLOC_SUPERVSIOR_DEV, - uart::PLOC_SUPV_BAUD, supv::MAX_PACKET_SIZE * 20, UartModes::NON_CANONICAL); - supervisorCookie->setNoFixedSizeReply(); - auto supvHelper = new PlocSupvHelper(objects::PLOC_SUPERVISOR_HELPER); - new PlocSupervisorHandler(objects::PLOC_SUPERVISOR_HANDLER, objects::UART_COM_IF, - supervisorCookie, Gpio(gpioIds::ENABLE_SUPV_UART, gpioComIF), - pcdu::PDU1_CH6_PLOC_12V, supvHelper); -#endif /* OBSW_ADD_PLOC_SUPERVISOR == 1 */ - static_cast(consumer); -} - -void ObjectFactory::createReactionWheelComponents(LinuxLibgpioIF* gpioComIF) { - using namespace gpio; - GpioCookie* gpioCookieRw = new GpioCookie; - GpioCallback* csRw1 = - new GpioCallback("Chip select reaction wheel 1", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieRw->addGpio(gpioIds::CS_RW1, csRw1); - GpioCallback* csRw2 = - new GpioCallback("Chip select reaction wheel 2", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieRw->addGpio(gpioIds::CS_RW2, csRw2); - GpioCallback* csRw3 = - new GpioCallback("Chip select reaction wheel 3", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieRw->addGpio(gpioIds::CS_RW3, csRw3); - GpioCallback* csRw4 = - new GpioCallback("Chip select reaction wheel 4", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieRw->addGpio(gpioIds::CS_RW4, csRw4); - - std::stringstream consumer; - GpiodRegularByLineName* gpio = nullptr; - consumer << "0x" << std::hex << objects::RW1; - gpio = new GpiodRegularByLineName(q7s::gpioNames::EN_RW_1, consumer.str(), Direction::OUT, - Levels::LOW); - gpioCookieRw->addGpio(gpioIds::EN_RW1, gpio); - consumer.str(""); - consumer << "0x" << std::hex << objects::RW2; - gpio = new GpiodRegularByLineName(q7s::gpioNames::EN_RW_2, consumer.str(), Direction::OUT, - Levels::LOW); - gpioCookieRw->addGpio(gpioIds::EN_RW2, gpio); - consumer.str(""); - consumer << "0x" << std::hex << objects::RW3; - gpio = new GpiodRegularByLineName(q7s::gpioNames::EN_RW_3, consumer.str(), Direction::OUT, - Levels::LOW); - gpioCookieRw->addGpio(gpioIds::EN_RW3, gpio); - consumer.str(""); - consumer << "0x" << std::hex << objects::RW4; - gpio = new GpiodRegularByLineName(q7s::gpioNames::EN_RW_4, consumer.str(), Direction::OUT, - Levels::LOW); - gpioCookieRw->addGpio(gpioIds::EN_RW4, gpio); - - gpioComIF->addGpios(gpioCookieRw); - -#if OBSW_ADD_RW == 1 - auto rw1SpiCookie = - new SpiCookie(addresses::RW1, gpioIds::CS_RW1, q7s::SPI_RW_DEV, RwDefinitions::MAX_REPLY_SIZE, - spi::RW_MODE, spi::RW_SPEED, &rwSpiCallback::spiCallback, nullptr); - auto rw2SpiCookie = - new SpiCookie(addresses::RW2, gpioIds::CS_RW2, q7s::SPI_RW_DEV, RwDefinitions::MAX_REPLY_SIZE, - spi::RW_MODE, spi::RW_SPEED, &rwSpiCallback::spiCallback, nullptr); - auto rw3SpiCookie = - new SpiCookie(addresses::RW3, gpioIds::CS_RW3, q7s::SPI_RW_DEV, RwDefinitions::MAX_REPLY_SIZE, - spi::RW_MODE, spi::RW_SPEED, &rwSpiCallback::spiCallback, nullptr); - auto rw4SpiCookie = - new SpiCookie(addresses::RW4, gpioIds::CS_RW4, q7s::SPI_RW_DEV, RwDefinitions::MAX_REPLY_SIZE, - spi::RW_MODE, spi::RW_SPEED, &rwSpiCallback::spiCallback, nullptr); - - auto rwHandler1 = - new RwHandler(objects::RW1, objects::SPI_COM_IF, rw1SpiCookie, gpioComIF, gpioIds::EN_RW1); - rw1SpiCookie->setCallbackArgs(rwHandler1); -#if OBSW_DEBUG_RW == 1 - rwHandler1->setStartUpImmediately(); - rwHandler1->setDebugMode(true); -#endif - auto rwHandler2 = - new RwHandler(objects::RW2, objects::SPI_COM_IF, rw2SpiCookie, gpioComIF, gpioIds::EN_RW2); - rw2SpiCookie->setCallbackArgs(rwHandler2); -#if OBSW_DEBUG_RW == 1 - rwHandler2->setStartUpImmediately(); - rwHandler2->setDebugMode(true); -#endif - auto rwHandler3 = - new RwHandler(objects::RW3, objects::SPI_COM_IF, rw3SpiCookie, gpioComIF, gpioIds::EN_RW3); - rw3SpiCookie->setCallbackArgs(rwHandler3); -#if OBSW_DEBUG_RW == 1 - rwHandler3->setStartUpImmediately(); - rwHandler3->setDebugMode(true); -#endif - auto rwHandler4 = - new RwHandler(objects::RW4, objects::SPI_COM_IF, rw4SpiCookie, gpioComIF, gpioIds::EN_RW4); - rw4SpiCookie->setCallbackArgs(rwHandler4); -#if OBSW_DEBUG_RW == 1 - rwHandler4->setStartUpImmediately(); - rwHandler4->setDebugMode(true); -#endif -#endif /* OBSW_ADD_RW == 1 */ -} - -void ObjectFactory::createCcsdsComponents(LinuxLibgpioIF* gpioComIF) { - using namespace gpio; - // GPIO definitions of signals connected to the virtual channel interfaces of the PTME IP Core - GpioCookie* gpioCookiePtmeIp = new GpioCookie; - GpiodRegularByLineName* gpio = nullptr; - std::stringstream consumer; - consumer.str("PAPB VC0"); - gpio = new GpiodRegularByLineName(q7s::gpioNames::PAPB_BUSY_SIGNAL_VC0, consumer.str()); - gpioCookiePtmeIp->addGpio(gpioIds::VC0_PAPB_BUSY, gpio); - consumer.str("PAPB VC0"); - gpio = new GpiodRegularByLineName(q7s::gpioNames::PAPB_EMPTY_SIGNAL_VC0, consumer.str()); - gpioCookiePtmeIp->addGpio(gpioIds::VC0_PAPB_EMPTY, gpio); - consumer.str("PAPB VC 1"); - gpio = new GpiodRegularByLineName(q7s::gpioNames::PAPB_BUSY_SIGNAL_VC1, consumer.str()); - gpioCookiePtmeIp->addGpio(gpioIds::VC1_PAPB_BUSY, gpio); - consumer.str(""); - consumer.str("PAPB VC 1"); - gpioCookiePtmeIp->addGpio(gpioIds::VC1_PAPB_EMPTY, gpio); - consumer.str(""); - consumer.str("PAPB VC 2"); - gpio = new GpiodRegularByLineName(q7s::gpioNames::PAPB_BUSY_SIGNAL_VC2, consumer.str()); - gpioCookiePtmeIp->addGpio(gpioIds::VC2_PAPB_BUSY, gpio); - consumer.str(""); - consumer.str("PAPB VC 2"); - gpio = new GpiodRegularByLineName(q7s::gpioNames::PAPB_EMPTY_SIGNAL_VC2, consumer.str()); - gpioCookiePtmeIp->addGpio(gpioIds::VC2_PAPB_EMPTY, gpio); - consumer.str(""); - consumer.str("PAPB VC 3"); - gpio = new GpiodRegularByLineName(q7s::gpioNames::PAPB_BUSY_SIGNAL_VC3, consumer.str()); - gpioCookiePtmeIp->addGpio(gpioIds::VC3_PAPB_BUSY, gpio); - consumer.str(""); - consumer.str("PAPB VC 3"); - gpio = new GpiodRegularByLineName(q7s::gpioNames::PAPB_EMPTY_SIGNAL_VC3, consumer.str()); - gpioCookiePtmeIp->addGpio(gpioIds::VC3_PAPB_EMPTY, gpio); - - gpioComIF->addGpios(gpioCookiePtmeIp); - - // Creating virtual channel interfaces - VcInterfaceIF* vc0 = - new PapbVcInterface(gpioComIF, gpioIds::VC0_PAPB_BUSY, gpioIds::VC0_PAPB_EMPTY, q7s::UIO_PTME, - q7s::uiomapids::PTME_VC0); - VcInterfaceIF* vc1 = - new PapbVcInterface(gpioComIF, gpioIds::VC1_PAPB_BUSY, gpioIds::VC1_PAPB_EMPTY, q7s::UIO_PTME, - q7s::uiomapids::PTME_VC1); - VcInterfaceIF* vc2 = - new PapbVcInterface(gpioComIF, gpioIds::VC2_PAPB_BUSY, gpioIds::VC2_PAPB_EMPTY, q7s::UIO_PTME, - q7s::uiomapids::PTME_VC2); - VcInterfaceIF* vc3 = - new PapbVcInterface(gpioComIF, gpioIds::VC3_PAPB_BUSY, gpioIds::VC3_PAPB_EMPTY, q7s::UIO_PTME, - q7s::uiomapids::PTME_VC3); - - // Creating ptme object and adding virtual channel interfaces - Ptme* ptme = new Ptme(objects::PTME); - ptme->addVcInterface(ccsds::VC0, vc0); - ptme->addVcInterface(ccsds::VC1, vc1); - ptme->addVcInterface(ccsds::VC2, vc2); - ptme->addVcInterface(ccsds::VC3, vc3); - - AxiPtmeConfig* axiPtmeConfig = - new AxiPtmeConfig(objects::AXI_PTME_CONFIG, q7s::UIO_PTME, q7s::uiomapids::PTME_CONFIG); - PtmeConfig* ptmeConfig = new PtmeConfig(objects::PTME_CONFIG, axiPtmeConfig); -#if OBSW_ENABLE_SYRLINKS_TRANSMIT_TIMEOUT == 1 - // Set to high value when not sending via syrlinks - static const uint32_t TRANSMITTER_TIMEOUT = 86400000; // 1 day -#else - static const uint32_t TRANSMITTER_TIMEOUT = 900000; // 15 minutes -#endif - CCSDSHandler* ccsdsHandler = new CCSDSHandler( - objects::CCSDS_HANDLER, objects::PTME, objects::CCSDS_PACKET_DISTRIBUTOR, ptmeConfig, - gpioComIF, gpioIds::RS485_EN_TX_CLOCK, gpioIds::RS485_EN_TX_DATA, TRANSMITTER_TIMEOUT); - - VirtualChannel* vc = nullptr; - vc = new VirtualChannel(ccsds::VC0, common::VC0_QUEUE_SIZE, objects::CCSDS_HANDLER); - ccsdsHandler->addVirtualChannel(ccsds::VC0, vc); - vc = new VirtualChannel(ccsds::VC1, common::VC1_QUEUE_SIZE, objects::CCSDS_HANDLER); - ccsdsHandler->addVirtualChannel(ccsds::VC1, vc); - vc = new VirtualChannel(ccsds::VC2, common::VC2_QUEUE_SIZE, objects::CCSDS_HANDLER); - ccsdsHandler->addVirtualChannel(ccsds::VC2, vc); - vc = new VirtualChannel(ccsds::VC3, common::VC3_QUEUE_SIZE, objects::CCSDS_HANDLER); - ccsdsHandler->addVirtualChannel(ccsds::VC3, vc); - - GpioCookie* gpioCookiePdec = new GpioCookie; - consumer.str(""); - consumer << "0x" << std::hex << objects::PDEC_HANDLER; - // GPIO also low after linux boot (specified by device-tree) - gpio = new GpiodRegularByLineName(q7s::gpioNames::PDEC_RESET, consumer.str(), Direction::OUT, - Levels::LOW); - gpioCookiePdec->addGpio(gpioIds::PDEC_RESET, gpio); - - gpioComIF->addGpios(gpioCookiePdec); - - new PdecHandler(objects::PDEC_HANDLER, objects::CCSDS_HANDLER, gpioComIF, gpioIds::PDEC_RESET, - q7s::UIO_PDEC_CONFIG_MEMORY, q7s::UIO_PDEC_RAM, q7s::UIO_PDEC_REGISTERS); - - GpioCookie* gpioRS485Chip = new GpioCookie; - gpio = new GpiodRegularByLineName(q7s::gpioNames::RS485_EN_TX_CLOCK, "RS485 Transceiver", - Direction::OUT, Levels::LOW); - gpioRS485Chip->addGpio(gpioIds::RS485_EN_TX_CLOCK, gpio); - gpio = new GpiodRegularByLineName(q7s::gpioNames::RS485_EN_TX_DATA, "RS485 Transceiver", - Direction::OUT, Levels::LOW); - gpioRS485Chip->addGpio(gpioIds::RS485_EN_TX_DATA, gpio); - - // Default configuration enables RX channels (RXEN = LOW) - gpio = new GpiodRegularByLineName(q7s::gpioNames::RS485_EN_RX_CLOCK, "RS485 Transceiver", - Direction::OUT, Levels::LOW); - gpioRS485Chip->addGpio(gpioIds::RS485_EN_RX_CLOCK, gpio); - gpio = new GpiodRegularByLineName(q7s::gpioNames::RS485_EN_RX_DATA, "RS485 Transceiver", - Direction::OUT, Levels::LOW); - gpioRS485Chip->addGpio(gpioIds::RS485_EN_RX_DATA, gpio); - - gpioComIF->addGpios(gpioRS485Chip); -} - -void ObjectFactory::createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, - PowerSwitchIF* pwrSwitcher) { - using namespace gpio; - // Create all GPIO components first - GpioCookie* plPcduGpios = new GpioCookie; - GpiodRegularByLineName* gpio = nullptr; - std::string consumer; - // Switch pins are active high - consumer = "PLPCDU_ENB_VBAT_0"; - gpio = new GpiodRegularByLineName(q7s::gpioNames::PL_PCDU_ENABLE_VBAT0, consumer, Direction::OUT, - gpio::Levels::LOW); - plPcduGpios->addGpio(gpioIds::PLPCDU_ENB_VBAT0, gpio); - consumer = "PLPCDU_ENB_VBAT_1"; - gpio = new GpiodRegularByLineName(q7s::gpioNames::PL_PCDU_ENABLE_VBAT1, consumer, Direction::OUT, - gpio::Levels::LOW); - plPcduGpios->addGpio(gpioIds::PLPCDU_ENB_VBAT1, gpio); - consumer = "PLPCDU_ENB_DRO"; - gpio = new GpiodRegularByLineName(q7s::gpioNames::PL_PCDU_ENABLE_DRO, consumer, Direction::OUT, - gpio::Levels::LOW); - plPcduGpios->addGpio(gpioIds::PLPCDU_ENB_DRO, gpio); - consumer = "PLPCDU_ENB_X8"; - gpio = new GpiodRegularByLineName(q7s::gpioNames::PL_PCDU_ENABLE_X8, consumer, Direction::OUT, - gpio::Levels::LOW); - plPcduGpios->addGpio(gpioIds::PLPCDU_ENB_X8, gpio); - consumer = "PLPCDU_ENB_TX"; - gpio = new GpiodRegularByLineName(q7s::gpioNames::PL_PCDU_ENABLE_TX, consumer, Direction::OUT, - gpio::Levels::LOW); - plPcduGpios->addGpio(gpioIds::PLPCDU_ENB_TX, gpio); - consumer = "PLPCDU_ENB_MPA"; - gpio = new GpiodRegularByLineName(q7s::gpioNames::PL_PCDU_ENABLE_MPA, consumer, Direction::OUT, - gpio::Levels::LOW); - plPcduGpios->addGpio(gpioIds::PLPCDU_ENB_MPA, gpio); - consumer = "PLPCDU_ENB_HPA"; - gpio = new GpiodRegularByLineName(q7s::gpioNames::PL_PCDU_ENABLE_HPA, consumer, Direction::OUT, - gpio::Levels::LOW); - plPcduGpios->addGpio(gpioIds::PLPCDU_ENB_HPA, gpio); - - // Chip select pin is active low - consumer = "PLPCDU_ADC_CS"; - gpio = new GpiodRegularByLineName(q7s::gpioNames::PL_PCDU_ADC_CS, consumer, Direction::OUT, - gpio::Levels::HIGH); - plPcduGpios->addGpio(gpioIds::PLPCDU_ADC_CS, gpio); - gpioComIF->addGpios(plPcduGpios); - SpiCookie* spiCookie = new SpiCookie(addresses::PLPCDU_ADC, gpioIds::PLPCDU_ADC_CS, - q7s::SPI_DEFAULT_DEV, plpcdu::MAX_ADC_REPLY_SIZE, - spi::DEFAULT_MAX_1227_MODE, spi::PL_PCDU_MAX_1227_SPEED); - // Create device handler components - auto plPcduHandler = new PayloadPcduHandler( - objects::PLPCDU_HANDLER, objects::SPI_COM_IF, spiCookie, gpioComIF, SdCardManager::instance(), - pwrSwitcher, pcdu::Switches::PDU2_CH1_PL_PCDU_BATT_0_14V8, - pcdu::Switches::PDU2_CH6_PL_PCDU_BATT_1_14V8, false); - spiCookie->setCallbackMode(PayloadPcduHandler::extConvAsTwoCallback, plPcduHandler); -// plPcduHandler->enablePeriodicPrintout(true, 5); -// static_cast(plPcduHandler); -#if OBSW_TEST_PL_PCDU == 1 - plPcduHandler->setStartUpImmediately(); -#endif -#if OBSW_DEBUG_PL_PCDU == 1 - plPcduHandler->setToGoToNormalModeImmediately(true); - plPcduHandler->enablePeriodicPrintout(true, 10); -#endif -} - -void ObjectFactory::createTestComponents(LinuxLibgpioIF* gpioComIF) { - new Q7STestTask(objects::TEST_TASK); -#if OBSW_ADD_SPI_TEST_CODE == 1 - new SpiTestClass(objects::SPI_TEST, gpioComIF); -#endif -#if OBSW_ADD_I2C_TEST_CODE == 1 - new I2cTestClass(objects::I2C_TEST, q7s::I2C_DEFAULT_DEV); -#endif -#if OBSW_ADD_UART_TEST_CODE == 1 - new UartTestClass(objects::UART_TEST); -#endif -} - -void ObjectFactory::testAcsBrdAss(AcsBoardAssembly* acsAss) { - CommandMessage msg; - ModeMessage::setModeMessage(&msg, ModeMessage::CMD_MODE_COMMAND, DeviceHandlerIF::MODE_NORMAL, - duallane::A_SIDE); - ReturnValue_t result = MessageQueueSenderIF::sendMessage(acsAss->getCommandQueue(), &msg); - if (result != HasReturnvaluesIF::RETURN_OK) { - sif::warning << "Sending mode command failed" << std::endl; - } + + createMiscComponents(); } diff --git a/bsp_q7s/fm/CMakeLists.txt b/bsp_q7s/fm/CMakeLists.txt deleted file mode 100644 index 5d20a118..00000000 --- a/bsp_q7s/fm/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -target_sources(${OBSW_NAME} PRIVATE - fmObjectFactory.cpp -) diff --git a/bsp_q7s/fmObjectFactory.cpp b/bsp_q7s/fmObjectFactory.cpp new file mode 100644 index 00000000..561786e8 --- /dev/null +++ b/bsp_q7s/fmObjectFactory.cpp @@ -0,0 +1,64 @@ +#include "OBSWConfig.h" +#include "bsp_q7s/core/CoreController.h" +#include "bsp_q7s/core/ObjectFactory.h" +#include "busConf.h" +#include "commonObjects.h" +#include "devConf.h" +#include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h" +#include "linux/ObjectFactory.h" +#include "linux/callbacks/gpioCallbacks.h" +#include "mission/core/GenericFactory.h" + +void ObjectFactory::produce(void* args) { + ObjectFactory::setStatics(); + ObjectFactory::produceGenericObjects(); + + LinuxLibgpioIF* gpioComIF = nullptr; + UartComIF* uartComIF = nullptr; + SpiComIF* spiMainComIF = nullptr; + I2cComIF* i2cComIF = nullptr; + PowerSwitchIF* pwrSwitcher = nullptr; + SpiComIF* spiRwComIF = nullptr; + createCommunicationInterfaces(&gpioComIF, &uartComIF, &spiMainComIF, &i2cComIF, &spiRwComIF); + createTmpComponents(); + new CoreController(objects::CORE_CONTROLLER); + + gpioCallbacks::disableAllDecoder(gpioComIF); + createPcduComponents(gpioComIF, &pwrSwitcher); + createRadSensorComponent(gpioComIF); + createSunSensorComponents(gpioComIF, spiMainComIF, pwrSwitcher, q7s::SPI_DEFAULT_DEV); + +#if OBSW_ADD_ACS_BOARD == 1 + createAcsBoardComponents(gpioComIF, uartComIF, pwrSwitcher); +#endif + createHeaterComponents(); + createSolarArrayDeploymentComponents(); + createPlPcduComponents(gpioComIF, spiMainComIF, pwrSwitcher); +#if OBSW_ADD_SYRLINKS == 1 + createSyrlinksComponents(pwrSwitcher); +#endif /* OBSW_ADD_SYRLINKS == 1 */ + createRtdComponents(q7s::SPI_DEFAULT_DEV, gpioComIF, pwrSwitcher); + createPayloadComponents(gpioComIF); + +#if OBSW_ADD_MGT == 1 + createImtqComponents(pwrSwitcher); +#endif + createReactionWheelComponents(gpioComIF, pwrSwitcher); + +#if OBSW_ADD_BPX_BATTERY_HANDLER == 1 + createBpxBatteryComponent(); +#endif + +#if OBSW_ADD_STAR_TRACKER == 1 + createStrComponents(pwrSwitcher); +#endif /* OBSW_ADD_STAR_TRACKER == 1 */ +#if OBSW_USE_CCSDS_IP_CORE == 1 + createCcsdsComponents(gpioComIF); +#endif /* OBSW_USE_CCSDS_IP_CORE == 1 */ + /* Test Task */ +#if OBSW_ADD_TEST_CODE == 1 + createTestComponents(gpioComIF); +#endif /* OBSW_ADD_TEST_CODE == 1 */ + + createMiscComponents(); +} diff --git a/linux/ObjectFactory.cpp b/linux/ObjectFactory.cpp index da06ea06..8996c23d 100644 --- a/linux/ObjectFactory.cpp +++ b/linux/ObjectFactory.cpp @@ -71,7 +71,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[0] = - new SusHandler(objects::SUS_0_N_LOC_XFYFZM_PT_XF, 0, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_0_N_LOC_XFYFZM_PT_XF, 0, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_0_N_LOC_XFYFZM_PT_XF); susHandlers[0]->setParent(objects::SUS_BOARD_ASS); susHandlers[0]->setCustomFdir(fdir); @@ -79,7 +79,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[1] = - new SusHandler(objects::SUS_1_N_LOC_XBYFZM_PT_XB, 1, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_1_N_LOC_XBYFZM_PT_XB, 1, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_1_N_LOC_XBYFZM_PT_XB); susHandlers[1]->setParent(objects::SUS_BOARD_ASS); susHandlers[1]->setCustomFdir(fdir); @@ -87,7 +87,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[2] = - new SusHandler(objects::SUS_2_N_LOC_XFYBZB_PT_YB, 2, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_2_N_LOC_XFYBZB_PT_YB, 2, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_2_N_LOC_XFYBZB_PT_YB); susHandlers[2]->setParent(objects::SUS_BOARD_ASS); susHandlers[2]->setCustomFdir(fdir); @@ -95,7 +95,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo spiCookie = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[3] = - new SusHandler(objects::SUS_3_N_LOC_XFYBZF_PT_YF, 3, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_3_N_LOC_XFYBZF_PT_YF, 3, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_3_N_LOC_XFYBZF_PT_YF); susHandlers[3]->setParent(objects::SUS_BOARD_ASS); susHandlers[3]->setCustomFdir(fdir); @@ -103,7 +103,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo spiCookie = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[4] = - new SusHandler(objects::SUS_4_N_LOC_XMYFZF_PT_ZF, 4, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_4_N_LOC_XMYFZF_PT_ZF, 4, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_4_N_LOC_XMYFZF_PT_ZF); susHandlers[4]->setParent(objects::SUS_BOARD_ASS); susHandlers[4]->setCustomFdir(fdir); @@ -111,7 +111,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo spiCookie = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[5] = - new SusHandler(objects::SUS_5_N_LOC_XFYMZB_PT_ZB, 5, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_5_N_LOC_XFYMZB_PT_ZB, 5, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_5_N_LOC_XFYMZB_PT_ZB); susHandlers[5]->setParent(objects::SUS_BOARD_ASS); susHandlers[5]->setCustomFdir(fdir); @@ -119,7 +119,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[6] = - new SusHandler(objects::SUS_6_R_LOC_XFYBZM_PT_XF, 6, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_6_R_LOC_XFYBZM_PT_XF, 6, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_6_R_LOC_XFYBZM_PT_XF); susHandlers[6]->setParent(objects::SUS_BOARD_ASS); susHandlers[6]->setCustomFdir(fdir); @@ -127,7 +127,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[7] = - new SusHandler(objects::SUS_7_R_LOC_XBYBZM_PT_XB, 7, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_7_R_LOC_XBYBZM_PT_XB, 7, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_7_R_LOC_XBYBZM_PT_XB); susHandlers[7]->setParent(objects::SUS_BOARD_ASS); susHandlers[7]->setCustomFdir(fdir); @@ -135,7 +135,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[8] = - new SusHandler(objects::SUS_8_R_LOC_XBYBZB_PT_YB, 8, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_8_R_LOC_XBYBZB_PT_YB, 8, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_8_R_LOC_XBYBZB_PT_YB); susHandlers[8]->setParent(objects::SUS_BOARD_ASS); susHandlers[8]->setCustomFdir(fdir); @@ -143,7 +143,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[9] = - new SusHandler(objects::SUS_9_R_LOC_XBYBZB_PT_YF, 9, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_9_R_LOC_XBYBZB_PT_YF, 9, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_9_R_LOC_XBYBZB_PT_YF); susHandlers[9]->setParent(objects::SUS_BOARD_ASS); susHandlers[9]->setCustomFdir(fdir); @@ -151,7 +151,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo spiCookie = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[10] = - new SusHandler(objects::SUS_10_N_LOC_XMYBZF_PT_ZF, 10, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_10_N_LOC_XMYBZF_PT_ZF, 10, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_10_N_LOC_XMYBZF_PT_ZF); susHandlers[10]->setParent(objects::SUS_BOARD_ASS); susHandlers[10]->setCustomFdir(fdir); @@ -159,7 +159,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo spiCookie = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, spiDev, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[11] = - new SusHandler(objects::SUS_11_R_LOC_XBYMZB_PT_ZB, 11, objects::SPI_COM_IF, spiCookie); + new SusHandler(objects::SUS_11_R_LOC_XBYMZB_PT_ZB, 11, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_11_R_LOC_XBYMZB_PT_ZB); susHandlers[11]->setParent(objects::SUS_BOARD_ASS); susHandlers[11]->setCustomFdir(fdir); @@ -288,7 +288,7 @@ void ObjectFactory::createRtdComponents(std::string spiDev, GpioIF* gpioComIF, rtdCookies[idx] = new SpiCookie(cookieArgs[idx].first, cookieArgs[idx].second, spiDev, Max31865Definitions::MAX_REPLY_SIZE, spi::RTD_MODE, spi::RTD_SPEED); - rtds[idx] = new Max31865PT1000Handler(rtdIds[idx], objects::SPI_COM_IF, rtdCookies[idx]); + rtds[idx] = new Max31865PT1000Handler(rtdIds[idx], objects::SPI_MAIN_COM_IF, rtdCookies[idx]); rtds[idx]->setParent(objects::TCS_BOARD_ASS); rtdFdir = new RtdFdir(rtdIds[idx]); rtds[idx]->setCustomFdir(rtdFdir); diff --git a/linux/fsfwconfig/objects/systemObjectList.h b/linux/fsfwconfig/objects/systemObjectList.h index a03e4d38..22527c3e 100644 --- a/linux/fsfwconfig/objects/systemObjectList.h +++ b/linux/fsfwconfig/objects/systemObjectList.h @@ -47,8 +47,9 @@ enum sourceObjects : uint32_t { CSP_COM_IF = 0x49050001, I2C_COM_IF = 0x49040002, UART_COM_IF = 0x49030003, - SPI_COM_IF = 0x49020004, + SPI_MAIN_COM_IF = 0x49020004, GPIO_IF = 0x49010005, + SPI_RW_COM_IF = 0x49020005, /* Custom device handler */ PCDU_HANDLER = 0x442000A1, diff --git a/mission/system/RwAssembly.cpp b/mission/system/RwAssembly.cpp index 2b99759f..7149747e 100644 --- a/mission/system/RwAssembly.cpp +++ b/mission/system/RwAssembly.cpp @@ -32,6 +32,7 @@ void RwAssembly::performChildOperation() { ReturnValue_t RwAssembly::commandChildren(Mode_t mode, Submode_t submode) { ReturnValue_t result = RETURN_OK; + modeTransitionFailedSwitch = true; // Initialize the mode table to ensure all devices are in a defined state for (uint8_t idx = 0; idx < NUMBER_RWS; idx++) { modeTable[idx].setMode(MODE_OFF); @@ -51,7 +52,7 @@ ReturnValue_t RwAssembly::checkChildrenStateOn(Mode_t wantedMode, Submode_t want int devsInCorrectMode = 0; try { for (uint8_t idx = 0; idx < NUMBER_RWS; idx++) { - if (childrenMap.at(helper.rwIds[idx]).mode != wantedMode) { + if (childrenMap.at(helper.rwIds[idx]).mode == wantedMode) { devsInCorrectMode++; } } @@ -181,7 +182,10 @@ void RwAssembly::handleModeTransitionFailed(ReturnValue_t result) { if (targetMode == MODE_OFF) { AssemblyBase::handleModeTransitionFailed(result); } else { - // To avoid transitioning back to off - triggerEvent(MODE_TRANSITION_FAILED, result); + if (modeTransitionFailedSwitch) { + // To avoid transitioning back to off + triggerEvent(MODE_TRANSITION_FAILED, result); + modeTransitionFailedSwitch = false; + } } } diff --git a/mission/system/RwAssembly.h b/mission/system/RwAssembly.h index 1e94c431..482a18a3 100644 --- a/mission/system/RwAssembly.h +++ b/mission/system/RwAssembly.h @@ -20,6 +20,7 @@ class RwAssembly : public AssemblyBase { RwHelper helper; PowerSwitcher switcher; bool warningSwitch = true; + bool modeTransitionFailedSwitch = true; FixedArrayList modeTable; ReturnValue_t initialize() override; diff --git a/unittest/controller/testAcsController.cpp b/unittest/controller/testAcsController.cpp index 6117c5dc..acc4dfec 100644 --- a/unittest/controller/testAcsController.cpp +++ b/unittest/controller/testAcsController.cpp @@ -2,18 +2,16 @@ #include #include +#include +#include +#include #include "../testEnvironment.h" -#include -#include -#include #include "rapidcsv.h" - TEST_CASE("ACS Controller", "[AcsController]") { - SECTION("SectionTest") { - //acsCtrl.performOperation(); + // acsCtrl.performOperation(); CHECK(1 == 1); try { @@ -21,7 +19,7 @@ TEST_CASE("ACS Controller", "[AcsController]") { std::ifstream file("unittest/meineTestDaten.txt"); if (file.good()) { std::string line; - while(std::getline(file, line)) { + while (std::getline(file, line)) { std::cout << "ACS CTRL Test test file: " << line << std::endl; } } @@ -36,12 +34,8 @@ TEST_CASE("ACS Controller", "[AcsController]") { sif::warning << "CSV file test exception occured: " << e.what() << std::endl; } - REQUIRE(2 == 2); } - SECTION("SectionTest2") { - - } - + SECTION("SectionTest2") {} } From 4120befef0de64776b9622ac3ff8cc84d4254fc2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 01:50:49 +0200 Subject: [PATCH 52/60] update changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ff8271b..af74f87c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ list yields a list of all related PRs for each release. ## Added +- `RwAssembly` added to system components. Assembly works in principle, + issues making 4 consecutives RWs communicate at once.. + PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/224 - Adds a yocto helper script which is able to install the release build binaries (OBSW and Watchdog) into the `q7s-yocto` repository as long as the `q7s-package` or `q7s-yocto` repo was cloned in the same directory the EIVE OBSW repo. @@ -44,8 +47,6 @@ list yields a list of all related PRs for each release. ## Added -- `RwAssembly` added to system components - PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/224 - Custom Syrlinks FDIR which disabled most of the default FDIR functionality PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/232 - Custom Gomspace FDIR which disabled most of the default FDIR functionality From 3924430ea7ae957e1567f0c774348969ed460a6f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 10:04:25 +0200 Subject: [PATCH 53/60] update .cproject file again --- misc/eclipse/.cproject | 358 ++--------------------------------------- 1 file changed, 13 insertions(+), 345 deletions(-) diff --git a/misc/eclipse/.cproject b/misc/eclipse/.cproject index 3f612f37..f40535b7 100644 --- a/misc/eclipse/.cproject +++ b/misc/eclipse/.cproject @@ -57,7 +57,7 @@ - + @@ -119,7 +119,7 @@ - + @@ -187,7 +187,7 @@ - + @@ -255,7 +255,7 @@ - + @@ -418,7 +418,7 @@ - + @@ -580,7 +580,7 @@ - + @@ -603,7 +603,7 @@ - + - + @@ -917,7 +917,7 @@ - + @@ -1084,344 +1084,12 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1481,7 +1149,7 @@ - + @@ -1649,7 +1317,7 @@ - + @@ -1718,7 +1386,7 @@ - + From f5b1427c382d6e54080912b4be2b0193da94f678 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 10:06:56 +0200 Subject: [PATCH 54/60] fix images in README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cefb1046..05b04e6b 100644 --- a/README.md +++ b/README.md @@ -374,7 +374,7 @@ If you are comiling for the Raspberry Pi, you have to set the `LINUX_ROOTFS` env variable instead. You can find a base root filesystem for the Raspberry Pi [here](https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_IRS/Software/rootfs). -## Installing Vivado the the Xilinx development tools +## Installing Vivado and the Xilinx development tools It's also possible to perform debugging with a normal Eclipse installation by installing the TCF plugin and downloading the cross-compiler as specified in the section below. However, @@ -390,9 +390,9 @@ installed Vivado with the SDK core tools.
-
+
-
+
* For supported OS refer to https://www.xilinx.com/support/documentation/sw_manuals/xilinx2018_2/ug973-vivado-release-notes-install-license.pdf . Installation was tested on Windows and Ubuntu 21.04. From 17802aaa55fc18dbb1ccfff51c71dff70c444115 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 10:06:56 +0200 Subject: [PATCH 55/60] fix images in README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cefb1046..05b04e6b 100644 --- a/README.md +++ b/README.md @@ -374,7 +374,7 @@ If you are comiling for the Raspberry Pi, you have to set the `LINUX_ROOTFS` env variable instead. You can find a base root filesystem for the Raspberry Pi [here](https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_IRS/Software/rootfs). -## Installing Vivado the the Xilinx development tools +## Installing Vivado and the Xilinx development tools It's also possible to perform debugging with a normal Eclipse installation by installing the TCF plugin and downloading the cross-compiler as specified in the section below. However, @@ -390,9 +390,9 @@ installed Vivado with the SDK core tools.
-
+
-
+
* For supported OS refer to https://www.xilinx.com/support/documentation/sw_manuals/xilinx2018_2/ug973-vivado-release-notes-install-license.pdf . Installation was tested on Windows and Ubuntu 21.04. From 96710159b8b3cb54824e1d787a5ea9d1ac5e3b40 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 10:09:58 +0200 Subject: [PATCH 56/60] added missing eclipse instructions --- README.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 05b04e6b..fcff24d0 100644 --- a/README.md +++ b/README.md @@ -1127,16 +1127,28 @@ Eclipse indexer. The [TCF agent](https://wiki.eclipse.org/TCF) can be used to perform remote debugging on the Q7S. -1. Install the TCF agent plugin in Eclipse from +1. Copy the `.cproject` file and the `.project` file inside the `misc/eclipse` folder into the + repo root + + ```sh + cd eive-obsw + cp misc/eclipse/.cproject . + cp misc/eclipse/.project . + ``` + +2. Open the repo in Eclipse as a folder. + +3. Install the TCF agent plugin in Eclipse from the [releases](https://www.eclipse.org/tcf/downloads.php). Go to Help → Install New Software and use the download page, for - example https://download.eclipse.org/tools/tcf/releases/1.7/1.7.0/ to search for the plugin and install it. You can find the newest version [here](https://www.eclipse.org/tcf/downloads.php) + example https://download.eclipse.org/tools/tcf/releases/1.7/1.7.0/ to search for the plugin and + install it. You can find the newest version [here](https://www.eclipse.org/tcf/downloads.php) -2. Go to Window → Perspective → Open Perspective and open the **Target Explorer Perspective**. +4. Go to Window → Perspective → Open Perspective and open the **Target Explorer Perspective**. Here, the Q7S should show up if the local port forwarding was set up as explained previously. Please note that you have to connect to `localhost` and port `1534` with port forwaring set up. -3. A launch configuration was provided, but it might be necessary to adapt it for your own needs. +5. A launch configuration was provided, but it might be necessary to adapt it for your own needs. Alternatively: - Create a new **TCF Remote Application** by pressing the cogs button at the top or going to From 62c885e1de506955c98e17b353a9ba147fedf442 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 10:17:49 +0200 Subject: [PATCH 57/60] re-point tmtc --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 6b7b07c3..fcce78b4 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 6b7b07c3409fc24a8585c39e308156b3657c655e +Subproject commit fcce78b447aecd7bc1a65af1e44b51e1ca9d7437 From c043375ae37b79ce2639294b1d1bc81927dbba56 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 11:13:00 +0200 Subject: [PATCH 58/60] RW Refactoring - FSFW update: SPI device is part of ComIF now - Only set RW mode (speed is set a side effect but not necessary) once - Release SPI bus in the 70 ms delay duration --- bsp_q7s/callbacks/rwSpiCallback.cpp | 98 +++++++++++++++++------- bsp_q7s/callbacks/rwSpiCallback.h | 9 --- bsp_q7s/core/ObjectFactory.cpp | 58 +++++++------- fsfw | 2 +- linux/ObjectFactory.cpp | 29 ++++--- mission/devices/GyroADIS1650XHandler.cpp | 2 +- mission/devices/PayloadPcduHandler.cpp | 3 +- 7 files changed, 117 insertions(+), 84 deletions(-) diff --git a/bsp_q7s/callbacks/rwSpiCallback.cpp b/bsp_q7s/callbacks/rwSpiCallback.cpp index 90ff4f6f..5f9015c3 100644 --- a/bsp_q7s/callbacks/rwSpiCallback.cpp +++ b/bsp_q7s/callbacks/rwSpiCallback.cpp @@ -10,6 +10,22 @@ namespace rwSpiCallback { +namespace { +static bool MODE_SET = false; + +ReturnValue_t openSpi(const std::string& devname, int flags, GpioIF* gpioIF, gpioId_t gpioId, + MutexIF* mutex, MutexIF::TimeoutType timeoutType, uint32_t timeoutMs, + int& fd); +/** + * @brief This function closes a spi session. Pulls the chip select to high an releases the + * mutex. + * @param gpioId Gpio ID of chip select + * @param gpioIF Pointer to gpio interface to drive the chip select + * @param mutex The spi mutex + */ +void closeSpi(gpioId_t gpioId, GpioIF* gpioIF, MutexIF* mutex); +} // namespace + ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sendData, size_t sendLen, void* args) { // Stopwatch watch; @@ -35,34 +51,27 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen } int fileDescriptor = 0; - std::string device = cookie->getSpiDevice(); - UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "rwSpiCallback::spiCallback"); - if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) { - sif::error << "rwSpiCallback::spiCallback: Failed to open device file" << std::endl; - return SpiComIF::OPENING_FILE_FAILED; - } - spi::SpiModes spiMode = spi::SpiModes::MODE_0; - uint32_t spiSpeed = 0; - cookie->getSpiParameters(spiMode, spiSpeed, nullptr); - comIf->setSpiSpeedAndMode(fileDescriptor, spiMode, spiSpeed); - - result = mutex->lockMutex(timeoutType, timeoutMs); + const std::string& dev = comIf->getSpiDev(); + result = openSpi(dev, O_RDWR, gpioIF, gpioId, mutex, timeoutType, timeoutMs, fileDescriptor); if (result != HasReturnvaluesIF::RETURN_OK) { - sif::debug << "rwSpiCallback::spiCallback: Failed to lock mutex" << std::endl; return result; } - /** Sending frame start sign */ - writeBuffer[0] = 0x7E; - writeSize = 1; - - // Pull SPI CS low. For now, no support for active high given - if (gpioId != gpio::NO_GPIO) { - if (gpioIF->pullLow(gpioId) != HasReturnvaluesIF::RETURN_OK) { - sif::error << "rwSpiCallback::spiCallback: Failed to pull chip select low" << std::endl; - } + spi::SpiModes spiMode = spi::SpiModes::MODE_0; + uint32_t spiSpeed = 0; + cookie->getSpiParameters(spiMode, spiSpeed, nullptr); + // We are in protected section, so we can use the static variable here without issues. + // We don't need to set the speed because a SPI core is used, but the mode has to be set once + // correctly for all RWs + if (not MODE_SET) { + comIf->setSpiSpeedAndMode(fileDescriptor, spiMode, spiSpeed); + MODE_SET = true; } + /** Sending frame start sign */ + writeBuffer[0] = FLAG_BYTE; + writeSize = 1; + if (write(fileDescriptor, writeBuffer, writeSize) != static_cast(writeSize)) { sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl; closeSpi(gpioId, gpioIF, mutex); @@ -97,7 +106,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen } /** Sending frame end sign */ - writeBuffer[0] = 0x7E; + writeBuffer[0] = FLAG_BYTE; writeSize = 1; if (write(fileDescriptor, writeBuffer, writeSize) != static_cast(writeSize)) { @@ -115,8 +124,14 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen size_t replyBufferSize = cookie->getMaxBufferSize(); - /** There must be a delay of at least 20 ms after sending the command */ + // There must be a delay of at least 20 ms after sending the command. + // Delay for 70 ms here and release the SPI bus for that duration. + closeSpi(gpioId, gpioIF, mutex); usleep(RwDefinitions::SPI_REPLY_DELAY); + result = openSpi(dev, O_RDWR, gpioIF, gpioId, mutex, timeoutType, timeoutMs, fileDescriptor); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } /** * The reaction wheel responds with empty frames while preparing the reply data. @@ -204,8 +219,9 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen result = RwHandler::SPI_READ_FAILURE; break; } - if (byteRead != 0x7E) { - sif::error << "rwSpiCallback::spiCallback: Missing end sign 0x7E" << std::endl; + if (byteRead != FLAG_BYTE) { + sif::error << "rwSpiCallback::spiCallback: Missing end sign " << static_cast(FLAG_BYTE) + << std::endl; decodedFrameLen--; result = RwHandler::MISSING_END_SIGN; break; @@ -221,6 +237,33 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen return result; } +namespace { + +ReturnValue_t openSpi(const std::string& devname, int flags, GpioIF* gpioIF, gpioId_t gpioId, + MutexIF* mutex, MutexIF::TimeoutType timeoutType, uint32_t timeoutMs, + int& fd) { + ReturnValue_t result = mutex->lockMutex(timeoutType, timeoutMs); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::debug << "rwSpiCallback::spiCallback: Failed to lock mutex" << std::endl; + return result; + } + + fd = open(devname.c_str(), flags); + if (fd < 0) { + sif::error << "rwSpiCallback::spiCallback: Failed to open device file" << std::endl; + return SpiComIF::OPENING_FILE_FAILED; + } + + // Pull SPI CS low. For now, no support for active high given + if (gpioId != gpio::NO_GPIO) { + result = gpioIF->pullLow(gpioId); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::error << "rwSpiCallback::spiCallback: Failed to pull chip select low" << std::endl; + return result; + } + } + return HasReturnvaluesIF::RETURN_OK; +} void closeSpi(gpioId_t gpioId, GpioIF* gpioIF, MutexIF* mutex) { if (gpioId != gpio::NO_GPIO) { if (gpioIF->pullHigh(gpioId) != HasReturnvaluesIF::RETURN_OK) { @@ -232,4 +275,7 @@ void closeSpi(gpioId_t gpioId, GpioIF* gpioIF, MutexIF* mutex) { ; } } + +} // namespace + } // namespace rwSpiCallback diff --git a/bsp_q7s/callbacks/rwSpiCallback.h b/bsp_q7s/callbacks/rwSpiCallback.h index 843d5b80..4a5389a3 100644 --- a/bsp_q7s/callbacks/rwSpiCallback.h +++ b/bsp_q7s/callbacks/rwSpiCallback.h @@ -33,14 +33,5 @@ static constexpr uint8_t FLAG_BYTE = 0x7E; ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sendData, size_t sendLen, void* args); -/** - * @brief This function closes a spi session. Pulls the chip select to high an releases the - * mutex. - * @param gpioId Gpio ID of chip select - * @param gpioIF Pointer to gpio interface to drive the chip select - * @param mutex The spi mutex - */ -void closeSpi(gpioId_t gpioId, GpioIF* gpioIF, MutexIF* mutex); - } // namespace rwSpiCallback #endif /* BSP_Q7S_RW_SPI_CALLBACK_H_ */ diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index a3a21b3c..ff1e78cc 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -150,8 +150,8 @@ void ObjectFactory::createCommunicationInterfaces(LinuxLibgpioIF** gpioComIF, Ua new CspComIF(objects::CSP_COM_IF); *i2cComIF = new I2cComIF(objects::I2C_COM_IF); *uartComIF = new UartComIF(objects::UART_COM_IF); - *spiMainComIF = new SpiComIF(objects::SPI_MAIN_COM_IF, *gpioComIF); - *spiRWComIF = new SpiComIF(objects::SPI_RW_COM_IF, *gpioComIF); + *spiMainComIF = new SpiComIF(objects::SPI_MAIN_COM_IF, q7s::SPI_DEFAULT_DEV, *gpioComIF); + *spiRWComIF = new SpiComIF(objects::SPI_RW_COM_IF, q7s::SPI_RW_DEV, *gpioComIF); /* Adding gpios for chip select decoding to the gpioComIf */ q7s::gpioCallbacks::initSpiCsDecoder(*gpioComIF); } @@ -211,9 +211,9 @@ void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { gpioCookieRadSensor->addGpio(gpioIds::ENABLE_RADFET, gpio); gpioChecker(gpioComIF->addGpios(gpioCookieRadSensor), "RAD sensor"); - SpiCookie* spiCookieRadSensor = new SpiCookie( - addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, std::string(q7s::SPI_DEFAULT_DEV), - RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieRadSensor = + new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, RAD_SENSOR::READ_SIZE, + spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_MAIN_COM_IF, spiCookieRadSensor, gpioComIF); static_cast(radSensor); @@ -332,8 +332,8 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI #if OBSW_ADD_ACS_HANDLERS == 1 std::string spiDev = q7s::SPI_DEFAULT_DEV; SpiCookie* spiCookie = - new SpiCookie(addresses::MGM_0_LIS3, gpioIds::MGM_0_LIS3_CS, spiDev, - MGMLIS3MDL::MAX_BUFFER_SIZE, spi::DEFAULT_LIS3_MODE, spi::DEFAULT_LIS3_SPEED); + new SpiCookie(addresses::MGM_0_LIS3, gpioIds::MGM_0_LIS3_CS, MGMLIS3MDL::MAX_BUFFER_SIZE, + spi::DEFAULT_LIS3_MODE, spi::DEFAULT_LIS3_SPEED); auto mgmLis3Handler = new MgmLIS3MDLHandler(objects::MGM_0_LIS3_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, spi::LIS3_TRANSITION_DELAY); fdir = new AcsBoardFdir(objects::MGM_0_LIS3_HANDLER); @@ -347,8 +347,8 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI mgmLis3Handler->enablePeriodicPrintouts(true, 10); #endif spiCookie = - new SpiCookie(addresses::MGM_1_RM3100, gpioIds::MGM_1_RM3100_CS, spiDev, - RM3100::MAX_BUFFER_SIZE, spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED); + new SpiCookie(addresses::MGM_1_RM3100, gpioIds::MGM_1_RM3100_CS, RM3100::MAX_BUFFER_SIZE, + spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED); auto mgmRm3100Handler = new MgmRM3100Handler(objects::MGM_1_RM3100_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, spi::RM3100_TRANSITION_DELAY); @@ -364,8 +364,8 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI mgmRm3100Handler->enablePeriodicPrintouts(true, 10); #endif spiCookie = - new SpiCookie(addresses::MGM_2_LIS3, gpioIds::MGM_2_LIS3_CS, spiDev, - MGMLIS3MDL::MAX_BUFFER_SIZE, spi::DEFAULT_LIS3_MODE, spi::DEFAULT_LIS3_SPEED); + new SpiCookie(addresses::MGM_2_LIS3, gpioIds::MGM_2_LIS3_CS, MGMLIS3MDL::MAX_BUFFER_SIZE, + spi::DEFAULT_LIS3_MODE, spi::DEFAULT_LIS3_SPEED); mgmLis3Handler = new MgmLIS3MDLHandler(objects::MGM_2_LIS3_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, spi::LIS3_TRANSITION_DELAY); fdir = new AcsBoardFdir(objects::MGM_2_LIS3_HANDLER); @@ -380,8 +380,8 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI mgmLis3Handler->enablePeriodicPrintouts(true, 10); #endif spiCookie = - new SpiCookie(addresses::MGM_3_RM3100, gpioIds::MGM_3_RM3100_CS, spiDev, - RM3100::MAX_BUFFER_SIZE, spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED); + new SpiCookie(addresses::MGM_3_RM3100, gpioIds::MGM_3_RM3100_CS, RM3100::MAX_BUFFER_SIZE, + spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED); mgmRm3100Handler = new MgmRM3100Handler(objects::MGM_3_RM3100_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, spi::RM3100_TRANSITION_DELAY); fdir = new AcsBoardFdir(objects::MGM_3_RM3100_HANDLER); @@ -396,9 +396,9 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI #endif // Commented until ACS board V2 in in clean room again // Gyro 0 Side A - spiCookie = new SpiCookie(addresses::GYRO_0_ADIS, gpioIds::GYRO_0_ADIS_CS, spiDev, - ADIS1650X::MAXIMUM_REPLY_SIZE, spi::DEFAULT_ADIS16507_MODE, - spi::DEFAULT_ADIS16507_SPEED); + spiCookie = + new SpiCookie(addresses::GYRO_0_ADIS, gpioIds::GYRO_0_ADIS_CS, ADIS1650X::MAXIMUM_REPLY_SIZE, + spi::DEFAULT_ADIS16507_MODE, spi::DEFAULT_ADIS16507_SPEED); auto adisHandler = new GyroADIS1650XHandler(objects::GYRO_0_ADIS_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, ADIS1650X::Type::ADIS16505); @@ -414,9 +414,8 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI adisHandler->enablePeriodicPrintouts(true, 10); #endif // Gyro 1 Side A - spiCookie = - new SpiCookie(addresses::GYRO_1_L3G, gpioIds::GYRO_1_L3G_CS, spiDev, L3GD20H::MAX_BUFFER_SIZE, - spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); + spiCookie = new SpiCookie(addresses::GYRO_1_L3G, gpioIds::GYRO_1_L3G_CS, L3GD20H::MAX_BUFFER_SIZE, + spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); auto gyroL3gHandler = new GyroHandlerL3GD20H( objects::GYRO_1_L3G_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, spi::L3G_TRANSITION_DELAY); fdir = new AcsBoardFdir(objects::GYRO_1_L3G_HANDLER); @@ -431,9 +430,9 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI gyroL3gHandler->enablePeriodicPrintouts(true, 10); #endif // Gyro 2 Side B - spiCookie = new SpiCookie(addresses::GYRO_2_ADIS, gpioIds::GYRO_2_ADIS_CS, spiDev, - ADIS1650X::MAXIMUM_REPLY_SIZE, spi::DEFAULT_ADIS16507_MODE, - spi::DEFAULT_ADIS16507_SPEED); + spiCookie = + new SpiCookie(addresses::GYRO_2_ADIS, gpioIds::GYRO_2_ADIS_CS, ADIS1650X::MAXIMUM_REPLY_SIZE, + spi::DEFAULT_ADIS16507_MODE, spi::DEFAULT_ADIS16507_SPEED); adisHandler = new GyroADIS1650XHandler(objects::GYRO_2_ADIS_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, ADIS1650X::Type::ADIS16505); fdir = new AcsBoardFdir(objects::GYRO_2_ADIS_HANDLER); @@ -444,9 +443,8 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComI adisHandler->setToGoToNormalModeImmediately(); #endif // Gyro 3 Side B - spiCookie = - new SpiCookie(addresses::GYRO_3_L3G, gpioIds::GYRO_3_L3G_CS, spiDev, L3GD20H::MAX_BUFFER_SIZE, - spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); + spiCookie = new SpiCookie(addresses::GYRO_3_L3G, gpioIds::GYRO_3_L3G_CS, L3GD20H::MAX_BUFFER_SIZE, + spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); gyroL3gHandler = new GyroHandlerL3GD20H(objects::GYRO_3_L3G_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, spi::L3G_TRANSITION_DELAY); fdir = new AcsBoardFdir(objects::GYRO_3_L3G_HANDLER); @@ -661,8 +659,8 @@ void ObjectFactory::createReactionWheelComponents(LinuxLibgpioIF* gpioComIF, std::array rws = {}; for (uint8_t idx = 0; idx < rwCookies.size(); idx++) { rwCookies[idx] = new SpiCookie(rwCookieParams[idx].first, rwCookieParams[idx].second, - q7s::SPI_RW_DEV, RwDefinitions::MAX_REPLY_SIZE, spi::RW_MODE, - spi::RW_SPEED, &rwSpiCallback::spiCallback, nullptr); + RwDefinitions::MAX_REPLY_SIZE, spi::RW_MODE, spi::RW_SPEED, + &rwSpiCallback::spiCallback, nullptr); rws[idx] = new RwHandler(rwIds[idx], objects::SPI_RW_COM_IF, rwCookies[idx], gpioComIF, rwGpioIds[idx]); rwCookies[idx]->setCallbackArgs(rws[idx]); @@ -837,9 +835,9 @@ void ObjectFactory::createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* gpio::Levels::HIGH); plPcduGpios->addGpio(gpioIds::PLPCDU_ADC_CS, gpio); gpioChecker(gpioComIF->addGpios(plPcduGpios), "PL PCDU"); - SpiCookie* spiCookie = new SpiCookie(addresses::PLPCDU_ADC, gpioIds::PLPCDU_ADC_CS, - q7s::SPI_DEFAULT_DEV, plpcdu::MAX_ADC_REPLY_SIZE, - spi::DEFAULT_MAX_1227_MODE, spi::PL_PCDU_MAX_1227_SPEED); + SpiCookie* spiCookie = + new SpiCookie(addresses::PLPCDU_ADC, gpioIds::PLPCDU_ADC_CS, plpcdu::MAX_ADC_REPLY_SIZE, + spi::DEFAULT_MAX_1227_MODE, spi::PL_PCDU_MAX_1227_SPEED); // Create device handler components auto plPcduHandler = new PayloadPcduHandler( objects::PLPCDU_HANDLER, objects::SPI_MAIN_COM_IF, spiCookie, gpioComIF, diff --git a/fsfw b/fsfw index d72b212f..e06c4577 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit d72b212fa629029924d9862e3e862d0388911f8e +Subproject commit e06c457743991b2a0c2d84de9e169508ac428aa8 diff --git a/linux/ObjectFactory.cpp b/linux/ObjectFactory.cpp index 8996c23d..269b0f79 100644 --- a/linux/ObjectFactory.cpp +++ b/linux/ObjectFactory.cpp @@ -67,16 +67,15 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo #if OBSW_ADD_SUN_SENSORS == 1 SusFdir* fdir = nullptr; std::array susHandlers = {}; - SpiCookie* spiCookie = - new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, spiDev, SUS::MAX_CMD_SIZE, - spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + SpiCookie* spiCookie = new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, SUS::MAX_CMD_SIZE, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[0] = new SusHandler(objects::SUS_0_N_LOC_XFYFZM_PT_XF, 0, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_0_N_LOC_XFYFZM_PT_XF); susHandlers[0]->setParent(objects::SUS_BOARD_ASS); susHandlers[0]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, spiDev, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[1] = new SusHandler(objects::SUS_1_N_LOC_XBYFZM_PT_XB, 1, objects::SPI_MAIN_COM_IF, spiCookie); @@ -84,7 +83,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo susHandlers[1]->setParent(objects::SUS_BOARD_ASS); susHandlers[1]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, spiDev, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[2] = new SusHandler(objects::SUS_2_N_LOC_XFYBZB_PT_YB, 2, objects::SPI_MAIN_COM_IF, spiCookie); @@ -92,7 +91,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo susHandlers[2]->setParent(objects::SUS_BOARD_ASS); susHandlers[2]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, spiDev, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[3] = new SusHandler(objects::SUS_3_N_LOC_XFYBZF_PT_YF, 3, objects::SPI_MAIN_COM_IF, spiCookie); @@ -100,7 +99,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo susHandlers[3]->setParent(objects::SUS_BOARD_ASS); susHandlers[3]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, spiDev, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[4] = new SusHandler(objects::SUS_4_N_LOC_XMYFZF_PT_ZF, 4, objects::SPI_MAIN_COM_IF, spiCookie); @@ -108,7 +107,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo susHandlers[4]->setParent(objects::SUS_BOARD_ASS); susHandlers[4]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, spiDev, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[5] = new SusHandler(objects::SUS_5_N_LOC_XFYMZB_PT_ZB, 5, objects::SPI_MAIN_COM_IF, spiCookie); @@ -116,7 +115,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo susHandlers[5]->setParent(objects::SUS_BOARD_ASS); susHandlers[5]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, spiDev, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[6] = new SusHandler(objects::SUS_6_R_LOC_XFYBZM_PT_XF, 6, objects::SPI_MAIN_COM_IF, spiCookie); @@ -124,7 +123,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo susHandlers[6]->setParent(objects::SUS_BOARD_ASS); susHandlers[6]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, spiDev, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[7] = new SusHandler(objects::SUS_7_R_LOC_XBYBZM_PT_XB, 7, objects::SPI_MAIN_COM_IF, spiCookie); @@ -132,7 +131,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo susHandlers[7]->setParent(objects::SUS_BOARD_ASS); susHandlers[7]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, spiDev, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[8] = new SusHandler(objects::SUS_8_R_LOC_XBYBZB_PT_YB, 8, objects::SPI_MAIN_COM_IF, spiCookie); @@ -140,7 +139,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo susHandlers[8]->setParent(objects::SUS_BOARD_ASS); susHandlers[8]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, spiDev, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[9] = new SusHandler(objects::SUS_9_R_LOC_XBYBZB_PT_YF, 9, objects::SPI_MAIN_COM_IF, spiCookie); @@ -148,7 +147,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo susHandlers[9]->setParent(objects::SUS_BOARD_ASS); susHandlers[9]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, spiDev, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[10] = new SusHandler(objects::SUS_10_N_LOC_XMYBZF_PT_ZF, 10, objects::SPI_MAIN_COM_IF, spiCookie); @@ -156,7 +155,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo susHandlers[10]->setParent(objects::SUS_BOARD_ASS); susHandlers[10]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, spiDev, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[11] = new SusHandler(objects::SUS_11_R_LOC_XBYMZB_PT_ZB, 11, objects::SPI_MAIN_COM_IF, spiCookie); @@ -286,7 +285,7 @@ void ObjectFactory::createRtdComponents(std::string spiDev, GpioIF* gpioComIF, RtdFdir* rtdFdir = nullptr; for (uint8_t idx = 0; idx < NUMBER_RTDS; idx++) { rtdCookies[idx] = - new SpiCookie(cookieArgs[idx].first, cookieArgs[idx].second, spiDev, + new SpiCookie(cookieArgs[idx].first, cookieArgs[idx].second, Max31865Definitions::MAX_REPLY_SIZE, spi::RTD_MODE, spi::RTD_SPEED); rtds[idx] = new Max31865PT1000Handler(rtdIds[idx], objects::SPI_MAIN_COM_IF, rtdCookies[idx]); rtds[idx]->setParent(objects::TCS_BOARD_ASS); diff --git a/mission/devices/GyroADIS1650XHandler.cpp b/mission/devices/GyroADIS1650XHandler.cpp index 3b525287..ed9dd777 100644 --- a/mission/devices/GyroADIS1650XHandler.cpp +++ b/mission/devices/GyroADIS1650XHandler.cpp @@ -408,7 +408,7 @@ ReturnValue_t GyroADIS1650XHandler::spiSendCallback(SpiComIF *comIf, SpiCookie * int retval = 0; // Prepare transfer int fileDescriptor = 0; - std::string device = cookie->getSpiDevice(); + std::string device = comIf->getSpiDev(); UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage"); if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) { return SpiComIF::OPENING_FILE_FAILED; diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index 28ce0772..05e8edec 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -697,8 +697,7 @@ ReturnValue_t PayloadPcduHandler::transferAsTwo(SpiComIF* comIf, SpiCookie* cook int retval = 0; // Prepare transfer int fileDescriptor = 0; - std::string device = cookie->getSpiDevice(); - UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage"); + UnixFileGuard fileHelper(comIf->getSpiDev(), &fileDescriptor, O_RDWR, "SpiComIF::sendMessage"); if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) { return SpiComIF::OPENING_FILE_FAILED; } From 37002b47b374c5531f8f01f963cbc6a02c02b62e Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 11 May 2022 12:46:04 +0200 Subject: [PATCH 59/60] sequence count init value --- linux/devices/ploc/PlocMPSoCHandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/devices/ploc/PlocMPSoCHandler.h b/linux/devices/ploc/PlocMPSoCHandler.h index da71dd47..a4044d3e 100644 --- a/linux/devices/ploc/PlocMPSoCHandler.h +++ b/linux/devices/ploc/PlocMPSoCHandler.h @@ -108,7 +108,7 @@ class PlocMPSoCHandler : public DeviceHandlerBase, public CommandsActionsIF { MessageQueueIF* eventQueue = nullptr; MessageQueueIF* commandActionHelperQueue = nullptr; - SourceSequenceCounter sequenceCount; + SourceSequenceCounter sequenceCount = 0; uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE]; From 625abcfd5bae1a32ff7162c2251f5323438751c4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 May 2022 15:45:38 +0200 Subject: [PATCH 60/60] important bugfixes --- bsp_q7s/callbacks/rwSpiCallback.cpp | 25 ++++++++++--------- fsfw | 2 +- linux/devices/ploc/PlocMPSoCHandler.h | 2 +- mission/devices/RwHandler.cpp | 2 +- .../devices/devicedefinitions/RwDefinitions.h | 17 ++++++------- tmtc | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/bsp_q7s/callbacks/rwSpiCallback.cpp b/bsp_q7s/callbacks/rwSpiCallback.cpp index 5f9015c3..b65224e5 100644 --- a/bsp_q7s/callbacks/rwSpiCallback.cpp +++ b/bsp_q7s/callbacks/rwSpiCallback.cpp @@ -23,7 +23,7 @@ ReturnValue_t openSpi(const std::string& devname, int flags, GpioIF* gpioIF, gpi * @param gpioIF Pointer to gpio interface to drive the chip select * @param mutex The spi mutex */ -void closeSpi(gpioId_t gpioId, GpioIF* gpioIF, MutexIF* mutex); +void closeSpi(int fd, gpioId_t gpioId, GpioIF* gpioIF, MutexIF* mutex); } // namespace ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sendData, @@ -74,7 +74,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen if (write(fileDescriptor, writeBuffer, writeSize) != static_cast(writeSize)) { sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl; - closeSpi(gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, gpioIF, mutex); return RwHandler::SPI_WRITE_FAILURE; } @@ -99,7 +99,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen } if (write(fileDescriptor, writeBuffer, writeSize) != static_cast(writeSize)) { sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl; - closeSpi(gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, gpioIF, mutex); return RwHandler::SPI_WRITE_FAILURE; } idx++; @@ -111,14 +111,14 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen if (write(fileDescriptor, writeBuffer, writeSize) != static_cast(writeSize)) { sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl; - closeSpi(gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, gpioIF, mutex); return RwHandler::SPI_WRITE_FAILURE; } uint8_t* rxBuf = nullptr; result = comIf->getReadBuffer(cookie->getSpiAddress(), &rxBuf); if (result != HasReturnvaluesIF::RETURN_OK) { - closeSpi(gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, gpioIF, mutex); return result; } @@ -126,7 +126,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen // There must be a delay of at least 20 ms after sending the command. // Delay for 70 ms here and release the SPI bus for that duration. - closeSpi(gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, gpioIF, mutex); usleep(RwDefinitions::SPI_REPLY_DELAY); result = openSpi(dev, O_RDWR, gpioIF, gpioId, mutex, timeoutType, timeoutMs, fileDescriptor); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -141,13 +141,13 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen for (int idx = 0; idx < 10; idx++) { if (read(fileDescriptor, &byteRead, 1) != 1) { sif::error << "rwSpiCallback::spiCallback: Read failed" << std::endl; - closeSpi(gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, gpioIF, mutex); return RwHandler::SPI_READ_FAILURE; } if (idx == 0) { if (byteRead != FLAG_BYTE) { sif::error << "Invalid data, expected start marker" << std::endl; - closeSpi(gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, gpioIF, mutex); return RwHandler::NO_START_MARKER; } } @@ -158,7 +158,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen if (idx == 9) { sif::error << "rwSpiCallback::spiCallback: Empty frame timeout" << std::endl; - closeSpi(gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, gpioIF, mutex); return RwHandler::NO_REPLY; } } @@ -198,7 +198,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen continue; } else { sif::error << "rwSpiCallback::spiCallback: Invalid substitute" << std::endl; - closeSpi(gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, gpioIF, mutex); result = RwHandler::INVALID_SUBSTITUTE; break; } @@ -232,7 +232,7 @@ ReturnValue_t spiCallback(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sen cookie->setTransferSize(decodedFrameLen); - closeSpi(gpioId, gpioIF, mutex); + closeSpi(fileDescriptor, gpioId, gpioIF, mutex); return result; } @@ -264,7 +264,8 @@ ReturnValue_t openSpi(const std::string& devname, int flags, GpioIF* gpioIF, gpi } return HasReturnvaluesIF::RETURN_OK; } -void closeSpi(gpioId_t gpioId, GpioIF* gpioIF, MutexIF* mutex) { +void closeSpi(int fd, gpioId_t gpioId, GpioIF* gpioIF, MutexIF* mutex) { + close(fd); if (gpioId != gpio::NO_GPIO) { if (gpioIF->pullHigh(gpioId) != HasReturnvaluesIF::RETURN_OK) { sif::error << "closeSpi: Failed to pull chip select high" << std::endl; diff --git a/fsfw b/fsfw index ab2d7ca9..dafcaa60 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit ab2d7ca98fbfbb862e129ea57b65b712e3dec589 +Subproject commit dafcaa60079ba8e57753d389e6a569ee3eb0b7cb diff --git a/linux/devices/ploc/PlocMPSoCHandler.h b/linux/devices/ploc/PlocMPSoCHandler.h index a4044d3e..da71dd47 100644 --- a/linux/devices/ploc/PlocMPSoCHandler.h +++ b/linux/devices/ploc/PlocMPSoCHandler.h @@ -108,7 +108,7 @@ class PlocMPSoCHandler : public DeviceHandlerBase, public CommandsActionsIF { MessageQueueIF* eventQueue = nullptr; MessageQueueIF* commandActionHelperQueue = nullptr; - SourceSequenceCounter sequenceCount = 0; + SourceSequenceCounter sequenceCount; uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE]; diff --git a/mission/devices/RwHandler.cpp b/mission/devices/RwHandler.cpp index dae00d36..fd3462ec 100644 --- a/mission/devices/RwHandler.cpp +++ b/mission/devices/RwHandler.cpp @@ -333,7 +333,7 @@ void RwHandler::handleResetStatusReply(const uint8_t* packet) { PoolReadGuard rg(&lastResetStatusSet); uint8_t offset = 2; uint8_t resetStatus = packet[offset]; - if (resetStatus != RwDefinitions::CLEARED) { + if (resetStatus != 0) { internalState = InternalState::CLEAR_RESET_STATUS; lastResetStatusSet.lastNonClearedResetStatus = resetStatus; triggerEvent(RwDefinitions::RESET_OCCURED, resetStatus, 0); diff --git a/mission/devices/devicedefinitions/RwDefinitions.h b/mission/devices/devicedefinitions/RwDefinitions.h index 9fcb6454..d6a43622 100644 --- a/mission/devices/devicedefinitions/RwDefinitions.h +++ b/mission/devices/devicedefinitions/RwDefinitions.h @@ -14,7 +14,7 @@ static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::RW_HANDLER; //! [EXPORT] : [COMMENT] Reaction wheel signals an error state static constexpr Event ERROR_STATE = MAKE_EVENT(1, severity::HIGH); -static constexpr Event RESET_OCCURED = event::makeEvent(SUBSYSTEM_ID, 2, severity::HIGH); +static constexpr Event RESET_OCCURED = event::makeEvent(SUBSYSTEM_ID, 2, severity::LOW); static const uint32_t SPI_REPLY_DELAY = 70000; // us @@ -55,14 +55,13 @@ enum PoolIds : lp_id_t { enum States : uint8_t { STATE_ERROR, IDLE, COASTING, RUNNING_SPEED_STABLE, RUNNING_SPEED_CHANGING }; -enum LastResetStatus : uint8_t { - CLEARED = 0, - PIN_RESET = 1, - POR_PDR_BOR_RESET = 2, - SOFTWARE_RESET = 4, - INDEPENDENT_WATCHDOG_RESET = 8, - WINDOW_WATCHDOG_RESET = 16, - LOW_POWER_RESET = 32 +enum LastResetStatusBitPos : uint8_t { + PIN_RESET = 0, + POR_PDR_BOR_RESET = 1, + SOFTWARE_RESET = 2, + INDEPENDENT_WATCHDOG_RESET = 3, + WINDOW_WATCHDOG_RESET = 4, + LOW_POWER_RESET = 5 }; static const DeviceCommandId_t RESET_MCU = 1; diff --git a/tmtc b/tmtc index a648b7f7..bc02c9d6 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit a648b7f76f59838c73ce5286570b2130af426f96 +Subproject commit bc02c9d6076dc3f6e0b37a67be04a445245fdd1e