From 2fb8ca4aaa2b19acc5ee76435c6ca9d8e74698fa Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Mar 2022 12:48:23 +0100 Subject: [PATCH 01/20] plpcdu refactoring --- mission/devices/PayloadPcduHandler.cpp | 92 +++++++++++++++----------- mission/devices/PayloadPcduHandler.h | 9 +-- 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index 1d5f4b89..c0c9e771 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -22,54 +22,66 @@ PayloadPcduHandler::PayloadPcduHandler(object_id_t objectId, object_id_t comIF, sdcMan(sdcMan) {} void PayloadPcduHandler::doStartUp() { - if ((state != States::PCDU_OFF) and (state != States::ON_TRANS_SSR)) { + if ((state != States::PL_PCDU_OFF) and (state != States::ON_TRANS_SSR)) { // Config error sif::error << "PayloadPcduHandler::doStartUp: Invalid state" << std::endl; } - if (state == States::PCDU_OFF) { - // Switch on relays here - gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); - gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1); - state = States::ON_TRANS_SSR; - transitionOk = true; - } - if (state == States::ON_TRANS_SSR) { - // If necessary, check whether a certain amount of time has elapsed - if (transitionOk) { - transitionOk = false; - state = States::ON_TRANS_ADC_CLOSE_ZERO; - // We are now in ON mode - startTransition(MODE_NORMAL, 0); - adcCountdown.setTimeout(50); - adcCountdown.resetTimer(); - adcState = AdcStates::BOOT_DELAY; - // The ADC can now be read. If the values are not close to zero, we should not allow - // transition - monMode = MonitoringMode::CLOSE_TO_ZERO; - } - } + // TODO: Handle switching power on here + // TODO: Go to on mode here instead, indicating that the power is on + // We are now in ON mode + setMode(MODE_ON); } -void PayloadPcduHandler::stateMachineToNormal() { +void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom) { using namespace plpcdu; - if (adcState == AdcStates::BOOT_DELAY) { - if (adcCountdown.hasTimedOut()) { - adcState = AdcStates::SEND_SETUP; - adcCmdExecuted = false; + if(submode == plpcdu::NORMAL_ALL_ON or submode == plpcdu::NORMAL_ADC_ONLY) { + if(state == States::PL_PCDU_OFF) { + // TODO: Config error, emit error printout + setMode(MODE_OFF); } - } - if (adcState == AdcStates::SEND_SETUP) { - if (adcCmdExecuted) { - adcState = AdcStates::NORMAL; - setMode(MODE_NORMAL, NORMAL_ADC_ONLY); - adcCountdown.setTimeout(100); - adcCountdown.resetTimer(); - adcCmdExecuted = false; + if (state == States::POWER_CHANNELS_ON) { + // Switch on relays here + gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); + gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1); + state = States::ON_TRANS_SSR; + transitionOk = true; + } + if (state == States::ON_TRANS_SSR) { + // If necessary, check whether a certain amount of time has elapsed + if (transitionOk) { + transitionOk = false; + state = States::ON_TRANS_ADC_CLOSE_ZERO; + + adcCountdown.setTimeout(50); + adcCountdown.resetTimer(); + adcState = AdcStates::BOOT_DELAY; + // If the values are not close to zero, we should not allow transition + monMode = MonitoringMode::CLOSE_TO_ZERO; + } + } + if(state == States::ON_TRANS_ADC_CLOSE_ZERO) { + if (adcState == AdcStates::BOOT_DELAY) { + if (adcCountdown.hasTimedOut()) { + adcState = AdcStates::SEND_SETUP; + adcCmdExecuted = false; + } + } + if (adcState == AdcStates::SEND_SETUP) { + if (adcCmdExecuted) { + adcState = AdcStates::NORMAL; + if(submode == plpcdu::NORMAL_ADC_ONLY) { + setMode(MODE_NORMAL, NORMAL_ADC_ONLY); + } + adcCountdown.setTimeout(100); + adcCountdown.resetTimer(); + adcCmdExecuted = false; + } + } } } if (submode == plpcdu::NORMAL_ALL_ON) { if (state == States::ON_TRANS_ADC_CLOSE_ZERO) { - if (not commandExecuted) { + if (not commandExecuted and adcState == AdcStates::NORMAL) { float waitTime = DFT_SSR_TO_DRO_WAIT_TIME; params.getValue(PARAM_KEY_MAP[SSR_TO_DRO_WAIT_TIME], waitTime); countdown.setTimeout(std::round(waitTime * 1000)); @@ -188,7 +200,7 @@ void PayloadPcduHandler::stateMachineToNormal() { } // ADC values are ok, 5 seconds have elapsed if (transitionOk and countdown.hasTimedOut()) { - state = States::PCDU_ON; + state = States::PL_PCDU_ON; setMode(MODE_NORMAL, plpcdu::NORMAL_ALL_ON); countdown.resetTimer(); commandExecuted = false; @@ -200,7 +212,7 @@ void PayloadPcduHandler::stateMachineToNormal() { void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { if (mode == _MODE_TO_NORMAL) { - stateMachineToNormal(); + stateMachineToNormal(modeFrom, subModeFrom); } } @@ -398,7 +410,7 @@ void PayloadPcduHandler::transitionBackToOff(bool notifyFdir) { gpioIF->pullLow(gpioIds::PLPCDU_ENB_TX); gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT0); gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT1); - state = States::PCDU_OFF; + state = States::PL_PCDU_OFF; adcState = AdcStates::OFF; setMode(MODE_OFF); if (notifyFdir) { diff --git a/mission/devices/PayloadPcduHandler.h b/mission/devices/PayloadPcduHandler.h index b1c34359..5fa229b9 100644 --- a/mission/devices/PayloadPcduHandler.h +++ b/mission/devices/PayloadPcduHandler.h @@ -75,7 +75,8 @@ class PayloadPcduHandler : public DeviceHandlerBase { private: enum class States : uint8_t { - PCDU_OFF, + PL_PCDU_OFF, + POWER_CHANNELS_ON, // Solid State Relay, enable battery voltages VBAT0 and VBAT1. This will also switch on // the ADC ON_TRANS_SSR, @@ -92,8 +93,8 @@ class PayloadPcduHandler : public DeviceHandlerBase { // Switch on HPA component and monitor voltages for 5 seconds ON_TRANS_HPA, // All components of the experiment are on - PCDU_ON, - } state = States::PCDU_OFF; + PL_PCDU_ON, + } state = States::PL_PCDU_OFF; enum class AdcMode { EXT_CONV, INT_CONV } adcMode = AdcMode::INT_CONV; @@ -158,7 +159,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { void checkAdcValues(); void handleOutOfBoundsPrintout(); void checkJsonFileInit(); - void stateMachineToNormal(); + void stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom); bool checkVoltage(float val, float lowerBound, float upperBound, Event event); bool checkCurrent(float val, float upperBound, Event event); void handleFailureInjection(std::string output, Event event); From 0937697637c119c40bdca96489f83fbb1c371b51 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 25 Mar 2022 15:49:39 +0100 Subject: [PATCH 02/20] use transition mode --- mission/devices/PayloadPcduHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index dbd1708d..fbbdfc7d 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -29,7 +29,7 @@ void PayloadPcduHandler::doStartUp() { // TODO: Handle switching power on here // TODO: Go to on mode here instead, indicating that the power is on // We are now in ON mode - setMode(MODE_ON); + setMode(_MODE_TO_ON); } void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom) { From 74fa98d16120b77312ef9a845f1b99f8a39675e9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 25 Mar 2022 15:56:44 +0100 Subject: [PATCH 03/20] add dual lane power switcher for PL PCDU --- bsp_q7s/core/ObjectFactory.cpp | 12 +++++++----- bsp_q7s/core/ObjectFactory.h | 3 ++- mission/devices/PayloadPcduHandler.cpp | 14 ++++++++------ mission/devices/PayloadPcduHandler.h | 6 +++++- mission/system/TcsBoardAssembly.h | 3 +-- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index a499363c..05110f4b 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -148,7 +148,7 @@ void ObjectFactory::produce(void* args) { createHeaterComponents(); createSolarArrayDeploymentComponents(); - createPlPcduComponents(gpioComIF, spiComIF); + createPlPcduComponents(gpioComIF, spiComIF, pwrSwitcher); #if OBSW_ADD_SYRLINKS == 1 createSyrlinksComponents(); #endif /* OBSW_ADD_SYRLINKS == 1 */ @@ -1134,7 +1134,8 @@ void ObjectFactory::createCcsdsComponents(LinuxLibgpioIF* gpioComIF) { #endif /* BOARD_TE0720 == 0 */ } -void ObjectFactory::createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF) { +void ObjectFactory::createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, + PowerSwitchIF* pwrSwitcher) { using namespace gpio; // Create all GPIO components first GpioCookie* plPcduGpios = new GpioCookie; @@ -1180,9 +1181,10 @@ void ObjectFactory::createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* 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(), false); + auto plPcduHandler = new PayloadPcduHandler( + objects::PLPCDU_HANDLER, objects::SPI_COM_IF, spiCookie, gpioComIF, SdCardManager::instance(), + pwrSwitcher, pcduSwitches::Switches::PDU2_CH1_PL_PCDU_BATT_0_14V8, + pcduSwitches::Switches::PDU2_CH6_PL_PCDU_BATT_1_14V8, false); spiCookie->setCallbackMode(PayloadPcduHandler::extConvAsTwoCallback, plPcduHandler); static_cast(plPcduHandler); #if OBSW_TEST_PL_PCDU == 1 diff --git a/bsp_q7s/core/ObjectFactory.h b/bsp_q7s/core/ObjectFactory.h index ff88db8e..412f498c 100644 --- a/bsp_q7s/core/ObjectFactory.h +++ b/bsp_q7s/core/ObjectFactory.h @@ -15,7 +15,8 @@ void produce(void* args); void createCommunicationInterfaces(LinuxLibgpioIF** gpioComIF, UartComIF** uartComIF, SpiComIF** spiComIF, I2cComIF** i2cComIF); void createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF** pwrSwitcher); -void createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF); +void createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, + PowerSwitchIF* pwrSwitcher); void createTmpComponents(); void createRadSensorComponent(LinuxLibgpioIF* gpioComIF); void createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index fbbdfc7d..d781bdda 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -14,12 +14,14 @@ PayloadPcduHandler::PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie, GpioIF* gpioIF, SdCardMountedIF* sdcMan, - bool periodicPrintout) + PowerSwitchIF* pwrSwitcher, pcduSwitches::Switches switchA, + pcduSwitches::Switches switchB, bool periodicPrintout) : DeviceHandlerBase(objectId, comIF, cookie), adcSet(this), periodicPrintout(periodicPrintout), gpioIF(gpioIF), - sdcMan(sdcMan) {} + sdcMan(sdcMan), + pwrStateMachine(switchA, switchB, pwrSwitcher) {} void PayloadPcduHandler::doStartUp() { if ((state != States::PL_PCDU_OFF) and (state != States::ON_TRANS_SSR)) { @@ -34,8 +36,8 @@ void PayloadPcduHandler::doStartUp() { void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom) { using namespace plpcdu; - if(submode == plpcdu::NORMAL_ALL_ON or submode == plpcdu::NORMAL_ADC_ONLY) { - if(state == States::PL_PCDU_OFF) { + if (submode == plpcdu::NORMAL_ALL_ON or submode == plpcdu::NORMAL_ADC_ONLY) { + if (state == States::PL_PCDU_OFF) { // TODO: Config error, emit error printout setMode(MODE_OFF); } @@ -59,7 +61,7 @@ void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subMode monMode = MonitoringMode::CLOSE_TO_ZERO; } } - if(state == States::ON_TRANS_ADC_CLOSE_ZERO) { + if (state == States::ON_TRANS_ADC_CLOSE_ZERO) { if (adcState == AdcStates::BOOT_DELAY) { if (adcCountdown.hasTimedOut()) { adcState = AdcStates::SEND_SETUP; @@ -69,7 +71,7 @@ void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subMode if (adcState == AdcStates::SEND_SETUP) { if (adcCmdExecuted) { adcState = AdcStates::NORMAL; - if(submode == plpcdu::NORMAL_ADC_ONLY) { + if (submode == plpcdu::NORMAL_ADC_ONLY) { setMode(MODE_NORMAL, NORMAL_ADC_ONLY); } adcCountdown.setTimeout(100); diff --git a/mission/devices/PayloadPcduHandler.h b/mission/devices/PayloadPcduHandler.h index 5fa229b9..e99c737e 100644 --- a/mission/devices/PayloadPcduHandler.h +++ b/mission/devices/PayloadPcduHandler.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "events/subsystemIdRanges.h" #include "fsfw/FSFW.h" @@ -60,7 +61,9 @@ class PayloadPcduHandler : public DeviceHandlerBase { static constexpr Event I_HPA_OUT_OF_BOUNDS = event::makeEvent(SUBSYSTEM_ID, 11, severity::MEDIUM); PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie, GpioIF* gpioIF, - SdCardMountedIF* sdcMan, bool periodicPrintout); + SdCardMountedIF* sdcMan, PowerSwitchIF* pwrSwitcher, + pcduSwitches::Switches switchA, pcduSwitches::Switches switchB, + bool periodicPrintout); void setToGoToNormalModeImmediately(bool enable); void enablePeriodicPrintout(bool enable, uint8_t divider); @@ -133,6 +136,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { PoolEntry processedValues = PoolEntry({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}); PoolEntry tempC = PoolEntry({0.0}); + DualLanePowerStateMachine pwrStateMachine; void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override; void doStartUp() override; diff --git a/mission/system/TcsBoardAssembly.h b/mission/system/TcsBoardAssembly.h index cda78317..832f335d 100644 --- a/mission/system/TcsBoardAssembly.h +++ b/mission/system/TcsBoardAssembly.h @@ -14,8 +14,7 @@ struct TcsBoardHelper { class TcsBoardAssembly : public AssemblyBase, public ConfirmsFailuresIF { public: static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::TCS_BOARD_ASS; - static constexpr Event CHILDREN_LOST_MODE = - event::makeEvent(SUBSYSTEM_ID, 0, severity::MEDIUM); + static constexpr Event CHILDREN_LOST_MODE = event::makeEvent(SUBSYSTEM_ID, 0, severity::MEDIUM); TcsBoardAssembly(object_id_t objectId, object_id_t parentId, PowerSwitchIF* pwrSwitcher, power::Switch_t switcher, TcsBoardHelper helper); From f88a063d83c047c4d189ce14ec14dde115cd9dbe Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 25 Mar 2022 16:01:44 +0100 Subject: [PATCH 04/20] change to more generic type --- common/config/devices/powerSwitcherList.h | 5 ++++- mission/devices/PayloadPcduHandler.cpp | 4 ++-- mission/devices/PayloadPcduHandler.h | 5 ++--- mission/system/DualLanePowerStateMachine.cpp | 4 ++-- mission/system/DualLanePowerStateMachine.h | 6 +++--- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/common/config/devices/powerSwitcherList.h b/common/config/devices/powerSwitcherList.h index f99e0930..f77a3685 100644 --- a/common/config/devices/powerSwitcherList.h +++ b/common/config/devices/powerSwitcherList.h @@ -3,12 +3,15 @@ #include "OBSWConfig.h" +#include + #include #include namespace pcduSwitches { + /* Switches are uint8_t datatype and go from 0 to 255 */ -enum Switches: uint8_t { +enum Switches: power::Switch_t { PDU1_CH0_TCS_BOARD_3V3, PDU1_CH1_SYRLINKS_12V, PDU1_CH2_STAR_TRACKER_5V, diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index d781bdda..e21c1467 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -14,8 +14,8 @@ PayloadPcduHandler::PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie, GpioIF* gpioIF, SdCardMountedIF* sdcMan, - PowerSwitchIF* pwrSwitcher, pcduSwitches::Switches switchA, - pcduSwitches::Switches switchB, bool periodicPrintout) + PowerSwitchIF* pwrSwitcher, power::Switch_t switchA, + power::Switch_t switchB, bool periodicPrintout) : DeviceHandlerBase(objectId, comIF, cookie), adcSet(this), periodicPrintout(periodicPrintout), diff --git a/mission/devices/PayloadPcduHandler.h b/mission/devices/PayloadPcduHandler.h index e99c737e..7a30e297 100644 --- a/mission/devices/PayloadPcduHandler.h +++ b/mission/devices/PayloadPcduHandler.h @@ -61,9 +61,8 @@ class PayloadPcduHandler : public DeviceHandlerBase { static constexpr Event I_HPA_OUT_OF_BOUNDS = event::makeEvent(SUBSYSTEM_ID, 11, severity::MEDIUM); PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie, GpioIF* gpioIF, - SdCardMountedIF* sdcMan, PowerSwitchIF* pwrSwitcher, - pcduSwitches::Switches switchA, pcduSwitches::Switches switchB, - bool periodicPrintout); + SdCardMountedIF* sdcMan, PowerSwitchIF* pwrSwitcher, power::Switch_t switchCh0, + power::Switch_t switchCh1, bool periodicPrintout); void setToGoToNormalModeImmediately(bool enable); void enablePeriodicPrintout(bool enable, uint8_t divider); diff --git a/mission/system/DualLanePowerStateMachine.cpp b/mission/system/DualLanePowerStateMachine.cpp index 666e1d1e..5669ef7d 100644 --- a/mission/system/DualLanePowerStateMachine.cpp +++ b/mission/system/DualLanePowerStateMachine.cpp @@ -3,8 +3,8 @@ #include #include -DualLanePowerStateMachine::DualLanePowerStateMachine(pcduSwitches::Switches switchA, - pcduSwitches::Switches switchB, +DualLanePowerStateMachine::DualLanePowerStateMachine(power::Switch_t switchA, + power::Switch_t switchB, PowerSwitchIF* pwrSwitcher, dur_millis_t checkTimeout) : PowerStateMachineBase(pwrSwitcher, checkTimeout), SWITCH_A(switchA), SWITCH_B(switchB) {} diff --git a/mission/system/DualLanePowerStateMachine.h b/mission/system/DualLanePowerStateMachine.h index e22e7ae4..d2160c64 100644 --- a/mission/system/DualLanePowerStateMachine.h +++ b/mission/system/DualLanePowerStateMachine.h @@ -12,12 +12,12 @@ class PowerSwitchIF; class DualLanePowerStateMachine : public PowerStateMachineBase { public: - DualLanePowerStateMachine(pcduSwitches::Switches switchA, pcduSwitches::Switches switchB, + DualLanePowerStateMachine(power::Switch_t switchA, power::Switch_t switchB, PowerSwitchIF* pwrSwitcher, dur_millis_t checkTimeout = 5000); power::OpCodes fsm() override; - const pcduSwitches::Switches SWITCH_A; - const pcduSwitches::Switches SWITCH_B; + const power::Switch_t SWITCH_A; + const power::Switch_t SWITCH_B; private: }; From 2410c6ccc6a5ae44f9002f2191137e0eb590602c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 26 Mar 2022 16:38:42 +0100 Subject: [PATCH 05/20] added SUS component creation to RPi --- bsp_linux_board/ObjectFactory.cpp | 65 +-- bsp_linux_board/ObjectFactory.h | 5 + bsp_q7s/callbacks/CMakeLists.txt | 2 +- bsp_q7s/callbacks/gpioCallbacks.cpp | 487 ------------------- bsp_q7s/callbacks/q7sGpioCallbacks.cpp | 54 ++ bsp_q7s/callbacks/q7sGpioCallbacks.h | 15 + bsp_q7s/core/ObjectFactory.cpp | 188 +------ bsp_q7s/core/ObjectFactory.h | 2 - linux/CMakeLists.txt | 7 +- linux/ObjectFactory.cpp | 172 +++++++ linux/ObjectFactory.h | 14 + linux/callbacks/CMakeLists.txt | 3 + linux/callbacks/gpioCallbacks.cpp | 431 ++++++++++++++++ {bsp_q7s => linux}/callbacks/gpioCallbacks.h | 53 +- linux/fsfwconfig/OBSWConfig.h.in | 1 + 15 files changed, 775 insertions(+), 724 deletions(-) delete mode 100644 bsp_q7s/callbacks/gpioCallbacks.cpp create mode 100644 bsp_q7s/callbacks/q7sGpioCallbacks.cpp create mode 100644 bsp_q7s/callbacks/q7sGpioCallbacks.h create mode 100644 linux/ObjectFactory.cpp create mode 100644 linux/ObjectFactory.h create mode 100644 linux/callbacks/CMakeLists.txt create mode 100644 linux/callbacks/gpioCallbacks.cpp rename {bsp_q7s => linux}/callbacks/gpioCallbacks.h (61%) diff --git a/bsp_linux_board/ObjectFactory.cpp b/bsp_linux_board/ObjectFactory.cpp index 18da8896..f00c749a 100644 --- a/bsp_linux_board/ObjectFactory.cpp +++ b/bsp_linux_board/ObjectFactory.cpp @@ -9,6 +9,7 @@ #include "fsfw/tmtcpacket/pus/tm.h" #include "fsfw/tmtcservices/CommandingServiceBase.h" #include "fsfw/tmtcservices/PusServiceBase.h" +#include "linux/ObjectFactory.h" #include "linux/boardtest/LibgpiodTest.h" #include "linux/boardtest/SpiTestClass.h" #include "linux/boardtest/UartTestClass.h" @@ -63,38 +64,44 @@ void ObjectFactory::produce(void* args) { GpioIF* gpioIF = new LinuxLibgpioIF(objects::GPIO_IF); GpioCookie* gpioCookie = nullptr; static_cast(gpioCookie); - - new SpiComIF(objects::SPI_COM_IF, gpioIF); - - std::string spiDev; - SpiCookie* spiCookie = nullptr; - static_cast(spiCookie); + std::string spiDev = "/dev/spidev0.1"; + SpiComIF* spiComIF = new SpiComIF(objects::SPI_COM_IF, gpioIF); + static_cast(spiComIF); #if OBSW_ADD_ACS_BOARD == 1 - if (gpioCookie == nullptr) { - gpioCookie = new GpioCookie(); - } + createRpiAcsBoard(gpioIF, spiDev); +#endif + +#if OBSW_ADD_SUN_SENSORS == 1 + createSunSensorComponents(gpioIF, spiComIF, nullptr, spiDev); +#endif + +#if OBSW_ADD_TEST_CODE == 1 + createTestTasks(); +#endif /* OBSW_ADD_TEST_CODE == 1 */ +} + +void ObjectFactory::createRpiAcsBoard(GpioIF* gpioIF, std::string spiDev) { + GpioCookie* gpioCookie = new GpioCookie(); // TODO: Missing pin for Gyro 2 gpio::createRpiGpioConfig(gpioCookie, gpioIds::MGM_0_LIS3_CS, gpio::MGM_0_BCM_PIN, "MGM_0_LIS3", - gpio::Direction::OUT, 1); + gpio::Direction::OUT, gpio::Levels::HIGH); gpio::createRpiGpioConfig(gpioCookie, gpioIds::MGM_1_RM3100_CS, gpio::MGM_1_BCM_PIN, - "MGM_1_RM3100", gpio::Direction::OUT, 1); + "MGM_1_RM3100", gpio::Direction::OUT, gpio::Levels::HIGH); gpio::createRpiGpioConfig(gpioCookie, gpioIds::MGM_2_LIS3_CS, gpio::MGM_2_BCM_PIN, "MGM_2_LIS3", - gpio::Direction::OUT, 1); + gpio::Direction::OUT, gpio::Levels::HIGH); gpio::createRpiGpioConfig(gpioCookie, gpioIds::MGM_3_RM3100_CS, gpio::MGM_3_BCM_PIN, - "MGM_3_RM3100", gpio::Direction::OUT, 1); + "MGM_3_RM3100", gpio::Direction::OUT, gpio::Levels::HIGH); gpio::createRpiGpioConfig(gpioCookie, gpioIds::GYRO_0_ADIS_CS, gpio::GYRO_0_BCM_PIN, - "GYRO_0_ADIS", gpio::Direction::OUT, 1); + "GYRO_0_ADIS", gpio::Direction::OUT, gpio::Levels::HIGH); gpio::createRpiGpioConfig(gpioCookie, gpioIds::GYRO_1_L3G_CS, gpio::GYRO_1_BCM_PIN, "GYRO_1_L3G", - gpio::Direction::OUT, 1); + gpio::Direction::OUT, gpio::Levels::HIGH); gpio::createRpiGpioConfig(gpioCookie, gpioIds::GYRO_2_ADIS_CS, gpio::GYRO_2_BCM_PIN, - "GYRO_2_ADIS", gpio::Direction::OUT, 1); + "GYRO_2_ADIS", gpio::Direction::OUT, gpio::Levels::HIGH); gpio::createRpiGpioConfig(gpioCookie, gpioIds::GYRO_3_L3G_CS, gpio::GYRO_3_BCM_PIN, "GYRO_3_L3G", - gpio::Direction::OUT, 1); + gpio::Direction::OUT, gpio::Levels::HIGH); gpioIF->addGpios(gpioCookie); - - spiDev = "/dev/spidev0.1"; - spiCookie = + 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 = @@ -136,9 +143,9 @@ void ObjectFactory::produce(void* args) { spiCookie = new SpiCookie(addresses::GYRO_0_ADIS, gpioIds::GYRO_0_ADIS_CS, spiDev, - ADIS16507::MAXIMUM_REPLY_SIZE, spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); - auto adisHandler = - new GyroADIS16507Handler(objects::GYRO_0_ADIS_HANDLER, objects::SPI_COM_IF, spiCookie); + ADIS1650X::MAXIMUM_REPLY_SIZE, spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); + auto adisHandler = new GyroADIS1650XHandler(objects::GYRO_0_ADIS_HANDLER, objects::SPI_COM_IF, + spiCookie, ADIS1650X::Type::ADIS16505); adisHandler->setStartUpImmediately(); spiCookie = new SpiCookie(addresses::GYRO_1_L3G, gpioIds::GYRO_1_L3G_CS, spiDev, L3GD20H::MAX_BUFFER_SIZE, @@ -152,9 +159,9 @@ void ObjectFactory::produce(void* args) { spiCookie = new SpiCookie(addresses::GYRO_2_ADIS, gpioIds::GYRO_2_ADIS_CS, spiDev, - ADIS16507::MAXIMUM_REPLY_SIZE, spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); - adisHandler = - new GyroADIS16507Handler(objects::GYRO_2_ADIS_HANDLER, objects::SPI_COM_IF, spiCookie); + ADIS1650X::MAXIMUM_REPLY_SIZE, spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); + adisHandler = new GyroADIS1650XHandler(objects::GYRO_2_ADIS_HANDLER, objects::SPI_COM_IF, + spiCookie, ADIS1650X::Type::ADIS16505); adisHandler->setStartUpImmediately(); spiCookie = @@ -166,12 +173,6 @@ void ObjectFactory::produce(void* args) { #if FSFW_HAL_L3GD20_GYRO_DEBUG == 1 gyroL3gHandler->setToGoToNormalMode(true); #endif - -#endif /* RPI_TEST_ACS_BOARD == 1 */ - -#if OBSW_ADD_TEST_CODE == 1 - createTestTasks(); -#endif /* OBSW_ADD_TEST_CODE == 1 */ } void ObjectFactory::createTestTasks() { diff --git a/bsp_linux_board/ObjectFactory.h b/bsp_linux_board/ObjectFactory.h index 909baf06..7365fb8f 100644 --- a/bsp_linux_board/ObjectFactory.h +++ b/bsp_linux_board/ObjectFactory.h @@ -1,10 +1,15 @@ #ifndef BSP_LINUX_OBJECTFACTORY_H_ #define BSP_LINUX_OBJECTFACTORY_H_ +#include + +class GpioIF; + namespace ObjectFactory { void setStatics(); void produce(void* args); +void createRpiAcsBoard(GpioIF* gpioIF, std::string spiDev); void createTestTasks(); }; // namespace ObjectFactory diff --git a/bsp_q7s/callbacks/CMakeLists.txt b/bsp_q7s/callbacks/CMakeLists.txt index a4462937..584e6026 100644 --- a/bsp_q7s/callbacks/CMakeLists.txt +++ b/bsp_q7s/callbacks/CMakeLists.txt @@ -2,5 +2,5 @@ target_sources(${OBSW_NAME} PRIVATE rwSpiCallback.cpp gnssCallback.cpp pcduSwitchCb.cpp - gpioCallbacks.cpp + q7sGpioCallbacks.cpp ) diff --git a/bsp_q7s/callbacks/gpioCallbacks.cpp b/bsp_q7s/callbacks/gpioCallbacks.cpp deleted file mode 100644 index e5fd877a..00000000 --- a/bsp_q7s/callbacks/gpioCallbacks.cpp +++ /dev/null @@ -1,487 +0,0 @@ -#include "gpioCallbacks.h" - -#include -#include -#include -#include - -#include "busConf.h" - -namespace gpioCallbacks { - -GpioIF* gpioComInterface; - -void initSpiCsDecoder(GpioIF* gpioComIF) { - using namespace gpio; - ReturnValue_t result; - - if (gpioComIF == nullptr) { - sif::debug << "initSpiCsDecoder: Invalid gpioComIF" << std::endl; - return; - } - - gpioComInterface = gpioComIF; - - GpioCookie* spiMuxGpios = new GpioCookie; - - GpiodRegularByLineName* spiMuxBit = nullptr; - /** Setting mux bit 1 to low will disable IC21 on the interface board */ - spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_0_PIN, "SPI Mux Bit 1", - Direction::OUT, Levels::HIGH); - spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_0, spiMuxBit); - /** Setting mux bit 2 to low disables IC1 on the TCS board */ - spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_1_PIN, "SPI Mux Bit 2", - Direction::OUT, Levels::HIGH); - spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, spiMuxBit); - /** Setting mux bit 3 to low disables IC2 on the TCS board and IC22 on the interface board */ - spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_2_PIN, "SPI Mux Bit 3", - Direction::OUT, Levels::LOW); - spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_2, spiMuxBit); - - /** The following gpios can take arbitrary initial values */ - spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_3_PIN, "SPI Mux Bit 4", - Direction::OUT, Levels::LOW); - spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_3, spiMuxBit); - spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_4_PIN, "SPI Mux Bit 5", - Direction::OUT, Levels::LOW); - spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_4, spiMuxBit); - spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_5_PIN, "SPI Mux Bit 6", - Direction::OUT, Levels::LOW); - spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_5, spiMuxBit); - GpiodRegularByLineName* enRwDecoder = new GpiodRegularByLineName( - q7s::gpioNames::EN_RW_CS, "EN_RW_CS", Direction::OUT, Levels::HIGH); - spiMuxGpios->addGpio(gpioIds::EN_RW_CS, enRwDecoder); - - result = gpioComInterface->addGpios(spiMuxGpios); - if (result != HasReturnvaluesIF::RETURN_OK) { - sif::error << "initSpiCsDecoder: Failed to add mux bit gpios to gpioComIF" << std::endl; - return; - } -} - -void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Levels value, - void* args) { - using namespace gpio; - if (gpioComInterface == nullptr) { - sif::debug << "spiCsDecoderCallback: No gpioComIF specified. Call initSpiCsDecoder " - << "to specify gpioComIF" << std::endl; - return; - } - - /* Reading is not supported by the callback function */ - if (gpioOp == gpio::GpioOperation::READ) { - return; - } - - if (value == Levels::HIGH) { - switch (gpioId) { - case (gpioIds::RTD_IC_3): { - disableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_4): { - disableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_5): { - disableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_6): { - disableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_7): { - disableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_8): { - disableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_9): { - disableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_10): { - disableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_11): { - disableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_12): { - disableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_13): { - disableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_14): { - disableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_15): { - disableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_16): { - disableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_17): { - disableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_18): { - disableDecoderTcsIc2(); - break; - } - case (gpioIds::CS_SUS_0): { - disableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_1): { - disableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_2): { - disableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_3): { - disableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_4): { - disableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_5): { - disableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_6): { - disableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_SUS_7): { - disableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_SUS_8): { - disableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_SUS_9): { - disableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_SUS_10): { - disableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_SUS_11): { - disableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_RW1): { - disableRwDecoder(); - break; - } - case (gpioIds::CS_RW2): { - disableRwDecoder(); - break; - } - case (gpioIds::CS_RW3): { - disableRwDecoder(); - break; - } - case (gpioIds::CS_RW4): { - disableRwDecoder(); - break; - } - default: - sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl; - } - } else if (value == Levels::LOW) { - switch (gpioId) { - case (gpioIds::RTD_IC_3): { - selectY7(); - enableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_4): { - selectY6(); - enableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_5): { - selectY5(); - enableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_6): { - selectY4(); - enableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_7): { - selectY3(); - enableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_8): { - selectY2(); - enableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_9): { - selectY1(); - enableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_10): { - selectY0(); - enableDecoderTcsIc1(); - break; - } - case (gpioIds::RTD_IC_11): { - selectY7(); - enableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_12): { - selectY6(); - enableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_13): { - selectY5(); - enableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_14): { - selectY4(); - enableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_15): { - selectY3(); - enableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_16): { - selectY2(); - enableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_17): { - selectY1(); - enableDecoderTcsIc2(); - break; - } - case (gpioIds::RTD_IC_18): { - selectY0(); - enableDecoderTcsIc2(); - break; - } - case (gpioIds::CS_SUS_0): { - selectY0(); - enableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_1): { - selectY1(); - enableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_2): { - selectY2(); - enableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_3): { - selectY3(); - enableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_4): { - selectY4(); - enableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_5): { - selectY5(); - enableDecoderInterfaceBoardIc1(); - break; - } - case (gpioIds::CS_SUS_6): { - selectY0(); - enableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_SUS_7): { - selectY1(); - enableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_SUS_8): { - selectY2(); - enableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_SUS_9): { - selectY3(); - enableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_SUS_10): { - selectY4(); - enableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_SUS_11): { - selectY5(); - enableDecoderInterfaceBoardIc2(); - break; - } - case (gpioIds::CS_RW1): { - selectY0(); - enableRwDecoder(); - break; - } - case (gpioIds::CS_RW2): { - selectY1(); - enableRwDecoder(); - break; - } - case (gpioIds::CS_RW3): { - selectY2(); - enableRwDecoder(); - break; - } - case (gpioIds::CS_RW4): { - selectY3(); - enableRwDecoder(); - break; - } - default: - sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl; - } - } else { - sif::debug << "spiCsDecoderCallback: Invalid value. Must be 0 or 1" << std::endl; - } -} - -void enableDecoderTcsIc1() { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_0); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); -} - -void enableDecoderTcsIc2() { - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_0); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); -} - -void enableDecoderInterfaceBoardIc1() { - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); -} - -void enableDecoderInterfaceBoardIc2() { - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); -} - -void disableDecoderTcsIc1() { - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); -} - -void disableDecoderTcsIc2() { - // DO NOT CHANGE THE ORDER HERE - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); -} - -void disableDecoderInterfaceBoardIc1() { - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); -} - -void disableDecoderInterfaceBoardIc2() { - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); -} - -void enableRwDecoder() { gpioComInterface->pullHigh(gpioIds::EN_RW_CS); } - -void disableRwDecoder() { gpioComInterface->pullLow(gpioIds::EN_RW_CS); } - -void selectY0() { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); -} - -void selectY1() { - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); -} - -void selectY2() { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); -} - -void selectY3() { - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); -} - -void selectY4() { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); -} - -void selectY5() { - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); -} - -void selectY6() { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); -} - -void selectY7() { - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); -} - -void disableAllDecoder() { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_0); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullLow(gpioIds::EN_RW_CS); -} - -} // namespace gpioCallbacks diff --git a/bsp_q7s/callbacks/q7sGpioCallbacks.cpp b/bsp_q7s/callbacks/q7sGpioCallbacks.cpp new file mode 100644 index 00000000..6db5aed4 --- /dev/null +++ b/bsp_q7s/callbacks/q7sGpioCallbacks.cpp @@ -0,0 +1,54 @@ +#include "q7sGpioCallbacks.h" + +#include +#include +#include +#include + +#include "busConf.h" + +void q7s::gpioCallbacks::initSpiCsDecoder(GpioIF* gpioComIF) { + using namespace gpio; + ReturnValue_t result; + + if (gpioComIF == nullptr) { + sif::debug << "initSpiCsDecoder: Invalid gpioComIF" << std::endl; + return; + } + + GpioCookie* spiMuxGpios = new GpioCookie; + + GpiodRegularByLineName* spiMuxBit = nullptr; + /** Setting mux bit 1 to low will disable IC21 on the interface board */ + spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_0_PIN, "SPI Mux Bit 1", + Direction::OUT, Levels::HIGH); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_0, spiMuxBit); + /** Setting mux bit 2 to low disables IC1 on the TCS board */ + spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_1_PIN, "SPI Mux Bit 2", + Direction::OUT, Levels::HIGH); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, spiMuxBit); + /** Setting mux bit 3 to low disables IC2 on the TCS board and IC22 on the interface board */ + spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_2_PIN, "SPI Mux Bit 3", + Direction::OUT, Levels::LOW); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_2, spiMuxBit); + + /** The following gpios can take arbitrary initial values */ + spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_3_PIN, "SPI Mux Bit 4", + Direction::OUT, Levels::LOW); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_3, spiMuxBit); + spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_4_PIN, "SPI Mux Bit 5", + Direction::OUT, Levels::LOW); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_4, spiMuxBit); + spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_5_PIN, "SPI Mux Bit 6", + Direction::OUT, Levels::LOW); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_5, spiMuxBit); + GpiodRegularByLineName* enRwDecoder = new GpiodRegularByLineName( + q7s::gpioNames::EN_RW_CS, "EN_RW_CS", Direction::OUT, Levels::HIGH); + spiMuxGpios->addGpio(gpioIds::EN_RW_CS, enRwDecoder); + + result = gpioComIF->addGpios(spiMuxGpios); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::error << "initSpiCsDecoder: Failed to add mux bit gpios to gpioComIF" << std::endl; + return; + } +} diff --git a/bsp_q7s/callbacks/q7sGpioCallbacks.h b/bsp_q7s/callbacks/q7sGpioCallbacks.h new file mode 100644 index 00000000..e3306554 --- /dev/null +++ b/bsp_q7s/callbacks/q7sGpioCallbacks.h @@ -0,0 +1,15 @@ +#pragma once + +class GpioIF; + +namespace q7s { +namespace gpioCallbacks { + +/** + * @brief This function initializes the GPIOs used to control the SN74LVC138APWR decoders on + * the TCS Board and the interface board. + */ +void initSpiCsDecoder(GpioIF* gpioComIF); + +} // namespace gpioCallbacks +} // namespace q7s diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 4c8ec3fc..e6804b4b 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -1,22 +1,10 @@ #include "ObjectFactory.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "OBSWConfig.h" #include "bsp_q7s/boardtest/Q7STestTask.h" #include "bsp_q7s/callbacks/gnssCallback.h" -#include "bsp_q7s/callbacks/gpioCallbacks.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/devices/PlocMemoryDumper.h" @@ -29,15 +17,28 @@ #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/StarTrackerDefinitions.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/AcsBoardFdir.h" +#include "mission/system/RtdFdir.h" +#include "mission/system/SusAssembly.h" +#include "mission/system/SusFdir.h" +#include "mission/system/TcsBoardAssembly.h" #include "tmtc/apid.h" #include "tmtc/pusIds.h" @@ -137,10 +138,10 @@ void ObjectFactory::produce(void* args) { #if BOARD_TE0720 == 0 new CoreController(objects::CORE_CONTROLLER); - gpioCallbacks::disableAllDecoder(); + gpioCallbacks::disableAllDecoder(gpioComIF); createPcduComponents(gpioComIF, &pwrSwitcher); createRadSensorComponent(gpioComIF); - createSunSensorComponents(gpioComIF, spiComIF, pwrSwitcher); + createSunSensorComponents(gpioComIF, spiComIF, pwrSwitcher, q7s::SPI_DEFAULT_DEV); #if OBSW_ADD_ACS_BOARD == 1 createAcsBoardComponents(gpioComIF, uartComIF, pwrSwitcher); @@ -264,7 +265,7 @@ void ObjectFactory::createCommunicationInterfaces(LinuxLibgpioIF** gpioComIF, Ua #if BOARD_TE0720 == 0 /* Adding gpios for chip select decoding to the gpioComIf */ - gpioCallbacks::initSpiCsDecoder(*gpioComIF); + q7s::gpioCallbacks::initSpiCsDecoder(*gpioComIF); #endif } @@ -326,161 +327,6 @@ void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { #endif } -void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, - PowerSwitchIF* pwrSwitcher) { - using namespace gpio; - GpioCookie* gpioCookieSus = new GpioCookie(); - GpioCallback* susgpio = nullptr; - - susgpio = new GpioCallback("Chip select SUS 0", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_0, susgpio); - susgpio = new GpioCallback("Chip select SUS 1", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_1, susgpio); - susgpio = new GpioCallback("Chip select SUS 2", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_2, susgpio); - susgpio = new GpioCallback("Chip select SUS 3", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_3, susgpio); - susgpio = new GpioCallback("Chip select SUS 4", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_4, susgpio); - susgpio = new GpioCallback("Chip select SUS 5", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_5, susgpio); - susgpio = new GpioCallback("Chip select SUS 6", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_6, susgpio); - susgpio = new GpioCallback("Chip select SUS 7", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_7, susgpio); - susgpio = new GpioCallback("Chip select SUS 8", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_8, susgpio); - susgpio = new GpioCallback("Chip select SUS 9", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_9, susgpio); - susgpio = new GpioCallback("Chip select SUS 10", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_10, susgpio); - susgpio = new GpioCallback("Chip select SUS 11", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_11, susgpio); - - gpioComIF->addGpios(gpioCookieSus); - - SusFdir* fdir = nullptr; - std::array susHandlers = {}; -#if OBSW_ADD_SUN_SENSORS == 1 - SpiCookie* spiCookie = - new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE, - spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[0] = new SusHandler(objects::SUS_0, 0, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_0); - susHandlers[0]->setParent(objects::SUS_BOARD_ASS); - susHandlers[0]->setCustomFdir(fdir); - - spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, q7s::SPI_DEFAULT_DEV, - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[1] = new SusHandler(objects::SUS_1, 1, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_1); - susHandlers[1]->setParent(objects::SUS_BOARD_ASS); - susHandlers[1]->setCustomFdir(fdir); - - spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, q7s::SPI_DEFAULT_DEV, - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[2] = new SusHandler(objects::SUS_2, 2, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_2); - susHandlers[2]->setParent(objects::SUS_BOARD_ASS); - susHandlers[2]->setCustomFdir(fdir); - - spiCookie = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string(q7s::SPI_DEFAULT_DEV), - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[3] = new SusHandler(objects::SUS_3, 3, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_3); - susHandlers[3]->setParent(objects::SUS_BOARD_ASS); - susHandlers[3]->setCustomFdir(fdir); - - spiCookie = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string(q7s::SPI_DEFAULT_DEV), - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[4] = new SusHandler(objects::SUS_4, 4, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_4); - susHandlers[4]->setParent(objects::SUS_BOARD_ASS); - susHandlers[4]->setCustomFdir(fdir); - - spiCookie = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string(q7s::SPI_DEFAULT_DEV), - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[5] = new SusHandler(objects::SUS_5, 5, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_5); - susHandlers[5]->setParent(objects::SUS_BOARD_ASS); - susHandlers[5]->setCustomFdir(fdir); - - spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, q7s::SPI_DEFAULT_DEV, - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[6] = new SusHandler(objects::SUS_6, 6, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_6); - susHandlers[6]->setParent(objects::SUS_BOARD_ASS); - susHandlers[6]->setCustomFdir(fdir); - - spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, q7s::SPI_DEFAULT_DEV, - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[7] = new SusHandler(objects::SUS_7, 7, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_7); - susHandlers[7]->setParent(objects::SUS_BOARD_ASS); - susHandlers[7]->setCustomFdir(fdir); - - spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, q7s::SPI_DEFAULT_DEV, - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[8] = new SusHandler(objects::SUS_8, 8, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_8); - susHandlers[8]->setParent(objects::SUS_BOARD_ASS); - susHandlers[8]->setCustomFdir(fdir); - - spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, q7s::SPI_DEFAULT_DEV, - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[9] = new SusHandler(objects::SUS_9, 9, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_9); - susHandlers[9]->setParent(objects::SUS_BOARD_ASS); - susHandlers[9]->setCustomFdir(fdir); - - spiCookie = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, q7s::SPI_DEFAULT_DEV, - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[10] = new SusHandler(objects::SUS_10, 10, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_10); - susHandlers[10]->setParent(objects::SUS_BOARD_ASS); - susHandlers[10]->setCustomFdir(fdir); - - spiCookie = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, q7s::SPI_DEFAULT_DEV, - SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); - susHandlers[11] = new SusHandler(objects::SUS_11, 11, objects::SPI_COM_IF, spiCookie); - fdir = new SusFdir(objects::SUS_11); - susHandlers[11]->setParent(objects::SUS_BOARD_ASS); - susHandlers[11]->setCustomFdir(fdir); - - for (auto& sus : susHandlers) { - if (sus != nullptr) { -#if OBSW_TEST_SUS == 1 - sus->setStartUpImmediately(); - sus->setToGoToNormalMode(true); -#endif -#if OBSW_DEBUG_SUS == 1 - sus->enablePeriodicPrintout(true, 3); -#endif - } - } - std::array susIds = {objects::SUS_0, objects::SUS_1, objects::SUS_2, - objects::SUS_3, objects::SUS_4, objects::SUS_5, - objects::SUS_6, objects::SUS_7, objects::SUS_8, - objects::SUS_9, objects::SUS_10, objects::SUS_11}; - SusAssHelper susAssHelper = SusAssHelper(susIds); - auto susAss = - new SusAssembly(objects::SUS_BOARD_ASS, objects::NO_OBJECT, pwrSwitcher, susAssHelper); - static_cast(susAss); -#endif /* OBSW_ADD_SUN_SENSORS == 1 */ -} - void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComIF* uartComIF, PowerSwitchIF* pwrSwitcher) { using namespace gpio; diff --git a/bsp_q7s/core/ObjectFactory.h b/bsp_q7s/core/ObjectFactory.h index ff88db8e..1d15dcfa 100644 --- a/bsp_q7s/core/ObjectFactory.h +++ b/bsp_q7s/core/ObjectFactory.h @@ -18,8 +18,6 @@ void createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF** pwrSwitcher void createPlPcduComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF); void createTmpComponents(); void createRadSensorComponent(LinuxLibgpioIF* gpioComIF); -void createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF, - PowerSwitchIF* pwrSwitcher); void createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComIF* uartComIF, PowerSwitchIF* pwrSwitcher); void createHeaterComponents(); diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 79891a84..c183ea60 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -1,6 +1,11 @@ add_subdirectory(csp) add_subdirectory(utility) +add_subdirectory(callbacks) add_subdirectory(boardtest) add_subdirectory(devices) add_subdirectory(fsfwconfig) -add_subdirectory(obc) \ No newline at end of file +add_subdirectory(obc) + +target_sources(${OBSW_NAME} PUBLIC + ObjectFactory.cpp +) \ No newline at end of file diff --git a/linux/ObjectFactory.cpp b/linux/ObjectFactory.cpp new file mode 100644 index 00000000..102ef5d9 --- /dev/null +++ b/linux/ObjectFactory.cpp @@ -0,0 +1,172 @@ +#include "ObjectFactory.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "OBSWConfig.h" +#include "devConf.h" +#include "devices/addresses.h" +#include "devices/gpioIds.h" + +void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiComIF, + PowerSwitchIF* pwrSwitcher, std::string spiDev) { + using namespace gpio; + GpioCookie* gpioCookieSus = new GpioCookie(); + GpioCallback* susgpio = nullptr; + + susgpio = new GpioCallback("Chip select SUS 0", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_0, susgpio); + susgpio = new GpioCallback("Chip select SUS 1", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_1, susgpio); + susgpio = new GpioCallback("Chip select SUS 2", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_2, susgpio); + susgpio = new GpioCallback("Chip select SUS 3", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_3, susgpio); + susgpio = new GpioCallback("Chip select SUS 4", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_4, susgpio); + susgpio = new GpioCallback("Chip select SUS 5", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_5, susgpio); + susgpio = new GpioCallback("Chip select SUS 6", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_6, susgpio); + susgpio = new GpioCallback("Chip select SUS 7", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_7, susgpio); + susgpio = new GpioCallback("Chip select SUS 8", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_8, susgpio); + susgpio = new GpioCallback("Chip select SUS 9", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_9, susgpio); + susgpio = new GpioCallback("Chip select SUS 10", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_10, susgpio); + susgpio = new GpioCallback("Chip select SUS 11", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_11, susgpio); + + gpioComIF->addGpios(gpioCookieSus); + +#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); + susHandlers[0] = new SusHandler(objects::SUS_0, 0, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_0); + 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, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[1] = new SusHandler(objects::SUS_1, 1, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_1); + 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, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[2] = new SusHandler(objects::SUS_2, 2, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_2); + 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, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[3] = new SusHandler(objects::SUS_3, 3, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_3); + 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, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[4] = new SusHandler(objects::SUS_4, 4, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_4); + 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, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[5] = new SusHandler(objects::SUS_5, 5, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_5); + 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, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[6] = new SusHandler(objects::SUS_6, 6, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_6); + 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, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[7] = new SusHandler(objects::SUS_7, 7, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_7); + 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, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[8] = new SusHandler(objects::SUS_8, 8, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_8); + 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, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[9] = new SusHandler(objects::SUS_9, 9, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_9); + 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, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[10] = new SusHandler(objects::SUS_10, 10, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_10); + 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, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + susHandlers[11] = new SusHandler(objects::SUS_11, 11, objects::SPI_COM_IF, spiCookie); + fdir = new SusFdir(objects::SUS_11); + susHandlers[11]->setParent(objects::SUS_BOARD_ASS); + susHandlers[11]->setCustomFdir(fdir); + + for (auto& sus : susHandlers) { + if (sus != nullptr) { +#if OBSW_TEST_SUS == 1 + sus->setStartUpImmediately(); + sus->setToGoToNormalMode(true); +#endif +#if OBSW_DEBUG_SUS == 1 + sus->enablePeriodicPrintout(true, 3); +#endif + } + } + std::array susIds = {objects::SUS_0, objects::SUS_1, objects::SUS_2, + objects::SUS_3, objects::SUS_4, objects::SUS_5, + objects::SUS_6, objects::SUS_7, objects::SUS_8, + objects::SUS_9, objects::SUS_10, objects::SUS_11}; + SusAssHelper susAssHelper = SusAssHelper(susIds); + auto susAss = + new SusAssembly(objects::SUS_BOARD_ASS, objects::NO_OBJECT, pwrSwitcher, susAssHelper); + static_cast(susAss); +#endif /* OBSW_ADD_SUN_SENSORS == 1 */ +} diff --git a/linux/ObjectFactory.h b/linux/ObjectFactory.h new file mode 100644 index 00000000..7a6e964a --- /dev/null +++ b/linux/ObjectFactory.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +class GpioIF; +class SpiComIF; +class PowerSwitchIF; + +namespace ObjectFactory { + +void createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiComIF, PowerSwitchIF* pwrSwitcher, + std::string spiDev); + +} diff --git a/linux/callbacks/CMakeLists.txt b/linux/callbacks/CMakeLists.txt new file mode 100644 index 00000000..89bb24bb --- /dev/null +++ b/linux/callbacks/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${OBSW_NAME} PRIVATE + gpioCallbacks.cpp +) diff --git a/linux/callbacks/gpioCallbacks.cpp b/linux/callbacks/gpioCallbacks.cpp new file mode 100644 index 00000000..969aada0 --- /dev/null +++ b/linux/callbacks/gpioCallbacks.cpp @@ -0,0 +1,431 @@ +#include "gpioCallbacks.h" + +#include "devices/gpioIds.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw_hal/common/gpio/GpioCookie.h" +#include "fsfw_hal/common/gpio/GpioIF.h" + +void gpioCallbacks::spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, + gpio::Levels value, void* args) { + GpioIF* gpioIF = reinterpret_cast(args); + if (gpioIF == nullptr) { + sif::debug << "spiCsDecoderCallback: No gpioComIF specified. Call initSpiCsDecoder " + << "to specify gpioComIF" << std::endl; + return; + } + + /* Reading is not supported by the callback function */ + if (gpioOp == gpio::GpioOperation::READ) { + return; + } + + if (value == gpio::Levels::HIGH) { + switch (gpioId) { + case (gpioIds::RTD_IC_3): { + disableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_4): { + disableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_5): { + disableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_6): { + disableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_7): { + disableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_8): { + disableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_9): { + disableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_10): { + disableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_11): { + disableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_12): { + disableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_13): { + disableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_14): { + disableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_15): { + disableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_16): { + disableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_17): { + disableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_18): { + disableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_0): { + disableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_1): { + disableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_2): { + disableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_3): { + disableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_4): { + disableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_5): { + disableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_6): { + disableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_7): { + disableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_8): { + disableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_9): { + disableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_10): { + disableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_11): { + disableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_RW1): { + disableRwDecoder(gpioIF); + break; + } + case (gpioIds::CS_RW2): { + disableRwDecoder(gpioIF); + break; + } + case (gpioIds::CS_RW3): { + disableRwDecoder(gpioIF); + break; + } + case (gpioIds::CS_RW4): { + disableRwDecoder(gpioIF); + break; + } + default: + sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl; + } + } else if (value == gpio::Levels::LOW) { + switch (gpioId) { + case (gpioIds::RTD_IC_3): { + selectY7(gpioIF); + enableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_4): { + selectY6(gpioIF); + enableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_5): { + selectY5(gpioIF); + enableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_6): { + selectY4(gpioIF); + enableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_7): { + selectY3(gpioIF); + enableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_8): { + selectY2(gpioIF); + enableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_9): { + selectY1(gpioIF); + enableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_10): { + selectY0(gpioIF); + enableDecoderTcsIc1(gpioIF); + break; + } + case (gpioIds::RTD_IC_11): { + selectY7(gpioIF); + enableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_12): { + selectY6(gpioIF); + enableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_13): { + selectY5(gpioIF); + enableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_14): { + selectY4(gpioIF); + enableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_15): { + selectY3(gpioIF); + enableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_16): { + selectY2(gpioIF); + enableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_17): { + selectY1(gpioIF); + enableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::RTD_IC_18): { + selectY0(gpioIF); + enableDecoderTcsIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_0): { + selectY0(gpioIF); + enableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_1): { + selectY1(gpioIF); + enableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_2): { + selectY2(gpioIF); + enableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_3): { + selectY3(gpioIF); + enableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_4): { + selectY4(gpioIF); + enableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_5): { + selectY5(gpioIF); + enableDecoderInterfaceBoardIc1(gpioIF); + break; + } + case (gpioIds::CS_SUS_6): { + selectY0(gpioIF); + enableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_7): { + selectY1(gpioIF); + enableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_8): { + selectY2(gpioIF); + enableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_9): { + selectY3(gpioIF); + enableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_10): { + selectY4(gpioIF); + enableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_SUS_11): { + selectY5(gpioIF); + enableDecoderInterfaceBoardIc2(gpioIF); + break; + } + case (gpioIds::CS_RW1): { + selectY0(gpioIF); + enableRwDecoder(gpioIF); + break; + } + case (gpioIds::CS_RW2): { + selectY1(gpioIF); + enableRwDecoder(gpioIF); + break; + } + case (gpioIds::CS_RW3): { + selectY2(gpioIF); + enableRwDecoder(gpioIF); + break; + } + case (gpioIds::CS_RW4): { + selectY3(gpioIF); + enableRwDecoder(gpioIF); + break; + } + default: + sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl; + } + } else { + sif::debug << "spiCsDecoderCallback: Invalid value. Must be 0 or 1" << std::endl; + } +} + +void gpioCallbacks::enableDecoderTcsIc1(GpioIF* gpioIF) { + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_0); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_1); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_2); +} + +void gpioCallbacks::enableDecoderTcsIc2(GpioIF* gpioIF) { + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_0); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_1); +} + +void gpioCallbacks::enableDecoderInterfaceBoardIc1(GpioIF* gpioIF) { + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_0); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_2); +} + +void gpioCallbacks::enableDecoderInterfaceBoardIc2(GpioIF* gpioIF) { + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_0); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_2); +} + +void gpioCallbacks::disableDecoderTcsIc1(GpioIF* gpioIF) { + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_0); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_1); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_2); +} + +void gpioCallbacks::disableDecoderTcsIc2(GpioIF* gpioIF) { + // DO NOT CHANGE THE ORDER HERE + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_0); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_2); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_1); +} + +void gpioCallbacks::disableDecoderInterfaceBoardIc1(GpioIF* gpioIF) { + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_0); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_1); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_2); +} + +void gpioCallbacks::disableDecoderInterfaceBoardIc2(GpioIF* gpioIF) { + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_0); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_1); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_2); +} + +void gpioCallbacks::enableRwDecoder(GpioIF* gpioIF) { gpioIF->pullHigh(gpioIds::EN_RW_CS); } + +void gpioCallbacks::disableRwDecoder(GpioIF* gpioIF) { gpioIF->pullLow(gpioIds::EN_RW_CS); } + +void gpioCallbacks::selectY0(GpioIF* gpioIF) { + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_5); +} + +void gpioCallbacks::selectY1(GpioIF* gpioIF) { + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_5); +} + +void gpioCallbacks::selectY2(GpioIF* gpioIF) { + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_5); +} + +void gpioCallbacks::selectY3(GpioIF* gpioIF) { + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_5); +} + +void gpioCallbacks::selectY4(GpioIF* gpioIF) { + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_5); +} + +void gpioCallbacks::selectY5(GpioIF* gpioIF) { + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_5); +} + +void gpioCallbacks::selectY6(GpioIF* gpioIF) { + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_5); +} + +void gpioCallbacks::selectY7(GpioIF* gpioIF) { + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioIF->pullHigh(gpioIds::SPI_MUX_BIT_5); +} + +void gpioCallbacks::disableAllDecoder(GpioIF* gpioIF) { + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_2); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_0); + gpioIF->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioIF->pullLow(gpioIds::EN_RW_CS); +} diff --git a/bsp_q7s/callbacks/gpioCallbacks.h b/linux/callbacks/gpioCallbacks.h similarity index 61% rename from bsp_q7s/callbacks/gpioCallbacks.h rename to linux/callbacks/gpioCallbacks.h index 6b4e99bf..fca89603 100644 --- a/bsp_q7s/callbacks/gpioCallbacks.h +++ b/linux/callbacks/gpioCallbacks.h @@ -1,16 +1,10 @@ -#ifndef LINUX_GPIO_GPIOCALLBACKS_H_ -#define LINUX_GPIO_GPIOCALLBACKS_H_ +#pragma once -#include #include -namespace gpioCallbacks { +class GpioIF; -/** - * @brief This function initializes the GPIOs used to control the SN74LVC138APWR decoders on - * the TCS Board and the interface board. - */ -void initSpiCsDecoder(GpioIF* gpioComIF); +namespace gpioCallbacks { /** * @brief This function implements the decoding to multiply gpios by using the decoder @@ -23,51 +17,50 @@ void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Lev * @brief This function sets mux bits 1-3 to a state which will only enable the decoder * on the TCS board which is named to IC1 in the schematic. */ -void enableDecoderTcsIc1(); +void enableDecoderTcsIc1(GpioIF* gpioIF); /** * @brief This function sets mux bits 1-3 to a state which will only enable the decoder * on the TCS board which is named to IC2 in the schematic. */ -void enableDecoderTcsIc2(); +void enableDecoderTcsIc2(GpioIF* gpioIF); /** * @brief This function sets mux bits 1-3 to a state which will only enable the decoder * on the inteface board board which is named to IC21 in the schematic. */ -void enableDecoderInterfaceBoardIc1(); +void enableDecoderInterfaceBoardIc1(GpioIF* gpioIF); /** * @brief This function sets mux bits 1-3 to a state which will only enable the decoder * on the inteface board board which is named to IC22 in the schematic. */ -void enableDecoderInterfaceBoardIc2(); +void enableDecoderInterfaceBoardIc2(GpioIF* gpioIF); -void disableDecoderTcsIc1(); -void disableDecoderTcsIc2(); -void disableDecoderInterfaceBoardIc1(); -void disableDecoderInterfaceBoardIc2(); +void disableDecoderTcsIc1(GpioIF* gpioIF); +void disableDecoderTcsIc2(GpioIF* gpioIF); +void disableDecoderInterfaceBoardIc1(GpioIF* gpioIF); +void disableDecoderInterfaceBoardIc2(GpioIF* gpioIF); /** * @brief Enables the reaction wheel chip select decoder (IC3). */ -void enableRwDecoder(); -void disableRwDecoder(); +void enableRwDecoder(GpioIF* gpioIF); +void disableRwDecoder(GpioIF* gpioIF); /** * @brief This function disables all decoder. */ -void disableAllDecoder(); +void disableAllDecoder(GpioIF* gpioIF); /** The following functions enable the appropriate channel of the currently enabled decoder */ -void selectY0(); -void selectY1(); -void selectY2(); -void selectY3(); -void selectY4(); -void selectY5(); -void selectY6(); -void selectY7(); -} // namespace gpioCallbacks +void selectY0(GpioIF* gpioIF); +void selectY1(GpioIF* gpioIF); +void selectY2(GpioIF* gpioIF); +void selectY3(GpioIF* gpioIF); +void selectY4(GpioIF* gpioIF); +void selectY5(GpioIF* gpioIF); +void selectY6(GpioIF* gpioIF); +void selectY7(GpioIF* gpioIF); -#endif /* LINUX_GPIO_GPIOCALLBACKS_H_ */ +} // namespace gpioCallbacks diff --git a/linux/fsfwconfig/OBSWConfig.h.in b/linux/fsfwconfig/OBSWConfig.h.in index 5abe4e3f..76328566 100644 --- a/linux/fsfwconfig/OBSWConfig.h.in +++ b/linux/fsfwconfig/OBSWConfig.h.in @@ -127,6 +127,7 @@ debugging. */ #define OBSW_ADD_SUN_SENSORS 0 #define OBSW_ADD_MGT 0 #define OBSW_ADD_ACS_BOARD 0 +#define OBSW_ADD_ACS_HANDLERS 0 #define OBSW_ADD_GPS_0 0 #define OBSW_ADD_GPS_1 0 #define OBSW_ADD_RW 0 From 6e25cf912f261ce79304b4693e591ec3efb31d2d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 28 Mar 2022 10:34:03 +0200 Subject: [PATCH 06/20] tmtc update --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 43a534db..bca8d5d0 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 43a534db9cf8ee14e6c1296dac8b3e2c3c94b240 +Subproject commit bca8d5d05d25812b4e112ac0544b24915ec01971 From 66029cb47aebfb18ea2a19b8949e3afa3359fe94 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 28 Mar 2022 12:23:56 +0200 Subject: [PATCH 07/20] implemented switch handling --- fsfw | 2 +- mission/devices/PayloadPcduHandler.cpp | 51 ++++++++++++++++++++------ mission/devices/PayloadPcduHandler.h | 8 +++- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/fsfw b/fsfw index e6130263..6ea1eabb 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit e6130263ef144c5b1f6eafef734a0150a92d6cda +Subproject commit 6ea1eabb2dd3688f2c7db484cd141f15c9f4fe49 diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index e21c1467..b6c8a6a6 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -28,17 +28,39 @@ void PayloadPcduHandler::doStartUp() { // Config error sif::error << "PayloadPcduHandler::doStartUp: Invalid state" << std::endl; } - // TODO: Handle switching power on here - // TODO: Go to on mode here instead, indicating that the power is on - // We are now in ON mode - setMode(_MODE_TO_ON); + if (pwrStateMachine.getState() == power::States::IDLE) { + pwrStateMachine.start(MODE_ON, pwrSubmode); + } + auto opCode = pwrStateMachine.fsm(); + if (opCode == power::OpCodes::TO_NOT_OFF_DONE or opCode == power::OpCodes::TIMEOUT_OCCURED) { + pwrStateMachine.reset(); + quickTransitionAlreadyCalled = false; + setMode(_MODE_TO_ON); + } +} + +void PayloadPcduHandler::doShutDown() { + if (not quickTransitionAlreadyCalled) { + quickTransitionBackToOff(false, false); + quickTransitionAlreadyCalled = true; + } + if (pwrStateMachine.getState() == power::States::IDLE) { + pwrStateMachine.start(MODE_OFF, 0); + } + auto opCode = pwrStateMachine.fsm(); + if (opCode == power::OpCodes::TO_OFF_DONE or opCode == power::OpCodes::TIMEOUT_OCCURED) { + pwrStateMachine.reset(); + // No need to set mode _MODE_POWER_DOWN, power switching was already handled + setMode(MODE_OFF); + } } void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom) { using namespace plpcdu; if (submode == plpcdu::NORMAL_ALL_ON or submode == plpcdu::NORMAL_ADC_ONLY) { if (state == States::PL_PCDU_OFF) { - // TODO: Config error, emit error printout + sif::error << "PayloadPcduHandler::stateMachineToNormal: Unexpected state PL_PCDU_OFF" + << "detected" << std::endl; setMode(MODE_OFF); } if (state == States::POWER_CHANNELS_ON) { @@ -215,11 +237,11 @@ void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subMode void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { if (mode == _MODE_TO_NORMAL) { stateMachineToNormal(modeFrom, subModeFrom); + return; } + DeviceHandlerBase::doTransition(modeFrom, subModeFrom); } -void PayloadPcduHandler::doShutDown() { transitionBackToOff(false); } - ReturnValue_t PayloadPcduHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { switch (adcState) { case (AdcStates::SEND_SETUP): { @@ -402,7 +424,7 @@ void PayloadPcduHandler::enablePeriodicPrintout(bool enable, uint8_t divider) { opDivider.setDivider(divider); } -void PayloadPcduHandler::transitionBackToOff(bool notifyFdir) { +void PayloadPcduHandler::quickTransitionBackToOff(bool startTransitionToOff, bool notifyFdir) { States currentState = state; gpioIF->pullLow(gpioIds::PLPCDU_ENB_HPA); gpioIF->pullLow(gpioIds::PLPCDU_ENB_MPA); @@ -414,7 +436,9 @@ void PayloadPcduHandler::transitionBackToOff(bool notifyFdir) { gpioIF->pullLow(gpioIds::PLPCDU_ENB_VBAT1); state = States::PL_PCDU_OFF; adcState = AdcStates::OFF; - setMode(MODE_OFF); + if (startTransitionToOff) { + startTransition(MODE_OFF, 0); + } if (notifyFdir) { triggerEvent(TRANSITION_BACK_TO_OFF, static_cast(currentState)); } @@ -568,7 +592,8 @@ bool PayloadPcduHandler::checkVoltage(float val, float lowerBound, float upperBo serializeFloat(p2, val); triggerEvent(event, tooLarge, p2); transitionOk = false; - transitionBackToOff(true); + quickTransitionBackToOff(true, true); + quickTransitionAlreadyCalled = true; return false; } return true; @@ -580,7 +605,8 @@ bool PayloadPcduHandler::checkCurrent(float val, float upperBound, Event event) serializeFloat(p2, val); triggerEvent(event, true, p2); transitionOk = false; - transitionBackToOff(true); + quickTransitionBackToOff(true, true); + quickTransitionAlreadyCalled = true; return false; } return true; @@ -670,7 +696,8 @@ void PayloadPcduHandler::handleFailureInjection(std::string output, Event event) << std::endl; triggerEvent(event, 0, 0); transitionOk = false; - transitionBackToOff(true); + quickTransitionBackToOff(true, true); + quickTransitionAlreadyCalled = true; droToX8InjectionRequested = false; } diff --git a/mission/devices/PayloadPcduHandler.h b/mission/devices/PayloadPcduHandler.h index 7a30e297..62c6f728 100644 --- a/mission/devices/PayloadPcduHandler.h +++ b/mission/devices/PayloadPcduHandler.h @@ -4,13 +4,14 @@ #include #include #include -#include #include "events/subsystemIdRanges.h" #include "fsfw/FSFW.h" #include "fsfw_hal/common/gpio/GpioIF.h" #include "mission/devices/devicedefinitions/payloadPcduDefinitions.h" #include "mission/memory/SdCardMountedIF.h" +#include "mission/system/DualLanePowerStateMachine.h" +#include "mission/system/definitions.h" #ifdef FSFW_OSAL_LINUX class SpiComIF; @@ -98,6 +99,8 @@ class PayloadPcduHandler : public DeviceHandlerBase { PL_PCDU_ON, } state = States::PL_PCDU_OFF; + duallane::Submodes pwrSubmode = duallane::Submodes::A_SIDE; + enum class AdcMode { EXT_CONV, INT_CONV } adcMode = AdcMode::INT_CONV; enum class MonitoringMode { NONE, CLOSE_TO_ZERO, NEGATIVE } monMode = MonitoringMode::NONE; @@ -130,6 +133,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { GpioIF* gpioIF; SdCardMountedIF* sdcMan; plpcdu::PlPcduParameter params; + bool quickTransitionAlreadyCalled = true; PoolEntry channelValues = PoolEntry({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); PoolEntry processedValues = @@ -141,7 +145,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { void doStartUp() override; void doShutDown() override; // Main FDIR function which goes from any PL PCDU state back to all off - void transitionBackToOff(bool notifyFdir); + void quickTransitionBackToOff(bool startTransitionToOff, bool notifyFdir); ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override; ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t* id) override; void fillCommandAndReplyMap() override; From 39b9ed06c3eca563c057e815a003cf8fd30a3656 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 28 Mar 2022 12:30:57 +0200 Subject: [PATCH 08/20] submodule updates --- fsfw | 2 +- tmtc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fsfw b/fsfw index e6130263..6ea1eabb 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit e6130263ef144c5b1f6eafef734a0150a92d6cda +Subproject commit 6ea1eabb2dd3688f2c7db484cd141f15c9f4fe49 diff --git a/tmtc b/tmtc index 43a534db..e3743042 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 43a534db9cf8ee14e6c1296dac8b3e2c3c94b240 +Subproject commit e37430423e814b9e05f25d63970f2c2b5048cfb1 From 6fa975cc74c9478063a56fa255e3b65252d7aef3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 28 Mar 2022 15:29:42 +0200 Subject: [PATCH 09/20] simplified PL PCDU --- fsfw | 2 +- mission/devices/PayloadPcduHandler.cpp | 207 +++++++----------- mission/devices/PayloadPcduHandler.h | 2 +- .../payloadPcduDefinitions.h | 10 + tmtc | 2 +- 5 files changed, 92 insertions(+), 131 deletions(-) diff --git a/fsfw b/fsfw index 6ea1eabb..283a37dc 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 6ea1eabb2dd3688f2c7db484cd141f15c9f4fe49 +Subproject commit 283a37dccc064b71a0e4ca5c483c9a5a5241d355 diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index b6c8a6a6..a3652193 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -35,6 +35,7 @@ void PayloadPcduHandler::doStartUp() { if (opCode == power::OpCodes::TO_NOT_OFF_DONE or opCode == power::OpCodes::TIMEOUT_OCCURED) { pwrStateMachine.reset(); quickTransitionAlreadyCalled = false; + state = States::POWER_CHANNELS_ON; setMode(_MODE_TO_ON); } } @@ -55,13 +56,22 @@ void PayloadPcduHandler::doShutDown() { } } -void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom) { +void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { + if (mode == _MODE_TO_NORMAL) { + stateMachineToNormal(modeFrom, subModeFrom); + return; + } + DeviceHandlerBase::doTransition(modeFrom, subModeFrom); +} + +ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom) { using namespace plpcdu; - if (submode == plpcdu::NORMAL_ALL_ON or submode == plpcdu::NORMAL_ADC_ONLY) { + if (submode == NormalSubmodes::SOLID_STATE_RELAYS_ADC_ON) { if (state == States::PL_PCDU_OFF) { sif::error << "PayloadPcduHandler::stateMachineToNormal: Unexpected state PL_PCDU_OFF" << "detected" << std::endl; setMode(MODE_OFF); + return HasReturnvaluesIF::RETURN_FAILED; } if (state == States::POWER_CHANNELS_ON) { // Switch on relays here @@ -93,153 +103,73 @@ void PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_t subMode if (adcState == AdcStates::SEND_SETUP) { if (adcCmdExecuted) { adcState = AdcStates::NORMAL; - if (submode == plpcdu::NORMAL_ADC_ONLY) { - setMode(MODE_NORMAL, NORMAL_ADC_ONLY); - } adcCountdown.setTimeout(100); adcCountdown.resetTimer(); adcCmdExecuted = false; + if (submode == plpcdu::NORMAL_ADC_ONLY) { + setMode(MODE_NORMAL, submode); + return HasReturnvaluesIF::RETURN_OK; + } } } } } - if (submode == plpcdu::NORMAL_ALL_ON) { - if (state == States::ON_TRANS_ADC_CLOSE_ZERO) { - if (not commandExecuted and adcState == AdcStates::NORMAL) { - float waitTime = DFT_SSR_TO_DRO_WAIT_TIME; - params.getValue(PARAM_KEY_MAP[SSR_TO_DRO_WAIT_TIME], waitTime); - countdown.setTimeout(std::round(waitTime * 1000)); - countdown.resetTimer(); - commandExecuted = true; - // TODO: For now, skip ADC check - transitionOk = true; - } - // ADC values are ok, 5 seconds have elapsed - if (transitionOk and countdown.hasTimedOut()) { - state = States::ON_TRANS_DRO; - // Now start monitoring for negative voltages instead - monMode = MonitoringMode::NEGATIVE; - commandExecuted = false; - transitionOk = false; - } - } - if (state == States::ON_TRANS_DRO) { - if (not commandExecuted) { - float waitTime = DFT_DRO_TO_X8_WAIT_TIME; - params.getValue(PARAM_KEY_MAP[DRO_TO_X8_WAIT_TIME], waitTime); - countdown.setTimeout(std::round(waitTime * 1000)); - countdown.resetTimer(); + + if (submode == NormalSubmodes::DRO_ON) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "Enabling PL PCDU DRO module" << std::endl; + sif::info << "Enabling PL PCDU DRO module" << std::endl; #endif - // Switch on DRO and start monitoring for negative voltages - gpioIF->pullHigh(gpioIds::PLPCDU_ENB_DRO); - adcCountdown.setTimeout(100); - adcCountdown.resetTimer(); - commandExecuted = true; - } - // ADC values are ok, 5 seconds have elapsed - if (transitionOk and countdown.hasTimedOut()) { - state = States::ON_TRANS_X8; - commandExecuted = false; - transitionOk = false; - } - } - if (state == States::ON_TRANS_X8) { - if (not commandExecuted) { - float waitTime = DFT_X8_TO_TX_WAIT_TIME; - params.getValue(PARAM_KEY_MAP[X8_TO_TX_WAIT_TIME], waitTime); - countdown.setTimeout(std::round(waitTime * 1000)); - countdown.resetTimer(); + // Switch on DRO and start monitoring for negative voltages + gpioIF->pullHigh(gpioIds::PLPCDU_ENB_DRO); + adcCountdown.setTimeout(100); + adcCountdown.resetTimer(); + setMode(MODE_NORMAL, submode); + } + + if (submode == NormalSubmodes::X8_ON) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "Enabling PL PCDU X8 module" << std::endl; #endif - // Switch on X8 - gpioIF->pullHigh(gpioIds::PLPCDU_ENB_X8); - adcCountdown.setTimeout(100); - adcCountdown.resetTimer(); - commandExecuted = true; - } - // ADC values are ok, 5 seconds have elapsed - if (transitionOk and countdown.hasTimedOut()) { - state = States::ON_TRANS_TX; - commandExecuted = false; - transitionOk = false; - } - } - if (state == States::ON_TRANS_TX) { - if (not commandExecuted) { - float waitTime = DFT_TX_TO_MPA_WAIT_TIME; - params.getValue(PARAM_KEY_MAP[TX_TO_MPA_WAIT_TIME], waitTime); - countdown.setTimeout(std::round(waitTime * 1000)); - countdown.resetTimer(); + // Switch on DRO and start monitoring for negative voltages + gpioIF->pullHigh(gpioIds::PLPCDU_ENB_DRO); + adcCountdown.setTimeout(100); + adcCountdown.resetTimer(); + setMode(MODE_NORMAL, submode); + } + + if (submode == NormalSubmodes::TX_ON) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "Enabling PL PCDU TX module" << std::endl; #endif - // Switch on TX - gpioIF->pullHigh(gpioIds::PLPCDU_ENB_TX); - // Wait for 100 ms before checking ADC values - adcCountdown.setTimeout(100); - adcCountdown.resetTimer(); - commandExecuted = true; - } - // ADC values are ok, 5 seconds have elapsed - if (transitionOk and countdown.hasTimedOut()) { - state = States::ON_TRANS_MPA; - commandExecuted = false; - transitionOk = false; - } - } - if (state == States::ON_TRANS_MPA) { - if (not commandExecuted) { - float waitTime = DFT_MPA_TO_HPA_WAIT_TIME; - params.getValue(PARAM_KEY_MAP[MPA_TO_HPA_WAIT_TIME], waitTime); - countdown.setTimeout(std::round(waitTime * 1000)); - countdown.resetTimer(); + // Switch on DRO and start monitoring for negative voltages + gpioIF->pullHigh(gpioIds::PLPCDU_ENB_TX); + adcCountdown.setTimeout(100); + adcCountdown.resetTimer(); + setMode(MODE_NORMAL, submode); + } + + if (submode == NormalSubmodes::MPA_ON) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "Enabling PL PCDU MPA module" << std::endl; #endif - // Switch on MPA - gpioIF->pullHigh(gpioIds::PLPCDU_ENB_MPA); - // Wait for 100 ms before checking ADC values - adcCountdown.setTimeout(100); - adcCountdown.resetTimer(); - commandExecuted = true; - } - // ADC values are ok, 5 seconds have elapsed - if (transitionOk and countdown.hasTimedOut()) { - state = States::ON_TRANS_HPA; - commandExecuted = false; - transitionOk = false; - } - } - if (state == States::ON_TRANS_HPA) { - if (not commandExecuted) { - // Switch on HPA - gpioIF->pullHigh(gpioIds::PLPCDU_ENB_HPA); + // Switch on DRO and start monitoring for negative voltages + gpioIF->pullHigh(gpioIds::PLPCDU_ENB_MPA); + adcCountdown.setTimeout(100); + adcCountdown.resetTimer(); + setMode(MODE_NORMAL, submode); + } + + if (submode == NormalSubmodes::HPA_ON) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "Enabling PL PCDU HPA module" << std::endl; #endif - commandExecuted = true; - } - // ADC values are ok, 5 seconds have elapsed - if (transitionOk and countdown.hasTimedOut()) { - state = States::PL_PCDU_ON; - setMode(MODE_NORMAL, plpcdu::NORMAL_ALL_ON); - countdown.resetTimer(); - commandExecuted = false; - transitionOk = false; - } - } + // Switch on DRO and start monitoring for negative voltages + gpioIF->pullHigh(gpioIds::PLPCDU_ENB_HPA); + adcCountdown.setTimeout(100); + adcCountdown.resetTimer(); + setMode(MODE_NORMAL, submode); } -} - -void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { - if (mode == _MODE_TO_NORMAL) { - stateMachineToNormal(modeFrom, subModeFrom); - return; - } - DeviceHandlerBase::doTransition(modeFrom, subModeFrom); + return RETURN_OK; } ReturnValue_t PayloadPcduHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { @@ -613,7 +543,28 @@ bool PayloadPcduHandler::checkCurrent(float val, float upperBound, Event event) } ReturnValue_t PayloadPcduHandler::isModeCombinationValid(Mode_t mode, Submode_t submode) { - if (mode == MODE_NORMAL and submode <= 1) { + using namespace plpcdu; + if (mode == MODE_NORMAL) { + if (submode == NormalSubmodes::SOLID_STATE_RELAYS_ADC_ON and + this->submode != NormalSubmodes::ALL_OFF) { + return TRANS_NOT_ALLOWED; + } + if ((submode == NormalSubmodes::DRO_ON and + this->submode != NormalSubmodes::SOLID_STATE_RELAYS_ADC_ON)) { + return TRANS_NOT_ALLOWED; + } + if ((submode == NormalSubmodes::X8_ON and this->submode != NormalSubmodes::DRO_ON)) { + return TRANS_NOT_ALLOWED; + } + if ((submode == NormalSubmodes::TX_ON and this->submode != NormalSubmodes::X8_ON)) { + return TRANS_NOT_ALLOWED; + } + if ((submode == NormalSubmodes::MPA_ON and this->submode != NormalSubmodes::MPA_ON)) { + return TRANS_NOT_ALLOWED; + } + if ((submode == NormalSubmodes::HPA_ON and this->submode != NormalSubmodes::MPA_ON)) { + return TRANS_NOT_ALLOWED; + } return HasReturnvaluesIF::RETURN_OK; } return DeviceHandlerBase::isModeCombinationValid(mode, submode); diff --git a/mission/devices/PayloadPcduHandler.h b/mission/devices/PayloadPcduHandler.h index 62c6f728..18311ec8 100644 --- a/mission/devices/PayloadPcduHandler.h +++ b/mission/devices/PayloadPcduHandler.h @@ -166,7 +166,7 @@ class PayloadPcduHandler : public DeviceHandlerBase { void checkAdcValues(); void handleOutOfBoundsPrintout(); void checkJsonFileInit(); - void stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom); + ReturnValue_t stateMachineToNormal(Mode_t modeFrom, Submode_t subModeFrom); bool checkVoltage(float val, float lowerBound, float upperBound, Event event); bool checkCurrent(float val, float upperBound, Event event); void handleFailureInjection(std::string output, Event event); diff --git a/mission/devices/devicedefinitions/payloadPcduDefinitions.h b/mission/devices/devicedefinitions/payloadPcduDefinitions.h index b6ce949e..89523fad 100644 --- a/mission/devices/devicedefinitions/payloadPcduDefinitions.h +++ b/mission/devices/devicedefinitions/payloadPcduDefinitions.h @@ -94,6 +94,16 @@ static constexpr DeviceCommandId_t READ_WITH_TEMP_EXT = 3; static constexpr Submode_t NORMAL_ADC_ONLY = 0; static constexpr Submode_t NORMAL_ALL_ON = 1; +enum NormalSubmodes { + ALL_OFF = 0, + SOLID_STATE_RELAYS_ADC_ON = 1, + DRO_ON = 2, + X8_ON = 3, + TX_ON = 4, + MPA_ON = 5, + HPA_ON = 6 +}; + // 12 ADC values * 2 + trailing zero static constexpr size_t ADC_REPLY_SIZE = 25; // Conversion byte + 24 * zero diff --git a/tmtc b/tmtc index bca8d5d0..e3743042 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit bca8d5d05d25812b4e112ac0544b24915ec01971 +Subproject commit e37430423e814b9e05f25d63970f2c2b5048cfb1 From f2f350116f4b42ea725c684903a55927ae8e7a82 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 30 Mar 2022 12:09:17 +0200 Subject: [PATCH 10/20] tmtc update --- mission/devices/PayloadPcduHandler.cpp | 3 ++- tmtc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index c9574b83..60bf26a0 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -547,8 +547,9 @@ bool PayloadPcduHandler::checkCurrent(float val, float upperBound, Event event) ReturnValue_t PayloadPcduHandler::isModeCombinationValid(Mode_t mode, Submode_t submode) { using namespace plpcdu; if (mode == MODE_NORMAL) { + // Also deals with the case where the mode is MODE_ON, submode should be 0 here if (submode == NormalSubmodes::SOLID_STATE_RELAYS_ADC_ON and - this->submode != NormalSubmodes::ALL_OFF) { + (this->mode == MODE_NORMAL and this->submode != NormalSubmodes::ALL_OFF)) { return TRANS_NOT_ALLOWED; } if ((submode == NormalSubmodes::DRO_ON and diff --git a/tmtc b/tmtc index e3743042..b5a9dac8 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit e37430423e814b9e05f25d63970f2c2b5048cfb1 +Subproject commit b5a9dac8f6d3733779a67a72b14a20091069a346 From 2bb9cdc612a102210ccb259beccabb0d737676f5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 30 Mar 2022 12:18:45 +0200 Subject: [PATCH 11/20] submodule update --- fsfw | 2 +- tmtc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fsfw b/fsfw index b52f1925..7b6f68c5 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit b52f19254b8072a32203eaab91ea3c65b513ba7e +Subproject commit 7b6f68c509e9849473af77db5599f1a2b742c070 diff --git a/tmtc b/tmtc index 6db0a2cb..e13bb402 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 6db0a2cb791909a69506ed56df5518c277ece275 +Subproject commit e13bb402a2780142cc1b3b56c2873a4cbcf12a3b From dec5dc7c96c3d20f63b9e5a842fb0a60e7e86f1f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 30 Mar 2022 12:22:49 +0200 Subject: [PATCH 12/20] changes for FSFW power refactoring --- mission/devices/HeaterHandler.cpp | 7 +++++-- mission/devices/HeaterHandler.h | 4 ++-- mission/devices/PCDUHandler.cpp | 13 ++++++++----- mission/devices/PCDUHandler.h | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index 255ba6ec..ed62840b 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -134,7 +134,7 @@ ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t return result; } -void HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const { +ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) { ReturnValue_t result; store_address_t storeAddress; uint8_t commandData[2]; @@ -164,6 +164,7 @@ void HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) con << "message" << std::endl; } } + return result; } void HeaterHandler::handleActiveCommands() { @@ -338,7 +339,9 @@ gpioId_t HeaterHandler::getGpioIdFromSwitchNr(int switchNr) { MessageQueueId_t HeaterHandler::getCommandQueue() const { return commandQueue->getId(); } -void HeaterHandler::sendFuseOnCommand(uint8_t fuseNr) const {} +ReturnValue_t HeaterHandler::sendFuseOnCommand(uint8_t fuseNr) { + return RETURN_OK; +} ReturnValue_t HeaterHandler::getSwitchState(uint8_t switchNr) const { return 0; } diff --git a/mission/devices/HeaterHandler.h b/mission/devices/HeaterHandler.h index 2a8ce555..18b821ec 100644 --- a/mission/devices/HeaterHandler.h +++ b/mission/devices/HeaterHandler.h @@ -43,8 +43,8 @@ class HeaterHandler : public ExecutableObjectIF, virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; - virtual void sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const override; - virtual void sendFuseOnCommand(uint8_t fuseNr) const override; + virtual ReturnValue_t sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) override; + virtual ReturnValue_t sendFuseOnCommand(uint8_t fuseNr) override; /** * @brief This function will be called from the Heater object to check * the current switch state. diff --git a/mission/devices/PCDUHandler.cpp b/mission/devices/PCDUHandler.cpp index 2f91c140..fa8f3c91 100644 --- a/mission/devices/PCDUHandler.cpp +++ b/mission/devices/PCDUHandler.cpp @@ -205,7 +205,7 @@ void PCDUHandler::updatePdu1SwitchStates() { LocalDataPoolManager* PCDUHandler::getHkManagerHandle() { return &poolManager; } -void PCDUHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const { +ReturnValue_t PCDUHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) { using namespace pcduSwitches; ReturnValue_t result; uint16_t memoryAddress = 0; @@ -261,7 +261,7 @@ void PCDUHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const } // This is a dangerous command. Reject/Igore it for now case pcduSwitches::PDU2_CH0_Q7S: { - return; + return RETURN_FAILED; // memoryAddress = PDU2::CONFIG_ADDRESS_OUT_EN_Q7S; // pdu = ObjectManager::instance()->get(objects::PDU2_HANDLER); // break; @@ -309,7 +309,7 @@ void PCDUHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const default: { sif::error << "PCDUHandler::sendSwitchCommand: Invalid switch number " << std::endl; - return; + return RETURN_FAILED; } } @@ -322,7 +322,7 @@ void PCDUHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const break; default: sif::error << "PCDUHandler::sendSwitchCommand: Invalid state commanded" << std::endl; - return; + return RETURN_FAILED; } GomspaceSetParamMessage setParamMessage(memoryAddress, ¶meterValue, parameterValueSize); @@ -347,9 +347,12 @@ void PCDUHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const // Can't use trigger event because of const function constraint, but this hack seems to work this->forwardEvent(power::SWITCH_CMD_SENT, parameterValue, switchNr); } + return result; } -void PCDUHandler::sendFuseOnCommand(uint8_t fuseNr) const {} +ReturnValue_t PCDUHandler::sendFuseOnCommand(uint8_t fuseNr) { + return RETURN_OK; +} ReturnValue_t PCDUHandler::getSwitchState(uint8_t switchNr) const { if (switchNr >= pcduSwitches::NUMBER_OF_SWITCHES) { diff --git a/mission/devices/PCDUHandler.h b/mission/devices/PCDUHandler.h index 3d014205..c44052bb 100644 --- a/mission/devices/PCDUHandler.h +++ b/mission/devices/PCDUHandler.h @@ -33,8 +33,8 @@ class PCDUHandler : public PowerSwitchIF, store_address_t storeId = storeId::INVALID_STORE_ADDRESS, bool* clearMessage = nullptr) override; - virtual void sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const override; - virtual void sendFuseOnCommand(uint8_t fuseNr) const override; + virtual ReturnValue_t sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) override; + virtual ReturnValue_t sendFuseOnCommand(uint8_t fuseNr) override; virtual ReturnValue_t getSwitchState(uint8_t switchNr) const override; virtual ReturnValue_t getFuseState(uint8_t fuseNr) const override; virtual uint32_t getSwitchDelayMs(void) const override; From 2c8b691ca4d06eb2f6569ec7bdd6b7f2e3c83f61 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 30 Mar 2022 17:44:07 +0200 Subject: [PATCH 13/20] continued rpi sus port --- bsp_linux_board/CMakeLists.txt | 1 + bsp_linux_board/ObjectFactory.cpp | 11 ++++- bsp_linux_board/boardconfig/rpiConfig.h.in | 12 ----- bsp_linux_board/definitions.h | 30 ++++++++++++ bsp_linux_board/gpioInit.cpp | 56 ++++++++++++++++++++++ bsp_linux_board/gpioInit.h | 20 ++++++++ fsfw | 2 +- generators/fsfwgen | 2 +- linux/boardtest/SpiTestClass.h | 7 ++- mission/devices/HeaterHandler.cpp | 2 +- mission/devices/HeaterHandler.h | 4 +- tmtc | 2 +- 12 files changed, 128 insertions(+), 21 deletions(-) create mode 100644 bsp_linux_board/definitions.h create mode 100644 bsp_linux_board/gpioInit.cpp create mode 100644 bsp_linux_board/gpioInit.h diff --git a/bsp_linux_board/CMakeLists.txt b/bsp_linux_board/CMakeLists.txt index 0272f476..9884b983 100644 --- a/bsp_linux_board/CMakeLists.txt +++ b/bsp_linux_board/CMakeLists.txt @@ -1,6 +1,7 @@ target_sources(${OBSW_NAME} PUBLIC InitMission.cpp main.cpp + gpioInit.cpp ObjectFactory.cpp ) diff --git a/bsp_linux_board/ObjectFactory.cpp b/bsp_linux_board/ObjectFactory.cpp index f00c749a..259397e4 100644 --- a/bsp_linux_board/ObjectFactory.cpp +++ b/bsp_linux_board/ObjectFactory.cpp @@ -2,9 +2,11 @@ #include "OBSWConfig.h" #include "devConf.h" +#include "gpioInit.h" #include "devices/addresses.h" #include "devices/gpioIds.h" #include "fsfw/datapoollocal/LocalDataPoolManager.h" +#include "fsfw/power/DummyPowerSwitcher.h" #include "fsfw/tasks/TaskFactory.h" #include "fsfw/tmtcpacket/pus/tm.h" #include "fsfw/tmtcservices/CommandingServiceBase.h" @@ -67,14 +69,19 @@ void ObjectFactory::produce(void* args) { std::string spiDev = "/dev/spidev0.1"; SpiComIF* spiComIF = new SpiComIF(objects::SPI_COM_IF, gpioIF); static_cast(spiComIF); + auto pwrSwitcher = new DummyPowerSwitcher(objects::PCDU_HANDLER, 18, 0); -#if OBSW_ADD_ACS_BOARD == 1 +#if OBSW_ADD_ACS_BOARD == 1 && defined(RASPBERRY_PI) createRpiAcsBoard(gpioIF, spiDev); #endif #if OBSW_ADD_SUN_SENSORS == 1 - createSunSensorComponents(gpioIF, spiComIF, nullptr, spiDev); +#ifdef RASPBERRY_PI + rpi::gpio::initSpiCsDecoder(gpioIF); #endif + createSunSensorComponents(gpioIF, spiComIF, pwrSwitcher, spiDev); +#endif + #if OBSW_ADD_TEST_CODE == 1 createTestTasks(); diff --git a/bsp_linux_board/boardconfig/rpiConfig.h.in b/bsp_linux_board/boardconfig/rpiConfig.h.in index 7341fcca..b58a1037 100644 --- a/bsp_linux_board/boardconfig/rpiConfig.h.in +++ b/bsp_linux_board/boardconfig/rpiConfig.h.in @@ -17,16 +17,4 @@ #define RPI_ADD_UART_TEST 0 -/* Adapt these values accordingly */ -namespace gpio { -static constexpr uint8_t MGM_0_BCM_PIN = 17; -static constexpr uint8_t MGM_1_BCM_PIN = 27; -static constexpr uint8_t MGM_2_BCM_PIN = 22; -static constexpr uint8_t MGM_3_BCM_PIN = 23; -static constexpr uint8_t GYRO_0_BCM_PIN = 5; -static constexpr uint8_t GYRO_1_BCM_PIN = 6; -static constexpr uint8_t GYRO_2_BCM_PIN = 13; -static constexpr uint8_t GYRO_3_BCM_PIN = 19; -} - #endif /* BSP_RPI_BOARDCONFIG_RPI_CONFIG_H_ */ diff --git a/bsp_linux_board/definitions.h b/bsp_linux_board/definitions.h new file mode 100644 index 00000000..a47b0125 --- /dev/null +++ b/bsp_linux_board/definitions.h @@ -0,0 +1,30 @@ +#ifndef BSP_LINUX_BOARD_DEFINITIONS_H_ +#define BSP_LINUX_BOARD_DEFINITIONS_H_ + +#include "OBSWConfig.h" +#include + +#ifdef RASPBERRY_PI + +/* Adapt these values accordingly */ +namespace gpio { +static constexpr uint8_t MGM_0_BCM_PIN = 17; +static constexpr uint8_t MGM_1_BCM_PIN = 27; +static constexpr uint8_t MGM_2_BCM_PIN = 22; +static constexpr uint8_t MGM_3_BCM_PIN = 23; +static constexpr uint8_t GYRO_0_BCM_PIN = 5; +static constexpr uint8_t GYRO_1_BCM_PIN = 6; +static constexpr uint8_t GYRO_2_BCM_PIN = 13; +static constexpr uint8_t GYRO_3_BCM_PIN = 19; + +static constexpr uint8_t SPI_MUX_0_BCM = 17; +static constexpr uint8_t SPI_MUX_1_BCM = 27; +static constexpr uint8_t SPI_MUX_2_BCM = 22; +static constexpr uint8_t SPI_MUX_3_BCM = 23; +static constexpr uint8_t SPI_MUX_4_BCM = 5; +static constexpr uint8_t SPI_MUX_5_BCM = 6; +} + +#endif + +#endif /* BSP_LINUX_BOARD_DEFINITIONS_H_ */ diff --git a/bsp_linux_board/gpioInit.cpp b/bsp_linux_board/gpioInit.cpp new file mode 100644 index 00000000..8b6eab26 --- /dev/null +++ b/bsp_linux_board/gpioInit.cpp @@ -0,0 +1,56 @@ +#include "gpioInit.h" +#include "definitions.h" + +#include + +#include +#include +#include "fsfw_hal/linux/rpi/GpioRPi.h" +#include + +#ifdef RASPBERRY_PI + +struct MuxInfo { + MuxInfo(gpioId_t gpioId, int bcmNum, std::string consumer) + : gpioId(gpioId), bcmNum(bcmNum), consumer(consumer) {} + gpioId_t gpioId; + int bcmNum; + std::string consumer; +}; + +void rpi::gpio::initSpiCsDecoder(GpioIF* gpioComIF) { + using namespace ::gpio; + ReturnValue_t result; + + if (gpioComIF == nullptr) { + sif::debug << "initSpiCsDecoder: Invalid gpioComIF" << std::endl; + return; + } + + std::array<::MuxInfo, 6> muxInfo { + MuxInfo(gpioIds::SPI_MUX_BIT_0, SPI_MUX_0_BCM, "SPI_MUX_0"), + MuxInfo(gpioIds::SPI_MUX_BIT_1, SPI_MUX_1_BCM, "SPI_MUX_1"), + MuxInfo(gpioIds::SPI_MUX_BIT_2, SPI_MUX_2_BCM, "SPI_MUX_2"), + MuxInfo(gpioIds::SPI_MUX_BIT_3, SPI_MUX_3_BCM, "SPI_MUX_3"), + MuxInfo(gpioIds::SPI_MUX_BIT_4, SPI_MUX_4_BCM, "SPI_MUX_4"), + MuxInfo(gpioIds::SPI_MUX_BIT_5, SPI_MUX_5_BCM, "SPI_MUX_5"), + }; + GpioCookie* spiMuxGpios = new GpioCookie; + + for (const auto& info: muxInfo) { + result = createRpiGpioConfig(spiMuxGpios, info.gpioId, info.bcmNum, info.consumer, + Direction::OUT, Levels::LOW); + if(result != HasReturnvaluesIF::RETURN_OK) { + sif::error << "Creating Raspberry Pi SPI Mux GPIO failed with code " << result << std::endl; + return; + } + } + + result = gpioComIF->addGpios(spiMuxGpios); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::error << "initSpiCsDecoder: Failed to add mux bit gpios to gpioComIF" << std::endl; + return; + } +} + +#endif diff --git a/bsp_linux_board/gpioInit.h b/bsp_linux_board/gpioInit.h new file mode 100644 index 00000000..be7f2f99 --- /dev/null +++ b/bsp_linux_board/gpioInit.h @@ -0,0 +1,20 @@ +#pragma once + +#include "OBSWConfig.h" + +class GpioIF; + +#ifdef RASPBERRY_PI +namespace rpi { +namespace gpio { + +/** + * @brief This function initializes the GPIOs used to control the SN74LVC138APWR decoders on + * the TCS Board and the interface board. + */ +void initSpiCsDecoder(GpioIF* gpioComIF); + +} // namespace gpioCallbacks +} // namespace rpi + +#endif diff --git a/fsfw b/fsfw index 283a37dc..127fbeb9 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 283a37dccc064b71a0e4ca5c483c9a5a5241d355 +Subproject commit 127fbeb98020e091f9b5a385fd2a2ca47ccbc02f diff --git a/generators/fsfwgen b/generators/fsfwgen index a3ea5dd2..1c8be25e 160000 --- a/generators/fsfwgen +++ b/generators/fsfwgen @@ -1 +1 @@ -Subproject commit a3ea5dd2e7223c52e4f494e170850609b7b3a572 +Subproject commit 1c8be25e185aada13392a75234fa463240f424a0 diff --git a/linux/boardtest/SpiTestClass.h b/linux/boardtest/SpiTestClass.h index 15675f1a..dad42f4d 100644 --- a/linux/boardtest/SpiTestClass.h +++ b/linux/boardtest/SpiTestClass.h @@ -3,9 +3,14 @@ #include "OBSWConfig.h" -#if defined(XIPHOS_Q7S) +#ifdef XIPHOS_Q7S #include "busConf.h" #endif + +#ifdef RASPBERRY_PI +#include +#endif + #include #include #include diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index 255ba6ec..a1cfc058 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -134,7 +134,7 @@ ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t return result; } -void HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const { +ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) { ReturnValue_t result; store_address_t storeAddress; uint8_t commandData[2]; diff --git a/mission/devices/HeaterHandler.h b/mission/devices/HeaterHandler.h index 2a8ce555..18b821ec 100644 --- a/mission/devices/HeaterHandler.h +++ b/mission/devices/HeaterHandler.h @@ -43,8 +43,8 @@ class HeaterHandler : public ExecutableObjectIF, virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; - virtual void sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const override; - virtual void sendFuseOnCommand(uint8_t fuseNr) const override; + virtual ReturnValue_t sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) override; + virtual ReturnValue_t sendFuseOnCommand(uint8_t fuseNr) override; /** * @brief This function will be called from the Heater object to check * the current switch state. diff --git a/tmtc b/tmtc index e3743042..5c43f638 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit e37430423e814b9e05f25d63970f2c2b5048cfb1 +Subproject commit 5c43f638acb87e4ae07cea697cf8875c06431427 From 44bd42ded61381b19470ebcdcb1e5344edb045e6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 30 Mar 2022 17:47:49 +0200 Subject: [PATCH 14/20] added missing cast --- bsp_linux_board/ObjectFactory.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bsp_linux_board/ObjectFactory.cpp b/bsp_linux_board/ObjectFactory.cpp index 259397e4..496f7cd2 100644 --- a/bsp_linux_board/ObjectFactory.cpp +++ b/bsp_linux_board/ObjectFactory.cpp @@ -70,6 +70,7 @@ void ObjectFactory::produce(void* args) { SpiComIF* spiComIF = new SpiComIF(objects::SPI_COM_IF, gpioIF); static_cast(spiComIF); auto pwrSwitcher = new DummyPowerSwitcher(objects::PCDU_HANDLER, 18, 0); + static_cast(pwrSwitcher); #if OBSW_ADD_ACS_BOARD == 1 && defined(RASPBERRY_PI) createRpiAcsBoard(gpioIF, spiDev); From a4f99b3e787f6208ee9fe953cb5641400db26cb3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 30 Mar 2022 17:50:13 +0200 Subject: [PATCH 15/20] moved spi dev name to definitions file --- bsp_linux_board/ObjectFactory.cpp | 4 ++-- bsp_linux_board/definitions.h | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bsp_linux_board/ObjectFactory.cpp b/bsp_linux_board/ObjectFactory.cpp index 496f7cd2..b245fee7 100644 --- a/bsp_linux_board/ObjectFactory.cpp +++ b/bsp_linux_board/ObjectFactory.cpp @@ -66,7 +66,7 @@ void ObjectFactory::produce(void* args) { GpioIF* gpioIF = new LinuxLibgpioIF(objects::GPIO_IF); GpioCookie* gpioCookie = nullptr; static_cast(gpioCookie); - std::string spiDev = "/dev/spidev0.1"; + SpiComIF* spiComIF = new SpiComIF(objects::SPI_COM_IF, gpioIF); static_cast(spiComIF); auto pwrSwitcher = new DummyPowerSwitcher(objects::PCDU_HANDLER, 18, 0); @@ -80,7 +80,7 @@ void ObjectFactory::produce(void* args) { #ifdef RASPBERRY_PI rpi::gpio::initSpiCsDecoder(gpioIF); #endif - createSunSensorComponents(gpioIF, spiComIF, pwrSwitcher, spiDev); + createSunSensorComponents(gpioIF, spiComIF, pwrSwitcher, spi::DEV); #endif diff --git a/bsp_linux_board/definitions.h b/bsp_linux_board/definitions.h index a47b0125..d1d7fe19 100644 --- a/bsp_linux_board/definitions.h +++ b/bsp_linux_board/definitions.h @@ -6,6 +6,12 @@ #ifdef RASPBERRY_PI +namespace spi { + +static constexpr char DEV[] = "/dev/spidev0.1"; + +} + /* Adapt these values accordingly */ namespace gpio { static constexpr uint8_t MGM_0_BCM_PIN = 17; From 9958b37fba3e89362ebf4985cde5dd020ca6c945 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 30 Mar 2022 17:50:36 +0200 Subject: [PATCH 16/20] afmt --- bsp_linux_board/ObjectFactory.cpp | 3 +-- bsp_linux_board/definitions.h | 5 +++-- bsp_linux_board/gpioInit.cpp | 28 ++++++++++++++-------------- bsp_linux_board/gpioInit.h | 2 +- mission/devices/HeaterHandler.cpp | 4 +--- mission/devices/PCDUHandler.cpp | 4 +--- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/bsp_linux_board/ObjectFactory.cpp b/bsp_linux_board/ObjectFactory.cpp index b245fee7..09a1001a 100644 --- a/bsp_linux_board/ObjectFactory.cpp +++ b/bsp_linux_board/ObjectFactory.cpp @@ -2,7 +2,6 @@ #include "OBSWConfig.h" #include "devConf.h" -#include "gpioInit.h" #include "devices/addresses.h" #include "devices/gpioIds.h" #include "fsfw/datapoollocal/LocalDataPoolManager.h" @@ -11,6 +10,7 @@ #include "fsfw/tmtcpacket/pus/tm.h" #include "fsfw/tmtcservices/CommandingServiceBase.h" #include "fsfw/tmtcservices/PusServiceBase.h" +#include "gpioInit.h" #include "linux/ObjectFactory.h" #include "linux/boardtest/LibgpiodTest.h" #include "linux/boardtest/SpiTestClass.h" @@ -83,7 +83,6 @@ void ObjectFactory::produce(void* args) { createSunSensorComponents(gpioIF, spiComIF, pwrSwitcher, spi::DEV); #endif - #if OBSW_ADD_TEST_CODE == 1 createTestTasks(); #endif /* OBSW_ADD_TEST_CODE == 1 */ diff --git a/bsp_linux_board/definitions.h b/bsp_linux_board/definitions.h index d1d7fe19..1b6814f4 100644 --- a/bsp_linux_board/definitions.h +++ b/bsp_linux_board/definitions.h @@ -1,9 +1,10 @@ #ifndef BSP_LINUX_BOARD_DEFINITIONS_H_ #define BSP_LINUX_BOARD_DEFINITIONS_H_ -#include "OBSWConfig.h" #include +#include "OBSWConfig.h" + #ifdef RASPBERRY_PI namespace spi { @@ -29,7 +30,7 @@ static constexpr uint8_t SPI_MUX_2_BCM = 22; static constexpr uint8_t SPI_MUX_3_BCM = 23; static constexpr uint8_t SPI_MUX_4_BCM = 5; static constexpr uint8_t SPI_MUX_5_BCM = 6; -} +} // namespace gpio #endif diff --git a/bsp_linux_board/gpioInit.cpp b/bsp_linux_board/gpioInit.cpp index 8b6eab26..f913db8a 100644 --- a/bsp_linux_board/gpioInit.cpp +++ b/bsp_linux_board/gpioInit.cpp @@ -1,18 +1,18 @@ #include "gpioInit.h" -#include "definitions.h" #include - #include #include -#include "fsfw_hal/linux/rpi/GpioRPi.h" #include +#include "definitions.h" +#include "fsfw_hal/linux/rpi/GpioRPi.h" + #ifdef RASPBERRY_PI struct MuxInfo { MuxInfo(gpioId_t gpioId, int bcmNum, std::string consumer) - : gpioId(gpioId), bcmNum(bcmNum), consumer(consumer) {} + : gpioId(gpioId), bcmNum(bcmNum), consumer(consumer) {} gpioId_t gpioId; int bcmNum; std::string consumer; @@ -27,20 +27,20 @@ void rpi::gpio::initSpiCsDecoder(GpioIF* gpioComIF) { return; } - std::array<::MuxInfo, 6> muxInfo { - MuxInfo(gpioIds::SPI_MUX_BIT_0, SPI_MUX_0_BCM, "SPI_MUX_0"), - MuxInfo(gpioIds::SPI_MUX_BIT_1, SPI_MUX_1_BCM, "SPI_MUX_1"), - MuxInfo(gpioIds::SPI_MUX_BIT_2, SPI_MUX_2_BCM, "SPI_MUX_2"), - MuxInfo(gpioIds::SPI_MUX_BIT_3, SPI_MUX_3_BCM, "SPI_MUX_3"), - MuxInfo(gpioIds::SPI_MUX_BIT_4, SPI_MUX_4_BCM, "SPI_MUX_4"), - MuxInfo(gpioIds::SPI_MUX_BIT_5, SPI_MUX_5_BCM, "SPI_MUX_5"), + std::array<::MuxInfo, 6> muxInfo{ + MuxInfo(gpioIds::SPI_MUX_BIT_0, SPI_MUX_0_BCM, "SPI_MUX_0"), + MuxInfo(gpioIds::SPI_MUX_BIT_1, SPI_MUX_1_BCM, "SPI_MUX_1"), + MuxInfo(gpioIds::SPI_MUX_BIT_2, SPI_MUX_2_BCM, "SPI_MUX_2"), + MuxInfo(gpioIds::SPI_MUX_BIT_3, SPI_MUX_3_BCM, "SPI_MUX_3"), + MuxInfo(gpioIds::SPI_MUX_BIT_4, SPI_MUX_4_BCM, "SPI_MUX_4"), + MuxInfo(gpioIds::SPI_MUX_BIT_5, SPI_MUX_5_BCM, "SPI_MUX_5"), }; GpioCookie* spiMuxGpios = new GpioCookie; - for (const auto& info: muxInfo) { + for (const auto& info : muxInfo) { result = createRpiGpioConfig(spiMuxGpios, info.gpioId, info.bcmNum, info.consumer, - Direction::OUT, Levels::LOW); - if(result != HasReturnvaluesIF::RETURN_OK) { + Direction::OUT, Levels::LOW); + if (result != HasReturnvaluesIF::RETURN_OK) { sif::error << "Creating Raspberry Pi SPI Mux GPIO failed with code " << result << std::endl; return; } diff --git a/bsp_linux_board/gpioInit.h b/bsp_linux_board/gpioInit.h index be7f2f99..0ca66412 100644 --- a/bsp_linux_board/gpioInit.h +++ b/bsp_linux_board/gpioInit.h @@ -14,7 +14,7 @@ namespace gpio { */ void initSpiCsDecoder(GpioIF* gpioComIF); -} // namespace gpioCallbacks +} // namespace gpio } // namespace rpi #endif diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index ed62840b..5e78bc0e 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -339,9 +339,7 @@ gpioId_t HeaterHandler::getGpioIdFromSwitchNr(int switchNr) { MessageQueueId_t HeaterHandler::getCommandQueue() const { return commandQueue->getId(); } -ReturnValue_t HeaterHandler::sendFuseOnCommand(uint8_t fuseNr) { - return RETURN_OK; -} +ReturnValue_t HeaterHandler::sendFuseOnCommand(uint8_t fuseNr) { return RETURN_OK; } ReturnValue_t HeaterHandler::getSwitchState(uint8_t switchNr) const { return 0; } diff --git a/mission/devices/PCDUHandler.cpp b/mission/devices/PCDUHandler.cpp index fa8f3c91..837d4f37 100644 --- a/mission/devices/PCDUHandler.cpp +++ b/mission/devices/PCDUHandler.cpp @@ -350,9 +350,7 @@ ReturnValue_t PCDUHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onO return result; } -ReturnValue_t PCDUHandler::sendFuseOnCommand(uint8_t fuseNr) { - return RETURN_OK; -} +ReturnValue_t PCDUHandler::sendFuseOnCommand(uint8_t fuseNr) { return RETURN_OK; } ReturnValue_t PCDUHandler::getSwitchState(uint8_t switchNr) const { if (switchNr >= pcduSwitches::NUMBER_OF_SWITCHES) { From ac0e1aebbae9cd1feebb21c788a310cad4e132bc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 30 Mar 2022 23:01:38 +0200 Subject: [PATCH 17/20] minor bugfix, works now --- mission/devices/PayloadPcduHandler.cpp | 17 +++++++++-------- .../devicedefinitions/payloadPcduDefinitions.h | 3 --- mission/system/PlPcduAssembly.cpp | 1 - mission/system/PlPcduAssembly.h | 4 ---- 4 files changed, 9 insertions(+), 16 deletions(-) delete mode 100644 mission/system/PlPcduAssembly.cpp delete mode 100644 mission/system/PlPcduAssembly.h diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index 60bf26a0..36835051 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -74,6 +74,9 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ return HasReturnvaluesIF::RETURN_FAILED; } if (state == States::POWER_CHANNELS_ON) { +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "Switching on SSR VBAT0 & VBAT1 GPIOs" << std::endl; +#endif // Switch on relays here gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1); @@ -106,10 +109,8 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ adcCountdown.setTimeout(100); adcCountdown.resetTimer(); adcCmdExecuted = false; - if (submode == plpcdu::NORMAL_ADC_ONLY) { - setMode(MODE_NORMAL, submode); - return HasReturnvaluesIF::RETURN_OK; - } + setMode(MODE_NORMAL, submode); + return HasReturnvaluesIF::RETURN_OK; } } } @@ -128,7 +129,7 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ if (submode == NormalSubmodes::X8_ON) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "Enabling PL PCDU X8 module" << std::endl; + sif::info << "Enabling PL PCDU X8 module" << std::endl; #endif // Switch on DRO and start monitoring for negative voltages gpioIF->pullHigh(gpioIds::PLPCDU_ENB_DRO); @@ -139,7 +140,7 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ if (submode == NormalSubmodes::TX_ON) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "Enabling PL PCDU TX module" << std::endl; + sif::info << "Enabling PL PCDU TX module" << std::endl; #endif // Switch on DRO and start monitoring for negative voltages gpioIF->pullHigh(gpioIds::PLPCDU_ENB_TX); @@ -150,7 +151,7 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ if (submode == NormalSubmodes::MPA_ON) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "Enabling PL PCDU MPA module" << std::endl; + sif::info << "Enabling PL PCDU MPA module" << std::endl; #endif // Switch on DRO and start monitoring for negative voltages gpioIF->pullHigh(gpioIds::PLPCDU_ENB_MPA); @@ -161,7 +162,7 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ if (submode == NormalSubmodes::HPA_ON) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "Enabling PL PCDU HPA module" << std::endl; + sif::info << "Enabling PL PCDU HPA module" << std::endl; #endif // Switch on DRO and start monitoring for negative voltages gpioIF->pullHigh(gpioIds::PLPCDU_ENB_HPA); diff --git a/mission/devices/devicedefinitions/payloadPcduDefinitions.h b/mission/devices/devicedefinitions/payloadPcduDefinitions.h index 34a3847a..3013cb82 100644 --- a/mission/devices/devicedefinitions/payloadPcduDefinitions.h +++ b/mission/devices/devicedefinitions/payloadPcduDefinitions.h @@ -91,9 +91,6 @@ static constexpr DeviceCommandId_t SETUP_CMD = 1; static constexpr DeviceCommandId_t READ_TEMP_EXT = 2; static constexpr DeviceCommandId_t READ_WITH_TEMP_EXT = 3; -static constexpr Submode_t NORMAL_ADC_ONLY = 0; -static constexpr Submode_t NORMAL_ALL_ON = 1; - enum NormalSubmodes { ALL_OFF = 0, SOLID_STATE_RELAYS_ADC_ON = 1, diff --git a/mission/system/PlPcduAssembly.cpp b/mission/system/PlPcduAssembly.cpp deleted file mode 100644 index 88403be2..00000000 --- a/mission/system/PlPcduAssembly.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "PlPcduAssembly.h" diff --git a/mission/system/PlPcduAssembly.h b/mission/system/PlPcduAssembly.h deleted file mode 100644 index d74a6693..00000000 --- a/mission/system/PlPcduAssembly.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef MISSION_SYSTEM_PLPCDUASSEMBLY_H_ -#define MISSION_SYSTEM_PLPCDUASSEMBLY_H_ - -#endif /* MISSION_SYSTEM_PLPCDUASSEMBLY_H_ */ From 637941e089caae1abf5515753ab4b862e6bafe49 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 31 Mar 2022 14:40:42 +0200 Subject: [PATCH 18/20] important bugfixes --- linux/fsfwconfig/OBSWConfig.h.in | 6 +++--- mission/devices/PayloadPcduHandler.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/linux/fsfwconfig/OBSWConfig.h.in b/linux/fsfwconfig/OBSWConfig.h.in index 69e6744b..a3ef335c 100644 --- a/linux/fsfwconfig/OBSWConfig.h.in +++ b/linux/fsfwconfig/OBSWConfig.h.in @@ -50,7 +50,7 @@ debugging. */ #define OBSW_ADD_RTD_DEVICES 1 #define OBSW_ADD_TMP_DEVICES 0 #define OBSW_ADD_RAD_SENSORS 1 -#define OBSW_ADD_PL_PCDU 0 +#define OBSW_ADD_PL_PCDU 1 #define OBSW_ADD_SYRLINKS 0 #define OBSW_ENABLE_SYRLINKS_TRANSMIT_TIMEOUT 0 #define OBSW_STAR_TRACKER_GROUND_CONFIG 1 @@ -88,10 +88,10 @@ debugging. */ #define OBSW_ADD_PL_PCDU 0 #define OBSW_ADD_SYRLINKS 0 #define OBSW_ENABLE_SYRLINKS_TRANSMIT_TIMEOUT 0 -#define OBSW_SYRLINKS_SIMULATED 1 +#define OBSW_SYRLINKS_SIMULATED 1 #define OBSW_STAR_TRACKER_GROUND_CONFIG 1 #define OBSW_ENABLE_PERIODIC_HK 0 -#define OBSW_PRINT_CORE_HK 0 +#define OBSW_PRINT_CORE_HK 0 #define OBSW_INITIALIZE_SWITCHES 0 #endif diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index 36835051..7a1924c1 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -75,7 +75,7 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ } if (state == States::POWER_CHANNELS_ON) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "Switching on SSR VBAT0 & VBAT1 GPIOs" << std::endl; + sif::info << "Switching on SSR VBAT0 & VBAT1 GPIOs" << std::endl; #endif // Switch on relays here gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0); @@ -132,7 +132,7 @@ ReturnValue_t PayloadPcduHandler::stateMachineToNormal(Mode_t modeFrom, Submode_ sif::info << "Enabling PL PCDU X8 module" << std::endl; #endif // Switch on DRO and start monitoring for negative voltages - gpioIF->pullHigh(gpioIds::PLPCDU_ENB_DRO); + gpioIF->pullHigh(gpioIds::PLPCDU_ENB_X8); adcCountdown.setTimeout(100); adcCountdown.resetTimer(); setMode(MODE_NORMAL, submode); @@ -563,7 +563,7 @@ ReturnValue_t PayloadPcduHandler::isModeCombinationValid(Mode_t mode, Submode_t if ((submode == NormalSubmodes::TX_ON and this->submode != NormalSubmodes::X8_ON)) { return TRANS_NOT_ALLOWED; } - if ((submode == NormalSubmodes::MPA_ON and this->submode != NormalSubmodes::MPA_ON)) { + if ((submode == NormalSubmodes::MPA_ON and this->submode != NormalSubmodes::TX_ON)) { return TRANS_NOT_ALLOWED; } if ((submode == NormalSubmodes::HPA_ON and this->submode != NormalSubmodes::MPA_ON)) { From 33ec092998ed4b579ba6ab83869de3768a3a0dfe Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 31 Mar 2022 17:58:16 +0200 Subject: [PATCH 19/20] ported RTD code as well --- bsp_linux_board/InitMission.cpp | 2 +- bsp_linux_board/main.cpp | 2 +- bsp_q7s/core/ObjectFactory.cpp | 112 +---------------- bsp_q7s/core/ObjectFactory.h | 1 - linux/ObjectFactory.cpp | 114 ++++++++++++++++++ linux/ObjectFactory.h | 3 +- .../pollingSequenceFactory.cpp | 22 ++-- 7 files changed, 130 insertions(+), 126 deletions(-) diff --git a/bsp_linux_board/InitMission.cpp b/bsp_linux_board/InitMission.cpp index 6dfe3af1..0fa7a4f6 100644 --- a/bsp_linux_board/InitMission.cpp +++ b/bsp_linux_board/InitMission.cpp @@ -192,7 +192,7 @@ void initmission::createPstTasks(TaskFactory& factory, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; #if OBSW_ADD_SPI_TEST_CODE == 0 FixedTimeslotTaskIF* spiPst = factory.createFixedTimeslotTask( - "SPI_PST", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 3.0, missedDeadlineFunc); + "SPI_PST", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 1.0, missedDeadlineFunc); result = pst::pstSpi(spiPst); if (result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: Creating PST failed!" << std::endl; diff --git a/bsp_linux_board/main.cpp b/bsp_linux_board/main.cpp index 2f8ac4bc..98c4d79b 100644 --- a/bsp_linux_board/main.cpp +++ b/bsp_linux_board/main.cpp @@ -22,7 +22,7 @@ int main(void) { std::cout << "-- EIVE OBSW --" << std::endl; std::cout << "-- Compiled for Linux board " << BOARD_NAME << " --" << std::endl; std::cout << "-- OBSW " << SW_NAME << " v" << SW_VERSION << "." << SW_SUBVERSION << "." - << SW_REVISION << ", FSFW v" << fsfw::FSFW_VERSION << "--" << std::endl; + << SW_REVISION << ", FSFW v" << fsfw::FSFW_VERSION << " --" << std::endl; std::cout << "-- " << __DATE__ << " " << __TIME__ << " --" << std::endl; initmission::initMission(); diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index bbae65f2..125010f4 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -154,7 +154,7 @@ void ObjectFactory::produce(void* args) { #if OBSW_ADD_SYRLINKS == 1 createSyrlinksComponents(); #endif /* OBSW_ADD_SYRLINKS == 1 */ - createRtdComponents(gpioComIF, pwrSwitcher); + createRtdComponents(q7s::SPI_DEFAULT_DEV, gpioComIF, pwrSwitcher); createPayloadComponents(gpioComIF); #if OBSW_ADD_MGT == 1 @@ -646,116 +646,6 @@ void ObjectFactory::createSyrlinksComponents() { new SyrlinksHkHandler(objects::SYRLINKS_HK_HANDLER, objects::UART_COM_IF, syrlinksUartCookie); } -void ObjectFactory::createRtdComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF* pwrSwitcher) { - using namespace gpio; - GpioCookie* rtdGpioCookie = new GpioCookie; - - GpioCallback* gpioRtdIc0 = new GpioCallback("Chip select RTD IC0", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_3, gpioRtdIc0); - GpioCallback* gpioRtdIc1 = new GpioCallback("Chip select RTD IC1", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_4, gpioRtdIc1); - GpioCallback* gpioRtdIc2 = new GpioCallback("Chip select RTD IC2", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_5, gpioRtdIc2); - GpioCallback* gpioRtdIc3 = new GpioCallback("Chip select RTD IC3", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_6, gpioRtdIc3); - GpioCallback* gpioRtdIc4 = new GpioCallback("Chip select RTD IC4", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_7, gpioRtdIc4); - GpioCallback* gpioRtdIc5 = new GpioCallback("Chip select RTD IC5", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_8, gpioRtdIc5); - GpioCallback* gpioRtdIc6 = new GpioCallback("Chip select RTD IC6", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_9, gpioRtdIc6); - GpioCallback* gpioRtdIc7 = new GpioCallback("Chip select RTD IC7", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_10, gpioRtdIc7); - GpioCallback* gpioRtdIc8 = new GpioCallback("Chip select RTD IC8", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_11, gpioRtdIc8); - GpioCallback* gpioRtdIc9 = new GpioCallback("Chip select RTD IC9", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_12, gpioRtdIc9); - GpioCallback* gpioRtdIc10 = new GpioCallback("Chip select RTD IC10", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_13, gpioRtdIc10); - GpioCallback* gpioRtdIc11 = new GpioCallback("Chip select RTD IC11", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_14, gpioRtdIc11); - GpioCallback* gpioRtdIc12 = new GpioCallback("Chip select RTD IC12", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_15, gpioRtdIc12); - GpioCallback* gpioRtdIc13 = new GpioCallback("Chip select RTD IC13", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_16, gpioRtdIc13); - GpioCallback* gpioRtdIc14 = new GpioCallback("Chip select RTD IC14", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_17, gpioRtdIc14); - GpioCallback* gpioRtdIc15 = new GpioCallback("Chip select RTD IC15", Direction::OUT, Levels::HIGH, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - rtdGpioCookie->addGpio(gpioIds::RTD_IC_18, gpioRtdIc15); - - gpioComIF->addGpios(rtdGpioCookie); - - static constexpr uint8_t NUMBER_RTDS = 16; -#if OBSW_ADD_RTD_DEVICES == 1 - std::array, NUMBER_RTDS> cookieArgs = {{ - {addresses::RTD_IC_3, gpioIds::RTD_IC_3}, - {addresses::RTD_IC_4, gpioIds::RTD_IC_4}, - {addresses::RTD_IC_5, gpioIds::RTD_IC_5}, - {addresses::RTD_IC_6, gpioIds::RTD_IC_6}, - {addresses::RTD_IC_7, gpioIds::RTD_IC_7}, - {addresses::RTD_IC_8, gpioIds::RTD_IC_8}, - {addresses::RTD_IC_9, gpioIds::RTD_IC_9}, - {addresses::RTD_IC_10, gpioIds::RTD_IC_10}, - {addresses::RTD_IC_11, gpioIds::RTD_IC_11}, - {addresses::RTD_IC_12, gpioIds::RTD_IC_12}, - {addresses::RTD_IC_13, gpioIds::RTD_IC_13}, - {addresses::RTD_IC_14, gpioIds::RTD_IC_14}, - {addresses::RTD_IC_15, gpioIds::RTD_IC_15}, - {addresses::RTD_IC_16, gpioIds::RTD_IC_16}, - {addresses::RTD_IC_17, gpioIds::RTD_IC_17}, - {addresses::RTD_IC_18, gpioIds::RTD_IC_18}, - }}; - std::array rtdIds = { - objects::RTD_IC_3, objects::RTD_IC_4, objects::RTD_IC_5, objects::RTD_IC_6, - objects::RTD_IC_7, objects::RTD_IC_8, objects::RTD_IC_9, objects::RTD_IC_10, - objects::RTD_IC_11, objects::RTD_IC_12, objects::RTD_IC_13, objects::RTD_IC_14, - objects::RTD_IC_15, objects::RTD_IC_16, objects::RTD_IC_17, objects::RTD_IC_18}; - std::array rtdCookies = {}; - std::array rtds = {}; - RtdFdir* rtdFdir = nullptr; - for (uint8_t idx = 0; idx < NUMBER_RTDS; idx++) { - rtdCookies[idx] = - new SpiCookie(cookieArgs[idx].first, cookieArgs[idx].second, q7s::SPI_DEFAULT_DEV, - Max31865Definitions::MAX_REPLY_SIZE, spi::RTD_MODE, spi::RTD_SPEED); - rtds[idx] = new Max31865PT1000Handler(rtdIds[idx], objects::SPI_COM_IF, rtdCookies[idx]); - rtds[idx]->setParent(objects::TCS_BOARD_ASS); - rtdFdir = new RtdFdir(rtdIds[idx]); - rtds[idx]->setCustomFdir(rtdFdir); - rtds[idx]->setDeviceIdx(idx + 3); - } - -#if OBSW_TEST_RTD == 1 - for (auto& rtd : rtds) { - if (rtd != nullptr) { - rtd->setStartUpImmediately(); - rtd->setInstantNormal(true); - } - } -#endif // OBSW_TEST_RTD == 1 - TcsBoardHelper helper(rtdIds); - TcsBoardAssembly* tcsBoardAss = - new TcsBoardAssembly(objects::TCS_BOARD_ASS, objects::NO_OBJECT, pwrSwitcher, - pcduSwitches::Switches::PDU1_CH0_TCS_BOARD_3V3, helper); - static_cast(tcsBoardAss); -#endif // OBSW_ADD_RTD_DEVICES == 1 -} - void ObjectFactory::createPayloadComponents(LinuxLibgpioIF* gpioComIF) { using namespace gpio; std::stringstream consumer; diff --git a/bsp_q7s/core/ObjectFactory.h b/bsp_q7s/core/ObjectFactory.h index 049b59a2..9bb2043c 100644 --- a/bsp_q7s/core/ObjectFactory.h +++ b/bsp_q7s/core/ObjectFactory.h @@ -24,7 +24,6 @@ void createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, UartComIF* uartComIF, void createHeaterComponents(); void createSolarArrayDeploymentComponents(); void createSyrlinksComponents(); -void createRtdComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF* pwrSwitcher); void createPayloadComponents(LinuxLibgpioIF* gpioComIF); void createReactionWheelComponents(LinuxLibgpioIF* gpioComIF); void createCcsdsComponents(LinuxLibgpioIF* gpioComIF); diff --git a/linux/ObjectFactory.cpp b/linux/ObjectFactory.cpp index 102ef5d9..267b5f4d 100644 --- a/linux/ObjectFactory.cpp +++ b/linux/ObjectFactory.cpp @@ -7,9 +7,12 @@ #include #include #include +#include #include +#include #include #include +#include #include "OBSWConfig.h" #include "devConf.h" @@ -170,3 +173,114 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo static_cast(susAss); #endif /* OBSW_ADD_SUN_SENSORS == 1 */ } + +void ObjectFactory::createRtdComponents(std::string spiDev, GpioIF* gpioComIF, + PowerSwitchIF* pwrSwitcher) { + using namespace gpio; + GpioCookie* rtdGpioCookie = new GpioCookie; + + GpioCallback* gpioRtdIc0 = new GpioCallback("Chip select RTD IC0", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_3, gpioRtdIc0); + GpioCallback* gpioRtdIc1 = new GpioCallback("Chip select RTD IC1", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_4, gpioRtdIc1); + GpioCallback* gpioRtdIc2 = new GpioCallback("Chip select RTD IC2", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_5, gpioRtdIc2); + GpioCallback* gpioRtdIc3 = new GpioCallback("Chip select RTD IC3", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_6, gpioRtdIc3); + GpioCallback* gpioRtdIc4 = new GpioCallback("Chip select RTD IC4", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_7, gpioRtdIc4); + GpioCallback* gpioRtdIc5 = new GpioCallback("Chip select RTD IC5", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_8, gpioRtdIc5); + GpioCallback* gpioRtdIc6 = new GpioCallback("Chip select RTD IC6", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_9, gpioRtdIc6); + GpioCallback* gpioRtdIc7 = new GpioCallback("Chip select RTD IC7", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_10, gpioRtdIc7); + GpioCallback* gpioRtdIc8 = new GpioCallback("Chip select RTD IC8", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_11, gpioRtdIc8); + GpioCallback* gpioRtdIc9 = new GpioCallback("Chip select RTD IC9", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_12, gpioRtdIc9); + GpioCallback* gpioRtdIc10 = new GpioCallback("Chip select RTD IC10", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_13, gpioRtdIc10); + GpioCallback* gpioRtdIc11 = new GpioCallback("Chip select RTD IC11", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_14, gpioRtdIc11); + GpioCallback* gpioRtdIc12 = new GpioCallback("Chip select RTD IC12", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_15, gpioRtdIc12); + GpioCallback* gpioRtdIc13 = new GpioCallback("Chip select RTD IC13", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_16, gpioRtdIc13); + GpioCallback* gpioRtdIc14 = new GpioCallback("Chip select RTD IC14", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_17, gpioRtdIc14); + GpioCallback* gpioRtdIc15 = new GpioCallback("Chip select RTD IC15", Direction::OUT, Levels::HIGH, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC_18, gpioRtdIc15); + + gpioComIF->addGpios(rtdGpioCookie); + +#if OBSW_ADD_RTD_DEVICES == 1 + static constexpr uint8_t NUMBER_RTDS = 16; + std::array, NUMBER_RTDS> cookieArgs = {{ + {addresses::RTD_IC_3, gpioIds::RTD_IC_3}, + {addresses::RTD_IC_4, gpioIds::RTD_IC_4}, + {addresses::RTD_IC_5, gpioIds::RTD_IC_5}, + {addresses::RTD_IC_6, gpioIds::RTD_IC_6}, + {addresses::RTD_IC_7, gpioIds::RTD_IC_7}, + {addresses::RTD_IC_8, gpioIds::RTD_IC_8}, + {addresses::RTD_IC_9, gpioIds::RTD_IC_9}, + {addresses::RTD_IC_10, gpioIds::RTD_IC_10}, + {addresses::RTD_IC_11, gpioIds::RTD_IC_11}, + {addresses::RTD_IC_12, gpioIds::RTD_IC_12}, + {addresses::RTD_IC_13, gpioIds::RTD_IC_13}, + {addresses::RTD_IC_14, gpioIds::RTD_IC_14}, + {addresses::RTD_IC_15, gpioIds::RTD_IC_15}, + {addresses::RTD_IC_16, gpioIds::RTD_IC_16}, + {addresses::RTD_IC_17, gpioIds::RTD_IC_17}, + {addresses::RTD_IC_18, gpioIds::RTD_IC_18}, + }}; + std::array rtdIds = { + objects::RTD_IC_3, objects::RTD_IC_4, objects::RTD_IC_5, objects::RTD_IC_6, + objects::RTD_IC_7, objects::RTD_IC_8, objects::RTD_IC_9, objects::RTD_IC_10, + objects::RTD_IC_11, objects::RTD_IC_12, objects::RTD_IC_13, objects::RTD_IC_14, + objects::RTD_IC_15, objects::RTD_IC_16, objects::RTD_IC_17, objects::RTD_IC_18}; + std::array rtdCookies = {}; + std::array rtds = {}; + RtdFdir* rtdFdir = nullptr; + for (uint8_t idx = 0; idx < NUMBER_RTDS; idx++) { + 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]->setParent(objects::TCS_BOARD_ASS); + rtdFdir = new RtdFdir(rtdIds[idx]); + rtds[idx]->setCustomFdir(rtdFdir); + rtds[idx]->setDeviceIdx(idx + 3); + } + +#if OBSW_TEST_RTD == 1 + for (auto& rtd : rtds) { + if (rtd != nullptr) { + rtd->setStartUpImmediately(); + rtd->setInstantNormal(true); + } + } +#endif // OBSW_TEST_RTD == 1 + TcsBoardHelper helper(rtdIds); + TcsBoardAssembly* tcsBoardAss = + new TcsBoardAssembly(objects::TCS_BOARD_ASS, objects::NO_OBJECT, pwrSwitcher, + pcduSwitches::Switches::PDU1_CH0_TCS_BOARD_3V3, helper); + static_cast(tcsBoardAss); +#endif // OBSW_ADD_RTD_DEVICES == 1 +} diff --git a/linux/ObjectFactory.h b/linux/ObjectFactory.h index 7a6e964a..d918115f 100644 --- a/linux/ObjectFactory.h +++ b/linux/ObjectFactory.h @@ -10,5 +10,6 @@ namespace ObjectFactory { void createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiComIF, PowerSwitchIF* pwrSwitcher, std::string spiDev); +void createRtdComponents(std::string spiDev, GpioIF* gpioComIF, PowerSwitchIF* pwrSwitcher); -} +} // namespace ObjectFactory diff --git a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index fdd4897e..652fb3bc 100644 --- a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -165,17 +165,17 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { #if OBSW_ADD_SUN_SENSORS == 1 - bool addSus0 = true; - bool addSus1 = true; - bool addSus2 = true; - bool addSus3 = true; - bool addSus4 = true; - bool addSus5 = true; - bool addSus6 = true; - bool addSus7 = true; - bool addSus8 = true; - bool addSus9 = true; - bool addSus10 = true; + bool addSus0 = false; + bool addSus1 = false; + bool addSus2 = false; + bool addSus3 = false; + bool addSus4 = false; + bool addSus5 = false; + bool addSus6 = false; + bool addSus7 = false; + bool addSus8 = false; + bool addSus9 = false; + bool addSus10 = false; bool addSus11 = true; /** * The sun sensor will be shutdown as soon as the chip select is pulled high. Thus all From 487c21f16a373e4b4e4beb5f8a8f653c7d91cb76 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 31 Mar 2022 18:04:55 +0200 Subject: [PATCH 20/20] fixes --- bsp_linux_board/ObjectFactory.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bsp_linux_board/ObjectFactory.cpp b/bsp_linux_board/ObjectFactory.cpp index 09a1001a..b1ae6005 100644 --- a/bsp_linux_board/ObjectFactory.cpp +++ b/bsp_linux_board/ObjectFactory.cpp @@ -76,13 +76,20 @@ void ObjectFactory::produce(void* args) { createRpiAcsBoard(gpioIF, spiDev); #endif -#if OBSW_ADD_SUN_SENSORS == 1 +#if OBSW_ADD_SUN_SENSORS == 1 || defined(OBSW_ADD_RTD_DEVICES) #ifdef RASPBERRY_PI rpi::gpio::initSpiCsDecoder(gpioIF); #endif +#endif + +#if OBSW_ADD_SUN_SENSORS == 1 createSunSensorComponents(gpioIF, spiComIF, pwrSwitcher, spi::DEV); #endif +#if OBSW_ADD_RTD_DEVICES == 1 + createRtdComponents(spi::DEV, gpioIF, pwrSwitcher); +#endif + #if OBSW_ADD_TEST_CODE == 1 createTestTasks(); #endif /* OBSW_ADD_TEST_CODE == 1 */