From 86df9a9e302f8b96bc040f3b2c657baea53fff07 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Feb 2021 13:38:04 +0100 Subject: [PATCH 01/13] updated eive repo --- CMakeLists.txt | 14 ++++++++------ fsfw | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05ca6671..a8d94fa2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,16 +162,18 @@ else() set(TARGET_STRING "Target BSP: Hosted") endif() +string(CONCAT POST_BUILD_COMMENT + "Build directory: ${CMAKE_BINARY_DIR}\n" + "Target OSAL: ${OS_FSFW}\n" + "Target Build Type: ${CMAKE_BUILD_TYPE}\n" + "${TARGET_STRING}" +) + add_custom_command( TARGET ${TARGET_NAME} POST_BUILD - #COMMAND echo "Build directory: ${CMAKE_BINARY_DIR}" - #COMMAND echo "Target OSAL: ${OS_FSFW}" - #COMMAND echo "Target Build Type: ${CMAKE_BUILD_TYPE}" - #COMMAND echo "${TARGET_STRING}" COMMAND ${CMAKE_SIZE} ${TARGET_NAME}${FILE_SUFFIX} - COMMENT "Build directory: ${CMAKE_BINARY_DIR}\nTarget OSAL: ${OS_FSFW}\n" - "Target Build Type: ${CMAKE_BUILD_TYPE}\n${TARGET_STRING}" + COMMENT ${POST_BUILD_COMMENT} ) include (${CMAKE_SCRIPT_PATH}/BuildType.cmake) diff --git a/fsfw b/fsfw index 50733e22..5f197be2 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 50733e223adaf9fc95d9728c62a026ea6efac1d2 +Subproject commit 5f197be2ff4b7cfa1940d41a5d02c08ffe1abd3b From 75a1db70f49070bdb57cba6bd11650205adc0a4d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Feb 2021 13:40:04 +0100 Subject: [PATCH 02/13] fsfw update --- fsfw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfw b/fsfw index 5f197be2..8c5e261a 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 5f197be2ff4b7cfa1940d41a5d02c08ffe1abd3b +Subproject commit 8c5e261a0db46e53a7655c98766ebd65a13dc10a From 19fb5535f6466b1df9281910a876c71d48c54d59 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Feb 2021 13:41:32 +0100 Subject: [PATCH 03/13] fsfw update --- fsfw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfw b/fsfw index 50733e22..8c5e261a 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 50733e223adaf9fc95d9728c62a026ea6efac1d2 +Subproject commit 8c5e261a0db46e53a7655c98766ebd65a13dc10a From 8e0b38f8db6587e129d8f37e1d70e7986aec7af2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Feb 2021 14:15:06 +0100 Subject: [PATCH 04/13] tmtc update --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 7e64595d..a84d125b 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 7e64595d1a34732ed5d178cbbae634104634763f +Subproject commit a84d125b4be5b88d43738e874c67e71633772306 From 9b8c4fadb155807eed37cd9b03afada8323a1475 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 3 Feb 2021 14:18:13 +0100 Subject: [PATCH 05/13] tmtc update --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index a84d125b..361eb39a 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit a84d125b4be5b88d43738e874c67e71633772306 +Subproject commit 361eb39aa12cf99cc6fd3931dc829d5de6a09b94 From 015251dab1e3f244ba1f8411fa3ffb0ac379a9c5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 5 Feb 2021 11:17:40 +0100 Subject: [PATCH 06/13] fsfw update --- fsfw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfw b/fsfw index 8c5e261a..257e79f8 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 8c5e261a0db46e53a7655c98766ebd65a13dc10a +Subproject commit 257e79f8fcdc1711bdf6cee7b6c878de5942e08f From 1c3d0488e8cba956bcf5e094cb955012ed78d975 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Feb 2021 12:43:03 +0100 Subject: [PATCH 07/13] fsfw update --- fsfw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfw b/fsfw index 257e79f8..5209a9bb 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 257e79f8fcdc1711bdf6cee7b6c878de5942e08f +Subproject commit 5209a9bb89f171cd874084585fa2ed4c967e8dac From 7b4949583b8885edcc5b6349b093b17e85a04318 Mon Sep 17 00:00:00 2001 From: Martin Zietz Date: Fri, 12 Feb 2021 12:52:40 +0100 Subject: [PATCH 08/13] enabled gpio switching in heater again --- bsp_q7s/ObjectFactory.cpp | 3 ++- cmake/scripts/Q7S/win_path_helper_xilinx_tools.sh | 1 + fsfwconfig/OBSWConfig.h | 2 +- mission/devices/HeaterHandler.cpp | 4 ++-- mission/devices/PCDUHandler.cpp | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 5ddb1b36..2ce52aaf 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -104,7 +104,8 @@ void ObjectFactory::produce(){ std::string("Heater0"), Gpio::OUT); gpioCookie->addGpio(gpioIds::HEATER_0, gpioConfigForDummyHeater); #else - GpioConfig_t gpioConfigHeater0(std::string("gpiochip5"), 6, + /* Pin H2-11 on stack connector */ + GpioConfig_t gpioConfigHeater0(std::string("gpiochip5"), 20, std::string("Heater0"), Gpio::OUT); gpioCookie->addGpio(gpioIds::HEATER_0, gpioConfigHeater0); #endif diff --git a/cmake/scripts/Q7S/win_path_helper_xilinx_tools.sh b/cmake/scripts/Q7S/win_path_helper_xilinx_tools.sh index ac2411b7..c9bcc54a 100644 --- a/cmake/scripts/Q7S/win_path_helper_xilinx_tools.sh +++ b/cmake/scripts/Q7S/win_path_helper_xilinx_tools.sh @@ -1,3 +1,4 @@ +#!/bin/sh export PATH=$PATH:"/c/Xilinx/SDK/2018.2/gnu/aarch32/nt/gcc-arm-linux-gnueabi/bin" export CROSS_COMPILE="arm-linux-gnueabihf" diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index ed3ee6f5..954931d8 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -14,7 +14,7 @@ #define TE0720 0 -#define PDU2_DEBUG 1 +#define PDU2_DEBUG 0 #define PDU1_DEBUG 0 #include "OBSWVersion.h" diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index 6f383ca1..b6cccb2b 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -212,7 +212,7 @@ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) { if (mainSwitchState == PowerSwitchIF::SWITCH_ON) { if (!checkSwitchState(switchNr)) { gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr); -// result = gpioInterface->pullHigh(gpioId); + result = gpioInterface->pullHigh(gpioId); result = RETURN_OK; if (result != RETURN_OK) { sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id" @@ -263,7 +263,7 @@ void HeaterHandler::handleSwitchOffCommand(HeaterMapIter heaterMapIter) { /* Check whether switch is already off */ if (checkSwitchState(switchNr)) { gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr); -// result = gpioInterface->pullLow(gpioId); + result = gpioInterface->pullLow(gpioId); result = RETURN_OK; if (result != RETURN_OK) { sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id" diff --git a/mission/devices/PCDUHandler.cpp b/mission/devices/PCDUHandler.cpp index 6e9227d3..9fe9fbdb 100644 --- a/mission/devices/PCDUHandler.cpp +++ b/mission/devices/PCDUHandler.cpp @@ -267,7 +267,7 @@ ReturnValue_t PCDUHandler::getFuseState( uint8_t fuseNr ) const { } uint32_t PCDUHandler::getSwitchDelayMs(void) const { - return 15000; + return 20000; } object_id_t PCDUHandler::getObjectId() const { From b908393b79242fdf5047e0e976ff62006755a4fb Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Fri, 12 Feb 2021 15:24:37 +0100 Subject: [PATCH 09/13] added all heater switches --- bsp_q7s/ObjectFactory.cpp | 28 ++++++++++++++++++++++++++++ mission/devices/HeaterHandler.cpp | 18 ++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 06c1eca5..59c8c817 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -108,9 +108,37 @@ void ObjectFactory::produce(){ GpioConfig_t gpioConfigHeater0(std::string("gpiochip7"), 18, std::string("Heater0"), Gpio::OUT); gpioCookie->addGpio(gpioIds::HEATER_0, gpioConfigHeater0); + + /* Pin H2-12 on stack connector */ GpioConfig_t gpioConfigHeater1(std::string("gpiochip7"), 14, std::string("Heater1"), Gpio::OUT); gpioCookie->addGpio(gpioIds::HEATER_1, gpioConfigHeater1); + + /* Pin H2-13 on stack connector */ + GpioConfig_t gpioConfigHeater2(std::string("gpiochip7"), 20, + std::string("Heater2"), Gpio::OUT); + gpioCookie->addGpio(gpioIds::HEATER_2, gpioConfigHeater2); + + GpioConfig_t gpioConfigHeater3(std::string("gpiochip7"), 16, + std::string("Heater3"), Gpio::OUT); + gpioCookie->addGpio(gpioIds::HEATER_3, gpioConfigHeater3); + + GpioConfig_t gpioConfigHeater4(std::string("gpiochip7"), 24, + std::string("Heater4"), Gpio::OUT); + gpioCookie->addGpio(gpioIds::HEATER_4, gpioConfigHeater4); + + GpioConfig_t gpioConfigHeater5(std::string("gpiochip7"), 26, + std::string("Heater5"), Gpio::OUT); + gpioCookie->addGpio(gpioIds::HEATER_5, gpioConfigHeater5); + + GpioConfig_t gpioConfigHeater6(std::string("gpiochip7"), 22, + std::string("Heater6"), Gpio::OUT); + gpioCookie->addGpio(gpioIds::HEATER_6, gpioConfigHeater6); + + GpioConfig_t gpioConfigHeater7(std::string("gpiochip7"), 28, + std::string("Heater7"), Gpio::OUT); + gpioCookie->addGpio(gpioIds::HEATER_7, gpioConfigHeater7); + #endif new LinuxLibgpioIF(objects::GPIO_IF); new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER, diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index b7f03171..aedb4b03 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -311,6 +311,24 @@ gpioId_t HeaterHandler::getGpioIdFromSwitchNr(int switchNr) { case heaterSwitches::HEATER_1: gpioId = gpioIds::HEATER_1; break; + case heaterSwitches::HEATER_2: + gpioId = gpioIds::HEATER_2; + break; + case heaterSwitches::HEATER_3: + gpioId = gpioIds::HEATER_3; + break; + case heaterSwitches::HEATER_4: + gpioId = gpioIds::HEATER_4; + break; + case heaterSwitches::HEATER_5: + gpioId = gpioIds::HEATER_5; + break; + case heaterSwitches::HEATER_6: + gpioId = gpioIds::HEATER_6; + break; + case heaterSwitches::HEATER_7: + gpioId = gpioIds::HEATER_7; + break; default: sif::error << "HeaterHandler::getGpioIdFromSwitchNr: Unknown heater switch number" << std::endl; From 76e59e35937e6f415b747fc814c10aedc21ed67d Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Fri, 12 Feb 2021 21:23:35 +0100 Subject: [PATCH 10/13] improved linux libgpiod interface --- bsp_q7s/ObjectFactory.cpp | 18 ++-- bsp_q7s/gpio/GpioIF.h | 9 ++ bsp_q7s/gpio/LinuxLibgpioIF.cpp | 156 ++++++++++++++++++++---------- bsp_q7s/gpio/LinuxLibgpioIF.h | 12 ++- bsp_q7s/gpio/cookies/GpioCookie.h | 14 ++- mission/devices/HeaterHandler.cpp | 20 +++- 6 files changed, 155 insertions(+), 74 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 59c8c817..37692eb6 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -101,42 +101,42 @@ void ObjectFactory::produce(){ #if TE0720 == 1 // Configuration for MIO0 on TE0720-03-1CFA GpioConfig_t gpioConfigForDummyHeater(std::string("gpiochip0"), 0, - std::string("Heater0"), Gpio::OUT); + std::string("Heater0"), Gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_0, gpioConfigForDummyHeater); #else /* Pin H2-11 on stack connector */ GpioConfig_t gpioConfigHeater0(std::string("gpiochip7"), 18, - std::string("Heater0"), Gpio::OUT); + std::string("Heater0"), Gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_0, gpioConfigHeater0); /* Pin H2-12 on stack connector */ GpioConfig_t gpioConfigHeater1(std::string("gpiochip7"), 14, - std::string("Heater1"), Gpio::OUT); + std::string("Heater1"), Gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_1, gpioConfigHeater1); /* Pin H2-13 on stack connector */ GpioConfig_t gpioConfigHeater2(std::string("gpiochip7"), 20, - std::string("Heater2"), Gpio::OUT); + std::string("Heater2"), Gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_2, gpioConfigHeater2); GpioConfig_t gpioConfigHeater3(std::string("gpiochip7"), 16, - std::string("Heater3"), Gpio::OUT); + std::string("Heater3"), Gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_3, gpioConfigHeater3); GpioConfig_t gpioConfigHeater4(std::string("gpiochip7"), 24, - std::string("Heater4"), Gpio::OUT); + std::string("Heater4"), Gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_4, gpioConfigHeater4); GpioConfig_t gpioConfigHeater5(std::string("gpiochip7"), 26, - std::string("Heater5"), Gpio::OUT); + std::string("Heater5"), Gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_5, gpioConfigHeater5); GpioConfig_t gpioConfigHeater6(std::string("gpiochip7"), 22, - std::string("Heater6"), Gpio::OUT); + std::string("Heater6"), Gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_6, gpioConfigHeater6); GpioConfig_t gpioConfigHeater7(std::string("gpiochip7"), 28, - std::string("Heater7"), Gpio::OUT); + std::string("Heater7"), Gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_7, gpioConfigHeater7); #endif diff --git a/bsp_q7s/gpio/GpioIF.h b/bsp_q7s/gpio/GpioIF.h index cf688db8..d1f02dd8 100644 --- a/bsp_q7s/gpio/GpioIF.h +++ b/bsp_q7s/gpio/GpioIF.h @@ -38,6 +38,15 @@ public: * @param gpioId A unique number which specifies the GPIO to drive. */ virtual ReturnValue_t pullLow(gpioId_t gpioId) = 0; + + /** + * @brief This function requires a child to implement the functionaliy to read the state of + * an ouput or input gpio. + * + * @param gpioId A unique number which specifies the GPIO to read. + * @param gpioState State of GPIO will be written to this pointer. + */ + virtual ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) = 0; }; #endif /* BSP_Q7S_GPIO_GPIOIF_H_ */ diff --git a/bsp_q7s/gpio/LinuxLibgpioIF.cpp b/bsp_q7s/gpio/LinuxLibgpioIF.cpp index 7e98abd6..415ce3d0 100644 --- a/bsp_q7s/gpio/LinuxLibgpioIF.cpp +++ b/bsp_q7s/gpio/LinuxLibgpioIF.cpp @@ -14,7 +14,6 @@ LinuxLibgpioIF::~LinuxLibgpioIF() { ReturnValue_t LinuxLibgpioIF::initialize(CookieIF * cookie){ ReturnValue_t result; GpioMap mapToAdd; - GpioMapIter mapToAddIter; if(cookie == nullptr) { sif::error << "LinuxLibgpioIF::initialize: Invalid cookie" << std::endl; @@ -30,14 +29,86 @@ ReturnValue_t LinuxLibgpioIF::initialize(CookieIF * cookie){ mapToAdd = gpioCookie->getGpioMap(); result = checkForConflicts(mapToAdd); - if (result != HasReturnvaluesIF::RETURN_OK){ + if (result != RETURN_OK){ return result; } + result = configureGpios(mapToAdd); + if (result != RETURN_OK) { + return RETURN_FAILED; + } + /* Register new GPIOs in gpioMap*/ gpioMap.insert(mapToAdd.begin(), mapToAdd.end()); - return HasReturnvaluesIF::RETURN_OK; + return RETURN_OK; +} + +ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap mapToAdd) { + GpioMapIter mapToAddIter; + std::string chipname; + unsigned int lineNum; + struct gpiod_chip *chip; + Gpio::Direction direction; + std::string consumer; + struct gpiod_line *lineHandle; + int result; + + for (mapToAddIter = mapToAdd.begin(); mapToAddIter != mapToAdd.end(); mapToAddIter++) { + + chipname = gpioMapIter->second.chipname; + chip = gpiod_chip_open_by_name(chipname.c_str()); + if (!chip) { + sif::error << "LinuxLibgpioIF::configureGpios: Failed to open chip " + << chipname << ". Gpio ID: " << gpioMapIter->first << std::endl; + return RETURN_FAILED; + } + + lineNum = gpioMapIter->second.lineNum; + lineHandle = gpiod_chip_get_line(chip, lineNum); + if (!lineHandle) { + sif::error << "LinuxLibgpioIF::configureGpios: Failed to open line" << std::endl; + gpiod_chip_close(chip); + return RETURN_FAILED; + } + + direction = gpioMapIter->second.direction; + consumer = gpioMapIter->second.consumer; + /* Configure direction and add a description to the GPIO */ + switch (direction) { + case Gpio::OUT: + result = gpiod_line_request_output(lineHandle, consumer.c_str(), + gpioMapIter->second.initValue); + if (result < 0) { + sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line " + << lineNum << " from GPIO instance with ID: " << gpioMapIter->first + << std::endl; + gpiod_line_release(lineHandle); + return RETURN_FAILED; + } + break; + case Gpio::IN: + result = gpiod_line_request_input(lineHandle, consumer.c_str()); + if (result < 0) { + sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line " + << lineNum << " from GPIO instance with ID: " << gpioMapIter->first + << std::endl; + gpiod_line_release(lineHandle); + return RETURN_FAILED; + } + break; + default: + sif::error << "LinuxLibgpioIF::configureGpios: Invalid direction specified" + << std::endl; + return RETURN_FAILED; + } + /** + * Write line handle to GPIO configuration instance so it can later be used to set or + * read states of GPIOs. + */ + gpioMapIter->second.lineHandle = lineHandle; + } + return RETURN_OK; } ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId){ @@ -50,60 +121,39 @@ ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId){ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, unsigned int logiclevel) { + int result; + struct gpiod_line *lineHandle; + GpioMapIter gpioMapIter = gpioMap.find(gpioId); - std::string chipname; - unsigned int lineNum; - struct gpiod_chip *chip; - struct gpiod_line *line; - int result; - Gpio::Direction direction; - std::string consumer; + if (gpioMapIter == gpioMap.end()){ + sif::debug << "LinuxLibgpioIF::driveGpio: Unknown gpio id " << gpioId << std::endl; + return RETURN_FAILED; + } - /* Verify if GPIO has been configured as output */ - direction = gpioMapIter->second.direction; - if (direction != Gpio::OUT) { - sif::error << "LinuxLibgpioIF::driveGpio: GPIO with ID " << gpioId - << "not configured as output" << std::endl; - return CONFIGURATION_FAILURE; - } - - chipname = gpioMapIter->second.chipname; - chip = gpiod_chip_open_by_name(chipname.c_str()); - if (!chip) { - sif::error << "LinuxLibgpioIF::driveGpio: Failed to open chip " - << chipname << ". Gpio ID: " << gpioId << std::endl; - return OPEN_CHIP_FAILURE; - } - - lineNum = gpioMapIter->second.lineNum; - line = gpiod_chip_get_line(chip, lineNum); - if (!line) { - sif::error << "LinuxLibgpioIF::driveGpio: Failed to open line. Gpio ID " - << gpioId << std::endl; - gpiod_chip_close(chip); - return OPEN_LINE_FAILURE; - } - - consumer = gpioMapIter->second.consumer; - result = gpiod_line_request_output(line, consumer.c_str(), 0); - if (result < 0) { - sif::error << "LinuxLibgpioIF::driveGpio: Failed to request line " - << line << " from GPIO instance with ID: " << gpioId - << std::endl; - gpiod_line_release(line); - return REQUEST_LINE_FAILURE; - } - - result = gpiod_line_set_value(line, logiclevel); + lineHandle = gpioMapIter->second.lineHandle; + result = gpiod_line_set_value(lineHandle, logiclevel); if (result < 0) { sif::error << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " - << gpioId << "to low" << std::endl; - gpiod_line_release(line); - return PULLING_HIGH_FAILURE; + << gpioId << "to logic level" << logiclevel << std::endl; + return DRIVE_GPIO_FAILURE; } - gpiod_line_release(line); - return HasReturnvaluesIF::RETURN_OK; + return RETURN_OK; +} + +ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) { + struct gpiod_line *lineHandle; + + GpioMapIter gpioMapIter = gpioMap.find(gpioId); + if (gpioMapIter == gpioMap.end()){ + sif::debug << "LinuxLibgpioIF::readGpio: Unknown gpio id " << gpioId << std::endl; + return RETURN_FAILED; + } + + lineHandle = gpioMapIter->second.lineHandle; + *gpioState = gpiod_line_get_value(lineHandle); + + return RETURN_OK; } ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap mapToAdd){ @@ -118,12 +168,12 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap mapToAdd){ if (mapToAddIter->second.direction != gpioMapIter->second.direction){ sif::error << "LinuxLibgpioIF::checkForConflicts: Detected conflict " << "for GPIO " << mapToAddIter->first << std::endl; - return HasReturnvaluesIF::RETURN_OK; + return RETURN_OK; } /* Remove element from map to add because a entry for this GPIO * already exists */ mapToAdd.erase(mapToAddIter); } } - return HasReturnvaluesIF::RETURN_OK; + return RETURN_OK; } diff --git a/bsp_q7s/gpio/LinuxLibgpioIF.h b/bsp_q7s/gpio/LinuxLibgpioIF.h index 0eaf8c48..ef2bf8b5 100644 --- a/bsp_q7s/gpio/LinuxLibgpioIF.h +++ b/bsp_q7s/gpio/LinuxLibgpioIF.h @@ -18,11 +18,7 @@ public: static const uint8_t INTERFACE_ID = CLASS_ID::LINUX_LIBGPIO_IF; - static const ReturnValue_t CONFIGURATION_FAILURE = MAKE_RETURN_CODE(0x1); - static const ReturnValue_t OPEN_CHIP_FAILURE = MAKE_RETURN_CODE(0x2); - static const ReturnValue_t OPEN_LINE_FAILURE = MAKE_RETURN_CODE(0x3); - static const ReturnValue_t REQUEST_LINE_FAILURE = MAKE_RETURN_CODE(0x4); - static const ReturnValue_t PULLING_HIGH_FAILURE = MAKE_RETURN_CODE(0x5); + static const ReturnValue_t DRIVE_GPIO_FAILURE = MAKE_RETURN_CODE(0x2); LinuxLibgpioIF(object_id_t objectId); virtual ~LinuxLibgpioIF(); @@ -30,6 +26,7 @@ public: ReturnValue_t initialize(CookieIF * cookie) override; ReturnValue_t pullHigh(gpioId_t gpioId) override; ReturnValue_t pullLow(gpioId_t gpioId) override; + ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) override; private: @@ -56,6 +53,11 @@ private: * @return RETURN_OK if successful, otherwise RETURN_FAILED */ ReturnValue_t checkForConflicts(GpioMap mapToAdd); + + /** + * @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd. + */ + ReturnValue_t configureGpios(GpioMap mapToAdd); }; #endif /* BSP_Q7S_GPIO_LINUXLIBGPIOIF_H_ */ diff --git a/bsp_q7s/gpio/cookies/GpioCookie.h b/bsp_q7s/gpio/cookies/GpioCookie.h index 16ba3b8c..517434c1 100644 --- a/bsp_q7s/gpio/cookies/GpioCookie.h +++ b/bsp_q7s/gpio/cookies/GpioCookie.h @@ -21,19 +21,25 @@ namespace Gpio { * the GPIO to access. E.g. gpiochip0. To detect names of * GPIO groups run gpiodetect on the linux command line. * @param lineNum The offset of the GPIO within the GPIO group. - * @param consumer Name of the consumer currently accessing the GPIO. - * @param direction Specifies whether the GPIO should be used as in- or output. + * @param consumer Name of the consumer. Simply a description of the GPIO configuration. + * @param direction Specifies whether the GPIO should be used as in- or output. + * @param initValue Defines the initial state of the GPIO when configured as output. Only required + * for output GPIOs. + * @param lineHandle The handle returned by gpiod_chip_get_line will be later written to this + * pointer. */ typedef struct GpioConfig { GpioConfig(std::string chipname_, int lineNum_, std::string consumer_, - Gpio::Direction direction_) : + Gpio::Direction direction_, int initValue_) : chipname(chipname_), lineNum(lineNum_), consumer(consumer_), direction( - direction_) { + direction_), initValue(initValue_) { } std::string chipname; int lineNum; std::string consumer; Gpio::Direction direction; + int initValue; + struct gpiod_line *lineHandle; } GpioConfig_t; using GpioMap = std::unordered_map; using GpioMapIter = GpioMap::iterator; diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index aedb4b03..0545a9e1 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -213,15 +213,22 @@ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) { if (!checkSwitchState(switchNr)) { gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr); result = gpioInterface->pullHigh(gpioId); - result = RETURN_OK; if (result != RETURN_OK) { - sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id" + sif::error << "HeaterHandler::handleSwitchOnCommand: Failed to pull gpio with id" << gpioId << "high" << std::endl; triggerEvent(GPIO_PULL_HIGH_FAILED, result); } else { switchStates[switchNr] = ON; } + int gpioState; + result = gpioInterface->readGpio(gpioId, &gpioState); + if (result != RETURN_OK) { + sif::debug << "HeaterHandler::handleSwitchOnCommand: Failed to read gpio" + << std::endl; + } + sif::debug << "HeaterHandler::handleSwitchOnCommand: GPIO state: " << gpioState + << std::endl; } else { triggerEvent(SWITCH_ALREADY_ON, switchNr); @@ -264,7 +271,6 @@ void HeaterHandler::handleSwitchOffCommand(HeaterMapIter heaterMapIter) { if (checkSwitchState(switchNr)) { gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr); result = gpioInterface->pullLow(gpioId); - result = RETURN_OK; if (result != RETURN_OK) { sif::error << "HeaterHandler::handleSwitchOffCommand: Failed to pull gpio with id" << gpioId << " low" << std::endl; @@ -277,6 +283,14 @@ void HeaterHandler::handleSwitchOffCommand(HeaterMapIter heaterMapIter) { mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF); } } + int gpioState; + result = gpioInterface->readGpio(gpioId, &gpioState); + if (result != RETURN_OK) { + sif::debug << "HeaterHandler::handleSwitchOnCommand: Failed to read gpio" + << std::endl; + } + sif::debug << "HeaterHandler::handleSwitchOnCommand: GPIO state: " << gpioState + << std::endl; } else { sif::info << "HeaterHandler::handleSwitchOffCommand: Switch already off" << std::endl; From 6cd9d439bcba4c217cb9cf89053f4605328cebd9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 13 Feb 2021 19:00:34 +0100 Subject: [PATCH 11/13] fsfw and tmtc update --- fsfw | 2 +- tmtc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fsfw b/fsfw index 5209a9bb..c2839825 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 5209a9bb89f171cd874084585fa2ed4c967e8dac +Subproject commit c28398257b68facbabb19d7228b045f1388305df diff --git a/tmtc b/tmtc index 361eb39a..c10fbe7f 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 361eb39aa12cf99cc6fd3931dc829d5de6a09b94 +Subproject commit c10fbe7fbec6b32ceb725da62e18e4db5dc112a7 From bdc4b1cec54f504a3c3d485b3bf0d87e0e3e667e Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 14 Feb 2021 09:25:40 +0100 Subject: [PATCH 12/13] added gpio read function --- CMakeLists.txt | 2 + bsp_q7s/InitMission.cpp | 14 +++++- bsp_q7s/ObjectFactory.cpp | 53 +++++++++++++++++------ bsp_q7s/comIF/CspComIF.cpp | 1 - bsp_q7s/gpio/CMakeLists.txt | 5 +++ bsp_q7s/gpio/LinuxLibgpioIF.cpp | 31 ++++++------- bsp_q7s/gpio/LinuxLibgpioIF.h | 2 +- bsp_q7s/gpio/cookies/GpioCookie.h | 2 +- fsfwconfig/OBSWConfig.h | 3 +- fsfwconfig/devices/gpioIds.h | 1 + fsfwconfig/objects/systemObjectList.h | 1 + mission/devices/GomspaceDeviceHandler.cpp | 5 ++- mission/devices/GomspaceDeviceHandler.h | 6 +++ mission/devices/HeaterHandler.cpp | 20 +-------- test/test.mk | 3 -- test/testtasks/CMakeLists.txt | 8 ++++ test/testtasks/LibgpioTest.cpp | 35 +++++++++++++++ test/testtasks/LibgpioTest.h | 25 +++++++++++ 18 files changed, 161 insertions(+), 56 deletions(-) delete mode 100644 test/test.mk create mode 100644 test/testtasks/CMakeLists.txt create mode 100644 test/testtasks/LibgpioTest.cpp create mode 100644 test/testtasks/LibgpioTest.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 05ca6671..99eb93bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ set(LIB_CSP_NAME libcsp) set(FSFW_PATH fsfw) set(MISSION_PATH mission) set(CSPLIB_PATH libcsp) +set(TEST_PATH test/testtasks) set(FSFW_WARNING_SHADOW_LOCAL_GCC OFF) @@ -84,6 +85,7 @@ endif() add_subdirectory(${BSP_PATH}) add_subdirectory(${FSFW_PATH}) add_subdirectory(${MISSION_PATH}) +add_subdirectory(${TEST_PATH}) ################################################################################ # Post-Sources preparation diff --git a/bsp_q7s/InitMission.cpp b/bsp_q7s/InitMission.cpp index ee39c4ea..fd4cde43 100644 --- a/bsp_q7s/InitMission.cpp +++ b/bsp_q7s/InitMission.cpp @@ -157,6 +157,16 @@ void InitMission::initTasks(){ // << "failed!" << std::endl; // } +#endif + +#if TE0720 == 1 && TEST_LIBGPIOD == 1 + PeriodicTaskIF* TestTask = TaskFactory::instance()-> + createPeriodicTask("Libgpiod Test Task", 60, + PeriodicTaskIF::MINIMUM_STACK_SIZE, 1, nullptr); + result = TestTask->addComponent(objects::LIBGPIOD_TEST); + if(result != HasReturnvaluesIF::RETURN_OK){ + sif::error << "Object add component libgpiod test task object" << std::endl; + } #endif //Main thread sleep @@ -174,8 +184,8 @@ void InitMission::initTasks(){ PusMedPrio->startTask(); PusLowPrio->startTask(); -#if OBSW_ADD_TEST_CODE == 1 -// TestTimeslotTask->startTask(); +#if TE0720 == 1 && TEST_LIBGPIOD == 1 + TestTask->startTask(); #endif sif::info << "Tasks started.." << std::endl; } diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 37692eb6..7ee93a2c 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -33,6 +33,10 @@ #include #include +# if TEST_LIBGPIOD == 1 +#include "LibgpioTest.h" +#endif + void Factory::setStaticFrameworkObjectIds() { PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR; PusServiceBase::packetDestination = objects::TM_FUNNEL; @@ -56,15 +60,6 @@ void ObjectFactory::produce(){ Factory::setStaticFrameworkObjectIds(); ObjectFactory::produceGenericObjects(); - /* Cookies */ - CspCookie* p60DockCspCookie = new CspCookie(P60Dock::MAX_REPLY_LENGTH, - addresses::P60DOCK); - CspCookie* pdu1CspCookie = new CspCookie(PDU::MAX_REPLY_LENGTH, - addresses::PDU1); - CspCookie* pdu2CspCookie = new CspCookie(PDU::MAX_REPLY_LENGTH, - addresses::PDU2); - CspCookie* acuCspCookie = new CspCookie(ACU::MAX_REPLY_LENGTH, - addresses::ACU); #if TE0720 == 1 I2cCookie* i2cCookieTmp1075tcs1 = new I2cCookie(addresses::TMP1075_TCS_1, TMP1075::MAX_REPLY_LENGTH, std::string("/dev/i2c-0")); @@ -80,12 +75,31 @@ void ObjectFactory::produce(){ new CspComIF(objects::CSP_COM_IF); new I2cComIF(objects::I2C_COM_IF); +#if TE0720 == 0 + CspCookie* p60DockCspCookie = new CspCookie(P60Dock::MAX_REPLY_LENGTH, + addresses::P60DOCK); + CspCookie* pdu1CspCookie = new CspCookie(PDU::MAX_REPLY_LENGTH, + addresses::PDU1); + CspCookie* pdu2CspCookie = new CspCookie(PDU::MAX_REPLY_LENGTH, + addresses::PDU2); + CspCookie* acuCspCookie = new CspCookie(ACU::MAX_REPLY_LENGTH, + addresses::ACU); /* Device Handler */ - new P60DockHandler(objects::P60DOCK_HANDLER, objects::CSP_COM_IF, p60DockCspCookie); - new PDU1Handler(objects::PDU1_HANDLER, objects::CSP_COM_IF, pdu1CspCookie); - new PDU2Handler(objects::PDU2_HANDLER, objects::CSP_COM_IF, pdu2CspCookie); - new ACUHandler(objects::ACU_HANDLER, objects::CSP_COM_IF, acuCspCookie); + P60DockHandler* p60dockhandler = new P60DockHandler(objects::P60DOCK_HANDLER, objects::CSP_COM_IF, p60DockCspCookie); + PDU1Handler* pdu1handler = new PDU1Handler(objects::PDU1_HANDLER, objects::CSP_COM_IF, pdu1CspCookie); + PDU2Handler* pdu2handler = new PDU2Handler(objects::PDU2_HANDLER, objects::CSP_COM_IF, pdu2CspCookie); + ACUHandler* acuhandler = new ACUHandler(objects::ACU_HANDLER, objects::CSP_COM_IF, acuCspCookie); new PCDUHandler(objects::PCDU_HANDLER, 50); + + /** + * Setting PCDU devices to mode normal immediately after start up because PCDU is always + * running. + */ + p60dockhandler->setModeNormal(); + pdu1handler->setModeNormal(); + pdu2handler->setModeNormal(); + acuhandler->setModeNormal(); +#endif /* Temperature sensors */ Tmp1075Handler* tmp1075Handler_1 = new Tmp1075Handler( objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, @@ -99,10 +113,19 @@ void ObjectFactory::produce(){ /* Thermal objects */ GpioCookie* gpioCookie = new GpioCookie; #if TE0720 == 1 + +#if TEST_LIBGPIOD == 1 + /* Configure MIO0 as input */ + GpioConfig_t gpioConfigMio0(std::string("gpiochip0"), 0, + std::string("MIO0"), Gpio::IN, 0); + gpioCookie->addGpio(gpioIds::Test_ID, gpioConfigMio0); +#else // Configuration for MIO0 on TE0720-03-1CFA GpioConfig_t gpioConfigForDummyHeater(std::string("gpiochip0"), 0, std::string("Heater0"), Gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_0, gpioConfigForDummyHeater); +#endif + #else /* Pin H2-11 on stack connector */ GpioConfig_t gpioConfigHeater0(std::string("gpiochip7"), 18, @@ -148,4 +171,8 @@ void ObjectFactory::produce(){ objects::CCSDS_PACKET_DISTRIBUTOR, objects::TM_STORE, objects::TC_STORE); new TcUnixUdpPollingTask(objects::UDP_POLLING_TASK, objects::UDP_BRIDGE); + +#if TE0720 == 1 && TEST_LIBGPIOD == 1 + new LibgpioTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie); +#endif } diff --git a/bsp_q7s/comIF/CspComIF.cpp b/bsp_q7s/comIF/CspComIF.cpp index 52a92cc9..9d7543c3 100644 --- a/bsp_q7s/comIF/CspComIF.cpp +++ b/bsp_q7s/comIF/CspComIF.cpp @@ -187,7 +187,6 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort, reply = csp_read(conn, timeout_ms); if (reply == NULL) { sif::error << "CspComIF::cspTransfer: Failed to read csp packet" << std::endl; - csp_buffer_free(reply); csp_close(conn); return RETURN_FAILED; } diff --git a/bsp_q7s/gpio/CMakeLists.txt b/bsp_q7s/gpio/CMakeLists.txt index e35dd300..3b789394 100644 --- a/bsp_q7s/gpio/CMakeLists.txt +++ b/bsp_q7s/gpio/CMakeLists.txt @@ -3,4 +3,9 @@ target_sources(${TARGET_NAME} PUBLIC LinuxLibgpioIF.cpp ) +target_include_directories(${TARGET_NAME} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/cookies +) + diff --git a/bsp_q7s/gpio/LinuxLibgpioIF.cpp b/bsp_q7s/gpio/LinuxLibgpioIF.cpp index 415ce3d0..97159315 100644 --- a/bsp_q7s/gpio/LinuxLibgpioIF.cpp +++ b/bsp_q7s/gpio/LinuxLibgpioIF.cpp @@ -33,7 +33,7 @@ ReturnValue_t LinuxLibgpioIF::initialize(CookieIF * cookie){ return result; } - result = configureGpios(mapToAdd); + result = configureGpios(&mapToAdd); if (result != RETURN_OK) { return RETURN_FAILED; } @@ -44,7 +44,7 @@ ReturnValue_t LinuxLibgpioIF::initialize(CookieIF * cookie){ return RETURN_OK; } -ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap mapToAdd) { +ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap* mapToAdd) { GpioMapIter mapToAddIter; std::string chipname; unsigned int lineNum; @@ -54,17 +54,18 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap mapToAdd) { struct gpiod_line *lineHandle; int result; - for (mapToAddIter = mapToAdd.begin(); mapToAddIter != mapToAdd.end(); mapToAddIter++) { + mapToAddIter = mapToAdd->begin(); + for (; mapToAddIter != mapToAdd->end(); mapToAddIter++) { - chipname = gpioMapIter->second.chipname; + chipname = mapToAddIter->second.chipname; chip = gpiod_chip_open_by_name(chipname.c_str()); if (!chip) { sif::error << "LinuxLibgpioIF::configureGpios: Failed to open chip " - << chipname << ". Gpio ID: " << gpioMapIter->first << std::endl; + << chipname << ". Gpio ID: " << mapToAddIter->first << std::endl; return RETURN_FAILED; } - lineNum = gpioMapIter->second.lineNum; + lineNum = mapToAddIter->second.lineNum; lineHandle = gpiod_chip_get_line(chip, lineNum); if (!lineHandle) { sif::error << "LinuxLibgpioIF::configureGpios: Failed to open line" << std::endl; @@ -72,16 +73,16 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap mapToAdd) { return RETURN_FAILED; } - direction = gpioMapIter->second.direction; - consumer = gpioMapIter->second.consumer; + direction = mapToAddIter->second.direction; + consumer = mapToAddIter->second.consumer; /* Configure direction and add a description to the GPIO */ switch (direction) { case Gpio::OUT: result = gpiod_line_request_output(lineHandle, consumer.c_str(), - gpioMapIter->second.initValue); + mapToAddIter->second.initValue); if (result < 0) { sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line " - << lineNum << " from GPIO instance with ID: " << gpioMapIter->first + << lineNum << " from GPIO instance with ID: " << mapToAddIter->first << std::endl; gpiod_line_release(lineHandle); return RETURN_FAILED; @@ -91,7 +92,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap mapToAdd) { result = gpiod_line_request_input(lineHandle, consumer.c_str()); if (result < 0) { sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line " - << lineNum << " from GPIO instance with ID: " << gpioMapIter->first + << lineNum << " from GPIO instance with ID: " << mapToAddIter->first << std::endl; gpiod_line_release(lineHandle); return RETURN_FAILED; @@ -106,7 +107,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap mapToAdd) { * Write line handle to GPIO configuration instance so it can later be used to set or * read states of GPIOs. */ - gpioMapIter->second.lineHandle = lineHandle; + mapToAddIter->second.lineHandle = lineHandle; } return RETURN_OK; } @@ -124,7 +125,7 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, int result; struct gpiod_line *lineHandle; - GpioMapIter gpioMapIter = gpioMap.find(gpioId); + gpioMapIter = gpioMap.find(gpioId); if (gpioMapIter == gpioMap.end()){ sif::debug << "LinuxLibgpioIF::driveGpio: Unknown gpio id " << gpioId << std::endl; return RETURN_FAILED; @@ -134,7 +135,7 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, result = gpiod_line_set_value(lineHandle, logiclevel); if (result < 0) { sif::error << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " - << gpioId << "to logic level" << logiclevel << std::endl; + << gpioId << " to logic level " << logiclevel << std::endl; return DRIVE_GPIO_FAILURE; } @@ -144,7 +145,7 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) { struct gpiod_line *lineHandle; - GpioMapIter gpioMapIter = gpioMap.find(gpioId); + gpioMapIter = gpioMap.find(gpioId); if (gpioMapIter == gpioMap.end()){ sif::debug << "LinuxLibgpioIF::readGpio: Unknown gpio id " << gpioId << std::endl; return RETURN_FAILED; diff --git a/bsp_q7s/gpio/LinuxLibgpioIF.h b/bsp_q7s/gpio/LinuxLibgpioIF.h index ef2bf8b5..f8cc1a09 100644 --- a/bsp_q7s/gpio/LinuxLibgpioIF.h +++ b/bsp_q7s/gpio/LinuxLibgpioIF.h @@ -57,7 +57,7 @@ private: /** * @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd. */ - ReturnValue_t configureGpios(GpioMap mapToAdd); + ReturnValue_t configureGpios(GpioMap* mapToAdd); }; #endif /* BSP_Q7S_GPIO_LINUXLIBGPIOIF_H_ */ diff --git a/bsp_q7s/gpio/cookies/GpioCookie.h b/bsp_q7s/gpio/cookies/GpioCookie.h index 517434c1..acc360e0 100644 --- a/bsp_q7s/gpio/cookies/GpioCookie.h +++ b/bsp_q7s/gpio/cookies/GpioCookie.h @@ -39,7 +39,7 @@ typedef struct GpioConfig { std::string consumer; Gpio::Direction direction; int initValue; - struct gpiod_line *lineHandle; + struct gpiod_line* lineHandle; } GpioConfig_t; using GpioMap = std::unordered_map; using GpioMapIter = GpioMap::iterator; diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 2bbd1ca8..f5456b4d 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -6,7 +6,8 @@ #ifndef FSFWCONFIG_OBSWCONFIG_H_ #define FSFWCONFIG_OBSWCONFIG_H_ -#define OBSW_ADD_TEST_CODE 0 +#define TEST_LIBGPIOD 0 +#define ADD_TEST_TAST 1 // These defines should be disabled for mission code but are useful for // debugging. diff --git a/fsfwconfig/devices/gpioIds.h b/fsfwconfig/devices/gpioIds.h index 90ab29cb..332de906 100644 --- a/fsfwconfig/devices/gpioIds.h +++ b/fsfwconfig/devices/gpioIds.h @@ -13,6 +13,7 @@ namespace gpioIds { HEATER_5, HEATER_6, HEATER_7, + Test_ID }; } diff --git a/fsfwconfig/objects/systemObjectList.h b/fsfwconfig/objects/systemObjectList.h index 8bb027f8..d5a2e737 100644 --- a/fsfwconfig/objects/systemObjectList.h +++ b/fsfwconfig/objects/systemObjectList.h @@ -50,6 +50,7 @@ namespace objects { /* 0x54 ('T') for test handlers */ TEST_TASK = 0x54694269, + LIBGPIOD_TEST = 0x54123456, SPI_TEST = 0x54000010, DUMMY_INTERFACE = 0x5400CAFE, DUMMY_HANDLER = 0x5400AFFE, diff --git a/mission/devices/GomspaceDeviceHandler.cpp b/mission/devices/GomspaceDeviceHandler.cpp index f02548c2..44ede8b7 100644 --- a/mission/devices/GomspaceDeviceHandler.cpp +++ b/mission/devices/GomspaceDeviceHandler.cpp @@ -6,7 +6,6 @@ GomspaceDeviceHandler::GomspaceDeviceHandler(object_id_t objectId, object_id_t c uint16_t hkTableReplySize, LocalPoolDataSetBase* hkTableDataset) : DeviceHandlerBase(objectId, comIF, comCookie), maxConfigTableAddress(maxConfigTableAddress), maxHkTableAddress(maxHkTableAddress), hkTableReplySize(hkTableReplySize), hkTableDataset(hkTableDataset) { - mode = MODE_NORMAL; if (comCookie == NULL) { sif::error << "GomspaceDeviceHandler::GomspaceDeviceHandler: Invalid com cookie" << std::endl; @@ -392,3 +391,7 @@ LocalPoolDataSetBase* GomspaceDeviceHandler::getDataSetHandle(sid_t sid) { return nullptr; } } + +void GomspaceDeviceHandler::setModeNormal() { + mode = MODE_NORMAL; +} diff --git a/mission/devices/GomspaceDeviceHandler.h b/mission/devices/GomspaceDeviceHandler.h index 76ef8226..81c62502 100644 --- a/mission/devices/GomspaceDeviceHandler.h +++ b/mission/devices/GomspaceDeviceHandler.h @@ -36,6 +36,12 @@ public: uint16_t hkTableReplySize, LocalPoolDataSetBase* hkTableDataset); virtual ~GomspaceDeviceHandler(); + /** + * @brief This function can be used to set a gomspace device to normal mode immediately after + * object creation. + */ + void setModeNormal(); + protected: static const uint8_t MAX_PACKET_LEN = 36; diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index 0545a9e1..a810e2a6 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -214,21 +214,13 @@ void HeaterHandler::handleSwitchOnCommand(HeaterMapIter heaterMapIter) { gpioId_t gpioId = getGpioIdFromSwitchNr(switchNr); result = gpioInterface->pullHigh(gpioId); if (result != RETURN_OK) { - sif::error << "HeaterHandler::handleSwitchOnCommand: Failed to pull gpio with id" - << gpioId << "high" << std::endl; + sif::error << "HeaterHandler::handleSwitchOnCommand: Failed to pull gpio with id " + << gpioId << " high" << std::endl; triggerEvent(GPIO_PULL_HIGH_FAILED, result); } else { switchStates[switchNr] = ON; } - int gpioState; - result = gpioInterface->readGpio(gpioId, &gpioState); - if (result != RETURN_OK) { - sif::debug << "HeaterHandler::handleSwitchOnCommand: Failed to read gpio" - << std::endl; - } - sif::debug << "HeaterHandler::handleSwitchOnCommand: GPIO state: " << gpioState - << std::endl; } else { triggerEvent(SWITCH_ALREADY_ON, switchNr); @@ -283,14 +275,6 @@ void HeaterHandler::handleSwitchOffCommand(HeaterMapIter heaterMapIter) { mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF); } } - int gpioState; - result = gpioInterface->readGpio(gpioId, &gpioState); - if (result != RETURN_OK) { - sif::debug << "HeaterHandler::handleSwitchOnCommand: Failed to read gpio" - << std::endl; - } - sif::debug << "HeaterHandler::handleSwitchOnCommand: GPIO state: " << gpioState - << std::endl; } else { sif::info << "HeaterHandler::handleSwitchOffCommand: Switch already off" << std::endl; diff --git a/test/test.mk b/test/test.mk deleted file mode 100644 index 701ec2d1..00000000 --- a/test/test.mk +++ /dev/null @@ -1,3 +0,0 @@ -CXXSRC += $(wildcard $(CURRENTPATH)/testdevices/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/testinterfaces/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/testtasks/*.cpp) \ No newline at end of file diff --git a/test/testtasks/CMakeLists.txt b/test/testtasks/CMakeLists.txt new file mode 100644 index 00000000..c1f6beb7 --- /dev/null +++ b/test/testtasks/CMakeLists.txt @@ -0,0 +1,8 @@ +target_sources(${TARGET_NAME} PUBLIC + LibgpioTest.cpp + TestTask.cpp +) + +target_include_directories(${TARGET_NAME} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/test/testtasks/LibgpioTest.cpp b/test/testtasks/LibgpioTest.cpp new file mode 100644 index 00000000..01628f0e --- /dev/null +++ b/test/testtasks/LibgpioTest.cpp @@ -0,0 +1,35 @@ +#include "LibgpioTest.h" +#include "devices/gpioIds.h" +#include +#include + +LibgpioTest::LibgpioTest(object_id_t objectId, object_id_t gpioIfobjectId, GpioCookie* gpioCookie) : + TestTask(objectId) { + + gpioInterface = objectManager->get(gpioIfobjectId); + if (gpioInterface == nullptr) { + sif::error << "LibgpioTest::LibgpioTest: Invalid Gpio interface." << std::endl; + } + gpioInterface->initialize(gpioCookie); +} + +LibgpioTest::~LibgpioTest() { +} + +ReturnValue_t LibgpioTest::performPeriodicAction() { + int gpioState; + ReturnValue_t result; + + result = gpioInterface->readGpio(gpioIds::Test_ID, &gpioState); + if (result != RETURN_OK) { + sif::debug << "LibgpioTest::performPeriodicAction: Failed to read gpio " + << std::endl; + return RETURN_FAILED; + } + else { + sif::debug << "LibgpioTest::performPeriodicAction: MIO 0 state = " << gpioState + << std::endl; + } + return RETURN_OK; +} + diff --git a/test/testtasks/LibgpioTest.h b/test/testtasks/LibgpioTest.h new file mode 100644 index 00000000..2d670149 --- /dev/null +++ b/test/testtasks/LibgpioTest.h @@ -0,0 +1,25 @@ +#ifndef TEST_TESTTASKS_LIBGPIOTEST_H_ +#define TEST_TESTTASKS_LIBGPIOTEST_H_ + +#include "TestTask.h" +#include "GpioIF.h" +#include "GpioCookie.h" +#include + +/** + * @brief Test for the GPIO read implementation of the LinuxLibgpioIF. + * @author J. Meier + */ +class LibgpioTest: public TestTask { +public: + LibgpioTest(object_id_t objectId, object_id_t gpioIfobjectId, GpioCookie* gpioCookie); + virtual ~LibgpioTest(); + +protected: + virtual ReturnValue_t performPeriodicAction() override; + +private: + GpioIF* gpioInterface; +}; + +#endif /* TEST_TESTTASKS_LIBGPIOTEST_H_ */ From 88f62c5a1170a1bb113fe8714038d5d382a25ba7 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 14 Feb 2021 11:03:53 +0100 Subject: [PATCH 13/13] restructured objectfactory and init_mission for libgpio test on te0720 --- bsp_q7s/InitMission.cpp | 17 ++------- bsp_q7s/ObjectFactory.cpp | 38 +++++++++---------- etl | 2 +- fsfw | 2 +- fsfwconfig/OBSWConfig.h | 2 +- test/testtasks/CMakeLists.txt | 2 +- .../{LibgpioTest.cpp => LibgpiodTest.cpp} | 15 ++++---- .../{LibgpioTest.h => LibgpiodTest.h} | 12 +++--- tmtc | 2 +- 9 files changed, 40 insertions(+), 52 deletions(-) rename test/testtasks/{LibgpioTest.cpp => LibgpiodTest.cpp} (55%) rename test/testtasks/{LibgpioTest.h => LibgpiodTest.h} (54%) diff --git a/bsp_q7s/InitMission.cpp b/bsp_q7s/InitMission.cpp index fd4cde43..681d6b48 100644 --- a/bsp_q7s/InitMission.cpp +++ b/bsp_q7s/InitMission.cpp @@ -137,6 +137,7 @@ void InitMission::initTasks(){ << std::endl; } +#if TE0720 == 0 FixedTimeslotTaskIF* GomSpacePstTask = TaskFactory::instance()-> createFixedTimeslotTask("GS_PST_TASK", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE*8, 3.0, nullptr); @@ -144,19 +145,7 @@ void InitMission::initTasks(){ if(result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: GomSpace PST initialization " << "failed!" << std::endl; -} - - -#if OBSW_ADD_TEST_CODE == 1 -// FixedTimeslotTaskIF* TestTimeslotTask = TaskFactory::instance()-> -// createFixedTimeslotTask("PST_TEST_TASK", 10, -// PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr); -// result = pst::pollingSequenceTestFunction(TestTimeslotTask); -// if(result != HasReturnvaluesIF::RETURN_OK) { -// sif::error << "InitMission::createTasks: Test PST initialization " -// << "failed!" << std::endl; -// } - + } #endif #if TE0720 == 1 && TEST_LIBGPIOD == 1 @@ -175,7 +164,9 @@ void InitMission::initTasks(){ UdpBridgeTask->startTask(); UdpPollingTask->startTask(); +#if TE0720 == 0 GomSpacePstTask->startTask(); +#endif PollingSequenceTableTaskDefault->startTask(); PusVerification->startTask(); diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 7ee93a2c..5dde01d3 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -34,7 +34,7 @@ #include # if TEST_LIBGPIOD == 1 -#include "LibgpioTest.h" +#include "LibgpiodTest.h" #endif void Factory::setStaticFrameworkObjectIds() { @@ -110,23 +110,9 @@ void ObjectFactory::produce(){ i2cCookieTmp1075tcs2); tmp1075Handler_2->setStartUpImmediately(); - /* Thermal objects */ GpioCookie* gpioCookie = new GpioCookie; -#if TE0720 == 1 - -#if TEST_LIBGPIOD == 1 - /* Configure MIO0 as input */ - GpioConfig_t gpioConfigMio0(std::string("gpiochip0"), 0, - std::string("MIO0"), Gpio::IN, 0); - gpioCookie->addGpio(gpioIds::Test_ID, gpioConfigMio0); -#else - // Configuration for MIO0 on TE0720-03-1CFA - GpioConfig_t gpioConfigForDummyHeater(std::string("gpiochip0"), 0, - std::string("Heater0"), Gpio::OUT, 0); - gpioCookie->addGpio(gpioIds::HEATER_0, gpioConfigForDummyHeater); -#endif - -#else + new LinuxLibgpioIF(objects::GPIO_IF); +#if TE0720 == 0 /* Pin H2-11 on stack connector */ GpioConfig_t gpioConfigHeater0(std::string("gpiochip7"), 18, std::string("Heater0"), Gpio::OUT, 0); @@ -162,10 +148,9 @@ void ObjectFactory::produce(){ std::string("Heater7"), Gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_7, gpioConfigHeater7); + new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER, + pcduSwitches::TCS_BOARD_8V_HEATER_IN); #endif - new LinuxLibgpioIF(objects::GPIO_IF); - new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER, - pcduSwitches::TCS_BOARD_8V_HEATER_IN); new TmTcUnixUdpBridge(objects::UDP_BRIDGE, objects::CCSDS_PACKET_DISTRIBUTOR, @@ -173,6 +158,17 @@ void ObjectFactory::produce(){ new TcUnixUdpPollingTask(objects::UDP_POLLING_TASK, objects::UDP_BRIDGE); #if TE0720 == 1 && TEST_LIBGPIOD == 1 - new LibgpioTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie); + /* Configure MIO0 as input */ + GpioConfig_t gpioConfigMio0(std::string("gpiochip0"), 0, + std::string("MIO0"), Gpio::IN, 0); + gpioCookie->addGpio(gpioIds::Test_ID, gpioConfigMio0); + new LibgpiodTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie); +#elif TE0720 == 1 + // Configuration for MIO0 on TE0720-03-1CFA + GpioConfig_t gpioConfigForDummyHeater(std::string("gpiochip0"), 0, + std::string("Heater0"), Gpio::OUT, 0); + gpioCookie->addGpio(gpioIds::HEATER_0, gpioConfigForDummyHeater); + new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER, + pcduSwitches::TCS_BOARD_8V_HEATER_IN); #endif } diff --git a/etl b/etl index 1ac3b77e..ae06e641 160000 --- a/etl +++ b/etl @@ -1 +1 @@ -Subproject commit 1ac3b77ef40aa783024d15185ee8ff41ae04a73e +Subproject commit ae06e6417702b770c49289c9e7162cb3f4a5a217 diff --git a/fsfw b/fsfw index e994d81e..7d0916a4 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit e994d81e1862fade52b090311b3978fb59061966 +Subproject commit 7d0916a44e18c87b00998448333023186b3d85b1 diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index f5456b4d..6cdf0024 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -7,7 +7,7 @@ #define FSFWCONFIG_OBSWCONFIG_H_ #define TEST_LIBGPIOD 0 -#define ADD_TEST_TAST 1 +#define ADD_TEST_TAST 0 // These defines should be disabled for mission code but are useful for // debugging. diff --git a/test/testtasks/CMakeLists.txt b/test/testtasks/CMakeLists.txt index c1f6beb7..7c2df391 100644 --- a/test/testtasks/CMakeLists.txt +++ b/test/testtasks/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(${TARGET_NAME} PUBLIC - LibgpioTest.cpp + LibgpiodTest.cpp TestTask.cpp ) diff --git a/test/testtasks/LibgpioTest.cpp b/test/testtasks/LibgpiodTest.cpp similarity index 55% rename from test/testtasks/LibgpioTest.cpp rename to test/testtasks/LibgpiodTest.cpp index 01628f0e..3315f0f6 100644 --- a/test/testtasks/LibgpioTest.cpp +++ b/test/testtasks/LibgpiodTest.cpp @@ -1,33 +1,34 @@ -#include "LibgpioTest.h" +#include "LibgpiodTest.h" + #include "devices/gpioIds.h" #include #include -LibgpioTest::LibgpioTest(object_id_t objectId, object_id_t gpioIfobjectId, GpioCookie* gpioCookie) : +LibgpiodTest::LibgpiodTest(object_id_t objectId, object_id_t gpioIfobjectId, GpioCookie* gpioCookie) : TestTask(objectId) { gpioInterface = objectManager->get(gpioIfobjectId); if (gpioInterface == nullptr) { - sif::error << "LibgpioTest::LibgpioTest: Invalid Gpio interface." << std::endl; + sif::error << "LibgpiodTest::LibgpiodTest: Invalid Gpio interface." << std::endl; } gpioInterface->initialize(gpioCookie); } -LibgpioTest::~LibgpioTest() { +LibgpiodTest::~LibgpiodTest() { } -ReturnValue_t LibgpioTest::performPeriodicAction() { +ReturnValue_t LibgpiodTest::performPeriodicAction() { int gpioState; ReturnValue_t result; result = gpioInterface->readGpio(gpioIds::Test_ID, &gpioState); if (result != RETURN_OK) { - sif::debug << "LibgpioTest::performPeriodicAction: Failed to read gpio " + sif::debug << "LibgpiodTest::performPeriodicAction: Failed to read gpio " << std::endl; return RETURN_FAILED; } else { - sif::debug << "LibgpioTest::performPeriodicAction: MIO 0 state = " << gpioState + sif::debug << "LibgpiodTest::performPeriodicAction: MIO 0 state = " << gpioState << std::endl; } return RETURN_OK; diff --git a/test/testtasks/LibgpioTest.h b/test/testtasks/LibgpiodTest.h similarity index 54% rename from test/testtasks/LibgpioTest.h rename to test/testtasks/LibgpiodTest.h index 2d670149..c64f25a3 100644 --- a/test/testtasks/LibgpioTest.h +++ b/test/testtasks/LibgpiodTest.h @@ -1,5 +1,5 @@ -#ifndef TEST_TESTTASKS_LIBGPIOTEST_H_ -#define TEST_TESTTASKS_LIBGPIOTEST_H_ +#ifndef TEST_TESTTASKS_LIBGPIODTEST_H_ +#define TEST_TESTTASKS_LIBGPIODTEST_H_ #include "TestTask.h" #include "GpioIF.h" @@ -10,10 +10,10 @@ * @brief Test for the GPIO read implementation of the LinuxLibgpioIF. * @author J. Meier */ -class LibgpioTest: public TestTask { +class LibgpiodTest: public TestTask { public: - LibgpioTest(object_id_t objectId, object_id_t gpioIfobjectId, GpioCookie* gpioCookie); - virtual ~LibgpioTest(); + LibgpiodTest(object_id_t objectId, object_id_t gpioIfobjectId, GpioCookie* gpioCookie); + virtual ~LibgpiodTest(); protected: virtual ReturnValue_t performPeriodicAction() override; @@ -22,4 +22,4 @@ private: GpioIF* gpioInterface; }; -#endif /* TEST_TESTTASKS_LIBGPIOTEST_H_ */ +#endif /* TEST_TESTTASKS_LIBGPIODTEST_H_ */ diff --git a/tmtc b/tmtc index 4433fb68..110ec964 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 4433fb68ac268ab72f763c2ef80b13d84600ad47 +Subproject commit 110ec9644a520af9c6f4cb7f2b5d47f3d34ba256