Compare commits
2 Commits
small-fix-
...
mueller/sp
Author | SHA1 | Date | |
---|---|---|---|
06111ec3ed | |||
51087518b0 |
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,14 +1,6 @@
|
|||||||
# PyCharm and CLion
|
|
||||||
/.idea/*
|
|
||||||
!/.idea/runConfigurations
|
|
||||||
!/.idea/cmake.xml
|
|
||||||
!/.idea/codeStyles
|
|
||||||
|
|
||||||
# Eclipse
|
|
||||||
.cproject
|
.cproject
|
||||||
.project
|
.project
|
||||||
.settings
|
.settings
|
||||||
.metadata
|
.metadata
|
||||||
|
|
||||||
/build*
|
/build*
|
||||||
/cmake-build*
|
|
||||||
|
14
.idea/codeStyles/Project.xml
generated
14
.idea/codeStyles/Project.xml
generated
@ -1,14 +0,0 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<code_scheme name="Project" version="173">
|
|
||||||
<clangFormatSettings>
|
|
||||||
<option name="ENABLED" value="true" />
|
|
||||||
</clangFormatSettings>
|
|
||||||
<codeStyleSettings language="CMake">
|
|
||||||
<indentOptions>
|
|
||||||
<option name="INDENT_SIZE" value="2" />
|
|
||||||
<option name="CONTINUATION_INDENT_SIZE" value="0" />
|
|
||||||
<option name="TAB_SIZE" value="2" />
|
|
||||||
</indentOptions>
|
|
||||||
</codeStyleSettings>
|
|
||||||
</code_scheme>
|
|
||||||
</component>
|
|
5
.idea/codeStyles/codeStyleConfig.xml
generated
5
.idea/codeStyles/codeStyleConfig.xml
generated
@ -1,5 +0,0 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<state>
|
|
||||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
|
||||||
</state>
|
|
||||||
</component>
|
|
112
CHANGELOG.md
112
CHANGELOG.md
@ -8,106 +8,30 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
# [unreleased]
|
# [unreleased]
|
||||||
|
|
||||||
# [v6.0.0]
|
# [v5.0.0]
|
||||||
|
|
||||||
## Added
|
|
||||||
|
|
||||||
- DHB TM handler `handleDeviceTM` renamed to `handleDeviceTm` and now takes
|
|
||||||
`util::DataWrapper` as the data input argument. This allows more flexibility in the possible
|
|
||||||
types of telemetry.
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/669
|
|
||||||
- Add `util::DataWrapper` class inside the `util` module. This is a tagged union which allows
|
|
||||||
to specify raw data either as a classic C-style raw pointer and size or as a `SerializeIF`
|
|
||||||
pointer.
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/668
|
|
||||||
- Add new `UnsignedByteField` class
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/660
|
|
||||||
|
|
||||||
## Changes
|
## Changes
|
||||||
|
|
||||||
- Removed `HasReturnvaluesIF` class in favor of `returnvalue` namespace with `OK` and `FAILED`
|
|
||||||
constants.
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/659
|
|
||||||
- Overhaul of the TMTC stack, including various changes and improvements
|
|
||||||
for other modules
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/655
|
|
||||||
which also includes a migration guide
|
|
||||||
|
|
||||||
# [v5.0.0] 25.07.2022
|
|
||||||
|
|
||||||
## Changes
|
|
||||||
|
|
||||||
- Renamed auto-formatting script to `auto-formatter.sh` and made it more robust.
|
|
||||||
If `cmake-format` is installed, it will also auto-format the `CMakeLists.txt` files now.
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/625
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/626
|
|
||||||
- Bump C++ required version to C++17. Every project which uses the FSFW and every modern
|
- Bump C++ required version to C++17. Every project which uses the FSFW and every modern
|
||||||
compiler supports it
|
compiler supports it
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/622
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/622
|
||||||
|
- HAL Linux SPI: Set the Clock Default State when setting new SPI speed
|
||||||
|
and mode
|
||||||
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/573
|
||||||
|
- GPIO HAL: `Direction`, `GpioOperation` and `Levels` are enum classes now, which prevents
|
||||||
|
name clashes with Windows defines.
|
||||||
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/572
|
||||||
- New CMake option `FSFW_HAL_LINUX_ADD_LIBGPIOD` to specifically exclude `gpiod` code.
|
- New CMake option `FSFW_HAL_LINUX_ADD_LIBGPIOD` to specifically exclude `gpiod` code.
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/572
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/572
|
||||||
- HAL Devicehandlers: Periodic printout is run-time configurable now
|
- HAL Devicehandlers: Periodic printout is run-time configurable now
|
||||||
- `oneShotAction` flag in the `TestTask` class is not static anymore
|
- `oneShotAction` flag in the `TestTask` class is not static anymore
|
||||||
- `SimpleRingBuffer::writeData` now checks if the amount is larger than the total size of the
|
|
||||||
Buffer and rejects such writeData calls with `returnvalue::FAILED`
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/586
|
|
||||||
- Major update for version handling, using `git describe` to fetch version information with git.
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/601
|
|
||||||
- Add helper functions provided by [`cmake-modules`](https://github.com/bilke/cmake-modules)
|
|
||||||
manually now. Those should not change too often and only a small subset is needed
|
|
||||||
- Separate folder for easier update and for distinction
|
|
||||||
- LICENSE file included
|
|
||||||
- use `int` for version numbers to allow unset or uninitialized version
|
|
||||||
- Initialize Version object with numbers set to -1
|
|
||||||
- Instead of hardcoding the git hash, it is now retrieved from git
|
|
||||||
- `Version` now allows specifying additional version information like the git SHA1 hash and the
|
|
||||||
versions since the last tag
|
|
||||||
- Additional information is set to the last part of the git describe output for `FSFW_VERSION` now.
|
|
||||||
- Version still need to be hand-updated if the FSFW is not included as a submodule for now.
|
|
||||||
- IPC Message Queue Handling: Allow passing an optional `MqArgs` argument into the MessageQueue
|
- IPC Message Queue Handling: Allow passing an optional `MqArgs` argument into the MessageQueue
|
||||||
creation call. It allows passing context information and an arbitrary user argument into
|
creation call. It allows passing context information and an arbitrary user argument into
|
||||||
the message queue. Also streamlined and simplified `MessageQueue` implementation for all OSALs
|
the message queue. Also streamlined and simplified `MessageQueue` implementation for all OSALs
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/583
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/583
|
||||||
- Internal API change: Moved the `fsfw_hal` to the `src` folder and integration and internal
|
|
||||||
tests part of `fsfw_tests` to `src`. Unittests are now in a dedicated folder called `unittests`
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/653
|
|
||||||
|
|
||||||
### Task Module Refactoring
|
|
||||||
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/636
|
|
||||||
|
|
||||||
**Refactoring general task code**
|
|
||||||
|
|
||||||
- There was a lot of duplicate/boilerplate code inside the individual task IF OSAL implementations.
|
|
||||||
Remove it by introducing base classes `PeriodicTaskBase` and `FixedTimeslotTaskBase`.
|
|
||||||
|
|
||||||
**Refactor PeriodicTaskIF**
|
|
||||||
|
|
||||||
- Convert `virtual ReturnValue_t addComponent(object_id_t object)` to
|
|
||||||
`virtual ReturnValue_t addComponent(object_id_t object, uint8_t opCode = 0)`, allowing to pass
|
|
||||||
the operation code passed to `performOperation`. Updated API taking
|
|
||||||
an `ExecutableObjectIF` accordingly
|
|
||||||
|
|
||||||
**Refactor FixedTimeslotTaskIF**
|
|
||||||
|
|
||||||
- Add additional `addSlot` function which takes an `ExecutableObjectIF` pointer and its Object ID
|
|
||||||
|
|
||||||
**Refactor FixedSequenceSlot**
|
|
||||||
|
|
||||||
- Introduce typedef `CustomCheckFunc` for `ReturnValue_t (*customCheckFunction)(const SlotList&)`.
|
|
||||||
- Convert `ReturnValue_t (*customCheckFunction)(const SlotList&)` to
|
|
||||||
`ReturnValue_t (*customCheckFunction)(const SlotList&, void*)`, allowing arbitrary user arguments
|
|
||||||
for the custom checker
|
|
||||||
|
|
||||||
**Linux Task Module**
|
|
||||||
|
|
||||||
- Use composition instead of inheritance for the `PeriodicPosixTask` and make the `PosixTask` a
|
|
||||||
member of the class
|
|
||||||
|
|
||||||
### HAL
|
### HAL
|
||||||
|
|
||||||
- HAL Linux Uart: Baudrate and bits per word are enums now, avoiding misconfigurations
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/585
|
|
||||||
- HAL Linux SPI: Set the Clock Default State when setting new SPI speed
|
- HAL Linux SPI: Set the Clock Default State when setting new SPI speed
|
||||||
and mode
|
and mode
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/573
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/573
|
||||||
@ -145,13 +69,6 @@ https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/593
|
|||||||
|
|
||||||
## Additions
|
## Additions
|
||||||
|
|
||||||
- New constructor for PoolEntry which allows to simply specify the length of the pool entry.
|
|
||||||
This is also the new default constructor for scalar value with 0 as an initial value
|
|
||||||
- Added options for CI/CD builds: `FSFW_CICD_BUILD`. This allows the source code to know
|
|
||||||
whether it is running in CI/CD
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/623
|
|
||||||
- Basic `clion` support: Update `.gitignore` and add some basic run configurations
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/625
|
|
||||||
- LTO support: Allow using LTO/IPO by setting `FSFW_ENABLE_LTO=1`. CMake is able to detect whether
|
- LTO support: Allow using LTO/IPO by setting `FSFW_ENABLE_LTO=1`. CMake is able to detect whether
|
||||||
the user compiler supports IPO/LPO. LTO is on by default now. Most modern compilers support it,
|
the user compiler supports IPO/LPO. LTO is on by default now. Most modern compilers support it,
|
||||||
can make good use of it and it usually makes the code faster and/or smaller.
|
can make good use of it and it usually makes the code faster and/or smaller.
|
||||||
@ -166,12 +83,10 @@ https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/593
|
|||||||
- https://gitlab.kitware.com/cmake/cmake/-/issues/21696
|
- https://gitlab.kitware.com/cmake/cmake/-/issues/21696
|
||||||
Easiest solution for now: Keep this option OFF by default.
|
Easiest solution for now: Keep this option OFF by default.
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/616
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/616
|
||||||
|
- Linux HAL: Add wiretapping option for I2C. Enabled with `FSFW_HAL_I2C_WIRETAPPING` defined to 1
|
||||||
- Dedicated Version class and constant `fsfw::FSFW_VERSION` containing version information
|
- Dedicated Version class and constant `fsfw::FSFW_VERSION` containing version information
|
||||||
inside `fsfw/version.h`
|
inside `fsfw/version.h`
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/559
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/559
|
||||||
- Added generic PUS TC Scheduler Service 11. It depends on the new added Emebeded Template Library
|
|
||||||
(ETL) dependency.
|
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/594
|
|
||||||
- Added ETL dependency and improved library dependency management
|
- Added ETL dependency and improved library dependency management
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/592
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/592
|
||||||
- Add a `DummyPowerSwitcher` module which can be useful for test setups when no PCDU is available
|
- Add a `DummyPowerSwitcher` module which can be useful for test setups when no PCDU is available
|
||||||
@ -180,17 +95,6 @@ https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/593
|
|||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/590
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/590
|
||||||
- `Subsystem`: New API to add table and sequence entries
|
- `Subsystem`: New API to add table and sequence entries
|
||||||
|
|
||||||
## HAL
|
|
||||||
|
|
||||||
- SPI: Cache the SPI device in the communication interface. Architecturally, this makes a
|
|
||||||
lot more sense because each ComIF should be responsible for one SPI bus.
|
|
||||||
- SPI: Move the empty transfer to update the line polarity to separate function. This means
|
|
||||||
it is not automatically called when calling the setter function for SPI speed and mode.
|
|
||||||
The user should call this function after locking the CS mutex if multiple SPI devices with
|
|
||||||
differing speeds and modes are attached to one bus.
|
|
||||||
- SPI: Getter functions for SPI speed and mode.
|
|
||||||
- I2C: Add wiretapping option for I2C. Enabled with `FSFW_HAL_I2C_WIRETAPPING` defined to 1.
|
|
||||||
|
|
||||||
## Fixed
|
## Fixed
|
||||||
|
|
||||||
- TCP TMTC Server: `MutexGuard` was not created properly in
|
- TCP TMTC Server: `MutexGuard` was not created properly in
|
||||||
|
148
CMakeLists.txt
148
CMakeLists.txt
@ -1,78 +1,28 @@
|
|||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
set(MSG_PREFIX "fsfw |")
|
|
||||||
|
|
||||||
# Add the cmake folder so the FindSphinx module is found
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
||||||
list(APPEND CMAKE_MODULE_PATH
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-modules/bilke")
|
|
||||||
list(APPEND CMAKE_MODULE_PATH
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-modules/rpavlik")
|
|
||||||
|
|
||||||
# ##############################################################################
|
|
||||||
# Version file handling #
|
|
||||||
# ##############################################################################
|
|
||||||
|
|
||||||
set(FSFW_VERSION_IF_GIT_FAILS 5)
|
|
||||||
set(FSFW_SUBVERSION_IF_GIT_FAILS 0)
|
|
||||||
set(FSFW_REVISION_IF_GIT_FAILS 0)
|
|
||||||
|
|
||||||
set(FSFW_GIT_VER_HANDLING_OK FALSE)
|
|
||||||
# Version handling
|
|
||||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
|
|
||||||
message(STATUS "${MSG_PREFIX} Determining version information with git")
|
|
||||||
include(FsfwHelpers)
|
|
||||||
determine_version_with_git("--exclude" "docker_*")
|
|
||||||
if(GIT_INFO)
|
|
||||||
set(FSFW_GIT_INFO
|
|
||||||
${GIT_INFO}
|
|
||||||
CACHE STRING "Version information retrieved with git describe")
|
|
||||||
list(GET FSFW_GIT_INFO 1 FSFW_VERSION)
|
|
||||||
list(GET FSFW_GIT_INFO 2 FSFW_SUBVERSION)
|
|
||||||
list(GET FSFW_GIT_INFO 3 FSFW_REVISION)
|
|
||||||
list(GET FSFW_GIT_INFO 4 FSFW_VCS_INFO)
|
|
||||||
if(NOT FSFW_VERSION)
|
|
||||||
set(FSFW_VERSION ${FSFW_VERSION_IF_GIT_FAILS})
|
|
||||||
endif()
|
|
||||||
if(NOT FSFW_SUBVERSION)
|
|
||||||
set(FSFW_SUBVERSION ${FSFW_SUBVERSION_IF_GIT_FAILS})
|
|
||||||
endif()
|
|
||||||
if(NOT FSFW_REVISION)
|
|
||||||
set(FSFW_REVISION ${FSFW_REVISION_IF_GIT_FAILS})
|
|
||||||
endif()
|
|
||||||
set(FSFW_GIT_VER_HANDLING_OK TRUE)
|
|
||||||
else()
|
|
||||||
set(FSFW_GIT_VER_HANDLING_OK FALSE)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
if(NOT FSFW_GIT_VER_HANDLING_OK)
|
|
||||||
set(FSFW_VERSION ${FSFW_VERSION_IF_GIT_FAILS})
|
|
||||||
set(FSFW_SUBVERSION ${FSFW_SUBVERSION_IF_GIT_FAILS})
|
|
||||||
set(FSFW_REVISION ${FSFW_REVISION_IF_GIT_FAILS})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(LIB_FSFW_NAME fsfw)
|
set(LIB_FSFW_NAME fsfw)
|
||||||
project(${LIB_FSFW_NAME}
|
project(${LIB_FSFW_NAME})
|
||||||
VERSION ${FSFW_VERSION}.${FSFW_SUBVERSION}.${FSFW_REVISION})
|
|
||||||
|
|
||||||
if(NOT CMAKE_CXX_STANDARD)
|
if(NOT CMAKE_CXX_STANDARD)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
elseif(${CMAKE_CXX_STANDARD} LESS 17)
|
elseif(${CMAKE_CXX_STANDARD} LESS 17)
|
||||||
message(
|
message(FATAL_ERROR "Compiling the FSFW requires a minimum of C++17 support")
|
||||||
FATAL_ERROR
|
|
||||||
"${MSG_PREFIX} Compiling the FSFW requires a minimum of C++17 support")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(FSFW_SOURCES_DIR "${CMAKE_SOURCE_DIR}/src/fsfw")
|
set(FSFW_VERSION 4)
|
||||||
|
set(FSFW_SUBVERSION 0)
|
||||||
|
set(FSFW_REVISION 0)
|
||||||
|
|
||||||
|
# Add the cmake folder so the FindSphinx module is found
|
||||||
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||||
|
|
||||||
set(FSFW_ETL_LIB_NAME etl)
|
set(FSFW_ETL_LIB_NAME etl)
|
||||||
set(FSFW_ETL_LINK_TARGET etl::etl)
|
|
||||||
set(FSFW_ETL_LIB_MAJOR_VERSION
|
set(FSFW_ETL_LIB_MAJOR_VERSION
|
||||||
20
|
20
|
||||||
CACHE STRING "ETL library major version requirement")
|
CACHE STRING "ETL library major version requirement")
|
||||||
set(FSFW_ETL_LIB_VERSION
|
set(FSFW_ETL_LIB_VERSION
|
||||||
${FSFW_ETL_LIB_MAJOR_VERSION}.28.0
|
${FSFW_ETL_LIB_MAJOR_VERSION}.27.3
|
||||||
CACHE STRING "ETL library exact version requirement")
|
CACHE STRING "ETL library exact version requirement")
|
||||||
set(FSFW_ETL_LINK_TARGET etl::etl)
|
set(FSFW_ETL_LINK_TARGET etl::etl)
|
||||||
|
|
||||||
@ -104,11 +54,10 @@ if(FSFW_GENERATE_SECTIONS)
|
|||||||
option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON)
|
option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(FSFW_BUILD_TESTS "Build unittest binary in addition to static library"
|
option(FSFW_BUILD_UNITTESTS
|
||||||
OFF)
|
"Build unittest binary in addition to static library" OFF)
|
||||||
option(FSFW_CICD_BUILD "Build for CI/CD. This can disable problematic test" OFF)
|
|
||||||
option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF)
|
option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF)
|
||||||
if(FSFW_BUILD_TESTS)
|
if(FSFW_BUILD_UNITTESTS)
|
||||||
option(FSFW_TESTS_GEN_COV "Generate coverage data for unittests" ON)
|
option(FSFW_TESTS_GEN_COV "Generate coverage data for unittests" ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -118,12 +67,6 @@ option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON)
|
|||||||
option(FSFW_ADD_UNITTESTS "Add regular unittests. Requires Catch2" OFF)
|
option(FSFW_ADD_UNITTESTS "Add regular unittests. Requires Catch2" OFF)
|
||||||
option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON)
|
option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON)
|
||||||
|
|
||||||
if(UNIX)
|
|
||||||
option(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS "Add Linux peripheral drivers"
|
|
||||||
OFF)
|
|
||||||
option(FSFW_HAL_LINUX_ADD_LIBGPIOD "Attempt to add Linux GPIOD drivers" OFF)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Optional sources
|
# Optional sources
|
||||||
option(FSFW_ADD_PUS "Compile with PUS sources" ON)
|
option(FSFW_ADD_PUS "Compile with PUS sources" ON)
|
||||||
option(FSFW_ADD_MONITORING "Compile with monitoring components" ON)
|
option(FSFW_ADD_MONITORING "Compile with monitoring components" ON)
|
||||||
@ -146,18 +89,16 @@ if(IPO_SUPPORTED AND FSFW_ENABLE_IPO)
|
|||||||
TRUE)
|
TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FSFW_BUILD_TESTS)
|
if(FSFW_BUILD_UNITTESTS)
|
||||||
message(
|
message(
|
||||||
STATUS
|
STATUS "Building the FSFW unittests in addition to the static library")
|
||||||
"${MSG_PREFIX} Building the FSFW unittests in addition to the static library"
|
|
||||||
)
|
|
||||||
# Check whether the user has already installed Catch2 first
|
# Check whether the user has already installed Catch2 first
|
||||||
find_package(Catch2 ${FSFW_CATCH2_LIB_MAJOR_VERSION})
|
find_package(Catch2 ${FSFW_CATCH2_LIB_MAJOR_VERSION})
|
||||||
# Not installed, so use FetchContent to download and provide Catch2
|
# Not installed, so use FetchContent to download and provide Catch2
|
||||||
if(NOT Catch2_FOUND)
|
if(NOT Catch2_FOUND)
|
||||||
message(
|
message(
|
||||||
STATUS
|
STATUS
|
||||||
"${MSG_PREFIX} Catch2 installation not found. Downloading Catch2 library with FetchContent"
|
"Catch2 installation not found. Downloading Catch2 library with FetchContent"
|
||||||
)
|
)
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
@ -169,9 +110,10 @@ if(FSFW_BUILD_TESTS)
|
|||||||
list(APPEND FSFW_FETCH_CONTENT_TARGETS Catch2)
|
list(APPEND FSFW_FETCH_CONTENT_TARGETS Catch2)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(FSFW_CONFIG_PATH unittests/testcfg)
|
set(FSFW_CONFIG_PATH tests/src/fsfw_tests/unit/testcfg)
|
||||||
configure_file(unittests/testcfg/FSFWConfig.h.in FSFWConfig.h)
|
configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in FSFWConfig.h)
|
||||||
configure_file(unittests/testcfg/TestsConfig.h.in tests/TestsConfig.h)
|
configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in
|
||||||
|
tests/TestsConfig.h)
|
||||||
|
|
||||||
project(${FSFW_TEST_TGT} CXX C)
|
project(${FSFW_TEST_TGT} CXX C)
|
||||||
add_executable(${FSFW_TEST_TGT})
|
add_executable(${FSFW_TEST_TGT})
|
||||||
@ -181,26 +123,28 @@ if(FSFW_BUILD_TESTS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FSFW_TESTS_GEN_COV)
|
if(FSFW_TESTS_GEN_COV)
|
||||||
message(STATUS "${MSG_PREFIX} Generating coverage data for the library")
|
message(STATUS "Generating coverage data for the library")
|
||||||
message(STATUS "${MSG_PREFIX} Targets linking against ${LIB_FSFW_NAME} "
|
message(STATUS "Targets linking against ${LIB_FSFW_NAME} "
|
||||||
"will be compiled with coverage data as well")
|
"will be compiled with coverage data as well")
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
cmake-modules GIT_REPOSITORY https://github.com/bilke/cmake-modules.git)
|
||||||
|
FetchContent_MakeAvailable(cmake-modules)
|
||||||
set(CMAKE_BUILD_TYPE "Debug")
|
set(CMAKE_BUILD_TYPE "Debug")
|
||||||
|
list(APPEND CMAKE_MODULE_PATH ${cmake-modules_SOURCE_DIR})
|
||||||
include(CodeCoverage)
|
include(CodeCoverage)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message(
|
message(STATUS "Finding and/or providing ETL library")
|
||||||
STATUS
|
|
||||||
"${MSG_PREFIX} Finding and/or providing etl library with version ${FSFW_ETL_LIB_MAJOR_VERSION}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check whether the user has already installed ETL first
|
# Check whether the user has already installed ETL first
|
||||||
find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} CONFIG QUIET)
|
find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} QUIET)
|
||||||
# Not installed, so use FetchContent to download and provide etl
|
# Not installed, so use FetchContent to download and provide etl
|
||||||
if(NOT ${FSFW_ETL_LIB_NAME}_FOUND)
|
if(NOT ${FSFW_ETL_LIB_NAME}_FOUND)
|
||||||
message(
|
message(
|
||||||
STATUS
|
STATUS
|
||||||
"${MSG_PREFIX} No ETL installation was found with find_package. Installing and providing "
|
"No ETL installation was found with find_package. Installing and providing "
|
||||||
"etl with FindPackage")
|
"etl with FindPackage")
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
@ -238,9 +182,7 @@ target_include_directories(${LIB_FSFW_NAME}
|
|||||||
|
|
||||||
# Backwards comptability
|
# Backwards comptability
|
||||||
if(OS_FSFW AND NOT FSFW_OSAL)
|
if(OS_FSFW AND NOT FSFW_OSAL)
|
||||||
message(
|
message(WARNING "Please pass the FSFW OSAL as FSFW_OSAL instead of OS_FSFW")
|
||||||
WARNING
|
|
||||||
"${MSG_PREFIX} Please pass the FSFW OSAL as FSFW_OSAL instead of OS_FSFW")
|
|
||||||
set(FSFW_OSAL OS_FSFW)
|
set(FSFW_OSAL OS_FSFW)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -256,6 +198,7 @@ if(NOT FSFW_OSAL)
|
|||||||
"host"
|
"host"
|
||||||
CACHE STRING "OS abstraction layer used in the FSFW")
|
CACHE STRING "OS abstraction layer used in the FSFW")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(FSFW_OSAL_DEFINITION FSFW_OSAL_HOST)
|
set(FSFW_OSAL_DEFINITION FSFW_OSAL_HOST)
|
||||||
@ -275,9 +218,7 @@ elseif(FSFW_OSAL STREQUAL rtems)
|
|||||||
set(FSFW_OSAL_RTEMS ON)
|
set(FSFW_OSAL_RTEMS ON)
|
||||||
else()
|
else()
|
||||||
message(
|
message(
|
||||||
WARNING
|
WARNING "Invalid operating system for FSFW specified! Setting to host..")
|
||||||
"${MSG_PREFIX} Invalid operating system for FSFW specified! Setting to host.."
|
|
||||||
)
|
|
||||||
set(FSFW_OS_NAME "Host")
|
set(FSFW_OS_NAME "Host")
|
||||||
set(OS_FSFW "host")
|
set(OS_FSFW "host")
|
||||||
endif()
|
endif()
|
||||||
@ -285,20 +226,19 @@ endif()
|
|||||||
configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h)
|
configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h)
|
||||||
configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h)
|
configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h)
|
||||||
|
|
||||||
message(
|
message(STATUS "Compiling FSFW for the ${FSFW_OS_NAME} operating system.")
|
||||||
STATUS "${MSG_PREFIX} Compiling FSFW for the ${FSFW_OS_NAME} operating system"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
add_subdirectory(contrib)
|
add_subdirectory(tests)
|
||||||
if(FSFW_BUILD_TESTS)
|
if(FSFW_ADD_HAL)
|
||||||
add_subdirectory(unittests)
|
add_subdirectory(hal)
|
||||||
endif()
|
endif()
|
||||||
|
add_subdirectory(contrib)
|
||||||
if(FSFW_BUILD_DOCS)
|
if(FSFW_BUILD_DOCS)
|
||||||
add_subdirectory(docs)
|
add_subdirectory(docs)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FSFW_BUILD_TESTS)
|
if(FSFW_BUILD_UNITTESTS)
|
||||||
if(FSFW_TESTS_GEN_COV)
|
if(FSFW_TESTS_GEN_COV)
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
include(CodeCoverage)
|
include(CodeCoverage)
|
||||||
@ -358,12 +298,8 @@ endif()
|
|||||||
if(NOT FSFW_CONFIG_PATH)
|
if(NOT FSFW_CONFIG_PATH)
|
||||||
set(DEF_CONF_PATH misc/defaultcfg/fsfwconfig)
|
set(DEF_CONF_PATH misc/defaultcfg/fsfwconfig)
|
||||||
if(NOT FSFW_BUILD_DOCS)
|
if(NOT FSFW_BUILD_DOCS)
|
||||||
message(
|
message(WARNING "Flight Software Framework configuration path not set!")
|
||||||
WARNING
|
message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..")
|
||||||
"${MSG_PREFIX} Flight Software Framework configuration path not set")
|
|
||||||
message(
|
|
||||||
WARNING
|
|
||||||
"${MSG_PREFIX} Setting default configuration from ${DEF_CONF_PATH} ..")
|
|
||||||
endif()
|
endif()
|
||||||
add_subdirectory(${DEF_CONF_PATH})
|
add_subdirectory(${DEF_CONF_PATH})
|
||||||
set(FSFW_CONFIG_PATH ${DEF_CONF_PATH})
|
set(FSFW_CONFIG_PATH ${DEF_CONF_PATH})
|
||||||
@ -455,8 +391,8 @@ target_include_directories(
|
|||||||
target_compile_options(${LIB_FSFW_NAME} PRIVATE ${FSFW_WARNING_FLAGS}
|
target_compile_options(${LIB_FSFW_NAME} PRIVATE ${FSFW_WARNING_FLAGS}
|
||||||
${COMPILER_FLAGS})
|
${COMPILER_FLAGS})
|
||||||
|
|
||||||
target_link_libraries(${LIB_FSFW_NAME} PRIVATE ${FSFW_ADDITIONAL_LINK_LIBS})
|
target_link_libraries(${LIB_FSFW_NAME} PRIVATE ${FSFW_ETL_LINK_TARGET}
|
||||||
target_link_libraries(${LIB_FSFW_NAME} PUBLIC ${FSFW_ETL_LINK_TARGET})
|
${FSFW_ADDITIONAL_LINK_LIBS})
|
||||||
|
|
||||||
string(
|
string(
|
||||||
CONCAT
|
CONCAT
|
||||||
|
13
README.md
13
README.md
@ -99,7 +99,7 @@ add and link against the FSFW library in general.
|
|||||||
|
|
||||||
4. Link against the FSFW library
|
4. Link against the FSFW library
|
||||||
|
|
||||||
```sh
|
```cmake
|
||||||
target_link_libraries(${YourProjectName} PRIVATE fsfw)
|
target_link_libraries(${YourProjectName} PRIVATE fsfw)
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -131,15 +131,15 @@ default. This can be disabled by setting the `FSFW_TESTS_COV_GEN` option to `OFF
|
|||||||
You can use the following commands inside the `fsfw` folder to set up the build system
|
You can use the following commands inside the `fsfw` folder to set up the build system
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
mkdir build-tests && cd build-tests
|
mkdir build-Unittest && cd build-Unittest
|
||||||
cmake -DFSFW_BUILD_TESTS=ON -DFSFW_OSAL=host -DCMAKE_BUILD_TYPE=Debug ..
|
cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host -DCMAKE_BUILD_TYPE=Debug ..
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also use `-DFSFW_OSAL=linux` on Linux systems.
|
You can also use `-DFSFW_OSAL=linux` on Linux systems.
|
||||||
|
|
||||||
Coverage data in HTML format can be generated using the `CodeCoverage`
|
Coverage data in HTML format can be generated using the `CodeCoverage`
|
||||||
[CMake module](https://github.com/bilke/cmake-modules/tree/master).
|
[CMake module](https://github.com/bilke/cmake-modules/tree/master).
|
||||||
To build the unittests, run them and then generate the coverage data in this format,
|
To build the unittests, run them and then generare the coverage data in this format,
|
||||||
the following command can be used inside the build directory after the build system was set up
|
the following command can be used inside the build directory after the build system was set up
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@ -188,10 +188,7 @@ and open the documentation conveniently. Try `helper.py -h for more information.
|
|||||||
|
|
||||||
The formatting is done by the `clang-format` tool. The configuration is contained within the
|
The formatting is done by the `clang-format` tool. The configuration is contained within the
|
||||||
`.clang-format` file in the repository root. As long as `clang-format` is installed, you
|
`.clang-format` file in the repository root. As long as `clang-format` is installed, you
|
||||||
can run the `auto-format.sh` helper script to format all source files consistently. Furthermore cmake-format is required to format CMake files which can be installed with:
|
can run the `apply-clang-format.sh` helper script to format all source files consistently.
|
||||||
````sh
|
|
||||||
sudo pip install cmakelang
|
|
||||||
````
|
|
||||||
|
|
||||||
## Index
|
## Index
|
||||||
|
|
||||||
|
@ -12,9 +12,3 @@ RUN git clone https://github.com/catchorg/Catch2.git && \
|
|||||||
git checkout v3.0.0-preview5 && \
|
git checkout v3.0.0-preview5 && \
|
||||||
cmake -Bbuild -H. -DBUILD_TESTING=OFF && \
|
cmake -Bbuild -H. -DBUILD_TESTING=OFF && \
|
||||||
cmake --build build/ --target install
|
cmake --build build/ --target install
|
||||||
|
|
||||||
RUN git clone https://github.com/ETLCPP/etl.git && \
|
|
||||||
cd etl && \
|
|
||||||
git checkout 20.28.0 && \
|
|
||||||
cmake -B build . && \
|
|
||||||
cmake --install build/
|
|
||||||
|
6
automation/Jenkinsfile
vendored
6
automation/Jenkinsfile
vendored
@ -1,9 +1,9 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
environment {
|
environment {
|
||||||
BUILDDIR = 'cmake-build-tests'
|
BUILDDIR = 'build-tests'
|
||||||
}
|
}
|
||||||
agent {
|
agent {
|
||||||
docker { image 'fsfw-ci:d3'}
|
docker { image 'fsfw-ci:d2'}
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Clean') {
|
stage('Clean') {
|
||||||
@ -14,7 +14,7 @@ pipeline {
|
|||||||
stage('Configure') {
|
stage('Configure') {
|
||||||
steps {
|
steps {
|
||||||
dir(BUILDDIR) {
|
dir(BUILDDIR) {
|
||||||
sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_TESTS=ON -DFSFW_CICD_BUILD=ON ..'
|
sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
# Determines the git version with git describe and returns it by setting
|
|
||||||
# the GIT_INFO list in the parent scope. The list has the following entries
|
|
||||||
# 1. Full version string
|
|
||||||
# 2. Major version
|
|
||||||
# 3. Minor version
|
|
||||||
# 4. Revision
|
|
||||||
# 5. git SHA hash and commits since tag
|
|
||||||
function(determine_version_with_git)
|
|
||||||
include(GetGitRevisionDescription)
|
|
||||||
git_describe(VERSION ${ARGN})
|
|
||||||
string(FIND ${VERSION} "." VALID_VERSION)
|
|
||||||
if(VALID_VERSION EQUAL -1)
|
|
||||||
message(WARNING "Version string ${VERSION} retrieved with git describe is invalid")
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
# Parse the version information into pieces.
|
|
||||||
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" _VERSION_MAJOR "${VERSION}")
|
|
||||||
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" _VERSION_MINOR "${VERSION}")
|
|
||||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" _VERSION_PATCH "${VERSION}")
|
|
||||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
|
|
||||||
set(GIT_INFO ${VERSION})
|
|
||||||
list(APPEND GIT_INFO ${_VERSION_MAJOR})
|
|
||||||
list(APPEND GIT_INFO ${_VERSION_MINOR})
|
|
||||||
list(APPEND GIT_INFO ${_VERSION_PATCH})
|
|
||||||
list(APPEND GIT_INFO ${VERSION_SHA1})
|
|
||||||
set(GIT_INFO ${GIT_INFO} PARENT_SCOPE)
|
|
||||||
message(STATUS "${MSG_PREFIX} Set git version info into GIT_INFO from the git tag ${VERSION}")
|
|
||||||
endfunction()
|
|
@ -1,7 +0,0 @@
|
|||||||
The files in the `bilke` folder were manually copy and pasted from the
|
|
||||||
[cmake-modules repository](https://github.com/bilke/cmake-modules). It was decided to do
|
|
||||||
this because only a small subset of its provided functions are needed.
|
|
||||||
|
|
||||||
The files in the `rpavlik` folder were manually copy and pasted from the
|
|
||||||
[cmake-modules repository](https://github.com/rpavlik/cmake-modules). It was decided to do
|
|
||||||
this because only a small subset of its provided functions are needed.
|
|
@ -1,719 +0,0 @@
|
|||||||
# Copyright (c) 2012 - 2017, Lars Bilke
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
# are permitted provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
# list of conditions and the following disclaimer.
|
|
||||||
#
|
|
||||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
# this list of conditions and the following disclaimer in the documentation
|
|
||||||
# and/or other materials provided with the distribution.
|
|
||||||
#
|
|
||||||
# 3. Neither the name of the copyright holder nor the names of its contributors
|
|
||||||
# may be used to endorse or promote products derived from this software without
|
|
||||||
# specific prior written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
#
|
|
||||||
# CHANGES:
|
|
||||||
#
|
|
||||||
# 2012-01-31, Lars Bilke
|
|
||||||
# - Enable Code Coverage
|
|
||||||
#
|
|
||||||
# 2013-09-17, Joakim Söderberg
|
|
||||||
# - Added support for Clang.
|
|
||||||
# - Some additional usage instructions.
|
|
||||||
#
|
|
||||||
# 2016-02-03, Lars Bilke
|
|
||||||
# - Refactored functions to use named parameters
|
|
||||||
#
|
|
||||||
# 2017-06-02, Lars Bilke
|
|
||||||
# - Merged with modified version from github.com/ufz/ogs
|
|
||||||
#
|
|
||||||
# 2019-05-06, Anatolii Kurotych
|
|
||||||
# - Remove unnecessary --coverage flag
|
|
||||||
#
|
|
||||||
# 2019-12-13, FeRD (Frank Dana)
|
|
||||||
# - Deprecate COVERAGE_LCOVR_EXCLUDES and COVERAGE_GCOVR_EXCLUDES lists in favor
|
|
||||||
# of tool-agnostic COVERAGE_EXCLUDES variable, or EXCLUDE setup arguments.
|
|
||||||
# - CMake 3.4+: All excludes can be specified relative to BASE_DIRECTORY
|
|
||||||
# - All setup functions: accept BASE_DIRECTORY, EXCLUDE list
|
|
||||||
# - Set lcov basedir with -b argument
|
|
||||||
# - Add automatic --demangle-cpp in lcovr, if 'c++filt' is available (can be
|
|
||||||
# overridden with NO_DEMANGLE option in setup_target_for_coverage_lcovr().)
|
|
||||||
# - Delete output dir, .info file on 'make clean'
|
|
||||||
# - Remove Python detection, since version mismatches will break gcovr
|
|
||||||
# - Minor cleanup (lowercase function names, update examples...)
|
|
||||||
#
|
|
||||||
# 2019-12-19, FeRD (Frank Dana)
|
|
||||||
# - Rename Lcov outputs, make filtered file canonical, fix cleanup for targets
|
|
||||||
#
|
|
||||||
# 2020-01-19, Bob Apthorpe
|
|
||||||
# - Added gfortran support
|
|
||||||
#
|
|
||||||
# 2020-02-17, FeRD (Frank Dana)
|
|
||||||
# - Make all add_custom_target()s VERBATIM to auto-escape wildcard characters
|
|
||||||
# in EXCLUDEs, and remove manual escaping from gcovr targets
|
|
||||||
#
|
|
||||||
# 2021-01-19, Robin Mueller
|
|
||||||
# - Add CODE_COVERAGE_VERBOSE option which will allow to print out commands which are run
|
|
||||||
# - Added the option for users to set the GCOVR_ADDITIONAL_ARGS variable to supply additional
|
|
||||||
# flags to the gcovr command
|
|
||||||
#
|
|
||||||
# 2020-05-04, Mihchael Davis
|
|
||||||
# - Add -fprofile-abs-path to make gcno files contain absolute paths
|
|
||||||
# - Fix BASE_DIRECTORY not working when defined
|
|
||||||
# - Change BYPRODUCT from folder to index.html to stop ninja from complaining about double defines
|
|
||||||
#
|
|
||||||
# 2021-05-10, Martin Stump
|
|
||||||
# - Check if the generator is multi-config before warning about non-Debug builds
|
|
||||||
#
|
|
||||||
# 2022-02-22, Marko Wehle
|
|
||||||
# - Change gcovr output from -o <filename> for --xml <filename> and --html <filename> output respectively.
|
|
||||||
# This will allow for Multiple Output Formats at the same time by making use of GCOVR_ADDITIONAL_ARGS, e.g. GCOVR_ADDITIONAL_ARGS "--txt".
|
|
||||||
#
|
|
||||||
# USAGE:
|
|
||||||
#
|
|
||||||
# 1. Copy this file into your cmake modules path.
|
|
||||||
#
|
|
||||||
# 2. Add the following line to your CMakeLists.txt (best inside an if-condition
|
|
||||||
# using a CMake option() to enable it just optionally):
|
|
||||||
# include(CodeCoverage)
|
|
||||||
#
|
|
||||||
# 3. Append necessary compiler flags for all supported source files:
|
|
||||||
# append_coverage_compiler_flags()
|
|
||||||
# Or for specific target:
|
|
||||||
# append_coverage_compiler_flags_to_target(YOUR_TARGET_NAME)
|
|
||||||
#
|
|
||||||
# 3.a (OPTIONAL) Set appropriate optimization flags, e.g. -O0, -O1 or -Og
|
|
||||||
#
|
|
||||||
# 4. If you need to exclude additional directories from the report, specify them
|
|
||||||
# using full paths in the COVERAGE_EXCLUDES variable before calling
|
|
||||||
# setup_target_for_coverage_*().
|
|
||||||
# Example:
|
|
||||||
# set(COVERAGE_EXCLUDES
|
|
||||||
# '${PROJECT_SOURCE_DIR}/src/dir1/*'
|
|
||||||
# '/path/to/my/src/dir2/*')
|
|
||||||
# Or, use the EXCLUDE argument to setup_target_for_coverage_*().
|
|
||||||
# Example:
|
|
||||||
# setup_target_for_coverage_lcov(
|
|
||||||
# NAME coverage
|
|
||||||
# EXECUTABLE testrunner
|
|
||||||
# EXCLUDE "${PROJECT_SOURCE_DIR}/src/dir1/*" "/path/to/my/src/dir2/*")
|
|
||||||
#
|
|
||||||
# 4.a NOTE: With CMake 3.4+, COVERAGE_EXCLUDES or EXCLUDE can also be set
|
|
||||||
# relative to the BASE_DIRECTORY (default: PROJECT_SOURCE_DIR)
|
|
||||||
# Example:
|
|
||||||
# set(COVERAGE_EXCLUDES "dir1/*")
|
|
||||||
# setup_target_for_coverage_gcovr_html(
|
|
||||||
# NAME coverage
|
|
||||||
# EXECUTABLE testrunner
|
|
||||||
# BASE_DIRECTORY "${PROJECT_SOURCE_DIR}/src"
|
|
||||||
# EXCLUDE "dir2/*")
|
|
||||||
#
|
|
||||||
# 5. Use the functions described below to create a custom make target which
|
|
||||||
# runs your test executable and produces a code coverage report.
|
|
||||||
#
|
|
||||||
# 6. Build a Debug build:
|
|
||||||
# cmake -DCMAKE_BUILD_TYPE=Debug ..
|
|
||||||
# make
|
|
||||||
# make my_coverage_target
|
|
||||||
#
|
|
||||||
|
|
||||||
include(CMakeParseArguments)
|
|
||||||
|
|
||||||
option(CODE_COVERAGE_VERBOSE "Verbose information" FALSE)
|
|
||||||
|
|
||||||
# Check prereqs
|
|
||||||
find_program( GCOV_PATH gcov )
|
|
||||||
find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl)
|
|
||||||
find_program( FASTCOV_PATH NAMES fastcov fastcov.py )
|
|
||||||
find_program( GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat )
|
|
||||||
find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test)
|
|
||||||
find_program( CPPFILT_PATH NAMES c++filt )
|
|
||||||
|
|
||||||
if(NOT GCOV_PATH)
|
|
||||||
message(FATAL_ERROR "gcov not found! Aborting...")
|
|
||||||
endif() # NOT GCOV_PATH
|
|
||||||
|
|
||||||
get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
|
|
||||||
list(GET LANGUAGES 0 LANG)
|
|
||||||
|
|
||||||
if("${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
|
|
||||||
if("${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS 3)
|
|
||||||
message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
|
|
||||||
endif()
|
|
||||||
elseif(NOT CMAKE_COMPILER_IS_GNUCXX)
|
|
||||||
if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "[Ff]lang")
|
|
||||||
# Do nothing; exit conditional without error if true
|
|
||||||
elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
|
|
||||||
# Do nothing; exit conditional without error if true
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(COVERAGE_COMPILER_FLAGS "-g -fprofile-arcs -ftest-coverage"
|
|
||||||
CACHE INTERNAL "")
|
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
|
||||||
include(CheckCXXCompilerFlag)
|
|
||||||
check_cxx_compiler_flag(-fprofile-abs-path HAVE_fprofile_abs_path)
|
|
||||||
if(HAVE_fprofile_abs_path)
|
|
||||||
set(COVERAGE_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(CMAKE_Fortran_FLAGS_COVERAGE
|
|
||||||
${COVERAGE_COMPILER_FLAGS}
|
|
||||||
CACHE STRING "Flags used by the Fortran compiler during coverage builds."
|
|
||||||
FORCE )
|
|
||||||
set(CMAKE_CXX_FLAGS_COVERAGE
|
|
||||||
${COVERAGE_COMPILER_FLAGS}
|
|
||||||
CACHE STRING "Flags used by the C++ compiler during coverage builds."
|
|
||||||
FORCE )
|
|
||||||
set(CMAKE_C_FLAGS_COVERAGE
|
|
||||||
${COVERAGE_COMPILER_FLAGS}
|
|
||||||
CACHE STRING "Flags used by the C compiler during coverage builds."
|
|
||||||
FORCE )
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
|
||||||
""
|
|
||||||
CACHE STRING "Flags used for linking binaries during coverage builds."
|
|
||||||
FORCE )
|
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
|
|
||||||
""
|
|
||||||
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
|
|
||||||
FORCE )
|
|
||||||
mark_as_advanced(
|
|
||||||
CMAKE_Fortran_FLAGS_COVERAGE
|
|
||||||
CMAKE_CXX_FLAGS_COVERAGE
|
|
||||||
CMAKE_C_FLAGS_COVERAGE
|
|
||||||
CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
|
||||||
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
|
|
||||||
|
|
||||||
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
|
||||||
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG))
|
|
||||||
message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading")
|
|
||||||
endif() # NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG)
|
|
||||||
|
|
||||||
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
|
|
||||||
link_libraries(gcov)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Defines a target for running and collection code coverage information
|
|
||||||
# Builds dependencies, runs the given executable and outputs reports.
|
|
||||||
# NOTE! The executable should always have a ZERO as exit code otherwise
|
|
||||||
# the coverage generation will not complete.
|
|
||||||
#
|
|
||||||
# setup_target_for_coverage_lcov(
|
|
||||||
# NAME testrunner_coverage # New target name
|
|
||||||
# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
|
|
||||||
# DEPENDENCIES testrunner # Dependencies to build first
|
|
||||||
# BASE_DIRECTORY "../" # Base directory for report
|
|
||||||
# # (defaults to PROJECT_SOURCE_DIR)
|
|
||||||
# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative
|
|
||||||
# # to BASE_DIRECTORY, with CMake 3.4+)
|
|
||||||
# NO_DEMANGLE # Don't demangle C++ symbols
|
|
||||||
# # even if c++filt is found
|
|
||||||
# )
|
|
||||||
function(setup_target_for_coverage_lcov)
|
|
||||||
|
|
||||||
set(options NO_DEMANGLE)
|
|
||||||
set(oneValueArgs BASE_DIRECTORY NAME)
|
|
||||||
set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES LCOV_ARGS GENHTML_ARGS)
|
|
||||||
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
||||||
|
|
||||||
if(NOT LCOV_PATH)
|
|
||||||
message(FATAL_ERROR "lcov not found! Aborting...")
|
|
||||||
endif() # NOT LCOV_PATH
|
|
||||||
|
|
||||||
if(NOT GENHTML_PATH)
|
|
||||||
message(FATAL_ERROR "genhtml not found! Aborting...")
|
|
||||||
endif() # NOT GENHTML_PATH
|
|
||||||
|
|
||||||
# Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
|
|
||||||
if(DEFINED Coverage_BASE_DIRECTORY)
|
|
||||||
get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
|
|
||||||
else()
|
|
||||||
set(BASEDIR ${PROJECT_SOURCE_DIR})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Collect excludes (CMake 3.4+: Also compute absolute paths)
|
|
||||||
set(LCOV_EXCLUDES "")
|
|
||||||
foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_LCOV_EXCLUDES})
|
|
||||||
if(CMAKE_VERSION VERSION_GREATER 3.4)
|
|
||||||
get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
|
|
||||||
endif()
|
|
||||||
list(APPEND LCOV_EXCLUDES "${EXCLUDE}")
|
|
||||||
endforeach()
|
|
||||||
list(REMOVE_DUPLICATES LCOV_EXCLUDES)
|
|
||||||
|
|
||||||
# Conditional arguments
|
|
||||||
if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE})
|
|
||||||
set(GENHTML_EXTRA_ARGS "--demangle-cpp")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Setting up commands which will be run to generate coverage data.
|
|
||||||
# Cleanup lcov
|
|
||||||
set(LCOV_CLEAN_CMD
|
|
||||||
${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -directory .
|
|
||||||
-b ${BASEDIR} --zerocounters
|
|
||||||
)
|
|
||||||
# Create baseline to make sure untouched files show up in the report
|
|
||||||
set(LCOV_BASELINE_CMD
|
|
||||||
${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -c -i -d . -b
|
|
||||||
${BASEDIR} -o ${Coverage_NAME}.base
|
|
||||||
)
|
|
||||||
# Run tests
|
|
||||||
set(LCOV_EXEC_TESTS_CMD
|
|
||||||
${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
|
|
||||||
)
|
|
||||||
# Capturing lcov counters and generating report
|
|
||||||
set(LCOV_CAPTURE_CMD
|
|
||||||
${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --directory . -b
|
|
||||||
${BASEDIR} --capture --output-file ${Coverage_NAME}.capture
|
|
||||||
)
|
|
||||||
# add baseline counters
|
|
||||||
set(LCOV_BASELINE_COUNT_CMD
|
|
||||||
${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -a ${Coverage_NAME}.base
|
|
||||||
-a ${Coverage_NAME}.capture --output-file ${Coverage_NAME}.total
|
|
||||||
)
|
|
||||||
# filter collected data to final coverage report
|
|
||||||
set(LCOV_FILTER_CMD
|
|
||||||
${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --remove
|
|
||||||
${Coverage_NAME}.total ${LCOV_EXCLUDES} --output-file ${Coverage_NAME}.info
|
|
||||||
)
|
|
||||||
# Generate HTML output
|
|
||||||
set(LCOV_GEN_HTML_CMD
|
|
||||||
${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS} -o
|
|
||||||
${Coverage_NAME} ${Coverage_NAME}.info
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if(CODE_COVERAGE_VERBOSE)
|
|
||||||
message(STATUS "Executed command report")
|
|
||||||
message(STATUS "Command to clean up lcov: ")
|
|
||||||
string(REPLACE ";" " " LCOV_CLEAN_CMD_SPACED "${LCOV_CLEAN_CMD}")
|
|
||||||
message(STATUS "${LCOV_CLEAN_CMD_SPACED}")
|
|
||||||
|
|
||||||
message(STATUS "Command to create baseline: ")
|
|
||||||
string(REPLACE ";" " " LCOV_BASELINE_CMD_SPACED "${LCOV_BASELINE_CMD}")
|
|
||||||
message(STATUS "${LCOV_BASELINE_CMD_SPACED}")
|
|
||||||
|
|
||||||
message(STATUS "Command to run the tests: ")
|
|
||||||
string(REPLACE ";" " " LCOV_EXEC_TESTS_CMD_SPACED "${LCOV_EXEC_TESTS_CMD}")
|
|
||||||
message(STATUS "${LCOV_EXEC_TESTS_CMD_SPACED}")
|
|
||||||
|
|
||||||
message(STATUS "Command to capture counters and generate report: ")
|
|
||||||
string(REPLACE ";" " " LCOV_CAPTURE_CMD_SPACED "${LCOV_CAPTURE_CMD}")
|
|
||||||
message(STATUS "${LCOV_CAPTURE_CMD_SPACED}")
|
|
||||||
|
|
||||||
message(STATUS "Command to add baseline counters: ")
|
|
||||||
string(REPLACE ";" " " LCOV_BASELINE_COUNT_CMD_SPACED "${LCOV_BASELINE_COUNT_CMD}")
|
|
||||||
message(STATUS "${LCOV_BASELINE_COUNT_CMD_SPACED}")
|
|
||||||
|
|
||||||
message(STATUS "Command to filter collected data: ")
|
|
||||||
string(REPLACE ";" " " LCOV_FILTER_CMD_SPACED "${LCOV_FILTER_CMD}")
|
|
||||||
message(STATUS "${LCOV_FILTER_CMD_SPACED}")
|
|
||||||
|
|
||||||
message(STATUS "Command to generate lcov HTML output: ")
|
|
||||||
string(REPLACE ";" " " LCOV_GEN_HTML_CMD_SPACED "${LCOV_GEN_HTML_CMD}")
|
|
||||||
message(STATUS "${LCOV_GEN_HTML_CMD_SPACED}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Setup target
|
|
||||||
add_custom_target(${Coverage_NAME}
|
|
||||||
COMMAND ${LCOV_CLEAN_CMD}
|
|
||||||
COMMAND ${LCOV_BASELINE_CMD}
|
|
||||||
COMMAND ${LCOV_EXEC_TESTS_CMD}
|
|
||||||
COMMAND ${LCOV_CAPTURE_CMD}
|
|
||||||
COMMAND ${LCOV_BASELINE_COUNT_CMD}
|
|
||||||
COMMAND ${LCOV_FILTER_CMD}
|
|
||||||
COMMAND ${LCOV_GEN_HTML_CMD}
|
|
||||||
|
|
||||||
# Set output files as GENERATED (will be removed on 'make clean')
|
|
||||||
BYPRODUCTS
|
|
||||||
${Coverage_NAME}.base
|
|
||||||
${Coverage_NAME}.capture
|
|
||||||
${Coverage_NAME}.total
|
|
||||||
${Coverage_NAME}.info
|
|
||||||
${Coverage_NAME}/index.html
|
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
||||||
DEPENDS ${Coverage_DEPENDENCIES}
|
|
||||||
VERBATIM # Protect arguments to commands
|
|
||||||
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Show where to find the lcov info report
|
|
||||||
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
|
|
||||||
COMMAND ;
|
|
||||||
COMMENT "Lcov code coverage info report saved in ${Coverage_NAME}.info."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Show info where to find the report
|
|
||||||
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
|
|
||||||
COMMAND ;
|
|
||||||
COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
|
|
||||||
)
|
|
||||||
|
|
||||||
endfunction() # setup_target_for_coverage_lcov
|
|
||||||
|
|
||||||
# Defines a target for running and collection code coverage information
|
|
||||||
# Builds dependencies, runs the given executable and outputs reports.
|
|
||||||
# NOTE! The executable should always have a ZERO as exit code otherwise
|
|
||||||
# the coverage generation will not complete.
|
|
||||||
#
|
|
||||||
# setup_target_for_coverage_gcovr_xml(
|
|
||||||
# NAME ctest_coverage # New target name
|
|
||||||
# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
|
|
||||||
# DEPENDENCIES executable_target # Dependencies to build first
|
|
||||||
# BASE_DIRECTORY "../" # Base directory for report
|
|
||||||
# # (defaults to PROJECT_SOURCE_DIR)
|
|
||||||
# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative
|
|
||||||
# # to BASE_DIRECTORY, with CMake 3.4+)
|
|
||||||
# )
|
|
||||||
# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the
|
|
||||||
# GCVOR command.
|
|
||||||
function(setup_target_for_coverage_gcovr_xml)
|
|
||||||
|
|
||||||
set(options NONE)
|
|
||||||
set(oneValueArgs BASE_DIRECTORY NAME)
|
|
||||||
set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
|
|
||||||
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
||||||
|
|
||||||
if(NOT GCOVR_PATH)
|
|
||||||
message(FATAL_ERROR "gcovr not found! Aborting...")
|
|
||||||
endif() # NOT GCOVR_PATH
|
|
||||||
|
|
||||||
# Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
|
|
||||||
if(DEFINED Coverage_BASE_DIRECTORY)
|
|
||||||
get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
|
|
||||||
else()
|
|
||||||
set(BASEDIR ${PROJECT_SOURCE_DIR})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Collect excludes (CMake 3.4+: Also compute absolute paths)
|
|
||||||
set(GCOVR_EXCLUDES "")
|
|
||||||
foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES})
|
|
||||||
if(CMAKE_VERSION VERSION_GREATER 3.4)
|
|
||||||
get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
|
|
||||||
endif()
|
|
||||||
list(APPEND GCOVR_EXCLUDES "${EXCLUDE}")
|
|
||||||
endforeach()
|
|
||||||
list(REMOVE_DUPLICATES GCOVR_EXCLUDES)
|
|
||||||
|
|
||||||
# Combine excludes to several -e arguments
|
|
||||||
set(GCOVR_EXCLUDE_ARGS "")
|
|
||||||
foreach(EXCLUDE ${GCOVR_EXCLUDES})
|
|
||||||
list(APPEND GCOVR_EXCLUDE_ARGS "-e")
|
|
||||||
list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}")
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# Set up commands which will be run to generate coverage data
|
|
||||||
# Run tests
|
|
||||||
set(GCOVR_XML_EXEC_TESTS_CMD
|
|
||||||
${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
|
|
||||||
)
|
|
||||||
# Running gcovr
|
|
||||||
set(GCOVR_XML_CMD
|
|
||||||
${GCOVR_PATH} --xml ${Coverage_NAME}.xml -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
|
|
||||||
${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
if(CODE_COVERAGE_VERBOSE)
|
|
||||||
message(STATUS "Executed command report")
|
|
||||||
|
|
||||||
message(STATUS "Command to run tests: ")
|
|
||||||
string(REPLACE ";" " " GCOVR_XML_EXEC_TESTS_CMD_SPACED "${GCOVR_XML_EXEC_TESTS_CMD}")
|
|
||||||
message(STATUS "${GCOVR_XML_EXEC_TESTS_CMD_SPACED}")
|
|
||||||
|
|
||||||
message(STATUS "Command to generate gcovr XML coverage data: ")
|
|
||||||
string(REPLACE ";" " " GCOVR_XML_CMD_SPACED "${GCOVR_XML_CMD}")
|
|
||||||
message(STATUS "${GCOVR_XML_CMD_SPACED}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_custom_target(${Coverage_NAME}
|
|
||||||
COMMAND ${GCOVR_XML_EXEC_TESTS_CMD}
|
|
||||||
COMMAND ${GCOVR_XML_CMD}
|
|
||||||
|
|
||||||
BYPRODUCTS ${Coverage_NAME}.xml
|
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
||||||
DEPENDS ${Coverage_DEPENDENCIES}
|
|
||||||
VERBATIM # Protect arguments to commands
|
|
||||||
COMMENT "Running gcovr to produce Cobertura code coverage report."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Show info where to find the report
|
|
||||||
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
|
|
||||||
COMMAND ;
|
|
||||||
COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml."
|
|
||||||
)
|
|
||||||
endfunction() # setup_target_for_coverage_gcovr_xml
|
|
||||||
|
|
||||||
# Defines a target for running and collection code coverage information
|
|
||||||
# Builds dependencies, runs the given executable and outputs reports.
|
|
||||||
# NOTE! The executable should always have a ZERO as exit code otherwise
|
|
||||||
# the coverage generation will not complete.
|
|
||||||
#
|
|
||||||
# setup_target_for_coverage_gcovr_html(
|
|
||||||
# NAME ctest_coverage # New target name
|
|
||||||
# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
|
|
||||||
# DEPENDENCIES executable_target # Dependencies to build first
|
|
||||||
# BASE_DIRECTORY "../" # Base directory for report
|
|
||||||
# # (defaults to PROJECT_SOURCE_DIR)
|
|
||||||
# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative
|
|
||||||
# # to BASE_DIRECTORY, with CMake 3.4+)
|
|
||||||
# )
|
|
||||||
# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the
|
|
||||||
# GCVOR command.
|
|
||||||
function(setup_target_for_coverage_gcovr_html)
|
|
||||||
|
|
||||||
set(options NONE)
|
|
||||||
set(oneValueArgs BASE_DIRECTORY NAME)
|
|
||||||
set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
|
|
||||||
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
||||||
|
|
||||||
if(NOT GCOVR_PATH)
|
|
||||||
message(FATAL_ERROR "gcovr not found! Aborting...")
|
|
||||||
endif() # NOT GCOVR_PATH
|
|
||||||
|
|
||||||
# Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
|
|
||||||
if(DEFINED Coverage_BASE_DIRECTORY)
|
|
||||||
get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
|
|
||||||
else()
|
|
||||||
set(BASEDIR ${PROJECT_SOURCE_DIR})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Collect excludes (CMake 3.4+: Also compute absolute paths)
|
|
||||||
set(GCOVR_EXCLUDES "")
|
|
||||||
foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES})
|
|
||||||
if(CMAKE_VERSION VERSION_GREATER 3.4)
|
|
||||||
get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
|
|
||||||
endif()
|
|
||||||
list(APPEND GCOVR_EXCLUDES "${EXCLUDE}")
|
|
||||||
endforeach()
|
|
||||||
list(REMOVE_DUPLICATES GCOVR_EXCLUDES)
|
|
||||||
|
|
||||||
# Combine excludes to several -e arguments
|
|
||||||
set(GCOVR_EXCLUDE_ARGS "")
|
|
||||||
foreach(EXCLUDE ${GCOVR_EXCLUDES})
|
|
||||||
list(APPEND GCOVR_EXCLUDE_ARGS "-e")
|
|
||||||
list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}")
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# Set up commands which will be run to generate coverage data
|
|
||||||
# Run tests
|
|
||||||
set(GCOVR_HTML_EXEC_TESTS_CMD
|
|
||||||
${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
|
|
||||||
)
|
|
||||||
# Create folder
|
|
||||||
set(GCOVR_HTML_FOLDER_CMD
|
|
||||||
${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/${Coverage_NAME}
|
|
||||||
)
|
|
||||||
# Running gcovr
|
|
||||||
set(GCOVR_HTML_CMD
|
|
||||||
${GCOVR_PATH} --html ${Coverage_NAME}/index.html --html-details -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
|
|
||||||
${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
if(CODE_COVERAGE_VERBOSE)
|
|
||||||
message(STATUS "Executed command report")
|
|
||||||
|
|
||||||
message(STATUS "Command to run tests: ")
|
|
||||||
string(REPLACE ";" " " GCOVR_HTML_EXEC_TESTS_CMD_SPACED "${GCOVR_HTML_EXEC_TESTS_CMD}")
|
|
||||||
message(STATUS "${GCOVR_HTML_EXEC_TESTS_CMD_SPACED}")
|
|
||||||
|
|
||||||
message(STATUS "Command to create a folder: ")
|
|
||||||
string(REPLACE ";" " " GCOVR_HTML_FOLDER_CMD_SPACED "${GCOVR_HTML_FOLDER_CMD}")
|
|
||||||
message(STATUS "${GCOVR_HTML_FOLDER_CMD_SPACED}")
|
|
||||||
|
|
||||||
message(STATUS "Command to generate gcovr HTML coverage data: ")
|
|
||||||
string(REPLACE ";" " " GCOVR_HTML_CMD_SPACED "${GCOVR_HTML_CMD}")
|
|
||||||
message(STATUS "${GCOVR_HTML_CMD_SPACED}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_custom_target(${Coverage_NAME}
|
|
||||||
COMMAND ${GCOVR_HTML_EXEC_TESTS_CMD}
|
|
||||||
COMMAND ${GCOVR_HTML_FOLDER_CMD}
|
|
||||||
COMMAND ${GCOVR_HTML_CMD}
|
|
||||||
|
|
||||||
BYPRODUCTS ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html # report directory
|
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
||||||
DEPENDS ${Coverage_DEPENDENCIES}
|
|
||||||
VERBATIM # Protect arguments to commands
|
|
||||||
COMMENT "Running gcovr to produce HTML code coverage report."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Show info where to find the report
|
|
||||||
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
|
|
||||||
COMMAND ;
|
|
||||||
COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
|
|
||||||
)
|
|
||||||
|
|
||||||
endfunction() # setup_target_for_coverage_gcovr_html
|
|
||||||
|
|
||||||
# Defines a target for running and collection code coverage information
|
|
||||||
# Builds dependencies, runs the given executable and outputs reports.
|
|
||||||
# NOTE! The executable should always have a ZERO as exit code otherwise
|
|
||||||
# the coverage generation will not complete.
|
|
||||||
#
|
|
||||||
# setup_target_for_coverage_fastcov(
|
|
||||||
# NAME testrunner_coverage # New target name
|
|
||||||
# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
|
|
||||||
# DEPENDENCIES testrunner # Dependencies to build first
|
|
||||||
# BASE_DIRECTORY "../" # Base directory for report
|
|
||||||
# # (defaults to PROJECT_SOURCE_DIR)
|
|
||||||
# EXCLUDE "src/dir1/" "src/dir2/" # Patterns to exclude.
|
|
||||||
# NO_DEMANGLE # Don't demangle C++ symbols
|
|
||||||
# # even if c++filt is found
|
|
||||||
# SKIP_HTML # Don't create html report
|
|
||||||
# POST_CMD perl -i -pe s!${PROJECT_SOURCE_DIR}/!!g ctest_coverage.json # E.g. for stripping source dir from file paths
|
|
||||||
# )
|
|
||||||
function(setup_target_for_coverage_fastcov)
|
|
||||||
|
|
||||||
set(options NO_DEMANGLE SKIP_HTML)
|
|
||||||
set(oneValueArgs BASE_DIRECTORY NAME)
|
|
||||||
set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES FASTCOV_ARGS GENHTML_ARGS POST_CMD)
|
|
||||||
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
||||||
|
|
||||||
if(NOT FASTCOV_PATH)
|
|
||||||
message(FATAL_ERROR "fastcov not found! Aborting...")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT Coverage_SKIP_HTML AND NOT GENHTML_PATH)
|
|
||||||
message(FATAL_ERROR "genhtml not found! Aborting...")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
|
|
||||||
if(Coverage_BASE_DIRECTORY)
|
|
||||||
get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
|
|
||||||
else()
|
|
||||||
set(BASEDIR ${PROJECT_SOURCE_DIR})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Collect excludes (Patterns, not paths, for fastcov)
|
|
||||||
set(FASTCOV_EXCLUDES "")
|
|
||||||
foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_FASTCOV_EXCLUDES})
|
|
||||||
list(APPEND FASTCOV_EXCLUDES "${EXCLUDE}")
|
|
||||||
endforeach()
|
|
||||||
list(REMOVE_DUPLICATES FASTCOV_EXCLUDES)
|
|
||||||
|
|
||||||
# Conditional arguments
|
|
||||||
if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE})
|
|
||||||
set(GENHTML_EXTRA_ARGS "--demangle-cpp")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Set up commands which will be run to generate coverage data
|
|
||||||
set(FASTCOV_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS})
|
|
||||||
|
|
||||||
set(FASTCOV_CAPTURE_CMD ${FASTCOV_PATH} ${Coverage_FASTCOV_ARGS} --gcov ${GCOV_PATH}
|
|
||||||
--search-directory ${BASEDIR}
|
|
||||||
--process-gcno
|
|
||||||
--output ${Coverage_NAME}.json
|
|
||||||
--exclude ${FASTCOV_EXCLUDES}
|
|
||||||
--exclude ${FASTCOV_EXCLUDES}
|
|
||||||
)
|
|
||||||
|
|
||||||
set(FASTCOV_CONVERT_CMD ${FASTCOV_PATH}
|
|
||||||
-C ${Coverage_NAME}.json --lcov --output ${Coverage_NAME}.info
|
|
||||||
)
|
|
||||||
|
|
||||||
if(Coverage_SKIP_HTML)
|
|
||||||
set(FASTCOV_HTML_CMD ";")
|
|
||||||
else()
|
|
||||||
set(FASTCOV_HTML_CMD ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS}
|
|
||||||
-o ${Coverage_NAME} ${Coverage_NAME}.info
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(FASTCOV_POST_CMD ";")
|
|
||||||
if(Coverage_POST_CMD)
|
|
||||||
set(FASTCOV_POST_CMD ${Coverage_POST_CMD})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CODE_COVERAGE_VERBOSE)
|
|
||||||
message(STATUS "Code coverage commands for target ${Coverage_NAME} (fastcov):")
|
|
||||||
|
|
||||||
message(" Running tests:")
|
|
||||||
string(REPLACE ";" " " FASTCOV_EXEC_TESTS_CMD_SPACED "${FASTCOV_EXEC_TESTS_CMD}")
|
|
||||||
message(" ${FASTCOV_EXEC_TESTS_CMD_SPACED}")
|
|
||||||
|
|
||||||
message(" Capturing fastcov counters and generating report:")
|
|
||||||
string(REPLACE ";" " " FASTCOV_CAPTURE_CMD_SPACED "${FASTCOV_CAPTURE_CMD}")
|
|
||||||
message(" ${FASTCOV_CAPTURE_CMD_SPACED}")
|
|
||||||
|
|
||||||
message(" Converting fastcov .json to lcov .info:")
|
|
||||||
string(REPLACE ";" " " FASTCOV_CONVERT_CMD_SPACED "${FASTCOV_CONVERT_CMD}")
|
|
||||||
message(" ${FASTCOV_CONVERT_CMD_SPACED}")
|
|
||||||
|
|
||||||
if(NOT Coverage_SKIP_HTML)
|
|
||||||
message(" Generating HTML report: ")
|
|
||||||
string(REPLACE ";" " " FASTCOV_HTML_CMD_SPACED "${FASTCOV_HTML_CMD}")
|
|
||||||
message(" ${FASTCOV_HTML_CMD_SPACED}")
|
|
||||||
endif()
|
|
||||||
if(Coverage_POST_CMD)
|
|
||||||
message(" Running post command: ")
|
|
||||||
string(REPLACE ";" " " FASTCOV_POST_CMD_SPACED "${FASTCOV_POST_CMD}")
|
|
||||||
message(" ${FASTCOV_POST_CMD_SPACED}")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Setup target
|
|
||||||
add_custom_target(${Coverage_NAME}
|
|
||||||
|
|
||||||
# Cleanup fastcov
|
|
||||||
COMMAND ${FASTCOV_PATH} ${Coverage_FASTCOV_ARGS} --gcov ${GCOV_PATH}
|
|
||||||
--search-directory ${BASEDIR}
|
|
||||||
--zerocounters
|
|
||||||
|
|
||||||
COMMAND ${FASTCOV_EXEC_TESTS_CMD}
|
|
||||||
COMMAND ${FASTCOV_CAPTURE_CMD}
|
|
||||||
COMMAND ${FASTCOV_CONVERT_CMD}
|
|
||||||
COMMAND ${FASTCOV_HTML_CMD}
|
|
||||||
COMMAND ${FASTCOV_POST_CMD}
|
|
||||||
|
|
||||||
# Set output files as GENERATED (will be removed on 'make clean')
|
|
||||||
BYPRODUCTS
|
|
||||||
${Coverage_NAME}.info
|
|
||||||
${Coverage_NAME}.json
|
|
||||||
${Coverage_NAME}/index.html # report directory
|
|
||||||
|
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
||||||
DEPENDS ${Coverage_DEPENDENCIES}
|
|
||||||
VERBATIM # Protect arguments to commands
|
|
||||||
COMMENT "Resetting code coverage counters to zero. Processing code coverage counters and generating report."
|
|
||||||
)
|
|
||||||
|
|
||||||
set(INFO_MSG "fastcov code coverage info report saved in ${Coverage_NAME}.info and ${Coverage_NAME}.json.")
|
|
||||||
if(NOT Coverage_SKIP_HTML)
|
|
||||||
string(APPEND INFO_MSG " Open ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html in your browser to view the coverage report.")
|
|
||||||
endif()
|
|
||||||
# Show where to find the fastcov info report
|
|
||||||
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo ${INFO_MSG}
|
|
||||||
)
|
|
||||||
|
|
||||||
endfunction() # setup_target_for_coverage_fastcov
|
|
||||||
|
|
||||||
function(append_coverage_compiler_flags)
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
|
||||||
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
|
|
||||||
message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}")
|
|
||||||
endfunction() # append_coverage_compiler_flags
|
|
||||||
|
|
||||||
# Setup coverage for specific library
|
|
||||||
function(append_coverage_compiler_flags_to_target name)
|
|
||||||
target_compile_options(${name}
|
|
||||||
PRIVATE ${COVERAGE_COMPILER_FLAGS})
|
|
||||||
endfunction()
|
|
@ -1,23 +0,0 @@
|
|||||||
Boost Software License - Version 1.0 - August 17th, 2003
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person or organization
|
|
||||||
obtaining a copy of the software and accompanying documentation covered by
|
|
||||||
this license (the "Software") to use, reproduce, display, distribute,
|
|
||||||
execute, and transmit the Software, and to prepare derivative works of the
|
|
||||||
Software, and to permit third-parties to whom the Software is furnished to
|
|
||||||
do so, all subject to the following:
|
|
||||||
|
|
||||||
The copyright notices in the Software and this entire statement, including
|
|
||||||
the above license grant, this restriction and the following disclaimer,
|
|
||||||
must be included in all copies of the Software, in whole or in part, and
|
|
||||||
all derivative works of the Software, unless such copies or derivative
|
|
||||||
works are solely in the form of machine-executable object code generated by
|
|
||||||
a source language processor.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
|
||||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
|
||||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
|
||||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
@ -1,284 +0,0 @@
|
|||||||
# - Returns a version string from Git
|
|
||||||
#
|
|
||||||
# These functions force a re-configure on each git commit so that you can
|
|
||||||
# trust the values of the variables in your build system.
|
|
||||||
#
|
|
||||||
# get_git_head_revision(<refspecvar> <hashvar> [ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR])
|
|
||||||
#
|
|
||||||
# Returns the refspec and sha hash of the current head revision
|
|
||||||
#
|
|
||||||
# git_describe(<var> [<additional arguments to git describe> ...])
|
|
||||||
#
|
|
||||||
# Returns the results of git describe on the source tree, and adjusting
|
|
||||||
# the output so that it tests false if an error occurs.
|
|
||||||
#
|
|
||||||
# git_describe_working_tree(<var> [<additional arguments to git describe> ...])
|
|
||||||
#
|
|
||||||
# Returns the results of git describe on the working tree (--dirty option),
|
|
||||||
# and adjusting the output so that it tests false if an error occurs.
|
|
||||||
#
|
|
||||||
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
|
|
||||||
#
|
|
||||||
# Returns the results of git describe --exact-match on the source tree,
|
|
||||||
# and adjusting the output so that it tests false if there was no exact
|
|
||||||
# matching tag.
|
|
||||||
#
|
|
||||||
# git_local_changes(<var>)
|
|
||||||
#
|
|
||||||
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
|
|
||||||
# Uses the return code of "git diff-index --quiet HEAD --".
|
|
||||||
# Does not regard untracked files.
|
|
||||||
#
|
|
||||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
|
||||||
#
|
|
||||||
# Original Author:
|
|
||||||
# 2009-2020 Ryan Pavlik <ryan.pavlik@gmail.com> <abiryan@ryand.net>
|
|
||||||
# http://academic.cleardefinition.com
|
|
||||||
#
|
|
||||||
# Copyright 2009-2013, Iowa State University.
|
|
||||||
# Copyright 2013-2020, Ryan Pavlik
|
|
||||||
# Copyright 2013-2020, Contributors
|
|
||||||
# SPDX-License-Identifier: BSL-1.0
|
|
||||||
# Distributed under the Boost Software License, Version 1.0.
|
|
||||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
# http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
if(__get_git_revision_description)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
set(__get_git_revision_description YES)
|
|
||||||
|
|
||||||
# We must run the following at "include" time, not at function call time,
|
|
||||||
# to find the path to this module rather than the path to a calling list file
|
|
||||||
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
|
|
||||||
|
|
||||||
# Function _git_find_closest_git_dir finds the next closest .git directory
|
|
||||||
# that is part of any directory in the path defined by _start_dir.
|
|
||||||
# The result is returned in the parent scope variable whose name is passed
|
|
||||||
# as variable _git_dir_var. If no .git directory can be found, the
|
|
||||||
# function returns an empty string via _git_dir_var.
|
|
||||||
#
|
|
||||||
# Example: Given a path C:/bla/foo/bar and assuming C:/bla/.git exists and
|
|
||||||
# neither foo nor bar contain a file/directory .git. This wil return
|
|
||||||
# C:/bla/.git
|
|
||||||
#
|
|
||||||
function(_git_find_closest_git_dir _start_dir _git_dir_var)
|
|
||||||
set(cur_dir "${_start_dir}")
|
|
||||||
set(git_dir "${_start_dir}/.git")
|
|
||||||
while(NOT EXISTS "${git_dir}")
|
|
||||||
# .git dir not found, search parent directories
|
|
||||||
set(git_previous_parent "${cur_dir}")
|
|
||||||
get_filename_component(cur_dir "${cur_dir}" DIRECTORY)
|
|
||||||
if(cur_dir STREQUAL git_previous_parent)
|
|
||||||
# We have reached the root directory, we are not in git
|
|
||||||
set(${_git_dir_var}
|
|
||||||
""
|
|
||||||
PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
set(git_dir "${cur_dir}/.git")
|
|
||||||
endwhile()
|
|
||||||
set(${_git_dir_var}
|
|
||||||
"${git_dir}"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(get_git_head_revision _refspecvar _hashvar)
|
|
||||||
_git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR)
|
|
||||||
|
|
||||||
if("${ARGN}" STREQUAL "ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR")
|
|
||||||
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR TRUE)
|
|
||||||
else()
|
|
||||||
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR FALSE)
|
|
||||||
endif()
|
|
||||||
if(NOT "${GIT_DIR}" STREQUAL "")
|
|
||||||
file(RELATIVE_PATH _relative_to_source_dir "${CMAKE_SOURCE_DIR}"
|
|
||||||
"${GIT_DIR}")
|
|
||||||
if("${_relative_to_source_dir}" MATCHES "[.][.]" AND NOT ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR)
|
|
||||||
# We've gone above the CMake root dir.
|
|
||||||
set(GIT_DIR "")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
if("${GIT_DIR}" STREQUAL "")
|
|
||||||
set(${_refspecvar}
|
|
||||||
"GITDIR-NOTFOUND"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
set(${_hashvar}
|
|
||||||
"GITDIR-NOTFOUND"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Check if the current source dir is a git submodule or a worktree.
|
|
||||||
# In both cases .git is a file instead of a directory.
|
|
||||||
#
|
|
||||||
if(NOT IS_DIRECTORY ${GIT_DIR})
|
|
||||||
# The following git command will return a non empty string that
|
|
||||||
# points to the super project working tree if the current
|
|
||||||
# source dir is inside a git submodule.
|
|
||||||
# Otherwise the command will return an empty string.
|
|
||||||
#
|
|
||||||
execute_process(
|
|
||||||
COMMAND "${GIT_EXECUTABLE}" rev-parse
|
|
||||||
--show-superproject-working-tree
|
|
||||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
||||||
OUTPUT_VARIABLE out
|
|
||||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
if(NOT "${out}" STREQUAL "")
|
|
||||||
# If out is empty, GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a submodule
|
|
||||||
file(READ ${GIT_DIR} submodule)
|
|
||||||
string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE
|
|
||||||
${submodule})
|
|
||||||
string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE)
|
|
||||||
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
|
|
||||||
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE}
|
|
||||||
ABSOLUTE)
|
|
||||||
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
|
|
||||||
else()
|
|
||||||
# GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a worktree
|
|
||||||
file(READ ${GIT_DIR} worktree_ref)
|
|
||||||
# The .git directory contains a path to the worktree information directory
|
|
||||||
# inside the parent git repo of the worktree.
|
|
||||||
#
|
|
||||||
string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir
|
|
||||||
${worktree_ref})
|
|
||||||
string(STRIP ${git_worktree_dir} git_worktree_dir)
|
|
||||||
_git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR)
|
|
||||||
set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
|
|
||||||
endif()
|
|
||||||
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
|
|
||||||
if(NOT EXISTS "${GIT_DATA}")
|
|
||||||
file(MAKE_DIRECTORY "${GIT_DATA}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT EXISTS "${HEAD_SOURCE_FILE}")
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
set(HEAD_FILE "${GIT_DATA}/HEAD")
|
|
||||||
configure_file("${HEAD_SOURCE_FILE}" "${HEAD_FILE}" COPYONLY)
|
|
||||||
|
|
||||||
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
|
|
||||||
"${GIT_DATA}/grabRef.cmake" @ONLY)
|
|
||||||
include("${GIT_DATA}/grabRef.cmake")
|
|
||||||
|
|
||||||
set(${_refspecvar}
|
|
||||||
"${HEAD_REF}"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
set(${_hashvar}
|
|
||||||
"${HEAD_HASH}"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(git_describe _var)
|
|
||||||
if(NOT GIT_FOUND)
|
|
||||||
find_package(Git QUIET)
|
|
||||||
endif()
|
|
||||||
get_git_head_revision(refspec hash)
|
|
||||||
if(NOT GIT_FOUND)
|
|
||||||
set(${_var}
|
|
||||||
"GIT-NOTFOUND"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
if(NOT hash)
|
|
||||||
set(${_var}
|
|
||||||
"HEAD-HASH-NOTFOUND"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# TODO sanitize
|
|
||||||
#if((${ARGN}" MATCHES "&&") OR
|
|
||||||
# (ARGN MATCHES "||") OR
|
|
||||||
# (ARGN MATCHES "\\;"))
|
|
||||||
# message("Please report the following error to the project!")
|
|
||||||
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
|
|
||||||
#endif()
|
|
||||||
|
|
||||||
#message(STATUS "Arguments to execute_process: ${ARGN}")
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND "${GIT_EXECUTABLE}" describe --tags --always ${hash} ${ARGN}
|
|
||||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
||||||
RESULT_VARIABLE res
|
|
||||||
OUTPUT_VARIABLE out
|
|
||||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
if(NOT res EQUAL 0)
|
|
||||||
set(out "${out}-${res}-NOTFOUND")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(${_var}
|
|
||||||
"${out}"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(git_describe_working_tree _var)
|
|
||||||
if(NOT GIT_FOUND)
|
|
||||||
find_package(Git QUIET)
|
|
||||||
endif()
|
|
||||||
if(NOT GIT_FOUND)
|
|
||||||
set(${_var}
|
|
||||||
"GIT-NOTFOUND"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND "${GIT_EXECUTABLE}" describe --dirty ${ARGN}
|
|
||||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
||||||
RESULT_VARIABLE res
|
|
||||||
OUTPUT_VARIABLE out
|
|
||||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
if(NOT res EQUAL 0)
|
|
||||||
set(out "${out}-${res}-NOTFOUND")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(${_var}
|
|
||||||
"${out}"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(git_get_exact_tag _var)
|
|
||||||
git_describe(out --exact-match ${ARGN})
|
|
||||||
set(${_var}
|
|
||||||
"${out}"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(git_local_changes _var)
|
|
||||||
if(NOT GIT_FOUND)
|
|
||||||
find_package(Git QUIET)
|
|
||||||
endif()
|
|
||||||
get_git_head_revision(refspec hash)
|
|
||||||
if(NOT GIT_FOUND)
|
|
||||||
set(${_var}
|
|
||||||
"GIT-NOTFOUND"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
if(NOT hash)
|
|
||||||
set(${_var}
|
|
||||||
"HEAD-HASH-NOTFOUND"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
|
|
||||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
||||||
RESULT_VARIABLE res
|
|
||||||
OUTPUT_VARIABLE out
|
|
||||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
if(res EQUAL 0)
|
|
||||||
set(${_var}
|
|
||||||
"CLEAN"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
else()
|
|
||||||
set(${_var}
|
|
||||||
"DIRTY"
|
|
||||||
PARENT_SCOPE)
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
@ -1,43 +0,0 @@
|
|||||||
#
|
|
||||||
# Internal file for GetGitRevisionDescription.cmake
|
|
||||||
#
|
|
||||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
|
||||||
#
|
|
||||||
# Original Author:
|
|
||||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
|
||||||
# http://academic.cleardefinition.com
|
|
||||||
# Iowa State University HCI Graduate Program/VRAC
|
|
||||||
#
|
|
||||||
# Copyright 2009-2012, Iowa State University
|
|
||||||
# Copyright 2011-2015, Contributors
|
|
||||||
# Distributed under the Boost Software License, Version 1.0.
|
|
||||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
# http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
# SPDX-License-Identifier: BSL-1.0
|
|
||||||
|
|
||||||
set(HEAD_HASH)
|
|
||||||
|
|
||||||
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
|
|
||||||
|
|
||||||
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
|
|
||||||
if(HEAD_CONTENTS MATCHES "ref")
|
|
||||||
# named branch
|
|
||||||
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
|
|
||||||
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
|
|
||||||
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
|
|
||||||
else()
|
|
||||||
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
|
|
||||||
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
|
|
||||||
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
|
|
||||||
set(HEAD_HASH "${CMAKE_MATCH_1}")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
# detached HEAD
|
|
||||||
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT HEAD_HASH)
|
|
||||||
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
|
|
||||||
string(STRIP "${HEAD_HASH}" HEAD_HASH)
|
|
||||||
endif()
|
|
@ -1,26 +0,0 @@
|
|||||||
Copyright (c) <year> <owner>. All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
3. Neither the name of the copyright holder nor the names of its contributors
|
|
||||||
may be used to endorse or promote products derived from this software without
|
|
||||||
specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
|
||||||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -1,23 +0,0 @@
|
|||||||
Boost Software License - Version 1.0 - August 17th, 2003
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person or organization
|
|
||||||
obtaining a copy of the software and accompanying documentation covered by
|
|
||||||
this license (the "Software") to use, reproduce, display, distribute, execute,
|
|
||||||
and transmit the Software, and to prepare derivative works of the Software,
|
|
||||||
and to permit third-parties to whom the Software is furnished to do so, all
|
|
||||||
subject to the following:
|
|
||||||
|
|
||||||
The copyright notices in the Software and this entire statement, including
|
|
||||||
the above license grant, this restriction and the following disclaimer, must
|
|
||||||
be included in all copies of the Software, in whole or in part, and all derivative
|
|
||||||
works of the Software, unless such copies or derivative works are solely in
|
|
||||||
the form of machine-executable object code generated by a source language
|
|
||||||
processor.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES
|
|
||||||
OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
@ -1,23 +0,0 @@
|
|||||||
Boost Software License - Version 1.0 - August 17th, 2003
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person or organization
|
|
||||||
obtaining a copy of the software and accompanying documentation covered by
|
|
||||||
this license (the "Software") to use, reproduce, display, distribute,
|
|
||||||
execute, and transmit the Software, and to prepare derivative works of the
|
|
||||||
Software, and to permit third-parties to whom the Software is furnished to
|
|
||||||
do so, all subject to the following:
|
|
||||||
|
|
||||||
The copyright notices in the Software and this entire statement, including
|
|
||||||
the above license grant, this restriction and the following disclaimer,
|
|
||||||
must be included in all copies of the Software, in whole or in part, and
|
|
||||||
all derivative works of the Software, unless such copies or derivative
|
|
||||||
works are solely in the form of machine-executable object code generated by
|
|
||||||
a source language processor.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
|
||||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
|
||||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
|
||||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
@ -14,7 +14,7 @@ FSFW to achieve that. The fsfw uses run-time type information but exceptions are
|
|||||||
# Failure Handling
|
# Failure Handling
|
||||||
|
|
||||||
Functions should return a defined `ReturnValue_t` to signal to the caller that something has
|
Functions should return a defined `ReturnValue_t` to signal to the caller that something has
|
||||||
gone wrong. Returnvalues must be unique. For this the function `returnvalue::makeCode`
|
gone wrong. Returnvalues must be unique. For this the function `HasReturnvaluesIF::makeReturnCode`
|
||||||
or the macro `MAKE_RETURN` can be used. The `CLASS_ID` is a unique id for that type of object.
|
or the macro `MAKE_RETURN` can be used. The `CLASS_ID` is a unique id for that type of object.
|
||||||
See `returnvalues/FwClassIds` folder. The user can add custom `CLASS_ID`s via the
|
See `returnvalues/FwClassIds` folder. The user can add custom `CLASS_ID`s via the
|
||||||
`fsfwconfig` folder.
|
`fsfwconfig` folder.
|
||||||
|
@ -144,7 +144,7 @@ ReturnValue_t GyroHandler::initializeLocalDataPool(localpool::DataPool &localDat
|
|||||||
new PoolEntry<uint8_t>({0}));
|
new PoolEntry<uint8_t>({0}));
|
||||||
|
|
||||||
poolManager.subscribeForPeriodicPacket(gyroData.getSid(), false, 4.0, false);
|
poolManager.subscribeForPeriodicPacket(gyroData.getSid(), false, 4.0, false);
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ in any case:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
PoolReadGuard readHelper(&gyroData);
|
PoolReadGuard readHelper(&gyroData);
|
||||||
if(readHelper.getReadResult() == returnvalue::OK) {
|
if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||||
if(not gyroData.isValid()) {
|
if(not gyroData.isValid()) {
|
||||||
gyroData.setValidity(true, true);
|
gyroData.setValidity(true, true);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
Returnvalue API
|
Returnvalue API
|
||||||
==================
|
==================
|
||||||
|
|
||||||
.. doxygenfile:: returnvalue.h
|
.. doxygenfile:: HasReturnvaluesIF.h
|
||||||
|
|
||||||
.. _fwclassids:
|
.. _fwclassids:
|
||||||
|
|
||||||
|
@ -75,11 +75,11 @@ and the respective source file with sensible default return values:
|
|||||||
void TestDeviceHandler::doShutDown() {}
|
void TestDeviceHandler::doShutDown() {}
|
||||||
|
|
||||||
ReturnValue_t TestDeviceHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
|
ReturnValue_t TestDeviceHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TestDeviceHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
|
ReturnValue_t TestDeviceHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestDeviceHandler::fillCommandAndReplyMap() {}
|
void TestDeviceHandler::fillCommandAndReplyMap() {}
|
||||||
@ -87,17 +87,17 @@ and the respective source file with sensible default return values:
|
|||||||
ReturnValue_t TestDeviceHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
ReturnValue_t TestDeviceHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||||
const uint8_t* commandData,
|
const uint8_t* commandData,
|
||||||
size_t commandDataLen) {
|
size_t commandDataLen) {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TestDeviceHandler::scanForReply(const uint8_t* start, size_t remainingSize,
|
ReturnValue_t TestDeviceHandler::scanForReply(const uint8_t* start, size_t remainingSize,
|
||||||
DeviceCommandId_t* foundId, size_t* foundLen) {
|
DeviceCommandId_t* foundId, size_t* foundLen) {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TestDeviceHandler::interpretDeviceReply(DeviceCommandId_t id,
|
ReturnValue_t TestDeviceHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||||
const uint8_t* packet) {
|
const uint8_t* packet) {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t TestDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
|
uint32_t TestDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
|
||||||
@ -106,5 +106,5 @@ and the respective source file with sensible default return values:
|
|||||||
|
|
||||||
ReturnValue_t TestDeviceHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
ReturnValue_t TestDeviceHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||||
LocalDataPoolManager& poolManager) {
|
LocalDataPoolManager& poolManager) {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ You can use the following commands inside the ``fsfw`` folder to set up the buil
|
|||||||
.. code-block:: console
|
.. code-block:: console
|
||||||
|
|
||||||
mkdir build-tests && cd build-tests
|
mkdir build-tests && cd build-tests
|
||||||
cmake -DFSFW_BUILD_TESTS=ON -DFSFW_OSAL=host ..
|
cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host ..
|
||||||
|
|
||||||
|
|
||||||
You can also use ``-DFSFW_OSAL=linux`` on Linux systems.
|
You can also use ``-DFSFW_OSAL=linux`` on Linux systems.
|
||||||
|
@ -18,7 +18,7 @@ Failure Handling
|
|||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
Functions should return a defined :cpp:type:`ReturnValue_t` to signal to the caller that something has
|
Functions should return a defined :cpp:type:`ReturnValue_t` to signal to the caller that something has
|
||||||
gone wrong. Returnvalues must be unique. For this the function :cpp:func:`returnvalue::makeCode`
|
gone wrong. Returnvalues must be unique. For this the function :cpp:func:`HasReturnvaluesIF::makeReturnCode`
|
||||||
or the :ref:`macro MAKE_RETURN_CODE <retvalapi>` can be used. The ``CLASS_ID`` is a unique ID for that type of object.
|
or the :ref:`macro MAKE_RETURN_CODE <retvalapi>` can be used. The ``CLASS_ID`` is a unique ID for that type of object.
|
||||||
See the :ref:`FSFW Class IDs file <fwclassids>`. The user can add custom ``CLASS_ID``\s via the
|
See the :ref:`FSFW Class IDs file <fwclassids>`. The user can add custom ``CLASS_ID``\s via the
|
||||||
``fsfwconfig`` folder.
|
``fsfwconfig`` folder.
|
||||||
|
@ -150,7 +150,7 @@ with a housekeeping service command.
|
|||||||
new PoolEntry<uint8_t>({0}));
|
new PoolEntry<uint8_t>({0}));
|
||||||
|
|
||||||
poolManager.subscribeForPeriodicPacket(gyroData.getSid(), false, 4.0, false);
|
poolManager.subscribeForPeriodicPacket(gyroData.getSid(), false, 4.0, false);
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Now, if we receive some sensor data and converted them into the right format,
|
Now, if we receive some sensor data and converted them into the right format,
|
||||||
@ -160,7 +160,7 @@ in any case:
|
|||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
|
|
||||||
PoolReadGuard readHelper(&gyroData);
|
PoolReadGuard readHelper(&gyroData);
|
||||||
if(readHelper.getReadResult() == returnvalue::OK) {
|
if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||||
if(not gyroData.isValid()) {
|
if(not gyroData.isValid()) {
|
||||||
gyroData.setValidity(true, true);
|
gyroData.setValidity(true, true);
|
||||||
}
|
}
|
||||||
|
48
hal/CMakeLists.txt
Normal file
48
hal/CMakeLists.txt
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
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. Requires gpiod library" OFF)
|
||||||
|
# On by default for now because I did not have an issue including and compiling those files
|
||||||
|
# and libraries on a Desktop Linux system and the primary target of the FSFW is still embedded
|
||||||
|
# Linux. The only exception from this is the gpiod library which requires a dedicated installation,
|
||||||
|
# but CMake is able to determine whether this library is installed with find_library.
|
||||||
|
option(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS "Add peripheral drivers for embedded Linux" ON)
|
||||||
|
option(FSFW_HAL_LINUX_ADD_LIBGPIOD "Target implements libgpiod" ON)
|
||||||
|
|
||||||
|
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}
|
||||||
|
)
|
9
hal/src/CMakeLists.txt
Normal file
9
hal/src/CMakeLists.txt
Normal file
@ -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)
|
3
hal/src/fsfw_hal/common/gpio/CMakeLists.txt
Normal file
3
hal/src/fsfw_hal/common/gpio/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
GpioCookie.cpp
|
||||||
|
)
|
@ -11,7 +11,7 @@ ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
|
|||||||
#else
|
#else
|
||||||
sif::printWarning("GpioCookie::addGpio: gpioConfig is nullpointer\n");
|
sif::printWarning("GpioCookie::addGpio: gpioConfig is nullpointer\n");
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
auto gpioMapIter = gpioMap.find(gpioId);
|
auto gpioMapIter = gpioMap.find(gpioId);
|
||||||
if (gpioMapIter == gpioMap.end()) {
|
if (gpioMapIter == gpioMap.end()) {
|
||||||
@ -25,9 +25,9 @@ ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
|
|||||||
sif::printWarning("GpioCookie::addGpio: Failed to add GPIO %d to GPIO map\n", gpioId);
|
sif::printWarning("GpioCookie::addGpio: Failed to add GPIO %d to GPIO map\n", gpioId);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
@ -36,7 +36,7 @@ ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
|
|||||||
sif::printWarning("GpioCookie::addGpio: GPIO already exists in GPIO map\n");
|
sif::printWarning("GpioCookie::addGpio: GPIO already exists in GPIO map\n");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
GpioMap GpioCookie::getGpioMap() const { return gpioMap; }
|
GpioMap GpioCookie::getGpioMap() const { return gpioMap; }
|
@ -2,7 +2,7 @@
|
|||||||
#define COMMON_GPIO_GPIOCOOKIE_H_
|
#define COMMON_GPIO_GPIOCOOKIE_H_
|
||||||
|
|
||||||
#include <fsfw/devicehandlers/CookieIF.h>
|
#include <fsfw/devicehandlers/CookieIF.h>
|
||||||
#include <fsfw/returnvalues/returnvalue.h>
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
|
||||||
#include "GpioIF.h"
|
#include "GpioIF.h"
|
||||||
#include "gpioDefinitions.h"
|
#include "gpioDefinitions.h"
|
@ -2,7 +2,7 @@
|
|||||||
#define COMMON_GPIO_GPIOIF_H_
|
#define COMMON_GPIO_GPIOIF_H_
|
||||||
|
|
||||||
#include <fsfw/devicehandlers/CookieIF.h>
|
#include <fsfw/devicehandlers/CookieIF.h>
|
||||||
#include <fsfw/returnvalues/returnvalue.h>
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
|
||||||
#include "gpioDefinitions.h"
|
#include "gpioDefinitions.h"
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ class GpioCookie;
|
|||||||
* over GPIOs.
|
* over GPIOs.
|
||||||
* @author J. Meier
|
* @author J. Meier
|
||||||
*/
|
*/
|
||||||
class GpioIF {
|
class GpioIF : public HasReturnvaluesIF {
|
||||||
public:
|
public:
|
||||||
virtual ~GpioIF(){};
|
virtual ~GpioIF(){};
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ class GpioIF {
|
|||||||
* functionality to pull a certain GPIO to high logic level.
|
* functionality to pull a certain GPIO to high logic level.
|
||||||
*
|
*
|
||||||
* @param gpioId A unique number which specifies the GPIO to drive.
|
* @param gpioId A unique number which specifies the GPIO to drive.
|
||||||
* @return Returns returnvalue::OK for success. This should never return returnvalue::FAILED.
|
* @return Returns RETURN_OK for success. This should never return RETURN_FAILED.
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t pullHigh(gpioId_t gpioId) = 0;
|
virtual ReturnValue_t pullHigh(gpioId_t gpioId) = 0;
|
||||||
|
|
||||||
@ -46,9 +46,9 @@ class GpioIF {
|
|||||||
* an ouput or input gpio.
|
* an ouput or input gpio.
|
||||||
*
|
*
|
||||||
* @param gpioId A unique number which specifies the GPIO to read.
|
* @param gpioId A unique number which specifies the GPIO to read.
|
||||||
* @param gpioState State of GPIO will be written to this reference
|
* @param gpioState State of GPIO will be written to this pointer.
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t readGpio(gpioId_t gpioId, gpio::Levels& gpioState) = 0;
|
virtual ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* COMMON_GPIO_GPIOIF_H_ */
|
#endif /* COMMON_GPIO_GPIOIF_H_ */
|
@ -9,7 +9,7 @@ using gpioId_t = uint16_t;
|
|||||||
|
|
||||||
namespace gpio {
|
namespace gpio {
|
||||||
|
|
||||||
enum class Levels : int { LOW = 0, HIGH = 1, FAILED = -1, NONE = 99 };
|
enum class Levels : int { LOW = 0, HIGH = 1, NONE = 99 };
|
||||||
|
|
||||||
enum class Direction : int { IN = 0, OUT = 1 };
|
enum class Direction : int { IN = 0, OUT = 1 };
|
||||||
|
|
5
hal/src/fsfw_hal/devicehandlers/CMakeLists.txt
Normal file
5
hal/src/fsfw_hal/devicehandlers/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
GyroL3GD20Handler.cpp
|
||||||
|
MgmRM3100Handler.cpp
|
||||||
|
MgmLIS3MDLHandler.cpp
|
||||||
|
)
|
@ -70,9 +70,9 @@ ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t
|
|||||||
"GyroL3GD20Handler::buildTransitionDeviceCommand: "
|
"GyroL3GD20Handler::buildTransitionDeviceCommand: "
|
||||||
"Unknown internal state!\n");
|
"Unknown internal state!\n");
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GyroHandlerL3GD20H::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
ReturnValue_t GyroHandlerL3GD20H::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||||
@ -135,7 +135,7 @@ ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(DeviceCommandId_t devi
|
|||||||
default:
|
default:
|
||||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GyroHandlerL3GD20H::scanForReply(const uint8_t *start, size_t len,
|
ReturnValue_t GyroHandlerL3GD20H::scanForReply(const uint8_t *start, size_t len,
|
||||||
@ -144,12 +144,12 @@ ReturnValue_t GyroHandlerL3GD20H::scanForReply(const uint8_t *start, size_t len,
|
|||||||
*foundId = this->getPendingCommand();
|
*foundId = this->getPendingCommand();
|
||||||
*foundLen = this->rawPacketLen;
|
*foundLen = this->rawPacketLen;
|
||||||
|
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
||||||
const uint8_t *packet) {
|
const uint8_t *packet) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case (L3GD20H::CONFIGURE_CTRL_REGS): {
|
case (L3GD20H::CONFIGURE_CTRL_REGS): {
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
@ -207,7 +207,7 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
PoolReadGuard readSet(&dataset);
|
PoolReadGuard readSet(&dataset);
|
||||||
if (readSet.getReadResult() == returnvalue::OK) {
|
if (readSet.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||||
if (std::abs(angVelocX) < this->absLimitX) {
|
if (std::abs(angVelocX) < this->absLimitX) {
|
||||||
dataset.angVelocX = angVelocX;
|
dataset.angVelocX = angVelocX;
|
||||||
dataset.angVelocX.setValid(true);
|
dataset.angVelocX.setValid(true);
|
||||||
@ -252,9 +252,7 @@ ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(localpool::DataPool &l
|
|||||||
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Y, new PoolEntry<float>({0.0}));
|
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Y, new PoolEntry<float>({0.0}));
|
||||||
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Z, new PoolEntry<float>({0.0}));
|
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Z, new PoolEntry<float>({0.0}));
|
||||||
localDataPoolMap.emplace(L3GD20H::TEMPERATURE, new PoolEntry<float>({0.0}));
|
localDataPoolMap.emplace(L3GD20H::TEMPERATURE, new PoolEntry<float>({0.0}));
|
||||||
poolManager.subscribeForRegularPeriodicPacket(
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
subdp::RegularHkPeriodicParams(dataset.getSid(), false, 10.0));
|
|
||||||
return returnvalue::OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GyroHandlerL3GD20H::fillCommandAndReplyMap() {
|
void GyroHandlerL3GD20H::fillCommandAndReplyMap() {
|
@ -82,7 +82,7 @@ ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand(DeviceCommandId_t
|
|||||||
#else
|
#else
|
||||||
sif::printWarning("GyroHandler::buildTransitionDeviceCommand: Unknown internal state!\n");
|
sif::printWarning("GyroHandler::buildTransitionDeviceCommand: Unknown internal state!\n");
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buildCommandFromCommand(*id, NULL, 0);
|
return buildCommandFromCommand(*id, NULL, 0);
|
||||||
@ -137,7 +137,7 @@ ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(DeviceCommandId_t devic
|
|||||||
|
|
||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
rawPacketLen = MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1;
|
rawPacketLen = MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1;
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
case (MGMLIS3MDL::READ_TEMPERATURE): {
|
case (MGMLIS3MDL::READ_TEMPERATURE): {
|
||||||
std::memset(commandBuffer, 0, 3);
|
std::memset(commandBuffer, 0, 3);
|
||||||
@ -145,7 +145,7 @@ ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(DeviceCommandId_t devic
|
|||||||
|
|
||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
rawPacketLen = 3;
|
rawPacketLen = 3;
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
case (MGMLIS3MDL::IDENTIFY_DEVICE): {
|
case (MGMLIS3MDL::IDENTIFY_DEVICE): {
|
||||||
return identifyDevice();
|
return identifyDevice();
|
||||||
@ -155,7 +155,7 @@ ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(DeviceCommandId_t devic
|
|||||||
}
|
}
|
||||||
case (MGMLIS3MDL::SETUP_MGM): {
|
case (MGMLIS3MDL::SETUP_MGM): {
|
||||||
setupMgm();
|
setupMgm();
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
case (MGMLIS3MDL::ACCURACY_OP_MODE_SET): {
|
case (MGMLIS3MDL::ACCURACY_OP_MODE_SET): {
|
||||||
return setOperatingMode(commandData, commandDataLen);
|
return setOperatingMode(commandData, commandDataLen);
|
||||||
@ -163,7 +163,7 @@ ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(DeviceCommandId_t devic
|
|||||||
default:
|
default:
|
||||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmLIS3MDLHandler::identifyDevice() {
|
ReturnValue_t MgmLIS3MDLHandler::identifyDevice() {
|
||||||
@ -174,7 +174,7 @@ ReturnValue_t MgmLIS3MDLHandler::identifyDevice() {
|
|||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
rawPacketLen = size;
|
rawPacketLen = size;
|
||||||
|
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start, size_t len,
|
ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start, size_t len,
|
||||||
@ -234,7 +234,7 @@ ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start, size_t len,
|
|||||||
|
|
||||||
/* Data with SPI Interface always has this answer */
|
/* Data with SPI Interface always has this answer */
|
||||||
if (start[0] == 0b11111111) {
|
if (start[0] == 0b11111111) {
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
} else {
|
} else {
|
||||||
return DeviceHandlerIF::INVALID_DATA;
|
return DeviceHandlerIF::INVALID_DATA;
|
||||||
}
|
}
|
||||||
@ -285,23 +285,27 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
PoolReadGuard readHelper(&dataset);
|
PoolReadGuard readHelper(&dataset);
|
||||||
if (readHelper.getReadResult() == returnvalue::OK) {
|
if (readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||||
if (std::abs(mgmX) > absLimitX or std::abs(mgmY) > absLimitY or
|
|
||||||
std::abs(mgmZ) > absLimitZ) {
|
|
||||||
dataset.fieldStrengths.setValid(false);
|
|
||||||
}
|
|
||||||
if (std::abs(mgmX) < absLimitX) {
|
if (std::abs(mgmX) < absLimitX) {
|
||||||
dataset.fieldStrengths[0] = mgmX;
|
dataset.fieldStrengthX = mgmX;
|
||||||
|
dataset.fieldStrengthX.setValid(true);
|
||||||
|
} else {
|
||||||
|
dataset.fieldStrengthX.setValid(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::abs(mgmY) < absLimitY) {
|
if (std::abs(mgmY) < absLimitY) {
|
||||||
dataset.fieldStrengths[1] = mgmY;
|
dataset.fieldStrengthY = mgmY;
|
||||||
|
dataset.fieldStrengthY.setValid(true);
|
||||||
|
} else {
|
||||||
|
dataset.fieldStrengthY.setValid(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::abs(mgmZ) < absLimitZ) {
|
if (std::abs(mgmZ) < absLimitZ) {
|
||||||
dataset.fieldStrengths[2] = mgmZ;
|
dataset.fieldStrengthZ = mgmZ;
|
||||||
|
dataset.fieldStrengthZ.setValid(true);
|
||||||
|
} else {
|
||||||
|
dataset.fieldStrengthZ.setValid(false);
|
||||||
}
|
}
|
||||||
dataset.fieldStrengths.setValid(true);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -320,7 +324,7 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t result = dataset.read();
|
ReturnValue_t result = dataset.read();
|
||||||
if (result == returnvalue::OK) {
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||||
dataset.temperature = tempValue;
|
dataset.temperature = tempValue;
|
||||||
dataset.commit();
|
dataset.commit();
|
||||||
}
|
}
|
||||||
@ -331,7 +335,7 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, cons
|
|||||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
MGMLIS3MDL::Sensitivies MgmLIS3MDLHandler::getSensitivity(uint8_t ctrlRegister2) {
|
MGMLIS3MDL::Sensitivies MgmLIS3MDLHandler::getSensitivity(uint8_t ctrlRegister2) {
|
||||||
@ -371,16 +375,13 @@ float MgmLIS3MDLHandler::getSensitivityFactor(MGMLIS3MDL::Sensitivies sens) {
|
|||||||
|
|
||||||
ReturnValue_t MgmLIS3MDLHandler::enableTemperatureSensor(const uint8_t *commandData,
|
ReturnValue_t MgmLIS3MDLHandler::enableTemperatureSensor(const uint8_t *commandData,
|
||||||
size_t commandDataLen) {
|
size_t commandDataLen) {
|
||||||
if (commandData == nullptr) {
|
|
||||||
return INVALID_COMMAND_PARAMETER;
|
|
||||||
}
|
|
||||||
triggerEvent(CHANGE_OF_SETUP_PARAMETER);
|
triggerEvent(CHANGE_OF_SETUP_PARAMETER);
|
||||||
uint32_t size = 2;
|
uint32_t size = 2;
|
||||||
commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1);
|
commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1);
|
||||||
if (commandDataLen > 1) {
|
if (commandDataLen > 1) {
|
||||||
return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
||||||
}
|
}
|
||||||
switch (commandData[0]) {
|
switch (*commandData) {
|
||||||
case (MGMLIS3MDL::ON): {
|
case (MGMLIS3MDL::ON): {
|
||||||
commandBuffer[1] = registers[0] | (1 << 7);
|
commandBuffer[1] = registers[0] | (1 << 7);
|
||||||
break;
|
break;
|
||||||
@ -397,7 +398,7 @@ ReturnValue_t MgmLIS3MDLHandler::enableTemperatureSensor(const uint8_t *commandD
|
|||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
rawPacketLen = size;
|
rawPacketLen = size;
|
||||||
|
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmLIS3MDLHandler::setOperatingMode(const uint8_t *commandData,
|
ReturnValue_t MgmLIS3MDLHandler::setOperatingMode(const uint8_t *commandData,
|
||||||
@ -454,7 +455,7 @@ ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() {
|
|||||||
rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1;
|
rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1;
|
||||||
|
|
||||||
// We dont have to check if this is working because we just did i
|
// We dont have to check if this is working because we just did i
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgmLIS3MDLHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
|
void MgmLIS3MDLHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
|
||||||
@ -467,10 +468,11 @@ void MgmLIS3MDLHandler::modeChanged(void) { internalState = InternalState::STATE
|
|||||||
|
|
||||||
ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||||
LocalDataPoolManager &poolManager) {
|
LocalDataPoolManager &poolManager) {
|
||||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTHS, &mgmXYZ);
|
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
|
||||||
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, &temperature);
|
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
|
||||||
poolManager.subscribeForRegularPeriodicPacket({dataset.getSid(), false, 10.0});
|
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
|
||||||
return returnvalue::OK;
|
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, new PoolEntry<float>({0.0}));
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgmLIS3MDLHandler::setAbsoluteLimits(float xLimit, float yLimit, float zLimit) {
|
void MgmLIS3MDLHandler::setAbsoluteLimits(float xLimit, float yLimit, float zLimit) {
|
@ -103,8 +103,6 @@ class MgmLIS3MDLHandler : public DeviceHandlerBase {
|
|||||||
CommunicationStep communicationStep = CommunicationStep::DATA;
|
CommunicationStep communicationStep = CommunicationStep::DATA;
|
||||||
bool commandExecuted = false;
|
bool commandExecuted = false;
|
||||||
|
|
||||||
PoolEntry<float> mgmXYZ = PoolEntry<float>(3);
|
|
||||||
PoolEntry<float> temperature = PoolEntry<float>();
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Device specific commands and variables */
|
/* Device specific commands and variables */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
@ -4,7 +4,7 @@
|
|||||||
#include "fsfw/devicehandlers/DeviceHandlerMessage.h"
|
#include "fsfw/devicehandlers/DeviceHandlerMessage.h"
|
||||||
#include "fsfw/globalfunctions/bitutility.h"
|
#include "fsfw/globalfunctions/bitutility.h"
|
||||||
#include "fsfw/objectmanager/SystemObjectIF.h"
|
#include "fsfw/objectmanager/SystemObjectIF.h"
|
||||||
#include "fsfw/returnvalues/returnvalue.h"
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
|
||||||
MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication,
|
MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication,
|
||||||
CookieIF *comCookie, uint32_t transitionDelay)
|
CookieIF *comCookie, uint32_t transitionDelay)
|
||||||
@ -93,7 +93,7 @@ ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(DeviceCommandId_t *
|
|||||||
"Unknown internal state\n");
|
"Unknown internal state\n");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildCommandFromCommand(*id, commandBuffer, commandLen);
|
return buildCommandFromCommand(*id, commandBuffer, commandLen);
|
||||||
@ -146,7 +146,7 @@ ReturnValue_t MgmRM3100Handler::buildCommandFromCommand(DeviceCommandId_t device
|
|||||||
default:
|
default:
|
||||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
ReturnValue_t MgmRM3100Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||||
@ -159,11 +159,11 @@ ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start, size_t len,
|
|||||||
// For SPI, ID will always be the one of the last sent command
|
// For SPI, ID will always be the one of the last sent command
|
||||||
*foundId = this->getPendingCommand();
|
*foundId = this->getPendingCommand();
|
||||||
*foundLen = len;
|
*foundLen = len;
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case (RM3100::CONFIGURE_CMM):
|
case (RM3100::CONFIGURE_CMM):
|
||||||
case (RM3100::CONFIGURE_CYCLE_COUNT):
|
case (RM3100::CONFIGURE_CYCLE_COUNT):
|
||||||
@ -250,7 +250,7 @@ ReturnValue_t MgmRM3100Handler::handleCycleCountConfigCommand(DeviceCommandId_t
|
|||||||
std::memcpy(commandBuffer + 5, &cycleCountRegValueZ, 2);
|
std::memcpy(commandBuffer + 5, &cycleCountRegValueZ, 2);
|
||||||
rawPacketLen = 7;
|
rawPacketLen = 7;
|
||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue, const uint8_t *commandData,
|
ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue, const uint8_t *commandData,
|
||||||
@ -258,7 +258,7 @@ ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue, const uin
|
|||||||
RM3100::CycleCountCommand command(oneCycleValue);
|
RM3100::CycleCountCommand command(oneCycleValue);
|
||||||
ReturnValue_t result =
|
ReturnValue_t result =
|
||||||
command.deSerialize(&commandData, &commandDataLen, SerializeIF::Endianness::BIG);
|
command.deSerialize(&commandData, &commandDataLen, SerializeIF::Endianness::BIG);
|
||||||
if (result != returnvalue::OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +274,7 @@ ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue, const uin
|
|||||||
cycleCountRegValueX = command.cycleCountX;
|
cycleCountRegValueX = command.cycleCountX;
|
||||||
cycleCountRegValueY = command.cycleCountY;
|
cycleCountRegValueY = command.cycleCountY;
|
||||||
cycleCountRegValueZ = command.cycleCountZ;
|
cycleCountRegValueZ = command.cycleCountZ;
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::handleTmrcConfigCommand(DeviceCommandId_t deviceCommand,
|
ReturnValue_t MgmRM3100Handler::handleTmrcConfigCommand(DeviceCommandId_t deviceCommand,
|
||||||
@ -289,7 +289,7 @@ ReturnValue_t MgmRM3100Handler::handleTmrcConfigCommand(DeviceCommandId_t device
|
|||||||
tmrcRegValue = commandData[0];
|
tmrcRegValue = commandData[0];
|
||||||
rawPacketLen = 2;
|
rawPacketLen = 2;
|
||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgmRM3100Handler::fillCommandAndReplyMap() {
|
void MgmRM3100Handler::fillCommandAndReplyMap() {
|
||||||
@ -305,13 +305,14 @@ void MgmRM3100Handler::fillCommandAndReplyMap() {
|
|||||||
insertInCommandAndReplyMap(RM3100::READ_DATA, 3, &primaryDataset);
|
insertInCommandAndReplyMap(RM3100::READ_DATA, 3, &primaryDataset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgmRM3100Handler::modeChanged() { internalState = InternalState::NONE; }
|
void MgmRM3100Handler::modeChanged(void) { internalState = InternalState::NONE; }
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||||
LocalDataPoolManager &poolManager) {
|
LocalDataPoolManager &poolManager) {
|
||||||
localDataPoolMap.emplace(RM3100::FIELD_STRENGTHS, &mgmXYZ);
|
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
|
||||||
poolManager.subscribeForRegularPeriodicPacket({primaryDataset.getSid(), false, 10.0});
|
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
|
||||||
return returnvalue::OK;
|
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t MgmRM3100Handler::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
uint32_t MgmRM3100Handler::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||||
@ -352,13 +353,13 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
|||||||
|
|
||||||
// TODO: Sanity check on values?
|
// TODO: Sanity check on values?
|
||||||
PoolReadGuard readGuard(&primaryDataset);
|
PoolReadGuard readGuard(&primaryDataset);
|
||||||
if (readGuard.getReadResult() == returnvalue::OK) {
|
if (readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||||
primaryDataset.fieldStrengths[0] = fieldStrengthX;
|
primaryDataset.fieldStrengthX = fieldStrengthX;
|
||||||
primaryDataset.fieldStrengths[1] = fieldStrengthY;
|
primaryDataset.fieldStrengthY = fieldStrengthY;
|
||||||
primaryDataset.fieldStrengths[2] = fieldStrengthZ;
|
primaryDataset.fieldStrengthZ = fieldStrengthZ;
|
||||||
primaryDataset.setValidity(true, true);
|
primaryDataset.setValidity(true, true);
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgmRM3100Handler::enablePeriodicPrintouts(bool enable, uint8_t divider) {
|
void MgmRM3100Handler::enablePeriodicPrintouts(bool enable, uint8_t divider) {
|
@ -85,7 +85,6 @@ class MgmRM3100Handler : public DeviceHandlerBase {
|
|||||||
|
|
||||||
bool goToNormalModeAtStartup = false;
|
bool goToNormalModeAtStartup = false;
|
||||||
uint32_t transitionDelay;
|
uint32_t transitionDelay;
|
||||||
PoolEntry<float> mgmXYZ = PoolEntry<float>(3);
|
|
||||||
|
|
||||||
ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
|
ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
|
||||||
const uint8_t *commandData, size_t commandDataLen);
|
const uint8_t *commandData, size_t commandDataLen);
|
@ -139,7 +139,12 @@ static const uint8_t CTRL_REG5_DEFAULT = 0;
|
|||||||
|
|
||||||
static const uint32_t MGM_DATA_SET_ID = READ_CONFIG_AND_DATA;
|
static const uint32_t MGM_DATA_SET_ID = READ_CONFIG_AND_DATA;
|
||||||
|
|
||||||
enum MgmPoolIds : lp_id_t { FIELD_STRENGTHS, TEMPERATURE_CELCIUS };
|
enum MgmPoolIds : lp_id_t {
|
||||||
|
FIELD_STRENGTH_X,
|
||||||
|
FIELD_STRENGTH_Y,
|
||||||
|
FIELD_STRENGTH_Z,
|
||||||
|
TEMPERATURE_CELCIUS
|
||||||
|
};
|
||||||
|
|
||||||
class MgmPrimaryDataset : public StaticLocalDataSet<4> {
|
class MgmPrimaryDataset : public StaticLocalDataSet<4> {
|
||||||
public:
|
public:
|
||||||
@ -147,10 +152,9 @@ class MgmPrimaryDataset : public StaticLocalDataSet<4> {
|
|||||||
|
|
||||||
MgmPrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
|
MgmPrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
|
||||||
|
|
||||||
/**
|
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_X, this);
|
||||||
* Field strenghts in uT
|
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Y, this);
|
||||||
*/
|
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Z, this);
|
||||||
lp_vec_t<float, 3> fieldStrengths = lp_vec_t<float, 3>(sid.objectId, FIELD_STRENGTHS, this);
|
|
||||||
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, TEMPERATURE_CELCIUS, this);
|
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, TEMPERATURE_CELCIUS, this);
|
||||||
};
|
};
|
||||||
|
|
@ -101,7 +101,11 @@ class CycleCountCommand : public SerialLinkedListAdapter<SerializeIF> {
|
|||||||
|
|
||||||
static constexpr uint32_t MGM_DATASET_ID = READ_DATA;
|
static constexpr uint32_t MGM_DATASET_ID = READ_DATA;
|
||||||
|
|
||||||
enum MgmPoolIds : lp_id_t { FIELD_STRENGTHS };
|
enum MgmPoolIds : lp_id_t {
|
||||||
|
FIELD_STRENGTH_X,
|
||||||
|
FIELD_STRENGTH_Y,
|
||||||
|
FIELD_STRENGTH_Z,
|
||||||
|
};
|
||||||
|
|
||||||
class Rm3100PrimaryDataset : public StaticLocalDataSet<3> {
|
class Rm3100PrimaryDataset : public StaticLocalDataSet<3> {
|
||||||
public:
|
public:
|
||||||
@ -109,10 +113,10 @@ class Rm3100PrimaryDataset : public StaticLocalDataSet<3> {
|
|||||||
|
|
||||||
Rm3100PrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {}
|
Rm3100PrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {}
|
||||||
|
|
||||||
/**
|
// Field strengths in micro Tesla.
|
||||||
* Field strenghts in uT
|
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_X, this);
|
||||||
*/
|
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Y, this);
|
||||||
lp_vec_t<float, 3> fieldStrengths = lp_vec_t<float, 3>(sid.objectId, FIELD_STRENGTHS, this);
|
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Z, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace RM3100
|
} // namespace RM3100
|
25
hal/src/fsfw_hal/linux/CMakeLists.txt
Normal file
25
hal/src/fsfw_hal/linux/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
if(FSFW_HAL_ADD_RASPBERRY_PI)
|
||||||
|
add_subdirectory(rpi)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
UnixFileGuard.cpp
|
||||||
|
CommandExecutor.cpp
|
||||||
|
utility.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
if(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS)
|
||||||
|
if(FSFW_HAL_LINUX_ADD_LIBGPIOD)
|
||||||
|
add_subdirectory(gpio)
|
||||||
|
endif()
|
||||||
|
add_subdirectory(uart)
|
||||||
|
# Adding those does not really make sense on Apple systems which
|
||||||
|
# are generally host systems. It won't even compile as the headers
|
||||||
|
# are missing
|
||||||
|
if(NOT APPLE)
|
||||||
|
add_subdirectory(i2c)
|
||||||
|
add_subdirectory(spi)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(uio)
|
@ -23,7 +23,7 @@ ReturnValue_t CommandExecutor::load(std::string command, bool blocking, bool pri
|
|||||||
if (state == States::IDLE) {
|
if (state == States::IDLE) {
|
||||||
state = States::COMMAND_LOADED;
|
state = States::COMMAND_LOADED;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t CommandExecutor::execute() {
|
ReturnValue_t CommandExecutor::execute() {
|
||||||
@ -32,12 +32,10 @@ ReturnValue_t CommandExecutor::execute() {
|
|||||||
} else if (state == States::PENDING) {
|
} else if (state == States::PENDING) {
|
||||||
return COMMAND_PENDING;
|
return COMMAND_PENDING;
|
||||||
}
|
}
|
||||||
// Reset data in read vector
|
|
||||||
std::memset(readVec.data(), 0, readVec.size());
|
|
||||||
currentCmdFile = popen(currentCmd.c_str(), "r");
|
currentCmdFile = popen(currentCmd.c_str(), "r");
|
||||||
if (currentCmdFile == nullptr) {
|
if (currentCmdFile == nullptr) {
|
||||||
lastError = errno;
|
lastError = errno;
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
if (blocking) {
|
if (blocking) {
|
||||||
ReturnValue_t result = executeBlocking();
|
ReturnValue_t result = executeBlocking();
|
||||||
@ -48,7 +46,7 @@ ReturnValue_t CommandExecutor::execute() {
|
|||||||
waiter.fd = currentFd;
|
waiter.fd = currentFd;
|
||||||
}
|
}
|
||||||
state = States::PENDING;
|
state = States::PENDING;
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t CommandExecutor::close() {
|
ReturnValue_t CommandExecutor::close() {
|
||||||
@ -58,7 +56,7 @@ ReturnValue_t CommandExecutor::close() {
|
|||||||
pclose(currentCmdFile);
|
pclose(currentCmdFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandExecutor::printLastError(std::string funcName) const {
|
void CommandExecutor::printLastError(std::string funcName) const {
|
||||||
@ -81,7 +79,7 @@ void CommandExecutor::setRingBuffer(SimpleRingBuffer* ringBuffer,
|
|||||||
|
|
||||||
ReturnValue_t CommandExecutor::check(bool& replyReceived) {
|
ReturnValue_t CommandExecutor::check(bool& replyReceived) {
|
||||||
if (blocking) {
|
if (blocking) {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case (States::IDLE):
|
case (States::IDLE):
|
||||||
@ -96,7 +94,7 @@ ReturnValue_t CommandExecutor::check(bool& replyReceived) {
|
|||||||
int result = poll(&waiter, 1, 0);
|
int result = poll(&waiter, 1, 0);
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case (0): {
|
case (0): {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case (1): {
|
case (1): {
|
||||||
@ -153,7 +151,7 @@ ReturnValue_t CommandExecutor::check(bool& replyReceived) {
|
|||||||
ReturnValue_t retval = EXECUTION_FINISHED;
|
ReturnValue_t retval = EXECUTION_FINISHED;
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
lastError = result;
|
lastError = result;
|
||||||
retval = returnvalue::FAILED;
|
retval = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
state = States::IDLE;
|
state = States::IDLE;
|
||||||
currentCmdFile = nullptr;
|
currentCmdFile = nullptr;
|
||||||
@ -163,7 +161,7 @@ ReturnValue_t CommandExecutor::check(bool& replyReceived) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandExecutor::reset() {
|
void CommandExecutor::reset() {
|
||||||
@ -203,9 +201,7 @@ ReturnValue_t CommandExecutor::executeBlocking() {
|
|||||||
int result = pclose(currentCmdFile);
|
int result = pclose(currentCmdFile);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
lastError = result;
|
lastError = result;
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<char>& CommandExecutor::getReadVector() const { return readVec; }
|
|
@ -7,7 +7,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "fsfw/returnvalues/FwClassIds.h"
|
#include "fsfw/returnvalues/FwClassIds.h"
|
||||||
#include "fsfw/returnvalues/returnvalue.h"
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
|
||||||
class SimpleRingBuffer;
|
class SimpleRingBuffer;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -31,25 +31,27 @@ class CommandExecutor {
|
|||||||
static constexpr uint8_t CLASS_ID = CLASS_ID::LINUX_OSAL;
|
static constexpr uint8_t CLASS_ID = CLASS_ID::LINUX_OSAL;
|
||||||
|
|
||||||
//! [EXPORT] : [COMMENT] Execution of the current command has finished
|
//! [EXPORT] : [COMMENT] Execution of the current command has finished
|
||||||
static constexpr ReturnValue_t EXECUTION_FINISHED = returnvalue::makeCode(CLASS_ID, 0);
|
static constexpr ReturnValue_t EXECUTION_FINISHED =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 0);
|
||||||
|
|
||||||
//! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries
|
//! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries
|
||||||
//! to load another command but a command is still pending
|
//! to load another command but a command is still pending
|
||||||
static constexpr ReturnValue_t COMMAND_PENDING = returnvalue::makeCode(CLASS_ID, 1);
|
static constexpr ReturnValue_t COMMAND_PENDING = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
|
||||||
//! [EXPORT] : [COMMENT] Some bytes have been read from the executing process
|
//! [EXPORT] : [COMMENT] Some bytes have been read from the executing process
|
||||||
static constexpr ReturnValue_t BYTES_READ = returnvalue::makeCode(CLASS_ID, 2);
|
static constexpr ReturnValue_t BYTES_READ = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2);
|
||||||
//! [EXPORT] : [COMMENT] Command execution failed
|
//! [EXPORT] : [COMMENT] Command execution failed
|
||||||
static constexpr ReturnValue_t COMMAND_ERROR = returnvalue::makeCode(CLASS_ID, 3);
|
static constexpr ReturnValue_t COMMAND_ERROR = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3);
|
||||||
//! [EXPORT] : [COMMENT]
|
//! [EXPORT] : [COMMENT]
|
||||||
static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING = returnvalue::makeCode(CLASS_ID, 4);
|
static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING =
|
||||||
static constexpr ReturnValue_t PCLOSE_CALL_ERROR = returnvalue::makeCode(CLASS_ID, 6);
|
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 4);
|
||||||
|
static constexpr ReturnValue_t PCLOSE_CALL_ERROR = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 6);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. Is initialized with maximum size of internal buffer to read data from the
|
* Constructor. Is initialized with maximum size of internal buffer to read data from the
|
||||||
* executed process.
|
* executed process.
|
||||||
* @param maxSize
|
* @param maxSize
|
||||||
*/
|
*/
|
||||||
explicit CommandExecutor(size_t maxSize);
|
CommandExecutor(const size_t maxSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a new command which should be executed
|
* Load a new command which should be executed
|
||||||
@ -62,11 +64,11 @@ class CommandExecutor {
|
|||||||
/**
|
/**
|
||||||
* Execute the loaded command.
|
* Execute the loaded command.
|
||||||
* @return
|
* @return
|
||||||
* - In blocking mode, it will return returnvalue::FAILED if
|
* - In blocking mode, it will return RETURN_FAILED if
|
||||||
* the result of the system call was not 0. The error value can be accessed using
|
* the result of the system call was not 0. The error value can be accessed using
|
||||||
* getLastError
|
* getLastError
|
||||||
* - In non-blocking mode, this call will start
|
* - In non-blocking mode, this call will start
|
||||||
* the execution and then return returnvalue::OK
|
* the execution and then return RETURN_OK
|
||||||
*/
|
*/
|
||||||
ReturnValue_t execute();
|
ReturnValue_t execute();
|
||||||
/**
|
/**
|
||||||
@ -75,8 +77,8 @@ class CommandExecutor {
|
|||||||
* @return
|
* @return
|
||||||
* - BYTES_READ if bytes have been read from the executing process. It is recommended to call
|
* - BYTES_READ if bytes have been read from the executing process. It is recommended to call
|
||||||
* check again after this
|
* check again after this
|
||||||
* - returnvalue::OK execution is pending, but no bytes have been read from the executing process
|
* - RETURN_OK execution is pending, but no bytes have been read from the executing process
|
||||||
* - returnvalue::FAILED if execution has failed, error value can be accessed using getLastError
|
* - RETURN_FAILED if execution has failed, error value can be accessed using getLastError
|
||||||
* - EXECUTION_FINISHED if the process was executed successfully
|
* - EXECUTION_FINISHED if the process was executed successfully
|
||||||
* - NO_COMMAND_LOADED_OR_PENDING self-explanatory
|
* - NO_COMMAND_LOADED_OR_PENDING self-explanatory
|
||||||
* - COMMAND_ERROR internal poll error
|
* - COMMAND_ERROR internal poll error
|
||||||
@ -85,7 +87,7 @@ class CommandExecutor {
|
|||||||
/**
|
/**
|
||||||
* Abort the current command. Should normally not be necessary, check can be used to find
|
* Abort the current command. Should normally not be necessary, check can be used to find
|
||||||
* out whether command execution was successful
|
* out whether command execution was successful
|
||||||
* @return returnvalue::OK
|
* @return RETURN_OK
|
||||||
*/
|
*/
|
||||||
ReturnValue_t close();
|
ReturnValue_t close();
|
||||||
|
|
||||||
@ -107,8 +109,6 @@ class CommandExecutor {
|
|||||||
*/
|
*/
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
const std::vector<char>& getReadVector() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string currentCmd;
|
std::string currentCmd;
|
||||||
bool blocking = true;
|
bool blocking = true;
|
@ -6,7 +6,7 @@
|
|||||||
#include "fsfw/FSFW.h"
|
#include "fsfw/FSFW.h"
|
||||||
#include "fsfw/serviceinterface.h"
|
#include "fsfw/serviceinterface.h"
|
||||||
|
|
||||||
UnixFileGuard::UnixFileGuard(const std::string& device, int* fileDescriptor, int flags,
|
UnixFileGuard::UnixFileGuard(std::string device, int* fileDescriptor, int flags,
|
||||||
std::string diagnosticPrefix)
|
std::string diagnosticPrefix)
|
||||||
: fileDescriptor(fileDescriptor) {
|
: fileDescriptor(fileDescriptor) {
|
||||||
if (fileDescriptor == nullptr) {
|
if (fileDescriptor == nullptr) {
|
@ -2,7 +2,7 @@
|
|||||||
#define LINUX_UTILITY_UNIXFILEGUARD_H_
|
#define LINUX_UTILITY_UNIXFILEGUARD_H_
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <fsfw/returnvalues/returnvalue.h>
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -15,7 +15,7 @@ class UnixFileGuard {
|
|||||||
|
|
||||||
static constexpr ReturnValue_t OPEN_FILE_FAILED = 1;
|
static constexpr ReturnValue_t OPEN_FILE_FAILED = 1;
|
||||||
|
|
||||||
UnixFileGuard(const std::string& device, int* fileDescriptor, int flags,
|
UnixFileGuard(std::string device, int* fileDescriptor, int flags,
|
||||||
std::string diagnosticPrefix = "");
|
std::string diagnosticPrefix = "");
|
||||||
|
|
||||||
virtual ~UnixFileGuard();
|
virtual ~UnixFileGuard();
|
||||||
@ -24,7 +24,7 @@ class UnixFileGuard {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int* fileDescriptor = nullptr;
|
int* fileDescriptor = nullptr;
|
||||||
ReturnValue_t openStatus = returnvalue::OK;
|
ReturnValue_t openStatus = HasReturnvaluesIF::RETURN_OK;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LINUX_UTILITY_UNIXFILEGUARD_H_ */
|
#endif /* LINUX_UTILITY_UNIXFILEGUARD_H_ */
|
16
hal/src/fsfw_hal/linux/gpio/CMakeLists.txt
Normal file
16
hal/src/fsfw_hal/linux/gpio/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# 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)
|
||||||
|
|
||||||
|
if(${LIB_GPIO} MATCHES LIB_GPIO-NOTFOUND)
|
||||||
|
message(STATUS "gpiod library not found, not linking against it")
|
||||||
|
else()
|
||||||
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
LinuxLibgpioIF.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
${LIB_GPIO}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
@ -23,30 +23,30 @@ ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
|
|||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "LinuxLibgpioIF::addGpios: Invalid cookie" << std::endl;
|
sif::error << "LinuxLibgpioIF::addGpios: Invalid cookie" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
GpioMap mapToAdd = gpioCookie->getGpioMap();
|
GpioMap mapToAdd = gpioCookie->getGpioMap();
|
||||||
|
|
||||||
/* Check whether this ID already exists in the map and remove duplicates */
|
/* Check whether this ID already exists in the map and remove duplicates */
|
||||||
result = checkForConflicts(mapToAdd);
|
result = checkForConflicts(mapToAdd);
|
||||||
if (result != returnvalue::OK) {
|
if (result != RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = configureGpios(mapToAdd);
|
result = configureGpios(mapToAdd);
|
||||||
if (result != returnvalue::OK) {
|
if (result != RETURN_OK) {
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register new GPIOs in gpioMap */
|
/* Register new GPIOs in gpioMap */
|
||||||
gpioMap.insert(mapToAdd.begin(), mapToAdd.end());
|
gpioMap.insert(mapToAdd.begin(), mapToAdd.end());
|
||||||
|
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = RETURN_OK;
|
||||||
for (auto& gpioConfig : mapToAdd) {
|
for (auto& gpioConfig : mapToAdd) {
|
||||||
auto& gpioType = gpioConfig.second->gpioType;
|
auto& gpioType = gpioConfig.second->gpioType;
|
||||||
switch (gpioType) {
|
switch (gpioType) {
|
||||||
@ -86,7 +86,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
|||||||
gpioCallback->initValue, gpioCallback->callbackArgs);
|
gpioCallback->initValue, gpioCallback->callbackArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result != returnvalue::OK) {
|
if (result != RETURN_OK) {
|
||||||
return GPIO_INIT_FAILED;
|
return GPIO_INIT_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLabel(gpioId_t gpioId,
|
|||||||
sif::warning << "LinuxLibgpioIF::configureGpioByLabel: Failed to open gpio from gpio "
|
sif::warning << "LinuxLibgpioIF::configureGpioByLabel: Failed to open gpio from gpio "
|
||||||
<< "group with label " << label << ". Gpio ID: " << gpioId << std::endl;
|
<< "group with label " << label << ". Gpio ID: " << gpioId << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
std::string failOutput = "label: " + label;
|
std::string failOutput = "label: " + label;
|
||||||
return configureRegularGpio(gpioId, chip, gpioByLabel, failOutput);
|
return configureRegularGpio(gpioId, chip, gpioByLabel, failOutput);
|
||||||
@ -116,7 +116,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId, GpiodRegularB
|
|||||||
sif::warning << "LinuxLibgpioIF::configureGpioByChip: Failed to open chip " << chipname
|
sif::warning << "LinuxLibgpioIF::configureGpioByChip: Failed to open chip " << chipname
|
||||||
<< ". Gpio ID: " << gpioId << std::endl;
|
<< ". Gpio ID: " << gpioId << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
std::string failOutput = "chipname: " + chipname;
|
std::string failOutput = "chipname: " + chipname;
|
||||||
return configureRegularGpio(gpioId, chip, gpioByChip, failOutput);
|
return configureRegularGpio(gpioId, chip, gpioByChip, failOutput);
|
||||||
@ -132,7 +132,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
|
|||||||
gpiod_ctxless_find_line(lineName.c_str(), chipname, MAX_CHIPNAME_LENGTH, &lineOffset);
|
gpiod_ctxless_find_line(lineName.c_str(), chipname, MAX_CHIPNAME_LENGTH, &lineOffset);
|
||||||
if (result != LINE_FOUND) {
|
if (result != LINE_FOUND) {
|
||||||
parseFindeLineResult(result, lineName);
|
parseFindeLineResult(result, lineName);
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpioByLineName.lineNum = static_cast<int>(lineOffset);
|
gpioByLineName.lineNum = static_cast<int>(lineOffset);
|
||||||
@ -143,7 +143,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
|
|||||||
sif::warning << "LinuxLibgpioIF::configureGpioByLineName: Failed to open chip " << chipname
|
sif::warning << "LinuxLibgpioIF::configureGpioByLineName: Failed to open chip " << chipname
|
||||||
<< ". <Gpio ID: " << gpioId << std::endl;
|
<< ". <Gpio ID: " << gpioId << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
std::string failOutput = "line name: " + lineName;
|
std::string failOutput = "line name: " + lineName;
|
||||||
return configureRegularGpio(gpioId, chip, gpioByLineName, failOutput);
|
return configureRegularGpio(gpioId, chip, gpioByLineName, failOutput);
|
||||||
@ -168,7 +168,7 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod
|
|||||||
sif::warning << "Check if Linux GPIO configuration has changed. " << std::endl;
|
sif::warning << "Check if Linux GPIO configuration has changed. " << std::endl;
|
||||||
#endif
|
#endif
|
||||||
gpiod_chip_close(chip);
|
gpiod_chip_close(chip);
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
direction = regularGpio.direction;
|
direction = regularGpio.direction;
|
||||||
@ -202,7 +202,7 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod
|
|||||||
lineNum, gpioId);
|
lineNum, gpioId);
|
||||||
#endif
|
#endif
|
||||||
gpiod_line_release(lineHandle);
|
gpiod_line_release(lineHandle);
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -210,7 +210,7 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod
|
|||||||
* read states of GPIOs.
|
* read states of GPIOs.
|
||||||
*/
|
*/
|
||||||
regularGpio.lineHandle = lineHandle;
|
regularGpio.lineHandle = lineHandle;
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
|
ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
|
||||||
@ -238,7 +238,7 @@ ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
|
|||||||
}
|
}
|
||||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, gpio::Levels::HIGH,
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, gpio::Levels::HIGH,
|
||||||
gpioCallback->callbackArgs);
|
gpioCallback->callbackArgs);
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
@ -270,7 +270,7 @@ ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) {
|
|||||||
}
|
}
|
||||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, gpio::Levels::LOW,
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, gpio::Levels::LOW,
|
||||||
gpioCallback->callbackArgs);
|
gpioCallback->callbackArgs);
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
@ -291,10 +291,10 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, GpiodRegularBase& regul
|
|||||||
return DRIVE_GPIO_FAILURE;
|
return DRIVE_GPIO_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, gpio::Levels& gpioState) {
|
ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
|
||||||
gpioMapIter = gpioMap.find(gpioId);
|
gpioMapIter = gpioMap.find(gpioId);
|
||||||
if (gpioMapIter == gpioMap.end()) {
|
if (gpioMapIter == gpioMap.end()) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
@ -313,10 +313,7 @@ ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, gpio::Levels& gpioState)
|
|||||||
if (regularGpio == nullptr) {
|
if (regularGpio == nullptr) {
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
gpioState = static_cast<gpio::Levels>(gpiod_line_get_value(regularGpio->lineHandle));
|
*gpioState = gpiod_line_get_value(regularGpio->lineHandle);
|
||||||
if (gpioState == gpio::Levels::FAILED) {
|
|
||||||
return GPIO_GET_VALUE_FAILED;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||||
if (gpioCallback->callback == nullptr) {
|
if (gpioCallback->callback == nullptr) {
|
||||||
@ -324,14 +321,14 @@ ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, gpio::Levels& gpioState)
|
|||||||
}
|
}
|
||||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ, gpio::Levels::NONE,
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ, gpio::Levels::NONE,
|
||||||
gpioCallback->callbackArgs);
|
gpioCallback->callbackArgs);
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd) {
|
ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd) {
|
||||||
ReturnValue_t status = returnvalue::OK;
|
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
for (auto& gpioConfig : mapToAdd) {
|
for (auto& gpioConfig : mapToAdd) {
|
||||||
switch (gpioConfig.second->gpioType) {
|
switch (gpioConfig.second->gpioType) {
|
||||||
case (gpio::GpioTypes::GPIO_REGULAR_BY_CHIP):
|
case (gpio::GpioTypes::GPIO_REGULAR_BY_CHIP):
|
||||||
@ -343,7 +340,7 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd) {
|
|||||||
}
|
}
|
||||||
// Check for conflicts and remove duplicates if necessary
|
// Check for conflicts and remove duplicates if necessary
|
||||||
result = checkForConflictsById(gpioConfig.first, gpioConfig.second->gpioType, mapToAdd);
|
result = checkForConflictsById(gpioConfig.first, gpioConfig.second->gpioType, mapToAdd);
|
||||||
if (result != returnvalue::OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
status = result;
|
status = result;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -355,7 +352,7 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd) {
|
|||||||
}
|
}
|
||||||
// Check for conflicts and remove duplicates if necessary
|
// Check for conflicts and remove duplicates if necessary
|
||||||
result = checkForConflictsById(gpioConfig.first, gpioConfig.second->gpioType, mapToAdd);
|
result = checkForConflictsById(gpioConfig.first, gpioConfig.second->gpioType, mapToAdd);
|
||||||
if (result != returnvalue::OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
status = result;
|
status = result;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -429,7 +426,7 @@ ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck,
|
|||||||
mapToAdd.erase(gpioIdToCheck);
|
mapToAdd.erase(gpioIdToCheck);
|
||||||
return GPIO_DUPLICATE_DETECTED;
|
return GPIO_DUPLICATE_DETECTED;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinuxLibgpioIF::parseFindeLineResult(int result, std::string& lineName) {
|
void LinuxLibgpioIF::parseFindeLineResult(int result, std::string& lineName) {
|
@ -19,14 +19,18 @@ class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
|||||||
public:
|
public:
|
||||||
static const uint8_t gpioRetvalId = CLASS_ID::HAL_GPIO;
|
static const uint8_t gpioRetvalId = CLASS_ID::HAL_GPIO;
|
||||||
|
|
||||||
static constexpr ReturnValue_t UNKNOWN_GPIO_ID = returnvalue::makeCode(gpioRetvalId, 1);
|
static constexpr ReturnValue_t UNKNOWN_GPIO_ID =
|
||||||
static constexpr ReturnValue_t DRIVE_GPIO_FAILURE = returnvalue::makeCode(gpioRetvalId, 2);
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 1);
|
||||||
static constexpr ReturnValue_t GPIO_TYPE_FAILURE = returnvalue::makeCode(gpioRetvalId, 3);
|
static constexpr ReturnValue_t DRIVE_GPIO_FAILURE =
|
||||||
static constexpr ReturnValue_t GPIO_INVALID_INSTANCE = returnvalue::makeCode(gpioRetvalId, 4);
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 2);
|
||||||
static constexpr ReturnValue_t GPIO_DUPLICATE_DETECTED = returnvalue::makeCode(gpioRetvalId, 5);
|
static constexpr ReturnValue_t GPIO_TYPE_FAILURE =
|
||||||
static constexpr ReturnValue_t GPIO_INIT_FAILED = returnvalue::makeCode(gpioRetvalId, 6);
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 3);
|
||||||
// Will be returned if getting the line value failed. Error type will be set to errno in this case
|
static constexpr ReturnValue_t GPIO_INVALID_INSTANCE =
|
||||||
static constexpr ReturnValue_t GPIO_GET_VALUE_FAILED = returnvalue::makeCode(gpioRetvalId, 7);
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 4);
|
||||||
|
static constexpr ReturnValue_t GPIO_DUPLICATE_DETECTED =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 5);
|
||||||
|
static constexpr ReturnValue_t GPIO_INIT_FAILED =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 6);
|
||||||
|
|
||||||
LinuxLibgpioIF(object_id_t objectId);
|
LinuxLibgpioIF(object_id_t objectId);
|
||||||
virtual ~LinuxLibgpioIF();
|
virtual ~LinuxLibgpioIF();
|
||||||
@ -34,7 +38,7 @@ class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
|||||||
ReturnValue_t addGpios(GpioCookie* gpioCookie) override;
|
ReturnValue_t addGpios(GpioCookie* gpioCookie) override;
|
||||||
ReturnValue_t pullHigh(gpioId_t gpioId) override;
|
ReturnValue_t pullHigh(gpioId_t gpioId) override;
|
||||||
ReturnValue_t pullLow(gpioId_t gpioId) override;
|
ReturnValue_t pullLow(gpioId_t gpioId) override;
|
||||||
ReturnValue_t readGpio(gpioId_t gpioId, gpio::Levels& gpioState) override;
|
ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const size_t MAX_CHIPNAME_LENGTH = 11;
|
static const size_t MAX_CHIPNAME_LENGTH = 11;
|
||||||
@ -67,7 +71,7 @@ class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
|||||||
*
|
*
|
||||||
* @param mapToAdd The GPIOs which shall be added to the gpioMap.
|
* @param mapToAdd The GPIOs which shall be added to the gpioMap.
|
||||||
*
|
*
|
||||||
* @return returnvalue::OK if successful, otherwise returnvalue::FAILED
|
* @return RETURN_OK if successful, otherwise RETURN_FAILED
|
||||||
*/
|
*/
|
||||||
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
|
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
|
||||||
|
|
8
hal/src/fsfw_hal/linux/i2c/CMakeLists.txt
Normal file
8
hal/src/fsfw_hal/linux/i2c/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PUBLIC
|
||||||
|
I2cComIF.cpp
|
||||||
|
I2cCookie.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -52,16 +52,16 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
|
|||||||
<< i2cAddress << "to I2C device "
|
<< i2cAddress << "to I2C device "
|
||||||
<< "map" << std::endl;
|
<< "map" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "I2cComIF::initializeInterface: Device with address " << i2cAddress
|
sif::error << "I2cComIF::initializeInterface: Device with address " << i2cAddress
|
||||||
<< "already in use" << std::endl;
|
<< "already in use" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
|
ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
|
||||||
@ -73,11 +73,11 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
|
|||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "I2cComIF::sendMessage: Send Data is nullptr" << std::endl;
|
sif::error << "I2cComIF::sendMessage: Send Data is nullptr" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sendLen == 0) {
|
if (sendLen == 0) {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
||||||
@ -95,16 +95,16 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
|
|||||||
sif::error << "I2cComIF::sendMessage: i2cAddress of Cookie not "
|
sif::error << "I2cComIF::sendMessage: i2cAddress of Cookie not "
|
||||||
<< "registered in i2cDeviceMap" << std::endl;
|
<< "registered in i2cDeviceMap" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceFile = i2cCookie->getDeviceFile();
|
deviceFile = i2cCookie->getDeviceFile();
|
||||||
UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::sendMessage");
|
UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::sendMessage");
|
||||||
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return fileHelper.getOpenResult();
|
return fileHelper.getOpenResult();
|
||||||
}
|
}
|
||||||
result = openDevice(deviceFile, i2cAddress, &fd);
|
result = openDevice(deviceFile, i2cAddress, &fd);
|
||||||
if (result != returnvalue::OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,17 +114,17 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
|
|||||||
"device with error code "
|
"device with error code "
|
||||||
<< errno << ". Error description: " << strerror(errno) << std::endl;
|
<< errno << ". Error description: " << strerror(errno) << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FSFW_HAL_I2C_WIRETAPPING == 1
|
#if FSFW_HAL_I2C_WIRETAPPING == 1
|
||||||
sif::info << "Sent I2C data to bus " << deviceFile << ":" << std::endl;
|
sif::info << "Sent I2C data to bus " << deviceFile << ":" << std::endl;
|
||||||
arrayprinter::print(sendData, sendLen);
|
arrayprinter::print(sendData, sendLen);
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::getSendSuccess(CookieIF* cookie) { return returnvalue::OK; }
|
ReturnValue_t I2cComIF::getSendSuccess(CookieIF* cookie) { return HasReturnvaluesIF::RETURN_OK; }
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
|
ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
|
||||||
ReturnValue_t result;
|
ReturnValue_t result;
|
||||||
@ -132,7 +132,7 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
|
|||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
|
|
||||||
if (requestLen == 0) {
|
if (requestLen == 0) {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
||||||
@ -152,16 +152,16 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
|
|||||||
<< "registered in i2cDeviceMap" << std::endl;
|
<< "registered in i2cDeviceMap" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
i2cDeviceMapIter->second.replyLen = 0;
|
i2cDeviceMapIter->second.replyLen = 0;
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceFile = i2cCookie->getDeviceFile();
|
deviceFile = i2cCookie->getDeviceFile();
|
||||||
UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::requestReceiveMessage");
|
UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::requestReceiveMessage");
|
||||||
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return fileHelper.getOpenResult();
|
return fileHelper.getOpenResult();
|
||||||
}
|
}
|
||||||
result = openDevice(deviceFile, i2cAddress, &fd);
|
result = openDevice(deviceFile, i2cAddress, &fd);
|
||||||
if (result != returnvalue::OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
i2cDeviceMapIter->second.replyLen = 0;
|
i2cDeviceMapIter->second.replyLen = 0;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -170,21 +170,19 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
|
|||||||
|
|
||||||
int readLen = read(fd, replyBuffer, requestLen);
|
int readLen = read(fd, replyBuffer, requestLen);
|
||||||
if (readLen != static_cast<int>(requestLen)) {
|
if (readLen != static_cast<int>(requestLen)) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1 and FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C "
|
||||||
if (readLen < 0) {
|
<< "device failed with error code " << errno << ". Description"
|
||||||
sif::warning << "I2cComIF::requestReceiveMessage: Reading from I2C "
|
<< " of error: " << strerror(errno) << std::endl;
|
||||||
<< "device failed with error code " << errno << " | " << strerror(errno)
|
sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from " << requestLen
|
||||||
<< std::endl;
|
<< " bytes" << std::endl;
|
||||||
} else {
|
|
||||||
sif::warning << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from "
|
|
||||||
<< requestLen << " bytes" << std::endl;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
i2cDeviceMapIter->second.replyLen = 0;
|
i2cDeviceMapIter->second.replyLen = 0;
|
||||||
return returnvalue::FAILED;
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::debug << "I2cComIF::requestReceiveMessage: Read " << readLen << " of " << requestLen
|
||||||
|
<< " bytes" << std::endl;
|
||||||
|
#endif
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FSFW_HAL_I2C_WIRETAPPING == 1
|
#if FSFW_HAL_I2C_WIRETAPPING == 1
|
||||||
@ -193,7 +191,7 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
i2cDeviceMapIter->second.replyLen = requestLen;
|
i2cDeviceMapIter->second.replyLen = requestLen;
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
|
ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
|
||||||
@ -212,12 +210,12 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
|
|||||||
sif::error << "I2cComIF::readReceivedMessage: i2cAddress of Cookie not "
|
sif::error << "I2cComIF::readReceivedMessage: i2cAddress of Cookie not "
|
||||||
<< "found in i2cDeviceMap" << std::endl;
|
<< "found in i2cDeviceMap" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
*buffer = i2cDeviceMapIter->second.replyBuffer.data();
|
*buffer = i2cDeviceMapIter->second.replyBuffer.data();
|
||||||
*size = i2cDeviceMapIter->second.replyLen;
|
*size = i2cDeviceMapIter->second.replyLen;
|
||||||
|
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::openDevice(std::string deviceFile, address_t i2cAddress,
|
ReturnValue_t I2cComIF::openDevice(std::string deviceFile, address_t i2cAddress,
|
||||||
@ -233,7 +231,7 @@ ReturnValue_t I2cComIF::openDevice(std::string deviceFile, address_t i2cAddress,
|
|||||||
sif::printWarning("Error description: %s\n", strerror(errno));
|
sif::printWarning("Error description: %s\n", strerror(errno));
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
@ -49,7 +49,7 @@ class I2cComIF : public DeviceCommunicationIF, public SystemObject {
|
|||||||
* @param deviceFile The name of the device file. E.g. i2c-0
|
* @param deviceFile The name of the device file. E.g. i2c-0
|
||||||
* @param i2cAddress The address of the i2c slave device.
|
* @param i2cAddress The address of the i2c slave device.
|
||||||
* @param fileDescriptor Pointer to device descriptor.
|
* @param fileDescriptor Pointer to device descriptor.
|
||||||
* @return returnvalue::OK if successful, otherwise returnvalue::FAILED.
|
* @return RETURN_OK if successful, otherwise RETURN_FAILED.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t openDevice(std::string deviceFile, address_t i2cAddress, int *fileDescriptor);
|
ReturnValue_t openDevice(std::string deviceFile, address_t i2cAddress, int *fileDescriptor);
|
||||||
};
|
};
|
3
hal/src/fsfw_hal/linux/rpi/CMakeLists.txt
Normal file
3
hal/src/fsfw_hal/linux/rpi/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
GpioRPi.cpp
|
||||||
|
)
|
@ -9,7 +9,7 @@ ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int
|
|||||||
std::string consumer, gpio::Direction direction,
|
std::string consumer, gpio::Direction direction,
|
||||||
gpio::Levels initValue) {
|
gpio::Levels initValue) {
|
||||||
if (cookie == nullptr) {
|
if (cookie == nullptr) {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto config = new GpiodRegularByChip();
|
auto config = new GpiodRegularByChip();
|
||||||
@ -30,9 +30,9 @@ ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int
|
|||||||
sif::printError("createRpiGpioConfig: BCM pin %d invalid!\n", bcmPin);
|
sif::printError("createRpiGpioConfig: BCM pin %d invalid!\n", bcmPin);
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
config->lineNum = bcmPin;
|
config->lineNum = bcmPin;
|
||||||
cookie->addGpio(gpioId, config);
|
cookie->addGpio(gpioId, config);
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef BSP_RPI_GPIO_GPIORPI_H_
|
#ifndef BSP_RPI_GPIO_GPIORPI_H_
|
||||||
#define BSP_RPI_GPIO_GPIORPI_H_
|
#define BSP_RPI_GPIO_GPIORPI_H_
|
||||||
|
|
||||||
#include <fsfw/returnvalues/returnvalue.h>
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
|
||||||
#include "../../common/gpio/gpioDefinitions.h"
|
#include "../../common/gpio/gpioDefinitions.h"
|
||||||
|
|
8
hal/src/fsfw_hal/linux/spi/CMakeLists.txt
Normal file
8
hal/src/fsfw_hal/linux/spi/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PUBLIC
|
||||||
|
SpiComIF.cpp
|
||||||
|
SpiCookie.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "fsfw/ipc/MutexIF.h"
|
#include "fsfw/ipc/MutexIF.h"
|
||||||
#include "fsfw/returnvalues/returnvalue.h"
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
#include "fsfw_hal/common/gpio/GpioIF.h"
|
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||||
|
|
||||||
class ManualCsLockWrapper {
|
class ManualCsLockWrapper : public HasReturnvaluesIF {
|
||||||
public:
|
public:
|
||||||
ManualCsLockWrapper(MutexIF* lock, GpioIF* gpioIF, SpiCookie* cookie,
|
ManualCsLockWrapper(MutexIF* lock, GpioIF* gpioIF, SpiCookie* cookie,
|
||||||
MutexIF::TimeoutType type = MutexIF::TimeoutType::BLOCKING,
|
MutexIF::TimeoutType type = MutexIF::TimeoutType::BLOCKING,
|
||||||
@ -16,18 +16,18 @@ class ManualCsLockWrapper {
|
|||||||
}
|
}
|
||||||
cookie->setCsLockManual(true);
|
cookie->setCsLockManual(true);
|
||||||
lockResult = lock->lockMutex(type, timeoutMs);
|
lockResult = lock->lockMutex(type, timeoutMs);
|
||||||
if (lockResult != returnvalue::OK) {
|
if (lockResult != RETURN_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gpioResult = gpioIF->pullLow(cookie->getChipSelectPin());
|
gpioResult = gpioIF->pullLow(cookie->getChipSelectPin());
|
||||||
}
|
}
|
||||||
|
|
||||||
~ManualCsLockWrapper() {
|
~ManualCsLockWrapper() {
|
||||||
if (gpioResult == returnvalue::OK) {
|
if (gpioResult == RETURN_OK) {
|
||||||
gpioIF->pullHigh(cookie->getChipSelectPin());
|
gpioIF->pullHigh(cookie->getChipSelectPin());
|
||||||
}
|
}
|
||||||
cookie->setCsLockManual(false);
|
cookie->setCsLockManual(false);
|
||||||
if (lockResult == returnvalue::OK) {
|
if (lockResult == RETURN_OK) {
|
||||||
lock->unlockMutex();
|
lock->unlockMutex();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,8 +15,8 @@
|
|||||||
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
||||||
#include "fsfw_hal/linux/utility.h"
|
#include "fsfw_hal/linux/utility.h"
|
||||||
|
|
||||||
SpiComIF::SpiComIF(object_id_t objectId, std::string devname, GpioIF* gpioComIF)
|
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF)
|
||||||
: SystemObject(objectId), gpioComIF(gpioComIF), dev(std::move(devname)) {
|
: SystemObject(objectId), gpioComIF(gpioComIF) {
|
||||||
if (gpioComIF == nullptr) {
|
if (gpioComIF == nullptr) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
@ -27,7 +27,7 @@ SpiComIF::SpiComIF(object_id_t objectId, std::string devname, GpioIF* gpioComIF)
|
|||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
csMutex = MutexFactory::instance()->createMutex();
|
spiMutex = MutexFactory::instance()->createMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
|
ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
|
||||||
@ -56,7 +56,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
|
|||||||
static_cast<unsigned long>(spiAddress));
|
static_cast<unsigned long>(spiAddress));
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
/* Now we emplaced the read buffer in the map, we still need to assign that location
|
/* Now we emplaced the read buffer in the map, we still need to assign that location
|
||||||
to the SPI driver transfer struct */
|
to the SPI driver transfer struct */
|
||||||
@ -69,7 +69,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
|
|||||||
sif::printError("SpiComIF::initializeInterface: SPI address already exists!\n");
|
sif::printError("SpiComIF::initializeInterface: SPI address already exists!\n");
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pull CS high in any case to be sure that device is inactive */
|
/* Pull CS high in any case to be sure that device is inactive */
|
||||||
@ -85,8 +85,9 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
|
|||||||
spiCookie->getSpiParameters(spiMode, spiSpeed, ¶ms);
|
spiCookie->getSpiParameters(spiMode, spiSpeed, ¶ms);
|
||||||
|
|
||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
UnixFileGuard fileHelper(dev, &fileDescriptor, O_RDWR, "SpiComIF::initializeInterface");
|
UnixFileGuard fileHelper(spiCookie->getSpiDevice(), &fileDescriptor, O_RDWR,
|
||||||
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
"SpiComIF::initializeInterface");
|
||||||
|
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return fileHelper.getOpenResult();
|
return fileHelper.getOpenResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,12 +129,12 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
|
|||||||
"Could not write bits per word!");
|
"Could not write bits per word!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
|
ReturnValue_t SpiComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
|
||||||
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
|
|
||||||
if (spiCookie == nullptr) {
|
if (spiCookie == nullptr) {
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
@ -177,12 +178,13 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
|
|||||||
spiCookie->assignReadBuffer(iter->second.replyBuffer.data());
|
spiCookie->assignReadBuffer(iter->second.replyBuffer.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
/* Prepare transfer */
|
/* Prepare transfer */
|
||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
UnixFileGuard fileHelper(dev, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage");
|
std::string device = spiCookie->getSpiDevice();
|
||||||
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage");
|
||||||
|
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return OPENING_FILE_FAILED;
|
return OPENING_FILE_FAILED;
|
||||||
}
|
}
|
||||||
spi::SpiModes spiMode = spi::SpiModes::MODE_0;
|
spi::SpiModes spiMode = spi::SpiModes::MODE_0;
|
||||||
@ -202,7 +204,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
|
|||||||
if (gpioId != gpio::NO_GPIO and not csLockManual) {
|
if (gpioId != gpio::NO_GPIO and not csLockManual) {
|
||||||
spiCookie->getMutexParams(csType, csTimeout);
|
spiCookie->getMutexParams(csType, csTimeout);
|
||||||
result = csMutex->lockMutex(csType, csTimeout);
|
result = csMutex->lockMutex(csType, csTimeout);
|
||||||
if (result != returnvalue::OK) {
|
if (result != RETURN_OK) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "SpiComIF::sendMessage: Failed to lock mutex with code "
|
sif::error << "SpiComIF::sendMessage: Failed to lock mutex with code "
|
||||||
@ -214,9 +216,8 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
|
|||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
updateLinePolarity(fileDescriptor);
|
ReturnValue_t result = gpioComIF->pullLow(gpioId);
|
||||||
result = gpioComIF->pullLow(gpioId);
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
if (result != returnvalue::OK) {
|
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "SpiComIF::sendMessage: Pulling low CS pin failed" << std::endl;
|
sif::warning << "SpiComIF::sendMessage: Pulling low CS pin failed" << std::endl;
|
||||||
@ -226,8 +227,6 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
|
|||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
updateLinePolarity(fileDescriptor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute transfer */
|
/* Execute transfer */
|
||||||
@ -257,8 +256,8 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
|
|||||||
|
|
||||||
if (gpioId != gpio::NO_GPIO and not csLockManual) {
|
if (gpioId != gpio::NO_GPIO and not csLockManual) {
|
||||||
gpioComIF->pullHigh(gpioId);
|
gpioComIF->pullHigh(gpioId);
|
||||||
result = csMutex->unlockMutex();
|
result = spiMutex->unlockMutex();
|
||||||
if (result != returnvalue::OK) {
|
if (result != RETURN_OK) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "SpiComIF::sendMessage: Failed to unlock mutex" << std::endl;
|
sif::error << "SpiComIF::sendMessage: Failed to unlock mutex" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -268,7 +267,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::getSendSuccess(CookieIF* cookie) { return returnvalue::OK; }
|
ReturnValue_t SpiComIF::getSendSuccess(CookieIF* cookie) { return HasReturnvaluesIF::RETURN_OK; }
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
|
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
|
||||||
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
||||||
@ -277,35 +276,41 @@ ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (spiCookie->isFullDuplex()) {
|
if (spiCookie->isFullDuplex()) {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return performHalfDuplexReception(spiCookie);
|
return performHalfDuplexReception(spiCookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
|
ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
|
std::string device = spiCookie->getSpiDevice();
|
||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
UnixFileGuard fileHelper(dev, &fileDescriptor, O_RDWR, "SpiComIF::requestReceiveMessage");
|
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::requestReceiveMessage");
|
||||||
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return OPENING_FILE_FAILED;
|
return OPENING_FILE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* rxBuf = nullptr;
|
uint8_t* rxBuf = nullptr;
|
||||||
size_t readSize = spiCookie->getCurrentTransferSize();
|
size_t readSize = spiCookie->getCurrentTransferSize();
|
||||||
result = getReadBuffer(spiCookie->getSpiAddress(), &rxBuf);
|
result = getReadBuffer(spiCookie->getSpiAddress(), &rxBuf);
|
||||||
if (result != returnvalue::OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool csLockManual = spiCookie->getCsLockManual();
|
bool csLockManual = spiCookie->getCsLockManual();
|
||||||
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
||||||
|
<<<<<<< Updated upstream
|
||||||
|
if (gpioId != gpio::NO_GPIO) {
|
||||||
|
result = spiMutex->lockMutex(timeoutType, timeoutMs);
|
||||||
|
=======
|
||||||
MutexIF::TimeoutType csType;
|
MutexIF::TimeoutType csType;
|
||||||
dur_millis_t csTimeout = 0;
|
dur_millis_t csTimeout = 0;
|
||||||
if (gpioId != gpio::NO_GPIO and not csLockManual) {
|
if (gpioId != gpio::NO_GPIO and not csLockManual) {
|
||||||
spiCookie->getMutexParams(csType, csTimeout);
|
spiCookie->getMutexParams(csType, csTimeout);
|
||||||
result = csMutex->lockMutex(csType, csTimeout);
|
result = csMutex->lockMutex(csType, csTimeout);
|
||||||
if (result != returnvalue::OK) {
|
>>>>>>> Stashed changes
|
||||||
|
if (result != RETURN_OK) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "SpiComIF::sendMessage: Failed to lock mutex with code "
|
sif::error << "SpiComIF::sendMessage: Failed to lock mutex with code "
|
||||||
@ -333,8 +338,8 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
|
|||||||
|
|
||||||
if (gpioId != gpio::NO_GPIO and not csLockManual) {
|
if (gpioId != gpio::NO_GPIO and not csLockManual) {
|
||||||
gpioComIF->pullHigh(gpioId);
|
gpioComIF->pullHigh(gpioId);
|
||||||
result = csMutex->unlockMutex();
|
result = spiMutex->unlockMutex();
|
||||||
if (result != returnvalue::OK) {
|
if (result != RETURN_OK) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "SpiComIF::getSendSuccess: Failed to unlock mutex" << std::endl;
|
sif::error << "SpiComIF::getSendSuccess: Failed to unlock mutex" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -348,21 +353,33 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
|
|||||||
ReturnValue_t SpiComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
|
ReturnValue_t SpiComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
|
||||||
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
||||||
if (spiCookie == nullptr) {
|
if (spiCookie == nullptr) {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
uint8_t* rxBuf = nullptr;
|
uint8_t* rxBuf = nullptr;
|
||||||
ReturnValue_t result = getReadBuffer(spiCookie->getSpiAddress(), &rxBuf);
|
ReturnValue_t result = getReadBuffer(spiCookie->getSpiAddress(), &rxBuf);
|
||||||
if (result != returnvalue::OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer = rxBuf;
|
*buffer = rxBuf;
|
||||||
*size = spiCookie->getCurrentTransferSize();
|
*size = spiCookie->getCurrentTransferSize();
|
||||||
spiCookie->setTransferSize(0);
|
spiCookie->setTransferSize(0);
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< Updated upstream
|
||||||
|
MutexIF* SpiComIF::getMutex(MutexIF::TimeoutType* timeoutType, uint32_t* timeoutMs) {
|
||||||
|
if (timeoutType != nullptr) {
|
||||||
|
*timeoutType = this->timeoutType;
|
||||||
|
}
|
||||||
|
if (timeoutMs != nullptr) {
|
||||||
|
*timeoutMs = this->timeoutMs;
|
||||||
|
}
|
||||||
|
return spiMutex;
|
||||||
|
}
|
||||||
|
=======
|
||||||
MutexIF* SpiComIF::getCsMutex() { return csMutex; }
|
MutexIF* SpiComIF::getCsMutex() { return csMutex; }
|
||||||
|
>>>>>>> Stashed changes
|
||||||
|
|
||||||
void SpiComIF::performSpiWiretapping(SpiCookie* spiCookie) {
|
void SpiComIF::performSpiWiretapping(SpiCookie* spiCookie) {
|
||||||
if (spiCookie == nullptr) {
|
if (spiCookie == nullptr) {
|
||||||
@ -385,16 +402,16 @@ void SpiComIF::performSpiWiretapping(SpiCookie* spiCookie) {
|
|||||||
|
|
||||||
ReturnValue_t SpiComIF::getReadBuffer(address_t spiAddress, uint8_t** buffer) {
|
ReturnValue_t SpiComIF::getReadBuffer(address_t spiAddress, uint8_t** buffer) {
|
||||||
if (buffer == nullptr) {
|
if (buffer == nullptr) {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto iter = spiDeviceMap.find(spiAddress);
|
auto iter = spiDeviceMap.find(spiAddress);
|
||||||
if (iter == spiDeviceMap.end()) {
|
if (iter == spiDeviceMap.end()) {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer = iter->second.replyBuffer.data();
|
*buffer = iter->second.replyBuffer.data();
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
GpioIF* SpiComIF::getGpioInterface() { return gpioComIF; }
|
GpioIF* SpiComIF::getGpioInterface() { return gpioComIF; }
|
||||||
@ -409,27 +426,11 @@ void SpiComIF::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed)
|
|||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI speed failed");
|
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI speed failed");
|
||||||
}
|
}
|
||||||
}
|
// This updates the SPI clock default polarity. Only setting the mode does not update
|
||||||
|
// the line state, which can be an issue on mode switches because the clock line will
|
||||||
void SpiComIF::getSpiSpeedAndMode(int spiFd, spi::SpiModes& mode, uint32_t& speed) const {
|
// switch the state after the chip select is pulled low
|
||||||
uint8_t tmpMode = 0;
|
|
||||||
int retval = ioctl(spiFd, SPI_IOC_RD_MODE, &tmpMode);
|
|
||||||
if (retval != 0) {
|
|
||||||
utility::handleIoctlError("SpiComIF::getSpiSpeedAndMode: Reading SPI mode failed");
|
|
||||||
}
|
|
||||||
mode = static_cast<spi::SpiModes>(tmpMode);
|
|
||||||
|
|
||||||
retval = ioctl(spiFd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
|
|
||||||
if (retval != 0) {
|
|
||||||
utility::handleIoctlError("SpiComIF::getSpiSpeedAndMode: Getting SPI speed failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& SpiComIF::getSpiDev() const { return dev; }
|
|
||||||
|
|
||||||
void SpiComIF::updateLinePolarity(int spiFd) {
|
|
||||||
clockUpdateTransfer.len = 0;
|
clockUpdateTransfer.len = 0;
|
||||||
int retval = ioctl(spiFd, SPI_IOC_MESSAGE(1), &clockUpdateTransfer);
|
retval = ioctl(spiFd, SPI_IOC_MESSAGE(1), &clockUpdateTransfer);
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Updating SPI default clock failed");
|
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Updating SPI default clock failed");
|
||||||
}
|
}
|
@ -22,16 +22,17 @@ class SpiCookie;
|
|||||||
*/
|
*/
|
||||||
class SpiComIF : public DeviceCommunicationIF, public SystemObject {
|
class SpiComIF : public DeviceCommunicationIF, public SystemObject {
|
||||||
public:
|
public:
|
||||||
static constexpr uint8_t spiRetvalId = CLASS_ID::HAL_SPI;
|
static constexpr uint8_t CLASS_ID = CLASS_ID::HAL_SPI;
|
||||||
static constexpr ReturnValue_t OPENING_FILE_FAILED = returnvalue::makeCode(spiRetvalId, 0);
|
static constexpr ReturnValue_t OPENING_FILE_FAILED =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 0);
|
||||||
/* Full duplex (ioctl) transfer failure */
|
/* Full duplex (ioctl) transfer failure */
|
||||||
static constexpr ReturnValue_t FULL_DUPLEX_TRANSFER_FAILED =
|
static constexpr ReturnValue_t FULL_DUPLEX_TRANSFER_FAILED =
|
||||||
returnvalue::makeCode(spiRetvalId, 1);
|
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
|
||||||
/* Half duplex (read/write) transfer failure */
|
/* Half duplex (read/write) transfer failure */
|
||||||
static constexpr ReturnValue_t HALF_DUPLEX_TRANSFER_FAILED =
|
static constexpr ReturnValue_t HALF_DUPLEX_TRANSFER_FAILED =
|
||||||
returnvalue::makeCode(spiRetvalId, 2);
|
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2);
|
||||||
|
|
||||||
SpiComIF(object_id_t objectId, std::string devname, GpioIF* gpioComIF);
|
SpiComIF(object_id_t objectId, GpioIF* gpioComIF);
|
||||||
|
|
||||||
ReturnValue_t initializeInterface(CookieIF* cookie) override;
|
ReturnValue_t initializeInterface(CookieIF* cookie) override;
|
||||||
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
|
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
|
||||||
@ -44,7 +45,6 @@ class SpiComIF : public DeviceCommunicationIF, public SystemObject {
|
|||||||
* the chip select must be driven from outside of the com if.
|
* the chip select must be driven from outside of the com if.
|
||||||
*/
|
*/
|
||||||
MutexIF* getCsMutex();
|
MutexIF* getCsMutex();
|
||||||
void setMutexParams(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a regular send operation using Linux iotcl. This is public so it can be used
|
* Perform a regular send operation using Linux iotcl. This is public so it can be used
|
||||||
@ -59,20 +59,6 @@ class SpiComIF : public DeviceCommunicationIF, public SystemObject {
|
|||||||
|
|
||||||
GpioIF* getGpioInterface();
|
GpioIF* getGpioInterface();
|
||||||
void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed);
|
void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed);
|
||||||
void getSpiSpeedAndMode(int spiFd, spi::SpiModes& mode, uint32_t& speed) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This updates the SPI clock default polarity. Only setting the mode does not update
|
|
||||||
* the line state, which can be an issue on mode switches because the clock line will
|
|
||||||
* switch the state after the chip select is pulled low.
|
|
||||||
*
|
|
||||||
* It is recommended to call this function after #setSpiSpeedAndMode and after locking the
|
|
||||||
* CS mutex if the SPI bus has multiple SPI devices with different speed and SPI modes attached.
|
|
||||||
* @param spiFd
|
|
||||||
*/
|
|
||||||
void updateLinePolarity(int spiFd);
|
|
||||||
|
|
||||||
const std::string& getSpiDev() const;
|
|
||||||
void performSpiWiretapping(SpiCookie* spiCookie);
|
void performSpiWiretapping(SpiCookie* spiCookie);
|
||||||
|
|
||||||
ReturnValue_t getReadBuffer(address_t spiAddress, uint8_t** buffer);
|
ReturnValue_t getReadBuffer(address_t spiAddress, uint8_t** buffer);
|
||||||
@ -90,8 +76,7 @@ class SpiComIF : public DeviceCommunicationIF, public SystemObject {
|
|||||||
* pulled high
|
* pulled high
|
||||||
*/
|
*/
|
||||||
MutexIF* csMutex = nullptr;
|
MutexIF* csMutex = nullptr;
|
||||||
// MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
|
||||||
// uint32_t timeoutMs = DEFAULT_MUTEX_TIMEOUT;
|
|
||||||
spi_ioc_transfer clockUpdateTransfer = {};
|
spi_ioc_transfer clockUpdateTransfer = {};
|
||||||
|
|
||||||
using SpiDeviceMap = std::unordered_map<address_t, SpiInstance>;
|
using SpiDeviceMap = std::unordered_map<address_t, SpiInstance>;
|
@ -1,25 +1,26 @@
|
|||||||
#include "SpiCookie.h"
|
#include "SpiCookie.h"
|
||||||
|
|
||||||
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, const size_t maxSize,
|
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)
|
spi::SpiModes spiMode, uint32_t spiSpeed)
|
||||||
: SpiCookie(spi::SpiComIfModes::REGULAR, spiAddress, chipSelect, maxSize, spiMode, spiSpeed,
|
: SpiCookie(spiAddress, gpio::NO_GPIO, spiDev, maxSize, spiMode, spiSpeed) {}
|
||||||
nullptr, nullptr) {}
|
|
||||||
|
|
||||||
SpiCookie::SpiCookie(address_t spiAddress, const size_t maxSize, spi::SpiModes spiMode,
|
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
||||||
uint32_t spiSpeed)
|
|
||||||
: SpiCookie(spiAddress, gpio::NO_GPIO, maxSize, spiMode, spiSpeed) {}
|
|
||||||
|
|
||||||
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, const size_t maxSize,
|
|
||||||
spi::SpiModes spiMode, uint32_t spiSpeed,
|
|
||||||
spi::send_callback_function_t callback, void* args)
|
|
||||||
: SpiCookie(spi::SpiComIfModes::CALLBACK, spiAddress, chipSelect, maxSize, spiMode, spiSpeed,
|
|
||||||
callback, args) {}
|
|
||||||
|
|
||||||
SpiCookie::SpiCookie(spi::SpiComIfModes comIfMode, address_t spiAddress, gpioId_t chipSelect,
|
|
||||||
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed,
|
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed,
|
||||||
spi::send_callback_function_t callback, void* args)
|
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),
|
: spiAddress(spiAddress),
|
||||||
chipSelectPin(chipSelect),
|
chipSelectPin(chipSelect),
|
||||||
|
spiDevice(spiDev),
|
||||||
comIfMode(comIfMode),
|
comIfMode(comIfMode),
|
||||||
maxSize(maxSize),
|
maxSize(maxSize),
|
||||||
spiMode(spiMode),
|
spiMode(spiMode),
|
||||||
@ -49,6 +50,8 @@ size_t SpiCookie::getMaxBufferSize() const { return maxSize; }
|
|||||||
|
|
||||||
address_t SpiCookie::getSpiAddress() const { return spiAddress; }
|
address_t SpiCookie::getSpiAddress() const { return spiAddress; }
|
||||||
|
|
||||||
|
std::string SpiCookie::getSpiDevice() const { return spiDevice; }
|
||||||
|
|
||||||
void SpiCookie::setThreeWireSpi(bool enable) { uncommonParameters.threeWireSpi = enable; }
|
void SpiCookie::setThreeWireSpi(bool enable) { uncommonParameters.threeWireSpi = enable; }
|
||||||
|
|
||||||
void SpiCookie::setLsbFirst(bool enable) { uncommonParameters.lsbFirst = enable; }
|
void SpiCookie::setLsbFirst(bool enable) { uncommonParameters.lsbFirst = enable; }
|
@ -33,22 +33,23 @@ class SpiCookie : public CookieIF {
|
|||||||
* @param spiDev
|
* @param spiDev
|
||||||
* @param maxSize
|
* @param maxSize
|
||||||
*/
|
*/
|
||||||
SpiCookie(address_t spiAddress, gpioId_t chipSelect, const size_t maxSize, spi::SpiModes spiMode,
|
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxSize,
|
||||||
uint32_t spiSpeed);
|
spi::SpiModes spiMode, uint32_t spiSpeed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like constructor above, but without a dedicated GPIO CS. Can be used for hardware
|
* Like constructor above, but without a dedicated GPIO CS. Can be used for hardware
|
||||||
* slave select or if CS logic is performed with decoders.
|
* slave select or if CS logic is performed with decoders.
|
||||||
*/
|
*/
|
||||||
SpiCookie(address_t spiAddress, const size_t maxReplySize, spi::SpiModes spiMode,
|
SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxReplySize,
|
||||||
uint32_t spiSpeed);
|
spi::SpiModes spiMode, uint32_t spiSpeed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use the callback mode of the SPI communication interface. The user can pass the callback
|
* Use the callback mode of the SPI communication interface. The user can pass the callback
|
||||||
* function here or by using the setter function #setCallbackMode
|
* function here or by using the setter function #setCallbackMode
|
||||||
*/
|
*/
|
||||||
SpiCookie(address_t spiAddress, gpioId_t chipSelect, const size_t maxSize, spi::SpiModes spiMode,
|
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxSize,
|
||||||
uint32_t spiSpeed, spi::send_callback_function_t callback, void* args);
|
spi::SpiModes spiMode, uint32_t spiSpeed, spi::send_callback_function_t callback,
|
||||||
|
void* args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the callback function
|
* Get the callback function
|
||||||
@ -58,6 +59,7 @@ class SpiCookie : public CookieIF {
|
|||||||
void getCallback(spi::send_callback_function_t* callback, void** args);
|
void getCallback(spi::send_callback_function_t* callback, void** args);
|
||||||
|
|
||||||
address_t getSpiAddress() const;
|
address_t getSpiAddress() const;
|
||||||
|
std::string getSpiDevice() const;
|
||||||
gpioId_t getChipSelectPin() const;
|
gpioId_t getChipSelectPin() const;
|
||||||
size_t getMaxBufferSize() const;
|
size_t getMaxBufferSize() const;
|
||||||
|
|
||||||
@ -152,6 +154,7 @@ class SpiCookie : public CookieIF {
|
|||||||
private:
|
private:
|
||||||
address_t spiAddress;
|
address_t spiAddress;
|
||||||
gpioId_t chipSelectPin;
|
gpioId_t chipSelectPin;
|
||||||
|
std::string spiDevice;
|
||||||
|
|
||||||
spi::SpiComIfModes comIfMode;
|
spi::SpiComIfModes comIfMode;
|
||||||
|
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "../../common/gpio/gpioDefinitions.h"
|
#include "../../common/gpio/gpioDefinitions.h"
|
||||||
#include "../../common/spi/spiCommon.h"
|
#include "../../common/spi/spiCommon.h"
|
||||||
#include "fsfw/returnvalues/returnvalue.h"
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
|
||||||
class SpiCookie;
|
class SpiCookie;
|
||||||
class SpiComIF;
|
class SpiComIF;
|
4
hal/src/fsfw_hal/linux/uart/CMakeLists.txt
Normal file
4
hal/src/fsfw_hal/linux/uart/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PUBLIC
|
||||||
|
UartComIF.cpp
|
||||||
|
UartCookie.cpp
|
||||||
|
)
|
@ -37,7 +37,7 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
|
|||||||
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
||||||
int fileDescriptor = configureUartPort(uartCookie);
|
int fileDescriptor = configureUartPort(uartCookie);
|
||||||
if (fileDescriptor < 0) {
|
if (fileDescriptor < 0) {
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
size_t maxReplyLen = uartCookie->getMaxReplyLen();
|
size_t maxReplyLen = uartCookie->getMaxReplyLen();
|
||||||
UartElements uartElements = {fileDescriptor, std::vector<uint8_t>(maxReplyLen), 0};
|
UartElements uartElements = {fileDescriptor, std::vector<uint8_t>(maxReplyLen), 0};
|
||||||
@ -47,17 +47,17 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
|
|||||||
sif::warning << "UartComIF::initializeInterface: Failed to insert device " << deviceFile
|
sif::warning << "UartComIF::initializeInterface: Failed to insert device " << deviceFile
|
||||||
<< "to UART device map" << std::endl;
|
<< "to UART device map" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "UartComIF::initializeInterface: UART device " << deviceFile
|
sif::warning << "UartComIF::initializeInterface: UART device " << deviceFile
|
||||||
<< " already in use" << std::endl;
|
<< " already in use" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
||||||
@ -329,14 +329,14 @@ ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData,
|
|||||||
UartDeviceMapIter uartDeviceMapIter;
|
UartDeviceMapIter uartDeviceMapIter;
|
||||||
|
|
||||||
if (sendLen == 0) {
|
if (sendLen == 0) {
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sendData == nullptr) {
|
if (sendData == nullptr) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "UartComIF::sendMessage: Send data is nullptr" << std::endl;
|
sif::warning << "UartComIF::sendMessage: Send data is nullptr" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||||
@ -354,7 +354,7 @@ ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData,
|
|||||||
sif::debug << "UartComIF::sendMessage: Device file " << deviceFile << "not in UART map"
|
sif::debug << "UartComIF::sendMessage: Device file " << deviceFile << "not in UART map"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = uartDeviceMapIter->second.fileDescriptor;
|
fd = uartDeviceMapIter->second.fileDescriptor;
|
||||||
@ -364,13 +364,13 @@ ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData,
|
|||||||
sif::error << "UartComIF::sendMessage: Failed to send data with error code " << errno
|
sif::error << "UartComIF::sendMessage: Failed to send data with error code " << errno
|
||||||
<< ": Error description: " << strerror(errno) << std::endl;
|
<< ": Error description: " << strerror(errno) << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::getSendSuccess(CookieIF* cookie) { return returnvalue::OK; }
|
ReturnValue_t UartComIF::getSendSuccess(CookieIF* cookie) { return RETURN_OK; }
|
||||||
|
|
||||||
ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
|
ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
@ -389,7 +389,7 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestL
|
|||||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||||
|
|
||||||
if (uartMode == UartModes::NON_CANONICAL and requestLen == 0) {
|
if (uartMode == UartModes::NON_CANONICAL and requestLen == 0) {
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
||||||
@ -397,7 +397,7 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestL
|
|||||||
sif::debug << "UartComIF::requestReceiveMessage: Device file " << deviceFile
|
sif::debug << "UartComIF::requestReceiveMessage: Device file " << deviceFile
|
||||||
<< " not in uart map" << std::endl;
|
<< " not in uart map" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uartMode == UartModes::CANONICAL) {
|
if (uartMode == UartModes::CANONICAL) {
|
||||||
@ -405,13 +405,13 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestL
|
|||||||
} else if (uartMode == UartModes::NON_CANONICAL) {
|
} else if (uartMode == UartModes::NON_CANONICAL) {
|
||||||
return handleNoncanonicalRead(*uartCookie, uartDeviceMapIter, requestLen);
|
return handleNoncanonicalRead(*uartCookie, uartDeviceMapIter, requestLen);
|
||||||
} else {
|
} else {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter,
|
ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter,
|
||||||
size_t requestLen) {
|
size_t requestLen) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
uint8_t maxReadCycles = uartCookie.getReadCycles();
|
uint8_t maxReadCycles = uartCookie.getReadCycles();
|
||||||
uint8_t currentReadCycles = 0;
|
uint8_t currentReadCycles = 0;
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
@ -454,7 +454,7 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (bytesRead > 0) {
|
} else if (bytesRead > 0) {
|
||||||
@ -487,18 +487,18 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie& uartCookie, UartDevi
|
|||||||
}
|
}
|
||||||
int bytesRead = read(fd, bufferPtr, requestLen);
|
int bytesRead = read(fd, bufferPtr, requestLen);
|
||||||
if (bytesRead < 0) {
|
if (bytesRead < 0) {
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
} else if (bytesRead != static_cast<int>(requestLen)) {
|
} else if (bytesRead != static_cast<int>(requestLen)) {
|
||||||
if (uartCookie.isReplySizeFixed()) {
|
if (uartCookie.isReplySizeFixed()) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead << " of "
|
sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead << " of "
|
||||||
<< requestLen << " bytes" << std::endl;
|
<< requestLen << " bytes" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
iter->second.replyLen = bytesRead;
|
iter->second.replyLen = bytesRead;
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
|
ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
|
||||||
@ -520,7 +520,7 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
|
|||||||
sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile << " not in uart map"
|
sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile << " not in uart map"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer = uartDeviceMapIter->second.replyBuffer.data();
|
*buffer = uartDeviceMapIter->second.replyBuffer.data();
|
||||||
@ -529,7 +529,7 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
|
|||||||
/* Length is reset to 0 to prevent reading the same data twice */
|
/* Length is reset to 0 to prevent reading the same data twice */
|
||||||
uartDeviceMapIter->second.replyLen = 0;
|
uartDeviceMapIter->second.replyLen = 0;
|
||||||
|
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) {
|
ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) {
|
||||||
@ -547,9 +547,9 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) {
|
|||||||
if (uartDeviceMapIter != uartDeviceMap.end()) {
|
if (uartDeviceMapIter != uartDeviceMap.end()) {
|
||||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||||
tcflush(fd, TCIFLUSH);
|
tcflush(fd, TCIFLUSH);
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) {
|
ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) {
|
||||||
@ -567,9 +567,9 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) {
|
|||||||
if (uartDeviceMapIter != uartDeviceMap.end()) {
|
if (uartDeviceMapIter != uartDeviceMap.end()) {
|
||||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||||
tcflush(fd, TCOFLUSH);
|
tcflush(fd, TCOFLUSH);
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) {
|
ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) {
|
||||||
@ -587,9 +587,9 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) {
|
|||||||
if (uartDeviceMapIter != uartDeviceMap.end()) {
|
if (uartDeviceMapIter != uartDeviceMap.end()) {
|
||||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||||
tcflush(fd, TCIOFLUSH);
|
tcflush(fd, TCIOFLUSH);
|
||||||
return returnvalue::OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return returnvalue::FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UartComIF::setUartMode(struct termios* options, UartCookie& uartCookie) {
|
void UartComIF::setUartMode(struct termios* options, UartCookie& uartCookie) {
|
@ -22,9 +22,12 @@ class UartComIF : public DeviceCommunicationIF, public SystemObject {
|
|||||||
public:
|
public:
|
||||||
static constexpr uint8_t uartRetvalId = CLASS_ID::HAL_UART;
|
static constexpr uint8_t uartRetvalId = CLASS_ID::HAL_UART;
|
||||||
|
|
||||||
static constexpr ReturnValue_t UART_READ_FAILURE = returnvalue::makeCode(uartRetvalId, 1);
|
static constexpr ReturnValue_t UART_READ_FAILURE =
|
||||||
static constexpr ReturnValue_t UART_READ_SIZE_MISSMATCH = returnvalue::makeCode(uartRetvalId, 2);
|
HasReturnvaluesIF::makeReturnCode(uartRetvalId, 1);
|
||||||
static constexpr ReturnValue_t UART_RX_BUFFER_TOO_SMALL = returnvalue::makeCode(uartRetvalId, 3);
|
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);
|
UartComIF(object_id_t objectId);
|
||||||
|
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include <fsfw/serviceinterface.h>
|
#include <fsfw/serviceinterface.h>
|
||||||
|
|
||||||
UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate,
|
UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode,
|
||||||
size_t maxReplyLen, UartModes uartMode)
|
UartBaudRate baudrate, size_t maxReplyLen)
|
||||||
: handlerId(handlerId),
|
: handlerId(handlerId),
|
||||||
deviceFile(deviceFile),
|
deviceFile(deviceFile),
|
||||||
uartMode(uartMode),
|
uartMode(uartMode),
|
@ -69,8 +69,8 @@ class UartCookie : public CookieIF {
|
|||||||
* 8 databits (number of bits transfered with one uart frame)
|
* 8 databits (number of bits transfered with one uart frame)
|
||||||
* One stop bit
|
* One stop bit
|
||||||
*/
|
*/
|
||||||
UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate,
|
UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode,
|
||||||
size_t maxReplyLen, UartModes uartMode = UartModes::NON_CANONICAL);
|
UartBaudRate baudrate, size_t maxReplyLen);
|
||||||
|
|
||||||
virtual ~UartCookie();
|
virtual ~UartCookie();
|
||||||
|
|
3
hal/src/fsfw_hal/linux/uio/CMakeLists.txt
Normal file
3
hal/src/fsfw_hal/linux/uio/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PUBLIC
|
||||||
|
UioMapper.cpp
|
||||||
|
)
|
@ -18,17 +18,17 @@ UioMapper::UioMapper(std::string uioFile, int mapNum) : uioFile(uioFile), mapNum
|
|||||||
UioMapper::~UioMapper() {}
|
UioMapper::~UioMapper() {}
|
||||||
|
|
||||||
ReturnValue_t UioMapper::getMappedAdress(uint32_t** address, Permissions permissions) {
|
ReturnValue_t UioMapper::getMappedAdress(uint32_t** address, Permissions permissions) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
int fd = open(uioFile.c_str(), O_RDWR);
|
int fd = open(uioFile.c_str(), O_RDWR);
|
||||||
if (fd < 1) {
|
if (fd < 1) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "PtmeAxiConfig::initialize: Invalid UIO device file" << std::endl;
|
sif::error << "PtmeAxiConfig::initialize: Invalid UIO device file" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
result = getMapSize(&size);
|
result = getMapSize(&size);
|
||||||
if (result != returnvalue::OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
*address = static_cast<uint32_t*>(
|
*address = static_cast<uint32_t*>(
|
||||||
@ -39,9 +39,9 @@ ReturnValue_t UioMapper::getMappedAdress(uint32_t** address, Permissions permiss
|
|||||||
sif::error << "UioMapper::getMappedAdress: Failed to map physical address of uio device "
|
sif::error << "UioMapper::getMappedAdress: Failed to map physical address of uio device "
|
||||||
<< uioFile.c_str() << " and map" << static_cast<int>(mapNum) << std::endl;
|
<< uioFile.c_str() << " and map" << static_cast<int>(mapNum) << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UioMapper::getMapSize(size_t* size) {
|
ReturnValue_t UioMapper::getMapSize(size_t* size) {
|
||||||
@ -54,7 +54,7 @@ ReturnValue_t UioMapper::getMapSize(size_t* size) {
|
|||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "UioMapper::getMapSize: Failed to open file " << namestream.str() << std::endl;
|
sif::error << "UioMapper::getMapSize: Failed to open file " << namestream.str() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
char hexstring[SIZE_HEX_STRING] = "";
|
char hexstring[SIZE_HEX_STRING] = "";
|
||||||
int items = fscanf(fp, "%s", hexstring);
|
int items = fscanf(fp, "%s", hexstring);
|
||||||
@ -66,7 +66,7 @@ ReturnValue_t UioMapper::getMapSize(size_t* size) {
|
|||||||
<< namestream.str() << std::endl;
|
<< namestream.str() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
uint32_t sizeTmp = 0;
|
uint32_t sizeTmp = 0;
|
||||||
items = sscanf(hexstring, "%x", &sizeTmp);
|
items = sscanf(hexstring, "%x", &sizeTmp);
|
||||||
@ -79,8 +79,8 @@ ReturnValue_t UioMapper::getMapSize(size_t* size) {
|
|||||||
<< "size of map" << mapNum << " to integer" << std::endl;
|
<< "size of map" << mapNum << " to integer" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "fsfw/returnvalues/returnvalue.h"
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Class to help opening uio device files and mapping the physical addresses into the user
|
* @brief Class to help opening uio device files and mapping the physical addresses into the user
|
@ -2,4 +2,6 @@ add_subdirectory(spi)
|
|||||||
add_subdirectory(gpio)
|
add_subdirectory(gpio)
|
||||||
add_subdirectory(devicetest)
|
add_subdirectory(devicetest)
|
||||||
|
|
||||||
target_sources(${LIB_FSFW_NAME} PRIVATE dma.cpp)
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
dma.cpp
|
||||||
|
)
|
3
hal/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt
Normal file
3
hal/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
GyroL3GD20H.cpp
|
||||||
|
)
|
@ -84,7 +84,7 @@ ReturnValue_t GyroL3GD20H::initialize() {
|
|||||||
spiHandle->Init.Mode = SPI_MODE_MASTER;
|
spiHandle->Init.Mode = SPI_MODE_MASTER;
|
||||||
if (HAL_SPI_Init(spiHandle) != HAL_OK) {
|
if (HAL_SPI_Init(spiHandle) != HAL_OK) {
|
||||||
sif::printWarning("Error initializing SPI\n");
|
sif::printWarning("Error initializing SPI\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete mspCfg;
|
delete mspCfg;
|
||||||
@ -106,11 +106,11 @@ ReturnValue_t GyroL3GD20H::initialize() {
|
|||||||
return handlePollingTransferInit();
|
return handlePollingTransferInit();
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GyroL3GD20H::performOperation() {
|
ReturnValue_t GyroL3GD20H::performOperation() {
|
||||||
@ -125,10 +125,10 @@ ReturnValue_t GyroL3GD20H::performOperation() {
|
|||||||
return handleInterruptSensorRead();
|
return handleInterruptSensorRead();
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
||||||
@ -162,10 +162,10 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
|||||||
case (TransferStates::FAILURE): {
|
case (TransferStates::FAILURE): {
|
||||||
sif::printWarning("Transfer failure\n");
|
sif::printWarning("Transfer failure\n");
|
||||||
transferState = TransferStates::FAILURE;
|
transferState = TransferStates::FAILURE;
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,10 +194,10 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
|||||||
case (TransferStates::FAILURE): {
|
case (TransferStates::FAILURE): {
|
||||||
sif::printWarning("GyroL3GD20H::initialize: Configuration transfer failure\n");
|
sif::printWarning("GyroL3GD20H::initialize: Configuration transfer failure\n");
|
||||||
transferState = TransferStates::FAILURE;
|
transferState = TransferStates::FAILURE;
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,13 +228,13 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
|||||||
case (TransferStates::FAILURE): {
|
case (TransferStates::FAILURE): {
|
||||||
sif::printWarning("GyroL3GD20H::initialize: Configuration transfer failure\n");
|
sif::printWarning("GyroL3GD20H::initialize: Configuration transfer failure\n");
|
||||||
transferState = TransferStates::FAILURE;
|
transferState = TransferStates::FAILURE;
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GyroL3GD20H::handleDmaSensorRead() {
|
ReturnValue_t GyroL3GD20H::handleDmaSensorRead() {
|
||||||
@ -259,13 +259,13 @@ ReturnValue_t GyroL3GD20H::handleDmaSensorRead() {
|
|||||||
case (TransferStates::FAILURE): {
|
case (TransferStates::FAILURE): {
|
||||||
sif::printWarning("GyroL3GD20H::handleDmaSensorRead: Sensor read failure\n");
|
sif::printWarning("GyroL3GD20H::handleDmaSensorRead: Sensor read failure\n");
|
||||||
transferState = TransferStates::FAILURE;
|
transferState = TransferStates::FAILURE;
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_StatusTypeDef GyroL3GD20H::performDmaTransfer(size_t sendSize) {
|
HAL_StatusTypeDef GyroL3GD20H::performDmaTransfer(size_t sendSize) {
|
||||||
@ -298,14 +298,14 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
|
|||||||
}
|
}
|
||||||
case (HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
case (HAL_ERROR): {
|
case (HAL_ERROR): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,14 +323,14 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
|
|||||||
}
|
}
|
||||||
case (HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
case (HAL_ERROR): {
|
case (HAL_ERROR): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,17 +353,17 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
|
|||||||
}
|
}
|
||||||
case (HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
case (HAL_ERROR): {
|
case (HAL_ERROR): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GyroL3GD20H::handlePollingSensorRead() {
|
ReturnValue_t GyroL3GD20H::handlePollingSensorRead() {
|
||||||
@ -380,17 +380,17 @@ ReturnValue_t GyroL3GD20H::handlePollingSensorRead() {
|
|||||||
}
|
}
|
||||||
case (HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
case (HAL_ERROR): {
|
case (HAL_ERROR): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
||||||
@ -416,7 +416,7 @@ ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
|||||||
case (HAL_ERROR):
|
case (HAL_ERROR):
|
||||||
case (HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n");
|
sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,7 +438,7 @@ ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
|||||||
case (HAL_ERROR):
|
case (HAL_ERROR):
|
||||||
case (HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n");
|
sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,10 +465,10 @@ ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
|||||||
case (HAL_ERROR):
|
case (HAL_ERROR):
|
||||||
case (HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n");
|
sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GyroL3GD20H::handleInterruptSensorRead() {
|
ReturnValue_t GyroL3GD20H::handleInterruptSensorRead() {
|
||||||
@ -489,10 +489,10 @@ ReturnValue_t GyroL3GD20H::handleInterruptSensorRead() {
|
|||||||
case (HAL_ERROR):
|
case (HAL_ERROR):
|
||||||
case (HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Sensor read failure using interrupts\n");
|
sif::printDebug("GyroL3GD20H::initialize: Sensor read failure using interrupts\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GyroL3GD20H::prepareConfigRegs(uint8_t *configRegs) {
|
void GyroL3GD20H::prepareConfigRegs(uint8_t *configRegs) {
|
@ -6,14 +6,10 @@
|
|||||||
|
|
||||||
#include "../spi/mspInit.h"
|
#include "../spi/mspInit.h"
|
||||||
#include "../spi/spiDefinitions.h"
|
#include "../spi/spiDefinitions.h"
|
||||||
#include "fsfw/returnvalues/returnvalue.h"
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
#include "stm32h7xx_hal.h"
|
#include "stm32h7xx_hal.h"
|
||||||
#include "stm32h7xx_hal_spi.h"
|
#include "stm32h7xx_hal_spi.h"
|
||||||
|
|
||||||
#ifndef STM_USE_PERIPHERAL_TX_BUFFER_MPU_PROTECTION
|
|
||||||
#define STM_USE_PERIPHERAL_TX_BUFFER_MPU_PROTECTION 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
enum class TransferStates { IDLE, WAIT, SUCCESS, FAILURE };
|
enum class TransferStates { IDLE, WAIT, SUCCESS, FAILURE };
|
||||||
|
|
||||||
class GyroL3GD20H {
|
class GyroL3GD20H {
|
3
hal/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt
Normal file
3
hal/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
gpio.cpp
|
||||||
|
)
|
2
hal/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt
Normal file
2
hal/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
)
|
9
hal/src/fsfw_hal/stm32h7/spi/CMakeLists.txt
Normal file
9
hal/src/fsfw_hal/stm32h7/spi/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
|
spiCore.cpp
|
||||||
|
spiDefinitions.cpp
|
||||||
|
spiInterrupts.cpp
|
||||||
|
mspInit.cpp
|
||||||
|
SpiCookie.cpp
|
||||||
|
SpiComIF.cpp
|
||||||
|
stm32h743zi.cpp
|
||||||
|
)
|
@ -35,7 +35,7 @@ void SpiComIF::addDmaHandles(DMA_HandleTypeDef *txHandle, DMA_HandleTypeDef *rxH
|
|||||||
spi::setDmaHandles(txHandle, rxHandle);
|
spi::setDmaHandles(txHandle, rxHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::initialize() { return returnvalue::OK; }
|
ReturnValue_t SpiComIF::initialize() { return HasReturnvaluesIF::RETURN_OK; }
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||||
SpiCookie *spiCookie = dynamic_cast<SpiCookie *>(cookie);
|
SpiCookie *spiCookie = dynamic_cast<SpiCookie *>(cookie);
|
||||||
@ -55,7 +55,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
spi::getDmaHandles(&txHandle, &rxHandle);
|
spi::getDmaHandles(&txHandle, &rxHandle);
|
||||||
if (txHandle == nullptr or rxHandle == nullptr) {
|
if (txHandle == nullptr or rxHandle == nullptr) {
|
||||||
sif::printError("SpiComIF::initialize: DMA handles not set!\n");
|
sif::printError("SpiComIF::initialize: DMA handles not set!\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// This semaphore ensures thread-safety for a given bus
|
// This semaphore ensures thread-safety for a given bus
|
||||||
@ -79,7 +79,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
static_cast<unsigned long>(spiAddress));
|
static_cast<unsigned long>(spiAddress));
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto gpioPin = spiCookie->getChipSelectGpioPin();
|
auto gpioPin = spiCookie->getChipSelectGpioPin();
|
||||||
@ -98,7 +98,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
printCfgError("SPI Bus Index");
|
printCfgError("SPI Bus Index");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto mspCfg = spiCookie->getMspCfg();
|
auto mspCfg = spiCookie->getMspCfg();
|
||||||
@ -107,21 +107,21 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct *>(mspCfg);
|
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct *>(mspCfg);
|
||||||
if (typedCfg == nullptr) {
|
if (typedCfg == nullptr) {
|
||||||
printCfgError("Polling MSP");
|
printCfgError("Polling MSP");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
spi::setSpiPollingMspFunctions(typedCfg);
|
spi::setSpiPollingMspFunctions(typedCfg);
|
||||||
} else if (transferMode == spi::TransferModes::INTERRUPT) {
|
} else if (transferMode == spi::TransferModes::INTERRUPT) {
|
||||||
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct *>(mspCfg);
|
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct *>(mspCfg);
|
||||||
if (typedCfg == nullptr) {
|
if (typedCfg == nullptr) {
|
||||||
printCfgError("IRQ MSP");
|
printCfgError("IRQ MSP");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
spi::setSpiIrqMspFunctions(typedCfg);
|
spi::setSpiIrqMspFunctions(typedCfg);
|
||||||
} else if (transferMode == spi::TransferModes::DMA) {
|
} else if (transferMode == spi::TransferModes::DMA) {
|
||||||
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct *>(mspCfg);
|
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct *>(mspCfg);
|
||||||
if (typedCfg == nullptr) {
|
if (typedCfg == nullptr) {
|
||||||
printCfgError("DMA MSP");
|
printCfgError("DMA MSP");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
// Check DMA handles
|
// Check DMA handles
|
||||||
DMA_HandleTypeDef *txHandle = nullptr;
|
DMA_HandleTypeDef *txHandle = nullptr;
|
||||||
@ -129,7 +129,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
spi::getDmaHandles(&txHandle, &rxHandle);
|
spi::getDmaHandles(&txHandle, &rxHandle);
|
||||||
if (txHandle == nullptr or rxHandle == nullptr) {
|
if (txHandle == nullptr or rxHandle == nullptr) {
|
||||||
printCfgError("DMA Handle");
|
printCfgError("DMA Handle");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
spi::setSpiDmaMspFunctions(typedCfg);
|
spi::setSpiDmaMspFunctions(typedCfg);
|
||||||
}
|
}
|
||||||
@ -145,12 +145,12 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
|
|
||||||
if (HAL_SPI_Init(&spiHandle) != HAL_OK) {
|
if (HAL_SPI_Init(&spiHandle) != HAL_OK) {
|
||||||
sif::printWarning("SpiComIF::initialize: Error initializing SPI\n");
|
sif::printWarning("SpiComIF::initialize: Error initializing SPI\n");
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
// The MSP configuration struct is not required anymore
|
// The MSP configuration struct is not required anymore
|
||||||
spiCookie->deleteMspCfg();
|
spiCookie->deleteMspCfg();
|
||||||
|
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) {
|
ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) {
|
||||||
@ -163,7 +163,7 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
|||||||
|
|
||||||
auto iter = spiDeviceMap.find(spiCookie->getDeviceAddress());
|
auto iter = spiDeviceMap.find(spiCookie->getDeviceAddress());
|
||||||
if (iter == spiDeviceMap.end()) {
|
if (iter == spiDeviceMap.end()) {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
iter->second.currentTransferLen = sendLen;
|
iter->second.currentTransferLen = sendLen;
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
|||||||
case (spi::TransferStates::FAILURE):
|
case (spi::TransferStates::FAILURE):
|
||||||
case (spi::TransferStates::SUCCESS):
|
case (spi::TransferStates::SUCCESS):
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,13 +194,13 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
|||||||
sendData, sendLen);
|
sendData, sendLen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) { return returnvalue::OK; }
|
ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) { return HasReturnvaluesIF::RETURN_OK; }
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
|
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) {
|
ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) {
|
||||||
@ -212,7 +212,7 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
|||||||
case (spi::TransferStates::SUCCESS): {
|
case (spi::TransferStates::SUCCESS): {
|
||||||
auto iter = spiDeviceMap.find(spiCookie->getDeviceAddress());
|
auto iter = spiDeviceMap.find(spiCookie->getDeviceAddress());
|
||||||
if (iter == spiDeviceMap.end()) {
|
if (iter == spiDeviceMap.end()) {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
*buffer = iter->second.replyBuffer.data();
|
*buffer = iter->second.replyBuffer.data();
|
||||||
*size = iter->second.currentTransferLen;
|
*size = iter->second.currentTransferLen;
|
||||||
@ -228,18 +228,18 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
spiCookie->setTransferState(spi::TransferStates::IDLE);
|
spiCookie->setTransferState(spi::TransferStates::IDLE);
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
case (spi::TransferStates::WAIT):
|
case (spi::TransferStates::WAIT):
|
||||||
case (spi::TransferStates::IDLE): {
|
case (spi::TransferStates::IDLE): {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiComIF::setDefaultPollingTimeout(dur_millis_t timeout) {
|
void SpiComIF::setDefaultPollingTimeout(dur_millis_t timeout) {
|
||||||
@ -252,7 +252,7 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t *recvPtr, SPI_HandleT
|
|||||||
auto gpioPort = spiCookie.getChipSelectGpioPort();
|
auto gpioPort = spiCookie.getChipSelectGpioPort();
|
||||||
auto gpioPin = spiCookie.getChipSelectGpioPin();
|
auto gpioPin = spiCookie.getChipSelectGpioPin();
|
||||||
auto returnval = spiSemaphore->acquire(timeoutType, timeoutMs);
|
auto returnval = spiSemaphore->acquire(timeoutType, timeoutMs);
|
||||||
if (returnval != returnvalue::OK) {
|
if (returnval != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return returnval;
|
return returnval;
|
||||||
}
|
}
|
||||||
spiCookie.setTransferState(spi::TransferStates::WAIT);
|
spiCookie.setTransferState(spi::TransferStates::WAIT);
|
||||||
@ -299,7 +299,7 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t *recvPtr, SPI_HandleT
|
|||||||
return spi::HAL_ERROR_RETVAL;
|
return spi::HAL_ERROR_RETVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::handleInterruptSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
|
ReturnValue_t SpiComIF::handleInterruptSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
|
||||||
@ -318,7 +318,7 @@ ReturnValue_t SpiComIF::handleIrqSendOperation(uint8_t *recvPtr, SPI_HandleTypeD
|
|||||||
SpiCookie &spiCookie, const uint8_t *sendData,
|
SpiCookie &spiCookie, const uint8_t *sendData,
|
||||||
size_t sendLen) {
|
size_t sendLen) {
|
||||||
ReturnValue_t result = genericIrqSendSetup(recvPtr, spiHandle, spiCookie, sendData, sendLen);
|
ReturnValue_t result = genericIrqSendSetup(recvPtr, spiHandle, spiCookie, sendData, sendLen);
|
||||||
if (result != returnvalue::OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// yet another HAL driver which is not const-correct..
|
// yet another HAL driver which is not const-correct..
|
||||||
@ -366,7 +366,7 @@ ReturnValue_t SpiComIF::halErrorHandler(HAL_StatusTypeDef status, spi::TransferM
|
|||||||
return spi::HAL_TIMEOUT_RETVAL;
|
return spi::HAL_TIMEOUT_RETVAL;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return returnvalue::FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,7 +379,7 @@ ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef
|
|||||||
|
|
||||||
// Take the semaphore which will be released by a callback when the transfer is complete
|
// Take the semaphore which will be released by a callback when the transfer is complete
|
||||||
ReturnValue_t result = spiSemaphore->acquire(SemaphoreIF::TimeoutType::WAITING, timeoutMs);
|
ReturnValue_t result = spiSemaphore->acquire(SemaphoreIF::TimeoutType::WAITING, timeoutMs);
|
||||||
if (result != returnvalue::OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
// Configuration error
|
// Configuration error
|
||||||
sif::printWarning(
|
sif::printWarning(
|
||||||
"SpiComIF::handleInterruptSendOperation: Semaphore "
|
"SpiComIF::handleInterruptSendOperation: Semaphore "
|
||||||
@ -399,7 +399,7 @@ ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef
|
|||||||
HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(),
|
HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(),
|
||||||
GPIO_PIN_RESET);
|
GPIO_PIN_RESET);
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiComIF::spiTransferTxCompleteCallback(SPI_HandleTypeDef *hspi, void *args) {
|
void SpiComIF::spiTransferTxCompleteCallback(SPI_HandleTypeDef *hspi, void *args) {
|
||||||
@ -445,7 +445,7 @@ void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetSt
|
|||||||
#elif defined FSFW_OSAL_RTEMS
|
#elif defined FSFW_OSAL_RTEMS
|
||||||
ReturnValue_t result = comIF->spiSemaphore->release();
|
ReturnValue_t result = comIF->spiSemaphore->release();
|
||||||
#endif
|
#endif
|
||||||
if (result != returnvalue::OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
// Configuration error
|
// Configuration error
|
||||||
printf("SpiComIF::genericIrqHandler: Failure releasing Semaphore!\n");
|
printf("SpiComIF::genericIrqHandler: Failure releasing Semaphore!\n");
|
||||||
}
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user