From 2c8b691ca4d06eb2f6569ec7bdd6b7f2e3c83f61 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 30 Mar 2022 17:44:07 +0200 Subject: [PATCH] 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