From cb9e9d3ec02487164d96c8d58eda2ae8058322c1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 14 Feb 2021 12:35:08 +0100 Subject: [PATCH] added new linux folder --- CMakeLists.txt | 7 +++ bsp_q7s/ObjectFactory.cpp | 20 +++---- bsp_q7s/boardtest/LibgpiodTest.h | 4 +- bsp_q7s/gpio/CMakeLists.txt | 7 --- bsp_q7s/gpio/LinuxLibgpioIF.cpp | 10 ++-- bsp_q7s/gpio/LinuxLibgpioIF.h | 4 +- linux/CMakeLists.txt | 2 + linux/gpio/CMakeLists.txt | 7 +++ .../cookies => linux/gpio}/GpioCookie.cpp | 2 +- .../gpio/cookies => linux/gpio}/GpioCookie.h | 52 +++++++++---------- {bsp_q7s => linux}/gpio/GpioIF.h | 0 11 files changed, 62 insertions(+), 53 deletions(-) create mode 100644 linux/CMakeLists.txt create mode 100644 linux/gpio/CMakeLists.txt rename {bsp_q7s/gpio/cookies => linux/gpio}/GpioCookie.cpp (93%) rename {bsp_q7s/gpio/cookies => linux/gpio}/GpioCookie.h (68%) rename {bsp_q7s => linux}/gpio/GpioIF.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec6dc555..0c726931 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,8 +44,10 @@ set(FSFW_PATH fsfw) set(MISSION_PATH mission) set(CSPLIB_PATH libcsp) set(TEST_PATH test/testtasks) +set(LINUX_PATH linux) set(FSFW_WARNING_SHADOW_LOCAL_GCC OFF) +set(ADD_LINUX_FILES FALSE) # Analyse different OS and architecture/target options, determine BSP_PATH, # display information about compiler etc. @@ -61,6 +63,7 @@ if(TGT_BSP) if(${TGT_BSP} MATCHES "arm/q7s") set(ADD_CSP_LIB TRUE) endif() + set(ADD_LINUX_FILES TRUE) else() # Required by FSFW library set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig") @@ -82,6 +85,10 @@ if(ADD_CSP_LIB) add_subdirectory(${CSPLIB_PATH}) endif() +if(ADD_LINUX_FILES) + add_subdirectory(${LINUX_PATH}) +endif() + add_subdirectory(${BSP_PATH}) add_subdirectory(${FSFW_PATH}) add_subdirectory(${MISSION_PATH}) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 5dde01d3..8b14fb24 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -115,37 +115,37 @@ void ObjectFactory::produce(){ #if TE0720 == 0 /* Pin H2-11 on stack connector */ GpioConfig_t gpioConfigHeater0(std::string("gpiochip7"), 18, - std::string("Heater0"), Gpio::OUT, 0); + 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, 0); + 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, 0); + std::string("Heater2"), gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_2, gpioConfigHeater2); GpioConfig_t gpioConfigHeater3(std::string("gpiochip7"), 16, - std::string("Heater3"), Gpio::OUT, 0); + std::string("Heater3"), gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_3, gpioConfigHeater3); GpioConfig_t gpioConfigHeater4(std::string("gpiochip7"), 24, - std::string("Heater4"), Gpio::OUT, 0); + std::string("Heater4"), gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_4, gpioConfigHeater4); GpioConfig_t gpioConfigHeater5(std::string("gpiochip7"), 26, - std::string("Heater5"), Gpio::OUT, 0); + std::string("Heater5"), gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_5, gpioConfigHeater5); GpioConfig_t gpioConfigHeater6(std::string("gpiochip7"), 22, - std::string("Heater6"), Gpio::OUT, 0); + std::string("Heater6"), gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_6, gpioConfigHeater6); GpioConfig_t gpioConfigHeater7(std::string("gpiochip7"), 28, - std::string("Heater7"), Gpio::OUT, 0); + std::string("Heater7"), gpio::OUT, 0); gpioCookie->addGpio(gpioIds::HEATER_7, gpioConfigHeater7); new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER, @@ -160,13 +160,13 @@ void ObjectFactory::produce(){ #if TE0720 == 1 && TEST_LIBGPIOD == 1 /* Configure MIO0 as input */ GpioConfig_t gpioConfigMio0(std::string("gpiochip0"), 0, - std::string("MIO0"), Gpio::IN, 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); + 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); diff --git a/bsp_q7s/boardtest/LibgpiodTest.h b/bsp_q7s/boardtest/LibgpiodTest.h index c64f25a3..bc87a5c4 100644 --- a/bsp_q7s/boardtest/LibgpiodTest.h +++ b/bsp_q7s/boardtest/LibgpiodTest.h @@ -2,8 +2,8 @@ #define TEST_TESTTASKS_LIBGPIODTEST_H_ #include "TestTask.h" -#include "GpioIF.h" -#include "GpioCookie.h" +#include +#include #include /** diff --git a/bsp_q7s/gpio/CMakeLists.txt b/bsp_q7s/gpio/CMakeLists.txt index 3b789394..1041cea7 100644 --- a/bsp_q7s/gpio/CMakeLists.txt +++ b/bsp_q7s/gpio/CMakeLists.txt @@ -1,11 +1,4 @@ target_sources(${TARGET_NAME} PUBLIC - cookies/GpioCookie.cpp 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 97159315..97d0cc12 100644 --- a/bsp_q7s/gpio/LinuxLibgpioIF.cpp +++ b/bsp_q7s/gpio/LinuxLibgpioIF.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "LinuxLibgpioIF.h" +#include #include #include @@ -49,7 +49,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap* mapToAdd) { std::string chipname; unsigned int lineNum; struct gpiod_chip *chip; - Gpio::Direction direction; + gpio::Direction direction; std::string consumer; struct gpiod_line *lineHandle; int result; @@ -77,7 +77,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap* mapToAdd) { consumer = mapToAddIter->second.consumer; /* Configure direction and add a description to the GPIO */ switch (direction) { - case Gpio::OUT: + case gpio::OUT: result = gpiod_line_request_output(lineHandle, consumer.c_str(), mapToAddIter->second.initValue); if (result < 0) { @@ -88,7 +88,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap* mapToAdd) { return RETURN_FAILED; } break; - case Gpio::IN: + case gpio::IN: result = gpiod_line_request_input(lineHandle, consumer.c_str()); if (result < 0) { sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line " diff --git a/bsp_q7s/gpio/LinuxLibgpioIF.h b/bsp_q7s/gpio/LinuxLibgpioIF.h index f8cc1a09..f91a35ca 100644 --- a/bsp_q7s/gpio/LinuxLibgpioIF.h +++ b/bsp_q7s/gpio/LinuxLibgpioIF.h @@ -1,9 +1,9 @@ #ifndef BSP_Q7S_GPIO_LINUXLIBGPIOIF_H_ #define BSP_Q7S_GPIO_LINUXLIBGPIOIF_H_ -#include +#include +#include #include -#include #include /** diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt new file mode 100644 index 00000000..c102da2f --- /dev/null +++ b/linux/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(gpio) + diff --git a/linux/gpio/CMakeLists.txt b/linux/gpio/CMakeLists.txt new file mode 100644 index 00000000..642555fe --- /dev/null +++ b/linux/gpio/CMakeLists.txt @@ -0,0 +1,7 @@ +target_sources(${TARGET_NAME} PUBLIC + GpioCookie.cpp +) + + + + diff --git a/bsp_q7s/gpio/cookies/GpioCookie.cpp b/linux/gpio/GpioCookie.cpp similarity index 93% rename from bsp_q7s/gpio/cookies/GpioCookie.cpp rename to linux/gpio/GpioCookie.cpp index 36760c4d..f4e585d1 100644 --- a/bsp_q7s/gpio/cookies/GpioCookie.cpp +++ b/linux/gpio/GpioCookie.cpp @@ -1,4 +1,4 @@ -#include +#include "GpioCookie.h" #include GpioCookie::GpioCookie() { diff --git a/bsp_q7s/gpio/cookies/GpioCookie.h b/linux/gpio/GpioCookie.h similarity index 68% rename from bsp_q7s/gpio/cookies/GpioCookie.h rename to linux/gpio/GpioCookie.h index acc360e0..72011750 100644 --- a/bsp_q7s/gpio/cookies/GpioCookie.h +++ b/linux/gpio/GpioCookie.h @@ -1,17 +1,17 @@ #ifndef SAM9G20_COMIF_COOKIES_GPIO_COOKIE_H_ #define SAM9G20_COMIF_COOKIES_GPIO_COOKIE_H_ +#include "GpioIF.h" #include -#include #include #include #include -namespace Gpio { - enum Direction { - IN = 0, - OUT = 1 - }; +namespace gpio { +enum Direction { + IN = 0, + OUT = 1 +}; } /** @@ -29,17 +29,17 @@ namespace Gpio { * pointer. */ typedef struct GpioConfig { - GpioConfig(std::string chipname_, int lineNum_, std::string consumer_, - Gpio::Direction direction_, int initValue_) : - chipname(chipname_), lineNum(lineNum_), consumer(consumer_), direction( - direction_), initValue(initValue_) { - } - std::string chipname; - int lineNum; - std::string consumer; - Gpio::Direction direction; - int initValue; - struct gpiod_line* lineHandle; + GpioConfig(std::string chipname_, int lineNum_, std::string consumer_, + gpio::Direction direction_, int initValue_) : + chipname(chipname_), lineNum(lineNum_), consumer(consumer_), direction(direction_), + initValue(initValue_) { + } + std::string chipname; + int lineNum; + std::string consumer; + gpio::Direction direction; + int initValue; + struct gpiod_line* lineHandle = nullptr; } GpioConfig_t; using GpioMap = std::unordered_map; using GpioMapIter = GpioMap::iterator; @@ -57,20 +57,20 @@ using GpioMapIter = GpioMap::iterator; class GpioCookie: public CookieIF { public: - GpioCookie(); + GpioCookie(); - virtual ~GpioCookie(); + virtual ~GpioCookie(); - void addGpio(gpioId_t gpioId, GpioConfig_t gpioConfig); - /** - * @brief Get map with registered GPIOs. - */ - GpioMap getGpioMap() const; + void addGpio(gpioId_t gpioId, GpioConfig_t gpioConfig); + /** + * @brief Get map with registered GPIOs. + */ + GpioMap getGpioMap() const; private: - GpioMap gpioMap; - GpioMapIter gpioMapIter; + GpioMap gpioMap; + GpioMapIter gpioMapIter; }; #endif diff --git a/bsp_q7s/gpio/GpioIF.h b/linux/gpio/GpioIF.h similarity index 100% rename from bsp_q7s/gpio/GpioIF.h rename to linux/gpio/GpioIF.h