diff --git a/CHANGELOG b/CHANGELOG index 09b8db6a1..8f86c147d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,17 +1,81 @@ -## Changes from ASTP 1.0.0 to 1.1.0 +# Changed from ASTP 1.1.0 to 1.2.0 + +## API Changes + +### FSFW Architecture + +- New src folder which contains all source files except the HAL, contributed code and test code +- External and internal API mostly stayed the same +- Folder names are now all smaller case: internalError was renamed to internalerror and + FreeRTOS was renamed to freertos +- Warning if optional headers are used but the modules was not added to the source files to compile + +### HAL + +- HAL added back into FSFW. It is tightly bound to the FSFW, and compiling it as a static library + made using it more complicated than necessary + +## Bugfixes + +### FreeRTOS QueueMapManager + +- Fixed a bug which causes the first generated Queue ID to be invalid + +## Enhancements + +### FSFW Architecture + +- See API changes chapter. This change will keep the internal API consistent in the future + +# Changes from ASTP 1.0.0 to 1.1.0 + +## API Changes ### PUS - Added PUS C support +- SUBSYSTEM_IDs added for PUS Services +- Added new Parameter which must be defined in config: fsfwconfig::FSFW_MAX_TM_PACKET_SIZE + +### ObjectManager + + - ObjectManager is now a singelton + ### Configuration - Additional configuration option fsfwconfig::FSFW_MAX_TM_PACKET_SIZE which need to be specified in FSFWConfig.h +### CMake + +- Changed Cmake FSFW_ADDITIONAL_INC_PATH to FSFW_ADDITIONAL_INC_PATHS + +## Bugfixes + +- timemanager/TimeStamperIF.h: Timestamp config was not used correctly, leading to different timestamp sizes than configured in fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE +- TCP server fixes + +## Enhancements + +### FreeRTOS Queue Handles + +- Fixed an internal issue how FreeRTOS MessageQueues were handled + +### Linux OSAL + +- Better printf error messages + +### CMake + +- Check for C++11 as mininimum required Version + +### Debug Output + +- Changed Warning color to magenta, which is well readable on both dark and light mode IDEs -## Changes from ASTP 0.0.1 to 1.0.0 +# Changes from ASTP 0.0.1 to 1.0.0 ### Host OSAL diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ba73a3f6..5ff66a6d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,20 +3,33 @@ cmake_minimum_required(VERSION 3.13) option(FSFW_GENERATE_SECTIONS "Generate function and data sections. Required to remove unused code" ON ) - if(FSFW_GENERATE_SECTIONS) option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON) endif() option(FSFW_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON) # Options to exclude parts of the FSFW from compilation. -option(FSFW_USE_RMAP "Compile with RMAP" ON) -option(FSFW_USE_DATALINKLAYER "Compile with Data Link Layer" ON) +option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON) +option(FSFW_ADD_UNITTESTS "Add regular unittests. Requires Catch2" OFF) +option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON) + +# Optional sources +option(FSFW_ADD_PUS "Compile with PUS sources" ON) +option(FSFW_ADD_MONITORING "Compile with monitoring components" ON) + +option(FSFW_ADD_RMAP "Compile with RMAP" OFF) +option(FSFW_ADD_DATALINKLAYER "Compile with Data Link Layer" OFF) +option(FSFW_ADD_COORDINATES "Compile with coordinate components" OFF) +option(FSFW_ADD_TMSTORAGE "Compile with tm storage components" OFF) + +# Contrib sources +option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF) set(LIB_FSFW_NAME fsfw) add_library(${LIB_FSFW_NAME}) +set(FSFW_CORE_INC_PATH "inc") -set_property(CACHE OS_FSFW PROPERTY STRINGS host linux rtems freertos) +set_property(CACHE FSFW_OSAL PROPERTY STRINGS host linux rtems freertos) if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) @@ -25,100 +38,61 @@ elseif(${CMAKE_CXX_STANDARD} LESS 11) message(FATAL_ERROR "Compiling the FSFW requires a minimum of C++11 support") endif() -if(NOT OS_FSFW) - message(STATUS "No OS for FSFW via OS_FSFW set. Assuming host OS") +# Backwards comptability +if(OS_FSFW AND NOT FSFW_OSAL) + message(WARNING "Please pass the FSFW OSAL as FSFW_OSAL instead of OS_FSFW") + set(FSFW_OSAL OS_FSFW) +endif() + +if(NOT FSFW_OSAL) + message(STATUS "No OS for FSFW via FSFW_OSAL set. Assuming host OS") # Assume host OS and autodetermine from OS_FSFW if(UNIX) - set(OS_FSFW "linux" + set(FSFW_OSAL "linux" CACHE STRING "OS abstraction layer used in the FSFW" ) elseif(WIN32) - set(OS_FSFW "host" + set(FSFW_OSAL "host" CACHE STRING "OS abstraction layer used in the FSFW" ) endif() endif() -set(FSFW_OSAL_DEFINITION FSFW_HOST) +set(FSFW_OSAL_DEFINITION FSFW_OSAL_HOST) -if(${OS_FSFW} STREQUAL host) - set(OS_FSFW_NAME "Host") -elseif(${OS_FSFW} STREQUAL linux) - set(OS_FSFW_NAME "Linux") - set(FSFW_OSAL_DEFINITION FSFW_LINUX) -elseif(${OS_FSFW} STREQUAL freertos) - set(OS_FSFW_NAME "FreeRTOS") - set(FSFW_OSAL_DEFINITION FSFW_FREERTOS) - target_link_libraries(${LIB_FSFW_NAME} PRIVATE +if(FSFW_OSAL MATCHES host) + set(OS_FSFW_NAME "Host") + set(FSFW_OSAL_HOST ON) +elseif(FSFW_OSAL MATCHES linux) + set(OS_FSFW_NAME "Linux") + set(FSFW_OSAL_LINUX ON) +elseif(FSFW_OSAL MATCHES freertos) + set(OS_FSFW_NAME "FreeRTOS") + set(FSFW_OSAL_FREERTOS ON) + target_link_libraries(${LIB_FSFW_NAME} PRIVATE ${LIB_OS_NAME} - ) -elseif(${OS_FSFW} STREQUAL rtems) - set(OS_FSFW_NAME "RTEMS") - set(FSFW_OSAL_DEFINITION FSFW_RTEMS) + ) +elseif(FSFW_OSAL STREQUAL rtems) + set(OS_FSFW_NAME "RTEMS") + set(FSFW_OSAL_RTEMS ON) else() - message(WARNING - "Invalid operating system for FSFW specified! Setting to host.." - ) - set(OS_FSFW_NAME "Host") - set(OS_FSFW "host") + message(WARNING + "Invalid operating system for FSFW specified! Setting to host.." + ) + set(OS_FSFW_NAME "Host") + set(OS_FSFW "host") endif() -target_compile_definitions(${LIB_FSFW_NAME} PRIVATE - ${FSFW_OSAL_DEFINITION} -) - -target_compile_definitions(${LIB_FSFW_NAME} INTERFACE - ${FSFW_OSAL_DEFINITION} -) - message(STATUS "Compiling FSFW for the ${OS_FSFW_NAME} operating system.") -add_subdirectory(action) -add_subdirectory(container) -add_subdirectory(controller) -add_subdirectory(coordinates) - -if(FSFW_USE_DATALINKLAYER) - add_subdirectory(datalinklayer) +add_subdirectory(src) +add_subdirectory(tests) +if(FSFW_ADD_HAL) + add_subdirectory(hal) endif() - -add_subdirectory(datapool) -add_subdirectory(datapoollocal) -add_subdirectory(housekeeping) -add_subdirectory(devicehandlers) -add_subdirectory(events) -add_subdirectory(fdir) -add_subdirectory(globalfunctions) -add_subdirectory(health) -add_subdirectory(internalError) -add_subdirectory(ipc) -add_subdirectory(memory) -add_subdirectory(modes) -add_subdirectory(monitoring) -add_subdirectory(objectmanager) -add_subdirectory(osal) -add_subdirectory(parameters) -add_subdirectory(power) -add_subdirectory(pus) - -if(FSFW_USE_RMAP) - add_subdirectory(rmap) -endif() - -add_subdirectory(serialize) -add_subdirectory(serviceinterface) -add_subdirectory(storagemanager) -add_subdirectory(subsystem) -add_subdirectory(tasks) -add_subdirectory(tcdistribution) -add_subdirectory(thermal) -add_subdirectory(timemanager) -add_subdirectory(tmstorage) -add_subdirectory(tmtcpacket) -add_subdirectory(tmtcservices) -add_subdirectory(unittest) +add_subdirectory(contrib) # The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it. # If this is not given, we include the default configuration and emit a warning. @@ -191,6 +165,7 @@ endif() target_include_directories(${LIB_FSFW_NAME} INTERFACE ${CMAKE_SOURCE_DIR} ${FSFW_CONFIG_PATH_ABSOLUTE} + ${FSFW_CORE_INC_PATH} ${FSFW_ADD_INC_PATHS_ABS} ) @@ -200,6 +175,7 @@ target_include_directories(${LIB_FSFW_NAME} INTERFACE target_include_directories(${LIB_FSFW_NAME} PRIVATE ${CMAKE_SOURCE_DIR} ${FSFW_CONFIG_PATH_ABSOLUTE} + ${FSFW_CORE_INC_PATH} ${FSFW_ADD_INC_PATHS_ABS} ) diff --git a/FSFW.h b/FSFW.h deleted file mode 100644 index df06ff3df..000000000 --- a/FSFW.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef FSFW_FSFW_H_ -#define FSFW_FSFW_H_ - -#include "FSFWConfig.h" - - -#endif /* FSFW_FSFW_H_ */ diff --git a/FSFWVersion.h b/FSFWVersion.h deleted file mode 100644 index df2d49a51..000000000 --- a/FSFWVersion.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef FSFW_DEFAULTCFG_VERSION_H_ -#define FSFW_DEFAULTCFG_VERSION_H_ - -const char* const FSFW_VERSION_NAME = "ASTP"; - -#define FSFW_VERSION 1 -#define FSFW_SUBVERSION 0 -#define FSFW_REVISION 0 - - - -#endif /* FSFW_DEFAULTCFG_VERSION_H_ */ diff --git a/README.md b/README.md index 484d65c07..48d2b8e7f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![FSFW Logo](logo/FSFW_Logo_V3_bw.png) +![FSFW Logo](misc/logo/FSFW_Logo_V3_bw.png) # Flight Software Framework (FSFW) diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt new file mode 100644 index 000000000..e83da6afa --- /dev/null +++ b/contrib/CMakeLists.txt @@ -0,0 +1,9 @@ +target_include_directories(${LIB_FSFW_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_include_directories(${LIB_FSFW_NAME} INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_subdirectory(fsfw_contrib) diff --git a/contrib/fsfw_contrib/CMakeLists.txt b/contrib/fsfw_contrib/CMakeLists.txt new file mode 100644 index 000000000..3a7e4182a --- /dev/null +++ b/contrib/fsfw_contrib/CMakeLists.txt @@ -0,0 +1,11 @@ +if(FSFW_ADD_SGP4_PROPAGATOR) + target_sources(${LIB_FSFW_NAME} PRIVATE + sgp4/sgp4unit.cpp + ) + target_include_directories(${LIB_FSFW_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/sgp4 + ) + target_include_directories(${LIB_FSFW_NAME} INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/sgp4 + ) +endif() diff --git a/contrib/sgp4/LICENSE b/contrib/fsfw_contrib/sgp4/LICENSE similarity index 100% rename from contrib/sgp4/LICENSE rename to contrib/fsfw_contrib/sgp4/LICENSE diff --git a/contrib/sgp4/sgp4unit.cpp b/contrib/fsfw_contrib/sgp4/sgp4unit.cpp similarity index 100% rename from contrib/sgp4/sgp4unit.cpp rename to contrib/fsfw_contrib/sgp4/sgp4unit.cpp diff --git a/contrib/sgp4/sgp4unit.h b/contrib/fsfw_contrib/sgp4/sgp4unit.h similarity index 100% rename from contrib/sgp4/sgp4unit.h rename to contrib/fsfw_contrib/sgp4/sgp4unit.h diff --git a/datapoollocal/datapoollocal.h b/datapoollocal/datapoollocal.h deleted file mode 100644 index c5c470788..000000000 --- a/datapoollocal/datapoollocal.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ -#define FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ - -/* Collected related headers */ -#include "LocalPoolVariable.h" -#include "LocalPoolVector.h" -#include "StaticLocalDataSet.h" -#include "LocalDataSet.h" -#include "SharedLocalDataSet.h" - - -#endif /* FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ */ diff --git a/defaultcfg/fsfwconfig/fsfwconfig.mk b/defaultcfg/fsfwconfig/fsfwconfig.mk deleted file mode 100644 index 51543eba8..000000000 --- a/defaultcfg/fsfwconfig/fsfwconfig.mk +++ /dev/null @@ -1,15 +0,0 @@ -CXXSRC += $(wildcard $(CURRENTPATH)/ipc/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/objects/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/pollingsequence/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/events/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/tmtc/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/devices/*.cpp) - -INCLUDES += $(CURRENTPATH) -INCLUDES += $(CURRENTPATH)/objects -INCLUDES += $(CURRENTPATH)/returnvalues -INCLUDES += $(CURRENTPATH)/tmtc -INCLUDES += $(CURRENTPATH)/events -INCLUDES += $(CURRENTPATH)/devices -INCLUDES += $(CURRENTPATH)/pollingsequence -INCLUDES += $(CURRENTPATH)/ipc diff --git a/events/CMakeLists.txt b/events/CMakeLists.txt deleted file mode 100644 index 4e935167a..000000000 --- a/events/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -target_sources(${LIB_FSFW_NAME} - PRIVATE - EventManager.cpp - EventMessage.cpp -) - -add_subdirectory(eventmatching) \ No newline at end of file diff --git a/fsfw.mk b/fsfw.mk deleted file mode 100644 index 0d72fae14..000000000 --- a/fsfw.mk +++ /dev/null @@ -1,75 +0,0 @@ -# This submake file needs to be included by the primary Makefile. -# This file needs FRAMEWORK_PATH and OS_FSFW set correctly by another Makefile. -# Valid API settings: rtems, linux, freeRTOS, host - -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/action/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/container/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/contrib/sgp4/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/controller/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/coordinates/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datalinklayer/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapool/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapoollocal/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapoollocal/internal/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/housekeeping/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/devicehandlers/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/events/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/events/eventmatching/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/fdir/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/globalfunctions/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/globalfunctions/matching/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/globalfunctions/math/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/health/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/internalError/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/ipc/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/memory/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/modes/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/monitoring/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/objectmanager/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/*.cpp) - -# select the OS -ifeq ($(OS_FSFW),rtems) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/rtems/*.cpp) - -else ifeq ($(OS_FSFW),linux) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/linux/*.cpp) - -else ifeq ($(OS_FSFW),freeRTOS) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/FreeRTOS/*.cpp) - -else ifeq ($(OS_FSFW),host) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/host/*.cpp) -ifeq ($(OS),Windows_NT) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/windows/*.cpp) -else -# For now, the linux UDP bridge sources needs to be included manually by upper makefile -# for host OS because we can't be sure the OS is linux. -# Following lines can be used to do this: -# CXXSRC += $(FRAMEWORK_PATH)/osal/linux/TcUnixUdpPollingTask.cpp -# CXXSRC += $(FRAMEWORK_PATH)/osal/linux/TmTcUnixUdpBridge.cpp -endif - -else -$(error invalid OS_FSFW specified, valid OS_FSFW are rtems, linux, freeRTOS, host) -endif - -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/parameters/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/power/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/returnvalues/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/rmap/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/serialize/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/serviceinterface/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/storagemanager/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/subsystem/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/subsystem/modes/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tasks/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tcdistribution/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/thermal/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/timemanager/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmstorage/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/packetmatcher/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/pus/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcservices/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/pus/*.cpp) diff --git a/globalfunctions/DleEncoder.cpp b/globalfunctions/DleEncoder.cpp deleted file mode 100644 index 8520389d2..000000000 --- a/globalfunctions/DleEncoder.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include "../globalfunctions/DleEncoder.h" - -DleEncoder::DleEncoder() {} - -DleEncoder::~DleEncoder() {} - -ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream, - size_t sourceLen, uint8_t* destStream, size_t maxDestLen, - size_t* encodedLen, bool addStxEtx) { - if (maxDestLen < 2) { - return STREAM_TOO_SHORT; - } - size_t encodedIndex = 0, sourceIndex = 0; - uint8_t nextByte; - if (addStxEtx) { - destStream[0] = STX_CHAR; - ++encodedIndex; - } - - while (encodedIndex < maxDestLen and sourceIndex < sourceLen) - { - nextByte = sourceStream[sourceIndex]; - // STX, ETX and CR characters in the stream need to be escaped with DLE - if (nextByte == STX_CHAR or nextByte == ETX_CHAR or nextByte == CARRIAGE_RETURN) { - if (encodedIndex + 1 >= maxDestLen) { - return STREAM_TOO_SHORT; - } - else { - destStream[encodedIndex] = DLE_CHAR; - ++encodedIndex; - /* Escaped byte will be actual byte + 0x40. This prevents - * STX, ETX, and carriage return characters from appearing - * in the encoded data stream at all, so when polling an - * encoded stream, the transmission can be stopped at ETX. - * 0x40 was chosen at random with special requirements: - * - Prevent going from one control char to another - * - Prevent overflow for common characters */ - destStream[encodedIndex] = nextByte + 0x40; - } - } - // DLE characters are simply escaped with DLE. - else if (nextByte == DLE_CHAR) { - if (encodedIndex + 1 >= maxDestLen) { - return STREAM_TOO_SHORT; - } - else { - destStream[encodedIndex] = DLE_CHAR; - ++encodedIndex; - destStream[encodedIndex] = DLE_CHAR; - } - } - else { - destStream[encodedIndex] = nextByte; - } - ++encodedIndex; - ++sourceIndex; - } - - if (sourceIndex == sourceLen and encodedIndex < maxDestLen) { - if (addStxEtx) { - destStream[encodedIndex] = ETX_CHAR; - ++encodedIndex; - } - *encodedLen = encodedIndex; - return RETURN_OK; - } - else { - return STREAM_TOO_SHORT; - } -} - -ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream, - size_t sourceStreamLen, size_t *readLen, uint8_t *destStream, - size_t maxDestStreamlen, size_t *decodedLen) { - size_t encodedIndex = 0, decodedIndex = 0; - uint8_t nextByte; - if (*sourceStream != STX_CHAR) { - return DECODING_ERROR; - } - ++encodedIndex; - - while ((encodedIndex < sourceStreamLen) && (decodedIndex < maxDestStreamlen) - && (sourceStream[encodedIndex] != ETX_CHAR) - && (sourceStream[encodedIndex] != STX_CHAR)) { - if (sourceStream[encodedIndex] == DLE_CHAR) { - nextByte = sourceStream[encodedIndex + 1]; - // The next byte is a DLE character that was escaped by another - // DLE character, so we can write it to the destination stream. - if (nextByte == DLE_CHAR) { - destStream[decodedIndex] = nextByte; - } - else { - /* The next byte is a STX, DTX or 0x0D character which - * was escaped by a DLE character. The actual byte was - * also encoded by adding + 0x40 to prevent having control chars, - * in the stream at all, so we convert it back. */ - if (nextByte == 0x42 or nextByte == 0x43 or nextByte == 0x4D) { - destStream[decodedIndex] = nextByte - 0x40; - } - else { - return DECODING_ERROR; - } - } - ++encodedIndex; - } - else { - destStream[decodedIndex] = sourceStream[encodedIndex]; - } - - ++encodedIndex; - ++decodedIndex; - } - - if (sourceStream[encodedIndex] != ETX_CHAR) { - *readLen = ++encodedIndex; - return DECODING_ERROR; - } - else { - *readLen = ++encodedIndex; - *decodedLen = decodedIndex; - return RETURN_OK; - } -} - diff --git a/globalfunctions/DleEncoder.h b/globalfunctions/DleEncoder.h deleted file mode 100644 index 6d073f9a2..000000000 --- a/globalfunctions/DleEncoder.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ -#define FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ - -#include "../returnvalues/HasReturnvaluesIF.h" -#include - -/** - * @brief This DLE Encoder (Data Link Encoder) can be used to encode and - * decode arbitrary data with ASCII control characters - * @details - * List of control codes: - * https://en.wikipedia.org/wiki/C0_and_C1_control_codes - * - * This encoder can be used to achieve a basic transport layer when using - * char based transmission systems. - * The passed source strean is converted into a encoded stream by adding - * a STX marker at the start of the stream and an ETX marker at the end of - * the stream. Any STX, ETX, DLE and CR occurrences in the source stream are - * escaped by a DLE character. The encoder also replaces escaped control chars - * by another char, so STX, ETX and CR should not appear anywhere in the actual - * encoded data stream. - * - * When using a strictly char based reception of packets encoded with DLE, - * STX can be used to notify a reader that actual data will start to arrive - * while ETX can be used to notify the reader that the data has ended. - */ -class DleEncoder: public HasReturnvaluesIF { -private: - DleEncoder(); - virtual ~DleEncoder(); - -public: - static constexpr uint8_t INTERFACE_ID = CLASS_ID::DLE_ENCODER; - static constexpr ReturnValue_t STREAM_TOO_SHORT = MAKE_RETURN_CODE(0x01); - static constexpr ReturnValue_t DECODING_ERROR = MAKE_RETURN_CODE(0x02); - - //! Start Of Text character. First character is encoded stream - static constexpr uint8_t STX_CHAR = 0x02; - //! End Of Text character. Last character in encoded stream - static constexpr uint8_t ETX_CHAR = 0x03; - //! Data Link Escape character. Used to escape STX, ETX and DLE occurrences - //! in the source stream. - static constexpr uint8_t DLE_CHAR = 0x10; - static constexpr uint8_t CARRIAGE_RETURN = 0x0D; - - /** - * Encodes the give data stream by preceding it with the STX marker - * and ending it with an ETX marker. STX, ETX and DLE characters inside - * the stream are escaped by DLE characters and also replaced by adding - * 0x40 (which is reverted in the decoding process). - * @param sourceStream - * @param sourceLen - * @param destStream - * @param maxDestLen - * @param encodedLen - * @param addStxEtx - * Adding STX and ETX can be omitted, if they are added manually. - * @return - */ - static ReturnValue_t encode(const uint8_t *sourceStream, size_t sourceLen, - uint8_t *destStream, size_t maxDestLen, size_t *encodedLen, - bool addStxEtx = true); - - /** - * Converts an encoded stream back. - * @param sourceStream - * @param sourceStreamLen - * @param readLen - * @param destStream - * @param maxDestStreamlen - * @param decodedLen - * @return - */ - static ReturnValue_t decode(const uint8_t *sourceStream, - size_t sourceStreamLen, size_t *readLen, uint8_t *destStream, - size_t maxDestStreamlen, size_t *decodedLen); -}; - -#endif /* FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ */ diff --git a/hal/CMakeLists.txt b/hal/CMakeLists.txt new file mode 100644 index 000000000..7a9a0ffaa --- /dev/null +++ b/hal/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.13) + +# Can also be changed by upper CMakeLists.txt file +find_library(LIB_FSFW_NAME fsfw REQUIRED) + +option(FSFW_HAL_ADD_LINUX "Add the Linux HAL to the sources. Required gpiod library" OFF) +option(FSFW_HAL_ADD_RASPBERRY_PI "Add Raspberry Pi specific code to the sources" OFF) +option(FSFW_HAL_ADD_STM32H7 "Add the STM32H7 HAL to the sources" OFF) +option(FSFW_HAL_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON) + +set(LINUX_HAL_PATH_NAME linux) +set(STM32H7_PATH_NAME stm32h7) + +add_subdirectory(src) + +foreach(INCLUDE_PATH ${FSFW_HAL_ADDITIONAL_INC_PATHS}) + if(IS_ABSOLUTE ${INCLUDE_PATH}) + set(CURR_ABS_INC_PATH "${INCLUDE_PATH}") + else() + get_filename_component(CURR_ABS_INC_PATH + ${INCLUDE_PATH} REALPATH BASE_DIR ${CMAKE_SOURCE_DIR}) + endif() + + if(CMAKE_VERBOSE) + message(STATUS "FSFW include path: ${CURR_ABS_INC_PATH}") + endif() + + list(APPEND FSFW_HAL_ADD_INC_PATHS_ABS ${CURR_ABS_INC_PATH}) +endforeach() + +target_include_directories(${LIB_FSFW_NAME} PRIVATE + ${FSFW_HAL_ADD_INC_PATHS_ABS} +) + +target_compile_definitions(${LIB_FSFW_NAME} PRIVATE + ${FSFW_HAL_DEFINES} +) + +target_link_libraries(${LIB_FSFW_NAME} PRIVATE + ${FSFW_HAL_LINK_LIBS} +) diff --git a/hal/src/CMakeLists.txt b/hal/src/CMakeLists.txt new file mode 100644 index 000000000..76ee45c6d --- /dev/null +++ b/hal/src/CMakeLists.txt @@ -0,0 +1,9 @@ +target_include_directories(${LIB_FSFW_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_include_directories(${LIB_FSFW_NAME} INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_subdirectory(fsfw_hal) diff --git a/hal/src/fsfw_hal/CMakeLists.txt b/hal/src/fsfw_hal/CMakeLists.txt new file mode 100644 index 000000000..f5901e91d --- /dev/null +++ b/hal/src/fsfw_hal/CMakeLists.txt @@ -0,0 +1,10 @@ +add_subdirectory(devicehandlers) +add_subdirectory(common) + +if(FSFW_HAL_ADD_LINUX) + add_subdirectory(linux) +endif() + +if(FSFW_HAL_ADD_STM32H7) + add_subdirectory(stm32h7) +endif() diff --git a/hal/src/fsfw_hal/common/CMakeLists.txt b/hal/src/fsfw_hal/common/CMakeLists.txt new file mode 100644 index 000000000..f1cfec526 --- /dev/null +++ b/hal/src/fsfw_hal/common/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(gpio) diff --git a/hal/src/fsfw_hal/common/gpio/CMakeLists.txt b/hal/src/fsfw_hal/common/gpio/CMakeLists.txt new file mode 100644 index 000000000..098c05fa1 --- /dev/null +++ b/hal/src/fsfw_hal/common/gpio/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + GpioCookie.cpp +) \ No newline at end of file diff --git a/hal/src/fsfw_hal/common/gpio/GpioCookie.cpp b/hal/src/fsfw_hal/common/gpio/GpioCookie.cpp new file mode 100644 index 000000000..7c56ebcfe --- /dev/null +++ b/hal/src/fsfw_hal/common/gpio/GpioCookie.cpp @@ -0,0 +1,50 @@ +#include "fsfw_hal/common/gpio/GpioCookie.h" +#include "fsfw/serviceinterface/ServiceInterface.h" + +GpioCookie::GpioCookie() { +} + +ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) { + if (gpioConfig == nullptr) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "GpioCookie::addGpio: gpioConfig is nullpointer" << std::endl; +#else + sif::printWarning("GpioCookie::addGpio: gpioConfig is nullpointer\n"); +#endif + return HasReturnvaluesIF::RETURN_FAILED; + } + auto gpioMapIter = gpioMap.find(gpioId); + if(gpioMapIter == gpioMap.end()) { + auto statusPair = gpioMap.emplace(gpioId, gpioConfig); + if (statusPair.second == false) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "GpioCookie::addGpio: Failed to add GPIO " << gpioId << + " to GPIO map" << std::endl; +#else + sif::printWarning("GpioCookie::addGpio: Failed to add GPIO %d to GPIO map\n", gpioId); +#endif +#endif + return HasReturnvaluesIF::RETURN_FAILED; + } + return HasReturnvaluesIF::RETURN_OK; + } +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "GpioCookie::addGpio: GPIO already exists in GPIO map " << std::endl; +#else + sif::printWarning("GpioCookie::addGpio: GPIO already exists in GPIO map\n"); +#endif +#endif + return HasReturnvaluesIF::RETURN_FAILED; +} + +GpioMap GpioCookie::getGpioMap() const { + return gpioMap; +} + +GpioCookie::~GpioCookie() { + for(auto& config: gpioMap) { + delete(config.second); + } +} diff --git a/hal/src/fsfw_hal/common/gpio/GpioCookie.h b/hal/src/fsfw_hal/common/gpio/GpioCookie.h new file mode 100644 index 000000000..0473fe0f2 --- /dev/null +++ b/hal/src/fsfw_hal/common/gpio/GpioCookie.h @@ -0,0 +1,41 @@ +#ifndef COMMON_GPIO_GPIOCOOKIE_H_ +#define COMMON_GPIO_GPIOCOOKIE_H_ + +#include "GpioIF.h" +#include "gpioDefinitions.h" + +#include +#include + +/** + * @brief Cookie for the GpioIF. Allows the GpioIF to determine which + * GPIOs to initialize and whether they should be configured as in- or + * output. + * @details One GpioCookie can hold multiple GPIO configurations. To add a new + * GPIO configuration to a GpioCookie use the GpioCookie::addGpio + * function. + * + * @author J. Meier + */ +class GpioCookie: public CookieIF { +public: + + GpioCookie(); + + virtual ~GpioCookie(); + + ReturnValue_t addGpio(gpioId_t gpioId, GpioBase* gpioConfig); + + /** + * @brief Get map with registered GPIOs. + */ + GpioMap getGpioMap() const; + +private: + /** + * Returns a copy of the internal GPIO map. + */ + GpioMap gpioMap; +}; + +#endif /* COMMON_GPIO_GPIOCOOKIE_H_ */ diff --git a/hal/src/fsfw_hal/common/gpio/GpioIF.h b/hal/src/fsfw_hal/common/gpio/GpioIF.h new file mode 100644 index 000000000..af73f94c5 --- /dev/null +++ b/hal/src/fsfw_hal/common/gpio/GpioIF.h @@ -0,0 +1,54 @@ +#ifndef COMMON_GPIO_GPIOIF_H_ +#define COMMON_GPIO_GPIOIF_H_ + +#include "gpioDefinitions.h" +#include +#include + +class GpioCookie; + +/** + * @brief This class defines the interface for objects requiring the control + * over GPIOs. + * @author J. Meier + */ +class GpioIF : public HasReturnvaluesIF { +public: + + virtual ~GpioIF() {}; + + /** + * @brief Called by the GPIO using object. + * @param cookie Cookie specifying informations of the GPIOs required + * by a object. + */ + virtual ReturnValue_t addGpios(GpioCookie* cookie) = 0; + + /** + * @brief By implementing this function a child must provide the + * functionality to pull a certain GPIO to high logic level. + * + * @param gpioId A unique number which specifies the GPIO to drive. + * @return Returns RETURN_OK for success. This should never return RETURN_FAILED. + */ + virtual ReturnValue_t pullHigh(gpioId_t gpioId) = 0; + + /** + * @brief By implementing this function a child must provide the + * functionality to pull a certain GPIO to low logic level. + * + * @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 functionality 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 /* COMMON_GPIO_GPIOIF_H_ */ diff --git a/hal/src/fsfw_hal/common/gpio/gpioDefinitions.h b/hal/src/fsfw_hal/common/gpio/gpioDefinitions.h new file mode 100644 index 000000000..688d9c9bf --- /dev/null +++ b/hal/src/fsfw_hal/common/gpio/gpioDefinitions.h @@ -0,0 +1,140 @@ +#ifndef COMMON_GPIO_GPIODEFINITIONS_H_ +#define COMMON_GPIO_GPIODEFINITIONS_H_ + +#include +#include +#include + +using gpioId_t = uint16_t; + +namespace gpio { + +enum Levels { + LOW = 0, + HIGH = 1 +}; + +enum Direction { + IN = 0, + OUT = 1 +}; + +enum GpioOperation { + READ, + WRITE +}; + +enum GpioTypes { + NONE, + GPIO_REGULAR_BY_CHIP, + GPIO_REGULAR_BY_LABEL, + CALLBACK +}; + +static constexpr gpioId_t NO_GPIO = -1; + +using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args); + +} + +/** + * @brief Struct containing information about the GPIO to use. This is + * required by the libgpiod to access and drive a GPIO. + * @param chipname String of the chipname specifying the group which contains 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. 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. + */ +class GpioBase { +public: + + GpioBase() = default; + + GpioBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction, + int initValue): + gpioType(gpioType), consumer(consumer),direction(direction), initValue(initValue) {} + + virtual~ GpioBase() {}; + + // Can be used to cast GpioBase to a concrete child implementation + gpio::GpioTypes gpioType = gpio::GpioTypes::NONE; + std::string consumer; + gpio::Direction direction = gpio::Direction::IN; + int initValue = 0; +}; + +class GpiodRegularBase: public GpioBase { +public: + GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction, + int initValue, int lineNum): GpioBase(gpioType, consumer, direction, initValue), + lineNum(lineNum) { + } + int lineNum = 0; + struct gpiod_line* lineHandle = nullptr; +}; + +class GpiodRegularByChip: public GpiodRegularBase { +public: + GpiodRegularByChip() : + GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, + std::string(), gpio::Direction::IN, gpio::LOW, 0) { + } + + GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_, + gpio::Direction direction_, int initValue_) : + GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, + consumer_, direction_, initValue_, lineNum_), + chipname(chipname_){ + } + + GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_) : + GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_, + gpio::Direction::IN, gpio::LOW, lineNum_), + chipname(chipname_) { + } + + std::string chipname; +}; + +class GpiodRegularByLabel: public GpiodRegularBase { +public: + GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_, + gpio::Direction direction_, int initValue_) : + GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_, + direction_, initValue_, lineNum_), + label(label_) { + } + + GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_) : + GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_, + gpio::Direction::IN, gpio::LOW, lineNum_), + label(label_) { + } + + std::string label; +}; + +class GpioCallback: public GpioBase { +public: + GpioCallback(std::string consumer, gpio::Direction direction_, int initValue_, + gpio::gpio_cb_t callback, void* callbackArgs): + GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_), + callback(callback), callbackArgs(callbackArgs) {} + + gpio::gpio_cb_t callback = nullptr; + void* callbackArgs = nullptr; +}; + + +using GpioMap = std::map; +using GpioUnorderedMap = std::unordered_map; +using GpioMapIter = GpioMap::iterator; +using GpioUnorderedMapIter = GpioUnorderedMap::iterator; + +#endif /* LINUX_GPIO_GPIODEFINITIONS_H_ */ diff --git a/hal/src/fsfw_hal/common/spi/spiCommon.h b/hal/src/fsfw_hal/common/spi/spiCommon.h new file mode 100644 index 000000000..9b3aef6a2 --- /dev/null +++ b/hal/src/fsfw_hal/common/spi/spiCommon.h @@ -0,0 +1,17 @@ +#ifndef FSFW_HAL_COMMON_SPI_SPICOMMON_H_ +#define FSFW_HAL_COMMON_SPI_SPICOMMON_H_ + +#include + +namespace spi { + +enum SpiModes: uint8_t { + MODE_0, + MODE_1, + MODE_2, + MODE_3 +}; + +} + +#endif /* FSFW_HAL_COMMON_SPI_SPICOMMON_H_ */ diff --git a/hal/src/fsfw_hal/devicehandlers/CMakeLists.txt b/hal/src/fsfw_hal/devicehandlers/CMakeLists.txt new file mode 100644 index 000000000..94e67c722 --- /dev/null +++ b/hal/src/fsfw_hal/devicehandlers/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + GyroL3GD20Handler.cpp + MgmRM3100Handler.cpp + MgmLIS3MDLHandler.cpp +) diff --git a/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp b/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp new file mode 100644 index 000000000..d27351d72 --- /dev/null +++ b/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.cpp @@ -0,0 +1,287 @@ +#include "GyroL3GD20Handler.h" + +#include "fsfw/datapool/PoolReadGuard.h" + +#include + +GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication, + CookieIF *comCookie, uint32_t transitionDelayMs): + DeviceHandlerBase(objectId, deviceCommunication, comCookie), + transitionDelayMs(transitionDelayMs), dataset(this) { +#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1 + debugDivider = new PeriodicOperationDivider(3); +#endif +} + +GyroHandlerL3GD20H::~GyroHandlerL3GD20H() {} + +void GyroHandlerL3GD20H::doStartUp() { + if(internalState == InternalState::NONE) { + internalState = InternalState::CONFIGURE; + } + + if(internalState == InternalState::CONFIGURE) { + if(commandExecuted) { + internalState = InternalState::CHECK_REGS; + commandExecuted = false; + } + } + + if(internalState == InternalState::CHECK_REGS) { + if(commandExecuted) { + internalState = InternalState::NORMAL; + if(goNormalModeImmediately) { + setMode(MODE_NORMAL); + } + else { + setMode(_MODE_TO_ON); + } + commandExecuted = false; + } + } +} + +void GyroHandlerL3GD20H::doShutDown() { + setMode(_MODE_POWER_DOWN); +} + +ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t *id) { + switch(internalState) { + case(InternalState::NONE): + case(InternalState::NORMAL): { + return NOTHING_TO_SEND; + } + case(InternalState::CONFIGURE): { + *id = L3GD20H::CONFIGURE_CTRL_REGS; + uint8_t command [5]; + command[0] = L3GD20H::CTRL_REG_1_VAL; + command[1] = L3GD20H::CTRL_REG_2_VAL; + command[2] = L3GD20H::CTRL_REG_3_VAL; + command[3] = L3GD20H::CTRL_REG_4_VAL; + command[4] = L3GD20H::CTRL_REG_5_VAL; + return buildCommandFromCommand(*id, command, 5); + } + case(InternalState::CHECK_REGS): { + *id = L3GD20H::READ_REGS; + return buildCommandFromCommand(*id, nullptr, 0); + } + default: +#if FSFW_CPP_OSTREAM_ENABLED == 1 + /* Might be a configuration error. */ + sif::warning << "GyroL3GD20Handler::buildTransitionDeviceCommand: " + "Unknown internal state!" << std::endl; +#else + sif::printDebug("GyroL3GD20Handler::buildTransitionDeviceCommand: " + "Unknown internal state!\n"); +#endif + return HasReturnvaluesIF::RETURN_OK; + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t GyroHandlerL3GD20H::buildNormalDeviceCommand(DeviceCommandId_t *id) { + *id = L3GD20H::READ_REGS; + return buildCommandFromCommand(*id, nullptr, 0); +} + +ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t *commandData, + size_t commandDataLen) { + switch(deviceCommand) { + case(L3GD20H::READ_REGS): { + commandBuffer[0] = L3GD20H::READ_START | L3GD20H::AUTO_INCREMENT_MASK | L3GD20H::READ_MASK; + std::memset(commandBuffer + 1, 0, L3GD20H::READ_LEN); + rawPacket = commandBuffer; + rawPacketLen = L3GD20H::READ_LEN + 1; + break; + } + case(L3GD20H::CONFIGURE_CTRL_REGS): { + commandBuffer[0] = L3GD20H::CTRL_REG_1 | L3GD20H::AUTO_INCREMENT_MASK; + if(commandData == nullptr or commandDataLen != 5) { + return DeviceHandlerIF::INVALID_COMMAND_PARAMETER; + } + + ctrlReg1Value = commandData[0]; + ctrlReg2Value = commandData[1]; + ctrlReg3Value = commandData[2]; + ctrlReg4Value = commandData[3]; + ctrlReg5Value = commandData[4]; + + bool fsH = ctrlReg4Value & L3GD20H::SET_FS_1; + bool fsL = ctrlReg4Value & L3GD20H::SET_FS_0; + + if(not fsH and not fsL) { + sensitivity = L3GD20H::SENSITIVITY_00; + } + else if(not fsH and fsL) { + sensitivity = L3GD20H::SENSITIVITY_01; + } + else { + sensitivity = L3GD20H::SENSITIVITY_11; + } + + commandBuffer[1] = ctrlReg1Value; + commandBuffer[2] = ctrlReg2Value; + commandBuffer[3] = ctrlReg3Value; + commandBuffer[4] = ctrlReg4Value; + commandBuffer[5] = ctrlReg5Value; + + rawPacket = commandBuffer; + rawPacketLen = 6; + break; + } + case(L3GD20H::READ_CTRL_REGS): { + commandBuffer[0] = L3GD20H::READ_START | L3GD20H::AUTO_INCREMENT_MASK | + L3GD20H::READ_MASK; + + std::memset(commandBuffer + 1, 0, 5); + rawPacket = commandBuffer; + rawPacketLen = 6; + break; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t GyroHandlerL3GD20H::scanForReply(const uint8_t *start, size_t len, + DeviceCommandId_t *foundId, size_t *foundLen) { + // For SPI, the ID will always be the one of the last sent command + *foundId = this->getPendingCommand(); + *foundLen = this->rawPacketLen; + + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + switch(id) { + case(L3GD20H::CONFIGURE_CTRL_REGS): { + commandExecuted = true; + break; + } + case(L3GD20H::READ_CTRL_REGS): { + if(packet[1] == ctrlReg1Value and packet[2] == ctrlReg2Value and + packet[3] == ctrlReg3Value and packet[4] == ctrlReg4Value and + packet[5] == ctrlReg5Value) { + commandExecuted = true; + } + else { + // Attempt reconfiguration + internalState = InternalState::CONFIGURE; + return DeviceHandlerIF::DEVICE_REPLY_INVALID; + } + break; + } + case(L3GD20H::READ_REGS): { + if(packet[1] != ctrlReg1Value and packet[2] != ctrlReg2Value and + packet[3] != ctrlReg3Value and packet[4] != ctrlReg4Value and + packet[5] != ctrlReg5Value) { + return DeviceHandlerIF::DEVICE_REPLY_INVALID; + } + else { + if(internalState == InternalState::CHECK_REGS) { + commandExecuted = true; + } + } + + statusReg = packet[L3GD20H::STATUS_IDX]; + + int16_t angVelocXRaw = packet[L3GD20H::OUT_X_H] << 8 | packet[L3GD20H::OUT_X_L]; + int16_t angVelocYRaw = packet[L3GD20H::OUT_Y_H] << 8 | packet[L3GD20H::OUT_Y_L]; + int16_t angVelocZRaw = packet[L3GD20H::OUT_Z_H] << 8 | packet[L3GD20H::OUT_Z_L]; + float angVelocX = angVelocXRaw * sensitivity; + float angVelocY = angVelocYRaw * sensitivity; + float angVelocZ = angVelocZRaw * sensitivity; + + int8_t temperaturOffset = (-1) * packet[L3GD20H::TEMPERATURE_IDX]; + float temperature = 25.0 + temperaturOffset; +#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1 + if(debugDivider->checkAndIncrement()) { + /* Set terminal to utf-8 if there is an issue with micro printout. */ +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "GyroHandlerL3GD20H: Angular velocities (deg/s):" << std::endl; + sif::info << "X: " << angVelocX << std::endl; + sif::info << "Y: " << angVelocY << std::endl; + sif::info << "Z: " << angVelocZ << std::endl; +#else + sif::printInfo("GyroHandlerL3GD20H: Angular velocities (deg/s):\n"); + sif::printInfo("X: %f\n", angVelocX); + sif::printInfo("Y: %f\n", angVelocY); + sif::printInfo("Z: %f\n", angVelocZ); +#endif + } +#endif + + PoolReadGuard readSet(&dataset); + if(readSet.getReadResult() == HasReturnvaluesIF::RETURN_OK) { + if(std::abs(angVelocX) < this->absLimitX) { + dataset.angVelocX = angVelocX; + dataset.angVelocX.setValid(true); + } + else { + dataset.angVelocX.setValid(false); + } + + if(std::abs(angVelocY) < this->absLimitY) { + dataset.angVelocY = angVelocY; + dataset.angVelocY.setValid(true); + } + else { + dataset.angVelocY.setValid(false); + } + + if(std::abs(angVelocZ) < this->absLimitZ) { + dataset.angVelocZ = angVelocZ; + dataset.angVelocZ.setValid(true); + } + else { + dataset.angVelocZ.setValid(false); + } + + dataset.temperature = temperature; + dataset.temperature.setValid(true); + } + break; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return result; +} + + +uint32_t GyroHandlerL3GD20H::getTransitionDelayMs(Mode_t from, Mode_t to) { + return this->transitionDelayMs; +} + +void GyroHandlerL3GD20H::setToGoToNormalMode(bool enable) { + this->goNormalModeImmediately = true; +} + +ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool( + localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { + localDataPoolMap.emplace(L3GD20H::ANG_VELOC_X, new PoolEntry({0.0})); + localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Y, new PoolEntry({0.0})); + localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Z, new PoolEntry({0.0})); + localDataPoolMap.emplace(L3GD20H::TEMPERATURE, new PoolEntry({0.0})); + return HasReturnvaluesIF::RETURN_OK; +} + +void GyroHandlerL3GD20H::fillCommandAndReplyMap() { + insertInCommandAndReplyMap(L3GD20H::READ_REGS, 1, &dataset); + insertInCommandAndReplyMap(L3GD20H::CONFIGURE_CTRL_REGS, 1); + insertInCommandAndReplyMap(L3GD20H::READ_CTRL_REGS, 1); +} + +void GyroHandlerL3GD20H::modeChanged() { + internalState = InternalState::NONE; +} + +void GyroHandlerL3GD20H::setAbsoluteLimits(float limitX, float limitY, float limitZ) { + this->absLimitX = limitX; + this->absLimitY = limitY; + this->absLimitZ = limitZ; +} diff --git a/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.h b/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.h new file mode 100644 index 000000000..e73d2fbbf --- /dev/null +++ b/hal/src/fsfw_hal/devicehandlers/GyroL3GD20Handler.h @@ -0,0 +1,99 @@ +#ifndef MISSION_DEVICES_GYROL3GD20HANDLER_H_ +#define MISSION_DEVICES_GYROL3GD20HANDLER_H_ + +#include "fsfw/FSFW.h" +#include "devicedefinitions/GyroL3GD20Definitions.h" + +#include +#include + +/** + * @brief Device Handler for the L3GD20H gyroscope sensor + * (https://www.st.com/en/mems-and-sensors/l3gd20h.html) + * @details + * Advanced documentation: + * https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/L3GD20H_Gyro + * + * Data is read big endian with the smallest possible range of 245 degrees per second. + */ +class GyroHandlerL3GD20H: public DeviceHandlerBase { +public: + GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication, + CookieIF* comCookie, uint32_t transitionDelayMs); + virtual ~GyroHandlerL3GD20H(); + + /** + * Set the absolute limit for the values on the axis in degrees per second. + * The dataset values will be marked as invalid if that limit is exceeded + * @param xLimit + * @param yLimit + * @param zLimit + */ + void setAbsoluteLimits(float limitX, float limitY, float limitZ); + + /** + * @brief Configure device handler to go to normal mode immediately + */ + void setToGoToNormalMode(bool enable); +protected: + + /* DeviceHandlerBase overrides */ + ReturnValue_t buildTransitionDeviceCommand( + DeviceCommandId_t *id) override; + void doStartUp() override; + void doShutDown() override; + ReturnValue_t buildNormalDeviceCommand( + DeviceCommandId_t *id) override; + ReturnValue_t buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t *commandData, + size_t commandDataLen) override; + ReturnValue_t scanForReply(const uint8_t *start, size_t len, + DeviceCommandId_t *foundId, size_t *foundLen) override; + virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) override; + + void fillCommandAndReplyMap() override; + void modeChanged() override; + virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) override; + +private: + uint32_t transitionDelayMs = 0; + GyroPrimaryDataset dataset; + + float absLimitX = L3GD20H::RANGE_DPS_00; + float absLimitY = L3GD20H::RANGE_DPS_00; + float absLimitZ = L3GD20H::RANGE_DPS_00; + + enum class InternalState { + NONE, + CONFIGURE, + CHECK_REGS, + NORMAL + }; + InternalState internalState = InternalState::NONE; + bool commandExecuted = false; + + uint8_t statusReg = 0; + bool goNormalModeImmediately = false; + + uint8_t ctrlReg1Value = L3GD20H::CTRL_REG_1_VAL; + uint8_t ctrlReg2Value = L3GD20H::CTRL_REG_2_VAL; + uint8_t ctrlReg3Value = L3GD20H::CTRL_REG_3_VAL; + uint8_t ctrlReg4Value = L3GD20H::CTRL_REG_4_VAL; + uint8_t ctrlReg5Value = L3GD20H::CTRL_REG_5_VAL; + + uint8_t commandBuffer[L3GD20H::READ_LEN + 1]; + + // Set default value + float sensitivity = L3GD20H::SENSITIVITY_00; + +#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1 + PeriodicOperationDivider* debugDivider = nullptr; +#endif +}; + + + +#endif /* MISSION_DEVICES_GYROL3GD20HANDLER_H_ */ diff --git a/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp new file mode 100644 index 000000000..804e83f2e --- /dev/null +++ b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp @@ -0,0 +1,520 @@ +#include "MgmLIS3MDLHandler.h" + +#include "fsfw/datapool/PoolReadGuard.h" +#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 +#include "fsfw/globalfunctions/PeriodicOperationDivider.h" +#endif + +#include + +MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCommunication, + CookieIF* comCookie, uint32_t transitionDelay): + DeviceHandlerBase(objectId, deviceCommunication, comCookie), + dataset(this), transitionDelay(transitionDelay) { +#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 + debugDivider = new PeriodicOperationDivider(3); +#endif + // Set to default values right away + registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; + registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; + registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT; + registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT; + registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT; + +} + +MgmLIS3MDLHandler::~MgmLIS3MDLHandler() { +} + + +void MgmLIS3MDLHandler::doStartUp() { + switch (internalState) { + case(InternalState::STATE_NONE): { + internalState = InternalState::STATE_FIRST_CONTACT; + break; + } + case(InternalState::STATE_FIRST_CONTACT): { + /* Will be set by checking device ID (WHO AM I register) */ + if(commandExecuted) { + commandExecuted = false; + internalState = InternalState::STATE_SETUP; + } + break; + } + case(InternalState::STATE_SETUP): { + internalState = InternalState::STATE_CHECK_REGISTERS; + break; + } + case(InternalState::STATE_CHECK_REGISTERS): { + /* Set up cached registers which will be used to configure the MGM. */ + if(commandExecuted) { + commandExecuted = false; + if(goToNormalMode) { + setMode(MODE_NORMAL); + } + else { + setMode(_MODE_TO_ON); + } + } + break; + } + default: + break; + } + +} + +void MgmLIS3MDLHandler::doShutDown() { + setMode(_MODE_POWER_DOWN); +} + +ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand( + DeviceCommandId_t *id) { + switch (internalState) { + case(InternalState::STATE_NONE): + case(InternalState::STATE_NORMAL): { + return HasReturnvaluesIF::RETURN_OK; + } + case(InternalState::STATE_FIRST_CONTACT): { + *id = MGMLIS3MDL::IDENTIFY_DEVICE; + break; + } + case(InternalState::STATE_SETUP): { + *id = MGMLIS3MDL::SETUP_MGM; + break; + } + case(InternalState::STATE_CHECK_REGISTERS): { + *id = MGMLIS3MDL::READ_CONFIG_AND_DATA; + break; + } + default: { + /* might be a configuration error. */ +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "GyroHandler::buildTransitionDeviceCommand: Unknown internal state!" << + std::endl; +#else + sif::printWarning("GyroHandler::buildTransitionDeviceCommand: Unknown internal state!\n"); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + return HasReturnvaluesIF::RETURN_OK; + } + + } + return buildCommandFromCommand(*id, NULL, 0); +} + +uint8_t MgmLIS3MDLHandler::readCommand(uint8_t command, bool continuousCom) { + command |= (1 << MGMLIS3MDL::RW_BIT); + if (continuousCom == true) { + command |= (1 << MGMLIS3MDL::MS_BIT); + } + return command; +} + +uint8_t MgmLIS3MDLHandler::writeCommand(uint8_t command, bool continuousCom) { + command &= ~(1 << MGMLIS3MDL::RW_BIT); + if (continuousCom == true) { + command |= (1 << MGMLIS3MDL::MS_BIT); + } + return command; +} + +void MgmLIS3MDLHandler::setupMgm() { + + registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; + registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; + registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT; + registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT; + registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT; + + prepareCtrlRegisterWrite(); +} + +ReturnValue_t MgmLIS3MDLHandler::buildNormalDeviceCommand( + DeviceCommandId_t *id) { + // Data/config register will be read in an alternating manner. + if(communicationStep == CommunicationStep::DATA) { + *id = MGMLIS3MDL::READ_CONFIG_AND_DATA; + communicationStep = CommunicationStep::TEMPERATURE; + return buildCommandFromCommand(*id, NULL, 0); + } + else { + *id = MGMLIS3MDL::READ_TEMPERATURE; + communicationStep = CommunicationStep::DATA; + return buildCommandFromCommand(*id, NULL, 0); + } + +} + +ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t *commandData, + size_t commandDataLen) { + switch(deviceCommand) { + case(MGMLIS3MDL::READ_CONFIG_AND_DATA): { + std::memset(commandBuffer, 0, sizeof(commandBuffer)); + commandBuffer[0] = readCommand(MGMLIS3MDL::CTRL_REG1, true); + + rawPacket = commandBuffer; + rawPacketLen = MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1; + return RETURN_OK; + } + case(MGMLIS3MDL::READ_TEMPERATURE): { + std::memset(commandBuffer, 0, 3); + commandBuffer[0] = readCommand(MGMLIS3MDL::TEMP_LOWBYTE, true); + + rawPacket = commandBuffer; + rawPacketLen = 3; + return RETURN_OK; + } + case(MGMLIS3MDL::IDENTIFY_DEVICE): { + return identifyDevice(); + } + case(MGMLIS3MDL::TEMP_SENSOR_ENABLE): { + return enableTemperatureSensor(commandData, commandDataLen); + } + case(MGMLIS3MDL::SETUP_MGM): { + setupMgm(); + return HasReturnvaluesIF::RETURN_OK; + } + case(MGMLIS3MDL::ACCURACY_OP_MODE_SET): { + return setOperatingMode(commandData, commandDataLen); + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; +} + +ReturnValue_t MgmLIS3MDLHandler::identifyDevice() { + uint32_t size = 2; + commandBuffer[0] = readCommand(MGMLIS3MDL::IDENTIFY_DEVICE_REG_ADDR); + commandBuffer[1] = 0x00; + + rawPacket = commandBuffer; + rawPacketLen = size; + + return RETURN_OK; +} + +ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start, + size_t len, DeviceCommandId_t *foundId, size_t *foundLen) { + *foundLen = len; + if (len == MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1) { + *foundLen = len; + *foundId = MGMLIS3MDL::READ_CONFIG_AND_DATA; + // Check validity by checking config registers + if (start[1] != registers[0] or start[2] != registers[1] or + start[3] != registers[2] or start[4] != registers[3] or + start[5] != registers[4]) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "MGMHandlerLIS3MDL::scanForReply: Invalid registers!" << std::endl; +#else + sif::printWarning("MGMHandlerLIS3MDL::scanForReply: Invalid registers!\n"); +#endif +#endif + return DeviceHandlerIF::INVALID_DATA; + } + if(mode == _MODE_START_UP) { + commandExecuted = true; + } + + } + else if(len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) { + *foundLen = len; + *foundId = MGMLIS3MDL::READ_TEMPERATURE; + } + else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) { + *foundLen = len; + *foundId = MGMLIS3MDL::SETUP_MGM; + } + else if (len == SINGLE_COMMAND_ANSWER_LEN) { + *foundLen = len; + *foundId = getPendingCommand(); + if(*foundId == MGMLIS3MDL::IDENTIFY_DEVICE) { + if(start[1] != MGMLIS3MDL::DEVICE_ID) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "MGMHandlerLIS3MDL::scanForReply: " + "Device identification failed!" << std::endl; +#else + sif::printWarning("MGMHandlerLIS3MDL::scanForReply: " + "Device identification failed!\n"); +#endif +#endif + return DeviceHandlerIF::INVALID_DATA; + } + + if(mode == _MODE_START_UP) { + commandExecuted = true; + } + } + } + else { + return DeviceHandlerIF::INVALID_DATA; + } + + /* Data with SPI Interface always has this answer */ + if (start[0] == 0b11111111) { + return RETURN_OK; + } + else { + return DeviceHandlerIF::INVALID_DATA; + } + +} +ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) { + + switch (id) { + case MGMLIS3MDL::IDENTIFY_DEVICE: { + break; + } + case MGMLIS3MDL::SETUP_MGM: { + break; + } + case MGMLIS3MDL::READ_CONFIG_AND_DATA: { + // TODO: Store configuration in new local datasets. + float sensitivityFactor = getSensitivityFactor(getSensitivity(registers[2])); + + int16_t mgmMeasurementRawX = packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8 + | packet[MGMLIS3MDL::X_LOWBYTE_IDX] ; + int16_t mgmMeasurementRawY = packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8 + | packet[MGMLIS3MDL::Y_LOWBYTE_IDX] ; + int16_t mgmMeasurementRawZ = packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8 + | packet[MGMLIS3MDL::Z_LOWBYTE_IDX] ; + + /* Target value in microtesla */ + float mgmX = static_cast(mgmMeasurementRawX) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; + float mgmY = static_cast(mgmMeasurementRawY) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; + float mgmZ = static_cast(mgmMeasurementRawZ) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; + +#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 + if(debugDivider->checkAndIncrement()) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "MGMHandlerLIS3: Magnetic field strength in" + " microtesla:" << std::endl; + sif::info << "X: " << mgmX << " uT" << std::endl; + sif::info << "Y: " << mgmY << " uT" << std::endl; + sif::info << "Z: " << mgmZ << " uT" << std::endl; +#else + sif::printInfo("MGMHandlerLIS3: Magnetic field strength in microtesla:\n"); + sif::printInfo("X: %f uT\n", mgmX); + sif::printInfo("Y: %f uT\n", mgmY); + sif::printInfo("Z: %f uT\n", mgmZ); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 0 */ + } +#endif /* OBSW_VERBOSE_LEVEL >= 1 */ + PoolReadGuard readHelper(&dataset); + if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) { + if(std::abs(mgmX) < absLimitX) { + dataset.fieldStrengthX = mgmX; + dataset.fieldStrengthX.setValid(true); + } + else { + dataset.fieldStrengthX.setValid(false); + } + + if(std::abs(mgmY) < absLimitY) { + dataset.fieldStrengthY = mgmY; + dataset.fieldStrengthY.setValid(true); + } + else { + dataset.fieldStrengthY.setValid(false); + } + + if(std::abs(mgmZ) < absLimitZ) { + dataset.fieldStrengthZ = mgmZ; + dataset.fieldStrengthZ.setValid(true); + } + else { + dataset.fieldStrengthZ.setValid(false); + } + } + break; + } + + case MGMLIS3MDL::READ_TEMPERATURE: { + int16_t tempValueRaw = packet[2] << 8 | packet[1]; + float tempValue = 25.0 + ((static_cast(tempValueRaw)) / 8.0); + #if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 + if(debugDivider->check()) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" << + std::endl; +#else + sif::printInfo("MGMHandlerLIS3: Temperature: %f C\n"); +#endif + } +#endif + ReturnValue_t result = dataset.read(); + if(result == HasReturnvaluesIF::RETURN_OK) { + dataset.temperature = tempValue; + dataset.commit(); + } + break; + } + + default: { + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } + + } + return RETURN_OK; +} + +MGMLIS3MDL::Sensitivies MgmLIS3MDLHandler::getSensitivity(uint8_t ctrlRegister2) { + bool fs0Set = ctrlRegister2 & (1 << MGMLIS3MDL::FSO); // Checks if FS0 bit is set + bool fs1Set = ctrlRegister2 & (1 << MGMLIS3MDL::FS1); // Checks if FS1 bit is set + + if (fs0Set && fs1Set) + return MGMLIS3MDL::Sensitivies::GAUSS_16; + else if (!fs0Set && fs1Set) + return MGMLIS3MDL::Sensitivies::GAUSS_12; + else if (fs0Set && !fs1Set) + return MGMLIS3MDL::Sensitivies::GAUSS_8; + else + return MGMLIS3MDL::Sensitivies::GAUSS_4; +} + +float MgmLIS3MDLHandler::getSensitivityFactor(MGMLIS3MDL::Sensitivies sens) { + switch(sens) { + case(MGMLIS3MDL::GAUSS_4): { + return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_4_SENS; + } + case(MGMLIS3MDL::GAUSS_8): { + return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_8_SENS; + } + case(MGMLIS3MDL::GAUSS_12): { + return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_12_SENS; + } + case(MGMLIS3MDL::GAUSS_16): { + return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_16_SENS; + } + default: { + // Should never happen + return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_4_SENS; + } + } +} + + +ReturnValue_t MgmLIS3MDLHandler::enableTemperatureSensor( + const uint8_t *commandData, size_t commandDataLen) { + triggerEvent(CHANGE_OF_SETUP_PARAMETER); + uint32_t size = 2; + commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1); + if (commandDataLen > 1) { + return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; + } + switch (*commandData) { + case (MGMLIS3MDL::ON): { + commandBuffer[1] = registers[0] | (1 << 7); + break; + } + case (MGMLIS3MDL::OFF): { + commandBuffer[1] = registers[0] & ~(1 << 7); + break; + } + default: + return INVALID_COMMAND_PARAMETER; + } + registers[0] = commandBuffer[1]; + + rawPacket = commandBuffer; + rawPacketLen = size; + + return RETURN_OK; +} + +ReturnValue_t MgmLIS3MDLHandler::setOperatingMode(const uint8_t *commandData, + size_t commandDataLen) { + triggerEvent(CHANGE_OF_SETUP_PARAMETER); + if (commandDataLen != 1) { + return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; + } + + switch (commandData[0]) { + case MGMLIS3MDL::LOW: + registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) & (~(1 << MGMLIS3MDL::OM0)); + registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) & (~(1 << MGMLIS3MDL::OMZ0)); + break; + case MGMLIS3MDL::MEDIUM: + registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) | (1 << MGMLIS3MDL::OM0); + registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) | (1 << MGMLIS3MDL::OMZ0); + break; + + case MGMLIS3MDL::HIGH: + registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) & (~(1 << MGMLIS3MDL::OM0)); + registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) & (~(1 << MGMLIS3MDL::OMZ0)); + break; + + case MGMLIS3MDL::ULTRA: + registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) | (1 << MGMLIS3MDL::OM0); + registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) | (1 << MGMLIS3MDL::OMZ0); + break; + default: + break; + } + + return prepareCtrlRegisterWrite(); +} + +void MgmLIS3MDLHandler::fillCommandAndReplyMap() { + insertInCommandAndReplyMap(MGMLIS3MDL::READ_CONFIG_AND_DATA, 1, &dataset); + insertInCommandAndReplyMap(MGMLIS3MDL::READ_TEMPERATURE, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::SETUP_MGM, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::IDENTIFY_DEVICE, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::TEMP_SENSOR_ENABLE, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::ACCURACY_OP_MODE_SET, 1); +} + +void MgmLIS3MDLHandler::setToGoToNormalMode(bool enable) { + this->goToNormalMode = enable; +} + +ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() { + commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1, true); + + for (size_t i = 0; i < MGMLIS3MDL::NR_OF_CTRL_REGISTERS; i++) { + commandBuffer[i + 1] = registers[i]; + } + rawPacket = commandBuffer; + rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1; + + // We dont have to check if this is working because we just did i + return RETURN_OK; +} + +void MgmLIS3MDLHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { + +} + +uint32_t MgmLIS3MDLHandler::getTransitionDelayMs(Mode_t from, Mode_t to) { + return transitionDelay; +} + +void MgmLIS3MDLHandler::modeChanged(void) { + internalState = InternalState::STATE_NONE; +} + +ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool( + localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { + localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X, + new PoolEntry({0.0})); + localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, + new PoolEntry({0.0})); + localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, + new PoolEntry({0.0})); + localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, + new PoolEntry({0.0})); + return HasReturnvaluesIF::RETURN_OK; +} + +void MgmLIS3MDLHandler::setAbsoluteLimits(float xLimit, float yLimit, float zLimit) { + this->absLimitX = xLimit; + this->absLimitY = yLimit; + this->absLimitZ = zLimit; +} diff --git a/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h new file mode 100644 index 000000000..6bf89a494 --- /dev/null +++ b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h @@ -0,0 +1,186 @@ +#ifndef MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ +#define MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ + +#include "fsfw/FSFW.h" +#include "events/subsystemIdRanges.h" +#include "devicedefinitions/MgmLIS3HandlerDefs.h" + +#include "fsfw/devicehandlers/DeviceHandlerBase.h" + +class PeriodicOperationDivider; + +/** + * @brief Device handler object for the LIS3MDL 3-axis magnetometer + * by STMicroeletronics + * @details + * Datasheet can be found online by googling LIS3MDL. + * Flight manual: + * https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/LIS3MDL_MGM + * @author L. Loidold, R. Mueller + */ +class MgmLIS3MDLHandler: public DeviceHandlerBase { +public: + enum class CommunicationStep { + DATA, + TEMPERATURE + }; + + static const uint8_t INTERFACE_ID = CLASS_ID::MGM_LIS3MDL; + static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::MGM_LIS3MDL; + //Notifies a command to change the setup parameters + static const Event CHANGE_OF_SETUP_PARAMETER = MAKE_EVENT(0, severity::LOW); + + MgmLIS3MDLHandler(uint32_t objectId, object_id_t deviceCommunication, CookieIF* comCookie, + uint32_t transitionDelay); + virtual ~MgmLIS3MDLHandler(); + + /** + * Set the absolute limit for the values on the axis in microtesla. The dataset values will + * be marked as invalid if that limit is exceeded + * @param xLimit + * @param yLimit + * @param zLimit + */ + void setAbsoluteLimits(float xLimit, float yLimit, float zLimit); + void setToGoToNormalMode(bool enable); + +protected: + + /** DeviceHandlerBase overrides */ + void doShutDown() override; + void doStartUp() override; + void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override; + virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override; + ReturnValue_t buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t *commandData, + size_t commandDataLen) override; + ReturnValue_t buildTransitionDeviceCommand( + DeviceCommandId_t *id) override; + ReturnValue_t buildNormalDeviceCommand( + DeviceCommandId_t *id) override; + ReturnValue_t scanForReply(const uint8_t *start, size_t len, + DeviceCommandId_t *foundId, size_t *foundLen) override; + /** + * This implementation is tailored towards space applications and will flag values larger + * than 100 microtesla on X,Y and 150 microtesla on Z as invalid + * @param id + * @param packet + * @return + */ + virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) override; + void fillCommandAndReplyMap() override; + void modeChanged(void) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) override; + +private: + MGMLIS3MDL::MgmPrimaryDataset dataset; + //Length a single command SPI answer + static const uint8_t SINGLE_COMMAND_ANSWER_LEN = 2; + + uint32_t transitionDelay; + // Single SPI command has 2 bytes, first for adress, second for content + size_t singleComandSize = 2; + // Has the size for all adresses of the lis3mdl + the continous write bit + uint8_t commandBuffer[MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1]; + + float absLimitX = 100; + float absLimitY = 100; + float absLimitZ = 150; + + /** + * We want to save the registers we set, so we dont have to read the + * registers when we want to change something. + * --> everytime we change set a register we have to save it + */ + uint8_t registers[MGMLIS3MDL::NR_OF_CTRL_REGISTERS]; + + uint8_t statusRegister = 0; + bool goToNormalMode = false; + + enum class InternalState { + STATE_NONE, + STATE_FIRST_CONTACT, + STATE_SETUP, + STATE_CHECK_REGISTERS, + STATE_NORMAL + }; + + InternalState internalState = InternalState::STATE_NONE; + CommunicationStep communicationStep = CommunicationStep::DATA; + bool commandExecuted = false; + + /*------------------------------------------------------------------------*/ + /* Device specific commands and variables */ + /*------------------------------------------------------------------------*/ + /** + * Sets the read bit for the command + * @param single command to set the read-bit at + * @param boolean to select a continuous read bit, default = false + */ + uint8_t readCommand(uint8_t command, bool continuousCom = false); + + /** + * Sets the write bit for the command + * @param single command to set the write-bit at + * @param boolean to select a continuous write bit, default = false + */ + uint8_t writeCommand(uint8_t command, bool continuousCom = false); + + /** + * This Method gets the full scale for the measurement range + * e.g.: +- 4 gauss. See p.25 datasheet. + * @return The ReturnValue does not contain the sign of the value + */ + MGMLIS3MDL::Sensitivies getSensitivity(uint8_t ctrlReg2); + + /** + * The 16 bit value needs to be multiplied with a sensitivity factor + * which depends on the sensitivity configuration + * + * @param sens Configured sensitivity of the LIS3 device + * @return Multiplication factor to get the sensor value from raw data. + */ + float getSensitivityFactor(MGMLIS3MDL::Sensitivies sens); + + /** + * This Command detects the device ID + */ + ReturnValue_t identifyDevice(); + + virtual void setupMgm(); + + /*------------------------------------------------------------------------*/ + /* Non normal commands */ + /*------------------------------------------------------------------------*/ + /** + * Enables/Disables the integrated Temperaturesensor + * @param commandData On or Off + * @param length of the commandData: has to be 1 + */ + virtual ReturnValue_t enableTemperatureSensor(const uint8_t *commandData, + size_t commandDataLen); + + /** + * Sets the accuracy of the measurement of the axis. The noise is changing. + * @param commandData LOW, MEDIUM, HIGH, ULTRA + * @param length of the command, has to be 1 + */ + virtual ReturnValue_t setOperatingMode(const uint8_t *commandData, + size_t commandDataLen); + + /** + * We always update all registers together, so this method updates + * the rawpacket and rawpacketLen, so we just manipulate the local + * saved register + * + */ + ReturnValue_t prepareCtrlRegisterWrite(); + +#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 + PeriodicOperationDivider* debugDivider; +#endif +}; + +#endif /* MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ */ diff --git a/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp b/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp new file mode 100644 index 000000000..124eebbc8 --- /dev/null +++ b/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp @@ -0,0 +1,376 @@ +#include "MgmRM3100Handler.h" + +#include "fsfw/datapool/PoolReadGuard.h" +#include "fsfw/globalfunctions/bitutility.h" +#include "fsfw/devicehandlers/DeviceHandlerMessage.h" +#include "fsfw/objectmanager/SystemObjectIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" + + +MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId, + object_id_t deviceCommunication, CookieIF* comCookie, uint32_t transitionDelay): + DeviceHandlerBase(objectId, deviceCommunication, comCookie), + primaryDataset(this), transitionDelay(transitionDelay) { +#if FSFW_HAL_RM3100_MGM_DEBUG == 1 + debugDivider = new PeriodicOperationDivider(3); +#endif +} + +MgmRM3100Handler::~MgmRM3100Handler() {} + +void MgmRM3100Handler::doStartUp() { + switch(internalState) { + case(InternalState::NONE): { + internalState = InternalState::CONFIGURE_CMM; + break; + } + case(InternalState::CONFIGURE_CMM): { + internalState = InternalState::READ_CMM; + break; + } + case(InternalState::READ_CMM): { + if(commandExecuted) { + internalState = InternalState::STATE_CONFIGURE_TMRC; + } + break; + } + case(InternalState::STATE_CONFIGURE_TMRC): { + if(commandExecuted) { + internalState = InternalState::STATE_READ_TMRC; + } + break; + } + case(InternalState::STATE_READ_TMRC): { + if(commandExecuted) { + internalState = InternalState::NORMAL; + if(goToNormalModeAtStartup) { + setMode(MODE_NORMAL); + } + else { + setMode(_MODE_TO_ON); + } + } + break; + } + default: { + break; + } + } +} + +void MgmRM3100Handler::doShutDown() { + setMode(_MODE_POWER_DOWN); +} + +ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand( + DeviceCommandId_t *id) { + size_t commandLen = 0; + switch(internalState) { + case(InternalState::NONE): + case(InternalState::NORMAL): { + return NOTHING_TO_SEND; + } + case(InternalState::CONFIGURE_CMM): { + *id = RM3100::CONFIGURE_CMM; + break; + } + case(InternalState::READ_CMM): { + *id = RM3100::READ_CMM; + break; + } + case(InternalState::STATE_CONFIGURE_TMRC): { + commandBuffer[0] = RM3100::TMRC_DEFAULT_VALUE; + commandLen = 1; + *id = RM3100::CONFIGURE_TMRC; + break; + } + case(InternalState::STATE_READ_TMRC): { + *id = RM3100::READ_TMRC; + break; + } + default: +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + // Might be a configuration error + sif::warning << "MgmRM3100Handler::buildTransitionDeviceCommand: " + "Unknown internal state" << std::endl; +#else + sif::printWarning("MgmRM3100Handler::buildTransitionDeviceCommand: " + "Unknown internal state\n"); +#endif +#endif + return HasReturnvaluesIF::RETURN_OK; + } + + return buildCommandFromCommand(*id, commandBuffer, commandLen); +} + +ReturnValue_t MgmRM3100Handler::buildCommandFromCommand(DeviceCommandId_t deviceCommand, + const uint8_t *commandData, size_t commandDataLen) { + switch(deviceCommand) { + case(RM3100::CONFIGURE_CMM): { + commandBuffer[0] = RM3100::CMM_REGISTER; + commandBuffer[1] = RM3100::CMM_VALUE; + rawPacket = commandBuffer; + rawPacketLen = 2; + break; + } + case(RM3100::READ_CMM): { + commandBuffer[0] = RM3100::CMM_REGISTER | RM3100::READ_MASK; + commandBuffer[1] = 0; + rawPacket = commandBuffer; + rawPacketLen = 2; + break; + } + case(RM3100::CONFIGURE_TMRC): { + return handleTmrcConfigCommand(deviceCommand, commandData, commandDataLen); + } + case(RM3100::READ_TMRC): { + commandBuffer[0] = RM3100::TMRC_REGISTER | RM3100::READ_MASK; + commandBuffer[1] = 0; + rawPacket = commandBuffer; + rawPacketLen = 2; + break; + } + case(RM3100::CONFIGURE_CYCLE_COUNT): { + return handleCycleCountConfigCommand(deviceCommand, commandData, commandDataLen); + } + case(RM3100::READ_CYCLE_COUNT): { + commandBuffer[0] = RM3100::CYCLE_COUNT_START_REGISTER | RM3100::READ_MASK; + std::memset(commandBuffer + 1, 0, 6); + rawPacket = commandBuffer; + rawPacketLen = 7; + break; + } + case(RM3100::READ_DATA): { + commandBuffer[0] = RM3100::MEASUREMENT_REG_START | RM3100::READ_MASK; + std::memset(commandBuffer + 1, 0, 9); + rawPacketLen = 10; + break; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return RETURN_OK; +} + +ReturnValue_t MgmRM3100Handler::buildNormalDeviceCommand( + DeviceCommandId_t *id) { + *id = RM3100::READ_DATA; + return buildCommandFromCommand(*id, nullptr, 0); +} + +ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start, + size_t len, DeviceCommandId_t *foundId, + size_t *foundLen) { + + // For SPI, ID will always be the one of the last sent command + *foundId = this->getPendingCommand(); + *foundLen = len; + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + switch(id) { + case(RM3100::CONFIGURE_CMM): + case(RM3100::CONFIGURE_CYCLE_COUNT): + case(RM3100::CONFIGURE_TMRC): { + // We can only check whether write was successful with read operation + if(mode == _MODE_START_UP) { + commandExecuted = true; + } + break; + } + case(RM3100::READ_CMM): { + uint8_t cmmValue = packet[1]; + // We clear the seventh bit in any case + // because this one is zero sometimes for some reason + bitutil::bitClear(&cmmValue, 6); + if(cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) { + commandExecuted = true; + } + else { + // Attempt reconfiguration + internalState = InternalState::CONFIGURE_CMM; + return DeviceHandlerIF::DEVICE_REPLY_INVALID; + } + break; + } + case(RM3100::READ_TMRC): { + if(packet[1] == tmrcRegValue) { + commandExecuted = true; + // Reading TMRC was commanded. Trigger event to inform ground + if(mode != _MODE_START_UP) { + triggerEvent(tmrcSet, tmrcRegValue, 0); + } + } + else { + // Attempt reconfiguration + internalState = InternalState::STATE_CONFIGURE_TMRC; + return DeviceHandlerIF::DEVICE_REPLY_INVALID; + } + break; + } + case(RM3100::READ_CYCLE_COUNT): { + uint16_t cycleCountX = packet[1] << 8 | packet[2]; + uint16_t cycleCountY = packet[3] << 8 | packet[4]; + uint16_t cycleCountZ = packet[5] << 8 | packet[6]; + if(cycleCountX != cycleCountRegValueX or cycleCountY != cycleCountRegValueY or + cycleCountZ != cycleCountRegValueZ) { + return DeviceHandlerIF::DEVICE_REPLY_INVALID; + } + // Reading TMRC was commanded. Trigger event to inform ground + if(mode != _MODE_START_UP) { + uint32_t eventParam1 = (cycleCountX << 16) | cycleCountY; + triggerEvent(cycleCountersSet, eventParam1, cycleCountZ); + } + break; + } + case(RM3100::READ_DATA): { + result = handleDataReadout(packet); + break; + } + default: + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } + + return result; +} + +ReturnValue_t MgmRM3100Handler::handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand, + const uint8_t *commandData, size_t commandDataLen) { + if(commandData == nullptr) { + return DeviceHandlerIF::INVALID_COMMAND_PARAMETER; + } + + // Set cycle count + if(commandDataLen == 2) { + handleCycleCommand(true, commandData, commandDataLen); + } + else if(commandDataLen == 6) { + handleCycleCommand(false, commandData, commandDataLen); + } + else { + return DeviceHandlerIF::INVALID_COMMAND_PARAMETER; + } + + commandBuffer[0] = RM3100::CYCLE_COUNT_VALUE; + std::memcpy(commandBuffer + 1, &cycleCountRegValueX, 2); + std::memcpy(commandBuffer + 3, &cycleCountRegValueY, 2); + std::memcpy(commandBuffer + 5, &cycleCountRegValueZ, 2); + rawPacketLen = 7; + rawPacket = commandBuffer; + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue, + const uint8_t *commandData, size_t commandDataLen) { + RM3100::CycleCountCommand command(oneCycleValue); + ReturnValue_t result = command.deSerialize(&commandData, &commandDataLen, + SerializeIF::Endianness::BIG); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + + // Data sheet p.30 "while noise limits the useful upper range to ~400 cycle counts." + if(command.cycleCountX > 450 ) { + return DeviceHandlerIF::INVALID_COMMAND_PARAMETER; + } + + if(not oneCycleValue and (command.cycleCountY > 450 or command.cycleCountZ > 450)) { + return DeviceHandlerIF::INVALID_COMMAND_PARAMETER; + } + + cycleCountRegValueX = command.cycleCountX; + cycleCountRegValueY = command.cycleCountY; + cycleCountRegValueZ = command.cycleCountZ; + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t MgmRM3100Handler::handleTmrcConfigCommand(DeviceCommandId_t deviceCommand, + const uint8_t *commandData, size_t commandDataLen) { + if(commandData == nullptr or commandDataLen != 1) { + return DeviceHandlerIF::INVALID_COMMAND_PARAMETER; + } + + commandBuffer[0] = RM3100::TMRC_REGISTER; + commandBuffer[1] = commandData[0]; + tmrcRegValue = commandData[0]; + rawPacketLen = 2; + rawPacket = commandBuffer; + return HasReturnvaluesIF::RETURN_OK; +} + +void MgmRM3100Handler::fillCommandAndReplyMap() { + insertInCommandAndReplyMap(RM3100::CONFIGURE_CMM, 3); + insertInCommandAndReplyMap(RM3100::READ_CMM, 3); + + insertInCommandAndReplyMap(RM3100::CONFIGURE_TMRC, 3); + insertInCommandAndReplyMap(RM3100::READ_TMRC, 3); + + insertInCommandAndReplyMap(RM3100::CONFIGURE_CYCLE_COUNT, 3); + insertInCommandAndReplyMap(RM3100::READ_CYCLE_COUNT, 3); + + insertInCommandAndReplyMap(RM3100::READ_DATA, 3, &primaryDataset); +} + +void MgmRM3100Handler::modeChanged(void) { + internalState = InternalState::NONE; +} + +ReturnValue_t MgmRM3100Handler::initializeLocalDataPool( + localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { + localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_X, new PoolEntry({0.0})); + localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Y, new PoolEntry({0.0})); + localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Z, new PoolEntry({0.0})); + return HasReturnvaluesIF::RETURN_OK; +} + +uint32_t MgmRM3100Handler::getTransitionDelayMs(Mode_t from, Mode_t to) { + return this->transitionDelay; +} + +void MgmRM3100Handler::setToGoToNormalMode(bool enable) { + goToNormalModeAtStartup = enable; +} + +ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) { + // Analyze data here. The sensor generates 24 bit signed values so we need to do some bitshift + // trickery here to calculate the raw values first + int32_t fieldStrengthRawX = ((packet[1] << 24) | (packet[2] << 16) | (packet[3] << 8)) >> 8; + int32_t fieldStrengthRawY = ((packet[4] << 24) | (packet[5] << 16) | (packet[6] << 8)) >> 8; + int32_t fieldStrengthRawZ = ((packet[7] << 24) | (packet[8] << 16) | (packet[3] << 8)) >> 8; + + // Now scale to physical value in microtesla + float fieldStrengthX = fieldStrengthRawX * scaleFactorX; + float fieldStrengthY = fieldStrengthRawY * scaleFactorX; + float fieldStrengthZ = fieldStrengthRawZ * scaleFactorX; + +#if FSFW_HAL_RM3100_MGM_DEBUG == 1 + if(debugDivider->checkAndIncrement()) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "MgmRM3100Handler: Magnetic field strength in" + " microtesla:" << std::endl; + sif::info << "X: " << fieldStrengthX << " uT" << std::endl; + sif::info << "Y: " << fieldStrengthY << " uT" << std::endl; + sif::info << "Z: " << fieldStrengthZ << " uT" << std::endl; +#else + sif::printInfo("MgmRM3100Handler: Magnetic field strength in microtesla:\n"); + sif::printInfo("X: %f uT\n", fieldStrengthX); + sif::printInfo("Y: %f uT\n", fieldStrengthY); + sif::printInfo("Z: %f uT\n", fieldStrengthZ); +#endif + } +#endif + + // TODO: Sanity check on values? + PoolReadGuard readGuard(&primaryDataset); + if(readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) { + primaryDataset.fieldStrengthX = fieldStrengthX; + primaryDataset.fieldStrengthY = fieldStrengthY; + primaryDataset.fieldStrengthZ = fieldStrengthZ; + primaryDataset.setValidity(true, true); + } + return RETURN_OK; +} diff --git a/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.h b/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.h new file mode 100644 index 000000000..6627cbb75 --- /dev/null +++ b/hal/src/fsfw_hal/devicehandlers/MgmRM3100Handler.h @@ -0,0 +1,110 @@ +#ifndef MISSION_DEVICES_MGMRM3100HANDLER_H_ +#define MISSION_DEVICES_MGMRM3100HANDLER_H_ + +#include "fsfw/FSFW.h" +#include "devicedefinitions/MgmRM3100HandlerDefs.h" +#include "fsfw/devicehandlers/DeviceHandlerBase.h" + +#if FSFW_HAL_RM3100_MGM_DEBUG == 1 +#include "fsfw/globalfunctions/PeriodicOperationDivider.h" +#endif + +/** + * @brief Device Handler for the RM3100 geomagnetic magnetometer sensor + * (https://www.pnicorp.com/rm3100/) + * @details + * Flight manual: + * https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/RM3100_MGM + */ +class MgmRM3100Handler: public DeviceHandlerBase { +public: + static const uint8_t INTERFACE_ID = CLASS_ID::MGM_RM3100; + + //! [EXPORT] : [COMMENT] P1: TMRC value which was set, P2: 0 + static constexpr Event tmrcSet = event::makeEvent(SUBSYSTEM_ID::MGM_RM3100, + 0x00, severity::INFO); + + //! [EXPORT] : [COMMENT] Cycle counter set. P1: First two bytes new Cycle Count X + //! P1: Second two bytes new Cycle Count Y + //! P2: New cycle count Z + static constexpr Event cycleCountersSet = event::makeEvent( + SUBSYSTEM_ID::MGM_RM3100, 0x01, severity::INFO); + + MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication, + CookieIF* comCookie, uint32_t transitionDelay); + virtual ~MgmRM3100Handler(); + + /** + * Configure device handler to go to normal mode after startup immediately + * @param enable + */ + void setToGoToNormalMode(bool enable); + +protected: + + /* DeviceHandlerBase overrides */ + ReturnValue_t buildTransitionDeviceCommand( + DeviceCommandId_t *id) override; + void doStartUp() override; + void doShutDown() override; + ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override; + ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, + const uint8_t *commandData, size_t commandDataLen) override; + ReturnValue_t scanForReply(const uint8_t *start, size_t len, + DeviceCommandId_t *foundId, size_t *foundLen) override; + ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override; + + void fillCommandAndReplyMap() override; + void modeChanged(void) override; + virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) override; + +private: + + enum class InternalState { + NONE, + CONFIGURE_CMM, + READ_CMM, + // The cycle count states are propably not going to be used because + // the default cycle count will be used. + STATE_CONFIGURE_CYCLE_COUNT, + STATE_READ_CYCLE_COUNT, + STATE_CONFIGURE_TMRC, + STATE_READ_TMRC, + NORMAL + }; + InternalState internalState = InternalState::NONE; + bool commandExecuted = false; + RM3100::Rm3100PrimaryDataset primaryDataset; + + uint8_t commandBuffer[10]; + uint8_t commandBufferLen = 0; + + uint8_t cmmRegValue = RM3100::CMM_VALUE; + uint8_t tmrcRegValue = RM3100::TMRC_DEFAULT_VALUE; + uint16_t cycleCountRegValueX = RM3100::CYCLE_COUNT_VALUE; + uint16_t cycleCountRegValueY = RM3100::CYCLE_COUNT_VALUE; + uint16_t cycleCountRegValueZ = RM3100::CYCLE_COUNT_VALUE; + float scaleFactorX = 1.0 / RM3100::DEFAULT_GAIN; + float scaleFactorY = 1.0 / RM3100::DEFAULT_GAIN; + float scaleFactorZ = 1.0 / RM3100::DEFAULT_GAIN; + + bool goToNormalModeAtStartup = false; + uint32_t transitionDelay; + + ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand, + const uint8_t *commandData,size_t commandDataLen); + ReturnValue_t handleCycleCommand(bool oneCycleValue, + const uint8_t *commandData, size_t commandDataLen); + + ReturnValue_t handleTmrcConfigCommand(DeviceCommandId_t deviceCommand, + const uint8_t *commandData,size_t commandDataLen); + + ReturnValue_t handleDataReadout(const uint8_t* packet); +#if FSFW_HAL_RM3100_MGM_DEBUG == 1 + PeriodicOperationDivider* debugDivider; +#endif +}; + +#endif /* MISSION_DEVICEHANDLING_MGMRM3100HANDLER_H_ */ diff --git a/hal/src/fsfw_hal/devicehandlers/devicedefinitions/GyroL3GD20Definitions.h b/hal/src/fsfw_hal/devicehandlers/devicedefinitions/GyroL3GD20Definitions.h new file mode 100644 index 000000000..56a2468dc --- /dev/null +++ b/hal/src/fsfw_hal/devicehandlers/devicedefinitions/GyroL3GD20Definitions.h @@ -0,0 +1,143 @@ +#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_ +#define MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_ + +#include +#include +#include + +namespace L3GD20H { + +/* Actual size is 15 but we round up a bit */ +static constexpr size_t MAX_BUFFER_SIZE = 16; + +static constexpr uint8_t READ_MASK = 0b10000000; + +static constexpr uint8_t AUTO_INCREMENT_MASK = 0b01000000; + +static constexpr uint8_t WHO_AM_I_REG = 0b00001111; +static constexpr uint8_t WHO_AM_I_VAL = 0b11010111; + +/*------------------------------------------------------------------------*/ +/* Control registers */ +/*------------------------------------------------------------------------*/ +static constexpr uint8_t CTRL_REG_1 = 0b00100000; +static constexpr uint8_t CTRL_REG_2 = 0b00100001; +static constexpr uint8_t CTRL_REG_3 = 0b00100010; +static constexpr uint8_t CTRL_REG_4 = 0b00100011; +static constexpr uint8_t CTRL_REG_5 = 0b00100100; + +/* Register 1 */ +static constexpr uint8_t SET_DR_1 = 1 << 7; +static constexpr uint8_t SET_DR_0 = 1 << 6; +static constexpr uint8_t SET_BW_1 = 1 << 5; +static constexpr uint8_t SET_BW_0 = 1 << 4; +static constexpr uint8_t SET_POWER_NORMAL_MODE = 1 << 3; +static constexpr uint8_t SET_Z_ENABLE = 1 << 2; +static constexpr uint8_t SET_X_ENABLE = 1 << 1; +static constexpr uint8_t SET_Y_ENABLE = 1; + +static constexpr uint8_t CTRL_REG_1_VAL = SET_POWER_NORMAL_MODE | SET_Z_ENABLE | + SET_Y_ENABLE | SET_X_ENABLE; + +/* Register 2 */ +static constexpr uint8_t EXTERNAL_EDGE_ENB = 1 << 7; +static constexpr uint8_t LEVEL_SENSITIVE_TRIGGER = 1 << 6; +static constexpr uint8_t SET_HPM_1 = 1 << 5; +static constexpr uint8_t SET_HPM_0 = 1 << 4; +static constexpr uint8_t SET_HPCF_3 = 1 << 3; +static constexpr uint8_t SET_HPCF_2 = 1 << 2; +static constexpr uint8_t SET_HPCF_1 = 1 << 1; +static constexpr uint8_t SET_HPCF_0 = 1; + +static constexpr uint8_t CTRL_REG_2_VAL = 0b00000000; + +/* Register 3 */ +static constexpr uint8_t CTRL_REG_3_VAL = 0b00000000; + +/* Register 4 */ +static constexpr uint8_t SET_BNU = 1 << 7; +static constexpr uint8_t SET_BLE = 1 << 6; +static constexpr uint8_t SET_FS_1 = 1 << 5; +static constexpr uint8_t SET_FS_0 = 1 << 4; +static constexpr uint8_t SET_IMP_ENB = 1 << 3; +static constexpr uint8_t SET_SELF_TEST_ENB_1 = 1 << 2; +static constexpr uint8_t SET_SELF_TEST_ENB_0 = 1 << 1; +static constexpr uint8_t SET_SPI_IF_SELECT = 1; + +/* Enable big endian data format */ +static constexpr uint8_t CTRL_REG_4_VAL = SET_BLE; + +/* Register 5 */ +static constexpr uint8_t SET_REBOOT_MEM = 1 << 7; +static constexpr uint8_t SET_FIFO_ENB = 1 << 6; + +static constexpr uint8_t CTRL_REG_5_VAL = 0b00000000; + +/* Possible range values in degrees per second (DPS). */ +static constexpr uint16_t RANGE_DPS_00 = 245; +static constexpr float SENSITIVITY_00 = 8.75 * 0.001; +static constexpr uint16_t RANGE_DPS_01 = 500; +static constexpr float SENSITIVITY_01 = 17.5 * 0.001; +static constexpr uint16_t RANGE_DPS_11 = 2000; +static constexpr float SENSITIVITY_11 = 70.0 * 0.001; + +static constexpr uint8_t READ_START = CTRL_REG_1; +static constexpr size_t READ_LEN = 14; + +/* Indexing */ +static constexpr uint8_t REFERENCE_IDX = 6; +static constexpr uint8_t TEMPERATURE_IDX = 7; +static constexpr uint8_t STATUS_IDX = 8; +static constexpr uint8_t OUT_X_H = 9; +static constexpr uint8_t OUT_X_L = 10; +static constexpr uint8_t OUT_Y_H = 11; +static constexpr uint8_t OUT_Y_L = 12; +static constexpr uint8_t OUT_Z_H = 13; +static constexpr uint8_t OUT_Z_L = 14; + +/*------------------------------------------------------------------------*/ +/* Device Handler specific */ +/*------------------------------------------------------------------------*/ +static constexpr DeviceCommandId_t READ_REGS = 0; +static constexpr DeviceCommandId_t CONFIGURE_CTRL_REGS = 1; +static constexpr DeviceCommandId_t READ_CTRL_REGS = 2; + +static constexpr uint32_t GYRO_DATASET_ID = READ_REGS; + +enum GyroPoolIds: lp_id_t { + ANG_VELOC_X, + ANG_VELOC_Y, + ANG_VELOC_Z, + TEMPERATURE +}; + +} + +class GyroPrimaryDataset: public StaticLocalDataSet<5> { +public: + + /** Constructor for data users like controllers */ + GyroPrimaryDataset(object_id_t mgmId): + StaticLocalDataSet(sid_t(mgmId, L3GD20H::GYRO_DATASET_ID)) { + setAllVariablesReadOnly(); + } + + /* Angular velocities in degrees per second (DPS) */ + lp_var_t angVelocX = lp_var_t(sid.objectId, + L3GD20H::ANG_VELOC_X, this); + lp_var_t angVelocY = lp_var_t(sid.objectId, + L3GD20H::ANG_VELOC_Y, this); + lp_var_t angVelocZ = lp_var_t(sid.objectId, + L3GD20H::ANG_VELOC_Z, this); + lp_var_t temperature = lp_var_t(sid.objectId, + L3GD20H::TEMPERATURE, this); +private: + + friend class GyroHandlerL3GD20H; + /** Constructor for the data creator */ + GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner): + StaticLocalDataSet(hkOwner, L3GD20H::GYRO_DATASET_ID) {} +}; + + +#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_ */ diff --git a/hal/src/fsfw_hal/devicehandlers/devicedefinitions/MgmLIS3HandlerDefs.h b/hal/src/fsfw_hal/devicehandlers/devicedefinitions/MgmLIS3HandlerDefs.h new file mode 100644 index 000000000..9d65aae27 --- /dev/null +++ b/hal/src/fsfw_hal/devicehandlers/devicedefinitions/MgmLIS3HandlerDefs.h @@ -0,0 +1,178 @@ +#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_ +#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_ + +#include +#include +#include +#include + +namespace MGMLIS3MDL { + +enum Set { + ON, OFF +}; +enum OpMode { + LOW, MEDIUM, HIGH, ULTRA +}; + +enum Sensitivies: uint8_t { + GAUSS_4 = 4, + GAUSS_8 = 8, + GAUSS_12 = 12, + GAUSS_16 = 16 +}; + +/* Actually 15, we just round up a bit */ +static constexpr size_t MAX_BUFFER_SIZE = 16; + +/* Field data register scaling */ +static constexpr uint8_t GAUSS_TO_MICROTESLA_FACTOR = 100; +static constexpr float FIELD_LSB_PER_GAUSS_4_SENS = 1.0 / 6842.0; +static constexpr float FIELD_LSB_PER_GAUSS_8_SENS = 1.0 / 3421.0; +static constexpr float FIELD_LSB_PER_GAUSS_12_SENS = 1.0 / 2281.0; +static constexpr float FIELD_LSB_PER_GAUSS_16_SENS = 1.0 / 1711.0; + +static const DeviceCommandId_t READ_CONFIG_AND_DATA = 0x00; +static const DeviceCommandId_t SETUP_MGM = 0x01; +static const DeviceCommandId_t READ_TEMPERATURE = 0x02; +static const DeviceCommandId_t IDENTIFY_DEVICE = 0x03; +static const DeviceCommandId_t TEMP_SENSOR_ENABLE = 0x04; +static const DeviceCommandId_t ACCURACY_OP_MODE_SET = 0x05; + +/* Number of all control registers */ +static const uint8_t NR_OF_CTRL_REGISTERS = 5; +/* Number of registers in the MGM */ +static const uint8_t NR_OF_REGISTERS = 19; +/* Total number of adresses for all registers */ +static const uint8_t TOTAL_NR_OF_ADRESSES = 52; +static const uint8_t NR_OF_DATA_AND_CFG_REGISTERS = 14; +static const uint8_t TEMPERATURE_REPLY_LEN = 3; +static const uint8_t SETUP_REPLY_LEN = 6; + +/*------------------------------------------------------------------------*/ +/* Register adresses */ +/*------------------------------------------------------------------------*/ +/* Register adress returns identifier of device with default 0b00111101 */ +static const uint8_t IDENTIFY_DEVICE_REG_ADDR = 0b00001111; +static const uint8_t DEVICE_ID = 0b00111101; // Identifier for Device + +/* Register adress to access register 1 */ +static const uint8_t CTRL_REG1 = 0b00100000; +/* Register adress to access register 2 */ +static const uint8_t CTRL_REG2 = 0b00100001; +/* Register adress to access register 3 */ +static const uint8_t CTRL_REG3 = 0b00100010; +/* Register adress to access register 4 */ +static const uint8_t CTRL_REG4 = 0b00100011; +/* Register adress to access register 5 */ +static const uint8_t CTRL_REG5 = 0b00100100; + +/* Register adress to access status register */ +static const uint8_t STATUS_REG_IDX = 8; +static const uint8_t STATUS_REG = 0b00100111; + +/* Register adress to access low byte of x-axis */ +static const uint8_t X_LOWBYTE_IDX = 9; +static const uint8_t X_LOWBYTE = 0b00101000; +/* Register adress to access high byte of x-axis */ +static const uint8_t X_HIGHBYTE_IDX = 10; +static const uint8_t X_HIGHBYTE = 0b00101001; +/* Register adress to access low byte of y-axis */ +static const uint8_t Y_LOWBYTE_IDX = 11; +static const uint8_t Y_LOWBYTE = 0b00101010; +/* Register adress to access high byte of y-axis */ +static const uint8_t Y_HIGHBYTE_IDX = 12; +static const uint8_t Y_HIGHBYTE = 0b00101011; +/* Register adress to access low byte of z-axis */ +static const uint8_t Z_LOWBYTE_IDX = 13; +static const uint8_t Z_LOWBYTE = 0b00101100; +/* Register adress to access high byte of z-axis */ +static const uint8_t Z_HIGHBYTE_IDX = 14; +static const uint8_t Z_HIGHBYTE = 0b00101101; + +/* Register adress to access low byte of temperature sensor */ +static const uint8_t TEMP_LOWBYTE = 0b00101110; +/* Register adress to access high byte of temperature sensor */ +static const uint8_t TEMP_HIGHBYTE = 0b00101111; + +/*------------------------------------------------------------------------*/ +/* Initialize Setup Register set bits */ +/*------------------------------------------------------------------------*/ +/* General transfer bits */ +// Read=1 / Write=0 Bit +static const uint8_t RW_BIT = 7; +// Continous Read/Write Bit, increment adress +static const uint8_t MS_BIT = 6; + +/* CTRL_REG1 bits */ +static const uint8_t ST = 0; // Self test enable bit, enabled = 1 +// Enable rates higher than 80 Hz enabled = 1 +static const uint8_t FAST_ODR = 1; +static const uint8_t DO0 = 2; // Output data rate bit 2 +static const uint8_t DO1 = 3; // Output data rate bit 3 +static const uint8_t DO2 = 4; // Output data rate bit 4 +static const uint8_t OM0 = 5; // XY operating mode bit 5 +static const uint8_t OM1 = 6; // XY operating mode bit 6 +static const uint8_t TEMP_EN = 7; // Temperature sensor enable enabled = 1 +static const uint8_t CTRL_REG1_DEFAULT = (1 << TEMP_EN) | (1 << OM1) | + (1 << DO0) | (1 << DO1) | (1 << DO2); + +/* CTRL_REG2 bits */ +//reset configuration registers and user registers +static const uint8_t SOFT_RST = 2; +static const uint8_t REBOOT = 3; //reboot memory content +static const uint8_t FSO = 5; //full-scale selection bit 5 +static const uint8_t FS1 = 6; //full-scale selection bit 6 +static const uint8_t CTRL_REG2_DEFAULT = 0; + +/* CTRL_REG3 bits */ +static const uint8_t MD0 = 0; //Operating mode bit 0 +static const uint8_t MD1 = 1; //Operating mode bit 1 +//SPI serial interface mode selection enabled = 3-wire-mode +static const uint8_t SIM = 2; +static const uint8_t LP = 5; //low-power mode +static const uint8_t CTRL_REG3_DEFAULT = 0; + +/* CTRL_REG4 bits */ +//big/little endian data selection enabled = MSb at lower adress +static const uint8_t BLE = 1; +static const uint8_t OMZ0 = 2; //Z operating mode bit 2 +static const uint8_t OMZ1 = 3; //Z operating mode bit 3 +static const uint8_t CTRL_REG4_DEFAULT = (1 << OMZ1); + +/* CTRL_REG5 bits */ +static const uint8_t BDU = 6; //Block data update +static const uint8_t FAST_READ = 7; //Fast read enabled = 1 +static const uint8_t CTRL_REG5_DEFAULT = 0; + +static const uint32_t MGM_DATA_SET_ID = READ_CONFIG_AND_DATA; + +enum MgmPoolIds: lp_id_t { + FIELD_STRENGTH_X, + FIELD_STRENGTH_Y, + FIELD_STRENGTH_Z, + TEMPERATURE_CELCIUS +}; + +class MgmPrimaryDataset: public StaticLocalDataSet<4> { +public: + MgmPrimaryDataset(HasLocalDataPoolIF* hkOwner): + StaticLocalDataSet(hkOwner, MGM_DATA_SET_ID) {} + + MgmPrimaryDataset(object_id_t mgmId): + StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {} + + lp_var_t fieldStrengthX = lp_var_t(sid.objectId, + FIELD_STRENGTH_X, this); + lp_var_t fieldStrengthY = lp_var_t(sid.objectId, + FIELD_STRENGTH_Y, this); + lp_var_t fieldStrengthZ = lp_var_t(sid.objectId, + FIELD_STRENGTH_Z, this); + lp_var_t temperature = lp_var_t(sid.objectId, + TEMPERATURE_CELCIUS, this); +}; + +} + + +#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_ */ diff --git a/hal/src/fsfw_hal/devicehandlers/devicedefinitions/MgmRM3100HandlerDefs.h b/hal/src/fsfw_hal/devicehandlers/devicedefinitions/MgmRM3100HandlerDefs.h new file mode 100644 index 000000000..b6375692c --- /dev/null +++ b/hal/src/fsfw_hal/devicehandlers/devicedefinitions/MgmRM3100HandlerDefs.h @@ -0,0 +1,132 @@ +#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_ +#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_ + +#include +#include +#include +#include +#include + +namespace RM3100 { + +/* Actually 10, we round up a little bit */ +static constexpr size_t MAX_BUFFER_SIZE = 12; + +static constexpr uint8_t READ_MASK = 0x80; + +/*----------------------------------------------------------------------------*/ +/* CMM Register */ +/*----------------------------------------------------------------------------*/ +static constexpr uint8_t SET_CMM_CMZ = 1 << 6; +static constexpr uint8_t SET_CMM_CMY = 1 << 5; +static constexpr uint8_t SET_CMM_CMX = 1 << 4; +static constexpr uint8_t SET_CMM_DRDM = 1 << 2; +static constexpr uint8_t SET_CMM_START = 1; +static constexpr uint8_t CMM_REGISTER = 0x01; + +static constexpr uint8_t CMM_VALUE = SET_CMM_CMZ | SET_CMM_CMY | SET_CMM_CMX | + SET_CMM_DRDM | SET_CMM_START; + +/*----------------------------------------------------------------------------*/ +/* Cycle count register */ +/*----------------------------------------------------------------------------*/ +// Default value (200) +static constexpr uint8_t CYCLE_COUNT_VALUE = 0xC8; + +static constexpr float DEFAULT_GAIN = static_cast(CYCLE_COUNT_VALUE) / + 100 * 38; +static constexpr uint8_t CYCLE_COUNT_START_REGISTER = 0x04; + +/*----------------------------------------------------------------------------*/ +/* TMRC register */ +/*----------------------------------------------------------------------------*/ +static constexpr uint8_t TMRC_150HZ_VALUE = 0x94; +static constexpr uint8_t TMRC_75HZ_VALUE = 0x95; +static constexpr uint8_t TMRC_DEFAULT_37HZ_VALUE = 0x96; + +static constexpr uint8_t TMRC_REGISTER = 0x0B; +static constexpr uint8_t TMRC_DEFAULT_VALUE = TMRC_DEFAULT_37HZ_VALUE; + +static constexpr uint8_t MEASUREMENT_REG_START = 0x24; +static constexpr uint8_t BIST_REGISTER = 0x33; +static constexpr uint8_t DATA_READY_VAL = 0b10000000; +static constexpr uint8_t STATUS_REGISTER = 0x34; +static constexpr uint8_t REVID_REGISTER = 0x36; + +// Range in Microtesla. 1 T equals 10000 Gauss (for comparison with LIS3 MGM) +static constexpr uint16_t RANGE = 800; + +static constexpr DeviceCommandId_t READ_DATA = 0; + +static constexpr DeviceCommandId_t CONFIGURE_CMM = 1; +static constexpr DeviceCommandId_t READ_CMM = 2; + +static constexpr DeviceCommandId_t CONFIGURE_TMRC = 3; +static constexpr DeviceCommandId_t READ_TMRC = 4; + +static constexpr DeviceCommandId_t CONFIGURE_CYCLE_COUNT = 5; +static constexpr DeviceCommandId_t READ_CYCLE_COUNT = 6; + +class CycleCountCommand: public SerialLinkedListAdapter { +public: + CycleCountCommand(bool oneCycleCount = true): oneCycleCount(oneCycleCount) { + setLinks(oneCycleCount); + } + + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness) override { + ReturnValue_t result = SerialLinkedListAdapter::deSerialize(buffer, + size, streamEndianness); + if(oneCycleCount) { + cycleCountY = cycleCountX; + cycleCountZ = cycleCountX; + } + return result; + } + + SerializeElement cycleCountX; + SerializeElement cycleCountY; + SerializeElement cycleCountZ; + +private: + void setLinks(bool oneCycleCount) { + setStart(&cycleCountX); + if(not oneCycleCount) { + cycleCountX.setNext(&cycleCountY); + cycleCountY.setNext(&cycleCountZ); + } + } + + bool oneCycleCount; +}; + +static constexpr uint32_t MGM_DATASET_ID = READ_DATA; + +enum MgmPoolIds: lp_id_t { + FIELD_STRENGTH_X, + FIELD_STRENGTH_Y, + FIELD_STRENGTH_Z, +}; + +class Rm3100PrimaryDataset: public StaticLocalDataSet<3> { +public: + Rm3100PrimaryDataset(HasLocalDataPoolIF* hkOwner): + StaticLocalDataSet(hkOwner, MGM_DATASET_ID) {} + + Rm3100PrimaryDataset(object_id_t mgmId): + StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {} + + // Field strengths in micro Tesla. + lp_var_t fieldStrengthX = lp_var_t(sid.objectId, + FIELD_STRENGTH_X, this); + lp_var_t fieldStrengthY = lp_var_t(sid.objectId, + FIELD_STRENGTH_Y, this); + lp_var_t fieldStrengthZ = lp_var_t(sid.objectId, + FIELD_STRENGTH_Z, this); +}; + +} + + + +#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_ */ diff --git a/hal/src/fsfw_hal/host/CMakeLists.txt b/hal/src/fsfw_hal/host/CMakeLists.txt new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/hal/src/fsfw_hal/host/CMakeLists.txt @@ -0,0 +1 @@ + diff --git a/hal/src/fsfw_hal/linux/CMakeLists.txt b/hal/src/fsfw_hal/linux/CMakeLists.txt new file mode 100644 index 000000000..5944b0e5d --- /dev/null +++ b/hal/src/fsfw_hal/linux/CMakeLists.txt @@ -0,0 +1,13 @@ +if(FSFW_HAL_ADD_RASPBERRY_PI) + add_subdirectory(rpi) +endif() + +target_sources(${LIB_FSFW_NAME} PRIVATE + UnixFileGuard.cpp + utility.cpp +) + +add_subdirectory(gpio) +add_subdirectory(spi) +add_subdirectory(i2c) +add_subdirectory(uart) \ No newline at end of file diff --git a/hal/src/fsfw_hal/linux/UnixFileGuard.cpp b/hal/src/fsfw_hal/linux/UnixFileGuard.cpp new file mode 100644 index 000000000..5019343e8 --- /dev/null +++ b/hal/src/fsfw_hal/linux/UnixFileGuard.cpp @@ -0,0 +1,37 @@ +#include "fsfw/FSFW.h" +#include "fsfw/serviceinterface.h" +#include "fsfw_hal/linux/UnixFileGuard.h" + +#include +#include + +UnixFileGuard::UnixFileGuard(std::string device, int* fileDescriptor, int flags, + std::string diagnosticPrefix): + fileDescriptor(fileDescriptor) { + if(fileDescriptor == nullptr) { + return; + } + *fileDescriptor = open(device.c_str(), flags); + if (*fileDescriptor < 0) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << diagnosticPrefix << ": Opening device failed with error code " << + errno << ": " << strerror(errno) << std::endl; +#else + sif::printWarning("%s: Opening device failed with error code %d: %s\n", + diagnosticPrefix, errno, strerror(errno)); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + openStatus = OPEN_FILE_FAILED; + } +} + +UnixFileGuard::~UnixFileGuard() { + if(fileDescriptor != nullptr) { + close(*fileDescriptor); + } +} + +ReturnValue_t UnixFileGuard::getOpenResult() const { + return openStatus; +} diff --git a/hal/src/fsfw_hal/linux/UnixFileGuard.h b/hal/src/fsfw_hal/linux/UnixFileGuard.h new file mode 100644 index 000000000..fb595704e --- /dev/null +++ b/hal/src/fsfw_hal/linux/UnixFileGuard.h @@ -0,0 +1,33 @@ +#ifndef LINUX_UTILITY_UNIXFILEGUARD_H_ +#define LINUX_UTILITY_UNIXFILEGUARD_H_ + +#include + +#include + +#include +#include + + +class UnixFileGuard { +public: + static constexpr int READ_WRITE_FLAG = O_RDWR; + static constexpr int READ_ONLY_FLAG = O_RDONLY; + static constexpr int NON_BLOCKING_IO_FLAG = O_NONBLOCK; + + static constexpr ReturnValue_t OPEN_FILE_FAILED = 1; + + UnixFileGuard(std::string device, int* fileDescriptor, int flags, + std::string diagnosticPrefix = ""); + + virtual~ UnixFileGuard(); + + ReturnValue_t getOpenResult() const; +private: + int* fileDescriptor = nullptr; + ReturnValue_t openStatus = HasReturnvaluesIF::RETURN_OK; +}; + + + +#endif /* LINUX_UTILITY_UNIXFILEGUARD_H_ */ diff --git a/hal/src/fsfw_hal/linux/gpio/CMakeLists.txt b/hal/src/fsfw_hal/linux/gpio/CMakeLists.txt new file mode 100644 index 000000000..7083f70df --- /dev/null +++ b/hal/src/fsfw_hal/linux/gpio/CMakeLists.txt @@ -0,0 +1,12 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + LinuxLibgpioIF.cpp +) + +# This abstraction layer requires the gpiod library. You can install this library +# with "sudo apt-get install -y libgpiod-dev". If you are cross-compiling, you need +# to install the package before syncing the sysroot to your host computer. +find_library(LIB_GPIO gpiod REQUIRED) + +target_link_libraries(${LIB_FSFW_NAME} PRIVATE + ${LIB_GPIO} +) \ No newline at end of file diff --git a/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp b/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp new file mode 100644 index 000000000..15c3d1187 --- /dev/null +++ b/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.cpp @@ -0,0 +1,344 @@ +#include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h" +#include "fsfw_hal/common/gpio/gpioDefinitions.h" +#include "fsfw_hal/common/gpio/GpioCookie.h" + +#include + +#include +#include +#include + +LinuxLibgpioIF::LinuxLibgpioIF(object_id_t objectId) : SystemObject(objectId) { +} + +LinuxLibgpioIF::~LinuxLibgpioIF() { + for(auto& config: gpioMap) { + delete(config.second); + } +} + +ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) { + ReturnValue_t result; + if(gpioCookie == nullptr) { + sif::error << "LinuxLibgpioIF::addGpios: Invalid cookie" << std::endl; + return RETURN_FAILED; + } + + GpioMap mapToAdd = gpioCookie->getGpioMap(); + + /* Check whether this ID already exists in the map and remove duplicates */ + result = checkForConflicts(mapToAdd); + 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 RETURN_OK; +} + +ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) { + for(auto& gpioConfig: mapToAdd) { + auto& gpioType = gpioConfig.second->gpioType; + switch(gpioType) { + case(gpio::GpioTypes::NONE): { + return GPIO_INVALID_INSTANCE; + } + case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP): { + auto regularGpio = dynamic_cast(gpioConfig.second); + if(regularGpio == nullptr) { + return GPIO_INVALID_INSTANCE; + } + configureGpioByChip(gpioConfig.first, *regularGpio); + break; + } + case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):{ + auto regularGpio = dynamic_cast(gpioConfig.second); + if(regularGpio == nullptr) { + return GPIO_INVALID_INSTANCE; + } + configureGpioByLabel(gpioConfig.first, *regularGpio); + break; + } + case(gpio::GpioTypes::CALLBACK): { + auto gpioCallback = dynamic_cast(gpioConfig.second); + if(gpioCallback->callback == nullptr) { + return GPIO_INVALID_INSTANCE; + } + gpioCallback->callback(gpioConfig.first, gpio::GpioOperation::WRITE, + gpioCallback->initValue, gpioCallback->callbackArgs); + } + } + } + return RETURN_OK; +} + +ReturnValue_t LinuxLibgpioIF::configureGpioByLabel(gpioId_t gpioId, + GpiodRegularByLabel &gpioByLabel) { + std::string& label = gpioByLabel.label; + struct gpiod_chip* chip = gpiod_chip_open_by_label(label.c_str()); + if (chip == nullptr) { + sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open gpio from gpio " + << "group with label " << label << ". Gpio ID: " << gpioId << std::endl; + return RETURN_FAILED; + + } + std::string failOutput = "label: " + label; + return configureRegularGpio(gpioId, gpioByLabel.gpioType, chip, gpioByLabel, failOutput); +} + +ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId, + GpiodRegularByChip &gpioByChip) { + std::string& chipname = gpioByChip.chipname; + struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname.c_str()); + if (chip == nullptr) { + sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open chip " + << chipname << ". Gpio ID: " << gpioId << std::endl; + return RETURN_FAILED; + } + std::string failOutput = "chipname: " + chipname; + return configureRegularGpio(gpioId, gpioByChip.gpioType, chip, gpioByChip, failOutput); +} + +ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, gpio::GpioTypes gpioType, + struct gpiod_chip* chip, GpiodRegularBase& regularGpio, std::string failOutput) { + unsigned int lineNum; + gpio::Direction direction; + std::string consumer; + struct gpiod_line *lineHandle; + int result = 0; + + lineNum = regularGpio.lineNum; + lineHandle = gpiod_chip_get_line(chip, lineNum); + if (!lineHandle) { + sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open line " << std::endl; + sif::warning << "GPIO ID: " << gpioId << ", line number: " << lineNum << + ", " << failOutput << std::endl; + sif::warning << "Check if Linux GPIO configuration has changed. " << std::endl; + gpiod_chip_close(chip); + return RETURN_FAILED; + } + + direction = regularGpio.direction; + consumer = regularGpio.consumer; + /* Configure direction and add a description to the GPIO */ + switch (direction) { + case(gpio::OUT): { + result = gpiod_line_request_output(lineHandle, consumer.c_str(), + regularGpio.initValue); + if (result < 0) { + sif::error << "LinuxLibgpioIF::configureRegularGpio: Failed to request line " << lineNum << + " from GPIO instance with ID: " << gpioId << 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: " << gpioId << std::endl; + gpiod_line_release(lineHandle); + return RETURN_FAILED; + } + break; + } + default: { + sif::error << "LinuxLibgpioIF::configureGpios: Invalid direction specified" + << std::endl; + return GPIO_INVALID_INSTANCE; + } + + } + /** + * Write line handle to GPIO configuration instance so it can later be used to set or + * read states of GPIOs. + */ + regularGpio.lineHandle = lineHandle; + return RETURN_OK; +} + +ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) { + gpioMapIter = gpioMap.find(gpioId); + if (gpioMapIter == gpioMap.end()) { + sif::warning << "LinuxLibgpioIF::pullHigh: Unknown GPIO ID " << gpioId << std::endl; + return UNKNOWN_GPIO_ID; + } + + auto gpioType = gpioMapIter->second->gpioType; + if(gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or + gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL) { + auto regularGpio = dynamic_cast(gpioMapIter->second); + if(regularGpio == nullptr) { + return GPIO_TYPE_FAILURE; + } + return driveGpio(gpioId, *regularGpio, gpio::HIGH); + } + else { + auto gpioCallback = dynamic_cast(gpioMapIter->second); + if(gpioCallback->callback == nullptr) { + return GPIO_INVALID_INSTANCE; + } + gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, + 1, gpioCallback->callbackArgs); + return RETURN_OK; + } + return GPIO_TYPE_FAILURE; +} + +ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) { + gpioMapIter = gpioMap.find(gpioId); + if (gpioMapIter == gpioMap.end()) { + sif::warning << "LinuxLibgpioIF::pullLow: Unknown GPIO ID " << gpioId << std::endl; + return UNKNOWN_GPIO_ID; + } + + auto& gpioType = gpioMapIter->second->gpioType; + if(gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or + gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL) { + auto regularGpio = dynamic_cast(gpioMapIter->second); + if(regularGpio == nullptr) { + return GPIO_TYPE_FAILURE; + } + return driveGpio(gpioId, *regularGpio, gpio::LOW); + } + else { + auto gpioCallback = dynamic_cast(gpioMapIter->second); + if(gpioCallback->callback == nullptr) { + return GPIO_INVALID_INSTANCE; + } + gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, + 0, gpioCallback->callbackArgs); + return RETURN_OK; + } + return GPIO_TYPE_FAILURE; +} + +ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, + GpiodRegularBase& regularGpio, gpio::Levels logicLevel) { + int result = gpiod_line_set_value(regularGpio.lineHandle, logicLevel); + if (result < 0) { + sif::warning << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " << gpioId << + " to logic level " << logicLevel << std::endl; + return DRIVE_GPIO_FAILURE; + } + + return RETURN_OK; +} + +ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) { + gpioMapIter = gpioMap.find(gpioId); + if (gpioMapIter == gpioMap.end()){ + sif::warning << "LinuxLibgpioIF::readGpio: Unknown GPIOD ID " << gpioId << std::endl; + return UNKNOWN_GPIO_ID; + } + auto gpioType = gpioMapIter->second->gpioType; + if(gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or + gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL) { + auto regularGpio = dynamic_cast(gpioMapIter->second); + if(regularGpio == nullptr) { + return GPIO_TYPE_FAILURE; + } + *gpioState = gpiod_line_get_value(regularGpio->lineHandle); + } + else { + + } + + + return RETURN_OK; +} + +ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){ + ReturnValue_t status = HasReturnvaluesIF::RETURN_OK; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + for(auto& gpioConfig: mapToAdd) { + switch(gpioConfig.second->gpioType) { + case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP): + case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL): { + auto regularGpio = dynamic_cast(gpioConfig.second); + if(regularGpio == nullptr) { + return GPIO_TYPE_FAILURE; + } + /* Check for conflicts and remove duplicates if necessary */ + result = checkForConflictsRegularGpio(gpioConfig.first, *regularGpio, mapToAdd); + if(result != HasReturnvaluesIF::RETURN_OK) { + status = result; + } + break; + } + case(gpio::GpioTypes::CALLBACK): { + auto callbackGpio = dynamic_cast(gpioConfig.second); + if(callbackGpio == nullptr) { + return GPIO_TYPE_FAILURE; + } + /* Check for conflicts and remove duplicates if necessary */ + result = checkForConflictsCallbackGpio(gpioConfig.first, callbackGpio, mapToAdd); + if(result != HasReturnvaluesIF::RETURN_OK) { + status = result; + } + break; + } + default: { + + } + } + } + return status; +} + + +ReturnValue_t LinuxLibgpioIF::checkForConflictsRegularGpio(gpioId_t gpioIdToCheck, + GpiodRegularBase& gpioToCheck, GpioMap& mapToAdd) { + /* Cross check with private map */ + gpioMapIter = gpioMap.find(gpioIdToCheck); + if(gpioMapIter != gpioMap.end()) { + auto& gpioType = gpioMapIter->second->gpioType; + if(gpioType != gpio::GpioTypes::GPIO_REGULAR_BY_CHIP and + gpioType != gpio::GpioTypes::GPIO_REGULAR_BY_LABEL) { + sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for different " + "GPIO type" << gpioIdToCheck << ". Removing duplicate." << std::endl; + mapToAdd.erase(gpioIdToCheck); + return HasReturnvaluesIF::RETURN_OK; + } + auto ownRegularGpio = dynamic_cast(gpioMapIter->second); + if(ownRegularGpio == nullptr) { + return GPIO_TYPE_FAILURE; + } + + /* Remove element from map to add because a entry for this GPIO + already exists */ + sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition" + << " detected. Duplicate will be removed from map to add." << std::endl; + mapToAdd.erase(gpioIdToCheck); + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t LinuxLibgpioIF::checkForConflictsCallbackGpio(gpioId_t gpioIdToCheck, + GpioCallback *callbackGpio, GpioMap& mapToAdd) { + /* Cross check with private map */ + gpioMapIter = gpioMap.find(gpioIdToCheck); + if(gpioMapIter != gpioMap.end()) { + if(gpioMapIter->second->gpioType != gpio::GpioTypes::CALLBACK) { + sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for different " + "GPIO type" << gpioIdToCheck << ". Removing duplicate." << std::endl; + mapToAdd.erase(gpioIdToCheck); + return HasReturnvaluesIF::RETURN_OK; + } + + /* Remove element from map to add because a entry for this GPIO + already exists */ + sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition" + << " detected. Duplicate will be removed from map to add." << std::endl; + mapToAdd.erase(gpioIdToCheck); + } + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.h b/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.h new file mode 100644 index 000000000..31e4a7e80 --- /dev/null +++ b/hal/src/fsfw_hal/linux/gpio/LinuxLibgpioIF.h @@ -0,0 +1,82 @@ +#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_ +#define LINUX_GPIO_LINUXLIBGPIOIF_H_ + +#include "../../common/gpio/GpioIF.h" +#include +#include + +class GpioCookie; +class GpiodRegularIF; + +/** + * @brief This class implements the GpioIF for a linux based system. The + * implementation is based on the libgpiod lib which requires linux 4.8 + * or higher. + * @note The Petalinux SDK from Xilinx supports libgpiod since Petalinux + * 2019.1. + */ +class LinuxLibgpioIF : public GpioIF, public SystemObject { +public: + + static const uint8_t gpioRetvalId = CLASS_ID::HAL_GPIO; + + static constexpr ReturnValue_t UNKNOWN_GPIO_ID = + HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 1); + static constexpr ReturnValue_t DRIVE_GPIO_FAILURE = + HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 2); + static constexpr ReturnValue_t GPIO_TYPE_FAILURE = + HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 3); + static constexpr ReturnValue_t GPIO_INVALID_INSTANCE = + HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 4); + + LinuxLibgpioIF(object_id_t objectId); + virtual ~LinuxLibgpioIF(); + + ReturnValue_t addGpios(GpioCookie* gpioCookie) 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: + /* Holds the information and configuration of all used GPIOs */ + GpioUnorderedMap gpioMap; + GpioUnorderedMapIter gpioMapIter; + + /** + * @brief This functions drives line of a GPIO specified by the GPIO ID. + * + * @param gpioId The GPIO ID of the GPIO to drive. + * @param logiclevel The logic level to set. O or 1. + */ + ReturnValue_t driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio, + gpio::Levels logicLevel); + + ReturnValue_t configureGpioByLabel(gpioId_t gpioId, GpiodRegularByLabel& gpioByLabel); + ReturnValue_t configureGpioByChip(gpioId_t gpioId, GpiodRegularByChip& gpioByChip); + ReturnValue_t configureRegularGpio(gpioId_t gpioId, gpio::GpioTypes gpioType, + struct gpiod_chip* chip, GpiodRegularBase& regularGpio, std::string failOutput); + + /** + * @brief This function checks if GPIOs are already registered and whether + * there exists a conflict in the GPIO configuration. E.g. the + * direction. + * + * @param mapToAdd The GPIOs which shall be added to the gpioMap. + * + * @return RETURN_OK if successful, otherwise RETURN_FAILED + */ + ReturnValue_t checkForConflicts(GpioMap& mapToAdd); + + ReturnValue_t checkForConflictsRegularGpio(gpioId_t gpiodId, GpiodRegularBase& regularGpio, + GpioMap& mapToAdd); + ReturnValue_t checkForConflictsCallbackGpio(gpioId_t gpiodId, GpioCallback* regularGpio, + GpioMap& mapToAdd); + + /** + * @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd. + */ + ReturnValue_t configureGpios(GpioMap& mapToAdd); + +}; + +#endif /* LINUX_GPIO_LINUXLIBGPIOIF_H_ */ diff --git a/hal/src/fsfw_hal/linux/i2c/CMakeLists.txt b/hal/src/fsfw_hal/linux/i2c/CMakeLists.txt new file mode 100644 index 000000000..3eb0882cc --- /dev/null +++ b/hal/src/fsfw_hal/linux/i2c/CMakeLists.txt @@ -0,0 +1,8 @@ +target_sources(${LIB_FSFW_NAME} PUBLIC + I2cComIF.cpp + I2cCookie.cpp +) + + + + diff --git a/hal/src/fsfw_hal/linux/i2c/I2cComIF.cpp b/hal/src/fsfw_hal/linux/i2c/I2cComIF.cpp new file mode 100644 index 000000000..98d9a5107 --- /dev/null +++ b/hal/src/fsfw_hal/linux/i2c/I2cComIF.cpp @@ -0,0 +1,205 @@ +#include "fsfw_hal/linux/i2c/I2cComIF.h" +#include "fsfw_hal/linux/utility.h" +#include "fsfw_hal/linux/UnixFileGuard.h" + +#include "fsfw/serviceinterface/ServiceInterface.h" + +#include +#include +#include +#include +#include + +#include + + +I2cComIF::I2cComIF(object_id_t objectId): SystemObject(objectId){ +} + +I2cComIF::~I2cComIF() {} + +ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) { + + address_t i2cAddress; + std::string deviceFile; + + if(cookie == nullptr) { + sif::error << "I2cComIF::initializeInterface: Invalid cookie!" << std::endl; + return NULLPOINTER; + } + I2cCookie* i2cCookie = dynamic_cast(cookie); + if(i2cCookie == nullptr) { + sif::error << "I2cComIF::initializeInterface: Invalid I2C cookie!" << std::endl; + return NULLPOINTER; + } + + i2cAddress = i2cCookie->getAddress(); + + i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); + if(i2cDeviceMapIter == i2cDeviceMap.end()) { + size_t maxReplyLen = i2cCookie->getMaxReplyLen(); + I2cInstance i2cInstance = {std::vector(maxReplyLen), 0}; + auto statusPair = i2cDeviceMap.emplace(i2cAddress, i2cInstance); + if (not statusPair.second) { + sif::error << "I2cComIF::initializeInterface: Failed to insert device with address " << + i2cAddress << "to I2C device " << "map" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + return HasReturnvaluesIF::RETURN_OK; + } + + sif::error << "I2cComIF::initializeInterface: Device with address " << i2cAddress << + "already in use" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; +} + +ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie, + const uint8_t *sendData, size_t sendLen) { + + ReturnValue_t result; + int fd; + std::string deviceFile; + + if(sendData == nullptr) { + sif::error << "I2cComIF::sendMessage: Send Data is nullptr" + << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + + if(sendLen == 0) { + return HasReturnvaluesIF::RETURN_OK; + } + + I2cCookie* i2cCookie = dynamic_cast(cookie); + if(i2cCookie == nullptr) { + sif::error << "I2cComIF::sendMessage: Invalid I2C Cookie!" << std::endl; + return NULLPOINTER; + } + + address_t i2cAddress = i2cCookie->getAddress(); + i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); + if (i2cDeviceMapIter == i2cDeviceMap.end()) { + sif::error << "I2cComIF::sendMessage: i2cAddress of Cookie not " + << "registered in i2cDeviceMap" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + + deviceFile = i2cCookie->getDeviceFile(); + UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::sendMessage"); + if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) { + return fileHelper.getOpenResult(); + } + result = openDevice(deviceFile, i2cAddress, &fd); + if (result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + + if (write(fd, sendData, sendLen) != (int)sendLen) { + sif::error << "I2cComIF::sendMessage: Failed to send data to I2C " + "device with error code " << errno << ". Error description: " + << strerror(errno) << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t I2cComIF::getSendSuccess(CookieIF *cookie) { + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie, + size_t requestLen) { + ReturnValue_t result; + int fd; + std::string deviceFile; + + if (requestLen == 0) { + return HasReturnvaluesIF::RETURN_OK; + } + + I2cCookie* i2cCookie = dynamic_cast(cookie); + if(i2cCookie == nullptr) { + sif::error << "I2cComIF::requestReceiveMessage: Invalid I2C Cookie!" << std::endl; + i2cDeviceMapIter->second.replyLen = 0; + return NULLPOINTER; + } + + address_t i2cAddress = i2cCookie->getAddress(); + i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); + if (i2cDeviceMapIter == i2cDeviceMap.end()) { + sif::error << "I2cComIF::requestReceiveMessage: i2cAddress of Cookie not " + << "registered in i2cDeviceMap" << std::endl; + i2cDeviceMapIter->second.replyLen = 0; + return HasReturnvaluesIF::RETURN_FAILED; + } + + deviceFile = i2cCookie->getDeviceFile(); + UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::requestReceiveMessage"); + if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) { + return fileHelper.getOpenResult(); + } + result = openDevice(deviceFile, i2cAddress, &fd); + if (result != HasReturnvaluesIF::RETURN_OK){ + i2cDeviceMapIter->second.replyLen = 0; + return result; + } + + uint8_t* replyBuffer = i2cDeviceMapIter->second.replyBuffer.data(); + + int readLen = read(fd, replyBuffer, requestLen); + if (readLen != static_cast(requestLen)) { +#if FSFW_VERBOSE_LEVEL >= 1 and FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C " + << "device failed with error code " << errno <<". Description" + << " of error: " << strerror(errno) << std::endl; + sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from " + << requestLen << " bytes" << std::endl; +#endif + i2cDeviceMapIter->second.replyLen = 0; + sif::debug << "I2cComIF::requestReceiveMessage: Read " << readLen << " of " << requestLen << " bytes" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + + i2cDeviceMapIter->second.replyLen = requestLen; + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t I2cComIF::readReceivedMessage(CookieIF *cookie, + uint8_t **buffer, size_t* size) { + I2cCookie* i2cCookie = dynamic_cast(cookie); + if(i2cCookie == nullptr) { + sif::error << "I2cComIF::readReceivedMessage: Invalid I2C Cookie!" << std::endl; + return NULLPOINTER; + } + + address_t i2cAddress = i2cCookie->getAddress(); + i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); + if (i2cDeviceMapIter == i2cDeviceMap.end()) { + sif::error << "I2cComIF::readReceivedMessage: i2cAddress of Cookie not " + << "found in i2cDeviceMap" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + *buffer = i2cDeviceMapIter->second.replyBuffer.data(); + *size = i2cDeviceMapIter->second.replyLen; + + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t I2cComIF::openDevice(std::string deviceFile, + address_t i2cAddress, int* fileDescriptor) { + + if (ioctl(*fileDescriptor, I2C_SLAVE, i2cAddress) < 0) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "I2cComIF: Specifying target device failed with error code " << errno << "." + << std::endl; + sif::warning << "Error description " << strerror(errno) << std::endl; +#else + sif::printWarning("I2cComIF: Specifying target device failed with error code %d.\n"); + sif::printWarning("Error description: %s\n", strerror(errno)); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + return HasReturnvaluesIF::RETURN_FAILED; + } + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/hal/src/fsfw_hal/linux/i2c/I2cComIF.h b/hal/src/fsfw_hal/linux/i2c/I2cComIF.h new file mode 100644 index 000000000..0856c9bde --- /dev/null +++ b/hal/src/fsfw_hal/linux/i2c/I2cComIF.h @@ -0,0 +1,61 @@ +#ifndef LINUX_I2C_I2COMIF_H_ +#define LINUX_I2C_I2COMIF_H_ + +#include "I2cCookie.h" +#include +#include + +#include +#include + +/** + * @brief This is the communication interface for I2C devices connected + * to a system running a Linux OS. + * + * @note The Xilinx Linux kernel might not support to read more than 255 bytes at once. + * + * @author J. Meier + */ +class I2cComIF: public DeviceCommunicationIF, public SystemObject { +public: + I2cComIF(object_id_t objectId); + + virtual ~I2cComIF(); + + ReturnValue_t initializeInterface(CookieIF * cookie) override; + ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData, + size_t sendLen) override; + ReturnValue_t getSendSuccess(CookieIF *cookie) override; + ReturnValue_t requestReceiveMessage(CookieIF *cookie, + size_t requestLen) override; + ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, + size_t *size) override; + +private: + + struct I2cInstance { + std::vector replyBuffer; + size_t replyLen; + }; + + using I2cDeviceMap = std::unordered_map; + using I2cDeviceMapIter = I2cDeviceMap::iterator; + + /* In this map all i2c devices will be registered with their address and + * the appropriate file descriptor will be stored */ + I2cDeviceMap i2cDeviceMap; + I2cDeviceMapIter i2cDeviceMapIter; + + /** + * @brief This function opens an I2C device and binds the opened file + * to a specific I2C address. + * @param deviceFile The name of the device file. E.g. i2c-0 + * @param i2cAddress The address of the i2c slave device. + * @param fileDescriptor Pointer to device descriptor. + * @return RETURN_OK if successful, otherwise RETURN_FAILED. + */ + ReturnValue_t openDevice(std::string deviceFile, + address_t i2cAddress, int* fileDescriptor); +}; + +#endif /* LINUX_I2C_I2COMIF_H_ */ diff --git a/hal/src/fsfw_hal/linux/i2c/I2cCookie.cpp b/hal/src/fsfw_hal/linux/i2c/I2cCookie.cpp new file mode 100644 index 000000000..aebffedba --- /dev/null +++ b/hal/src/fsfw_hal/linux/i2c/I2cCookie.cpp @@ -0,0 +1,20 @@ +#include "fsfw_hal/linux/i2c/I2cCookie.h" + +I2cCookie::I2cCookie(address_t i2cAddress_, size_t maxReplyLen_, + std::string deviceFile_) : + i2cAddress(i2cAddress_), maxReplyLen(maxReplyLen_), deviceFile(deviceFile_) { +} + +address_t I2cCookie::getAddress() const { + return i2cAddress; +} + +size_t I2cCookie::getMaxReplyLen() const { + return maxReplyLen; +} + +std::string I2cCookie::getDeviceFile() const { + return deviceFile; +} + +I2cCookie::~I2cCookie() {} diff --git a/hal/src/fsfw_hal/linux/i2c/I2cCookie.h b/hal/src/fsfw_hal/linux/i2c/I2cCookie.h new file mode 100644 index 000000000..888a2b124 --- /dev/null +++ b/hal/src/fsfw_hal/linux/i2c/I2cCookie.h @@ -0,0 +1,38 @@ +#ifndef LINUX_I2C_I2CCOOKIE_H_ +#define LINUX_I2C_I2CCOOKIE_H_ + +#include +#include + +/** + * @brief Cookie for the i2cDeviceComIF. + * + * @author J. Meier + */ +class I2cCookie: public CookieIF { +public: + + /** + * @brief Constructor for the I2C cookie. + * @param i2cAddress_ The i2c address of the target device. + * @param maxReplyLen_ The maximum expected length of a reply from the + * target device. + * @param devicFile_ The device file specifying the i2c interface to use. E.g. "/dev/i2c-0". + */ + I2cCookie(address_t i2cAddress_, size_t maxReplyLen_, + std::string deviceFile_); + + virtual ~I2cCookie(); + + address_t getAddress() const; + size_t getMaxReplyLen() const; + std::string getDeviceFile() const; + +private: + + address_t i2cAddress = 0; + size_t maxReplyLen = 0; + std::string deviceFile; +}; + +#endif /* LINUX_I2C_I2CCOOKIE_H_ */ diff --git a/hal/src/fsfw_hal/linux/rpi/CMakeLists.txt b/hal/src/fsfw_hal/linux/rpi/CMakeLists.txt new file mode 100644 index 000000000..47be218c0 --- /dev/null +++ b/hal/src/fsfw_hal/linux/rpi/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + GpioRPi.cpp +) \ No newline at end of file diff --git a/hal/src/fsfw_hal/linux/rpi/GpioRPi.cpp b/hal/src/fsfw_hal/linux/rpi/GpioRPi.cpp new file mode 100644 index 000000000..e1c274c0c --- /dev/null +++ b/hal/src/fsfw_hal/linux/rpi/GpioRPi.cpp @@ -0,0 +1,38 @@ +#include "fsfw/FSFW.h" + +#include "fsfw_hal/linux/rpi/GpioRPi.h" +#include "fsfw_hal/common/gpio/GpioCookie.h" + +#include + + +ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin, + std::string consumer, gpio::Direction direction, int initValue) { + if(cookie == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + + auto config = new GpiodRegularByChip(); + /* Default chipname for Raspberry Pi. There is still gpiochip1 for expansion, but most users + will not need this */ + config->chipname = "gpiochip0"; + + config->consumer = consumer; + config->direction = direction; + config->initValue = initValue; + + /* Sanity check for the BCM pins before assigning it */ + if(bcmPin > 27) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "createRpiGpioConfig: BCM pin " << bcmPin << " invalid!" << std::endl; +#else + sif::printError("createRpiGpioConfig: BCM pin %d invalid!\n", bcmPin); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + return HasReturnvaluesIF::RETURN_FAILED; + } + config->lineNum = bcmPin; + cookie->addGpio(gpioId, config); + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/hal/src/fsfw_hal/linux/rpi/GpioRPi.h b/hal/src/fsfw_hal/linux/rpi/GpioRPi.h new file mode 100644 index 000000000..54917e6d0 --- /dev/null +++ b/hal/src/fsfw_hal/linux/rpi/GpioRPi.h @@ -0,0 +1,26 @@ +#ifndef BSP_RPI_GPIO_GPIORPI_H_ +#define BSP_RPI_GPIO_GPIORPI_H_ + +#include +#include "../../common/gpio/gpioDefinitions.h" + +class GpioCookie; + +namespace gpio { + +/** + * Create a GpioConfig_t. This function does a sanity check on the BCM pin number and fails if the + * BCM pin is invalid. + * @param cookie Adds the configuration to this cookie directly + * @param gpioId ID which identifies the GPIO configuration + * @param bcmPin Raspberry Pi BCM pin + * @param consumer Information string + * @param direction GPIO direction + * @param initValue Intial value for output pins, 0 for low, 1 for high + * @return + */ +ReturnValue_t createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin, + std::string consumer, gpio::Direction direction, int initValue); +} + +#endif /* BSP_RPI_GPIO_GPIORPI_H_ */ diff --git a/hal/src/fsfw_hal/linux/spi/CMakeLists.txt b/hal/src/fsfw_hal/linux/spi/CMakeLists.txt new file mode 100644 index 000000000..404e1f477 --- /dev/null +++ b/hal/src/fsfw_hal/linux/spi/CMakeLists.txt @@ -0,0 +1,8 @@ +target_sources(${LIB_FSFW_NAME} PUBLIC + SpiComIF.cpp + SpiCookie.cpp +) + + + + diff --git a/hal/src/fsfw_hal/linux/spi/SpiComIF.cpp b/hal/src/fsfw_hal/linux/spi/SpiComIF.cpp new file mode 100644 index 000000000..9c4e66ae1 --- /dev/null +++ b/hal/src/fsfw_hal/linux/spi/SpiComIF.cpp @@ -0,0 +1,408 @@ +#include "fsfw/FSFW.h" +#include "fsfw_hal/linux/spi/SpiComIF.h" +#include "fsfw_hal/linux/spi/SpiCookie.h" +#include "fsfw_hal/linux/utility.h" +#include "fsfw_hal/linux/UnixFileGuard.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include + +SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF): + SystemObject(objectId), gpioComIF(gpioComIF) { + if(gpioComIF == nullptr) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "SpiComIF::SpiComIF: GPIO communication interface invalid!" << std::endl; +#else + sif::printError("SpiComIF::SpiComIF: GPIO communication interface invalid!\n"); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + } + + spiMutex = MutexFactory::instance()->createMutex(); +} + +ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) { + int retval = 0; + SpiCookie* spiCookie = dynamic_cast(cookie); + if(spiCookie == nullptr) { + return NULLPOINTER; + } + + address_t spiAddress = spiCookie->getSpiAddress(); + + auto iter = spiDeviceMap.find(spiAddress); + if(iter == spiDeviceMap.end()) { + size_t bufferSize = spiCookie->getMaxBufferSize(); + SpiInstance spiInstance(bufferSize); + auto statusPair = spiDeviceMap.emplace(spiAddress, spiInstance); + if (not statusPair.second) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "SpiComIF::initializeInterface: Failed to insert device with address " << + spiAddress << "to SPI device map" << std::endl; +#else + sif::printError("SpiComIF::initializeInterface: Failed to insert device with address " + "%lu to SPI device map\n", static_cast(spiAddress)); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + return HasReturnvaluesIF::RETURN_FAILED; + } + /* Now we emplaced the read buffer in the map, we still need to assign that location + to the SPI driver transfer struct */ + spiCookie->assignReadBuffer(statusPair.first->second.replyBuffer.data()); + } + else { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "SpiComIF::initializeInterface: SPI address already exists!" << std::endl; +#else + sif::printError("SpiComIF::initializeInterface: SPI address already exists!\n"); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + return HasReturnvaluesIF::RETURN_FAILED; + } + + /* Pull CS high in any case to be sure that device is inactive */ + gpioId_t gpioId = spiCookie->getChipSelectPin(); + if(gpioId != gpio::NO_GPIO) { + gpioComIF->pullHigh(gpioId); + } + + uint32_t spiSpeed = 0; + spi::SpiModes spiMode = spi::SpiModes::MODE_0; + + SpiCookie::UncommonParameters params; + spiCookie->getSpiParameters(spiMode, spiSpeed, ¶ms); + + int fileDescriptor = 0; + UnixFileGuard fileHelper(spiCookie->getSpiDevice(), &fileDescriptor, O_RDWR, + "SpiComIF::initializeInterface"); + if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) { + return fileHelper.getOpenResult(); + } + + /* These flags are rather uncommon */ + if(params.threeWireSpi or params.noCs or params.csHigh) { + uint32_t currentMode = 0; + retval = ioctl(fileDescriptor, SPI_IOC_RD_MODE32, ¤tMode); + if(retval != 0) { + utility::handleIoctlError("SpiComIF::initialiezInterface: Could not read full mode!"); + } + + if(params.threeWireSpi) { + currentMode |= SPI_3WIRE; + } + if(params.noCs) { + /* Some drivers like the Raspberry Pi ignore this flag in any case */ + currentMode |= SPI_NO_CS; + } + if(params.csHigh) { + currentMode |= SPI_CS_HIGH; + } + /* Write adapted mode */ + retval = ioctl(fileDescriptor, SPI_IOC_WR_MODE32, ¤tMode); + if(retval != 0) { + utility::handleIoctlError("SpiComIF::initialiezInterface: Could not write full mode!"); + } + } + if(params.lsbFirst) { + retval = ioctl(fileDescriptor, SPI_IOC_WR_LSB_FIRST, ¶ms.lsbFirst); + if(retval != 0) { + utility::handleIoctlError("SpiComIF::initializeInterface: Setting LSB first failed"); + } + } + if(params.bitsPerWord != 8) { + retval = ioctl(fileDescriptor, SPI_IOC_WR_BITS_PER_WORD, ¶ms.bitsPerWord); + if(retval != 0) { + utility::handleIoctlError("SpiComIF::initializeInterface: " + "Could not write bits per word!"); + } + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) { + SpiCookie* spiCookie = dynamic_cast(cookie); + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + + if(spiCookie == nullptr) { + return NULLPOINTER; + } + + if(sendLen > spiCookie->getMaxBufferSize()) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "SpiComIF::sendMessage: Too much data sent, send length " << sendLen << + "larger than maximum buffer length " << spiCookie->getMaxBufferSize() << std::endl; +#else + sif::printWarning("SpiComIF::sendMessage: Too much data sent, send length %lu larger " + "than maximum buffer length %lu!\n", static_cast(sendLen), + static_cast(spiCookie->getMaxBufferSize())); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + return DeviceCommunicationIF::TOO_MUCH_DATA; + } + + if(spiCookie->getComIfMode() == spi::SpiComIfModes::REGULAR) { + result = performRegularSendOperation(spiCookie, sendData, sendLen); + } + else if(spiCookie->getComIfMode() == spi::SpiComIfModes::CALLBACK) { + spi::send_callback_function_t sendFunc = nullptr; + void* funcArgs = nullptr; + spiCookie->getCallback(&sendFunc, &funcArgs); + if(sendFunc != nullptr) { + result = sendFunc(this, spiCookie, sendData, sendLen, funcArgs); + } + } + return result; +} + +ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const uint8_t *sendData, + size_t sendLen) { + address_t spiAddress = spiCookie->getSpiAddress(); + auto iter = spiDeviceMap.find(spiAddress); + if(iter != spiDeviceMap.end()) { + spiCookie->assignReadBuffer(iter->second.replyBuffer.data()); + } + + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + int retval = 0; + /* Prepare transfer */ + int fileDescriptor = 0; + std::string device = spiCookie->getSpiDevice(); + UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage"); + if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) { + return OPENING_FILE_FAILED; + } + spi::SpiModes spiMode = spi::SpiModes::MODE_0; + uint32_t spiSpeed = 0; + spiCookie->getSpiParameters(spiMode, spiSpeed, nullptr); + setSpiSpeedAndMode(fileDescriptor, spiMode, spiSpeed); + spiCookie->assignWriteBuffer(sendData); + spiCookie->setTransferSize(sendLen); + + bool fullDuplex = spiCookie->isFullDuplex(); + gpioId_t gpioId = spiCookie->getChipSelectPin(); + + /* Pull SPI CS low. For now, no support for active high given */ + if(gpioId != gpio::NO_GPIO) { + result = spiMutex->lockMutex(timeoutType, timeoutMs); + if (result != RETURN_OK) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "SpiComIF::sendMessage: Failed to lock mutex" << std::endl; +#else + sif::printError("SpiComIF::sendMessage: Failed to lock mutex\n"); +#endif +#endif + return result; + } + ReturnValue_t result = gpioComIF->pullLow(gpioId); + if(result != HasReturnvaluesIF::RETURN_OK) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "SpiComIF::sendMessage: Pulling low CS pin failed" << std::endl; +#else + sif::printWarning("SpiComIF::sendMessage: Pulling low CS pin failed"); +#endif +#endif + return result; + } + } + + /* Execute transfer */ + if(fullDuplex) { + /* Initiate a full duplex SPI transfer. */ + retval = ioctl(fileDescriptor, SPI_IOC_MESSAGE(1), spiCookie->getTransferStructHandle()); + if(retval < 0) { + utility::handleIoctlError("SpiComIF::sendMessage: ioctl error."); + result = FULL_DUPLEX_TRANSFER_FAILED; + } +#if FSFW_HAL_SPI_WIRETAPPING == 1 + performSpiWiretapping(spiCookie); +#endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */ + } + else { + /* We write with a blocking half-duplex transfer here */ + if (write(fileDescriptor, sendData, sendLen) != static_cast(sendLen)) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "SpiComIF::sendMessage: Half-Duplex write operation failed!" << + std::endl; +#else + sif::printWarning("SpiComIF::sendMessage: Half-Duplex write operation failed!\n"); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + result = HALF_DUPLEX_TRANSFER_FAILED; + } + } + + if(gpioId != gpio::NO_GPIO) { + gpioComIF->pullHigh(gpioId); + result = spiMutex->unlockMutex(); + if (result != RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "SpiComIF::sendMessage: Failed to unlock mutex" << std::endl; +#endif + return result; + } + } + return result; +} + +ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) { + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) { + SpiCookie* spiCookie = dynamic_cast(cookie); + if(spiCookie == nullptr) { + return NULLPOINTER; + } + + if(spiCookie->isFullDuplex()) { + return HasReturnvaluesIF::RETURN_OK; + } + + return performHalfDuplexReception(spiCookie); +} + + +ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + std::string device = spiCookie->getSpiDevice(); + int fileDescriptor = 0; + UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, + "SpiComIF::requestReceiveMessage"); + if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) { + return OPENING_FILE_FAILED; + } + + uint8_t* rxBuf = nullptr; + size_t readSize = spiCookie->getCurrentTransferSize(); + result = getReadBuffer(spiCookie->getSpiAddress(), &rxBuf); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + + gpioId_t gpioId = spiCookie->getChipSelectPin(); + if(gpioId != gpio::NO_GPIO) { + result = spiMutex->lockMutex(timeoutType, timeoutMs); + if (result != RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "SpiComIF::getSendSuccess: Failed to lock mutex" << std::endl; +#endif + return result; + } + gpioComIF->pullLow(gpioId); + } + + if(read(fileDescriptor, rxBuf, readSize) != static_cast(readSize)) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "SpiComIF::sendMessage: Half-Duplex read operation failed!" << std::endl; +#else + sif::printWarning("SpiComIF::sendMessage: Half-Duplex read operation failed!\n"); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + result = HALF_DUPLEX_TRANSFER_FAILED; + } + + if(gpioId != gpio::NO_GPIO) { + gpioComIF->pullHigh(gpioId); + result = spiMutex->unlockMutex(); + if (result != RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "SpiComIF::getSendSuccess: Failed to unlock mutex" << std::endl; +#endif + return result; + } + } + + return result; +} + +ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) { + SpiCookie* spiCookie = dynamic_cast(cookie); + if(spiCookie == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + uint8_t* rxBuf = nullptr; + ReturnValue_t result = getReadBuffer(spiCookie->getSpiAddress(), &rxBuf); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + + *buffer = rxBuf; + *size = spiCookie->getCurrentTransferSize(); + spiCookie->setTransferSize(0); + return HasReturnvaluesIF::RETURN_OK; +} + +MutexIF* SpiComIF::getMutex(MutexIF::TimeoutType* timeoutType, uint32_t* timeoutMs) { + if(timeoutType != nullptr) { + *timeoutType = this->timeoutType; + } + if(timeoutMs != nullptr) { + *timeoutMs = this->timeoutMs; + } + return spiMutex; +} + +void SpiComIF::performSpiWiretapping(SpiCookie* spiCookie) { + if(spiCookie == nullptr) { + return; + } + size_t dataLen = spiCookie->getTransferStructHandle()->len; + uint8_t* dataPtr = reinterpret_cast(spiCookie->getTransferStructHandle()->tx_buf); +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Sent SPI data: " << std::endl; + arrayprinter::print(dataPtr, dataLen, OutputType::HEX, false); + sif::info << "Received SPI data: " << std::endl; +#else + sif::printInfo("Sent SPI data: \n"); + arrayprinter::print(dataPtr, dataLen, OutputType::HEX, false); + sif::printInfo("Received SPI data: \n"); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + dataPtr = reinterpret_cast(spiCookie->getTransferStructHandle()->rx_buf); + arrayprinter::print(dataPtr, dataLen, OutputType::HEX, false); +} + +ReturnValue_t SpiComIF::getReadBuffer(address_t spiAddress, uint8_t** buffer) { + if(buffer == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + + auto iter = spiDeviceMap.find(spiAddress); + if(iter == spiDeviceMap.end()) { + return HasReturnvaluesIF::RETURN_FAILED; + } + + *buffer = iter->second.replyBuffer.data(); + return HasReturnvaluesIF::RETURN_OK; +} + +GpioIF* SpiComIF::getGpioInterface() { + return gpioComIF; +} + +void SpiComIF::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed) { + int retval = ioctl(spiFd, SPI_IOC_WR_MODE, reinterpret_cast(&mode)); + if(retval != 0) { + utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI mode failed"); + } + + retval = ioctl(spiFd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); + if(retval != 0) { + utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI speed failed"); + } +} diff --git a/hal/src/fsfw_hal/linux/spi/SpiComIF.h b/hal/src/fsfw_hal/linux/spi/SpiComIF.h new file mode 100644 index 000000000..bcca7462d --- /dev/null +++ b/hal/src/fsfw_hal/linux/spi/SpiComIF.h @@ -0,0 +1,91 @@ +#ifndef LINUX_SPI_SPICOMIF_H_ +#define LINUX_SPI_SPICOMIF_H_ + +#include "fsfw/FSFW.h" +#include "spiDefinitions.h" +#include "returnvalues/classIds.h" +#include "fsfw_hal/common/gpio/GpioIF.h" + +#include "fsfw/devicehandlers/DeviceCommunicationIF.h" +#include "fsfw/objectmanager/SystemObject.h" + +#include +#include + +class SpiCookie; + +/** + * @brief Encapsulates access to linux SPI driver for FSFW objects + * @details + * Right now, only full-duplex SPI is supported. Most device specific transfer properties + * are contained in the SPI cookie. + * @author R. Mueller + */ +class SpiComIF: public DeviceCommunicationIF, public SystemObject { +public: + static constexpr uint8_t spiRetvalId = CLASS_ID::HAL_SPI; + static constexpr ReturnValue_t OPENING_FILE_FAILED = + HasReturnvaluesIF::makeReturnCode(spiRetvalId, 0); + /* Full duplex (ioctl) transfer failure */ + static constexpr ReturnValue_t FULL_DUPLEX_TRANSFER_FAILED = + HasReturnvaluesIF::makeReturnCode(spiRetvalId, 1); + /* Half duplex (read/write) transfer failure */ + static constexpr ReturnValue_t HALF_DUPLEX_TRANSFER_FAILED = + HasReturnvaluesIF::makeReturnCode(spiRetvalId, 2); + + SpiComIF(object_id_t objectId, GpioIF* gpioComIF); + + ReturnValue_t initializeInterface(CookieIF * cookie) override; + ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData, + size_t sendLen) override; + ReturnValue_t getSendSuccess(CookieIF *cookie) override; + ReturnValue_t requestReceiveMessage(CookieIF *cookie, + size_t requestLen) override; + ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, + size_t *size) override; + + /** + * @brief This function returns the mutex which can be used to protect the spi bus when + * the chip select must be driven from outside of the com if. + */ + MutexIF* getMutex(MutexIF::TimeoutType* timeoutType = nullptr, uint32_t* timeoutMs = nullptr); + + /** + * Perform a regular send operation using Linux iotcl. This is public so it can be used + * in functions like a user callback if special handling is only necessary for certain commands. + * @param spiCookie + * @param sendData + * @param sendLen + * @return + */ + ReturnValue_t performRegularSendOperation(SpiCookie* spiCookie, const uint8_t *sendData, + size_t sendLen); + + GpioIF* getGpioInterface(); + void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed); + void performSpiWiretapping(SpiCookie* spiCookie); + + ReturnValue_t getReadBuffer(address_t spiAddress, uint8_t** buffer); + +private: + + struct SpiInstance { + SpiInstance(size_t maxRecvSize): replyBuffer(std::vector(maxRecvSize)) {} + std::vector replyBuffer; + }; + + GpioIF* gpioComIF = nullptr; + + MutexIF* spiMutex = nullptr; + MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; + uint32_t timeoutMs = 20; + + using SpiDeviceMap = std::unordered_map; + using SpiDeviceMapIter = SpiDeviceMap::iterator; + + SpiDeviceMap spiDeviceMap; + + ReturnValue_t performHalfDuplexReception(SpiCookie* spiCookie); +}; + +#endif /* LINUX_SPI_SPICOMIF_H_ */ diff --git a/hal/src/fsfw_hal/linux/spi/SpiCookie.cpp b/hal/src/fsfw_hal/linux/spi/SpiCookie.cpp new file mode 100644 index 000000000..f07954e95 --- /dev/null +++ b/hal/src/fsfw_hal/linux/spi/SpiCookie.cpp @@ -0,0 +1,144 @@ +#include "fsfw_hal/linux/spi/SpiCookie.h" + +SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, + const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed): + SpiCookie(spi::SpiComIfModes::REGULAR, spiAddress, chipSelect, spiDev, maxSize, spiMode, + spiSpeed, nullptr, nullptr) { + +} + +SpiCookie::SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxSize, + spi::SpiModes spiMode, uint32_t spiSpeed): + SpiCookie(spiAddress, gpio::NO_GPIO, spiDev, maxSize, spiMode, spiSpeed) { +} + +SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, + const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed, + spi::send_callback_function_t callback, void *args): + SpiCookie(spi::SpiComIfModes::CALLBACK, spiAddress, chipSelect, spiDev, maxSize, + spiMode, spiSpeed, callback, args) { +} + +SpiCookie::SpiCookie(spi::SpiComIfModes comIfMode, address_t spiAddress, gpioId_t chipSelect, + std::string spiDev, const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed, + spi::send_callback_function_t callback, void* args): + spiAddress(spiAddress), chipSelectPin(chipSelect), spiDevice(spiDev), + comIfMode(comIfMode), maxSize(maxSize), spiMode(spiMode), spiSpeed(spiSpeed), + sendCallback(callback), callbackArgs(args) { +} + +spi::SpiComIfModes SpiCookie::getComIfMode() const { + return this->comIfMode; +} + +void SpiCookie::getSpiParameters(spi::SpiModes& spiMode, uint32_t& spiSpeed, + UncommonParameters* parameters) const { + spiMode = this->spiMode; + spiSpeed = this->spiSpeed; + + if(parameters != nullptr) { + parameters->threeWireSpi = uncommonParameters.threeWireSpi; + parameters->lsbFirst = uncommonParameters.lsbFirst; + parameters->noCs = uncommonParameters.noCs; + parameters->bitsPerWord = uncommonParameters.bitsPerWord; + parameters->csHigh = uncommonParameters.csHigh; + } +} + +gpioId_t SpiCookie::getChipSelectPin() const { + return chipSelectPin; +} + +size_t SpiCookie::getMaxBufferSize() const { + return maxSize; +} + +address_t SpiCookie::getSpiAddress() const { + return spiAddress; +} + +std::string SpiCookie::getSpiDevice() const { + return spiDevice; +} + +void SpiCookie::setThreeWireSpi(bool enable) { + uncommonParameters.threeWireSpi = enable; +} + +void SpiCookie::setLsbFirst(bool enable) { + uncommonParameters.lsbFirst = enable; +} + +void SpiCookie::setNoCs(bool enable) { + uncommonParameters.noCs = enable; +} + +void SpiCookie::setBitsPerWord(uint8_t bitsPerWord) { + uncommonParameters.bitsPerWord = bitsPerWord; +} + +void SpiCookie::setCsHigh(bool enable) { + uncommonParameters.csHigh = enable; +} + +void SpiCookie::activateCsDeselect(bool deselectCs, uint16_t delayUsecs) { + spiTransferStruct.cs_change = deselectCs; + spiTransferStruct.delay_usecs = delayUsecs; +} + +void SpiCookie::assignReadBuffer(uint8_t* rx) { + if(rx != nullptr) { + spiTransferStruct.rx_buf = reinterpret_cast<__u64>(rx); + } +} + +void SpiCookie::assignWriteBuffer(const uint8_t* tx) { + if(tx != nullptr) { + spiTransferStruct.tx_buf = reinterpret_cast<__u64>(tx); + } +} + +void SpiCookie::setCallbackMode(spi::send_callback_function_t callback, + void *args) { + this->comIfMode = spi::SpiComIfModes::CALLBACK; + this->sendCallback = callback; + this->callbackArgs = args; +} + +void SpiCookie::setCallbackArgs(void *args) { + this->callbackArgs = args; +} + +spi_ioc_transfer* SpiCookie::getTransferStructHandle() { + return &spiTransferStruct; +} + +void SpiCookie::setFullOrHalfDuplex(bool halfDuplex) { + this->halfDuplex = halfDuplex; +} + +bool SpiCookie::isFullDuplex() const { + return not this->halfDuplex; +} + +void SpiCookie::setTransferSize(size_t transferSize) { + spiTransferStruct.len = transferSize; +} + +size_t SpiCookie::getCurrentTransferSize() const { + return spiTransferStruct.len; +} + +void SpiCookie::setSpiSpeed(uint32_t newSpeed) { + this->spiSpeed = newSpeed; +} + +void SpiCookie::setSpiMode(spi::SpiModes newMode) { + this->spiMode = newMode; +} + +void SpiCookie::getCallback(spi::send_callback_function_t *callback, + void **args) { + *callback = this->sendCallback; + *args = this->callbackArgs; +} diff --git a/hal/src/fsfw_hal/linux/spi/SpiCookie.h b/hal/src/fsfw_hal/linux/spi/SpiCookie.h new file mode 100644 index 000000000..844fd4219 --- /dev/null +++ b/hal/src/fsfw_hal/linux/spi/SpiCookie.h @@ -0,0 +1,183 @@ +#ifndef LINUX_SPI_SPICOOKIE_H_ +#define LINUX_SPI_SPICOOKIE_H_ + +#include "spiDefinitions.h" +#include "../../common/gpio/gpioDefinitions.h" + +#include + +#include + +/** + * @brief This cookie class is passed to the SPI communication interface + * @details + * This cookie contains device specific properties like speed and SPI mode or the SPI transfer + * struct required by the Linux SPI driver. It also contains a handle to a GPIO interface + * to perform slave select switching when necessary. + * + * The user can specify gpio::NO_GPIO as the GPIO ID or use a custom send callback to meet + * special requirements like expander slave select switching (e.g. GPIO or I2C expander) + * or special timing related requirements. + */ +class SpiCookie: public CookieIF { +public: + /** + * Each SPI device will have a corresponding cookie. The cookie is used by the communication + * interface and contains device specific information like the largest expected size to be + * sent and received and the GPIO pin used to toggle the SPI slave select pin. + * @param spiAddress + * @param chipSelect Chip select. gpio::NO_GPIO can be used for hardware slave selects. + * @param spiDev + * @param maxSize + */ + SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, + const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed); + + /** + * Like constructor above, but without a dedicated GPIO CS. Can be used for hardware + * slave select or if CS logic is performed with decoders. + */ + SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxReplySize, + spi::SpiModes spiMode, uint32_t spiSpeed); + + /** + * Use the callback mode of the SPI communication interface. The user can pass the callback + * function here or by using the setter function #setCallbackMode + */ + SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxSize, + spi::SpiModes spiMode, uint32_t spiSpeed, spi::send_callback_function_t callback, + void *args); + + /** + * Get the callback function + * @param callback + * @param args + */ + void getCallback(spi::send_callback_function_t* callback, void** args); + + address_t getSpiAddress() const; + std::string getSpiDevice() const; + gpioId_t getChipSelectPin() const; + size_t getMaxBufferSize() const; + + spi::SpiComIfModes getComIfMode() const; + + /** Enables changing SPI speed at run-time */ + void setSpiSpeed(uint32_t newSpeed); + /** Enables changing the SPI mode at run-time */ + void setSpiMode(spi::SpiModes newMode); + + /** + * Set the SPI to callback mode and assigns the user supplied callback and an argument + * passed to the callback. + * @param callback + * @param args + */ + void setCallbackMode(spi::send_callback_function_t callback, void* args); + + /** + * Can be used to set the callback arguments and a later point than initialization. + * @param args + */ + void setCallbackArgs(void* args); + + /** + * True if SPI transfers should be performed in full duplex mode + * @return + */ + bool isFullDuplex() const; + + /** + * Set transfer type to full duplex or half duplex. Full duplex is the default setting, + * ressembling common SPI hardware implementation with shift registers, where read and writes + * happen simultaneosly. + * @param fullDuplex + */ + void setFullOrHalfDuplex(bool halfDuplex); + + /** + * This needs to be called to specify where the SPI driver writes to or reads from. + * @param readLocation + * @param writeLocation + */ + void assignReadBuffer(uint8_t* rx); + void assignWriteBuffer(const uint8_t* tx); + /** + * Set size for the next transfer. Set to 0 for no transfer + * @param transferSize + */ + void setTransferSize(size_t transferSize); + size_t getCurrentTransferSize() const; + + struct UncommonParameters { + uint8_t bitsPerWord = 8; + bool noCs = false; + bool csHigh = false; + bool threeWireSpi = false; + /* MSB first is more common */ + bool lsbFirst = false; + }; + + /** + * Can be used to explicitely disable hardware chip select. + * Some drivers like the Raspberry Pi Linux driver will not use hardware chip select by default + * (see https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md) + * @param enable + */ + void setNoCs(bool enable); + void setThreeWireSpi(bool enable); + void setLsbFirst(bool enable); + void setCsHigh(bool enable); + void setBitsPerWord(uint8_t bitsPerWord); + + void getSpiParameters(spi::SpiModes& spiMode, uint32_t& spiSpeed, + UncommonParameters* parameters = nullptr) const; + + /** + * See spidev.h cs_change and delay_usecs + * @param deselectCs + * @param delayUsecs + */ + void activateCsDeselect(bool deselectCs, uint16_t delayUsecs); + + spi_ioc_transfer* getTransferStructHandle(); +private: + + /** + * Internal constructor which initializes every field + * @param spiAddress + * @param chipSelect + * @param spiDev + * @param maxSize + * @param spiMode + * @param spiSpeed + * @param callback + * @param args + */ + SpiCookie(spi::SpiComIfModes comIfMode, address_t spiAddress, gpioId_t chipSelect, + std::string spiDev, const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed, + spi::send_callback_function_t callback, void* args); + + address_t spiAddress; + gpioId_t chipSelectPin; + std::string spiDevice; + + spi::SpiComIfModes comIfMode; + + // Required for regular mode + const size_t maxSize; + spi::SpiModes spiMode; + uint32_t spiSpeed; + bool halfDuplex = false; + + // Required for callback mode + spi::send_callback_function_t sendCallback = nullptr; + void* callbackArgs = nullptr; + + struct spi_ioc_transfer spiTransferStruct = {}; + UncommonParameters uncommonParameters; +}; + + + +#endif /* LINUX_SPI_SPICOOKIE_H_ */ diff --git a/hal/src/fsfw_hal/linux/spi/spiDefinitions.h b/hal/src/fsfw_hal/linux/spi/spiDefinitions.h new file mode 100644 index 000000000..14af4fd52 --- /dev/null +++ b/hal/src/fsfw_hal/linux/spi/spiDefinitions.h @@ -0,0 +1,28 @@ +#ifndef LINUX_SPI_SPIDEFINITONS_H_ +#define LINUX_SPI_SPIDEFINITONS_H_ + +#include "../../common/gpio/gpioDefinitions.h" +#include "../../common/spi/spiCommon.h" + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include + +#include + +class SpiCookie; +class SpiComIF; + +namespace spi { + +enum SpiComIfModes { + REGULAR, + CALLBACK +}; + + +using send_callback_function_t = ReturnValue_t (*) (SpiComIF* comIf, SpiCookie *cookie, + const uint8_t *sendData, size_t sendLen, void* args); + +} + +#endif /* LINUX_SPI_SPIDEFINITONS_H_ */ diff --git a/hal/src/fsfw_hal/linux/uart/CMakeLists.txt b/hal/src/fsfw_hal/linux/uart/CMakeLists.txt new file mode 100644 index 000000000..21ed0278f --- /dev/null +++ b/hal/src/fsfw_hal/linux/uart/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(${LIB_FSFW_NAME} PUBLIC + UartComIF.cpp + UartCookie.cpp +) diff --git a/hal/src/fsfw_hal/linux/uart/UartComIF.cpp b/hal/src/fsfw_hal/linux/uart/UartComIF.cpp new file mode 100644 index 000000000..f5754c6ea --- /dev/null +++ b/hal/src/fsfw_hal/linux/uart/UartComIF.cpp @@ -0,0 +1,529 @@ +#include "UartComIF.h" +#include "OBSWConfig.h" + +#include "fsfw_hal/linux/utility.h" +#include "fsfw/serviceinterface/ServiceInterface.h" + +#include +#include +#include +#include +#include + +UartComIF::UartComIF(object_id_t objectId): SystemObject(objectId){ +} + +UartComIF::~UartComIF() {} + +ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) { + + std::string deviceFile; + UartDeviceMapIter uartDeviceMapIter; + + if(cookie == nullptr) { + return NULLPOINTER; + } + + UartCookie* uartCookie = dynamic_cast(cookie); + if (uartCookie == nullptr) { + sif::error << "UartComIF::initializeInterface: Invalid UART Cookie!" << std::endl; + return NULLPOINTER; + } + + deviceFile = uartCookie->getDeviceFile(); + + uartDeviceMapIter = uartDeviceMap.find(deviceFile); + if(uartDeviceMapIter == uartDeviceMap.end()) { + int fileDescriptor = configureUartPort(uartCookie); + if (fileDescriptor < 0) { + return RETURN_FAILED; + } + size_t maxReplyLen = uartCookie->getMaxReplyLen(); + UartElements uartElements = {fileDescriptor, std::vector(maxReplyLen), 0}; + auto status = uartDeviceMap.emplace(deviceFile, uartElements); + if (status.second == false) { + sif::warning << "UartComIF::initializeInterface: Failed to insert device " << + deviceFile << "to UART device map" << std::endl; + return RETURN_FAILED; + } + } + else { + sif::warning << "UartComIF::initializeInterface: UART device " << deviceFile << + " already in use" << std::endl; + return RETURN_FAILED; + } + + return RETURN_OK; +} + +int UartComIF::configureUartPort(UartCookie* uartCookie) { + + struct termios options = {}; + + std::string deviceFile = uartCookie->getDeviceFile(); + int flags = O_RDWR; + if(uartCookie->getUartMode() == UartModes::CANONICAL) { + // In non-canonical mode, don't specify O_NONBLOCK because these properties will be + // controlled by the VTIME and VMIN parameters and O_NONBLOCK would override this + flags |= O_NONBLOCK; + } + int fd = open(deviceFile.c_str(), flags); + + if (fd < 0) { + sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile << + "with error code " << errno << strerror(errno) << std::endl; + return fd; + } + + /* Read in existing settings */ + if(tcgetattr(fd, &options) != 0) { + sif::warning << "UartComIF::configureUartPort: Error " << errno << "from tcgetattr: " + << strerror(errno) << std::endl; + return fd; + } + + setParityOptions(&options, uartCookie); + setStopBitOptions(&options, uartCookie); + setDatasizeOptions(&options, uartCookie); + setFixedOptions(&options); + setUartMode(&options, *uartCookie); + if(uartCookie->getInputShouldBeFlushed()) { + tcflush(fd, TCIFLUSH); + } + + /* Sets uart to non-blocking mode. Read returns immediately when there are no data available */ + options.c_cc[VTIME] = 0; + options.c_cc[VMIN] = 0; + + configureBaudrate(&options, uartCookie); + + /* Save option settings */ + if (tcsetattr(fd, TCSANOW, &options) != 0) { + sif::warning << "UartComIF::configureUartPort: Failed to set options with error " << + errno << ": " << strerror(errno); + return fd; + } + return fd; +} + +void UartComIF::setParityOptions(struct termios* options, UartCookie* uartCookie) { + /* Clear parity bit */ + options->c_cflag &= ~PARENB; + switch (uartCookie->getParity()) { + case Parity::EVEN: + options->c_cflag |= PARENB; + options->c_cflag &= ~PARODD; + break; + case Parity::ODD: + options->c_cflag |= PARENB; + options->c_cflag |= PARODD; + break; + default: + break; + } +} + +void UartComIF::setStopBitOptions(struct termios* options, UartCookie* uartCookie) { + /* Clear stop field. Sets stop bit to one bit */ + options->c_cflag &= ~CSTOPB; + switch (uartCookie->getStopBits()) { + case StopBits::TWO_STOP_BITS: + options->c_cflag |= CSTOPB; + break; + default: + break; + } +} + +void UartComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCookie) { + /* Clear size bits */ + options->c_cflag &= ~CSIZE; + switch (uartCookie->getBitsPerWord()) { + case 5: + options->c_cflag |= CS5; + break; + case 6: + options->c_cflag |= CS6; + break; + case 7: + options->c_cflag |= CS7; + break; + case 8: + options->c_cflag |= CS8; + break; + default: + sif::warning << "UartComIF::setDatasizeOptions: Invalid size specified" << std::endl; + break; + } +} + +void UartComIF::setFixedOptions(struct termios* options) { + /* Disable RTS/CTS hardware flow control */ + options->c_cflag &= ~CRTSCTS; + /* Turn on READ & ignore ctrl lines (CLOCAL = 1) */ + options->c_cflag |= CREAD | CLOCAL; + /* Disable echo */ + options->c_lflag &= ~ECHO; + /* Disable erasure */ + options->c_lflag &= ~ECHOE; + /* Disable new-line echo */ + options->c_lflag &= ~ECHONL; + /* Disable interpretation of INTR, QUIT and SUSP */ + options->c_lflag &= ~ISIG; + /* Turn off s/w flow ctrl */ + options->c_iflag &= ~(IXON | IXOFF | IXANY); + /* Disable any special handling of received bytes */ + options->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL); + /* Prevent special interpretation of output bytes (e.g. newline chars) */ + options->c_oflag &= ~OPOST; + /* Prevent conversion of newline to carriage return/line feed */ + options->c_oflag &= ~ONLCR; +} + +void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCookie) { + switch (uartCookie->getBaudrate()) { + case 50: + cfsetispeed(options, B50); + cfsetospeed(options, B50); + break; + case 75: + cfsetispeed(options, B75); + cfsetospeed(options, B75); + break; + case 110: + cfsetispeed(options, B110); + cfsetospeed(options, B110); + break; + case 134: + cfsetispeed(options, B134); + cfsetospeed(options, B134); + break; + case 150: + cfsetispeed(options, B150); + cfsetospeed(options, B150); + break; + case 200: + cfsetispeed(options, B200); + cfsetospeed(options, B200); + break; + case 300: + cfsetispeed(options, B300); + cfsetospeed(options, B300); + break; + case 600: + cfsetispeed(options, B600); + cfsetospeed(options, B600); + break; + case 1200: + cfsetispeed(options, B1200); + cfsetospeed(options, B1200); + break; + case 1800: + cfsetispeed(options, B1800); + cfsetospeed(options, B1800); + break; + case 2400: + cfsetispeed(options, B2400); + cfsetospeed(options, B2400); + break; + case 4800: + cfsetispeed(options, B4800); + cfsetospeed(options, B4800); + break; + case 9600: + cfsetispeed(options, B9600); + cfsetospeed(options, B9600); + break; + case 19200: + cfsetispeed(options, B19200); + cfsetospeed(options, B19200); + break; + case 38400: + cfsetispeed(options, B38400); + cfsetospeed(options, B38400); + break; + case 57600: + cfsetispeed(options, B57600); + cfsetospeed(options, B57600); + break; + case 115200: + cfsetispeed(options, B115200); + cfsetospeed(options, B115200); + break; + case 230400: + cfsetispeed(options, B230400); + cfsetospeed(options, B230400); + break; + case 460800: + cfsetispeed(options, B460800); + cfsetospeed(options, B460800); + break; + default: + sif::warning << "UartComIF::configureBaudrate: Baudrate not supported" << std::endl; + break; + } +} + +ReturnValue_t UartComIF::sendMessage(CookieIF *cookie, + const uint8_t *sendData, size_t sendLen) { + int fd = 0; + std::string deviceFile; + UartDeviceMapIter uartDeviceMapIter; + + if(sendLen == 0) { + return RETURN_OK; + } + + if(sendData == nullptr) { + sif::warning << "UartComIF::sendMessage: Send data is nullptr" << std::endl; + return RETURN_FAILED; + } + + UartCookie* uartCookie = dynamic_cast(cookie); + if(uartCookie == nullptr) { + sif::warning << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl; + return NULLPOINTER; + } + + deviceFile = uartCookie->getDeviceFile(); + uartDeviceMapIter = uartDeviceMap.find(deviceFile); + if (uartDeviceMapIter == uartDeviceMap.end()) { + sif::debug << "UartComIF::sendMessage: Device file " << deviceFile << + "not in UART map" << std::endl; + return RETURN_FAILED; + } + + fd = uartDeviceMapIter->second.fileDescriptor; + + if (write(fd, sendData, sendLen) != (int)sendLen) { + sif::error << "UartComIF::sendMessage: Failed to send data with error code " << + errno << ": Error description: " << strerror(errno) << std::endl; + return RETURN_FAILED; + } + + return RETURN_OK; +} + +ReturnValue_t UartComIF::getSendSuccess(CookieIF *cookie) { + return RETURN_OK; +} + +ReturnValue_t UartComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) { + std::string deviceFile; + UartDeviceMapIter uartDeviceMapIter; + + UartCookie* uartCookie = dynamic_cast(cookie); + if(uartCookie == nullptr) { + sif::debug << "UartComIF::requestReceiveMessage: Invalid Uart Cookie!" << std::endl; + return NULLPOINTER; + } + + UartModes uartMode = uartCookie->getUartMode(); + deviceFile = uartCookie->getDeviceFile(); + uartDeviceMapIter = uartDeviceMap.find(deviceFile); + + if(uartMode == UartModes::NON_CANONICAL and requestLen == 0) { + return RETURN_OK; + } + + if (uartDeviceMapIter == uartDeviceMap.end()) { + sif::debug << "UartComIF::requestReceiveMessage: Device file " << deviceFile + << " not in uart map" << std::endl; + return RETURN_FAILED; + } + + if (uartMode == UartModes::CANONICAL) { + return handleCanonicalRead(*uartCookie, uartDeviceMapIter, requestLen); + } + else if (uartMode == UartModes::NON_CANONICAL) { + return handleNoncanonicalRead(*uartCookie, uartDeviceMapIter, requestLen); + } + else { + return HasReturnvaluesIF::RETURN_FAILED; + } +} + +ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter, + size_t requestLen) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + uint8_t maxReadCycles = uartCookie.getReadCycles(); + uint8_t currentReadCycles = 0; + int bytesRead = 0; + size_t currentBytesRead = 0; + size_t maxReplySize = uartCookie.getMaxReplyLen(); + int fd = iter->second.fileDescriptor; + auto bufferPtr = iter->second.replyBuffer.data(); + iter->second.replyLen = 0; + do { + size_t allowedReadSize = 0; + if(currentBytesRead >= maxReplySize) { + // Overflow risk. Emit warning, trigger event and break. If this happens, + // the reception buffer is not large enough or data is not polled often enough. +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!" + << std::endl; +#else + sif::printWarning("UartComIF::requestReceiveMessage: " + "Next read would cause overflow!"); +#endif +#endif + result = UART_RX_BUFFER_TOO_SMALL; + break; + } + else { + allowedReadSize = maxReplySize - currentBytesRead; + } + + bytesRead = read(fd, bufferPtr, allowedReadSize); + if (bytesRead < 0) { + // EAGAIN: No data available in non-blocking mode + if(errno != EAGAIN) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "UartComIF::handleCanonicalRead: read failed with code" << + errno << ": " << strerror(errno) << std::endl; +#else + sif::printWarning("UartComIF::handleCanonicalRead: read failed with code %d: %s\n", + errno, strerror(errno)); +#endif +#endif + return RETURN_FAILED; + } + + } + else if(bytesRead > 0) { + iter->second.replyLen += bytesRead; + bufferPtr += bytesRead; + currentBytesRead += bytesRead; + } + currentReadCycles++; + } while(bytesRead > 0 and currentReadCycles < maxReadCycles); + return result; +} + +ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie &uartCookie, UartDeviceMapIter &iter, + size_t requestLen) { + int fd = iter->second.fileDescriptor; + auto bufferPtr = iter->second.replyBuffer.data(); + // Size check to prevent buffer overflow + if(requestLen > uartCookie.getMaxReplyLen()) { +#if OBSW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!" + << std::endl; +#else + sif::printWarning("UartComIF::requestReceiveMessage: " + "Next read would cause overflow!"); +#endif +#endif + return UART_RX_BUFFER_TOO_SMALL; + } + int bytesRead = read(fd, bufferPtr, requestLen); + if (bytesRead < 0) { + return RETURN_FAILED; + } + else if (bytesRead != static_cast(requestLen)) { + if(uartCookie.isReplySizeFixed()) { + sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead << + " of " << requestLen << " bytes" << std::endl; + return RETURN_FAILED; + } + } + iter->second.replyLen = bytesRead; + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t UartComIF::readReceivedMessage(CookieIF *cookie, + uint8_t **buffer, size_t* size) { + + std::string deviceFile; + UartDeviceMapIter uartDeviceMapIter; + + UartCookie* uartCookie = dynamic_cast(cookie); + if(uartCookie == nullptr) { + sif::debug << "UartComIF::readReceivedMessage: Invalid uart cookie!" << std::endl; + return NULLPOINTER; + } + + deviceFile = uartCookie->getDeviceFile(); + uartDeviceMapIter = uartDeviceMap.find(deviceFile); + if (uartDeviceMapIter == uartDeviceMap.end()) { + sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile << + " not in uart map" << std::endl; + return RETURN_FAILED; + } + + *buffer = uartDeviceMapIter->second.replyBuffer.data(); + *size = uartDeviceMapIter->second.replyLen; + + /* Length is reset to 0 to prevent reading the same data twice */ + uartDeviceMapIter->second.replyLen = 0; + + return RETURN_OK; +} + +ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF *cookie) { + std::string deviceFile; + UartDeviceMapIter uartDeviceMapIter; + UartCookie* uartCookie = dynamic_cast(cookie); + if(uartCookie == nullptr) { + sif::warning << "UartComIF::flushUartRxBuffer: Invalid uart cookie!" << std::endl; + return NULLPOINTER; + } + deviceFile = uartCookie->getDeviceFile(); + uartDeviceMapIter = uartDeviceMap.find(deviceFile); + if(uartDeviceMapIter != uartDeviceMap.end()) { + int fd = uartDeviceMapIter->second.fileDescriptor; + tcflush(fd, TCIFLUSH); + return RETURN_OK; + } + return RETURN_FAILED; +} + +ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) { + std::string deviceFile; + UartDeviceMapIter uartDeviceMapIter; + UartCookie* uartCookie = dynamic_cast(cookie); + if(uartCookie == nullptr) { + sif::warning << "UartComIF::flushUartTxBuffer: Invalid uart cookie!" << std::endl; + return NULLPOINTER; + } + deviceFile = uartCookie->getDeviceFile(); + uartDeviceMapIter = uartDeviceMap.find(deviceFile); + if(uartDeviceMapIter != uartDeviceMap.end()) { + int fd = uartDeviceMapIter->second.fileDescriptor; + tcflush(fd, TCOFLUSH); + return RETURN_OK; + } + return RETURN_FAILED; +} + +ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) { + std::string deviceFile; + UartDeviceMapIter uartDeviceMapIter; + UartCookie* uartCookie = dynamic_cast(cookie); + if(uartCookie == nullptr) { + sif::warning << "UartComIF::flushUartTxAndRxBuf: Invalid uart cookie!" << std::endl; + return NULLPOINTER; + } + deviceFile = uartCookie->getDeviceFile(); + uartDeviceMapIter = uartDeviceMap.find(deviceFile); + if(uartDeviceMapIter != uartDeviceMap.end()) { + int fd = uartDeviceMapIter->second.fileDescriptor; + tcflush(fd, TCIOFLUSH); + return RETURN_OK; + } + return RETURN_FAILED; +} + +void UartComIF::setUartMode(struct termios *options, UartCookie &uartCookie) { + UartModes uartMode = uartCookie.getUartMode(); + if(uartMode == UartModes::NON_CANONICAL) { + /* Disable canonical mode */ + options->c_lflag &= ~ICANON; + } + else if(uartMode == UartModes::CANONICAL) { + options->c_lflag |= ICANON; + } +} diff --git a/hal/src/fsfw_hal/linux/uart/UartComIF.h b/hal/src/fsfw_hal/linux/uart/UartComIF.h new file mode 100644 index 000000000..68d2b9f5f --- /dev/null +++ b/hal/src/fsfw_hal/linux/uart/UartComIF.h @@ -0,0 +1,125 @@ +#ifndef BSP_Q7S_COMIF_UARTCOMIF_H_ +#define BSP_Q7S_COMIF_UARTCOMIF_H_ + +#include "UartCookie.h" +#include +#include + +#include +#include + +/** + * @brief This is the communication interface to access serial ports on linux based operating + * systems. + * + * @details The implementation follows the instructions from https://blog.mbedded.ninja/programming/ + * operating-systems/linux/linux-serial-ports-using-c-cpp/#disabling-canonical-mode + * + * @author J. Meier + */ +class UartComIF: public DeviceCommunicationIF, public SystemObject { +public: + static constexpr uint8_t uartRetvalId = CLASS_ID::HAL_UART; + + static constexpr ReturnValue_t UART_READ_FAILURE = + HasReturnvaluesIF::makeReturnCode(uartRetvalId, 1); + static constexpr ReturnValue_t UART_READ_SIZE_MISSMATCH = + HasReturnvaluesIF::makeReturnCode(uartRetvalId, 2); + static constexpr ReturnValue_t UART_RX_BUFFER_TOO_SMALL = + HasReturnvaluesIF::makeReturnCode(uartRetvalId, 3); + + UartComIF(object_id_t objectId); + + virtual ~UartComIF(); + + ReturnValue_t initializeInterface(CookieIF * cookie) override; + ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData, + size_t sendLen) override; + ReturnValue_t getSendSuccess(CookieIF *cookie) override; + ReturnValue_t requestReceiveMessage(CookieIF *cookie, + size_t requestLen) override; + ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, + size_t *size) override; + + /** + * @brief This function discards all data received but not read in the UART buffer. + */ + ReturnValue_t flushUartRxBuffer(CookieIF *cookie); + + /** + * @brief This function discards all data in the transmit buffer of the UART driver. + */ + ReturnValue_t flushUartTxBuffer(CookieIF *cookie); + + /** + * @brief This function discards both data in the transmit and receive buffer of the UART. + */ + ReturnValue_t flushUartTxAndRxBuf(CookieIF *cookie); + +private: + + using UartDeviceFile_t = std::string; + + struct UartElements { + int fileDescriptor; + std::vector replyBuffer; + /** Number of bytes read will be written to this variable */ + size_t replyLen; + }; + + using UartDeviceMap = std::unordered_map; + using UartDeviceMapIter = UartDeviceMap::iterator; + + /** + * The uart devie map stores informations of initialized uart ports. + */ + UartDeviceMap uartDeviceMap; + + /** + * @brief This function opens and configures a uart device by using the information stored + * in the uart cookie. + * @param uartCookie Pointer to uart cookie with information about the uart. Contains the + * uart device file, baudrate, parity, stopbits etc. + * @return The file descriptor of the configured uart. + */ + int configureUartPort(UartCookie* uartCookie); + + /** + * @brief This function adds the parity settings to the termios options struct. + * + * @param options Pointer to termios options struct which will be modified to enable or disable + * parity checking. + * @param uartCookie Pointer to uart cookie containing the information about the desired + * parity settings. + * + */ + void setParityOptions(struct termios* options, UartCookie* uartCookie); + + void setStopBitOptions(struct termios* options, UartCookie* uartCookie); + + /** + * @brief This function sets options which are not configurable by the uartCookie. + */ + void setFixedOptions(struct termios* options); + + /** + * @brief With this function the datasize settings are added to the termios options struct. + */ + void setDatasizeOptions(struct termios* options, UartCookie* uartCookie); + + /** + * @brief This functions adds the baudrate specified in the uartCookie to the termios options + * struct. + */ + void configureBaudrate(struct termios* options, UartCookie* uartCookie); + + void setUartMode(struct termios* options, UartCookie& uartCookie); + + ReturnValue_t handleCanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter, + size_t requestLen); + ReturnValue_t handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter, + size_t requestLen); + +}; + +#endif /* BSP_Q7S_COMIF_UARTCOMIF_H_ */ diff --git a/hal/src/fsfw_hal/linux/uart/UartCookie.cpp b/hal/src/fsfw_hal/linux/uart/UartCookie.cpp new file mode 100644 index 000000000..1c52e9cd1 --- /dev/null +++ b/hal/src/fsfw_hal/linux/uart/UartCookie.cpp @@ -0,0 +1,97 @@ +#include "fsfw_hal/linux/uart/UartCookie.h" + +#include + +UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, + uint32_t baudrate, size_t maxReplyLen): + handlerId(handlerId), deviceFile(deviceFile), uartMode(uartMode), + baudrate(baudrate), maxReplyLen(maxReplyLen) { +} + +UartCookie::~UartCookie() {} + +uint32_t UartCookie::getBaudrate() const { + return baudrate; +} + +size_t UartCookie::getMaxReplyLen() const { + return maxReplyLen; +} + +std::string UartCookie::getDeviceFile() const { + return deviceFile; +} + +void UartCookie::setParityOdd() { + parity = Parity::ODD; +} + +void UartCookie::setParityEven() { + parity = Parity::EVEN; +} + +Parity UartCookie::getParity() const { + return parity; +} + +void UartCookie::setBitsPerWord(uint8_t bitsPerWord_) { + switch(bitsPerWord_) { + case 5: + case 6: + case 7: + case 8: + break; + default: + sif::debug << "UartCookie::setBitsPerWord: Invalid bits per word specified" << std::endl; + return; + } + bitsPerWord = bitsPerWord_; +} + +uint8_t UartCookie::getBitsPerWord() const { + return bitsPerWord; +} + +StopBits UartCookie::getStopBits() const { + return stopBits; +} + +void UartCookie::setTwoStopBits() { + stopBits = StopBits::TWO_STOP_BITS; +} + +void UartCookie::setOneStopBit() { + stopBits = StopBits::ONE_STOP_BIT; +} + +UartModes UartCookie::getUartMode() const { + return uartMode; +} + +void UartCookie::setReadCycles(uint8_t readCycles) { + this->readCycles = readCycles; +} + +void UartCookie::setToFlushInput(bool enable) { + this->flushInput = enable; +} + +uint8_t UartCookie::getReadCycles() const { + return readCycles; +} + +bool UartCookie::getInputShouldBeFlushed() { + return this->flushInput; +} + +object_id_t UartCookie::getHandlerId() const { + return this->handlerId; +} + +void UartCookie::setNoFixedSizeReply() { + replySizeFixed = false; +} + +bool UartCookie::isReplySizeFixed() { + return replySizeFixed; +} diff --git a/hal/src/fsfw_hal/linux/uart/UartCookie.h b/hal/src/fsfw_hal/linux/uart/UartCookie.h new file mode 100644 index 000000000..faf95d50e --- /dev/null +++ b/hal/src/fsfw_hal/linux/uart/UartCookie.h @@ -0,0 +1,121 @@ +#ifndef SAM9G20_COMIF_COOKIES_UART_COOKIE_H_ +#define SAM9G20_COMIF_COOKIES_UART_COOKIE_H_ + +#include +#include + +#include + +enum class Parity { + NONE, + EVEN, + ODD +}; + +enum class StopBits { + ONE_STOP_BIT, + TWO_STOP_BITS +}; + +enum class UartModes { + CANONICAL, + NON_CANONICAL +}; + +/** + * @brief Cookie for the UartComIF. There are many options available to configure the UART driver. + * The constructor only requests for common options like the baudrate. Other options can + * be set by member functions. + * + * @author J. Meier + */ +class UartCookie: public CookieIF { +public: + + /** + * @brief Constructor for the uart cookie. + * @param deviceFile The device file specifying the uart to use, e.g. "/dev/ttyPS1" + * @param uartMode Specify the UART mode. The canonical mode should be used if the + * messages are separated by a delimited character like '\n'. See the + * termios documentation for more information + * @param baudrate The baudrate to use for input and output. Possible Baudrates are: 50, + * 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, B19200, + * 38400, 57600, 115200, 230400, 460800 + * @param maxReplyLen The maximum size an object using this cookie expects + * @details + * Default configuration: No parity + * 8 databits (number of bits transfered with one uart frame) + * One stop bit + */ + UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, + uint32_t baudrate, size_t maxReplyLen); + + virtual ~UartCookie(); + + uint32_t getBaudrate() const; + size_t getMaxReplyLen() const; + std::string getDeviceFile() const; + Parity getParity() const; + uint8_t getBitsPerWord() const; + StopBits getStopBits() const; + UartModes getUartMode() const; + object_id_t getHandlerId() const; + + /** + * The UART ComIF will only perform a specified number of read cycles for the canonical mode. + * The user can specify how many of those read cycles are performed for one device handler + * communication cycle. An example use-case would be to read all available GPS NMEA strings + * at once. + * @param readCycles + */ + void setReadCycles(uint8_t readCycles); + uint8_t getReadCycles() const; + + /** + * Allows to flush the data which was received but has not been read yet. This is useful + * to discard obsolete data at software startup. + */ + void setToFlushInput(bool enable); + bool getInputShouldBeFlushed(); + + /** + * Functions two enable parity checking. + */ + void setParityOdd(); + void setParityEven(); + + /** + * Function two set number of bits per UART frame. + */ + void setBitsPerWord(uint8_t bitsPerWord_); + + /** + * Function to specify the number of stopbits. + */ + void setTwoStopBits(); + void setOneStopBit(); + + /** + * Calling this function prevents the UartComIF to return failed if not all requested bytes + * could be read. This is required by a device handler when the size of a reply is not known. + */ + void setNoFixedSizeReply(); + + bool isReplySizeFixed(); + +private: + + const object_id_t handlerId; + std::string deviceFile; + const UartModes uartMode; + bool flushInput = false; + uint32_t baudrate; + size_t maxReplyLen = 0; + Parity parity = Parity::NONE; + uint8_t bitsPerWord = 8; + uint8_t readCycles = 1; + StopBits stopBits = StopBits::ONE_STOP_BIT; + bool replySizeFixed = true; +}; + +#endif diff --git a/hal/src/fsfw_hal/linux/utility.cpp b/hal/src/fsfw_hal/linux/utility.cpp new file mode 100644 index 000000000..99489e3f7 --- /dev/null +++ b/hal/src/fsfw_hal/linux/utility.cpp @@ -0,0 +1,26 @@ +#include "fsfw/FSFW.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw_hal/linux/utility.h" + +#include +#include + +void utility::handleIoctlError(const char* const customPrintout) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + if(customPrintout != nullptr) { + sif::warning << customPrintout << std::endl; + } + sif::warning << "handleIoctlError: Error code " << errno << ", "<< strerror(errno) << + std::endl; +#else + if(customPrintout != nullptr) { + sif::printWarning("%s\n", customPrintout); + } + sif::printWarning("handleIoctlError: Error code %d, %s\n", errno, strerror(errno)); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + +} + + diff --git a/hal/src/fsfw_hal/linux/utility.h b/hal/src/fsfw_hal/linux/utility.h new file mode 100644 index 000000000..0353b1d07 --- /dev/null +++ b/hal/src/fsfw_hal/linux/utility.h @@ -0,0 +1,10 @@ +#ifndef LINUX_UTILITY_UTILITY_H_ +#define LINUX_UTILITY_UTILITY_H_ + +namespace utility { + +void handleIoctlError(const char* const customPrintout); + +} + +#endif /* LINUX_UTILITY_UTILITY_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/CMakeLists.txt b/hal/src/fsfw_hal/stm32h7/CMakeLists.txt new file mode 100644 index 000000000..bae3b1ac8 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/CMakeLists.txt @@ -0,0 +1,7 @@ +add_subdirectory(spi) +add_subdirectory(gpio) +add_subdirectory(devicetest) + +target_sources(${LIB_FSFW_NAME} PRIVATE + dma.cpp +) diff --git a/hal/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt b/hal/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt new file mode 100644 index 000000000..7bd4c3a96 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + GyroL3GD20H.cpp +) \ No newline at end of file diff --git a/hal/src/fsfw_hal/stm32h7/devicetest/GyroL3GD20H.cpp b/hal/src/fsfw_hal/stm32h7/devicetest/GyroL3GD20H.cpp new file mode 100644 index 000000000..051be3449 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/devicetest/GyroL3GD20H.cpp @@ -0,0 +1,558 @@ +#include "fsfw_hal/stm32h7/devicetest/GyroL3GD20H.h" + +#include "fsfw_hal/stm32h7/spi/mspInit.h" +#include "fsfw_hal/stm32h7/spi/spiDefinitions.h" +#include "fsfw_hal/stm32h7/spi/spiCore.h" +#include "fsfw_hal/stm32h7/spi/spiInterrupts.h" +#include "fsfw_hal/stm32h7/spi/stm32h743ziSpi.h" + +#include "fsfw/tasks/TaskFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" + +#include "stm32h7xx_hal_spi.h" +#include "stm32h7xx_hal_rcc.h" + +#include + +alignas(32) std::array GyroL3GD20H::rxBuffer; +alignas(32) std::array +GyroL3GD20H::txBuffer __attribute__((section(".dma_buffer"))); + +TransferStates transferState = TransferStates::IDLE; +spi::TransferModes GyroL3GD20H::transferMode = spi::TransferModes::POLLING; + + +GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transferMode_): + spiHandle(spiHandle) { + txDmaHandle = new DMA_HandleTypeDef(); + rxDmaHandle = new DMA_HandleTypeDef(); + spi::setSpiHandle(spiHandle); + spi::assignSpiUserArgs(spi::SpiBus::SPI_1, spiHandle); + transferMode = transferMode_; + if(transferMode == spi::TransferModes::DMA) { + mspCfg = new spi::MspDmaConfigStruct(); + auto typedCfg = dynamic_cast(mspCfg); + spi::setDmaHandles(txDmaHandle, rxDmaHandle); + spi::h743zi::standardDmaCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS, + IrqPriorities::HIGHEST_FREERTOS, IrqPriorities::HIGHEST_FREERTOS); + spi::setSpiDmaMspFunctions(typedCfg); + } + else if(transferMode == spi::TransferModes::INTERRUPT) { + mspCfg = new spi::MspIrqConfigStruct(); + auto typedCfg = dynamic_cast(mspCfg); + spi::h743zi::standardInterruptCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS); + spi::setSpiIrqMspFunctions(typedCfg); + } + else if(transferMode == spi::TransferModes::POLLING) { + mspCfg = new spi::MspPollingConfigStruct(); + auto typedCfg = dynamic_cast(mspCfg); + spi::h743zi::standardPollingCfg(*typedCfg); + spi::setSpiPollingMspFunctions(typedCfg); + } + + spi::assignTransferRxTxCompleteCallback(&spiTransferCompleteCallback, nullptr); + spi::assignTransferErrorCallback(&spiTransferErrorCallback, nullptr); + + GPIO_InitTypeDef chipSelect = {}; + __HAL_RCC_GPIOD_CLK_ENABLE(); + chipSelect.Pin = GPIO_PIN_14; + chipSelect.Mode = GPIO_MODE_OUTPUT_PP; + HAL_GPIO_Init(GPIOD, &chipSelect); + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET); +} + +GyroL3GD20H::~GyroL3GD20H() { + delete txDmaHandle; + delete rxDmaHandle; + if(mspCfg != nullptr) { + delete mspCfg; + } +} + +ReturnValue_t GyroL3GD20H::initialize() { + // Configure the SPI peripheral + spiHandle->Instance = SPI1; + spiHandle->Init.BaudRatePrescaler = spi::getPrescaler(HAL_RCC_GetHCLKFreq(), 3900000); + spiHandle->Init.Direction = SPI_DIRECTION_2LINES; + spi::assignSpiMode(spi::SpiModes::MODE_3, *spiHandle); + spiHandle->Init.DataSize = SPI_DATASIZE_8BIT; + spiHandle->Init.FirstBit = SPI_FIRSTBIT_MSB; + spiHandle->Init.TIMode = SPI_TIMODE_DISABLE; + spiHandle->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + spiHandle->Init.CRCPolynomial = 7; + spiHandle->Init.CRCLength = SPI_CRC_LENGTH_8BIT; + spiHandle->Init.NSS = SPI_NSS_SOFT; + spiHandle->Init.NSSPMode = SPI_NSS_PULSE_DISABLE; + // Recommended setting to avoid glitches + spiHandle->Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE; + spiHandle->Init.Mode = SPI_MODE_MASTER; + if(HAL_SPI_Init(spiHandle) != HAL_OK) { + sif::printWarning("Error initializing SPI\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + + delete mspCfg; + transferState = TransferStates::WAIT; + + sif::printInfo("GyroL3GD20H::performOperation: Reading WHO AM I register\n"); + + txBuffer[0] = WHO_AM_I_REG | STM_READ_MASK; + txBuffer[1] = 0; + + switch(transferMode) { + case(spi::TransferModes::DMA): { + return handleDmaTransferInit(); + } + case(spi::TransferModes::INTERRUPT): { + return handleInterruptTransferInit(); + } + case(spi::TransferModes::POLLING): { + return handlePollingTransferInit(); + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t GyroL3GD20H::performOperation() { + switch(transferMode) { + case(spi::TransferModes::DMA): { + return handleDmaSensorRead(); + } + case(spi::TransferModes::POLLING): { + return handlePollingSensorRead(); + } + case(spi::TransferModes::INTERRUPT): { + return handleInterruptSensorRead(); + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t GyroL3GD20H::handleDmaTransferInit() { + /* Clean D-cache */ + /* Make sure the address is 32-byte aligned and add 32-bytes to length, + in case it overlaps cacheline */ + // See https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices + HAL_StatusTypeDef result = performDmaTransfer(2); + if(result != HAL_OK) { + // Transfer error in transmission process + sif::printWarning("GyroL3GD20H::initialize: Error transmitting SPI with DMA\n"); + } + + // Wait for the transfer to complete + while (transferState == TransferStates::WAIT) { + TaskFactory::delayTask(1); + } + + switch(transferState) { + case(TransferStates::SUCCESS): { + uint8_t whoAmIVal = rxBuffer[1]; + if(whoAmIVal != EXPECTED_WHO_AM_I_VAL) { + sif::printDebug("GyroL3GD20H::initialize: " + "Read WHO AM I value %d not equal to expected value!\n", whoAmIVal); + } + transferState = TransferStates::IDLE; + break; + } + case(TransferStates::FAILURE): { + sif::printWarning("Transfer failure\n"); + transferState = TransferStates::FAILURE; + return HasReturnvaluesIF::RETURN_FAILED; + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + + sif::printInfo("GyroL3GD20H::initialize: Configuring device\n"); + // Configure the 5 configuration registers + uint8_t configRegs[5]; + prepareConfigRegs(configRegs); + + result = performDmaTransfer(6); + if(result != HAL_OK) { + // Transfer error in transmission process + sif::printWarning("Error transmitting SPI with DMA\n"); + } + + // Wait for the transfer to complete + while (transferState == TransferStates::WAIT) { + TaskFactory::delayTask(1); + } + + switch(transferState) { + case(TransferStates::SUCCESS): { + sif::printInfo("GyroL3GD20H::initialize: Configuration transfer success\n"); + transferState = TransferStates::IDLE; + break; + } + case(TransferStates::FAILURE): { + sif::printWarning("GyroL3GD20H::initialize: Configuration transfer failure\n"); + transferState = TransferStates::FAILURE; + return HasReturnvaluesIF::RETURN_FAILED; + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + + + txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK; + std::memset(txBuffer.data() + 1, 0 , 5); + result = performDmaTransfer(6); + if(result != HAL_OK) { + // Transfer error in transmission process + sif::printWarning("Error transmitting SPI with DMA\n"); + } + // Wait for the transfer to complete + while (transferState == TransferStates::WAIT) { + TaskFactory::delayTask(1); + } + + switch(transferState) { + case(TransferStates::SUCCESS): { + if(rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or + rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or + rxBuffer[5] != configRegs[4]) { + sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n"); + } + else { + sif::printInfo("GyroL3GD20H::initialize: Configuration success\n"); + } + transferState = TransferStates::IDLE; + break; + } + case(TransferStates::FAILURE): { + sif::printWarning("GyroL3GD20H::initialize: Configuration transfer failure\n"); + transferState = TransferStates::FAILURE; + return HasReturnvaluesIF::RETURN_FAILED; + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t GyroL3GD20H::handleDmaSensorRead() { + txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK; + std::memset(txBuffer.data() + 1, 0 , 14); + + HAL_StatusTypeDef result = performDmaTransfer(15); + if(result != HAL_OK) { + // Transfer error in transmission process + sif::printDebug("GyroL3GD20H::handleDmaSensorRead: Error transmitting SPI with DMA\n"); + } + // Wait for the transfer to complete + while (transferState == TransferStates::WAIT) { + TaskFactory::delayTask(1); + } + + switch(transferState) { + case(TransferStates::SUCCESS): { + handleSensorReadout(); + break; + } + case(TransferStates::FAILURE): { + sif::printWarning("GyroL3GD20H::handleDmaSensorRead: Sensor read failure\n"); + transferState = TransferStates::FAILURE; + return HasReturnvaluesIF::RETURN_FAILED; + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + return HasReturnvaluesIF::RETURN_OK; +} + +HAL_StatusTypeDef GyroL3GD20H::performDmaTransfer(size_t sendSize) { + transferState = TransferStates::WAIT; +#if STM_USE_PERIPHERAL_TX_BUFFER_MPU_PROTECTION == 0 + SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t)txBuffer.data()) & ~(uint32_t)0x1F), + txBuffer.size()+32); +#endif + + // Start SPI transfer via DMA + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET); + return HAL_SPI_TransmitReceive_DMA(spiHandle, txBuffer.data(), rxBuffer.data(), sendSize); +} + +ReturnValue_t GyroL3GD20H::handlePollingTransferInit() { + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET); + auto result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 2, 1000); + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET); + switch(result) { + case(HAL_OK): { + sif::printInfo("GyroL3GD20H::initialize: Polling transfer success\n"); + uint8_t whoAmIVal = rxBuffer[1]; + if(whoAmIVal != EXPECTED_WHO_AM_I_VAL) { + sif::printDebug("GyroL3GD20H::performOperation: " + "Read WHO AM I value %d not equal to expected value!\n", whoAmIVal); + } + break; + } + case(HAL_TIMEOUT): { + sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + case(HAL_ERROR): { + sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + + sif::printInfo("GyroL3GD20H::initialize: Configuring device\n"); + // Configure the 5 configuration registers + uint8_t configRegs[5]; + prepareConfigRegs(configRegs); + + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET); + result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 6, 1000); + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET); + switch(result) { + case(HAL_OK): { + break; + } + case(HAL_TIMEOUT): { + sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + case(HAL_ERROR): { + sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + + txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK; + std::memset(txBuffer.data() + 1, 0 , 5); + + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET); + result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 6, 1000); + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET); + switch(result) { + case(HAL_OK): { + if(rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or + rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or + rxBuffer[5] != configRegs[4]) { + sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n"); + } + else { + sif::printInfo("GyroL3GD20H::initialize: Configuration success\n"); + } + break; + } + case(HAL_TIMEOUT): { + sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + case(HAL_ERROR): { + sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t GyroL3GD20H::handlePollingSensorRead() { + txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK; + std::memset(txBuffer.data() + 1, 0 , 14); + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET); + auto result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 15, 1000); + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET); + + switch(result) { + case(HAL_OK): { + handleSensorReadout(); + break; + } + case(HAL_TIMEOUT): { + sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + case(HAL_ERROR): { + sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() { + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET); + switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 2)) { + case(HAL_OK): { + sif::printInfo("GyroL3GD20H::initialize: Interrupt transfer success\n"); + // Wait for the transfer to complete + while (transferState == TransferStates::WAIT) { + TaskFactory::delayTask(1); + } + + uint8_t whoAmIVal = rxBuffer[1]; + if(whoAmIVal != EXPECTED_WHO_AM_I_VAL) { + sif::printDebug("GyroL3GD20H::initialize: " + "Read WHO AM I value %d not equal to expected value!\n", whoAmIVal); + } + break; + } + case(HAL_BUSY): + case(HAL_ERROR): + case(HAL_TIMEOUT): { + sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + } + + sif::printInfo("GyroL3GD20H::initialize: Configuring device\n"); + transferState = TransferStates::WAIT; + // Configure the 5 configuration registers + uint8_t configRegs[5]; + prepareConfigRegs(configRegs); + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET); + switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 6)) { + case(HAL_OK): { + // Wait for the transfer to complete + while (transferState == TransferStates::WAIT) { + TaskFactory::delayTask(1); + } + break; + } + case(HAL_BUSY): + case(HAL_ERROR): + case(HAL_TIMEOUT): { + sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + } + + txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK; + std::memset(txBuffer.data() + 1, 0 , 5); + transferState = TransferStates::WAIT; + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET); + switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 6)) { + case(HAL_OK): { + // Wait for the transfer to complete + while (transferState == TransferStates::WAIT) { + TaskFactory::delayTask(1); + } + if(rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or + rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or + rxBuffer[5] != configRegs[4]) { + sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n"); + } + else { + sif::printInfo("GyroL3GD20H::initialize: Configuration success\n"); + } + break; + } + case(HAL_BUSY): + case(HAL_ERROR): + case(HAL_TIMEOUT): { + sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t GyroL3GD20H::handleInterruptSensorRead() { + transferState = TransferStates::WAIT; + txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK; + std::memset(txBuffer.data() + 1, 0 , 14); + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET); + switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 15)) { + case(HAL_OK): { + // Wait for the transfer to complete + while (transferState == TransferStates::WAIT) { + TaskFactory::delayTask(1); + } + handleSensorReadout(); + break; + } + case(HAL_BUSY): + case(HAL_ERROR): + case(HAL_TIMEOUT): { + sif::printDebug("GyroL3GD20H::initialize: Sensor read failure using interrupts\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + } + return HasReturnvaluesIF::RETURN_OK; +} + +void GyroL3GD20H::prepareConfigRegs(uint8_t* configRegs) { + // Enable sensor + configRegs[0] = 0b00001111; + configRegs[1] = 0b00000000; + configRegs[2] = 0b00000000; + // Big endian select + configRegs[3] = 0b01000000; + configRegs[4] = 0b00000000; + + txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK; + std::memcpy(txBuffer.data() + 1, configRegs, 5); +} + +uint8_t GyroL3GD20H::readRegPolling(uint8_t reg) { + uint8_t rxBuf[2] = {}; + uint8_t txBuf[2] = {}; + txBuf[0] = reg | STM_READ_MASK; + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET); + auto result = HAL_SPI_TransmitReceive(spiHandle, txBuf, rxBuf, 2, 1000); + if(result) {}; + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET); + return rxBuf[1]; +} + +void GyroL3GD20H::handleSensorReadout() { + uint8_t statusReg = rxBuffer[8]; + int16_t gyroXRaw = rxBuffer[9] << 8 | rxBuffer[10]; + float gyroX = static_cast(gyroXRaw) * 0.00875; + int16_t gyroYRaw = rxBuffer[11] << 8 | rxBuffer[12]; + float gyroY = static_cast(gyroYRaw) * 0.00875; + int16_t gyroZRaw = rxBuffer[13] << 8 | rxBuffer[14]; + float gyroZ = static_cast(gyroZRaw) * 0.00875; + sif::printInfo("Status register: 0b" BYTE_TO_BINARY_PATTERN "\n", BYTE_TO_BINARY(statusReg)); + sif::printInfo("Gyro X: %f\n", gyroX); + sif::printInfo("Gyro Y: %f\n", gyroY); + sif::printInfo("Gyro Z: %f\n", gyroZ); +} + + +void GyroL3GD20H::spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* args) { + transferState = TransferStates::SUCCESS; + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET); + if(GyroL3GD20H::transferMode == spi::TransferModes::DMA) { + // Invalidate cache prior to access by CPU + SCB_InvalidateDCache_by_Addr ((uint32_t *)GyroL3GD20H::rxBuffer.data(), + GyroL3GD20H::recvBufferSize); + } +} + +/** + * @brief SPI error callbacks. + * @param hspi: SPI handle + * @note This example shows a simple way to report transfer error, and you can + * add your own implementation. + * @retval None + */ +void GyroL3GD20H::spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void* args) { + transferState = TransferStates::FAILURE; +} diff --git a/hal/src/fsfw_hal/stm32h7/devicetest/GyroL3GD20H.h b/hal/src/fsfw_hal/stm32h7/devicetest/GyroL3GD20H.h new file mode 100644 index 000000000..b65654de6 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/devicetest/GyroL3GD20H.h @@ -0,0 +1,70 @@ +#ifndef FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_ +#define FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_ + +#include "stm32h7xx_hal.h" +#include "stm32h7xx_hal_spi.h" +#include "../spi/mspInit.h" +#include "../spi/spiDefinitions.h" + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" + +#include +#include + +enum class TransferStates { + IDLE, + WAIT, + SUCCESS, + FAILURE +}; + +class GyroL3GD20H { +public: + GyroL3GD20H(SPI_HandleTypeDef* spiHandle, spi::TransferModes transferMode); + ~GyroL3GD20H(); + + ReturnValue_t initialize(); + ReturnValue_t performOperation(); + +private: + + const uint8_t WHO_AM_I_REG = 0b00001111; + const uint8_t STM_READ_MASK = 0b10000000; + const uint8_t STM_AUTO_INCREMENT_MASK = 0b01000000; + const uint8_t EXPECTED_WHO_AM_I_VAL = 0b11010111; + const uint8_t CTRL_REG_1 = 0b00100000; + const uint32_t L3G_RANGE = 245; + + SPI_HandleTypeDef* spiHandle; + + static spi::TransferModes transferMode; + static constexpr size_t recvBufferSize = 32 * 10; + static std::array rxBuffer; + static constexpr size_t txBufferSize = 32; + static std::array txBuffer; + + ReturnValue_t handleDmaTransferInit(); + ReturnValue_t handlePollingTransferInit(); + ReturnValue_t handleInterruptTransferInit(); + + ReturnValue_t handleDmaSensorRead(); + HAL_StatusTypeDef performDmaTransfer(size_t sendSize); + ReturnValue_t handlePollingSensorRead(); + ReturnValue_t handleInterruptSensorRead(); + + uint8_t readRegPolling(uint8_t reg); + + static void spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* args); + static void spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void* args); + + + void prepareConfigRegs(uint8_t* configRegs); + void handleSensorReadout(); + + + DMA_HandleTypeDef* txDmaHandle = {}; + DMA_HandleTypeDef* rxDmaHandle = {}; + spi::MspCfgBase* mspCfg = {}; +}; + +#endif /* FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/dma.cpp b/hal/src/fsfw_hal/stm32h7/dma.cpp new file mode 100644 index 000000000..bedf4aa49 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/dma.cpp @@ -0,0 +1,84 @@ +#include + +#include +#include + +user_handler_t DMA_1_USER_HANDLERS[8]; +user_args_t DMA_1_USER_ARGS[8]; + +user_handler_t DMA_2_USER_HANDLERS[8]; +user_args_t DMA_2_USER_ARGS[8]; + +void dma::assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx, + user_handler_t user_handler, user_args_t user_args) { + if(dma_idx == DMA_1) { + DMA_1_USER_HANDLERS[stream_idx] = user_handler; + DMA_1_USER_ARGS[stream_idx] = user_args; + } + else if(dma_idx == DMA_2) { + DMA_2_USER_HANDLERS[stream_idx] = user_handler; + DMA_2_USER_ARGS[stream_idx] = user_args; + } +} + +// The interrupt handlers in the format required for the IRQ vector table + +/* Do not change these function names! They need to be exactly equal to the name of the functions +defined in the startup_stm32h743xx.s files! */ + +#define GENERIC_DMA_IRQ_HANDLER(DMA_IDX, STREAM_IDX) \ + if(DMA_##DMA_IDX##_USER_HANDLERS[STREAM_IDX] != NULL) { \ + DMA_##DMA_IDX##_USER_HANDLERS[STREAM_IDX](DMA_##DMA_IDX##_USER_ARGS[STREAM_IDX]); \ + return; \ + } \ + Default_Handler() \ + +extern"C" void DMA1_Stream0_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(1, 0); +} +extern"C" void DMA1_Stream1_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(1, 1); +} +extern"C" void DMA1_Stream2_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(1, 2); +} +extern"C" void DMA1_Stream3_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(1, 3); +} +extern"C" void DMA1_Stream4_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(1, 4); +} +extern"C" void DMA1_Stream5_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(1, 5); +} +extern"C" void DMA1_Stream6_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(1, 6); +} +extern"C" void DMA1_Stream7_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(1, 7); +} + +extern"C" void DMA2_Stream0_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(2, 0); +} +extern"C" void DMA2_Stream1_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(2, 1); +} +extern"C" void DMA2_Stream2_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(2, 2); +} +extern"C" void DMA2_Stream3_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(2, 3); +} +extern"C" void DMA2_Stream4_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(2, 4); +} +extern"C" void DMA2_Stream5_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(2, 5); +} +extern"C" void DMA2_Stream6_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(2, 6); +} +extern"C" void DMA2_Stream7_IRQHandler() { + GENERIC_DMA_IRQ_HANDLER(2, 7); +} diff --git a/hal/src/fsfw_hal/stm32h7/dma.h b/hal/src/fsfw_hal/stm32h7/dma.h new file mode 100644 index 000000000..779a64cbe --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/dma.h @@ -0,0 +1,49 @@ +#ifndef FSFW_HAL_STM32H7_DMA_H_ +#define FSFW_HAL_STM32H7_DMA_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "interrupts.h" +#include + +namespace dma { + +enum DMAType { + TX = 0, + RX = 1 +}; + +enum DMAIndexes: uint8_t { + DMA_1 = 1, + DMA_2 = 2 +}; + +enum DMAStreams { + STREAM_0 = 0, + STREAM_1 = 1, + STREAM_2 = 2, + STREAM_3 = 3, + STREAM_4 = 4, + STREAM_5 = 5, + STREAM_6 = 6, + STREAM_7 = 7, +} ; + +/** + * Assign user interrupt handlers for DMA streams, allowing to pass an + * arbitrary argument as well. Generally, this argument will be the related DMA handle. + * @param user_handler + * @param user_args + */ +void assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx, + user_handler_t user_handler, user_args_t user_args); + +} + +#ifdef __cplusplus +} +#endif + +#endif /* FSFW_HAL_STM32H7_DMA_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt b/hal/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt new file mode 100644 index 000000000..35245b253 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + gpio.cpp +) diff --git a/hal/src/fsfw_hal/stm32h7/gpio/gpio.cpp b/hal/src/fsfw_hal/stm32h7/gpio/gpio.cpp new file mode 100644 index 000000000..5a890d7f9 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/gpio/gpio.cpp @@ -0,0 +1,71 @@ +#include "fsfw_hal/stm32h7/gpio/gpio.h" + +#include "stm32h7xx_hal_rcc.h" + +void gpio::initializeGpioClock(GPIO_TypeDef* gpioPort) { +#ifdef GPIOA + if(gpioPort == GPIOA) { + __HAL_RCC_GPIOA_CLK_ENABLE(); + } +#endif + +#ifdef GPIOB + if(gpioPort == GPIOB) { + __HAL_RCC_GPIOB_CLK_ENABLE(); + } +#endif + +#ifdef GPIOC + if(gpioPort == GPIOC) { + __HAL_RCC_GPIOC_CLK_ENABLE(); + } +#endif + +#ifdef GPIOD + if(gpioPort == GPIOD) { + __HAL_RCC_GPIOD_CLK_ENABLE(); + } +#endif + +#ifdef GPIOE + if(gpioPort == GPIOE) { + __HAL_RCC_GPIOE_CLK_ENABLE(); + } +#endif + +#ifdef GPIOF + if(gpioPort == GPIOF) { + __HAL_RCC_GPIOF_CLK_ENABLE(); + } +#endif + +#ifdef GPIOG + if(gpioPort == GPIOG) { + __HAL_RCC_GPIOG_CLK_ENABLE(); + } +#endif + +#ifdef GPIOH + if(gpioPort == GPIOH) { + __HAL_RCC_GPIOH_CLK_ENABLE(); + } +#endif + +#ifdef GPIOI + if(gpioPort == GPIOI) { + __HAL_RCC_GPIOI_CLK_ENABLE(); + } +#endif + +#ifdef GPIOJ + if(gpioPort == GPIOJ) { + __HAL_RCC_GPIOJ_CLK_ENABLE(); + } +#endif + +#ifdef GPIOK + if(gpioPort == GPIOK) { + __HAL_RCC_GPIOK_CLK_ENABLE(); + } +#endif +} diff --git a/hal/src/fsfw_hal/stm32h7/gpio/gpio.h b/hal/src/fsfw_hal/stm32h7/gpio/gpio.h new file mode 100644 index 000000000..38fcd708d --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/gpio/gpio.h @@ -0,0 +1,12 @@ +#ifndef FSFW_HAL_STM32H7_GPIO_GPIO_H_ +#define FSFW_HAL_STM32H7_GPIO_GPIO_H_ + +#include "stm32h7xx.h" + +namespace gpio { + +void initializeGpioClock(GPIO_TypeDef* gpioPort); + +} + +#endif /* FSFW_HAL_STM32H7_GPIO_GPIO_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt b/hal/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt new file mode 100644 index 000000000..5ecb09909 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE +) diff --git a/hal/src/fsfw_hal/stm32h7/interrupts.h b/hal/src/fsfw_hal/stm32h7/interrupts.h new file mode 100644 index 000000000..aef60bf74 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/interrupts.h @@ -0,0 +1,28 @@ +#ifndef FSFW_HAL_STM32H7_INTERRUPTS_H_ +#define FSFW_HAL_STM32H7_INTERRUPTS_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Default handler which is defined in startup file as assembly code. + */ +extern void Default_Handler(); + +typedef void (*user_handler_t) (void*); +typedef void* user_args_t; + +enum IrqPriorities: uint8_t { + HIGHEST = 0, + HIGHEST_FREERTOS = 6, + LOWEST = 15 +}; + +#ifdef __cplusplus +} +#endif + +#endif /* FSFW_HAL_STM32H7_INTERRUPTS_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/spi/CMakeLists.txt b/hal/src/fsfw_hal/stm32h7/spi/CMakeLists.txt new file mode 100644 index 000000000..e28c35aa2 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/CMakeLists.txt @@ -0,0 +1,9 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + spiCore.cpp + spiDefinitions.cpp + spiInterrupts.cpp + mspInit.cpp + SpiCookie.cpp + SpiComIF.cpp + stm32h743ziSpi.cpp +) diff --git a/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.cpp b/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.cpp new file mode 100644 index 000000000..1813aac02 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.cpp @@ -0,0 +1,468 @@ +#include "fsfw_hal/stm32h7/spi/SpiComIF.h" +#include "fsfw_hal/stm32h7/spi/SpiCookie.h" + +#include "fsfw/tasks/SemaphoreFactory.h" +#include "fsfw_hal/stm32h7/spi/spiCore.h" +#include "fsfw_hal/stm32h7/spi/spiInterrupts.h" +#include "fsfw_hal/stm32h7/spi/mspInit.h" +#include "fsfw_hal/stm32h7/gpio/gpio.h" + +// FreeRTOS required special Semaphore handling from an ISR. Therefore, we use the concrete +// instance here, because RTEMS and FreeRTOS are the only relevant OSALs currently +// and it is not trivial to add a releaseFromISR to the SemaphoreIF +#if defined FSFW_OSAL_RTEMS +#include "fsfw/osal/rtems/BinarySemaphore.h" +#elif defined FSFW_OSAL_FREERTOS +#include "fsfw/osal/freertos/TaskManagement.h" +#include "fsfw/osal/freertos/BinarySemaphore.h" +#endif + +#include "stm32h7xx_hal_gpio.h" + +SpiComIF::SpiComIF(object_id_t objectId): SystemObject(objectId) { + void* irqArgsVoided = reinterpret_cast(&irqArgs); + spi::assignTransferRxTxCompleteCallback(&spiTransferCompleteCallback, irqArgsVoided); + spi::assignTransferRxCompleteCallback(&spiTransferRxCompleteCallback, irqArgsVoided); + spi::assignTransferTxCompleteCallback(&spiTransferTxCompleteCallback, irqArgsVoided); + spi::assignTransferErrorCallback(&spiTransferErrorCallback, irqArgsVoided); +} + +void SpiComIF::configureCacheMaintenanceOnTxBuffer(bool enable) { + this->cacheMaintenanceOnTxBuffer = enable; +} + +void SpiComIF::addDmaHandles(DMA_HandleTypeDef *txHandle, DMA_HandleTypeDef *rxHandle) { + spi::setDmaHandles(txHandle, rxHandle); +} + +ReturnValue_t SpiComIF::initialize() { + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) { + SpiCookie* spiCookie = dynamic_cast(cookie); + if(spiCookie == nullptr) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error < "SpiComIF::initializeInterface: Invalid cookie" << std::endl; +#else + sif::printError("SpiComIF::initializeInterface: Invalid cookie\n"); +#endif + return NULLPOINTER; + } + auto transferMode = spiCookie->getTransferMode(); + + if(transferMode == spi::TransferModes::DMA) { + DMA_HandleTypeDef *txHandle = nullptr; + DMA_HandleTypeDef *rxHandle = nullptr; + spi::getDmaHandles(&txHandle, &rxHandle); + if(txHandle == nullptr or rxHandle == nullptr) { + sif::printError("SpiComIF::initialize: DMA handles not set!\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + } + // This semaphore ensures thread-safety for a given bus + spiSemaphore = dynamic_cast( + SemaphoreFactory::instance()->createBinarySemaphore()); + address_t spiAddress = spiCookie->getDeviceAddress(); + + auto iter = spiDeviceMap.find(spiAddress); + if(iter == spiDeviceMap.end()) { + size_t bufferSize = spiCookie->getMaxRecvSize(); + auto statusPair = spiDeviceMap.emplace(spiAddress, SpiInstance(bufferSize)); + if (not statusPair.second) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "SpiComIF::initializeInterface: Failed to insert device with address " << + spiAddress << "to SPI device map" << std::endl; +#else + sif::printError("SpiComIF::initializeInterface: Failed to insert device with address " + "%lu to SPI device map\n", static_cast(spiAddress)); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + return HasReturnvaluesIF::RETURN_FAILED; + } + } + auto gpioPin = spiCookie->getChipSelectGpioPin(); + auto gpioPort = spiCookie->getChipSelectGpioPort(); + + SPI_HandleTypeDef& spiHandle = spiCookie->getSpiHandle(); + + auto spiIdx = spiCookie->getSpiIdx(); + if(spiIdx == spi::SpiBus::SPI_1) { +#ifdef SPI1 + spiHandle.Instance = SPI1; +#endif + } + else if(spiIdx == spi::SpiBus::SPI_2) { +#ifdef SPI2 + spiHandle.Instance = SPI2; +#endif + } + else { + printCfgError("SPI Bus Index"); + return HasReturnvaluesIF::RETURN_FAILED; + } + + auto mspCfg = spiCookie->getMspCfg(); + + if(transferMode == spi::TransferModes::POLLING) { + auto typedCfg = dynamic_cast(mspCfg); + if(typedCfg == nullptr) { + printCfgError("Polling MSP"); + return HasReturnvaluesIF::RETURN_FAILED; + } + spi::setSpiPollingMspFunctions(typedCfg); + } + else if(transferMode == spi::TransferModes::INTERRUPT) { + auto typedCfg = dynamic_cast(mspCfg); + if(typedCfg == nullptr) { + printCfgError("IRQ MSP"); + return HasReturnvaluesIF::RETURN_FAILED; + } + spi::setSpiIrqMspFunctions(typedCfg); + } + else if(transferMode == spi::TransferModes::DMA) { + auto typedCfg = dynamic_cast(mspCfg); + if(typedCfg == nullptr) { + printCfgError("DMA MSP"); + return HasReturnvaluesIF::RETURN_FAILED; + } + // Check DMA handles + DMA_HandleTypeDef* txHandle = nullptr; + DMA_HandleTypeDef* rxHandle = nullptr; + spi::getDmaHandles(&txHandle, &rxHandle); + if(txHandle == nullptr or rxHandle == nullptr) { + printCfgError("DMA Handle"); + return HasReturnvaluesIF::RETURN_FAILED; + } + spi::setSpiDmaMspFunctions(typedCfg); + } + + gpio::initializeGpioClock(gpioPort); + GPIO_InitTypeDef chipSelect = {}; + chipSelect.Pin = gpioPin; + chipSelect.Mode = GPIO_MODE_OUTPUT_PP; + HAL_GPIO_Init(gpioPort, &chipSelect); + HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET); + + if(HAL_SPI_Init(&spiHandle) != HAL_OK) { + sif::printWarning("SpiComIF::initialize: Error initializing SPI\n"); + return HasReturnvaluesIF::RETURN_FAILED; + } + // The MSP configuration struct is not required anymore + spiCookie->deleteMspCfg(); + + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) { + SpiCookie* spiCookie = dynamic_cast(cookie); + if(spiCookie == nullptr) { + return NULLPOINTER; + } + + SPI_HandleTypeDef& spiHandle = spiCookie->getSpiHandle(); + + auto iter = spiDeviceMap.find(spiCookie->getDeviceAddress()); + if(iter == spiDeviceMap.end()) { + return HasReturnvaluesIF::RETURN_FAILED; + } + iter->second.currentTransferLen = sendLen; + + auto transferMode = spiCookie->getTransferMode(); + switch(spiCookie->getTransferState()) { + case(spi::TransferStates::IDLE): { + break; + } + case(spi::TransferStates::WAIT): + case(spi::TransferStates::FAILURE): + case(spi::TransferStates::SUCCESS): + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + + switch(transferMode) { + case(spi::TransferModes::POLLING): { + return handlePollingSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie, + sendData, sendLen); + } + case(spi::TransferModes::INTERRUPT): { + return handleInterruptSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie, + sendData, sendLen); + } + case(spi::TransferModes::DMA): { + return handleDmaSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie, + sendData, sendLen); + } + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) { + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) { + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) { + SpiCookie* spiCookie = dynamic_cast(cookie); + if(spiCookie == nullptr) { + return NULLPOINTER; + } + switch(spiCookie->getTransferState()) { + case(spi::TransferStates::SUCCESS): { + auto iter = spiDeviceMap.find(spiCookie->getDeviceAddress()); + if(iter == spiDeviceMap.end()) { + return HasReturnvaluesIF::RETURN_FAILED; + } + *buffer = iter->second.replyBuffer.data(); + *size = iter->second.currentTransferLen; + spiCookie->setTransferState(spi::TransferStates::IDLE); + break; + } + case(spi::TransferStates::FAILURE): { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "SpiComIF::readReceivedMessage: Transfer failure" << std::endl; +#else + sif::printWarning("SpiComIF::readReceivedMessage: Transfer failure\n"); +#endif +#endif + spiCookie->setTransferState(spi::TransferStates::IDLE); + return HasReturnvaluesIF::RETURN_FAILED; + } + case(spi::TransferStates::WAIT): + case(spi::TransferStates::IDLE): { + break; + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + + return HasReturnvaluesIF::RETURN_OK; +} + +void SpiComIF::setDefaultPollingTimeout(dur_millis_t timeout) { + this->defaultPollingTimeout = timeout; +} + +ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle, + SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) { + auto gpioPort = spiCookie.getChipSelectGpioPort(); + auto gpioPin = spiCookie.getChipSelectGpioPin(); + auto returnval = spiSemaphore->acquire(timeoutType, timeoutMs); + if(returnval != HasReturnvaluesIF::RETURN_OK) { + return returnval; + } + spiCookie.setTransferState(spi::TransferStates::WAIT); + HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET); + auto result = HAL_SPI_TransmitReceive(&spiHandle, const_cast(sendData), + recvPtr, sendLen, defaultPollingTimeout); + HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET); + spiSemaphore->release(); + switch(result) { + case(HAL_OK): { + spiCookie.setTransferState(spi::TransferStates::SUCCESS); + break; + } + case(HAL_TIMEOUT): { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "SpiComIF::sendMessage: Polling Mode | Timeout for SPI device" << + spiCookie->getDeviceAddress() << std::endl; +#else + sif::printWarning("SpiComIF::sendMessage: Polling Mode | Timeout for SPI device %d\n", + spiCookie.getDeviceAddress()); +#endif +#endif + spiCookie.setTransferState(spi::TransferStates::FAILURE); + return spi::HAL_TIMEOUT_RETVAL; + } + case(HAL_ERROR): + default: { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "SpiComIF::sendMessage: Polling Mode | HAL error for SPI device" << + spiCookie->getDeviceAddress() << std::endl; +#else + sif::printWarning("SpiComIF::sendMessage: Polling Mode | HAL error for SPI device %d\n", + spiCookie.getDeviceAddress()); +#endif +#endif + spiCookie.setTransferState(spi::TransferStates::FAILURE); + return spi::HAL_ERROR_RETVAL; + } + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t SpiComIF::handleInterruptSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle, + SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen) { + return handleIrqSendOperation(recvPtr, spiHandle, spiCookie, sendData, sendLen); +} + +ReturnValue_t SpiComIF::handleDmaSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle, + SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen) { + return handleIrqSendOperation(recvPtr, spiHandle, spiCookie, sendData, sendLen); +} + +ReturnValue_t SpiComIF::handleIrqSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef& spiHandle, + SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) { + ReturnValue_t result = genericIrqSendSetup(recvPtr, spiHandle, spiCookie, sendData, sendLen); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + // yet another HAL driver which is not const-correct.. + HAL_StatusTypeDef status = HAL_OK; + auto transferMode = spiCookie.getTransferMode(); + if(transferMode == spi::TransferModes::DMA) { + if(cacheMaintenanceOnTxBuffer) { + /* Clean D-cache. Make sure the address is 32-byte aligned and add 32-bytes to length, + in case it overlaps cacheline */ + SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t) sendData ) & ~(uint32_t)0x1F), + sendLen + 32); + } + status = HAL_SPI_TransmitReceive_DMA(&spiHandle, const_cast(sendData), + currentRecvPtr, sendLen); + } + else { + status = HAL_SPI_TransmitReceive_IT(&spiHandle, const_cast(sendData), + currentRecvPtr, sendLen); + } + switch(status) { + case(HAL_OK): { + break; + } + default: { + return halErrorHandler(status, transferMode); + } + } + return result; +} + +ReturnValue_t SpiComIF::halErrorHandler(HAL_StatusTypeDef status, spi::TransferModes transferMode) { + char modeString[10]; + if(transferMode == spi::TransferModes::DMA) { + std::snprintf(modeString, sizeof(modeString), "Dma"); + } + else { + std::snprintf(modeString, sizeof(modeString), "Interrupt"); + } + sif::printWarning("SpiComIF::handle%sSendOperation: HAL error %d occured\n", modeString, + status); + switch(status) { + case(HAL_BUSY): { + return spi::HAL_BUSY_RETVAL; + } + case(HAL_ERROR): { + return spi::HAL_ERROR_RETVAL; + } + case(HAL_TIMEOUT): { + return spi::HAL_TIMEOUT_RETVAL; + } + default: { + return HasReturnvaluesIF::RETURN_FAILED; + } + } +} + + +ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef& spiHandle, + SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) { + currentRecvPtr = recvPtr; + currentRecvBuffSize = sendLen; + + // Take the semaphore which will be released by a callback when the transfer is complete + ReturnValue_t result = spiSemaphore->acquire(SemaphoreIF::TimeoutType::WAITING, timeoutMs); + if(result != HasReturnvaluesIF::RETURN_OK) { + // Configuration error + sif::printWarning("SpiComIF::handleInterruptSendOperation: Semaphore " + "could not be acquired after %d ms\n", timeoutMs); + return result; + } + // Cache the current SPI handle in any case + spi::setSpiHandle(&spiHandle); + // Assign the IRQ arguments for the user callbacks + irqArgs.comIF = this; + irqArgs.spiCookie = &spiCookie; + // The SPI handle is passed to the default SPI callback as a void argument. This callback + // is different from the user callbacks specified above! + spi::assignSpiUserArgs(spiCookie.getSpiIdx(), reinterpret_cast(&spiHandle)); + HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(), + GPIO_PIN_RESET); + return HasReturnvaluesIF::RETURN_OK; +} + +void SpiComIF::spiTransferTxCompleteCallback(SPI_HandleTypeDef *hspi, void *args) { + genericIrqHandler(args, spi::TransferStates::SUCCESS); +} + +void SpiComIF::spiTransferRxCompleteCallback(SPI_HandleTypeDef *hspi, void *args) { + genericIrqHandler(args, spi::TransferStates::SUCCESS); +} + +void SpiComIF::spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void *args) { + genericIrqHandler(args, spi::TransferStates::SUCCESS); +} + +void SpiComIF::spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void *args) { + genericIrqHandler(args, spi::TransferStates::FAILURE); +} + +void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetState) { + IrqArgs* irqArgs = reinterpret_cast(irqArgsVoid); + if(irqArgs == nullptr) { + return; + } + SpiCookie* spiCookie = irqArgs->spiCookie; + SpiComIF* comIF = irqArgs->comIF; + if(spiCookie == nullptr or comIF == nullptr) { + return; + } + + spiCookie->setTransferState(targetState); + + // Pull CS pin high again + HAL_GPIO_WritePin(spiCookie->getChipSelectGpioPort(), spiCookie->getChipSelectGpioPin(), + GPIO_PIN_SET); + +#if defined FSFW_OSAL_FREERTOS + // Release the task semaphore + BaseType_t taskWoken = pdFALSE; + ReturnValue_t result = BinarySemaphore::releaseFromISR(comIF->spiSemaphore->getSemaphore(), + &taskWoken); +#elif defined FSFW_OSAL_RTEMS + ReturnValue_t result = comIF->spiSemaphore->release(); +#endif + if(result != HasReturnvaluesIF::RETURN_OK) { + // Configuration error + printf("SpiComIF::genericIrqHandler: Failure releasing Semaphore!\n"); + } + + // Perform cache maintenance operation for DMA transfers + if(spiCookie->getTransferMode() == spi::TransferModes::DMA) { + // Invalidate cache prior to access by CPU + SCB_InvalidateDCache_by_Addr ((uint32_t *) comIF->currentRecvPtr, + comIF->currentRecvBuffSize); + } +#if defined FSFW_OSAL_FREERTOS + /* Request a context switch if the SPI ComIF task was woken up and has a higher priority + than the currently running task */ + if(taskWoken == pdTRUE) { + TaskManagement::requestContextSwitch(CallContext::ISR); + } +#endif +} + +void SpiComIF::printCfgError(const char *const type) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "SpiComIF::initializeInterface: Invalid " << type << " configuration" + << std::endl; +#else + sif::printWarning("SpiComIF::initializeInterface: Invalid %s configuration\n", type); +#endif +} diff --git a/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.h b/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.h new file mode 100644 index 000000000..9548e102a --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/SpiComIF.h @@ -0,0 +1,130 @@ +#ifndef FSFW_HAL_STM32H7_SPI_SPICOMIF_H_ +#define FSFW_HAL_STM32H7_SPI_SPICOMIF_H_ + +#include "fsfw/tasks/SemaphoreIF.h" +#include "fsfw/devicehandlers/DeviceCommunicationIF.h" +#include "fsfw/objectmanager/SystemObject.h" + +#include "fsfw_hal/stm32h7/spi/spiDefinitions.h" +#include "stm32h7xx_hal_spi.h" +#include "stm32h743xx.h" + +#include +#include + +class SpiCookie; +class BinarySemaphore; + +/** + * @brief This communication interface allows using generic device handlers with using + * the STM32H7 SPI peripherals + * @details + * This communication interface supports all three major communcation modes: + * - Polling: Simple, but not recommended to real use-cases, blocks the CPU + * - Interrupt: Good for small data only arriving occasionally + * - DMA: Good for large data which also occur regularly. Please note that the number + * of DMA channels in limited + * The device specific information is usually kept in the SpiCookie class. The current + * implementation limits the transfer mode for a given SPI bus. + * @author R. Mueller + */ +class SpiComIF: + public SystemObject, + public DeviceCommunicationIF { +public: + /** + * Create a SPI communication interface for the given SPI peripheral (spiInstance) + * @param objectId + * @param spiInstance + * @param spiHandle + * @param transferMode + */ + SpiComIF(object_id_t objectId); + + /** + * Allows the user to disable cache maintenance on the TX buffer. This can be done if the + * TX buffers are places and MPU protected properly like specified in this link: + * https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices + * The cache maintenace is enabled by default. + * @param enable + */ + void configureCacheMaintenanceOnTxBuffer(bool enable); + + void setDefaultPollingTimeout(dur_millis_t timeout); + + /** + * Add the DMA handles. These need to be set in the DMA transfer mode is used. + * @param txHandle + * @param rxHandle + */ + void addDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle); + + ReturnValue_t initialize() override; +protected: + + // DeviceCommunicationIF overrides + virtual ReturnValue_t initializeInterface(CookieIF * cookie) override; + virtual ReturnValue_t sendMessage(CookieIF *cookie, + const uint8_t * sendData, size_t sendLen) override; + virtual ReturnValue_t getSendSuccess(CookieIF *cookie) override; + virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, + size_t requestLen) override; + virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, + uint8_t **buffer, size_t *size) override; + +private: + + struct SpiInstance { + SpiInstance(size_t maxRecvSize): replyBuffer(std::vector(maxRecvSize)) {} + std::vector replyBuffer; + size_t currentTransferLen = 0; + }; + + struct IrqArgs { + SpiComIF* comIF = nullptr; + SpiCookie* spiCookie = nullptr; + }; + + IrqArgs irqArgs; + + uint32_t defaultPollingTimeout = 50; + + SemaphoreIF::TimeoutType timeoutType = SemaphoreIF::TimeoutType::WAITING; + dur_millis_t timeoutMs = 20; + + BinarySemaphore* spiSemaphore = nullptr; + bool cacheMaintenanceOnTxBuffer = true; + + using SpiDeviceMap = std::map; + using SpiDeviceMapIter = SpiDeviceMap::iterator; + + uint8_t* currentRecvPtr = nullptr; + size_t currentRecvBuffSize = 0; + + SpiDeviceMap spiDeviceMap; + + ReturnValue_t handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle, + SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen); + ReturnValue_t handleInterruptSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle, + SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen); + ReturnValue_t handleDmaSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle, + SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen); + ReturnValue_t handleIrqSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle, + SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen); + ReturnValue_t genericIrqSendSetup(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle, + SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen); + ReturnValue_t halErrorHandler(HAL_StatusTypeDef status, spi::TransferModes transferMode); + + static void spiTransferTxCompleteCallback(SPI_HandleTypeDef *hspi, void* args); + static void spiTransferRxCompleteCallback(SPI_HandleTypeDef *hspi, void* args); + static void spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* args); + static void spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void* args); + + static void genericIrqHandler(void* irqArgs, spi::TransferStates targetState); + + void printCfgError(const char* const type); +}; + + + +#endif /* FSFW_HAL_STM32H7_SPI_SPICOMIF_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp new file mode 100644 index 000000000..88f1e1f14 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.cpp @@ -0,0 +1,78 @@ +#include "fsfw_hal/stm32h7/spi/SpiCookie.h" + + +SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode, + spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode, + uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort, size_t maxRecvSize): + deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode), + transferMode(transferMode), chipSelectGpioPin(chipSelectGpioPin), + chipSelectGpioPort(chipSelectGpioPort), mspCfg(mspCfg), maxRecvSize(maxRecvSize) { + spiHandle.Init.DataSize = SPI_DATASIZE_8BIT; + spiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB; + spiHandle.Init.TIMode = SPI_TIMODE_DISABLE; + spiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + spiHandle.Init.CRCPolynomial = 7; + spiHandle.Init.CRCLength = SPI_CRC_LENGTH_8BIT; + spiHandle.Init.NSS = SPI_NSS_SOFT; + spiHandle.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; + spiHandle.Init.Direction = SPI_DIRECTION_2LINES; + // Recommended setting to avoid glitches + spiHandle.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE; + spiHandle.Init.Mode = SPI_MODE_MASTER; + spi::assignSpiMode(spiMode, spiHandle); + spiHandle.Init.BaudRatePrescaler = spi::getPrescaler(HAL_RCC_GetHCLKFreq(), spiSpeed); +} + +uint16_t SpiCookie::getChipSelectGpioPin() const { + return chipSelectGpioPin; +} + +GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() { + return chipSelectGpioPort; +} + +address_t SpiCookie::getDeviceAddress() const { + return deviceAddress; +} + +spi::SpiBus SpiCookie::getSpiIdx() const { + return spiIdx; +} + +spi::SpiModes SpiCookie::getSpiMode() const { + return spiMode; +} + +uint32_t SpiCookie::getSpiSpeed() const { + return spiSpeed; +} + +size_t SpiCookie::getMaxRecvSize() const { + return maxRecvSize; +} + +SPI_HandleTypeDef& SpiCookie::getSpiHandle() { + return spiHandle; +} + +spi::MspCfgBase* SpiCookie::getMspCfg() { + return mspCfg; +} + +void SpiCookie::deleteMspCfg() { + if(mspCfg != nullptr) { + delete mspCfg; + } +} + +spi::TransferModes SpiCookie::getTransferMode() const { + return transferMode; +} + +void SpiCookie::setTransferState(spi::TransferStates transferState) { + this->transferState = transferState; +} + +spi::TransferStates SpiCookie::getTransferState() const { + return this->transferState; +} diff --git a/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h new file mode 100644 index 000000000..45226b4a9 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/SpiCookie.h @@ -0,0 +1,75 @@ +#ifndef FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_ +#define FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_ + +#include "spiDefinitions.h" +#include "mspInit.h" + +#include "fsfw/devicehandlers/CookieIF.h" + +#include "stm32h743xx.h" + +/** + * @brief SPI cookie implementation for the STM32H7 device family + * @details + * This cookie contains and caches device specific information to be used by the + * SPI communication interface + * @author R. Mueller + */ +class SpiCookie: public CookieIF { + friend class SpiComIF; +public: + /** + * Allows construction of a SPI cookie for a connected SPI device + * @param deviceAddress + * @param spiIdx SPI bus, e.g. SPI1 or SPI2 + * @param transferMode + * @param mspCfg This is the MSP configuration. The user is expected to supply + * a valid MSP configuration. See mspInit.h for functions + * to create one. + * @param spiSpeed + * @param spiMode + * @param chipSelectGpioPin GPIO port. Don't use a number here, use the 16 bit type + * definitions supplied in the MCU header file! (e.g. GPIO_PIN_X) + * @param chipSelectGpioPort GPIO port (e.g. GPIOA) + * @param maxRecvSize Maximum expected receive size. Chose as small as possible. + */ + SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode, + spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode, + uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort, size_t maxRecvSize); + + uint16_t getChipSelectGpioPin() const; + GPIO_TypeDef* getChipSelectGpioPort(); + address_t getDeviceAddress() const; + spi::SpiBus getSpiIdx() const; + spi::SpiModes getSpiMode() const; + spi::TransferModes getTransferMode() const; + uint32_t getSpiSpeed() const; + size_t getMaxRecvSize() const; + SPI_HandleTypeDef& getSpiHandle(); + +private: + address_t deviceAddress; + SPI_HandleTypeDef spiHandle = {}; + spi::SpiBus spiIdx; + uint32_t spiSpeed; + spi::SpiModes spiMode; + spi::TransferModes transferMode; + volatile spi::TransferStates transferState = spi::TransferStates::IDLE; + uint16_t chipSelectGpioPin; + GPIO_TypeDef* chipSelectGpioPort; + // The MSP configuration is cached here. Be careful when using this, it is automatically + // deleted by the SPI communication interface if it is not required anymore! + spi::MspCfgBase* mspCfg = nullptr; + const size_t maxRecvSize; + + // Only the SpiComIF is allowed to use this to prevent dangling pointers issues + spi::MspCfgBase* getMspCfg(); + void deleteMspCfg(); + + void setTransferState(spi::TransferStates transferState); + spi::TransferStates getTransferState() const; +}; + + + +#endif /* FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/spi/mspInit.cpp b/hal/src/fsfw_hal/stm32h7/spi/mspInit.cpp new file mode 100644 index 000000000..4df61f9b8 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/mspInit.cpp @@ -0,0 +1,253 @@ +#include "fsfw_hal/stm32h7/dma.h" +#include "fsfw_hal/stm32h7/spi/mspInit.h" +#include "fsfw_hal/stm32h7/spi/spiCore.h" +#include "fsfw_hal/stm32h7/spi/spiInterrupts.h" + +#include "stm32h743xx.h" +#include "stm32h7xx_hal_spi.h" +#include "stm32h7xx_hal_dma.h" +#include "stm32h7xx_hal_def.h" + +#include + +spi::msp_func_t mspInitFunc = nullptr; +spi::MspCfgBase* mspInitArgs = nullptr; + +spi::msp_func_t mspDeinitFunc = nullptr; +spi::MspCfgBase* mspDeinitArgs = nullptr; + +/** + * @brief SPI MSP Initialization + * This function configures the hardware resources used in this example: + * - Peripheral's clock enable + * - Peripheral's GPIO Configuration + * - DMA configuration for transmission request by peripheral + * - NVIC configuration for DMA interrupt request enable + * @param hspi: SPI handle pointer + * @retval None + */ +void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) { + auto cfg = dynamic_cast(cfgBase); + if(hspi == nullptr or cfg == nullptr) { + return; + } + setSpiHandle(hspi); + + DMA_HandleTypeDef* hdma_tx = nullptr; + DMA_HandleTypeDef* hdma_rx = nullptr; + spi::getDmaHandles(&hdma_tx, &hdma_rx); + if(hdma_tx == nullptr or hdma_rx == nullptr) { + printf("HAL_SPI_MspInit: Invalid DMA handles. Make sure to call setDmaHandles!\n"); + return; + } + + spi::halMspInitInterrupt(hspi, cfg); + + // DMA setup + if(cfg->dmaClkEnableWrapper == nullptr) { + mspErrorHandler("spi::halMspInitDma", "DMA Clock init invalid"); + } + cfg->dmaClkEnableWrapper(); + + // Configure the DMA + /* Configure the DMA handler for Transmission process */ + if(hdma_tx->Instance == nullptr) { + // Assume it was not configured properly + mspErrorHandler("spi::halMspInitDma", "DMA TX handle invalid"); + } + + HAL_DMA_Init(hdma_tx); + /* Associate the initialized DMA handle to the the SPI handle */ + __HAL_LINKDMA(hspi, hdmatx, *hdma_tx); + + HAL_DMA_Init(hdma_rx); + /* Associate the initialized DMA handle to the the SPI handle */ + __HAL_LINKDMA(hspi, hdmarx, *hdma_rx); + + /*##-4- Configure the NVIC for DMA #########################################*/ + /* NVIC configuration for DMA transfer complete interrupt (SPI1_RX) */ + // Assign the interrupt handler + dma::assignDmaUserHandler(cfg->rxDmaIndex, cfg->rxDmaStream, &spi::dmaRxIrqHandler, hdma_rx); + HAL_NVIC_SetPriority(cfg->rxDmaIrqNumber, cfg->rxPreEmptPriority, cfg->rxSubpriority); + HAL_NVIC_EnableIRQ(cfg->rxDmaIrqNumber); + + /* NVIC configuration for DMA transfer complete interrupt (SPI1_TX) */ + // Assign the interrupt handler + dma::assignDmaUserHandler(cfg->txDmaIndex, cfg->txDmaStream, + &spi::dmaTxIrqHandler, hdma_tx); + HAL_NVIC_SetPriority(cfg->txDmaIrqNumber, cfg->txPreEmptPriority, cfg->txSubpriority); + HAL_NVIC_EnableIRQ(cfg->txDmaIrqNumber); +} + +/** + * @brief SPI MSP De-Initialization + * This function frees the hardware resources used in this example: + * - Disable the Peripheral's clock + * - Revert GPIO, DMA and NVIC configuration to their default state + * @param hspi: SPI handle pointer + * @retval None + */ +void spi::halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) { + auto cfg = dynamic_cast(cfgBase); + if(hspi == nullptr or cfg == nullptr) { + return; + } + spi::halMspDeinitInterrupt(hspi, cfgBase); + DMA_HandleTypeDef* hdma_tx = NULL; + DMA_HandleTypeDef* hdma_rx = NULL; + spi::getDmaHandles(&hdma_tx, &hdma_rx); + if(hdma_tx == NULL || hdma_rx == NULL) { + printf("HAL_SPI_MspInit: Invalid DMA handles. Make sure to call setDmaHandles!\n"); + } + else { + // Disable the DMA + /* De-Initialize the DMA associated to transmission process */ + HAL_DMA_DeInit(hdma_tx); + /* De-Initialize the DMA associated to reception process */ + HAL_DMA_DeInit(hdma_rx); + } + + // Disable the NVIC for DMA + HAL_NVIC_DisableIRQ(cfg->txDmaIrqNumber); + HAL_NVIC_DisableIRQ(cfg->rxDmaIrqNumber); + +} + +void spi::halMspInitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) { + auto cfg = dynamic_cast(cfgBase); + GPIO_InitTypeDef GPIO_InitStruct = {}; + /*##-1- Enable peripherals and GPIO Clocks #################################*/ + /* Enable GPIO TX/RX clock */ + cfg->setupMacroWrapper(); + + /*##-2- Configure peripheral GPIO ##########################################*/ + /* SPI SCK GPIO pin configuration */ + GPIO_InitStruct.Pin = cfg->sckPin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.Alternate = cfg->sckAlternateFunction; + HAL_GPIO_Init(cfg->sckPort, &GPIO_InitStruct); + + /* SPI MISO GPIO pin configuration */ + GPIO_InitStruct.Pin = cfg->misoPin; + GPIO_InitStruct.Alternate = cfg->misoAlternateFunction; + HAL_GPIO_Init(cfg->misoPort, &GPIO_InitStruct); + + /* SPI MOSI GPIO pin configuration */ + GPIO_InitStruct.Pin = cfg->mosiPin; + GPIO_InitStruct.Alternate = cfg->mosiAlternateFunction; + HAL_GPIO_Init(cfg->mosiPort, &GPIO_InitStruct); +} + +void spi::halMspDeinitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) { + auto cfg = reinterpret_cast(cfgBase); + // Reset peripherals + cfg->cleanUpMacroWrapper(); + + // Disable peripherals and GPIO Clocks + /* Configure SPI SCK as alternate function */ + HAL_GPIO_DeInit(cfg->sckPort, cfg->sckPin); + /* Configure SPI MISO as alternate function */ + HAL_GPIO_DeInit(cfg->misoPort, cfg->misoPin); + /* Configure SPI MOSI as alternate function */ + HAL_GPIO_DeInit(cfg->mosiPort, cfg->mosiPin); +} + +void spi::halMspInitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) { + auto cfg = dynamic_cast(cfgBase); + if(cfg == nullptr or hspi == nullptr) { + return; + } + + spi::halMspInitPolling(hspi, cfg); + // Configure the NVIC for SPI + spi::assignSpiUserHandler(cfg->spiBus, cfg->spiIrqHandler, cfg->spiUserArgs); + HAL_NVIC_SetPriority(cfg->spiIrqNumber, cfg->preEmptPriority, cfg->subpriority); + HAL_NVIC_EnableIRQ(cfg->spiIrqNumber); +} + +void spi::halMspDeinitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) { + auto cfg = dynamic_cast(cfgBase); + spi::halMspDeinitPolling(hspi, cfg); + // Disable the NVIC for SPI + HAL_NVIC_DisableIRQ(cfg->spiIrqNumber); +} + +void spi::getMspInitFunction(msp_func_t* init_func, MspCfgBase** args) { + if(init_func != NULL && args != NULL) { + *init_func = mspInitFunc; + *args = mspInitArgs; + } +} + +void spi::getMspDeinitFunction(msp_func_t* deinit_func, MspCfgBase** args) { + if(deinit_func != NULL && args != NULL) { + *deinit_func = mspDeinitFunc; + *args = mspDeinitArgs; + } +} + +void spi::setSpiDmaMspFunctions(MspDmaConfigStruct* cfg, + msp_func_t initFunc, msp_func_t deinitFunc) { + mspInitFunc = initFunc; + mspDeinitFunc = deinitFunc; + mspInitArgs = cfg; + mspDeinitArgs = cfg; +} + +void spi::setSpiIrqMspFunctions(MspIrqConfigStruct *cfg, msp_func_t initFunc, + msp_func_t deinitFunc) { + mspInitFunc = initFunc; + mspDeinitFunc = deinitFunc; + mspInitArgs = cfg; + mspDeinitArgs = cfg; +} + +void spi::setSpiPollingMspFunctions(MspPollingConfigStruct *cfg, msp_func_t initFunc, + msp_func_t deinitFunc) { + mspInitFunc = initFunc; + mspDeinitFunc = deinitFunc; + mspInitArgs = cfg; + mspDeinitArgs = cfg; +} + +/** + * @brief SPI MSP Initialization + * This function configures the hardware resources used in this example: + * - Peripheral's clock enable + * - Peripheral's GPIO Configuration + * - DMA configuration for transmission request by peripheral + * - NVIC configuration for DMA interrupt request enable + * @param hspi: SPI handle pointer + * @retval None + */ +extern "C" void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) { + if(mspInitFunc != NULL) { + mspInitFunc(hspi, mspInitArgs); + } + else { + printf("HAL_SPI_MspInit: Please call set_msp_functions to assign SPI MSP functions\n"); + } +} + +/** + * @brief SPI MSP De-Initialization + * This function frees the hardware resources used in this example: + * - Disable the Peripheral's clock + * - Revert GPIO, DMA and NVIC configuration to their default state + * @param hspi: SPI handle pointer + * @retval None + */ +extern "C" void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi) { + if(mspDeinitFunc != NULL) { + mspDeinitFunc(hspi, mspDeinitArgs); + } + else { + printf("HAL_SPI_MspDeInit: Please call set_msp_functions to assign SPI MSP functions\n"); + } +} + +void spi::mspErrorHandler(const char* const function, const char *const message) { + printf("%s failure: %s\n", function, message); +} diff --git a/hal/src/fsfw_hal/stm32h7/spi/mspInit.h b/hal/src/fsfw_hal/stm32h7/spi/mspInit.h new file mode 100644 index 000000000..e6de2f8ea --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/mspInit.h @@ -0,0 +1,114 @@ +#ifndef FSFW_HAL_STM32H7_SPI_MSPINIT_H_ +#define FSFW_HAL_STM32H7_SPI_MSPINIT_H_ + +#include "spiDefinitions.h" +#include "../dma.h" + +#include "stm32h7xx_hal_spi.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief This file provides MSP implementation for DMA, IRQ and Polling mode for the + * SPI peripheral. This configuration is required for the SPI communication to work. + */ +namespace spi { + +struct MspCfgBase { + virtual ~MspCfgBase() = default; + + void (* cleanUpMacroWrapper) (void) = nullptr; + void (* setupMacroWrapper) (void) = nullptr; + + GPIO_TypeDef* sckPort = nullptr; + uint32_t sckPin = 0; + uint8_t sckAlternateFunction = 0; + GPIO_TypeDef* mosiPort = nullptr; + uint32_t mosiPin = 0; + uint8_t mosiAlternateFunction = 0; + GPIO_TypeDef* misoPort = nullptr; + uint32_t misoPin = 0; + uint8_t misoAlternateFunction = 0; +}; + +struct MspPollingConfigStruct: public MspCfgBase {}; + +/* A valid instance of this struct must be passed to the MSP initialization function as a void* +argument */ +struct MspIrqConfigStruct: public MspPollingConfigStruct { + SpiBus spiBus = SpiBus::SPI_1; + user_handler_t spiIrqHandler = nullptr; + user_args_t spiUserArgs = nullptr; + IRQn_Type spiIrqNumber = SPI1_IRQn; + // Priorities for NVIC + // Pre-Empt priority ranging from 0 to 15. If FreeRTOS calls are used, only 5-15 are allowed + IrqPriorities preEmptPriority = IrqPriorities::LOWEST; + IrqPriorities subpriority = IrqPriorities::LOWEST; +}; + +/* A valid instance of this struct must be passed to the MSP initialization function as a void* +argument */ +struct MspDmaConfigStruct: public MspIrqConfigStruct { + void (* dmaClkEnableWrapper) (void) = nullptr; + dma::DMAIndexes txDmaIndex; + dma::DMAIndexes rxDmaIndex; + dma::DMAStreams txDmaStream; + dma::DMAStreams rxDmaStream; + IRQn_Type txDmaIrqNumber = DMA1_Stream0_IRQn; + IRQn_Type rxDmaIrqNumber = DMA1_Stream1_IRQn; + // Priorities for NVIC + IrqPriorities txPreEmptPriority = IrqPriorities::LOWEST; + IrqPriorities rxPreEmptPriority = IrqPriorities::LOWEST; + IrqPriorities txSubpriority = IrqPriorities::LOWEST; + IrqPriorities rxSubpriority = IrqPriorities::LOWEST; +}; + +using msp_func_t = void (*) (SPI_HandleTypeDef* hspi, MspCfgBase* cfg); + + +void getMspInitFunction(msp_func_t* init_func, MspCfgBase **args); +void getMspDeinitFunction(msp_func_t* deinit_func, MspCfgBase **args); + +void halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfg); +void halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfg); + +void halMspInitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfg); +void halMspDeinitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfg); + +void halMspInitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfg); +void halMspDeinitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfg); + +/** + * Assign MSP init functions. Important for SPI configuration + * @param init_func + * @param init_args + * @param deinit_func + * @param deinit_args + */ +void setSpiDmaMspFunctions(MspDmaConfigStruct* cfg, + msp_func_t initFunc = &spi::halMspInitDma, + msp_func_t deinitFunc= &spi::halMspDeinitDma +); +void setSpiIrqMspFunctions(MspIrqConfigStruct* cfg, + msp_func_t initFunc = &spi::halMspInitInterrupt, + msp_func_t deinitFunc= &spi::halMspDeinitInterrupt +); +void setSpiPollingMspFunctions(MspPollingConfigStruct* cfg, + msp_func_t initFunc = &spi::halMspInitPolling, + msp_func_t deinitFunc= &spi::halMspDeinitPolling +); + +void mspErrorHandler(const char* const function, const char *const message); + +} + + +#ifdef __cplusplus +} +#endif + +#endif /* FSFW_HAL_STM32H7_SPI_MSPINIT_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/spi/spiCore.cpp b/hal/src/fsfw_hal/stm32h7/spi/spiCore.cpp new file mode 100644 index 000000000..e569c9f46 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/spiCore.cpp @@ -0,0 +1,341 @@ +#include "fsfw_hal/stm32h7/spi/spiCore.h" +#include "fsfw_hal/stm32h7/spi/spiDefinitions.h" + +#include + +SPI_HandleTypeDef* spiHandle = nullptr; +DMA_HandleTypeDef* hdmaTx = nullptr; +DMA_HandleTypeDef* hdmaRx = nullptr; + +spi_transfer_cb_t rxTxCb = nullptr; +void* rxTxArgs = nullptr; +spi_transfer_cb_t txCb = nullptr; +void* txArgs = nullptr; +spi_transfer_cb_t rxCb = nullptr; +void* rxArgs = nullptr; +spi_transfer_cb_t errorCb = nullptr; +void* errorArgs = nullptr; + +void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMAIndexes dmaIdx, + dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber); +void mapSpiBus(DMA_HandleTypeDef *handle, dma::DMAType dmaType, spi::SpiBus spiBus); + +void spi::configureDmaHandle(DMA_HandleTypeDef *handle, spi::SpiBus spiBus, dma::DMAType dmaType, + dma::DMAIndexes dmaIdx, dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber, + uint32_t dmaMode, uint32_t dmaPriority) { + using namespace dma; + mapIndexAndStream(handle, dmaType, dmaIdx, dmaStream, dmaIrqNumber); + mapSpiBus(handle, dmaType, spiBus); + + if(dmaType == DMAType::TX) { + handle->Init.Direction = DMA_MEMORY_TO_PERIPH; + } + else { + handle->Init.Direction = DMA_PERIPH_TO_MEMORY; + } + + handle->Init.Priority = dmaPriority; + handle->Init.Mode = dmaMode; + + // Standard settings for the rest for now + handle->Init.FIFOMode = DMA_FIFOMODE_DISABLE; + handle->Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; + handle->Init.MemBurst = DMA_MBURST_INC4; + handle->Init.PeriphBurst = DMA_PBURST_INC4; + handle->Init.PeriphInc = DMA_PINC_DISABLE; + handle->Init.MemInc = DMA_MINC_ENABLE; + handle->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + handle->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; +} + +void spi::setDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle) { + hdmaTx = txHandle; + hdmaRx = rxHandle; +} + +void spi::getDmaHandles(DMA_HandleTypeDef** txHandle, DMA_HandleTypeDef** rxHandle) { + *txHandle = hdmaTx; + *rxHandle = hdmaRx; +} + +void spi::setSpiHandle(SPI_HandleTypeDef *spiHandle_) { + if(spiHandle_ == NULL) { + return; + } + spiHandle = spiHandle_; +} + +void spi::assignTransferRxTxCompleteCallback(spi_transfer_cb_t callback, void *userArgs) { + rxTxCb = callback; + rxTxArgs = userArgs; +} + +void spi::assignTransferRxCompleteCallback(spi_transfer_cb_t callback, void *userArgs) { + rxCb = callback; + rxArgs = userArgs; +} + +void spi::assignTransferTxCompleteCallback(spi_transfer_cb_t callback, void *userArgs) { + txCb = callback; + txArgs = userArgs; +} + +void spi::assignTransferErrorCallback(spi_transfer_cb_t callback, void *userArgs) { + errorCb = callback; + errorArgs = userArgs; +} + +SPI_HandleTypeDef* spi::getSpiHandle() { + return spiHandle; +} + + + +/** + * @brief TxRx Transfer completed callback. + * @param hspi: SPI handle + */ +extern "C" void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) { + if(rxTxCb != NULL) { + rxTxCb(hspi, rxTxArgs); + } + else { + printf("HAL_SPI_TxRxCpltCallback: No user callback specified\n"); + } +} + +/** + * @brief TxRx Transfer completed callback. + * @param hspi: SPI handle + */ +extern "C" void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) { + if(txCb != NULL) { + txCb(hspi, txArgs); + } + else { + printf("HAL_SPI_TxCpltCallback: No user callback specified\n"); + } +} + +/** + * @brief TxRx Transfer completed callback. + * @param hspi: SPI handle + */ +extern "C" void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi) { + if(rxCb != nullptr) { + rxCb(hspi, rxArgs); + } + else { + printf("HAL_SPI_RxCpltCallback: No user callback specified\n"); + } +} + +/** + * @brief SPI error callbacks. + * @param hspi: SPI handle + * @note This example shows a simple way to report transfer error, and you can + * add your own implementation. + * @retval None + */ +extern "C" void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi) { + if(errorCb != nullptr) { + errorCb(hspi, rxArgs); + } + else { + printf("HAL_SPI_ErrorCallback: No user callback specified\n"); + } +} + +void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMAIndexes dmaIdx, + dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber) { + using namespace dma; + if(dmaIdx == DMAIndexes::DMA_1) { +#ifdef DMA1 + switch(dmaStream) { + case(DMAStreams::STREAM_0): { +#ifdef DMA1_Stream0 + handle->Instance = DMA1_Stream0; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA1_Stream0_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_1): { +#ifdef DMA1_Stream1 + handle->Instance = DMA1_Stream1; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA1_Stream1_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_2): { +#ifdef DMA1_Stream2 + handle->Instance = DMA1_Stream2; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA1_Stream2_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_3): { +#ifdef DMA1_Stream3 + handle->Instance = DMA1_Stream3; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA1_Stream3_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_4): { +#ifdef DMA1_Stream4 + handle->Instance = DMA1_Stream4; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA1_Stream4_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_5): { +#ifdef DMA1_Stream5 + handle->Instance = DMA1_Stream5; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA1_Stream5_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_6): { +#ifdef DMA1_Stream6 + handle->Instance = DMA1_Stream6; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA1_Stream6_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_7): { +#ifdef DMA1_Stream7 + handle->Instance = DMA1_Stream7; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA1_Stream7_IRQn; + } +#endif + break; + } + } + if(dmaType == DMAType::TX) { + handle->Init.Request = DMA_REQUEST_SPI1_TX; + } + else { + handle->Init.Request = DMA_REQUEST_SPI1_RX; + } +#endif /* DMA1 */ + } + if(dmaIdx == DMAIndexes::DMA_2) { +#ifdef DMA2 + switch(dmaStream) { + case(DMAStreams::STREAM_0): { +#ifdef DMA2_Stream0 + handle->Instance = DMA2_Stream0; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA2_Stream0_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_1): { +#ifdef DMA2_Stream1 + handle->Instance = DMA2_Stream1; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA2_Stream1_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_2): { +#ifdef DMA2_Stream2 + handle->Instance = DMA2_Stream2; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA2_Stream2_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_3): { +#ifdef DMA2_Stream3 + handle->Instance = DMA2_Stream3; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA2_Stream3_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_4): { +#ifdef DMA2_Stream4 + handle->Instance = DMA2_Stream4; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA2_Stream4_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_5): { +#ifdef DMA2_Stream5 + handle->Instance = DMA2_Stream5; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA2_Stream5_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_6): { +#ifdef DMA2_Stream6 + handle->Instance = DMA2_Stream6; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA2_Stream6_IRQn; + } +#endif + break; + } + case(DMAStreams::STREAM_7): { +#ifdef DMA2_Stream7 + handle->Instance = DMA2_Stream7; + if(dmaIrqNumber != nullptr) { + *dmaIrqNumber = DMA2_Stream7_IRQn; + } +#endif + break; + } + } +#endif /* DMA2 */ + } +} + +void mapSpiBus(DMA_HandleTypeDef *handle, dma::DMAType dmaType, spi::SpiBus spiBus) { + if(dmaType == dma::DMAType::TX) { + if(spiBus == spi::SpiBus::SPI_1) { +#ifdef DMA_REQUEST_SPI1_TX + handle->Init.Request = DMA_REQUEST_SPI1_TX; +#endif + } + else if(spiBus == spi::SpiBus::SPI_2) { +#ifdef DMA_REQUEST_SPI2_TX + handle->Init.Request = DMA_REQUEST_SPI2_TX; +#endif + } + } + else { + if(spiBus == spi::SpiBus::SPI_1) { +#ifdef DMA_REQUEST_SPI1_RX + handle->Init.Request = DMA_REQUEST_SPI1_RX; +#endif + } + else if(spiBus == spi::SpiBus::SPI_2) { +#ifdef DMA_REQUEST_SPI2_RX + handle->Init.Request = DMA_REQUEST_SPI2_RX; +#endif + } + } +} diff --git a/hal/src/fsfw_hal/stm32h7/spi/spiCore.h b/hal/src/fsfw_hal/stm32h7/spi/spiCore.h new file mode 100644 index 000000000..1ad5c6935 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/spiCore.h @@ -0,0 +1,54 @@ +#ifndef FSFW_HAL_STM32H7_SPI_SPICORE_H_ +#define FSFW_HAL_STM32H7_SPI_SPICORE_H_ + +#include "fsfw_hal/stm32h7/dma.h" +#include "fsfw_hal/stm32h7/spi/spiDefinitions.h" + +#include "stm32h7xx_hal.h" +#include "stm32h7xx_hal_dma.h" + +#ifdef __cplusplus +extern "C" { +#endif + +using spi_transfer_cb_t = void (*) (SPI_HandleTypeDef *hspi, void* userArgs); + +namespace spi { + +void configureDmaHandle(DMA_HandleTypeDef* handle, spi::SpiBus spiBus, + dma::DMAType dmaType, dma::DMAIndexes dmaIdx, + dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber, uint32_t dmaMode = DMA_NORMAL, + uint32_t dmaPriority = DMA_PRIORITY_LOW); + +/** + * Assign DMA handles. Required to use DMA for SPI transfers. + * @param txHandle + * @param rxHandle + */ +void setDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle); +void getDmaHandles(DMA_HandleTypeDef** txHandle, DMA_HandleTypeDef** rxHandle); + +/** + * Assign SPI handle. Needs to be done before using the SPI + * @param spiHandle + */ +void setSpiHandle(SPI_HandleTypeDef *spiHandle); + +void assignTransferRxTxCompleteCallback(spi_transfer_cb_t callback, void* userArgs); +void assignTransferRxCompleteCallback(spi_transfer_cb_t callback, void* userArgs); +void assignTransferTxCompleteCallback(spi_transfer_cb_t callback, void* userArgs); +void assignTransferErrorCallback(spi_transfer_cb_t callback, void* userArgs); + +/** + * Get the assigned SPI handle. + * @return + */ +SPI_HandleTypeDef* getSpiHandle(); + +} + +#ifdef __cplusplus +} +#endif + +#endif /* FSFW_HAL_STM32H7_SPI_SPICORE_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/spi/spiDefinitions.cpp b/hal/src/fsfw_hal/stm32h7/spi/spiDefinitions.cpp new file mode 100644 index 000000000..11655f5ec --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/spiDefinitions.cpp @@ -0,0 +1,52 @@ +#include "fsfw_hal/stm32h7/spi/spiDefinitions.h" + +void spi::assignSpiMode(SpiModes spiMode, SPI_HandleTypeDef& spiHandle) { + switch(spiMode) { + case(SpiModes::MODE_0): { + spiHandle.Init.CLKPolarity = SPI_POLARITY_LOW; + spiHandle.Init.CLKPhase = SPI_PHASE_1EDGE; + break; + } + case(SpiModes::MODE_1): { + spiHandle.Init.CLKPolarity = SPI_POLARITY_LOW; + spiHandle.Init.CLKPhase = SPI_PHASE_2EDGE; + break; + } + case(SpiModes::MODE_2): { + spiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH; + spiHandle.Init.CLKPhase = SPI_PHASE_1EDGE; + break; + } + case(SpiModes::MODE_3): { + spiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH; + spiHandle.Init.CLKPhase = SPI_PHASE_2EDGE; + break; + } + } +} + +uint32_t spi::getPrescaler(uint32_t clock_src_freq, uint32_t baudrate_mbps) { + uint32_t divisor = 0; + uint32_t spi_clk = clock_src_freq; + uint32_t presc = 0; + static const uint32_t baudrate[] = { + SPI_BAUDRATEPRESCALER_2, + SPI_BAUDRATEPRESCALER_4, + SPI_BAUDRATEPRESCALER_8, + SPI_BAUDRATEPRESCALER_16, + SPI_BAUDRATEPRESCALER_32, + SPI_BAUDRATEPRESCALER_64, + SPI_BAUDRATEPRESCALER_128, + SPI_BAUDRATEPRESCALER_256, + }; + + while( spi_clk > baudrate_mbps) { + presc = baudrate[divisor]; + if (++divisor > 7) + break; + + spi_clk = ( spi_clk >> 1); + } + + return presc; +} diff --git a/hal/src/fsfw_hal/stm32h7/spi/spiDefinitions.h b/hal/src/fsfw_hal/stm32h7/spi/spiDefinitions.h new file mode 100644 index 000000000..772bf32de --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/spiDefinitions.h @@ -0,0 +1,50 @@ +#ifndef FSFW_HAL_STM32H7_SPI_SPIDEFINITIONS_H_ +#define FSFW_HAL_STM32H7_SPI_SPIDEFINITIONS_H_ + +#include "../../common/spi/spiCommon.h" + +#include "fsfw/returnvalues/FwClassIds.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" + +#include "stm32h7xx_hal.h" +#include "stm32h7xx_hal_spi.h" + +namespace spi { + +static constexpr uint8_t HAL_SPI_ID = CLASS_ID::HAL_SPI; +static constexpr ReturnValue_t HAL_TIMEOUT_RETVAL = HasReturnvaluesIF::makeReturnCode(HAL_SPI_ID, 0); +static constexpr ReturnValue_t HAL_BUSY_RETVAL = HasReturnvaluesIF::makeReturnCode(HAL_SPI_ID, 1); +static constexpr ReturnValue_t HAL_ERROR_RETVAL = HasReturnvaluesIF::makeReturnCode(HAL_SPI_ID, 2); + +enum class TransferStates { + IDLE, + WAIT, + SUCCESS, + FAILURE +}; + +enum SpiBus { + SPI_1, + SPI_2 +}; + +enum TransferModes { + POLLING, + INTERRUPT, + DMA +}; + +void assignSpiMode(SpiModes spiMode, SPI_HandleTypeDef& spiHandle); + +/** + * @brief Set SPI frequency to calculate correspondent baud-rate prescaler. + * @param clock_src_freq Frequency of clock source + * @param baudrate_mbps Baudrate to set to set + * @retval Baudrate prescaler + */ +uint32_t getPrescaler(uint32_t clock_src_freq, uint32_t baudrate_mbps); + +} + + +#endif /* FSFW_HAL_STM32H7_SPI_SPIDEFINITIONS_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/spi/spiInterrupts.cpp b/hal/src/fsfw_hal/stm32h7/spi/spiInterrupts.cpp new file mode 100644 index 000000000..5d84208d9 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/spiInterrupts.cpp @@ -0,0 +1,106 @@ +#include "fsfw_hal/stm32h7/spi/spiInterrupts.h" +#include "fsfw_hal/stm32h7/spi/spiCore.h" + +#include "stm32h7xx_hal.h" +#include "stm32h7xx_hal_dma.h" +#include "stm32h7xx_hal_spi.h" + +#include + +user_handler_t spi1UserHandler = &spi::spiIrqHandler; +user_args_t spi1UserArgs = nullptr; + +user_handler_t spi2UserHandler = &spi::spiIrqHandler; +user_args_t spi2UserArgs = nullptr; + +/** + * @brief This function handles DMA Rx interrupt request. + * @param None + * @retval None + */ +void spi::dmaRxIrqHandler(void* dmaHandle) { + if(dmaHandle == nullptr) { + return; + } + HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dmaHandle); +} + +/** + * @brief This function handles DMA Rx interrupt request. + * @param None + * @retval None + */ +void spi::dmaTxIrqHandler(void* dmaHandle) { + if(dmaHandle == nullptr) { + return; + } + HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dmaHandle); +} + +/** + * @brief This function handles SPIx interrupt request. + * @param None + * @retval None + */ +void spi::spiIrqHandler(void* spiHandle) { + if(spiHandle == nullptr) { + return; + } + //auto currentSpiHandle = spi::getSpiHandle(); + HAL_SPI_IRQHandler((SPI_HandleTypeDef *) spiHandle); +} + +void spi::assignSpiUserHandler(spi::SpiBus spiIdx, user_handler_t userHandler, + user_args_t userArgs) { + if(spiIdx == spi::SpiBus::SPI_1) { + spi1UserHandler = userHandler; + spi1UserArgs = userArgs; + } + else { + spi2UserHandler = userHandler; + spi2UserArgs = userArgs; + } +} + +void spi::getSpiUserHandler(spi::SpiBus spiBus, user_handler_t *userHandler, + user_args_t *userArgs) { + if(userHandler == nullptr or userArgs == nullptr) { + return; + } + if(spiBus == spi::SpiBus::SPI_1) { + *userArgs = spi1UserArgs; + *userHandler = spi1UserHandler; + } + else { + *userArgs = spi2UserArgs; + *userHandler = spi2UserHandler; + } +} + +void spi::assignSpiUserArgs(spi::SpiBus spiBus, user_args_t userArgs) { + if(spiBus == spi::SpiBus::SPI_1) { + spi1UserArgs = userArgs; + } + else { + spi2UserArgs = userArgs; + } +} + +/* Do not change these function names! They need to be exactly equal to the name of the functions +defined in the startup_stm32h743xx.s files! */ + +extern "C" void SPI1_IRQHandler() { + if(spi1UserHandler != NULL) { + spi1UserHandler(spi1UserArgs); + return; + } + Default_Handler(); +} + +extern "C" void SPI2_IRQHandler() { + if(spi2UserHandler != nullptr) { + spi2UserHandler(spi2UserArgs); + return; + } + Default_Handler(); +} diff --git a/hal/src/fsfw_hal/stm32h7/spi/spiInterrupts.h b/hal/src/fsfw_hal/stm32h7/spi/spiInterrupts.h new file mode 100644 index 000000000..0b53f48bd --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/spiInterrupts.h @@ -0,0 +1,41 @@ +#ifndef FSFW_HAL_STM32H7_SPI_INTERRUPTS_H_ +#define FSFW_HAL_STM32H7_SPI_INTERRUPTS_H_ + +#include "../interrupts.h" +#include "spiDefinitions.h" + +#ifdef __cplusplus +extern "C" { +#endif + +namespace spi { + +void assignSpiUserArgs(spi::SpiBus spiBus, user_args_t userArgs); + +/** + * Assign a user interrupt handler for SPI bus 1, allowing to pass an arbitrary argument as well. + * Generally, this argument will be the related SPI handle. + * @param user_handler + * @param user_args + */ +void assignSpiUserHandler(spi::SpiBus spiBus, user_handler_t user_handler, + user_args_t user_args); +void getSpiUserHandler(spi::SpiBus spiBus, user_handler_t* user_handler, + user_args_t* user_args); + +/** + * Generic interrupt handlers supplied for convenience. Do not call these directly! Set them + * instead with assign_dma_user_handler and assign_spi_user_handler functions. + * @param dma_handle + */ +void dmaRxIrqHandler(void* dma_handle); +void dmaTxIrqHandler(void* dma_handle); +void spiIrqHandler(void* spi_handle); + +} + +#ifdef __cplusplus +} +#endif + +#endif /* FSFW_HAL_STM32H7_SPI_INTERRUPTS_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.cpp b/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.cpp new file mode 100644 index 000000000..43194704f --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.cpp @@ -0,0 +1,82 @@ +#include "fsfw_hal/stm32h7/spi/stm32h743ziSpi.h" +#include "fsfw_hal/stm32h7/spi/spiCore.h" +#include "fsfw_hal/stm32h7/spi/spiInterrupts.h" + +#include "stm32h7xx_hal.h" +#include "stm32h7xx_hal_rcc.h" + +#include + +void spiSetupWrapper() { + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_SPI1_CLK_ENABLE(); +} + +void spiCleanUpWrapper() { + __HAL_RCC_SPI1_FORCE_RESET(); + __HAL_RCC_SPI1_RELEASE_RESET(); +} + +void spiDmaClockEnableWrapper() { + __HAL_RCC_DMA2_CLK_ENABLE(); +} + +void spi::h743zi::standardPollingCfg(MspPollingConfigStruct& cfg) { + cfg.setupMacroWrapper = &spiSetupWrapper; + cfg.cleanUpMacroWrapper = &spiCleanUpWrapper; + cfg.sckPort = GPIOA; + cfg.sckPin = GPIO_PIN_5; + cfg.misoPort = GPIOA; + cfg.misoPin = GPIO_PIN_6; + cfg.mosiPort = GPIOA; + cfg.mosiPin = GPIO_PIN_7; + cfg.sckAlternateFunction = GPIO_AF5_SPI1; + cfg.mosiAlternateFunction = GPIO_AF5_SPI1; + cfg.misoAlternateFunction = GPIO_AF5_SPI1; +} + +void spi::h743zi::standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio, + IrqPriorities spiSubprio) { + // High, but works on FreeRTOS as well (priorities range from 0 to 15) + cfg.preEmptPriority = spiIrqPrio; + cfg.subpriority = spiSubprio; + cfg.spiIrqNumber = SPI1_IRQn; + cfg.spiBus = SpiBus::SPI_1; + user_handler_t spiUserHandler = nullptr; + user_args_t spiUserArgs = nullptr; + getSpiUserHandler(spi::SpiBus::SPI_1, &spiUserHandler, &spiUserArgs); + if(spiUserHandler == nullptr) { + printf("spi::h743zi::standardInterruptCfg: Invalid SPI user handlers\n"); + return; + } + cfg.spiUserArgs = spiUserArgs; + cfg.spiIrqHandler = spiUserHandler; + standardPollingCfg(cfg); +} + +void spi::h743zi::standardDmaCfg(MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio, + IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio, IrqPriorities spiSubprio, + IrqPriorities txSubprio, IrqPriorities rxSubprio) { + cfg.dmaClkEnableWrapper = &spiDmaClockEnableWrapper; + cfg.rxDmaIndex = dma::DMAIndexes::DMA_2; + cfg.txDmaIndex = dma::DMAIndexes::DMA_2; + cfg.txDmaStream = dma::DMAStreams::STREAM_3; + cfg.rxDmaStream = dma::DMAStreams::STREAM_2; + DMA_HandleTypeDef* txHandle; + DMA_HandleTypeDef* rxHandle; + spi::getDmaHandles(&txHandle, &rxHandle); + if(txHandle == nullptr or rxHandle == nullptr) { + printf("spi::h743zi::standardDmaCfg: Invalid DMA handles\n"); + return; + } + spi::configureDmaHandle(txHandle, spi::SpiBus::SPI_1, dma::DMAType::TX, cfg.txDmaIndex, + cfg.txDmaStream, &cfg.txDmaIrqNumber); + spi::configureDmaHandle(rxHandle, spi::SpiBus::SPI_1, dma::DMAType::RX, cfg.rxDmaIndex, + cfg.rxDmaStream, &cfg.rxDmaIrqNumber, DMA_NORMAL, DMA_PRIORITY_HIGH); + cfg.txPreEmptPriority = txIrqPrio; + cfg.rxPreEmptPriority = txSubprio; + cfg.txSubpriority = rxIrqPrio; + cfg.rxSubpriority = rxSubprio; + standardInterruptCfg(cfg, spiIrqPrio, spiSubprio); +} diff --git a/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.h b/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.h new file mode 100644 index 000000000..87689addf --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/spi/stm32h743ziSpi.h @@ -0,0 +1,23 @@ +#ifndef FSFW_HAL_STM32H7_SPI_STM32H743ZISPI_H_ +#define FSFW_HAL_STM32H7_SPI_STM32H743ZISPI_H_ + +#include "mspInit.h" + +namespace spi { + +namespace h743zi { + +void standardPollingCfg(MspPollingConfigStruct& cfg); +void standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio, + IrqPriorities spiSubprio = HIGHEST); +void standardDmaCfg(MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio, + IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio, + IrqPriorities spiSubprio = HIGHEST, IrqPriorities txSubPrio = HIGHEST, + IrqPriorities rxSubprio = HIGHEST); + +} +} + + + +#endif /* FSFW_HAL_STM32H7_SPI_STM32H743ZISPI_H_ */ diff --git a/hal/src/fsfw_hal/stm32h7/uart/CMakeLists.txt b/hal/src/fsfw_hal/stm32h7/uart/CMakeLists.txt new file mode 100644 index 000000000..5ecb09909 --- /dev/null +++ b/hal/src/fsfw_hal/stm32h7/uart/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE +) diff --git a/defaultcfg/README.md b/misc/defaultcfg/README.md similarity index 100% rename from defaultcfg/README.md rename to misc/defaultcfg/README.md diff --git a/defaultcfg/fsfwconfig/CMakeLists.txt b/misc/defaultcfg/fsfwconfig/CMakeLists.txt similarity index 100% rename from defaultcfg/fsfwconfig/CMakeLists.txt rename to misc/defaultcfg/fsfwconfig/CMakeLists.txt diff --git a/defaultcfg/fsfwconfig/FSFWConfig.h b/misc/defaultcfg/fsfwconfig/FSFWConfig.h similarity index 100% rename from defaultcfg/fsfwconfig/FSFWConfig.h rename to misc/defaultcfg/fsfwconfig/FSFWConfig.h diff --git a/defaultcfg/fsfwconfig/OBSWConfig.h b/misc/defaultcfg/fsfwconfig/OBSWConfig.h similarity index 100% rename from defaultcfg/fsfwconfig/OBSWConfig.h rename to misc/defaultcfg/fsfwconfig/OBSWConfig.h diff --git a/defaultcfg/fsfwconfig/OBSWVersion.h b/misc/defaultcfg/fsfwconfig/OBSWVersion.h similarity index 100% rename from defaultcfg/fsfwconfig/OBSWVersion.h rename to misc/defaultcfg/fsfwconfig/OBSWVersion.h diff --git a/defaultcfg/fsfwconfig/devices/logicalAddresses.h b/misc/defaultcfg/fsfwconfig/devices/logicalAddresses.h similarity index 100% rename from defaultcfg/fsfwconfig/devices/logicalAddresses.h rename to misc/defaultcfg/fsfwconfig/devices/logicalAddresses.h diff --git a/defaultcfg/fsfwconfig/devices/powerSwitcherList.h b/misc/defaultcfg/fsfwconfig/devices/powerSwitcherList.h similarity index 100% rename from defaultcfg/fsfwconfig/devices/powerSwitcherList.h rename to misc/defaultcfg/fsfwconfig/devices/powerSwitcherList.h diff --git a/defaultcfg/fsfwconfig/events/subsystemIdRanges.h b/misc/defaultcfg/fsfwconfig/events/subsystemIdRanges.h similarity index 100% rename from defaultcfg/fsfwconfig/events/subsystemIdRanges.h rename to misc/defaultcfg/fsfwconfig/events/subsystemIdRanges.h diff --git a/defaultcfg/fsfwconfig/ipc/missionMessageTypes.cpp b/misc/defaultcfg/fsfwconfig/ipc/missionMessageTypes.cpp similarity index 100% rename from defaultcfg/fsfwconfig/ipc/missionMessageTypes.cpp rename to misc/defaultcfg/fsfwconfig/ipc/missionMessageTypes.cpp diff --git a/defaultcfg/fsfwconfig/ipc/missionMessageTypes.h b/misc/defaultcfg/fsfwconfig/ipc/missionMessageTypes.h similarity index 100% rename from defaultcfg/fsfwconfig/ipc/missionMessageTypes.h rename to misc/defaultcfg/fsfwconfig/ipc/missionMessageTypes.h diff --git a/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp similarity index 97% rename from defaultcfg/fsfwconfig/objects/FsfwFactory.cpp rename to misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp index 428adf1d7..08ad41ec3 100644 --- a/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp +++ b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/defaultcfg/fsfwconfig/objects/FsfwFactory.h b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.h similarity index 100% rename from defaultcfg/fsfwconfig/objects/FsfwFactory.h rename to misc/defaultcfg/fsfwconfig/objects/FsfwFactory.h diff --git a/defaultcfg/fsfwconfig/objects/systemObjectList.h b/misc/defaultcfg/fsfwconfig/objects/systemObjectList.h similarity index 100% rename from defaultcfg/fsfwconfig/objects/systemObjectList.h rename to misc/defaultcfg/fsfwconfig/objects/systemObjectList.h diff --git a/defaultcfg/fsfwconfig/pollingsequence/PollingSequenceFactory.cpp b/misc/defaultcfg/fsfwconfig/pollingsequence/PollingSequenceFactory.cpp similarity index 100% rename from defaultcfg/fsfwconfig/pollingsequence/PollingSequenceFactory.cpp rename to misc/defaultcfg/fsfwconfig/pollingsequence/PollingSequenceFactory.cpp diff --git a/defaultcfg/fsfwconfig/pollingsequence/PollingSequenceFactory.h b/misc/defaultcfg/fsfwconfig/pollingsequence/PollingSequenceFactory.h similarity index 100% rename from defaultcfg/fsfwconfig/pollingsequence/PollingSequenceFactory.h rename to misc/defaultcfg/fsfwconfig/pollingsequence/PollingSequenceFactory.h diff --git a/defaultcfg/fsfwconfig/returnvalues/classIds.h b/misc/defaultcfg/fsfwconfig/returnvalues/classIds.h similarity index 100% rename from defaultcfg/fsfwconfig/returnvalues/classIds.h rename to misc/defaultcfg/fsfwconfig/returnvalues/classIds.h diff --git a/defaultcfg/fsfwconfig/tmtc/apid.h b/misc/defaultcfg/fsfwconfig/tmtc/apid.h similarity index 100% rename from defaultcfg/fsfwconfig/tmtc/apid.h rename to misc/defaultcfg/fsfwconfig/tmtc/apid.h diff --git a/defaultcfg/fsfwconfig/tmtc/pusIds.h b/misc/defaultcfg/fsfwconfig/tmtc/pusIds.h similarity index 100% rename from defaultcfg/fsfwconfig/tmtc/pusIds.h rename to misc/defaultcfg/fsfwconfig/tmtc/pusIds.h diff --git a/logo/FSFW_Logo_V3.png b/misc/logo/FSFW_Logo_V3.png similarity index 100% rename from logo/FSFW_Logo_V3.png rename to misc/logo/FSFW_Logo_V3.png diff --git a/logo/FSFW_Logo_V3.svg b/misc/logo/FSFW_Logo_V3.svg similarity index 100% rename from logo/FSFW_Logo_V3.svg rename to misc/logo/FSFW_Logo_V3.svg diff --git a/logo/FSFW_Logo_V3_bw.png b/misc/logo/FSFW_Logo_V3_bw.png similarity index 100% rename from logo/FSFW_Logo_V3_bw.png rename to misc/logo/FSFW_Logo_V3_bw.png diff --git a/osal/InternalErrorCodes.h b/osal/InternalErrorCodes.h deleted file mode 100644 index 1da116fa3..000000000 --- a/osal/InternalErrorCodes.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef INTERNALERRORCODES_H_ -#define INTERNALERRORCODES_H_ - -#include "../returnvalues/HasReturnvaluesIF.h" - -class InternalErrorCodes { -public: - static const uint8_t INTERFACE_ID = CLASS_ID::INTERNAL_ERROR_CODES; - -static const ReturnValue_t NO_CONFIGURATION_TABLE = MAKE_RETURN_CODE(0x01 ); -static const ReturnValue_t NO_CPU_TABLE = MAKE_RETURN_CODE(0x02 ); -static const ReturnValue_t INVALID_WORKSPACE_ADDRESS = MAKE_RETURN_CODE(0x03 ); -static const ReturnValue_t TOO_LITTLE_WORKSPACE = MAKE_RETURN_CODE(0x04 ); -static const ReturnValue_t WORKSPACE_ALLOCATION = MAKE_RETURN_CODE(0x05 ); -static const ReturnValue_t INTERRUPT_STACK_TOO_SMALL = MAKE_RETURN_CODE(0x06 ); -static const ReturnValue_t THREAD_EXITTED = MAKE_RETURN_CODE(0x07 ); -static const ReturnValue_t INCONSISTENT_MP_INFORMATION = MAKE_RETURN_CODE(0x08 ); -static const ReturnValue_t INVALID_NODE = MAKE_RETURN_CODE(0x09 ); -static const ReturnValue_t NO_MPCI = MAKE_RETURN_CODE(0x0a ); -static const ReturnValue_t BAD_PACKET = MAKE_RETURN_CODE(0x0b ); -static const ReturnValue_t OUT_OF_PACKETS = MAKE_RETURN_CODE(0x0c ); -static const ReturnValue_t OUT_OF_GLOBAL_OBJECTS = MAKE_RETURN_CODE(0x0d ); -static const ReturnValue_t OUT_OF_PROXIES = MAKE_RETURN_CODE(0x0e ); -static const ReturnValue_t INVALID_GLOBAL_ID = MAKE_RETURN_CODE(0x0f ); -static const ReturnValue_t BAD_STACK_HOOK = MAKE_RETURN_CODE(0x10 ); -static const ReturnValue_t BAD_ATTRIBUTES = MAKE_RETURN_CODE(0x11 ); -static const ReturnValue_t IMPLEMENTATION_KEY_CREATE_INCONSISTENCY = MAKE_RETURN_CODE(0x12 ); -static const ReturnValue_t IMPLEMENTATION_BLOCKING_OPERATION_CANCEL = MAKE_RETURN_CODE(0x13 ); -static const ReturnValue_t MUTEX_OBTAIN_FROM_BAD_STATE = MAKE_RETURN_CODE(0x14 ); -static const ReturnValue_t UNLIMITED_AND_MAXIMUM_IS_0 = MAKE_RETURN_CODE(0x15 ); - - virtual ~InternalErrorCodes(); - - static ReturnValue_t translate(uint8_t code); -private: - InternalErrorCodes(); -}; - -#endif /* INTERNALERRORCODES_H_ */ diff --git a/osal/linux/Timer.cpp b/osal/linux/Timer.cpp deleted file mode 100644 index fe0fbebba..000000000 --- a/osal/linux/Timer.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "Timer.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" -#include - - -Timer::Timer() { - sigevent sigEvent; - sigEvent.sigev_notify = SIGEV_NONE; - sigEvent.sigev_signo = 0; - sigEvent.sigev_value.sival_ptr = &timerId; - int status = timer_create(CLOCK_MONOTONIC, &sigEvent, &timerId); - if(status!=0){ -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "Timer creation failed with: " << status << - " errno: " << errno << std::endl; -#endif - } -} - -Timer::~Timer() { - timer_delete(timerId); -} - -int Timer::setTimer(uint32_t intervalMs) { - itimerspec timer; - timer.it_value.tv_sec = intervalMs / 1000; - timer.it_value.tv_nsec = (intervalMs * 1000000) % (1000000000); - timer.it_interval.tv_sec = 0; - timer.it_interval.tv_nsec = 0; - return timer_settime(timerId, 0, &timer, NULL); -} - - -int Timer::getTimer(uint32_t* remainingTimeMs){ - itimerspec timer; - timer.it_value.tv_sec = 0; - timer.it_value.tv_nsec = 0; - timer.it_interval.tv_sec = 0; - timer.it_interval.tv_nsec = 0; - int status = timer_gettime(timerId, &timer); - - *remainingTimeMs = timer.it_value.tv_sec * 1000 + timer.it_value.tv_nsec / 1000000; - - return status; -} diff --git a/osal/linux/Timer.h b/osal/linux/Timer.h deleted file mode 100644 index f94bca59b..000000000 --- a/osal/linux/Timer.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef FRAMEWORK_OSAL_LINUX_TIMER_H_ -#define FRAMEWORK_OSAL_LINUX_TIMER_H_ - -#include -#include -#include - -/** - * This class is a helper for the creation of a Clock Monotonic timer which does not trigger a signal - */ -class Timer { -public: - /** - * Creates the Timer sets the timerId Member - */ - Timer(); - /** - * Deletes the timer - * - * Careful! According to POSIX documentation: - * The treatment of any pending signal generated by the deleted timer is unspecified. - */ - virtual ~Timer(); - - /** - * Set the timer given in timerId to the given interval - * - * @param intervalMs Interval in ms to be set - * @return 0 on Success 1 else - */ - int setTimer(uint32_t intervalMs); - - /** - * Get the remaining time of the timer - * - * @param remainingTimeMs Pointer to integer value which is used to return the remaining time - * @return 0 on Success 1 else (see timer_getime documentation of posix function) - */ - int getTimer(uint32_t* remainingTimeMs); - -private: - timer_t timerId; -}; - -#endif /* FRAMEWORK_OSAL_LINUX_TIMER_H_ */ diff --git a/osal/rtems/RtemsBasic.cpp b/osal/rtems/RtemsBasic.cpp deleted file mode 100644 index 8ab0ddcd6..000000000 --- a/osal/rtems/RtemsBasic.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "RtemsBasic.h" - -// TODO: Can this be removed? - -//ReturnValue_t RtemsBasic::convertReturnCode(rtems_status_code inValue) { -// if (inValue == RTEMS_SUCCESSFUL) { -// return HasReturnvaluesIF::RETURN_OK; -// } else { -// switch(inValue){ -// case RTEMS_SUCCESSFUL: -// return OperatingSystemIF::SUCCESSFUL; -// case RTEMS_TASK_EXITTED: -// return OperatingSystemIF::TASK_EXITTED; -// case RTEMS_MP_NOT_CONFIGURED: -// return OperatingSystemIF::MP_NOT_CONFIGURED; -// case RTEMS_INVALID_NAME: -// return OperatingSystemIF::INVALID_NAME; -// case RTEMS_INVALID_ID: -// return OperatingSystemIF::INVALID_ID; -// case RTEMS_TOO_MANY: -// return OperatingSystemIF::TOO_MANY; -// case RTEMS_TIMEOUT: -// return OperatingSystemIF::TIMEOUT; -// case RTEMS_OBJECT_WAS_DELETED: -// return OperatingSystemIF::OBJECT_WAS_DELETED; -// case RTEMS_INVALID_SIZE: -// return OperatingSystemIF::INVALID_SIZE; -// case RTEMS_INVALID_ADDRESS: -// return OperatingSystemIF::INVALID_ADDRESS; -// case RTEMS_INVALID_NUMBER: -// return OperatingSystemIF::INVALID_NUMBER; -// case RTEMS_NOT_DEFINED: -// return OperatingSystemIF::NOT_DEFINED; -// case RTEMS_RESOURCE_IN_USE: -// return OperatingSystemIF::RESOURCE_IN_USE; -// //TODO RTEMS_UNSATISFIED is double mapped for FLP so it will only return Queue_empty and not unsatisfied -// case RTEMS_UNSATISFIED: -// return OperatingSystemIF::QUEUE_EMPTY; -// case RTEMS_INCORRECT_STATE: -// return OperatingSystemIF::INCORRECT_STATE; -// case RTEMS_ALREADY_SUSPENDED: -// return OperatingSystemIF::ALREADY_SUSPENDED; -// case RTEMS_ILLEGAL_ON_SELF: -// return OperatingSystemIF::ILLEGAL_ON_SELF; -// case RTEMS_ILLEGAL_ON_REMOTE_OBJECT: -// return OperatingSystemIF::ILLEGAL_ON_REMOTE_OBJECT; -// case RTEMS_CALLED_FROM_ISR: -// return OperatingSystemIF::CALLED_FROM_ISR; -// case RTEMS_INVALID_PRIORITY: -// return OperatingSystemIF::INVALID_PRIORITY; -// case RTEMS_INVALID_CLOCK: -// return OperatingSystemIF::INVALID_CLOCK; -// case RTEMS_INVALID_NODE: -// return OperatingSystemIF::INVALID_NODE; -// case RTEMS_NOT_CONFIGURED: -// return OperatingSystemIF::NOT_CONFIGURED; -// case RTEMS_NOT_OWNER_OF_RESOURCE: -// return OperatingSystemIF::NOT_OWNER_OF_RESOURCE; -// case RTEMS_NOT_IMPLEMENTED: -// return OperatingSystemIF::NOT_IMPLEMENTED; -// case RTEMS_INTERNAL_ERROR: -// return OperatingSystemIF::INTERNAL_ERROR; -// case RTEMS_NO_MEMORY: -// return OperatingSystemIF::NO_MEMORY; -// case RTEMS_IO_ERROR: -// return OperatingSystemIF::IO_ERROR; -// default: -// return HasReturnvaluesIF::RETURN_FAILED; -// } -// } -//} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..5a8f139ba --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,20 @@ +target_include_directories(${LIB_FSFW_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_include_directories(${LIB_FSFW_NAME} INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_subdirectory(fsfw) + +# Configure File + +target_include_directories(${LIB_FSFW_NAME} PRIVATE + ${CMAKE_CURRENT_BINARY_DIR} +) +target_include_directories(${LIB_FSFW_NAME} INTERFACE + ${CMAKE_CURRENT_BINARY_DIR} +) + +configure_file(fsfw/FSFW.h.in fsfw/FSFW.h) diff --git a/src/fsfw/CMakeLists.txt b/src/fsfw/CMakeLists.txt new file mode 100644 index 000000000..7c665e28a --- /dev/null +++ b/src/fsfw/CMakeLists.txt @@ -0,0 +1,55 @@ +# Core + +add_subdirectory(action) +add_subdirectory(container) +add_subdirectory(controller) +add_subdirectory(datapool) +add_subdirectory(datapoollocal) +add_subdirectory(devicehandlers) +add_subdirectory(events) +add_subdirectory(fdir) +add_subdirectory(globalfunctions) +add_subdirectory(health) +add_subdirectory(housekeeping) +add_subdirectory(internalerror) +add_subdirectory(ipc) +add_subdirectory(memory) +add_subdirectory(modes) +add_subdirectory(objectmanager) +add_subdirectory(parameters) +add_subdirectory(power) +add_subdirectory(serialize) +add_subdirectory(serviceinterface) +add_subdirectory(storagemanager) +add_subdirectory(subsystem) +add_subdirectory(tasks) +add_subdirectory(tcdistribution) +add_subdirectory(thermal) +add_subdirectory(timemanager) +add_subdirectory(tmtcpacket) +add_subdirectory(tmtcservices) + +# Optional + +if(FSFW_ADD_MONITORING) +add_subdirectory(monitoring) +endif() +if(FSFW_ADD_PUS) + add_subdirectory(pus) +endif() +if(FSFW_ADD_TMSTORAGE) + add_subdirectory(tmstorage) +endif() +if(FSFW_ADD_COORDINATES) + add_subdirectory(coordinates) +endif() +if(FSFW_ADD_RMAP) + add_subdirectory(rmap) +endif() +if(FSFW_ADD_DATALINKLAYER) + add_subdirectory(datalinklayer) +endif() + +# OSAL + +add_subdirectory(osal) diff --git a/src/fsfw/FSFW.h.in b/src/fsfw/FSFW.h.in new file mode 100644 index 000000000..ddc693730 --- /dev/null +++ b/src/fsfw/FSFW.h.in @@ -0,0 +1,36 @@ +#ifndef FSFW_FSFW_H_ +#define FSFW_FSFW_H_ + +#include "FSFWConfig.h" + +#cmakedefine FSFW_OSAL_RTEMS +#cmakedefine FSFW_OSAL_FREERTOS +#cmakedefine FSFW_OSAL_LINUX +#cmakedefine FSFW_OSAL_HOST + +#cmakedefine FSFW_ADD_RMAP +#cmakedefine FSFW_ADD_DATALINKLAYER +#cmakedefine FSFW_ADD_TMSTORAGE +#cmakedefine FSFW_ADD_COORDINATES +#cmakedefine FSFW_ADD_PUS +#cmakedefine FSFW_ADD_MONITORING +#cmakedefine FSFW_ADD_SGP4_PROPAGATOR + +// Can be used for low-level debugging of the SPI bus +#ifndef FSFW_HAL_SPI_WIRETAPPING +#define FSFW_HAL_SPI_WIRETAPPING 0 +#endif + +#ifndef FSFW_HAL_L3GD20_GYRO_DEBUG +#define FSFW_HAL_L3GD20_GYRO_DEBUG 0 +#endif /* FSFW_HAL_L3GD20_GYRO_DEBUG */ + +#ifndef FSFW_HAL_RM3100_MGM_DEBUG +#define FSFW_HAL_RM3100_MGM_DEBUG 0 +#endif /* FSFW_HAL_RM3100_MGM_DEBUG */ + +#ifndef FSFW_HAL_LIS3MDL_MGM_DEBUG +#define FSFW_HAL_LIS3MDL_MGM_DEBUG 0 +#endif /* FSFW_HAL_LIS3MDL_MGM_DEBUG */ + +#endif /* FSFW_FSFW_H_ */ diff --git a/src/fsfw/FSFWVersion.h b/src/fsfw/FSFWVersion.h new file mode 100644 index 000000000..c581a85cb --- /dev/null +++ b/src/fsfw/FSFWVersion.h @@ -0,0 +1,10 @@ +#ifndef FSFW_VERSION_H_ +#define FSFW_VERSION_H_ + +const char* const FSFW_VERSION_NAME = "ASTP"; + +#define FSFW_VERSION 2 +#define FSFW_SUBVERSION 0 +#define FSFW_REVISION 0 + +#endif /* FSFW_VERSION_H_ */ diff --git a/src/fsfw/action.h b/src/fsfw/action.h new file mode 100644 index 000000000..1300cf176 --- /dev/null +++ b/src/fsfw/action.h @@ -0,0 +1,11 @@ +#ifndef FSFW_INC_FSFW_ACTION_H_ +#define FSFW_INC_FSFW_ACTION_H_ + +#include "fsfw/action/ActionHelper.h" +#include "fsfw/action/ActionMessage.h" +#include "fsfw/action/CommandActionHelper.h" +#include "fsfw/action/HasActionsIF.h" +#include "fsfw/action/CommandsActionsIF.h" +#include "fsfw/action/SimpleActionHelper.h" + +#endif /* FSFW_INC_FSFW_ACTION_H_ */ diff --git a/action/ActionHelper.cpp b/src/fsfw/action/ActionHelper.cpp similarity index 91% rename from action/ActionHelper.cpp rename to src/fsfw/action/ActionHelper.cpp index 73007ea36..bebd55a79 100644 --- a/action/ActionHelper.cpp +++ b/src/fsfw/action/ActionHelper.cpp @@ -1,9 +1,8 @@ -#include "ActionHelper.h" -#include "HasActionsIF.h" +#include "fsfw/action.h" -#include "../ipc/MessageQueueSenderIF.h" -#include "../objectmanager/ObjectManager.h" -#include "../serviceinterface/ServiceInterface.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" ActionHelper::ActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue) : @@ -33,6 +32,17 @@ ReturnValue_t ActionHelper::initialize(MessageQueueIF* queueToUse_) { setQueueToUse(queueToUse_); } + if(queueToUse == nullptr) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "ActionHelper::initialize: No queue set" << std::endl; +#else + sif::printWarning("ActionHelper::initialize: No queue set\n"); +#endif +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + return HasReturnvaluesIF::RETURN_FAILED; + } + return HasReturnvaluesIF::RETURN_OK; } diff --git a/action/ActionHelper.h b/src/fsfw/action/ActionHelper.h similarity index 100% rename from action/ActionHelper.h rename to src/fsfw/action/ActionHelper.h diff --git a/action/ActionMessage.cpp b/src/fsfw/action/ActionMessage.cpp similarity index 93% rename from action/ActionMessage.cpp rename to src/fsfw/action/ActionMessage.cpp index f25858af9..7d66c57fc 100644 --- a/action/ActionMessage.cpp +++ b/src/fsfw/action/ActionMessage.cpp @@ -1,8 +1,7 @@ -#include "ActionMessage.h" -#include "HasActionsIF.h" +#include "fsfw/action.h" -#include "../objectmanager/ObjectManager.h" -#include "../storagemanager/StorageManagerIF.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/storagemanager/StorageManagerIF.h" ActionMessage::ActionMessage() { } diff --git a/action/ActionMessage.h b/src/fsfw/action/ActionMessage.h similarity index 92% rename from action/ActionMessage.h rename to src/fsfw/action/ActionMessage.h index 0c64588ca..c7570c9d9 100644 --- a/action/ActionMessage.h +++ b/src/fsfw/action/ActionMessage.h @@ -1,9 +1,9 @@ #ifndef FSFW_ACTION_ACTIONMESSAGE_H_ #define FSFW_ACTION_ACTIONMESSAGE_H_ -#include "../ipc/CommandMessage.h" -#include "../objectmanager/ObjectManagerIF.h" -#include "../storagemanager/StorageManagerIF.h" +#include "fsfw/ipc/CommandMessage.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/storagemanager/StorageManagerIF.h" using ActionId_t = uint32_t; diff --git a/action/CMakeLists.txt b/src/fsfw/action/CMakeLists.txt similarity index 100% rename from action/CMakeLists.txt rename to src/fsfw/action/CMakeLists.txt diff --git a/action/CommandActionHelper.cpp b/src/fsfw/action/CommandActionHelper.cpp similarity index 96% rename from action/CommandActionHelper.cpp rename to src/fsfw/action/CommandActionHelper.cpp index 31650cae9..b46dccebd 100644 --- a/action/CommandActionHelper.cpp +++ b/src/fsfw/action/CommandActionHelper.cpp @@ -1,9 +1,6 @@ -#include "ActionMessage.h" -#include "CommandActionHelper.h" -#include "CommandsActionsIF.h" -#include "HasActionsIF.h" +#include "fsfw/action.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/objectmanager/ObjectManager.h" CommandActionHelper::CommandActionHelper(CommandsActionsIF *setOwner) : owner(setOwner), queueToUse(NULL), ipcStore( diff --git a/action/CommandActionHelper.h b/src/fsfw/action/CommandActionHelper.h similarity index 82% rename from action/CommandActionHelper.h rename to src/fsfw/action/CommandActionHelper.h index 96ef1763a..ce297e663 100644 --- a/action/CommandActionHelper.h +++ b/src/fsfw/action/CommandActionHelper.h @@ -2,11 +2,11 @@ #define COMMANDACTIONHELPER_H_ #include "ActionMessage.h" -#include "../objectmanager/ObjectManagerIF.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../serialize/SerializeIF.h" -#include "../storagemanager/StorageManagerIF.h" -#include "../ipc/MessageQueueIF.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/serialize/SerializeIF.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/ipc/MessageQueueIF.h" class CommandsActionsIF; diff --git a/action/CommandsActionsIF.h b/src/fsfw/action/CommandsActionsIF.h similarity index 100% rename from action/CommandsActionsIF.h rename to src/fsfw/action/CommandsActionsIF.h diff --git a/action/HasActionsIF.h b/src/fsfw/action/HasActionsIF.h similarity index 100% rename from action/HasActionsIF.h rename to src/fsfw/action/HasActionsIF.h diff --git a/action/SimpleActionHelper.cpp b/src/fsfw/action/SimpleActionHelper.cpp similarity index 97% rename from action/SimpleActionHelper.cpp rename to src/fsfw/action/SimpleActionHelper.cpp index 8d34f40f2..7135ea624 100644 --- a/action/SimpleActionHelper.cpp +++ b/src/fsfw/action/SimpleActionHelper.cpp @@ -1,5 +1,4 @@ -#include "HasActionsIF.h" -#include "SimpleActionHelper.h" +#include "fsfw/action.h" SimpleActionHelper::SimpleActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue) : diff --git a/action/SimpleActionHelper.h b/src/fsfw/action/SimpleActionHelper.h similarity index 100% rename from action/SimpleActionHelper.h rename to src/fsfw/action/SimpleActionHelper.h diff --git a/container/ArrayList.h b/src/fsfw/container/ArrayList.h similarity index 100% rename from container/ArrayList.h rename to src/fsfw/container/ArrayList.h diff --git a/container/BinaryTree.h b/src/fsfw/container/BinaryTree.h similarity index 100% rename from container/BinaryTree.h rename to src/fsfw/container/BinaryTree.h diff --git a/container/CMakeLists.txt b/src/fsfw/container/CMakeLists.txt similarity index 100% rename from container/CMakeLists.txt rename to src/fsfw/container/CMakeLists.txt diff --git a/container/DynamicFIFO.h b/src/fsfw/container/DynamicFIFO.h similarity index 100% rename from container/DynamicFIFO.h rename to src/fsfw/container/DynamicFIFO.h diff --git a/container/FIFO.h b/src/fsfw/container/FIFO.h similarity index 100% rename from container/FIFO.h rename to src/fsfw/container/FIFO.h diff --git a/container/FIFOBase.h b/src/fsfw/container/FIFOBase.h similarity index 100% rename from container/FIFOBase.h rename to src/fsfw/container/FIFOBase.h diff --git a/container/FIFOBase.tpp b/src/fsfw/container/FIFOBase.tpp similarity index 100% rename from container/FIFOBase.tpp rename to src/fsfw/container/FIFOBase.tpp diff --git a/container/FixedArrayList.h b/src/fsfw/container/FixedArrayList.h similarity index 100% rename from container/FixedArrayList.h rename to src/fsfw/container/FixedArrayList.h diff --git a/container/FixedMap.h b/src/fsfw/container/FixedMap.h similarity index 100% rename from container/FixedMap.h rename to src/fsfw/container/FixedMap.h diff --git a/container/FixedOrderedMultimap.h b/src/fsfw/container/FixedOrderedMultimap.h similarity index 100% rename from container/FixedOrderedMultimap.h rename to src/fsfw/container/FixedOrderedMultimap.h diff --git a/container/FixedOrderedMultimap.tpp b/src/fsfw/container/FixedOrderedMultimap.tpp similarity index 100% rename from container/FixedOrderedMultimap.tpp rename to src/fsfw/container/FixedOrderedMultimap.tpp diff --git a/container/HybridIterator.h b/src/fsfw/container/HybridIterator.h similarity index 100% rename from container/HybridIterator.h rename to src/fsfw/container/HybridIterator.h diff --git a/container/IndexedRingMemoryArray.h b/src/fsfw/container/IndexedRingMemoryArray.h similarity index 100% rename from container/IndexedRingMemoryArray.h rename to src/fsfw/container/IndexedRingMemoryArray.h diff --git a/container/PlacementFactory.h b/src/fsfw/container/PlacementFactory.h similarity index 100% rename from container/PlacementFactory.h rename to src/fsfw/container/PlacementFactory.h diff --git a/container/RingBufferBase.h b/src/fsfw/container/RingBufferBase.h similarity index 100% rename from container/RingBufferBase.h rename to src/fsfw/container/RingBufferBase.h diff --git a/container/SharedRingBuffer.cpp b/src/fsfw/container/SharedRingBuffer.cpp similarity index 93% rename from container/SharedRingBuffer.cpp rename to src/fsfw/container/SharedRingBuffer.cpp index fe36341dd..f7c978028 100644 --- a/container/SharedRingBuffer.cpp +++ b/src/fsfw/container/SharedRingBuffer.cpp @@ -1,6 +1,6 @@ -#include "SharedRingBuffer.h" -#include "../ipc/MutexFactory.h" -#include "../ipc/MutexGuard.h" +#include "fsfw/container/SharedRingBuffer.h" +#include "fsfw/ipc/MutexFactory.h" +#include "fsfw/ipc/MutexGuard.h" SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size, bool overwriteOld, size_t maxExcessBytes): diff --git a/container/SharedRingBuffer.h b/src/fsfw/container/SharedRingBuffer.h similarity index 96% rename from container/SharedRingBuffer.h rename to src/fsfw/container/SharedRingBuffer.h index 9d6ea56c2..26aa45c14 100644 --- a/container/SharedRingBuffer.h +++ b/src/fsfw/container/SharedRingBuffer.h @@ -3,9 +3,10 @@ #include "SimpleRingBuffer.h" #include "DynamicFIFO.h" -#include "../ipc/MutexIF.h" -#include "../objectmanager/SystemObject.h" -#include "../timemanager/Clock.h" + +#include "fsfw/ipc/MutexIF.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/timemanager/Clock.h" /** * @brief Ring buffer which can be shared among multiple objects diff --git a/container/SimpleRingBuffer.cpp b/src/fsfw/container/SimpleRingBuffer.cpp similarity index 98% rename from container/SimpleRingBuffer.cpp rename to src/fsfw/container/SimpleRingBuffer.cpp index 8544acbf3..8de9cf08f 100644 --- a/container/SimpleRingBuffer.cpp +++ b/src/fsfw/container/SimpleRingBuffer.cpp @@ -1,4 +1,5 @@ -#include "SimpleRingBuffer.h" +#include "fsfw/container/SimpleRingBuffer.h" + #include SimpleRingBuffer::SimpleRingBuffer(const size_t size, bool overwriteOld, diff --git a/container/SimpleRingBuffer.h b/src/fsfw/container/SimpleRingBuffer.h similarity index 100% rename from container/SimpleRingBuffer.h rename to src/fsfw/container/SimpleRingBuffer.h diff --git a/container/SinglyLinkedList.h b/src/fsfw/container/SinglyLinkedList.h similarity index 100% rename from container/SinglyLinkedList.h rename to src/fsfw/container/SinglyLinkedList.h diff --git a/container/group.h b/src/fsfw/container/group.h similarity index 100% rename from container/group.h rename to src/fsfw/container/group.h diff --git a/controller/CMakeLists.txt b/src/fsfw/controller/CMakeLists.txt similarity index 100% rename from controller/CMakeLists.txt rename to src/fsfw/controller/CMakeLists.txt diff --git a/controller/ControllerBase.cpp b/src/fsfw/controller/ControllerBase.cpp similarity index 94% rename from controller/ControllerBase.cpp rename to src/fsfw/controller/ControllerBase.cpp index 5a94c0829..86838068e 100644 --- a/controller/ControllerBase.cpp +++ b/src/fsfw/controller/ControllerBase.cpp @@ -1,9 +1,9 @@ -#include "ControllerBase.h" +#include "fsfw/controller/ControllerBase.h" -#include "../subsystem/SubsystemBase.h" -#include "../ipc/QueueFactory.h" -#include "../action/HasActionsIF.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/subsystem/SubsystemBase.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/action/HasActionsIF.h" +#include "fsfw/objectmanager/ObjectManager.h" ControllerBase::ControllerBase(object_id_t setObjectId, object_id_t parentId, size_t commandQueueDepth) : diff --git a/controller/ControllerBase.h b/src/fsfw/controller/ControllerBase.h similarity index 89% rename from controller/ControllerBase.h rename to src/fsfw/controller/ControllerBase.h index f583342fe..1efe0cc1c 100644 --- a/controller/ControllerBase.h +++ b/src/fsfw/controller/ControllerBase.h @@ -1,14 +1,14 @@ #ifndef FSFW_CONTROLLER_CONTROLLERBASE_H_ #define FSFW_CONTROLLER_CONTROLLERBASE_H_ -#include "../health/HasHealthIF.h" -#include "../health/HealthHelper.h" -#include "../modes/HasModesIF.h" -#include "../modes/ModeHelper.h" -#include "../objectmanager/SystemObject.h" -#include "../tasks/ExecutableObjectIF.h" -#include "../tasks/PeriodicTaskIF.h" -#include "../datapool/HkSwitchHelper.h" +#include "fsfw/health/HasHealthIF.h" +#include "fsfw/health/HealthHelper.h" +#include "fsfw/modes/HasModesIF.h" +#include "fsfw/modes/ModeHelper.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/tasks/PeriodicTaskIF.h" +#include "fsfw/datapool/HkSwitchHelper.h" /** * @brief Generic base class for controller classes diff --git a/controller/ExtendedControllerBase.cpp b/src/fsfw/controller/ExtendedControllerBase.cpp similarity index 98% rename from controller/ExtendedControllerBase.cpp rename to src/fsfw/controller/ExtendedControllerBase.cpp index b5b8c6601..f59c50a91 100644 --- a/controller/ExtendedControllerBase.cpp +++ b/src/fsfw/controller/ExtendedControllerBase.cpp @@ -1,5 +1,4 @@ -#include "ExtendedControllerBase.h" - +#include "fsfw/controller/ExtendedControllerBase.h" ExtendedControllerBase::ExtendedControllerBase(object_id_t objectId, object_id_t parentId, size_t commandQueueDepth): diff --git a/controller/ExtendedControllerBase.h b/src/fsfw/controller/ExtendedControllerBase.h similarity index 93% rename from controller/ExtendedControllerBase.h rename to src/fsfw/controller/ExtendedControllerBase.h index 63c350e27..4172e03e8 100644 --- a/controller/ExtendedControllerBase.h +++ b/src/fsfw/controller/ExtendedControllerBase.h @@ -3,10 +3,9 @@ #include "ControllerBase.h" -#include "../action/HasActionsIF.h" -#include "../datapoollocal/HasLocalDataPoolIF.h" -#include "../action/ActionHelper.h" -#include "../datapoollocal/LocalDataPoolManager.h" +#include "fsfw/action.h" +#include "fsfw/datapoollocal/HasLocalDataPoolIF.h" +#include "fsfw/datapoollocal/LocalDataPoolManager.h" /** * @brief Extendes the basic ControllerBase with the common components diff --git a/coordinates/CMakeLists.txt b/src/fsfw/coordinates/CMakeLists.txt similarity index 100% rename from coordinates/CMakeLists.txt rename to src/fsfw/coordinates/CMakeLists.txt diff --git a/coordinates/CoordinateTransformations.cpp b/src/fsfw/coordinates/CoordinateTransformations.cpp similarity index 94% rename from coordinates/CoordinateTransformations.cpp rename to src/fsfw/coordinates/CoordinateTransformations.cpp index 4e2debbe8..fe879dd1a 100644 --- a/coordinates/CoordinateTransformations.cpp +++ b/src/fsfw/coordinates/CoordinateTransformations.cpp @@ -1,8 +1,9 @@ -#include "CoordinateTransformations.h" -#include "../globalfunctions/constants.h" -#include "../globalfunctions/math/MatrixOperations.h" -#include "../globalfunctions/math/VectorOperations.h" -#include +#include "fsfw/coordinates/CoordinateTransformations.h" +#include "fsfw/globalfunctions/constants.h" +#include "fsfw/globalfunctions/math/MatrixOperations.h" +#include "fsfw/globalfunctions/math/VectorOperations.h" + +#include #include @@ -17,11 +18,13 @@ void CoordinateTransformations::velocityEcfToEci(const double* ecfVelocity, ecfToEci(ecfVelocity, eciVelocity, ecfPosition, timeUTC); } -void CoordinateTransformations::positionEciToEcf(const double* eciCoordinates, double* ecfCoordinates,timeval *timeUTC){ +void CoordinateTransformations::positionEciToEcf(const double* eciCoordinates, + double* ecfCoordinates,timeval *timeUTC){ eciToEcf(eciCoordinates,ecfCoordinates,NULL,timeUTC); }; -void CoordinateTransformations::velocityEciToEcf(const double* eciVelocity,const double* eciPosition, double* ecfVelocity,timeval* timeUTC){ +void CoordinateTransformations::velocityEciToEcf(const double* eciVelocity, + const double* eciPosition, double* ecfVelocity,timeval* timeUTC){ eciToEcf(eciVelocity,ecfVelocity,eciPosition,timeUTC); } diff --git a/coordinates/CoordinateTransformations.h b/src/fsfw/coordinates/CoordinateTransformations.h similarity index 95% rename from coordinates/CoordinateTransformations.h rename to src/fsfw/coordinates/CoordinateTransformations.h index 09ea2c48c..ddc715d18 100644 --- a/coordinates/CoordinateTransformations.h +++ b/src/fsfw/coordinates/CoordinateTransformations.h @@ -1,7 +1,8 @@ #ifndef COORDINATETRANSFORMATIONS_H_ #define COORDINATETRANSFORMATIONS_H_ -#include "../timemanager/Clock.h" +#include "coordinatesConf.h" +#include "fsfw/timemanager/Clock.h" #include class CoordinateTransformations { diff --git a/coordinates/Jgm3Model.h b/src/fsfw/coordinates/Jgm3Model.h similarity index 96% rename from coordinates/Jgm3Model.h rename to src/fsfw/coordinates/Jgm3Model.h index 884ed1418..0eeaf08f4 100644 --- a/coordinates/Jgm3Model.h +++ b/src/fsfw/coordinates/Jgm3Model.h @@ -1,13 +1,14 @@ #ifndef FRAMEWORK_COORDINATES_JGM3MODEL_H_ #define FRAMEWORK_COORDINATES_JGM3MODEL_H_ -#include +#include "coordinatesConf.h" #include "CoordinateTransformations.h" -#include "../globalfunctions/math/VectorOperations.h" -#include "../globalfunctions/timevalOperations.h" -#include "../globalfunctions/constants.h" -#include +#include "fsfw/globalfunctions/math/VectorOperations.h" +#include "fsfw/globalfunctions/timevalOperations.h" +#include "fsfw/globalfunctions/constants.h" +#include +#include template class Jgm3Model { diff --git a/coordinates/Sgp4Propagator.cpp b/src/fsfw/coordinates/Sgp4Propagator.cpp similarity index 95% rename from coordinates/Sgp4Propagator.cpp rename to src/fsfw/coordinates/Sgp4Propagator.cpp index 5cb1497cf..a0e66ebd1 100644 --- a/coordinates/Sgp4Propagator.cpp +++ b/src/fsfw/coordinates/Sgp4Propagator.cpp @@ -1,10 +1,13 @@ -#include "CoordinateTransformations.h" -#include "Sgp4Propagator.h" -#include "../globalfunctions/constants.h" -#include "../globalfunctions/math/MatrixOperations.h" -#include "../globalfunctions/math/VectorOperations.h" -#include "../globalfunctions/timevalOperations.h" +#include "fsfw/coordinates/CoordinateTransformations.h" +#include "fsfw/coordinates/Sgp4Propagator.h" + +#include "fsfw/globalfunctions/constants.h" +#include "fsfw/globalfunctions/math/MatrixOperations.h" +#include "fsfw/globalfunctions/math/VectorOperations.h" +#include "fsfw/globalfunctions/timevalOperations.h" + #include + Sgp4Propagator::Sgp4Propagator() : initialized(false), epoch({0, 0}), whichconst(wgs84) { diff --git a/coordinates/Sgp4Propagator.h b/src/fsfw/coordinates/Sgp4Propagator.h similarity index 88% rename from coordinates/Sgp4Propagator.h rename to src/fsfw/coordinates/Sgp4Propagator.h index f813c6f4d..7c7a0a8c9 100644 --- a/coordinates/Sgp4Propagator.h +++ b/src/fsfw/coordinates/Sgp4Propagator.h @@ -1,11 +1,14 @@ #ifndef SGP4PROPAGATOR_H_ #define SGP4PROPAGATOR_H_ -#ifndef WIN32 +#include "coordinatesConf.h" +#include "fsfw/platform.h" + +#ifndef PLATFORM_WIN #include #endif -#include "../contrib/sgp4/sgp4unit.h" -#include "../returnvalues/HasReturnvaluesIF.h" +#include "fsfw_contrib/sgp4/sgp4unit.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" class Sgp4Propagator { public: diff --git a/src/fsfw/coordinates/coordinatesConf.h b/src/fsfw/coordinates/coordinatesConf.h new file mode 100644 index 000000000..9c1c37549 --- /dev/null +++ b/src/fsfw/coordinates/coordinatesConf.h @@ -0,0 +1,16 @@ +#ifndef FSFW_SRC_FSFW_COORDINATES_COORDINATESCONF_H_ +#define FSFW_SRC_FSFW_COORDINATES_COORDINATESCONF_H_ + +#include "fsfw/FSFW.h" + +#ifndef FSFW_ADD_COORDINATES +#warning Coordinates files were included but compilation was \ + not enabled with FSFW_ADD_COORDINATES +#endif + +#ifndef FSFW_ADD_SGP4_PROPAGATOR +#warning Coordinates files were included but SGP4 contributed code compilation was \ + not enabled with FSFW_ADD_SGP4_PROPAGATOR +#endif + +#endif /* FSFW_SRC_FSFW_COORDINATES_COORDINATESCONF_H_ */ diff --git a/datalinklayer/BCFrame.h b/src/fsfw/datalinklayer/BCFrame.h similarity index 98% rename from datalinklayer/BCFrame.h rename to src/fsfw/datalinklayer/BCFrame.h index b7795556d..9cedd41b2 100644 --- a/datalinklayer/BCFrame.h +++ b/src/fsfw/datalinklayer/BCFrame.h @@ -8,6 +8,7 @@ #ifndef BCFRAME_H_ #define BCFRAME_H_ +#include "dllConf.h" #include "CCSDSReturnValuesIF.h" /** diff --git a/datalinklayer/CCSDSReturnValuesIF.h b/src/fsfw/datalinklayer/CCSDSReturnValuesIF.h similarity index 98% rename from datalinklayer/CCSDSReturnValuesIF.h rename to src/fsfw/datalinklayer/CCSDSReturnValuesIF.h index 805b6969f..a31f9ced1 100644 --- a/datalinklayer/CCSDSReturnValuesIF.h +++ b/src/fsfw/datalinklayer/CCSDSReturnValuesIF.h @@ -8,7 +8,8 @@ #ifndef CCSDSRETURNVALUESIF_H_ #define CCSDSRETURNVALUESIF_H_ -#include "../returnvalues/HasReturnvaluesIF.h" +#include "dllConf.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" /** * This is a helper class to collect special return values that come up during CCSDS Handling. * @ingroup ccsds_handling diff --git a/datalinklayer/CMakeLists.txt b/src/fsfw/datalinklayer/CMakeLists.txt similarity index 100% rename from datalinklayer/CMakeLists.txt rename to src/fsfw/datalinklayer/CMakeLists.txt diff --git a/datalinklayer/Clcw.cpp b/src/fsfw/datalinklayer/Clcw.cpp similarity index 88% rename from datalinklayer/Clcw.cpp rename to src/fsfw/datalinklayer/Clcw.cpp index 13971929c..9f2fe7d30 100644 --- a/datalinklayer/Clcw.cpp +++ b/src/fsfw/datalinklayer/Clcw.cpp @@ -1,14 +1,5 @@ -/** - * @file Clcw.cpp - * @brief This file defines the Clcw class. - * @date 17.04.2013 - * @author baetz - */ - - - -#include "Clcw.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/datalinklayer/Clcw.h" +#include "fsfw/serviceinterface/ServiceInterface.h" Clcw::Clcw() { content.raw = 0; diff --git a/datalinklayer/Clcw.h b/src/fsfw/datalinklayer/Clcw.h similarity index 95% rename from datalinklayer/Clcw.h rename to src/fsfw/datalinklayer/Clcw.h index 8116d63b6..aa1ee35bb 100644 --- a/datalinklayer/Clcw.h +++ b/src/fsfw/datalinklayer/Clcw.h @@ -1,14 +1,9 @@ -/** - * @file Clcw.h - * @brief This file defines the Clcw class. - * @date 17.04.2013 - * @author baetz - */ - #ifndef CLCW_H_ #define CLCW_H_ +#include "dllConf.h" #include "ClcwIF.h" + /** * Small helper method to handle the Clcw values. * It has a content struct that manages the register and can be set externally. diff --git a/datalinklayer/ClcwIF.h b/src/fsfw/datalinklayer/ClcwIF.h similarity index 100% rename from datalinklayer/ClcwIF.h rename to src/fsfw/datalinklayer/ClcwIF.h diff --git a/datalinklayer/DataLinkLayer.cpp b/src/fsfw/datalinklayer/DataLinkLayer.cpp similarity index 97% rename from datalinklayer/DataLinkLayer.cpp rename to src/fsfw/datalinklayer/DataLinkLayer.cpp index 1bdaa4f5f..94199bc41 100644 --- a/datalinklayer/DataLinkLayer.cpp +++ b/src/fsfw/datalinklayer/DataLinkLayer.cpp @@ -1,6 +1,6 @@ -#include "DataLinkLayer.h" -#include "../globalfunctions/CRC.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/datalinklayer/DataLinkLayer.h" +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/serviceinterface/ServiceInterface.h" DataLinkLayer::DataLinkLayer(uint8_t* set_frame_buffer, ClcwIF* setClcw, uint8_t set_start_sequence_length, uint16_t set_scid) : diff --git a/datalinklayer/DataLinkLayer.h b/src/fsfw/datalinklayer/DataLinkLayer.h similarity index 90% rename from datalinklayer/DataLinkLayer.h rename to src/fsfw/datalinklayer/DataLinkLayer.h index 27e690066..9c2a2952b 100644 --- a/datalinklayer/DataLinkLayer.h +++ b/src/fsfw/datalinklayer/DataLinkLayer.h @@ -1,11 +1,13 @@ #ifndef DATALINKLAYER_H_ #define DATALINKLAYER_H_ +#include "dllConf.h" #include "CCSDSReturnValuesIF.h" #include "ClcwIF.h" #include "TcTransferFrame.h" #include "VirtualChannelReceptionIF.h" -#include "../events/Event.h" +#include "fsfw/events/Event.h" + #include @@ -21,11 +23,16 @@ public: static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SYSTEM_1; //! [EXPORT] : [COMMENT] A RF available signal was detected. P1: raw RFA state, P2: 0 static const Event RF_AVAILABLE = MAKE_EVENT(0, severity::INFO); - static const Event RF_LOST = MAKE_EVENT(1, severity::INFO); //!< A previously found RF available signal was lost. P1: raw RFA state, P2: 0 - static const Event BIT_LOCK = MAKE_EVENT(2, severity::INFO); //!< A Bit Lock signal. Was detected. P1: raw BLO state, P2: 0 - static const Event BIT_LOCK_LOST = MAKE_EVENT(3, severity::INFO); //!< A previously found Bit Lock signal was lost. P1: raw BLO state, P2: 0 + //! [EXPORT] : [COMMENT] A previously found RF available signal was lost. + //! P1: raw RFA state, P2: 0 + static const Event RF_LOST = MAKE_EVENT(1, severity::INFO); + //! [EXPORT] : [COMMENT] A Bit Lock signal. Was detected. P1: raw BLO state, P2: 0 + static const Event BIT_LOCK = MAKE_EVENT(2, severity::INFO); + //! [EXPORT] : [COMMENT] A previously found Bit Lock signal was lost. P1: raw BLO state, P2: 0 + static const Event BIT_LOCK_LOST = MAKE_EVENT(3, severity::INFO); // static const Event RF_CHAIN_LOST = MAKE_EVENT(4, severity::INFO); //!< The CCSDS Board detected that either bit lock or RF available or both are lost. No parameters. - static const Event FRAME_PROCESSING_FAILED = MAKE_EVENT(5, severity::LOW); //!< The CCSDS Board could not interpret a TC + //! [EXPORT] : [COMMENT] The CCSDS Board could not interpret a TC + static const Event FRAME_PROCESSING_FAILED = MAKE_EVENT(5, severity::LOW); /** * The Constructor sets the passed parameters and nothing else. * @param set_frame_buffer The buffer in which incoming frame candidates are stored. diff --git a/datalinklayer/Farm1StateIF.h b/src/fsfw/datalinklayer/Farm1StateIF.h similarity index 98% rename from datalinklayer/Farm1StateIF.h rename to src/fsfw/datalinklayer/Farm1StateIF.h index 71794d75e..7e1ba2ec5 100644 --- a/datalinklayer/Farm1StateIF.h +++ b/src/fsfw/datalinklayer/Farm1StateIF.h @@ -8,7 +8,9 @@ #ifndef FARM1STATEIF_H_ #define FARM1STATEIF_H_ +#include "dllConf.h" #include "CCSDSReturnValuesIF.h" + class VirtualChannelReception; class TcTransferFrame; class ClcwIF; diff --git a/datalinklayer/Farm1StateLockout.cpp b/src/fsfw/datalinklayer/Farm1StateLockout.cpp similarity index 70% rename from datalinklayer/Farm1StateLockout.cpp rename to src/fsfw/datalinklayer/Farm1StateLockout.cpp index 1b339a85f..b74d0a5f6 100644 --- a/datalinklayer/Farm1StateLockout.cpp +++ b/src/fsfw/datalinklayer/Farm1StateLockout.cpp @@ -1,16 +1,8 @@ -/** - * @file Farm1StateLockout.cpp - * @brief This file defines the Farm1StateLockout class. - * @date 24.04.2013 - * @author baetz - */ +#include "fsfw/datalinklayer/ClcwIF.h" +#include "fsfw/datalinklayer/Farm1StateLockout.h" +#include "fsfw/datalinklayer/TcTransferFrame.h" +#include "fsfw/datalinklayer/VirtualChannelReception.h" - - -#include "ClcwIF.h" -#include "Farm1StateLockout.h" -#include "TcTransferFrame.h" -#include "VirtualChannelReception.h" Farm1StateLockout::Farm1StateLockout(VirtualChannelReception* setMyVC) : myVC(setMyVC) { } diff --git a/datalinklayer/Farm1StateLockout.h b/src/fsfw/datalinklayer/Farm1StateLockout.h similarity index 93% rename from datalinklayer/Farm1StateLockout.h rename to src/fsfw/datalinklayer/Farm1StateLockout.h index 63cdc4d2b..a039c89b6 100644 --- a/datalinklayer/Farm1StateLockout.h +++ b/src/fsfw/datalinklayer/Farm1StateLockout.h @@ -1,13 +1,7 @@ -/** - * @file Farm1StateLockout.h - * @brief This file defines the Farm1StateLockout class. - * @date 24.04.2013 - * @author baetz - */ - #ifndef FARM1STATELOCKOUT_H_ #define FARM1STATELOCKOUT_H_ +#include "dllConf.h" #include "Farm1StateIF.h" /** diff --git a/datalinklayer/Farm1StateOpen.cpp b/src/fsfw/datalinklayer/Farm1StateOpen.cpp similarity index 79% rename from datalinklayer/Farm1StateOpen.cpp rename to src/fsfw/datalinklayer/Farm1StateOpen.cpp index 61c0997f9..6f91df47e 100644 --- a/datalinklayer/Farm1StateOpen.cpp +++ b/src/fsfw/datalinklayer/Farm1StateOpen.cpp @@ -1,17 +1,7 @@ -/** - * @file Farm1StateOpen.cpp - * @brief This file defines the Farm1StateOpen class. - * @date 24.04.2013 - * @author baetz - */ - - - - -#include "ClcwIF.h" -#include "Farm1StateOpen.h" -#include "TcTransferFrame.h" -#include "VirtualChannelReception.h" +#include "fsfw/datalinklayer/ClcwIF.h" +#include "fsfw/datalinklayer/Farm1StateOpen.h" +#include "fsfw/datalinklayer/TcTransferFrame.h" +#include "fsfw/datalinklayer/VirtualChannelReception.h" Farm1StateOpen::Farm1StateOpen(VirtualChannelReception* setMyVC) : myVC(setMyVC) { } diff --git a/datalinklayer/Farm1StateOpen.h b/src/fsfw/datalinklayer/Farm1StateOpen.h similarity index 99% rename from datalinklayer/Farm1StateOpen.h rename to src/fsfw/datalinklayer/Farm1StateOpen.h index 3b3a26048..c5506e7a7 100644 --- a/datalinklayer/Farm1StateOpen.h +++ b/src/fsfw/datalinklayer/Farm1StateOpen.h @@ -8,6 +8,7 @@ #ifndef FARM1STATEOPEN_H_ #define FARM1STATEOPEN_H_ +#include "dllConf.h" #include "Farm1StateIF.h" /** diff --git a/datalinklayer/Farm1StateWait.cpp b/src/fsfw/datalinklayer/Farm1StateWait.cpp similarity index 78% rename from datalinklayer/Farm1StateWait.cpp rename to src/fsfw/datalinklayer/Farm1StateWait.cpp index 9001e1f5f..8d3f97fc8 100644 --- a/datalinklayer/Farm1StateWait.cpp +++ b/src/fsfw/datalinklayer/Farm1StateWait.cpp @@ -1,15 +1,7 @@ -/** - * @file Farm1StateWait.cpp - * @brief This file defines the Farm1StateWait class. - * @date 24.04.2013 - * @author baetz - */ - - -#include "ClcwIF.h" -#include "Farm1StateWait.h" -#include "TcTransferFrame.h" -#include "VirtualChannelReception.h" +#include "fsfw/datalinklayer/ClcwIF.h" +#include "fsfw/datalinklayer/Farm1StateWait.h" +#include "fsfw/datalinklayer/TcTransferFrame.h" +#include "fsfw/datalinklayer/VirtualChannelReception.h" Farm1StateWait::Farm1StateWait(VirtualChannelReception* setMyVC) : myVC(setMyVC) { } diff --git a/datalinklayer/Farm1StateWait.h b/src/fsfw/datalinklayer/Farm1StateWait.h similarity index 98% rename from datalinklayer/Farm1StateWait.h rename to src/fsfw/datalinklayer/Farm1StateWait.h index 877c36c26..76704fdb3 100644 --- a/datalinklayer/Farm1StateWait.h +++ b/src/fsfw/datalinklayer/Farm1StateWait.h @@ -8,6 +8,7 @@ #ifndef FARM1STATEWAIT_H_ #define FARM1STATEWAIT_H_ +#include "dllConf.h" #include "Farm1StateIF.h" /** diff --git a/datalinklayer/MapPacketExtraction.cpp b/src/fsfw/datalinklayer/MapPacketExtraction.cpp similarity index 92% rename from datalinklayer/MapPacketExtraction.cpp rename to src/fsfw/datalinklayer/MapPacketExtraction.cpp index d377ca34d..7d06695ae 100644 --- a/datalinklayer/MapPacketExtraction.cpp +++ b/src/fsfw/datalinklayer/MapPacketExtraction.cpp @@ -1,12 +1,12 @@ -#include "MapPacketExtraction.h" +#include "fsfw/datalinklayer/MapPacketExtraction.h" -#include "../ipc/QueueFactory.h" -#include "../serviceinterface/ServiceInterfaceStream.h" -#include "../storagemanager/StorageManagerIF.h" -#include "../tmtcpacket/SpacePacketBase.h" -#include "../tmtcservices/AcceptsTelecommandsIF.h" -#include "../tmtcservices/TmTcMessage.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" +#include "fsfw/tmtcservices/TmTcMessage.h" +#include "fsfw/objectmanager/ObjectManager.h" #include diff --git a/datalinklayer/MapPacketExtraction.h b/src/fsfw/datalinklayer/MapPacketExtraction.h similarity index 94% rename from datalinklayer/MapPacketExtraction.h rename to src/fsfw/datalinklayer/MapPacketExtraction.h index ddb867fb2..30552a8e3 100644 --- a/datalinklayer/MapPacketExtraction.h +++ b/src/fsfw/datalinklayer/MapPacketExtraction.h @@ -1,10 +1,11 @@ #ifndef FSFW_DATALINKLAYER_MAPPACKETEXTRACTION_H_ #define FSFW_DATALINKLAYER_MAPPACKETEXTRACTION_H_ +#include "dllConf.h" #include "MapPacketExtractionIF.h" -#include "../objectmanager/ObjectManagerIF.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../ipc/MessageQueueSenderIF.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" class StorageManagerIF; diff --git a/datalinklayer/MapPacketExtractionIF.h b/src/fsfw/datalinklayer/MapPacketExtractionIF.h similarity index 98% rename from datalinklayer/MapPacketExtractionIF.h rename to src/fsfw/datalinklayer/MapPacketExtractionIF.h index e29ac6660..7f8a60afa 100644 --- a/datalinklayer/MapPacketExtractionIF.h +++ b/src/fsfw/datalinklayer/MapPacketExtractionIF.h @@ -8,6 +8,7 @@ #ifndef MAPPACKETEXTRACTIONIF_H_ #define MAPPACKETEXTRACTIONIF_H_ +#include "dllConf.h" #include "CCSDSReturnValuesIF.h" #include "TcTransferFrame.h" diff --git a/datalinklayer/TcTransferFrame.cpp b/src/fsfw/datalinklayer/TcTransferFrame.cpp similarity index 92% rename from datalinklayer/TcTransferFrame.cpp rename to src/fsfw/datalinklayer/TcTransferFrame.cpp index ee094dc32..42ccf7cac 100644 --- a/datalinklayer/TcTransferFrame.cpp +++ b/src/fsfw/datalinklayer/TcTransferFrame.cpp @@ -1,17 +1,8 @@ -/** - * @file TcTransferFrame.cpp - * @brief This file defines the TcTransferFrame class. - * @date 27.04.2013 - * @author baetz - */ - - - -#include "TcTransferFrame.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/datalinklayer/TcTransferFrame.h" +#include "fsfw/serviceinterface/ServiceInterface.h" TcTransferFrame::TcTransferFrame() { - frame = NULL; + frame = nullptr; } TcTransferFrame::TcTransferFrame(uint8_t* setData) { diff --git a/datalinklayer/TcTransferFrame.h b/src/fsfw/datalinklayer/TcTransferFrame.h similarity index 98% rename from datalinklayer/TcTransferFrame.h rename to src/fsfw/datalinklayer/TcTransferFrame.h index b58441fcc..9d4f6349b 100644 --- a/datalinklayer/TcTransferFrame.h +++ b/src/fsfw/datalinklayer/TcTransferFrame.h @@ -1,8 +1,10 @@ #ifndef TCTRANSFERFRAME_H_ #define TCTRANSFERFRAME_H_ -#include -#include +#include "dllConf.h" + +#include +#include /** * The TcTransferFrame class simplifies handling of such Frames. diff --git a/datalinklayer/TcTransferFrameLocal.cpp b/src/fsfw/datalinklayer/TcTransferFrameLocal.cpp similarity index 83% rename from datalinklayer/TcTransferFrameLocal.cpp rename to src/fsfw/datalinklayer/TcTransferFrameLocal.cpp index de8f568f4..f88f79e23 100644 --- a/datalinklayer/TcTransferFrameLocal.cpp +++ b/src/fsfw/datalinklayer/TcTransferFrameLocal.cpp @@ -1,14 +1,8 @@ -/** - * @file TcTransferFrameLocal.cpp - * @brief This file defines the TcTransferFrameLocal class. - * @date 27.04.2013 - * @author baetz - */ +#include "fsfw/datalinklayer/TcTransferFrameLocal.h" +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/serviceinterface/ServiceInterface.h" -#include "TcTransferFrameLocal.h" -#include "../globalfunctions/CRC.h" -#include "../serviceinterface/ServiceInterfaceStream.h" -#include +#include TcTransferFrameLocal::TcTransferFrameLocal(bool bypass, bool controlCommand, uint16_t scid, uint8_t vcId, uint8_t sequenceNumber, uint8_t setSegmentHeader, uint8_t* data, uint16_t dataSize, uint16_t forceCrc) { @@ -38,7 +32,7 @@ TcTransferFrameLocal::TcTransferFrameLocal(bool bypass, bool controlCommand, uin this->getFullFrame()[getFullSize()-1] = (crc & 0x00FF); } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "TcTransferFrameLocal: dataSize too large: " << dataSize << std::endl; + sif::warning << "TcTransferFrameLocal: dataSize too large: " << dataSize << std::endl; #endif } } else { diff --git a/datalinklayer/TcTransferFrameLocal.h b/src/fsfw/datalinklayer/TcTransferFrameLocal.h similarity index 98% rename from datalinklayer/TcTransferFrameLocal.h rename to src/fsfw/datalinklayer/TcTransferFrameLocal.h index 487d8940b..f2bf32755 100644 --- a/datalinklayer/TcTransferFrameLocal.h +++ b/src/fsfw/datalinklayer/TcTransferFrameLocal.h @@ -8,6 +8,7 @@ #ifndef TCTRANSFERFRAMELOCAL_H_ #define TCTRANSFERFRAMELOCAL_H_ +#include "dllConf.h" #include "TcTransferFrame.h" /** diff --git a/datalinklayer/VirtualChannelReception.cpp b/src/fsfw/datalinklayer/VirtualChannelReception.cpp similarity index 96% rename from datalinklayer/VirtualChannelReception.cpp rename to src/fsfw/datalinklayer/VirtualChannelReception.cpp index 3a56fe1e2..e0a88e8e8 100644 --- a/datalinklayer/VirtualChannelReception.cpp +++ b/src/fsfw/datalinklayer/VirtualChannelReception.cpp @@ -5,9 +5,9 @@ * @author baetz */ -#include "BCFrame.h" -#include "VirtualChannelReception.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/datalinklayer/BCFrame.h" +#include "fsfw/datalinklayer/VirtualChannelReception.h" +#include "fsfw/serviceinterface/ServiceInterface.h" VirtualChannelReception::VirtualChannelReception(uint8_t setChannelId, uint8_t setSlidingWindowWidth) : diff --git a/datalinklayer/VirtualChannelReception.h b/src/fsfw/datalinklayer/VirtualChannelReception.h similarity index 99% rename from datalinklayer/VirtualChannelReception.h rename to src/fsfw/datalinklayer/VirtualChannelReception.h index 9b4e2987e..314e18ece 100644 --- a/datalinklayer/VirtualChannelReception.h +++ b/src/fsfw/datalinklayer/VirtualChannelReception.h @@ -8,6 +8,7 @@ #ifndef VIRTUALCHANNELRECEPTION_H_ #define VIRTUALCHANNELRECEPTION_H_ +#include "dllConf.h" #include "CCSDSReturnValuesIF.h" #include "Clcw.h" #include "Farm1StateIF.h" @@ -16,6 +17,7 @@ #include "Farm1StateWait.h" #include "MapPacketExtractionIF.h" #include "VirtualChannelReceptionIF.h" + #include /** * Implementation of a TC Virtual Channel. diff --git a/datalinklayer/VirtualChannelReceptionIF.h b/src/fsfw/datalinklayer/VirtualChannelReceptionIF.h similarity index 95% rename from datalinklayer/VirtualChannelReceptionIF.h rename to src/fsfw/datalinklayer/VirtualChannelReceptionIF.h index 36f60e8c4..e7a21b3c4 100644 --- a/datalinklayer/VirtualChannelReceptionIF.h +++ b/src/fsfw/datalinklayer/VirtualChannelReceptionIF.h @@ -8,9 +8,10 @@ #ifndef VIRTUALCHANNELRECEPTIONIF_H_ #define VIRTUALCHANNELRECEPTIONIF_H_ +#include "dllConf.h" #include "ClcwIF.h" #include "TcTransferFrame.h" -#include "../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" /** * This is the interface for Virtual Channel reception classes. diff --git a/src/fsfw/datalinklayer/dllConf.h b/src/fsfw/datalinklayer/dllConf.h new file mode 100644 index 000000000..dce63ff04 --- /dev/null +++ b/src/fsfw/datalinklayer/dllConf.h @@ -0,0 +1,11 @@ +#ifndef FSFW_SRC_FSFW_DATALINKLAYER_DLLCONF_H_ +#define FSFW_SRC_FSFW_DATALINKLAYER_DLLCONF_H_ + +#include "fsfw/FSFW.h" + +#ifndef FSFW_ADD_DATALINKLAYER +#warning Datalinklayer files were included but compilation was \ + not enabled with FSFW_ADD_DATALINKLAYER +#endif + +#endif /* FSFW_SRC_FSFW_DATALINKLAYER_DLLCONF_H_ */ diff --git a/datapool/CMakeLists.txt b/src/fsfw/datapool/CMakeLists.txt similarity index 100% rename from datapool/CMakeLists.txt rename to src/fsfw/datapool/CMakeLists.txt diff --git a/datapool/DataSetIF.h b/src/fsfw/datapool/DataSetIF.h similarity index 100% rename from datapool/DataSetIF.h rename to src/fsfw/datapool/DataSetIF.h diff --git a/datapool/HkSwitchHelper.cpp b/src/fsfw/datapool/HkSwitchHelper.cpp similarity index 96% rename from datapool/HkSwitchHelper.cpp rename to src/fsfw/datapool/HkSwitchHelper.cpp index 21e37f59d..bcf237ba1 100644 --- a/datapool/HkSwitchHelper.cpp +++ b/src/fsfw/datapool/HkSwitchHelper.cpp @@ -1,5 +1,5 @@ -#include "../datapool/HkSwitchHelper.h" -#include "../ipc/QueueFactory.h" +#include "fsfw/datapool/HkSwitchHelper.h" +#include "fsfw/ipc/QueueFactory.h" HkSwitchHelper::HkSwitchHelper(EventReportingProxyIF* eventProxy) : commandActionHelper(this), eventProxy(eventProxy) { diff --git a/datapool/HkSwitchHelper.h b/src/fsfw/datapool/HkSwitchHelper.h similarity index 91% rename from datapool/HkSwitchHelper.h rename to src/fsfw/datapool/HkSwitchHelper.h index bb9e7dc68..611c5d86f 100644 --- a/datapool/HkSwitchHelper.h +++ b/src/fsfw/datapool/HkSwitchHelper.h @@ -1,9 +1,9 @@ #ifndef FRAMEWORK_DATAPOOL_HKSWITCHHELPER_H_ #define FRAMEWORK_DATAPOOL_HKSWITCHHELPER_H_ -#include "../tasks/ExecutableObjectIF.h" -#include "../action/CommandsActionsIF.h" -#include "../events/EventReportingProxyIF.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/action/CommandsActionsIF.h" +#include "fsfw/events/EventReportingProxyIF.h" //TODO this class violations separation between mission and framework //but it is only a transitional solution until the Datapool is diff --git a/datapool/PoolDataSetBase.cpp b/src/fsfw/datapool/PoolDataSetBase.cpp similarity index 98% rename from datapool/PoolDataSetBase.cpp rename to src/fsfw/datapool/PoolDataSetBase.cpp index 1bd586986..7856dc9a5 100644 --- a/datapool/PoolDataSetBase.cpp +++ b/src/fsfw/datapool/PoolDataSetBase.cpp @@ -1,7 +1,7 @@ -#include "PoolDataSetBase.h" -#include "ReadCommitIFAttorney.h" +#include "fsfw/datapool/PoolDataSetBase.h" +#include "fsfw/datapool/ReadCommitIFAttorney.h" -#include "../serviceinterface/ServiceInterface.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include diff --git a/datapool/PoolDataSetBase.h b/src/fsfw/datapool/PoolDataSetBase.h similarity index 99% rename from datapool/PoolDataSetBase.h rename to src/fsfw/datapool/PoolDataSetBase.h index 043c860a7..36cf2a30b 100644 --- a/datapool/PoolDataSetBase.h +++ b/src/fsfw/datapool/PoolDataSetBase.h @@ -3,8 +3,9 @@ #include "PoolDataSetIF.h" #include "PoolVariableIF.h" -#include "../serialize/SerializeIF.h" -#include "../ipc/MutexIF.h" + +#include "fsfw/serialize/SerializeIF.h" +#include "fsfw/ipc/MutexIF.h" /** * @brief The DataSetBase class manages a set of locally checked out variables. diff --git a/datapool/PoolDataSetIF.h b/src/fsfw/datapool/PoolDataSetIF.h similarity index 100% rename from datapool/PoolDataSetIF.h rename to src/fsfw/datapool/PoolDataSetIF.h diff --git a/datapool/PoolEntry.cpp b/src/fsfw/datapool/PoolEntry.cpp similarity index 94% rename from datapool/PoolEntry.cpp rename to src/fsfw/datapool/PoolEntry.cpp index 6504e20c5..0443aa117 100644 --- a/datapool/PoolEntry.cpp +++ b/src/fsfw/datapool/PoolEntry.cpp @@ -1,7 +1,8 @@ -#include "PoolEntry.h" +#include "fsfw/datapool/PoolEntry.h" + +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/globalfunctions/arrayprinter.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../globalfunctions/arrayprinter.h" #include #include diff --git a/datapool/PoolEntry.h b/src/fsfw/datapool/PoolEntry.h similarity index 100% rename from datapool/PoolEntry.h rename to src/fsfw/datapool/PoolEntry.h diff --git a/datapool/PoolEntryIF.h b/src/fsfw/datapool/PoolEntryIF.h similarity index 100% rename from datapool/PoolEntryIF.h rename to src/fsfw/datapool/PoolEntryIF.h diff --git a/datapool/PoolReadGuard.h b/src/fsfw/datapool/PoolReadGuard.h similarity index 100% rename from datapool/PoolReadGuard.h rename to src/fsfw/datapool/PoolReadGuard.h diff --git a/datapool/PoolVarList.h b/src/fsfw/datapool/PoolVarList.h similarity index 100% rename from datapool/PoolVarList.h rename to src/fsfw/datapool/PoolVarList.h diff --git a/datapool/PoolVariableIF.h b/src/fsfw/datapool/PoolVariableIF.h similarity index 100% rename from datapool/PoolVariableIF.h rename to src/fsfw/datapool/PoolVariableIF.h diff --git a/datapool/ReadCommitIF.h b/src/fsfw/datapool/ReadCommitIF.h similarity index 100% rename from datapool/ReadCommitIF.h rename to src/fsfw/datapool/ReadCommitIF.h diff --git a/datapool/ReadCommitIFAttorney.h b/src/fsfw/datapool/ReadCommitIFAttorney.h similarity index 100% rename from datapool/ReadCommitIFAttorney.h rename to src/fsfw/datapool/ReadCommitIFAttorney.h diff --git a/datapool/SharedDataSetIF.h b/src/fsfw/datapool/SharedDataSetIF.h similarity index 100% rename from datapool/SharedDataSetIF.h rename to src/fsfw/datapool/SharedDataSetIF.h diff --git a/src/fsfw/datapoollocal.h b/src/fsfw/datapoollocal.h new file mode 100644 index 000000000..7a3c4c20a --- /dev/null +++ b/src/fsfw/datapoollocal.h @@ -0,0 +1,11 @@ +#ifndef FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ +#define FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ + +/* Collected related headers */ +#include "fsfw/datapoollocal/LocalPoolVariable.h" +#include "fsfw/datapoollocal/LocalPoolVector.h" +#include "fsfw/datapoollocal/StaticLocalDataSet.h" +#include "fsfw/datapoollocal/LocalDataSet.h" +#include "fsfw/datapoollocal/SharedLocalDataSet.h" + +#endif /* FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ */ diff --git a/datapoollocal/AccessLocalPoolF.h b/src/fsfw/datapoollocal/AccessLocalPoolF.h similarity index 100% rename from datapoollocal/AccessLocalPoolF.h rename to src/fsfw/datapoollocal/AccessLocalPoolF.h diff --git a/datapoollocal/CMakeLists.txt b/src/fsfw/datapoollocal/CMakeLists.txt similarity index 100% rename from datapoollocal/CMakeLists.txt rename to src/fsfw/datapoollocal/CMakeLists.txt diff --git a/datapoollocal/HasLocalDataPoolIF.h b/src/fsfw/datapoollocal/HasLocalDataPoolIF.h similarity index 100% rename from datapoollocal/HasLocalDataPoolIF.h rename to src/fsfw/datapoollocal/HasLocalDataPoolIF.h diff --git a/datapoollocal/LocalDataPoolManager.cpp b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp similarity index 98% rename from datapoollocal/LocalDataPoolManager.cpp rename to src/fsfw/datapoollocal/LocalDataPoolManager.cpp index 71997b9b9..4a7066570 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp @@ -1,18 +1,16 @@ -#include "HasLocalDataPoolIF.h" -#include "LocalDataPoolManager.h" -#include "LocalPoolObjectBase.h" -#include "LocalPoolDataSetBase.h" +#include "fsfw/datapoollocal/LocalDataPoolManager.h" +#include "fsfw/datapoollocal.h" #include "internal/LocalPoolDataSetAttorney.h" #include "internal/HasLocalDpIFManagerAttorney.h" -#include "../housekeeping/HousekeepingSetPacket.h" -#include "../objectmanager/ObjectManager.h" -#include "../housekeeping/HousekeepingSnapshot.h" -#include "../housekeeping/AcceptsHkPacketsIF.h" -#include "../timemanager/CCSDSTime.h" -#include "../ipc/MutexFactory.h" -#include "../ipc/MutexGuard.h" -#include "../ipc/QueueFactory.h" +#include "fsfw/housekeeping/HousekeepingSetPacket.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/housekeeping/HousekeepingSnapshot.h" +#include "fsfw/housekeeping/AcceptsHkPacketsIF.h" +#include "fsfw/timemanager/CCSDSTime.h" +#include "fsfw/ipc/MutexFactory.h" +#include "fsfw/ipc/MutexGuard.h" +#include "fsfw/ipc/QueueFactory.h" #include #include diff --git a/datapoollocal/LocalDataPoolManager.h b/src/fsfw/datapoollocal/LocalDataPoolManager.h similarity index 97% rename from datapoollocal/LocalDataPoolManager.h rename to src/fsfw/datapoollocal/LocalDataPoolManager.h index 2ec81f1cf..9f91613b0 100644 --- a/datapoollocal/LocalDataPoolManager.h +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.h @@ -4,17 +4,17 @@ #include "ProvidesDataPoolSubscriptionIF.h" #include "AccessLocalPoolF.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../housekeeping/HousekeepingPacketDownlink.h" -#include "../housekeeping/HousekeepingMessage.h" -#include "../housekeeping/PeriodicHousekeepingHelper.h" -#include "../datapool/DataSetIF.h" -#include "../datapool/PoolEntry.h" -#include "../objectmanager/SystemObjectIF.h" -#include "../ipc/MutexIF.h" -#include "../ipc/CommandMessage.h" -#include "../ipc/MessageQueueIF.h" -#include "../ipc/MutexGuard.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/housekeeping/HousekeepingPacketDownlink.h" +#include "fsfw/housekeeping/HousekeepingMessage.h" +#include "fsfw/housekeeping/PeriodicHousekeepingHelper.h" +#include "fsfw/datapool/DataSetIF.h" +#include "fsfw/datapool/PoolEntry.h" +#include "fsfw/objectmanager/SystemObjectIF.h" +#include "fsfw/ipc/MutexIF.h" +#include "fsfw/ipc/CommandMessage.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/MutexGuard.h" #include #include diff --git a/datapoollocal/LocalDataSet.cpp b/src/fsfw/datapoollocal/LocalDataSet.cpp similarity index 80% rename from datapoollocal/LocalDataSet.cpp rename to src/fsfw/datapoollocal/LocalDataSet.cpp index aeb5c6b32..260f85001 100644 --- a/datapoollocal/LocalDataSet.cpp +++ b/src/fsfw/datapoollocal/LocalDataSet.cpp @@ -1,6 +1,7 @@ -#include "LocalDataSet.h" -#include "../datapoollocal/LocalDataPoolManager.h" -#include "../serialize/SerializeAdapter.h" +#include "fsfw/datapoollocal/LocalDataSet.h" +#include "fsfw/datapoollocal/LocalDataPoolManager.h" + +#include "fsfw/serialize/SerializeAdapter.h" #include #include diff --git a/datapoollocal/LocalDataSet.h b/src/fsfw/datapoollocal/LocalDataSet.h similarity index 100% rename from datapoollocal/LocalDataSet.h rename to src/fsfw/datapoollocal/LocalDataSet.h diff --git a/datapoollocal/LocalPoolDataSetBase.cpp b/src/fsfw/datapoollocal/LocalPoolDataSetBase.cpp similarity index 96% rename from datapoollocal/LocalPoolDataSetBase.cpp rename to src/fsfw/datapoollocal/LocalPoolDataSetBase.cpp index a7a7e6c85..5422c68ae 100644 --- a/datapoollocal/LocalPoolDataSetBase.cpp +++ b/src/fsfw/datapoollocal/LocalPoolDataSetBase.cpp @@ -1,13 +1,12 @@ -#include "LocalPoolDataSetBase.h" -#include "HasLocalDataPoolIF.h" +#include "fsfw/datapoollocal.h" #include "internal/HasLocalDpIFUserAttorney.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../objectmanager/ObjectManager.h" -#include "../globalfunctions/bitutility.h" -#include "../datapoollocal/LocalDataPoolManager.h" -#include "../housekeeping/PeriodicHousekeepingHelper.h" -#include "../serialize/SerializeAdapter.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/globalfunctions/bitutility.h" +#include "fsfw/datapoollocal/LocalDataPoolManager.h" +#include "fsfw/housekeeping/PeriodicHousekeepingHelper.h" +#include "fsfw/serialize/SerializeAdapter.h" #include #include diff --git a/datapoollocal/LocalPoolDataSetBase.h b/src/fsfw/datapoollocal/LocalPoolDataSetBase.h similarity index 99% rename from datapoollocal/LocalPoolDataSetBase.h rename to src/fsfw/datapoollocal/LocalPoolDataSetBase.h index ab67dc3f9..822e2cb89 100644 --- a/datapoollocal/LocalPoolDataSetBase.h +++ b/src/fsfw/datapoollocal/LocalPoolDataSetBase.h @@ -4,8 +4,8 @@ #include "MarkChangedIF.h" #include "localPoolDefinitions.h" -#include "../datapool/DataSetIF.h" -#include "../datapool/PoolDataSetBase.h" +#include "fsfw/datapool/DataSetIF.h" +#include "fsfw/datapool/PoolDataSetBase.h" #include diff --git a/datapoollocal/LocalPoolObjectBase.cpp b/src/fsfw/datapoollocal/LocalPoolObjectBase.cpp similarity index 94% rename from datapoollocal/LocalPoolObjectBase.cpp rename to src/fsfw/datapoollocal/LocalPoolObjectBase.cpp index 6920749b7..96b849c6a 100644 --- a/datapoollocal/LocalPoolObjectBase.cpp +++ b/src/fsfw/datapoollocal/LocalPoolObjectBase.cpp @@ -1,10 +1,10 @@ -#include "LocalPoolObjectBase.h" -#include "LocalDataPoolManager.h" -#include "AccessLocalPoolF.h" -#include "HasLocalDataPoolIF.h" +#include "fsfw/datapoollocal/LocalPoolObjectBase.h" +#include "fsfw/datapoollocal/LocalDataPoolManager.h" +#include "fsfw/datapoollocal/AccessLocalPoolF.h" +#include "fsfw/datapoollocal/HasLocalDataPoolIF.h" #include "internal/HasLocalDpIFUserAttorney.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/objectmanager/ObjectManager.h" LocalPoolObjectBase::LocalPoolObjectBase(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, diff --git a/datapoollocal/LocalPoolObjectBase.h b/src/fsfw/datapoollocal/LocalPoolObjectBase.h similarity index 93% rename from datapoollocal/LocalPoolObjectBase.h rename to src/fsfw/datapoollocal/LocalPoolObjectBase.h index 3f7fb6ddf..72275646f 100644 --- a/datapoollocal/LocalPoolObjectBase.h +++ b/src/fsfw/datapoollocal/LocalPoolObjectBase.h @@ -4,9 +4,9 @@ #include "MarkChangedIF.h" #include "localPoolDefinitions.h" -#include "../objectmanager/SystemObjectIF.h" -#include "../datapool/PoolVariableIF.h" -#include "../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/objectmanager/SystemObjectIF.h" +#include "fsfw/datapool/PoolVariableIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" class LocalDataPoolManager; class DataSetIF; diff --git a/datapoollocal/LocalPoolVariable.h b/src/fsfw/datapoollocal/LocalPoolVariable.h similarity index 100% rename from datapoollocal/LocalPoolVariable.h rename to src/fsfw/datapoollocal/LocalPoolVariable.h diff --git a/datapoollocal/LocalPoolVariable.tpp b/src/fsfw/datapoollocal/LocalPoolVariable.tpp similarity index 100% rename from datapoollocal/LocalPoolVariable.tpp rename to src/fsfw/datapoollocal/LocalPoolVariable.tpp diff --git a/datapoollocal/LocalPoolVector.h b/src/fsfw/datapoollocal/LocalPoolVector.h similarity index 100% rename from datapoollocal/LocalPoolVector.h rename to src/fsfw/datapoollocal/LocalPoolVector.h diff --git a/datapoollocal/LocalPoolVector.tpp b/src/fsfw/datapoollocal/LocalPoolVector.tpp similarity index 100% rename from datapoollocal/LocalPoolVector.tpp rename to src/fsfw/datapoollocal/LocalPoolVector.tpp diff --git a/datapoollocal/MarkChangedIF.h b/src/fsfw/datapoollocal/MarkChangedIF.h similarity index 100% rename from datapoollocal/MarkChangedIF.h rename to src/fsfw/datapoollocal/MarkChangedIF.h diff --git a/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h similarity index 100% rename from datapoollocal/ProvidesDataPoolSubscriptionIF.h rename to src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h diff --git a/datapoollocal/SharedLocalDataSet.cpp b/src/fsfw/datapoollocal/SharedLocalDataSet.cpp similarity index 96% rename from datapoollocal/SharedLocalDataSet.cpp rename to src/fsfw/datapoollocal/SharedLocalDataSet.cpp index 84c2d1c37..2ee00aca9 100644 --- a/datapoollocal/SharedLocalDataSet.cpp +++ b/src/fsfw/datapoollocal/SharedLocalDataSet.cpp @@ -1,4 +1,4 @@ -#include "SharedLocalDataSet.h" +#include "fsfw/datapoollocal/SharedLocalDataSet.h" SharedLocalDataSet::SharedLocalDataSet(object_id_t objectId, sid_t sid, diff --git a/datapoollocal/SharedLocalDataSet.h b/src/fsfw/datapoollocal/SharedLocalDataSet.h similarity index 100% rename from datapoollocal/SharedLocalDataSet.h rename to src/fsfw/datapoollocal/SharedLocalDataSet.h diff --git a/datapoollocal/StaticLocalDataSet.h b/src/fsfw/datapoollocal/StaticLocalDataSet.h similarity index 100% rename from datapoollocal/StaticLocalDataSet.h rename to src/fsfw/datapoollocal/StaticLocalDataSet.h diff --git a/datapoollocal/internal/CMakeLists.txt b/src/fsfw/datapoollocal/internal/CMakeLists.txt similarity index 100% rename from datapoollocal/internal/CMakeLists.txt rename to src/fsfw/datapoollocal/internal/CMakeLists.txt diff --git a/datapoollocal/internal/HasLocalDpIFManagerAttorney.cpp b/src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.cpp similarity index 76% rename from datapoollocal/internal/HasLocalDpIFManagerAttorney.cpp rename to src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.cpp index 65feda75e..a275626b0 100644 --- a/datapoollocal/internal/HasLocalDpIFManagerAttorney.cpp +++ b/src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.cpp @@ -1,7 +1,7 @@ #include "HasLocalDpIFManagerAttorney.h" -#include "../LocalPoolObjectBase.h" -#include "../LocalPoolDataSetBase.h" -#include "../HasLocalDataPoolIF.h" +#include "fsfw/datapoollocal/LocalPoolObjectBase.h" +#include "fsfw/datapoollocal/LocalPoolDataSetBase.h" +#include "fsfw/datapoollocal/HasLocalDataPoolIF.h" LocalPoolDataSetBase* HasLocalDpIFManagerAttorney::getDataSetHandle(HasLocalDataPoolIF* clientIF, sid_t sid) { diff --git a/datapoollocal/internal/HasLocalDpIFManagerAttorney.h b/src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.h similarity index 92% rename from datapoollocal/internal/HasLocalDpIFManagerAttorney.h rename to src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.h index dfe333a64..a82ee4893 100644 --- a/datapoollocal/internal/HasLocalDpIFManagerAttorney.h +++ b/src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.h @@ -1,7 +1,7 @@ #ifndef FSFW_DATAPOOLLOCAL_HASLOCALDPIFMANAGERATTORNEY_H_ #define FSFW_DATAPOOLLOCAL_HASLOCALDPIFMANAGERATTORNEY_H_ -#include "../localPoolDefinitions.h" +#include "fsfw/datapoollocal/localPoolDefinitions.h" class HasLocalDataPoolIF; class LocalPoolDataSetBase; diff --git a/datapoollocal/internal/HasLocalDpIFUserAttorney.cpp b/src/fsfw/datapoollocal/internal/HasLocalDpIFUserAttorney.cpp similarity index 63% rename from datapoollocal/internal/HasLocalDpIFUserAttorney.cpp rename to src/fsfw/datapoollocal/internal/HasLocalDpIFUserAttorney.cpp index 838204a76..8c52fbfb5 100644 --- a/datapoollocal/internal/HasLocalDpIFUserAttorney.cpp +++ b/src/fsfw/datapoollocal/internal/HasLocalDpIFUserAttorney.cpp @@ -1,6 +1,6 @@ #include "HasLocalDpIFUserAttorney.h" -#include "../AccessLocalPoolF.h" -#include "../HasLocalDataPoolIF.h" +#include "fsfw/datapoollocal/AccessLocalPoolF.h" +#include "fsfw/datapoollocal/HasLocalDataPoolIF.h" AccessPoolManagerIF* HasLocalDpIFUserAttorney::getAccessorHandle(HasLocalDataPoolIF *clientIF) { return clientIF->getAccessorHandle(); diff --git a/datapoollocal/internal/HasLocalDpIFUserAttorney.h b/src/fsfw/datapoollocal/internal/HasLocalDpIFUserAttorney.h similarity index 100% rename from datapoollocal/internal/HasLocalDpIFUserAttorney.h rename to src/fsfw/datapoollocal/internal/HasLocalDpIFUserAttorney.h diff --git a/datapoollocal/internal/LocalDpManagerAttorney.h b/src/fsfw/datapoollocal/internal/LocalDpManagerAttorney.h similarity index 100% rename from datapoollocal/internal/LocalDpManagerAttorney.h rename to src/fsfw/datapoollocal/internal/LocalDpManagerAttorney.h diff --git a/datapoollocal/internal/LocalPoolDataSetAttorney.h b/src/fsfw/datapoollocal/internal/LocalPoolDataSetAttorney.h similarity index 95% rename from datapoollocal/internal/LocalPoolDataSetAttorney.h rename to src/fsfw/datapoollocal/internal/LocalPoolDataSetAttorney.h index f81428cd1..9e46cffd5 100644 --- a/datapoollocal/internal/LocalPoolDataSetAttorney.h +++ b/src/fsfw/datapoollocal/internal/LocalPoolDataSetAttorney.h @@ -1,7 +1,7 @@ #ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETATTORNEY_H_ #define FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETATTORNEY_H_ -#include "../LocalPoolDataSetBase.h" +#include "fsfw/datapoollocal/LocalPoolDataSetBase.h" class LocalPoolDataSetAttorney { private: diff --git a/datapoollocal/localPoolDefinitions.h b/src/fsfw/datapoollocal/localPoolDefinitions.h similarity index 100% rename from datapoollocal/localPoolDefinitions.h rename to src/fsfw/datapoollocal/localPoolDefinitions.h diff --git a/devicehandlers/AcceptsDeviceResponsesIF.h b/src/fsfw/devicehandlers/AcceptsDeviceResponsesIF.h similarity index 100% rename from devicehandlers/AcceptsDeviceResponsesIF.h rename to src/fsfw/devicehandlers/AcceptsDeviceResponsesIF.h diff --git a/devicehandlers/AssemblyBase.cpp b/src/fsfw/devicehandlers/AssemblyBase.cpp similarity index 99% rename from devicehandlers/AssemblyBase.cpp rename to src/fsfw/devicehandlers/AssemblyBase.cpp index 46b2211ae..146adfcba 100644 --- a/devicehandlers/AssemblyBase.cpp +++ b/src/fsfw/devicehandlers/AssemblyBase.cpp @@ -1,4 +1,4 @@ -#include "AssemblyBase.h" +#include "fsfw/devicehandlers/AssemblyBase.h" AssemblyBase::AssemblyBase(object_id_t objectId, object_id_t parentId, uint16_t commandQueueDepth) : diff --git a/devicehandlers/AssemblyBase.h b/src/fsfw/devicehandlers/AssemblyBase.h similarity index 100% rename from devicehandlers/AssemblyBase.h rename to src/fsfw/devicehandlers/AssemblyBase.h diff --git a/devicehandlers/CMakeLists.txt b/src/fsfw/devicehandlers/CMakeLists.txt similarity index 100% rename from devicehandlers/CMakeLists.txt rename to src/fsfw/devicehandlers/CMakeLists.txt diff --git a/devicehandlers/ChildHandlerBase.cpp b/src/fsfw/devicehandlers/ChildHandlerBase.cpp similarity index 93% rename from devicehandlers/ChildHandlerBase.cpp rename to src/fsfw/devicehandlers/ChildHandlerBase.cpp index 628ea3e0f..e65087279 100644 --- a/devicehandlers/ChildHandlerBase.cpp +++ b/src/fsfw/devicehandlers/ChildHandlerBase.cpp @@ -1,5 +1,5 @@ -#include "ChildHandlerBase.h" -#include "../subsystem/SubsystemBase.h" +#include "fsfw/devicehandlers/ChildHandlerBase.h" +#include "fsfw/subsystem/SubsystemBase.h" ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, CookieIF * cookie, diff --git a/devicehandlers/ChildHandlerBase.h b/src/fsfw/devicehandlers/ChildHandlerBase.h similarity index 100% rename from devicehandlers/ChildHandlerBase.h rename to src/fsfw/devicehandlers/ChildHandlerBase.h diff --git a/devicehandlers/ChildHandlerFDIR.cpp b/src/fsfw/devicehandlers/ChildHandlerFDIR.cpp similarity index 84% rename from devicehandlers/ChildHandlerFDIR.cpp rename to src/fsfw/devicehandlers/ChildHandlerFDIR.cpp index cb4c75eaf..e1d1321d4 100644 --- a/devicehandlers/ChildHandlerFDIR.cpp +++ b/src/fsfw/devicehandlers/ChildHandlerFDIR.cpp @@ -1,4 +1,4 @@ -#include "ChildHandlerFDIR.h" +#include "fsfw/devicehandlers/ChildHandlerFDIR.h" ChildHandlerFDIR::ChildHandlerFDIR(object_id_t owner, object_id_t faultTreeParent, uint32_t recoveryCount) : diff --git a/devicehandlers/ChildHandlerFDIR.h b/src/fsfw/devicehandlers/ChildHandlerFDIR.h similarity index 100% rename from devicehandlers/ChildHandlerFDIR.h rename to src/fsfw/devicehandlers/ChildHandlerFDIR.h diff --git a/devicehandlers/CookieIF.h b/src/fsfw/devicehandlers/CookieIF.h similarity index 100% rename from devicehandlers/CookieIF.h rename to src/fsfw/devicehandlers/CookieIF.h diff --git a/devicehandlers/DeviceCommunicationIF.h b/src/fsfw/devicehandlers/DeviceCommunicationIF.h similarity index 100% rename from devicehandlers/DeviceCommunicationIF.h rename to src/fsfw/devicehandlers/DeviceCommunicationIF.h diff --git a/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp similarity index 96% rename from devicehandlers/DeviceHandlerBase.cpp rename to src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 5665b101b..535113fd4 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -1,17 +1,17 @@ -#include "DeviceHandlerBase.h" -#include "AcceptsDeviceResponsesIF.h" -#include "DeviceTmReportingWrapper.h" +#include "fsfw/devicehandlers/DeviceHandlerBase.h" +#include "fsfw/devicehandlers/AcceptsDeviceResponsesIF.h" +#include "fsfw/devicehandlers/DeviceTmReportingWrapper.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../objectmanager/ObjectManager.h" -#include "../storagemanager/StorageManagerIF.h" -#include "../thermal/ThermalComponentIF.h" -#include "../globalfunctions/CRC.h" -#include "../housekeeping/HousekeepingMessage.h" -#include "../ipc/MessageQueueMessage.h" -#include "../ipc/QueueFactory.h" -#include "../subsystem/SubsystemBase.h" -#include "../datapoollocal/LocalPoolVariable.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/thermal/ThermalComponentIF.h" +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/housekeeping/HousekeepingMessage.h" +#include "fsfw/ipc/MessageQueueMessage.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/subsystem/SubsystemBase.h" +#include "fsfw/datapoollocal/LocalPoolVariable.h" object_id_t DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT; object_id_t DeviceHandlerBase::rawDataReceiverId = objects::NO_OBJECT; @@ -461,7 +461,7 @@ size_t DeviceHandlerBase::getNextReplyLength(DeviceCommandId_t commandId){ return iter->second.replyLen; }else{ return 0; - } + } } ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceReply, @@ -469,7 +469,7 @@ ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceRep auto replyIter = deviceReplyMap.find(deviceReply); if (replyIter == deviceReplyMap.end()) { triggerEvent(INVALID_DEVICE_COMMAND, deviceReply); - return RETURN_FAILED; + return COMMAND_NOT_SUPPORTED; } else { DeviceReplyInfo *info = &(replyIter->second); if (maxDelayCycles != 0) { @@ -481,6 +481,25 @@ ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceRep } } +ReturnValue_t DeviceHandlerBase::updatePeriodicReply(bool enable, DeviceCommandId_t deviceReply) { + auto replyIter = deviceReplyMap.find(deviceReply); + if (replyIter == deviceReplyMap.end()) { + triggerEvent(INVALID_DEVICE_COMMAND, deviceReply); + return COMMAND_NOT_SUPPORTED; + } else { + DeviceReplyInfo *info = &(replyIter->second); + if(not info->periodic) { + return COMMAND_NOT_SUPPORTED; + } + if(enable) { + info->delayCycles = info->maxDelayCycles; + } + else { + info->delayCycles = 0; + } + } + return HasReturnvaluesIF::RETURN_OK; +} ReturnValue_t DeviceHandlerBase::setReplyDataset(DeviceCommandId_t replyId, LocalPoolDataSetBase *dataSet) { @@ -593,15 +612,15 @@ void DeviceHandlerBase::replyToReply(const DeviceCommandId_t command, DeviceRepl } DeviceCommandInfo* info = &replyInfo.command->second; if (info == nullptr){ - printWarningOrError(sif::OutputTypes::OUT_ERROR, - "replyToReply", HasReturnvaluesIF::RETURN_FAILED, - "Command pointer not found"); - return; + printWarningOrError(sif::OutputTypes::OUT_ERROR, + "replyToReply", HasReturnvaluesIF::RETURN_FAILED, + "Command pointer not found"); + return; } if (info->expectedReplies > 0){ - // Check before to avoid underflow - info->expectedReplies--; + // Check before to avoid underflow + info->expectedReplies--; } // Check if more replies are expected. If so, do nothing. if (info->expectedReplies == 0) { @@ -1336,10 +1355,20 @@ void DeviceHandlerBase::buildInternalCommand(void) { DeviceCommandMap::iterator iter = deviceCommandMap.find( deviceCommandId); if (iter == deviceCommandMap.end()) { +#if FSFW_VERBOSE_LEVEL >= 1 + char output[36]; + sprintf(output, "Command 0x%08x unknown", + static_cast(deviceCommandId)); + // so we can track misconfigurations + printWarningOrError(sif::OutputTypes::OUT_WARNING, + "buildInternalCommand", + COMMAND_NOT_SUPPORTED, + output); +#endif result = COMMAND_NOT_SUPPORTED; } else if (iter->second.isExecuting) { -#if FSFW_DISABLE_PRINTOUT == 0 +#if FSFW_VERBOSE_LEVEL >= 1 char output[36]; sprintf(output, "Command 0x%08x is executing", static_cast(deviceCommandId)); @@ -1550,7 +1579,7 @@ LocalDataPoolManager* DeviceHandlerBase::getHkManagerHandle() { return &poolManager; } -MessageQueueId_t DeviceHandlerBase::getCommanderId(DeviceCommandId_t replyId) const { +MessageQueueId_t DeviceHandlerBase::getCommanderQueueId(DeviceCommandId_t replyId) const { auto commandIter = deviceCommandMap.find(replyId); if(commandIter == deviceCommandMap.end()) { return MessageQueueIF::NO_QUEUE; diff --git a/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h similarity index 96% rename from devicehandlers/DeviceHandlerBase.h rename to src/fsfw/devicehandlers/DeviceHandlerBase.h index 53bd1e653..b182b6114 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -6,22 +6,22 @@ #include "DeviceHandlerFailureIsolation.h" #include "DeviceHandlerThermalSet.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../serviceinterface/serviceInterfaceDefintions.h" -#include "../objectmanager/SystemObject.h" -#include "../tasks/ExecutableObjectIF.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../action/HasActionsIF.h" -#include "../datapool/PoolVariableIF.h" -#include "../modes/HasModesIF.h" -#include "../power/PowerSwitchIF.h" -#include "../ipc/MessageQueueIF.h" -#include "../tasks/PeriodicTaskIF.h" -#include "../action/ActionHelper.h" -#include "../health/HealthHelper.h" -#include "../parameters/ParameterHelper.h" -#include "../datapoollocal/HasLocalDataPoolIF.h" -#include "../datapoollocal/LocalDataPoolManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/serviceinterface/serviceInterfaceDefintions.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/action/HasActionsIF.h" +#include "fsfw/datapool/PoolVariableIF.h" +#include "fsfw/modes/HasModesIF.h" +#include "fsfw/power/PowerSwitchIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/tasks/PeriodicTaskIF.h" +#include "fsfw/action/ActionHelper.h" +#include "fsfw/health/HealthHelper.h" +#include "fsfw/parameters/ParameterHelper.h" +#include "fsfw/datapoollocal/HasLocalDataPoolIF.h" +#include "fsfw/datapoollocal/LocalDataPoolManager.h" #include @@ -399,7 +399,7 @@ protected: */ virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) = 0; - MessageQueueId_t getCommanderId(DeviceCommandId_t replyId) const; + MessageQueueId_t getCommanderQueueId(DeviceCommandId_t replyId) const; /** * Helper function to get pending command. This is useful for devices * like SPI sensors to identify the last sent command. @@ -449,7 +449,9 @@ protected: * @param replyLen Will be supplied to the requestReceiveMessage call of * the communication interface. * @param periodic Indicates if the command is periodic (i.e. it is sent - * by the device repeatedly without request) or not. Default is aperiodic (0) + * by the device repeatedly without request) or not. Default is aperiodic (0). + * Please note that periodic replies are disabled by default. You can enable them with + * #updatePeriodicReply * @return - @c RETURN_OK when the command was successfully inserted, * - @c RETURN_FAILED else. */ @@ -464,7 +466,9 @@ protected: * @param maxDelayCycles The maximum number of delay cycles the reply waits * until it times out. * @param periodic Indicates if the command is periodic (i.e. it is sent - * by the device repeatedly without request) or not. Default is aperiodic (0) + * by the device repeatedly without request) or not. Default is aperiodic (0). + * Please note that periodic replies are disabled by default. You can enable them with + * #updatePeriodicReply * @return - @c RETURN_OK when the command was successfully inserted, * - @c RETURN_FAILED else. */ @@ -480,6 +484,14 @@ protected: */ ReturnValue_t insertInCommandMap(DeviceCommandId_t deviceCommand); + /** + * Enables a periodic reply for a given command. It sets to delay cycles to the specified + * maximum delay cycles for a given reply ID if enabled or to 0 if disabled. + * @param enable Specify whether to enable or disable a given periodic reply + * @return + */ + ReturnValue_t updatePeriodicReply(bool enable, DeviceCommandId_t deviceReply); + /** * @brief This function returns the reply length of the next reply to read. * @@ -493,16 +505,14 @@ protected: virtual size_t getNextReplyLength(DeviceCommandId_t deviceCommand); /** - * @brief This is a helper method to facilitate updating entries - * in the reply map. + * @brief This is a helper method to facilitate updating entries in the reply map. * @param deviceCommand Identifier of the reply to update. - * @param delayCycles The current number of delay cycles to wait. - * As stated in #fillCommandAndCookieMap, to disable periodic commands, - * this is set to zero. + * @param delayCycles The current number of delay cycles to wait. As stated in + * #fillCommandAndReplyMap, to disable periodic commands, this is set to zero. * @param maxDelayCycles The maximum number of delay cycles the reply waits * until it times out. By passing 0 the entry remains untouched. * @param periodic Indicates if the command is periodic (i.e. it is sent - * by the device repeatedly without request) or not.Default is aperiodic (0). + * by the device repeatedly without request) or not. Default is aperiodic (0). * Warning: The setting always overrides the value that was entered in the map. * @return - @c RETURN_OK when the command was successfully inserted, * - @c RETURN_FAILED else. diff --git a/devicehandlers/DeviceHandlerFailureIsolation.cpp b/src/fsfw/devicehandlers/DeviceHandlerFailureIsolation.cpp similarity index 95% rename from devicehandlers/DeviceHandlerFailureIsolation.cpp rename to src/fsfw/devicehandlers/DeviceHandlerFailureIsolation.cpp index b0708a594..8b1c14894 100644 --- a/devicehandlers/DeviceHandlerFailureIsolation.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerFailureIsolation.cpp @@ -1,12 +1,12 @@ -#include "DeviceHandlerFailureIsolation.h" +#include "fsfw/devicehandlers/DeviceHandlerFailureIsolation.h" -#include "../devicehandlers/DeviceHandlerIF.h" -#include "../objectmanager/ObjectManager.h" -#include "../modes/HasModesIF.h" -#include "../health/HealthTableIF.h" -#include "../power/Fuse.h" -#include "../serviceinterface/ServiceInterfaceStream.h" -#include "../thermal/ThermalComponentIF.h" +#include "fsfw/devicehandlers/DeviceHandlerIF.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/modes/HasModesIF.h" +#include "fsfw/health/HealthTableIF.h" +#include "fsfw/power/Fuse.h" +#include "fsfw/serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/thermal/ThermalComponentIF.h" object_id_t DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT; diff --git a/devicehandlers/DeviceHandlerFailureIsolation.h b/src/fsfw/devicehandlers/DeviceHandlerFailureIsolation.h similarity index 100% rename from devicehandlers/DeviceHandlerFailureIsolation.h rename to src/fsfw/devicehandlers/DeviceHandlerFailureIsolation.h diff --git a/devicehandlers/DeviceHandlerIF.h b/src/fsfw/devicehandlers/DeviceHandlerIF.h similarity index 99% rename from devicehandlers/DeviceHandlerIF.h rename to src/fsfw/devicehandlers/DeviceHandlerIF.h index fc31cce09..1933c571c 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/src/fsfw/devicehandlers/DeviceHandlerIF.h @@ -104,7 +104,8 @@ public: static const Event DEVICE_MISSED_REPLY = MAKE_EVENT(5, severity::LOW); static const Event DEVICE_UNKNOWN_REPLY = MAKE_EVENT(6, severity::LOW); static const Event DEVICE_UNREQUESTED_REPLY = MAKE_EVENT(7, severity::LOW); - static const Event INVALID_DEVICE_COMMAND = MAKE_EVENT(8, severity::LOW); //!< Indicates a SW bug in child class. + //! [EXPORT] : [COMMENT] Indicates a SW bug in child class. + static const Event INVALID_DEVICE_COMMAND = MAKE_EVENT(8, severity::LOW); static const Event MONITORING_LIMIT_EXCEEDED = MAKE_EVENT(9, severity::LOW); static const Event MONITORING_AMBIGUOUS = MAKE_EVENT(10, severity::HIGH); diff --git a/devicehandlers/DeviceHandlerMessage.cpp b/src/fsfw/devicehandlers/DeviceHandlerMessage.cpp similarity index 96% rename from devicehandlers/DeviceHandlerMessage.cpp rename to src/fsfw/devicehandlers/DeviceHandlerMessage.cpp index 69c9deb9f..48277c9ae 100644 --- a/devicehandlers/DeviceHandlerMessage.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerMessage.cpp @@ -1,5 +1,5 @@ -#include "DeviceHandlerMessage.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/devicehandlers/DeviceHandlerMessage.h" +#include "fsfw/objectmanager/ObjectManager.h" store_address_t DeviceHandlerMessage::getStoreAddress( const CommandMessage* message) { diff --git a/devicehandlers/DeviceHandlerMessage.h b/src/fsfw/devicehandlers/DeviceHandlerMessage.h similarity index 100% rename from devicehandlers/DeviceHandlerMessage.h rename to src/fsfw/devicehandlers/DeviceHandlerMessage.h diff --git a/devicehandlers/DeviceHandlerThermalSet.h b/src/fsfw/devicehandlers/DeviceHandlerThermalSet.h similarity index 100% rename from devicehandlers/DeviceHandlerThermalSet.h rename to src/fsfw/devicehandlers/DeviceHandlerThermalSet.h diff --git a/devicehandlers/DeviceTmReportingWrapper.cpp b/src/fsfw/devicehandlers/DeviceTmReportingWrapper.cpp similarity index 93% rename from devicehandlers/DeviceTmReportingWrapper.cpp rename to src/fsfw/devicehandlers/DeviceTmReportingWrapper.cpp index c70f57d6d..0300a24a3 100644 --- a/devicehandlers/DeviceTmReportingWrapper.cpp +++ b/src/fsfw/devicehandlers/DeviceTmReportingWrapper.cpp @@ -1,5 +1,5 @@ -#include "DeviceTmReportingWrapper.h" -#include "../serialize/SerializeAdapter.h" +#include "fsfw/devicehandlers/DeviceTmReportingWrapper.h" +#include "fsfw/serialize/SerializeAdapter.h" DeviceTmReportingWrapper::DeviceTmReportingWrapper(object_id_t objectId, ActionId_t actionId, SerializeIF* data) : diff --git a/devicehandlers/DeviceTmReportingWrapper.h b/src/fsfw/devicehandlers/DeviceTmReportingWrapper.h similarity index 100% rename from devicehandlers/DeviceTmReportingWrapper.h rename to src/fsfw/devicehandlers/DeviceTmReportingWrapper.h diff --git a/devicehandlers/HealthDevice.cpp b/src/fsfw/devicehandlers/HealthDevice.cpp similarity index 95% rename from devicehandlers/HealthDevice.cpp rename to src/fsfw/devicehandlers/HealthDevice.cpp index e23dd5b69..2f6e1dfbb 100644 --- a/devicehandlers/HealthDevice.cpp +++ b/src/fsfw/devicehandlers/HealthDevice.cpp @@ -1,5 +1,5 @@ -#include "HealthDevice.h" -#include "../ipc/QueueFactory.h" +#include "fsfw/devicehandlers/HealthDevice.h" +#include "fsfw/ipc/QueueFactory.h" HealthDevice::HealthDevice(object_id_t setObjectId, MessageQueueId_t parentQueue) : diff --git a/devicehandlers/HealthDevice.h b/src/fsfw/devicehandlers/HealthDevice.h similarity index 79% rename from devicehandlers/HealthDevice.h rename to src/fsfw/devicehandlers/HealthDevice.h index 738f0c7ea..bf9cdb822 100644 --- a/devicehandlers/HealthDevice.h +++ b/src/fsfw/devicehandlers/HealthDevice.h @@ -1,11 +1,11 @@ #ifndef FSFW_DEVICEHANDLERS_HEALTHDEVICE_H_ #define FSFW_DEVICEHANDLERS_HEALTHDEVICE_H_ -#include "../health/HasHealthIF.h" -#include "../health/HealthHelper.h" -#include "../objectmanager/SystemObject.h" -#include "../tasks/ExecutableObjectIF.h" -#include "../ipc/MessageQueueIF.h" +#include "fsfw/health/HasHealthIF.h" +#include "fsfw/health/HealthHelper.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/ipc/MessageQueueIF.h" class HealthDevice: public SystemObject, public ExecutableObjectIF, diff --git a/src/fsfw/events/CMakeLists.txt b/src/fsfw/events/CMakeLists.txt new file mode 100644 index 000000000..28eec7723 --- /dev/null +++ b/src/fsfw/events/CMakeLists.txt @@ -0,0 +1,6 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + EventManager.cpp + EventMessage.cpp +) + +add_subdirectory(eventmatching) diff --git a/events/Event.h b/src/fsfw/events/Event.h similarity index 100% rename from events/Event.h rename to src/fsfw/events/Event.h diff --git a/events/EventManager.cpp b/src/fsfw/events/EventManager.cpp similarity index 58% rename from events/EventManager.cpp rename to src/fsfw/events/EventManager.cpp index 8e2a2a829..958076a9b 100644 --- a/events/EventManager.cpp +++ b/src/fsfw/events/EventManager.cpp @@ -1,8 +1,8 @@ -#include "EventManager.h" -#include "EventMessage.h" +#include "fsfw/events/EventManager.h" +#include "fsfw/events/EventMessage.h" -#include "../ipc/QueueFactory.h" -#include "../ipc/MutexFactory.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/ipc/MutexFactory.h" MessageQueueId_t EventManagerIF::eventmanagerQueue = MessageQueueIF::NO_QUEUE; @@ -12,119 +12,119 @@ MessageQueueId_t EventManagerIF::eventmanagerQueue = MessageQueueIF::NO_QUEUE; // So a good guess is 75 to a max of 100 pools required for each, which fits well. const LocalPool::LocalPoolConfig EventManager::poolConfig = { {fsfwconfig::FSFW_EVENTMGMR_MATCHTREE_NODES, - sizeof(EventMatchTree::Node)}, + sizeof(EventMatchTree::Node)}, {fsfwconfig::FSFW_EVENTMGMT_EVENTIDMATCHERS, - sizeof(EventIdRangeMatcher)}, + sizeof(EventIdRangeMatcher)}, {fsfwconfig::FSFW_EVENTMGMR_RANGEMATCHERS, - sizeof(ReporterRangeMatcher)} + sizeof(ReporterRangeMatcher)} }; EventManager::EventManager(object_id_t setObjectId) : - SystemObject(setObjectId), - factoryBackend(0, poolConfig, false, true) { - mutex = MutexFactory::instance()->createMutex(); - eventReportQueue = QueueFactory::instance()->createMessageQueue( - MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE); + SystemObject(setObjectId), + factoryBackend(0, poolConfig, false, true) { + mutex = MutexFactory::instance()->createMutex(); + eventReportQueue = QueueFactory::instance()->createMessageQueue( + MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE); } EventManager::~EventManager() { - QueueFactory::instance()->deleteMessageQueue(eventReportQueue); - MutexFactory::instance()->deleteMutex(mutex); + QueueFactory::instance()->deleteMessageQueue(eventReportQueue); + MutexFactory::instance()->deleteMutex(mutex); } MessageQueueId_t EventManager::getEventReportQueue() { - return eventReportQueue->getId(); + return eventReportQueue->getId(); } ReturnValue_t EventManager::performOperation(uint8_t opCode) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - while (result == HasReturnvaluesIF::RETURN_OK) { - EventMessage message; - result = eventReportQueue->receiveMessage(&message); - if (result == HasReturnvaluesIF::RETURN_OK) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + while (result == HasReturnvaluesIF::RETURN_OK) { + EventMessage message; + result = eventReportQueue->receiveMessage(&message); + if (result == HasReturnvaluesIF::RETURN_OK) { #if FSFW_OBJ_EVENT_TRANSLATION == 1 - printEvent(&message); + printEvent(&message); #endif - notifyListeners(&message); - } - } - return HasReturnvaluesIF::RETURN_OK; + notifyListeners(&message); + } + } + return HasReturnvaluesIF::RETURN_OK; } void EventManager::notifyListeners(EventMessage* message) { - lockMutex(); - for (auto iter = listenerList.begin(); iter != listenerList.end(); ++iter) { - if (iter->second.match(message)) { - MessageQueueSenderIF::sendMessage(iter->first, message, - message->getSender()); - } - } - unlockMutex(); + lockMutex(); + for (auto iter = listenerList.begin(); iter != listenerList.end(); ++iter) { + if (iter->second.match(message)) { + MessageQueueSenderIF::sendMessage(iter->first, message, + message->getSender()); + } + } + unlockMutex(); } ReturnValue_t EventManager::registerListener(MessageQueueId_t listener, bool forwardAllButSelected) { - auto result = listenerList.insert( - std::pair(listener, - EventMatchTree(&factoryBackend, forwardAllButSelected))); - if (!result.second) { - return HasReturnvaluesIF::RETURN_FAILED; - } - return HasReturnvaluesIF::RETURN_OK; + auto result = listenerList.insert( + std::pair(listener, + EventMatchTree(&factoryBackend, forwardAllButSelected))); + if (!result.second) { + return HasReturnvaluesIF::RETURN_FAILED; + } + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t EventManager::subscribeToEvent(MessageQueueId_t listener, - EventId_t event) { - return subscribeToEventRange(listener, event); + EventId_t event) { + return subscribeToEventRange(listener, event); } ReturnValue_t EventManager::subscribeToAllEventsFrom(MessageQueueId_t listener, - object_id_t object) { - return subscribeToEventRange(listener, 0, 0, true, object); + object_id_t object) { + return subscribeToEventRange(listener, 0, 0, true, object); } ReturnValue_t EventManager::subscribeToEventRange(MessageQueueId_t listener, - EventId_t idFrom, EventId_t idTo, bool idInverted, - object_id_t reporterFrom, object_id_t reporterTo, - bool reporterInverted) { - auto iter = listenerList.find(listener); - if (iter == listenerList.end()) { - return LISTENER_NOT_FOUND; - } - lockMutex(); - ReturnValue_t result = iter->second.addMatch(idFrom, idTo, idInverted, - reporterFrom, reporterTo, reporterInverted); - unlockMutex(); - return result; + EventId_t idFrom, EventId_t idTo, bool idInverted, + object_id_t reporterFrom, object_id_t reporterTo, + bool reporterInverted) { + auto iter = listenerList.find(listener); + if (iter == listenerList.end()) { + return LISTENER_NOT_FOUND; + } + lockMutex(); + ReturnValue_t result = iter->second.addMatch(idFrom, idTo, idInverted, + reporterFrom, reporterTo, reporterInverted); + unlockMutex(); + return result; } ReturnValue_t EventManager::unsubscribeFromEventRange(MessageQueueId_t listener, - EventId_t idFrom, EventId_t idTo, bool idInverted, - object_id_t reporterFrom, object_id_t reporterTo, - bool reporterInverted) { - auto iter = listenerList.find(listener); - if (iter == listenerList.end()) { - return LISTENER_NOT_FOUND; - } - lockMutex(); - ReturnValue_t result = iter->second.removeMatch(idFrom, idTo, idInverted, - reporterFrom, reporterTo, reporterInverted); - unlockMutex(); - return result; + EventId_t idFrom, EventId_t idTo, bool idInverted, + object_id_t reporterFrom, object_id_t reporterTo, + bool reporterInverted) { + auto iter = listenerList.find(listener); + if (iter == listenerList.end()) { + return LISTENER_NOT_FOUND; + } + lockMutex(); + ReturnValue_t result = iter->second.removeMatch(idFrom, idTo, idInverted, + reporterFrom, reporterTo, reporterInverted); + unlockMutex(); + return result; } void EventManager::lockMutex() { - mutex->lockMutex(timeoutType, timeoutMs); + mutex->lockMutex(timeoutType, timeoutMs); } void EventManager::unlockMutex() { - mutex->unlockMutex(); + mutex->unlockMutex(); } void EventManager::setMutexTimeout(MutexIF::TimeoutType timeoutType, - uint32_t timeoutMs) { - this->timeoutType = timeoutType; - this->timeoutMs = timeoutMs; + uint32_t timeoutMs) { + this->timeoutType = timeoutType; + this->timeoutMs = timeoutMs; } #if FSFW_OBJ_EVENT_TRANSLATION == 1 @@ -157,7 +157,7 @@ void EventManager::printUtility(sif::OutputTypes printType, EventMessage *messag message->getReporter() << std::setfill(' ') << std::dec; } sif::info << " reported event with ID " << message->getEventId() << std::endl; - sif::debug << translateEvents(message->getEvent()) << " | " <getEvent()) << " | " <getParameter1() << " | P1 Dec: " << std::dec << message->getParameter1() << std::hex << " | P2 Hex: 0x" << message->getParameter2() << " | P2 Dec: " << std::dec << message->getParameter2() << std::endl; @@ -170,9 +170,10 @@ void EventManager::printUtility(sif::OutputTypes printType, EventMessage *messag sif::printInfo("Event Manager: Reporter ID 0x%08x reported event with ID %d\n", message->getReporter(), message->getEventId()); } - sif::printInfo("P1 Hex: 0x%x | P1 Dec: %d | P2 Hex: 0x%x | P2 Dec: %d\n", - message->getParameter1(), message->getParameter1(), - message->getParameter2(), message->getParameter2()); + + sif::printInfo("%s | P1 Hex: 0x%x | P1 Dec: %d | P2 Hex: 0x%x | P2 Dec: %d\n", + translateEvents(message->getEvent()), message->getParameter1(), + message->getParameter1(), message->getParameter2(), message->getParameter2()); #endif /* FSFW_CPP_OSTREAM_ENABLED == 0 */ } else { diff --git a/events/EventManager.h b/src/fsfw/events/EventManager.h similarity index 100% rename from events/EventManager.h rename to src/fsfw/events/EventManager.h diff --git a/events/EventManagerIF.h b/src/fsfw/events/EventManagerIF.h similarity index 100% rename from events/EventManagerIF.h rename to src/fsfw/events/EventManagerIF.h diff --git a/events/EventMessage.cpp b/src/fsfw/events/EventMessage.cpp similarity index 98% rename from events/EventMessage.cpp rename to src/fsfw/events/EventMessage.cpp index 548b4f0f3..74f42b06b 100644 --- a/events/EventMessage.cpp +++ b/src/fsfw/events/EventMessage.cpp @@ -1,4 +1,4 @@ -#include "EventMessage.h" +#include "fsfw/events/EventMessage.h" #include EventMessage::EventMessage() { diff --git a/events/EventMessage.h b/src/fsfw/events/EventMessage.h similarity index 88% rename from events/EventMessage.h rename to src/fsfw/events/EventMessage.h index f2f5ffb50..36e261bd6 100644 --- a/events/EventMessage.h +++ b/src/fsfw/events/EventMessage.h @@ -1,9 +1,9 @@ -#ifndef EVENTMESSAGE_H_ -#define EVENTMESSAGE_H_ +#ifndef FSFW_EVENTS_EVENTMESSAGE_H_ +#define FSFW_EVENTS_EVENTMESSAGE_H_ #include "Event.h" -#include "../ipc/MessageQueueMessage.h" -#include "../objectmanager/ObjectManagerIF.h" +#include "fsfw/ipc/MessageQueueMessage.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" /** * Passing on events through IPC. @@ -49,4 +49,4 @@ protected: }; -#endif /* EVENTMESSAGE_H_ */ +#endif /* FSFW_EVENTS_EVENTMESSAGE_H_ */ diff --git a/events/EventReportingProxyIF.h b/src/fsfw/events/EventReportingProxyIF.h similarity index 100% rename from events/EventReportingProxyIF.h rename to src/fsfw/events/EventReportingProxyIF.h diff --git a/events/eventmatching/CMakeLists.txt b/src/fsfw/events/eventmatching/CMakeLists.txt similarity index 100% rename from events/eventmatching/CMakeLists.txt rename to src/fsfw/events/eventmatching/CMakeLists.txt diff --git a/events/eventmatching/EventIdRangeMatcher.cpp b/src/fsfw/events/eventmatching/EventIdRangeMatcher.cpp similarity index 84% rename from events/eventmatching/EventIdRangeMatcher.cpp rename to src/fsfw/events/eventmatching/EventIdRangeMatcher.cpp index 974567d4f..92089f7cf 100644 --- a/events/eventmatching/EventIdRangeMatcher.cpp +++ b/src/fsfw/events/eventmatching/EventIdRangeMatcher.cpp @@ -1,4 +1,4 @@ -#include "EventIdRangeMatcher.h" +#include "fsfw/events/eventmatching/EventIdRangeMatcher.h" EventIdRangeMatcher::EventIdRangeMatcher(EventId_t lower, EventId_t upper, bool inverted) : EventRangeMatcherBase(lower, upper, inverted) { diff --git a/events/eventmatching/EventIdRangeMatcher.h b/src/fsfw/events/eventmatching/EventIdRangeMatcher.h similarity index 100% rename from events/eventmatching/EventIdRangeMatcher.h rename to src/fsfw/events/eventmatching/EventIdRangeMatcher.h diff --git a/events/eventmatching/EventMatchTree.cpp b/src/fsfw/events/eventmatching/EventMatchTree.cpp similarity index 94% rename from events/eventmatching/EventMatchTree.cpp rename to src/fsfw/events/eventmatching/EventMatchTree.cpp index 55e4083f4..66e9e91a8 100644 --- a/events/eventmatching/EventMatchTree.cpp +++ b/src/fsfw/events/eventmatching/EventMatchTree.cpp @@ -1,7 +1,7 @@ -#include "EventIdRangeMatcher.h" -#include "EventMatchTree.h" -#include "ReporterRangeMatcher.h" -#include "SeverityRangeMatcher.h" +#include "fsfw/events/eventmatching/EventIdRangeMatcher.h" +#include "fsfw/events/eventmatching/EventMatchTree.h" +#include "fsfw/events/eventmatching/ReporterRangeMatcher.h" +#include "fsfw/events/eventmatching/SeverityRangeMatcher.h" EventMatchTree::EventMatchTree(StorageManagerIF* storageBackend, bool invertedMatch) : diff --git a/events/eventmatching/EventMatchTree.h b/src/fsfw/events/eventmatching/EventMatchTree.h similarity index 100% rename from events/eventmatching/EventMatchTree.h rename to src/fsfw/events/eventmatching/EventMatchTree.h diff --git a/events/eventmatching/EventRangeMatcherBase.h b/src/fsfw/events/eventmatching/EventRangeMatcherBase.h similarity index 100% rename from events/eventmatching/EventRangeMatcherBase.h rename to src/fsfw/events/eventmatching/EventRangeMatcherBase.h diff --git a/events/eventmatching/ReporterRangeMatcher.cpp b/src/fsfw/events/eventmatching/ReporterRangeMatcher.cpp similarity index 84% rename from events/eventmatching/ReporterRangeMatcher.cpp rename to src/fsfw/events/eventmatching/ReporterRangeMatcher.cpp index 611797260..fc3a2f9fd 100644 --- a/events/eventmatching/ReporterRangeMatcher.cpp +++ b/src/fsfw/events/eventmatching/ReporterRangeMatcher.cpp @@ -1,4 +1,4 @@ -#include "ReporterRangeMatcher.h" +#include "fsfw/events/eventmatching/ReporterRangeMatcher.h" ReporterRangeMatcher::ReporterRangeMatcher(object_id_t lower, object_id_t upper, bool inverted) : EventRangeMatcherBase(lower, upper, inverted) { diff --git a/events/eventmatching/ReporterRangeMatcher.h b/src/fsfw/events/eventmatching/ReporterRangeMatcher.h similarity index 100% rename from events/eventmatching/ReporterRangeMatcher.h rename to src/fsfw/events/eventmatching/ReporterRangeMatcher.h diff --git a/events/eventmatching/SeverityRangeMatcher.cpp b/src/fsfw/events/eventmatching/SeverityRangeMatcher.cpp similarity index 70% rename from events/eventmatching/SeverityRangeMatcher.cpp rename to src/fsfw/events/eventmatching/SeverityRangeMatcher.cpp index 6fd382714..230e4e776 100644 --- a/events/eventmatching/SeverityRangeMatcher.cpp +++ b/src/fsfw/events/eventmatching/SeverityRangeMatcher.cpp @@ -1,6 +1,6 @@ -#include "SeverityRangeMatcher.h" -#include "../../events/EventMessage.h" -#include "../../serialize/SerializeAdapter.h" +#include "fsfw/events/eventmatching/SeverityRangeMatcher.h" +#include "fsfw/events/EventMessage.h" +#include "fsfw/serialize/SerializeAdapter.h" SeverityRangeMatcher::SeverityRangeMatcher(EventSeverity_t from, EventSeverity_t till, bool inverted) : EventRangeMatcherBase(from, till, inverted) { diff --git a/events/eventmatching/SeverityRangeMatcher.h b/src/fsfw/events/eventmatching/SeverityRangeMatcher.h similarity index 100% rename from events/eventmatching/SeverityRangeMatcher.h rename to src/fsfw/events/eventmatching/SeverityRangeMatcher.h diff --git a/events/eventmatching/eventmatching.h b/src/fsfw/events/eventmatching/eventmatching.h similarity index 100% rename from events/eventmatching/eventmatching.h rename to src/fsfw/events/eventmatching/eventmatching.h diff --git a/events/fwSubsystemIdRanges.h b/src/fsfw/events/fwSubsystemIdRanges.h similarity index 94% rename from events/fwSubsystemIdRanges.h rename to src/fsfw/events/fwSubsystemIdRanges.h index 88dee9b4e..08fb878d6 100644 --- a/events/fwSubsystemIdRanges.h +++ b/src/fsfw/events/fwSubsystemIdRanges.h @@ -29,6 +29,8 @@ enum: uint8_t { PUS_SERVICE_9 = 89, PUS_SERVICE_17 = 97, PUS_SERVICE_23 = 103, + MGM_LIS3MDL = 106, + MGM_RM3100 = 107, FW_SUBSYSTEM_ID_RANGE }; diff --git a/fdir/CMakeLists.txt b/src/fsfw/fdir/CMakeLists.txt similarity index 100% rename from fdir/CMakeLists.txt rename to src/fsfw/fdir/CMakeLists.txt diff --git a/fdir/ConfirmsFailuresIF.h b/src/fsfw/fdir/ConfirmsFailuresIF.h similarity index 100% rename from fdir/ConfirmsFailuresIF.h rename to src/fsfw/fdir/ConfirmsFailuresIF.h diff --git a/fdir/EventCorrelation.cpp b/src/fsfw/fdir/EventCorrelation.cpp similarity index 95% rename from fdir/EventCorrelation.cpp rename to src/fsfw/fdir/EventCorrelation.cpp index d60fc6ca3..5b0233349 100644 --- a/fdir/EventCorrelation.cpp +++ b/src/fsfw/fdir/EventCorrelation.cpp @@ -1,4 +1,4 @@ -#include "EventCorrelation.h" +#include "fsfw/fdir/EventCorrelation.h" EventCorrelation::EventCorrelation(uint32_t timeout) : eventPending(false) { diff --git a/fdir/EventCorrelation.h b/src/fsfw/fdir/EventCorrelation.h similarity index 100% rename from fdir/EventCorrelation.h rename to src/fsfw/fdir/EventCorrelation.h diff --git a/fdir/FailureIsolationBase.cpp b/src/fsfw/fdir/FailureIsolationBase.cpp similarity index 95% rename from fdir/FailureIsolationBase.cpp rename to src/fsfw/fdir/FailureIsolationBase.cpp index 764fc9184..717e5072b 100644 --- a/fdir/FailureIsolationBase.cpp +++ b/src/fsfw/fdir/FailureIsolationBase.cpp @@ -1,9 +1,9 @@ -#include "../events/EventManagerIF.h" -#include "FailureIsolationBase.h" -#include "../health/HasHealthIF.h" -#include "../health/HealthMessage.h" -#include "../ipc/QueueFactory.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/events/EventManagerIF.h" +#include "fsfw/fdir/FailureIsolationBase.h" +#include "fsfw/health/HasHealthIF.h" +#include "fsfw/health/HealthMessage.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/objectmanager/ObjectManager.h" FailureIsolationBase::FailureIsolationBase(object_id_t owner, object_id_t parent, uint8_t messageDepth, uint8_t parameterDomainBase) : diff --git a/fdir/FailureIsolationBase.h b/src/fsfw/fdir/FailureIsolationBase.h similarity index 100% rename from fdir/FailureIsolationBase.h rename to src/fsfw/fdir/FailureIsolationBase.h diff --git a/fdir/FaultCounter.cpp b/src/fsfw/fdir/FaultCounter.cpp similarity index 98% rename from fdir/FaultCounter.cpp rename to src/fsfw/fdir/FaultCounter.cpp index 53c1dd7de..0b30a67d4 100644 --- a/fdir/FaultCounter.cpp +++ b/src/fsfw/fdir/FaultCounter.cpp @@ -1,4 +1,4 @@ -#include "FaultCounter.h" +#include "fsfw/fdir/FaultCounter.h" FaultCounter::FaultCounter(uint32_t failureThreshold, uint32_t decrementAfterMs, uint8_t setParameterDomain) : diff --git a/fdir/FaultCounter.h b/src/fsfw/fdir/FaultCounter.h similarity index 79% rename from fdir/FaultCounter.h rename to src/fsfw/fdir/FaultCounter.h index e0670c4b3..a85e8cf76 100644 --- a/fdir/FaultCounter.h +++ b/src/fsfw/fdir/FaultCounter.h @@ -1,8 +1,8 @@ -#ifndef FRAMEWORK_FDIR_FAULTCOUNTER_H_ -#define FRAMEWORK_FDIR_FAULTCOUNTER_H_ +#ifndef FSFW_FDIR_FAULTCOUNTER_H_ +#define FSFW_FDIR_FAULTCOUNTER_H_ -#include "../parameters/HasParametersIF.h" -#include "../timemanager/Countdown.h" +#include "fsfw/parameters/HasParametersIF.h" +#include "fsfw/timemanager/Countdown.h" class FaultCounter: public HasParametersIF { public: @@ -35,4 +35,4 @@ private: uint32_t failureThreshold; }; -#endif /* FRAMEWORK_FDIR_FAULTCOUNTER_H_ */ +#endif /* FSFW_FDIR_FAULTCOUNTER_H_ */ diff --git a/globalfunctions/AsciiConverter.cpp b/src/fsfw/globalfunctions/AsciiConverter.cpp similarity index 99% rename from globalfunctions/AsciiConverter.cpp rename to src/fsfw/globalfunctions/AsciiConverter.cpp index 9eb3698fb..099088158 100644 --- a/globalfunctions/AsciiConverter.cpp +++ b/src/fsfw/globalfunctions/AsciiConverter.cpp @@ -1,4 +1,5 @@ -#include "AsciiConverter.h" +#include "fsfw/globalfunctions/AsciiConverter.h" + #include #include diff --git a/globalfunctions/AsciiConverter.h b/src/fsfw/globalfunctions/AsciiConverter.h similarity index 100% rename from globalfunctions/AsciiConverter.h rename to src/fsfw/globalfunctions/AsciiConverter.h diff --git a/globalfunctions/CMakeLists.txt b/src/fsfw/globalfunctions/CMakeLists.txt similarity index 100% rename from globalfunctions/CMakeLists.txt rename to src/fsfw/globalfunctions/CMakeLists.txt diff --git a/globalfunctions/CRC.cpp b/src/fsfw/globalfunctions/CRC.cpp similarity index 99% rename from globalfunctions/CRC.cpp rename to src/fsfw/globalfunctions/CRC.cpp index 7bb568066..3df6018cf 100644 --- a/globalfunctions/CRC.cpp +++ b/src/fsfw/globalfunctions/CRC.cpp @@ -1,4 +1,4 @@ -#include "CRC.h" +#include "fsfw/globalfunctions/CRC.h" #include const uint16_t CRC::crc16ccitt_table[256] = { diff --git a/globalfunctions/CRC.h b/src/fsfw/globalfunctions/CRC.h similarity index 100% rename from globalfunctions/CRC.h rename to src/fsfw/globalfunctions/CRC.h diff --git a/src/fsfw/globalfunctions/DleEncoder.cpp b/src/fsfw/globalfunctions/DleEncoder.cpp new file mode 100644 index 000000000..91db54454 --- /dev/null +++ b/src/fsfw/globalfunctions/DleEncoder.cpp @@ -0,0 +1,298 @@ +#include "fsfw/globalfunctions/DleEncoder.h" + +DleEncoder::DleEncoder(bool escapeStxEtx, bool escapeCr): + escapeStxEtx(escapeStxEtx), escapeCr(escapeCr) {} + +DleEncoder::~DleEncoder() {} + +ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream, + size_t sourceLen, uint8_t* destStream, size_t maxDestLen, + size_t* encodedLen, bool addStxEtx) { + if(escapeStxEtx) { + return encodeStreamEscaped(sourceStream, sourceLen, + destStream, maxDestLen, encodedLen, addStxEtx); + } + else { + return encodeStreamNonEscaped(sourceStream, sourceLen, + destStream, maxDestLen, encodedLen, addStxEtx); + } + +} + +ReturnValue_t DleEncoder::encodeStreamEscaped(const uint8_t *sourceStream, size_t sourceLen, + uint8_t *destStream, size_t maxDestLen, size_t *encodedLen, + bool addStxEtx) { + size_t encodedIndex = 0; + size_t sourceIndex = 0; + uint8_t nextByte = 0; + if(addStxEtx) { + if(maxDestLen < 1) { + return STREAM_TOO_SHORT; + } + destStream[encodedIndex++] = STX_CHAR; + } + while (encodedIndex < maxDestLen and sourceIndex < sourceLen) { + nextByte = sourceStream[sourceIndex]; + // STX, ETX and CR characters in the stream need to be escaped with DLE + if ((nextByte == STX_CHAR or nextByte == ETX_CHAR) or + (this->escapeCr and nextByte == CARRIAGE_RETURN)) { + if (encodedIndex + 1 >= maxDestLen) { + return STREAM_TOO_SHORT; + } + else { + destStream[encodedIndex] = DLE_CHAR; + ++encodedIndex; + /* Escaped byte will be actual byte + 0x40. This prevents + * STX, ETX, and carriage return characters from appearing + * in the encoded data stream at all, so when polling an + * encoded stream, the transmission can be stopped at ETX. + * 0x40 was chosen at random with special requirements: + * - Prevent going from one control char to another + * - Prevent overflow for common characters */ + destStream[encodedIndex] = nextByte + 0x40; + } + } + // DLE characters are simply escaped with DLE. + else if (nextByte == DLE_CHAR) { + if (encodedIndex + 1 >= maxDestLen) { + return STREAM_TOO_SHORT; + } + else { + destStream[encodedIndex] = DLE_CHAR; + ++encodedIndex; + destStream[encodedIndex] = DLE_CHAR; + } + } + else { + destStream[encodedIndex] = nextByte; + } + ++encodedIndex; + ++sourceIndex; + } + + if (sourceIndex == sourceLen) { + if (addStxEtx) { + if(encodedIndex + 1 >= maxDestLen) { + return STREAM_TOO_SHORT; + } + destStream[encodedIndex] = ETX_CHAR; + ++encodedIndex; + } + *encodedLen = encodedIndex; + return RETURN_OK; + } + else { + return STREAM_TOO_SHORT; + } +} + +ReturnValue_t DleEncoder::encodeStreamNonEscaped(const uint8_t *sourceStream, size_t sourceLen, + uint8_t *destStream, size_t maxDestLen, size_t *encodedLen, + bool addStxEtx) { + size_t encodedIndex = 0; + size_t sourceIndex = 0; + uint8_t nextByte = 0; + if(addStxEtx) { + if(maxDestLen < 2) { + return STREAM_TOO_SHORT; + } + destStream[encodedIndex++] = DLE_CHAR; + destStream[encodedIndex++] = STX_CHAR; + } + while (encodedIndex < maxDestLen and sourceIndex < sourceLen) { + nextByte = sourceStream[sourceIndex]; + // DLE characters are simply escaped with DLE. + if (nextByte == DLE_CHAR) { + if (encodedIndex + 1 >= maxDestLen) { + return STREAM_TOO_SHORT; + } + else { + destStream[encodedIndex] = DLE_CHAR; + ++encodedIndex; + destStream[encodedIndex] = DLE_CHAR; + } + } + else { + destStream[encodedIndex] = nextByte; + } + ++encodedIndex; + ++sourceIndex; + } + + if (sourceIndex == sourceLen) { + if (addStxEtx) { + if(encodedIndex + 2 >= maxDestLen) { + return STREAM_TOO_SHORT; + } + destStream[encodedIndex++] = DLE_CHAR; + destStream[encodedIndex++] = ETX_CHAR; + } + *encodedLen = encodedIndex; + return RETURN_OK; + } + else { + return STREAM_TOO_SHORT; + } +} + +ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream, + size_t sourceStreamLen, size_t *readLen, uint8_t *destStream, + size_t maxDestStreamlen, size_t *decodedLen) { + if(escapeStxEtx) { + return decodeStreamEscaped(sourceStream, sourceStreamLen, + readLen, destStream, maxDestStreamlen, decodedLen); + } + else { + return decodeStreamNonEscaped(sourceStream, sourceStreamLen, + readLen, destStream, maxDestStreamlen, decodedLen); + } +} + +ReturnValue_t DleEncoder::decodeStreamEscaped(const uint8_t *sourceStream, size_t sourceStreamLen, + size_t *readLen, uint8_t *destStream, + size_t maxDestStreamlen, size_t *decodedLen) { + size_t encodedIndex = 0; + size_t decodedIndex = 0; + uint8_t nextByte; + + //init to 0 so that we can just return in the first checks (which do not consume anything from + //the source stream) + *readLen = 0; + + if(maxDestStreamlen < 1) { + return STREAM_TOO_SHORT; + } + if (sourceStream[encodedIndex++] != STX_CHAR) { + return DECODING_ERROR; + } + while ((encodedIndex < sourceStreamLen) and (decodedIndex < maxDestStreamlen)) { + switch(sourceStream[encodedIndex]) { + case(DLE_CHAR): { + if(encodedIndex + 1 >= sourceStreamLen) { + //reached the end of the sourceStream + *readLen = sourceStreamLen; + return DECODING_ERROR; + } + nextByte = sourceStream[encodedIndex + 1]; + // The next byte is a DLE character that was escaped by another + // DLE character, so we can write it to the destination stream. + if (nextByte == DLE_CHAR) { + destStream[decodedIndex] = nextByte; + } + else { + /* The next byte is a STX, DTX or 0x0D character which + * was escaped by a DLE character. The actual byte was + * also encoded by adding + 0x40 to prevent having control chars, + * in the stream at all, so we convert it back. */ + if ((nextByte == STX_CHAR + 0x40 or nextByte == ETX_CHAR + 0x40) or + (this->escapeCr and nextByte == CARRIAGE_RETURN + 0x40)) { + destStream[decodedIndex] = nextByte - 0x40; + } + else { + // Set readLen so user can resume parsing after incorrect data + *readLen = encodedIndex + 2; + return DECODING_ERROR; + } + } + ++encodedIndex; + break; + } + case(STX_CHAR): { + *readLen = encodedIndex; + return DECODING_ERROR; + } + case(ETX_CHAR): { + *readLen = ++encodedIndex; + *decodedLen = decodedIndex; + return RETURN_OK; + } + default: { + destStream[decodedIndex] = sourceStream[encodedIndex]; + break; + } + } + ++encodedIndex; + ++decodedIndex; + } + + if(decodedIndex == maxDestStreamlen) { + //so far we did not find anything wrong here, so let user try again + *readLen = 0; + return STREAM_TOO_SHORT; + } else { + *readLen = encodedIndex; + return DECODING_ERROR; + } +} + +ReturnValue_t DleEncoder::decodeStreamNonEscaped(const uint8_t *sourceStream, + size_t sourceStreamLen, size_t *readLen, uint8_t *destStream, + size_t maxDestStreamlen, size_t *decodedLen) { + size_t encodedIndex = 0; + size_t decodedIndex = 0; + uint8_t nextByte; + + //init to 0 so that we can just return in the first checks (which do not consume anything from + //the source stream) + *readLen = 0; + + if(maxDestStreamlen < 2) { + return STREAM_TOO_SHORT; + } + if (sourceStream[encodedIndex++] != DLE_CHAR) { + return DECODING_ERROR; + } + if (sourceStream[encodedIndex++] != STX_CHAR) { + *readLen = 1; + return DECODING_ERROR; + } + while ((encodedIndex < sourceStreamLen) && (decodedIndex < maxDestStreamlen)) { + if (sourceStream[encodedIndex] == DLE_CHAR) { + if(encodedIndex + 1 >= sourceStreamLen) { + *readLen = encodedIndex; + return DECODING_ERROR; + } + nextByte = sourceStream[encodedIndex + 1]; + if(nextByte == STX_CHAR) { + // Set readLen so the DLE/STX char combination is preserved. Could be start of + // another frame + *readLen = encodedIndex; + return DECODING_ERROR; + } + else if(nextByte == DLE_CHAR) { + // The next byte is a DLE character that was escaped by another + // DLE character, so we can write it to the destination stream. + destStream[decodedIndex] = nextByte; + ++encodedIndex; + } + else if(nextByte == ETX_CHAR) { + // End of stream reached + *readLen = encodedIndex + 2; + *decodedLen = decodedIndex; + return RETURN_OK; + } + else { + *readLen = encodedIndex; + return DECODING_ERROR; + } + } + else { + destStream[decodedIndex] = sourceStream[encodedIndex]; + } + ++encodedIndex; + ++decodedIndex; + } + + if(decodedIndex == maxDestStreamlen) { + //so far we did not find anything wrong here, so let user try again + *readLen = 0; + return STREAM_TOO_SHORT; + } else { + *readLen = encodedIndex; + return DECODING_ERROR; + } +} + +void DleEncoder::setEscapeMode(bool escapeStxEtx) { + this->escapeStxEtx = escapeStxEtx; +} diff --git a/src/fsfw/globalfunctions/DleEncoder.h b/src/fsfw/globalfunctions/DleEncoder.h new file mode 100644 index 000000000..09fa27262 --- /dev/null +++ b/src/fsfw/globalfunctions/DleEncoder.h @@ -0,0 +1,118 @@ +#ifndef FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ +#define FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include + +/** + * @brief This DLE Encoder (Data Link Encoder) can be used to encode and + * decode arbitrary data with ASCII control characters + * @details + * List of control codes: + * https://en.wikipedia.org/wiki/C0_and_C1_control_codes + * + * This encoder can be used to achieve a basic transport layer when using + * char based transmission systems. There are two implemented variants: + * + * 1. Escaped variant + * + * The encoded stream starts with a STX marker and ends with an ETX marker. + * STX and ETX occurrences in the stream are escaped and internally encoded as well so the + * receiver side can simply check for STX and ETX markers as frame delimiters. When using a + * strictly char based reception of packets encoded with DLE, + * STX can be used to notify a reader that actual data will start to arrive + * while ETX can be used to notify the reader that the data has ended. + * + * 2. Non-escaped variant + * + * The encoded stream starts with DLE STX and ends with DLE ETX. All DLE occurrences in the stream + * are escaped with DLE. If the receiver detects a DLE char, it needs to read the next char + * to determine whether a start (STX) or end (ETX) of a frame has been detected. + */ +class DleEncoder: public HasReturnvaluesIF { +public: + /** + * Create an encoder instance with the given configuration. + * @param escapeStxEtx Determines whether the algorithm works in escaped or non-escaped mode + * @param escapeCr In escaped mode, escape all CR occurrences as well + */ + DleEncoder(bool escapeStxEtx = true, bool escapeCr = false); + + void setEscapeMode(bool escapeStxEtx); + + virtual ~DleEncoder(); + + static constexpr uint8_t INTERFACE_ID = CLASS_ID::DLE_ENCODER; + static constexpr ReturnValue_t STREAM_TOO_SHORT = MAKE_RETURN_CODE(0x01); + static constexpr ReturnValue_t DECODING_ERROR = MAKE_RETURN_CODE(0x02); + + //! Start Of Text character. First character is encoded stream + static constexpr uint8_t STX_CHAR = 0x02; + //! End Of Text character. Last character in encoded stream + static constexpr uint8_t ETX_CHAR = 0x03; + //! Data Link Escape character. Used to escape STX, ETX and DLE occurrences + //! in the source stream. + static constexpr uint8_t DLE_CHAR = 0x10; + static constexpr uint8_t CARRIAGE_RETURN = 0x0D; + + /** + * Encodes the give data stream by preceding it with the STX marker + * and ending it with an ETX marker. DLE characters inside + * the stream are escaped by DLE characters. STX, ETX and CR characters can be escaped with a + * DLE character as well. The escaped characters are also encoded by adding + * 0x40 (which is reverted in the decoding process). This is performed so the source stream + * does not have STX/ETX/CR occurrences anymore, so the receiving side can simply parse for + * start and end markers + * @param sourceStream + * @param sourceLen + * @param destStream + * @param maxDestLen + * @param encodedLen + * @param addStxEtx Adding STX start marker and ETX end marker can be omitted, + * if they are added manually + * @return + * - RETURN_OK for successful encoding operation + * - STREAM_TOO_SHORT if the destination stream is too short + */ + ReturnValue_t encode(const uint8_t *sourceStream, size_t sourceLen, + uint8_t *destStream, size_t maxDestLen, size_t *encodedLen, + bool addStxEtx = true); + + /** + * Converts an encoded stream back. + * @param sourceStream + * @param sourceStreamLen + * @param readLen + * @param destStream + * @param maxDestStreamlen + * @param decodedLen + * @return + * - RETURN_OK for successful decode operation + * - DECODE_ERROR if the source stream is invalid + * - STREAM_TOO_SHORT if the destination stream is too short + */ + ReturnValue_t decode(const uint8_t *sourceStream, + size_t sourceStreamLen, size_t *readLen, uint8_t *destStream, + size_t maxDestStreamlen, size_t *decodedLen); + +private: + + ReturnValue_t encodeStreamEscaped(const uint8_t *sourceStream, size_t sourceLen, + uint8_t *destStream, size_t maxDestLen, size_t *encodedLen, + bool addStxEtx = true); + + ReturnValue_t encodeStreamNonEscaped(const uint8_t *sourceStream, size_t sourceLen, + uint8_t *destStream, size_t maxDestLen, size_t *encodedLen, + bool addStxEtx = true); + + ReturnValue_t decodeStreamEscaped(const uint8_t *sourceStream, size_t sourceStreamLen, + size_t *readLen, uint8_t *destStream, size_t maxDestStreamlen, size_t *decodedLen); + + ReturnValue_t decodeStreamNonEscaped(const uint8_t *sourceStream, size_t sourceStreamLen, + size_t *readLen, uint8_t *destStream, size_t maxDestStreamlen, size_t *decodedLen); + + bool escapeStxEtx; + bool escapeCr; +}; + +#endif /* FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ */ diff --git a/globalfunctions/PeriodicOperationDivider.cpp b/src/fsfw/globalfunctions/PeriodicOperationDivider.cpp similarity index 93% rename from globalfunctions/PeriodicOperationDivider.cpp rename to src/fsfw/globalfunctions/PeriodicOperationDivider.cpp index 28e98feba..62cc6f4c6 100644 --- a/globalfunctions/PeriodicOperationDivider.cpp +++ b/src/fsfw/globalfunctions/PeriodicOperationDivider.cpp @@ -1,4 +1,4 @@ -#include "PeriodicOperationDivider.h" +#include "fsfw/globalfunctions/PeriodicOperationDivider.h" PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider, diff --git a/globalfunctions/PeriodicOperationDivider.h b/src/fsfw/globalfunctions/PeriodicOperationDivider.h similarity index 100% rename from globalfunctions/PeriodicOperationDivider.h rename to src/fsfw/globalfunctions/PeriodicOperationDivider.h diff --git a/globalfunctions/Type.cpp b/src/fsfw/globalfunctions/Type.cpp similarity index 97% rename from globalfunctions/Type.cpp rename to src/fsfw/globalfunctions/Type.cpp index fa6d2f281..5f1e05d15 100644 --- a/globalfunctions/Type.cpp +++ b/src/fsfw/globalfunctions/Type.cpp @@ -1,5 +1,5 @@ -#include "Type.h" -#include "../serialize/SerializeAdapter.h" +#include "fsfw/globalfunctions/Type.h" +#include "fsfw/serialize/SerializeAdapter.h" Type::Type() : actualType(UNKNOWN_TYPE) { diff --git a/globalfunctions/Type.h b/src/fsfw/globalfunctions/Type.h similarity index 96% rename from globalfunctions/Type.h rename to src/fsfw/globalfunctions/Type.h index fa894e3e9..cfbb3cfa9 100644 --- a/globalfunctions/Type.h +++ b/src/fsfw/globalfunctions/Type.h @@ -1,8 +1,9 @@ #ifndef FSFW_GLOBALFUNCTIONS_TYPE_H_ #define FSFW_GLOBALFUNCTIONS_TYPE_H_ -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../serialize/SerializeIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/serialize/SerializeIF.h" + #include /** diff --git a/globalfunctions/arrayprinter.cpp b/src/fsfw/globalfunctions/arrayprinter.cpp similarity index 97% rename from globalfunctions/arrayprinter.cpp rename to src/fsfw/globalfunctions/arrayprinter.cpp index 3c729c6bb..45a1cb38c 100644 --- a/globalfunctions/arrayprinter.cpp +++ b/src/fsfw/globalfunctions/arrayprinter.cpp @@ -1,5 +1,6 @@ -#include "arrayprinter.h" -#include "../serviceinterface/ServiceInterface.h" +#include "fsfw/globalfunctions/arrayprinter.h" +#include "fsfw/serviceinterface/ServiceInterface.h" + #include diff --git a/globalfunctions/arrayprinter.h b/src/fsfw/globalfunctions/arrayprinter.h similarity index 100% rename from globalfunctions/arrayprinter.h rename to src/fsfw/globalfunctions/arrayprinter.h diff --git a/globalfunctions/bitutility.cpp b/src/fsfw/globalfunctions/bitutility.cpp similarity index 94% rename from globalfunctions/bitutility.cpp rename to src/fsfw/globalfunctions/bitutility.cpp index 5cc92dac5..628e30c2b 100644 --- a/globalfunctions/bitutility.cpp +++ b/src/fsfw/globalfunctions/bitutility.cpp @@ -1,4 +1,4 @@ -#include "bitutility.h" +#include "fsfw/globalfunctions/bitutility.h" void bitutil::bitSet(uint8_t *byte, uint8_t position) { if(position > 7) { diff --git a/globalfunctions/bitutility.h b/src/fsfw/globalfunctions/bitutility.h similarity index 100% rename from globalfunctions/bitutility.h rename to src/fsfw/globalfunctions/bitutility.h diff --git a/globalfunctions/constants.h b/src/fsfw/globalfunctions/constants.h similarity index 100% rename from globalfunctions/constants.h rename to src/fsfw/globalfunctions/constants.h diff --git a/globalfunctions/matching/BinaryMatcher.h b/src/fsfw/globalfunctions/matching/BinaryMatcher.h similarity index 100% rename from globalfunctions/matching/BinaryMatcher.h rename to src/fsfw/globalfunctions/matching/BinaryMatcher.h diff --git a/globalfunctions/matching/DecimalMatcher.h b/src/fsfw/globalfunctions/matching/DecimalMatcher.h similarity index 100% rename from globalfunctions/matching/DecimalMatcher.h rename to src/fsfw/globalfunctions/matching/DecimalMatcher.h diff --git a/globalfunctions/matching/MatchTree.h b/src/fsfw/globalfunctions/matching/MatchTree.h similarity index 100% rename from globalfunctions/matching/MatchTree.h rename to src/fsfw/globalfunctions/matching/MatchTree.h diff --git a/globalfunctions/matching/MatcherIF.h b/src/fsfw/globalfunctions/matching/MatcherIF.h similarity index 100% rename from globalfunctions/matching/MatcherIF.h rename to src/fsfw/globalfunctions/matching/MatcherIF.h diff --git a/globalfunctions/matching/RangeMatcher.h b/src/fsfw/globalfunctions/matching/RangeMatcher.h similarity index 100% rename from globalfunctions/matching/RangeMatcher.h rename to src/fsfw/globalfunctions/matching/RangeMatcher.h diff --git a/globalfunctions/matching/SerializeableMatcherIF.h b/src/fsfw/globalfunctions/matching/SerializeableMatcherIF.h similarity index 100% rename from globalfunctions/matching/SerializeableMatcherIF.h rename to src/fsfw/globalfunctions/matching/SerializeableMatcherIF.h diff --git a/globalfunctions/math/CMakeLists.txt b/src/fsfw/globalfunctions/math/CMakeLists.txt similarity index 100% rename from globalfunctions/math/CMakeLists.txt rename to src/fsfw/globalfunctions/math/CMakeLists.txt diff --git a/globalfunctions/math/MatrixOperations.h b/src/fsfw/globalfunctions/math/MatrixOperations.h similarity index 100% rename from globalfunctions/math/MatrixOperations.h rename to src/fsfw/globalfunctions/math/MatrixOperations.h diff --git a/globalfunctions/math/QuaternionOperations.cpp b/src/fsfw/globalfunctions/math/QuaternionOperations.cpp similarity index 97% rename from globalfunctions/math/QuaternionOperations.cpp rename to src/fsfw/globalfunctions/math/QuaternionOperations.cpp index c09426daa..31ba20445 100644 --- a/globalfunctions/math/QuaternionOperations.cpp +++ b/src/fsfw/globalfunctions/math/QuaternionOperations.cpp @@ -1,5 +1,5 @@ -#include "QuaternionOperations.h" -#include "VectorOperations.h" +#include "fsfw/globalfunctions/math/QuaternionOperations.h" +#include "fsfw/globalfunctions/math/VectorOperations.h" #include #include diff --git a/globalfunctions/math/QuaternionOperations.h b/src/fsfw/globalfunctions/math/QuaternionOperations.h similarity index 100% rename from globalfunctions/math/QuaternionOperations.h rename to src/fsfw/globalfunctions/math/QuaternionOperations.h diff --git a/globalfunctions/math/VectorOperations.h b/src/fsfw/globalfunctions/math/VectorOperations.h similarity index 100% rename from globalfunctions/math/VectorOperations.h rename to src/fsfw/globalfunctions/math/VectorOperations.h diff --git a/globalfunctions/sign.h b/src/fsfw/globalfunctions/sign.h similarity index 100% rename from globalfunctions/sign.h rename to src/fsfw/globalfunctions/sign.h diff --git a/globalfunctions/timevalOperations.cpp b/src/fsfw/globalfunctions/timevalOperations.cpp similarity index 98% rename from globalfunctions/timevalOperations.cpp rename to src/fsfw/globalfunctions/timevalOperations.cpp index 1228da047..e91e7f57b 100644 --- a/globalfunctions/timevalOperations.cpp +++ b/src/fsfw/globalfunctions/timevalOperations.cpp @@ -1,4 +1,4 @@ -#include "timevalOperations.h" +#include "fsfw/globalfunctions/timevalOperations.h" timeval& operator+=(timeval& lhs, const timeval& rhs) { int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec; diff --git a/globalfunctions/timevalOperations.h b/src/fsfw/globalfunctions/timevalOperations.h similarity index 100% rename from globalfunctions/timevalOperations.h rename to src/fsfw/globalfunctions/timevalOperations.h diff --git a/src/fsfw/health.h b/src/fsfw/health.h new file mode 100644 index 000000000..0b7c87933 --- /dev/null +++ b/src/fsfw/health.h @@ -0,0 +1,9 @@ +#ifndef FSFW_INC_FSFW_HEALTH_H_ +#define FSFW_INC_FSFW_HEALTH_H_ + +#include "src/core/health/HasHealthIF.h" +#include "src/core/health/HealthHelper.h" +#include "src/core/health/HealthMessage.h" +#include "src/core/health/HealthTable.h" + +#endif /* FSFW_INC_FSFW_HEALTH_H_ */ diff --git a/health/CMakeLists.txt b/src/fsfw/health/CMakeLists.txt similarity index 100% rename from health/CMakeLists.txt rename to src/fsfw/health/CMakeLists.txt diff --git a/health/HasHealthIF.h b/src/fsfw/health/HasHealthIF.h similarity index 100% rename from health/HasHealthIF.h rename to src/fsfw/health/HasHealthIF.h diff --git a/health/HealthHelper.cpp b/src/fsfw/health/HealthHelper.cpp similarity index 97% rename from health/HealthHelper.cpp rename to src/fsfw/health/HealthHelper.cpp index 28419108f..6bbbe25bf 100644 --- a/health/HealthHelper.cpp +++ b/src/fsfw/health/HealthHelper.cpp @@ -1,5 +1,6 @@ -#include "HealthHelper.h" -#include "../serviceinterface/ServiceInterface.h" +#include "fsfw/health/HealthHelper.h" + +#include "fsfw/serviceinterface/ServiceInterface.h" HealthHelper::HealthHelper(HasHealthIF* owner, object_id_t objectId) : objectId(objectId), owner(owner) { diff --git a/health/HealthHelper.h b/src/fsfw/health/HealthHelper.h similarity index 100% rename from health/HealthHelper.h rename to src/fsfw/health/HealthHelper.h diff --git a/health/HealthMessage.cpp b/src/fsfw/health/HealthMessage.cpp similarity index 95% rename from health/HealthMessage.cpp rename to src/fsfw/health/HealthMessage.cpp index 52479c263..31b6273b6 100644 --- a/health/HealthMessage.cpp +++ b/src/fsfw/health/HealthMessage.cpp @@ -1,4 +1,4 @@ -#include "HealthMessage.h" +#include "fsfw/health/HealthMessage.h" void HealthMessage::setHealthMessage(CommandMessage* message, Command_t command, HasHealthIF::HealthState health, HasHealthIF::HealthState oldHealth) { diff --git a/health/HealthMessage.h b/src/fsfw/health/HealthMessage.h similarity index 96% rename from health/HealthMessage.h rename to src/fsfw/health/HealthMessage.h index fb979c663..3dc58977d 100644 --- a/health/HealthMessage.h +++ b/src/fsfw/health/HealthMessage.h @@ -2,7 +2,7 @@ #define FSFW_HEALTH_HEALTHMESSAGE_H_ #include "HasHealthIF.h" -#include "../ipc/CommandMessage.h" +#include "fsfw/ipc/CommandMessage.h" class HealthMessage { public: diff --git a/health/HealthTable.cpp b/src/fsfw/health/HealthTable.cpp similarity index 95% rename from health/HealthTable.cpp rename to src/fsfw/health/HealthTable.cpp index 3fed1deb1..a3300462c 100644 --- a/health/HealthTable.cpp +++ b/src/fsfw/health/HealthTable.cpp @@ -1,7 +1,8 @@ -#include "HealthTable.h" -#include "../ipc/MutexGuard.h" -#include "../ipc/MutexFactory.h" -#include "../serialize/SerializeAdapter.h" +#include "fsfw/health/HealthTable.h" + +#include "fsfw/ipc/MutexGuard.h" +#include "fsfw/ipc/MutexFactory.h" +#include "fsfw/serialize/SerializeAdapter.h" HealthTable::HealthTable(object_id_t objectid) : SystemObject(objectid) { diff --git a/health/HealthTable.h b/src/fsfw/health/HealthTable.h similarity index 100% rename from health/HealthTable.h rename to src/fsfw/health/HealthTable.h diff --git a/health/HealthTableIF.h b/src/fsfw/health/HealthTableIF.h similarity index 100% rename from health/HealthTableIF.h rename to src/fsfw/health/HealthTableIF.h diff --git a/health/ManagesHealthIF.h b/src/fsfw/health/ManagesHealthIF.h similarity index 100% rename from health/ManagesHealthIF.h rename to src/fsfw/health/ManagesHealthIF.h diff --git a/src/fsfw/housekeeping.h b/src/fsfw/housekeeping.h new file mode 100644 index 000000000..0627d523d --- /dev/null +++ b/src/fsfw/housekeeping.h @@ -0,0 +1,9 @@ +#ifndef FSFW_INC_FSFW_HOUSEKEEPING_H_ +#define FSFW_INC_FSFW_HOUSEKEEPING_H_ + +#include "src/core/housekeeping/HousekeepingMessage.h" +#include "src/core/housekeeping/HousekeepingPacketDownlink.h" +#include "src/core/housekeeping/HousekeepingSetPacket.h" +#include "src/core/housekeeping/HousekeepingSnapshot.h" + +#endif /* FSFW_INC_FSFW_HOUSEKEEPING_H_ */ diff --git a/housekeeping/AcceptsHkPacketsIF.h b/src/fsfw/housekeeping/AcceptsHkPacketsIF.h similarity index 100% rename from housekeeping/AcceptsHkPacketsIF.h rename to src/fsfw/housekeeping/AcceptsHkPacketsIF.h diff --git a/housekeeping/CMakeLists.txt b/src/fsfw/housekeeping/CMakeLists.txt similarity index 100% rename from housekeeping/CMakeLists.txt rename to src/fsfw/housekeeping/CMakeLists.txt diff --git a/housekeeping/HousekeepingMessage.cpp b/src/fsfw/housekeeping/HousekeepingMessage.cpp similarity index 98% rename from housekeeping/HousekeepingMessage.cpp rename to src/fsfw/housekeeping/HousekeepingMessage.cpp index 71f7ff172..432a86203 100644 --- a/housekeeping/HousekeepingMessage.cpp +++ b/src/fsfw/housekeeping/HousekeepingMessage.cpp @@ -1,6 +1,7 @@ -#include "HousekeepingMessage.h" +#include "fsfw/housekeeping/HousekeepingMessage.h" + +#include "fsfw/objectmanager/ObjectManager.h" -#include "../objectmanager/ObjectManager.h" #include HousekeepingMessage::~HousekeepingMessage() {} diff --git a/housekeeping/HousekeepingMessage.h b/src/fsfw/housekeeping/HousekeepingMessage.h similarity index 95% rename from housekeeping/HousekeepingMessage.h rename to src/fsfw/housekeeping/HousekeepingMessage.h index a38ff73fd..509a68c9f 100644 --- a/housekeeping/HousekeepingMessage.h +++ b/src/fsfw/housekeeping/HousekeepingMessage.h @@ -1,11 +1,11 @@ #ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGMESSAGE_H_ #define FSFW_HOUSEKEEPING_HOUSEKEEPINGMESSAGE_H_ -#include "../datapoollocal/localPoolDefinitions.h" -#include "../ipc/CommandMessage.h" -#include "../ipc/FwMessageTypes.h" -#include "../objectmanager/frameworkObjects.h" -#include "../storagemanager/StorageManagerIF.h" +#include "fsfw/datapoollocal/localPoolDefinitions.h" +#include "fsfw/ipc/CommandMessage.h" +#include "fsfw/ipc/FwMessageTypes.h" +#include "fsfw/objectmanager/frameworkObjects.h" +#include "fsfw/storagemanager/StorageManagerIF.h" /** diff --git a/housekeeping/HousekeepingPacketDownlink.h b/src/fsfw/housekeeping/HousekeepingPacketDownlink.h similarity index 100% rename from housekeeping/HousekeepingPacketDownlink.h rename to src/fsfw/housekeeping/HousekeepingPacketDownlink.h diff --git a/housekeeping/HousekeepingSetPacket.h b/src/fsfw/housekeeping/HousekeepingSetPacket.h similarity index 100% rename from housekeeping/HousekeepingSetPacket.h rename to src/fsfw/housekeeping/HousekeepingSetPacket.h diff --git a/housekeeping/HousekeepingSnapshot.h b/src/fsfw/housekeeping/HousekeepingSnapshot.h similarity index 100% rename from housekeeping/HousekeepingSnapshot.h rename to src/fsfw/housekeeping/HousekeepingSnapshot.h diff --git a/housekeeping/PeriodicHousekeepingHelper.cpp b/src/fsfw/housekeeping/PeriodicHousekeepingHelper.cpp similarity index 96% rename from housekeeping/PeriodicHousekeepingHelper.cpp rename to src/fsfw/housekeeping/PeriodicHousekeepingHelper.cpp index 892eb354a..68740d339 100644 --- a/housekeeping/PeriodicHousekeepingHelper.cpp +++ b/src/fsfw/housekeeping/PeriodicHousekeepingHelper.cpp @@ -1,6 +1,6 @@ -#include "PeriodicHousekeepingHelper.h" +#include "fsfw/housekeeping/PeriodicHousekeepingHelper.h" -#include "../datapoollocal/LocalPoolDataSetBase.h" +#include "fsfw/datapoollocal/LocalPoolDataSetBase.h" #include PeriodicHousekeepingHelper::PeriodicHousekeepingHelper( diff --git a/housekeeping/PeriodicHousekeepingHelper.h b/src/fsfw/housekeeping/PeriodicHousekeepingHelper.h similarity index 96% rename from housekeeping/PeriodicHousekeepingHelper.h rename to src/fsfw/housekeeping/PeriodicHousekeepingHelper.h index 3256fbffa..4e93308be 100644 --- a/housekeeping/PeriodicHousekeepingHelper.h +++ b/src/fsfw/housekeeping/PeriodicHousekeepingHelper.h @@ -1,7 +1,7 @@ #ifndef FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_ #define FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_ -#include "../timemanager/Clock.h" +#include "fsfw/timemanager/Clock.h" #include class LocalPoolDataSetBase; diff --git a/internalError/CMakeLists.txt b/src/fsfw/internalerror/CMakeLists.txt similarity index 100% rename from internalError/CMakeLists.txt rename to src/fsfw/internalerror/CMakeLists.txt diff --git a/internalError/InternalErrorDataset.h b/src/fsfw/internalerror/InternalErrorDataset.h similarity index 100% rename from internalError/InternalErrorDataset.h rename to src/fsfw/internalerror/InternalErrorDataset.h diff --git a/internalError/InternalErrorReporter.cpp b/src/fsfw/internalerror/InternalErrorReporter.cpp similarity index 96% rename from internalError/InternalErrorReporter.cpp rename to src/fsfw/internalerror/InternalErrorReporter.cpp index 786184484..8689ab3e3 100644 --- a/internalError/InternalErrorReporter.cpp +++ b/src/fsfw/internalerror/InternalErrorReporter.cpp @@ -1,9 +1,9 @@ -#include "InternalErrorReporter.h" +#include "fsfw/internalerror/InternalErrorReporter.h" -#include "../ipc/QueueFactory.h" -#include "../ipc/MutexFactory.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../datapool/PoolReadGuard.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/ipc/MutexFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/datapool/PoolReadGuard.h" InternalErrorReporter::InternalErrorReporter(object_id_t setObjectId, uint32_t messageQueueDepth): SystemObject(setObjectId), diff --git a/internalError/InternalErrorReporter.h b/src/fsfw/internalerror/InternalErrorReporter.h similarity index 91% rename from internalError/InternalErrorReporter.h rename to src/fsfw/internalerror/InternalErrorReporter.h index 580cb8f6c..57a6a1355 100644 --- a/internalError/InternalErrorReporter.h +++ b/src/fsfw/internalerror/InternalErrorReporter.h @@ -3,12 +3,12 @@ #include "InternalErrorReporterIF.h" -#include "../tasks/PeriodicTaskIF.h" -#include "../internalError/InternalErrorDataset.h" -#include "../datapoollocal/LocalDataPoolManager.h" -#include "../tasks/ExecutableObjectIF.h" -#include "../objectmanager/SystemObject.h" -#include "../ipc/MutexIF.h" +#include "fsfw/tasks/PeriodicTaskIF.h" +#include "fsfw/internalerror/InternalErrorDataset.h" +#include "fsfw/datapoollocal/LocalDataPoolManager.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/ipc/MutexIF.h" /** * @brief This class is used to track internal errors like lost telemetry, diff --git a/internalError/InternalErrorReporterIF.h b/src/fsfw/internalerror/InternalErrorReporterIF.h similarity index 100% rename from internalError/InternalErrorReporterIF.h rename to src/fsfw/internalerror/InternalErrorReporterIF.h diff --git a/ipc/CMakeLists.txt b/src/fsfw/ipc/CMakeLists.txt similarity index 100% rename from ipc/CMakeLists.txt rename to src/fsfw/ipc/CMakeLists.txt diff --git a/ipc/CommandMessage.cpp b/src/fsfw/ipc/CommandMessage.cpp similarity index 97% rename from ipc/CommandMessage.cpp rename to src/fsfw/ipc/CommandMessage.cpp index 513debd3d..9448d1528 100644 --- a/ipc/CommandMessage.cpp +++ b/src/fsfw/ipc/CommandMessage.cpp @@ -1,5 +1,6 @@ -#include "CommandMessage.h" -#include "CommandMessageCleaner.h" +#include "fsfw/ipc/CommandMessage.h" +#include "fsfw/ipc/CommandMessageCleaner.h" + #include CommandMessage::CommandMessage() { diff --git a/ipc/CommandMessage.h b/src/fsfw/ipc/CommandMessage.h similarity index 100% rename from ipc/CommandMessage.h rename to src/fsfw/ipc/CommandMessage.h diff --git a/ipc/CommandMessageCleaner.cpp b/src/fsfw/ipc/CommandMessageCleaner.cpp similarity index 64% rename from ipc/CommandMessageCleaner.cpp rename to src/fsfw/ipc/CommandMessageCleaner.cpp index 29998124e..0918d7393 100644 --- a/ipc/CommandMessageCleaner.cpp +++ b/src/fsfw/ipc/CommandMessageCleaner.cpp @@ -1,15 +1,18 @@ -#include "CommandMessageCleaner.h" +#include "fsfw/FSFW.h" +#include "fsfw/ipc/CommandMessageCleaner.h" -#include "../memory/GenericFileSystemMessage.h" -#include "../devicehandlers/DeviceHandlerMessage.h" -#include "../health/HealthMessage.h" -#include "../memory/MemoryMessage.h" -#include "../modes/ModeMessage.h" -#include "../monitoring/MonitoringMessage.h" -#include "../subsystem/modes/ModeSequenceMessage.h" -#include "../tmstorage/TmStoreMessage.h" -#include "../housekeeping/HousekeepingMessage.h" -#include "../parameters/ParameterMessage.h" +#include "fsfw/memory/GenericFileSystemMessage.h" +#include "fsfw/devicehandlers/DeviceHandlerMessage.h" +#include "fsfw/health/HealthMessage.h" +#include "fsfw/memory/MemoryMessage.h" +#include "fsfw/modes/ModeMessage.h" +#include "fsfw/monitoring/MonitoringMessage.h" +#include "fsfw/subsystem/modes/ModeSequenceMessage.h" +#include "fsfw/housekeeping/HousekeepingMessage.h" +#include "fsfw/parameters/ParameterMessage.h" +#ifdef FSFW_ADD_TMSTORAGE +#include "fsfw/tmstorage/TmStoreMessage.h" +#endif void CommandMessageCleaner::clearCommandMessage(CommandMessage* message) { switch(message->getMessageType()){ @@ -34,9 +37,11 @@ void CommandMessageCleaner::clearCommandMessage(CommandMessage* message) { case messagetypes::MONITORING: MonitoringMessage::clear(message); break; +#ifdef FSFW_ADD_TMSTORAGE case messagetypes::TM_STORE: TmStoreMessage::clear(message); break; +#endif case messagetypes::PARAMETER: ParameterMessage::clear(message); break; diff --git a/ipc/CommandMessageCleaner.h b/src/fsfw/ipc/CommandMessageCleaner.h similarity index 100% rename from ipc/CommandMessageCleaner.h rename to src/fsfw/ipc/CommandMessageCleaner.h diff --git a/ipc/CommandMessageIF.h b/src/fsfw/ipc/CommandMessageIF.h similarity index 100% rename from ipc/CommandMessageIF.h rename to src/fsfw/ipc/CommandMessageIF.h diff --git a/ipc/FwMessageTypes.h b/src/fsfw/ipc/FwMessageTypes.h similarity index 100% rename from ipc/FwMessageTypes.h rename to src/fsfw/ipc/FwMessageTypes.h diff --git a/ipc/MessageQueueIF.h b/src/fsfw/ipc/MessageQueueIF.h similarity index 100% rename from ipc/MessageQueueIF.h rename to src/fsfw/ipc/MessageQueueIF.h diff --git a/ipc/MessageQueueMessage.cpp b/src/fsfw/ipc/MessageQueueMessage.cpp similarity index 94% rename from ipc/MessageQueueMessage.cpp rename to src/fsfw/ipc/MessageQueueMessage.cpp index 1958af54a..62b826e92 100644 --- a/ipc/MessageQueueMessage.cpp +++ b/src/fsfw/ipc/MessageQueueMessage.cpp @@ -1,6 +1,7 @@ -#include "MessageQueueMessage.h" -#include "../serviceinterface/ServiceInterfaceStream.h" -#include "../globalfunctions/arrayprinter.h" +#include "fsfw/ipc/MessageQueueMessage.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/globalfunctions/arrayprinter.h" + #include MessageQueueMessage::MessageQueueMessage() : diff --git a/ipc/MessageQueueMessage.h b/src/fsfw/ipc/MessageQueueMessage.h similarity index 99% rename from ipc/MessageQueueMessage.h rename to src/fsfw/ipc/MessageQueueMessage.h index 111056caf..e9ef67561 100644 --- a/ipc/MessageQueueMessage.h +++ b/src/fsfw/ipc/MessageQueueMessage.h @@ -1,7 +1,7 @@ #ifndef FSFW_IPC_MESSAGEQUEUEMESSAGE_H_ #define FSFW_IPC_MESSAGEQUEUEMESSAGE_H_ -#include "../ipc/MessageQueueMessageIF.h" +#include "fsfw/ipc/MessageQueueMessageIF.h" #include /** diff --git a/ipc/MessageQueueMessageIF.h b/src/fsfw/ipc/MessageQueueMessageIF.h similarity index 100% rename from ipc/MessageQueueMessageIF.h rename to src/fsfw/ipc/MessageQueueMessageIF.h diff --git a/ipc/MessageQueueSenderIF.h b/src/fsfw/ipc/MessageQueueSenderIF.h similarity index 100% rename from ipc/MessageQueueSenderIF.h rename to src/fsfw/ipc/MessageQueueSenderIF.h diff --git a/ipc/MutexFactory.h b/src/fsfw/ipc/MutexFactory.h similarity index 100% rename from ipc/MutexFactory.h rename to src/fsfw/ipc/MutexFactory.h diff --git a/ipc/MutexGuard.h b/src/fsfw/ipc/MutexGuard.h similarity index 100% rename from ipc/MutexGuard.h rename to src/fsfw/ipc/MutexGuard.h diff --git a/ipc/MutexIF.h b/src/fsfw/ipc/MutexIF.h similarity index 100% rename from ipc/MutexIF.h rename to src/fsfw/ipc/MutexIF.h diff --git a/ipc/QueueFactory.h b/src/fsfw/ipc/QueueFactory.h similarity index 100% rename from ipc/QueueFactory.h rename to src/fsfw/ipc/QueueFactory.h diff --git a/ipc/messageQueueDefinitions.h b/src/fsfw/ipc/messageQueueDefinitions.h similarity index 100% rename from ipc/messageQueueDefinitions.h rename to src/fsfw/ipc/messageQueueDefinitions.h diff --git a/memory/AcceptsMemoryMessagesIF.h b/src/fsfw/memory/AcceptsMemoryMessagesIF.h similarity index 100% rename from memory/AcceptsMemoryMessagesIF.h rename to src/fsfw/memory/AcceptsMemoryMessagesIF.h diff --git a/memory/CMakeLists.txt b/src/fsfw/memory/CMakeLists.txt similarity index 100% rename from memory/CMakeLists.txt rename to src/fsfw/memory/CMakeLists.txt diff --git a/memory/GenericFileSystemMessage.cpp b/src/fsfw/memory/GenericFileSystemMessage.cpp similarity index 91% rename from memory/GenericFileSystemMessage.cpp rename to src/fsfw/memory/GenericFileSystemMessage.cpp index b0e1a9ec8..bd36d87b2 100644 --- a/memory/GenericFileSystemMessage.cpp +++ b/src/fsfw/memory/GenericFileSystemMessage.cpp @@ -1,7 +1,7 @@ -#include "GenericFileSystemMessage.h" +#include "fsfw/memory/GenericFileSystemMessage.h" -#include "../objectmanager/ObjectManager.h" -#include "../storagemanager/StorageManagerIF.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/storagemanager/StorageManagerIF.h" void GenericFileSystemMessage::setCreateFileCommand(CommandMessage* message, store_address_t storeId) { @@ -34,8 +34,9 @@ void GenericFileSystemMessage::setReportFileAttributesReply(CommandMessage *mess } void GenericFileSystemMessage::setDeleteDirectoryCommand(CommandMessage* message, - store_address_t storeId) { + store_address_t storeId, bool deleteRecursively) { message->setCommand(CMD_DELETE_DIRECTORY); + message->setParameter(deleteRecursively); message->setParameter2(storeId.raw); } @@ -133,6 +134,12 @@ bool GenericFileSystemMessage::getReadReply(const CommandMessage *message, return message->getParameter(); } +store_address_t GenericFileSystemMessage::getDeleteDirectoryCommand(const CommandMessage *message, + bool &deleteRecursively) { + deleteRecursively = message->getParameter(); + return getStoreId(message); +} + ReturnValue_t GenericFileSystemMessage::clear(CommandMessage* message) { switch(message->getCommand()) { case(CMD_CREATE_FILE): diff --git a/memory/GenericFileSystemMessage.h b/src/fsfw/memory/GenericFileSystemMessage.h similarity index 96% rename from memory/GenericFileSystemMessage.h rename to src/fsfw/memory/GenericFileSystemMessage.h index 6351dab90..fcd2075d1 100644 --- a/memory/GenericFileSystemMessage.h +++ b/src/fsfw/memory/GenericFileSystemMessage.h @@ -79,7 +79,9 @@ public: static void setCreateDirectoryCommand(CommandMessage* message, store_address_t storeId); static void setDeleteDirectoryCommand(CommandMessage* message, - store_address_t storeId); + store_address_t storeId, bool deleteRecursively); + static store_address_t getDeleteDirectoryCommand(const CommandMessage* message, + bool& deleteRecursively); static void setSuccessReply(CommandMessage* message); static void setFailureReply(CommandMessage* message, diff --git a/memory/HasFileSystemIF.h b/src/fsfw/memory/HasFileSystemIF.h similarity index 79% rename from memory/HasFileSystemIF.h rename to src/fsfw/memory/HasFileSystemIF.h index 73c934105..ec941f596 100644 --- a/memory/HasFileSystemIF.h +++ b/src/fsfw/memory/HasFileSystemIF.h @@ -36,9 +36,8 @@ public: //! [EXPORT] : P1: Sequence number missing static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_READ = MAKE_RETURN_CODE(16); - - virtual ~HasFileSystemIF() {} + /** * Function to get the MessageQueueId_t of the implementing object * @return MessageQueueId_t of the object @@ -46,7 +45,7 @@ public: virtual MessageQueueId_t getCommandQueue() const = 0; /** - * Generic function to append to file. + * @brief Generic function to append to file. * @param dirname Directory of the file * @param filename The filename of the file * @param data The data to write to the file @@ -63,12 +62,12 @@ public: uint16_t packetNumber, void* args = nullptr) = 0; /** - * Generic function to create a new file. + * @brief Generic function to create a new file. * @param repositoryPath * @param filename * @param data * @param size - * @param args Any other arguments which an implementation might require. + * @param args Any other arguments which an implementation might require * @return */ virtual ReturnValue_t createFile(const char* repositoryPath, @@ -76,14 +75,30 @@ public: size_t size = 0, void* args = nullptr) = 0; /** - * Generic function to delete a file. + * @brief Generic function to delete a file. * @param repositoryPath * @param filename - * @param args + * @param args Any other arguments which an implementation might require * @return */ virtual ReturnValue_t deleteFile(const char* repositoryPath, const char* filename, void* args = nullptr) = 0; + + /** + * @brief Generic function to create a directory + * @param repositoryPath + * @param args Any other arguments which an implementation might require + * @return + */ + virtual ReturnValue_t createDirectory(const char* repositoryPath, void* args = nullptr) = 0; + + /** + * @brief Generic function to remove a directory + * @param repositoryPath + * @param args Any other arguments which an implementation might require + */ + virtual ReturnValue_t removeDirectory(const char* repositoryPath, + bool deleteRecurively = false, void* args = nullptr) = 0; }; diff --git a/memory/HasMemoryIF.h b/src/fsfw/memory/HasMemoryIF.h similarity index 100% rename from memory/HasMemoryIF.h rename to src/fsfw/memory/HasMemoryIF.h diff --git a/memory/MemoryHelper.cpp b/src/fsfw/memory/MemoryHelper.cpp similarity index 95% rename from memory/MemoryHelper.cpp rename to src/fsfw/memory/MemoryHelper.cpp index d83a9fabf..2039a488f 100644 --- a/memory/MemoryHelper.cpp +++ b/src/fsfw/memory/MemoryHelper.cpp @@ -1,10 +1,10 @@ -#include "MemoryHelper.h" -#include "MemoryMessage.h" +#include "fsfw/memory/MemoryHelper.h" +#include "fsfw/memory/MemoryMessage.h" -#include "../globalfunctions/CRC.h" -#include "../objectmanager/ObjectManager.h" -#include "../serialize/EndianConverter.h" -#include "../serviceinterface/ServiceInterface.h" +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serialize/EndianConverter.h" +#include "fsfw/serviceinterface/ServiceInterface.h" MemoryHelper::MemoryHelper(HasMemoryIF* workOnThis, MessageQueueIF* useThisQueue): diff --git a/memory/MemoryHelper.h b/src/fsfw/memory/MemoryHelper.h similarity index 100% rename from memory/MemoryHelper.h rename to src/fsfw/memory/MemoryHelper.h diff --git a/memory/MemoryMessage.cpp b/src/fsfw/memory/MemoryMessage.cpp similarity index 97% rename from memory/MemoryMessage.cpp rename to src/fsfw/memory/MemoryMessage.cpp index 1f050ef8b..9df526096 100644 --- a/memory/MemoryMessage.cpp +++ b/src/fsfw/memory/MemoryMessage.cpp @@ -1,6 +1,6 @@ -#include "MemoryMessage.h" +#include "fsfw/memory/MemoryMessage.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/objectmanager/ObjectManager.h" uint32_t MemoryMessage::getAddress(const CommandMessage* message) { return message->getParameter(); diff --git a/memory/MemoryMessage.h b/src/fsfw/memory/MemoryMessage.h similarity index 100% rename from memory/MemoryMessage.h rename to src/fsfw/memory/MemoryMessage.h diff --git a/modes/CMakeLists.txt b/src/fsfw/modes/CMakeLists.txt similarity index 100% rename from modes/CMakeLists.txt rename to src/fsfw/modes/CMakeLists.txt diff --git a/modes/HasModesIF.h b/src/fsfw/modes/HasModesIF.h similarity index 100% rename from modes/HasModesIF.h rename to src/fsfw/modes/HasModesIF.h diff --git a/modes/ModeHelper.cpp b/src/fsfw/modes/ModeHelper.cpp similarity index 95% rename from modes/ModeHelper.cpp rename to src/fsfw/modes/ModeHelper.cpp index 6be4f776d..d2c5067d0 100644 --- a/modes/ModeHelper.cpp +++ b/src/fsfw/modes/ModeHelper.cpp @@ -1,8 +1,8 @@ -#include "HasModesIF.h" -#include "ModeHelper.h" +#include "fsfw/modes/HasModesIF.h" +#include "fsfw/modes/ModeHelper.h" -#include "../ipc/MessageQueueSenderIF.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" ModeHelper::ModeHelper(HasModesIF *owner) : commandedMode(HasModesIF::MODE_OFF), diff --git a/modes/ModeHelper.h b/src/fsfw/modes/ModeHelper.h similarity index 89% rename from modes/ModeHelper.h rename to src/fsfw/modes/ModeHelper.h index c2f089ec4..27928a295 100644 --- a/modes/ModeHelper.h +++ b/src/fsfw/modes/ModeHelper.h @@ -2,9 +2,9 @@ #define FSFW_MODES_MODEHELPER_H_ #include "ModeMessage.h" -#include "../ipc/MessageQueueIF.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../timemanager/Countdown.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/timemanager/Countdown.h" class HasModesIF; diff --git a/modes/ModeMessage.cpp b/src/fsfw/modes/ModeMessage.cpp similarity index 95% rename from modes/ModeMessage.cpp rename to src/fsfw/modes/ModeMessage.cpp index b33bba60b..a228304d6 100644 --- a/modes/ModeMessage.cpp +++ b/src/fsfw/modes/ModeMessage.cpp @@ -1,4 +1,4 @@ -#include "ModeMessage.h" +#include "fsfw/modes/ModeMessage.h" Mode_t ModeMessage::getMode(const CommandMessage* message) { return message->getParameter(); diff --git a/modes/ModeMessage.h b/src/fsfw/modes/ModeMessage.h similarity index 100% rename from modes/ModeMessage.h rename to src/fsfw/modes/ModeMessage.h diff --git a/monitoring/AbsLimitMonitor.h b/src/fsfw/monitoring/AbsLimitMonitor.h similarity index 98% rename from monitoring/AbsLimitMonitor.h rename to src/fsfw/monitoring/AbsLimitMonitor.h index 5feb369c0..f3bbf04c2 100644 --- a/monitoring/AbsLimitMonitor.h +++ b/src/fsfw/monitoring/AbsLimitMonitor.h @@ -1,6 +1,7 @@ #ifndef FSFW_MONITORING_ABSLIMITMONITOR_H_ #define FSFW_MONITORING_ABSLIMITMONITOR_H_ +#include "monitoringConf.h" #include "MonitorBase.h" #include diff --git a/monitoring/CMakeLists.txt b/src/fsfw/monitoring/CMakeLists.txt similarity index 100% rename from monitoring/CMakeLists.txt rename to src/fsfw/monitoring/CMakeLists.txt diff --git a/monitoring/HasMonitorsIF.h b/src/fsfw/monitoring/HasMonitorsIF.h similarity index 96% rename from monitoring/HasMonitorsIF.h rename to src/fsfw/monitoring/HasMonitorsIF.h index 04f634374..205209523 100644 --- a/monitoring/HasMonitorsIF.h +++ b/src/fsfw/monitoring/HasMonitorsIF.h @@ -1,6 +1,7 @@ #ifndef FSFW_MONITORING_HASMONITORSIF_H_ #define FSFW_MONITORING_HASMONITORSIF_H_ +#include "monitoringConf.h" #include "../events/EventReportingProxyIF.h" #include "../objectmanager/ObjectManagerIF.h" #include "../ipc/MessageQueueSenderIF.h" diff --git a/monitoring/LimitMonitor.h b/src/fsfw/monitoring/LimitMonitor.h similarity index 99% rename from monitoring/LimitMonitor.h rename to src/fsfw/monitoring/LimitMonitor.h index cd8b8d130..2565ebaaf 100644 --- a/monitoring/LimitMonitor.h +++ b/src/fsfw/monitoring/LimitMonitor.h @@ -1,6 +1,7 @@ #ifndef FRAMEWORK_MONITORING_LIMITMONITOR_H_ #define FRAMEWORK_MONITORING_LIMITMONITOR_H_ +#include "monitoringConf.h" #include "MonitorBase.h" /** diff --git a/monitoring/LimitViolationReporter.cpp b/src/fsfw/monitoring/LimitViolationReporter.cpp similarity index 87% rename from monitoring/LimitViolationReporter.cpp rename to src/fsfw/monitoring/LimitViolationReporter.cpp index 2de1e008a..a0b8a4cb7 100644 --- a/monitoring/LimitViolationReporter.cpp +++ b/src/fsfw/monitoring/LimitViolationReporter.cpp @@ -1,9 +1,9 @@ -#include "LimitViolationReporter.h" -#include "MonitoringIF.h" -#include "ReceivesMonitoringReportsIF.h" +#include "fsfw/monitoring/LimitViolationReporter.h" +#include "fsfw/monitoring/MonitoringIF.h" +#include "fsfw/monitoring/ReceivesMonitoringReportsIF.h" -#include "../objectmanager/ObjectManager.h" -#include "../serialize/SerializeAdapter.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serialize/SerializeAdapter.h" ReturnValue_t LimitViolationReporter::sendLimitViolationReport(const SerializeIF* data) { ReturnValue_t result = checkClassLoaded(); diff --git a/monitoring/LimitViolationReporter.h b/src/fsfw/monitoring/LimitViolationReporter.h similarity index 96% rename from monitoring/LimitViolationReporter.h rename to src/fsfw/monitoring/LimitViolationReporter.h index a71b972ff..b254e3120 100644 --- a/monitoring/LimitViolationReporter.h +++ b/src/fsfw/monitoring/LimitViolationReporter.h @@ -7,6 +7,7 @@ #ifndef LIMITVIOLATIONREPORTER_H_ #define LIMITVIOLATIONREPORTER_H_ +#include "monitoringConf.h" #include "../returnvalues/HasReturnvaluesIF.h" #include "../serialize/SerializeIF.h" #include "../storagemanager/StorageManagerIF.h" diff --git a/monitoring/MonitorBase.h b/src/fsfw/monitoring/MonitorBase.h similarity index 98% rename from monitoring/MonitorBase.h rename to src/fsfw/monitoring/MonitorBase.h index 967f0f62f..261b3eac8 100644 --- a/monitoring/MonitorBase.h +++ b/src/fsfw/monitoring/MonitorBase.h @@ -1,6 +1,7 @@ #ifndef FSFW_MONITORING_MONITORBASE_H_ #define FSFW_MONITORING_MONITORBASE_H_ +#include "monitoringConf.h" #include "LimitViolationReporter.h" #include "MonitoringIF.h" #include "MonitoringMessageContent.h" diff --git a/monitoring/MonitorReporter.h b/src/fsfw/monitoring/MonitorReporter.h similarity index 99% rename from monitoring/MonitorReporter.h rename to src/fsfw/monitoring/MonitorReporter.h index d155594d6..e27d0101a 100644 --- a/monitoring/MonitorReporter.h +++ b/src/fsfw/monitoring/MonitorReporter.h @@ -1,6 +1,7 @@ #ifndef FSFW_MONITORING_MONITORREPORTER_H_ #define FSFW_MONITORING_MONITORREPORTER_H_ +#include "monitoringConf.h" #include "LimitViolationReporter.h" #include "MonitoringIF.h" #include "MonitoringMessageContent.h" diff --git a/monitoring/MonitoringIF.h b/src/fsfw/monitoring/MonitoringIF.h similarity index 98% rename from monitoring/MonitoringIF.h rename to src/fsfw/monitoring/MonitoringIF.h index 32c625307..9c35b419c 100644 --- a/monitoring/MonitoringIF.h +++ b/src/fsfw/monitoring/MonitoringIF.h @@ -1,8 +1,8 @@ #ifndef FSFW_MONITORING_MONITORINGIF_H_ #define FSFW_MONITORING_MONITORINGIF_H_ +#include "monitoringConf.h" #include "MonitoringMessage.h" -#include "../memory/HasMemoryIF.h" #include "../serialize/SerializeIF.h" class MonitoringIF : public SerializeIF { @@ -62,6 +62,4 @@ public: } }; - - #endif /* FSFW_MONITORING_MONITORINGIF_H_ */ diff --git a/monitoring/MonitoringMessage.cpp b/src/fsfw/monitoring/MonitoringMessage.cpp similarity index 91% rename from monitoring/MonitoringMessage.cpp rename to src/fsfw/monitoring/MonitoringMessage.cpp index 6e5f49ccb..8bbb77650 100644 --- a/monitoring/MonitoringMessage.cpp +++ b/src/fsfw/monitoring/MonitoringMessage.cpp @@ -1,5 +1,5 @@ -#include "MonitoringMessage.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/monitoring/MonitoringMessage.h" +#include "fsfw/objectmanager/ObjectManager.h" MonitoringMessage::~MonitoringMessage() { } diff --git a/monitoring/MonitoringMessage.h b/src/fsfw/monitoring/MonitoringMessage.h similarity index 86% rename from monitoring/MonitoringMessage.h rename to src/fsfw/monitoring/MonitoringMessage.h index 84b027504..a625e388b 100644 --- a/monitoring/MonitoringMessage.h +++ b/src/fsfw/monitoring/MonitoringMessage.h @@ -1,8 +1,9 @@ #ifndef MONITORINGMESSAGE_H_ #define MONITORINGMESSAGE_H_ -#include "../ipc/CommandMessage.h" -#include "../storagemanager/StorageManagerIF.h" +#include "monitoringConf.h" +#include "fsfw/ipc/CommandMessage.h" +#include "fsfw/storagemanager/StorageManagerIF.h" class MonitoringMessage: public CommandMessage { public: diff --git a/monitoring/MonitoringMessageContent.h b/src/fsfw/monitoring/MonitoringMessageContent.h similarity index 99% rename from monitoring/MonitoringMessageContent.h rename to src/fsfw/monitoring/MonitoringMessageContent.h index 1d5f9c92c..cf8c87521 100644 --- a/monitoring/MonitoringMessageContent.h +++ b/src/fsfw/monitoring/MonitoringMessageContent.h @@ -1,6 +1,7 @@ #ifndef FSFW_MONITORING_MONITORINGMESSAGECONTENT_H_ #define FSFW_MONITORING_MONITORINGMESSAGECONTENT_H_ +#include "monitoringConf.h" #include "HasMonitorsIF.h" #include "MonitoringIF.h" diff --git a/monitoring/ReceivesMonitoringReportsIF.h b/src/fsfw/monitoring/ReceivesMonitoringReportsIF.h similarity index 78% rename from monitoring/ReceivesMonitoringReportsIF.h rename to src/fsfw/monitoring/ReceivesMonitoringReportsIF.h index fb37c16c4..6c126c84b 100644 --- a/monitoring/ReceivesMonitoringReportsIF.h +++ b/src/fsfw/monitoring/ReceivesMonitoringReportsIF.h @@ -1,7 +1,8 @@ #ifndef RECEIVESMONITORINGREPORTSIF_H_ #define RECEIVESMONITORINGREPORTSIF_H_ -#include "../ipc/MessageQueueSenderIF.h" +#include "monitoringConf.h" +#include "fsfw/ipc/messageQueueDefinitions.h" class ReceivesMonitoringReportsIF { public: diff --git a/monitoring/TriplexMonitor.h b/src/fsfw/monitoring/TriplexMonitor.h similarity index 99% rename from monitoring/TriplexMonitor.h rename to src/fsfw/monitoring/TriplexMonitor.h index 295a61749..ff995b5dd 100644 --- a/monitoring/TriplexMonitor.h +++ b/src/fsfw/monitoring/TriplexMonitor.h @@ -1,6 +1,7 @@ #ifndef FRAMEWORK_MONITORING_TRIPLEXMONITOR_H_ #define FRAMEWORK_MONITORING_TRIPLEXMONITOR_H_ +#include "monitoringConf.h" #include "../datapool/DataSet.h" #include "../datapool/PIDReaderList.h" #include "../health/HealthTableIF.h" diff --git a/monitoring/TwoValueLimitMonitor.h b/src/fsfw/monitoring/TwoValueLimitMonitor.h similarity index 98% rename from monitoring/TwoValueLimitMonitor.h rename to src/fsfw/monitoring/TwoValueLimitMonitor.h index e690cdae2..cd34391cd 100644 --- a/monitoring/TwoValueLimitMonitor.h +++ b/src/fsfw/monitoring/TwoValueLimitMonitor.h @@ -1,6 +1,7 @@ #ifndef FRAMEWORK_MONITORING_TWOVALUELIMITMONITOR_H_ #define FRAMEWORK_MONITORING_TWOVALUELIMITMONITOR_H_ +#include "monitoringConf.h" #include "LimitMonitor.h" template diff --git a/src/fsfw/monitoring/monitoringConf.h b/src/fsfw/monitoring/monitoringConf.h new file mode 100644 index 000000000..25cac8db4 --- /dev/null +++ b/src/fsfw/monitoring/monitoringConf.h @@ -0,0 +1,11 @@ +#ifndef FSFW_MONITORING_MONITORINGCONF_H_ +#define FSFW_MONITORING_MONITORINGCONF_H_ + +#include "fsfw/FSFW.h" + +#ifndef FSFW_ADD_MONITORING +#warning Monitoring files were included but compilation was \ + not enabled with FSFW_ADD_MONITORING +#endif + +#endif /* FSFW_MONITORING_MONITORINGCONF_H_ */ diff --git a/src/fsfw/objectmanager.h b/src/fsfw/objectmanager.h new file mode 100644 index 000000000..50a90c9fa --- /dev/null +++ b/src/fsfw/objectmanager.h @@ -0,0 +1,8 @@ +#ifndef FSFW_SRC_FSFW_OBJECTMANAGER_H_ +#define FSFW_SRC_FSFW_OBJECTMANAGER_H_ + +#include "objectmanager/ObjectManager.h" +#include "objectmanager/SystemObject.h" +#include "objectmanager/frameworkObjects.h" + +#endif /* FSFW_SRC_FSFW_OBJECTMANAGER_H_ */ diff --git a/objectmanager/CMakeLists.txt b/src/fsfw/objectmanager/CMakeLists.txt similarity index 100% rename from objectmanager/CMakeLists.txt rename to src/fsfw/objectmanager/CMakeLists.txt diff --git a/objectmanager/ObjectManager.cpp b/src/fsfw/objectmanager/ObjectManager.cpp similarity index 97% rename from objectmanager/ObjectManager.cpp rename to src/fsfw/objectmanager/ObjectManager.cpp index 3e6820a76..639688ab8 100644 --- a/objectmanager/ObjectManager.cpp +++ b/src/fsfw/objectmanager/ObjectManager.cpp @@ -1,5 +1,5 @@ -#include "ObjectManager.h" -#include "../serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #if FSFW_CPP_OSTREAM_ENABLED == 1 #include diff --git a/objectmanager/ObjectManager.h b/src/fsfw/objectmanager/ObjectManager.h similarity index 100% rename from objectmanager/ObjectManager.h rename to src/fsfw/objectmanager/ObjectManager.h diff --git a/objectmanager/ObjectManagerIF.h b/src/fsfw/objectmanager/ObjectManagerIF.h similarity index 100% rename from objectmanager/ObjectManagerIF.h rename to src/fsfw/objectmanager/ObjectManagerIF.h diff --git a/objectmanager/SystemObject.cpp b/src/fsfw/objectmanager/SystemObject.cpp similarity index 87% rename from objectmanager/SystemObject.cpp rename to src/fsfw/objectmanager/SystemObject.cpp index 123bbe655..bad389752 100644 --- a/objectmanager/SystemObject.cpp +++ b/src/fsfw/objectmanager/SystemObject.cpp @@ -1,6 +1,6 @@ -#include "ObjectManager.h" -#include "SystemObject.h" -#include "../events/EventManagerIF.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/events/EventManagerIF.h" SystemObject::SystemObject(object_id_t setObjectId, bool doRegister) : objectId(setObjectId), registered(doRegister) { diff --git a/objectmanager/SystemObject.h b/src/fsfw/objectmanager/SystemObject.h similarity index 93% rename from objectmanager/SystemObject.h rename to src/fsfw/objectmanager/SystemObject.h index d9c4236d0..e7d2ae2bf 100644 --- a/objectmanager/SystemObject.h +++ b/src/fsfw/objectmanager/SystemObject.h @@ -2,9 +2,9 @@ #define FSFW_OBJECTMANAGER_SYSTEMOBJECT_H_ #include "SystemObjectIF.h" -#include "../events/Event.h" -#include "../events/EventReportingProxyIF.h" -#include "../timemanager/Clock.h" +#include "fsfw/events/Event.h" +#include "fsfw/events/EventReportingProxyIF.h" +#include "fsfw/timemanager/Clock.h" /** * @brief This class automates insertion into the ObjectManager and diff --git a/objectmanager/SystemObjectIF.h b/src/fsfw/objectmanager/SystemObjectIF.h similarity index 100% rename from objectmanager/SystemObjectIF.h rename to src/fsfw/objectmanager/SystemObjectIF.h diff --git a/objectmanager/frameworkObjects.h b/src/fsfw/objectmanager/frameworkObjects.h similarity index 100% rename from objectmanager/frameworkObjects.h rename to src/fsfw/objectmanager/frameworkObjects.h diff --git a/osal/CMakeLists.txt b/src/fsfw/osal/CMakeLists.txt similarity index 80% rename from osal/CMakeLists.txt rename to src/fsfw/osal/CMakeLists.txt index 76b939b1a..f3c5cfadc 100644 --- a/osal/CMakeLists.txt +++ b/src/fsfw/osal/CMakeLists.txt @@ -1,11 +1,11 @@ # Check the OS_FSFW variable -if(${OS_FSFW} STREQUAL "freertos") - add_subdirectory(FreeRTOS) -elseif(${OS_FSFW} STREQUAL "rtems") +if(FSFW_OSAL MATCHES "freertos") + add_subdirectory(freertos) +elseif(FSFW_OSAL MATCHES "rtems") add_subdirectory(rtems) -elseif(${OS_FSFW} STREQUAL "linux") +elseif(FSFW_OSAL MATCHES "linux") add_subdirectory(linux) -elseif(${OS_FSFW} STREQUAL "host") +elseif(FSFW_OSAL MATCHES "host") add_subdirectory(host) if (WIN32) add_subdirectory(windows) diff --git a/osal/Endiness.h b/src/fsfw/osal/Endiness.h similarity index 100% rename from osal/Endiness.h rename to src/fsfw/osal/Endiness.h diff --git a/src/fsfw/osal/InternalErrorCodes.h b/src/fsfw/osal/InternalErrorCodes.h new file mode 100644 index 000000000..e75228757 --- /dev/null +++ b/src/fsfw/osal/InternalErrorCodes.h @@ -0,0 +1,39 @@ +#ifndef INTERNALERRORCODES_H_ +#define INTERNALERRORCODES_H_ + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" + +class InternalErrorCodes { +public: + static const uint8_t INTERFACE_ID = CLASS_ID::INTERNAL_ERROR_CODES; + + static const ReturnValue_t NO_CONFIGURATION_TABLE = MAKE_RETURN_CODE(0x01 ); + static const ReturnValue_t NO_CPU_TABLE = MAKE_RETURN_CODE(0x02 ); + static const ReturnValue_t INVALID_WORKSPACE_ADDRESS = MAKE_RETURN_CODE(0x03 ); + static const ReturnValue_t TOO_LITTLE_WORKSPACE = MAKE_RETURN_CODE(0x04 ); + static const ReturnValue_t WORKSPACE_ALLOCATION = MAKE_RETURN_CODE(0x05 ); + static const ReturnValue_t INTERRUPT_STACK_TOO_SMALL = MAKE_RETURN_CODE(0x06 ); + static const ReturnValue_t THREAD_EXITTED = MAKE_RETURN_CODE(0x07 ); + static const ReturnValue_t INCONSISTENT_MP_INFORMATION = MAKE_RETURN_CODE(0x08 ); + static const ReturnValue_t INVALID_NODE = MAKE_RETURN_CODE(0x09 ); + static const ReturnValue_t NO_MPCI = MAKE_RETURN_CODE(0x0a ); + static const ReturnValue_t BAD_PACKET = MAKE_RETURN_CODE(0x0b ); + static const ReturnValue_t OUT_OF_PACKETS = MAKE_RETURN_CODE(0x0c ); + static const ReturnValue_t OUT_OF_GLOBAL_OBJECTS = MAKE_RETURN_CODE(0x0d ); + static const ReturnValue_t OUT_OF_PROXIES = MAKE_RETURN_CODE(0x0e ); + static const ReturnValue_t INVALID_GLOBAL_ID = MAKE_RETURN_CODE(0x0f ); + static const ReturnValue_t BAD_STACK_HOOK = MAKE_RETURN_CODE(0x10 ); + static const ReturnValue_t BAD_ATTRIBUTES = MAKE_RETURN_CODE(0x11 ); + static const ReturnValue_t IMPLEMENTATION_KEY_CREATE_INCONSISTENCY = MAKE_RETURN_CODE(0x12 ); + static const ReturnValue_t IMPLEMENTATION_BLOCKING_OPERATION_CANCEL = MAKE_RETURN_CODE(0x13 ); + static const ReturnValue_t MUTEX_OBTAIN_FROM_BAD_STATE = MAKE_RETURN_CODE(0x14 ); + static const ReturnValue_t UNLIMITED_AND_MAXIMUM_IS_0 = MAKE_RETURN_CODE(0x15 ); + + virtual ~InternalErrorCodes(); + + static ReturnValue_t translate(uint8_t code); +private: + InternalErrorCodes(); +}; + +#endif /* INTERNALERRORCODES_H_ */ diff --git a/osal/common/CMakeLists.txt b/src/fsfw/osal/common/CMakeLists.txt similarity index 100% rename from osal/common/CMakeLists.txt rename to src/fsfw/osal/common/CMakeLists.txt diff --git a/osal/common/TcpIpBase.cpp b/src/fsfw/osal/common/TcpIpBase.cpp similarity index 94% rename from osal/common/TcpIpBase.cpp rename to src/fsfw/osal/common/TcpIpBase.cpp index 0b37e38ca..b6b64e138 100644 --- a/osal/common/TcpIpBase.cpp +++ b/src/fsfw/osal/common/TcpIpBase.cpp @@ -1,5 +1,5 @@ -#include "TcpIpBase.h" -#include "../../platform.h" +#include "fsfw/osal/common/TcpIpBase.h" +#include "fsfw/platform.h" #ifdef PLATFORM_UNIX #include diff --git a/osal/common/TcpIpBase.h b/src/fsfw/osal/common/TcpIpBase.h similarity index 100% rename from osal/common/TcpIpBase.h rename to src/fsfw/osal/common/TcpIpBase.h diff --git a/osal/common/TcpTmTcBridge.cpp b/src/fsfw/osal/common/TcpTmTcBridge.cpp similarity index 87% rename from osal/common/TcpTmTcBridge.cpp rename to src/fsfw/osal/common/TcpTmTcBridge.cpp index 24fab9a90..3cd03c368 100644 --- a/osal/common/TcpTmTcBridge.cpp +++ b/src/fsfw/osal/common/TcpTmTcBridge.cpp @@ -1,23 +1,21 @@ -#include "TcpTmTcBridge.h" -#include "tcpipHelpers.h" +#include "fsfw/platform.h" +#include "fsfw/osal/common/TcpTmTcBridge.h" -#include -#include -#include +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/ipc/MutexGuard.h" +#include "fsfw/osal/common/TcpTmTcBridge.h" -#ifdef _WIN32 +#ifdef PLATFORM_WIN #include -#elif defined(__unix__) +#elif defined PLATFORM_UNIX #include #include #endif -const std::string TcpTmTcBridge::DEFAULT_UDP_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT; - TcpTmTcBridge::TcpTmTcBridge(object_id_t objectId, object_id_t tcDestination, object_id_t tmStoreId, object_id_t tcStoreId): TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) { diff --git a/osal/common/TcpTmTcBridge.h b/src/fsfw/osal/common/TcpTmTcBridge.h similarity index 92% rename from osal/common/TcpTmTcBridge.h rename to src/fsfw/osal/common/TcpTmTcBridge.h index 6cfacb9fa..dc46f1f01 100644 --- a/osal/common/TcpTmTcBridge.h +++ b/src/fsfw/osal/common/TcpTmTcBridge.h @@ -2,7 +2,7 @@ #define FSFW_OSAL_COMMON_TCPTMTCBRIDGE_H_ #include "TcpIpBase.h" -#include "../../tmtcservices/TmTcBridge.h" +#include "fsfw/tmtcservices/TmTcBridge.h" #ifdef _WIN32 @@ -29,8 +29,6 @@ class TcpTmTcBridge: public TmTcBridge { friend class TcpTmTcServer; public: - /* The ports chosen here should not be used by any other process. */ - static const std::string DEFAULT_UDP_SERVER_PORT; /** * Constructor diff --git a/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp similarity index 92% rename from osal/common/TcpTmTcServer.cpp rename to src/fsfw/osal/common/TcpTmTcServer.cpp index 38f72647f..11ab71af8 100644 --- a/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -1,15 +1,15 @@ -#include "TcpTmTcServer.h" -#include "TcpTmTcBridge.h" -#include "tcpipHelpers.h" +#include "fsfw/osal/common/TcpTmTcServer.h" +#include "fsfw/osal/common/TcpTmTcBridge.h" +#include "fsfw/osal/common/tcpipHelpers.h" -#include "../../platform.h" -#include "../../container/SharedRingBuffer.h" -#include "../../ipc/MessageQueueSenderIF.h" -#include "../../ipc/MutexGuard.h" -#include "../../objectmanager/ObjectManager.h" +#include "fsfw/platform.h" +#include "fsfw/container/SharedRingBuffer.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" +#include "fsfw/ipc/MutexGuard.h" +#include "fsfw/objectmanager/ObjectManager.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../tmtcservices/TmTcMessage.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tmtcservices/TmTcMessage.h" #ifdef PLATFORM_WIN #include @@ -22,14 +22,14 @@ #define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0 #endif -const std::string TcpTmTcServer::DEFAULT_TCP_SERVER_PORT = "7303"; +const std::string TcpTmTcServer::DEFAULT_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT; TcpTmTcServer::TcpTmTcServer(object_id_t objectId, object_id_t tmtcTcpBridge, size_t receptionBufferSize, std::string customTcpServerPort): SystemObject(objectId), tmtcBridgeId(tmtcTcpBridge), tcpPort(customTcpServerPort), receptionBuffer(receptionBufferSize) { if(tcpPort == "") { - tcpPort = DEFAULT_TCP_SERVER_PORT; + tcpPort = DEFAULT_SERVER_PORT; } } @@ -200,6 +200,10 @@ void TcpTmTcServer::setTcpBacklog(uint8_t tcpBacklog) { this->tcpBacklog = tcpBacklog; } +std::string TcpTmTcServer::getTcpPort() const { + return tcpPort; +} + ReturnValue_t TcpTmTcServer::handleTmSending(socket_t connSocket) { // Access to the FIFO is mutex protected because it is filled by the bridge MutexGuard(tmtcBridge->mutex, tmtcBridge->timeoutType, tmtcBridge->mutexTimeoutMs); diff --git a/osal/common/TcpTmTcServer.h b/src/fsfw/osal/common/TcpTmTcServer.h similarity index 85% rename from osal/common/TcpTmTcServer.h rename to src/fsfw/osal/common/TcpTmTcServer.h index f7c36d69c..c69160807 100644 --- a/osal/common/TcpTmTcServer.h +++ b/src/fsfw/osal/common/TcpTmTcServer.h @@ -3,13 +3,14 @@ #include "TcpIpBase.h" -#include "../../platform.h" -#include "../../ipc/messageQueueDefinitions.h" -#include "../../ipc/MessageQueueIF.h" -#include "../../objectmanager/frameworkObjects.h" -#include "../../objectmanager/SystemObject.h" -#include "../../storagemanager/StorageManagerIF.h" -#include "../../tasks/ExecutableObjectIF.h" +#include "fsfw/platform.h" +#include "fsfw/osal/common/tcpipHelpers.h" +#include "fsfw/ipc/messageQueueDefinitions.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/objectmanager/frameworkObjects.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/tasks/ExecutableObjectIF.h" #ifdef PLATFORM_UNIX #include @@ -41,10 +42,9 @@ class TcpTmTcServer: public TcpIpBase, public ExecutableObjectIF { public: - /* The ports chosen here should not be used by any other process. */ - static const std::string DEFAULT_TCP_SERVER_PORT; + static const std::string DEFAULT_SERVER_PORT; - static constexpr size_t ETHERNET_MTU_SIZE = 1500; + static constexpr size_t ETHERNET_MTU_SIZE = 1500; /** * TCP Server Constructor @@ -65,6 +65,8 @@ public: ReturnValue_t performOperation(uint8_t opCode) override; ReturnValue_t initializeAfterTaskCreation() override; + std::string getTcpPort() const; + protected: StorageManagerIF* tcStore = nullptr; StorageManagerIF* tmStore = nullptr; diff --git a/osal/common/UdpTcPollingTask.cpp b/src/fsfw/osal/common/UdpTcPollingTask.cpp similarity index 95% rename from osal/common/UdpTcPollingTask.cpp rename to src/fsfw/osal/common/UdpTcPollingTask.cpp index 4453e1bc2..35e086ee0 100644 --- a/osal/common/UdpTcPollingTask.cpp +++ b/src/fsfw/osal/common/UdpTcPollingTask.cpp @@ -1,9 +1,10 @@ -#include "UdpTcPollingTask.h" -#include "tcpipHelpers.h" -#include "../../platform.h" -#include "../../globalfunctions/arrayprinter.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../objectmanager/ObjectManager.h" +#include "fsfw/osal/common/UdpTcPollingTask.h" +#include "fsfw/osal/common/tcpipHelpers.h" + +#include "fsfw/platform.h" +#include "fsfw/globalfunctions/arrayprinter.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" #ifdef PLATFORM_WIN #include diff --git a/osal/common/UdpTcPollingTask.h b/src/fsfw/osal/common/UdpTcPollingTask.h similarity index 100% rename from osal/common/UdpTcPollingTask.h rename to src/fsfw/osal/common/UdpTcPollingTask.h diff --git a/osal/common/UdpTmTcBridge.cpp b/src/fsfw/osal/common/UdpTmTcBridge.cpp similarity index 92% rename from osal/common/UdpTmTcBridge.cpp rename to src/fsfw/osal/common/UdpTmTcBridge.cpp index 4c83385ba..734a2b15b 100644 --- a/osal/common/UdpTmTcBridge.cpp +++ b/src/fsfw/osal/common/UdpTmTcBridge.cpp @@ -1,9 +1,9 @@ -#include "UdpTmTcBridge.h" -#include "tcpipHelpers.h" +#include "fsfw/osal/common/UdpTmTcBridge.h" +#include "fsfw/osal/common/tcpipHelpers.h" -#include "../../platform.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../ipc/MutexGuard.h" +#include "fsfw/platform.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/ipc/MutexGuard.h" #ifdef PLATFORM_WIN #include @@ -17,13 +17,13 @@ #define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0 #endif -const std::string UdpTmTcBridge::DEFAULT_UDP_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT; +const std::string UdpTmTcBridge::DEFAULT_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT; UdpTmTcBridge::UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination, std::string udpServerPort, object_id_t tmStoreId, object_id_t tcStoreId): TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) { if(udpServerPort == "") { - this->udpServerPort = DEFAULT_UDP_SERVER_PORT; + this->udpServerPort = DEFAULT_SERVER_PORT; } else { this->udpServerPort = udpServerPort; @@ -108,6 +108,10 @@ UdpTmTcBridge::~UdpTmTcBridge() { } } +std::string UdpTmTcBridge::getUdpPort() const { + return udpServerPort; +} + ReturnValue_t UdpTmTcBridge::sendTm(const uint8_t *data, size_t dataLen) { int flags = 0; diff --git a/osal/common/UdpTmTcBridge.h b/src/fsfw/osal/common/UdpTmTcBridge.h similarity index 92% rename from osal/common/UdpTmTcBridge.h rename to src/fsfw/osal/common/UdpTmTcBridge.h index 7a346de57..4d634e649 100644 --- a/osal/common/UdpTmTcBridge.h +++ b/src/fsfw/osal/common/UdpTmTcBridge.h @@ -2,8 +2,8 @@ #define FSFW_OSAL_COMMON_TMTCUDPBRIDGE_H_ #include "TcpIpBase.h" -#include "../../platform.h" -#include "../../tmtcservices/TmTcBridge.h" +#include "fsfw/platform.h" +#include "fsfw/tmtcservices/TmTcBridge.h" #ifdef PLATFORM_WIN #include @@ -28,7 +28,7 @@ class UdpTmTcBridge: friend class UdpTcPollingTask; public: /* The ports chosen here should not be used by any other process. */ - static const std::string DEFAULT_UDP_SERVER_PORT; + static const std::string DEFAULT_SERVER_PORT; UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination, std::string udpServerPort = "", object_id_t tmStoreId = objects::TM_STORE, @@ -44,6 +44,8 @@ public: void checkAndSetClientAddress(sockaddr& clientAddress); + std::string getUdpPort() const; + protected: virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override; diff --git a/osal/common/tcpipCommon.cpp b/src/fsfw/osal/common/tcpipCommon.cpp similarity index 94% rename from osal/common/tcpipCommon.cpp rename to src/fsfw/osal/common/tcpipCommon.cpp index ca4dbf180..0fdbf867a 100644 --- a/osal/common/tcpipCommon.cpp +++ b/src/fsfw/osal/common/tcpipCommon.cpp @@ -1,7 +1,8 @@ -#include "tcpipCommon.h" -#include +#include "fsfw/platform.h" +#include "fsfw/osal/common/tcpipCommon.h" +#include "fsfw/serviceinterface/ServiceInterface.h" -#ifdef _WIN32 +#ifdef PLATFORM_WIN #include #endif diff --git a/osal/common/tcpipCommon.h b/src/fsfw/osal/common/tcpipCommon.h similarity index 87% rename from osal/common/tcpipCommon.h rename to src/fsfw/osal/common/tcpipCommon.h index ce7a90cd1..5a04144e1 100644 --- a/osal/common/tcpipCommon.h +++ b/src/fsfw/osal/common/tcpipCommon.h @@ -1,7 +1,7 @@ #ifndef FSFW_OSAL_COMMON_TCPIPCOMMON_H_ #define FSFW_OSAL_COMMON_TCPIPCOMMON_H_ -#include "../../timemanager/clockDefinitions.h" +#include "fsfw/timemanager/clockDefinitions.h" #include #ifdef _WIN32 @@ -13,7 +13,7 @@ namespace tcpip { -const char* const DEFAULT_SERVER_PORT = "7301"; +static constexpr char DEFAULT_SERVER_PORT[] = "7301"; enum class Protocol { UDP, diff --git a/osal/common/tcpipHelpers.h b/src/fsfw/osal/common/tcpipHelpers.h similarity index 85% rename from osal/common/tcpipHelpers.h rename to src/fsfw/osal/common/tcpipHelpers.h index 9764a93fe..bf9a7b5ae 100644 --- a/osal/common/tcpipHelpers.h +++ b/src/fsfw/osal/common/tcpipHelpers.h @@ -1,7 +1,7 @@ #ifndef FSFW_OSAL_WINDOWS_TCPIPHELPERS_H_ #define FSFW_OSAL_WINDOWS_TCPIPHELPERS_H_ -#include "../../timemanager/clockDefinitions.h" +#include "fsfw/timemanager/clockDefinitions.h" #include "tcpipCommon.h" namespace tcpip { diff --git a/osal/FreeRTOS/BinSemaphUsingTask.cpp b/src/fsfw/osal/freertos/BinSemaphUsingTask.cpp similarity index 95% rename from osal/FreeRTOS/BinSemaphUsingTask.cpp rename to src/fsfw/osal/freertos/BinSemaphUsingTask.cpp index 7d609aeed..637c1925f 100644 --- a/osal/FreeRTOS/BinSemaphUsingTask.cpp +++ b/src/fsfw/osal/freertos/BinSemaphUsingTask.cpp @@ -1,6 +1,6 @@ -#include "BinSemaphUsingTask.h" -#include "TaskManagement.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/osal/freertos/BinSemaphUsingTask.h" +#include "fsfw/osal/freertos/TaskManagement.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #if (tskKERNEL_VERSION_MAJOR == 8 && tskKERNEL_VERSION_MINOR > 2) || \ tskKERNEL_VERSION_MAJOR > 8 diff --git a/osal/FreeRTOS/BinSemaphUsingTask.h b/src/fsfw/osal/freertos/BinSemaphUsingTask.h similarity index 95% rename from osal/FreeRTOS/BinSemaphUsingTask.h rename to src/fsfw/osal/freertos/BinSemaphUsingTask.h index ec434853e..0645b1fad 100644 --- a/osal/FreeRTOS/BinSemaphUsingTask.h +++ b/src/fsfw/osal/freertos/BinSemaphUsingTask.h @@ -1,11 +1,11 @@ #ifndef FSFW_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_ #define FSFW_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_ -#include "../../returnvalues/HasReturnvaluesIF.h" -#include "../../tasks/SemaphoreIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tasks/SemaphoreIF.h" -#include -#include +#include "FreeRTOS.h" +#include "task.h" #if (tskKERNEL_VERSION_MAJOR == 8 && tskKERNEL_VERSION_MINOR > 2) || \ tskKERNEL_VERSION_MAJOR > 8 diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/src/fsfw/osal/freertos/BinarySemaphore.cpp similarity index 94% rename from osal/FreeRTOS/BinarySemaphore.cpp rename to src/fsfw/osal/freertos/BinarySemaphore.cpp index c0349b7c9..4ec5d30f8 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/src/fsfw/osal/freertos/BinarySemaphore.cpp @@ -1,6 +1,6 @@ -#include "BinarySemaphore.h" -#include "TaskManagement.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/osal/freertos/BinarySemaphore.h" +#include "fsfw/osal/freertos/TaskManagement.h" +#include "fsfw/serviceinterface/ServiceInterface.h" BinarySemaphore::BinarySemaphore() { handle = xSemaphoreCreateBinary(); diff --git a/osal/FreeRTOS/BinarySemaphore.h b/src/fsfw/osal/freertos/BinarySemaphore.h similarity index 95% rename from osal/FreeRTOS/BinarySemaphore.h rename to src/fsfw/osal/freertos/BinarySemaphore.h index 8969d5038..1ae56ff66 100644 --- a/osal/FreeRTOS/BinarySemaphore.h +++ b/src/fsfw/osal/freertos/BinarySemaphore.h @@ -1,11 +1,11 @@ #ifndef FSFW_OSAL_FREERTOS_BINARYSEMPAHORE_H_ #define FSFW_OSAL_FREERTOS_BINARYSEMPAHORE_H_ -#include "../../returnvalues/HasReturnvaluesIF.h" -#include "../../tasks/SemaphoreIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tasks/SemaphoreIF.h" -#include -#include +#include "FreeRTOS.h" +#include "semphr.h" /** * @brief OS Tool to achieve synchronization of between tasks or between diff --git a/osal/FreeRTOS/CMakeLists.txt b/src/fsfw/osal/freertos/CMakeLists.txt similarity index 75% rename from osal/FreeRTOS/CMakeLists.txt rename to src/fsfw/osal/freertos/CMakeLists.txt index 4da24a710..40bdcd0f5 100644 --- a/osal/FreeRTOS/CMakeLists.txt +++ b/src/fsfw/osal/freertos/CMakeLists.txt @@ -22,10 +22,11 @@ target_sources(${LIB_FSFW_NAME} # FreeRTOS as a static library and set LIB_OS_NAME to the target name of the # library. if(NOT LIB_OS_NAME) - message(FATAL_ERROR - "FreeRTOS needs to be linked as a target and " - "LIB_OS_NAME needs to be set to the target" + message(STATUS + "LIB_OS_NAME is empty. Make sure to include the FreeRTOS header path properly." ) +else() + target_link_libraries(${LIB_FSFW_NAME} PRIVATE + ${LIB_OS_NAME} + ) endif() - -target_link_libraries(${LIB_FSWFW_NAME} ${LIB_OS_NAME}) \ No newline at end of file diff --git a/osal/FreeRTOS/Clock.cpp b/src/fsfw/osal/freertos/Clock.cpp similarity index 93% rename from osal/FreeRTOS/Clock.cpp rename to src/fsfw/osal/freertos/Clock.cpp index 66207d75e..eddf2fec4 100644 --- a/osal/FreeRTOS/Clock.cpp +++ b/src/fsfw/osal/freertos/Clock.cpp @@ -1,13 +1,13 @@ -#include "Timekeeper.h" +#include "fsfw/osal/freertos/Timekeeper.h" -#include "../../timemanager/Clock.h" -#include "../../globalfunctions/timevalOperations.h" +#include "fsfw/timemanager/Clock.h" +#include "fsfw/globalfunctions/timevalOperations.h" -#include -#include +#include "FreeRTOS.h" +#include "task.h" -#include -#include +#include +#include //TODO sanitize input? //TODO much of this code can be reused for tick-only systems diff --git a/osal/FreeRTOS/CountingSemaphUsingTask.cpp b/src/fsfw/osal/freertos/CountingSemaphUsingTask.cpp similarity index 95% rename from osal/FreeRTOS/CountingSemaphUsingTask.cpp rename to src/fsfw/osal/freertos/CountingSemaphUsingTask.cpp index 750ea9d65..a34a6508b 100644 --- a/osal/FreeRTOS/CountingSemaphUsingTask.cpp +++ b/src/fsfw/osal/freertos/CountingSemaphUsingTask.cpp @@ -1,7 +1,7 @@ -#include "CountingSemaphUsingTask.h" -#include "TaskManagement.h" +#include "fsfw/osal/freertos/CountingSemaphUsingTask.h" +#include "fsfw/osal/freertos/TaskManagement.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #if (tskKERNEL_VERSION_MAJOR == 8 && tskKERNEL_VERSION_MINOR > 2) || \ tskKERNEL_VERSION_MAJOR > 8 diff --git a/osal/FreeRTOS/CountingSemaphUsingTask.h b/src/fsfw/osal/freertos/CountingSemaphUsingTask.h similarity index 97% rename from osal/FreeRTOS/CountingSemaphUsingTask.h rename to src/fsfw/osal/freertos/CountingSemaphUsingTask.h index 45915b6b5..eb2fc67bd 100644 --- a/osal/FreeRTOS/CountingSemaphUsingTask.h +++ b/src/fsfw/osal/freertos/CountingSemaphUsingTask.h @@ -2,10 +2,10 @@ #define FSFW_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_ #include "CountingSemaphUsingTask.h" -#include "../../tasks/SemaphoreIF.h" +#include "fsfw/tasks/SemaphoreIF.h" -#include -#include +#include "FreeRTOS.h" +#include "task.h" #if (tskKERNEL_VERSION_MAJOR == 8 && tskKERNEL_VERSION_MINOR > 2) || \ tskKERNEL_VERSION_MAJOR > 8 diff --git a/osal/FreeRTOS/CountingSemaphore.cpp b/src/fsfw/osal/freertos/CountingSemaphore.cpp similarity index 87% rename from osal/FreeRTOS/CountingSemaphore.cpp rename to src/fsfw/osal/freertos/CountingSemaphore.cpp index 40884d273..90dc771f4 100644 --- a/osal/FreeRTOS/CountingSemaphore.cpp +++ b/src/fsfw/osal/freertos/CountingSemaphore.cpp @@ -1,9 +1,10 @@ -#include "CountingSemaphore.h" -#include "TaskManagement.h" +#include "fsfw/osal/freertos/CountingSemaphore.h" +#include "fsfw/osal/freertos/TaskManagement.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/serviceinterface/ServiceInterface.h" -#include +#include "FreeRTOS.h" +#include "semphr.h" // Make sure #define configUSE_COUNTING_SEMAPHORES 1 is set in // free FreeRTOSConfig.h file. diff --git a/osal/FreeRTOS/CountingSemaphore.h b/src/fsfw/osal/freertos/CountingSemaphore.h similarity index 100% rename from osal/FreeRTOS/CountingSemaphore.h rename to src/fsfw/osal/freertos/CountingSemaphore.h diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/src/fsfw/osal/freertos/FixedTimeslotTask.cpp similarity index 97% rename from osal/FreeRTOS/FixedTimeslotTask.cpp rename to src/fsfw/osal/freertos/FixedTimeslotTask.cpp index a722c9585..9690991d7 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/src/fsfw/osal/freertos/FixedTimeslotTask.cpp @@ -1,7 +1,7 @@ -#include "FixedTimeslotTask.h" +#include "fsfw/osal/freertos/FixedTimeslotTask.h" -#include "../../objectmanager/ObjectManager.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" uint32_t FixedTimeslotTask::deadlineMissedCount = 0; const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = configMINIMAL_STACK_SIZE; diff --git a/osal/FreeRTOS/FixedTimeslotTask.h b/src/fsfw/osal/freertos/FixedTimeslotTask.h similarity index 94% rename from osal/FreeRTOS/FixedTimeslotTask.h rename to src/fsfw/osal/freertos/FixedTimeslotTask.h index f2245ba4a..ebd902cca 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.h +++ b/src/fsfw/osal/freertos/FixedTimeslotTask.h @@ -2,12 +2,12 @@ #define FSFW_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_ #include "FreeRTOSTaskIF.h" -#include "../../tasks/FixedSlotSequence.h" -#include "../../tasks/FixedTimeslotTaskIF.h" -#include "../../tasks/Typedef.h" +#include "fsfw/tasks/FixedSlotSequence.h" +#include "fsfw/tasks/FixedTimeslotTaskIF.h" +#include "fsfw/tasks/Typedef.h" -#include -#include +#include "FreeRTOS.h" +#include "task.h" class FixedTimeslotTask: public FixedTimeslotTaskIF, public FreeRTOSTaskIF { public: diff --git a/osal/FreeRTOS/FreeRTOSTaskIF.h b/src/fsfw/osal/freertos/FreeRTOSTaskIF.h similarity index 95% rename from osal/FreeRTOS/FreeRTOSTaskIF.h rename to src/fsfw/osal/freertos/FreeRTOSTaskIF.h index 2a2d94947..08f0df257 100644 --- a/osal/FreeRTOS/FreeRTOSTaskIF.h +++ b/src/fsfw/osal/freertos/FreeRTOSTaskIF.h @@ -1,8 +1,8 @@ #ifndef FSFW_OSAL_FREERTOS_FREERTOSTASKIF_H_ #define FSFW_OSAL_FREERTOS_FREERTOSTASKIF_H_ -#include -#include +#include "FreeRTOS.h" +#include "task.h" class FreeRTOSTaskIF { public: diff --git a/osal/FreeRTOS/MessageQueue.cpp b/src/fsfw/osal/freertos/MessageQueue.cpp similarity index 96% rename from osal/FreeRTOS/MessageQueue.cpp rename to src/fsfw/osal/freertos/MessageQueue.cpp index cc8bd6a70..487fa8648 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/src/fsfw/osal/freertos/MessageQueue.cpp @@ -1,7 +1,8 @@ -#include "MessageQueue.h" -#include "QueueMapManager.h" -#include "../../objectmanager/ObjectManager.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/osal/freertos/MessageQueue.h" +#include "fsfw/osal/freertos/QueueMapManager.h" + +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" MessageQueue::MessageQueue(size_t messageDepth, size_t maxMessageSize): maxMessageSize(maxMessageSize) { diff --git a/osal/FreeRTOS/MessageQueue.h b/src/fsfw/osal/freertos/MessageQueue.h similarity index 96% rename from osal/FreeRTOS/MessageQueue.h rename to src/fsfw/osal/freertos/MessageQueue.h index be74d4fe0..debb30348 100644 --- a/osal/FreeRTOS/MessageQueue.h +++ b/src/fsfw/osal/freertos/MessageQueue.h @@ -3,13 +3,13 @@ #include "TaskManagement.h" -#include "../../internalError/InternalErrorReporterIF.h" -#include "../../ipc/MessageQueueIF.h" -#include "../../ipc/MessageQueueMessageIF.h" +#include "fsfw/internalerror/InternalErrorReporterIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/MessageQueueMessageIF.h" +#include "fsfw/ipc/MessageQueueMessage.h" -#include -#include -#include +#include "FreeRTOS.h" +#include "queue.h" /** * @brief This class manages sending and receiving of diff --git a/osal/FreeRTOS/Mutex.cpp b/src/fsfw/osal/freertos/Mutex.cpp similarity index 92% rename from osal/FreeRTOS/Mutex.cpp rename to src/fsfw/osal/freertos/Mutex.cpp index 0b85ca135..8d1313e6a 100644 --- a/osal/FreeRTOS/Mutex.cpp +++ b/src/fsfw/osal/freertos/Mutex.cpp @@ -1,6 +1,6 @@ -#include "Mutex.h" +#include "fsfw/osal/freertos/Mutex.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/serviceinterface/ServiceInterface.h" Mutex::Mutex() { handle = xSemaphoreCreateMutex(); diff --git a/osal/FreeRTOS/Mutex.h b/src/fsfw/osal/freertos/Mutex.h similarity index 86% rename from osal/FreeRTOS/Mutex.h rename to src/fsfw/osal/freertos/Mutex.h index 156d431c2..082679c72 100644 --- a/osal/FreeRTOS/Mutex.h +++ b/src/fsfw/osal/freertos/Mutex.h @@ -1,10 +1,10 @@ #ifndef FRAMEWORK_FREERTOS_MUTEX_H_ #define FRAMEWORK_FREERTOS_MUTEX_H_ -#include "../../ipc/MutexIF.h" +#include "fsfw/ipc/MutexIF.h" -#include -#include +#include "FreeRTOS.h" +#include "semphr.h" /** * @brief OS component to implement MUTual EXclusion diff --git a/osal/FreeRTOS/MutexFactory.cpp b/src/fsfw/osal/freertos/MutexFactory.cpp similarity index 89% rename from osal/FreeRTOS/MutexFactory.cpp rename to src/fsfw/osal/freertos/MutexFactory.cpp index d9569e35d..f8b48c7d0 100644 --- a/osal/FreeRTOS/MutexFactory.cpp +++ b/src/fsfw/osal/freertos/MutexFactory.cpp @@ -1,6 +1,6 @@ -#include "Mutex.h" +#include "fsfw/osal/freertos/Mutex.h" -#include "../../ipc/MutexFactory.h" +#include "fsfw/ipc/MutexFactory.h" //TODO: Different variant than the lazy loading in QueueFactory. diff --git a/osal/FreeRTOS/PeriodicTask.cpp b/src/fsfw/osal/freertos/PeriodicTask.cpp similarity index 95% rename from osal/FreeRTOS/PeriodicTask.cpp rename to src/fsfw/osal/freertos/PeriodicTask.cpp index 42d6681d3..7ef1c837c 100644 --- a/osal/FreeRTOS/PeriodicTask.cpp +++ b/src/fsfw/osal/freertos/PeriodicTask.cpp @@ -1,8 +1,8 @@ -#include "PeriodicTask.h" +#include "fsfw/osal/freertos/PeriodicTask.h" -#include "../../objectmanager/ObjectManager.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../tasks/ExecutableObjectIF.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tasks/ExecutableObjectIF.h" PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority, TaskStackSize setStack, TaskPeriod setPeriod, diff --git a/osal/FreeRTOS/PeriodicTask.h b/src/fsfw/osal/freertos/PeriodicTask.h similarity index 95% rename from osal/FreeRTOS/PeriodicTask.h rename to src/fsfw/osal/freertos/PeriodicTask.h index 36ef568f6..e910a0c63 100644 --- a/osal/FreeRTOS/PeriodicTask.h +++ b/src/fsfw/osal/freertos/PeriodicTask.h @@ -2,12 +2,12 @@ #define FSFW_OSAL_FREERTOS_PERIODICTASK_H_ #include "FreeRTOSTaskIF.h" -#include "../../objectmanager/ObjectManagerIF.h" -#include "../../tasks/PeriodicTaskIF.h" -#include "../../tasks/Typedef.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/tasks/PeriodicTaskIF.h" +#include "fsfw/tasks/Typedef.h" -#include -#include +#include "FreeRTOS.h" +#include "task.h" #include diff --git a/osal/FreeRTOS/QueueFactory.cpp b/src/fsfw/osal/freertos/QueueFactory.cpp similarity index 86% rename from osal/FreeRTOS/QueueFactory.cpp rename to src/fsfw/osal/freertos/QueueFactory.cpp index ed29e10cf..536c16c0e 100644 --- a/osal/FreeRTOS/QueueFactory.cpp +++ b/src/fsfw/osal/freertos/QueueFactory.cpp @@ -1,7 +1,7 @@ -#include "MessageQueue.h" +#include "fsfw/osal/freertos/MessageQueue.h" -#include "../../ipc/MessageQueueSenderIF.h" -#include "../../ipc/QueueFactory.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" +#include "fsfw/ipc/QueueFactory.h" QueueFactory* QueueFactory::factoryInstance = nullptr; diff --git a/osal/FreeRTOS/QueueMapManager.cpp b/src/fsfw/osal/freertos/QueueMapManager.cpp similarity index 83% rename from osal/FreeRTOS/QueueMapManager.cpp rename to src/fsfw/osal/freertos/QueueMapManager.cpp index 51cfe11db..7d6b2f124 100644 --- a/osal/FreeRTOS/QueueMapManager.cpp +++ b/src/fsfw/osal/freertos/QueueMapManager.cpp @@ -1,6 +1,6 @@ -#include "QueueMapManager.h" -#include "../../ipc/MutexFactory.h" -#include "../../ipc/MutexGuard.h" +#include "fsfw/osal/freertos/QueueMapManager.h" +#include "fsfw/ipc/MutexFactory.h" +#include "fsfw/ipc/MutexGuard.h" QueueMapManager* QueueMapManager::mqManagerInstance = nullptr; @@ -17,7 +17,13 @@ QueueMapManager* QueueMapManager::instance() { ReturnValue_t QueueMapManager::addMessageQueue(QueueHandle_t queue, MessageQueueId_t* id) { MutexGuard lock(mapLock); - uint32_t currentId = queueCounter++; + uint32_t currentId = queueCounter; + queueCounter++; + if(currentId == MessageQueueIF::NO_QUEUE) { + // Skip the NO_QUEUE value + currentId = queueCounter; + queueCounter++; + } auto returnPair = queueMap.emplace(currentId, queue); if(not returnPair.second) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/osal/FreeRTOS/QueueMapManager.h b/src/fsfw/osal/freertos/QueueMapManager.h similarity index 84% rename from osal/FreeRTOS/QueueMapManager.h rename to src/fsfw/osal/freertos/QueueMapManager.h index 91a839f0c..dbe0526bc 100644 --- a/osal/FreeRTOS/QueueMapManager.h +++ b/src/fsfw/osal/freertos/QueueMapManager.h @@ -1,12 +1,12 @@ #ifndef FSFW_OSAL_FREERTOS_QUEUEMAPMANAGER_H_ #define FSFW_OSAL_FREERTOS_QUEUEMAPMANAGER_H_ -#include "../../ipc/MutexIF.h" -#include "../../ipc/messageQueueDefinitions.h" -#include "../../ipc/MessageQueueIF.h" +#include "fsfw/ipc/MutexIF.h" +#include "fsfw/ipc/messageQueueDefinitions.h" +#include "fsfw/ipc/MessageQueueIF.h" -#include "freertos/FreeRTOS.h" -#include "freertos/queue.h" +#include "FreeRTOS.h" +#include "queue.h" #include @@ -39,7 +39,7 @@ private: QueueMapManager(); ~QueueMapManager(); - uint32_t queueCounter = 0; + uint32_t queueCounter = MessageQueueIF::NO_QUEUE + 1; MutexIF* mapLock; QueueMap queueMap; static QueueMapManager* mqManagerInstance; diff --git a/osal/FreeRTOS/README.md b/src/fsfw/osal/freertos/README.md similarity index 100% rename from osal/FreeRTOS/README.md rename to src/fsfw/osal/freertos/README.md diff --git a/osal/FreeRTOS/SemaphoreFactory.cpp b/src/fsfw/osal/freertos/SemaphoreFactory.cpp similarity index 83% rename from osal/FreeRTOS/SemaphoreFactory.cpp rename to src/fsfw/osal/freertos/SemaphoreFactory.cpp index df005f6a5..b6e8f86e1 100644 --- a/osal/FreeRTOS/SemaphoreFactory.cpp +++ b/src/fsfw/osal/freertos/SemaphoreFactory.cpp @@ -1,9 +1,10 @@ -#include "../../osal/FreeRTOS/BinarySemaphore.h" -#include "../../osal/FreeRTOS/BinSemaphUsingTask.h" -#include "../../osal/FreeRTOS/CountingSemaphore.h" -#include "../../osal/FreeRTOS/CountingSemaphUsingTask.h" -#include "../../tasks/SemaphoreFactory.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/osal/freertos/BinarySemaphore.h" +#include "fsfw/osal/freertos/BinSemaphUsingTask.h" +#include "fsfw/osal/freertos/CountingSemaphore.h" +#include "fsfw/osal/freertos/CountingSemaphUsingTask.h" + +#include "fsfw/tasks/SemaphoreFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr; diff --git a/osal/FreeRTOS/TaskFactory.cpp b/src/fsfw/osal/freertos/TaskFactory.cpp similarity index 88% rename from osal/FreeRTOS/TaskFactory.cpp rename to src/fsfw/osal/freertos/TaskFactory.cpp index 5b64811ae..21ca80cb0 100644 --- a/osal/FreeRTOS/TaskFactory.cpp +++ b/src/fsfw/osal/freertos/TaskFactory.cpp @@ -1,9 +1,8 @@ -#include "../../tasks/TaskFactory.h" -#include "../../returnvalues/HasReturnvaluesIF.h" - -#include "PeriodicTask.h" -#include "FixedTimeslotTask.h" +#include "fsfw/tasks/TaskFactory.h" +#include "fsfw/osal/freertos/PeriodicTask.h" +#include "fsfw/osal/freertos/FixedTimeslotTask.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" TaskFactory* TaskFactory::factoryInstance = new TaskFactory(); diff --git a/osal/FreeRTOS/TaskManagement.cpp b/src/fsfw/osal/freertos/TaskManagement.cpp similarity index 92% rename from osal/FreeRTOS/TaskManagement.cpp rename to src/fsfw/osal/freertos/TaskManagement.cpp index c0d0067e9..f19aa4fdc 100644 --- a/osal/FreeRTOS/TaskManagement.cpp +++ b/src/fsfw/osal/freertos/TaskManagement.cpp @@ -1,4 +1,4 @@ -#include "TaskManagement.h" +#include "fsfw/osal/freertos/TaskManagement.h" void TaskManagement::vRequestContextSwitchFromTask() { vTaskDelay(0); diff --git a/osal/FreeRTOS/TaskManagement.h b/src/fsfw/osal/freertos/TaskManagement.h similarity index 91% rename from osal/FreeRTOS/TaskManagement.h rename to src/fsfw/osal/freertos/TaskManagement.h index b9aece48b..9aa107978 100644 --- a/osal/FreeRTOS/TaskManagement.h +++ b/src/fsfw/osal/freertos/TaskManagement.h @@ -1,10 +1,10 @@ -#ifndef FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ -#define FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ +#ifndef FSFW_OSAL_FREERTOS_TASKMANAGEMENT_H_ +#define FSFW_OSAL_FREERTOS_TASKMANAGEMENT_H_ #include "../../returnvalues/HasReturnvaluesIF.h" -#include -#include +#include "FreeRTOS.h" +#include "task.h" #include diff --git a/osal/FreeRTOS/Timekeeper.cpp b/src/fsfw/osal/freertos/Timekeeper.cpp similarity index 91% rename from osal/FreeRTOS/Timekeeper.cpp rename to src/fsfw/osal/freertos/Timekeeper.cpp index d986d832e..1b7dc7414 100644 --- a/osal/FreeRTOS/Timekeeper.cpp +++ b/src/fsfw/osal/freertos/Timekeeper.cpp @@ -1,6 +1,6 @@ -#include "Timekeeper.h" +#include "fsfw/osal/freertos/Timekeeper.h" -#include +#include "FreeRTOSConfig.h" Timekeeper * Timekeeper::myinstance = nullptr; diff --git a/osal/FreeRTOS/Timekeeper.h b/src/fsfw/osal/freertos/Timekeeper.h similarity index 93% rename from osal/FreeRTOS/Timekeeper.h rename to src/fsfw/osal/freertos/Timekeeper.h index 7d583f7db..d4d0bc07b 100644 --- a/osal/FreeRTOS/Timekeeper.h +++ b/src/fsfw/osal/freertos/Timekeeper.h @@ -3,8 +3,8 @@ #include "../../timemanager/Clock.h" -#include -#include +#include "FreeRTOS.h" +#include "task.h" /** diff --git a/osal/host/CMakeLists.txt b/src/fsfw/osal/host/CMakeLists.txt similarity index 100% rename from osal/host/CMakeLists.txt rename to src/fsfw/osal/host/CMakeLists.txt diff --git a/osal/host/Clock.cpp b/src/fsfw/osal/host/Clock.cpp similarity index 97% rename from osal/host/Clock.cpp rename to src/fsfw/osal/host/Clock.cpp index 1018de574..0bdcd8f54 100644 --- a/osal/host/Clock.cpp +++ b/src/fsfw/osal/host/Clock.cpp @@ -1,6 +1,6 @@ -#include "../../serviceinterface/ServiceInterface.h" -#include "../../timemanager/Clock.h" -#include "../../platform.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/timemanager/Clock.h" +#include "fsfw/platform.h" #include diff --git a/osal/host/FixedTimeslotTask.cpp b/src/fsfw/osal/host/FixedTimeslotTask.cpp similarity index 93% rename from osal/host/FixedTimeslotTask.cpp rename to src/fsfw/osal/host/FixedTimeslotTask.cpp index 3ad191e52..f9a0588cb 100644 --- a/osal/host/FixedTimeslotTask.cpp +++ b/src/fsfw/osal/host/FixedTimeslotTask.cpp @@ -1,20 +1,20 @@ -#include "taskHelpers.h" +#include "fsfw/osal/host/taskHelpers.h" +#include "fsfw/osal/host/FixedTimeslotTask.h" +#include "fsfw/osal/host/FixedTimeslotTask.h" -#include "../../platform.h" -#include "../../osal/host/FixedTimeslotTask.h" -#include "../../ipc/MutexFactory.h" -#include "../../osal/host/Mutex.h" -#include "../../osal/host/FixedTimeslotTask.h" -#include "../../objectmanager/ObjectManager.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../tasks/ExecutableObjectIF.h" +#include "fsfw/platform.h" +#include "fsfw/ipc/MutexFactory.h" +#include "fsfw/osal/host/Mutex.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tasks/ExecutableObjectIF.h" #include #include #if defined(PLATFORM_WIN) #include -#include "../windows/winTaskHelpers.h" +#include "fsfw/osal/windows/winTaskHelpers.h" #elif defined(PLATFORM_UNIX) #include #endif diff --git a/osal/host/FixedTimeslotTask.h b/src/fsfw/osal/host/FixedTimeslotTask.h similarity index 100% rename from osal/host/FixedTimeslotTask.h rename to src/fsfw/osal/host/FixedTimeslotTask.h diff --git a/osal/host/MessageQueue.cpp b/src/fsfw/osal/host/MessageQueue.cpp similarity index 95% rename from osal/host/MessageQueue.cpp rename to src/fsfw/osal/host/MessageQueue.cpp index a2137e271..c7bcb042a 100644 --- a/osal/host/MessageQueue.cpp +++ b/src/fsfw/osal/host/MessageQueue.cpp @@ -1,10 +1,10 @@ -#include "MessageQueue.h" -#include "QueueMapManager.h" +#include "fsfw/osal/host/MessageQueue.h" +#include "fsfw/osal/host/QueueMapManager.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../objectmanager/ObjectManager.h" -#include "../../ipc/MutexFactory.h" -#include "../../ipc/MutexGuard.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/ipc/MutexFactory.h" +#include "fsfw/ipc/MutexGuard.h" #include diff --git a/osal/host/MessageQueue.h b/src/fsfw/osal/host/MessageQueue.h similarity index 97% rename from osal/host/MessageQueue.h rename to src/fsfw/osal/host/MessageQueue.h index 1c9b5e331..0bdfd8fcb 100644 --- a/osal/host/MessageQueue.h +++ b/src/fsfw/osal/host/MessageQueue.h @@ -1,11 +1,11 @@ #ifndef FRAMEWORK_OSAL_HOST_MESSAGEQUEUE_H_ #define FRAMEWORK_OSAL_HOST_MESSAGEQUEUE_H_ -#include "../../internalError/InternalErrorReporterIF.h" -#include "../../ipc/MessageQueueIF.h" -#include "../../ipc/MessageQueueMessage.h" -#include "../../ipc/MutexIF.h" -#include "../../timemanager/Clock.h" +#include "fsfw/internalerror/InternalErrorReporterIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/MessageQueueMessage.h" +#include "fsfw/ipc/MutexIF.h" +#include "fsfw/timemanager/Clock.h" #include #include diff --git a/osal/host/Mutex.cpp b/src/fsfw/osal/host/Mutex.cpp similarity index 89% rename from osal/host/Mutex.cpp rename to src/fsfw/osal/host/Mutex.cpp index 892028b23..e423ea937 100644 --- a/osal/host/Mutex.cpp +++ b/src/fsfw/osal/host/Mutex.cpp @@ -1,5 +1,5 @@ -#include "Mutex.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/osal/host/Mutex.h" +#include "fsfw/serviceinterface/ServiceInterface.h" Mutex::Mutex() {} diff --git a/osal/host/Mutex.h b/src/fsfw/osal/host/Mutex.h similarity index 95% rename from osal/host/Mutex.h rename to src/fsfw/osal/host/Mutex.h index 0bd93c8ac..e90ce9321 100644 --- a/osal/host/Mutex.h +++ b/src/fsfw/osal/host/Mutex.h @@ -1,7 +1,7 @@ #ifndef FSFW_OSAL_HOSTED_MUTEX_H_ #define FSFW_OSAL_HOSTED_MUTEX_H_ -#include "../../ipc/MutexIF.h" +#include "fsfw/ipc/MutexIF.h" #include diff --git a/osal/host/MutexFactory.cpp b/src/fsfw/osal/host/MutexFactory.cpp similarity index 90% rename from osal/host/MutexFactory.cpp rename to src/fsfw/osal/host/MutexFactory.cpp index f3b98fd1d..872879065 100644 --- a/osal/host/MutexFactory.cpp +++ b/src/fsfw/osal/host/MutexFactory.cpp @@ -1,5 +1,5 @@ -#include "../../ipc/MutexFactory.h" -#include "../../osal/host/Mutex.h" +#include "fsfw/osal/host/Mutex.h" +#include "fsfw/ipc/MutexFactory.h" //TODO: Different variant than the lazy loading in QueueFactory. //What's better and why? -> one is on heap the other on bss/data diff --git a/osal/host/PeriodicTask.cpp b/src/fsfw/osal/host/PeriodicTask.cpp similarity index 93% rename from osal/host/PeriodicTask.cpp rename to src/fsfw/osal/host/PeriodicTask.cpp index 180272d0c..def3a6cb8 100644 --- a/osal/host/PeriodicTask.cpp +++ b/src/fsfw/osal/host/PeriodicTask.cpp @@ -1,19 +1,19 @@ -#include "Mutex.h" -#include "PeriodicTask.h" -#include "taskHelpers.h" +#include "fsfw/osal/host/Mutex.h" +#include "fsfw/osal/host/PeriodicTask.h" +#include "fsfw/osal/host/taskHelpers.h" -#include "../../platform.h" -#include "../../ipc/MutexFactory.h" -#include "../../objectmanager/ObjectManager.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../tasks/ExecutableObjectIF.h" +#include "fsfw/platform.h" +#include "fsfw/ipc/MutexFactory.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tasks/ExecutableObjectIF.h" #include #include #if defined(PLATFORM_WIN) #include -#include +#include "fsfw/osal/windows/winTaskHelpers.h" #elif defined(PLATFORM_UNIX) #include #endif diff --git a/osal/host/PeriodicTask.h b/src/fsfw/osal/host/PeriodicTask.h similarity index 100% rename from osal/host/PeriodicTask.h rename to src/fsfw/osal/host/PeriodicTask.h diff --git a/osal/host/QueueFactory.cpp b/src/fsfw/osal/host/QueueFactory.cpp similarity index 83% rename from osal/host/QueueFactory.cpp rename to src/fsfw/osal/host/QueueFactory.cpp index 1a679c96c..466bb33b4 100644 --- a/osal/host/QueueFactory.cpp +++ b/src/fsfw/osal/host/QueueFactory.cpp @@ -1,10 +1,9 @@ +#include "fsfw/osal/host/MessageQueue.h" -#include "MessageQueue.h" - -#include "../../ipc/MessageQueueSenderIF.h" -#include "../../ipc/MessageQueueMessageIF.h" -#include "../../ipc/QueueFactory.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" +#include "fsfw/ipc/MessageQueueMessageIF.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include diff --git a/osal/host/QueueMapManager.cpp b/src/fsfw/osal/host/QueueMapManager.cpp similarity index 82% rename from osal/host/QueueMapManager.cpp rename to src/fsfw/osal/host/QueueMapManager.cpp index 879bc36d2..58575cf67 100644 --- a/osal/host/QueueMapManager.cpp +++ b/src/fsfw/osal/host/QueueMapManager.cpp @@ -1,8 +1,8 @@ -#include "QueueMapManager.h" +#include "fsfw/osal/host/QueueMapManager.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../ipc/MutexFactory.h" -#include "../../ipc/MutexGuard.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/ipc/MutexFactory.h" +#include "fsfw/ipc/MutexGuard.h" QueueMapManager* QueueMapManager::mqManagerInstance = nullptr; @@ -24,7 +24,13 @@ QueueMapManager* QueueMapManager::instance() { ReturnValue_t QueueMapManager::addMessageQueue( MessageQueueIF* queueToInsert, MessageQueueId_t* id) { MutexGuard lock(mapLock); - uint32_t currentId = queueCounter++; + uint32_t currentId = queueCounter; + queueCounter++; + if(currentId == MessageQueueIF::NO_QUEUE) { + // Skip the NO_QUEUE value + currentId = queueCounter; + queueCounter++; + } auto returnPair = queueMap.emplace(currentId, queueToInsert); if(not returnPair.second) { /* This should never happen for the atomic variable. */ diff --git a/osal/host/QueueMapManager.h b/src/fsfw/osal/host/QueueMapManager.h similarity index 96% rename from osal/host/QueueMapManager.h rename to src/fsfw/osal/host/QueueMapManager.h index e274bed24..2dd2a01d4 100644 --- a/osal/host/QueueMapManager.h +++ b/src/fsfw/osal/host/QueueMapManager.h @@ -41,7 +41,7 @@ private: QueueMapManager(); ~QueueMapManager(); - uint32_t queueCounter = 0; + uint32_t queueCounter = MessageQueueIF::NO_QUEUE + 1; MutexIF* mapLock; QueueMap queueMap; static QueueMapManager* mqManagerInstance; diff --git a/osal/host/SemaphoreFactory.cpp b/src/fsfw/osal/host/SemaphoreFactory.cpp similarity index 91% rename from osal/host/SemaphoreFactory.cpp rename to src/fsfw/osal/host/SemaphoreFactory.cpp index 530b3e450..3ea12877b 100644 --- a/osal/host/SemaphoreFactory.cpp +++ b/src/fsfw/osal/host/SemaphoreFactory.cpp @@ -1,5 +1,5 @@ -#include "../../tasks/SemaphoreFactory.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/tasks/SemaphoreFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr; diff --git a/osal/host/TaskFactory.cpp b/src/fsfw/osal/host/TaskFactory.cpp similarity index 84% rename from osal/host/TaskFactory.cpp rename to src/fsfw/osal/host/TaskFactory.cpp index 71d0bf8b9..ad59bd1a1 100644 --- a/osal/host/TaskFactory.cpp +++ b/src/fsfw/osal/host/TaskFactory.cpp @@ -1,10 +1,11 @@ -#include "taskHelpers.h" -#include "../../tasks/TaskFactory.h" -#include "../../osal/host/FixedTimeslotTask.h" -#include "../../osal/host/PeriodicTask.h" -#include "../../returnvalues/HasReturnvaluesIF.h" -#include "../../tasks/PeriodicTaskIF.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/osal/host/FixedTimeslotTask.h" +#include "fsfw/osal/host/PeriodicTask.h" +#include "fsfw/osal/host/taskHelpers.h" + +#include "fsfw/tasks/TaskFactory.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tasks/PeriodicTaskIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include diff --git a/osal/host/taskHelpers.cpp b/src/fsfw/osal/host/taskHelpers.cpp similarity index 94% rename from osal/host/taskHelpers.cpp rename to src/fsfw/osal/host/taskHelpers.cpp index be4c29adc..a7de76d95 100644 --- a/osal/host/taskHelpers.cpp +++ b/src/fsfw/osal/host/taskHelpers.cpp @@ -1,4 +1,4 @@ -#include "taskHelpers.h" +#include "fsfw/osal/host/taskHelpers.h" #include #include diff --git a/osal/host/taskHelpers.h b/src/fsfw/osal/host/taskHelpers.h similarity index 100% rename from osal/host/taskHelpers.h rename to src/fsfw/osal/host/taskHelpers.h diff --git a/osal/linux/BinarySemaphore.cpp b/src/fsfw/osal/linux/BinarySemaphore.cpp similarity index 95% rename from osal/linux/BinarySemaphore.cpp rename to src/fsfw/osal/linux/BinarySemaphore.cpp index 110b0a909..3ef04cf09 100644 --- a/osal/linux/BinarySemaphore.cpp +++ b/src/fsfw/osal/linux/BinarySemaphore.cpp @@ -1,11 +1,11 @@ -#include "BinarySemaphore.h" -#include "unixUtility.h" -#include "../../serviceinterface/ServiceInterfacePrinter.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/osal/linux/BinarySemaphore.h" +#include "fsfw/osal/linux/unixUtility.h" +#include "fsfw/serviceinterface/ServiceInterfacePrinter.h" +#include "fsfw/serviceinterface/ServiceInterfaceStream.h" #include #include -#include +#include BinarySemaphore::BinarySemaphore() { diff --git a/osal/linux/BinarySemaphore.h b/src/fsfw/osal/linux/BinarySemaphore.h similarity index 100% rename from osal/linux/BinarySemaphore.h rename to src/fsfw/osal/linux/BinarySemaphore.h diff --git a/osal/linux/CMakeLists.txt b/src/fsfw/osal/linux/CMakeLists.txt similarity index 97% rename from osal/linux/CMakeLists.txt rename to src/fsfw/osal/linux/CMakeLists.txt index 0fb66b3ed..418007643 100644 --- a/osal/linux/CMakeLists.txt +++ b/src/fsfw/osal/linux/CMakeLists.txt @@ -13,7 +13,6 @@ target_sources(${LIB_FSFW_NAME} QueueFactory.cpp SemaphoreFactory.cpp TaskFactory.cpp - Timer.cpp tcpipHelpers.cpp unixUtility.cpp ) diff --git a/osal/linux/Clock.cpp b/src/fsfw/osal/linux/Clock.cpp similarity index 97% rename from osal/linux/Clock.cpp rename to src/fsfw/osal/linux/Clock.cpp index 960d9c0d7..d79c72be7 100644 --- a/osal/linux/Clock.cpp +++ b/src/fsfw/osal/linux/Clock.cpp @@ -1,5 +1,5 @@ -#include "../../serviceinterface/ServiceInterfaceStream.h" -#include "../../timemanager/Clock.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/timemanager/Clock.h" #include #include diff --git a/osal/linux/CountingSemaphore.cpp b/src/fsfw/osal/linux/CountingSemaphore.cpp similarity index 93% rename from osal/linux/CountingSemaphore.cpp rename to src/fsfw/osal/linux/CountingSemaphore.cpp index 752e150b1..cc2117f34 100644 --- a/osal/linux/CountingSemaphore.cpp +++ b/src/fsfw/osal/linux/CountingSemaphore.cpp @@ -1,7 +1,7 @@ -#include "CountingSemaphore.h" -#include "unixUtility.h" +#include "fsfw/osal/linux/CountingSemaphore.h" +#include "fsfw/osal/linux/unixUtility.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include diff --git a/osal/linux/CountingSemaphore.h b/src/fsfw/osal/linux/CountingSemaphore.h similarity index 100% rename from osal/linux/CountingSemaphore.h rename to src/fsfw/osal/linux/CountingSemaphore.h diff --git a/osal/linux/FixedTimeslotTask.cpp b/src/fsfw/osal/linux/FixedTimeslotTask.cpp similarity index 95% rename from osal/linux/FixedTimeslotTask.cpp rename to src/fsfw/osal/linux/FixedTimeslotTask.cpp index c60c287a7..f66482990 100644 --- a/osal/linux/FixedTimeslotTask.cpp +++ b/src/fsfw/osal/linux/FixedTimeslotTask.cpp @@ -1,7 +1,7 @@ -#include "FixedTimeslotTask.h" +#include "fsfw/osal/linux/FixedTimeslotTask.h" -#include "../../objectmanager/ObjectManager.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include diff --git a/osal/linux/FixedTimeslotTask.h b/src/fsfw/osal/linux/FixedTimeslotTask.h similarity index 100% rename from osal/linux/FixedTimeslotTask.h rename to src/fsfw/osal/linux/FixedTimeslotTask.h diff --git a/osal/linux/InternalErrorCodes.cpp b/src/fsfw/osal/linux/InternalErrorCodes.cpp similarity index 84% rename from osal/linux/InternalErrorCodes.cpp rename to src/fsfw/osal/linux/InternalErrorCodes.cpp index a01cc72ac..14274535f 100644 --- a/osal/linux/InternalErrorCodes.cpp +++ b/src/fsfw/osal/linux/InternalErrorCodes.cpp @@ -1,4 +1,4 @@ -#include "../../osal/InternalErrorCodes.h" +#include "fsfw/osal/InternalErrorCodes.h" ReturnValue_t InternalErrorCodes::translate(uint8_t code) { //TODO This class can be removed diff --git a/osal/linux/MessageQueue.cpp b/src/fsfw/osal/linux/MessageQueue.cpp similarity index 98% rename from osal/linux/MessageQueue.cpp rename to src/fsfw/osal/linux/MessageQueue.cpp index 3c1511439..b068c04fe 100644 --- a/osal/linux/MessageQueue.cpp +++ b/src/fsfw/osal/linux/MessageQueue.cpp @@ -1,8 +1,8 @@ -#include "MessageQueue.h" -#include "unixUtility.h" +#include "fsfw/osal/linux/MessageQueue.h" +#include "fsfw/osal/linux/unixUtility.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" #include diff --git a/osal/linux/MessageQueue.h b/src/fsfw/osal/linux/MessageQueue.h similarity index 98% rename from osal/linux/MessageQueue.h rename to src/fsfw/osal/linux/MessageQueue.h index 935ee948d..cf0ac10c4 100644 --- a/osal/linux/MessageQueue.h +++ b/src/fsfw/osal/linux/MessageQueue.h @@ -1,9 +1,9 @@ #ifndef FSFW_OSAL_LINUX_MESSAGEQUEUE_H_ #define FSFW_OSAL_LINUX_MESSAGEQUEUE_H_ -#include "../../internalError/InternalErrorReporterIF.h" -#include "../../ipc/MessageQueueIF.h" -#include "../../ipc/MessageQueueMessage.h" +#include "fsfw/internalerror/InternalErrorReporterIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/MessageQueueMessage.h" #include /** diff --git a/osal/linux/Mutex.cpp b/src/fsfw/osal/linux/Mutex.cpp similarity index 95% rename from osal/linux/Mutex.cpp rename to src/fsfw/osal/linux/Mutex.cpp index 33e84aacc..7391c6b5b 100644 --- a/osal/linux/Mutex.cpp +++ b/src/fsfw/osal/linux/Mutex.cpp @@ -1,8 +1,8 @@ -#include "Mutex.h" -#include "unixUtility.h" +#include "fsfw/osal/linux/Mutex.h" +#include "fsfw/osal/linux/unixUtility.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../timemanager/Clock.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/timemanager/Clock.h" #include #include diff --git a/osal/linux/Mutex.h b/src/fsfw/osal/linux/Mutex.h similarity index 100% rename from osal/linux/Mutex.h rename to src/fsfw/osal/linux/Mutex.h diff --git a/osal/linux/MutexFactory.cpp b/src/fsfw/osal/linux/MutexFactory.cpp similarity index 86% rename from osal/linux/MutexFactory.cpp rename to src/fsfw/osal/linux/MutexFactory.cpp index 80211f8bc..373ff7da2 100644 --- a/osal/linux/MutexFactory.cpp +++ b/src/fsfw/osal/linux/MutexFactory.cpp @@ -1,6 +1,6 @@ -#include "Mutex.h" +#include "fsfw/osal/linux/Mutex.h" -#include "../../ipc/MutexFactory.h" +#include "fsfw/ipc/MutexFactory.h" //TODO: Different variant than the lazy loading in QueueFactory. What's better and why? MutexFactory* MutexFactory::factoryInstance = new MutexFactory(); diff --git a/osal/linux/PeriodicPosixTask.cpp b/src/fsfw/osal/linux/PeriodicPosixTask.cpp similarity index 91% rename from osal/linux/PeriodicPosixTask.cpp rename to src/fsfw/osal/linux/PeriodicPosixTask.cpp index c0152bec2..0603cf6ab 100644 --- a/osal/linux/PeriodicPosixTask.cpp +++ b/src/fsfw/osal/linux/PeriodicPosixTask.cpp @@ -1,8 +1,8 @@ -#include "PeriodicPosixTask.h" +#include "fsfw/osal/linux/PeriodicPosixTask.h" -#include "../../objectmanager/ObjectManager.h" -#include "../../tasks/ExecutableObjectIF.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include diff --git a/osal/linux/PeriodicPosixTask.h b/src/fsfw/osal/linux/PeriodicPosixTask.h similarity index 100% rename from osal/linux/PeriodicPosixTask.h rename to src/fsfw/osal/linux/PeriodicPosixTask.h diff --git a/osal/linux/PosixThread.cpp b/src/fsfw/osal/linux/PosixThread.cpp similarity index 98% rename from osal/linux/PosixThread.cpp rename to src/fsfw/osal/linux/PosixThread.cpp index 36501282a..5ca41d73f 100644 --- a/osal/linux/PosixThread.cpp +++ b/src/fsfw/osal/linux/PosixThread.cpp @@ -1,7 +1,7 @@ -#include "PosixThread.h" -#include "unixUtility.h" +#include "fsfw/osal/linux/PosixThread.h" +#include "fsfw/osal/linux/unixUtility.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include #include diff --git a/osal/linux/PosixThread.h b/src/fsfw/osal/linux/PosixThread.h similarity index 100% rename from osal/linux/PosixThread.h rename to src/fsfw/osal/linux/PosixThread.h diff --git a/osal/linux/QueueFactory.cpp b/src/fsfw/osal/linux/QueueFactory.cpp similarity index 79% rename from osal/linux/QueueFactory.cpp rename to src/fsfw/osal/linux/QueueFactory.cpp index 44def48a5..1df26ca9f 100644 --- a/osal/linux/QueueFactory.cpp +++ b/src/fsfw/osal/linux/QueueFactory.cpp @@ -1,14 +1,12 @@ -#include "../../ipc/QueueFactory.h" -#include "MessageQueue.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/osal/linux/MessageQueue.h" -#include "../../ipc/messageQueueDefinitions.h" -#include "../../ipc/MessageQueueSenderIF.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/ipc/messageQueueDefinitions.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" #include #include - #include QueueFactory* QueueFactory::factoryInstance = nullptr; diff --git a/osal/linux/SemaphoreFactory.cpp b/src/fsfw/osal/linux/SemaphoreFactory.cpp similarity index 81% rename from osal/linux/SemaphoreFactory.cpp rename to src/fsfw/osal/linux/SemaphoreFactory.cpp index cfb5f12dd..0a0974be0 100644 --- a/osal/linux/SemaphoreFactory.cpp +++ b/src/fsfw/osal/linux/SemaphoreFactory.cpp @@ -1,8 +1,7 @@ -#include "BinarySemaphore.h" -#include "CountingSemaphore.h" +#include "fsfw/osal/linux/BinarySemaphore.h" +#include "fsfw/osal/linux/CountingSemaphore.h" -#include "../../tasks/SemaphoreFactory.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/tasks/SemaphoreFactory.h" SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr; diff --git a/osal/linux/TaskFactory.cpp b/src/fsfw/osal/linux/TaskFactory.cpp similarity index 88% rename from osal/linux/TaskFactory.cpp rename to src/fsfw/osal/linux/TaskFactory.cpp index 80bf47b7c..53aea0ac0 100644 --- a/osal/linux/TaskFactory.cpp +++ b/src/fsfw/osal/linux/TaskFactory.cpp @@ -1,9 +1,9 @@ -#include "FixedTimeslotTask.h" -#include "PeriodicPosixTask.h" +#include "fsfw/osal/linux/FixedTimeslotTask.h" +#include "fsfw/osal/linux/PeriodicPosixTask.h" -#include "../../tasks/TaskFactory.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tasks/TaskFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" //TODO: Different variant than the lazy loading in QueueFactory. What's better and why? TaskFactory* TaskFactory::factoryInstance = new TaskFactory(); diff --git a/osal/linux/tcpipHelpers.cpp b/src/fsfw/osal/linux/tcpipHelpers.cpp similarity index 94% rename from osal/linux/tcpipHelpers.cpp rename to src/fsfw/osal/linux/tcpipHelpers.cpp index d7c644ecb..800c6fb76 100644 --- a/osal/linux/tcpipHelpers.cpp +++ b/src/fsfw/osal/linux/tcpipHelpers.cpp @@ -1,7 +1,7 @@ -#include "../common/tcpipHelpers.h" +#include "fsfw/osal/common/tcpipHelpers.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../tasks/TaskFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tasks/TaskFactory.h" #include #include diff --git a/osal/linux/unixUtility.cpp b/src/fsfw/osal/linux/unixUtility.cpp similarity index 73% rename from osal/linux/unixUtility.cpp rename to src/fsfw/osal/linux/unixUtility.cpp index d7aab4ba7..57e1f17a3 100644 --- a/osal/linux/unixUtility.cpp +++ b/src/fsfw/osal/linux/unixUtility.cpp @@ -1,6 +1,6 @@ -#include "FSFWConfig.h" -#include "unixUtility.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/FSFW.h" +#include "fsfw/osal/linux/unixUtility.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include #include @@ -14,7 +14,7 @@ void utility::printUnixErrorGeneric(const char* const className, #if FSFW_VERBOSE_LEVEL >= 1 if(outputType == sif::OutputTypes::OUT_ERROR) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << className << "::" << function << ":" << failString << " error: " + sif::error << className << "::" << function << ": " << failString << " error: " << strerror(errno) << std::endl; #else sif::printError("%s::%s: %s error: %s\n", className, function, failString, strerror(errno)); @@ -22,7 +22,7 @@ void utility::printUnixErrorGeneric(const char* const className, } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << className << "::" << function << ":" << failString << " error: " + sif::warning << className << "::" << function << ": " << failString << " error: " << strerror(errno) << std::endl; #else sif::printWarning("%s::%s: %s error: %s\n", className, function, failString, strerror(errno)); diff --git a/osal/linux/unixUtility.h b/src/fsfw/osal/linux/unixUtility.h similarity index 100% rename from osal/linux/unixUtility.h rename to src/fsfw/osal/linux/unixUtility.h diff --git a/src/fsfw/osal/rtems/BinarySemaphore.cpp b/src/fsfw/osal/rtems/BinarySemaphore.cpp new file mode 100644 index 000000000..6d145d983 --- /dev/null +++ b/src/fsfw/osal/rtems/BinarySemaphore.cpp @@ -0,0 +1,23 @@ +#include "BinarySemaphore.h" + +#include + +BinarySemaphore::BinarySemaphore() { +} + +BinarySemaphore::~BinarySemaphore() { + +} + +ReturnValue_t BinarySemaphore::acquire(TimeoutType timeoutType, uint32_t timeoutMs) { + return HasReturnvaluesIF::RETURN_OK; +} + + +ReturnValue_t BinarySemaphore::release() { + return HasReturnvaluesIF::RETURN_OK; +} + +uint8_t BinarySemaphore::getSemaphoreCounter() const { + return 0; +} diff --git a/src/fsfw/osal/rtems/BinarySemaphore.h b/src/fsfw/osal/rtems/BinarySemaphore.h new file mode 100644 index 000000000..a2796af1b --- /dev/null +++ b/src/fsfw/osal/rtems/BinarySemaphore.h @@ -0,0 +1,23 @@ +#ifndef FSFW_OSAL_RTEMS_BINARYSEMAPHORE_H_ +#define FSFW_OSAL_RTEMS_BINARYSEMAPHORE_H_ + +#include "fsfw/tasks/SemaphoreIF.h" + +class BinarySemaphore: public SemaphoreIF { +public: + BinarySemaphore(); + virtual ~BinarySemaphore(); + + // Semaphore IF implementations + ReturnValue_t acquire(TimeoutType timeoutType = + TimeoutType::BLOCKING, uint32_t timeoutMs = 0) override; + ReturnValue_t release() override; + uint8_t getSemaphoreCounter() const override; + +private: + +}; + + + +#endif /* FSFW_SRC_FSFW_OSAL_RTEMS_BINARYSEMAPHORE_H_ */ diff --git a/osal/rtems/CMakeLists.txt b/src/fsfw/osal/rtems/CMakeLists.txt similarity index 86% rename from osal/rtems/CMakeLists.txt rename to src/fsfw/osal/rtems/CMakeLists.txt index cd266125f..734566a37 100644 --- a/osal/rtems/CMakeLists.txt +++ b/src/fsfw/osal/rtems/CMakeLists.txt @@ -13,6 +13,8 @@ target_sources(${LIB_FSFW_NAME} RtemsBasic.cpp RTEMSTaskBase.cpp TaskFactory.cpp + BinarySemaphore.cpp + SemaphoreFactory.cpp ) diff --git a/osal/rtems/Clock.cpp b/src/fsfw/osal/rtems/Clock.cpp similarity index 97% rename from osal/rtems/Clock.cpp rename to src/fsfw/osal/rtems/Clock.cpp index ae720c361..42f30dcce 100644 --- a/osal/rtems/Clock.cpp +++ b/src/fsfw/osal/rtems/Clock.cpp @@ -1,7 +1,7 @@ -#include "RtemsBasic.h" +#include "fsfw/osal/rtems/RtemsBasic.h" -#include "../../timemanager/Clock.h" -#include "../../ipc/MutexGuard.h" +#include "fsfw/timemanager/Clock.h" +#include "fsfw/ipc/MutexGuard.h" #include #include diff --git a/osal/rtems/CpuUsage.cpp b/src/fsfw/osal/rtems/CpuUsage.cpp similarity index 97% rename from osal/rtems/CpuUsage.cpp rename to src/fsfw/osal/rtems/CpuUsage.cpp index 89c01336a..771b52dc7 100644 --- a/osal/rtems/CpuUsage.cpp +++ b/src/fsfw/osal/rtems/CpuUsage.cpp @@ -1,6 +1,6 @@ -#include "CpuUsage.h" -#include "../../serialize/SerialArrayListAdapter.h" -#include "../../serialize/SerializeAdapter.h" +#include "fsfw/osal/rtems/CpuUsage.h" +#include "fsfw/serialize/SerialArrayListAdapter.h" +#include "fsfw/serialize/SerializeAdapter.h" #include extern "C" { diff --git a/osal/rtems/CpuUsage.h b/src/fsfw/osal/rtems/CpuUsage.h similarity index 93% rename from osal/rtems/CpuUsage.h rename to src/fsfw/osal/rtems/CpuUsage.h index f487e1911..6b6b9910f 100644 --- a/osal/rtems/CpuUsage.h +++ b/src/fsfw/osal/rtems/CpuUsage.h @@ -1,8 +1,8 @@ #ifndef CPUUSAGE_H_ #define CPUUSAGE_H_ -#include "../../container/FixedArrayList.h" -#include "../../serialize/SerializeIF.h" +#include "fsfw/container/FixedArrayList.h" +#include "fsfw/serialize/SerializeIF.h" #include class CpuUsage : public SerializeIF { diff --git a/osal/rtems/FixedTimeslotTask.cpp b/src/fsfw/osal/rtems/FixedTimeslotTask.cpp similarity index 93% rename from osal/rtems/FixedTimeslotTask.cpp rename to src/fsfw/osal/rtems/FixedTimeslotTask.cpp index 19960a4c0..8b313df64 100644 --- a/osal/rtems/FixedTimeslotTask.cpp +++ b/src/fsfw/osal/rtems/FixedTimeslotTask.cpp @@ -1,11 +1,11 @@ -#include "FixedTimeslotTask.h" -#include "RtemsBasic.h" +#include "fsfw/osal/rtems/FixedTimeslotTask.h" +#include "fsfw/osal/rtems/RtemsBasic.h" -#include "../../tasks/FixedSequenceSlot.h" -#include "../../objectmanager/SystemObjectIF.h" -#include "../../objectmanager/ObjectManager.h" -#include "../../returnvalues/HasReturnvaluesIF.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/tasks/FixedSequenceSlot.h" +#include "fsfw/objectmanager/SystemObjectIF.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include #include diff --git a/osal/rtems/FixedTimeslotTask.h b/src/fsfw/osal/rtems/FixedTimeslotTask.h similarity index 100% rename from osal/rtems/FixedTimeslotTask.h rename to src/fsfw/osal/rtems/FixedTimeslotTask.h diff --git a/osal/rtems/InitTask.cpp b/src/fsfw/osal/rtems/InitTask.cpp similarity index 52% rename from osal/rtems/InitTask.cpp rename to src/fsfw/osal/rtems/InitTask.cpp index 80afed3d9..8a9bb9f63 100644 --- a/osal/rtems/InitTask.cpp +++ b/src/fsfw/osal/rtems/InitTask.cpp @@ -1,5 +1,5 @@ -#include "InitTask.h" -#include "RtemsBasic.h" +#include "fsfw/osal/rtems/InitTask.h" +#include "fsfw/osal/rtems/RtemsBasic.h" diff --git a/osal/rtems/InitTask.h b/src/fsfw/osal/rtems/InitTask.h similarity index 100% rename from osal/rtems/InitTask.h rename to src/fsfw/osal/rtems/InitTask.h diff --git a/osal/rtems/InternalErrorCodes.cpp b/src/fsfw/osal/rtems/InternalErrorCodes.cpp similarity index 97% rename from osal/rtems/InternalErrorCodes.cpp rename to src/fsfw/osal/rtems/InternalErrorCodes.cpp index f40798147..049286d78 100644 --- a/osal/rtems/InternalErrorCodes.cpp +++ b/src/fsfw/osal/rtems/InternalErrorCodes.cpp @@ -1,4 +1,4 @@ -#include "../../osal/InternalErrorCodes.h" +#include "fsfw/osal/InternalErrorCodes.h" #include ReturnValue_t InternalErrorCodes::translate(uint8_t code) { diff --git a/osal/rtems/MessageQueue.cpp b/src/fsfw/osal/rtems/MessageQueue.cpp similarity index 96% rename from osal/rtems/MessageQueue.cpp rename to src/fsfw/osal/rtems/MessageQueue.cpp index e8128e90c..65fe0946c 100644 --- a/osal/rtems/MessageQueue.cpp +++ b/src/fsfw/osal/rtems/MessageQueue.cpp @@ -1,8 +1,8 @@ -#include "MessageQueue.h" -#include "RtemsBasic.h" +#include "fsfw/osal/rtems/MessageQueue.h" +#include "fsfw/osal/rtems/RtemsBasic.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" #include diff --git a/osal/rtems/MessageQueue.h b/src/fsfw/osal/rtems/MessageQueue.h similarity index 98% rename from osal/rtems/MessageQueue.h rename to src/fsfw/osal/rtems/MessageQueue.h index 342f1e30f..fa143ebe0 100644 --- a/osal/rtems/MessageQueue.h +++ b/src/fsfw/osal/rtems/MessageQueue.h @@ -1,9 +1,9 @@ #ifndef FSFW_OSAL_RTEMS_MESSAGEQUEUE_H_ #define FSFW_OSAL_RTEMS_MESSAGEQUEUE_H_ -#include "../../internalError/InternalErrorReporterIF.h" -#include "../../ipc/MessageQueueIF.h" -#include "../../ipc/MessageQueueMessage.h" +#include "fsfw/internalerror/InternalErrorReporterIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/MessageQueueMessage.h" #include "RtemsBasic.h" /** diff --git a/osal/rtems/Mutex.cpp b/src/fsfw/osal/rtems/Mutex.cpp similarity index 96% rename from osal/rtems/Mutex.cpp rename to src/fsfw/osal/rtems/Mutex.cpp index f65c1f55b..2dfa39fa4 100644 --- a/osal/rtems/Mutex.cpp +++ b/src/fsfw/osal/rtems/Mutex.cpp @@ -1,5 +1,5 @@ -#include "Mutex.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/osal/rtems/Mutex.h" +#include "fsfw/serviceinterface/ServiceInterface.h" uint8_t Mutex::count = 0; diff --git a/osal/rtems/Mutex.h b/src/fsfw/osal/rtems/Mutex.h similarity index 100% rename from osal/rtems/Mutex.h rename to src/fsfw/osal/rtems/Mutex.h diff --git a/osal/rtems/MutexFactory.cpp b/src/fsfw/osal/rtems/MutexFactory.cpp similarity index 83% rename from osal/rtems/MutexFactory.cpp rename to src/fsfw/osal/rtems/MutexFactory.cpp index adc599e94..bf7ce666c 100644 --- a/osal/rtems/MutexFactory.cpp +++ b/src/fsfw/osal/rtems/MutexFactory.cpp @@ -1,6 +1,6 @@ -#include "Mutex.h" +#include "fsfw/osal/rtems/Mutex.h" -#include "../../ipc/MutexFactory.h" +#include "fsfw/ipc/MutexFactory.h" MutexFactory* MutexFactory::factoryInstance = new MutexFactory(); diff --git a/osal/rtems/PeriodicTask.cpp b/src/fsfw/osal/rtems/PeriodicTask.cpp similarity index 93% rename from osal/rtems/PeriodicTask.cpp rename to src/fsfw/osal/rtems/PeriodicTask.cpp index 587173442..db98153cb 100644 --- a/osal/rtems/PeriodicTask.cpp +++ b/src/fsfw/osal/rtems/PeriodicTask.cpp @@ -1,8 +1,8 @@ -#include "PeriodicTask.h" +#include "fsfw/osal/rtems/PeriodicTask.h" -#include "../../serviceinterface/ServiceInterface.h" -#include "../../objectmanager/ObjectManager.h" -#include "../../tasks/ExecutableObjectIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/tasks/ExecutableObjectIF.h" PeriodicTask::PeriodicTask(const char *name, rtems_task_priority setPriority, size_t setStack, rtems_interval setPeriod, void (*setDeadlineMissedFunc)()) : diff --git a/osal/rtems/PeriodicTask.h b/src/fsfw/osal/rtems/PeriodicTask.h similarity index 100% rename from osal/rtems/PeriodicTask.h rename to src/fsfw/osal/rtems/PeriodicTask.h diff --git a/osal/rtems/QueueFactory.cpp b/src/fsfw/osal/rtems/QueueFactory.cpp similarity index 90% rename from osal/rtems/QueueFactory.cpp rename to src/fsfw/osal/rtems/QueueFactory.cpp index ff5613041..ddcc39598 100644 --- a/osal/rtems/QueueFactory.cpp +++ b/src/fsfw/osal/rtems/QueueFactory.cpp @@ -1,7 +1,8 @@ -#include "../../ipc/QueueFactory.h" -#include "../../ipc/MessageQueueSenderIF.h" -#include "MessageQueue.h" -#include "RtemsBasic.h" +#include "fsfw/osal/rtems/MessageQueue.h" +#include "fsfw/osal/rtems/RtemsBasic.h" + +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" QueueFactory* QueueFactory::factoryInstance = nullptr; diff --git a/osal/rtems/RTEMSTaskBase.cpp b/src/fsfw/osal/rtems/RTEMSTaskBase.cpp similarity index 96% rename from osal/rtems/RTEMSTaskBase.cpp rename to src/fsfw/osal/rtems/RTEMSTaskBase.cpp index d0cdc8765..fc8bbed58 100644 --- a/osal/rtems/RTEMSTaskBase.cpp +++ b/src/fsfw/osal/rtems/RTEMSTaskBase.cpp @@ -1,5 +1,5 @@ -#include "RTEMSTaskBase.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/osal/rtems/RTEMSTaskBase.h" +#include "fsfw/serviceinterface/ServiceInterface.h" const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = RTEMS_MINIMUM_STACK_SIZE; diff --git a/osal/rtems/RTEMSTaskBase.h b/src/fsfw/osal/rtems/RTEMSTaskBase.h similarity index 100% rename from osal/rtems/RTEMSTaskBase.h rename to src/fsfw/osal/rtems/RTEMSTaskBase.h diff --git a/src/fsfw/osal/rtems/RtemsBasic.cpp b/src/fsfw/osal/rtems/RtemsBasic.cpp new file mode 100644 index 000000000..463824ad7 --- /dev/null +++ b/src/fsfw/osal/rtems/RtemsBasic.cpp @@ -0,0 +1 @@ +#include "fsfw/osal/rtems/RtemsBasic.h" diff --git a/osal/rtems/RtemsBasic.h b/src/fsfw/osal/rtems/RtemsBasic.h similarity index 92% rename from osal/rtems/RtemsBasic.h rename to src/fsfw/osal/rtems/RtemsBasic.h index 73f23186e..382697a33 100644 --- a/osal/rtems/RtemsBasic.h +++ b/src/fsfw/osal/rtems/RtemsBasic.h @@ -1,7 +1,7 @@ #ifndef FSFW_OSAL_RTEMS_RTEMSBASIC_H_ #define FSFW_OSAL_RTEMS_RTEMSBASIC_H_ -#include "../../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include #include diff --git a/src/fsfw/osal/rtems/SemaphoreFactory.cpp b/src/fsfw/osal/rtems/SemaphoreFactory.cpp new file mode 100644 index 000000000..cec4b833a --- /dev/null +++ b/src/fsfw/osal/rtems/SemaphoreFactory.cpp @@ -0,0 +1,34 @@ +#include "fsfw/osal/rtems/BinarySemaphore.h" +//#include "fsfw/osal/rtems/CountingSemaphore.h" + +#include "fsfw/tasks/SemaphoreFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" + +SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr; + +SemaphoreFactory::SemaphoreFactory() { +} + +SemaphoreFactory::~SemaphoreFactory() { + delete factoryInstance; +} + +SemaphoreFactory* SemaphoreFactory::instance() { + if (factoryInstance == nullptr){ + factoryInstance = new SemaphoreFactory(); + } + return SemaphoreFactory::factoryInstance; +} + +SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t argument) { + return new BinarySemaphore(); +} + +SemaphoreIF* SemaphoreFactory::createCountingSemaphore(uint8_t maxCount, + uint8_t initCount, uint32_t argument) { + return nullptr; +} + +void SemaphoreFactory::deleteSemaphore(SemaphoreIF* semaphore) { + delete semaphore; +} diff --git a/osal/rtems/TaskFactory.cpp b/src/fsfw/osal/rtems/TaskFactory.cpp similarity index 86% rename from osal/rtems/TaskFactory.cpp rename to src/fsfw/osal/rtems/TaskFactory.cpp index 095e9a262..dd3e92fc2 100644 --- a/osal/rtems/TaskFactory.cpp +++ b/src/fsfw/osal/rtems/TaskFactory.cpp @@ -1,10 +1,10 @@ -#include "FixedTimeslotTask.h" -#include "PeriodicTask.h" -#include "InitTask.h" -#include "RtemsBasic.h" +#include "fsfw/osal/rtems/FixedTimeslotTask.h" +#include "fsfw/osal/rtems/PeriodicTask.h" +#include "fsfw/osal/rtems/InitTask.h" +#include "fsfw/osal/rtems/RtemsBasic.h" -#include "../../tasks/TaskFactory.h" -#include "../../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tasks/TaskFactory.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" //TODO: Different variant than the lazy loading in QueueFactory. What's better and why? TaskFactory* TaskFactory::factoryInstance = new TaskFactory(); diff --git a/osal/windows/CMakeLists.txt b/src/fsfw/osal/windows/CMakeLists.txt similarity index 100% rename from osal/windows/CMakeLists.txt rename to src/fsfw/osal/windows/CMakeLists.txt diff --git a/osal/windows/tcpipHelpers.cpp b/src/fsfw/osal/windows/tcpipHelpers.cpp similarity index 90% rename from osal/windows/tcpipHelpers.cpp rename to src/fsfw/osal/windows/tcpipHelpers.cpp index 3dab9406c..37d6fb2f4 100644 --- a/osal/windows/tcpipHelpers.cpp +++ b/src/fsfw/osal/windows/tcpipHelpers.cpp @@ -1,8 +1,8 @@ -#include "../common/tcpipHelpers.h" -#include +#include "fsfw/FSFW.h" +#include "fsfw/osal/common/tcpipHelpers.h" -#include "../../tasks/TaskFactory.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/tasks/TaskFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include diff --git a/osal/windows/winTaskHelpers.cpp b/src/fsfw/osal/windows/winTaskHelpers.cpp similarity index 98% rename from osal/windows/winTaskHelpers.cpp rename to src/fsfw/osal/windows/winTaskHelpers.cpp index 6765b952c..20d4d98d3 100644 --- a/osal/windows/winTaskHelpers.cpp +++ b/src/fsfw/osal/windows/winTaskHelpers.cpp @@ -1,4 +1,5 @@ -#include +#include "fsfw/osal/windows/winTaskHelpers.h" + #include TaskPriority tasks::makeWinPriority(PriorityClass prioClass, PriorityNumber prioNumber) { diff --git a/osal/windows/winTaskHelpers.h b/src/fsfw/osal/windows/winTaskHelpers.h similarity index 100% rename from osal/windows/winTaskHelpers.h rename to src/fsfw/osal/windows/winTaskHelpers.h diff --git a/parameters/CMakeLists.txt b/src/fsfw/parameters/CMakeLists.txt similarity index 100% rename from parameters/CMakeLists.txt rename to src/fsfw/parameters/CMakeLists.txt diff --git a/parameters/HasParametersIF.h b/src/fsfw/parameters/HasParametersIF.h similarity index 100% rename from parameters/HasParametersIF.h rename to src/fsfw/parameters/HasParametersIF.h diff --git a/parameters/ParameterHelper.cpp b/src/fsfw/parameters/ParameterHelper.cpp similarity index 97% rename from parameters/ParameterHelper.cpp rename to src/fsfw/parameters/ParameterHelper.cpp index 694ec5a44..9250a1d4b 100644 --- a/parameters/ParameterHelper.cpp +++ b/src/fsfw/parameters/ParameterHelper.cpp @@ -1,7 +1,7 @@ -#include "ParameterHelper.h" -#include "ParameterMessage.h" +#include "fsfw/parameters/ParameterHelper.h" +#include "fsfw/parameters/ParameterMessage.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/objectmanager/ObjectManager.h" ParameterHelper::ParameterHelper(ReceivesParameterMessagesIF* owner): owner(owner) {} diff --git a/parameters/ParameterHelper.h b/src/fsfw/parameters/ParameterHelper.h similarity index 100% rename from parameters/ParameterHelper.h rename to src/fsfw/parameters/ParameterHelper.h diff --git a/parameters/ParameterMessage.cpp b/src/fsfw/parameters/ParameterMessage.cpp similarity index 95% rename from parameters/ParameterMessage.cpp rename to src/fsfw/parameters/ParameterMessage.cpp index 8a5835ff5..ee58339ca 100644 --- a/parameters/ParameterMessage.cpp +++ b/src/fsfw/parameters/ParameterMessage.cpp @@ -1,6 +1,6 @@ -#include "ParameterMessage.h" +#include "fsfw/parameters/ParameterMessage.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/objectmanager/ObjectManager.h" ParameterId_t ParameterMessage::getParameterId(const CommandMessage* message) { return message->getParameter(); diff --git a/parameters/ParameterMessage.h b/src/fsfw/parameters/ParameterMessage.h similarity index 100% rename from parameters/ParameterMessage.h rename to src/fsfw/parameters/ParameterMessage.h diff --git a/parameters/ParameterWrapper.cpp b/src/fsfw/parameters/ParameterWrapper.cpp similarity index 98% rename from parameters/ParameterWrapper.cpp rename to src/fsfw/parameters/ParameterWrapper.cpp index 660d7db71..8c09a8221 100644 --- a/parameters/ParameterWrapper.cpp +++ b/src/fsfw/parameters/ParameterWrapper.cpp @@ -1,6 +1,6 @@ -#include "ParameterWrapper.h" -#include -#include +#include "fsfw/FSFW.h" +#include "fsfw/parameters/ParameterWrapper.h" +#include "fsfw/serviceinterface/ServiceInterface.h" ParameterWrapper::ParameterWrapper() : pointsToStream(false), type(Type::UNKNOWN_TYPE) { diff --git a/parameters/ParameterWrapper.h b/src/fsfw/parameters/ParameterWrapper.h similarity index 100% rename from parameters/ParameterWrapper.h rename to src/fsfw/parameters/ParameterWrapper.h diff --git a/parameters/ReceivesParameterMessagesIF.h b/src/fsfw/parameters/ReceivesParameterMessagesIF.h similarity index 100% rename from parameters/ReceivesParameterMessagesIF.h rename to src/fsfw/parameters/ReceivesParameterMessagesIF.h diff --git a/platform.h b/src/fsfw/platform.h similarity index 100% rename from platform.h rename to src/fsfw/platform.h diff --git a/power/CMakeLists.txt b/src/fsfw/power/CMakeLists.txt similarity index 100% rename from power/CMakeLists.txt rename to src/fsfw/power/CMakeLists.txt diff --git a/power/Fuse.cpp b/src/fsfw/power/Fuse.cpp similarity index 96% rename from power/Fuse.cpp rename to src/fsfw/power/Fuse.cpp index 0cb1385b5..821bdbc51 100644 --- a/power/Fuse.cpp +++ b/src/fsfw/power/Fuse.cpp @@ -1,10 +1,10 @@ -#include "Fuse.h" +#include "fsfw/power/Fuse.h" -#include "../monitoring/LimitViolationReporter.h" -#include "../monitoring/MonitoringMessageContent.h" -#include "../objectmanager/ObjectManager.h" -#include "../serialize/SerialFixedArrayListAdapter.h" -#include "../ipc/QueueFactory.h" +#include "fsfw/monitoring/LimitViolationReporter.h" +#include "fsfw/monitoring/MonitoringMessageContent.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serialize/SerialFixedArrayListAdapter.h" +#include "fsfw/ipc/QueueFactory.h" object_id_t Fuse::powerSwitchId = 0; diff --git a/power/Fuse.h b/src/fsfw/power/Fuse.h similarity index 100% rename from power/Fuse.h rename to src/fsfw/power/Fuse.h diff --git a/power/PowerComponent.cpp b/src/fsfw/power/PowerComponent.cpp similarity index 96% rename from power/PowerComponent.cpp rename to src/fsfw/power/PowerComponent.cpp index 9ea84dadb..fb66748ae 100644 --- a/power/PowerComponent.cpp +++ b/src/fsfw/power/PowerComponent.cpp @@ -1,5 +1,5 @@ -#include "PowerComponent.h" -#include "../serialize/SerializeAdapter.h" +#include "fsfw/power/PowerComponent.h" +#include "fsfw/serialize/SerializeAdapter.h" PowerComponent::PowerComponent(): switchId1(0xFF), switchId2(0xFF), diff --git a/power/PowerComponent.h b/src/fsfw/power/PowerComponent.h similarity index 92% rename from power/PowerComponent.h rename to src/fsfw/power/PowerComponent.h index 6b9778a59..3889a2ae7 100644 --- a/power/PowerComponent.h +++ b/src/fsfw/power/PowerComponent.h @@ -3,8 +3,8 @@ #include "PowerComponentIF.h" -#include "../objectmanager/frameworkObjects.h" -#include "../objectmanager/SystemObjectIF.h" +#include "fsfw/objectmanager/frameworkObjects.h" +#include "fsfw/objectmanager/SystemObjectIF.h" class PowerComponent: public PowerComponentIF { diff --git a/power/PowerComponentIF.h b/src/fsfw/power/PowerComponentIF.h similarity index 100% rename from power/PowerComponentIF.h rename to src/fsfw/power/PowerComponentIF.h diff --git a/power/PowerSensor.cpp b/src/fsfw/power/PowerSensor.cpp similarity index 98% rename from power/PowerSensor.cpp rename to src/fsfw/power/PowerSensor.cpp index 40d7afc61..e1e313533 100644 --- a/power/PowerSensor.cpp +++ b/src/fsfw/power/PowerSensor.cpp @@ -1,6 +1,6 @@ -#include "PowerSensor.h" +#include "fsfw/power/PowerSensor.h" -#include "../ipc/QueueFactory.h" +#include "fsfw/ipc/QueueFactory.h" PowerSensor::PowerSensor(object_id_t objectId, sid_t setId, VariableIds ids, DefaultLimits limits, SensorEvents events, uint16_t confirmationCount) : diff --git a/power/PowerSensor.h b/src/fsfw/power/PowerSensor.h similarity index 87% rename from power/PowerSensor.h rename to src/fsfw/power/PowerSensor.h index 5a21ab104..d00c5420c 100644 --- a/power/PowerSensor.h +++ b/src/fsfw/power/PowerSensor.h @@ -1,12 +1,12 @@ #ifndef FSFW_POWER_POWERSENSOR_H_ #define FSFW_POWER_POWERSENSOR_H_ -#include "../datapoollocal/StaticLocalDataSet.h" -#include "../devicehandlers/HealthDevice.h" -#include "../monitoring/LimitMonitor.h" -#include "../parameters/ParameterHelper.h" -#include "../objectmanager/SystemObject.h" -#include "../ipc/MessageQueueIF.h" +#include "fsfw/datapoollocal/StaticLocalDataSet.h" +#include "fsfw/devicehandlers/HealthDevice.h" +#include "fsfw/monitoring/LimitMonitor.h" +#include "fsfw/parameters/ParameterHelper.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/ipc/MessageQueueIF.h" class PowerController; diff --git a/power/PowerSwitchIF.h b/src/fsfw/power/PowerSwitchIF.h similarity index 100% rename from power/PowerSwitchIF.h rename to src/fsfw/power/PowerSwitchIF.h diff --git a/power/PowerSwitcher.cpp b/src/fsfw/power/PowerSwitcher.cpp similarity index 95% rename from power/PowerSwitcher.cpp rename to src/fsfw/power/PowerSwitcher.cpp index 642a26971..f849a7fb2 100644 --- a/power/PowerSwitcher.cpp +++ b/src/fsfw/power/PowerSwitcher.cpp @@ -1,7 +1,7 @@ -#include "PowerSwitcher.h" +#include "fsfw/power/PowerSwitcher.h" -#include "../objectmanager/ObjectManager.h" -#include "../serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" PowerSwitcher::PowerSwitcher(uint8_t setSwitch1, uint8_t setSwitch2, PowerSwitcher::State_t setStartState): diff --git a/power/PowerSwitcher.h b/src/fsfw/power/PowerSwitcher.h similarity index 100% rename from power/PowerSwitcher.h rename to src/fsfw/power/PowerSwitcher.h diff --git a/pus/CMakeLists.txt b/src/fsfw/pus/CMakeLists.txt similarity index 100% rename from pus/CMakeLists.txt rename to src/fsfw/pus/CMakeLists.txt diff --git a/pus/CService200ModeCommanding.cpp b/src/fsfw/pus/CService200ModeCommanding.cpp similarity index 92% rename from pus/CService200ModeCommanding.cpp rename to src/fsfw/pus/CService200ModeCommanding.cpp index d178b3a98..66c61dbe2 100644 --- a/pus/CService200ModeCommanding.cpp +++ b/src/fsfw/pus/CService200ModeCommanding.cpp @@ -1,11 +1,11 @@ -#include "CService200ModeCommanding.h" -#include "servicepackets/Service200Packets.h" +#include "fsfw/pus/CService200ModeCommanding.h" +#include "fsfw/pus/servicepackets/Service200Packets.h" -#include "../modes/HasModesIF.h" -#include "../objectmanager/ObjectManager.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../serialize/SerialLinkedListAdapter.h" -#include "../modes/ModeMessage.h" +#include "fsfw/modes/HasModesIF.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/serialize/SerialLinkedListAdapter.h" +#include "fsfw/modes/ModeMessage.h" CService200ModeCommanding::CService200ModeCommanding(object_id_t objectId, uint16_t apid, uint8_t serviceId, uint8_t numParallelCommands, diff --git a/pus/CService200ModeCommanding.h b/src/fsfw/pus/CService200ModeCommanding.h similarity index 98% rename from pus/CService200ModeCommanding.h rename to src/fsfw/pus/CService200ModeCommanding.h index 840402120..d523d6c3a 100644 --- a/pus/CService200ModeCommanding.h +++ b/src/fsfw/pus/CService200ModeCommanding.h @@ -1,7 +1,7 @@ #ifndef FSFW_PUS_CSERVICE200MODECOMMANDING_H_ #define FSFW_PUS_CSERVICE200MODECOMMANDING_H_ -#include "../tmtcservices/CommandingServiceBase.h" +#include "fsfw/tmtcservices/CommandingServiceBase.h" /** * @brief Custom PUS service to set mode of all objects implementing HasModesIF diff --git a/pus/CService201HealthCommanding.cpp b/src/fsfw/pus/CService201HealthCommanding.cpp similarity index 92% rename from pus/CService201HealthCommanding.cpp rename to src/fsfw/pus/CService201HealthCommanding.cpp index 52a8a603c..1e414c824 100644 --- a/pus/CService201HealthCommanding.cpp +++ b/src/fsfw/pus/CService201HealthCommanding.cpp @@ -1,10 +1,10 @@ -#include "CService201HealthCommanding.h" -#include "servicepackets/Service201Packets.h" +#include "fsfw/pus/CService201HealthCommanding.h" +#include "fsfw/pus/servicepackets/Service201Packets.h" -#include "../health/HasHealthIF.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../objectmanager/ObjectManager.h" -#include "../health/HealthMessage.h" +#include "fsfw/health/HasHealthIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/health/HealthMessage.h" CService201HealthCommanding::CService201HealthCommanding(object_id_t objectId, diff --git a/pus/CService201HealthCommanding.h b/src/fsfw/pus/CService201HealthCommanding.h similarity index 100% rename from pus/CService201HealthCommanding.h rename to src/fsfw/pus/CService201HealthCommanding.h diff --git a/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp similarity index 87% rename from pus/Service17Test.cpp rename to src/fsfw/pus/Service17Test.cpp index 37258cc16..20227172c 100644 --- a/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -1,9 +1,9 @@ -#include "Service17Test.h" -#include +#include "fsfw/FSFW.h" +#include "fsfw/pus/Service17Test.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../objectmanager/SystemObject.h" -#include "../tmtcpacket/pus/tm/TmPacketStored.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" Service17Test::Service17Test(object_id_t objectId, diff --git a/pus/Service17Test.h b/src/fsfw/pus/Service17Test.h similarity index 93% rename from pus/Service17Test.h rename to src/fsfw/pus/Service17Test.h index 83d436ea3..d1e1ecceb 100644 --- a/pus/Service17Test.h +++ b/src/fsfw/pus/Service17Test.h @@ -1,8 +1,8 @@ #ifndef FSFW_PUS_SERVICE17TEST_H_ #define FSFW_PUS_SERVICE17TEST_H_ -#include "../tmtcservices/PusServiceBase.h" -#include "../objectmanager/SystemObject.h" +#include "fsfw/tmtcservices/PusServiceBase.h" +#include "fsfw/objectmanager/SystemObject.h" /** * @brief Test Service diff --git a/pus/Service1TelecommandVerification.cpp b/src/fsfw/pus/Service1TelecommandVerification.cpp similarity index 90% rename from pus/Service1TelecommandVerification.cpp rename to src/fsfw/pus/Service1TelecommandVerification.cpp index 8aec6902c..c6b024f9e 100644 --- a/pus/Service1TelecommandVerification.cpp +++ b/src/fsfw/pus/Service1TelecommandVerification.cpp @@ -1,12 +1,12 @@ -#include "Service1TelecommandVerification.h" -#include "servicepackets/Service1Packets.h" +#include "fsfw/pus/Service1TelecommandVerification.h" +#include "fsfw/pus/servicepackets/Service1Packets.h" -#include "../ipc/QueueFactory.h" -#include "../objectmanager/ObjectManager.h" -#include "../tmtcservices/PusVerificationReport.h" -#include "../tmtcpacket/pus/tm/TmPacketStored.h" -#include "../serviceinterface/ServiceInterfaceStream.h" -#include "../tmtcservices/AcceptsTelemetryIF.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/tmtcservices/PusVerificationReport.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" Service1TelecommandVerification::Service1TelecommandVerification( object_id_t objectId, uint16_t apid, uint8_t serviceId, diff --git a/pus/Service1TelecommandVerification.h b/src/fsfw/pus/Service1TelecommandVerification.h similarity index 91% rename from pus/Service1TelecommandVerification.h rename to src/fsfw/pus/Service1TelecommandVerification.h index 3d68a4e06..262844935 100644 --- a/pus/Service1TelecommandVerification.h +++ b/src/fsfw/pus/Service1TelecommandVerification.h @@ -1,12 +1,12 @@ #ifndef FSFW_PUS_SERVICE1TELECOMMANDVERIFICATION_H_ #define FSFW_PUS_SERVICE1TELECOMMANDVERIFICATION_H_ -#include "../objectmanager/SystemObject.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../tasks/ExecutableObjectIF.h" -#include "../tmtcservices/AcceptsVerifyMessageIF.h" -#include "../tmtcservices/PusVerificationReport.h" -#include "../ipc/MessageQueueIF.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/tmtcservices/AcceptsVerifyMessageIF.h" +#include "fsfw/tmtcservices/PusVerificationReport.h" +#include "fsfw/ipc/MessageQueueIF.h" /** * @brief Verify TC acceptance, start, progress and execution. diff --git a/pus/Service20ParameterManagement.cpp b/src/fsfw/pus/Service20ParameterManagement.cpp similarity index 95% rename from pus/Service20ParameterManagement.cpp rename to src/fsfw/pus/Service20ParameterManagement.cpp index c4e4b5eb1..e28e78046 100644 --- a/pus/Service20ParameterManagement.cpp +++ b/src/fsfw/pus/Service20ParameterManagement.cpp @@ -1,11 +1,11 @@ -#include "Service20ParameterManagement.h" -#include "servicepackets/Service20Packets.h" +#include "fsfw/pus/Service20ParameterManagement.h" +#include "fsfw/pus/servicepackets/Service20Packets.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../parameters/HasParametersIF.h" -#include "../parameters/ParameterMessage.h" -#include "../objectmanager/ObjectManager.h" -#include "../parameters/ReceivesParameterMessagesIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/parameters/HasParametersIF.h" +#include "fsfw/parameters/ParameterMessage.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/parameters/ReceivesParameterMessagesIF.h" Service20ParameterManagement::Service20ParameterManagement(object_id_t objectId, uint16_t apid, diff --git a/pus/Service20ParameterManagement.h b/src/fsfw/pus/Service20ParameterManagement.h similarity index 97% rename from pus/Service20ParameterManagement.h rename to src/fsfw/pus/Service20ParameterManagement.h index 5370bfcb3..63ec199cb 100644 --- a/pus/Service20ParameterManagement.h +++ b/src/fsfw/pus/Service20ParameterManagement.h @@ -1,7 +1,7 @@ #ifndef FSFW_PUS_SERVICE20PARAMETERMANAGEMENT_H_ #define FSFW_PUS_SERVICE20PARAMETERMANAGEMENT_H_ -#include "../tmtcservices/CommandingServiceBase.h" +#include "fsfw/tmtcservices/CommandingServiceBase.h" /** * @brief PUS Service 20 Parameter Service implementation diff --git a/pus/Service2DeviceAccess.cpp b/src/fsfw/pus/Service2DeviceAccess.cpp similarity index 91% rename from pus/Service2DeviceAccess.cpp rename to src/fsfw/pus/Service2DeviceAccess.cpp index 4cf75d32e..0e5edfd34 100644 --- a/pus/Service2DeviceAccess.cpp +++ b/src/fsfw/pus/Service2DeviceAccess.cpp @@ -1,15 +1,15 @@ -#include "Service2DeviceAccess.h" -#include "servicepackets/Service2Packets.h" +#include "fsfw/pus/Service2DeviceAccess.h" +#include "fsfw/pus/servicepackets/Service2Packets.h" -#include "../objectmanager/ObjectManager.h" -#include "../devicehandlers/DeviceHandlerIF.h" -#include "../storagemanager/StorageManagerIF.h" -#include "../devicehandlers/DeviceHandlerMessage.h" -#include "../serialize/EndianConverter.h" -#include "../action/ActionMessage.h" -#include "../serialize/SerializeAdapter.h" -#include "../serialize/SerialLinkedListAdapter.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/devicehandlers/DeviceHandlerIF.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/devicehandlers/DeviceHandlerMessage.h" +#include "fsfw/serialize/EndianConverter.h" +#include "fsfw/action/ActionMessage.h" +#include "fsfw/serialize/SerializeAdapter.h" +#include "fsfw/serialize/SerialLinkedListAdapter.h" +#include "fsfw/serviceinterface/ServiceInterface.h" Service2DeviceAccess::Service2DeviceAccess(object_id_t objectId, uint16_t apid, uint8_t serviceId, uint8_t numberOfParallelCommands, diff --git a/pus/Service2DeviceAccess.h b/src/fsfw/pus/Service2DeviceAccess.h similarity index 95% rename from pus/Service2DeviceAccess.h rename to src/fsfw/pus/Service2DeviceAccess.h index b62e6854a..e518863c5 100644 --- a/pus/Service2DeviceAccess.h +++ b/src/fsfw/pus/Service2DeviceAccess.h @@ -1,9 +1,9 @@ #ifndef FSFW_PUS_SERVICE2DEVICEACCESS_H_ #define FSFW_PUS_SERVICE2DEVICEACCESS_H_ -#include "../objectmanager/SystemObjectIF.h" -#include "../devicehandlers/AcceptsDeviceResponsesIF.h" -#include "../tmtcservices/CommandingServiceBase.h" +#include "fsfw/objectmanager/SystemObjectIF.h" +#include "fsfw/devicehandlers/AcceptsDeviceResponsesIF.h" +#include "fsfw/tmtcservices/CommandingServiceBase.h" /** * @brief Raw Commanding and Wiretapping of devices. diff --git a/pus/Service3Housekeeping.cpp b/src/fsfw/pus/Service3Housekeeping.cpp similarity index 98% rename from pus/Service3Housekeeping.cpp rename to src/fsfw/pus/Service3Housekeeping.cpp index 6b1275b32..2b91f366d 100644 --- a/pus/Service3Housekeeping.cpp +++ b/src/fsfw/pus/Service3Housekeeping.cpp @@ -1,8 +1,8 @@ -#include "Service3Housekeeping.h" -#include "servicepackets/Service3Packets.h" +#include "fsfw/pus/Service3Housekeeping.h" +#include "fsfw/pus/servicepackets/Service3Packets.h" -#include "../objectmanager/ObjectManager.h" -#include "../datapoollocal/HasLocalDataPoolIF.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/datapoollocal/HasLocalDataPoolIF.h" Service3Housekeeping::Service3Housekeeping(object_id_t objectId, uint16_t apid, uint8_t serviceId): diff --git a/pus/Service3Housekeeping.h b/src/fsfw/pus/Service3Housekeeping.h similarity index 96% rename from pus/Service3Housekeeping.h rename to src/fsfw/pus/Service3Housekeeping.h index 269710ef3..d2dc6066d 100644 --- a/pus/Service3Housekeeping.h +++ b/src/fsfw/pus/Service3Housekeeping.h @@ -1,9 +1,9 @@ #ifndef FSFW_PUS_SERVICE3HOUSEKEEPINGSERVICE_H_ #define FSFW_PUS_SERVICE3HOUSEKEEPINGSERVICE_H_ -#include "../housekeeping/AcceptsHkPacketsIF.h" -#include "../housekeeping/HousekeepingMessage.h" -#include "../tmtcservices/CommandingServiceBase.h" +#include "fsfw/housekeeping/AcceptsHkPacketsIF.h" +#include "fsfw/housekeeping/HousekeepingMessage.h" +#include "fsfw/tmtcservices/CommandingServiceBase.h" /** * @brief Manges spacecraft housekeeping reports and diff --git a/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp similarity index 90% rename from pus/Service5EventReporting.cpp rename to src/fsfw/pus/Service5EventReporting.cpp index 0c139f3aa..36aa7e704 100644 --- a/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -1,11 +1,11 @@ -#include "Service5EventReporting.h" -#include "servicepackets/Service5Packets.h" +#include "fsfw/pus/Service5EventReporting.h" +#include "fsfw/pus/servicepackets/Service5Packets.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../objectmanager/ObjectManager.h" -#include "../events/EventManagerIF.h" -#include "../ipc/QueueFactory.h" -#include "../tmtcpacket/pus/tm/TmPacketStored.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/events/EventManagerIF.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" Service5EventReporting::Service5EventReporting(object_id_t objectId, diff --git a/pus/Service5EventReporting.h b/src/fsfw/pus/Service5EventReporting.h similarity index 97% rename from pus/Service5EventReporting.h rename to src/fsfw/pus/Service5EventReporting.h index 69242801f..35ff34b63 100644 --- a/pus/Service5EventReporting.h +++ b/src/fsfw/pus/Service5EventReporting.h @@ -1,8 +1,8 @@ #ifndef FSFW_PUS_SERVICE5EVENTREPORTING_H_ #define FSFW_PUS_SERVICE5EVENTREPORTING_H_ -#include "../tmtcservices/PusServiceBase.h" -#include "../events/EventMessage.h" +#include "fsfw/tmtcservices/PusServiceBase.h" +#include "fsfw/events/EventMessage.h" /** * @brief Report on-board events like information or errors diff --git a/pus/Service8FunctionManagement.cpp b/src/fsfw/pus/Service8FunctionManagement.cpp similarity index 93% rename from pus/Service8FunctionManagement.cpp rename to src/fsfw/pus/Service8FunctionManagement.cpp index 77b7dc80c..39e872a0f 100644 --- a/pus/Service8FunctionManagement.cpp +++ b/src/fsfw/pus/Service8FunctionManagement.cpp @@ -1,12 +1,12 @@ -#include "Service8FunctionManagement.h" -#include "servicepackets/Service8Packets.h" +#include "fsfw/pus/Service8FunctionManagement.h" +#include "fsfw/pus/servicepackets/Service8Packets.h" -#include "../objectmanager/ObjectManager.h" -#include "../objectmanager/SystemObjectIF.h" -#include "../action/HasActionsIF.h" -#include "../devicehandlers/DeviceHandlerIF.h" -#include "../serialize/SerializeAdapter.h" -#include "../serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/objectmanager/SystemObjectIF.h" +#include "fsfw/action/HasActionsIF.h" +#include "fsfw/devicehandlers/DeviceHandlerIF.h" +#include "fsfw/serialize/SerializeAdapter.h" +#include "fsfw/serviceinterface/ServiceInterface.h" Service8FunctionManagement::Service8FunctionManagement(object_id_t objectId, uint16_t apid, uint8_t serviceId, uint8_t numParallelCommands, diff --git a/pus/Service8FunctionManagement.h b/src/fsfw/pus/Service8FunctionManagement.h similarity index 96% rename from pus/Service8FunctionManagement.h rename to src/fsfw/pus/Service8FunctionManagement.h index 00153cfb0..debdf6364 100644 --- a/pus/Service8FunctionManagement.h +++ b/src/fsfw/pus/Service8FunctionManagement.h @@ -1,8 +1,8 @@ #ifndef FSFW_PUS_SERVICE8FUNCTIONMANAGEMENT_H_ #define FSFW_PUS_SERVICE8FUNCTIONMANAGEMENT_H_ -#include "../action/ActionMessage.h" -#include "../tmtcservices/CommandingServiceBase.h" +#include "fsfw/action/ActionMessage.h" +#include "fsfw/tmtcservices/CommandingServiceBase.h" /** * @brief Functional commanding. diff --git a/pus/Service9TimeManagement.cpp b/src/fsfw/pus/Service9TimeManagement.cpp similarity index 84% rename from pus/Service9TimeManagement.cpp rename to src/fsfw/pus/Service9TimeManagement.cpp index 5625bdd8f..619b24056 100644 --- a/pus/Service9TimeManagement.cpp +++ b/src/fsfw/pus/Service9TimeManagement.cpp @@ -1,9 +1,9 @@ -#include "Service9TimeManagement.h" -#include "servicepackets/Service9Packets.h" +#include "fsfw/pus/Service9TimeManagement.h" +#include "fsfw/pus/servicepackets/Service9Packets.h" -#include "../timemanager/CCSDSTime.h" -#include "../events/EventManagerIF.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/timemanager/CCSDSTime.h" +#include "fsfw/events/EventManagerIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" Service9TimeManagement::Service9TimeManagement(object_id_t objectId, diff --git a/pus/Service9TimeManagement.h b/src/fsfw/pus/Service9TimeManagement.h similarity index 96% rename from pus/Service9TimeManagement.h rename to src/fsfw/pus/Service9TimeManagement.h index 70b86966d..d8e183a42 100644 --- a/pus/Service9TimeManagement.h +++ b/src/fsfw/pus/Service9TimeManagement.h @@ -1,7 +1,7 @@ #ifndef FSFW_PUS_SERVICE9TIMEMANAGEMENT_H_ #define FSFW_PUS_SERVICE9TIMEMANAGEMENT_H_ -#include "../tmtcservices/PusServiceBase.h" +#include "fsfw/tmtcservices/PusServiceBase.h" class Service9TimeManagement: public PusServiceBase { public: diff --git a/pus/servicepackets/Service1Packets.h b/src/fsfw/pus/servicepackets/Service1Packets.h similarity index 98% rename from pus/servicepackets/Service1Packets.h rename to src/fsfw/pus/servicepackets/Service1Packets.h index 2249b4b0f..02ae339f8 100644 --- a/pus/servicepackets/Service1Packets.h +++ b/src/fsfw/pus/servicepackets/Service1Packets.h @@ -13,10 +13,10 @@ /** * @brief FailureReport class to serialize a failure report - * @brief Subservice 1, 3, 5, 7 + * @brief Subservice 2, 4, 6, 8 * @ingroup spacepackets */ -class FailureReport: public SerializeIF { //!< [EXPORT] : [SUBSERVICE] 1, 3, 5, 7 +class FailureReport: public SerializeIF { //!< [EXPORT] : [SUBSERVICE] 2, 4, 6, 8 public: FailureReport(uint8_t failureSubtype_, uint16_t packetId_, uint16_t packetSequenceControl_, uint8_t stepNumber_, @@ -108,10 +108,10 @@ private: }; /** - * @brief Subservices 2, 4, 6, 8 + * @brief Subservices 1, 3, 5, 7 * @ingroup spacepackets */ -class SuccessReport: public SerializeIF { //!< [EXPORT] : [SUBSERVICE] 2, 4, 6, 8 +class SuccessReport: public SerializeIF { //!< [EXPORT] : [SUBSERVICE] 1, 3, 5, 7 public: SuccessReport(uint8_t subtype_, uint16_t packetId_, uint16_t packetSequenceControl_,uint8_t stepNumber_) : diff --git a/pus/servicepackets/Service200Packets.h b/src/fsfw/pus/servicepackets/Service200Packets.h similarity index 100% rename from pus/servicepackets/Service200Packets.h rename to src/fsfw/pus/servicepackets/Service200Packets.h diff --git a/pus/servicepackets/Service201Packets.h b/src/fsfw/pus/servicepackets/Service201Packets.h similarity index 100% rename from pus/servicepackets/Service201Packets.h rename to src/fsfw/pus/servicepackets/Service201Packets.h diff --git a/pus/servicepackets/Service20Packets.h b/src/fsfw/pus/servicepackets/Service20Packets.h similarity index 100% rename from pus/servicepackets/Service20Packets.h rename to src/fsfw/pus/servicepackets/Service20Packets.h diff --git a/pus/servicepackets/Service2Packets.h b/src/fsfw/pus/servicepackets/Service2Packets.h similarity index 100% rename from pus/servicepackets/Service2Packets.h rename to src/fsfw/pus/servicepackets/Service2Packets.h diff --git a/pus/servicepackets/Service3Packets.h b/src/fsfw/pus/servicepackets/Service3Packets.h similarity index 100% rename from pus/servicepackets/Service3Packets.h rename to src/fsfw/pus/servicepackets/Service3Packets.h diff --git a/pus/servicepackets/Service5Packets.h b/src/fsfw/pus/servicepackets/Service5Packets.h similarity index 100% rename from pus/servicepackets/Service5Packets.h rename to src/fsfw/pus/servicepackets/Service5Packets.h diff --git a/pus/servicepackets/Service8Packets.h b/src/fsfw/pus/servicepackets/Service8Packets.h similarity index 100% rename from pus/servicepackets/Service8Packets.h rename to src/fsfw/pus/servicepackets/Service8Packets.h diff --git a/pus/servicepackets/Service9Packets.h b/src/fsfw/pus/servicepackets/Service9Packets.h similarity index 100% rename from pus/servicepackets/Service9Packets.h rename to src/fsfw/pus/servicepackets/Service9Packets.h diff --git a/returnvalues/FwClassIds.h b/src/fsfw/returnvalues/FwClassIds.h similarity index 95% rename from returnvalues/FwClassIds.h rename to src/fsfw/returnvalues/FwClassIds.h index af32f9a76..4a3a578a8 100644 --- a/returnvalues/FwClassIds.h +++ b/src/fsfw/returnvalues/FwClassIds.h @@ -72,10 +72,14 @@ enum: uint8_t { PUS_SERVICE_3, //PUS3 PUS_SERVICE_9, //PUS9 FILE_SYSTEM, //FILS + LINUX_OSAL, //UXOS HAL_SPI, //HSPI HAL_UART, //HURT HAL_I2C, //HI2C HAL_GPIO, //HGIO + FIXED_SLOT_TASK_IF, //FTIF + MGM_LIS3MDL, //MGMLIS3 + MGM_RM3100, //MGMRM3100 FW_CLASS_ID_COUNT // [EXPORT] : [END] }; diff --git a/returnvalues/HasReturnvaluesIF.h b/src/fsfw/returnvalues/HasReturnvaluesIF.h similarity index 100% rename from returnvalues/HasReturnvaluesIF.h rename to src/fsfw/returnvalues/HasReturnvaluesIF.h diff --git a/rmap/CMakeLists.txt b/src/fsfw/rmap/CMakeLists.txt similarity index 100% rename from rmap/CMakeLists.txt rename to src/fsfw/rmap/CMakeLists.txt diff --git a/rmap/RMAP.cpp b/src/fsfw/rmap/RMAP.cpp similarity index 93% rename from rmap/RMAP.cpp rename to src/fsfw/rmap/RMAP.cpp index 7ea6e5329..6ac4904d2 100644 --- a/rmap/RMAP.cpp +++ b/src/fsfw/rmap/RMAP.cpp @@ -1,8 +1,8 @@ -#include "RMAP.h" -#include "rmapStructs.h" -#include "RMAPChannelIF.h" +#include "fsfw/rmap/RMAP.h" +#include "fsfw/rmap/rmapStructs.h" +#include "fsfw/rmap/RMAPChannelIF.h" -#include "../devicehandlers/DeviceCommunicationIF.h" +#include "fsfw/devicehandlers/DeviceCommunicationIF.h" #include diff --git a/rmap/RMAP.h b/src/fsfw/rmap/RMAP.h similarity index 99% rename from rmap/RMAP.h rename to src/fsfw/rmap/RMAP.h index 83e29fede..ff310db08 100644 --- a/rmap/RMAP.h +++ b/src/fsfw/rmap/RMAP.h @@ -1,8 +1,9 @@ #ifndef FSFW_RMAP_RMAP_H_ #define FSFW_RMAP_RMAP_H_ -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../rmap/RMAPCookie.h" +#include "rmapConf.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/rmap/RMAPCookie.h" //SHOULDTODO: clean up includes for RMAP, should be enough to include RMAP.h but right now it's quite chaotic... diff --git a/rmap/RMAPChannelIF.h b/src/fsfw/rmap/RMAPChannelIF.h similarity index 98% rename from rmap/RMAPChannelIF.h rename to src/fsfw/rmap/RMAPChannelIF.h index 0aa809c53..7fbda3482 100644 --- a/rmap/RMAPChannelIF.h +++ b/src/fsfw/rmap/RMAPChannelIF.h @@ -1,8 +1,9 @@ #ifndef FSFW_RMAP_RMAPCHANNELIF_H_ #define FSFW_RMAP_RMAPCHANNELIF_H_ +#include "rmapConf.h" #include "RMAPCookie.h" -#include "../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include class RMAPChannelIF { diff --git a/rmap/RMAPCookie.cpp b/src/fsfw/rmap/RMAPCookie.cpp similarity index 97% rename from rmap/RMAPCookie.cpp rename to src/fsfw/rmap/RMAPCookie.cpp index f8fe2d3eb..393a5ce0a 100644 --- a/rmap/RMAPCookie.cpp +++ b/src/fsfw/rmap/RMAPCookie.cpp @@ -1,5 +1,6 @@ -#include "RMAPChannelIF.h" -#include "RMAPCookie.h" +#include "fsfw/rmap/RMAPChannelIF.h" +#include "fsfw/rmap/RMAPCookie.h" + #include diff --git a/rmap/RMAPCookie.h b/src/fsfw/rmap/RMAPCookie.h similarity index 95% rename from rmap/RMAPCookie.h rename to src/fsfw/rmap/RMAPCookie.h index 385426468..032e5a468 100644 --- a/rmap/RMAPCookie.h +++ b/src/fsfw/rmap/RMAPCookie.h @@ -1,8 +1,9 @@ #ifndef FSFW_RMAP_RMAPCOOKIE_H_ #define FSFW_RMAP_RMAPCOOKIE_H_ +#include "rmapConf.h" #include "rmapStructs.h" -#include "../devicehandlers/CookieIF.h" +#include "fsfw/devicehandlers/CookieIF.h" #include class RMAPChannelIF; diff --git a/rmap/RmapDeviceCommunicationIF.cpp b/src/fsfw/rmap/RmapDeviceCommunicationIF.cpp similarity index 94% rename from rmap/RmapDeviceCommunicationIF.cpp rename to src/fsfw/rmap/RmapDeviceCommunicationIF.cpp index d81baabd5..2fab613e4 100644 --- a/rmap/RmapDeviceCommunicationIF.cpp +++ b/src/fsfw/rmap/RmapDeviceCommunicationIF.cpp @@ -1,5 +1,5 @@ -#include "RmapDeviceCommunicationIF.h" -#include "RMAP.h" +#include "fsfw/rmap/RmapDeviceCommunicationIF.h" +#include "fsfw/rmap/RMAP.h" //TODO Cast here are all potential bugs RmapDeviceCommunicationIF::~RmapDeviceCommunicationIF() { diff --git a/rmap/RmapDeviceCommunicationIF.h b/src/fsfw/rmap/RmapDeviceCommunicationIF.h similarity index 97% rename from rmap/RmapDeviceCommunicationIF.h rename to src/fsfw/rmap/RmapDeviceCommunicationIF.h index 1333966a7..36baf87b1 100644 --- a/rmap/RmapDeviceCommunicationIF.h +++ b/src/fsfw/rmap/RmapDeviceCommunicationIF.h @@ -1,7 +1,8 @@ #ifndef FSFW_RMAP_RMAPDEVICECOMMUNICATIONINTERFACE_H_ #define FSFW_RMAP_RMAPDEVICECOMMUNICATIONINTERFACE_H_ -#include "../devicehandlers/DeviceCommunicationIF.h" +#include "rmapConf.h" +#include "fsfw/devicehandlers/DeviceCommunicationIF.h" /** * @brief This class is a implementation of a DeviceCommunicationIF for RMAP calls. diff --git a/src/fsfw/rmap/rmapConf.h b/src/fsfw/rmap/rmapConf.h new file mode 100644 index 000000000..c4fa1e549 --- /dev/null +++ b/src/fsfw/rmap/rmapConf.h @@ -0,0 +1,10 @@ +#ifndef FSFW_SRC_FSFW_RMAP_RAMCONF_H_ +#define FSFW_SRC_FSFW_RMAP_RAMCONF_H_ + +#include "fsfw/FSFW.h" + +#ifndef FSFW_ADD_RMAP +#warning RMAP was included but compilation was not enabled with FSFW_ADD_RMAP +#endif + +#endif /* FSFW_SRC_FSFW_RMAP_RAMCONF_H_ */ diff --git a/rmap/rmapStructs.h b/src/fsfw/rmap/rmapStructs.h similarity index 99% rename from rmap/rmapStructs.h rename to src/fsfw/rmap/rmapStructs.h index 11d8bb85b..de8b3a592 100644 --- a/rmap/rmapStructs.h +++ b/src/fsfw/rmap/rmapStructs.h @@ -1,6 +1,8 @@ #ifndef FSFW_RMAP_RMAPSTRUCTS_H_ #define FSFW_RMAP_RMAPSTRUCTS_H_ +#include "rmapConf.h" + #include //SHOULDDO: having the defines within a namespace would be nice. Problem are the defines referencing the previous define, eg RMAP_COMMAND_WRITE diff --git a/src/fsfw/serialize.h b/src/fsfw/serialize.h new file mode 100644 index 000000000..7cd735bb9 --- /dev/null +++ b/src/fsfw/serialize.h @@ -0,0 +1,10 @@ +#ifndef FSFW_INC_FSFW_SERIALIZE_H_ +#define FSFW_INC_FSFW_SERIALIZE_H_ + +#include "src/core/serialize/EndianConverter.h" +#include "src/core/serialize/SerialArrayListAdapter.h" +#include "src/core/serialize/SerialBufferAdapter.h" +#include "src/core/serialize/SerializeElement.h" +#include "src/core/serialize/SerialLinkedListAdapter.h" + +#endif /* FSFW_INC_FSFW_SERIALIZE_H_ */ diff --git a/serialize/CMakeLists.txt b/src/fsfw/serialize/CMakeLists.txt similarity index 100% rename from serialize/CMakeLists.txt rename to src/fsfw/serialize/CMakeLists.txt diff --git a/serialize/EndianConverter.h b/src/fsfw/serialize/EndianConverter.h similarity index 100% rename from serialize/EndianConverter.h rename to src/fsfw/serialize/EndianConverter.h diff --git a/serialize/SerialArrayListAdapter.h b/src/fsfw/serialize/SerialArrayListAdapter.h similarity index 100% rename from serialize/SerialArrayListAdapter.h rename to src/fsfw/serialize/SerialArrayListAdapter.h diff --git a/serialize/SerialBufferAdapter.cpp b/src/fsfw/serialize/SerialBufferAdapter.cpp similarity index 97% rename from serialize/SerialBufferAdapter.cpp rename to src/fsfw/serialize/SerialBufferAdapter.cpp index 53b8c3d53..4f03658a9 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/src/fsfw/serialize/SerialBufferAdapter.cpp @@ -1,5 +1,5 @@ -#include "../serialize/SerialBufferAdapter.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/serialize/SerialBufferAdapter.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include template diff --git a/serialize/SerialBufferAdapter.h b/src/fsfw/serialize/SerialBufferAdapter.h similarity index 96% rename from serialize/SerialBufferAdapter.h rename to src/fsfw/serialize/SerialBufferAdapter.h index 9a89e18ba..6c79cd03d 100644 --- a/serialize/SerialBufferAdapter.h +++ b/src/fsfw/serialize/SerialBufferAdapter.h @@ -1,8 +1,8 @@ #ifndef SERIALBUFFERADAPTER_H_ #define SERIALBUFFERADAPTER_H_ -#include "../serialize/SerializeIF.h" -#include "../serialize/SerializeAdapter.h" +#include "fsfw/serialize/SerializeIF.h" +#include "fsfw/serialize/SerializeAdapter.h" /** * This adapter provides an interface for SerializeIF to serialize or deserialize diff --git a/serialize/SerialFixedArrayListAdapter.h b/src/fsfw/serialize/SerialFixedArrayListAdapter.h similarity index 100% rename from serialize/SerialFixedArrayListAdapter.h rename to src/fsfw/serialize/SerialFixedArrayListAdapter.h diff --git a/serialize/SerialLinkedListAdapter.h b/src/fsfw/serialize/SerialLinkedListAdapter.h similarity index 100% rename from serialize/SerialLinkedListAdapter.h rename to src/fsfw/serialize/SerialLinkedListAdapter.h diff --git a/serialize/SerializeAdapter.h b/src/fsfw/serialize/SerializeAdapter.h similarity index 100% rename from serialize/SerializeAdapter.h rename to src/fsfw/serialize/SerializeAdapter.h diff --git a/serialize/SerializeElement.h b/src/fsfw/serialize/SerializeElement.h similarity index 100% rename from serialize/SerializeElement.h rename to src/fsfw/serialize/SerializeElement.h diff --git a/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h similarity index 100% rename from serialize/SerializeIF.h rename to src/fsfw/serialize/SerializeIF.h diff --git a/src/fsfw/serviceinterface.h b/src/fsfw/serviceinterface.h new file mode 100644 index 000000000..2e9a0b7e4 --- /dev/null +++ b/src/fsfw/serviceinterface.h @@ -0,0 +1,6 @@ +#ifndef FSFW_SRC_FSFW_SERVICEINTERFACE_H_ +#define FSFW_SRC_FSFW_SERVICEINTERFACE_H_ + +#include "serviceinterface/ServiceInterface.h" + +#endif /* FSFW_SRC_FSFW_SERVICEINTERFACE_H_ */ diff --git a/serviceinterface/CMakeLists.txt b/src/fsfw/serviceinterface/CMakeLists.txt similarity index 100% rename from serviceinterface/CMakeLists.txt rename to src/fsfw/serviceinterface/CMakeLists.txt diff --git a/serviceinterface/ServiceInterface.h b/src/fsfw/serviceinterface/ServiceInterface.h similarity index 92% rename from serviceinterface/ServiceInterface.h rename to src/fsfw/serviceinterface/ServiceInterface.h index e95dd9a47..9f05b96cc 100644 --- a/serviceinterface/ServiceInterface.h +++ b/src/fsfw/serviceinterface/ServiceInterface.h @@ -1,7 +1,7 @@ #ifndef FSFW_SERVICEINTERFACE_SERVICEINTERFACE_H_ #define FSFW_SERVICEINTERFACE_SERVICEINTERFACE_H_ -#include +#include "fsfw/FSFW.h" #include "serviceInterfaceDefintions.h" #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/serviceinterface/ServiceInterfaceBuffer.cpp b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp similarity index 94% rename from serviceinterface/ServiceInterfaceBuffer.cpp rename to src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp index b85a43a44..0411e6744 100644 --- a/serviceinterface/ServiceInterfaceBuffer.cpp +++ b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.cpp @@ -1,10 +1,10 @@ -#include "ServiceInterfaceBuffer.h" +#include "fsfw/serviceinterface/ServiceInterfaceBuffer.h" #if FSFW_CPP_OSTREAM_ENABLED == 1 -#include "../timemanager/Clock.h" +#include "fsfw/timemanager/Clock.h" -#include "serviceInterfaceDefintions.h" +#include "fsfw/serviceinterface/serviceInterfaceDefintions.h" #include #include @@ -146,8 +146,8 @@ std::string* ServiceInterfaceBuffer::getPreamble(size_t * preambleSize) { #endif int32_t charCount = sprintf(parsePosition, - "%s: | %02" SCNu32 ":%02" SCNu32 ":%02" SCNu32 ".%03" SCNu32 " | ", - this->logMessage.c_str(), loggerTime.hour, + "%s%s | %02" SCNu32 ":%02" SCNu32 ":%02" SCNu32 ".%03" SCNu32 " | ", + this->logMessage.c_str(), sif::ANSI_COLOR_RESET, loggerTime.hour, loggerTime.minute, loggerTime.second, loggerTime.usecond /1000); @@ -171,9 +171,11 @@ bool ServiceInterfaceBuffer::crAdditionEnabled() const { return addCrToPreamble; } +#if FSFW_COLORED_OUTPUT == 1 void ServiceInterfaceBuffer::setAsciiColorPrefix(std::string colorPrefix) { - this->colorPrefix = colorPrefix; + this->colorPrefix = colorPrefix; } +#endif #ifdef UT699 #include "../osal/rtems/Interrupt.h" diff --git a/serviceinterface/ServiceInterfaceBuffer.h b/src/fsfw/serviceinterface/ServiceInterfaceBuffer.h similarity index 100% rename from serviceinterface/ServiceInterfaceBuffer.h rename to src/fsfw/serviceinterface/ServiceInterfaceBuffer.h diff --git a/serviceinterface/ServiceInterfacePrinter.cpp b/src/fsfw/serviceinterface/ServiceInterfacePrinter.cpp similarity index 85% rename from serviceinterface/ServiceInterfacePrinter.cpp rename to src/fsfw/serviceinterface/ServiceInterfacePrinter.cpp index ce797f1c1..e42e515d7 100644 --- a/serviceinterface/ServiceInterfacePrinter.cpp +++ b/src/fsfw/serviceinterface/ServiceInterfacePrinter.cpp @@ -1,7 +1,7 @@ -#include -#include "ServiceInterfacePrinter.h" -#include "serviceInterfaceDefintions.h" -#include "../timemanager/Clock.h" +#include "fsfw/FSFW.h" +#include "fsfw/serviceinterface/ServiceInterfacePrinter.h" +#include "fsfw/serviceinterface/serviceInterfaceDefintions.h" +#include "fsfw/timemanager/Clock.h" #include #include @@ -56,25 +56,29 @@ void fsfwPrint(sif::PrintLevel printType, const char* fmt, va_list arg) { #endif if (printType == sif::PrintLevel::INFO_LEVEL) { - len += sprintf(bufferPosition + len, "INFO: "); + len += sprintf(bufferPosition + len, "INFO"); } if(printType == sif::PrintLevel::DEBUG_LEVEL) { - len += sprintf(bufferPosition + len, "DEBUG: "); + len += sprintf(bufferPosition + len, "DEBUG"); } if(printType == sif::PrintLevel::WARNING_LEVEL) { - len += sprintf(bufferPosition + len, "WARNING: "); + len += sprintf(bufferPosition + len, "WARNING"); } if(printType == sif::PrintLevel::ERROR_LEVEL) { - len += sprintf(bufferPosition + len, "ERROR: "); + len += sprintf(bufferPosition + len, "ERROR"); } +#if FSFW_COLORED_OUTPUT == 1 + len += sprintf(bufferPosition + len, sif::ANSI_COLOR_RESET); +#endif + Clock::TimeOfDay_t now; Clock::getDateAndTime(&now); /* * Log current time to terminal if desired. */ - len += sprintf(bufferPosition + len, "| %lu:%02lu:%02lu.%03lu | ", + len += sprintf(bufferPosition + len, " | %lu:%02lu:%02lu.%03lu | ", (unsigned long) now.hour, (unsigned long) now.minute, (unsigned long) now.second, diff --git a/serviceinterface/ServiceInterfacePrinter.h b/src/fsfw/serviceinterface/ServiceInterfacePrinter.h similarity index 100% rename from serviceinterface/ServiceInterfacePrinter.h rename to src/fsfw/serviceinterface/ServiceInterfacePrinter.h diff --git a/serviceinterface/ServiceInterfaceStream.cpp b/src/fsfw/serviceinterface/ServiceInterfaceStream.cpp similarity index 88% rename from serviceinterface/ServiceInterfaceStream.cpp rename to src/fsfw/serviceinterface/ServiceInterfaceStream.cpp index 80942b880..6139299ba 100644 --- a/serviceinterface/ServiceInterfaceStream.cpp +++ b/src/fsfw/serviceinterface/ServiceInterfaceStream.cpp @@ -1,4 +1,4 @@ -#include "ServiceInterfaceStream.h" +#include "fsfw/serviceinterface/ServiceInterfaceStream.h" #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -19,9 +19,11 @@ bool ServiceInterfaceStream::crAdditionEnabled() const { return streambuf.crAdditionEnabled(); } +#if FSFW_COLORED_OUTPUT == 1 void ServiceInterfaceStream::setAsciiColorPrefix(std::string asciiColorCode) { streambuf.setAsciiColorPrefix(asciiColorCode); } +#endif #endif diff --git a/serviceinterface/ServiceInterfaceStream.h b/src/fsfw/serviceinterface/ServiceInterfaceStream.h similarity index 98% rename from serviceinterface/ServiceInterfaceStream.h rename to src/fsfw/serviceinterface/ServiceInterfaceStream.h index aceddb22c..545ab2415 100644 --- a/serviceinterface/ServiceInterfaceStream.h +++ b/src/fsfw/serviceinterface/ServiceInterfaceStream.h @@ -46,7 +46,9 @@ public: */ bool crAdditionEnabled() const; +#if FSFW_COLORED_OUTPUT == 1 void setAsciiColorPrefix(std::string asciiColorCode); +#endif protected: ServiceInterfaceBuffer streambuf; diff --git a/serviceinterface/serviceInterfaceDefintions.h b/src/fsfw/serviceinterface/serviceInterfaceDefintions.h similarity index 100% rename from serviceinterface/serviceInterfaceDefintions.h rename to src/fsfw/serviceinterface/serviceInterfaceDefintions.h diff --git a/storagemanager/CMakeLists.txt b/src/fsfw/storagemanager/CMakeLists.txt similarity index 100% rename from storagemanager/CMakeLists.txt rename to src/fsfw/storagemanager/CMakeLists.txt diff --git a/storagemanager/ConstStorageAccessor.cpp b/src/fsfw/storagemanager/ConstStorageAccessor.cpp similarity index 92% rename from storagemanager/ConstStorageAccessor.cpp rename to src/fsfw/storagemanager/ConstStorageAccessor.cpp index aab848628..67736d519 100644 --- a/storagemanager/ConstStorageAccessor.cpp +++ b/src/fsfw/storagemanager/ConstStorageAccessor.cpp @@ -1,8 +1,8 @@ -#include "ConstStorageAccessor.h" -#include "StorageManagerIF.h" +#include "fsfw/storagemanager/ConstStorageAccessor.h" +#include "fsfw/storagemanager/StorageManagerIF.h" -#include "../serviceinterface/ServiceInterfaceStream.h" -#include "../globalfunctions/arrayprinter.h" +#include "fsfw/serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/globalfunctions/arrayprinter.h" #include diff --git a/storagemanager/ConstStorageAccessor.h b/src/fsfw/storagemanager/ConstStorageAccessor.h similarity index 100% rename from storagemanager/ConstStorageAccessor.h rename to src/fsfw/storagemanager/ConstStorageAccessor.h diff --git a/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp similarity index 99% rename from storagemanager/LocalPool.cpp rename to src/fsfw/storagemanager/LocalPool.cpp index 41c9250a6..c5e74e089 100644 --- a/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -1,7 +1,7 @@ -#include "LocalPool.h" -#include "FSFWConfig.h" +#include "fsfw/FSFW.h" +#include "fsfw/storagemanager/LocalPool.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/objectmanager/ObjectManager.h" #include diff --git a/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h similarity index 96% rename from storagemanager/LocalPool.h rename to src/fsfw/storagemanager/LocalPool.h index 6a6664853..383d8a941 100644 --- a/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -1,12 +1,13 @@ #ifndef FSFW_STORAGEMANAGER_LOCALPOOL_H_ #define FSFW_STORAGEMANAGER_LOCALPOOL_H_ -#include "StorageManagerIF.h" -#include "../objectmanager/SystemObject.h" -#include "../objectmanager/ObjectManagerIF.h" -#include "../serviceinterface/ServiceInterfaceStream.h" -#include "../internalError/InternalErrorReporterIF.h" -#include "../storagemanager/StorageAccessor.h" +#include "fsfw/storagemanager/StorageManagerIF.h" + +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/internalerror/InternalErrorReporterIF.h" +#include "fsfw/storagemanager/StorageAccessor.h" #include #include diff --git a/storagemanager/PoolManager.cpp b/src/fsfw/storagemanager/PoolManager.cpp similarity index 96% rename from storagemanager/PoolManager.cpp rename to src/fsfw/storagemanager/PoolManager.cpp index eec849078..073371ad1 100644 --- a/storagemanager/PoolManager.cpp +++ b/src/fsfw/storagemanager/PoolManager.cpp @@ -1,5 +1,6 @@ -#include "PoolManager.h" -#include +#include "fsfw/FSFW.h" +#include "fsfw/storagemanager/PoolManager.h" + PoolManager::PoolManager(object_id_t setObjectId, const LocalPoolConfig& localPoolConfig): diff --git a/storagemanager/PoolManager.h b/src/fsfw/storagemanager/PoolManager.h similarity index 100% rename from storagemanager/PoolManager.h rename to src/fsfw/storagemanager/PoolManager.h diff --git a/storagemanager/StorageAccessor.cpp b/src/fsfw/storagemanager/StorageAccessor.cpp similarity index 93% rename from storagemanager/StorageAccessor.cpp rename to src/fsfw/storagemanager/StorageAccessor.cpp index a7b4fae4f..95f61a750 100644 --- a/storagemanager/StorageAccessor.cpp +++ b/src/fsfw/storagemanager/StorageAccessor.cpp @@ -1,6 +1,7 @@ -#include "StorageAccessor.h" -#include "StorageManagerIF.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/storagemanager/StorageAccessor.h" +#include "fsfw/storagemanager/StorageManagerIF.h" + +#include "fsfw/serviceinterface/ServiceInterface.h" #include diff --git a/storagemanager/StorageAccessor.h b/src/fsfw/storagemanager/StorageAccessor.h similarity index 100% rename from storagemanager/StorageAccessor.h rename to src/fsfw/storagemanager/StorageAccessor.h diff --git a/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h similarity index 100% rename from storagemanager/StorageManagerIF.h rename to src/fsfw/storagemanager/StorageManagerIF.h diff --git a/storagemanager/storeAddress.h b/src/fsfw/storagemanager/storeAddress.h similarity index 100% rename from storagemanager/storeAddress.h rename to src/fsfw/storagemanager/storeAddress.h diff --git a/subsystem/CMakeLists.txt b/src/fsfw/subsystem/CMakeLists.txt similarity index 100% rename from subsystem/CMakeLists.txt rename to src/fsfw/subsystem/CMakeLists.txt diff --git a/subsystem/Subsystem.cpp b/src/fsfw/subsystem/Subsystem.cpp similarity index 98% rename from subsystem/Subsystem.cpp rename to src/fsfw/subsystem/Subsystem.cpp index dffad0346..0c8e3f352 100644 --- a/subsystem/Subsystem.cpp +++ b/src/fsfw/subsystem/Subsystem.cpp @@ -1,11 +1,11 @@ -#include "Subsystem.h" +#include "fsfw/subsystem/Subsystem.h" -#include "../health/HealthMessage.h" -#include "../objectmanager/ObjectManager.h" -#include "../serialize/SerialArrayListAdapter.h" -#include "../serialize/SerialFixedArrayListAdapter.h" -#include "../serialize/SerializeElement.h" -#include "../serialize/SerialLinkedListAdapter.h" +#include "fsfw/health/HealthMessage.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serialize/SerialArrayListAdapter.h" +#include "fsfw/serialize/SerialFixedArrayListAdapter.h" +#include "fsfw/serialize/SerializeElement.h" +#include "fsfw/serialize/SerialLinkedListAdapter.h" #include diff --git a/subsystem/Subsystem.h b/src/fsfw/subsystem/Subsystem.h similarity index 100% rename from subsystem/Subsystem.h rename to src/fsfw/subsystem/Subsystem.h diff --git a/subsystem/SubsystemBase.cpp b/src/fsfw/subsystem/SubsystemBase.cpp similarity index 98% rename from subsystem/SubsystemBase.cpp rename to src/fsfw/subsystem/SubsystemBase.cpp index 0d4593242..afcd43ade 100644 --- a/subsystem/SubsystemBase.cpp +++ b/src/fsfw/subsystem/SubsystemBase.cpp @@ -1,8 +1,8 @@ -#include "SubsystemBase.h" +#include "fsfw/subsystem/SubsystemBase.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../objectmanager/ObjectManager.h" -#include "../ipc/QueueFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/ipc/QueueFactory.h" SubsystemBase::SubsystemBase(object_id_t setObjectId, object_id_t parent, Mode_t initialMode, uint16_t commandQueueDepth) : diff --git a/subsystem/SubsystemBase.h b/src/fsfw/subsystem/SubsystemBase.h similarity index 100% rename from subsystem/SubsystemBase.h rename to src/fsfw/subsystem/SubsystemBase.h diff --git a/subsystem/modes/CMakeLists.txt b/src/fsfw/subsystem/modes/CMakeLists.txt similarity index 100% rename from subsystem/modes/CMakeLists.txt rename to src/fsfw/subsystem/modes/CMakeLists.txt diff --git a/subsystem/modes/HasModeSequenceIF.h b/src/fsfw/subsystem/modes/HasModeSequenceIF.h similarity index 100% rename from subsystem/modes/HasModeSequenceIF.h rename to src/fsfw/subsystem/modes/HasModeSequenceIF.h diff --git a/subsystem/modes/ModeDefinitions.h b/src/fsfw/subsystem/modes/ModeDefinitions.h similarity index 100% rename from subsystem/modes/ModeDefinitions.h rename to src/fsfw/subsystem/modes/ModeDefinitions.h diff --git a/subsystem/modes/ModeSequenceMessage.cpp b/src/fsfw/subsystem/modes/ModeSequenceMessage.cpp similarity index 92% rename from subsystem/modes/ModeSequenceMessage.cpp rename to src/fsfw/subsystem/modes/ModeSequenceMessage.cpp index 749a90bf4..d75702760 100644 --- a/subsystem/modes/ModeSequenceMessage.cpp +++ b/src/fsfw/subsystem/modes/ModeSequenceMessage.cpp @@ -1,7 +1,7 @@ -#include "ModeSequenceMessage.h" +#include "fsfw/subsystem/modes/ModeSequenceMessage.h" -#include "../../objectmanager/ObjectManager.h" -#include "../../storagemanager/StorageManagerIF.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/storagemanager/StorageManagerIF.h" void ModeSequenceMessage::setModeSequenceMessage(CommandMessage* message, Command_t command, Mode_t sequence, store_address_t storeAddress) { diff --git a/subsystem/modes/ModeSequenceMessage.h b/src/fsfw/subsystem/modes/ModeSequenceMessage.h similarity index 95% rename from subsystem/modes/ModeSequenceMessage.h rename to src/fsfw/subsystem/modes/ModeSequenceMessage.h index 7852c9848..0dbe7ffbf 100644 --- a/subsystem/modes/ModeSequenceMessage.h +++ b/src/fsfw/subsystem/modes/ModeSequenceMessage.h @@ -3,8 +3,8 @@ #include "ModeDefinitions.h" -#include "../../ipc/CommandMessage.h" -#include "../../storagemanager/StorageManagerIF.h" +#include "fsfw/ipc/CommandMessage.h" +#include "fsfw/storagemanager/StorageManagerIF.h" class ModeSequenceMessage { diff --git a/subsystem/modes/ModeStore.cpp b/src/fsfw/subsystem/modes/ModeStore.cpp similarity index 98% rename from subsystem/modes/ModeStore.cpp rename to src/fsfw/subsystem/modes/ModeStore.cpp index e216a167a..e28bbc4fe 100644 --- a/subsystem/modes/ModeStore.cpp +++ b/src/fsfw/subsystem/modes/ModeStore.cpp @@ -1,4 +1,4 @@ -#include "ModeStore.h" +#include "fsfw/subsystem/modes/ModeStore.h" // todo: I think some parts are deprecated. If this is used, the define // USE_MODESTORE could be part of the new FSFWConfig.h file. diff --git a/subsystem/modes/ModeStore.h b/src/fsfw/subsystem/modes/ModeStore.h similarity index 100% rename from subsystem/modes/ModeStore.h rename to src/fsfw/subsystem/modes/ModeStore.h diff --git a/subsystem/modes/ModeStoreIF.h b/src/fsfw/subsystem/modes/ModeStoreIF.h similarity index 100% rename from subsystem/modes/ModeStoreIF.h rename to src/fsfw/subsystem/modes/ModeStoreIF.h diff --git a/tasks/CMakeLists.txt b/src/fsfw/tasks/CMakeLists.txt similarity index 100% rename from tasks/CMakeLists.txt rename to src/fsfw/tasks/CMakeLists.txt diff --git a/tasks/ExecutableObjectIF.h b/src/fsfw/tasks/ExecutableObjectIF.h similarity index 100% rename from tasks/ExecutableObjectIF.h rename to src/fsfw/tasks/ExecutableObjectIF.h diff --git a/tasks/FixedSequenceSlot.cpp b/src/fsfw/tasks/FixedSequenceSlot.cpp similarity index 85% rename from tasks/FixedSequenceSlot.cpp rename to src/fsfw/tasks/FixedSequenceSlot.cpp index f5d82178d..9f617b589 100644 --- a/tasks/FixedSequenceSlot.cpp +++ b/src/fsfw/tasks/FixedSequenceSlot.cpp @@ -1,5 +1,6 @@ -#include "FixedSequenceSlot.h" -#include "PeriodicTaskIF.h" +#include "fsfw/tasks/FixedSequenceSlot.h" +#include "fsfw/tasks/PeriodicTaskIF.h" + #include FixedSequenceSlot::FixedSequenceSlot(object_id_t handlerId, uint32_t setTime, diff --git a/tasks/FixedSequenceSlot.h b/src/fsfw/tasks/FixedSequenceSlot.h similarity index 97% rename from tasks/FixedSequenceSlot.h rename to src/fsfw/tasks/FixedSequenceSlot.h index 1744ec198..aea77dfe8 100644 --- a/tasks/FixedSequenceSlot.h +++ b/src/fsfw/tasks/FixedSequenceSlot.h @@ -2,7 +2,7 @@ #define FSFW_TASKS_FIXEDSEQUENCESLOT_H_ #include "ExecutableObjectIF.h" -#include "../objectmanager/ObjectManagerIF.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" class PeriodicTaskIF; diff --git a/tasks/FixedSlotSequence.cpp b/src/fsfw/tasks/FixedSlotSequence.cpp similarity index 94% rename from tasks/FixedSlotSequence.cpp rename to src/fsfw/tasks/FixedSlotSequence.cpp index 54b6ae6d3..5e896af4b 100644 --- a/tasks/FixedSlotSequence.cpp +++ b/src/fsfw/tasks/FixedSlotSequence.cpp @@ -1,5 +1,6 @@ -#include "FixedSlotSequence.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/tasks/FixedSlotSequence.h" +#include "fsfw/tasks/FixedTimeslotTaskIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include FixedSlotSequence::FixedSlotSequence(uint32_t setLengthMs) : @@ -92,10 +93,9 @@ void FixedSlotSequence::addSlot(object_id_t componentId, uint32_t slotTimeMs, ReturnValue_t FixedSlotSequence::checkSequence() const { if(slotList.empty()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FixedSlotSequence::checkSequence:" - << " Slot list is empty!" << std::endl; + sif::warning << "FixedSlotSequence::checkSequence: Slot list is empty!" << std::endl; #endif - return HasReturnvaluesIF::RETURN_FAILED; + return FixedTimeslotTaskIF::SLOT_LIST_EMPTY; } if(customCheckFunction != nullptr) { diff --git a/tasks/FixedSlotSequence.h b/src/fsfw/tasks/FixedSlotSequence.h similarity index 98% rename from tasks/FixedSlotSequence.h rename to src/fsfw/tasks/FixedSlotSequence.h index 077dd10ba..7f49ea0c5 100644 --- a/tasks/FixedSlotSequence.h +++ b/src/fsfw/tasks/FixedSlotSequence.h @@ -2,7 +2,7 @@ #define FSFW_TASKS_FIXEDSLOTSEQUENCE_H_ #include "FixedSequenceSlot.h" -#include "../objectmanager/SystemObject.h" +#include "fsfw/objectmanager/SystemObject.h" #include @@ -136,6 +136,7 @@ public: * @details * Checks if timing is ok (must be ascending) and if all handlers were found. * @return + * - SLOT_LIST_EMPTY if the slot list is empty */ ReturnValue_t checkSequence() const; @@ -147,6 +148,7 @@ public: * The general check will be continued for now if the custom check function * fails but a diagnostic debug output will be given. * @param customCheckFunction + * */ void addCustomCheck(ReturnValue_t (*customCheckFunction)(const SlotList &)); diff --git a/tasks/FixedTimeslotTaskIF.h b/src/fsfw/tasks/FixedTimeslotTaskIF.h similarity index 81% rename from tasks/FixedTimeslotTaskIF.h rename to src/fsfw/tasks/FixedTimeslotTaskIF.h index 2fc7e0922..605239a47 100644 --- a/tasks/FixedTimeslotTaskIF.h +++ b/src/fsfw/tasks/FixedTimeslotTaskIF.h @@ -2,7 +2,8 @@ #define FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_ #include "PeriodicTaskIF.h" -#include "../objectmanager/ObjectManagerIF.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/returnvalues/FwClassIds.h" /** * @brief Following the same principle as the base class IF. @@ -12,6 +13,8 @@ class FixedTimeslotTaskIF : public PeriodicTaskIF { public: virtual ~FixedTimeslotTaskIF() {} + static constexpr ReturnValue_t SLOT_LIST_EMPTY = HasReturnvaluesIF::makeReturnCode( + CLASS_ID::FIXED_SLOT_TASK_IF, 0); /** * Add an object with a slot time and the execution step to the task. * The execution step will be passed to the object (e.g. as an operation diff --git a/tasks/PeriodicTaskIF.h b/src/fsfw/tasks/PeriodicTaskIF.h similarity index 100% rename from tasks/PeriodicTaskIF.h rename to src/fsfw/tasks/PeriodicTaskIF.h diff --git a/tasks/SemaphoreFactory.h b/src/fsfw/tasks/SemaphoreFactory.h similarity index 97% rename from tasks/SemaphoreFactory.h rename to src/fsfw/tasks/SemaphoreFactory.h index 01c09d1b5..2df7d53f5 100644 --- a/tasks/SemaphoreFactory.h +++ b/src/fsfw/tasks/SemaphoreFactory.h @@ -1,7 +1,7 @@ #ifndef FSFW_TASKS_SEMAPHOREFACTORY_H_ #define FSFW_TASKS_SEMAPHOREFACTORY_H_ -#include "../tasks/SemaphoreIF.h" +#include "fsfw/tasks/SemaphoreIF.h" /** * Creates Semaphore. diff --git a/tasks/SemaphoreIF.h b/src/fsfw/tasks/SemaphoreIF.h similarity index 100% rename from tasks/SemaphoreIF.h rename to src/fsfw/tasks/SemaphoreIF.h diff --git a/tasks/TaskFactory.h b/src/fsfw/tasks/TaskFactory.h similarity index 100% rename from tasks/TaskFactory.h rename to src/fsfw/tasks/TaskFactory.h diff --git a/tasks/Typedef.h b/src/fsfw/tasks/Typedef.h similarity index 55% rename from tasks/Typedef.h rename to src/fsfw/tasks/Typedef.h index 55f6bda26..f2f9fe65a 100644 --- a/tasks/Typedef.h +++ b/src/fsfw/tasks/Typedef.h @@ -1,5 +1,8 @@ -#ifndef FRAMEWORK_TASKS_TYPEDEF_H_ -#define FRAMEWORK_TASKS_TYPEDEF_H_ +#ifndef FSFW_TASKS_TYPEDEF_H_ +#define FSFW_TASKS_TYPEDEF_H_ + +#include +#include typedef const char* TaskName; typedef uint32_t TaskPriority; @@ -7,4 +10,4 @@ typedef size_t TaskStackSize; typedef double TaskPeriod; typedef void (*TaskDeadlineMissedFunction)(); -#endif /* FRAMEWORK_TASKS_TYPEDEF_H_ */ +#endif /* FSFW_TASKS_TYPEDEF_H_ */ diff --git a/tcdistribution/CCSDSDistributor.cpp b/src/fsfw/tcdistribution/CCSDSDistributor.cpp similarity index 94% rename from tcdistribution/CCSDSDistributor.cpp rename to src/fsfw/tcdistribution/CCSDSDistributor.cpp index 7380866aa..ffceaecc7 100644 --- a/tcdistribution/CCSDSDistributor.cpp +++ b/src/fsfw/tcdistribution/CCSDSDistributor.cpp @@ -1,8 +1,8 @@ -#include "CCSDSDistributor.h" +#include "fsfw/tcdistribution/CCSDSDistributor.h" -#include "../objectmanager/ObjectManager.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../tmtcpacket/SpacePacketBase.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tmtcpacket/SpacePacketBase.h" #define CCSDS_DISTRIBUTOR_DEBUGGING 0 diff --git a/tcdistribution/CCSDSDistributor.h b/src/fsfw/tcdistribution/CCSDSDistributor.h similarity index 100% rename from tcdistribution/CCSDSDistributor.h rename to src/fsfw/tcdistribution/CCSDSDistributor.h diff --git a/tcdistribution/CCSDSDistributorIF.h b/src/fsfw/tcdistribution/CCSDSDistributorIF.h similarity index 100% rename from tcdistribution/CCSDSDistributorIF.h rename to src/fsfw/tcdistribution/CCSDSDistributorIF.h diff --git a/tcdistribution/CMakeLists.txt b/src/fsfw/tcdistribution/CMakeLists.txt similarity index 100% rename from tcdistribution/CMakeLists.txt rename to src/fsfw/tcdistribution/CMakeLists.txt diff --git a/tcdistribution/PUSDistributor.cpp b/src/fsfw/tcdistribution/PUSDistributor.cpp similarity index 94% rename from tcdistribution/PUSDistributor.cpp rename to src/fsfw/tcdistribution/PUSDistributor.cpp index 955a80932..eec02429d 100644 --- a/tcdistribution/PUSDistributor.cpp +++ b/src/fsfw/tcdistribution/PUSDistributor.cpp @@ -1,9 +1,9 @@ -#include "CCSDSDistributorIF.h" -#include "PUSDistributor.h" +#include "fsfw/tcdistribution/CCSDSDistributorIF.h" +#include "fsfw/tcdistribution/PUSDistributor.h" -#include "../objectmanager/ObjectManager.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../tmtcservices/PusVerificationReport.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tmtcservices/PusVerificationReport.h" #define PUS_DISTRIBUTOR_DEBUGGING 0 diff --git a/tcdistribution/PUSDistributor.h b/src/fsfw/tcdistribution/PUSDistributor.h similarity index 92% rename from tcdistribution/PUSDistributor.h rename to src/fsfw/tcdistribution/PUSDistributor.h index c6f863f04..53a996ca7 100644 --- a/tcdistribution/PUSDistributor.h +++ b/src/fsfw/tcdistribution/PUSDistributor.h @@ -5,10 +5,10 @@ #include "TcDistributor.h" #include "TcPacketCheck.h" -#include "../tmtcpacket/pus/tc.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../tmtcservices/AcceptsTelecommandsIF.h" -#include "../tmtcservices/VerificationReporter.h" +#include "fsfw/tmtcpacket/pus/tc.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" +#include "fsfw/tmtcservices/VerificationReporter.h" /** * This class accepts PUS Telecommands and forwards them to Application diff --git a/tcdistribution/PUSDistributorIF.h b/src/fsfw/tcdistribution/PUSDistributorIF.h similarity index 100% rename from tcdistribution/PUSDistributorIF.h rename to src/fsfw/tcdistribution/PUSDistributorIF.h diff --git a/tcdistribution/TcDistributor.cpp b/src/fsfw/tcdistribution/TcDistributor.cpp similarity index 89% rename from tcdistribution/TcDistributor.cpp rename to src/fsfw/tcdistribution/TcDistributor.cpp index df0695564..8384e6eee 100644 --- a/tcdistribution/TcDistributor.cpp +++ b/src/fsfw/tcdistribution/TcDistributor.cpp @@ -1,8 +1,8 @@ -#include "TcDistributor.h" +#include "fsfw/tcdistribution/TcDistributor.h" -#include "../serviceinterface/ServiceInterfaceStream.h" -#include "../tmtcservices/TmTcMessage.h" -#include "../ipc/QueueFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tmtcservices/TmTcMessage.h" +#include "fsfw/ipc/QueueFactory.h" TcDistributor::TcDistributor(object_id_t objectId) : SystemObject(objectId) { diff --git a/tcdistribution/TcDistributor.h b/src/fsfw/tcdistribution/TcDistributor.h similarity index 93% rename from tcdistribution/TcDistributor.h rename to src/fsfw/tcdistribution/TcDistributor.h index 5d0ca45d2..14b532bd3 100644 --- a/tcdistribution/TcDistributor.h +++ b/src/fsfw/tcdistribution/TcDistributor.h @@ -1,13 +1,13 @@ #ifndef FSFW_TMTCSERVICES_TCDISTRIBUTOR_H_ #define FSFW_TMTCSERVICES_TCDISTRIBUTOR_H_ -#include "../objectmanager/ObjectManagerIF.h" -#include "../objectmanager/SystemObject.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../storagemanager/StorageManagerIF.h" -#include "../tasks/ExecutableObjectIF.h" -#include "../tmtcservices/TmTcMessage.h" -#include "../ipc/MessageQueueIF.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/tmtcservices/TmTcMessage.h" +#include "fsfw/ipc/MessageQueueIF.h" #include /** diff --git a/tcdistribution/TcPacketCheck.cpp b/src/fsfw/tcdistribution/TcPacketCheck.cpp similarity index 78% rename from tcdistribution/TcPacketCheck.cpp rename to src/fsfw/tcdistribution/TcPacketCheck.cpp index b3a025a49..44501c58c 100644 --- a/tcdistribution/TcPacketCheck.cpp +++ b/src/fsfw/tcdistribution/TcPacketCheck.cpp @@ -1,11 +1,11 @@ -#include "TcPacketCheck.h" +#include "fsfw/tcdistribution/TcPacketCheck.h" -#include "../globalfunctions/CRC.h" -#include "../tmtcpacket/pus/tc/TcPacketBase.h" -#include "../tmtcpacket/pus/tc/TcPacketStoredBase.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../storagemanager/StorageManagerIF.h" -#include "../tmtcservices/VerificationCodes.h" +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/tmtcpacket/pus/tc/TcPacketBase.h" +#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/tmtcservices/VerificationCodes.h" TcPacketCheck::TcPacketCheck(uint16_t setApid): apid(setApid) { } diff --git a/tcdistribution/TcPacketCheck.h b/src/fsfw/tcdistribution/TcPacketCheck.h similarity index 94% rename from tcdistribution/TcPacketCheck.h rename to src/fsfw/tcdistribution/TcPacketCheck.h index 7106b7e41..519943c7f 100644 --- a/tcdistribution/TcPacketCheck.h +++ b/src/fsfw/tcdistribution/TcPacketCheck.h @@ -1,9 +1,9 @@ #ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECK_H_ #define FSFW_TCDISTRIBUTION_TCPACKETCHECK_H_ -#include "../FSFW.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../tmtcservices/PusVerificationReport.h" +#include "fsfw/FSFW.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tmtcservices/PusVerificationReport.h" class TcPacketStoredBase; diff --git a/thermal/AbstractTemperatureSensor.cpp b/src/fsfw/thermal/AbstractTemperatureSensor.cpp similarity index 95% rename from thermal/AbstractTemperatureSensor.cpp rename to src/fsfw/thermal/AbstractTemperatureSensor.cpp index 40b305af9..68e8d1c08 100644 --- a/thermal/AbstractTemperatureSensor.cpp +++ b/src/fsfw/thermal/AbstractTemperatureSensor.cpp @@ -1,5 +1,5 @@ -#include "AbstractTemperatureSensor.h" -#include "../ipc/QueueFactory.h" +#include "fsfw/thermal/AbstractTemperatureSensor.h" +#include "fsfw/ipc/QueueFactory.h" AbstractTemperatureSensor::AbstractTemperatureSensor(object_id_t setObjectid, ThermalModuleIF *thermalModule) : diff --git a/thermal/AbstractTemperatureSensor.h b/src/fsfw/thermal/AbstractTemperatureSensor.h similarity index 86% rename from thermal/AbstractTemperatureSensor.h rename to src/fsfw/thermal/AbstractTemperatureSensor.h index a1153314e..719d84fec 100644 --- a/thermal/AbstractTemperatureSensor.h +++ b/src/fsfw/thermal/AbstractTemperatureSensor.h @@ -1,12 +1,12 @@ #ifndef ABSTRACTSENSOR_H_ #define ABSTRACTSENSOR_H_ -#include "../health/HasHealthIF.h" -#include "../health/HealthHelper.h" -#include "../objectmanager/SystemObject.h" -#include "../tasks/ExecutableObjectIF.h" -#include "../parameters/ParameterHelper.h" -#include "../ipc/MessageQueueIF.h" +#include "fsfw/health/HasHealthIF.h" +#include "fsfw/health/HealthHelper.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/parameters/ParameterHelper.h" +#include "fsfw/ipc/MessageQueueIF.h" #include "ThermalModuleIF.h" #include "tcsDefinitions.h" diff --git a/thermal/AcceptsThermalMessagesIF.h b/src/fsfw/thermal/AcceptsThermalMessagesIF.h similarity index 100% rename from thermal/AcceptsThermalMessagesIF.h rename to src/fsfw/thermal/AcceptsThermalMessagesIF.h diff --git a/thermal/CMakeLists.txt b/src/fsfw/thermal/CMakeLists.txt similarity index 100% rename from thermal/CMakeLists.txt rename to src/fsfw/thermal/CMakeLists.txt diff --git a/thermal/Heater.cpp b/src/fsfw/thermal/Heater.cpp similarity index 98% rename from thermal/Heater.cpp rename to src/fsfw/thermal/Heater.cpp index f97cb543f..e6acba136 100644 --- a/thermal/Heater.cpp +++ b/src/fsfw/thermal/Heater.cpp @@ -1,9 +1,9 @@ -#include "Heater.h" +#include "fsfw/thermal/Heater.h" -#include "../objectmanager/ObjectManager.h" -#include "../devicehandlers/DeviceHandlerFailureIsolation.h" -#include "../power/Fuse.h" -#include "../ipc/QueueFactory.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/devicehandlers/DeviceHandlerFailureIsolation.h" +#include "fsfw/power/Fuse.h" +#include "fsfw/ipc/QueueFactory.h" Heater::Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1) : HealthDevice(objectId, 0), internalState(STATE_OFF), switch0(switch0), switch1(switch1), diff --git a/thermal/Heater.h b/src/fsfw/thermal/Heater.h similarity index 92% rename from thermal/Heater.h rename to src/fsfw/thermal/Heater.h index 2caddd852..2a40cac6e 100644 --- a/thermal/Heater.h +++ b/src/fsfw/thermal/Heater.h @@ -1,11 +1,12 @@ #ifndef FSFW_THERMAL_HEATER_H_ #define FSFW_THERMAL_HEATER_H_ -#include "../devicehandlers/HealthDevice.h" -#include "../parameters/ParameterHelper.h" -#include "../power/PowerSwitchIF.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../timemanager/Countdown.h" +#include "fsfw/devicehandlers/HealthDevice.h" +#include "fsfw/parameters/ParameterHelper.h" +#include "fsfw/power/PowerSwitchIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/timemanager/Countdown.h" + #include diff --git a/thermal/RedundantHeater.cpp b/src/fsfw/thermal/RedundantHeater.cpp similarity index 95% rename from thermal/RedundantHeater.cpp rename to src/fsfw/thermal/RedundantHeater.cpp index 6463fcc8e..e7b774cba 100644 --- a/thermal/RedundantHeater.cpp +++ b/src/fsfw/thermal/RedundantHeater.cpp @@ -1,4 +1,4 @@ -#include "RedundantHeater.h" +#include "fsfw/thermal/RedundantHeater.h" RedundantHeater::~RedundantHeater() { } diff --git a/thermal/RedundantHeater.h b/src/fsfw/thermal/RedundantHeater.h similarity index 100% rename from thermal/RedundantHeater.h rename to src/fsfw/thermal/RedundantHeater.h diff --git a/thermal/TemperatureSensor.h b/src/fsfw/thermal/TemperatureSensor.h similarity index 100% rename from thermal/TemperatureSensor.h rename to src/fsfw/thermal/TemperatureSensor.h diff --git a/thermal/ThermalComponent.cpp b/src/fsfw/thermal/ThermalComponent.cpp similarity index 99% rename from thermal/ThermalComponent.cpp rename to src/fsfw/thermal/ThermalComponent.cpp index d42c34b33..8d4b7bbdb 100644 --- a/thermal/ThermalComponent.cpp +++ b/src/fsfw/thermal/ThermalComponent.cpp @@ -1,4 +1,4 @@ -#include "ThermalComponent.h" +#include "fsfw/thermal/ThermalComponent.h" ThermalComponent::ThermalComponent(object_id_t reportingObjectId, uint8_t domainId, gp_id_t temperaturePoolId, diff --git a/thermal/ThermalComponent.h b/src/fsfw/thermal/ThermalComponent.h similarity index 100% rename from thermal/ThermalComponent.h rename to src/fsfw/thermal/ThermalComponent.h diff --git a/thermal/ThermalComponentCore.cpp b/src/fsfw/thermal/ThermalComponentCore.cpp similarity index 98% rename from thermal/ThermalComponentCore.cpp rename to src/fsfw/thermal/ThermalComponentCore.cpp index 7df04b047..7718ac369 100644 --- a/thermal/ThermalComponentCore.cpp +++ b/src/fsfw/thermal/ThermalComponentCore.cpp @@ -1,5 +1,5 @@ -#include "ThermalComponentCore.h" -#include "tcsDefinitions.h" +#include "fsfw/thermal/ThermalComponentCore.h" +#include "fsfw/thermal/tcsDefinitions.h" ThermalComponentCore::ThermalComponentCore(object_id_t reportingObjectId, uint8_t domainId, gp_id_t temperaturePoolId, diff --git a/thermal/ThermalComponentCore.h b/src/fsfw/thermal/ThermalComponentCore.h similarity index 98% rename from thermal/ThermalComponentCore.h rename to src/fsfw/thermal/ThermalComponentCore.h index a1fa594a5..194300159 100644 --- a/thermal/ThermalComponentCore.h +++ b/src/fsfw/thermal/ThermalComponentCore.h @@ -6,7 +6,7 @@ #include "AbstractTemperatureSensor.h" #include "ThermalModule.h" -#include "../datapoollocal/LocalPoolVariable.h" +#include "fsfw/datapoollocal/LocalPoolVariable.h" /** * @brief diff --git a/thermal/ThermalComponentIF.h b/src/fsfw/thermal/ThermalComponentIF.h similarity index 100% rename from thermal/ThermalComponentIF.h rename to src/fsfw/thermal/ThermalComponentIF.h diff --git a/thermal/ThermalModule.cpp b/src/fsfw/thermal/ThermalModule.cpp similarity index 97% rename from thermal/ThermalModule.cpp rename to src/fsfw/thermal/ThermalModule.cpp index de3475429..d8108ab3d 100644 --- a/thermal/ThermalModule.cpp +++ b/src/fsfw/thermal/ThermalModule.cpp @@ -1,8 +1,8 @@ -#include "ThermalModule.h" -#include "AbstractTemperatureSensor.h" +#include "fsfw/thermal/ThermalModule.h" +#include "fsfw/thermal/AbstractTemperatureSensor.h" -#include "../monitoring/LimitViolationReporter.h" -#include "../monitoring/MonitoringMessageContent.h" +#include "fsfw/monitoring/LimitViolationReporter.h" +#include "fsfw/monitoring/MonitoringMessageContent.h" ThermalModule::ThermalModule(gp_id_t moduleTemperaturePoolId, diff --git a/thermal/ThermalModule.h b/src/fsfw/thermal/ThermalModule.h similarity index 100% rename from thermal/ThermalModule.h rename to src/fsfw/thermal/ThermalModule.h diff --git a/thermal/ThermalModuleIF.h b/src/fsfw/thermal/ThermalModuleIF.h similarity index 100% rename from thermal/ThermalModuleIF.h rename to src/fsfw/thermal/ThermalModuleIF.h diff --git a/thermal/ThermalMonitorReporter.cpp b/src/fsfw/thermal/ThermalMonitorReporter.cpp similarity index 94% rename from thermal/ThermalMonitorReporter.cpp rename to src/fsfw/thermal/ThermalMonitorReporter.cpp index cefc61107..31503203e 100644 --- a/thermal/ThermalMonitorReporter.cpp +++ b/src/fsfw/thermal/ThermalMonitorReporter.cpp @@ -1,7 +1,7 @@ -#include "ThermalMonitorReporter.h" -#include "ThermalComponentIF.h" +#include "fsfw/thermal/ThermalMonitorReporter.h" +#include "fsfw/thermal/ThermalComponentIF.h" -#include "../monitoring/MonitoringIF.h" +#include "fsfw/monitoring/MonitoringIF.h" ThermalMonitorReporter::~ThermalMonitorReporter() { } diff --git a/thermal/ThermalMonitorReporter.h b/src/fsfw/thermal/ThermalMonitorReporter.h similarity index 100% rename from thermal/ThermalMonitorReporter.h rename to src/fsfw/thermal/ThermalMonitorReporter.h diff --git a/thermal/tcsDefinitions.h b/src/fsfw/thermal/tcsDefinitions.h similarity index 100% rename from thermal/tcsDefinitions.h rename to src/fsfw/thermal/tcsDefinitions.h diff --git a/timemanager/CCSDSTime.cpp b/src/fsfw/timemanager/CCSDSTime.cpp similarity index 99% rename from timemanager/CCSDSTime.cpp rename to src/fsfw/timemanager/CCSDSTime.cpp index 192c1f57a..2475a5ebd 100644 --- a/timemanager/CCSDSTime.cpp +++ b/src/fsfw/timemanager/CCSDSTime.cpp @@ -1,5 +1,6 @@ -#include "CCSDSTime.h" -#include +#include "fsfw/FSFW.h" +#include "fsfw/timemanager/CCSDSTime.h" + #include #include #include diff --git a/timemanager/CCSDSTime.h b/src/fsfw/timemanager/CCSDSTime.h similarity index 100% rename from timemanager/CCSDSTime.h rename to src/fsfw/timemanager/CCSDSTime.h diff --git a/src/fsfw/timemanager/CMakeLists.txt b/src/fsfw/timemanager/CMakeLists.txt new file mode 100644 index 000000000..004677729 --- /dev/null +++ b/src/fsfw/timemanager/CMakeLists.txt @@ -0,0 +1,8 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + CCSDSTime.cpp + Countdown.cpp + Stopwatch.cpp + TimeMessage.cpp + TimeStamper.cpp + ClockCommon.cpp +) diff --git a/timemanager/Clock.h b/src/fsfw/timemanager/Clock.h similarity index 97% rename from timemanager/Clock.h rename to src/fsfw/timemanager/Clock.h index 6a76c86d9..b1d6bfafb 100644 --- a/timemanager/Clock.h +++ b/src/fsfw/timemanager/Clock.h @@ -2,9 +2,9 @@ #define FSFW_TIMEMANAGER_CLOCK_H_ #include "clockDefinitions.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../ipc/MutexFactory.h" -#include "../globalfunctions/timevalOperations.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/ipc/MutexFactory.h" +#include "fsfw/globalfunctions/timevalOperations.h" #include diff --git a/timemanager/ClockCommon.cpp b/src/fsfw/timemanager/ClockCommon.cpp similarity index 95% rename from timemanager/ClockCommon.cpp rename to src/fsfw/timemanager/ClockCommon.cpp index e56d4953a..82c65b965 100644 --- a/timemanager/ClockCommon.cpp +++ b/src/fsfw/timemanager/ClockCommon.cpp @@ -1,5 +1,5 @@ -#include "Clock.h" -#include "../ipc/MutexGuard.h" +#include "fsfw/timemanager/Clock.h" +#include "fsfw/ipc/MutexGuard.h" ReturnValue_t Clock::convertUTCToTT(timeval utc, timeval *tt) { uint16_t leapSeconds; diff --git a/src/fsfw/timemanager/Countdown.cpp b/src/fsfw/timemanager/Countdown.cpp new file mode 100644 index 000000000..23d574776 --- /dev/null +++ b/src/fsfw/timemanager/Countdown.cpp @@ -0,0 +1,51 @@ +#include "fsfw/timemanager/Countdown.h" + +Countdown::Countdown(uint32_t initialTimeout): timeout(initialTimeout) { +} + +Countdown::~Countdown() { +} + +ReturnValue_t Countdown::setTimeout(uint32_t milliseconds) { + ReturnValue_t returnValue = Clock::getUptime( &startTime ); + timeout = milliseconds; + return returnValue; +} + +bool Countdown::hasTimedOut() const { + if ( uint32_t( this->getCurrentTime() - startTime) >= timeout) { + return true; + } else { + return false; + } +} + +bool Countdown::isBusy() const { + return !hasTimedOut(); +} + +ReturnValue_t Countdown::resetTimer() { + return setTimeout(timeout); +} + +void Countdown::timeOut() { + startTime = this->getCurrentTime() - timeout; +} + +uint32_t Countdown::getRemainingMillis() const { + // We fetch the time before the if-statement + // to be sure that the return is in + // range 0 <= number <= timeout + uint32_t currentTime = this->getCurrentTime(); + if (this->hasTimedOut()){ + return 0; + }else{ + return (startTime + timeout) - currentTime; + } +} + +uint32_t Countdown::getCurrentTime() const { + uint32_t currentTime; + Clock::getUptime( ¤tTime ); + return currentTime; +} diff --git a/src/fsfw/timemanager/Countdown.h b/src/fsfw/timemanager/Countdown.h new file mode 100644 index 000000000..c0afdf755 --- /dev/null +++ b/src/fsfw/timemanager/Countdown.h @@ -0,0 +1,80 @@ +#ifndef FSFW_TIMEMANAGER_COUNTDOWN_H_ +#define FSFW_TIMEMANAGER_COUNTDOWN_H_ + +#include "Clock.h" + +/** + * + * Countdown keeps track of a timespan. + * + * Countdown::resetTimer restarts the timer. + * Countdown::setTimeout sets a new countdown duration and resets. + * + * Can be checked with Countdown::hasTimedOut or + * Countdown::isBusy. + * + * Countdown::timeOut will force the timer to time out. + * + */ +class Countdown { +public: + /** + * Constructor which sets the countdown duration in milliseconds + * + * It does not start the countdown! + * Call resetTimer or setTimeout before usage! + * Otherwise a call to hasTimedOut might return True. + * + * @param initialTimeout Countdown duration in milliseconds + */ + Countdown(uint32_t initialTimeout = 0); + ~Countdown(); + /** + * Call to set a new countdown duration. + * + * Resets the countdown! + * + * @param milliseconds new countdown duration in milliseconds + * @return Returnvalue from Clock::getUptime + */ + ReturnValue_t setTimeout(uint32_t milliseconds); + /** + * Returns true if the countdown duration has passed. + * + * @return True if the countdown has passed + * False if it is still running + */ + bool hasTimedOut() const; + /** + * Complementary to hasTimedOut. + * + * @return True if the countdown is till running + * False if it is still running + */ + bool isBusy() const; + /** + * Uses last set timeout value and restarts timer. + */ + ReturnValue_t resetTimer(); + /** + * Returns the remaining milliseconds (0 if timeout) + */ + uint32_t getRemainingMillis() const; + /** + * Makes hasTimedOut() return true + */ + void timeOut(); + /** + * Internal countdown duration in milliseconds + */ + uint32_t timeout; +private: + /** + * Last time the timer was started (uptime) + */ + uint32_t startTime = 0; + + uint32_t getCurrentTime() const; +}; + +#endif /* FSFW_TIMEMANAGER_COUNTDOWN_H_ */ diff --git a/timemanager/ReceivesTimeInfoIF.h b/src/fsfw/timemanager/ReceivesTimeInfoIF.h similarity index 100% rename from timemanager/ReceivesTimeInfoIF.h rename to src/fsfw/timemanager/ReceivesTimeInfoIF.h diff --git a/timemanager/Stopwatch.cpp b/src/fsfw/timemanager/Stopwatch.cpp similarity index 95% rename from timemanager/Stopwatch.cpp rename to src/fsfw/timemanager/Stopwatch.cpp index 04ccab726..a8f870297 100644 --- a/timemanager/Stopwatch.cpp +++ b/src/fsfw/timemanager/Stopwatch.cpp @@ -1,5 +1,5 @@ -#include "Stopwatch.h" -#include "../serviceinterface/ServiceInterface.h" +#include "fsfw/timemanager/Stopwatch.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #if FSFW_CPP_OSTREAM_ENABLED == 1 #include diff --git a/timemanager/Stopwatch.h b/src/fsfw/timemanager/Stopwatch.h similarity index 100% rename from timemanager/Stopwatch.h rename to src/fsfw/timemanager/Stopwatch.h diff --git a/timemanager/TimeMessage.cpp b/src/fsfw/timemanager/TimeMessage.cpp similarity index 94% rename from timemanager/TimeMessage.cpp rename to src/fsfw/timemanager/TimeMessage.cpp index 66aea0f4d..320f30002 100644 --- a/timemanager/TimeMessage.cpp +++ b/src/fsfw/timemanager/TimeMessage.cpp @@ -1,4 +1,4 @@ -#include "TimeMessage.h" +#include "fsfw/timemanager/TimeMessage.h" TimeMessage::TimeMessage() { this->messageSize += sizeof(timeval) + sizeof(uint32_t); diff --git a/timemanager/TimeMessage.h b/src/fsfw/timemanager/TimeMessage.h similarity index 100% rename from timemanager/TimeMessage.h rename to src/fsfw/timemanager/TimeMessage.h diff --git a/timemanager/TimeStamper.cpp b/src/fsfw/timemanager/TimeStamper.cpp similarity index 87% rename from timemanager/TimeStamper.cpp rename to src/fsfw/timemanager/TimeStamper.cpp index d9f0f2f3e..4926c2d59 100644 --- a/timemanager/TimeStamper.cpp +++ b/src/fsfw/timemanager/TimeStamper.cpp @@ -1,5 +1,6 @@ -#include "TimeStamper.h" -#include "Clock.h" +#include "fsfw/timemanager/TimeStamper.h" +#include "fsfw/timemanager/Clock.h" + #include TimeStamper::TimeStamper(object_id_t objectId): SystemObject(objectId) {} diff --git a/timemanager/TimeStamper.h b/src/fsfw/timemanager/TimeStamper.h similarity index 100% rename from timemanager/TimeStamper.h rename to src/fsfw/timemanager/TimeStamper.h diff --git a/timemanager/TimeStamperIF.h b/src/fsfw/timemanager/TimeStamperIF.h similarity index 100% rename from timemanager/TimeStamperIF.h rename to src/fsfw/timemanager/TimeStamperIF.h diff --git a/timemanager/clockDefinitions.h b/src/fsfw/timemanager/clockDefinitions.h similarity index 100% rename from timemanager/clockDefinitions.h rename to src/fsfw/timemanager/clockDefinitions.h diff --git a/tmstorage/CMakeLists.txt b/src/fsfw/tmstorage/CMakeLists.txt similarity index 100% rename from tmstorage/CMakeLists.txt rename to src/fsfw/tmstorage/CMakeLists.txt diff --git a/tmstorage/TmStoreBackendIF.h b/src/fsfw/tmstorage/TmStoreBackendIF.h similarity index 95% rename from tmstorage/TmStoreBackendIF.h rename to src/fsfw/tmstorage/TmStoreBackendIF.h index 4ae776095..4183334b9 100644 --- a/tmstorage/TmStoreBackendIF.h +++ b/src/fsfw/tmstorage/TmStoreBackendIF.h @@ -1,11 +1,13 @@ #ifndef FSFW_TMTCSERVICES_TMSTOREBACKENDIF_H_ #define FSFW_TMTCSERVICES_TMSTOREBACKENDIF_H_ -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../objectmanager/SystemObjectIF.h" -#include "../parameters/HasParametersIF.h" -#include "../storagemanager/StorageManagerIF.h" -#include "../timemanager/Clock.h" +#include "tmStorageConf.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/objectmanager/SystemObjectIF.h" +#include "fsfw/parameters/HasParametersIF.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/timemanager/Clock.h" + class TmPacketInformation; class TmPacketMinimal; class SpacePacketBase; diff --git a/tmstorage/TmStoreFrontendIF.h b/src/fsfw/tmstorage/TmStoreFrontendIF.h similarity index 95% rename from tmstorage/TmStoreFrontendIF.h rename to src/fsfw/tmstorage/TmStoreFrontendIF.h index beee7ede0..11b2a6863 100644 --- a/tmstorage/TmStoreFrontendIF.h +++ b/src/fsfw/tmstorage/TmStoreFrontendIF.h @@ -1,9 +1,10 @@ #ifndef FSFW_TMTCSERVICES_TMSTOREFRONTENDIF_H_ #define FSFW_TMTCSERVICES_TMSTOREFRONTENDIF_H_ +#include "tmStorageConf.h" #include "TmStorePackets.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../ipc/MessageQueueSenderIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" class TmPacketMinimal; class SpacePacketBase; diff --git a/tmstorage/TmStoreMessage.cpp b/src/fsfw/tmstorage/TmStoreMessage.cpp similarity index 99% rename from tmstorage/TmStoreMessage.cpp rename to src/fsfw/tmstorage/TmStoreMessage.cpp index 11af6121e..fa5fb5414 100644 --- a/tmstorage/TmStoreMessage.cpp +++ b/src/fsfw/tmstorage/TmStoreMessage.cpp @@ -1,5 +1,5 @@ #include "TmStoreMessage.h" -#include "../objectmanager/ObjectManager.h" +#include "fsfw/objectmanager/ObjectManager.h" TmStoreMessage::~TmStoreMessage() { diff --git a/tmstorage/TmStoreMessage.h b/src/fsfw/tmstorage/TmStoreMessage.h similarity index 95% rename from tmstorage/TmStoreMessage.h rename to src/fsfw/tmstorage/TmStoreMessage.h index d0178920c..51f86b3ad 100644 --- a/tmstorage/TmStoreMessage.h +++ b/src/fsfw/tmstorage/TmStoreMessage.h @@ -1,10 +1,11 @@ #ifndef FSFW_TMSTORAGE_TMSTOREMESSAGE_H_ #define FSFW_TMSTORAGE_TMSTOREMESSAGE_H_ +#include "tmStorageConf.h" #include "TmStorePackets.h" -#include "../ipc/CommandMessage.h" -#include "../storagemanager/StorageManagerIF.h" -#include "../objectmanager/SystemObjectIF.h" +#include "fsfw/ipc/CommandMessage.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/objectmanager/SystemObjectIF.h" class TmStoreMessage { public: diff --git a/tmstorage/TmStorePackets.h b/src/fsfw/tmstorage/TmStorePackets.h similarity index 95% rename from tmstorage/TmStorePackets.h rename to src/fsfw/tmstorage/TmStorePackets.h index 53a5d8d6b..738f7ac21 100644 --- a/tmstorage/TmStorePackets.h +++ b/src/fsfw/tmstorage/TmStorePackets.h @@ -1,14 +1,15 @@ #ifndef FSFW_TMSTORAGE_TMSTOREPACKETS_H_ #define FSFW_TMSTORAGE_TMSTOREPACKETS_H_ -#include "../serialize/SerialFixedArrayListAdapter.h" -#include "../serialize/SerializeElement.h" -#include "../serialize/SerialLinkedListAdapter.h" -#include "../serialize/SerialBufferAdapter.h" -#include "../tmtcpacket/pus/tm/TmPacketMinimal.h" -#include "../timemanager/TimeStamperIF.h" -#include "../timemanager/CCSDSTime.h" -#include "../globalfunctions/timevalOperations.h" +#include "tmStorageConf.h" +#include "fsfw/serialize/SerialFixedArrayListAdapter.h" +#include "fsfw/serialize/SerializeElement.h" +#include "fsfw/serialize/SerialLinkedListAdapter.h" +#include "fsfw/serialize/SerialBufferAdapter.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h" +#include "fsfw/timemanager/TimeStamperIF.h" +#include "fsfw/timemanager/CCSDSTime.h" +#include "fsfw/globalfunctions/timevalOperations.h" class ServiceSubservice: public SerialLinkedListAdapter { public: diff --git a/src/fsfw/tmstorage/tmStorageConf.h b/src/fsfw/tmstorage/tmStorageConf.h new file mode 100644 index 000000000..e5c3d0d5b --- /dev/null +++ b/src/fsfw/tmstorage/tmStorageConf.h @@ -0,0 +1,11 @@ +#ifndef FSFW_TMSTORAGE_TMSTORAGECONF_H_ +#define FSFW_TMSTORAGE_TMSTORAGECONF_H_ + +#include "fsfw/FSFW.h" + +#ifndef FSFW_ADD_TMSTORAGE +#warning TM storage files were includes but compilation was \ + not enabled with FSFW_ADD_TMSTORAGE +#endif + +#endif /* FSFW_TMSTORAGE_TMSTORAGECONF_H_ */ diff --git a/tmtcpacket/CMakeLists.txt b/src/fsfw/tmtcpacket/CMakeLists.txt similarity index 100% rename from tmtcpacket/CMakeLists.txt rename to src/fsfw/tmtcpacket/CMakeLists.txt diff --git a/tmtcpacket/SpacePacket.cpp b/src/fsfw/tmtcpacket/SpacePacket.cpp similarity index 66% rename from tmtcpacket/SpacePacket.cpp rename to src/fsfw/tmtcpacket/SpacePacket.cpp index b8ba27e9a..cbf82e0db 100644 --- a/tmtcpacket/SpacePacket.cpp +++ b/src/fsfw/tmtcpacket/SpacePacket.cpp @@ -1,10 +1,10 @@ -#include "../serviceinterface/ServiceInterfaceStream.h" -#include "ccsds_header.h" -#include "SpacePacket.h" -#include +#include "fsfw/tmtcpacket/ccsds_header.h" +#include "fsfw/tmtcpacket/SpacePacket.h" +#include -SpacePacket::SpacePacket( uint16_t packetDataLength, bool isTelecommand, uint16_t apid, uint16_t sequenceCount ): -SpacePacketBase( (uint8_t*)&this->localData ) { +SpacePacket::SpacePacket(uint16_t packetDataLength, bool isTelecommand, uint16_t apid, + uint16_t sequenceCount): + SpacePacketBase( (uint8_t*)&this->localData ) { initSpacePacketHeader(isTelecommand, false, apid, sequenceCount); this->setPacketSequenceCount(sequenceCount); if ( packetDataLength <= sizeof(this->localData.fields.buffer) ) { diff --git a/tmtcpacket/SpacePacket.h b/src/fsfw/tmtcpacket/SpacePacket.h similarity index 100% rename from tmtcpacket/SpacePacket.h rename to src/fsfw/tmtcpacket/SpacePacket.h diff --git a/tmtcpacket/SpacePacketBase.cpp b/src/fsfw/tmtcpacket/SpacePacketBase.cpp similarity index 97% rename from tmtcpacket/SpacePacketBase.cpp rename to src/fsfw/tmtcpacket/SpacePacketBase.cpp index 14198027d..e9a0b8362 100644 --- a/tmtcpacket/SpacePacketBase.cpp +++ b/src/fsfw/tmtcpacket/SpacePacketBase.cpp @@ -1,5 +1,6 @@ -#include "SpacePacketBase.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/serviceinterface/ServiceInterface.h" + #include SpacePacketBase::SpacePacketBase( const uint8_t* set_address ) { diff --git a/tmtcpacket/SpacePacketBase.h b/src/fsfw/tmtcpacket/SpacePacketBase.h similarity index 100% rename from tmtcpacket/SpacePacketBase.h rename to src/fsfw/tmtcpacket/SpacePacketBase.h diff --git a/tmtcpacket/ccsds_header.h b/src/fsfw/tmtcpacket/ccsds_header.h similarity index 100% rename from tmtcpacket/ccsds_header.h rename to src/fsfw/tmtcpacket/ccsds_header.h diff --git a/tmtcpacket/packetmatcher/ApidMatcher.h b/src/fsfw/tmtcpacket/packetmatcher/ApidMatcher.h similarity index 100% rename from tmtcpacket/packetmatcher/ApidMatcher.h rename to src/fsfw/tmtcpacket/packetmatcher/ApidMatcher.h diff --git a/tmtcpacket/packetmatcher/CMakeLists.txt b/src/fsfw/tmtcpacket/packetmatcher/CMakeLists.txt similarity index 100% rename from tmtcpacket/packetmatcher/CMakeLists.txt rename to src/fsfw/tmtcpacket/packetmatcher/CMakeLists.txt diff --git a/tmtcpacket/packetmatcher/PacketMatchTree.cpp b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp similarity index 96% rename from tmtcpacket/packetmatcher/PacketMatchTree.cpp rename to src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp index 05e176ef2..7f8aae9a5 100644 --- a/tmtcpacket/packetmatcher/PacketMatchTree.cpp +++ b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp @@ -1,7 +1,7 @@ -#include "ApidMatcher.h" -#include "PacketMatchTree.h" -#include "ServiceMatcher.h" -#include "SubserviceMatcher.h" +#include "fsfw/tmtcpacket/packetmatcher/ApidMatcher.h" +#include "fsfw/tmtcpacket/packetmatcher/PacketMatchTree.h" +#include "fsfw/tmtcpacket/packetmatcher/ServiceMatcher.h" +#include "fsfw/tmtcpacket/packetmatcher/SubserviceMatcher.h" // This should be configurable.. const LocalPool::LocalPoolConfig PacketMatchTree::poolConfig = { diff --git a/tmtcpacket/packetmatcher/PacketMatchTree.h b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.h similarity index 86% rename from tmtcpacket/packetmatcher/PacketMatchTree.h rename to src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.h index a40b5099c..e2439c749 100644 --- a/tmtcpacket/packetmatcher/PacketMatchTree.h +++ b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.h @@ -1,10 +1,10 @@ #ifndef FSFW_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_ #define FSFW_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_ -#include "../../container/PlacementFactory.h" -#include "../../globalfunctions/matching/MatchTree.h" -#include "../../storagemanager/LocalPool.h" -#include "../../tmtcpacket/pus/tm/TmPacketMinimal.h" +#include "fsfw/container/PlacementFactory.h" +#include "fsfw/globalfunctions/matching/MatchTree.h" +#include "fsfw/storagemanager/LocalPool.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h" class PacketMatchTree: public MatchTree, public HasReturnvaluesIF { public: diff --git a/tmtcpacket/packetmatcher/ServiceMatcher.h b/src/fsfw/tmtcpacket/packetmatcher/ServiceMatcher.h similarity index 100% rename from tmtcpacket/packetmatcher/ServiceMatcher.h rename to src/fsfw/tmtcpacket/packetmatcher/ServiceMatcher.h diff --git a/tmtcpacket/packetmatcher/SubserviceMatcher.h b/src/fsfw/tmtcpacket/packetmatcher/SubserviceMatcher.h similarity index 100% rename from tmtcpacket/packetmatcher/SubserviceMatcher.h rename to src/fsfw/tmtcpacket/packetmatcher/SubserviceMatcher.h diff --git a/tmtcpacket/pus/CMakeLists.txt b/src/fsfw/tmtcpacket/pus/CMakeLists.txt similarity index 100% rename from tmtcpacket/pus/CMakeLists.txt rename to src/fsfw/tmtcpacket/pus/CMakeLists.txt diff --git a/src/fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h b/src/fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h new file mode 100644 index 000000000..b839223ae --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h @@ -0,0 +1,19 @@ +#ifndef FSFW_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_ +#define FSFW_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_ + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" + +class TmPacketMinimal; + +class PacketTimestampInterpreterIF { +public: + virtual ~PacketTimestampInterpreterIF() {} + virtual ReturnValue_t getPacketTime(TmPacketMinimal* packet, + timeval* timestamp) const = 0; + virtual ReturnValue_t getPacketTimeRaw(TmPacketMinimal* packet, const uint8_t** timePtr, + uint32_t* size) const = 0; +}; + + + +#endif /* FSFW_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_ */ diff --git a/tmtcpacket/pus/tc.h b/src/fsfw/tmtcpacket/pus/tc.h similarity index 100% rename from tmtcpacket/pus/tc.h rename to src/fsfw/tmtcpacket/pus/tc.h diff --git a/tmtcpacket/pus/tc/CMakeLists.txt b/src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt similarity index 100% rename from tmtcpacket/pus/tc/CMakeLists.txt rename to src/fsfw/tmtcpacket/pus/tc/CMakeLists.txt diff --git a/tmtcpacket/pus/tc/TcPacketBase.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketBase.cpp similarity index 66% rename from tmtcpacket/pus/tc/TcPacketBase.cpp rename to src/fsfw/tmtcpacket/pus/tc/TcPacketBase.cpp index dd576fec8..0c7a41830 100644 --- a/tmtcpacket/pus/tc/TcPacketBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketBase.cpp @@ -1,8 +1,8 @@ -#include "TcPacketBase.h" +#include "fsfw/tmtcpacket/pus/tc/TcPacketBase.h" -#include "../../../globalfunctions/CRC.h" -#include "../../../globalfunctions/arrayprinter.h" -#include "../../../serviceinterface/ServiceInterface.h" +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/globalfunctions/arrayprinter.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include diff --git a/tmtcpacket/pus/tc/TcPacketBase.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketBase.h similarity index 99% rename from tmtcpacket/pus/tc/TcPacketBase.h rename to src/fsfw/tmtcpacket/pus/tc/TcPacketBase.h index e28722469..14356c8cd 100644 --- a/tmtcpacket/pus/tc/TcPacketBase.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketBase.h @@ -1,7 +1,7 @@ #ifndef TMTCPACKET_PUS_TCPACKETBASE_H_ #define TMTCPACKET_PUS_TCPACKETBASE_H_ -#include "../../../tmtcpacket/SpacePacketBase.h" +#include "fsfw/tmtcpacket/SpacePacketBase.h" #include /** diff --git a/tmtcpacket/pus/tc/TcPacketPus.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp similarity index 97% rename from tmtcpacket/pus/tc/TcPacketPus.cpp rename to src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp index d2b19206f..28533754d 100644 --- a/tmtcpacket/pus/tc/TcPacketPus.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp @@ -1,5 +1,5 @@ -#include "TcPacketPus.h" -#include "../../../globalfunctions/CRC.h" +#include "fsfw/tmtcpacket/pus/tc/TcPacketPus.h" +#include "fsfw/globalfunctions/CRC.h" #include diff --git a/tmtcpacket/pus/tc/TcPacketPus.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h similarity index 97% rename from tmtcpacket/pus/tc/TcPacketPus.h rename to src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h index 7a28a957d..082541ba2 100644 --- a/tmtcpacket/pus/tc/TcPacketPus.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h @@ -1,8 +1,8 @@ #ifndef FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_ #define FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_ -#include "../../../FSFW.h" -#include "../../ccsds_header.h" +#include "fsfw/FSFW.h" +#include "fsfw/tmtcpacket/ccsds_header.h" #include "TcPacketBase.h" #include diff --git a/tmtcpacket/pus/tc/TcPacketStoredBase.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp similarity index 90% rename from tmtcpacket/pus/tc/TcPacketStoredBase.cpp rename to src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp index cf980e682..98ce1725b 100644 --- a/tmtcpacket/pus/tc/TcPacketStoredBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp @@ -1,8 +1,8 @@ -#include "TcPacketStoredBase.h" +#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h" -#include "../../../objectmanager/ObjectManager.h" -#include "../../../serviceinterface/ServiceInterface.h" -#include "../../../objectmanager/frameworkObjects.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/frameworkObjects.h" #include diff --git a/tmtcpacket/pus/tc/TcPacketStoredBase.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h similarity index 100% rename from tmtcpacket/pus/tc/TcPacketStoredBase.h rename to src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h diff --git a/tmtcpacket/pus/tc/TcPacketStoredIF.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h similarity index 100% rename from tmtcpacket/pus/tc/TcPacketStoredIF.h rename to src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h diff --git a/tmtcpacket/pus/tc/TcPacketStoredPus.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp similarity index 95% rename from tmtcpacket/pus/tc/TcPacketStoredPus.cpp rename to src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp index 426aafdb3..5ea9f5b13 100644 --- a/tmtcpacket/pus/tc/TcPacketStoredPus.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp @@ -1,6 +1,6 @@ -#include "TcPacketStoredPus.h" +#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h" -#include "../../../serviceinterface/ServiceInterface.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include diff --git a/tmtcpacket/pus/tc/TcPacketStoredPus.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h similarity index 100% rename from tmtcpacket/pus/tc/TcPacketStoredPus.h rename to src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h diff --git a/tmtcpacket/pus/tm.h b/src/fsfw/tmtcpacket/pus/tm.h similarity index 92% rename from tmtcpacket/pus/tm.h rename to src/fsfw/tmtcpacket/pus/tm.h index 591ada7c3..afbe8251b 100644 --- a/tmtcpacket/pus/tm.h +++ b/src/fsfw/tmtcpacket/pus/tm.h @@ -1,7 +1,7 @@ #ifndef FSFW_TMTCPACKET_PUS_TM_H_ #define FSFW_TMTCPACKET_PUS_TM_H_ -#include "../../FSFW.h" +#include "fsfw/FSFW.h" #if FSFW_USE_PUS_C_TELEMETRY == 1 #include "tm/TmPacketPusC.h" diff --git a/tmtcpacket/pus/tm/CMakeLists.txt b/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt similarity index 100% rename from tmtcpacket/pus/tm/CMakeLists.txt rename to src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt diff --git a/tmtcpacket/pus/tm/TmPacketBase.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp similarity index 87% rename from tmtcpacket/pus/tm/TmPacketBase.cpp rename to src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp index 3dd1749fe..d448fe5eb 100644 --- a/tmtcpacket/pus/tm/TmPacketBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp @@ -1,10 +1,10 @@ -#include "TmPacketBase.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketBase.h" -#include "../../../globalfunctions/CRC.h" -#include "../../../globalfunctions/arrayprinter.h" -#include "../../../objectmanager/ObjectManager.h" -#include "../../../serviceinterface/ServiceInterface.h" -#include "../../../timemanager/CCSDSTime.h" +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/globalfunctions/arrayprinter.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/timemanager/CCSDSTime.h" #include diff --git a/tmtcpacket/pus/tm/TmPacketBase.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h similarity index 95% rename from tmtcpacket/pus/tm/TmPacketBase.h rename to src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h index 9f534f294..0379b977e 100644 --- a/tmtcpacket/pus/tm/TmPacketBase.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h @@ -1,13 +1,15 @@ #ifndef TMTCPACKET_PUS_TMPACKETBASE_H_ #define TMTCPACKET_PUS_TMPACKETBASE_H_ -#include "../../SpacePacketBase.h" -#include "../../../timemanager/TimeStamperIF.h" -#include "../../../timemanager/Clock.h" -#include "../../../objectmanager/SystemObjectIF.h" +#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/timemanager/TimeStamperIF.h" +#include "fsfw/timemanager/Clock.h" +#include "fsfw/objectmanager/SystemObjectIF.h" + +namespace Factory { -namespace Factory{ void setStaticFrameworkObjectIds(); + } diff --git a/tmtcpacket/pus/tm/TmPacketMinimal.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.cpp similarity index 91% rename from tmtcpacket/pus/tm/TmPacketMinimal.cpp rename to src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.cpp index 3f785cde8..25e159da7 100644 --- a/tmtcpacket/pus/tm/TmPacketMinimal.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.cpp @@ -1,5 +1,5 @@ -#include "TmPacketMinimal.h" -#include "../PacketTimestampInterpreterIF.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h" +#include "fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h" #include #include diff --git a/tmtcpacket/pus/tm/TmPacketMinimal.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h similarity index 100% rename from tmtcpacket/pus/tm/TmPacketMinimal.h rename to src/fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h diff --git a/tmtcpacket/pus/tm/TmPacketPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp similarity index 87% rename from tmtcpacket/pus/tm/TmPacketPusA.cpp rename to src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp index bdc0a815e..c6540af58 100644 --- a/tmtcpacket/pus/tm/TmPacketPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp @@ -1,11 +1,11 @@ -#include "TmPacketPusA.h" -#include "TmPacketBase.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketPusA.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketBase.h" -#include "../../../globalfunctions/CRC.h" -#include "../../../globalfunctions/arrayprinter.h" -#include "../../../objectmanager/ObjectManagerIF.h" -#include "../../../serviceinterface/ServiceInterfaceStream.h" -#include "../../../timemanager/CCSDSTime.h" +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/globalfunctions/arrayprinter.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/timemanager/CCSDSTime.h" #include diff --git a/tmtcpacket/pus/tm/TmPacketPusA.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h similarity index 95% rename from tmtcpacket/pus/tm/TmPacketPusA.h rename to src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h index 49f26b348..3856c7798 100644 --- a/tmtcpacket/pus/tm/TmPacketPusA.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h @@ -2,10 +2,10 @@ #define FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_ #include "TmPacketBase.h" -#include "../../SpacePacketBase.h" -#include "../../../timemanager/TimeStamperIF.h" -#include "../../../timemanager/Clock.h" -#include "../../../objectmanager/SystemObjectIF.h" +#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/timemanager/TimeStamperIF.h" +#include "fsfw/timemanager/Clock.h" +#include "fsfw/objectmanager/SystemObjectIF.h" namespace Factory{ void setStaticFrameworkObjectIds(); diff --git a/tmtcpacket/pus/tm/TmPacketPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp similarity index 87% rename from tmtcpacket/pus/tm/TmPacketPusC.cpp rename to src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp index 5090aaebe..ea25f5d26 100644 --- a/tmtcpacket/pus/tm/TmPacketPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp @@ -1,11 +1,11 @@ -#include "TmPacketPusC.h" -#include "TmPacketBase.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketPusC.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketBase.h" -#include "../../../globalfunctions/CRC.h" -#include "../../../globalfunctions/arrayprinter.h" -#include "../../../objectmanager/ObjectManagerIF.h" -#include "../../../serviceinterface/ServiceInterfaceStream.h" -#include "../../../timemanager/CCSDSTime.h" +#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/globalfunctions/arrayprinter.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/timemanager/CCSDSTime.h" #include diff --git a/tmtcpacket/pus/tm/TmPacketPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h similarity index 95% rename from tmtcpacket/pus/tm/TmPacketPusC.h rename to src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h index 2a6d3bf61..fe373c6fe 100644 --- a/tmtcpacket/pus/tm/TmPacketPusC.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h @@ -2,10 +2,10 @@ #define FSFW_TMTCPACKET_PUS_TMPACKETPUSC_H_ #include "TmPacketBase.h" -#include "../../SpacePacketBase.h" -#include "../../../timemanager/TimeStamperIF.h" -#include "../../../timemanager/Clock.h" -#include "../../../objectmanager/SystemObjectIF.h" +#include "fsfw/tmtcpacket/SpacePacketBase.h" +#include "fsfw/timemanager/TimeStamperIF.h" +#include "fsfw/timemanager/Clock.h" +#include "fsfw/objectmanager/SystemObjectIF.h" namespace Factory{ void setStaticFrameworkObjectIds(); diff --git a/tmtcpacket/pus/tm/TmPacketStored.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStored.h similarity index 100% rename from tmtcpacket/pus/tm/TmPacketStored.h rename to src/fsfw/tmtcpacket/pus/tm/TmPacketStored.h diff --git a/tmtcpacket/pus/tm/TmPacketStoredBase.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp similarity index 93% rename from tmtcpacket/pus/tm/TmPacketStoredBase.cpp rename to src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp index ba8b15d1a..466e4cd20 100644 --- a/tmtcpacket/pus/tm/TmPacketStoredBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp @@ -1,8 +1,8 @@ -#include "TmPacketStoredBase.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h" -#include "../../../objectmanager/ObjectManager.h" -#include "../../../serviceinterface/ServiceInterface.h" -#include "../../../tmtcservices/TmTcMessage.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tmtcservices/TmTcMessage.h" #include diff --git a/tmtcpacket/pus/tm/TmPacketStoredBase.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h similarity index 92% rename from tmtcpacket/pus/tm/TmPacketStoredBase.h rename to src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h index 1bc092dd7..8e8b9c70b 100644 --- a/tmtcpacket/pus/tm/TmPacketStoredBase.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h @@ -1,15 +1,15 @@ #ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_ #define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_ -#include "../../../FSFW.h" +#include "fsfw/FSFW.h" #include "TmPacketBase.h" #include "TmPacketStoredBase.h" #include "TmPacketPusA.h" -#include "../../../serialize/SerializeIF.h" -#include "../../../storagemanager/StorageManagerIF.h" -#include "../../../internalError/InternalErrorReporterIF.h" -#include "../../../ipc/MessageQueueSenderIF.h" +#include "fsfw/serialize/SerializeIF.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/internalerror/InternalErrorReporterIF.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" /** * This class generates a ECSS PUS Telemetry packet within a given diff --git a/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp similarity index 94% rename from tmtcpacket/pus/tm/TmPacketStoredPusA.cpp rename to src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp index 02fb77ef5..538dc95e8 100644 --- a/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp @@ -1,7 +1,7 @@ -#include "TmPacketStoredPusA.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h" -#include "../../../serviceinterface/ServiceInterface.h" -#include "../../../tmtcservices/TmTcMessage.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tmtcservices/TmTcMessage.h" #include diff --git a/tmtcpacket/pus/tm/TmPacketStoredPusA.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h similarity index 100% rename from tmtcpacket/pus/tm/TmPacketStoredPusA.h rename to src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h diff --git a/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp similarity index 94% rename from tmtcpacket/pus/tm/TmPacketStoredPusC.cpp rename to src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp index 6f8f7fa26..add4f4b9f 100644 --- a/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp @@ -1,7 +1,7 @@ -#include "TmPacketStoredPusC.h" +#include "fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h" -#include "../../../serviceinterface/ServiceInterface.h" -#include "../../../tmtcservices/TmTcMessage.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tmtcservices/TmTcMessage.h" #include diff --git a/tmtcpacket/pus/tm/TmPacketStoredPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h similarity index 100% rename from tmtcpacket/pus/tm/TmPacketStoredPusC.h rename to src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h diff --git a/tmtcservices/AcceptsTelecommandsIF.h b/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h similarity index 100% rename from tmtcservices/AcceptsTelecommandsIF.h rename to src/fsfw/tmtcservices/AcceptsTelecommandsIF.h diff --git a/tmtcservices/AcceptsTelemetryIF.h b/src/fsfw/tmtcservices/AcceptsTelemetryIF.h similarity index 100% rename from tmtcservices/AcceptsTelemetryIF.h rename to src/fsfw/tmtcservices/AcceptsTelemetryIF.h diff --git a/tmtcservices/AcceptsVerifyMessageIF.h b/src/fsfw/tmtcservices/AcceptsVerifyMessageIF.h similarity index 100% rename from tmtcservices/AcceptsVerifyMessageIF.h rename to src/fsfw/tmtcservices/AcceptsVerifyMessageIF.h diff --git a/tmtcservices/CMakeLists.txt b/src/fsfw/tmtcservices/CMakeLists.txt similarity index 100% rename from tmtcservices/CMakeLists.txt rename to src/fsfw/tmtcservices/CMakeLists.txt diff --git a/tmtcservices/CommandingServiceBase.cpp b/src/fsfw/tmtcservices/CommandingServiceBase.cpp similarity index 97% rename from tmtcservices/CommandingServiceBase.cpp rename to src/fsfw/tmtcservices/CommandingServiceBase.cpp index 307a2a982..10805b473 100644 --- a/tmtcservices/CommandingServiceBase.cpp +++ b/src/fsfw/tmtcservices/CommandingServiceBase.cpp @@ -1,14 +1,13 @@ -#include "AcceptsTelemetryIF.h" -#include "CommandingServiceBase.h" -#include "TmTcMessage.h" -#include +#include "fsfw/tmtcservices/CommandingServiceBase.h" +#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" +#include "fsfw/tmtcservices/TmTcMessage.h" -#include "../tcdistribution/PUSDistributorIF.h" -#include "../objectmanager/ObjectManager.h" -#include "../ipc/QueueFactory.h" -#include "../tmtcpacket/pus/tc.h" -#include "../tmtcpacket/pus/tm.h" -#include "../serviceinterface/ServiceInterface.h" +#include "fsfw/tcdistribution/PUSDistributorIF.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/tmtcpacket/pus/tc.h" +#include "fsfw/tmtcpacket/pus/tm.h" +#include "fsfw/serviceinterface/ServiceInterface.h" object_id_t CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; object_id_t CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; diff --git a/tmtcservices/CommandingServiceBase.h b/src/fsfw/tmtcservices/CommandingServiceBase.h similarity index 97% rename from tmtcservices/CommandingServiceBase.h rename to src/fsfw/tmtcservices/CommandingServiceBase.h index 4ee4a21a5..b6709693e 100644 --- a/tmtcservices/CommandingServiceBase.h +++ b/src/fsfw/tmtcservices/CommandingServiceBase.h @@ -3,17 +3,16 @@ #include "AcceptsTelecommandsIF.h" #include "VerificationReporter.h" +#include "fsfw/FSFW.h" -#include "../objectmanager/SystemObject.h" -#include "../storagemanager/StorageManagerIF.h" -#include "../tasks/ExecutableObjectIF.h" -#include "../ipc/MessageQueueIF.h" -#include "../ipc/CommandMessage.h" -#include "../container/FixedMap.h" -#include "../container/FIFO.h" -#include "../serialize/SerializeIF.h" - -#include +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/CommandMessage.h" +#include "fsfw/container/FixedMap.h" +#include "fsfw/container/FIFO.h" +#include "fsfw/serialize/SerializeIF.h" class TcPacketStored; class TcPacketStoredBase; diff --git a/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp similarity index 91% rename from tmtcservices/PusServiceBase.cpp rename to src/fsfw/tmtcservices/PusServiceBase.cpp index 811c9bcb6..866e0844a 100644 --- a/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -1,12 +1,12 @@ -#include "PusServiceBase.h" -#include "AcceptsTelemetryIF.h" -#include "PusVerificationReport.h" -#include "TmTcMessage.h" +#include "fsfw/tmtcservices/PusServiceBase.h" +#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" +#include "fsfw/tmtcservices/PusVerificationReport.h" +#include "fsfw/tmtcservices/TmTcMessage.h" -#include "../objectmanager/ObjectManager.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../tcdistribution/PUSDistributorIF.h" -#include "../ipc/QueueFactory.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/tcdistribution/PUSDistributorIF.h" +#include "fsfw/ipc/QueueFactory.h" object_id_t PusServiceBase::packetSource = 0; object_id_t PusServiceBase::packetDestination = 0; diff --git a/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h similarity index 95% rename from tmtcservices/PusServiceBase.h rename to src/fsfw/tmtcservices/PusServiceBase.h index 6cde6fb49..ea4147fe8 100644 --- a/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -5,12 +5,12 @@ #include "VerificationCodes.h" #include "VerificationReporter.h" -#include "../objectmanager/ObjectManagerIF.h" -#include "../objectmanager/SystemObject.h" -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../tasks/ExecutableObjectIF.h" -#include "../tmtcpacket/pus/tc.h" -#include "../ipc/MessageQueueIF.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/tmtcpacket/pus/tc.h" +#include "fsfw/ipc/MessageQueueIF.h" namespace Factory{ void setStaticFrameworkObjectIds(); diff --git a/tmtcservices/PusVerificationReport.cpp b/src/fsfw/tmtcservices/PusVerificationReport.cpp similarity index 97% rename from tmtcservices/PusVerificationReport.cpp rename to src/fsfw/tmtcservices/PusVerificationReport.cpp index c64e5feb3..827486cea 100644 --- a/tmtcservices/PusVerificationReport.cpp +++ b/src/fsfw/tmtcservices/PusVerificationReport.cpp @@ -1,5 +1,5 @@ -#include "../serialize/SerializeAdapter.h" -#include "../tmtcservices/PusVerificationReport.h" +#include "fsfw/serialize/SerializeAdapter.h" +#include "fsfw/tmtcservices/PusVerificationReport.h" PusVerificationMessage::PusVerificationMessage() { } diff --git a/tmtcservices/PusVerificationReport.h b/src/fsfw/tmtcservices/PusVerificationReport.h similarity index 93% rename from tmtcservices/PusVerificationReport.h rename to src/fsfw/tmtcservices/PusVerificationReport.h index 0e1732efc..c22ba535e 100644 --- a/tmtcservices/PusVerificationReport.h +++ b/src/fsfw/tmtcservices/PusVerificationReport.h @@ -3,9 +3,9 @@ #include "VerificationCodes.h" -#include "../ipc/MessageQueueMessage.h" -#include "../tmtcpacket/pus/tc/TcPacketBase.h" -#include "../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/ipc/MessageQueueMessage.h" +#include "fsfw/tmtcpacket/pus/tc/TcPacketBase.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" class PusVerificationMessage: public MessageQueueMessage { private: diff --git a/tmtcservices/SourceSequenceCounter.h b/src/fsfw/tmtcservices/SourceSequenceCounter.h similarity index 100% rename from tmtcservices/SourceSequenceCounter.h rename to src/fsfw/tmtcservices/SourceSequenceCounter.h diff --git a/tmtcservices/TmTcBridge.cpp b/src/fsfw/tmtcservices/TmTcBridge.cpp similarity index 97% rename from tmtcservices/TmTcBridge.cpp rename to src/fsfw/tmtcservices/TmTcBridge.cpp index 7198bc765..7346cfe2a 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/src/fsfw/tmtcservices/TmTcBridge.cpp @@ -1,9 +1,9 @@ -#include "TmTcBridge.h" +#include "fsfw/tmtcservices/TmTcBridge.h" -#include "../objectmanager/ObjectManager.h" -#include "../ipc/QueueFactory.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../globalfunctions/arrayprinter.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/ipc/QueueFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/globalfunctions/arrayprinter.h" #define TMTCBRIDGE_WIRETAPPING 0 diff --git a/tmtcservices/TmTcBridge.h b/src/fsfw/tmtcservices/TmTcBridge.h similarity index 93% rename from tmtcservices/TmTcBridge.h rename to src/fsfw/tmtcservices/TmTcBridge.h index d3e1c5471..4980caff9 100644 --- a/tmtcservices/TmTcBridge.h +++ b/src/fsfw/tmtcservices/TmTcBridge.h @@ -4,12 +4,12 @@ #include "AcceptsTelemetryIF.h" #include "AcceptsTelecommandsIF.h" -#include "../objectmanager/SystemObject.h" -#include "../tasks/ExecutableObjectIF.h" -#include "../ipc/MessageQueueIF.h" -#include "../storagemanager/StorageManagerIF.h" -#include "../container/DynamicFIFO.h" -#include "../tmtcservices/TmTcMessage.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/container/DynamicFIFO.h" +#include "fsfw/tmtcservices/TmTcMessage.h" class TmTcBridge : public AcceptsTelemetryIF, public AcceptsTelecommandsIF, @@ -19,7 +19,7 @@ class TmTcBridge : public AcceptsTelemetryIF, public: static constexpr uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20; static constexpr uint8_t LIMIT_STORED_DATA_SENT_PER_CYCLE = 15; - static constexpr uint8_t LIMIT_DOWNLINK_PACKETS_STORED = 20; + static constexpr uint8_t LIMIT_DOWNLINK_PACKETS_STORED = 200; static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5; static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10; diff --git a/tmtcservices/TmTcMessage.cpp b/src/fsfw/tmtcservices/TmTcMessage.cpp similarity index 93% rename from tmtcservices/TmTcMessage.cpp rename to src/fsfw/tmtcservices/TmTcMessage.cpp index c0f32aaac..9dbd8fd83 100644 --- a/tmtcservices/TmTcMessage.cpp +++ b/src/fsfw/tmtcservices/TmTcMessage.cpp @@ -1,4 +1,4 @@ -#include "TmTcMessage.h" +#include "fsfw/tmtcservices/TmTcMessage.h" #include diff --git a/tmtcservices/TmTcMessage.h b/src/fsfw/tmtcservices/TmTcMessage.h similarity index 94% rename from tmtcservices/TmTcMessage.h rename to src/fsfw/tmtcservices/TmTcMessage.h index 7d2a7bdb6..5e6647fe8 100644 --- a/tmtcservices/TmTcMessage.h +++ b/src/fsfw/tmtcservices/TmTcMessage.h @@ -1,8 +1,8 @@ #ifndef FSFW_TMTCSERVICES_TMTCMESSAGE_H_ #define FSFW_TMTCSERVICES_TMTCMESSAGE_H_ -#include "../ipc/MessageQueueMessage.h" -#include "../storagemanager/StorageManagerIF.h" +#include "fsfw/ipc/MessageQueueMessage.h" +#include "fsfw/storagemanager/StorageManagerIF.h" /** * @brief This message class is used to pass Telecommand and Telemetry * packets between tasks. diff --git a/tmtcservices/VerificationCodes.h b/src/fsfw/tmtcservices/VerificationCodes.h similarity index 100% rename from tmtcservices/VerificationCodes.h rename to src/fsfw/tmtcservices/VerificationCodes.h diff --git a/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp similarity index 92% rename from tmtcservices/VerificationReporter.cpp rename to src/fsfw/tmtcservices/VerificationReporter.cpp index 74e0719c8..2b371d1e7 100644 --- a/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -1,11 +1,11 @@ -#include "VerificationReporter.h" -#include "AcceptsVerifyMessageIF.h" -#include "PusVerificationReport.h" +#include "fsfw/tmtcservices/VerificationReporter.h" +#include "fsfw/tmtcservices/AcceptsVerifyMessageIF.h" +#include "fsfw/tmtcservices/PusVerificationReport.h" -#include "../objectmanager/ObjectManager.h" -#include "../ipc/MessageQueueIF.h" -#include "../serviceinterface/ServiceInterface.h" -#include "../objectmanager/frameworkObjects.h" +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/objectmanager/frameworkObjects.h" object_id_t VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; diff --git a/tmtcservices/VerificationReporter.h b/src/fsfw/tmtcservices/VerificationReporter.h similarity index 97% rename from tmtcservices/VerificationReporter.h rename to src/fsfw/tmtcservices/VerificationReporter.h index f26fa54f5..4a64d3df1 100644 --- a/tmtcservices/VerificationReporter.h +++ b/src/fsfw/tmtcservices/VerificationReporter.h @@ -2,7 +2,7 @@ #define FSFW_TMTCSERVICES_VERIFICATIONREPORTER_H_ #include "PusVerificationReport.h" -#include "../objectmanager/ObjectManagerIF.h" +#include "fsfw/objectmanager/ObjectManagerIF.h" namespace Factory{ void setStaticFrameworkObjectIds(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..febd4f0ab --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(src) diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt new file mode 100644 index 000000000..6673f1e41 --- /dev/null +++ b/tests/src/CMakeLists.txt @@ -0,0 +1,9 @@ +target_include_directories(${LIB_FSFW_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_include_directories(${LIB_FSFW_NAME} INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_subdirectory(fsfw_tests) diff --git a/tests/src/fsfw_tests/CMakeLists.txt b/tests/src/fsfw_tests/CMakeLists.txt new file mode 100644 index 000000000..e4a6be80c --- /dev/null +++ b/tests/src/fsfw_tests/CMakeLists.txt @@ -0,0 +1,8 @@ + +if(FSFW_ADD_INTERNAL_TESTS) + add_subdirectory(internal) +endif() + +if(FSFW_ADD_UNITTESTS) + add_subdirectory(unit) +endif() diff --git a/unittest/internal/CMakeLists.txt b/tests/src/fsfw_tests/internal/CMakeLists.txt similarity index 57% rename from unittest/internal/CMakeLists.txt rename to tests/src/fsfw_tests/internal/CMakeLists.txt index 11fd2b2ff..2a144a9be 100644 --- a/unittest/internal/CMakeLists.txt +++ b/tests/src/fsfw_tests/internal/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${LIB_FSFW_NAME} PRIVATE InternalUnitTester.cpp UnittDefinitions.cpp ) diff --git a/tests/src/fsfw_tests/internal/InternalUnitTester.cpp b/tests/src/fsfw_tests/internal/InternalUnitTester.cpp new file mode 100644 index 000000000..20998d64d --- /dev/null +++ b/tests/src/fsfw_tests/internal/InternalUnitTester.cpp @@ -0,0 +1,45 @@ +#include "fsfw_tests/internal/InternalUnitTester.h" +#include "fsfw_tests/internal/UnittDefinitions.h" + +#include "fsfw_tests/internal/osal/IntTestMq.h" +#include "fsfw_tests/internal/osal/IntTestSemaphore.h" +#include "fsfw_tests/internal/osal/IntTestMutex.h" +#include "fsfw_tests/internal/serialize/IntTestSerialization.h" +#include "fsfw_tests/internal/globalfunctions/TestArrayPrinter.h" + +#include + +InternalUnitTester::InternalUnitTester() {} + +InternalUnitTester::~InternalUnitTester() {} + +ReturnValue_t InternalUnitTester::performTests( + const struct InternalUnitTester::TestConfig& testConfig) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Running internal unit tests.. Error messages might follow" << + std::endl; +#else + sif::printInfo("Running internal unit tests..\n"); +#endif + + testserialize::test_serialization(); + testmq::testMq(); + if(testConfig.testSemaphores) { + testsemaph::testBinSemaph(); + testsemaph::testCountingSemaph(); + } + testmutex::testMutex(); + if(testConfig.testArrayPrinter) { + arrayprinter::testArrayPrinter(); + } + +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Internal unit tests finished." << std::endl; +#else + sif::printInfo("Internal unit tests finished.\n"); +#endif + return RETURN_OK; +} + + + diff --git a/unittest/internal/InternalUnitTester.h b/tests/src/fsfw_tests/internal/InternalUnitTester.h similarity index 77% rename from unittest/internal/InternalUnitTester.h rename to tests/src/fsfw_tests/internal/InternalUnitTester.h index ae954c6ac..433a0f1f8 100644 --- a/unittest/internal/InternalUnitTester.h +++ b/tests/src/fsfw_tests/internal/InternalUnitTester.h @@ -2,7 +2,7 @@ #define FRAMEWORK_TEST_UNITTESTCLASS_H_ #include "UnittDefinitions.h" -#include "../../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" /** @@ -17,7 +17,8 @@ class InternalUnitTester: public HasReturnvaluesIF { public: struct TestConfig { - bool testArrayPrinter; + bool testArrayPrinter = false; + bool testSemaphores = true; }; InternalUnitTester(); @@ -27,7 +28,7 @@ public: * Some function which calls all other tests * @return */ - virtual ReturnValue_t performTests(struct InternalUnitTester::TestConfig& testConfig); + virtual ReturnValue_t performTests(const struct InternalUnitTester::TestConfig& testConfig); }; diff --git a/unittest/internal/UnittDefinitions.cpp b/tests/src/fsfw_tests/internal/UnittDefinitions.cpp similarity index 87% rename from unittest/internal/UnittDefinitions.cpp rename to tests/src/fsfw_tests/internal/UnittDefinitions.cpp index ed4b59c1c..7f754a0a4 100644 --- a/unittest/internal/UnittDefinitions.cpp +++ b/tests/src/fsfw_tests/internal/UnittDefinitions.cpp @@ -1,4 +1,4 @@ -#include "UnittDefinitions.h" +#include "fsfw_tests/internal/UnittDefinitions.h" ReturnValue_t unitt::put_error(std::string errorId) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/unittest/internal/UnittDefinitions.h b/tests/src/fsfw_tests/internal/UnittDefinitions.h similarity index 88% rename from unittest/internal/UnittDefinitions.h rename to tests/src/fsfw_tests/internal/UnittDefinitions.h index 3e14fec57..7e7e06a6f 100644 --- a/unittest/internal/UnittDefinitions.h +++ b/tests/src/fsfw_tests/internal/UnittDefinitions.h @@ -1,8 +1,9 @@ #ifndef UNITTEST_INTERNAL_UNITTDEFINITIONS_H_ #define UNITTEST_INTERNAL_UNITTDEFINITIONS_H_ -#include "../../returnvalues/HasReturnvaluesIF.h" -#include "../../serviceinterface/ServiceInterface.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" + #include #include #include diff --git a/tests/src/fsfw_tests/internal/globalfunctions/CMakeLists.txt b/tests/src/fsfw_tests/internal/globalfunctions/CMakeLists.txt new file mode 100644 index 000000000..cde97734f --- /dev/null +++ b/tests/src/fsfw_tests/internal/globalfunctions/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + TestArrayPrinter.cpp +) diff --git a/unittest/internal/globalfunctions/TestArrayPrinter.cpp b/tests/src/fsfw_tests/internal/globalfunctions/TestArrayPrinter.cpp similarity index 94% rename from unittest/internal/globalfunctions/TestArrayPrinter.cpp rename to tests/src/fsfw_tests/internal/globalfunctions/TestArrayPrinter.cpp index de016d198..b43113433 100644 --- a/unittest/internal/globalfunctions/TestArrayPrinter.cpp +++ b/tests/src/fsfw_tests/internal/globalfunctions/TestArrayPrinter.cpp @@ -1,4 +1,4 @@ -#include "TestArrayPrinter.h" +#include "fsfw_tests/internal/globalfunctions/TestArrayPrinter.h" void arrayprinter::testArrayPrinter() { { diff --git a/unittest/internal/globalfunctions/TestArrayPrinter.h b/tests/src/fsfw_tests/internal/globalfunctions/TestArrayPrinter.h similarity index 100% rename from unittest/internal/globalfunctions/TestArrayPrinter.h rename to tests/src/fsfw_tests/internal/globalfunctions/TestArrayPrinter.h diff --git a/unittest/internal/osal/CMakeLists.txt b/tests/src/fsfw_tests/internal/osal/CMakeLists.txt similarity index 58% rename from unittest/internal/osal/CMakeLists.txt rename to tests/src/fsfw_tests/internal/osal/CMakeLists.txt index c6f1eb95c..843160891 100644 --- a/unittest/internal/osal/CMakeLists.txt +++ b/tests/src/fsfw_tests/internal/osal/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(${TARGET_NAME} PRIVATE +target_sources(${LIB_FSFW_NAME} PRIVATE IntTestMq.cpp IntTestMutex.cpp IntTestSemaphore.cpp diff --git a/unittest/internal/osal/IntTestMq.cpp b/tests/src/fsfw_tests/internal/osal/IntTestMq.cpp similarity index 93% rename from unittest/internal/osal/IntTestMq.cpp rename to tests/src/fsfw_tests/internal/osal/IntTestMq.cpp index fc8e963ef..6c31b3541 100644 --- a/unittest/internal/osal/IntTestMq.cpp +++ b/tests/src/fsfw_tests/internal/osal/IntTestMq.cpp @@ -1,5 +1,5 @@ -#include "IntTestMq.h" -#include +#include "fsfw_tests/internal/osal/IntTestMq.h" +#include "fsfw_tests/internal/UnittDefinitions.h" #include #include @@ -49,5 +49,4 @@ void testmq::testMq() { if(senderId != testSenderMqId) { unitt::put_error(id); } - } diff --git a/unittest/internal/osal/IntTestMq.h b/tests/src/fsfw_tests/internal/osal/IntTestMq.h similarity index 100% rename from unittest/internal/osal/IntTestMq.h rename to tests/src/fsfw_tests/internal/osal/IntTestMq.h diff --git a/unittest/internal/osal/IntTestMutex.cpp b/tests/src/fsfw_tests/internal/osal/IntTestMutex.cpp similarity index 78% rename from unittest/internal/osal/IntTestMutex.cpp rename to tests/src/fsfw_tests/internal/osal/IntTestMutex.cpp index 13d87a8b0..d9184cd83 100644 --- a/unittest/internal/osal/IntTestMutex.cpp +++ b/tests/src/fsfw_tests/internal/osal/IntTestMutex.cpp @@ -1,10 +1,12 @@ -#include "IntTestMutex.h" +#include "fsfw_tests/internal/osal/IntTestMutex.h" +#include "fsfw_tests/internal/UnittDefinitions.h" +#include "fsfw/platform.h" #include -#include -#if defined(WIN32) || defined(UNIX) -#include +#if defined PLATFORM_WIN || defined PLATFORM_UNIX +#include "fsfw/osal/host/Mutex.h" + #include #include #endif @@ -20,7 +22,7 @@ void testmutex::testMutex() { // timed_mutex from the C++ library specifies undefined behaviour if // the timed mutex is locked twice from the same thread. // TODO: we should pass a define like FSFW_OSAL_HOST to the build. -#if defined(WIN32) || defined(UNIX) +#if defined PLATFORM_WIN || defined PLATFORM_UNIX // This calls the function from // another thread and stores the returnvalue in a future. auto future = std::async(&MutexIF::lockMutex, mutex, MutexIF::TimeoutType::WAITING, 1); @@ -37,8 +39,7 @@ void testmutex::testMutex() { unitt::put_error(id); } - // TODO: we should pass a define like FSFW_OSAL_HOST to the build. -#if !defined(WIN32) && !defined(UNIX) +#if !defined PLATFORM_WIN && !defined PLATFORM_UNIX result = mutex->unlockMutex(); if(result != MutexIF::CURR_THREAD_DOES_NOT_OWN_MUTEX) { unitt::put_error(id); diff --git a/unittest/internal/osal/IntTestMutex.h b/tests/src/fsfw_tests/internal/osal/IntTestMutex.h similarity index 100% rename from unittest/internal/osal/IntTestMutex.h rename to tests/src/fsfw_tests/internal/osal/IntTestMutex.h diff --git a/unittest/internal/osal/IntTestSemaphore.cpp b/tests/src/fsfw_tests/internal/osal/IntTestSemaphore.cpp similarity index 92% rename from unittest/internal/osal/IntTestSemaphore.cpp rename to tests/src/fsfw_tests/internal/osal/IntTestSemaphore.cpp index 43990c2cd..4b28f961b 100644 --- a/unittest/internal/osal/IntTestSemaphore.cpp +++ b/tests/src/fsfw_tests/internal/osal/IntTestSemaphore.cpp @@ -1,9 +1,10 @@ -#include "IntTestSemaphore.h" -#include +#include "fsfw/FSFW.h" +#include "fsfw_tests/internal/osal/IntTestSemaphore.h" +#include "fsfw_tests/internal/UnittDefinitions.h" -#include -#include -#include +#include "fsfw/tasks/SemaphoreFactory.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/timemanager/Stopwatch.h" #include @@ -16,7 +17,7 @@ void testsemaph::testBinSemaph() { } testBinSemaphoreImplementation(binSemaph, id); SemaphoreFactory::instance()->deleteSemaphore(binSemaph); -#if defined(freeRTOS) +#if defined FSFW_OSAL_FREERTOS SemaphoreIF* binSemaphUsingTask = SemaphoreFactory::instance()->createBinarySemaphore(1); testBinSemaphoreImplementation(binSemaphUsingTask, id); @@ -36,7 +37,7 @@ void testsemaph::testCountingSemaph() { } testBinSemaphoreImplementation(countingSemaph, id); SemaphoreFactory::instance()->deleteSemaphore(countingSemaph); -#if defined(freeRTOS) +#if defined FSFW_OSAL_FREERTOS countingSemaph = SemaphoreFactory::instance()-> createCountingSemaphore(1, 1, 1); testBinSemaphoreImplementation(countingSemaph, id); @@ -50,7 +51,7 @@ void testsemaph::testCountingSemaph() { createCountingSemaphore(3,3); testCountingSemaphImplementation(countingSemaph, id); SemaphoreFactory::instance()->deleteSemaphore(countingSemaph); -#if defined(freeRTOS) +#if defined FSFW_OSAL_FREERTOS countingSemaph = SemaphoreFactory::instance()-> createCountingSemaphore(3, 0, 1); uint8_t semaphCount = countingSemaph->getSemaphoreCounter(); diff --git a/unittest/internal/osal/IntTestSemaphore.h b/tests/src/fsfw_tests/internal/osal/IntTestSemaphore.h similarity index 100% rename from unittest/internal/osal/IntTestSemaphore.h rename to tests/src/fsfw_tests/internal/osal/IntTestSemaphore.h diff --git a/tests/src/fsfw_tests/internal/serialize/CMakeLists.txt b/tests/src/fsfw_tests/internal/serialize/CMakeLists.txt new file mode 100644 index 000000000..47e8b538e --- /dev/null +++ b/tests/src/fsfw_tests/internal/serialize/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + IntTestSerialization.cpp +) diff --git a/unittest/internal/serialize/IntTestSerialization.cpp b/tests/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp similarity index 98% rename from unittest/internal/serialize/IntTestSerialization.cpp rename to tests/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp index 69d82942e..4720f706c 100644 --- a/unittest/internal/serialize/IntTestSerialization.cpp +++ b/tests/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp @@ -1,5 +1,5 @@ -#include "IntTestSerialization.h" -#include +#include "fsfw_tests/internal/serialize/IntTestSerialization.h" +#include "fsfw_tests/internal/UnittDefinitions.h" #include #include diff --git a/unittest/internal/serialize/IntTestSerialization.h b/tests/src/fsfw_tests/internal/serialize/IntTestSerialization.h similarity index 88% rename from unittest/internal/serialize/IntTestSerialization.h rename to tests/src/fsfw_tests/internal/serialize/IntTestSerialization.h index 8706e0572..0767fb446 100644 --- a/unittest/internal/serialize/IntTestSerialization.h +++ b/tests/src/fsfw_tests/internal/serialize/IntTestSerialization.h @@ -1,7 +1,7 @@ #ifndef FSFW_UNITTEST_INTERNAL_INTTESTSERIALIZATION_H_ #define FSFW_UNITTEST_INTERNAL_INTTESTSERIALIZATION_H_ -#include "../../../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include namespace testserialize { diff --git a/tests/src/fsfw_tests/unit/CMakeLists.txt b/tests/src/fsfw_tests/unit/CMakeLists.txt new file mode 100644 index 000000000..f30e4b6bf --- /dev/null +++ b/tests/src/fsfw_tests/unit/CMakeLists.txt @@ -0,0 +1,22 @@ +target_sources(${TARGET_NAME} PRIVATE + CatchDefinitions.cpp + CatchFactory.cpp + printChar.cpp +) + +if(FSFW_CUSTOM_UNITTEST_RUNNER) + target_sources(${TARGET_NAME} PRIVATE + CatchRunner.cpp + CatchSetup.cpp + ) +endif() + +add_subdirectory(action) +add_subdirectory(container) +add_subdirectory(osal) +add_subdirectory(serialize) +add_subdirectory(datapoollocal) +add_subdirectory(storagemanager) +add_subdirectory(globalfunctions) +add_subdirectory(timemanager) +add_subdirectory(tmtcpacket) diff --git a/unittest/user/unittest/core/CatchDefinitions.cpp b/tests/src/fsfw_tests/unit/CatchDefinitions.cpp similarity index 100% rename from unittest/user/unittest/core/CatchDefinitions.cpp rename to tests/src/fsfw_tests/unit/CatchDefinitions.cpp diff --git a/unittest/user/unittest/core/CatchDefinitions.h b/tests/src/fsfw_tests/unit/CatchDefinitions.h similarity index 100% rename from unittest/user/unittest/core/CatchDefinitions.h rename to tests/src/fsfw_tests/unit/CatchDefinitions.h diff --git a/unittest/user/unittest/core/CatchFactory.cpp b/tests/src/fsfw_tests/unit/CatchFactory.cpp similarity index 89% rename from unittest/user/unittest/core/CatchFactory.cpp rename to tests/src/fsfw_tests/unit/CatchFactory.cpp index 9afb4fdd4..010ab5ddd 100644 --- a/unittest/user/unittest/core/CatchFactory.cpp +++ b/tests/src/fsfw_tests/unit/CatchFactory.cpp @@ -1,17 +1,21 @@ #include "CatchFactory.h" +#include "datapoollocal/LocalPoolOwnerBase.h" +#include "mocks/HkReceiverMock.h" + #include #include #include #include -#include +#include #include #include -#include +#include #include #include -#include -#include + + +#if FSFW_ADD_DEFAULT_FACTORY_FUNCTIONS == 1 /** * @brief Produces system objects. @@ -26,7 +30,7 @@ * * @ingroup init */ -void Factory::produce(void) { +void Factory::produceFrameworkObjects(void* args) { setStaticFrameworkObjectIds(); new EventManager(objects::EVENT_MANAGER); new HealthTable(objects::HEALTH_TABLE); @@ -55,7 +59,6 @@ void Factory::produce(void) { }; new PoolManager(objects::IPC_STORE, poolCfg); } - } void Factory::setStaticFrameworkObjectIds() { @@ -77,5 +80,4 @@ void Factory::setStaticFrameworkObjectIds() { TmPacketBase::timeStamperId = objects::NO_OBJECT; } - - +#endif diff --git a/tests/src/fsfw_tests/unit/CatchFactory.h b/tests/src/fsfw_tests/unit/CatchFactory.h new file mode 100644 index 000000000..38ec46bd0 --- /dev/null +++ b/tests/src/fsfw_tests/unit/CatchFactory.h @@ -0,0 +1,24 @@ +#ifndef FSFW_CATCHFACTORY_H_ +#define FSFW_CATCHFACTORY_H_ + +#include "TestsConfig.h" +#include "fsfw/objectmanager/SystemObjectIF.h" +#include "fsfw/objectmanager/ObjectManager.h" + +// TODO: It is possible to solve this more cleanly using a special class which +// is allowed to set the object IDs and has virtual functions. +#if FSFW_ADD_DEFAULT_FACTORY_FUNCTIONS == 1 + +namespace Factory { + /** + * @brief Creates all SystemObject elements which are persistent + * during execution. + */ + void produceFrameworkObjects(void* args); + void setStaticFrameworkObjectIds(); + +} + +#endif /* FSFW_ADD_DEFAULT_FSFW_FACTORY == 1 */ + +#endif /* FSFW_CATCHFACTORY_H_ */ diff --git a/unittest/user/unittest/core/CatchRunner.cpp b/tests/src/fsfw_tests/unit/CatchRunner.cpp similarity index 78% rename from unittest/user/unittest/core/CatchRunner.cpp rename to tests/src/fsfw_tests/unit/CatchRunner.cpp index 886d641f3..c96db7f41 100644 --- a/unittest/user/unittest/core/CatchRunner.cpp +++ b/tests/src/fsfw_tests/unit/CatchRunner.cpp @@ -6,7 +6,7 @@ * from the eclipse market place to get colored characters. */ -#include +#include "CatchRunner.h" #define CATCH_CONFIG_COLOUR_WINDOWS @@ -14,11 +14,11 @@ extern int customSetup(); -int main( int argc, char* argv[] ) { +int fsfwtest::customMain(int argc, char* argv[]) { customSetup(); // Catch internal function call - int result = Catch::Session().run( argc, argv ); + int result = Catch::Session().run(argc, argv); // global clean-up return result; diff --git a/tests/src/fsfw_tests/unit/CatchRunner.h b/tests/src/fsfw_tests/unit/CatchRunner.h new file mode 100644 index 000000000..720625c63 --- /dev/null +++ b/tests/src/fsfw_tests/unit/CatchRunner.h @@ -0,0 +1,14 @@ +#ifndef FSFW_TESTS_USER_UNITTEST_CORE_CATCHRUNNER_H_ +#define FSFW_TESTS_USER_UNITTEST_CORE_CATCHRUNNER_H_ + +namespace fsfwtest { + +/** + * Can be called by upper level main() if default Catch2 main is overriden + * @return + */ +int customMain(int argc, char* argv[]); + +} + +#endif /* FSFW_TESTS_USER_UNITTEST_CORE_CATCHRUNNER_H_ */ diff --git a/unittest/user/unittest/core/CatchSetup.cpp b/tests/src/fsfw_tests/unit/CatchSetup.cpp similarity index 57% rename from unittest/user/unittest/core/CatchSetup.cpp rename to tests/src/fsfw_tests/unit/CatchSetup.cpp index bda314003..a0791bc9e 100644 --- a/unittest/user/unittest/core/CatchSetup.cpp +++ b/tests/src/fsfw_tests/unit/CatchSetup.cpp @@ -5,10 +5,9 @@ #include #endif -#include -#include -#include -#include +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" /* Global instantiations normally done in main.cpp */ @@ -24,13 +23,11 @@ ServiceInterfaceStream warning("WARNING"); } #endif -/* Global object manager */ -ObjectManagerIF *objectManager; - int customSetup() { // global setup - objectManager = new ObjectManager(Factory::produce); - objectManager -> initialize(); + ObjectManager* objMan = ObjectManager::instance(); + objMan->setObjectFactoryFunction(Factory::produceFrameworkObjects, nullptr); + objMan->initialize(); return 0; } diff --git a/unittest/tests/action/CMakeLists.txt b/tests/src/fsfw_tests/unit/action/CMakeLists.txt similarity index 100% rename from unittest/tests/action/CMakeLists.txt rename to tests/src/fsfw_tests/unit/action/CMakeLists.txt diff --git a/unittest/tests/action/TestActionHelper.cpp b/tests/src/fsfw_tests/unit/action/TestActionHelper.cpp similarity index 97% rename from unittest/tests/action/TestActionHelper.cpp rename to tests/src/fsfw_tests/unit/action/TestActionHelper.cpp index d8bd58c99..3129b0019 100644 --- a/unittest/tests/action/TestActionHelper.cpp +++ b/tests/src/fsfw_tests/unit/action/TestActionHelper.cpp @@ -1,13 +1,10 @@ #include "TestActionHelper.h" - -#include +#include "fsfw_tests/unit/mocks/MessageQueueMockBase.h" #include #include -#include #include - #include diff --git a/unittest/tests/action/TestActionHelper.h b/tests/src/fsfw_tests/unit/action/TestActionHelper.h similarity index 96% rename from unittest/tests/action/TestActionHelper.h rename to tests/src/fsfw_tests/unit/action/TestActionHelper.h index 641ea2c63..34b228c05 100644 --- a/unittest/tests/action/TestActionHelper.h +++ b/tests/src/fsfw_tests/unit/action/TestActionHelper.h @@ -1,12 +1,11 @@ #ifndef UNITTEST_HOSTED_TESTACTIONHELPER_H_ #define UNITTEST_HOSTED_TESTACTIONHELPER_H_ +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include -#include #include - class ActionHelperOwnerMockBase: public HasActionsIF { public: bool getCommandQueueCalled = false; diff --git a/unittest/tests/container/CMakeLists.txt b/tests/src/fsfw_tests/unit/container/CMakeLists.txt similarity index 100% rename from unittest/tests/container/CMakeLists.txt rename to tests/src/fsfw_tests/unit/container/CMakeLists.txt diff --git a/unittest/tests/container/RingBufferTest.cpp b/tests/src/fsfw_tests/unit/container/RingBufferTest.cpp similarity index 99% rename from unittest/tests/container/RingBufferTest.cpp rename to tests/src/fsfw_tests/unit/container/RingBufferTest.cpp index 32a2502d0..819401ab3 100644 --- a/unittest/tests/container/RingBufferTest.cpp +++ b/tests/src/fsfw_tests/unit/container/RingBufferTest.cpp @@ -1,4 +1,4 @@ -#include +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include diff --git a/unittest/tests/container/TestArrayList.cpp b/tests/src/fsfw_tests/unit/container/TestArrayList.cpp similarity index 98% rename from unittest/tests/container/TestArrayList.cpp rename to tests/src/fsfw_tests/unit/container/TestArrayList.cpp index 1fd330b67..9417144ce 100644 --- a/unittest/tests/container/TestArrayList.cpp +++ b/tests/src/fsfw_tests/unit/container/TestArrayList.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include /** * @brief Array List test diff --git a/unittest/tests/container/TestDynamicFifo.cpp b/tests/src/fsfw_tests/unit/container/TestDynamicFifo.cpp similarity index 99% rename from unittest/tests/container/TestDynamicFifo.cpp rename to tests/src/fsfw_tests/unit/container/TestDynamicFifo.cpp index 2b572d520..a1bab3ba0 100644 --- a/unittest/tests/container/TestDynamicFifo.cpp +++ b/tests/src/fsfw_tests/unit/container/TestDynamicFifo.cpp @@ -1,9 +1,10 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include #include -#include TEST_CASE( "Dynamic Fifo Tests", "[TestDynamicFifo]") { INFO("Dynamic Fifo Tests"); diff --git a/unittest/tests/container/TestFifo.cpp b/tests/src/fsfw_tests/unit/container/TestFifo.cpp similarity index 98% rename from unittest/tests/container/TestFifo.cpp rename to tests/src/fsfw_tests/unit/container/TestFifo.cpp index fbcd40cc6..311dd8fd9 100644 --- a/unittest/tests/container/TestFifo.cpp +++ b/tests/src/fsfw_tests/unit/container/TestFifo.cpp @@ -1,9 +1,10 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include #include -#include TEST_CASE( "Static Fifo Tests", "[TestFifo]") { INFO("Fifo Tests"); diff --git a/unittest/tests/container/TestFixedArrayList.cpp b/tests/src/fsfw_tests/unit/container/TestFixedArrayList.cpp similarity index 95% rename from unittest/tests/container/TestFixedArrayList.cpp rename to tests/src/fsfw_tests/unit/container/TestFixedArrayList.cpp index 1a85f30d8..ed597f73a 100644 --- a/unittest/tests/container/TestFixedArrayList.cpp +++ b/tests/src/fsfw_tests/unit/container/TestFixedArrayList.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include TEST_CASE( "FixedArrayList Tests", "[TestFixedArrayList]") { diff --git a/unittest/tests/container/TestFixedMap.cpp b/tests/src/fsfw_tests/unit/container/TestFixedMap.cpp similarity index 99% rename from unittest/tests/container/TestFixedMap.cpp rename to tests/src/fsfw_tests/unit/container/TestFixedMap.cpp index 297171ca0..488418b93 100644 --- a/unittest/tests/container/TestFixedMap.cpp +++ b/tests/src/fsfw_tests/unit/container/TestFixedMap.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include template class FixedMap; diff --git a/unittest/tests/container/TestFixedOrderedMultimap.cpp b/tests/src/fsfw_tests/unit/container/TestFixedOrderedMultimap.cpp similarity index 99% rename from unittest/tests/container/TestFixedOrderedMultimap.cpp rename to tests/src/fsfw_tests/unit/container/TestFixedOrderedMultimap.cpp index a47d6efb0..23d917443 100644 --- a/unittest/tests/container/TestFixedOrderedMultimap.cpp +++ b/tests/src/fsfw_tests/unit/container/TestFixedOrderedMultimap.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include TEST_CASE( "FixedOrderedMultimap Tests", "[TestFixedOrderedMultimap]") { INFO("FixedOrderedMultimap Tests"); diff --git a/unittest/tests/container/TestPlacementFactory.cpp b/tests/src/fsfw_tests/unit/container/TestPlacementFactory.cpp similarity index 97% rename from unittest/tests/container/TestPlacementFactory.cpp rename to tests/src/fsfw_tests/unit/container/TestPlacementFactory.cpp index 14cf8eb4c..1e328fc74 100644 --- a/unittest/tests/container/TestPlacementFactory.cpp +++ b/tests/src/fsfw_tests/unit/container/TestPlacementFactory.cpp @@ -1,10 +1,11 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include #include #include -#include TEST_CASE( "PlacementFactory Tests", "[TestPlacementFactory]") { INFO("PlacementFactory Tests"); diff --git a/unittest/tests/datapoollocal/CMakeLists.txt b/tests/src/fsfw_tests/unit/datapoollocal/CMakeLists.txt similarity index 100% rename from unittest/tests/datapoollocal/CMakeLists.txt rename to tests/src/fsfw_tests/unit/datapoollocal/CMakeLists.txt diff --git a/unittest/tests/datapoollocal/DataSetTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp similarity index 99% rename from unittest/tests/datapoollocal/DataSetTest.cpp rename to tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp index b8748eb43..94b13f2f5 100644 --- a/unittest/tests/datapoollocal/DataSetTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp @@ -1,7 +1,5 @@ #include "LocalPoolOwnerBase.h" - -#include -#include +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include @@ -10,7 +8,8 @@ #include #include -#include +#include +#include TEST_CASE("DataSetTest" , "[DataSetTest]") { LocalPoolOwnerBase* poolOwner = ObjectManager::instance()-> diff --git a/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp similarity index 99% rename from unittest/tests/datapoollocal/LocalPoolManagerTest.cpp rename to tests/src/fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp index 4a4d08fb2..7b2f9412d 100644 --- a/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp @@ -1,7 +1,5 @@ #include "LocalPoolOwnerBase.h" - -#include -#include +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include @@ -10,7 +8,10 @@ #include #include #include -#include + +#include +#include + #include diff --git a/unittest/tests/datapoollocal/LocalPoolOwnerBase.cpp b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.cpp similarity index 100% rename from unittest/tests/datapoollocal/LocalPoolOwnerBase.cpp rename to tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.cpp diff --git a/unittest/tests/datapoollocal/LocalPoolOwnerBase.h b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h similarity index 99% rename from unittest/tests/datapoollocal/LocalPoolOwnerBase.h rename to tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h index 4c244b169..ea5bb7e0d 100644 --- a/unittest/tests/datapoollocal/LocalPoolOwnerBase.h +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h @@ -2,6 +2,7 @@ #define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ #include "objects/systemObjectList.h" +#include "../mocks/MessageQueueMockBase.h" #include #include @@ -10,7 +11,6 @@ #include #include #include -#include #include namespace lpool { diff --git a/unittest/tests/datapoollocal/LocalPoolVariableTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp similarity index 99% rename from unittest/tests/datapoollocal/LocalPoolVariableTest.cpp rename to tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp index 514d81258..648a76e29 100644 --- a/unittest/tests/datapoollocal/LocalPoolVariableTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp @@ -1,10 +1,10 @@ #include "LocalPoolOwnerBase.h" +#include "fsfw_tests/unit/CatchDefinitions.h" -#include #include #include -#include +#include TEST_CASE("LocalPoolVariable" , "[LocPoolVarTest]") { LocalPoolOwnerBase* poolOwner = ObjectManager::instance()-> diff --git a/unittest/tests/datapoollocal/LocalPoolVectorTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp similarity index 99% rename from unittest/tests/datapoollocal/LocalPoolVectorTest.cpp rename to tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp index 5b3dd105a..3f846dec4 100644 --- a/unittest/tests/datapoollocal/LocalPoolVectorTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp @@ -1,9 +1,10 @@ #include "LocalPoolOwnerBase.h" +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include #include -#include + TEST_CASE("LocalPoolVector" , "[LocPoolVecTest]") { LocalPoolOwnerBase* poolOwner = ObjectManager::instance()-> diff --git a/unittest/internal/globalfunctions/CMakeLists.txt b/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt similarity index 63% rename from unittest/internal/globalfunctions/CMakeLists.txt rename to tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt index 4ea49bf74..617c7f5a0 100644 --- a/unittest/internal/globalfunctions/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/globalfunctions/CMakeLists.txt @@ -1,3 +1,3 @@ target_sources(${TARGET_NAME} PRIVATE - TestArrayPrinter.cpp + testDleEncoder.cpp ) diff --git a/tests/src/fsfw_tests/unit/globalfunctions/testDleEncoder.cpp b/tests/src/fsfw_tests/unit/globalfunctions/testDleEncoder.cpp new file mode 100644 index 000000000..cffd53083 --- /dev/null +++ b/tests/src/fsfw_tests/unit/globalfunctions/testDleEncoder.cpp @@ -0,0 +1,227 @@ +#include "fsfw/globalfunctions/DleEncoder.h" +#include "fsfw_tests/unit/CatchDefinitions.h" +#include "catch2/catch_test_macros.hpp" + +#include + +const std::vector TEST_ARRAY_0 = { 0, 0, 0, 0, 0 }; +const std::vector TEST_ARRAY_1 = { 0, DleEncoder::DLE_CHAR, 5}; +const std::vector TEST_ARRAY_2 = { 0, DleEncoder::STX_CHAR, 5}; +const std::vector TEST_ARRAY_3 = { 0, DleEncoder::CARRIAGE_RETURN, DleEncoder::ETX_CHAR}; +const std::vector TEST_ARRAY_4 = { DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR, + DleEncoder::STX_CHAR }; + +const std::vector TEST_ARRAY_0_ENCODED_ESCAPED = { + DleEncoder::STX_CHAR, 0, 0, 0, 0, 0, DleEncoder::ETX_CHAR +}; +const std::vector TEST_ARRAY_0_ENCODED_NON_ESCAPED = { + DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR, 0, 0, 0, 0, 0, + DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR +}; + +const std::vector TEST_ARRAY_1_ENCODED_ESCAPED = { + DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR, DleEncoder::DLE_CHAR, 5, DleEncoder::ETX_CHAR +}; +const std::vector TEST_ARRAY_1_ENCODED_NON_ESCAPED = { + DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR, DleEncoder::DLE_CHAR, + 5, DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR +}; + +const std::vector TEST_ARRAY_2_ENCODED_ESCAPED = { + DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR + 0x40, + 5, DleEncoder::ETX_CHAR +}; +const std::vector TEST_ARRAY_2_ENCODED_NON_ESCAPED = { + DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR, 0, + DleEncoder::STX_CHAR, 5, DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR +}; + +const std::vector TEST_ARRAY_3_ENCODED_ESCAPED = { + DleEncoder::STX_CHAR, 0, DleEncoder::CARRIAGE_RETURN, + DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR + 0x40, DleEncoder::ETX_CHAR +}; +const std::vector TEST_ARRAY_3_ENCODED_NON_ESCAPED = { + DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR, 0, + DleEncoder::CARRIAGE_RETURN, DleEncoder::ETX_CHAR, DleEncoder::DLE_CHAR, + DleEncoder::ETX_CHAR +}; + +const std::vector TEST_ARRAY_4_ENCODED_ESCAPED = { + DleEncoder::STX_CHAR, DleEncoder::DLE_CHAR, DleEncoder::DLE_CHAR, + DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR + 0x40, DleEncoder::DLE_CHAR, + DleEncoder::STX_CHAR + 0x40, DleEncoder::ETX_CHAR +}; +const std::vector TEST_ARRAY_4_ENCODED_NON_ESCAPED = { + DleEncoder::DLE_CHAR, DleEncoder::STX_CHAR, DleEncoder::DLE_CHAR, DleEncoder::DLE_CHAR, + DleEncoder::ETX_CHAR, DleEncoder::STX_CHAR, DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR +}; + + +TEST_CASE("DleEncoder" , "[DleEncoder]") { + DleEncoder dleEncoder; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + std::array buffer; + + size_t encodedLen = 0; + size_t readLen = 0; + size_t decodedLen = 0; + + auto testLambdaEncode = [&](DleEncoder& encoder, const std::vector& vecToEncode, + const std::vector& expectedVec) { + result = encoder.encode(vecToEncode.data(), vecToEncode.size(), + buffer.data(), buffer.size(), &encodedLen); + REQUIRE(result == retval::CATCH_OK); + for(size_t idx = 0; idx < expectedVec.size(); idx++) { + REQUIRE(buffer[idx] == expectedVec[idx]); + } + REQUIRE(encodedLen == expectedVec.size()); + }; + + auto testLambdaDecode = [&](DleEncoder& encoder, const std::vector& testVecEncoded, + const std::vector& expectedVec) { + result = encoder.decode(testVecEncoded.data(), + testVecEncoded.size(), + &readLen, buffer.data(), buffer.size(), &decodedLen); + REQUIRE(result == retval::CATCH_OK); + REQUIRE(readLen == testVecEncoded.size()); + REQUIRE(decodedLen == expectedVec.size()); + for(size_t idx = 0; idx < decodedLen; idx++) { + REQUIRE(buffer[idx] == expectedVec[idx]); + } + }; + + SECTION("Encoding") { + testLambdaEncode(dleEncoder, TEST_ARRAY_0, TEST_ARRAY_0_ENCODED_ESCAPED); + testLambdaEncode(dleEncoder, TEST_ARRAY_1, TEST_ARRAY_1_ENCODED_ESCAPED); + testLambdaEncode(dleEncoder, TEST_ARRAY_2, TEST_ARRAY_2_ENCODED_ESCAPED); + testLambdaEncode(dleEncoder, TEST_ARRAY_3, TEST_ARRAY_3_ENCODED_ESCAPED); + testLambdaEncode(dleEncoder, TEST_ARRAY_4, TEST_ARRAY_4_ENCODED_ESCAPED); + + auto testFaultyEncoding = [&](const std::vector& vecToEncode, + const std::vector& expectedVec) { + + for(size_t faultyDestSize = 0; faultyDestSize < expectedVec.size(); faultyDestSize ++) { + result = dleEncoder.encode(vecToEncode.data(), vecToEncode.size(), + buffer.data(), faultyDestSize, &encodedLen); + REQUIRE(result == static_cast(DleEncoder::STREAM_TOO_SHORT)); + } + }; + + testFaultyEncoding(TEST_ARRAY_0, TEST_ARRAY_0_ENCODED_ESCAPED); + testFaultyEncoding(TEST_ARRAY_1, TEST_ARRAY_1_ENCODED_ESCAPED); + testFaultyEncoding(TEST_ARRAY_2, TEST_ARRAY_2_ENCODED_ESCAPED); + testFaultyEncoding(TEST_ARRAY_3, TEST_ARRAY_3_ENCODED_ESCAPED); + testFaultyEncoding(TEST_ARRAY_4, TEST_ARRAY_4_ENCODED_ESCAPED); + + dleEncoder.setEscapeMode(false); + testLambdaEncode(dleEncoder, TEST_ARRAY_0, TEST_ARRAY_0_ENCODED_NON_ESCAPED); + testLambdaEncode(dleEncoder, TEST_ARRAY_1, TEST_ARRAY_1_ENCODED_NON_ESCAPED); + testLambdaEncode(dleEncoder, TEST_ARRAY_2, TEST_ARRAY_2_ENCODED_NON_ESCAPED); + testLambdaEncode(dleEncoder, TEST_ARRAY_3, TEST_ARRAY_3_ENCODED_NON_ESCAPED); + testLambdaEncode(dleEncoder, TEST_ARRAY_4, TEST_ARRAY_4_ENCODED_NON_ESCAPED); + + testFaultyEncoding(TEST_ARRAY_0, TEST_ARRAY_0_ENCODED_NON_ESCAPED); + testFaultyEncoding(TEST_ARRAY_1, TEST_ARRAY_1_ENCODED_NON_ESCAPED); + testFaultyEncoding(TEST_ARRAY_2, TEST_ARRAY_2_ENCODED_NON_ESCAPED); + testFaultyEncoding(TEST_ARRAY_3, TEST_ARRAY_3_ENCODED_NON_ESCAPED); + testFaultyEncoding(TEST_ARRAY_4, TEST_ARRAY_4_ENCODED_NON_ESCAPED); + dleEncoder.setEscapeMode(true); + } + + SECTION("Decoding") { + testLambdaDecode(dleEncoder, TEST_ARRAY_0_ENCODED_ESCAPED, TEST_ARRAY_0); + testLambdaDecode(dleEncoder, TEST_ARRAY_1_ENCODED_ESCAPED, TEST_ARRAY_1); + testLambdaDecode(dleEncoder, TEST_ARRAY_2_ENCODED_ESCAPED, TEST_ARRAY_2); + testLambdaDecode(dleEncoder, TEST_ARRAY_3_ENCODED_ESCAPED, TEST_ARRAY_3); + testLambdaDecode(dleEncoder, TEST_ARRAY_4_ENCODED_ESCAPED, TEST_ARRAY_4); + + // Faulty source data + auto testArray1EncodedFaulty = TEST_ARRAY_1_ENCODED_ESCAPED; + testArray1EncodedFaulty[3] = 0; + result = dleEncoder.decode(testArray1EncodedFaulty.data(), testArray1EncodedFaulty.size(), + &readLen, buffer.data(), buffer.size(), &encodedLen); + REQUIRE(result == static_cast(DleEncoder::DECODING_ERROR)); + auto testArray2EncodedFaulty = TEST_ARRAY_2_ENCODED_ESCAPED; + testArray2EncodedFaulty[5] = 0; + result = dleEncoder.decode(testArray2EncodedFaulty.data(), testArray2EncodedFaulty.size(), + &readLen, buffer.data(), buffer.size(), &encodedLen); + REQUIRE(result == static_cast(DleEncoder::DECODING_ERROR)); + auto testArray4EncodedFaulty = TEST_ARRAY_4_ENCODED_ESCAPED; + testArray4EncodedFaulty[2] = 0; + result = dleEncoder.decode(testArray4EncodedFaulty.data(), testArray4EncodedFaulty.size(), + &readLen, buffer.data(), buffer.size(), &encodedLen); + REQUIRE(result == static_cast(DleEncoder::DECODING_ERROR)); + auto testArray4EncodedFaulty2 = TEST_ARRAY_4_ENCODED_ESCAPED; + testArray4EncodedFaulty2[4] = 0; + result = dleEncoder.decode(testArray4EncodedFaulty2.data(), testArray4EncodedFaulty2.size(), + &readLen, buffer.data(), buffer.size(), &encodedLen); + REQUIRE(result == static_cast(DleEncoder::DECODING_ERROR)); + + auto testFaultyDecoding = [&](const std::vector& vecToDecode, + const std::vector& expectedVec) { + for(size_t faultyDestSizes = 0; + faultyDestSizes < expectedVec.size(); + faultyDestSizes ++) { + result = dleEncoder.decode(vecToDecode.data(), + vecToDecode.size(), &readLen, + buffer.data(), faultyDestSizes, &decodedLen); + REQUIRE(result == static_cast(DleEncoder::STREAM_TOO_SHORT)); + } + }; + + testFaultyDecoding(TEST_ARRAY_0_ENCODED_ESCAPED, TEST_ARRAY_0); + testFaultyDecoding(TEST_ARRAY_1_ENCODED_ESCAPED, TEST_ARRAY_1); + testFaultyDecoding(TEST_ARRAY_2_ENCODED_ESCAPED, TEST_ARRAY_2); + testFaultyDecoding(TEST_ARRAY_3_ENCODED_ESCAPED, TEST_ARRAY_3); + testFaultyDecoding(TEST_ARRAY_4_ENCODED_ESCAPED, TEST_ARRAY_4); + + dleEncoder.setEscapeMode(false); + testLambdaDecode(dleEncoder, TEST_ARRAY_0_ENCODED_NON_ESCAPED, TEST_ARRAY_0); + testLambdaDecode(dleEncoder, TEST_ARRAY_1_ENCODED_NON_ESCAPED, TEST_ARRAY_1); + testLambdaDecode(dleEncoder, TEST_ARRAY_2_ENCODED_NON_ESCAPED, TEST_ARRAY_2); + testLambdaDecode(dleEncoder, TEST_ARRAY_3_ENCODED_NON_ESCAPED, TEST_ARRAY_3); + testLambdaDecode(dleEncoder, TEST_ARRAY_4_ENCODED_NON_ESCAPED, TEST_ARRAY_4); + + testFaultyDecoding(TEST_ARRAY_0_ENCODED_NON_ESCAPED, TEST_ARRAY_0); + testFaultyDecoding(TEST_ARRAY_1_ENCODED_NON_ESCAPED, TEST_ARRAY_1); + testFaultyDecoding(TEST_ARRAY_2_ENCODED_NON_ESCAPED, TEST_ARRAY_2); + testFaultyDecoding(TEST_ARRAY_3_ENCODED_NON_ESCAPED, TEST_ARRAY_3); + testFaultyDecoding(TEST_ARRAY_4_ENCODED_NON_ESCAPED, TEST_ARRAY_4); + + // Faulty source data + testArray1EncodedFaulty = TEST_ARRAY_1_ENCODED_NON_ESCAPED; + auto prevVal = testArray1EncodedFaulty[0]; + testArray1EncodedFaulty[0] = 0; + result = dleEncoder.decode(testArray1EncodedFaulty.data(), testArray1EncodedFaulty.size(), + &readLen, buffer.data(), buffer.size(), &encodedLen); + REQUIRE(result == static_cast(DleEncoder::DECODING_ERROR)); + testArray1EncodedFaulty[0] = prevVal; + testArray1EncodedFaulty[1] = 0; + result = dleEncoder.decode(testArray1EncodedFaulty.data(), testArray1EncodedFaulty.size(), + &readLen, buffer.data(), buffer.size(), &encodedLen); + REQUIRE(result == static_cast(DleEncoder::DECODING_ERROR)); + + testArray1EncodedFaulty = TEST_ARRAY_1_ENCODED_NON_ESCAPED; + testArray1EncodedFaulty[6] = 0; + result = dleEncoder.decode(testArray1EncodedFaulty.data(), testArray1EncodedFaulty.size(), + &readLen, buffer.data(), buffer.size(), &encodedLen); + REQUIRE(result == static_cast(DleEncoder::DECODING_ERROR)); + testArray1EncodedFaulty = TEST_ARRAY_1_ENCODED_NON_ESCAPED; + testArray1EncodedFaulty[7] = 0; + result = dleEncoder.decode(testArray1EncodedFaulty.data(), testArray1EncodedFaulty.size(), + &readLen, buffer.data(), buffer.size(), &encodedLen); + REQUIRE(result == static_cast(DleEncoder::DECODING_ERROR)); + testArray4EncodedFaulty = TEST_ARRAY_4_ENCODED_NON_ESCAPED; + testArray4EncodedFaulty[3] = 0; + result = dleEncoder.decode(testArray4EncodedFaulty.data(), testArray4EncodedFaulty.size(), + &readLen, buffer.data(), buffer.size(), &encodedLen); + REQUIRE(result == static_cast(DleEncoder::DECODING_ERROR)); + + dleEncoder.setEscapeMode(true); + testArray1EncodedFaulty = TEST_ARRAY_1_ENCODED_ESCAPED; + testArray1EncodedFaulty[5] = 0; + result = dleEncoder.decode(testArray1EncodedFaulty.data(), testArray1EncodedFaulty.size(), + &readLen, buffer.data(), buffer.size(), &encodedLen); + REQUIRE(result == static_cast(DleEncoder::DECODING_ERROR)); + } +} diff --git a/unittest/tests/mocks/HkReceiverMock.h b/tests/src/fsfw_tests/unit/mocks/HkReceiverMock.h similarity index 100% rename from unittest/tests/mocks/HkReceiverMock.h rename to tests/src/fsfw_tests/unit/mocks/HkReceiverMock.h diff --git a/unittest/tests/mocks/MessageQueueMockBase.h b/tests/src/fsfw_tests/unit/mocks/MessageQueueMockBase.h similarity index 95% rename from unittest/tests/mocks/MessageQueueMockBase.h rename to tests/src/fsfw_tests/unit/mocks/MessageQueueMockBase.h index 3000f7fb5..93a00b7a6 100644 --- a/unittest/tests/mocks/MessageQueueMockBase.h +++ b/tests/src/fsfw_tests/unit/mocks/MessageQueueMockBase.h @@ -1,9 +1,12 @@ #ifndef FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ #define FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ -#include -#include -#include +#include "fsfw_tests/unit/CatchDefinitions.h" + +#include "fsfw/ipc/CommandMessage.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/MessageQueueMessage.h" + #include #include diff --git a/unittest/tests/osal/CMakeLists.txt b/tests/src/fsfw_tests/unit/osal/CMakeLists.txt similarity index 100% rename from unittest/tests/osal/CMakeLists.txt rename to tests/src/fsfw_tests/unit/osal/CMakeLists.txt diff --git a/unittest/tests/osal/TestMessageQueue.cpp b/tests/src/fsfw_tests/unit/osal/TestMessageQueue.cpp similarity index 96% rename from unittest/tests/osal/TestMessageQueue.cpp rename to tests/src/fsfw_tests/unit/osal/TestMessageQueue.cpp index e33b72404..07197bf70 100644 --- a/unittest/tests/osal/TestMessageQueue.cpp +++ b/tests/src/fsfw_tests/unit/osal/TestMessageQueue.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include #include diff --git a/unittest/tests/osal/TestSemaphore.cpp b/tests/src/fsfw_tests/unit/osal/TestSemaphore.cpp similarity index 100% rename from unittest/tests/osal/TestSemaphore.cpp rename to tests/src/fsfw_tests/unit/osal/TestSemaphore.cpp diff --git a/unittest/user/unittest/core/printChar.cpp b/tests/src/fsfw_tests/unit/printChar.cpp similarity index 100% rename from unittest/user/unittest/core/printChar.cpp rename to tests/src/fsfw_tests/unit/printChar.cpp diff --git a/unittest/user/unittest/core/printChar.h b/tests/src/fsfw_tests/unit/printChar.h similarity index 100% rename from unittest/user/unittest/core/printChar.h rename to tests/src/fsfw_tests/unit/printChar.h diff --git a/unittest/tests/serialize/CMakeLists.txt b/tests/src/fsfw_tests/unit/serialize/CMakeLists.txt similarity index 100% rename from unittest/tests/serialize/CMakeLists.txt rename to tests/src/fsfw_tests/unit/serialize/CMakeLists.txt diff --git a/unittest/tests/serialize/TestSerialBufferAdapter.cpp b/tests/src/fsfw_tests/unit/serialize/TestSerialBufferAdapter.cpp similarity index 99% rename from unittest/tests/serialize/TestSerialBufferAdapter.cpp rename to tests/src/fsfw_tests/unit/serialize/TestSerialBufferAdapter.cpp index 1938746d7..01d75881e 100644 --- a/unittest/tests/serialize/TestSerialBufferAdapter.cpp +++ b/tests/src/fsfw_tests/unit/serialize/TestSerialBufferAdapter.cpp @@ -1,7 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include -#include + #include diff --git a/unittest/tests/serialize/TestSerialLinkedPacket.cpp b/tests/src/fsfw_tests/unit/serialize/TestSerialLinkedPacket.cpp similarity index 96% rename from unittest/tests/serialize/TestSerialLinkedPacket.cpp rename to tests/src/fsfw_tests/unit/serialize/TestSerialLinkedPacket.cpp index b90ae9f86..b6bb214d7 100644 --- a/unittest/tests/serialize/TestSerialLinkedPacket.cpp +++ b/tests/src/fsfw_tests/unit/serialize/TestSerialLinkedPacket.cpp @@ -1,10 +1,9 @@ #include "TestSerialLinkedPacket.h" -#include +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include -#include #include diff --git a/unittest/tests/serialize/TestSerialLinkedPacket.h b/tests/src/fsfw_tests/unit/serialize/TestSerialLinkedPacket.h similarity index 100% rename from unittest/tests/serialize/TestSerialLinkedPacket.h rename to tests/src/fsfw_tests/unit/serialize/TestSerialLinkedPacket.h diff --git a/unittest/tests/serialize/TestSerialization.cpp b/tests/src/fsfw_tests/unit/serialize/TestSerialization.cpp similarity index 99% rename from unittest/tests/serialize/TestSerialization.cpp rename to tests/src/fsfw_tests/unit/serialize/TestSerialization.cpp index 3de581ec9..64deae3b2 100644 --- a/unittest/tests/serialize/TestSerialization.cpp +++ b/tests/src/fsfw_tests/unit/serialize/TestSerialization.cpp @@ -1,8 +1,8 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include #include -#include #include diff --git a/unittest/tests/storagemanager/CMakeLists.txt b/tests/src/fsfw_tests/unit/storagemanager/CMakeLists.txt similarity index 100% rename from unittest/tests/storagemanager/CMakeLists.txt rename to tests/src/fsfw_tests/unit/storagemanager/CMakeLists.txt diff --git a/unittest/tests/storagemanager/TestNewAccessor.cpp b/tests/src/fsfw_tests/unit/storagemanager/TestNewAccessor.cpp similarity index 99% rename from unittest/tests/storagemanager/TestNewAccessor.cpp rename to tests/src/fsfw_tests/unit/storagemanager/TestNewAccessor.cpp index 10d05c6b1..bd1634b7c 100644 --- a/unittest/tests/storagemanager/TestNewAccessor.cpp +++ b/tests/src/fsfw_tests/unit/storagemanager/TestNewAccessor.cpp @@ -1,6 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include + #include -#include + #include #include diff --git a/unittest/tests/storagemanager/TestPool.cpp b/tests/src/fsfw_tests/unit/storagemanager/TestPool.cpp similarity index 99% rename from unittest/tests/storagemanager/TestPool.cpp rename to tests/src/fsfw_tests/unit/storagemanager/TestPool.cpp index d05a3dd6e..013ecf86c 100644 --- a/unittest/tests/storagemanager/TestPool.cpp +++ b/tests/src/fsfw_tests/unit/storagemanager/TestPool.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include #include diff --git a/unittest/tests/globalfunctions/CMakeLists.txt b/tests/src/fsfw_tests/unit/timemanager/CMakeLists.txt similarity index 64% rename from unittest/tests/globalfunctions/CMakeLists.txt rename to tests/src/fsfw_tests/unit/timemanager/CMakeLists.txt index 4ea49bf74..2c6357114 100644 --- a/unittest/tests/globalfunctions/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/timemanager/CMakeLists.txt @@ -1,3 +1,3 @@ target_sources(${TARGET_NAME} PRIVATE - TestArrayPrinter.cpp + TestCountdown.cpp ) diff --git a/tests/src/fsfw_tests/unit/timemanager/TestCountdown.cpp b/tests/src/fsfw_tests/unit/timemanager/TestCountdown.cpp new file mode 100644 index 000000000..b1b26679e --- /dev/null +++ b/tests/src/fsfw_tests/unit/timemanager/TestCountdown.cpp @@ -0,0 +1,27 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" +#include +#include + + +TEST_CASE( "Countdown Tests", "[TestCountdown]") { + INFO("Countdown Tests"); + Countdown count(20); + REQUIRE(count.timeout == 20); + REQUIRE(count.setTimeout(100) == static_cast(HasReturnvaluesIF::RETURN_OK)); + REQUIRE(count.timeout == 100); + REQUIRE(count.setTimeout(150) == static_cast(HasReturnvaluesIF::RETURN_OK)); + REQUIRE(count.isBusy()); + REQUIRE(not count.hasTimedOut()); + uint32_t number = count.getRemainingMillis(); + REQUIRE(number > 0); + bool blocked = false; + while(not count.hasTimedOut()){ + blocked = true; + }; + REQUIRE(blocked); + number = count.getRemainingMillis(); + REQUIRE(number==0); + count.resetTimer(); + REQUIRE(not count.hasTimedOut()); + REQUIRE(count.isBusy()); +} diff --git a/unittest/tests/tmtcpacket/CMakeLists.txt b/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt similarity index 100% rename from unittest/tests/tmtcpacket/CMakeLists.txt rename to tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt diff --git a/unittest/tests/tmtcpacket/PusTmTest.cpp b/tests/src/fsfw_tests/unit/tmtcpacket/PusTmTest.cpp similarity index 100% rename from unittest/tests/tmtcpacket/PusTmTest.cpp rename to tests/src/fsfw_tests/unit/tmtcpacket/PusTmTest.cpp diff --git a/unittest/user/CMakeLists.txt b/tests/user/CMakeLists.txt similarity index 84% rename from unittest/user/CMakeLists.txt rename to tests/user/CMakeLists.txt index 722cc424c..2e1fdee31 100644 --- a/unittest/user/CMakeLists.txt +++ b/tests/user/CMakeLists.txt @@ -1,8 +1,5 @@ ################################################################################ # CMake support for the Flight Software Framework Tests -# -# Developed in an effort to replace Make with a modern build system. -# # Author: R. Mueller ################################################################################ @@ -12,6 +9,7 @@ cmake_minimum_required(VERSION 3.13) # set(CMAKE_VERBOSE TRUE) +# set(CODE_COVERAGE_VERBOSE TRUE) set(CMAKE_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -21,6 +19,8 @@ option(GENERATE_COVERAGE TRUE ) +set(FSFW_ADD_UNITTESTS ON) + if(TMTC_TEST) set(LINK_CATCH2 FALSE) else() @@ -28,20 +28,16 @@ else() endif() # Tests can be built with the Host OSAL or with the Linux OSAL. -if(NOT OS_FSFW) - set(OS_FSFW host CACHE STRING "OS for the FSFW.") +if(NOT FSFW_OSAL) + set(FSFW_OSAL host CACHE STRING "OS for the FSFW.") endif() -option(CUSTOM_UNITTEST_RUNNER +option(FSFW_CUSTOM_UNITTEST_RUNNER "Specify whether custom main or Catch2 main is used" TRUE ) -# Perform steps like loading toolchain files where applicable. -#include(${CMAKE_SCRIPT_PATH}/PreProjectConfig.cmake) -#pre_project_config() - # Project Name -project(fsfw_tests C CXX) +project(fsfw-tests C CXX) ################################################################################ # Pre-Sources preparation @@ -53,7 +49,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) # Set names and variables set(TARGET_NAME ${CMAKE_PROJECT_NAME}) -if(CUSTOM_UNITTEST_RUNNER) +if(FSFW_CUSTOM_UNITTEST_RUNNER) set(CATCH2_TARGET Catch2) else() set(CATCH2_TARGET Catch2WithMain) @@ -71,7 +67,7 @@ set(TMTC_TEST_PATH tests) # determine BSP_PATH # FreeRTOS -if(${OS_FSFW} STREQUAL linux) +if(FSFW_OSAL STREQUAL linux) add_definitions(-DUNIX -DLINUX) find_package(Threads REQUIRED) # Hosted @@ -94,6 +90,11 @@ if(GENERATE_COVERAGE) endif() set(FSFW_CONFIG_PATH testcfg) +set(FSFW_ADDITIONAL_INC_PATHS ${CMAKE_CURRENT_BINARY_DIR}) + +configure_file(${FSFW_CONFIG_PATH}/FSFWConfig.h.in FSFWConfig.h) +configure_file(${FSFW_CONFIG_PATH}/OBSWConfig.h.in OBSWConfig.h) +configure_file(${FSFW_CONFIG_PATH}/TestsConfig.h.in TestsConfig.h) ################################################################################ # Executable and Sources @@ -108,10 +109,16 @@ add_subdirectory(${FSFW_CONFIG_PATH}) if(LINK_CATCH2) add_subdirectory(${CATCH2_PATH}) - add_subdirectory(${FSFW_TESTS_PATH}) add_subdirectory(${TEST_SETUP_PATH}) else() + target_compile_definitions(${TARGET_NAME} PRIVATE + FSFW_DISABLE_PRINTOUT=0 + ) + target_compile_definitions(${LIB_FSFW_NAME} PRIVATE + FSFW_DISABLE_PRINTOUT=0 + ) add_subdirectory(${TMTC_TEST_PATH}) + add_subdirectory(${FSFW_TESTS_PATH}) endif() @@ -132,7 +139,7 @@ endif() if(GENERATE_COVERAGE) if(CMAKE_COMPILER_IS_GNUCXX) - set(CODE_COVERAGE_VERBOSE TRUE) + # set(CODE_COVERAGE_VERBOSE TRUE) include(CodeCoverage) # Remove quotes. @@ -194,6 +201,7 @@ endif() target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${FSFW_CONFIG_PATH} + ${CMAKE_CURRENT_BINARY_DIR} ) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") @@ -225,12 +233,9 @@ if(CMAKE_VERBOSE) message(STATUS "Warning flags: ${WARNING_FLAGS}") endif() - # Compile options for all sources. target_compile_options(${TARGET_NAME} PRIVATE - $<$:${WARNING_FLAGS} ${COMPILER_FLAGS}> - $<$:${WARNING_FLAGS} ${COMPILER_FLAGS}> - ${ABI_FLAGS} + ${WARNING_FLAGS} ) if(NOT CMAKE_SIZE) @@ -240,18 +245,17 @@ if(NOT CMAKE_SIZE) endif() endif() +string(CONCAT POST_BUILD_COMMENT + "Build directory: ${CMAKE_BINARY_DIR}\n" + "Target OSAL: ${FSFW_OSAL}\n" + "Target Build Type: ${CMAKE_BUILD_TYPE}" +) + 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 ${CMAKE_SIZE} ${TARGET_NAME}${FILE_SUFFIX} + POST_BUILD + COMMAND ${CMAKE_SIZE} ${TARGET_NAME}${FILE_SUFFIX} + COMMENT ${POST_BUILD_COMMENT} ) include (${CMAKE_SCRIPT_PATH}/BuildType.cmake) set_build_type() - - - - - diff --git a/unittest/README.md b/tests/user/README.md similarity index 100% rename from unittest/README.md rename to tests/user/README.md diff --git a/unittest/lcov.sh b/tests/user/lcov.sh similarity index 100% rename from unittest/lcov.sh rename to tests/user/lcov.sh diff --git a/unittest/user/testcfg/CMakeLists.txt b/tests/user/testcfg/CMakeLists.txt similarity index 100% rename from unittest/user/testcfg/CMakeLists.txt rename to tests/user/testcfg/CMakeLists.txt diff --git a/unittest/user/testcfg/FSFWConfig.h b/tests/user/testcfg/FSFWConfig.h.in similarity index 68% rename from unittest/user/testcfg/FSFWConfig.h rename to tests/user/testcfg/FSFWConfig.h.in index ed86e6e1f..d38f0648f 100644 --- a/unittest/user/testcfg/FSFWConfig.h +++ b/tests/user/testcfg/FSFWConfig.h.in @@ -7,18 +7,24 @@ //! Used to determine whether C++ ostreams are used which can increase //! the binary size significantly. If this is disabled, //! the C stdio functions can be used alternatively -#define FSFW_CPP_OSTREAM_ENABLED 1 +#define FSFW_CPP_OSTREAM_ENABLED 0 -//! More FSFW related printouts depending on level. Useful for development. -#define FSFW_VERBOSE_LEVEL 1 +//! More FSFW related printouts. Useful for development. +#define FSFW_ENHANCED_PRINTOUT 0 //! Can be used to completely disable printouts, even the C stdio ones. -#if FSFW_CPP_OSTREAM_ENABLED == 0 && FSFW_VERBOSE_LEVEL == 0 - #define FSFW_DISABLE_PRINTOUT 0 +//! By default, printouts will be disabled for the unit tests. +#if FSFW_CPP_OSTREAM_ENABLED == 0 && FSFW_ENHANCED_PRINTOUT == 0 + #ifndef FSFW_DISABLE_PRINTOUT + #define FSFW_DISABLE_PRINTOUT 1 + #endif #endif +//! Can be used to enable additional debugging printouts for developing the FSFW +#define FSFW_PRINT_VERBOSITY_LEVEL 0 + //! Can be used to disable the ANSI color sequences for C stdio. -#define FSFW_COLORED_OUTPUT 1 +#define FSFW_COLORED_OUTPUT 0 //! If FSFW_OBJ_EVENT_TRANSLATION is set to one, //! additional output which requires the translation files translateObjects @@ -40,6 +46,13 @@ //! Specify whether a special mode store is used for Subsystem components. #define FSFW_USE_MODESTORE 0 +//! Defines if the real time scheduler for linux should be used. +//! If set to 0, this will also disable priority settings for linux +//! as most systems will not allow to set nice values without privileges +//! For embedded linux system set this to 1. +//! If set to 1 the binary needs "cap_sys_nice=eip" privileges to run +#define FSFW_USE_REALTIME_FOR_LINUX 1 + namespace fsfwconfig { //! Default timestamp size. The default timestamp will be an eight byte CDC //! short timestamp. @@ -57,6 +70,9 @@ static constexpr size_t FSFW_EVENTMGMR_RANGEMATCHERS = 120; static constexpr uint8_t FSFW_CSB_FIFO_DEPTH = 6; static constexpr size_t FSFW_PRINT_BUFFER_SIZE = 124; + +static constexpr size_t FSFW_MAX_TM_PACKET_SIZE = 1500; + } #endif /* CONFIG_FSFWCONFIG_H_ */ diff --git a/tests/user/testcfg/OBSWConfig.h.in b/tests/user/testcfg/OBSWConfig.h.in new file mode 100644 index 000000000..34eda31f0 --- /dev/null +++ b/tests/user/testcfg/OBSWConfig.h.in @@ -0,0 +1,8 @@ +#ifndef TESTCFG_OBSWCONFIG_H_ +#define TESTCFG_OBSWCONFIG_H_ + + + + + +#endif /* TESTCFG_OBSWCONFIG_H_ */ diff --git a/tests/user/testcfg/TestsConfig.h.in b/tests/user/testcfg/TestsConfig.h.in new file mode 100644 index 000000000..7d9500702 --- /dev/null +++ b/tests/user/testcfg/TestsConfig.h.in @@ -0,0 +1,21 @@ +#ifndef FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_ +#define FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_ + +#define FSFW_ADD_DEFAULT_FACTORY_FUNCTIONS 1 + +#ifdef __cplusplus + +#include "objects/systemObjectList.h" +#include "events/subsystemIdRanges.h" +#include "returnvalues/classIds.h" + +namespace config { +#endif + +/* Add mission configuration flags here */ + +#ifdef __cplusplus +} +#endif + +#endif /* FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_ */ diff --git a/unittest/user/testcfg/devices/logicalAddresses.cpp b/tests/user/testcfg/devices/logicalAddresses.cpp similarity index 100% rename from unittest/user/testcfg/devices/logicalAddresses.cpp rename to tests/user/testcfg/devices/logicalAddresses.cpp diff --git a/unittest/user/testcfg/devices/logicalAddresses.h b/tests/user/testcfg/devices/logicalAddresses.h similarity index 100% rename from unittest/user/testcfg/devices/logicalAddresses.h rename to tests/user/testcfg/devices/logicalAddresses.h diff --git a/unittest/user/testcfg/devices/powerSwitcherList.cpp b/tests/user/testcfg/devices/powerSwitcherList.cpp similarity index 100% rename from unittest/user/testcfg/devices/powerSwitcherList.cpp rename to tests/user/testcfg/devices/powerSwitcherList.cpp diff --git a/unittest/user/testcfg/devices/powerSwitcherList.h b/tests/user/testcfg/devices/powerSwitcherList.h similarity index 100% rename from unittest/user/testcfg/devices/powerSwitcherList.h rename to tests/user/testcfg/devices/powerSwitcherList.h diff --git a/unittest/user/testcfg/events/subsystemIdRanges.h b/tests/user/testcfg/events/subsystemIdRanges.h similarity index 100% rename from unittest/user/testcfg/events/subsystemIdRanges.h rename to tests/user/testcfg/events/subsystemIdRanges.h diff --git a/unittest/user/testcfg/ipc/MissionMessageTypes.cpp b/tests/user/testcfg/ipc/MissionMessageTypes.cpp similarity index 100% rename from unittest/user/testcfg/ipc/MissionMessageTypes.cpp rename to tests/user/testcfg/ipc/MissionMessageTypes.cpp diff --git a/unittest/user/testcfg/ipc/MissionMessageTypes.h b/tests/user/testcfg/ipc/MissionMessageTypes.h similarity index 100% rename from unittest/user/testcfg/ipc/MissionMessageTypes.h rename to tests/user/testcfg/ipc/MissionMessageTypes.h diff --git a/unittest/user/testcfg/objects/systemObjectList.h b/tests/user/testcfg/objects/systemObjectList.h similarity index 86% rename from unittest/user/testcfg/objects/systemObjectList.h rename to tests/user/testcfg/objects/systemObjectList.h index 76f1ff90c..efd21e0de 100644 --- a/unittest/user/testcfg/objects/systemObjectList.h +++ b/tests/user/testcfg/objects/systemObjectList.h @@ -15,14 +15,17 @@ namespace objects { PUS_DISTRIBUTOR = 11, TM_FUNNEL = 12, - TCPIP_BRIDGE = 15, - TCPIP_HELPER = 16, + UDP_BRIDGE = 15, + UDP_POLLING_TASK = 16, TEST_ECHO_COM_IF = 20, TEST_DEVICE = 21, HK_RECEIVER_MOCK = 22, - TEST_LOCAL_POOL_OWNER_BASE = 25 + TEST_LOCAL_POOL_OWNER_BASE = 25, + + SHARED_SET_ID = 26 + }; } diff --git a/tests/user/testcfg/pollingsequence/PollingSequenceFactory.cpp b/tests/user/testcfg/pollingsequence/PollingSequenceFactory.cpp new file mode 100644 index 000000000..e3ee874a4 --- /dev/null +++ b/tests/user/testcfg/pollingsequence/PollingSequenceFactory.cpp @@ -0,0 +1,39 @@ +#include "PollingSequenceFactory.h" + +#include + +#include +#include +#include + +ReturnValue_t pst::pollingSequenceInitDefault( + FixedTimeslotTaskIF *thisSequence) { + /* Length of a communication cycle */ + uint32_t length = thisSequence->getPeriodMs(); + + /* Add polling sequence table here */ + thisSequence->addSlot(objects::TEST_DEVICE, 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::TEST_DEVICE, 0.3, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::TEST_DEVICE, 0.45 * length, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::TEST_DEVICE, 0.6 * length, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::TEST_DEVICE, 0.8 * length, + DeviceHandlerIF::GET_READ); + + if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { + return HasReturnvaluesIF::RETURN_OK; + } + else { +#if FSFW_CPP_OSTREAM_ENABLED + sif::error << "pst::pollingSequenceInitDefault: Sequence invalid!" + << std::endl; +#else + sif::printError("pst::pollingSequenceInitDefault: Sequence invalid!"); +#endif + return HasReturnvaluesIF::RETURN_FAILED; + } +} + diff --git a/unittest/user/testcfg/pollingsequence/PollingSequenceFactory.h b/tests/user/testcfg/pollingsequence/PollingSequenceFactory.h similarity index 100% rename from unittest/user/testcfg/pollingsequence/PollingSequenceFactory.h rename to tests/user/testcfg/pollingsequence/PollingSequenceFactory.h diff --git a/unittest/user/testcfg/returnvalues/classIds.h b/tests/user/testcfg/returnvalues/classIds.h similarity index 100% rename from unittest/user/testcfg/returnvalues/classIds.h rename to tests/user/testcfg/returnvalues/classIds.h diff --git a/unittest/user/testcfg/tmtc/apid.h b/tests/user/testcfg/tmtc/apid.h similarity index 100% rename from unittest/user/testcfg/tmtc/apid.h rename to tests/user/testcfg/tmtc/apid.h diff --git a/unittest/user/testcfg/tmtc/pusIds.h b/tests/user/testcfg/tmtc/pusIds.h similarity index 100% rename from unittest/user/testcfg/tmtc/pusIds.h rename to tests/user/testcfg/tmtc/pusIds.h diff --git a/unittest/user/testtemplate/TestTemplate.cpp b/tests/user/testtemplate/TestTemplate.cpp similarity index 100% rename from unittest/user/testtemplate/TestTemplate.cpp rename to tests/user/testtemplate/TestTemplate.cpp diff --git a/timemanager/CMakeLists.txt b/timemanager/CMakeLists.txt deleted file mode 100644 index 70dd41fa6..000000000 --- a/timemanager/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -target_sources(${LIB_FSFW_NAME} - PRIVATE - CCSDSTime.cpp - Countdown.cpp - Stopwatch.cpp - TimeMessage.cpp - TimeStamper.cpp - ClockCommon.cpp -) diff --git a/timemanager/Countdown.cpp b/timemanager/Countdown.cpp deleted file mode 100644 index 20b56189f..000000000 --- a/timemanager/Countdown.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "Countdown.h" - -Countdown::Countdown(uint32_t initialTimeout): timeout(initialTimeout) { -} - -Countdown::~Countdown() { -} - -ReturnValue_t Countdown::setTimeout(uint32_t miliseconds) { - ReturnValue_t return_value = Clock::getUptime( &startTime ); - timeout = miliseconds; - return return_value; -} - -bool Countdown::hasTimedOut() const { - uint32_t current_time; - Clock::getUptime( ¤t_time ); - if ( uint32_t(current_time - startTime) >= timeout) { - return true; - } else { - return false; - } -} - -bool Countdown::isBusy() const { - return !hasTimedOut(); -} - -ReturnValue_t Countdown::resetTimer() { - return setTimeout(timeout); -} - -void Countdown::timeOut() { - uint32_t current_time; - Clock::getUptime( ¤t_time ); - startTime= current_time - timeout; -} diff --git a/timemanager/Countdown.h b/timemanager/Countdown.h deleted file mode 100644 index f6a41e73d..000000000 --- a/timemanager/Countdown.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef FSFW_TIMEMANAGER_COUNTDOWN_H_ -#define FSFW_TIMEMANAGER_COUNTDOWN_H_ - -#include "Clock.h" - -/** - * @brief This file defines the Countdown class. - * @author baetz - */ -class Countdown { -public: - uint32_t timeout; - Countdown(uint32_t initialTimeout = 0); - ~Countdown(); - ReturnValue_t setTimeout(uint32_t miliseconds); - - bool hasTimedOut() const; - - bool isBusy() const; - - //!< Use last set timeout value and restart timer. - ReturnValue_t resetTimer(); - - //!< Make hasTimedOut() return true - void timeOut(); - -private: - uint32_t startTime = 0; -}; - -#endif /* FSFW_TIMEMANAGER_COUNTDOWN_H_ */ diff --git a/tmtcpacket/pus/PacketTimestampInterpreterIF.h b/tmtcpacket/pus/PacketTimestampInterpreterIF.h deleted file mode 100644 index 40e7a2eaa..000000000 --- a/tmtcpacket/pus/PacketTimestampInterpreterIF.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef FRAMEWORK_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_ -#define FRAMEWORK_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_ - -#include "../../returnvalues/HasReturnvaluesIF.h" -class TmPacketMinimal; - -class PacketTimestampInterpreterIF { -public: - virtual ~PacketTimestampInterpreterIF() {} - virtual ReturnValue_t getPacketTime(TmPacketMinimal* packet, - timeval* timestamp) const = 0; - virtual ReturnValue_t getPacketTimeRaw(TmPacketMinimal* packet, const uint8_t** timePtr, uint32_t* size) const = 0; -}; - - - -#endif /* FRAMEWORK_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_ */ diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt deleted file mode 100644 index 24f8ef6ff..000000000 --- a/unittest/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_subdirectory(internal) - -if(LINK_CATCH2) - add_subdirectory(tests) -endif() \ No newline at end of file diff --git a/unittest/internal/InternalUnitTester.cpp b/unittest/internal/InternalUnitTester.cpp deleted file mode 100644 index a9394ad3f..000000000 --- a/unittest/internal/InternalUnitTester.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "InternalUnitTester.h" -#include "UnittDefinitions.h" - -#include "osal/IntTestMq.h" -#include "osal/IntTestSemaphore.h" -#include "osal/IntTestMutex.h" -#include "serialize/IntTestSerialization.h" -#include "globalfunctions/TestArrayPrinter.h" - -#include - -InternalUnitTester::InternalUnitTester() {} - -InternalUnitTester::~InternalUnitTester() {} - -ReturnValue_t InternalUnitTester::performTests(struct InternalUnitTester::TestConfig& testConfig) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Running internal unit tests.." << std::endl; -#else - sif::printInfo("Running internal unit tests..\n"); -#endif - - testserialize::test_serialization(); - testmq::testMq(); - testsemaph::testBinSemaph(); - testsemaph::testCountingSemaph(); - testmutex::testMutex(); - if(testConfig.testArrayPrinter) { - arrayprinter::testArrayPrinter(); - } - -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Internal unit tests finished." << std::endl; -#else - sif::printInfo("Internal unit tests finished.\n"); -#endif - return RETURN_OK; -} - - - diff --git a/unittest/internal/internal.mk b/unittest/internal/internal.mk deleted file mode 100644 index 1d4c9c997..000000000 --- a/unittest/internal/internal.mk +++ /dev/null @@ -1,4 +0,0 @@ -CXXSRC += $(wildcard $(CURRENTPATH)/osal/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/serialize/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/globalfunctions/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/*.cpp) \ No newline at end of file diff --git a/unittest/internal/serialize/CMakeLists.txt b/unittest/internal/serialize/CMakeLists.txt deleted file mode 100644 index e8dc5717f..000000000 --- a/unittest/internal/serialize/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -target_sources(${TARGET_NAME} PRIVATE - IntTestSerialization.cpp -) diff --git a/unittest/tests/CMakeLists.txt b/unittest/tests/CMakeLists.txt deleted file mode 100644 index 180e1a51d..000000000 --- a/unittest/tests/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_subdirectory(action) -add_subdirectory(container) -add_subdirectory(osal) -add_subdirectory(serialize) -add_subdirectory(datapoollocal) -add_subdirectory(storagemanager) - diff --git a/unittest/tests/tests.mk b/unittest/tests/tests.mk deleted file mode 100644 index 47e634a26..000000000 --- a/unittest/tests/tests.mk +++ /dev/null @@ -1,8 +0,0 @@ -CXXSRC += $(wildcard $(CURRENTPATH)/container/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/action/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/serialize/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/storagemanager/*.cpp) - -# OSAL not included for now. - -INCLUDES += $(CURRENTPATH) \ No newline at end of file diff --git a/unittest/user/testcfg/Makefile-FSFW-Tests b/unittest/user/testcfg/Makefile-FSFW-Tests deleted file mode 100644 index 550fd1dee..000000000 --- a/unittest/user/testcfg/Makefile-FSFW-Tests +++ /dev/null @@ -1,416 +0,0 @@ -#------------------------------------------------------------------------------- -# Makefile for FSFW Test -#------------------------------------------------------------------------------- -# User-modifiable options -#------------------------------------------------------------------------------- -# Fundamentals on the build process of C/C++ Software: -# https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html - -# Make documentation: https://www.gnu.org/software/make/manual/make.pdf -# Online: https://www.gnu.org/software/make/manual/make.html -# General rules: http://make.mad-scientist.net/papers/rules-of-makefiles/#rule3 -SHELL = /bin/sh - -# Chip & board used for compilation -# (can be overriden by adding CHIP=chip and BOARD=board to the command-line) -# Unit Test can only be run on host machine for now (Linux) -FRAMEWORK_PATH = fsfw -TEST_FILE_ROOT = $(FRAMEWORK_PATH)/unittest -BOARD = unittest -LINUX = 1 -OS_FSFW = linux -CUSTOM_DEFINES += -D$(OS_FSFW) - -# Copied from stackoverflow, can be used to differentiate between Windows -# and Linux -ifeq ($(OS),Windows_NT) - CUSTOM_DEFINES += -DWIN32 - ifeq ($(PROCESSOR_ARCHITEW6432),AMD64) - CUSTOM_DEFINES += -DAMD64 - else - ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) - CUSTOM_DEFINES += -DAMD64 - endif - ifeq ($(PROCESSOR_ARCHITECTURE),x86) - CUSTOM_DEFINES += -DIA32 - endif - endif -else - UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Linux) - DETECTED_OS = LINUX - CUSTOM_DEFINES += -DLINUX - endif - ifeq ($(UNAME_S),Darwin) - CUSTOM_DEFINES += -DOSX - endif - UNAME_P := $(shell uname -p) - ifeq ($(UNAME_P),x86_64) - CUSTOM_DEFINES += -DAMD64 - endif - ifneq ($(filter %86,$(UNAME_P)),) - CUSTOM_DEFINES += -DIA32 - endif - ifneq ($(filter arm%,$(UNAME_P)),) - CUSTOM_DEFINES += -DARM - endif -endif - -UNIT_TEST = 1 -# General folder paths -CONFIG_PATH = testcfg -# Core copy has to be copied as well. -CORE_PATH = core -UNIT_TEST_PATH = $(TEST_FILE_ROOT)/tests - -# Output file basename -BASENAME = fsfw -BINARY_NAME := $(BASENAME)-$(BOARD) -# Output files will be put in this directory inside -OUTPUT_FOLDER = $(OS) - -# Optimization level. Optimized for debugging. -OPTIMIZATION = -O0 - -# Default debug output. Optimized for debugging. -DEBUG_LEVEL = -g3 - -ifdef GCOV -CUSTOM_DEFINES += -DGCOV -endif - - -# Output directories -BUILDPATH = _bin -DEPENDPATH = _dep -OBJECTPATH = _obj - -ifeq ($(MAKECMDGOALS),mission) -BUILD_FOLDER = mission -else -BUILD_FOLDER = devel -endif - -DEPENDDIR = $(DEPENDPATH)/$(OUTPUT_FOLDER)/$(BUILD_FOLDER) -OBJDIR = $(OBJECTPATH)/$(OUTPUT_FOLDER)/$(BUILD_FOLDER) -BINDIR = $(BUILDPATH) - -CLEANDEP = $(DEPENDPATH)/$(OUTPUT_FOLDER) -CLEANOBJ = $(OBJECTPATH)/$(OUTPUT_FOLDER) -CLEANBIN = $(BUILDPATH) -#------------------------------------------------------------------------------- -# Tools and Includes -#------------------------------------------------------------------------------- - -# Tool suffix when cross-compiling -CROSS_COMPILE = - -# C Compiler -CC = $(CROSS_COMPILE)gcc - -# C++ compiler -CXX = $(CROSS_COMPILE)g++ - -# Additional Tools -SIZE = $(CROSS_COMPILE)size -STRIP = $(CROSS_COMPILE)strip -CP = $(CROSS_COMPILE)objcopy - -HEXCOPY = $(CP) -O ihex -BINCOPY = $(CP) -O binary -# files to be compiled, will be filled in by include makefiles -# := assignment is neccessary so we get all paths right -# https://www.gnu.org/software/make/manual/html_node/Flavors.html -CSRC := -CXXSRC := -ASRC := -INCLUDES := - -# Directories where $(directoryname).mk files should be included from -SUBDIRS := $(FRAMEWORK_PATH) $(TEST_PATH) $(UNIT_TEST_PATH) $(CONFIG_PATH) \ - $(CORE_PATH) - - -I_INCLUDES += $(addprefix -I, $(INCLUDES)) - -# This is a hack from http://make.mad-scientist.net/the-eval-function/ -# -# The problem is, that included makefiles should be aware of their relative path -# but not need to guess or hardcode it. So we set $(CURRENTPATH) for them. If -# we do this globally and the included makefiles want to include other makefiles as -# well, they would overwrite $(CURRENTPATH), screwing the include after them. -# -# By using a for-loop with an eval'd macro, we can generate the code to include all -# sub-makefiles (with the correct $(CURRENTPATH) set) before actually evaluating -# (and by this possibly changing $(CURRENTPATH)) them. -# -# This works recursively, if an included makefile wants to include, it can safely set -# $(SUBDIRS) (which has already been evaluated here) and do -# "$(foreach S,$(SUBDIRS),$(eval $(INCLUDE_FILE)))" -# $(SUBDIRS) must be relative to the project root, so to include subdir foo, set -# $(SUBDIRS) = $(CURRENTPATH)/foo. -define INCLUDE_FILE -CURRENTPATH := $S -include $(S)/$(notdir $S).mk -endef -$(foreach S,$(SUBDIRS),$(eval $(INCLUDE_FILE))) - -INCLUDES += $(TEST_FILE_ROOT) -INCLUDES += $(TEST_FILE_ROOT)/catch2/ - -#------------------------------------------------------------------------------- -# Source Files -#------------------------------------------------------------------------------- - -# All source files which are not includes by the .mk files are added here -# Please ensure that no files are included by both .mk file and here ! - -# if a target is not listed in the current directory, -# make searches in the directories specified with VPATH - -# All C Sources included by .mk files are assigned here -# Add the objects to sources so dependency handling works -C_OBJECTS += $(CSRC:.c=.o) - -# Objects built from Assembly source files -ASM_OBJECTS = $(ASRC:.S=.o) - -# Objects built from C++ source files -CXX_OBJECTS += $(CXXSRC:.cpp=.o) - -#------------------------------------------------------------------------------- -# Build Configuration + Output -#------------------------------------------------------------------------------- - -TARGET = Debug build. -DEBUG_MESSAGE = Off -OPTIMIZATION_MESSAGE = Off - -# Define Messages -MSG_INFO = Software: Hosted unittest \(Catch2\) for the FSFW. -MSG_OPTIMIZATION = Optimization: $(OPTIMIZATION), $(OPTIMIZATION_MESSAGE) -MSG_TARGET = Target Build: $(TARGET) -MSG_DEBUG = Debug level: $(DEBUG_LEVEL), FSFW Debugging: $(DEBUG_MESSAGE) - -MSG_LINKING = Linking: -MSG_COMPILING = Compiling: -MSG_ASSEMBLING = Assembling: -MSG_DEPENDENCY = Collecting dependencies for: -MSG_BINARY = Generate binary: - -# See https://stackoverflow.com/questions/6687630/how-to-remove-unused-c-c-symbols-with-gcc-and-ld -# Used to throw away unused code. Reduces code size significantly ! -# -Wl,--gc-sections: needs to be passed to the linker to throw aways unused code -ifdef KEEP_UNUSED_CODE -PROTOTYPE_OPTIMIZATION = -UNUSED_CODE_REMOVAL = -else -PROTOTYPE_OPTIMIZATION = -ffunction-sections -fdata-sections -UNUSED_CODE_REMOVAL = -Wl,--gc-sections -# Link time optimization -# See https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html for reference -# Link time is larger and size of object files can not be retrieved -# but resulting binary is smaller. Could be used in mission/deployment build -# Requires -ffunction-section in linker call -LINK_TIME_OPTIMIZATION = -flto -OPTIMIZATION += $(PROTOTYPE_OPTIMIZATION) -endif - -# Dependency Flags -# These flags tell the compiler to build dependencies -# See: https://www.gnu.org/software/make/manual/html_node/Automatic-Prerequisites.html -# Using following guide: http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#combine -DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPENDDIR)/$*.d - -# Flags for the compiler call -# - std: Which C++ version to use. Common versions: c++11, c++14 and c++17 -# - Wall: enable all warnings -# - Wextra: enable extra warnings -# - g: defines debug level -# - fmessage-length: to control the formatting algorithm for diagnostic messages; -# =0 means no line-wrapping is done; each error message appears on a single line -# - fno-exceptions: stops generating extra code needed to propagate exceptions, -# which can produce significant data size overhead -CUSTOM_DEFINES += -DUNIT_TEST -WARNING_FLAGS = -Wall -Wshadow=local -Wextra -Wimplicit-fallthrough=1 \ - -Wno-unused-parameter - -CXXDEFINES := $(CUSTOM_DEFINES) -CFLAGS += -CXXFLAGS += -I. $(DEBUG_LEVEL) $(WARNING_FLAGS) $(DEPFLAGS) -fmessage-length=0 $(OPTIMIZATION)\ - $(I_INCLUDES) $(CXXDEFINES) -CPPFLAGS += -std=c++11 - -# Flags for the linker call -# LINK_INCLUDES specify the path to used libraries and the linker script -# LINK_LIBRARIES: Link real time support -LDFLAGS := $(DEBUG_LEVEL) $(UNUSED_CODE_REMOVAL) $(OPTIMIZATION) -pthread -LINK_INCLUDES := -LINK_LIBRARIES := - -ifdef LINUX -LINK_LIBRARIES += -lrt -endif - -ifeq ($(OS),Windows_NT) -LINK_LIBRARIES += -lwsock32 -lws2_32 -LDFLASGS += -fuse-ld=lld -endif - -# Gnu Coverage Tools Flags -ifdef GCOV -GCOV_CXXFLAGS = -fprofile-arcs -ftest-coverage --coverage -fno-inline \ - -fno-inline-small-functions -fno-default-inline -CXXFLAGS += $(GCOV_CXXFLAGS) -GCOV_LINKER_LIBS = -lgcov -fprofile-arcs -ftest-coverage -LINK_LIBRARIES += $(GCOV_LINKER_LIBS) -endif - -# $(info $${CXXFLAGS} is [${CXXFLAGS}]) - -#------------------------------------------------------------------------------- -# Rules -#------------------------------------------------------------------------------- -# the call function assigns parameters to temporary variables -# https://www.gnu.org/software/make/manual/make.html#Call-Function -# $(1) = Memory names -# Rules are called for each memory type -# Two Expansion Symbols $$ are to escape the dollar sign for eval. -# See: http://make.mad-scientist.net/the-eval-function/ - -default: all - -# Cleans all files -hardclean: - -rm -rf $(BUILDPATH) - -rm -rf $(OBJECTPATH) - -rm -rf $(DEPENDPATH) - -# Only clean files for current build -clean: - -rm -rf $(CLEANOBJ) - -rm -rf $(CLEANBIN) - -rm -rf $(CLEANDEP) - -# Only clean binaries. Useful for changing the binary type when object files -# are already compiled so complete rebuild is not necessary -cleanbin: - -rm -rf $(CLEANBIN) - -# In this section, the binaries are built for all selected memories -# notestfw: all -all: executable - -# Build target configuration -release: OPTIMIZATION = -Os $(PROTOTYPE_OPTIMIZATION) $(LINK_TIME_OPTIMIZATION) -release: LINK_TIME_OPTIMIZATION = -flto -release: TARGET = Mission build. -release: OPTIMIZATION_MESSAGE = On with Link Time Optimization - -debug: CXXDEFINES += -DDEBUG -debug: TARGET = Debug -debug: DEBUG_MESSAGE = On - -ifndef KEEP_UNUSED_CODE -debug release: OPTIMIZATION_MESSAGE += , no unused code removal -endif - -debug release notestfw: executable - -executable: $(BINDIR)/$(BINARY_NAME).elf - @echo - @echo $(MSG_INFO) - @echo $(MSG_TARGET) - @echo $(MSG_OPTIMIZATION) - @echo $(MSG_DEBUG) - -C_OBJECTS_PREFIXED = $(addprefix $(OBJDIR)/, $(C_OBJECTS)) -CXX_OBJECTS_PREFIXED = $(addprefix $(OBJDIR)/, $(CXX_OBJECTS)) -ASM_OBJECTS_PREFIXED = $(addprefix $(OBJDIR)/, $(ASM_OBJECTS)) -ALL_OBJECTS = $(ASM_OBJECTS_PREFIXED) $(C_OBJECTS_PREFIXED) \ - $(CXX_OBJECTS_PREFIXED) - -# Useful for debugging the Makefile -# Also see: https://www.oreilly.com/openbook/make3/book/ch12.pdf -# $(info $${ALL_OBJECTS} is [${ALL_OBJECTS}]) -# $(info $${CXXSRC} is [${CXXSRC}]) - -# Automatic variables are used here extensively. Some of them -# are escaped($$) to suppress immediate evaluation. The most important ones are: -# $@: Name of Target (left side of rule) -# $<: Name of the first prerequisite (right side of rule) -# @^: List of all prerequisite, omitting duplicates -# @D: Directory and file-within-directory part of $@ - -# Generates binary and displays all build properties -# -p with mkdir ignores error and creates directory when needed. - -# SHOW_DETAILS = 1 - - -# Link with required libraries: HAL (Hardware Abstraction Layer) and -# HCC (File System Library) -$(BINDIR)/$(BINARY_NAME).elf: $(ALL_OBJECTS) - @echo - @echo $(MSG_LINKING) Target $@ - @mkdir -p $(@D) -ifdef SHOW_DETAILS - $(CXX) $(LDFLAGS) $(LINK_INCLUDES) -o $@ $^ $(LINK_LIBRARIES) -else - @$(CXX) $(LDFLAGS) $(LINK_INCLUDES) -o $@ $^ $(LINK_LIBRARIES) -endif -ifeq ($(BUILD_FOLDER), mission) -# With Link Time Optimization, section size is not available - $(SIZE) $@ -else - $(SIZE) $^ $@ -endif - -$(BINDIR)/$(BINARY_NAME).hex: $(BINDIR)/$(BINARY_NAME).elf - @echo - @echo $(MSG_BINARY) - @mkdir -p $(@D) - $(HEXCOPY) $< $@ - -# Build new objects for changed dependencies. -$(OBJDIR)/%.o: %.cpp -$(OBJDIR)/%.o: %.cpp $(DEPENDDIR)/%.d | $(DEPENDDIR) - @echo - @echo $(MSG_COMPILING) $< - @mkdir -p $(@D) -ifdef SHOW_DETAILS - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< -else - @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< -endif - -$(OBJDIR)/%.o: %.c -$(OBJDIR)/%.o: %.c $(DEPENDDIR)/%.d | $(DEPENDDIR) - @echo - @echo $(MSG_COMPILING) $< - @mkdir -p $(@D) -ifdef SHOW_DETAILS - $(CC) $(CXXFLAGS) $(CFLAGS) -c -o $@ $< -else - @$(CC) $(CXXFLAGS) $(CFLAGS) -c -o $@ $< -endif - -#------------------------------------------------------------------------------- -# Dependency Handling -#------------------------------------------------------------------------------- - -# Dependency Handling according to following guide: -# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ -$(DEPENDDIR): - @mkdir -p $(@D) -DEPENDENCY_RELATIVE = $(CSRC:.c=.d) $(CXXSRC:.cpp=.d) -# This is the list of all dependencies -DEPFILES = $(addprefix $(DEPENDDIR)/, $(DEPENDENCY_RELATIVE)) -# Create subdirectories for dependencies -$(DEPFILES): - @mkdir -p $(@D) -# Include all dependencies -include $(wildcard $(DEPFILES)) - -# .PHONY tells make that these targets aren't files -.PHONY: clean release debug all hardclean cleanbin diff --git a/unittest/user/testcfg/TestsConfig.h b/unittest/user/testcfg/TestsConfig.h deleted file mode 100644 index cd967fa73..000000000 --- a/unittest/user/testcfg/TestsConfig.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_ -#define FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_ - - -#define CUSTOM_UNITTEST_RUNNER 0 - - -#endif /* FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_ */ diff --git a/unittest/user/testcfg/cdatapool/dataPoolInit.cpp b/unittest/user/testcfg/cdatapool/dataPoolInit.cpp deleted file mode 100644 index ad2dc4ef5..000000000 --- a/unittest/user/testcfg/cdatapool/dataPoolInit.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "dataPoolInit.h" - -void datapool::dataPoolInit(std::map * poolMap) { - -} diff --git a/unittest/user/testcfg/cdatapool/dataPoolInit.h b/unittest/user/testcfg/cdatapool/dataPoolInit.h deleted file mode 100644 index 9425d7678..000000000 --- a/unittest/user/testcfg/cdatapool/dataPoolInit.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef HOSTED_CONFIG_CDATAPOOL_DATAPOOLINIT_H_ -#define HOSTED_CONFIG_CDATAPOOL_DATAPOOLINIT_H_ - -#include -#include -#include -#include - - -namespace datapool { - void dataPoolInit(std::map * poolMap); - - enum datapoolvariables { - NO_PARAMETER = 0, - }; -} -#endif /* CONFIG_CDATAPOOL_DATAPOOLINIT_H_ */ diff --git a/unittest/user/testcfg/pollingsequence/PollingSequenceFactory.cpp b/unittest/user/testcfg/pollingsequence/PollingSequenceFactory.cpp deleted file mode 100644 index b7f1fb3e1..000000000 --- a/unittest/user/testcfg/pollingsequence/PollingSequenceFactory.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "PollingSequenceFactory.h" - -#include -#include -#include - -ReturnValue_t pst::pollingSequenceInitDefault( - FixedTimeslotTaskIF *thisSequence) { - /* Length of a communication cycle */ - uint32_t length = thisSequence->getPeriodMs(); - - /* Add polling sequence table here */ - - if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { - return HasReturnvaluesIF::RETURN_OK; - } - else { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "pst::pollingSequenceInitDefault: Sequence invalid!" - << std::endl; -#endif - return HasReturnvaluesIF::RETURN_FAILED; - } -} - diff --git a/unittest/user/testcfg/testcfg.mk b/unittest/user/testcfg/testcfg.mk deleted file mode 100644 index fca2f7327..000000000 --- a/unittest/user/testcfg/testcfg.mk +++ /dev/null @@ -1,8 +0,0 @@ -CXXSRC += $(wildcard $(CURRENTPATH)/cdatapool/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/ipc/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/objects/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/pollingsequence/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/events/*.cpp) -CXXSRC += $(wildcard $(CURRENTPATH)/*.cpp) - -INCLUDES += $(CURRENTPATH) diff --git a/unittest/user/unittest/CMakeLists.txt b/unittest/user/unittest/CMakeLists.txt deleted file mode 100644 index ad6d4787c..000000000 --- a/unittest/user/unittest/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(core) diff --git a/unittest/user/unittest/core/CMakeLists.txt b/unittest/user/unittest/core/CMakeLists.txt deleted file mode 100644 index 0989926c3..000000000 --- a/unittest/user/unittest/core/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -target_sources(${TARGET_NAME} PRIVATE - CatchDefinitions.cpp - CatchFactory.cpp - CatchRunner.cpp - CatchSetup.cpp - printChar.cpp -) - -if(CUSTOM_UNITTEST_RUNNER) - target_sources(${TARGET_NAME} PRIVATE - CatchRunner.cpp - ) -endif() \ No newline at end of file diff --git a/unittest/user/unittest/core/CatchFactory.h b/unittest/user/unittest/core/CatchFactory.h deleted file mode 100644 index 024f762ee..000000000 --- a/unittest/user/unittest/core/CatchFactory.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef FSFW_CATCHFACTORY_H_ -#define FSFW_CATCHFACTORY_H_ - -#include - -namespace Factory { - /** - * @brief Creates all SystemObject elements which are persistent - * during execution. - */ - void produce(void* args); - void setStaticFrameworkObjectIds(); - -} - -#endif /* FSFW_CATCHFACTORY_H_ */ diff --git a/unittest/user/unittest/core/core.mk b/unittest/user/unittest/core/core.mk deleted file mode 100644 index 3e5626d33..000000000 --- a/unittest/user/unittest/core/core.mk +++ /dev/null @@ -1,3 +0,0 @@ -CXXSRC += $(wildcard $(CURRENTPATH)/*.cpp) - -INCLUDES += $(CURRENTPATH) \ No newline at end of file diff --git a/unittest/user/unlockRealtime.sh b/unittest/user/unlockRealtime.sh deleted file mode 100644 index b28d54904..000000000 --- a/unittest/user/unlockRealtime.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -# Run this script to unlock all permissions to run the linux binaries -# and create threads - -binaries=$(find $directory -type f -name "*.elf") - -echo Unlocking real time permissions for binaries and bash console... - -# Set up the soft realtime limit to maximum (99) -# Please note that the hard limit needs to be set to 99 too -# for this to work (check with ulimit -Hr). -# If that has not been done yet, add -# hard rtprio 99 -# to /etc/security/limits.conf -# It is also necessary and recommended to add -# soft rtprio 99 -# as well. This can also be done in the command line -# but would need to be done for each session. -ulimit -Sr 99 - -for binary in ${binaries}; do - sudo setcap 'cap_sys_nice=eip' ${binary} - result=$? - if [ ${result} = 0 ];then - echo ${binary} was unlocked - fi -done - -# sudo setcap 'cap_sys_nice=eip' /bin/bash -# result=$? -# if [ ${result} = 0 ];then -# echo /bin/bash was unlocked -# fi -