From 758c4e6f4fc3cac30c425212b5841b451e67797c Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 28 Mar 2022 09:08:11 +0200 Subject: [PATCH] uart isolator switch handling --- CMakeLists.txt | 4 +- bsp_q7s/boardconfig/busConf.h | 3 + bsp_q7s/core/ObjectFactory.cpp | 61 +++++++++++++------- bsp_q7s/core/ObjectFactory.h | 1 + bsp_te0720_1cfa/ObjectFactory.cpp | 8 ++- common/config/devices/gpioIds.h | 6 +- linux/devices/ploc/PlocMPSoCHandler.cpp | 10 +--- linux/devices/ploc/PlocMPSoCHandler.h | 8 +-- linux/devices/ploc/PlocSupervisorHandler.cpp | 11 ++-- linux/devices/ploc/PlocSupervisorHandler.h | 7 ++- test/CMakeLists.txt | 1 + 11 files changed, 75 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62a98c3d..585284ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,7 @@ set(LIB_JSON_NAME nlohmann_json::nlohmann_json) # Set path names set(FSFW_PATH fsfw) -set(TEST_PATH test/testtasks) +set(TEST_PATH test) set(UNITTEST_PATH unittest) set(LINUX_PATH linux) set(COMMON_PATH common) @@ -210,7 +210,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") set(COMPILER_FLAGS "/permissive-") endif() -if (NOT(TGT_BSP MATCHES "arm/te0720-1cfa")) +if (NOT(TGT_BSP MATCHES "arm/te0720-1cfa") AND NOT(TGT_BSP MATCHES "arm/q7s")) # Not installed, so use FetchContent to download and provide Catch2 if(NOT Catch2_FOUND) message(STATUS "Did not find a valid Catch2 installation. Using FetchContent to install it") diff --git a/bsp_q7s/boardconfig/busConf.h b/bsp_q7s/boardconfig/busConf.h index eba4fb36..5c52693c 100644 --- a/bsp_q7s/boardconfig/busConf.h +++ b/bsp_q7s/boardconfig/busConf.h @@ -94,6 +94,9 @@ static constexpr char PL_PCDU_ENABLE_HPA[] = "enable_plpcdu_hpa"; static constexpr char PL_PCDU_ENABLE_MPA[] = "enable_plpcdu_mpa"; static constexpr char PL_PCDU_ADC_CS[] = "plpcdu_adc_chip_select"; +static constexpr char ENABLE_SUPV_UART[] = "enable_supv_uart"; +static constexpr char ENABLE_MPSOC_UART[] = "enable_mpsoc_uart"; + } // namespace gpioNames } // namespace q7s diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 38244dad..9bff8c2d 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -153,6 +153,7 @@ void ObjectFactory::produce(void* args) { createSyrlinksComponents(); #endif /* OBSW_ADD_SYRLINKS == 1 */ createRtdComponents(gpioComIF, pwrSwitcher); + createPayloadComponents(gpioComIF); #if OBSW_ADD_MGT == 1 I2cCookie* imtqI2cCookie = @@ -180,27 +181,6 @@ void ObjectFactory::produce(void* args) { #endif #endif -#if OBSW_ADD_PLOC_MPSOC == 1 - UartCookie* plocMpsocCookie = - new UartCookie(objects::PLOC_MPSOC_HANDLER, q7s::UART_PLOC_MPSOC_DEV, - UartModes::NON_CANONICAL, uart::PLOC_MPSOC_BAUD, mpsoc::MAX_REPLY_SIZE); - PlocMPSoCHelper* plocMpsocHelper = new PlocMPSoCHelper(objects::PLOC_MPSOC_HELPER); - PlocMPSoCHandler* plocMPSoCHandler = - new PlocMPSoCHandler(objects::PLOC_MPSOC_HANDLER, objects::UART_COM_IF, plocMpsocCookie, - plocMpsocHelper, gpioComIF); - plocMPSoCHandler->setStartUpImmediately(); -#endif /* OBSW_ADD_PLOC_MPSOC == 1 */ - -#if OBSW_ADD_PLOC_SUPERVISOR == 1 - UartCookie* plocSupervisorCookie = new UartCookie( - objects::PLOC_SUPERVISOR_HANDLER, q7s::UART_PLOC_SUPERVSIOR_DEV, UartModes::NON_CANONICAL, - uart::PLOC_SUPERVISOR_BAUD, PLOC_SPV::MAX_PACKET_SIZE * 20); - plocSupervisorCookie->setNoFixedSizeReply(); - PlocSupervisorHandler* plocSupervisor = new PlocSupervisorHandler( - objects::PLOC_SUPERVISOR_HANDLER, objects::UART_COM_IF, plocSupervisorCookie); - plocSupervisor->setStartUpImmediately(); -#endif /* OBSW_ADD_PLOC_SUPERVISOR == 1 */ - new FileSystemHandler(objects::FILE_SYSTEM_HANDLER); #if OBSW_ADD_STAR_TRACKER == 1 @@ -929,6 +909,45 @@ void ObjectFactory::createRtdComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF #endif // OBSW_ADD_RTD_DEVICES == 1 } +void ObjectFactory::createPayloadComponents(LinuxLibgpioIF* gpioComIF) { + auto gpioCookie = new GpioCookie; + std::stringstream consumer; +#if OBSW_ADD_PLOC_MPSOC == 1 + consumer << "0x" << std::hex << objects::PLOC_MPSOC_HANDLER; + auto gpioConfig = new GpiodRegularByLineName(q7s::gpioNames::ENABLE_MPSOC_UART, consumer.str(), + Direction::OUT, Levels::HIGH); + gpioCookie->addGpio(gpioIds::ENABLE_MPSOC_UART, gpioConfig); + gpioComIF->addGpios(gpioCookie); + auto mpsocCookie = + new UartCookie(objects::PLOC_MPSOC_HANDLER, q7s::UART_PLOC_MPSOC_DEV, + UartModes::NON_CANONICAL, uart::PLOC_MPSOC_BAUD, mpsoc::MAX_REPLY_SIZE); + mpsocCookie->setNoFixedSizeReply(); + auto plocMpsocHelper = new PlocMPSoCHelper(objects::PLOC_MPSOC_HELPER); + auto plocMPSoC = + new PlocMPSoCHandler(objects::PLOC_MPSOC_HANDLER, objects::UART_COM_IF, plocMpsocCookie, + plocMpsocHelper, Gpio(gpioIds::ENABLE_MPSOC_UART, gpioComIF)); + plocMPSoC->setStartUpImmediately(); +#endif /* OBSW_ADD_PLOC_MPSOC == 1 */ + +#if OBSW_ADD_PLOC_SUPERVISOR == 1 + consumer << "0x" << std::hex << objects::PLOC_SUPERVISOR_HANDLER; + auto gpioConfig = new GpiodRegularByLineName(q7s::gpioNames::ENABLE_SUPV_UART, consumer.str(), + Direction::OUT, Levels::HIGH); + gpioCookie->addGpio(gpioIds::ENABLE_SUPV_UART, gpioConfig); + gpioComIF->addGpios(gpioCookie); + auto supervisorCookie = new UartCookie( + objects::PLOC_SUPERVISOR_HANDLER, q7s::UART_PLOC_SUPERVSIOR_DEV, UartModes::NON_CANONICAL, + uart::PLOC_SUPERVISOR_BAUD, PLOC_SPV::MAX_PACKET_SIZE * 20); + supervisorCookie->setNoFixedSizeReply(); + PlocSupervisorHandler* plocSupervisor = + new PlocSupervisorHandler(objects::PLOC_SUPERVISOR_HANDLER, objects::UART_COM_IF, + supervisorCookie, Gpio(gpioIds::ENABLE_MPSOC_UART, gpioComIF)); + plocSupervisor->setStartUpImmediately(); +#endif /* OBSW_ADD_PLOC_SUPERVISOR == 1 */ + static_cast(gpioCookie); + static_cast(consumer); +} + void ObjectFactory::createReactionWheelComponents(LinuxLibgpioIF* gpioComIF) { using namespace gpio; GpioCookie* gpioCookieRw = new GpioCookie; diff --git a/bsp_q7s/core/ObjectFactory.h b/bsp_q7s/core/ObjectFactory.h index ff88db8e..958e8f86 100644 --- a/bsp_q7s/core/ObjectFactory.h +++ b/bsp_q7s/core/ObjectFactory.h @@ -26,6 +26,7 @@ void createHeaterComponents(); void createSolarArrayDeploymentComponents(); void createSyrlinksComponents(); void createRtdComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF* pwrSwitcher); +void createPayloadComponents(LinuxLibgpioIF* gpioComIF); void createReactionWheelComponents(LinuxLibgpioIF* gpioComIF); void createCcsdsComponents(LinuxLibgpioIF* gpioComIF); void createTestComponents(LinuxLibgpioIF* gpioComIF); diff --git a/bsp_te0720_1cfa/ObjectFactory.cpp b/bsp_te0720_1cfa/ObjectFactory.cpp index b23a5e98..757cf31c 100644 --- a/bsp_te0720_1cfa/ObjectFactory.cpp +++ b/bsp_te0720_1cfa/ObjectFactory.cpp @@ -18,8 +18,10 @@ #include "mission/devices/Tmp1075Handler.h" #include "mission/core/GenericFactory.h" #include "mission/utility/TmFunnel.h" +#include "test/gpio/DummyGpioIF.h" #include "objects/systemObjectList.h" #include "devices/addresses.h" +#include "devices/gpioIds.h" #include "tmtc/apid.h" #include "tmtc/pusIds.h" @@ -48,8 +50,10 @@ void ObjectFactory::produce(void* args) { mpsocUartCookie->setNoFixedSizeReply(); PlocMPSoCHelper* plocMpsocHelper = new PlocMPSoCHelper(objects::PLOC_MPSOC_HELPER); new UartComIF(objects::UART_COM_IF); - PlocMPSoCHandler* plocMPSoCHandler = new PlocMPSoCHandler( - objects::PLOC_MPSOC_HANDLER, objects::UART_COM_IF, mpsocUartCookie, plocMpsocHelper); + auto dummyGpioIF = new DummyGpioIF(); + PlocMPSoCHandler* plocMPSoCHandler = + new PlocMPSoCHandler(objects::PLOC_MPSOC_HANDLER, objects::UART_COM_IF, mpsocUartCookie, + plocMpsocHelper, Gpio(gpioIds::ENABLE_MPSOC_UART, dummyGpioIF)); plocMPSoCHandler->setStartUpImmediately(); #endif /* OBSW_ADD_PLOC_MPSOC == 1 */ diff --git a/common/config/devices/gpioIds.h b/common/config/devices/gpioIds.h index e6f42eb4..199439cc 100644 --- a/common/config/devices/gpioIds.h +++ b/common/config/devices/gpioIds.h @@ -119,7 +119,11 @@ enum gpioId_t { PLPCDU_ENB_TX, PLPCDU_ENB_HPA, PLPCDU_ENB_MPA, - PLPCDU_ADC_CS + PLPCDU_ADC_CS, + + ENABLE_MPSOC_UART, + ENABLE_SUPV_UART + }; } diff --git a/linux/devices/ploc/PlocMPSoCHandler.cpp b/linux/devices/ploc/PlocMPSoCHandler.cpp index c2229c53..acdfbbca 100644 --- a/linux/devices/ploc/PlocMPSoCHandler.cpp +++ b/linux/devices/ploc/PlocMPSoCHandler.cpp @@ -6,17 +6,13 @@ PlocMPSoCHandler::PlocMPSoCHandler(object_id_t objectId, object_id_t uartComIFid, CookieIF* comCookie, PlocMPSoCHelper* plocMPSoCHelper, - LinuxLibgpioIF* gpioComIF, gpioId_t uartIsolatorSwitch) + Gpio uartIsolatorSwitch) : DeviceHandlerBase(objectId, uartComIFid, comCookie), plocMPSoCHelper(plocMPSoCHelper), - gpioComIF(gpioComIF), uartIsolatorSwitch(uartIsolatorSwitch) { if (comCookie == nullptr) { sif::error << "PlocMPSoCHandler: Invalid communication cookie" << std::endl; } - if (gpioComIF == nullptr) { - sif::error << "PlocMPSoCHandler: Invalid gpio communication interface" << std::endl; - } eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5); } @@ -125,11 +121,11 @@ void PlocMPSoCHandler::doStartUp() { #else setMode(_MODE_TO_ON); #endif - gpioComIF->pullHigh(uartIsolatorSwitch); + uartIsolatorSwitch.pullHigh(); } void PlocMPSoCHandler::doShutDown() { - gpioComIF->pullLow(uartIsolatorSwitch); + uartIsolatorSwitch.pullLow(); setMode(_MODE_POWER_DOWN); } diff --git a/linux/devices/ploc/PlocMPSoCHandler.h b/linux/devices/ploc/PlocMPSoCHandler.h index d923cc96..135583f0 100644 --- a/linux/devices/ploc/PlocMPSoCHandler.h +++ b/linux/devices/ploc/PlocMPSoCHandler.h @@ -8,7 +8,7 @@ #include "fsfw/ipc/QueueFactory.h" #include "fsfw/tmtcservices/SourceSequenceCounter.h" #include "fsfw_hal/linux/uart/UartComIF.h" -#include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h" +#include "fsfw_hal/linux/gpio/Gpio.h" #include "linux/devices/devicedefinitions/MPSoCReturnValuesIF.h" #include "linux/devices/devicedefinitions/PlocMPSoCDefinitions.h" @@ -29,8 +29,7 @@ class PlocMPSoCHandler : public DeviceHandlerBase { public: PlocMPSoCHandler(object_id_t objectId, object_id_t uartComIFid, CookieIF* comCookie, - PlocMPSoCHelper* plocMPSoCHelper, LinuxLibgpioIF* gpioComIF, - gpioId_t uartIsolatorSwitch); + PlocMPSoCHelper* plocMPSoCHelper, Gpio uartIsolatorSwitch); virtual ~PlocMPSoCHandler(); virtual ReturnValue_t initialize() override; ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, @@ -99,8 +98,7 @@ class PlocMPSoCHandler : public DeviceHandlerBase { UartComIF* uartComIf = nullptr; PlocMPSoCHelper* plocMPSoCHelper = nullptr; - LinuxLibgpioIF* gpioComIF = nullptr; - gpioId_t uartIsolatorSwitch = gpio::NO_GPIO; + Gpio uartIsolatorSwitch; // Used to block incoming commands when MPSoC helper class is currently executing a command bool plocMPSoCHelperExecuting = false; diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index 192a0a0c..57658518 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -12,10 +12,9 @@ #include "OBSWConfig.h" PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, object_id_t uartComIFid, - CookieIF* comCookie, LinuxLibgpioIF* gpioComIF, - gpioId_t uartIsolatorSwitch) + CookieIF* comCookie, + Gpio uartIsolatorSwitch) : DeviceHandlerBase(objectId, uartComIFid, comCookie), - gpioComIF(gpioComIF), uartIsolatorSwitch(uartIsolatorSwitch), hkset(this), bootStatusReport(this), @@ -50,9 +49,13 @@ void PlocSupervisorHandler::doStartUp() { #else setMode(_MODE_TO_ON); #endif + uartIsolatorSwitch.pullHigh(); } -void PlocSupervisorHandler::doShutDown() { setMode(_MODE_POWER_DOWN); } +void PlocSupervisorHandler::doShutDown() { + setMode(_MODE_POWER_DOWN); + uartIsolatorSwitch.pullLow(); +} ReturnValue_t PlocSupervisorHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { return NOTHING_TO_SEND; diff --git a/linux/devices/ploc/PlocSupervisorHandler.h b/linux/devices/ploc/PlocSupervisorHandler.h index 5f133fef..b2db18b2 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.h +++ b/linux/devices/ploc/PlocSupervisorHandler.h @@ -5,7 +5,8 @@ #include "fsfw/devicehandlers/DeviceHandlerBase.h" #include "fsfw_hal/linux/uart/UartComIF.h" #include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h" -#include "inux/devices/devicedefinitions/PlocSupervisorDefinitions.h" +#include "fsfw_hal/linux/gpio/Gpio.h" +#include "linux/devices/devicedefinitions/PlocSupervisorDefinitions.h" #include "OBSWConfig.h" @@ -24,7 +25,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { public: PlocSupervisorHandler(object_id_t objectId, object_id_t uartComIFid, CookieIF* comCookie, - LinuxLibgpioIF* gpioComIF, gpioId_t uartIsolatorSwitch); + Gpio uartIsolatorSwitch); virtual ~PlocSupervisorHandler(); virtual ReturnValue_t initialize() override; @@ -115,7 +116,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { UartComIF* uartComIf = nullptr; LinuxLibgpioIF* gpioComIF = nullptr; - gpioId_t uartIsolatorSwitch = gpio::NO_GPIO; + Gpio uartIsolatorSwitch; PLOC_SPV::HkSet hkset; PLOC_SPV::BootStatusReport bootStatusReport; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 06c053c8..aea49d86 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(testtasks) +add_subdirectory(gpio)