merged develop
This commit is contained in:
commit
348274c145
7
.clang-format
Normal file
7
.clang-format
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: Google
|
||||||
|
IndentWidth: 2
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
ColumnLimit: 100
|
||||||
|
---
|
@ -4,6 +4,9 @@ set(FSFW_VERSION 2)
|
|||||||
set(FSFW_SUBVERSION 0)
|
set(FSFW_SUBVERSION 0)
|
||||||
set(FSFW_REVISION 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})
|
||||||
|
|
||||||
option(FSFW_GENERATE_SECTIONS
|
option(FSFW_GENERATE_SECTIONS
|
||||||
"Generate function and data sections. Required to remove unused code" ON
|
"Generate function and data sections. Required to remove unused code" ON
|
||||||
)
|
)
|
||||||
@ -12,6 +15,7 @@ if(FSFW_GENERATE_SECTIONS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(FSFW_BUILD_UNITTESTS "Build unittest binary in addition to static library" OFF)
|
option(FSFW_BUILD_UNITTESTS "Build unittest binary in addition to static library" OFF)
|
||||||
|
option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF)
|
||||||
if(FSFW_BUILD_UNITTESTS)
|
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()
|
||||||
@ -36,7 +40,9 @@ option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF)
|
|||||||
|
|
||||||
set(LIB_FSFW_NAME fsfw)
|
set(LIB_FSFW_NAME fsfw)
|
||||||
set(FSFW_TEST_TGT fsfw-tests)
|
set(FSFW_TEST_TGT fsfw-tests)
|
||||||
|
set(FSFW_DUMMY_TGT fsfw-dummy)
|
||||||
|
|
||||||
|
project(${LIB_FSFW_NAME})
|
||||||
add_library(${LIB_FSFW_NAME})
|
add_library(${LIB_FSFW_NAME})
|
||||||
|
|
||||||
if(FSFW_BUILD_UNITTESTS)
|
if(FSFW_BUILD_UNITTESTS)
|
||||||
@ -50,7 +56,7 @@ if(FSFW_BUILD_UNITTESTS)
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
Catch2
|
Catch2
|
||||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||||
GIT_TAG v3.0.0-preview3
|
GIT_TAG v3.0.0-preview4
|
||||||
)
|
)
|
||||||
|
|
||||||
FetchContent_MakeAvailable(Catch2)
|
FetchContent_MakeAvailable(Catch2)
|
||||||
@ -59,7 +65,6 @@ if(FSFW_BUILD_UNITTESTS)
|
|||||||
set(FSFW_CONFIG_PATH tests/src/fsfw_tests/unit/testcfg)
|
set(FSFW_CONFIG_PATH tests/src/fsfw_tests/unit/testcfg)
|
||||||
configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in FSFWConfig.h)
|
configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in FSFWConfig.h)
|
||||||
configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in tests/TestsConfig.h)
|
configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in tests/TestsConfig.h)
|
||||||
configure_file(tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in OBSWConfig.h)
|
|
||||||
|
|
||||||
project(${FSFW_TEST_TGT} CXX C)
|
project(${FSFW_TEST_TGT} CXX C)
|
||||||
add_executable(${FSFW_TEST_TGT})
|
add_executable(${FSFW_TEST_TGT})
|
||||||
@ -85,7 +90,7 @@ set(FSFW_CORE_INC_PATH "inc")
|
|||||||
|
|
||||||
set_property(CACHE FSFW_OSAL PROPERTY STRINGS host linux rtems freertos)
|
set_property(CACHE FSFW_OSAL PROPERTY STRINGS host linux rtems freertos)
|
||||||
|
|
||||||
# Configure Files
|
# For configure files
|
||||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
)
|
)
|
||||||
@ -147,13 +152,8 @@ else()
|
|||||||
set(OS_FSFW "host")
|
set(OS_FSFW "host")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FSFW_BUILD_UNITTESTS)
|
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)
|
|
||||||
else()
|
|
||||||
configure_file(src/fsfw/FSFW.h.in FSFW.h)
|
|
||||||
configure_file(src/fsfw/FSFWVersion.h.in FSFWVersion.h)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
message(STATUS "Compiling FSFW for the ${FSFW_OS_NAME} operating system.")
|
message(STATUS "Compiling FSFW for the ${FSFW_OS_NAME} operating system.")
|
||||||
|
|
||||||
@ -163,6 +163,9 @@ if(FSFW_ADD_HAL)
|
|||||||
add_subdirectory(hal)
|
add_subdirectory(hal)
|
||||||
endif()
|
endif()
|
||||||
add_subdirectory(contrib)
|
add_subdirectory(contrib)
|
||||||
|
if(FSFW_BUILD_DOCS)
|
||||||
|
add_subdirectory(docs)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(FSFW_BUILD_UNITTESTS)
|
if(FSFW_BUILD_UNITTESTS)
|
||||||
if(FSFW_TESTS_GEN_COV)
|
if(FSFW_TESTS_GEN_COV)
|
||||||
@ -189,13 +192,13 @@ if(FSFW_BUILD_UNITTESTS)
|
|||||||
"--exclude-unreachable-branches"
|
"--exclude-unreachable-branches"
|
||||||
)
|
)
|
||||||
set(COVERAGE_EXCLUDES
|
set(COVERAGE_EXCLUDES
|
||||||
"/c/msys64/mingw64/*"
|
"/c/msys64/mingw64/*" "*/fsfw_hal/*"
|
||||||
)
|
)
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
set(COVERAGE_EXCLUDES
|
set(COVERAGE_EXCLUDES
|
||||||
"/usr/include/*" "/usr/bin/*" "Catch2/*"
|
"/usr/include/*" "/usr/bin/*" "Catch2/*"
|
||||||
"/usr/local/include/*" "*/fsfw_tests/*"
|
"/usr/local/include/*" "*/fsfw_tests/*"
|
||||||
"*/catch2-src/*"
|
"*/catch2-src/*" "*/fsfw_hal/*"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -234,9 +237,11 @@ endif()
|
|||||||
# The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it.
|
# The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it.
|
||||||
# If this is not given, we include the default configuration and emit a warning.
|
# If this is not given, we include the default configuration and emit a warning.
|
||||||
if(NOT FSFW_CONFIG_PATH)
|
if(NOT FSFW_CONFIG_PATH)
|
||||||
message(WARNING "Flight Software Framework configuration path not set!")
|
|
||||||
set(DEF_CONF_PATH misc/defaultcfg/fsfwconfig)
|
set(DEF_CONF_PATH misc/defaultcfg/fsfwconfig)
|
||||||
|
if(NOT FSFW_BUILD_DOCS)
|
||||||
|
message(WARNING "Flight Software Framework configuration path not set!")
|
||||||
message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..")
|
message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..")
|
||||||
|
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})
|
||||||
endif()
|
endif()
|
||||||
|
26
README.md
26
README.md
@ -42,7 +42,7 @@ There are some functions like `printChar` which are different depending on the t
|
|||||||
and need to be implemented by the mission developer.
|
and need to be implemented by the mission developer.
|
||||||
|
|
||||||
A template configuration folder was provided and can be copied into the project root to have
|
A template configuration folder was provided and can be copied into the project root to have
|
||||||
a starting point. The [configuration section](doc/README-config.md#top) provides more specific
|
a starting point. The [configuration section](docs/README-config.md#top) provides more specific
|
||||||
information about the possible options.
|
information about the possible options.
|
||||||
|
|
||||||
## Adding the library
|
## Adding the library
|
||||||
@ -91,7 +91,7 @@ You can use the following commands inside the `fsfw` folder to set up the build
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
mkdir build-Unittest && cd build-Unittest
|
mkdir build-Unittest && cd build-Unittest
|
||||||
cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host ..
|
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.
|
||||||
@ -107,16 +107,22 @@ cmake --build . -- fsfw-tests_coverage -j
|
|||||||
|
|
||||||
The `coverage.py` script located in the `script` folder can also be used to do this conveniently.
|
The `coverage.py` script located in the `script` folder can also be used to do this conveniently.
|
||||||
|
|
||||||
|
## Formatting the sources
|
||||||
|
|
||||||
|
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
|
||||||
|
can run the `apply-clang-format.sh` helper script to format all source files consistently.
|
||||||
|
|
||||||
## Index
|
## Index
|
||||||
|
|
||||||
[1. High-level overview](doc/README-highlevel.md#top) <br>
|
[1. High-level overview](docs/README-highlevel.md#top) <br>
|
||||||
[2. Core components](doc/README-core.md#top) <br>
|
[2. Core components](docs/README-core.md#top) <br>
|
||||||
[3. Configuration](doc/README-config.md#top) <br>
|
[3. Configuration](docs/README-config.md#top) <br>
|
||||||
[4. OSAL overview](doc/README-osal.md#top) <br>
|
[4. OSAL overview](docs/README-osal.md#top) <br>
|
||||||
[5. PUS services](doc/README-pus.md#top) <br>
|
[5. PUS services](docs/README-pus.md#top) <br>
|
||||||
[6. Device Handler overview](doc/README-devicehandlers.md#top) <br>
|
[6. Device Handler overview](docs/README-devicehandlers.md#top) <br>
|
||||||
[7. Controller overview](doc/README-controllers.md#top) <br>
|
[7. Controller overview](docs/README-controllers.md#top) <br>
|
||||||
[8. Local Data Pools](doc/README-localpools.md#top) <br>
|
[8. Local Data Pools](docs/README-localpools.md#top) <br>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,4 +5,10 @@ RUN apt-get --yes upgrade
|
|||||||
|
|
||||||
#tzdata is a dependency, won't install otherwise
|
#tzdata is a dependency, won't install otherwise
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
RUN apt-get --yes install gcc g++ cmake make lcov git valgrind nano
|
RUN apt-get --yes install gcc g++ cmake make lcov git valgrind nano iputils-ping
|
||||||
|
|
||||||
|
RUN git clone https://github.com/catchorg/Catch2.git && \
|
||||||
|
cd Catch2 && \
|
||||||
|
git checkout v3.0.0-preview4 && \
|
||||||
|
cmake -Bbuild -H. -DBUILD_TESTING=OFF && \
|
||||||
|
cmake --build build/ --target install
|
||||||
|
35
automation/Jenkinsfile
vendored
35
automation/Jenkinsfile
vendored
@ -1,28 +1,23 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
|
||||||
environment {
|
environment {
|
||||||
BUILDDIR = 'build-unittests'
|
BUILDDIR = 'build-tests'
|
||||||
}
|
}
|
||||||
stages {
|
|
||||||
stage('Create Docker') {
|
|
||||||
agent {
|
agent {
|
||||||
dockerfile {
|
dockerfile {
|
||||||
dir 'automation'
|
dir 'automation'
|
||||||
additionalBuildArgs '--no-cache'
|
//force docker to redownload base image and rebuild all steps instead of caching them
|
||||||
|
//this way, we always get an up to date docker image one each build
|
||||||
|
additionalBuildArgs '--no-cache --pull'
|
||||||
reuseNode true
|
reuseNode true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stages {
|
||||||
|
stage('Clean') {
|
||||||
steps {
|
steps {
|
||||||
sh 'rm -rf $BUILDDIR'
|
sh 'rm -rf $BUILDDIR'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Configure') {
|
stage('Configure') {
|
||||||
agent {
|
|
||||||
dockerfile {
|
|
||||||
dir 'automation'
|
|
||||||
reuseNode true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
dir(BUILDDIR) {
|
dir(BUILDDIR) {
|
||||||
sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..'
|
sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..'
|
||||||
@ -30,12 +25,6 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
agent {
|
|
||||||
dockerfile {
|
|
||||||
dir 'automation'
|
|
||||||
reuseNode true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
dir(BUILDDIR) {
|
dir(BUILDDIR) {
|
||||||
sh 'cmake --build . -j'
|
sh 'cmake --build . -j'
|
||||||
@ -43,12 +32,6 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Unittests') {
|
stage('Unittests') {
|
||||||
agent {
|
|
||||||
dockerfile {
|
|
||||||
dir 'automation'
|
|
||||||
reuseNode true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
dir(BUILDDIR) {
|
dir(BUILDDIR) {
|
||||||
sh 'cmake --build . -- fsfw-tests_coverage -j'
|
sh 'cmake --build . -- fsfw-tests_coverage -j'
|
||||||
@ -56,12 +39,6 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Valgrind') {
|
stage('Valgrind') {
|
||||||
agent {
|
|
||||||
dockerfile {
|
|
||||||
dir 'automation'
|
|
||||||
reuseNode true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
dir(BUILDDIR) {
|
dir(BUILDDIR) {
|
||||||
sh 'valgrind --leak-check=full --error-exitcode=1 ./fsfw-tests'
|
sh 'valgrind --leak-check=full --error-exitcode=1 ./fsfw-tests'
|
||||||
|
13
cmake/FindSphinx.cmake
Normal file
13
cmake/FindSphinx.cmake
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Look for an executable called sphinx-build
|
||||||
|
find_program(SPHINX_EXECUTABLE
|
||||||
|
NAMES sphinx-build
|
||||||
|
DOC "Path to sphinx-build executable")
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
# Handle standard arguments to find_package like REQUIRED and QUIET
|
||||||
|
find_package_handle_standard_args(
|
||||||
|
Sphinx
|
||||||
|
"Failed to find sphinx-build executable"
|
||||||
|
SPHINX_EXECUTABLE
|
||||||
|
)
|
1
docs/.gitignore
vendored
Normal file
1
docs/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/_build
|
66
docs/CMakeLists.txt
Normal file
66
docs/CMakeLists.txt
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# This is based on this excellent posting provided by Sy:
|
||||||
|
# https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/
|
||||||
|
find_package(Doxygen REQUIRED)
|
||||||
|
find_package(Sphinx REQUIRED)
|
||||||
|
|
||||||
|
get_target_property(LIB_FSFW_PUBLIC_HEADER_DIRS ${LIB_FSFW_NAME} INTERFACE_INCLUDE_DIRECTORIES)
|
||||||
|
# TODO: Add HAL as well
|
||||||
|
file(GLOB_RECURSE LIB_FSFW_PUBLIC_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h)
|
||||||
|
file(GLOB_RECURSE RST_DOC_FILES ${PROJECT_SOURCE_DIR}/docs/*.rst)
|
||||||
|
|
||||||
|
set(DOXYGEN_INPUT_DIR ${PROJECT_SOURCE_DIR}/src)
|
||||||
|
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/doxygen)
|
||||||
|
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/xml/index.xml)
|
||||||
|
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
|
||||||
|
set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||||
|
|
||||||
|
# Replace variables inside @@ with the current values
|
||||||
|
configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)
|
||||||
|
|
||||||
|
# Doxygen won't create this for us
|
||||||
|
file(MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR})
|
||||||
|
|
||||||
|
# Only regenerate Doxygen when the Doxyfile or public headers change
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${DOXYGEN_INDEX_FILE}
|
||||||
|
DEPENDS ${LIB_FSFW_PUBLIC_HEADERS}
|
||||||
|
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
|
||||||
|
MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN}
|
||||||
|
COMMENT "Generating docs"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
|
||||||
|
# Nice named target so we can run the job easily
|
||||||
|
add_custom_target(Doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE})
|
||||||
|
|
||||||
|
set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}/sphinx)
|
||||||
|
set(SPHINX_INDEX_FILE ${SPHINX_BUILD}/index.html)
|
||||||
|
|
||||||
|
# Only regenerate Sphinx when:
|
||||||
|
# - Doxygen has rerun
|
||||||
|
# - Our doc files have been updated
|
||||||
|
# - The Sphinx config has been updated
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${SPHINX_INDEX_FILE}
|
||||||
|
COMMAND
|
||||||
|
${SPHINX_EXECUTABLE} -b html
|
||||||
|
# Tell Breathe where to find the Doxygen output
|
||||||
|
-Dbreathe_projects.fsfw=${DOXYGEN_OUTPUT_DIR}/xml
|
||||||
|
${SPHINX_SOURCE} ${SPHINX_BUILD}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
DEPENDS
|
||||||
|
# Other docs files you want to track should go here (or in some variable)
|
||||||
|
${RST_DOC_FILES}
|
||||||
|
${DOXYGEN_INDEX_FILE}
|
||||||
|
MAIN_DEPENDENCY ${SPHINX_SOURCE}/conf.py
|
||||||
|
COMMENT "Generating documentation with Sphinx"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Nice named target so we can run the job easily
|
||||||
|
add_custom_target(Sphinx ALL DEPENDS ${SPHINX_INDEX_FILE})
|
||||||
|
|
||||||
|
# Add an install target to install the docs
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
install(DIRECTORY ${SPHINX_BUILD}
|
||||||
|
DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
7
docs/Doxyfile.in
Normal file
7
docs/Doxyfile.in
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
INPUT = "@DOXYGEN_INPUT_DIR@"
|
||||||
|
|
||||||
|
RECURSIVE = YES
|
||||||
|
|
||||||
|
OUTPUT_DIRECTORY = "@DOXYGEN_OUTPUT_DIR@"
|
||||||
|
|
||||||
|
GENERATE_XML = YES
|
20
docs/Makefile
Normal file
20
docs/Makefile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Minimal makefile for Sphinx documentation
|
||||||
|
#
|
||||||
|
|
||||||
|
# You can set these variables from the command line, and also
|
||||||
|
# from the environment for the first two.
|
||||||
|
SPHINXOPTS ?=
|
||||||
|
SPHINXBUILD ?= sphinx-build
|
||||||
|
SOURCEDIR = .
|
||||||
|
BUILDDIR = _build
|
||||||
|
|
||||||
|
# Put it first so that "make" without argument is like "make help".
|
||||||
|
help:
|
||||||
|
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
|
|
||||||
|
.PHONY: help Makefile
|
||||||
|
|
||||||
|
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||||
|
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||||
|
%: Makefile
|
||||||
|
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
@ -31,7 +31,9 @@ cohesive pool variables. These sets simply iterator over the list of variables a
|
|||||||
`read` and `commit` functions of each variable. The following diagram shows the
|
`read` and `commit` functions of each variable. The following diagram shows the
|
||||||
high-level architecture of the local data pools.
|
high-level architecture of the local data pools.
|
||||||
|
|
||||||
<img align="center" src="./images/PoolArchitecture.png" width="50%"> <br>
|
.. image:: ../misc/logo/FSFW_Logo_V3_bw.png
|
||||||
|
:alt: FSFW Logo
|
||||||
|
|
||||||
|
|
||||||
An example is shown for using the local data pools with a Gyroscope.
|
An example is shown for using the local data pools with a Gyroscope.
|
||||||
For example, the following code shows an implementation to access data from a Gyroscope taken
|
For example, the following code shows an implementation to access data from a Gyroscope taken
|
16
docs/api.rst
Normal file
16
docs/api.rst
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
API
|
||||||
|
====
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 4
|
||||||
|
|
||||||
|
api/objectmanager
|
||||||
|
api/task
|
||||||
|
api/ipc
|
||||||
|
api/returnvalue
|
||||||
|
api/event
|
||||||
|
api/modes
|
||||||
|
api/health
|
||||||
|
api/action
|
||||||
|
api/devicehandler
|
||||||
|
api/controller
|
15
docs/api/action.rst
Normal file
15
docs/api/action.rst
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
Action Module API
|
||||||
|
=================
|
||||||
|
|
||||||
|
``ActionHelper``
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
.. doxygenclass:: ActionHelper
|
||||||
|
:members:
|
||||||
|
|
||||||
|
``HasActionsIF``
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
.. doxygenclass:: HasActionsIF
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
16
docs/api/controller.rst
Normal file
16
docs/api/controller.rst
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
Controller API
|
||||||
|
=================
|
||||||
|
|
||||||
|
``ControllerBase``
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
.. doxygenclass:: ControllerBase
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
||||||
|
|
||||||
|
``ExtendedControllerBase``
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
.. doxygenclass:: ExtendedControllerBase
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
16
docs/api/devicehandler.rst
Normal file
16
docs/api/devicehandler.rst
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
Device Handler Base API
|
||||||
|
=========================
|
||||||
|
|
||||||
|
``DeviceHandlerBase``
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
.. doxygenclass:: DeviceHandlerBase
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
||||||
|
|
||||||
|
``DeviceHandlerIF``
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
.. doxygenclass:: DeviceHandlerIF
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
6
docs/api/event.rst
Normal file
6
docs/api/event.rst
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
.. _eventapi:
|
||||||
|
|
||||||
|
Event API
|
||||||
|
============
|
||||||
|
|
||||||
|
.. doxygenfile:: Event.h
|
9
docs/api/health.rst
Normal file
9
docs/api/health.rst
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Health API
|
||||||
|
===========
|
||||||
|
|
||||||
|
``HasHealthIF``
|
||||||
|
------------------
|
||||||
|
|
||||||
|
.. doxygenclass:: HasHealthIF
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
9
docs/api/ipc.rst
Normal file
9
docs/api/ipc.rst
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
IPC Module API
|
||||||
|
=================
|
||||||
|
|
||||||
|
``MessageQueueIF``
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
.. doxygenclass:: MessageQueueIF
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
10
docs/api/modes.rst
Normal file
10
docs/api/modes.rst
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Modes API
|
||||||
|
=========
|
||||||
|
|
||||||
|
|
||||||
|
``HasModesIF``
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. doxygenclass:: HasModesIF
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
30
docs/api/objectmanager.rst
Normal file
30
docs/api/objectmanager.rst
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
Object Manager API
|
||||||
|
=========================
|
||||||
|
|
||||||
|
``SystemObject``
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
.. doxygenclass:: SystemObject
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
||||||
|
|
||||||
|
``ObjectManager``
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
.. doxygenclass:: ObjectManager
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
||||||
|
|
||||||
|
``SystemObjectIF``
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
.. doxygenclass:: SystemObjectIF
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
||||||
|
|
||||||
|
``ObjectManagerIF``
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
.. doxygenclass:: ObjectManagerIF
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
10
docs/api/returnvalue.rst
Normal file
10
docs/api/returnvalue.rst
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.. _retvalapi:
|
||||||
|
|
||||||
|
Returnvalue API
|
||||||
|
==================
|
||||||
|
|
||||||
|
.. doxygenfile:: HasReturnvaluesIF.h
|
||||||
|
|
||||||
|
.. _fwclassids:
|
||||||
|
|
||||||
|
.. doxygenfile:: FwClassIds.h
|
8
docs/api/task.rst
Normal file
8
docs/api/task.rst
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Task API
|
||||||
|
=========
|
||||||
|
|
||||||
|
``ExecutableObjectIF``
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
.. doxygenclass:: ExecutableObjectIF
|
||||||
|
:members:
|
56
docs/conf.py
Normal file
56
docs/conf.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
# Configuration file for the Sphinx documentation builder.
|
||||||
|
#
|
||||||
|
# This file only contains a selection of the most common options. For a full
|
||||||
|
# list see the documentation:
|
||||||
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||||
|
|
||||||
|
# -- Path setup --------------------------------------------------------------
|
||||||
|
|
||||||
|
# If extensions (or modules to document with autodoc) are in another directory,
|
||||||
|
# add these directories to sys.path here. If the directory is relative to the
|
||||||
|
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||||
|
#
|
||||||
|
# import os
|
||||||
|
# import sys
|
||||||
|
# sys.path.insert(0, os.path.abspath('.'))
|
||||||
|
|
||||||
|
|
||||||
|
# -- Project information -----------------------------------------------------
|
||||||
|
|
||||||
|
project = 'Flight Software Framework'
|
||||||
|
copyright = '2021, Institute of Space Systems (IRS)'
|
||||||
|
author = 'Institute of Space Systems (IRS)'
|
||||||
|
|
||||||
|
# The full version, including alpha/beta/rc tags
|
||||||
|
release = '2.0.1'
|
||||||
|
|
||||||
|
|
||||||
|
# -- General configuration ---------------------------------------------------
|
||||||
|
|
||||||
|
# Add any Sphinx extension module names here, as strings. They can be
|
||||||
|
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||||
|
# ones.
|
||||||
|
extensions = [ "breathe" ]
|
||||||
|
|
||||||
|
breathe_default_project = "fsfw"
|
||||||
|
|
||||||
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
|
templates_path = ['_templates']
|
||||||
|
|
||||||
|
# List of patterns, relative to source directory, that match files and
|
||||||
|
# directories to ignore when looking for source files.
|
||||||
|
# This pattern also affects html_static_path and html_extra_path.
|
||||||
|
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||||
|
|
||||||
|
|
||||||
|
# -- Options for HTML output -------------------------------------------------
|
||||||
|
|
||||||
|
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||||
|
# a list of builtin themes.
|
||||||
|
#
|
||||||
|
html_theme = 'alabaster'
|
||||||
|
|
||||||
|
# Add any paths that contain custom static files (such as style sheets) here,
|
||||||
|
# relative to this directory. They are copied after the builtin static files,
|
||||||
|
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||||
|
html_static_path = []
|
41
docs/config.rst
Normal file
41
docs/config.rst
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
Configuring the FSFW
|
||||||
|
=====================
|
||||||
|
|
||||||
|
The FSFW can be configured via the ``fsfwconfig`` folder. A template folder has been provided in
|
||||||
|
``misc/defaultcfg`` to have a starting point for this. The folder should be added
|
||||||
|
to the include path. The primary configuration file is the ``FSFWConfig.h`` folder. Some
|
||||||
|
of the available options will be explained in more detail here.
|
||||||
|
|
||||||
|
Auto-Translation of Events
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
The FSFW allows the automatic translation of events, which allows developers to track triggered
|
||||||
|
events directly via console output. Using this feature requires:
|
||||||
|
|
||||||
|
1. ``FSFW_OBJ_EVENT_TRANSLATION`` set to 1 in the configuration file.
|
||||||
|
2. Special auto-generated translation files which translate event IDs and object IDs into
|
||||||
|
human readable strings. These files can be generated using the
|
||||||
|
`fsfwgen Python scripts <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-gen>`_.
|
||||||
|
3. The generated translation files for the object IDs should be named ``translatesObjects.cpp``
|
||||||
|
and ``translateObjects.h`` and should be copied to the ``fsfwconfig/objects`` folder
|
||||||
|
4. The generated translation files for the event IDs should be named ``translateEvents.cpp`` and
|
||||||
|
``translateEvents.h`` and should be copied to the ``fsfwconfig/events`` folder
|
||||||
|
|
||||||
|
An example implementations of these translation file generators can be found as part
|
||||||
|
of the `SOURCE project here <https://git.ksat-stuttgart.de/source/sourceobsw/-/tree/develop/generators>`_
|
||||||
|
or the `FSFW example <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted/src/branch/master/generators>`_
|
||||||
|
|
||||||
|
Configuring the Event Manager
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
The number of allowed subscriptions can be modified with the following
|
||||||
|
parameters:
|
||||||
|
|
||||||
|
.. code-block:: cpp
|
||||||
|
|
||||||
|
namespace fsfwconfig {
|
||||||
|
//! Configure the allocated pool sizes for the event manager.
|
||||||
|
static constexpr size_t FSFW_EVENTMGMR_MATCHTREE_NODES = 240;
|
||||||
|
static constexpr size_t FSFW_EVENTMGMT_EVENTIDMATCHERS = 120;
|
||||||
|
static constexpr size_t FSFW_EVENTMGMR_RANGEMATCHERS = 120;
|
||||||
|
}
|
2
docs/controllers.rst
Normal file
2
docs/controllers.rst
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Controllers
|
||||||
|
=============
|
70
docs/core.rst
Normal file
70
docs/core.rst
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
.. _core:
|
||||||
|
|
||||||
|
Core Modules
|
||||||
|
=============
|
||||||
|
|
||||||
|
The core modules provide the most important functionalities of the Flight Software Framework.
|
||||||
|
|
||||||
|
Clock
|
||||||
|
------
|
||||||
|
|
||||||
|
- This is a class of static functions that can be used at anytime
|
||||||
|
- Leap Seconds must be set if any time conversions from UTC to other times is used
|
||||||
|
|
||||||
|
Object Manager
|
||||||
|
---------------
|
||||||
|
|
||||||
|
- Must be created during program startup
|
||||||
|
- The component which handles all references. All :cpp:class:`SystemObject`\s register at this
|
||||||
|
component.
|
||||||
|
- All :cpp:class:`SystemObject`\s needs to have a unique Object ID. Those can be managed like
|
||||||
|
framework objects.
|
||||||
|
- A reference to an object can be retrieved by calling the ``get`` function of
|
||||||
|
:cpp:class:`ObjectManagerIF`. The target type must be specified as a template argument.
|
||||||
|
A ``nullptr`` check of the returning pointer must be done. This function is based on
|
||||||
|
run-time type information.
|
||||||
|
|
||||||
|
.. code-block:: cpp
|
||||||
|
|
||||||
|
template <typename T> T* ObjectManagerIF::get(object_id_t id);
|
||||||
|
|
||||||
|
- A typical way to create all objects on startup is a handing a static produce function to the
|
||||||
|
ObjectManager on creation. By calling ``ObjectManager::instance()->initialize(produceFunc)`` the
|
||||||
|
produce function will be called and all :cpp:class:`SystemObject`\s will be initialized
|
||||||
|
afterwards.
|
||||||
|
|
||||||
|
Event Manager
|
||||||
|
---------------
|
||||||
|
|
||||||
|
- Component which allows routing of events
|
||||||
|
- Other objects can subscribe to specific events, ranges of events or all events of an object.
|
||||||
|
- Subscriptions can be done during runtime but should be done during initialization
|
||||||
|
- Amounts of allowed subscriptions can be configured in ``FSFWConfig.h``
|
||||||
|
|
||||||
|
Health Table
|
||||||
|
---------------
|
||||||
|
|
||||||
|
- A component which holds every health state
|
||||||
|
- Provides a thread safe way to access all health states without the need of message exchanges
|
||||||
|
|
||||||
|
Stores
|
||||||
|
--------------
|
||||||
|
|
||||||
|
- The message based communication can only exchange a few bytes of information inside the message
|
||||||
|
itself. Therefore, additional information can be exchanged with Stores. With this, only the
|
||||||
|
store address must be exchanged in the message.
|
||||||
|
- Internally, the FSFW uses an IPC Store to exchange data between processes. For incoming TCs a TC
|
||||||
|
Store is used. For outgoing TM a TM store is used.
|
||||||
|
- All of them should use the Thread Safe Class storagemanager/PoolManager
|
||||||
|
|
||||||
|
Tasks
|
||||||
|
---------
|
||||||
|
|
||||||
|
There are two different types of tasks:
|
||||||
|
|
||||||
|
- The PeriodicTask just executes objects that are of type ExecutableObjectIF in the order of the
|
||||||
|
insertion to the Tasks.
|
||||||
|
- FixedTimeslotTask executes a list of calls in the order of the given list. This is intended for
|
||||||
|
DeviceHandlers, where polling should be in a defined order. An example can be found in
|
||||||
|
``defaultcfg/fsfwconfig/pollingSequence`` folder
|
||||||
|
|
3
docs/devicehandlers.rst
Normal file
3
docs/devicehandlers.rst
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Device Handlers
|
||||||
|
==================
|
||||||
|
|
115
docs/getting_started.rst
Normal file
115
docs/getting_started.rst
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
Getting Started
|
||||||
|
================
|
||||||
|
|
||||||
|
|
||||||
|
Getting started
|
||||||
|
----------------
|
||||||
|
|
||||||
|
The `Hosted FSFW example`_ provides a good starting point and a demo to see the FSFW capabilities.
|
||||||
|
It is recommended to get started by building and playing around with the demo application.
|
||||||
|
There are also other examples provided for all OSALs using the popular embedded platforms
|
||||||
|
Raspberry Pi, Beagle Bone Black and STM32H7.
|
||||||
|
|
||||||
|
Generally, the FSFW is included in a project by providing
|
||||||
|
a configuration folder, building the static library and linking against it.
|
||||||
|
There are some functions like ``printChar`` which are different depending on the target architecture
|
||||||
|
and need to be implemented by the mission developer.
|
||||||
|
|
||||||
|
A template configuration folder was provided and can be copied into the project root to have
|
||||||
|
a starting point. The [configuration section](docs/README-config.md#top) provides more specific
|
||||||
|
information about the possible options.
|
||||||
|
|
||||||
|
Adding the library
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
The following steps show how to add and use FSFW components. It is still recommended to
|
||||||
|
try out the example mentioned above to get started, but the following steps show how to
|
||||||
|
add and link against the FSFW library in general.
|
||||||
|
|
||||||
|
1. Add this repository as a submodule
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
git submodule add https://egit.irs.uni-stuttgart.de/fsfw/fsfw.git fsfw
|
||||||
|
|
||||||
|
2. Add the following directive inside the uppermost ``CMakeLists.txt`` file of your project
|
||||||
|
|
||||||
|
.. code-block:: cmake
|
||||||
|
|
||||||
|
add_subdirectory(fsfw)
|
||||||
|
|
||||||
|
3. Make sure to provide a configuration folder and supply the path to that folder with
|
||||||
|
the `FSFW_CONFIG_PATH` CMake variable from the uppermost `CMakeLists.txt` file.
|
||||||
|
It is also necessary to provide the `printChar` function. You can find an example
|
||||||
|
implementation for a hosted build
|
||||||
|
`here <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted/src/branch/master/bsp_hosted/utility/printChar.c>`_.
|
||||||
|
|
||||||
|
4. Link against the FSFW library
|
||||||
|
|
||||||
|
.. code-block:: cmake
|
||||||
|
|
||||||
|
target_link_libraries(<YourProjectName> PRIVATE fsfw)
|
||||||
|
|
||||||
|
|
||||||
|
5. It should now be possible use the FSFW as a static library from the user code.
|
||||||
|
|
||||||
|
Building the unittests
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
The FSFW also has unittests which use the `Catch2 library`_.
|
||||||
|
These are built by setting the CMake option ``FSFW_BUILD_UNITTESTS`` to ``ON`` or `TRUE`
|
||||||
|
from your project `CMakeLists.txt` file or from the command line.
|
||||||
|
|
||||||
|
The fsfw-tests binary will be built as part of the static library and dropped alongside it.
|
||||||
|
If the unittests are built, the library and the tests will be built with coverage information by
|
||||||
|
default. This can be disabled by setting the `FSFW_TESTS_COV_GEN` option to `OFF` or `FALSE`.
|
||||||
|
|
||||||
|
You can use the following commands inside the ``fsfw`` folder to set up the build system
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
mkdir build-tests && cd build-tests
|
||||||
|
cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host ..
|
||||||
|
|
||||||
|
|
||||||
|
You can also use ``-DFSFW_OSAL=linux`` on Linux systems.
|
||||||
|
|
||||||
|
Coverage data in HTML format can be generated using the `Code coverage`_ CMake module.
|
||||||
|
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
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
cmake --build . -- fsfw-tests_coverage -j
|
||||||
|
|
||||||
|
|
||||||
|
The ``helper.py`` script located in the ``script`` folder can also be used to create, build
|
||||||
|
and open the unittests conveniently. Try ``helper.py -h`` for more information.
|
||||||
|
|
||||||
|
Building the documentation
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
The FSFW documentation is built using the tools Sphinx, doxygen and breathe based on the
|
||||||
|
instructions provided in `this blogpost <https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/>`_. You can set up a
|
||||||
|
documentation build system using the following commands
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
mkdir build-docs && cd build-docs
|
||||||
|
cmake -DFSFW_BUILD_DOCS=ON -DFSFW_OSAL=host ..
|
||||||
|
|
||||||
|
Then you can generate the documentation using
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
cmake --build . -j
|
||||||
|
|
||||||
|
You can find the generated documentation inside the ``docs/sphinx`` folder inside the build
|
||||||
|
folder. Simply open the ``index.html`` in the webbrowser of your choice.
|
||||||
|
|
||||||
|
The ``helper.py`` script located in the ``script`` folder can also be used to create, build
|
||||||
|
and open the documentation conveniently. Try ``helper.py -h`` for more information.
|
||||||
|
|
||||||
|
.. _`Hosted FSFW example`: https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted
|
||||||
|
.. _`Catch2 library`: https://github.com/catchorg/Catch2
|
||||||
|
.. _`Code coverage`: https://github.com/bilke/cmake-modules/tree/master
|
149
docs/highlevel.rst
Normal file
149
docs/highlevel.rst
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
.. _highlevel:
|
||||||
|
|
||||||
|
High-level overview
|
||||||
|
===================
|
||||||
|
|
||||||
|
Structure
|
||||||
|
----------
|
||||||
|
|
||||||
|
The general structure is driven by the usage of interfaces provided by objects.
|
||||||
|
The FSFW uses C++11 as baseline. The intention behind this is that this C++ Standard should be
|
||||||
|
widely available, even with older compilers.
|
||||||
|
The FSFW uses dynamic allocation during the initialization but provides static containers during runtime.
|
||||||
|
This simplifies the instantiation of objects and allows the usage of some standard containers.
|
||||||
|
Dynamic Allocation after initialization is discouraged and different solutions are provided in the
|
||||||
|
FSFW to achieve that. The fsfw uses run-time type information but exceptions are not allowed.
|
||||||
|
|
||||||
|
Failure Handling
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
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:`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.
|
||||||
|
See the :ref:`FSFW Class IDs file <fwclassids>`. The user can add custom ``CLASS_ID``\s via the
|
||||||
|
``fsfwconfig`` folder.
|
||||||
|
|
||||||
|
OSAL
|
||||||
|
------------
|
||||||
|
|
||||||
|
The FSFW provides operation system abstraction layers for Linux, FreeRTOS and RTEMS.
|
||||||
|
The OSAL provides periodic tasks, message queues, clocks and semaphores as well as mutexes.
|
||||||
|
The :ref:`OSAL README <osal>` provides more detailed information on provided components
|
||||||
|
and how to use them.
|
||||||
|
|
||||||
|
Core Components
|
||||||
|
----------------
|
||||||
|
|
||||||
|
The FSFW has following core components. More detailed informations can be found in the
|
||||||
|
:ref:`core component section <core>`:
|
||||||
|
|
||||||
|
1. Tasks: Abstraction for different (periodic) task types like periodic tasks or tasks
|
||||||
|
with fixed timeslots
|
||||||
|
2. ObjectManager: This module stores all `SystemObjects` by mapping a provided unique object ID
|
||||||
|
to the object handles.
|
||||||
|
3. Static Stores: Different stores are provided to store data of variable size (like telecommands
|
||||||
|
or small telemetry) in a pool structure without using dynamic memory allocation.
|
||||||
|
These pools are allocated up front.
|
||||||
|
4. Clock: This module provided common time related functions
|
||||||
|
5. EventManager: This module allows routing of events generated by `SystemObjects`
|
||||||
|
6. HealthTable: A component which stores the health states of objects
|
||||||
|
|
||||||
|
Static IDs in the framework
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
Some parts of the framework use a static routing address for communication.
|
||||||
|
An example setup of IDs can be found in the example config in ``misc/defaultcfg/fsfwconfig/objects``
|
||||||
|
inside the function ``Factory::setStaticFrameworkObjectIds``.
|
||||||
|
|
||||||
|
Events
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Events are tied to objects. EventIds can be generated by calling the
|
||||||
|
:ref:`macro MAKE_EVENT <eventapi>` or the function :cpp:func:`event::makeEvent`.
|
||||||
|
This works analog to the returnvalues. Every object that needs own Event IDs has to get a
|
||||||
|
unique ``SUBSYSTEM_ID``. Every :cpp:class:`SystemObject` can call
|
||||||
|
:cpp:func:`SystemObject::triggerEvent` from the parent class.
|
||||||
|
Therefore, event messages contain the specific EventId and the objectId of the object that
|
||||||
|
has triggered.
|
||||||
|
|
||||||
|
Internal Communication
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
Components communicate mostly via Messages through Queues.
|
||||||
|
Those queues are created by calling the singleton ``QueueFactory::instance()->create`` which
|
||||||
|
will create `MessageQueue` instances for the used OSAL.
|
||||||
|
|
||||||
|
External Communication
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
The external communication with the mission control system is mostly up to the user implementation.
|
||||||
|
The FSFW provides PUS Services which can be used to but don't need to be used.
|
||||||
|
The services can be seen as a conversion from a TC to a message based communication and back.
|
||||||
|
|
||||||
|
TMTC Communication
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The FSFW provides some components to facilitate TMTC handling via the PUS commands.
|
||||||
|
For example, a UDP or TCP PUS server socket can be opened on a specific port using the
|
||||||
|
files located in ``osal/common``. The FSFW example uses this functionality to allow sending
|
||||||
|
telecommands and receiving telemetry using the
|
||||||
|
`TMTC commander application <https://github.com/robamu-org/tmtccmd>`_.
|
||||||
|
|
||||||
|
Simple commands like the PUS Service 17 ping service can be tested by simply running the
|
||||||
|
``tmtc_client_cli.py`` or ``tmtc_client_gui.py`` utility in
|
||||||
|
the `example tmtc folder <https://egit.irs.uni-stuttgart.de/fsfw/fsfw_example_public/src/branch/master/tmtc>`_
|
||||||
|
while the `fsfw_example` application is running.
|
||||||
|
|
||||||
|
More generally, any class responsible for handling incoming telecommands and sending telemetry
|
||||||
|
can implement the generic ``TmTcBridge`` class located in ``tmtcservices``. Many applications
|
||||||
|
also use a dedicated polling task for reading telecommands which passes telecommands
|
||||||
|
to the ``TmTcBridge`` implementation.
|
||||||
|
|
||||||
|
CCSDS Frames, CCSDS Space Packets and PUS
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
If the communication is based on CCSDS Frames and Space Packets, several classes can be used to
|
||||||
|
distributed the packets to the corresponding services. Those can be found in ``tcdistribution``.
|
||||||
|
If Space Packets are used, a timestamper has to be provided by the user.
|
||||||
|
An example can be found in the ``timemanager`` folder, which uses ``CCSDSTime::CDS_short``.
|
||||||
|
|
||||||
|
Device Handlers
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
DeviceHandlers are another important component of the FSFW. The idea is, to have a software
|
||||||
|
counterpart of every physical device to provide a simple mode, health and commanding interface.
|
||||||
|
By separating the underlying Communication Interface with
|
||||||
|
``DeviceCommunicationIF``, a device handler (DH) can be tested on different hardware.
|
||||||
|
The DH has mechanisms to monitor the communication with the physical device which allow
|
||||||
|
for FDIR reaction. Device Handlers can be created by implementing ``DeviceHandlerBase``.
|
||||||
|
A standard FDIR component for the DH will be created automatically but can
|
||||||
|
be overwritten by the user. More information on DeviceHandlers can be found in the
|
||||||
|
related [documentation section](doc/README-devicehandlers.md#top).
|
||||||
|
|
||||||
|
Modes and Health
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
The two interfaces ``HasModesIF`` and ``HasHealthIF`` provide access for commanding and monitoring
|
||||||
|
of components. On-board mode management is implement in hierarchy system.
|
||||||
|
|
||||||
|
- Device handlers and controllers are the lowest part of the hierarchy.
|
||||||
|
- The next layer are assemblies. Those assemblies act as a component which handle
|
||||||
|
redundancies of handlers. Assemblies share a common core with the top level subsystem components
|
||||||
|
- The top level subsystem components are used to group assemblies, controllers and device handlers.
|
||||||
|
For example, a spacecraft can have a atttitude control subsystem and a power subsystem.
|
||||||
|
|
||||||
|
Those assemblies are intended to act as auto-generated components from a database which describes
|
||||||
|
the subsystem modes. The definitions contain transition and target tables which contain the DH,
|
||||||
|
Assembly and Controller Modes to be commanded.
|
||||||
|
Transition tables contain as many steps as needed to reach the mode from any other mode, e.g. a
|
||||||
|
switch into any higher AOCS mode might first turn on the sensors, than the actuators and the
|
||||||
|
controller as last component.
|
||||||
|
The target table is used to describe the state that is checked continuously by the subsystem.
|
||||||
|
All of this allows System Modes to be generated as Subsystem object as well from the same database.
|
||||||
|
This System contains list of subsystem modes in the transition and target tables.
|
||||||
|
Therefore, it allows a modular system to create system modes and easy commanding of those, because
|
||||||
|
only the highest components must be commanded.
|
||||||
|
|
||||||
|
The health state represents if the component is able to perform its tasks.
|
||||||
|
This can be used to signal the system to avoid using this component instead of a redundant one.
|
||||||
|
The on-board FDIR uses the health state for isolation and recovery.
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
69
docs/index.rst
Normal file
69
docs/index.rst
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
.. Flight Software Framework documentation master file, created by
|
||||||
|
sphinx-quickstart on Tue Nov 30 10:56:03 2021.
|
||||||
|
You can adapt this file completely to your liking, but it should at least
|
||||||
|
contain the root `toctree` directive.
|
||||||
|
|
||||||
|
Flight Software Framework (FSFW) documentation
|
||||||
|
================================================
|
||||||
|
|
||||||
|
.. image:: ../misc/logo/FSFW_Logo_V3_bw.png
|
||||||
|
:alt: FSFW Logo
|
||||||
|
|
||||||
|
The Flight Software Framework is a C++ Object Oriented Framework for unmanned,
|
||||||
|
automated systems like Satellites.
|
||||||
|
|
||||||
|
The initial version of the Flight Software Framework was developed during
|
||||||
|
the Flying Laptop Project by the University of Stuttgart in cooperation
|
||||||
|
with Airbus Defence and Space GmbH.
|
||||||
|
|
||||||
|
Quick facts
|
||||||
|
---------------
|
||||||
|
|
||||||
|
The framework is designed for systems, which communicate with external devices, perform control
|
||||||
|
loops, receive telecommands and send telemetry, and need to maintain a high level of availability.
|
||||||
|
Therefore, a mode and health system provides control over the states of the software and the
|
||||||
|
controlled devices. In addition, a simple mechanism of event based fault detection, isolation and
|
||||||
|
recovery is implemented as well.
|
||||||
|
|
||||||
|
The FSFW provides abstraction layers for operating systems to provide a uniform operating system
|
||||||
|
abstraction layer (OSAL). Some components of this OSAL are required internally by the FSFW but is
|
||||||
|
also very useful for developers to implement the same application logic on different operating
|
||||||
|
systems with a uniform interface.
|
||||||
|
|
||||||
|
Currently, the FSFW provides the following OSALs:
|
||||||
|
|
||||||
|
- Linux
|
||||||
|
- Host
|
||||||
|
- FreeRTOS
|
||||||
|
- RTEMS
|
||||||
|
|
||||||
|
The recommended hardware is a microprocessor with more than 1 MB of RAM and 1 MB of non-volatile
|
||||||
|
memory. For reference, current applications use a Cobham Gaisler UT699 (LEON3FT), a
|
||||||
|
ISISPACE IOBC or a Zynq-7020 SoC. The ``fsfw`` was also successfully run on the
|
||||||
|
STM32H743ZI-Nucleo board and on a Raspberry Pi and is currently running on the active
|
||||||
|
satellite mission Flying Laptop.
|
||||||
|
|
||||||
|
Index
|
||||||
|
-------
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
:caption: Contents:
|
||||||
|
|
||||||
|
getting_started
|
||||||
|
highlevel
|
||||||
|
core
|
||||||
|
config
|
||||||
|
osal
|
||||||
|
pus
|
||||||
|
devicehandlers
|
||||||
|
controllers
|
||||||
|
localpools
|
||||||
|
api
|
||||||
|
|
||||||
|
Indices and tables
|
||||||
|
==================
|
||||||
|
|
||||||
|
* :ref:`genindex`
|
||||||
|
* :ref:`modindex`
|
||||||
|
* :ref:`search`
|
181
docs/localpools.rst
Normal file
181
docs/localpools.rst
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
Local Data Pools
|
||||||
|
=========================================
|
||||||
|
|
||||||
|
The following text is targeted towards mission software developers which would like
|
||||||
|
to use the local data pools provided by the FSFW to store data like sensor values so they can be
|
||||||
|
used by other software objects like controllers as well. If a custom class should have a local
|
||||||
|
pool which can be used by other software objects as well, following steps have to be performed:
|
||||||
|
|
||||||
|
1. Create a ``LocalDataPoolManager`` member object in the custom class
|
||||||
|
2. Implement the ``HasLocalDataPoolIF`` with specifies the interface between the local pool
|
||||||
|
manager and the class owning the local pool.
|
||||||
|
|
||||||
|
The local data pool manager is also able to process housekeeping service requests in form
|
||||||
|
of messages, generate periodic housekeeping packet, generate notification and snapshots of changed
|
||||||
|
variables and datasets and process notifications and snapshots coming from other objects.
|
||||||
|
The two former tasks are related to the external interface using telemetry and telecommands (TMTC)
|
||||||
|
while the later two are related to data consumers like controllers only acting on data change
|
||||||
|
detected by the data creator instead of checking the data manually each cycle. Two important
|
||||||
|
framework classes ``DeviceHandlerBase`` and ``ExtendedControllerBase`` already perform the two steps
|
||||||
|
shown above so the steps required are altered slightly.
|
||||||
|
|
||||||
|
Storing and Accessing pool data
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
The pool manager is responsible for thread-safe access of the pool data, but the actual
|
||||||
|
access to the pool data from the point of view of a mission software developer happens via proxy
|
||||||
|
classes like pool variable classes. These classes store a copy
|
||||||
|
of the pool variable with the matching datatype and copy the actual data from the local pool
|
||||||
|
on a ``read`` call. Changed variables can then be written to the local pool with a ``commit`` call.
|
||||||
|
The ``read`` and ``commit`` calls are thread-safe and can be called concurrently from data creators
|
||||||
|
and data consumers. Generally, a user will create a dataset class which in turn groups all
|
||||||
|
cohesive pool variables. These sets simply iterator over the list of variables and call the
|
||||||
|
``read`` and ``commit`` functions of each variable. The following diagram shows the
|
||||||
|
high-level architecture of the local data pools.
|
||||||
|
|
||||||
|
.. image:: ../docs/images/PoolArchitecture.png
|
||||||
|
:alt: Pool Architecture
|
||||||
|
|
||||||
|
An example is shown for using the local data pools with a Gyroscope.
|
||||||
|
For example, the following code shows an implementation to access data from a Gyroscope taken
|
||||||
|
from the SOURCE CubeSat project:
|
||||||
|
|
||||||
|
.. code-block:: cpp
|
||||||
|
|
||||||
|
class GyroPrimaryDataset: public StaticLocalDataSet<3 * sizeof(float)> {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor for data users
|
||||||
|
* @param gyroId
|
||||||
|
*/
|
||||||
|
GyroPrimaryDataset(object_id_t gyroId):
|
||||||
|
StaticLocalDataSet(sid_t(gyroId, gyrodefs::GYRO_DATA_SET_ID)) {
|
||||||
|
setAllVariablesReadOnly();
|
||||||
|
}
|
||||||
|
|
||||||
|
lp_var_t<float> angVelocityX = lp_var_t<float>(sid.objectId,
|
||||||
|
gyrodefs::ANGULAR_VELOCITY_X, this);
|
||||||
|
lp_var_t<float> angVelocityY = lp_var_t<float>(sid.objectId,
|
||||||
|
gyrodefs::ANGULAR_VELOCITY_Y, this);
|
||||||
|
lp_var_t<float> angVelocityZ = lp_var_t<float>(sid.objectId,
|
||||||
|
gyrodefs::ANGULAR_VELOCITY_Z, this);
|
||||||
|
private:
|
||||||
|
|
||||||
|
friend class GyroHandler;
|
||||||
|
/**
|
||||||
|
* Constructor for data creator
|
||||||
|
* @param hkOwner
|
||||||
|
*/
|
||||||
|
GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
||||||
|
StaticLocalDataSet(hkOwner, gyrodefs::GYRO_DATA_SET_ID) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
There is a public constructor for users which sets all variables to read-only and there is a
|
||||||
|
constructor for the GyroHandler data creator by marking it private and declaring the ``GyroHandler``
|
||||||
|
as a friend class. Both the atittude controller and the ``GyroHandler`` can now
|
||||||
|
use the same class definition to access the pool variables with ``read`` and ``commit`` semantics
|
||||||
|
in a thread-safe way. Generally, each class requiring access will have the set class as a member
|
||||||
|
class. The data creator will also be generally a ``DeviceHandlerBase`` subclass and some additional
|
||||||
|
steps are necessary to expose the set for housekeeping purposes.
|
||||||
|
|
||||||
|
Using the local data pools in a ``DeviceHandlerBase`` subclass
|
||||||
|
--------------------------------------------------------------
|
||||||
|
|
||||||
|
It is very common to store data generated by devices like a sensor into a pool which can
|
||||||
|
then be used by other objects. Therefore, the ``DeviceHandlerBase`` already has a
|
||||||
|
local pool. Using the aforementioned example, the ``GyroHandler`` will now have the set class
|
||||||
|
as a member:
|
||||||
|
|
||||||
|
.. code-block:: cpp
|
||||||
|
|
||||||
|
class GyroHandler: ... {
|
||||||
|
|
||||||
|
public:
|
||||||
|
...
|
||||||
|
private:
|
||||||
|
...
|
||||||
|
GyroPrimaryDataset gyroData;
|
||||||
|
...
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
The constructor used for the creators expects the owner class as a parameter, so we initialize
|
||||||
|
the object in the `GyroHandler` constructor like this:
|
||||||
|
|
||||||
|
.. code-block:: cpp
|
||||||
|
|
||||||
|
GyroHandler::GyroHandler(object_id_t objectId, object_id_t comIF,
|
||||||
|
CookieIF *comCookie, uint8_t switchId):
|
||||||
|
DeviceHandlerBase(objectId, comIF, comCookie), switchId(switchId),
|
||||||
|
gyroData(this) {}
|
||||||
|
|
||||||
|
|
||||||
|
We need to assign the set to a reply ID used in the ``DeviceHandlerBase``.
|
||||||
|
The combination of the ``GyroHandler`` object ID and the reply ID will be the 64-bit structure ID
|
||||||
|
``sid_t`` and is used to globally identify the set, for example when requesting housekeeping data or
|
||||||
|
generating update messages. We need to assign our custom set class in some way so that the local
|
||||||
|
pool manager can access the custom data sets as well.
|
||||||
|
By default, the ``getDataSetHandle`` will take care of this tasks. The default implementation for a
|
||||||
|
``DeviceHandlerBase`` subclass will use the internal command map to retrieve
|
||||||
|
a handle to a dataset from a given reply ID. Therefore,
|
||||||
|
we assign the set in the ``fillCommandAndReplyMap`` function:
|
||||||
|
|
||||||
|
.. code-block:: cpp
|
||||||
|
|
||||||
|
void GyroHandler::fillCommandAndReplyMap() {
|
||||||
|
...
|
||||||
|
this->insertInCommandAndReplyMap(gyrodefs::GYRO_DATA, 3, &gyroData);
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Now, we need to create the actual pool entries as well, using the ``initializeLocalDataPool``
|
||||||
|
function. Here, we also immediately subscribe for periodic housekeeping packets
|
||||||
|
with an interval of 4 seconds. They are still disabled in this example and can be enabled
|
||||||
|
with a housekeeping service command.
|
||||||
|
|
||||||
|
.. code-block:: cpp
|
||||||
|
|
||||||
|
ReturnValue_t GyroHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||||
|
LocalDataPoolManager &poolManager) {
|
||||||
|
localDataPoolMap.emplace(gyrodefs::ANGULAR_VELOCITY_X,
|
||||||
|
new PoolEntry<float>({0.0}));
|
||||||
|
localDataPoolMap.emplace(gyrodefs::ANGULAR_VELOCITY_Y,
|
||||||
|
new PoolEntry<float>({0.0}));
|
||||||
|
localDataPoolMap.emplace(gyrodefs::ANGULAR_VELOCITY_Z,
|
||||||
|
new PoolEntry<float>({0.0}));
|
||||||
|
localDataPoolMap.emplace(gyrodefs::GENERAL_CONFIG_REG42,
|
||||||
|
new PoolEntry<uint8_t>({0}));
|
||||||
|
localDataPoolMap.emplace(gyrodefs::RANGE_CONFIG_REG43,
|
||||||
|
new PoolEntry<uint8_t>({0}));
|
||||||
|
|
||||||
|
poolManager.subscribeForPeriodicPacket(gyroData.getSid(), false, 4.0, false);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
Now, if we receive some sensor data and converted them into the right format,
|
||||||
|
we can write it into the pool like this, using a guard class to ensure the set is commited back
|
||||||
|
in any case:
|
||||||
|
|
||||||
|
.. code-block:: cpp
|
||||||
|
|
||||||
|
PoolReadGuard readHelper(&gyroData);
|
||||||
|
if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
if(not gyroData.isValid()) {
|
||||||
|
gyroData.setValidity(true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
gyroData.angVelocityX = angularVelocityX;
|
||||||
|
gyroData.angVelocityY = angularVelocityY;
|
||||||
|
gyroData.angVelocityZ = angularVelocityZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
The guard class will commit the changed data on destruction automatically.
|
||||||
|
|
||||||
|
Using the local data pools in a ``ExtendedControllerBase`` subclass
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Coming soon
|
||||||
|
|
||||||
|
|
35
docs/make.bat
Normal file
35
docs/make.bat
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
@ECHO OFF
|
||||||
|
|
||||||
|
pushd %~dp0
|
||||||
|
|
||||||
|
REM Command file for Sphinx documentation
|
||||||
|
|
||||||
|
if "%SPHINXBUILD%" == "" (
|
||||||
|
set SPHINXBUILD=sphinx-build
|
||||||
|
)
|
||||||
|
set SOURCEDIR=.
|
||||||
|
set BUILDDIR=_build
|
||||||
|
|
||||||
|
if "%1" == "" goto help
|
||||||
|
|
||||||
|
%SPHINXBUILD% >NUL 2>NUL
|
||||||
|
if errorlevel 9009 (
|
||||||
|
echo.
|
||||||
|
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||||
|
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||||
|
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||||
|
echo.may add the Sphinx directory to PATH.
|
||||||
|
echo.
|
||||||
|
echo.If you don't have Sphinx installed, grab it from
|
||||||
|
echo.http://sphinx-doc.org/
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||||
|
goto end
|
||||||
|
|
||||||
|
:help
|
||||||
|
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||||
|
|
||||||
|
:end
|
||||||
|
popd
|
63
docs/osal.rst
Normal file
63
docs/osal.rst
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
.. _osal:
|
||||||
|
|
||||||
|
Operating System Abstraction Layer (OSAL)
|
||||||
|
============================================
|
||||||
|
|
||||||
|
Some specific information on the provided OSALs are provided.
|
||||||
|
|
||||||
|
Linux
|
||||||
|
-------
|
||||||
|
|
||||||
|
This OSAL can be used to compile for Linux host systems like Ubuntu 20.04 or for
|
||||||
|
embedded Linux targets like the Raspberry Pi. This OSAL generally requires threading support
|
||||||
|
and real-time functionalities. For most UNIX systems, this is done by adding ``-lrt`` and
|
||||||
|
``-lpthread`` to the linked libraries in the compilation process. The CMake build support provided
|
||||||
|
will do this automatically for the ``fsfw`` target. It should be noted that most UNIX systems need
|
||||||
|
to be configured specifically to allow the real-time functionalities required by the FSFW.
|
||||||
|
|
||||||
|
Hosted OSAL
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
This is the newest OSAL. Support for Semaphores has not been implemented yet and will propably be
|
||||||
|
implemented as soon as C++20 with Semaphore support has matured. This OSAL can be used to run the
|
||||||
|
FSFW on any host system, but currently has only been tested on Windows 10 and Ubuntu 20.04. Unlike
|
||||||
|
the other OSALs, it uses dynamic memory allocation (e.g. for the message queue implementation).
|
||||||
|
Cross-platform serial port (USB) support might be added soon.
|
||||||
|
|
||||||
|
FreeRTOS OSAL
|
||||||
|
------------------
|
||||||
|
|
||||||
|
FreeRTOS is not included and the developer needs to take care of compiling the FreeRTOS sources and
|
||||||
|
adding the ``FreeRTOSConfig.h`` file location to the include path. This OSAL has only been tested
|
||||||
|
extensively with the pre-emptive scheduler configuration so far but it should in principle also be
|
||||||
|
possible to use a cooperative scheduler. It is recommended to use the `heap_4` allocation scheme.
|
||||||
|
When using newlib (nano), it is also recommended to add ``#define configUSE_NEWLIB_REENTRANT`` to
|
||||||
|
the FreeRTOS configuration file to ensure thread-safety.
|
||||||
|
|
||||||
|
When using this OSAL, developers also need to provide an implementation for the
|
||||||
|
``vRequestContextSwitchFromISR`` function. This has been done because the call to request a context
|
||||||
|
switch from an ISR is generally located in the ``portmacro.h`` header and is different depending on
|
||||||
|
the target architecture or device.
|
||||||
|
|
||||||
|
RTEMS OSAL
|
||||||
|
---------------
|
||||||
|
|
||||||
|
The RTEMS OSAL was the first implemented OSAL which is also used on the active satellite Flying Laptop.
|
||||||
|
|
||||||
|
TCP/IP socket abstraction
|
||||||
|
------------------------------
|
||||||
|
|
||||||
|
The Linux and Host OSAL provide abstraction layers for the socket API. Currently, only UDP sockets
|
||||||
|
have been imlemented. This is very useful to test TMTC handling either on the host computer
|
||||||
|
directly (targeting localhost with a TMTC application) or on embedded Linux devices, sending
|
||||||
|
TMTC packets via Ethernet.
|
||||||
|
|
||||||
|
Example Applications
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
There are example applications available for each OSAL
|
||||||
|
|
||||||
|
- `Hosted OSAL <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted>`_
|
||||||
|
- `Linux OSAL for MCUs <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-linux-mcu>`_
|
||||||
|
- `FreeRTOS OSAL on the STM32H743ZIT <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-stm32h7-freertos>`_
|
||||||
|
- `RTEMS OSAL on the STM32H743ZIT <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-stm32h7-rtems>`_
|
2
docs/pus.rst
Normal file
2
docs/pus.rst
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
PUS Services
|
||||||
|
==============
|
@ -3,7 +3,13 @@ cmake_minimum_required(VERSION 3.13)
|
|||||||
# Can also be changed by upper CMakeLists.txt file
|
# Can also be changed by upper CMakeLists.txt file
|
||||||
find_library(LIB_FSFW_NAME fsfw REQUIRED)
|
find_library(LIB_FSFW_NAME fsfw REQUIRED)
|
||||||
|
|
||||||
option(FSFW_HAL_ADD_LINUX "Add the Linux HAL to the sources. Required gpiod library" OFF)
|
option(FSFW_HAL_ADD_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_ADD_RASPBERRY_PI "Add Raspberry Pi specific code to the sources" OFF)
|
option(FSFW_HAL_ADD_RASPBERRY_PI "Add Raspberry Pi specific code to the sources" OFF)
|
||||||
option(FSFW_HAL_ADD_STM32H7 "Add the STM32H7 HAL to the sources" OFF)
|
option(FSFW_HAL_ADD_STM32H7 "Add the STM32H7 HAL to the sources" OFF)
|
||||||
option(FSFW_HAL_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON)
|
option(FSFW_HAL_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
add_subdirectory(devicehandlers)
|
add_subdirectory(devicehandlers)
|
||||||
add_subdirectory(common)
|
add_subdirectory(common)
|
||||||
|
|
||||||
if(FSFW_HAL_ADD_LINUX)
|
if(UNIX)
|
||||||
add_subdirectory(linux)
|
add_subdirectory(linux)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||||
|
|
||||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
GpioCookie::GpioCookie() {
|
GpioCookie::GpioCookie() {}
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
|
ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
|
||||||
if (gpioConfig == nullptr) {
|
if (gpioConfig == nullptr) {
|
||||||
@ -14,13 +14,13 @@ ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
|
|||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
auto gpioMapIter = gpioMap.find(gpioId);
|
auto gpioMapIter = gpioMap.find(gpioId);
|
||||||
if(gpioMapIter == gpioMap.end()) {
|
if (gpioMapIter == gpioMap.end()) {
|
||||||
auto statusPair = gpioMap.emplace(gpioId, gpioConfig);
|
auto statusPair = gpioMap.emplace(gpioId, gpioConfig);
|
||||||
if (statusPair.second == false) {
|
if (statusPair.second == false) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "GpioCookie::addGpio: Failed to add GPIO " << gpioId <<
|
sif::warning << "GpioCookie::addGpio: Failed to add GPIO " << gpioId << " to GPIO map"
|
||||||
" to GPIO map" << std::endl;
|
<< std::endl;
|
||||||
#else
|
#else
|
||||||
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
|
||||||
@ -39,12 +39,10 @@ ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
|
|||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
GpioMap GpioCookie::getGpioMap() const {
|
GpioMap GpioCookie::getGpioMap() const { return gpioMap; }
|
||||||
return gpioMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
GpioCookie::~GpioCookie() {
|
GpioCookie::~GpioCookie() {
|
||||||
for(auto& config: gpioMap) {
|
for (auto& config : gpioMap) {
|
||||||
delete(config.second);
|
delete (config.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef COMMON_GPIO_GPIOCOOKIE_H_
|
#ifndef COMMON_GPIO_GPIOCOOKIE_H_
|
||||||
#define COMMON_GPIO_GPIOCOOKIE_H_
|
#define COMMON_GPIO_GPIOCOOKIE_H_
|
||||||
|
|
||||||
#include "GpioIF.h"
|
|
||||||
#include "gpioDefinitions.h"
|
|
||||||
|
|
||||||
#include <fsfw/devicehandlers/CookieIF.h>
|
#include <fsfw/devicehandlers/CookieIF.h>
|
||||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
|
||||||
|
#include "GpioIF.h"
|
||||||
|
#include "gpioDefinitions.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Cookie for the GpioIF. Allows the GpioIF to determine which
|
* @brief Cookie for the GpioIF. Allows the GpioIF to determine which
|
||||||
* GPIOs to initialize and whether they should be configured as in- or
|
* GPIOs to initialize and whether they should be configured as in- or
|
||||||
@ -17,9 +17,8 @@
|
|||||||
*
|
*
|
||||||
* @author J. Meier
|
* @author J. Meier
|
||||||
*/
|
*/
|
||||||
class GpioCookie: public CookieIF {
|
class GpioCookie : public CookieIF {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GpioCookie();
|
GpioCookie();
|
||||||
|
|
||||||
virtual ~GpioCookie();
|
virtual ~GpioCookie();
|
||||||
@ -31,7 +30,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
GpioMap getGpioMap() const;
|
GpioMap getGpioMap() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Returns a copy of the internal GPIO map.
|
* Returns a copy of the internal GPIO map.
|
||||||
*/
|
*/
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#ifndef COMMON_GPIO_GPIOIF_H_
|
#ifndef COMMON_GPIO_GPIOIF_H_
|
||||||
#define COMMON_GPIO_GPIOIF_H_
|
#define COMMON_GPIO_GPIOIF_H_
|
||||||
|
|
||||||
#include "gpioDefinitions.h"
|
|
||||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
|
||||||
#include <fsfw/devicehandlers/CookieIF.h>
|
#include <fsfw/devicehandlers/CookieIF.h>
|
||||||
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
|
||||||
|
#include "gpioDefinitions.h"
|
||||||
|
|
||||||
class GpioCookie;
|
class GpioCookie;
|
||||||
|
|
||||||
@ -13,9 +14,8 @@ class GpioCookie;
|
|||||||
* @author J. Meier
|
* @author J. Meier
|
||||||
*/
|
*/
|
||||||
class GpioIF : public HasReturnvaluesIF {
|
class GpioIF : public HasReturnvaluesIF {
|
||||||
public:
|
public:
|
||||||
|
virtual ~GpioIF(){};
|
||||||
virtual ~GpioIF() {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called by the GPIO using object.
|
* @brief Called by the GPIO using object.
|
||||||
|
@ -1,29 +1,19 @@
|
|||||||
#ifndef COMMON_GPIO_GPIODEFINITIONS_H_
|
#ifndef COMMON_GPIO_GPIODEFINITIONS_H_
|
||||||
#define COMMON_GPIO_GPIODEFINITIONS_H_
|
#define COMMON_GPIO_GPIODEFINITIONS_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <map>
|
|
||||||
|
|
||||||
using gpioId_t = uint16_t;
|
using gpioId_t = uint16_t;
|
||||||
|
|
||||||
namespace gpio {
|
namespace gpio {
|
||||||
|
|
||||||
enum Levels: uint8_t {
|
enum Levels : uint8_t { LOW = 0, HIGH = 1, NONE = 99 };
|
||||||
LOW = 0,
|
|
||||||
HIGH = 1,
|
|
||||||
NONE = 99
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Direction: uint8_t {
|
enum Direction : uint8_t { IN = 0, OUT = 1 };
|
||||||
IN = 0,
|
|
||||||
OUT = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
enum GpioOperation {
|
enum GpioOperation { READ, WRITE };
|
||||||
READ,
|
|
||||||
WRITE
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class GpioTypes {
|
enum class GpioTypes {
|
||||||
NONE,
|
NONE,
|
||||||
@ -35,10 +25,10 @@ enum class GpioTypes {
|
|||||||
|
|
||||||
static constexpr gpioId_t NO_GPIO = -1;
|
static constexpr gpioId_t NO_GPIO = -1;
|
||||||
|
|
||||||
using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Levels value,
|
using gpio_cb_t = void (*)(gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Levels value,
|
||||||
void* args);
|
void* args);
|
||||||
|
|
||||||
}
|
} // namespace gpio
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Struct containing information about the GPIO to use. This is
|
* @brief Struct containing information about the GPIO to use. This is
|
||||||
@ -55,15 +45,14 @@ using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::L
|
|||||||
* pointer.
|
* pointer.
|
||||||
*/
|
*/
|
||||||
class GpioBase {
|
class GpioBase {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GpioBase() = default;
|
GpioBase() = default;
|
||||||
|
|
||||||
GpioBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
GpioBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||||
gpio::Levels initValue):
|
gpio::Levels initValue)
|
||||||
gpioType(gpioType), consumer(consumer),direction(direction), initValue(initValue) {}
|
: gpioType(gpioType), consumer(consumer), direction(direction), initValue(initValue) {}
|
||||||
|
|
||||||
virtual~ GpioBase() {};
|
virtual ~GpioBase(){};
|
||||||
|
|
||||||
// Can be used to cast GpioBase to a concrete child implementation
|
// Can be used to cast GpioBase to a concrete child implementation
|
||||||
gpio::GpioTypes gpioType = gpio::GpioTypes::NONE;
|
gpio::GpioTypes gpioType = gpio::GpioTypes::NONE;
|
||||||
@ -72,59 +61,53 @@ public:
|
|||||||
gpio::Levels initValue = gpio::Levels::NONE;
|
gpio::Levels initValue = gpio::Levels::NONE;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GpiodRegularBase: public GpioBase {
|
class GpiodRegularBase : public GpioBase {
|
||||||
public:
|
public:
|
||||||
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||||
gpio::Levels initValue, int lineNum):
|
gpio::Levels initValue, int lineNum)
|
||||||
GpioBase(gpioType, consumer, direction, initValue), lineNum(lineNum) {
|
: GpioBase(gpioType, consumer, direction, initValue), lineNum(lineNum) {}
|
||||||
}
|
|
||||||
|
|
||||||
// line number will be configured at a later point for the open by line name configuration
|
// line number will be configured at a later point for the open by line name configuration
|
||||||
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||||
gpio::Levels initValue): GpioBase(gpioType, consumer, direction, initValue) {
|
gpio::Levels initValue)
|
||||||
}
|
: GpioBase(gpioType, consumer, direction, initValue) {}
|
||||||
|
|
||||||
int lineNum = 0;
|
int lineNum = 0;
|
||||||
struct gpiod_line* lineHandle = nullptr;
|
struct gpiod_line* lineHandle = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GpiodRegularByChip: public GpiodRegularBase {
|
class GpiodRegularByChip : public GpiodRegularBase {
|
||||||
public:
|
public:
|
||||||
GpiodRegularByChip() :
|
GpiodRegularByChip()
|
||||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP,
|
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, std::string(), gpio::Direction::IN,
|
||||||
std::string(), gpio::Direction::IN, gpio::LOW, 0) {
|
gpio::LOW, 0) {}
|
||||||
}
|
|
||||||
|
|
||||||
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_,
|
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_,
|
||||||
gpio::Direction direction_, gpio::Levels initValue_) :
|
gpio::Direction direction_, gpio::Levels initValue_)
|
||||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP,
|
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_, direction_, initValue_,
|
||||||
consumer_, direction_, initValue_, lineNum_),
|
lineNum_),
|
||||||
chipname(chipname_){
|
chipname(chipname_) {}
|
||||||
}
|
|
||||||
|
|
||||||
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_) :
|
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_)
|
||||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_,
|
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_, gpio::Direction::IN,
|
||||||
gpio::Direction::IN, gpio::LOW, lineNum_),
|
gpio::LOW, lineNum_),
|
||||||
chipname(chipname_) {
|
chipname(chipname_) {}
|
||||||
}
|
|
||||||
|
|
||||||
std::string chipname;
|
std::string chipname;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GpiodRegularByLabel: public GpiodRegularBase {
|
class GpiodRegularByLabel : public GpiodRegularBase {
|
||||||
public:
|
public:
|
||||||
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_,
|
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_,
|
||||||
gpio::Direction direction_, gpio::Levels initValue_) :
|
gpio::Direction direction_, gpio::Levels initValue_)
|
||||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_,
|
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_, direction_, initValue_,
|
||||||
direction_, initValue_, lineNum_),
|
lineNum_),
|
||||||
label(label_) {
|
label(label_) {}
|
||||||
}
|
|
||||||
|
|
||||||
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_) :
|
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_)
|
||||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_,
|
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_, gpio::Direction::IN,
|
||||||
gpio::Direction::IN, gpio::LOW, lineNum_),
|
gpio::LOW, lineNum_),
|
||||||
label(label_) {
|
label(label_) {}
|
||||||
}
|
|
||||||
|
|
||||||
std::string label;
|
std::string label;
|
||||||
};
|
};
|
||||||
@ -134,34 +117,34 @@ public:
|
|||||||
* line name. This line name can be set in the device tree and must be unique. Otherwise
|
* line name. This line name can be set in the device tree and must be unique. Otherwise
|
||||||
* the driver will open the first line with the given name.
|
* the driver will open the first line with the given name.
|
||||||
*/
|
*/
|
||||||
class GpiodRegularByLineName: public GpiodRegularBase {
|
class GpiodRegularByLineName : public GpiodRegularBase {
|
||||||
public:
|
public:
|
||||||
GpiodRegularByLineName(std::string lineName_, std::string consumer_, gpio::Direction direction_,
|
GpiodRegularByLineName(std::string lineName_, std::string consumer_, gpio::Direction direction_,
|
||||||
gpio::Levels initValue_) :
|
gpio::Levels initValue_)
|
||||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, direction_,
|
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, direction_,
|
||||||
initValue_), lineName(lineName_) {
|
initValue_),
|
||||||
}
|
lineName(lineName_) {}
|
||||||
|
|
||||||
GpiodRegularByLineName(std::string lineName_, std::string consumer_) :
|
GpiodRegularByLineName(std::string lineName_, std::string consumer_)
|
||||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_,
|
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, gpio::Direction::IN,
|
||||||
gpio::Direction::IN, gpio::LOW), lineName(lineName_) {
|
gpio::LOW),
|
||||||
}
|
lineName(lineName_) {}
|
||||||
|
|
||||||
std::string lineName;
|
std::string lineName;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GpioCallback: public GpioBase {
|
class GpioCallback : public GpioBase {
|
||||||
public:
|
public:
|
||||||
GpioCallback(std::string consumer, gpio::Direction direction_, gpio::Levels initValue_,
|
GpioCallback(std::string consumer, gpio::Direction direction_, gpio::Levels initValue_,
|
||||||
gpio::gpio_cb_t callback, void* callbackArgs):
|
gpio::gpio_cb_t callback, void* callbackArgs)
|
||||||
GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
|
: GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
|
||||||
callback(callback), callbackArgs(callbackArgs) {}
|
callback(callback),
|
||||||
|
callbackArgs(callbackArgs) {}
|
||||||
|
|
||||||
gpio::gpio_cb_t callback = nullptr;
|
gpio::gpio_cb_t callback = nullptr;
|
||||||
void* callbackArgs = nullptr;
|
void* callbackArgs = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using GpioMap = std::map<gpioId_t, GpioBase*>;
|
using GpioMap = std::map<gpioId_t, GpioBase*>;
|
||||||
using GpioUnorderedMap = std::unordered_map<gpioId_t, GpioBase*>;
|
using GpioUnorderedMap = std::unordered_map<gpioId_t, GpioBase*>;
|
||||||
using GpioMapIter = GpioMap::iterator;
|
using GpioMapIter = GpioMap::iterator;
|
||||||
|
@ -5,12 +5,7 @@
|
|||||||
|
|
||||||
namespace spi {
|
namespace spi {
|
||||||
|
|
||||||
enum SpiModes: uint8_t {
|
enum SpiModes : uint8_t { MODE_0, MODE_1, MODE_2, MODE_3 };
|
||||||
MODE_0,
|
|
||||||
MODE_1,
|
|
||||||
MODE_2,
|
|
||||||
MODE_3
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
#include "GyroL3GD20Handler.h"
|
#include "GyroL3GD20Handler.h"
|
||||||
|
|
||||||
#include "fsfw/datapool/PoolReadGuard.h"
|
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#include "fsfw/datapool/PoolReadGuard.h"
|
||||||
|
|
||||||
GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
|
GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
|
||||||
CookieIF *comCookie, uint32_t transitionDelayMs):
|
CookieIF *comCookie, uint32_t transitionDelayMs)
|
||||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||||
transitionDelayMs(transitionDelayMs), dataset(this) {
|
transitionDelayMs(transitionDelayMs),
|
||||||
|
dataset(this) {
|
||||||
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
|
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
|
||||||
debugDivider = new PeriodicOperationDivider(3);
|
debugDivider = new PeriodicOperationDivider(3);
|
||||||
#endif
|
#endif
|
||||||
@ -16,24 +17,23 @@ GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceC
|
|||||||
GyroHandlerL3GD20H::~GyroHandlerL3GD20H() {}
|
GyroHandlerL3GD20H::~GyroHandlerL3GD20H() {}
|
||||||
|
|
||||||
void GyroHandlerL3GD20H::doStartUp() {
|
void GyroHandlerL3GD20H::doStartUp() {
|
||||||
if(internalState == InternalState::NONE) {
|
if (internalState == InternalState::NONE) {
|
||||||
internalState = InternalState::CONFIGURE;
|
internalState = InternalState::CONFIGURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(internalState == InternalState::CONFIGURE) {
|
if (internalState == InternalState::CONFIGURE) {
|
||||||
if(commandExecuted) {
|
if (commandExecuted) {
|
||||||
internalState = InternalState::CHECK_REGS;
|
internalState = InternalState::CHECK_REGS;
|
||||||
commandExecuted = false;
|
commandExecuted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(internalState == InternalState::CHECK_REGS) {
|
if (internalState == InternalState::CHECK_REGS) {
|
||||||
if(commandExecuted) {
|
if (commandExecuted) {
|
||||||
internalState = InternalState::NORMAL;
|
internalState = InternalState::NORMAL;
|
||||||
if(goNormalModeImmediately) {
|
if (goNormalModeImmediately) {
|
||||||
setMode(MODE_NORMAL);
|
setMode(MODE_NORMAL);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setMode(_MODE_TO_ON);
|
setMode(_MODE_TO_ON);
|
||||||
}
|
}
|
||||||
commandExecuted = false;
|
commandExecuted = false;
|
||||||
@ -41,19 +41,17 @@ void GyroHandlerL3GD20H::doStartUp() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GyroHandlerL3GD20H::doShutDown() {
|
void GyroHandlerL3GD20H::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||||
setMode(_MODE_POWER_DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||||
switch(internalState) {
|
switch (internalState) {
|
||||||
case(InternalState::NONE):
|
case (InternalState::NONE):
|
||||||
case(InternalState::NORMAL): {
|
case (InternalState::NORMAL): {
|
||||||
return NOTHING_TO_SEND;
|
return NOTHING_TO_SEND;
|
||||||
}
|
}
|
||||||
case(InternalState::CONFIGURE): {
|
case (InternalState::CONFIGURE): {
|
||||||
*id = L3GD20H::CONFIGURE_CTRL_REGS;
|
*id = L3GD20H::CONFIGURE_CTRL_REGS;
|
||||||
uint8_t command [5];
|
uint8_t command[5];
|
||||||
command[0] = L3GD20H::CTRL_REG_1_VAL;
|
command[0] = L3GD20H::CTRL_REG_1_VAL;
|
||||||
command[1] = L3GD20H::CTRL_REG_2_VAL;
|
command[1] = L3GD20H::CTRL_REG_2_VAL;
|
||||||
command[2] = L3GD20H::CTRL_REG_3_VAL;
|
command[2] = L3GD20H::CTRL_REG_3_VAL;
|
||||||
@ -61,7 +59,7 @@ ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t
|
|||||||
command[4] = L3GD20H::CTRL_REG_5_VAL;
|
command[4] = L3GD20H::CTRL_REG_5_VAL;
|
||||||
return buildCommandFromCommand(*id, command, 5);
|
return buildCommandFromCommand(*id, command, 5);
|
||||||
}
|
}
|
||||||
case(InternalState::CHECK_REGS): {
|
case (InternalState::CHECK_REGS): {
|
||||||
*id = L3GD20H::READ_REGS;
|
*id = L3GD20H::READ_REGS;
|
||||||
return buildCommandFromCommand(*id, nullptr, 0);
|
return buildCommandFromCommand(*id, nullptr, 0);
|
||||||
}
|
}
|
||||||
@ -69,9 +67,11 @@ ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t
|
|||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
/* Might be a configuration error. */
|
/* Might be a configuration error. */
|
||||||
sif::warning << "GyroL3GD20Handler::buildTransitionDeviceCommand: "
|
sif::warning << "GyroL3GD20Handler::buildTransitionDeviceCommand: "
|
||||||
"Unknown internal state!" << std::endl;
|
"Unknown internal state!"
|
||||||
|
<< std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printDebug("GyroL3GD20Handler::buildTransitionDeviceCommand: "
|
sif::printDebug(
|
||||||
|
"GyroL3GD20Handler::buildTransitionDeviceCommand: "
|
||||||
"Unknown internal state!\n");
|
"Unknown internal state!\n");
|
||||||
#endif
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
@ -84,20 +84,20 @@ ReturnValue_t GyroHandlerL3GD20H::buildNormalDeviceCommand(DeviceCommandId_t *id
|
|||||||
return buildCommandFromCommand(*id, nullptr, 0);
|
return buildCommandFromCommand(*id, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(
|
ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
const uint8_t *commandData,
|
||||||
size_t commandDataLen) {
|
size_t commandDataLen) {
|
||||||
switch(deviceCommand) {
|
switch (deviceCommand) {
|
||||||
case(L3GD20H::READ_REGS): {
|
case (L3GD20H::READ_REGS): {
|
||||||
commandBuffer[0] = L3GD20H::READ_START | L3GD20H::AUTO_INCREMENT_MASK | L3GD20H::READ_MASK;
|
commandBuffer[0] = L3GD20H::READ_START | L3GD20H::AUTO_INCREMENT_MASK | L3GD20H::READ_MASK;
|
||||||
std::memset(commandBuffer + 1, 0, L3GD20H::READ_LEN);
|
std::memset(commandBuffer + 1, 0, L3GD20H::READ_LEN);
|
||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
rawPacketLen = L3GD20H::READ_LEN + 1;
|
rawPacketLen = L3GD20H::READ_LEN + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(L3GD20H::CONFIGURE_CTRL_REGS): {
|
case (L3GD20H::CONFIGURE_CTRL_REGS): {
|
||||||
commandBuffer[0] = L3GD20H::CTRL_REG_1 | L3GD20H::AUTO_INCREMENT_MASK;
|
commandBuffer[0] = L3GD20H::CTRL_REG_1 | L3GD20H::AUTO_INCREMENT_MASK;
|
||||||
if(commandData == nullptr or commandDataLen != 5) {
|
if (commandData == nullptr or commandDataLen != 5) {
|
||||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,13 +110,11 @@ ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(
|
|||||||
bool fsH = ctrlReg4Value & L3GD20H::SET_FS_1;
|
bool fsH = ctrlReg4Value & L3GD20H::SET_FS_1;
|
||||||
bool fsL = ctrlReg4Value & L3GD20H::SET_FS_0;
|
bool fsL = ctrlReg4Value & L3GD20H::SET_FS_0;
|
||||||
|
|
||||||
if(not fsH and not fsL) {
|
if (not fsH and not fsL) {
|
||||||
sensitivity = L3GD20H::SENSITIVITY_00;
|
sensitivity = L3GD20H::SENSITIVITY_00;
|
||||||
}
|
} else if (not fsH and fsL) {
|
||||||
else if(not fsH and fsL) {
|
|
||||||
sensitivity = L3GD20H::SENSITIVITY_01;
|
sensitivity = L3GD20H::SENSITIVITY_01;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
sensitivity = L3GD20H::SENSITIVITY_11;
|
sensitivity = L3GD20H::SENSITIVITY_11;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,9 +128,8 @@ ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(
|
|||||||
rawPacketLen = 6;
|
rawPacketLen = 6;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(L3GD20H::READ_CTRL_REGS): {
|
case (L3GD20H::READ_CTRL_REGS): {
|
||||||
commandBuffer[0] = L3GD20H::READ_START | L3GD20H::AUTO_INCREMENT_MASK |
|
commandBuffer[0] = L3GD20H::READ_START | L3GD20H::AUTO_INCREMENT_MASK | L3GD20H::READ_MASK;
|
||||||
L3GD20H::READ_MASK;
|
|
||||||
|
|
||||||
std::memset(commandBuffer + 1, 0, 5);
|
std::memset(commandBuffer + 1, 0, 5);
|
||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
@ -157,32 +154,30 @@ ReturnValue_t GyroHandlerL3GD20H::scanForReply(const uint8_t *start, size_t len,
|
|||||||
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 = HasReturnvaluesIF::RETURN_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;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(L3GD20H::READ_CTRL_REGS): {
|
case (L3GD20H::READ_CTRL_REGS): {
|
||||||
if(packet[1] == ctrlReg1Value and packet[2] == ctrlReg2Value and
|
if (packet[1] == ctrlReg1Value and packet[2] == ctrlReg2Value and
|
||||||
packet[3] == ctrlReg3Value and packet[4] == ctrlReg4Value and
|
packet[3] == ctrlReg3Value and packet[4] == ctrlReg4Value and
|
||||||
packet[5] == ctrlReg5Value) {
|
packet[5] == ctrlReg5Value) {
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Attempt reconfiguration
|
// Attempt reconfiguration
|
||||||
internalState = InternalState::CONFIGURE;
|
internalState = InternalState::CONFIGURE;
|
||||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(L3GD20H::READ_REGS): {
|
case (L3GD20H::READ_REGS): {
|
||||||
if(packet[1] != ctrlReg1Value and packet[2] != ctrlReg2Value and
|
if (packet[1] != ctrlReg1Value and packet[2] != ctrlReg2Value and
|
||||||
packet[3] != ctrlReg3Value and packet[4] != ctrlReg4Value and
|
packet[3] != ctrlReg3Value and packet[4] != ctrlReg4Value and
|
||||||
packet[5] != ctrlReg5Value) {
|
packet[5] != ctrlReg5Value) {
|
||||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||||
}
|
} else {
|
||||||
else {
|
if (internalState == InternalState::CHECK_REGS) {
|
||||||
if(internalState == InternalState::CHECK_REGS) {
|
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,7 +194,7 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
int8_t temperaturOffset = (-1) * packet[L3GD20H::TEMPERATURE_IDX];
|
int8_t temperaturOffset = (-1) * packet[L3GD20H::TEMPERATURE_IDX];
|
||||||
float temperature = 25.0 + temperaturOffset;
|
float temperature = 25.0 + temperaturOffset;
|
||||||
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
|
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
|
||||||
if(debugDivider->checkAndIncrement()) {
|
if (debugDivider->checkAndIncrement()) {
|
||||||
/* Set terminal to utf-8 if there is an issue with micro printout. */
|
/* Set terminal to utf-8 if there is an issue with micro printout. */
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::info << "GyroHandlerL3GD20H: Angular velocities (deg/s):" << std::endl;
|
sif::info << "GyroHandlerL3GD20H: Angular velocities (deg/s):" << std::endl;
|
||||||
@ -216,28 +211,25 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
PoolReadGuard readSet(&dataset);
|
PoolReadGuard readSet(&dataset);
|
||||||
if(readSet.getReadResult() == HasReturnvaluesIF::RETURN_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);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dataset.angVelocX.setValid(false);
|
dataset.angVelocX.setValid(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(std::abs(angVelocY) < this->absLimitY) {
|
if (std::abs(angVelocY) < this->absLimitY) {
|
||||||
dataset.angVelocY = angVelocY;
|
dataset.angVelocY = angVelocY;
|
||||||
dataset.angVelocY.setValid(true);
|
dataset.angVelocY.setValid(true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dataset.angVelocY.setValid(false);
|
dataset.angVelocY.setValid(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(std::abs(angVelocZ) < this->absLimitZ) {
|
if (std::abs(angVelocZ) < this->absLimitZ) {
|
||||||
dataset.angVelocZ = angVelocZ;
|
dataset.angVelocZ = angVelocZ;
|
||||||
dataset.angVelocZ.setValid(true);
|
dataset.angVelocZ.setValid(true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dataset.angVelocZ.setValid(false);
|
dataset.angVelocZ.setValid(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,17 +244,14 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t GyroHandlerL3GD20H::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
uint32_t GyroHandlerL3GD20H::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||||
return this->transitionDelayMs;
|
return this->transitionDelayMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GyroHandlerL3GD20H::setToGoToNormalMode(bool enable) {
|
void GyroHandlerL3GD20H::setToGoToNormalMode(bool enable) { this->goNormalModeImmediately = true; }
|
||||||
this->goNormalModeImmediately = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(
|
ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
LocalDataPoolManager &poolManager) {
|
||||||
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_X, new PoolEntry<float>({0.0}));
|
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_X, new PoolEntry<float>({0.0}));
|
||||||
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}));
|
||||||
@ -276,9 +265,7 @@ void GyroHandlerL3GD20H::fillCommandAndReplyMap() {
|
|||||||
insertInCommandAndReplyMap(L3GD20H::READ_CTRL_REGS, 1);
|
insertInCommandAndReplyMap(L3GD20H::READ_CTRL_REGS, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GyroHandlerL3GD20H::modeChanged() {
|
void GyroHandlerL3GD20H::modeChanged() { internalState = InternalState::NONE; }
|
||||||
internalState = InternalState::NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GyroHandlerL3GD20H::setAbsoluteLimits(float limitX, float limitY, float limitZ) {
|
void GyroHandlerL3GD20H::setAbsoluteLimits(float limitX, float limitY, float limitZ) {
|
||||||
this->absLimitX = limitX;
|
this->absLimitX = limitX;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
#ifndef MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
||||||
#define MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
#define MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
||||||
|
|
||||||
#include "fsfw/FSFW.h"
|
|
||||||
#include "devicedefinitions/GyroL3GD20Definitions.h"
|
|
||||||
|
|
||||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||||
#include <fsfw/globalfunctions/PeriodicOperationDivider.h>
|
#include <fsfw/globalfunctions/PeriodicOperationDivider.h>
|
||||||
|
|
||||||
|
#include "devicedefinitions/GyroL3GD20Definitions.h"
|
||||||
|
#include "fsfw/FSFW.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Device Handler for the L3GD20H gyroscope sensor
|
* @brief Device Handler for the L3GD20H gyroscope sensor
|
||||||
* (https://www.st.com/en/mems-and-sensors/l3gd20h.html)
|
* (https://www.st.com/en/mems-and-sensors/l3gd20h.html)
|
||||||
@ -16,10 +16,10 @@
|
|||||||
*
|
*
|
||||||
* Data is read big endian with the smallest possible range of 245 degrees per second.
|
* Data is read big endian with the smallest possible range of 245 degrees per second.
|
||||||
*/
|
*/
|
||||||
class GyroHandlerL3GD20H: public DeviceHandlerBase {
|
class GyroHandlerL3GD20H : public DeviceHandlerBase {
|
||||||
public:
|
public:
|
||||||
GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
|
GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
|
||||||
CookieIF* comCookie, uint32_t transitionDelayMs);
|
uint32_t transitionDelayMs);
|
||||||
virtual ~GyroHandlerL3GD20H();
|
virtual ~GyroHandlerL3GD20H();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,22 +35,18 @@ public:
|
|||||||
* @brief Configure device handler to go to normal mode immediately
|
* @brief Configure device handler to go to normal mode immediately
|
||||||
*/
|
*/
|
||||||
void setToGoToNormalMode(bool enable);
|
void setToGoToNormalMode(bool enable);
|
||||||
protected:
|
|
||||||
|
|
||||||
|
protected:
|
||||||
/* DeviceHandlerBase overrides */
|
/* DeviceHandlerBase overrides */
|
||||||
ReturnValue_t buildTransitionDeviceCommand(
|
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
||||||
DeviceCommandId_t *id) override;
|
|
||||||
void doStartUp() override;
|
void doStartUp() override;
|
||||||
void doShutDown() override;
|
void doShutDown() override;
|
||||||
ReturnValue_t buildNormalDeviceCommand(
|
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
||||||
DeviceCommandId_t *id) override;
|
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||||
ReturnValue_t buildCommandFromCommand(
|
|
||||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
|
||||||
size_t commandDataLen) override;
|
size_t commandDataLen) override;
|
||||||
ReturnValue_t scanForReply(const uint8_t *start, size_t len,
|
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
|
||||||
DeviceCommandId_t *foundId, size_t *foundLen) override;
|
size_t *foundLen) override;
|
||||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
||||||
const uint8_t *packet) override;
|
|
||||||
|
|
||||||
void fillCommandAndReplyMap() override;
|
void fillCommandAndReplyMap() override;
|
||||||
void modeChanged() override;
|
void modeChanged() override;
|
||||||
@ -58,7 +54,7 @@ protected:
|
|||||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||||
LocalDataPoolManager &poolManager) override;
|
LocalDataPoolManager &poolManager) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t transitionDelayMs = 0;
|
uint32_t transitionDelayMs = 0;
|
||||||
GyroPrimaryDataset dataset;
|
GyroPrimaryDataset dataset;
|
||||||
|
|
||||||
@ -66,12 +62,7 @@ private:
|
|||||||
float absLimitY = L3GD20H::RANGE_DPS_00;
|
float absLimitY = L3GD20H::RANGE_DPS_00;
|
||||||
float absLimitZ = L3GD20H::RANGE_DPS_00;
|
float absLimitZ = L3GD20H::RANGE_DPS_00;
|
||||||
|
|
||||||
enum class InternalState {
|
enum class InternalState { NONE, CONFIGURE, CHECK_REGS, NORMAL };
|
||||||
NONE,
|
|
||||||
CONFIGURE,
|
|
||||||
CHECK_REGS,
|
|
||||||
NORMAL
|
|
||||||
};
|
|
||||||
InternalState internalState = InternalState::NONE;
|
InternalState internalState = InternalState::NONE;
|
||||||
bool commandExecuted = false;
|
bool commandExecuted = false;
|
||||||
|
|
||||||
@ -90,10 +81,8 @@ private:
|
|||||||
float sensitivity = L3GD20H::SENSITIVITY_00;
|
float sensitivity = L3GD20H::SENSITIVITY_00;
|
||||||
|
|
||||||
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
|
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
|
||||||
PeriodicOperationDivider* debugDivider = nullptr;
|
PeriodicOperationDivider *debugDivider = nullptr;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* MISSION_DEVICES_GYROL3GD20HANDLER_H_ */
|
#endif /* MISSION_DEVICES_GYROL3GD20HANDLER_H_ */
|
||||||
|
@ -8,9 +8,10 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCommunication,
|
MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCommunication,
|
||||||
CookieIF* comCookie, uint32_t transitionDelay):
|
CookieIF *comCookie, uint32_t transitionDelay)
|
||||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||||
dataset(this), transitionDelay(transitionDelay) {
|
dataset(this),
|
||||||
|
transitionDelay(transitionDelay) {
|
||||||
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
||||||
debugDivider = new PeriodicOperationDivider(3);
|
debugDivider = new PeriodicOperationDivider(3);
|
||||||
#endif
|
#endif
|
||||||
@ -20,39 +21,35 @@ MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCom
|
|||||||
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
|
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
|
||||||
registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT;
|
registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT;
|
||||||
registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT;
|
registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
MgmLIS3MDLHandler::~MgmLIS3MDLHandler() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MgmLIS3MDLHandler::~MgmLIS3MDLHandler() {}
|
||||||
|
|
||||||
void MgmLIS3MDLHandler::doStartUp() {
|
void MgmLIS3MDLHandler::doStartUp() {
|
||||||
switch (internalState) {
|
switch (internalState) {
|
||||||
case(InternalState::STATE_NONE): {
|
case (InternalState::STATE_NONE): {
|
||||||
internalState = InternalState::STATE_FIRST_CONTACT;
|
internalState = InternalState::STATE_FIRST_CONTACT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::STATE_FIRST_CONTACT): {
|
case (InternalState::STATE_FIRST_CONTACT): {
|
||||||
/* Will be set by checking device ID (WHO AM I register) */
|
/* Will be set by checking device ID (WHO AM I register) */
|
||||||
if(commandExecuted) {
|
if (commandExecuted) {
|
||||||
commandExecuted = false;
|
commandExecuted = false;
|
||||||
internalState = InternalState::STATE_SETUP;
|
internalState = InternalState::STATE_SETUP;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::STATE_SETUP): {
|
case (InternalState::STATE_SETUP): {
|
||||||
internalState = InternalState::STATE_CHECK_REGISTERS;
|
internalState = InternalState::STATE_CHECK_REGISTERS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::STATE_CHECK_REGISTERS): {
|
case (InternalState::STATE_CHECK_REGISTERS): {
|
||||||
/* Set up cached registers which will be used to configure the MGM. */
|
/* Set up cached registers which will be used to configure the MGM. */
|
||||||
if(commandExecuted) {
|
if (commandExecuted) {
|
||||||
commandExecuted = false;
|
commandExecuted = false;
|
||||||
if(goToNormalMode) {
|
if (goToNormalMode) {
|
||||||
setMode(MODE_NORMAL);
|
setMode(MODE_NORMAL);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setMode(_MODE_TO_ON);
|
setMode(_MODE_TO_ON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,43 +58,38 @@ void MgmLIS3MDLHandler::doStartUp() {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgmLIS3MDLHandler::doShutDown() {
|
void MgmLIS3MDLHandler::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||||
setMode(_MODE_POWER_DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand(
|
ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||||
DeviceCommandId_t *id) {
|
|
||||||
switch (internalState) {
|
switch (internalState) {
|
||||||
case(InternalState::STATE_NONE):
|
case (InternalState::STATE_NONE):
|
||||||
case(InternalState::STATE_NORMAL): {
|
case (InternalState::STATE_NORMAL): {
|
||||||
return DeviceHandlerBase::NOTHING_TO_SEND;
|
return DeviceHandlerBase::NOTHING_TO_SEND;
|
||||||
}
|
}
|
||||||
case(InternalState::STATE_FIRST_CONTACT): {
|
case (InternalState::STATE_FIRST_CONTACT): {
|
||||||
*id = MGMLIS3MDL::IDENTIFY_DEVICE;
|
*id = MGMLIS3MDL::IDENTIFY_DEVICE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::STATE_SETUP): {
|
case (InternalState::STATE_SETUP): {
|
||||||
*id = MGMLIS3MDL::SETUP_MGM;
|
*id = MGMLIS3MDL::SETUP_MGM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::STATE_CHECK_REGISTERS): {
|
case (InternalState::STATE_CHECK_REGISTERS): {
|
||||||
*id = MGMLIS3MDL::READ_CONFIG_AND_DATA;
|
*id = MGMLIS3MDL::READ_CONFIG_AND_DATA;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
/* might be a configuration error. */
|
/* might be a configuration error. */
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "GyroHandler::buildTransitionDeviceCommand: Unknown internal state!" <<
|
sif::warning << "GyroHandler::buildTransitionDeviceCommand: Unknown internal state!"
|
||||||
std::endl;
|
<< std::endl;
|
||||||
#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 HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return buildCommandFromCommand(*id, NULL, 0);
|
return buildCommandFromCommand(*id, NULL, 0);
|
||||||
}
|
}
|
||||||
@ -119,7 +111,6 @@ uint8_t MgmLIS3MDLHandler::writeCommand(uint8_t command, bool continuousCom) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MgmLIS3MDLHandler::setupMgm() {
|
void MgmLIS3MDLHandler::setupMgm() {
|
||||||
|
|
||||||
registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT;
|
registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT;
|
||||||
registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT;
|
registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT;
|
||||||
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
|
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
|
||||||
@ -129,27 +120,24 @@ void MgmLIS3MDLHandler::setupMgm() {
|
|||||||
prepareCtrlRegisterWrite();
|
prepareCtrlRegisterWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmLIS3MDLHandler::buildNormalDeviceCommand(
|
ReturnValue_t MgmLIS3MDLHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||||
DeviceCommandId_t *id) {
|
|
||||||
// Data/config register will be read in an alternating manner.
|
// Data/config register will be read in an alternating manner.
|
||||||
if(communicationStep == CommunicationStep::DATA) {
|
if (communicationStep == CommunicationStep::DATA) {
|
||||||
*id = MGMLIS3MDL::READ_CONFIG_AND_DATA;
|
*id = MGMLIS3MDL::READ_CONFIG_AND_DATA;
|
||||||
communicationStep = CommunicationStep::TEMPERATURE;
|
communicationStep = CommunicationStep::TEMPERATURE;
|
||||||
return buildCommandFromCommand(*id, NULL, 0);
|
return buildCommandFromCommand(*id, NULL, 0);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
*id = MGMLIS3MDL::READ_TEMPERATURE;
|
*id = MGMLIS3MDL::READ_TEMPERATURE;
|
||||||
communicationStep = CommunicationStep::DATA;
|
communicationStep = CommunicationStep::DATA;
|
||||||
return buildCommandFromCommand(*id, NULL, 0);
|
return buildCommandFromCommand(*id, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(
|
ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
const uint8_t *commandData,
|
||||||
size_t commandDataLen) {
|
size_t commandDataLen) {
|
||||||
switch(deviceCommand) {
|
switch (deviceCommand) {
|
||||||
case(MGMLIS3MDL::READ_CONFIG_AND_DATA): {
|
case (MGMLIS3MDL::READ_CONFIG_AND_DATA): {
|
||||||
std::memset(commandBuffer, 0, sizeof(commandBuffer));
|
std::memset(commandBuffer, 0, sizeof(commandBuffer));
|
||||||
commandBuffer[0] = readCommand(MGMLIS3MDL::CTRL_REG1, true);
|
commandBuffer[0] = readCommand(MGMLIS3MDL::CTRL_REG1, true);
|
||||||
|
|
||||||
@ -157,7 +145,7 @@ ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(
|
|||||||
rawPacketLen = MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1;
|
rawPacketLen = MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
case(MGMLIS3MDL::READ_TEMPERATURE): {
|
case (MGMLIS3MDL::READ_TEMPERATURE): {
|
||||||
std::memset(commandBuffer, 0, 3);
|
std::memset(commandBuffer, 0, 3);
|
||||||
commandBuffer[0] = readCommand(MGMLIS3MDL::TEMP_LOWBYTE, true);
|
commandBuffer[0] = readCommand(MGMLIS3MDL::TEMP_LOWBYTE, true);
|
||||||
|
|
||||||
@ -165,17 +153,17 @@ ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(
|
|||||||
rawPacketLen = 3;
|
rawPacketLen = 3;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
case(MGMLIS3MDL::IDENTIFY_DEVICE): {
|
case (MGMLIS3MDL::IDENTIFY_DEVICE): {
|
||||||
return identifyDevice();
|
return identifyDevice();
|
||||||
}
|
}
|
||||||
case(MGMLIS3MDL::TEMP_SENSOR_ENABLE): {
|
case (MGMLIS3MDL::TEMP_SENSOR_ENABLE): {
|
||||||
return enableTemperatureSensor(commandData, commandDataLen);
|
return enableTemperatureSensor(commandData, commandDataLen);
|
||||||
}
|
}
|
||||||
case(MGMLIS3MDL::SETUP_MGM): {
|
case (MGMLIS3MDL::SETUP_MGM): {
|
||||||
setupMgm();
|
setupMgm();
|
||||||
return HasReturnvaluesIF::RETURN_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);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -195,16 +183,15 @@ ReturnValue_t MgmLIS3MDLHandler::identifyDevice() {
|
|||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start,
|
ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start, size_t len,
|
||||||
size_t len, DeviceCommandId_t *foundId, size_t *foundLen) {
|
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||||
*foundLen = len;
|
*foundLen = len;
|
||||||
if (len == MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1) {
|
if (len == MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1) {
|
||||||
*foundLen = len;
|
*foundLen = len;
|
||||||
*foundId = MGMLIS3MDL::READ_CONFIG_AND_DATA;
|
*foundId = MGMLIS3MDL::READ_CONFIG_AND_DATA;
|
||||||
// Check validity by checking config registers
|
// Check validity by checking config registers
|
||||||
if (start[1] != registers[0] or start[2] != registers[1] or
|
if (start[1] != registers[0] or start[2] != registers[1] or start[3] != registers[2] or
|
||||||
start[3] != registers[2] or start[4] != registers[3] or
|
start[4] != registers[3] or start[5] != registers[4]) {
|
||||||
start[5] != registers[4]) {
|
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "MGMHandlerLIS3MDL::scanForReply: Invalid registers!" << std::endl;
|
sif::warning << "MGMHandlerLIS3MDL::scanForReply: Invalid registers!" << std::endl;
|
||||||
@ -214,57 +201,51 @@ ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start,
|
|||||||
#endif
|
#endif
|
||||||
return DeviceHandlerIF::INVALID_DATA;
|
return DeviceHandlerIF::INVALID_DATA;
|
||||||
}
|
}
|
||||||
if(mode == _MODE_START_UP) {
|
if (mode == _MODE_START_UP) {
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else if (len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) {
|
||||||
else if(len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) {
|
|
||||||
*foundLen = len;
|
*foundLen = len;
|
||||||
*foundId = MGMLIS3MDL::READ_TEMPERATURE;
|
*foundId = MGMLIS3MDL::READ_TEMPERATURE;
|
||||||
}
|
} else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) {
|
||||||
else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) {
|
|
||||||
*foundLen = len;
|
*foundLen = len;
|
||||||
*foundId = MGMLIS3MDL::SETUP_MGM;
|
*foundId = MGMLIS3MDL::SETUP_MGM;
|
||||||
}
|
} else if (len == SINGLE_COMMAND_ANSWER_LEN) {
|
||||||
else if (len == SINGLE_COMMAND_ANSWER_LEN) {
|
|
||||||
*foundLen = len;
|
*foundLen = len;
|
||||||
*foundId = getPendingCommand();
|
*foundId = getPendingCommand();
|
||||||
if(*foundId == MGMLIS3MDL::IDENTIFY_DEVICE) {
|
if (*foundId == MGMLIS3MDL::IDENTIFY_DEVICE) {
|
||||||
if(start[1] != MGMLIS3MDL::DEVICE_ID) {
|
if (start[1] != MGMLIS3MDL::DEVICE_ID) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "MGMHandlerLIS3MDL::scanForReply: "
|
sif::warning << "MGMHandlerLIS3MDL::scanForReply: "
|
||||||
"Device identification failed!" << std::endl;
|
"Device identification failed!"
|
||||||
|
<< std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("MGMHandlerLIS3MDL::scanForReply: "
|
sif::printWarning(
|
||||||
|
"MGMHandlerLIS3MDL::scanForReply: "
|
||||||
"Device identification failed!\n");
|
"Device identification failed!\n");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return DeviceHandlerIF::INVALID_DATA;
|
return DeviceHandlerIF::INVALID_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mode == _MODE_START_UP) {
|
if (mode == _MODE_START_UP) {
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return DeviceHandlerIF::INVALID_DATA;
|
return DeviceHandlerIF::INVALID_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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 RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return DeviceHandlerIF::INVALID_DATA;
|
return DeviceHandlerIF::INVALID_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
|
ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
||||||
const uint8_t *packet) {
|
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case MGMLIS3MDL::IDENTIFY_DEVICE: {
|
case MGMLIS3MDL::IDENTIFY_DEVICE: {
|
||||||
break;
|
break;
|
||||||
@ -276,26 +257,27 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
// TODO: Store configuration in new local datasets.
|
// TODO: Store configuration in new local datasets.
|
||||||
float sensitivityFactor = getSensitivityFactor(getSensitivity(registers[2]));
|
float sensitivityFactor = getSensitivityFactor(getSensitivity(registers[2]));
|
||||||
|
|
||||||
int16_t mgmMeasurementRawX = packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8
|
int16_t mgmMeasurementRawX =
|
||||||
| packet[MGMLIS3MDL::X_LOWBYTE_IDX] ;
|
packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::X_LOWBYTE_IDX];
|
||||||
int16_t mgmMeasurementRawY = packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8
|
int16_t mgmMeasurementRawY =
|
||||||
| packet[MGMLIS3MDL::Y_LOWBYTE_IDX] ;
|
packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::Y_LOWBYTE_IDX];
|
||||||
int16_t mgmMeasurementRawZ = packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8
|
int16_t mgmMeasurementRawZ =
|
||||||
| packet[MGMLIS3MDL::Z_LOWBYTE_IDX] ;
|
packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::Z_LOWBYTE_IDX];
|
||||||
|
|
||||||
/* Target value in microtesla */
|
/* Target value in microtesla */
|
||||||
float mgmX = static_cast<float>(mgmMeasurementRawX) * sensitivityFactor
|
float mgmX = static_cast<float>(mgmMeasurementRawX) * sensitivityFactor *
|
||||||
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||||
float mgmY = static_cast<float>(mgmMeasurementRawY) * sensitivityFactor
|
float mgmY = static_cast<float>(mgmMeasurementRawY) * sensitivityFactor *
|
||||||
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||||
float mgmZ = static_cast<float>(mgmMeasurementRawZ) * sensitivityFactor
|
float mgmZ = static_cast<float>(mgmMeasurementRawZ) * sensitivityFactor *
|
||||||
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||||
|
|
||||||
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
||||||
if(debugDivider->checkAndIncrement()) {
|
if (debugDivider->checkAndIncrement()) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::info << "MGMHandlerLIS3: Magnetic field strength in"
|
sif::info << "MGMHandlerLIS3: Magnetic field strength in"
|
||||||
" microtesla:" << std::endl;
|
" microtesla:"
|
||||||
|
<< std::endl;
|
||||||
sif::info << "X: " << mgmX << " uT" << std::endl;
|
sif::info << "X: " << mgmX << " uT" << std::endl;
|
||||||
sif::info << "Y: " << mgmY << " uT" << std::endl;
|
sif::info << "Y: " << mgmY << " uT" << std::endl;
|
||||||
sif::info << "Z: " << mgmZ << " uT" << std::endl;
|
sif::info << "Z: " << mgmZ << " uT" << std::endl;
|
||||||
@ -308,28 +290,25 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
}
|
}
|
||||||
#endif /* OBSW_VERBOSE_LEVEL >= 1 */
|
#endif /* OBSW_VERBOSE_LEVEL >= 1 */
|
||||||
PoolReadGuard readHelper(&dataset);
|
PoolReadGuard readHelper(&dataset);
|
||||||
if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
if (readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||||
if(std::abs(mgmX) < absLimitX) {
|
if (std::abs(mgmX) < absLimitX) {
|
||||||
dataset.fieldStrengthX = mgmX;
|
dataset.fieldStrengthX = mgmX;
|
||||||
dataset.fieldStrengthX.setValid(true);
|
dataset.fieldStrengthX.setValid(true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dataset.fieldStrengthX.setValid(false);
|
dataset.fieldStrengthX.setValid(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(std::abs(mgmY) < absLimitY) {
|
if (std::abs(mgmY) < absLimitY) {
|
||||||
dataset.fieldStrengthY = mgmY;
|
dataset.fieldStrengthY = mgmY;
|
||||||
dataset.fieldStrengthY.setValid(true);
|
dataset.fieldStrengthY.setValid(true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dataset.fieldStrengthY.setValid(false);
|
dataset.fieldStrengthY.setValid(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(std::abs(mgmZ) < absLimitZ) {
|
if (std::abs(mgmZ) < absLimitZ) {
|
||||||
dataset.fieldStrengthZ = mgmZ;
|
dataset.fieldStrengthZ = mgmZ;
|
||||||
dataset.fieldStrengthZ.setValid(true);
|
dataset.fieldStrengthZ.setValid(true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dataset.fieldStrengthZ.setValid(false);
|
dataset.fieldStrengthZ.setValid(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -339,18 +318,17 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
case MGMLIS3MDL::READ_TEMPERATURE: {
|
case MGMLIS3MDL::READ_TEMPERATURE: {
|
||||||
int16_t tempValueRaw = packet[2] << 8 | packet[1];
|
int16_t tempValueRaw = packet[2] << 8 | packet[1];
|
||||||
float tempValue = 25.0 + ((static_cast<float>(tempValueRaw)) / 8.0);
|
float tempValue = 25.0 + ((static_cast<float>(tempValueRaw)) / 8.0);
|
||||||
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
||||||
if(debugDivider->check()) {
|
if (debugDivider->check()) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" <<
|
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" << std::endl;
|
||||||
std::endl;
|
|
||||||
#else
|
#else
|
||||||
sif::printInfo("MGMHandlerLIS3: Temperature: %f C\n");
|
sif::printInfo("MGMHandlerLIS3: Temperature: %f C\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
ReturnValue_t result = dataset.read();
|
ReturnValue_t result = dataset.read();
|
||||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||||
dataset.temperature = tempValue;
|
dataset.temperature = tempValue;
|
||||||
dataset.commit();
|
dataset.commit();
|
||||||
}
|
}
|
||||||
@ -360,7 +338,6 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
default: {
|
default: {
|
||||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
@ -380,17 +357,17 @@ MGMLIS3MDL::Sensitivies MgmLIS3MDLHandler::getSensitivity(uint8_t ctrlRegister2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
float MgmLIS3MDLHandler::getSensitivityFactor(MGMLIS3MDL::Sensitivies sens) {
|
float MgmLIS3MDLHandler::getSensitivityFactor(MGMLIS3MDL::Sensitivies sens) {
|
||||||
switch(sens) {
|
switch (sens) {
|
||||||
case(MGMLIS3MDL::GAUSS_4): {
|
case (MGMLIS3MDL::GAUSS_4): {
|
||||||
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_4_SENS;
|
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_4_SENS;
|
||||||
}
|
}
|
||||||
case(MGMLIS3MDL::GAUSS_8): {
|
case (MGMLIS3MDL::GAUSS_8): {
|
||||||
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_8_SENS;
|
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_8_SENS;
|
||||||
}
|
}
|
||||||
case(MGMLIS3MDL::GAUSS_12): {
|
case (MGMLIS3MDL::GAUSS_12): {
|
||||||
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_12_SENS;
|
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_12_SENS;
|
||||||
}
|
}
|
||||||
case(MGMLIS3MDL::GAUSS_16): {
|
case (MGMLIS3MDL::GAUSS_16): {
|
||||||
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_16_SENS;
|
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_16_SENS;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -400,9 +377,8 @@ float MgmLIS3MDLHandler::getSensitivityFactor(MGMLIS3MDL::Sensitivies sens) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t MgmLIS3MDLHandler::enableTemperatureSensor(const uint8_t *commandData,
|
||||||
ReturnValue_t MgmLIS3MDLHandler::enableTemperatureSensor(
|
size_t commandDataLen) {
|
||||||
const uint8_t *commandData, size_t commandDataLen) {
|
|
||||||
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);
|
||||||
@ -471,9 +447,7 @@ void MgmLIS3MDLHandler::fillCommandAndReplyMap() {
|
|||||||
insertInCommandAndReplyMap(MGMLIS3MDL::ACCURACY_OP_MODE_SET, 1);
|
insertInCommandAndReplyMap(MGMLIS3MDL::ACCURACY_OP_MODE_SET, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgmLIS3MDLHandler::setToGoToNormalMode(bool enable) {
|
void MgmLIS3MDLHandler::setToGoToNormalMode(bool enable) { this->goToNormalMode = enable; }
|
||||||
this->goToNormalMode = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() {
|
ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() {
|
||||||
commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1, true);
|
commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1, true);
|
||||||
@ -488,28 +462,18 @@ ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() {
|
|||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgmLIS3MDLHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
|
void MgmLIS3MDLHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {}
|
||||||
|
|
||||||
}
|
uint32_t MgmLIS3MDLHandler::getTransitionDelayMs(Mode_t from, Mode_t to) { return transitionDelay; }
|
||||||
|
|
||||||
uint32_t MgmLIS3MDLHandler::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
void MgmLIS3MDLHandler::modeChanged(void) { internalState = InternalState::STATE_NONE; }
|
||||||
return transitionDelay;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MgmLIS3MDLHandler::modeChanged(void) {
|
ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||||
internalState = InternalState::STATE_NONE;
|
LocalDataPoolManager &poolManager) {
|
||||||
}
|
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
|
||||||
|
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
|
||||||
ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(
|
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
|
||||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, new PoolEntry<float>({0.0}));
|
||||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X,
|
|
||||||
new PoolEntry<float>({0.0}));
|
|
||||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y,
|
|
||||||
new PoolEntry<float>({0.0}));
|
|
||||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z,
|
|
||||||
new PoolEntry<float>({0.0}));
|
|
||||||
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS,
|
|
||||||
new PoolEntry<float>({0.0}));
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
#ifndef MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
#ifndef MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
||||||
#define MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
#define MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
||||||
|
|
||||||
#include "fsfw/FSFW.h"
|
|
||||||
#include "events/subsystemIdRanges.h"
|
|
||||||
#include "devicedefinitions/MgmLIS3HandlerDefs.h"
|
#include "devicedefinitions/MgmLIS3HandlerDefs.h"
|
||||||
|
#include "events/subsystemIdRanges.h"
|
||||||
|
#include "fsfw/FSFW.h"
|
||||||
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
||||||
|
|
||||||
class PeriodicOperationDivider;
|
class PeriodicOperationDivider;
|
||||||
@ -18,19 +17,16 @@ class PeriodicOperationDivider;
|
|||||||
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/LIS3MDL_MGM
|
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/LIS3MDL_MGM
|
||||||
* @author L. Loidold, R. Mueller
|
* @author L. Loidold, R. Mueller
|
||||||
*/
|
*/
|
||||||
class MgmLIS3MDLHandler: public DeviceHandlerBase {
|
class MgmLIS3MDLHandler : public DeviceHandlerBase {
|
||||||
public:
|
public:
|
||||||
enum class CommunicationStep {
|
enum class CommunicationStep { DATA, TEMPERATURE };
|
||||||
DATA,
|
|
||||||
TEMPERATURE
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::MGM_LIS3MDL;
|
static const uint8_t INTERFACE_ID = CLASS_ID::MGM_LIS3MDL;
|
||||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::MGM_LIS3MDL;
|
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::MGM_LIS3MDL;
|
||||||
//Notifies a command to change the setup parameters
|
// Notifies a command to change the setup parameters
|
||||||
static const Event CHANGE_OF_SETUP_PARAMETER = MAKE_EVENT(0, severity::LOW);
|
static const Event CHANGE_OF_SETUP_PARAMETER = MAKE_EVENT(0, severity::LOW);
|
||||||
|
|
||||||
MgmLIS3MDLHandler(uint32_t objectId, object_id_t deviceCommunication, CookieIF* comCookie,
|
MgmLIS3MDLHandler(uint32_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
|
||||||
uint32_t transitionDelay);
|
uint32_t transitionDelay);
|
||||||
virtual ~MgmLIS3MDLHandler();
|
virtual ~MgmLIS3MDLHandler();
|
||||||
|
|
||||||
@ -44,22 +40,18 @@ public:
|
|||||||
void setAbsoluteLimits(float xLimit, float yLimit, float zLimit);
|
void setAbsoluteLimits(float xLimit, float yLimit, float zLimit);
|
||||||
void setToGoToNormalMode(bool enable);
|
void setToGoToNormalMode(bool enable);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/** DeviceHandlerBase overrides */
|
/** DeviceHandlerBase overrides */
|
||||||
void doShutDown() override;
|
void doShutDown() override;
|
||||||
void doStartUp() override;
|
void doStartUp() override;
|
||||||
void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
|
void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
|
||||||
virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
|
virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
|
||||||
ReturnValue_t buildCommandFromCommand(
|
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
|
||||||
size_t commandDataLen) override;
|
size_t commandDataLen) override;
|
||||||
ReturnValue_t buildTransitionDeviceCommand(
|
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
||||||
DeviceCommandId_t *id) override;
|
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
||||||
ReturnValue_t buildNormalDeviceCommand(
|
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
|
||||||
DeviceCommandId_t *id) override;
|
size_t *foundLen) override;
|
||||||
ReturnValue_t scanForReply(const uint8_t *start, size_t len,
|
|
||||||
DeviceCommandId_t *foundId, size_t *foundLen) override;
|
|
||||||
/**
|
/**
|
||||||
* This implementation is tailored towards space applications and will flag values larger
|
* This implementation is tailored towards space applications and will flag values larger
|
||||||
* than 100 microtesla on X,Y and 150 microtesla on Z as invalid
|
* than 100 microtesla on X,Y and 150 microtesla on Z as invalid
|
||||||
@ -67,16 +59,15 @@ protected:
|
|||||||
* @param packet
|
* @param packet
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
||||||
const uint8_t *packet) override;
|
|
||||||
void fillCommandAndReplyMap() override;
|
void fillCommandAndReplyMap() override;
|
||||||
void modeChanged(void) override;
|
void modeChanged(void) override;
|
||||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||||
LocalDataPoolManager &poolManager) override;
|
LocalDataPoolManager &poolManager) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MGMLIS3MDL::MgmPrimaryDataset dataset;
|
MGMLIS3MDL::MgmPrimaryDataset dataset;
|
||||||
//Length a single command SPI answer
|
// Length a single command SPI answer
|
||||||
static const uint8_t SINGLE_COMMAND_ANSWER_LEN = 2;
|
static const uint8_t SINGLE_COMMAND_ANSWER_LEN = 2;
|
||||||
|
|
||||||
uint32_t transitionDelay;
|
uint32_t transitionDelay;
|
||||||
@ -159,16 +150,14 @@ private:
|
|||||||
* @param commandData On or Off
|
* @param commandData On or Off
|
||||||
* @param length of the commandData: has to be 1
|
* @param length of the commandData: has to be 1
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t enableTemperatureSensor(const uint8_t *commandData,
|
virtual ReturnValue_t enableTemperatureSensor(const uint8_t *commandData, size_t commandDataLen);
|
||||||
size_t commandDataLen);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the accuracy of the measurement of the axis. The noise is changing.
|
* Sets the accuracy of the measurement of the axis. The noise is changing.
|
||||||
* @param commandData LOW, MEDIUM, HIGH, ULTRA
|
* @param commandData LOW, MEDIUM, HIGH, ULTRA
|
||||||
* @param length of the command, has to be 1
|
* @param length of the command, has to be 1
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t setOperatingMode(const uint8_t *commandData,
|
virtual ReturnValue_t setOperatingMode(const uint8_t *commandData, size_t commandDataLen);
|
||||||
size_t commandDataLen);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We always update all registers together, so this method updates
|
* We always update all registers together, so this method updates
|
||||||
@ -179,7 +168,7 @@ private:
|
|||||||
ReturnValue_t prepareCtrlRegisterWrite();
|
ReturnValue_t prepareCtrlRegisterWrite();
|
||||||
|
|
||||||
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
||||||
PeriodicOperationDivider* debugDivider;
|
PeriodicOperationDivider *debugDivider;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
#include "MgmRM3100Handler.h"
|
#include "MgmRM3100Handler.h"
|
||||||
|
|
||||||
#include "fsfw/datapool/PoolReadGuard.h"
|
#include "fsfw/datapool/PoolReadGuard.h"
|
||||||
#include "fsfw/globalfunctions/bitutility.h"
|
|
||||||
#include "fsfw/devicehandlers/DeviceHandlerMessage.h"
|
#include "fsfw/devicehandlers/DeviceHandlerMessage.h"
|
||||||
|
#include "fsfw/globalfunctions/bitutility.h"
|
||||||
#include "fsfw/objectmanager/SystemObjectIF.h"
|
#include "fsfw/objectmanager/SystemObjectIF.h"
|
||||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
|
||||||
|
MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication,
|
||||||
MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId,
|
CookieIF *comCookie, uint32_t transitionDelay)
|
||||||
object_id_t deviceCommunication, CookieIF* comCookie, uint32_t transitionDelay):
|
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
primaryDataset(this),
|
||||||
primaryDataset(this), transitionDelay(transitionDelay) {
|
transitionDelay(transitionDelay) {
|
||||||
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
||||||
debugDivider = new PeriodicOperationDivider(3);
|
debugDivider = new PeriodicOperationDivider(3);
|
||||||
#endif
|
#endif
|
||||||
@ -19,34 +19,33 @@ MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId,
|
|||||||
MgmRM3100Handler::~MgmRM3100Handler() {}
|
MgmRM3100Handler::~MgmRM3100Handler() {}
|
||||||
|
|
||||||
void MgmRM3100Handler::doStartUp() {
|
void MgmRM3100Handler::doStartUp() {
|
||||||
switch(internalState) {
|
switch (internalState) {
|
||||||
case(InternalState::NONE): {
|
case (InternalState::NONE): {
|
||||||
internalState = InternalState::CONFIGURE_CMM;
|
internalState = InternalState::CONFIGURE_CMM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::CONFIGURE_CMM): {
|
case (InternalState::CONFIGURE_CMM): {
|
||||||
internalState = InternalState::READ_CMM;
|
internalState = InternalState::READ_CMM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::READ_CMM): {
|
case (InternalState::READ_CMM): {
|
||||||
if(commandExecuted) {
|
if (commandExecuted) {
|
||||||
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::STATE_CONFIGURE_TMRC): {
|
case (InternalState::STATE_CONFIGURE_TMRC): {
|
||||||
if(commandExecuted) {
|
if (commandExecuted) {
|
||||||
internalState = InternalState::STATE_READ_TMRC;
|
internalState = InternalState::STATE_READ_TMRC;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::STATE_READ_TMRC): {
|
case (InternalState::STATE_READ_TMRC): {
|
||||||
if(commandExecuted) {
|
if (commandExecuted) {
|
||||||
internalState = InternalState::NORMAL;
|
internalState = InternalState::NORMAL;
|
||||||
if(goToNormalModeAtStartup) {
|
if (goToNormalModeAtStartup) {
|
||||||
setMode(MODE_NORMAL);
|
setMode(MODE_NORMAL);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setMode(_MODE_TO_ON);
|
setMode(_MODE_TO_ON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,33 +57,30 @@ void MgmRM3100Handler::doStartUp() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgmRM3100Handler::doShutDown() {
|
void MgmRM3100Handler::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||||
setMode(_MODE_POWER_DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(
|
ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||||
DeviceCommandId_t *id) {
|
|
||||||
size_t commandLen = 0;
|
size_t commandLen = 0;
|
||||||
switch(internalState) {
|
switch (internalState) {
|
||||||
case(InternalState::NONE):
|
case (InternalState::NONE):
|
||||||
case(InternalState::NORMAL): {
|
case (InternalState::NORMAL): {
|
||||||
return NOTHING_TO_SEND;
|
return NOTHING_TO_SEND;
|
||||||
}
|
}
|
||||||
case(InternalState::CONFIGURE_CMM): {
|
case (InternalState::CONFIGURE_CMM): {
|
||||||
*id = RM3100::CONFIGURE_CMM;
|
*id = RM3100::CONFIGURE_CMM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::READ_CMM): {
|
case (InternalState::READ_CMM): {
|
||||||
*id = RM3100::READ_CMM;
|
*id = RM3100::READ_CMM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::STATE_CONFIGURE_TMRC): {
|
case (InternalState::STATE_CONFIGURE_TMRC): {
|
||||||
commandBuffer[0] = RM3100::TMRC_DEFAULT_VALUE;
|
commandBuffer[0] = RM3100::TMRC_DEFAULT_VALUE;
|
||||||
commandLen = 1;
|
commandLen = 1;
|
||||||
*id = RM3100::CONFIGURE_TMRC;
|
*id = RM3100::CONFIGURE_TMRC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(InternalState::STATE_READ_TMRC): {
|
case (InternalState::STATE_READ_TMRC): {
|
||||||
*id = RM3100::READ_TMRC;
|
*id = RM3100::READ_TMRC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -93,9 +89,11 @@ ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(
|
|||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
// Might be a configuration error
|
// Might be a configuration error
|
||||||
sif::warning << "MgmRM3100Handler::buildTransitionDeviceCommand: "
|
sif::warning << "MgmRM3100Handler::buildTransitionDeviceCommand: "
|
||||||
"Unknown internal state" << std::endl;
|
"Unknown internal state"
|
||||||
|
<< std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("MgmRM3100Handler::buildTransitionDeviceCommand: "
|
sif::printWarning(
|
||||||
|
"MgmRM3100Handler::buildTransitionDeviceCommand: "
|
||||||
"Unknown internal state\n");
|
"Unknown internal state\n");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -106,43 +104,44 @@ ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
ReturnValue_t MgmRM3100Handler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||||
const uint8_t *commandData, size_t commandDataLen) {
|
const uint8_t *commandData,
|
||||||
switch(deviceCommand) {
|
size_t commandDataLen) {
|
||||||
case(RM3100::CONFIGURE_CMM): {
|
switch (deviceCommand) {
|
||||||
|
case (RM3100::CONFIGURE_CMM): {
|
||||||
commandBuffer[0] = RM3100::CMM_REGISTER;
|
commandBuffer[0] = RM3100::CMM_REGISTER;
|
||||||
commandBuffer[1] = RM3100::CMM_VALUE;
|
commandBuffer[1] = RM3100::CMM_VALUE;
|
||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
rawPacketLen = 2;
|
rawPacketLen = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(RM3100::READ_CMM): {
|
case (RM3100::READ_CMM): {
|
||||||
commandBuffer[0] = RM3100::CMM_REGISTER | RM3100::READ_MASK;
|
commandBuffer[0] = RM3100::CMM_REGISTER | RM3100::READ_MASK;
|
||||||
commandBuffer[1] = 0;
|
commandBuffer[1] = 0;
|
||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
rawPacketLen = 2;
|
rawPacketLen = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(RM3100::CONFIGURE_TMRC): {
|
case (RM3100::CONFIGURE_TMRC): {
|
||||||
return handleTmrcConfigCommand(deviceCommand, commandData, commandDataLen);
|
return handleTmrcConfigCommand(deviceCommand, commandData, commandDataLen);
|
||||||
}
|
}
|
||||||
case(RM3100::READ_TMRC): {
|
case (RM3100::READ_TMRC): {
|
||||||
commandBuffer[0] = RM3100::TMRC_REGISTER | RM3100::READ_MASK;
|
commandBuffer[0] = RM3100::TMRC_REGISTER | RM3100::READ_MASK;
|
||||||
commandBuffer[1] = 0;
|
commandBuffer[1] = 0;
|
||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
rawPacketLen = 2;
|
rawPacketLen = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(RM3100::CONFIGURE_CYCLE_COUNT): {
|
case (RM3100::CONFIGURE_CYCLE_COUNT): {
|
||||||
return handleCycleCountConfigCommand(deviceCommand, commandData, commandDataLen);
|
return handleCycleCountConfigCommand(deviceCommand, commandData, commandDataLen);
|
||||||
}
|
}
|
||||||
case(RM3100::READ_CYCLE_COUNT): {
|
case (RM3100::READ_CYCLE_COUNT): {
|
||||||
commandBuffer[0] = RM3100::CYCLE_COUNT_START_REGISTER | RM3100::READ_MASK;
|
commandBuffer[0] = RM3100::CYCLE_COUNT_START_REGISTER | RM3100::READ_MASK;
|
||||||
std::memset(commandBuffer + 1, 0, 6);
|
std::memset(commandBuffer + 1, 0, 6);
|
||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
rawPacketLen = 7;
|
rawPacketLen = 7;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(RM3100::READ_DATA): {
|
case (RM3100::READ_DATA): {
|
||||||
commandBuffer[0] = RM3100::MEASUREMENT_REG_START | RM3100::READ_MASK;
|
commandBuffer[0] = RM3100::MEASUREMENT_REG_START | RM3100::READ_MASK;
|
||||||
std::memset(commandBuffer + 1, 0, 9);
|
std::memset(commandBuffer + 1, 0, 9);
|
||||||
rawPacketLen = 10;
|
rawPacketLen = 10;
|
||||||
@ -154,16 +153,13 @@ ReturnValue_t MgmRM3100Handler::buildCommandFromCommand(DeviceCommandId_t device
|
|||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::buildNormalDeviceCommand(
|
ReturnValue_t MgmRM3100Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||||
DeviceCommandId_t *id) {
|
|
||||||
*id = RM3100::READ_DATA;
|
*id = RM3100::READ_DATA;
|
||||||
return buildCommandFromCommand(*id, nullptr, 0);
|
return buildCommandFromCommand(*id, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start,
|
ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start, size_t len,
|
||||||
size_t len, DeviceCommandId_t *foundId,
|
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||||
size_t *foundLen) {
|
|
||||||
|
|
||||||
// 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;
|
||||||
@ -172,62 +168,60 @@ ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start,
|
|||||||
|
|
||||||
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 = HasReturnvaluesIF::RETURN_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):
|
||||||
case(RM3100::CONFIGURE_TMRC): {
|
case (RM3100::CONFIGURE_TMRC): {
|
||||||
// We can only check whether write was successful with read operation
|
// We can only check whether write was successful with read operation
|
||||||
if(mode == _MODE_START_UP) {
|
if (mode == _MODE_START_UP) {
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(RM3100::READ_CMM): {
|
case (RM3100::READ_CMM): {
|
||||||
uint8_t cmmValue = packet[1];
|
uint8_t cmmValue = packet[1];
|
||||||
// We clear the seventh bit in any case
|
// We clear the seventh bit in any case
|
||||||
// because this one is zero sometimes for some reason
|
// because this one is zero sometimes for some reason
|
||||||
bitutil::clear(&cmmValue, 6);
|
bitutil::clear(&cmmValue, 6);
|
||||||
if(cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) {
|
if (cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) {
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Attempt reconfiguration
|
// Attempt reconfiguration
|
||||||
internalState = InternalState::CONFIGURE_CMM;
|
internalState = InternalState::CONFIGURE_CMM;
|
||||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(RM3100::READ_TMRC): {
|
case (RM3100::READ_TMRC): {
|
||||||
if(packet[1] == tmrcRegValue) {
|
if (packet[1] == tmrcRegValue) {
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
// Reading TMRC was commanded. Trigger event to inform ground
|
// Reading TMRC was commanded. Trigger event to inform ground
|
||||||
if(mode != _MODE_START_UP) {
|
if (mode != _MODE_START_UP) {
|
||||||
triggerEvent(tmrcSet, tmrcRegValue, 0);
|
triggerEvent(tmrcSet, tmrcRegValue, 0);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Attempt reconfiguration
|
// Attempt reconfiguration
|
||||||
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
||||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(RM3100::READ_CYCLE_COUNT): {
|
case (RM3100::READ_CYCLE_COUNT): {
|
||||||
uint16_t cycleCountX = packet[1] << 8 | packet[2];
|
uint16_t cycleCountX = packet[1] << 8 | packet[2];
|
||||||
uint16_t cycleCountY = packet[3] << 8 | packet[4];
|
uint16_t cycleCountY = packet[3] << 8 | packet[4];
|
||||||
uint16_t cycleCountZ = packet[5] << 8 | packet[6];
|
uint16_t cycleCountZ = packet[5] << 8 | packet[6];
|
||||||
if(cycleCountX != cycleCountRegValueX or cycleCountY != cycleCountRegValueY or
|
if (cycleCountX != cycleCountRegValueX or cycleCountY != cycleCountRegValueY or
|
||||||
cycleCountZ != cycleCountRegValueZ) {
|
cycleCountZ != cycleCountRegValueZ) {
|
||||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||||
}
|
}
|
||||||
// Reading TMRC was commanded. Trigger event to inform ground
|
// Reading TMRC was commanded. Trigger event to inform ground
|
||||||
if(mode != _MODE_START_UP) {
|
if (mode != _MODE_START_UP) {
|
||||||
uint32_t eventParam1 = (cycleCountX << 16) | cycleCountY;
|
uint32_t eventParam1 = (cycleCountX << 16) | cycleCountY;
|
||||||
triggerEvent(cycleCountersSet, eventParam1, cycleCountZ);
|
triggerEvent(cycleCountersSet, eventParam1, cycleCountZ);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(RM3100::READ_DATA): {
|
case (RM3100::READ_DATA): {
|
||||||
result = handleDataReadout(packet);
|
result = handleDataReadout(packet);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -239,19 +233,18 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
|
ReturnValue_t MgmRM3100Handler::handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
|
||||||
const uint8_t *commandData, size_t commandDataLen) {
|
const uint8_t *commandData,
|
||||||
if(commandData == nullptr) {
|
size_t commandDataLen) {
|
||||||
|
if (commandData == nullptr) {
|
||||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set cycle count
|
// Set cycle count
|
||||||
if(commandDataLen == 2) {
|
if (commandDataLen == 2) {
|
||||||
handleCycleCommand(true, commandData, commandDataLen);
|
handleCycleCommand(true, commandData, commandDataLen);
|
||||||
}
|
} else if (commandDataLen == 6) {
|
||||||
else if(commandDataLen == 6) {
|
|
||||||
handleCycleCommand(false, commandData, commandDataLen);
|
handleCycleCommand(false, commandData, commandDataLen);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,21 +257,21 @@ ReturnValue_t MgmRM3100Handler::handleCycleCountConfigCommand(DeviceCommandId_t
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue,
|
ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue, const uint8_t *commandData,
|
||||||
const uint8_t *commandData, size_t commandDataLen) {
|
size_t commandDataLen) {
|
||||||
RM3100::CycleCountCommand command(oneCycleValue);
|
RM3100::CycleCountCommand command(oneCycleValue);
|
||||||
ReturnValue_t result = command.deSerialize(&commandData, &commandDataLen,
|
ReturnValue_t result =
|
||||||
SerializeIF::Endianness::BIG);
|
command.deSerialize(&commandData, &commandDataLen, SerializeIF::Endianness::BIG);
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data sheet p.30 "while noise limits the useful upper range to ~400 cycle counts."
|
// Data sheet p.30 "while noise limits the useful upper range to ~400 cycle counts."
|
||||||
if(command.cycleCountX > 450 ) {
|
if (command.cycleCountX > 450) {
|
||||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(not oneCycleValue and (command.cycleCountY > 450 or command.cycleCountZ > 450)) {
|
if (not oneCycleValue and (command.cycleCountY > 450 or command.cycleCountZ > 450)) {
|
||||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,8 +282,9 @@ ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::handleTmrcConfigCommand(DeviceCommandId_t deviceCommand,
|
ReturnValue_t MgmRM3100Handler::handleTmrcConfigCommand(DeviceCommandId_t deviceCommand,
|
||||||
const uint8_t *commandData, size_t commandDataLen) {
|
const uint8_t *commandData,
|
||||||
if(commandData == nullptr or commandDataLen != 1) {
|
size_t commandDataLen) {
|
||||||
|
if (commandData == nullptr or commandDataLen != 1) {
|
||||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,12 +309,10 @@ void MgmRM3100Handler::fillCommandAndReplyMap() {
|
|||||||
insertInCommandAndReplyMap(RM3100::READ_DATA, 3, &primaryDataset);
|
insertInCommandAndReplyMap(RM3100::READ_DATA, 3, &primaryDataset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgmRM3100Handler::modeChanged(void) {
|
void MgmRM3100Handler::modeChanged(void) { internalState = InternalState::NONE; }
|
||||||
internalState = InternalState::NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(
|
ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
LocalDataPoolManager &poolManager) {
|
||||||
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
|
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
|
||||||
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
|
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
|
||||||
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
|
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
|
||||||
@ -331,9 +323,7 @@ uint32_t MgmRM3100Handler::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
|||||||
return this->transitionDelay;
|
return this->transitionDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MgmRM3100Handler::setToGoToNormalMode(bool enable) {
|
void MgmRM3100Handler::setToGoToNormalMode(bool enable) { goToNormalModeAtStartup = enable; }
|
||||||
goToNormalModeAtStartup = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
||||||
// Analyze data here. The sensor generates 24 bit signed values so we need to do some bitshift
|
// Analyze data here. The sensor generates 24 bit signed values so we need to do some bitshift
|
||||||
@ -348,10 +338,11 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
|||||||
float fieldStrengthZ = fieldStrengthRawZ * scaleFactorX;
|
float fieldStrengthZ = fieldStrengthRawZ * scaleFactorX;
|
||||||
|
|
||||||
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
||||||
if(debugDivider->checkAndIncrement()) {
|
if (debugDivider->checkAndIncrement()) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::info << "MgmRM3100Handler: Magnetic field strength in"
|
sif::info << "MgmRM3100Handler: Magnetic field strength in"
|
||||||
" microtesla:" << std::endl;
|
" microtesla:"
|
||||||
|
<< std::endl;
|
||||||
sif::info << "X: " << fieldStrengthX << " uT" << std::endl;
|
sif::info << "X: " << fieldStrengthX << " uT" << std::endl;
|
||||||
sif::info << "Y: " << fieldStrengthY << " uT" << std::endl;
|
sif::info << "Y: " << fieldStrengthY << " uT" << std::endl;
|
||||||
sif::info << "Z: " << fieldStrengthZ << " uT" << std::endl;
|
sif::info << "Z: " << fieldStrengthZ << " uT" << std::endl;
|
||||||
@ -366,7 +357,7 @@ 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() == HasReturnvaluesIF::RETURN_OK) {
|
if (readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||||
primaryDataset.fieldStrengthX = fieldStrengthX;
|
primaryDataset.fieldStrengthX = fieldStrengthX;
|
||||||
primaryDataset.fieldStrengthY = fieldStrengthY;
|
primaryDataset.fieldStrengthY = fieldStrengthY;
|
||||||
primaryDataset.fieldStrengthZ = fieldStrengthZ;
|
primaryDataset.fieldStrengthZ = fieldStrengthZ;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef MISSION_DEVICES_MGMRM3100HANDLER_H_
|
#ifndef MISSION_DEVICES_MGMRM3100HANDLER_H_
|
||||||
#define MISSION_DEVICES_MGMRM3100HANDLER_H_
|
#define MISSION_DEVICES_MGMRM3100HANDLER_H_
|
||||||
|
|
||||||
#include "fsfw/FSFW.h"
|
|
||||||
#include "devicedefinitions/MgmRM3100HandlerDefs.h"
|
#include "devicedefinitions/MgmRM3100HandlerDefs.h"
|
||||||
|
#include "fsfw/FSFW.h"
|
||||||
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
||||||
|
|
||||||
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
||||||
@ -16,22 +16,21 @@
|
|||||||
* Flight manual:
|
* Flight manual:
|
||||||
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/RM3100_MGM
|
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/RM3100_MGM
|
||||||
*/
|
*/
|
||||||
class MgmRM3100Handler: public DeviceHandlerBase {
|
class MgmRM3100Handler : public DeviceHandlerBase {
|
||||||
public:
|
public:
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::MGM_RM3100;
|
static const uint8_t INTERFACE_ID = CLASS_ID::MGM_RM3100;
|
||||||
|
|
||||||
//! [EXPORT] : [COMMENT] P1: TMRC value which was set, P2: 0
|
//! [EXPORT] : [COMMENT] P1: TMRC value which was set, P2: 0
|
||||||
static constexpr Event tmrcSet = event::makeEvent(SUBSYSTEM_ID::MGM_RM3100,
|
static constexpr Event tmrcSet = event::makeEvent(SUBSYSTEM_ID::MGM_RM3100, 0x00, severity::INFO);
|
||||||
0x00, severity::INFO);
|
|
||||||
|
|
||||||
//! [EXPORT] : [COMMENT] Cycle counter set. P1: First two bytes new Cycle Count X
|
//! [EXPORT] : [COMMENT] Cycle counter set. P1: First two bytes new Cycle Count X
|
||||||
//! P1: Second two bytes new Cycle Count Y
|
//! P1: Second two bytes new Cycle Count Y
|
||||||
//! P2: New cycle count Z
|
//! P2: New cycle count Z
|
||||||
static constexpr Event cycleCountersSet = event::makeEvent(
|
static constexpr Event cycleCountersSet =
|
||||||
SUBSYSTEM_ID::MGM_RM3100, 0x01, severity::INFO);
|
event::makeEvent(SUBSYSTEM_ID::MGM_RM3100, 0x01, severity::INFO);
|
||||||
|
|
||||||
MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication,
|
MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
|
||||||
CookieIF* comCookie, uint32_t transitionDelay);
|
uint32_t transitionDelay);
|
||||||
virtual ~MgmRM3100Handler();
|
virtual ~MgmRM3100Handler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,18 +39,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setToGoToNormalMode(bool enable);
|
void setToGoToNormalMode(bool enable);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/* DeviceHandlerBase overrides */
|
/* DeviceHandlerBase overrides */
|
||||||
ReturnValue_t buildTransitionDeviceCommand(
|
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
||||||
DeviceCommandId_t *id) override;
|
|
||||||
void doStartUp() override;
|
void doStartUp() override;
|
||||||
void doShutDown() override;
|
void doShutDown() override;
|
||||||
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
||||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||||
const uint8_t *commandData, size_t commandDataLen) override;
|
size_t commandDataLen) override;
|
||||||
ReturnValue_t scanForReply(const uint8_t *start, size_t len,
|
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
|
||||||
DeviceCommandId_t *foundId, size_t *foundLen) override;
|
size_t *foundLen) override;
|
||||||
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
||||||
|
|
||||||
void fillCommandAndReplyMap() override;
|
void fillCommandAndReplyMap() override;
|
||||||
@ -60,8 +57,7 @@ protected:
|
|||||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||||
LocalDataPoolManager &poolManager) override;
|
LocalDataPoolManager &poolManager) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
enum class InternalState {
|
enum class InternalState {
|
||||||
NONE,
|
NONE,
|
||||||
CONFIGURE_CMM,
|
CONFIGURE_CMM,
|
||||||
@ -94,16 +90,16 @@ private:
|
|||||||
uint32_t transitionDelay;
|
uint32_t transitionDelay;
|
||||||
|
|
||||||
ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
|
ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
|
||||||
const uint8_t *commandData,size_t commandDataLen);
|
|
||||||
ReturnValue_t handleCycleCommand(bool oneCycleValue,
|
|
||||||
const uint8_t *commandData, size_t commandDataLen);
|
const uint8_t *commandData, size_t commandDataLen);
|
||||||
|
ReturnValue_t handleCycleCommand(bool oneCycleValue, const uint8_t *commandData,
|
||||||
|
size_t commandDataLen);
|
||||||
|
|
||||||
ReturnValue_t handleTmrcConfigCommand(DeviceCommandId_t deviceCommand,
|
ReturnValue_t handleTmrcConfigCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||||
const uint8_t *commandData,size_t commandDataLen);
|
size_t commandDataLen);
|
||||||
|
|
||||||
ReturnValue_t handleDataReadout(const uint8_t* packet);
|
ReturnValue_t handleDataReadout(const uint8_t *packet);
|
||||||
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
|
||||||
PeriodicOperationDivider* debugDivider;
|
PeriodicOperationDivider *debugDivider;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace L3GD20H {
|
namespace L3GD20H {
|
||||||
@ -36,8 +37,8 @@ static constexpr uint8_t SET_Z_ENABLE = 1 << 2;
|
|||||||
static constexpr uint8_t SET_X_ENABLE = 1 << 1;
|
static constexpr uint8_t SET_X_ENABLE = 1 << 1;
|
||||||
static constexpr uint8_t SET_Y_ENABLE = 1;
|
static constexpr uint8_t SET_Y_ENABLE = 1;
|
||||||
|
|
||||||
static constexpr uint8_t CTRL_REG_1_VAL = SET_POWER_NORMAL_MODE | SET_Z_ENABLE |
|
static constexpr uint8_t CTRL_REG_1_VAL =
|
||||||
SET_Y_ENABLE | SET_X_ENABLE;
|
SET_POWER_NORMAL_MODE | SET_Z_ENABLE | SET_Y_ENABLE | SET_X_ENABLE;
|
||||||
|
|
||||||
/* Register 2 */
|
/* Register 2 */
|
||||||
static constexpr uint8_t EXTERNAL_EDGE_ENB = 1 << 7;
|
static constexpr uint8_t EXTERNAL_EDGE_ENB = 1 << 7;
|
||||||
@ -104,40 +105,29 @@ static constexpr DeviceCommandId_t READ_CTRL_REGS = 2;
|
|||||||
|
|
||||||
static constexpr uint32_t GYRO_DATASET_ID = READ_REGS;
|
static constexpr uint32_t GYRO_DATASET_ID = READ_REGS;
|
||||||
|
|
||||||
enum GyroPoolIds: lp_id_t {
|
enum GyroPoolIds : lp_id_t { ANG_VELOC_X, ANG_VELOC_Y, ANG_VELOC_Z, TEMPERATURE };
|
||||||
ANG_VELOC_X,
|
|
||||||
ANG_VELOC_Y,
|
|
||||||
ANG_VELOC_Z,
|
|
||||||
TEMPERATURE
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
} // namespace L3GD20H
|
||||||
|
|
||||||
class GyroPrimaryDataset: public StaticLocalDataSet<5> {
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
class GyroPrimaryDataset : public StaticLocalDataSet<5> {
|
||||||
|
public:
|
||||||
/** Constructor for data users like controllers */
|
/** Constructor for data users like controllers */
|
||||||
GyroPrimaryDataset(object_id_t mgmId):
|
GyroPrimaryDataset(object_id_t mgmId)
|
||||||
StaticLocalDataSet(sid_t(mgmId, L3GD20H::GYRO_DATASET_ID)) {
|
: StaticLocalDataSet(sid_t(mgmId, L3GD20H::GYRO_DATASET_ID)) {
|
||||||
setAllVariablesReadOnly();
|
setAllVariablesReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Angular velocities in degrees per second (DPS) */
|
/* Angular velocities in degrees per second (DPS) */
|
||||||
lp_var_t<float> angVelocX = lp_var_t<float>(sid.objectId,
|
lp_var_t<float> angVelocX = lp_var_t<float>(sid.objectId, L3GD20H::ANG_VELOC_X, this);
|
||||||
L3GD20H::ANG_VELOC_X, this);
|
lp_var_t<float> angVelocY = lp_var_t<float>(sid.objectId, L3GD20H::ANG_VELOC_Y, this);
|
||||||
lp_var_t<float> angVelocY = lp_var_t<float>(sid.objectId,
|
lp_var_t<float> angVelocZ = lp_var_t<float>(sid.objectId, L3GD20H::ANG_VELOC_Z, this);
|
||||||
L3GD20H::ANG_VELOC_Y, this);
|
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, L3GD20H::TEMPERATURE, this);
|
||||||
lp_var_t<float> angVelocZ = lp_var_t<float>(sid.objectId,
|
|
||||||
L3GD20H::ANG_VELOC_Z, this);
|
|
||||||
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId,
|
|
||||||
L3GD20H::TEMPERATURE, this);
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
friend class GyroHandlerL3GD20H;
|
friend class GyroHandlerL3GD20H;
|
||||||
/** Constructor for the data creator */
|
/** Constructor for the data creator */
|
||||||
GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner)
|
||||||
StaticLocalDataSet(hkOwner, L3GD20H::GYRO_DATASET_ID) {}
|
: StaticLocalDataSet(hkOwner, L3GD20H::GYRO_DATASET_ID) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_ */
|
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_ */
|
||||||
|
@ -1,26 +1,18 @@
|
|||||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_
|
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_
|
||||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_
|
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_
|
||||||
|
|
||||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
|
||||||
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
||||||
|
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace MGMLIS3MDL {
|
namespace MGMLIS3MDL {
|
||||||
|
|
||||||
enum Set {
|
enum Set { ON, OFF };
|
||||||
ON, OFF
|
enum OpMode { LOW, MEDIUM, HIGH, ULTRA };
|
||||||
};
|
|
||||||
enum OpMode {
|
|
||||||
LOW, MEDIUM, HIGH, ULTRA
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Sensitivies: uint8_t {
|
enum Sensitivies : uint8_t { GAUSS_4 = 4, GAUSS_8 = 8, GAUSS_12 = 12, GAUSS_16 = 16 };
|
||||||
GAUSS_4 = 4,
|
|
||||||
GAUSS_8 = 8,
|
|
||||||
GAUSS_12 = 12,
|
|
||||||
GAUSS_16 = 16
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Actually 15, we just round up a bit */
|
/* Actually 15, we just round up a bit */
|
||||||
static constexpr size_t MAX_BUFFER_SIZE = 16;
|
static constexpr size_t MAX_BUFFER_SIZE = 16;
|
||||||
@ -114,65 +106,58 @@ static const uint8_t DO2 = 4; // Output data rate bit 4
|
|||||||
static const uint8_t OM0 = 5; // XY operating mode bit 5
|
static const uint8_t OM0 = 5; // XY operating mode bit 5
|
||||||
static const uint8_t OM1 = 6; // XY operating mode bit 6
|
static const uint8_t OM1 = 6; // XY operating mode bit 6
|
||||||
static const uint8_t TEMP_EN = 7; // Temperature sensor enable enabled = 1
|
static const uint8_t TEMP_EN = 7; // Temperature sensor enable enabled = 1
|
||||||
static const uint8_t CTRL_REG1_DEFAULT = (1 << TEMP_EN) | (1 << OM1) |
|
static const uint8_t CTRL_REG1_DEFAULT =
|
||||||
(1 << DO0) | (1 << DO1) | (1 << DO2);
|
(1 << TEMP_EN) | (1 << OM1) | (1 << DO0) | (1 << DO1) | (1 << DO2);
|
||||||
|
|
||||||
/* CTRL_REG2 bits */
|
/* CTRL_REG2 bits */
|
||||||
//reset configuration registers and user registers
|
// reset configuration registers and user registers
|
||||||
static const uint8_t SOFT_RST = 2;
|
static const uint8_t SOFT_RST = 2;
|
||||||
static const uint8_t REBOOT = 3; //reboot memory content
|
static const uint8_t REBOOT = 3; // reboot memory content
|
||||||
static const uint8_t FSO = 5; //full-scale selection bit 5
|
static const uint8_t FSO = 5; // full-scale selection bit 5
|
||||||
static const uint8_t FS1 = 6; //full-scale selection bit 6
|
static const uint8_t FS1 = 6; // full-scale selection bit 6
|
||||||
static const uint8_t CTRL_REG2_DEFAULT = 0;
|
static const uint8_t CTRL_REG2_DEFAULT = 0;
|
||||||
|
|
||||||
/* CTRL_REG3 bits */
|
/* CTRL_REG3 bits */
|
||||||
static const uint8_t MD0 = 0; //Operating mode bit 0
|
static const uint8_t MD0 = 0; // Operating mode bit 0
|
||||||
static const uint8_t MD1 = 1; //Operating mode bit 1
|
static const uint8_t MD1 = 1; // Operating mode bit 1
|
||||||
//SPI serial interface mode selection enabled = 3-wire-mode
|
// SPI serial interface mode selection enabled = 3-wire-mode
|
||||||
static const uint8_t SIM = 2;
|
static const uint8_t SIM = 2;
|
||||||
static const uint8_t LP = 5; //low-power mode
|
static const uint8_t LP = 5; // low-power mode
|
||||||
static const uint8_t CTRL_REG3_DEFAULT = 0;
|
static const uint8_t CTRL_REG3_DEFAULT = 0;
|
||||||
|
|
||||||
/* CTRL_REG4 bits */
|
/* CTRL_REG4 bits */
|
||||||
//big/little endian data selection enabled = MSb at lower adress
|
// big/little endian data selection enabled = MSb at lower adress
|
||||||
static const uint8_t BLE = 1;
|
static const uint8_t BLE = 1;
|
||||||
static const uint8_t OMZ0 = 2; //Z operating mode bit 2
|
static const uint8_t OMZ0 = 2; // Z operating mode bit 2
|
||||||
static const uint8_t OMZ1 = 3; //Z operating mode bit 3
|
static const uint8_t OMZ1 = 3; // Z operating mode bit 3
|
||||||
static const uint8_t CTRL_REG4_DEFAULT = (1 << OMZ1);
|
static const uint8_t CTRL_REG4_DEFAULT = (1 << OMZ1);
|
||||||
|
|
||||||
/* CTRL_REG5 bits */
|
/* CTRL_REG5 bits */
|
||||||
static const uint8_t BDU = 6; //Block data update
|
static const uint8_t BDU = 6; // Block data update
|
||||||
static const uint8_t FAST_READ = 7; //Fast read enabled = 1
|
static const uint8_t FAST_READ = 7; // Fast read enabled = 1
|
||||||
static const uint8_t CTRL_REG5_DEFAULT = 0;
|
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 {
|
enum MgmPoolIds : lp_id_t {
|
||||||
FIELD_STRENGTH_X,
|
FIELD_STRENGTH_X,
|
||||||
FIELD_STRENGTH_Y,
|
FIELD_STRENGTH_Y,
|
||||||
FIELD_STRENGTH_Z,
|
FIELD_STRENGTH_Z,
|
||||||
TEMPERATURE_CELCIUS
|
TEMPERATURE_CELCIUS
|
||||||
};
|
};
|
||||||
|
|
||||||
class MgmPrimaryDataset: public StaticLocalDataSet<4> {
|
class MgmPrimaryDataset : public StaticLocalDataSet<4> {
|
||||||
public:
|
public:
|
||||||
MgmPrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
MgmPrimaryDataset(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, MGM_DATA_SET_ID) {}
|
||||||
StaticLocalDataSet(hkOwner, MGM_DATA_SET_ID) {}
|
|
||||||
|
|
||||||
MgmPrimaryDataset(object_id_t mgmId):
|
MgmPrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
|
||||||
StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
|
|
||||||
|
|
||||||
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId,
|
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_X, this);
|
||||||
FIELD_STRENGTH_X, this);
|
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Y, this);
|
||||||
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId,
|
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Z, this);
|
||||||
FIELD_STRENGTH_Y, this);
|
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, TEMPERATURE_CELCIUS, this);
|
||||||
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId,
|
|
||||||
FIELD_STRENGTH_Z, this);
|
|
||||||
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId,
|
|
||||||
TEMPERATURE_CELCIUS, this);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace MGMLIS3MDL
|
||||||
|
|
||||||
|
|
||||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_ */
|
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_ */
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
|
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
|
||||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
|
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
|
||||||
|
|
||||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
|
||||||
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
||||||
|
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||||
#include <fsfw/serialize/SerialLinkedListAdapter.h>
|
#include <fsfw/serialize/SerialLinkedListAdapter.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace RM3100 {
|
namespace RM3100 {
|
||||||
@ -24,8 +25,8 @@ static constexpr uint8_t SET_CMM_DRDM = 1 << 2;
|
|||||||
static constexpr uint8_t SET_CMM_START = 1;
|
static constexpr uint8_t SET_CMM_START = 1;
|
||||||
static constexpr uint8_t CMM_REGISTER = 0x01;
|
static constexpr uint8_t CMM_REGISTER = 0x01;
|
||||||
|
|
||||||
static constexpr uint8_t CMM_VALUE = SET_CMM_CMZ | SET_CMM_CMY | SET_CMM_CMX |
|
static constexpr uint8_t CMM_VALUE =
|
||||||
SET_CMM_DRDM | SET_CMM_START;
|
SET_CMM_CMZ | SET_CMM_CMY | SET_CMM_CMX | SET_CMM_DRDM | SET_CMM_START;
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Cycle count register */
|
/* Cycle count register */
|
||||||
@ -33,8 +34,7 @@ static constexpr uint8_t CMM_VALUE = SET_CMM_CMZ | SET_CMM_CMY | SET_CMM_CMX |
|
|||||||
// Default value (200)
|
// Default value (200)
|
||||||
static constexpr uint8_t CYCLE_COUNT_VALUE = 0xC8;
|
static constexpr uint8_t CYCLE_COUNT_VALUE = 0xC8;
|
||||||
|
|
||||||
static constexpr float DEFAULT_GAIN = static_cast<float>(CYCLE_COUNT_VALUE) /
|
static constexpr float DEFAULT_GAIN = static_cast<float>(CYCLE_COUNT_VALUE) / 100 * 38;
|
||||||
100 * 38;
|
|
||||||
static constexpr uint8_t CYCLE_COUNT_START_REGISTER = 0x04;
|
static constexpr uint8_t CYCLE_COUNT_START_REGISTER = 0x04;
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@ -67,17 +67,16 @@ static constexpr DeviceCommandId_t READ_TMRC = 4;
|
|||||||
static constexpr DeviceCommandId_t CONFIGURE_CYCLE_COUNT = 5;
|
static constexpr DeviceCommandId_t CONFIGURE_CYCLE_COUNT = 5;
|
||||||
static constexpr DeviceCommandId_t READ_CYCLE_COUNT = 6;
|
static constexpr DeviceCommandId_t READ_CYCLE_COUNT = 6;
|
||||||
|
|
||||||
class CycleCountCommand: public SerialLinkedListAdapter<SerializeIF> {
|
class CycleCountCommand : public SerialLinkedListAdapter<SerializeIF> {
|
||||||
public:
|
public:
|
||||||
CycleCountCommand(bool oneCycleCount = true): oneCycleCount(oneCycleCount) {
|
CycleCountCommand(bool oneCycleCount = true) : oneCycleCount(oneCycleCount) {
|
||||||
setLinks(oneCycleCount);
|
setLinks(oneCycleCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
Endianness streamEndianness) override {
|
Endianness streamEndianness) override {
|
||||||
ReturnValue_t result = SerialLinkedListAdapter::deSerialize(buffer,
|
ReturnValue_t result = SerialLinkedListAdapter::deSerialize(buffer, size, streamEndianness);
|
||||||
size, streamEndianness);
|
if (oneCycleCount) {
|
||||||
if(oneCycleCount) {
|
|
||||||
cycleCountY = cycleCountX;
|
cycleCountY = cycleCountX;
|
||||||
cycleCountZ = cycleCountX;
|
cycleCountZ = cycleCountX;
|
||||||
}
|
}
|
||||||
@ -88,10 +87,10 @@ public:
|
|||||||
SerializeElement<uint16_t> cycleCountY;
|
SerializeElement<uint16_t> cycleCountY;
|
||||||
SerializeElement<uint16_t> cycleCountZ;
|
SerializeElement<uint16_t> cycleCountZ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setLinks(bool oneCycleCount) {
|
void setLinks(bool oneCycleCount) {
|
||||||
setStart(&cycleCountX);
|
setStart(&cycleCountX);
|
||||||
if(not oneCycleCount) {
|
if (not oneCycleCount) {
|
||||||
cycleCountX.setNext(&cycleCountY);
|
cycleCountX.setNext(&cycleCountY);
|
||||||
cycleCountY.setNext(&cycleCountZ);
|
cycleCountY.setNext(&cycleCountZ);
|
||||||
}
|
}
|
||||||
@ -102,31 +101,24 @@ private:
|
|||||||
|
|
||||||
static constexpr uint32_t MGM_DATASET_ID = READ_DATA;
|
static constexpr uint32_t MGM_DATASET_ID = READ_DATA;
|
||||||
|
|
||||||
enum MgmPoolIds: lp_id_t {
|
enum MgmPoolIds : lp_id_t {
|
||||||
FIELD_STRENGTH_X,
|
FIELD_STRENGTH_X,
|
||||||
FIELD_STRENGTH_Y,
|
FIELD_STRENGTH_Y,
|
||||||
FIELD_STRENGTH_Z,
|
FIELD_STRENGTH_Z,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Rm3100PrimaryDataset: public StaticLocalDataSet<3> {
|
class Rm3100PrimaryDataset : public StaticLocalDataSet<3> {
|
||||||
public:
|
public:
|
||||||
Rm3100PrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
Rm3100PrimaryDataset(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, MGM_DATASET_ID) {}
|
||||||
StaticLocalDataSet(hkOwner, MGM_DATASET_ID) {}
|
|
||||||
|
|
||||||
Rm3100PrimaryDataset(object_id_t mgmId):
|
Rm3100PrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {}
|
||||||
StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {}
|
|
||||||
|
|
||||||
// Field strengths in micro Tesla.
|
// Field strengths in micro Tesla.
|
||||||
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId,
|
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_X, this);
|
||||||
FIELD_STRENGTH_X, this);
|
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Y, this);
|
||||||
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId,
|
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Z, this);
|
||||||
FIELD_STRENGTH_Y, this);
|
|
||||||
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId,
|
|
||||||
FIELD_STRENGTH_Z, this);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace RM3100
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_ */
|
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_ */
|
||||||
|
@ -4,11 +4,13 @@ endif()
|
|||||||
|
|
||||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
UnixFileGuard.cpp
|
UnixFileGuard.cpp
|
||||||
|
CommandExecutor.cpp
|
||||||
utility.cpp
|
utility.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(gpio)
|
if(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS)
|
||||||
add_subdirectory(spi)
|
add_subdirectory(gpio)
|
||||||
add_subdirectory(i2c)
|
add_subdirectory(spi)
|
||||||
add_subdirectory(uart)
|
add_subdirectory(i2c)
|
||||||
add_subdirectory(uio)
|
add_subdirectory(uart)
|
||||||
|
endif()
|
||||||
|
207
hal/src/fsfw_hal/linux/CommandExecutor.cpp
Normal file
207
hal/src/fsfw_hal/linux/CommandExecutor.cpp
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
#include "CommandExecutor.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "fsfw/container/DynamicFIFO.h"
|
||||||
|
#include "fsfw/container/SimpleRingBuffer.h"
|
||||||
|
#include "fsfw/serviceinterface.h"
|
||||||
|
|
||||||
|
CommandExecutor::CommandExecutor(const size_t maxSize) : readVec(maxSize) {
|
||||||
|
waiter.events = POLLIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CommandExecutor::load(std::string command, bool blocking, bool printOutput) {
|
||||||
|
if (state == States::PENDING) {
|
||||||
|
return COMMAND_PENDING;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentCmd = command;
|
||||||
|
this->blocking = blocking;
|
||||||
|
this->printOutput = printOutput;
|
||||||
|
if (state == States::IDLE) {
|
||||||
|
state = States::COMMAND_LOADED;
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CommandExecutor::execute() {
|
||||||
|
if (state == States::IDLE) {
|
||||||
|
return NO_COMMAND_LOADED_OR_PENDING;
|
||||||
|
} else if (state == States::PENDING) {
|
||||||
|
return COMMAND_PENDING;
|
||||||
|
}
|
||||||
|
currentCmdFile = popen(currentCmd.c_str(), "r");
|
||||||
|
if (currentCmdFile == nullptr) {
|
||||||
|
lastError = errno;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
if (blocking) {
|
||||||
|
ReturnValue_t result = executeBlocking();
|
||||||
|
state = States::IDLE;
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
currentFd = fileno(currentCmdFile);
|
||||||
|
waiter.fd = currentFd;
|
||||||
|
}
|
||||||
|
state = States::PENDING;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CommandExecutor::close() {
|
||||||
|
if (state == States::PENDING) {
|
||||||
|
// Attempt to close process, irrespective of if it is running or not
|
||||||
|
if (currentCmdFile != nullptr) {
|
||||||
|
pclose(currentCmdFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandExecutor::printLastError(std::string funcName) const {
|
||||||
|
if (lastError != 0) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << funcName << " pclose failed with code " << lastError << ": "
|
||||||
|
<< strerror(lastError) << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printError("%s pclose failed with code %d: %s\n", funcName, lastError,
|
||||||
|
strerror(lastError));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandExecutor::setRingBuffer(SimpleRingBuffer* ringBuffer,
|
||||||
|
DynamicFIFO<uint16_t>* sizesFifo) {
|
||||||
|
this->ringBuffer = ringBuffer;
|
||||||
|
this->sizesFifo = sizesFifo;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CommandExecutor::check(bool& replyReceived) {
|
||||||
|
if (blocking) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
switch (state) {
|
||||||
|
case (States::IDLE):
|
||||||
|
case (States::COMMAND_LOADED): {
|
||||||
|
return NO_COMMAND_LOADED_OR_PENDING;
|
||||||
|
}
|
||||||
|
case (States::PENDING): {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int result = poll(&waiter, 1, 0);
|
||||||
|
switch (result) {
|
||||||
|
case (0): {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (1): {
|
||||||
|
if (waiter.revents & POLLIN) {
|
||||||
|
ssize_t readBytes = read(currentFd, readVec.data(), readVec.size());
|
||||||
|
if (readBytes == 0) {
|
||||||
|
// Should not happen
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "CommandExecutor::check: No bytes read "
|
||||||
|
"after poll event.."
|
||||||
|
<< std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("CommandExecutor::check: No bytes read after poll event..\n");
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
} else if (readBytes > 0) {
|
||||||
|
replyReceived = true;
|
||||||
|
if (printOutput) {
|
||||||
|
// It is assumed the command output is line terminated
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::info << currentCmd << " | " << readVec.data();
|
||||||
|
#else
|
||||||
|
sif::printInfo("%s | %s", currentCmd, readVec.data());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (ringBuffer != nullptr) {
|
||||||
|
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(readVec.data()), readBytes);
|
||||||
|
}
|
||||||
|
if (sizesFifo != nullptr) {
|
||||||
|
if (not sizesFifo->full()) {
|
||||||
|
sizesFifo->insert(readBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Should also not happen
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "CommandExecutor::check: Error " << errno << ": " << strerror(errno)
|
||||||
|
<< std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("CommandExecutor::check: Error %d: %s\n", errno, strerror(errno));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (waiter.revents & POLLERR) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "CommandExecuter::check: Poll error" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("CommandExecuter::check: Poll error\n");
|
||||||
|
#endif
|
||||||
|
return COMMAND_ERROR;
|
||||||
|
}
|
||||||
|
if (waiter.revents & POLLHUP) {
|
||||||
|
result = pclose(currentCmdFile);
|
||||||
|
ReturnValue_t retval = EXECUTION_FINISHED;
|
||||||
|
if (result != 0) {
|
||||||
|
lastError = result;
|
||||||
|
retval = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
state = States::IDLE;
|
||||||
|
currentCmdFile = nullptr;
|
||||||
|
currentFd = 0;
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandExecutor::reset() {
|
||||||
|
CommandExecutor::close();
|
||||||
|
currentCmdFile = nullptr;
|
||||||
|
currentFd = 0;
|
||||||
|
state = States::IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CommandExecutor::getLastError() const {
|
||||||
|
// See:
|
||||||
|
// https://stackoverflow.com/questions/808541/any-benefit-in-using-wexitstatus-macro-in-c-over-division-by-256-on-exit-statu
|
||||||
|
return WEXITSTATUS(this->lastError);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandExecutor::States CommandExecutor::getCurrentState() const { return state; }
|
||||||
|
|
||||||
|
ReturnValue_t CommandExecutor::executeBlocking() {
|
||||||
|
while (fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
|
||||||
|
std::string output(readVec.data());
|
||||||
|
if (printOutput) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::info << currentCmd << " | " << output;
|
||||||
|
#else
|
||||||
|
sif::printInfo("%s | %s", currentCmd, output);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (ringBuffer != nullptr) {
|
||||||
|
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size());
|
||||||
|
}
|
||||||
|
if (sizesFifo != nullptr) {
|
||||||
|
if (not sizesFifo->full()) {
|
||||||
|
sizesFifo->insert(output.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int result = pclose(currentCmdFile);
|
||||||
|
if (result != 0) {
|
||||||
|
lastError = result;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
129
hal/src/fsfw_hal/linux/CommandExecutor.h
Normal file
129
hal/src/fsfw_hal/linux/CommandExecutor.h
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
#ifndef FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
|
||||||
|
#define FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
|
||||||
|
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "fsfw/returnvalues/FwClassIds.h"
|
||||||
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
|
||||||
|
class SimpleRingBuffer;
|
||||||
|
template <typename T>
|
||||||
|
class DynamicFIFO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper class to execute shell commands in blocking and non-blocking mode
|
||||||
|
* @details
|
||||||
|
* This class is able to execute processes by using the Linux popen call. It also has the
|
||||||
|
* capability of writing the read output of a process into a provided ring buffer.
|
||||||
|
*
|
||||||
|
* The executor works by first loading the command which should be executed and specifying
|
||||||
|
* whether it should be executed blocking or non-blocking. After that, execution can be started
|
||||||
|
* with the execute command. In blocking mode, the execute command will block until the command
|
||||||
|
* has finished
|
||||||
|
*/
|
||||||
|
class CommandExecutor {
|
||||||
|
public:
|
||||||
|
enum class States { IDLE, COMMAND_LOADED, PENDING };
|
||||||
|
|
||||||
|
static constexpr uint8_t CLASS_ID = CLASS_ID::LINUX_OSAL;
|
||||||
|
|
||||||
|
//! [EXPORT] : [COMMENT] Execution of the current command has finished
|
||||||
|
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
|
||||||
|
//! to load another command but a command is still pending
|
||||||
|
static constexpr ReturnValue_t COMMAND_PENDING = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
|
||||||
|
//! [EXPORT] : [COMMENT] Some bytes have been read from the executing process
|
||||||
|
static constexpr ReturnValue_t BYTES_READ = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2);
|
||||||
|
//! [EXPORT] : [COMMENT] Command execution failed
|
||||||
|
static constexpr ReturnValue_t COMMAND_ERROR = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3);
|
||||||
|
//! [EXPORT] : [COMMENT]
|
||||||
|
static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING =
|
||||||
|
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
|
||||||
|
* executed process.
|
||||||
|
* @param maxSize
|
||||||
|
*/
|
||||||
|
CommandExecutor(const size_t maxSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a new command which should be executed
|
||||||
|
* @param command
|
||||||
|
* @param blocking
|
||||||
|
* @param printOutput
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t load(std::string command, bool blocking, bool printOutput = true);
|
||||||
|
/**
|
||||||
|
* Execute the loaded command.
|
||||||
|
* @return
|
||||||
|
* - 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
|
||||||
|
* getLastError
|
||||||
|
* - In non-blocking mode, this call will start
|
||||||
|
* the execution and then return RETURN_OK
|
||||||
|
*/
|
||||||
|
ReturnValue_t execute();
|
||||||
|
/**
|
||||||
|
* Only used in non-blocking mode. Checks the currently running command.
|
||||||
|
* @param bytesRead Will be set to the number of bytes read, if bytes have been read
|
||||||
|
* @return
|
||||||
|
* - BYTES_READ if bytes have been read from the executing process. It is recommended to call
|
||||||
|
* check again after this
|
||||||
|
* - RETURN_OK execution is pending, but no bytes have been read from the executing process
|
||||||
|
* - RETURN_FAILED if execution has failed, error value can be accessed using getLastError
|
||||||
|
* - EXECUTION_FINISHED if the process was executed successfully
|
||||||
|
* - NO_COMMAND_LOADED_OR_PENDING self-explanatory
|
||||||
|
* - COMMAND_ERROR internal poll error
|
||||||
|
*/
|
||||||
|
ReturnValue_t check(bool& replyReceived);
|
||||||
|
/**
|
||||||
|
* Abort the current command. Should normally not be necessary, check can be used to find
|
||||||
|
* out whether command execution was successful
|
||||||
|
* @return RETURN_OK
|
||||||
|
*/
|
||||||
|
ReturnValue_t close();
|
||||||
|
|
||||||
|
States getCurrentState() const;
|
||||||
|
int getLastError() const;
|
||||||
|
void printLastError(std::string funcName) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign a ring buffer and a FIFO which will be filled by the executor with the output
|
||||||
|
* read from the started process
|
||||||
|
* @param ringBuffer
|
||||||
|
* @param sizesFifo
|
||||||
|
*/
|
||||||
|
void setRingBuffer(SimpleRingBuffer* ringBuffer, DynamicFIFO<uint16_t>* sizesFifo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the executor. This calls close internally and then reset the state machine so new
|
||||||
|
* commands can be loaded and executed
|
||||||
|
*/
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string currentCmd;
|
||||||
|
bool blocking = true;
|
||||||
|
FILE* currentCmdFile = nullptr;
|
||||||
|
int currentFd = 0;
|
||||||
|
bool printOutput = true;
|
||||||
|
std::vector<char> readVec;
|
||||||
|
struct pollfd waiter {};
|
||||||
|
SimpleRingBuffer* ringBuffer = nullptr;
|
||||||
|
DynamicFIFO<uint16_t>* sizesFifo = nullptr;
|
||||||
|
|
||||||
|
States state = States::IDLE;
|
||||||
|
int lastError = 0;
|
||||||
|
|
||||||
|
ReturnValue_t executeBlocking();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_ */
|
@ -1,25 +1,26 @@
|
|||||||
#include "fsfw/FSFW.h"
|
|
||||||
#include "fsfw/serviceinterface.h"
|
|
||||||
#include "fsfw_hal/linux/UnixFileGuard.h"
|
#include "fsfw_hal/linux/UnixFileGuard.h"
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "fsfw/FSFW.h"
|
||||||
|
#include "fsfw/serviceinterface.h"
|
||||||
|
|
||||||
UnixFileGuard::UnixFileGuard(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) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*fileDescriptor = open(device.c_str(), flags);
|
*fileDescriptor = open(device.c_str(), flags);
|
||||||
if (*fileDescriptor < 0) {
|
if (*fileDescriptor < 0) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << diagnosticPrefix << ": Opening device failed with error code " <<
|
sif::warning << diagnosticPrefix << ": Opening device failed with error code " << errno << ": "
|
||||||
errno << ": " << strerror(errno) << std::endl;
|
<< strerror(errno) << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("%s: Opening device failed with error code %d: %s\n",
|
sif::printWarning("%s: Opening device failed with error code %d: %s\n", diagnosticPrefix, errno,
|
||||||
diagnosticPrefix, errno, strerror(errno));
|
strerror(errno));
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||||
openStatus = OPEN_FILE_FAILED;
|
openStatus = OPEN_FILE_FAILED;
|
||||||
@ -27,11 +28,9 @@ UnixFileGuard::UnixFileGuard(std::string device, int* fileDescriptor, int flags,
|
|||||||
}
|
}
|
||||||
|
|
||||||
UnixFileGuard::~UnixFileGuard() {
|
UnixFileGuard::~UnixFileGuard() {
|
||||||
if(fileDescriptor != nullptr) {
|
if (fileDescriptor != nullptr) {
|
||||||
close(*fileDescriptor);
|
close(*fileDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UnixFileGuard::getOpenResult() const {
|
ReturnValue_t UnixFileGuard::getOpenResult() const { return openStatus; }
|
||||||
return openStatus;
|
|
||||||
}
|
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
#ifndef LINUX_UTILITY_UNIXFILEGUARD_H_
|
#ifndef LINUX_UTILITY_UNIXFILEGUARD_H_
|
||||||
#define LINUX_UTILITY_UNIXFILEGUARD_H_
|
#define LINUX_UTILITY_UNIXFILEGUARD_H_
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
|
|
||||||
class UnixFileGuard {
|
class UnixFileGuard {
|
||||||
public:
|
public:
|
||||||
static constexpr int READ_WRITE_FLAG = O_RDWR;
|
static constexpr int READ_WRITE_FLAG = O_RDWR;
|
||||||
static constexpr int READ_ONLY_FLAG = O_RDONLY;
|
static constexpr int READ_ONLY_FLAG = O_RDONLY;
|
||||||
static constexpr int NON_BLOCKING_IO_FLAG = O_NONBLOCK;
|
static constexpr int NON_BLOCKING_IO_FLAG = O_NONBLOCK;
|
||||||
@ -20,14 +18,13 @@ public:
|
|||||||
UnixFileGuard(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();
|
||||||
|
|
||||||
ReturnValue_t getOpenResult() const;
|
ReturnValue_t getOpenResult() const;
|
||||||
private:
|
|
||||||
|
private:
|
||||||
int* fileDescriptor = nullptr;
|
int* fileDescriptor = nullptr;
|
||||||
ReturnValue_t openStatus = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t openStatus = HasReturnvaluesIF::RETURN_OK;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* LINUX_UTILITY_UNIXFILEGUARD_H_ */
|
#endif /* LINUX_UTILITY_UNIXFILEGUARD_H_ */
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
|
||||||
LinuxLibgpioIF.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
# This abstraction layer requires the gpiod library. You can install this library
|
# 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
|
# 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.
|
# to install the package before syncing the sysroot to your host computer.
|
||||||
find_library(LIB_GPIO gpiod REQUIRED)
|
find_library(LIB_GPIO gpiod)
|
||||||
|
|
||||||
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
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}
|
${LIB_GPIO}
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
@ -1,26 +1,25 @@
|
|||||||
#include "LinuxLibgpioIF.h"
|
#include "LinuxLibgpioIF.h"
|
||||||
|
|
||||||
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
|
#include <gpiod.h>
|
||||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <unistd.h>
|
|
||||||
#include <gpiod.h>
|
|
||||||
|
|
||||||
LinuxLibgpioIF::LinuxLibgpioIF(object_id_t objectId) : SystemObject(objectId) {
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
}
|
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||||
|
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
|
||||||
|
|
||||||
|
LinuxLibgpioIF::LinuxLibgpioIF(object_id_t objectId) : SystemObject(objectId) {}
|
||||||
|
|
||||||
LinuxLibgpioIF::~LinuxLibgpioIF() {
|
LinuxLibgpioIF::~LinuxLibgpioIF() {
|
||||||
for(auto& config: gpioMap) {
|
for (auto& config : gpioMap) {
|
||||||
delete(config.second);
|
delete (config.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
|
ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
|
||||||
ReturnValue_t result;
|
ReturnValue_t result;
|
||||||
if(gpioCookie == nullptr) {
|
if (gpioCookie == nullptr) {
|
||||||
sif::error << "LinuxLibgpioIF::addGpios: Invalid cookie" << std::endl;
|
sif::error << "LinuxLibgpioIF::addGpios: Invalid cookie" << std::endl;
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -29,7 +28,7 @@ ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
|
|||||||
|
|
||||||
/* 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 != RETURN_OK){
|
if (result != RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,39 +44,39 @@ ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
||||||
for(auto& gpioConfig: mapToAdd) {
|
for (auto& gpioConfig : mapToAdd) {
|
||||||
auto& gpioType = gpioConfig.second->gpioType;
|
auto& gpioType = gpioConfig.second->gpioType;
|
||||||
switch(gpioType) {
|
switch (gpioType) {
|
||||||
case(gpio::GpioTypes::NONE): {
|
case (gpio::GpioTypes::NONE): {
|
||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP): {
|
case (gpio::GpioTypes::GPIO_REGULAR_BY_CHIP): {
|
||||||
auto regularGpio = dynamic_cast<GpiodRegularByChip*>(gpioConfig.second);
|
auto regularGpio = dynamic_cast<GpiodRegularByChip*>(gpioConfig.second);
|
||||||
if(regularGpio == nullptr) {
|
if (regularGpio == nullptr) {
|
||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
configureGpioByChip(gpioConfig.first, *regularGpio);
|
configureGpioByChip(gpioConfig.first, *regularGpio);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):{
|
case (gpio::GpioTypes::GPIO_REGULAR_BY_LABEL): {
|
||||||
auto regularGpio = dynamic_cast<GpiodRegularByLabel*>(gpioConfig.second);
|
auto regularGpio = dynamic_cast<GpiodRegularByLabel*>(gpioConfig.second);
|
||||||
if(regularGpio == nullptr) {
|
if (regularGpio == nullptr) {
|
||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
configureGpioByLabel(gpioConfig.first, *regularGpio);
|
configureGpioByLabel(gpioConfig.first, *regularGpio);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME):{
|
case (gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
|
||||||
auto regularGpio = dynamic_cast<GpiodRegularByLineName*>(gpioConfig.second);
|
auto regularGpio = dynamic_cast<GpiodRegularByLineName*>(gpioConfig.second);
|
||||||
if(regularGpio == nullptr) {
|
if (regularGpio == nullptr) {
|
||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
configureGpioByLineName(gpioConfig.first, *regularGpio);
|
configureGpioByLineName(gpioConfig.first, *regularGpio);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(gpio::GpioTypes::CALLBACK): {
|
case (gpio::GpioTypes::CALLBACK): {
|
||||||
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioConfig.second);
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioConfig.second);
|
||||||
if(gpioCallback->callback == nullptr) {
|
if (gpioCallback->callback == nullptr) {
|
||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
gpioCallback->callback(gpioConfig.first, gpio::GpioOperation::WRITE,
|
gpioCallback->callback(gpioConfig.first, gpio::GpioOperation::WRITE,
|
||||||
@ -89,26 +88,24 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::configureGpioByLabel(gpioId_t gpioId,
|
ReturnValue_t LinuxLibgpioIF::configureGpioByLabel(gpioId_t gpioId,
|
||||||
GpiodRegularByLabel &gpioByLabel) {
|
GpiodRegularByLabel& gpioByLabel) {
|
||||||
std::string& label = gpioByLabel.label;
|
std::string& label = gpioByLabel.label;
|
||||||
struct gpiod_chip* chip = gpiod_chip_open_by_label(label.c_str());
|
struct gpiod_chip* chip = gpiod_chip_open_by_label(label.c_str());
|
||||||
if (chip == nullptr) {
|
if (chip == nullptr) {
|
||||||
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;
|
||||||
return RETURN_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId,
|
ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId, GpiodRegularByChip& gpioByChip) {
|
||||||
GpiodRegularByChip &gpioByChip) {
|
|
||||||
std::string& chipname = gpioByChip.chipname;
|
std::string& chipname = gpioByChip.chipname;
|
||||||
struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname.c_str());
|
struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname.c_str());
|
||||||
if (chip == nullptr) {
|
if (chip == nullptr) {
|
||||||
sif::warning << "LinuxLibgpioIF::configureGpioByChip: Failed to open chip "
|
sif::warning << "LinuxLibgpioIF::configureGpioByChip: Failed to open chip " << chipname
|
||||||
<< chipname << ". Gpio ID: " << gpioId << std::endl;
|
<< ". Gpio ID: " << gpioId << std::endl;
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
std::string failOutput = "chipname: " + chipname;
|
std::string failOutput = "chipname: " + chipname;
|
||||||
@ -116,13 +113,13 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
|
ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
|
||||||
GpiodRegularByLineName &gpioByLineName) {
|
GpiodRegularByLineName& gpioByLineName) {
|
||||||
std::string& lineName = gpioByLineName.lineName;
|
std::string& lineName = gpioByLineName.lineName;
|
||||||
char chipname[MAX_CHIPNAME_LENGTH];
|
char chipname[MAX_CHIPNAME_LENGTH];
|
||||||
unsigned int lineOffset;
|
unsigned int lineOffset;
|
||||||
|
|
||||||
int result = gpiod_ctxless_find_line(lineName.c_str(), chipname, MAX_CHIPNAME_LENGTH,
|
int result =
|
||||||
&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 RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
@ -132,8 +129,8 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
|
|||||||
|
|
||||||
struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname);
|
struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname);
|
||||||
if (chip == nullptr) {
|
if (chip == nullptr) {
|
||||||
sif::warning << "LinuxLibgpioIF::configureGpioByLineName: Failed to open chip "
|
sif::warning << "LinuxLibgpioIF::configureGpioByLineName: Failed to open chip " << chipname
|
||||||
<< chipname << ". <Gpio ID: " << gpioId << std::endl;
|
<< ". <Gpio ID: " << gpioId << std::endl;
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
std::string failOutput = "line name: " + lineName;
|
std::string failOutput = "line name: " + lineName;
|
||||||
@ -141,19 +138,20 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
|
ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
|
||||||
GpiodRegularBase& regularGpio, std::string failOutput) {
|
GpiodRegularBase& regularGpio,
|
||||||
|
std::string failOutput) {
|
||||||
unsigned int lineNum;
|
unsigned int lineNum;
|
||||||
gpio::Direction direction;
|
gpio::Direction direction;
|
||||||
std::string consumer;
|
std::string consumer;
|
||||||
struct gpiod_line *lineHandle;
|
struct gpiod_line* lineHandle;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
lineNum = regularGpio.lineNum;
|
lineNum = regularGpio.lineNum;
|
||||||
lineHandle = gpiod_chip_get_line(chip, lineNum);
|
lineHandle = gpiod_chip_get_line(chip, lineNum);
|
||||||
if (!lineHandle) {
|
if (!lineHandle) {
|
||||||
sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open line " << std::endl;
|
sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open line " << std::endl;
|
||||||
sif::warning << "GPIO ID: " << gpioId << ", line number: " << lineNum <<
|
sif::warning << "GPIO ID: " << gpioId << ", line number: " << lineNum << ", " << failOutput
|
||||||
", " << failOutput << std::endl;
|
<< std::endl;
|
||||||
sif::warning << "Check if Linux GPIO configuration has changed. " << std::endl;
|
sif::warning << "Check if Linux GPIO configuration has changed. " << std::endl;
|
||||||
gpiod_chip_close(chip);
|
gpiod_chip_close(chip);
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
@ -163,33 +161,32 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod
|
|||||||
consumer = regularGpio.consumer;
|
consumer = regularGpio.consumer;
|
||||||
/* Configure direction and add a description to the GPIO */
|
/* Configure direction and add a description to the GPIO */
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case(gpio::OUT): {
|
case (gpio::OUT): {
|
||||||
result = gpiod_line_request_output(lineHandle, consumer.c_str(),
|
result = gpiod_line_request_output(lineHandle, consumer.c_str(), regularGpio.initValue);
|
||||||
regularGpio.initValue);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(gpio::IN): {
|
case (gpio::IN): {
|
||||||
result = gpiod_line_request_input(lineHandle, consumer.c_str());
|
result = gpiod_line_request_input(lineHandle, consumer.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
sif::error << "LinuxLibgpioIF::configureGpios: Invalid direction specified"
|
sif::error << "LinuxLibgpioIF::configureGpios: Invalid direction specified" << std::endl;
|
||||||
<< std::endl;
|
|
||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "LinuxLibgpioIF::configureRegularGpio: Failed to request line " <<
|
sif::error << "LinuxLibgpioIF::configureRegularGpio: Failed to request line " << lineNum
|
||||||
lineNum << " from GPIO instance with ID: " << gpioId << std::endl;
|
<< " from GPIO instance with ID: " << gpioId << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printError("LinuxLibgpioIF::configureRegularGpio: "
|
sif::printError(
|
||||||
"Failed to request line %d from GPIO instance with ID: %d\n", lineNum, gpioId);
|
"LinuxLibgpioIF::configureRegularGpio: "
|
||||||
|
"Failed to request line %d from GPIO instance with ID: %d\n",
|
||||||
|
lineNum, gpioId);
|
||||||
#endif
|
#endif
|
||||||
gpiod_line_release(lineHandle);
|
gpiod_line_release(lineHandle);
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Write line handle to GPIO configuration instance so it can later be used to set or
|
* Write line handle to GPIO configuration instance so it can later be used to set or
|
||||||
@ -207,22 +204,21 @@ ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto gpioType = gpioMapIter->second->gpioType;
|
auto gpioType = gpioMapIter->second->gpioType;
|
||||||
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
|
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or
|
||||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
|
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL or
|
||||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||||
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
||||||
if(regularGpio == nullptr) {
|
if (regularGpio == nullptr) {
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
return driveGpio(gpioId, *regularGpio, gpio::HIGH);
|
return driveGpio(gpioId, *regularGpio, gpio::HIGH);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||||
if(gpioCallback->callback == nullptr) {
|
if (gpioCallback->callback == nullptr) {
|
||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, gpio::Levels::HIGH,
|
||||||
gpio::Levels::HIGH, gpioCallback->callbackArgs);
|
gpioCallback->callbackArgs);
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
@ -240,37 +236,38 @@ ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto& gpioType = gpioMapIter->second->gpioType;
|
auto& gpioType = gpioMapIter->second->gpioType;
|
||||||
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
|
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or
|
||||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
|
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL or
|
||||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||||
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
||||||
if(regularGpio == nullptr) {
|
if (regularGpio == nullptr) {
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
return driveGpio(gpioId, *regularGpio, gpio::LOW);
|
return driveGpio(gpioId, *regularGpio, gpio::LOW);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||||
if(gpioCallback->callback == nullptr) {
|
if (gpioCallback->callback == nullptr) {
|
||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, gpio::Levels::LOW,
|
||||||
gpio::Levels::LOW, gpioCallback->callbackArgs);
|
gpioCallback->callbackArgs);
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio,
|
||||||
GpiodRegularBase& regularGpio, gpio::Levels logicLevel) {
|
gpio::Levels logicLevel) {
|
||||||
int result = gpiod_line_set_value(regularGpio.lineHandle, logicLevel);
|
int result = gpiod_line_set_value(regularGpio.lineHandle, logicLevel);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " << gpioId <<
|
sif::warning << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " << gpioId
|
||||||
" to logic level " << logicLevel << std::endl;
|
<< " to logic level " << logicLevel << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID %d to "
|
sif::printWarning(
|
||||||
"logic level %d\n", gpioId, logicLevel);
|
"LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID %d to "
|
||||||
|
"logic level %d\n",
|
||||||
|
gpioId, logicLevel);
|
||||||
#endif
|
#endif
|
||||||
return DRIVE_GPIO_FAILURE;
|
return DRIVE_GPIO_FAILURE;
|
||||||
}
|
}
|
||||||
@ -280,7 +277,7 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
|||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* 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
|
||||||
sif::warning << "LinuxLibgpioIF::readGpio: Unknown GPIOD ID " << gpioId << std::endl;
|
sif::warning << "LinuxLibgpioIF::readGpio: Unknown GPIOD ID " << gpioId << std::endl;
|
||||||
#else
|
#else
|
||||||
@ -290,63 +287,60 @@ ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto gpioType = gpioMapIter->second->gpioType;
|
auto gpioType = gpioMapIter->second->gpioType;
|
||||||
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
|
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or
|
||||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
|
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL or
|
||||||
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||||
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
||||||
if(regularGpio == nullptr) {
|
if (regularGpio == nullptr) {
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
*gpioState = gpiod_line_get_value(regularGpio->lineHandle);
|
*gpioState = gpiod_line_get_value(regularGpio->lineHandle);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||||
if(gpioCallback->callback == nullptr) {
|
if (gpioCallback->callback == nullptr) {
|
||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ,
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ, gpio::Levels::NONE,
|
||||||
gpio::Levels::NONE, gpioCallback->callbackArgs);
|
gpioCallback->callbackArgs);
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
|
ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd) {
|
||||||
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_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):
|
||||||
case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):
|
case (gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):
|
||||||
case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
|
case (gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
|
||||||
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioConfig.second);
|
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioConfig.second);
|
||||||
if(regularGpio == nullptr) {
|
if (regularGpio == nullptr) {
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
// 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 != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
status = result;
|
status = result;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(gpio::GpioTypes::CALLBACK): {
|
case (gpio::GpioTypes::CALLBACK): {
|
||||||
auto callbackGpio = dynamic_cast<GpioCallback*>(gpioConfig.second);
|
auto callbackGpio = dynamic_cast<GpioCallback*>(gpioConfig.second);
|
||||||
if(callbackGpio == nullptr) {
|
if (callbackGpio == nullptr) {
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
// Check for conflicts and remove duplicates if necessary
|
// Check for conflicts and remove duplicates if necessary
|
||||||
result = checkForConflictsById(gpioConfig.first,
|
result = checkForConflictsById(gpioConfig.first, gpioConfig.second->gpioType, mapToAdd);
|
||||||
gpioConfig.second->gpioType, mapToAdd);
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
||||||
status = result;
|
status = result;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "Invalid GPIO type detected for GPIO ID " << gpioConfig.first
|
sif::warning << "Invalid GPIO type detected for GPIO ID " << gpioConfig.first << std::endl;
|
||||||
<< std::endl;
|
|
||||||
#else
|
#else
|
||||||
sif::printWarning("Invalid GPIO type detected for GPIO ID %d\n", gpioConfig.first);
|
sif::printWarning("Invalid GPIO type detected for GPIO ID %d\n", gpioConfig.first);
|
||||||
#endif
|
#endif
|
||||||
@ -358,38 +352,41 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck,
|
ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck,
|
||||||
gpio::GpioTypes expectedType, GpioMap& mapToAdd) {
|
gpio::GpioTypes expectedType,
|
||||||
|
GpioMap& mapToAdd) {
|
||||||
// Cross check with private map
|
// Cross check with private map
|
||||||
gpioMapIter = gpioMap.find(gpioIdToCheck);
|
gpioMapIter = gpioMap.find(gpioIdToCheck);
|
||||||
if(gpioMapIter != gpioMap.end()) {
|
if (gpioMapIter != gpioMap.end()) {
|
||||||
auto& gpioType = gpioMapIter->second->gpioType;
|
auto& gpioType = gpioMapIter->second->gpioType;
|
||||||
bool eraseDuplicateDifferentType = false;
|
bool eraseDuplicateDifferentType = false;
|
||||||
switch(expectedType) {
|
switch (expectedType) {
|
||||||
case(gpio::GpioTypes::NONE): {
|
case (gpio::GpioTypes::NONE): {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP):
|
case (gpio::GpioTypes::GPIO_REGULAR_BY_CHIP):
|
||||||
case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):
|
case (gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):
|
||||||
case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
|
case (gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
|
||||||
if(gpioType == gpio::GpioTypes::NONE or gpioType == gpio::GpioTypes::CALLBACK) {
|
if (gpioType == gpio::GpioTypes::NONE or gpioType == gpio::GpioTypes::CALLBACK) {
|
||||||
eraseDuplicateDifferentType = true;
|
eraseDuplicateDifferentType = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(gpio::GpioTypes::CALLBACK): {
|
case (gpio::GpioTypes::CALLBACK): {
|
||||||
if(gpioType != gpio::GpioTypes::CALLBACK) {
|
if (gpioType != gpio::GpioTypes::CALLBACK) {
|
||||||
eraseDuplicateDifferentType = true;
|
eraseDuplicateDifferentType = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(eraseDuplicateDifferentType) {
|
if (eraseDuplicateDifferentType) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for "
|
sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for "
|
||||||
"different GPIO type " << gpioIdToCheck <<
|
"different GPIO type "
|
||||||
". Removing duplicate from map to add" << std::endl;
|
<< gpioIdToCheck << ". Removing duplicate from map to add" << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("LinuxLibgpioIF::checkForConflicts: ID already exists for "
|
sif::printWarning(
|
||||||
"different GPIO type %d. Removing duplicate from map to add\n", gpioIdToCheck);
|
"LinuxLibgpioIF::checkForConflicts: ID already exists for "
|
||||||
|
"different GPIO type %d. Removing duplicate from map to add\n",
|
||||||
|
gpioIdToCheck);
|
||||||
#endif
|
#endif
|
||||||
mapToAdd.erase(gpioIdToCheck);
|
mapToAdd.erase(gpioIdToCheck);
|
||||||
return GPIO_DUPLICATE_DETECTED;
|
return GPIO_DUPLICATE_DETECTED;
|
||||||
@ -398,11 +395,14 @@ ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck,
|
|||||||
// Remove element from map to add because a entry for this GPIO already exists
|
// Remove element from map to add because a entry for this GPIO already exists
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO "
|
sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO "
|
||||||
"definition with ID " << gpioIdToCheck << " detected. " <<
|
"definition with ID "
|
||||||
"Duplicate will be removed from map to add" << std::endl;
|
<< gpioIdToCheck << " detected. "
|
||||||
|
<< "Duplicate will be removed from map to add" << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition "
|
sif::printWarning(
|
||||||
"with ID %d detected. Duplicate will be removed from map to add\n", gpioIdToCheck);
|
"LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition "
|
||||||
|
"with ID %d detected. Duplicate will be removed from map to add\n",
|
||||||
|
gpioIdToCheck);
|
||||||
#endif
|
#endif
|
||||||
mapToAdd.erase(gpioIdToCheck);
|
mapToAdd.erase(gpioIdToCheck);
|
||||||
return GPIO_DUPLICATE_DETECTED;
|
return GPIO_DUPLICATE_DETECTED;
|
||||||
@ -415,28 +415,32 @@ void LinuxLibgpioIF::parseFindeLineResult(int result, std::string& lineName) {
|
|||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
case LINE_NOT_EXISTS:
|
case LINE_NOT_EXISTS:
|
||||||
case LINE_ERROR: {
|
case LINE_ERROR: {
|
||||||
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Line with name " << lineName <<
|
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Line with name " << lineName
|
||||||
" does not exist" << std::endl;
|
<< " does not exist" << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
|
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
|
||||||
"with name " << lineName << std::endl;
|
"with name "
|
||||||
|
<< lineName << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
case LINE_NOT_EXISTS:
|
case LINE_NOT_EXISTS:
|
||||||
case LINE_ERROR: {
|
case LINE_ERROR: {
|
||||||
sif::printWarning("LinuxLibgpioIF::parseFindeLineResult: Line with name %s "
|
sif::printWarning(
|
||||||
"does not exist\n", lineName);
|
"LinuxLibgpioIF::parseFindeLineResult: Line with name %s "
|
||||||
|
"does not exist\n",
|
||||||
|
lineName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
sif::printWarning("LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
|
sif::printWarning(
|
||||||
"with name %s\n", lineName);
|
"LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
|
||||||
|
"with name %s\n",
|
||||||
|
lineName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_
|
#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_
|
||||||
#define LINUX_GPIO_LINUXLIBGPIOIF_H_
|
#define LINUX_GPIO_LINUXLIBGPIOIF_H_
|
||||||
|
|
||||||
|
#include "fsfw/objectmanager/SystemObject.h"
|
||||||
#include "fsfw/returnvalues/FwClassIds.h"
|
#include "fsfw/returnvalues/FwClassIds.h"
|
||||||
#include "fsfw_hal/common/gpio/GpioIF.h"
|
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||||
#include "fsfw/objectmanager/SystemObject.h"
|
|
||||||
|
|
||||||
class GpioCookie;
|
class GpioCookie;
|
||||||
class GpiodRegularIF;
|
class GpiodRegularIF;
|
||||||
@ -16,8 +16,7 @@ class GpiodRegularIF;
|
|||||||
* The Petalinux SDK from Xilinx supports libgpiod since Petalinux 2019.1.
|
* The Petalinux SDK from Xilinx supports libgpiod since Petalinux 2019.1.
|
||||||
*/
|
*/
|
||||||
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
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 =
|
static constexpr ReturnValue_t UNKNOWN_GPIO_ID =
|
||||||
@ -39,8 +38,7 @@ public:
|
|||||||
ReturnValue_t pullLow(gpioId_t gpioId) override;
|
ReturnValue_t pullLow(gpioId_t gpioId) override;
|
||||||
ReturnValue_t readGpio(gpioId_t gpioId, int* 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;
|
||||||
static const int LINE_NOT_EXISTS = 0;
|
static const int LINE_NOT_EXISTS = 0;
|
||||||
static const int LINE_ERROR = -1;
|
static const int LINE_ERROR = -1;
|
||||||
@ -56,13 +54,11 @@ private:
|
|||||||
* @param gpioId The GPIO ID of the GPIO to drive.
|
* @param gpioId The GPIO ID of the GPIO to drive.
|
||||||
* @param logiclevel The logic level to set. O or 1.
|
* @param logiclevel The logic level to set. O or 1.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio,
|
ReturnValue_t driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio, gpio::Levels logicLevel);
|
||||||
gpio::Levels logicLevel);
|
|
||||||
|
|
||||||
ReturnValue_t configureGpioByLabel(gpioId_t gpioId, GpiodRegularByLabel& gpioByLabel);
|
ReturnValue_t configureGpioByLabel(gpioId_t gpioId, GpiodRegularByLabel& gpioByLabel);
|
||||||
ReturnValue_t configureGpioByChip(gpioId_t gpioId, GpiodRegularByChip& gpioByChip);
|
ReturnValue_t configureGpioByChip(gpioId_t gpioId, GpiodRegularByChip& gpioByChip);
|
||||||
ReturnValue_t configureGpioByLineName(gpioId_t gpioId,
|
ReturnValue_t configureGpioByLineName(gpioId_t gpioId, GpiodRegularByLineName& gpioByLineName);
|
||||||
GpiodRegularByLineName &gpioByLineName);
|
|
||||||
ReturnValue_t configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
|
ReturnValue_t configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
|
||||||
GpiodRegularBase& regularGpio, std::string failOutput);
|
GpiodRegularBase& regularGpio, std::string failOutput);
|
||||||
|
|
||||||
@ -77,8 +73,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
|
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
|
||||||
|
|
||||||
ReturnValue_t checkForConflictsById(gpioId_t gpiodId, gpio::GpioTypes type,
|
ReturnValue_t checkForConflictsById(gpioId_t gpiodId, gpio::GpioTypes type, GpioMap& mapToAdd);
|
||||||
GpioMap& mapToAdd);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.
|
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.
|
||||||
|
@ -1,114 +1,123 @@
|
|||||||
#include "fsfw_hal/linux/i2c/I2cComIF.h"
|
#include "fsfw_hal/linux/i2c/I2cComIF.h"
|
||||||
#include "fsfw_hal/linux/utility.h"
|
|
||||||
#include "fsfw_hal/linux/UnixFileGuard.h"
|
|
||||||
|
|
||||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <linux/i2c-dev.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <linux/i2c-dev.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "fsfw/FSFW.h"
|
||||||
|
#include "fsfw/serviceinterface.h"
|
||||||
|
#include "fsfw_hal/linux/UnixFileGuard.h"
|
||||||
|
#include "fsfw_hal/linux/utility.h"
|
||||||
|
|
||||||
I2cComIF::I2cComIF(object_id_t objectId): SystemObject(objectId){
|
I2cComIF::I2cComIF(object_id_t objectId) : SystemObject(objectId) {}
|
||||||
}
|
|
||||||
|
|
||||||
I2cComIF::~I2cComIF() {}
|
I2cComIF::~I2cComIF() {}
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
|
ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
|
||||||
|
|
||||||
address_t i2cAddress;
|
address_t i2cAddress;
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
|
|
||||||
if(cookie == nullptr) {
|
if (cookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "I2cComIF::initializeInterface: Invalid cookie!" << std::endl;
|
sif::error << "I2cComIF::initializeInterface: Invalid cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
||||||
if(i2cCookie == nullptr) {
|
if (i2cCookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "I2cComIF::initializeInterface: Invalid I2C cookie!" << std::endl;
|
sif::error << "I2cComIF::initializeInterface: Invalid I2C cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2cAddress = i2cCookie->getAddress();
|
i2cAddress = i2cCookie->getAddress();
|
||||||
|
|
||||||
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
||||||
if(i2cDeviceMapIter == i2cDeviceMap.end()) {
|
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
|
||||||
size_t maxReplyLen = i2cCookie->getMaxReplyLen();
|
size_t maxReplyLen = i2cCookie->getMaxReplyLen();
|
||||||
I2cInstance i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0};
|
I2cInstance i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0};
|
||||||
auto statusPair = i2cDeviceMap.emplace(i2cAddress, i2cInstance);
|
auto statusPair = i2cDeviceMap.emplace(i2cAddress, i2cInstance);
|
||||||
if (not statusPair.second) {
|
if (not statusPair.second) {
|
||||||
sif::error << "I2cComIF::initializeInterface: Failed to insert device with address " <<
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
i2cAddress << "to I2C device " << "map" << std::endl;
|
sif::error << "I2cComIF::initializeInterface: Failed to insert device with address "
|
||||||
|
<< i2cAddress << "to I2C device "
|
||||||
|
<< "map" << std::endl;
|
||||||
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
sif::error << "I2cComIF::initializeInterface: Device with address " << i2cAddress <<
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
"already in use" << std::endl;
|
sif::error << "I2cComIF::initializeInterface: Device with address " << i2cAddress
|
||||||
|
<< "already in use" << std::endl;
|
||||||
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie,
|
ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
|
||||||
const uint8_t *sendData, size_t sendLen) {
|
|
||||||
|
|
||||||
ReturnValue_t result;
|
ReturnValue_t result;
|
||||||
int fd;
|
int fd;
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
|
|
||||||
if(sendData == nullptr) {
|
if (sendData == nullptr) {
|
||||||
sif::error << "I2cComIF::sendMessage: Send Data is nullptr"
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
<< std::endl;
|
sif::error << "I2cComIF::sendMessage: Send Data is nullptr" << std::endl;
|
||||||
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sendLen == 0) {
|
if (sendLen == 0) {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
||||||
if(i2cCookie == nullptr) {
|
if (i2cCookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "I2cComIF::sendMessage: Invalid I2C Cookie!" << std::endl;
|
sif::error << "I2cComIF::sendMessage: Invalid I2C Cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
address_t i2cAddress = i2cCookie->getAddress();
|
address_t i2cAddress = i2cCookie->getAddress();
|
||||||
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
||||||
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
|
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
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
|
||||||
return HasReturnvaluesIF::RETURN_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() != HasReturnvaluesIF::RETURN_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 != HasReturnvaluesIF::RETURN_OK){
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(fd, sendData, sendLen) != (int)sendLen) {
|
if (write(fd, sendData, sendLen) != static_cast<int>(sendLen)) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "I2cComIF::sendMessage: Failed to send data to I2C "
|
sif::error << "I2cComIF::sendMessage: Failed to send data to I2C "
|
||||||
"device with error code " << errno << ". Error description: "
|
"device with error code "
|
||||||
<< strerror(errno) << std::endl;
|
<< errno << ". Error description: " << strerror(errno) << std::endl;
|
||||||
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::getSendSuccess(CookieIF *cookie) {
|
ReturnValue_t I2cComIF::getSendSuccess(CookieIF* cookie) { return HasReturnvaluesIF::RETURN_OK; }
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
|
ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
|
||||||
size_t requestLen) {
|
|
||||||
ReturnValue_t result;
|
ReturnValue_t result;
|
||||||
int fd;
|
int fd;
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
@ -118,8 +127,10 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
|
|||||||
}
|
}
|
||||||
|
|
||||||
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
||||||
if(i2cCookie == nullptr) {
|
if (i2cCookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "I2cComIF::requestReceiveMessage: Invalid I2C Cookie!" << std::endl;
|
sif::error << "I2cComIF::requestReceiveMessage: Invalid I2C Cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
i2cDeviceMapIter->second.replyLen = 0;
|
i2cDeviceMapIter->second.replyLen = 0;
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
@ -127,19 +138,21 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
|
|||||||
address_t i2cAddress = i2cCookie->getAddress();
|
address_t i2cAddress = i2cCookie->getAddress();
|
||||||
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
||||||
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
|
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "I2cComIF::requestReceiveMessage: i2cAddress of Cookie not "
|
sif::error << "I2cComIF::requestReceiveMessage: i2cAddress of Cookie not "
|
||||||
<< "registered in i2cDeviceMap" << std::endl;
|
<< "registered in i2cDeviceMap" << std::endl;
|
||||||
|
#endif
|
||||||
i2cDeviceMapIter->second.replyLen = 0;
|
i2cDeviceMapIter->second.replyLen = 0;
|
||||||
return HasReturnvaluesIF::RETURN_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() != HasReturnvaluesIF::RETURN_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 != HasReturnvaluesIF::RETURN_OK){
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
i2cDeviceMapIter->second.replyLen = 0;
|
i2cDeviceMapIter->second.replyLen = 0;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -150,13 +163,16 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
|
|||||||
if (readLen != static_cast<int>(requestLen)) {
|
if (readLen != static_cast<int>(requestLen)) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1 and FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_VERBOSE_LEVEL >= 1 and FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C "
|
sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C "
|
||||||
<< "device failed with error code " << errno <<". Description"
|
<< "device failed with error code " << errno << ". Description"
|
||||||
<< " of error: " << strerror(errno) << std::endl;
|
<< " of error: " << strerror(errno) << std::endl;
|
||||||
sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from "
|
sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from " << requestLen
|
||||||
<< requestLen << " bytes" << std::endl;
|
<< " bytes" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
i2cDeviceMapIter->second.replyLen = 0;
|
i2cDeviceMapIter->second.replyLen = 0;
|
||||||
sif::debug << "I2cComIF::requestReceiveMessage: Read " << readLen << " of " << requestLen << " bytes" << std::endl;
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::debug << "I2cComIF::requestReceiveMessage: Read " << readLen << " of " << requestLen
|
||||||
|
<< " bytes" << std::endl;
|
||||||
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,19 +180,22 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::readReceivedMessage(CookieIF *cookie,
|
ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
|
||||||
uint8_t **buffer, size_t* size) {
|
|
||||||
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
|
||||||
if(i2cCookie == nullptr) {
|
if (i2cCookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "I2cComIF::readReceivedMessage: Invalid I2C Cookie!" << std::endl;
|
sif::error << "I2cComIF::readReceivedMessage: Invalid I2C Cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
address_t i2cAddress = i2cCookie->getAddress();
|
address_t i2cAddress = i2cCookie->getAddress();
|
||||||
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
|
||||||
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
|
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
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
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
*buffer = i2cDeviceMapIter->second.replyBuffer.data();
|
*buffer = i2cDeviceMapIter->second.replyBuffer.data();
|
||||||
@ -185,9 +204,8 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF *cookie,
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::openDevice(std::string deviceFile,
|
ReturnValue_t I2cComIF::openDevice(std::string deviceFile, address_t i2cAddress,
|
||||||
address_t i2cAddress, int* fileDescriptor) {
|
int* fileDescriptor) {
|
||||||
|
|
||||||
if (ioctl(*fileDescriptor, I2C_SLAVE, i2cAddress) < 0) {
|
if (ioctl(*fileDescriptor, I2C_SLAVE, i2cAddress) < 0) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
#ifndef LINUX_I2C_I2COMIF_H_
|
#ifndef LINUX_I2C_I2COMIF_H_
|
||||||
#define LINUX_I2C_I2COMIF_H_
|
#define LINUX_I2C_I2COMIF_H_
|
||||||
|
|
||||||
#include "I2cCookie.h"
|
|
||||||
#include <fsfw/objectmanager/SystemObject.h>
|
|
||||||
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
||||||
|
#include <fsfw/objectmanager/SystemObject.h>
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "I2cCookie.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This is the communication interface for I2C devices connected
|
* @brief This is the communication interface for I2C devices connected
|
||||||
* to a system running a Linux OS.
|
* to a system running a Linux OS.
|
||||||
@ -16,23 +17,19 @@
|
|||||||
*
|
*
|
||||||
* @author J. Meier
|
* @author J. Meier
|
||||||
*/
|
*/
|
||||||
class I2cComIF: public DeviceCommunicationIF, public SystemObject {
|
class I2cComIF : public DeviceCommunicationIF, public SystemObject {
|
||||||
public:
|
public:
|
||||||
I2cComIF(object_id_t objectId);
|
I2cComIF(object_id_t objectId);
|
||||||
|
|
||||||
virtual ~I2cComIF();
|
virtual ~I2cComIF();
|
||||||
|
|
||||||
ReturnValue_t initializeInterface(CookieIF * cookie) override;
|
ReturnValue_t initializeInterface(CookieIF *cookie) override;
|
||||||
ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData,
|
ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) override;
|
||||||
size_t sendLen) override;
|
|
||||||
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
||||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
|
||||||
size_t requestLen) override;
|
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override;
|
||||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
|
||||||
size_t *size) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
struct I2cInstance {
|
struct I2cInstance {
|
||||||
std::vector<uint8_t> replyBuffer;
|
std::vector<uint8_t> replyBuffer;
|
||||||
size_t replyLen;
|
size_t replyLen;
|
||||||
@ -54,8 +51,7 @@ private:
|
|||||||
* @param fileDescriptor Pointer to device descriptor.
|
* @param fileDescriptor Pointer to device descriptor.
|
||||||
* @return RETURN_OK if successful, otherwise RETURN_FAILED.
|
* @return RETURN_OK if successful, otherwise RETURN_FAILED.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t openDevice(std::string deviceFile,
|
ReturnValue_t openDevice(std::string deviceFile, address_t i2cAddress, int *fileDescriptor);
|
||||||
address_t i2cAddress, int* fileDescriptor);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LINUX_I2C_I2COMIF_H_ */
|
#endif /* LINUX_I2C_I2COMIF_H_ */
|
||||||
|
@ -1,20 +1,12 @@
|
|||||||
#include "fsfw_hal/linux/i2c/I2cCookie.h"
|
#include "fsfw_hal/linux/i2c/I2cCookie.h"
|
||||||
|
|
||||||
I2cCookie::I2cCookie(address_t i2cAddress_, size_t maxReplyLen_,
|
I2cCookie::I2cCookie(address_t i2cAddress_, size_t maxReplyLen_, std::string deviceFile_)
|
||||||
std::string deviceFile_) :
|
: i2cAddress(i2cAddress_), maxReplyLen(maxReplyLen_), deviceFile(deviceFile_) {}
|
||||||
i2cAddress(i2cAddress_), maxReplyLen(maxReplyLen_), deviceFile(deviceFile_) {
|
|
||||||
}
|
|
||||||
|
|
||||||
address_t I2cCookie::getAddress() const {
|
address_t I2cCookie::getAddress() const { return i2cAddress; }
|
||||||
return i2cAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t I2cCookie::getMaxReplyLen() const {
|
size_t I2cCookie::getMaxReplyLen() const { return maxReplyLen; }
|
||||||
return maxReplyLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string I2cCookie::getDeviceFile() const {
|
std::string I2cCookie::getDeviceFile() const { return deviceFile; }
|
||||||
return deviceFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
I2cCookie::~I2cCookie() {}
|
I2cCookie::~I2cCookie() {}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define LINUX_I2C_I2CCOOKIE_H_
|
#define LINUX_I2C_I2CCOOKIE_H_
|
||||||
|
|
||||||
#include <fsfw/devicehandlers/CookieIF.h>
|
#include <fsfw/devicehandlers/CookieIF.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -9,9 +10,8 @@
|
|||||||
*
|
*
|
||||||
* @author J. Meier
|
* @author J. Meier
|
||||||
*/
|
*/
|
||||||
class I2cCookie: public CookieIF {
|
class I2cCookie : public CookieIF {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructor for the I2C cookie.
|
* @brief Constructor for the I2C cookie.
|
||||||
* @param i2cAddress_ The i2c address of the target device.
|
* @param i2cAddress_ The i2c address of the target device.
|
||||||
@ -19,8 +19,7 @@ public:
|
|||||||
* target device.
|
* target device.
|
||||||
* @param devicFile_ The device file specifying the i2c interface to use. E.g. "/dev/i2c-0".
|
* @param devicFile_ The device file specifying the i2c interface to use. E.g. "/dev/i2c-0".
|
||||||
*/
|
*/
|
||||||
I2cCookie(address_t i2cAddress_, size_t maxReplyLen_,
|
I2cCookie(address_t i2cAddress_, size_t maxReplyLen_, std::string deviceFile_);
|
||||||
std::string deviceFile_);
|
|
||||||
|
|
||||||
virtual ~I2cCookie();
|
virtual ~I2cCookie();
|
||||||
|
|
||||||
@ -28,8 +27,7 @@ public:
|
|||||||
size_t getMaxReplyLen() const;
|
size_t getMaxReplyLen() const;
|
||||||
std::string getDeviceFile() const;
|
std::string getDeviceFile() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
address_t i2cAddress = 0;
|
address_t i2cAddress = 0;
|
||||||
size_t maxReplyLen = 0;
|
size_t maxReplyLen = 0;
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#include "fsfw/FSFW.h"
|
|
||||||
|
|
||||||
#include "fsfw_hal/linux/rpi/GpioRPi.h"
|
#include "fsfw_hal/linux/rpi/GpioRPi.h"
|
||||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
|
||||||
|
|
||||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||||
|
|
||||||
|
#include "fsfw/FSFW.h"
|
||||||
|
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||||
|
|
||||||
ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin,
|
ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin,
|
||||||
std::string consumer, gpio::Direction direction, int initValue) {
|
std::string consumer, gpio::Direction direction,
|
||||||
if(cookie == nullptr) {
|
int initValue) {
|
||||||
|
if (cookie == nullptr) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int
|
|||||||
config->initValue = initValue;
|
config->initValue = initValue;
|
||||||
|
|
||||||
/* Sanity check for the BCM pins before assigning it */
|
/* Sanity check for the BCM pins before assigning it */
|
||||||
if(bcmPin > 27) {
|
if (bcmPin > 27) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "createRpiGpioConfig: BCM pin " << bcmPin << " invalid!" << std::endl;
|
sif::error << "createRpiGpioConfig: BCM pin " << bcmPin << " invalid!" << std::endl;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define BSP_RPI_GPIO_GPIORPI_H_
|
#define BSP_RPI_GPIO_GPIORPI_H_
|
||||||
|
|
||||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
|
||||||
#include "../../common/gpio/gpioDefinitions.h"
|
#include "../../common/gpio/gpioDefinitions.h"
|
||||||
|
|
||||||
class GpioCookie;
|
class GpioCookie;
|
||||||
@ -21,6 +22,6 @@ namespace gpio {
|
|||||||
*/
|
*/
|
||||||
ReturnValue_t createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin,
|
ReturnValue_t createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin,
|
||||||
std::string consumer, gpio::Direction direction, int initValue);
|
std::string consumer, gpio::Direction direction, int initValue);
|
||||||
}
|
} // namespace gpio
|
||||||
|
|
||||||
#endif /* BSP_RPI_GPIO_GPIORPI_H_ */
|
#endif /* BSP_RPI_GPIO_GPIORPI_H_ */
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
#include "fsfw/FSFW.h"
|
|
||||||
#include "fsfw_hal/linux/spi/SpiComIF.h"
|
#include "fsfw_hal/linux/spi/SpiComIF.h"
|
||||||
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
|
||||||
#include "fsfw_hal/linux/utility.h"
|
|
||||||
#include "fsfw_hal/linux/UnixFileGuard.h"
|
|
||||||
|
|
||||||
#include <fsfw/ipc/MutexFactory.h>
|
|
||||||
#include <fsfw/globalfunctions/arrayprinter.h>
|
|
||||||
|
|
||||||
#include <linux/spi/spidev.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <fsfw/globalfunctions/arrayprinter.h>
|
||||||
|
#include <fsfw/ipc/MutexFactory.h>
|
||||||
|
#include <linux/spi/spidev.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF):
|
#include "fsfw/FSFW.h"
|
||||||
SystemObject(objectId), gpioComIF(gpioComIF) {
|
#include "fsfw_hal/linux/UnixFileGuard.h"
|
||||||
if(gpioComIF == nullptr) {
|
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
||||||
|
#include "fsfw_hal/linux/utility.h"
|
||||||
|
|
||||||
|
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF)
|
||||||
|
: SystemObject(objectId), gpioComIF(gpioComIF) {
|
||||||
|
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
|
||||||
sif::error << "SpiComIF::SpiComIF: GPIO communication interface invalid!" << std::endl;
|
sif::error << "SpiComIF::SpiComIF: GPIO communication interface invalid!" << std::endl;
|
||||||
@ -30,28 +30,30 @@ SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF):
|
|||||||
spiMutex = MutexFactory::instance()->createMutex();
|
spiMutex = MutexFactory::instance()->createMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
||||||
if(spiCookie == nullptr) {
|
if (spiCookie == nullptr) {
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
address_t spiAddress = spiCookie->getSpiAddress();
|
address_t spiAddress = spiCookie->getSpiAddress();
|
||||||
|
|
||||||
auto iter = spiDeviceMap.find(spiAddress);
|
auto iter = spiDeviceMap.find(spiAddress);
|
||||||
if(iter == spiDeviceMap.end()) {
|
if (iter == spiDeviceMap.end()) {
|
||||||
size_t bufferSize = spiCookie->getMaxBufferSize();
|
size_t bufferSize = spiCookie->getMaxBufferSize();
|
||||||
SpiInstance spiInstance(bufferSize);
|
SpiInstance spiInstance(bufferSize);
|
||||||
auto statusPair = spiDeviceMap.emplace(spiAddress, spiInstance);
|
auto statusPair = spiDeviceMap.emplace(spiAddress, spiInstance);
|
||||||
if (not statusPair.second) {
|
if (not statusPair.second) {
|
||||||
#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::initializeInterface: Failed to insert device with address " <<
|
sif::error << "SpiComIF::initializeInterface: Failed to insert device with address "
|
||||||
spiAddress << "to SPI device map" << std::endl;
|
<< spiAddress << "to SPI device map" << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printError("SpiComIF::initializeInterface: Failed to insert device with address "
|
sif::printError(
|
||||||
"%lu to SPI device map\n", static_cast<unsigned long>(spiAddress));
|
"SpiComIF::initializeInterface: Failed to insert device with address "
|
||||||
|
"%lu to SPI device map\n",
|
||||||
|
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
@ -59,8 +61,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
/* 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 */
|
||||||
spiCookie->assignReadBuffer(statusPair.first->second.replyBuffer.data());
|
spiCookie->assignReadBuffer(statusPair.first->second.replyBuffer.data());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
#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::initializeInterface: SPI address already exists!" << std::endl;
|
sif::error << "SpiComIF::initializeInterface: SPI address already exists!" << std::endl;
|
||||||
@ -73,7 +74,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
|
|
||||||
/* 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 */
|
||||||
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
||||||
if(gpioId != gpio::NO_GPIO) {
|
if (gpioId != gpio::NO_GPIO) {
|
||||||
gpioComIF->pullHigh(gpioId);
|
gpioComIF->pullHigh(gpioId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,91 +87,94 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
UnixFileGuard fileHelper(spiCookie->getSpiDevice(), &fileDescriptor, O_RDWR,
|
UnixFileGuard fileHelper(spiCookie->getSpiDevice(), &fileDescriptor, O_RDWR,
|
||||||
"SpiComIF::initializeInterface");
|
"SpiComIF::initializeInterface");
|
||||||
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return fileHelper.getOpenResult();
|
return fileHelper.getOpenResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* These flags are rather uncommon */
|
/* These flags are rather uncommon */
|
||||||
if(params.threeWireSpi or params.noCs or params.csHigh) {
|
if (params.threeWireSpi or params.noCs or params.csHigh) {
|
||||||
uint32_t currentMode = 0;
|
uint32_t currentMode = 0;
|
||||||
retval = ioctl(fileDescriptor, SPI_IOC_RD_MODE32, ¤tMode);
|
retval = ioctl(fileDescriptor, SPI_IOC_RD_MODE32, ¤tMode);
|
||||||
if(retval != 0) {
|
if (retval != 0) {
|
||||||
utility::handleIoctlError("SpiComIF::initialiezInterface: Could not read full mode!");
|
utility::handleIoctlError("SpiComIF::initialiezInterface: Could not read full mode!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(params.threeWireSpi) {
|
if (params.threeWireSpi) {
|
||||||
currentMode |= SPI_3WIRE;
|
currentMode |= SPI_3WIRE;
|
||||||
}
|
}
|
||||||
if(params.noCs) {
|
if (params.noCs) {
|
||||||
/* Some drivers like the Raspberry Pi ignore this flag in any case */
|
/* Some drivers like the Raspberry Pi ignore this flag in any case */
|
||||||
currentMode |= SPI_NO_CS;
|
currentMode |= SPI_NO_CS;
|
||||||
}
|
}
|
||||||
if(params.csHigh) {
|
if (params.csHigh) {
|
||||||
currentMode |= SPI_CS_HIGH;
|
currentMode |= SPI_CS_HIGH;
|
||||||
}
|
}
|
||||||
/* Write adapted mode */
|
/* Write adapted mode */
|
||||||
retval = ioctl(fileDescriptor, SPI_IOC_WR_MODE32, ¤tMode);
|
retval = ioctl(fileDescriptor, SPI_IOC_WR_MODE32, ¤tMode);
|
||||||
if(retval != 0) {
|
if (retval != 0) {
|
||||||
utility::handleIoctlError("SpiComIF::initialiezInterface: Could not write full mode!");
|
utility::handleIoctlError("SpiComIF::initialiezInterface: Could not write full mode!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(params.lsbFirst) {
|
if (params.lsbFirst) {
|
||||||
retval = ioctl(fileDescriptor, SPI_IOC_WR_LSB_FIRST, ¶ms.lsbFirst);
|
retval = ioctl(fileDescriptor, SPI_IOC_WR_LSB_FIRST, ¶ms.lsbFirst);
|
||||||
if(retval != 0) {
|
if (retval != 0) {
|
||||||
utility::handleIoctlError("SpiComIF::initializeInterface: Setting LSB first failed");
|
utility::handleIoctlError("SpiComIF::initializeInterface: Setting LSB first failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(params.bitsPerWord != 8) {
|
if (params.bitsPerWord != 8) {
|
||||||
retval = ioctl(fileDescriptor, SPI_IOC_WR_BITS_PER_WORD, ¶ms.bitsPerWord);
|
retval = ioctl(fileDescriptor, SPI_IOC_WR_BITS_PER_WORD, ¶ms.bitsPerWord);
|
||||||
if(retval != 0) {
|
if (retval != 0) {
|
||||||
utility::handleIoctlError("SpiComIF::initializeInterface: "
|
utility::handleIoctlError(
|
||||||
|
"SpiComIF::initializeInterface: "
|
||||||
"Could not write bits per word!");
|
"Could not write bits per word!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_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 = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
|
|
||||||
if(spiCookie == nullptr) {
|
if (spiCookie == nullptr) {
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sendLen > spiCookie->getMaxBufferSize()) {
|
if (sendLen > spiCookie->getMaxBufferSize()) {
|
||||||
#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: Too much data sent, send length " << sendLen <<
|
sif::warning << "SpiComIF::sendMessage: Too much data sent, send length " << sendLen
|
||||||
"larger than maximum buffer length " << spiCookie->getMaxBufferSize() << std::endl;
|
<< "larger than maximum buffer length " << spiCookie->getMaxBufferSize()
|
||||||
|
<< std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("SpiComIF::sendMessage: Too much data sent, send length %lu larger "
|
sif::printWarning(
|
||||||
"than maximum buffer length %lu!\n", static_cast<unsigned long>(sendLen),
|
"SpiComIF::sendMessage: Too much data sent, send length %lu larger "
|
||||||
|
"than maximum buffer length %lu!\n",
|
||||||
|
static_cast<unsigned long>(sendLen),
|
||||||
static_cast<unsigned long>(spiCookie->getMaxBufferSize()));
|
static_cast<unsigned long>(spiCookie->getMaxBufferSize()));
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||||
return DeviceCommunicationIF::TOO_MUCH_DATA;
|
return DeviceCommunicationIF::TOO_MUCH_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(spiCookie->getComIfMode() == spi::SpiComIfModes::REGULAR) {
|
if (spiCookie->getComIfMode() == spi::SpiComIfModes::REGULAR) {
|
||||||
result = performRegularSendOperation(spiCookie, sendData, sendLen);
|
result = performRegularSendOperation(spiCookie, sendData, sendLen);
|
||||||
}
|
} else if (spiCookie->getComIfMode() == spi::SpiComIfModes::CALLBACK) {
|
||||||
else if(spiCookie->getComIfMode() == spi::SpiComIfModes::CALLBACK) {
|
|
||||||
spi::send_callback_function_t sendFunc = nullptr;
|
spi::send_callback_function_t sendFunc = nullptr;
|
||||||
void* funcArgs = nullptr;
|
void* funcArgs = nullptr;
|
||||||
spiCookie->getCallback(&sendFunc, &funcArgs);
|
spiCookie->getCallback(&sendFunc, &funcArgs);
|
||||||
if(sendFunc != nullptr) {
|
if (sendFunc != nullptr) {
|
||||||
result = sendFunc(this, spiCookie, sendData, sendLen, funcArgs);
|
result = sendFunc(this, spiCookie, sendData, sendLen, funcArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const uint8_t *sendData,
|
ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const uint8_t* sendData,
|
||||||
size_t sendLen) {
|
size_t sendLen) {
|
||||||
address_t spiAddress = spiCookie->getSpiAddress();
|
address_t spiAddress = spiCookie->getSpiAddress();
|
||||||
auto iter = spiDeviceMap.find(spiAddress);
|
auto iter = spiDeviceMap.find(spiAddress);
|
||||||
if(iter != spiDeviceMap.end()) {
|
if (iter != spiDeviceMap.end()) {
|
||||||
spiCookie->assignReadBuffer(iter->second.replyBuffer.data());
|
spiCookie->assignReadBuffer(iter->second.replyBuffer.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +184,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
|
|||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
std::string device = spiCookie->getSpiDevice();
|
std::string device = spiCookie->getSpiDevice();
|
||||||
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage");
|
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage");
|
||||||
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
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;
|
||||||
@ -194,7 +198,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
|
|||||||
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
||||||
|
|
||||||
/* Pull SPI CS low. For now, no support for active high given */
|
/* Pull SPI CS low. For now, no support for active high given */
|
||||||
if(gpioId != gpio::NO_GPIO) {
|
if (gpioId != gpio::NO_GPIO) {
|
||||||
result = spiMutex->lockMutex(timeoutType, timeoutMs);
|
result = spiMutex->lockMutex(timeoutType, timeoutMs);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
@ -207,7 +211,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
ReturnValue_t result = gpioComIF->pullLow(gpioId);
|
ReturnValue_t result = gpioComIF->pullLow(gpioId);
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != 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
|
||||||
sif::warning << "SpiComIF::sendMessage: Pulling low CS pin failed" << std::endl;
|
sif::warning << "SpiComIF::sendMessage: Pulling low CS pin failed" << std::endl;
|
||||||
@ -220,24 +224,22 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Execute transfer */
|
/* Execute transfer */
|
||||||
if(fullDuplex) {
|
if (fullDuplex) {
|
||||||
/* Initiate a full duplex SPI transfer. */
|
/* Initiate a full duplex SPI transfer. */
|
||||||
retval = ioctl(fileDescriptor, SPI_IOC_MESSAGE(1), spiCookie->getTransferStructHandle());
|
retval = ioctl(fileDescriptor, SPI_IOC_MESSAGE(1), spiCookie->getTransferStructHandle());
|
||||||
if(retval < 0) {
|
if (retval < 0) {
|
||||||
utility::handleIoctlError("SpiComIF::sendMessage: ioctl error.");
|
utility::handleIoctlError("SpiComIF::sendMessage: ioctl error.");
|
||||||
result = FULL_DUPLEX_TRANSFER_FAILED;
|
result = FULL_DUPLEX_TRANSFER_FAILED;
|
||||||
}
|
}
|
||||||
#if FSFW_HAL_SPI_WIRETAPPING == 1
|
#if FSFW_HAL_SPI_WIRETAPPING == 1
|
||||||
performSpiWiretapping(spiCookie);
|
performSpiWiretapping(spiCookie);
|
||||||
#endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */
|
#endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
/* We write with a blocking half-duplex transfer here */
|
/* We write with a blocking half-duplex transfer here */
|
||||||
if (write(fileDescriptor, sendData, sendLen) != static_cast<ssize_t>(sendLen)) {
|
if (write(fileDescriptor, sendData, sendLen) != static_cast<ssize_t>(sendLen)) {
|
||||||
#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: Half-Duplex write operation failed!" <<
|
sif::warning << "SpiComIF::sendMessage: Half-Duplex write operation failed!" << std::endl;
|
||||||
std::endl;
|
|
||||||
#else
|
#else
|
||||||
sif::printWarning("SpiComIF::sendMessage: Half-Duplex write operation failed!\n");
|
sif::printWarning("SpiComIF::sendMessage: Half-Duplex write operation failed!\n");
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
@ -246,7 +248,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gpioId != gpio::NO_GPIO) {
|
if (gpioId != gpio::NO_GPIO) {
|
||||||
gpioComIF->pullHigh(gpioId);
|
gpioComIF->pullHigh(gpioId);
|
||||||
result = spiMutex->unlockMutex();
|
result = spiMutex->unlockMutex();
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
@ -259,43 +261,39 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) {
|
ReturnValue_t SpiComIF::getSendSuccess(CookieIF* cookie) { return HasReturnvaluesIF::RETURN_OK; }
|
||||||
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);
|
||||||
if(spiCookie == nullptr) {
|
if (spiCookie == nullptr) {
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(spiCookie->isFullDuplex()) {
|
if (spiCookie->isFullDuplex()) {
|
||||||
return HasReturnvaluesIF::RETURN_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 = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
std::string device = spiCookie->getSpiDevice();
|
std::string device = spiCookie->getSpiDevice();
|
||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR,
|
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::requestReceiveMessage");
|
||||||
"SpiComIF::requestReceiveMessage");
|
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_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 != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
||||||
if(gpioId != gpio::NO_GPIO) {
|
if (gpioId != gpio::NO_GPIO) {
|
||||||
result = spiMutex->lockMutex(timeoutType, timeoutMs);
|
result = spiMutex->lockMutex(timeoutType, timeoutMs);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
@ -306,7 +304,7 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
|
|||||||
gpioComIF->pullLow(gpioId);
|
gpioComIF->pullLow(gpioId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(read(fileDescriptor, rxBuf, readSize) != static_cast<ssize_t>(readSize)) {
|
if (read(fileDescriptor, rxBuf, readSize) != static_cast<ssize_t>(readSize)) {
|
||||||
#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: Half-Duplex read operation failed!" << std::endl;
|
sif::warning << "SpiComIF::sendMessage: Half-Duplex read operation failed!" << std::endl;
|
||||||
@ -317,7 +315,7 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
|
|||||||
result = HALF_DUPLEX_TRANSFER_FAILED;
|
result = HALF_DUPLEX_TRANSFER_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gpioId != gpio::NO_GPIO) {
|
if (gpioId != gpio::NO_GPIO) {
|
||||||
gpioComIF->pullHigh(gpioId);
|
gpioComIF->pullHigh(gpioId);
|
||||||
result = spiMutex->unlockMutex();
|
result = spiMutex->unlockMutex();
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
@ -331,14 +329,14 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 HasReturnvaluesIF::RETURN_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 != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,17 +347,17 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
MutexIF* SpiComIF::getMutex(MutexIF::TimeoutType* timeoutType, uint32_t* timeoutMs) {
|
MutexIF* SpiComIF::getMutex(MutexIF::TimeoutType* timeoutType, uint32_t* timeoutMs) {
|
||||||
if(timeoutType != nullptr) {
|
if (timeoutType != nullptr) {
|
||||||
*timeoutType = this->timeoutType;
|
*timeoutType = this->timeoutType;
|
||||||
}
|
}
|
||||||
if(timeoutMs != nullptr) {
|
if (timeoutMs != nullptr) {
|
||||||
*timeoutMs = this->timeoutMs;
|
*timeoutMs = this->timeoutMs;
|
||||||
}
|
}
|
||||||
return spiMutex;
|
return spiMutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiComIF::performSpiWiretapping(SpiCookie* spiCookie) {
|
void SpiComIF::performSpiWiretapping(SpiCookie* spiCookie) {
|
||||||
if(spiCookie == nullptr) {
|
if (spiCookie == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t dataLen = spiCookie->getTransferStructHandle()->len;
|
size_t dataLen = spiCookie->getTransferStructHandle()->len;
|
||||||
@ -378,12 +376,12 @@ 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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto iter = spiDeviceMap.find(spiAddress);
|
auto iter = spiDeviceMap.find(spiAddress);
|
||||||
if(iter == spiDeviceMap.end()) {
|
if (iter == spiDeviceMap.end()) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,18 +389,16 @@ ReturnValue_t SpiComIF::getReadBuffer(address_t spiAddress, uint8_t** buffer) {
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
GpioIF* SpiComIF::getGpioInterface() {
|
GpioIF* SpiComIF::getGpioInterface() { return gpioComIF; }
|
||||||
return gpioComIF;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiComIF::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed) {
|
void SpiComIF::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed) {
|
||||||
int retval = ioctl(spiFd, SPI_IOC_WR_MODE, reinterpret_cast<uint8_t*>(&mode));
|
int retval = ioctl(spiFd, SPI_IOC_WR_MODE, reinterpret_cast<uint8_t*>(&mode));
|
||||||
if(retval != 0) {
|
if (retval != 0) {
|
||||||
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI mode failed");
|
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI mode failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = ioctl(spiFd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
|
retval = ioctl(spiFd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
|
||||||
if(retval != 0) {
|
if (retval != 0) {
|
||||||
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI speed failed");
|
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI speed failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
#ifndef LINUX_SPI_SPICOMIF_H_
|
#ifndef LINUX_SPI_SPICOMIF_H_
|
||||||
#define LINUX_SPI_SPICOMIF_H_
|
#define LINUX_SPI_SPICOMIF_H_
|
||||||
|
|
||||||
#include "fsfw/FSFW.h"
|
#include <unordered_map>
|
||||||
#include "spiDefinitions.h"
|
#include <vector>
|
||||||
#include "returnvalues/classIds.h"
|
|
||||||
#include "fsfw_hal/common/gpio/GpioIF.h"
|
|
||||||
|
|
||||||
|
#include "fsfw/FSFW.h"
|
||||||
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
||||||
#include "fsfw/objectmanager/SystemObject.h"
|
#include "fsfw/objectmanager/SystemObject.h"
|
||||||
|
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||||
#include <vector>
|
#include "returnvalues/classIds.h"
|
||||||
#include <unordered_map>
|
#include "spiDefinitions.h"
|
||||||
|
|
||||||
class SpiCookie;
|
class SpiCookie;
|
||||||
|
|
||||||
@ -21,8 +20,8 @@ class SpiCookie;
|
|||||||
* are contained in the SPI cookie.
|
* are contained in the SPI cookie.
|
||||||
* @author R. Mueller
|
* @author R. Mueller
|
||||||
*/
|
*/
|
||||||
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 spiRetvalId = CLASS_ID::HAL_SPI;
|
||||||
static constexpr ReturnValue_t OPENING_FILE_FAILED =
|
static constexpr ReturnValue_t OPENING_FILE_FAILED =
|
||||||
HasReturnvaluesIF::makeReturnCode(spiRetvalId, 0);
|
HasReturnvaluesIF::makeReturnCode(spiRetvalId, 0);
|
||||||
@ -35,14 +34,11 @@ public:
|
|||||||
|
|
||||||
SpiComIF(object_id_t objectId, 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,
|
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
|
||||||
size_t sendLen) override;
|
ReturnValue_t getSendSuccess(CookieIF* cookie) override;
|
||||||
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
|
||||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
|
||||||
size_t requestLen) override;
|
|
||||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
|
||||||
size_t *size) override;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function returns the mutex which can be used to protect the spi bus when
|
* @brief This function returns the mutex which can be used to protect the spi bus when
|
||||||
@ -58,7 +54,7 @@ public:
|
|||||||
* @param sendLen
|
* @param sendLen
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ReturnValue_t performRegularSendOperation(SpiCookie* spiCookie, const uint8_t *sendData,
|
ReturnValue_t performRegularSendOperation(SpiCookie* spiCookie, const uint8_t* sendData,
|
||||||
size_t sendLen);
|
size_t sendLen);
|
||||||
|
|
||||||
GpioIF* getGpioInterface();
|
GpioIF* getGpioInterface();
|
||||||
@ -67,10 +63,9 @@ public:
|
|||||||
|
|
||||||
ReturnValue_t getReadBuffer(address_t spiAddress, uint8_t** buffer);
|
ReturnValue_t getReadBuffer(address_t spiAddress, uint8_t** buffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct SpiInstance {
|
struct SpiInstance {
|
||||||
SpiInstance(size_t maxRecvSize): replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
|
SpiInstance(size_t maxRecvSize) : replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
|
||||||
std::vector<uint8_t> replyBuffer;
|
std::vector<uint8_t> replyBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,42 +1,41 @@
|
|||||||
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
||||||
|
|
||||||
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
||||||
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed):
|
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed)
|
||||||
SpiCookie(spi::SpiComIfModes::REGULAR, spiAddress, chipSelect, spiDev, maxSize, spiMode,
|
: SpiCookie(spi::SpiComIfModes::REGULAR, spiAddress, chipSelect, spiDev, maxSize, spiMode,
|
||||||
spiSpeed, nullptr, nullptr) {
|
spiSpeed, nullptr, nullptr) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
SpiCookie::SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxSize,
|
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(spiAddress, gpio::NO_GPIO, spiDev, maxSize, spiMode, spiSpeed) {
|
: SpiCookie(spiAddress, gpio::NO_GPIO, spiDev, maxSize, spiMode, spiSpeed) {}
|
||||||
}
|
|
||||||
|
|
||||||
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
||||||
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,
|
: SpiCookie(spi::SpiComIfModes::CALLBACK, spiAddress, chipSelect, spiDev, maxSize, spiMode,
|
||||||
spiMode, spiSpeed, callback, args) {
|
spiSpeed, callback, args) {}
|
||||||
}
|
|
||||||
|
|
||||||
SpiCookie::SpiCookie(spi::SpiComIfModes comIfMode, address_t spiAddress, gpioId_t chipSelect,
|
SpiCookie::SpiCookie(spi::SpiComIfModes comIfMode, address_t spiAddress, gpioId_t chipSelect,
|
||||||
std::string spiDev, const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed,
|
std::string spiDev, const size_t maxSize, spi::SpiModes spiMode,
|
||||||
spi::send_callback_function_t callback, void* args):
|
uint32_t spiSpeed, spi::send_callback_function_t callback, void* args)
|
||||||
spiAddress(spiAddress), chipSelectPin(chipSelect), spiDevice(spiDev),
|
: spiAddress(spiAddress),
|
||||||
comIfMode(comIfMode), maxSize(maxSize), spiMode(spiMode), spiSpeed(spiSpeed),
|
chipSelectPin(chipSelect),
|
||||||
sendCallback(callback), callbackArgs(args) {
|
spiDevice(spiDev),
|
||||||
}
|
comIfMode(comIfMode),
|
||||||
|
maxSize(maxSize),
|
||||||
|
spiMode(spiMode),
|
||||||
|
spiSpeed(spiSpeed),
|
||||||
|
sendCallback(callback),
|
||||||
|
callbackArgs(args) {}
|
||||||
|
|
||||||
spi::SpiComIfModes SpiCookie::getComIfMode() const {
|
spi::SpiComIfModes SpiCookie::getComIfMode() const { return this->comIfMode; }
|
||||||
return this->comIfMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::getSpiParameters(spi::SpiModes& spiMode, uint32_t& spiSpeed,
|
void SpiCookie::getSpiParameters(spi::SpiModes& spiMode, uint32_t& spiSpeed,
|
||||||
UncommonParameters* parameters) const {
|
UncommonParameters* parameters) const {
|
||||||
spiMode = this->spiMode;
|
spiMode = this->spiMode;
|
||||||
spiSpeed = this->spiSpeed;
|
spiSpeed = this->spiSpeed;
|
||||||
|
|
||||||
if(parameters != nullptr) {
|
if (parameters != nullptr) {
|
||||||
parameters->threeWireSpi = uncommonParameters.threeWireSpi;
|
parameters->threeWireSpi = uncommonParameters.threeWireSpi;
|
||||||
parameters->lsbFirst = uncommonParameters.lsbFirst;
|
parameters->lsbFirst = uncommonParameters.lsbFirst;
|
||||||
parameters->noCs = uncommonParameters.noCs;
|
parameters->noCs = uncommonParameters.noCs;
|
||||||
@ -45,41 +44,25 @@ void SpiCookie::getSpiParameters(spi::SpiModes& spiMode, uint32_t& spiSpeed,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gpioId_t SpiCookie::getChipSelectPin() const {
|
gpioId_t SpiCookie::getChipSelectPin() const { return chipSelectPin; }
|
||||||
return chipSelectPin;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t SpiCookie::getMaxBufferSize() const {
|
size_t SpiCookie::getMaxBufferSize() const { return maxSize; }
|
||||||
return maxSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
address_t SpiCookie::getSpiAddress() const {
|
address_t SpiCookie::getSpiAddress() const { return spiAddress; }
|
||||||
return spiAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string SpiCookie::getSpiDevice() const {
|
std::string SpiCookie::getSpiDevice() const { return spiDevice; }
|
||||||
return spiDevice;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::setThreeWireSpi(bool enable) {
|
void SpiCookie::setThreeWireSpi(bool enable) { uncommonParameters.threeWireSpi = enable; }
|
||||||
uncommonParameters.threeWireSpi = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::setLsbFirst(bool enable) {
|
void SpiCookie::setLsbFirst(bool enable) { uncommonParameters.lsbFirst = enable; }
|
||||||
uncommonParameters.lsbFirst = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::setNoCs(bool enable) {
|
void SpiCookie::setNoCs(bool enable) { uncommonParameters.noCs = enable; }
|
||||||
uncommonParameters.noCs = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::setBitsPerWord(uint8_t bitsPerWord) {
|
void SpiCookie::setBitsPerWord(uint8_t bitsPerWord) {
|
||||||
uncommonParameters.bitsPerWord = bitsPerWord;
|
uncommonParameters.bitsPerWord = bitsPerWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiCookie::setCsHigh(bool enable) {
|
void SpiCookie::setCsHigh(bool enable) { uncommonParameters.csHigh = enable; }
|
||||||
uncommonParameters.csHigh = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::activateCsDeselect(bool deselectCs, uint16_t delayUsecs) {
|
void SpiCookie::activateCsDeselect(bool deselectCs, uint16_t delayUsecs) {
|
||||||
spiTransferStruct.cs_change = deselectCs;
|
spiTransferStruct.cs_change = deselectCs;
|
||||||
@ -87,58 +70,40 @@ void SpiCookie::activateCsDeselect(bool deselectCs, uint16_t delayUsecs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpiCookie::assignReadBuffer(uint8_t* rx) {
|
void SpiCookie::assignReadBuffer(uint8_t* rx) {
|
||||||
if(rx != nullptr) {
|
if (rx != nullptr) {
|
||||||
spiTransferStruct.rx_buf = reinterpret_cast<__u64>(rx);
|
spiTransferStruct.rx_buf = reinterpret_cast<__u64>(rx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiCookie::assignWriteBuffer(const uint8_t* tx) {
|
void SpiCookie::assignWriteBuffer(const uint8_t* tx) {
|
||||||
if(tx != nullptr) {
|
if (tx != nullptr) {
|
||||||
spiTransferStruct.tx_buf = reinterpret_cast<__u64>(tx);
|
spiTransferStruct.tx_buf = reinterpret_cast<__u64>(tx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiCookie::setCallbackMode(spi::send_callback_function_t callback,
|
void SpiCookie::setCallbackMode(spi::send_callback_function_t callback, void* args) {
|
||||||
void *args) {
|
|
||||||
this->comIfMode = spi::SpiComIfModes::CALLBACK;
|
this->comIfMode = spi::SpiComIfModes::CALLBACK;
|
||||||
this->sendCallback = callback;
|
this->sendCallback = callback;
|
||||||
this->callbackArgs = args;
|
this->callbackArgs = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiCookie::setCallbackArgs(void *args) {
|
void SpiCookie::setCallbackArgs(void* args) { this->callbackArgs = args; }
|
||||||
this->callbackArgs = args;
|
|
||||||
}
|
|
||||||
|
|
||||||
spi_ioc_transfer* SpiCookie::getTransferStructHandle() {
|
spi_ioc_transfer* SpiCookie::getTransferStructHandle() { return &spiTransferStruct; }
|
||||||
return &spiTransferStruct;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::setFullOrHalfDuplex(bool halfDuplex) {
|
void SpiCookie::setFullOrHalfDuplex(bool halfDuplex) { this->halfDuplex = halfDuplex; }
|
||||||
this->halfDuplex = halfDuplex;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SpiCookie::isFullDuplex() const {
|
bool SpiCookie::isFullDuplex() const { return not this->halfDuplex; }
|
||||||
return not this->halfDuplex;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::setTransferSize(size_t transferSize) {
|
void SpiCookie::setTransferSize(size_t transferSize) { spiTransferStruct.len = transferSize; }
|
||||||
spiTransferStruct.len = transferSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t SpiCookie::getCurrentTransferSize() const {
|
size_t SpiCookie::getCurrentTransferSize() const { return spiTransferStruct.len; }
|
||||||
return spiTransferStruct.len;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::setSpiSpeed(uint32_t newSpeed) {
|
void SpiCookie::setSpiSpeed(uint32_t newSpeed) { this->spiSpeed = newSpeed; }
|
||||||
this->spiSpeed = newSpeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::setSpiMode(spi::SpiModes newMode) {
|
void SpiCookie::setSpiMode(spi::SpiModes newMode) { this->spiMode = newMode; }
|
||||||
this->spiMode = newMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::getCallback(spi::send_callback_function_t *callback,
|
void SpiCookie::getCallback(spi::send_callback_function_t* callback, void** args) {
|
||||||
void **args) {
|
|
||||||
*callback = this->sendCallback;
|
*callback = this->sendCallback;
|
||||||
*args = this->callbackArgs;
|
*args = this->callbackArgs;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
#ifndef LINUX_SPI_SPICOOKIE_H_
|
#ifndef LINUX_SPI_SPICOOKIE_H_
|
||||||
#define LINUX_SPI_SPICOOKIE_H_
|
#define LINUX_SPI_SPICOOKIE_H_
|
||||||
|
|
||||||
#include "spiDefinitions.h"
|
|
||||||
#include "../../common/gpio/gpioDefinitions.h"
|
|
||||||
|
|
||||||
#include <fsfw/devicehandlers/CookieIF.h>
|
#include <fsfw/devicehandlers/CookieIF.h>
|
||||||
|
|
||||||
#include <linux/spi/spidev.h>
|
#include <linux/spi/spidev.h>
|
||||||
|
|
||||||
|
#include "../../common/gpio/gpioDefinitions.h"
|
||||||
|
#include "spiDefinitions.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This cookie class is passed to the SPI communication interface
|
* @brief This cookie class is passed to the SPI communication interface
|
||||||
* @details
|
* @details
|
||||||
@ -19,8 +18,8 @@
|
|||||||
* special requirements like expander slave select switching (e.g. GPIO or I2C expander)
|
* special requirements like expander slave select switching (e.g. GPIO or I2C expander)
|
||||||
* or special timing related requirements.
|
* or special timing related requirements.
|
||||||
*/
|
*/
|
||||||
class SpiCookie: public CookieIF {
|
class SpiCookie : public CookieIF {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Each SPI device will have a corresponding cookie. The cookie is used by the communication
|
* Each SPI device will have a corresponding cookie. The cookie is used by the communication
|
||||||
* interface and contains device specific information like the largest expected size to be
|
* interface and contains device specific information like the largest expected size to be
|
||||||
@ -30,8 +29,8 @@ public:
|
|||||||
* @param spiDev
|
* @param spiDev
|
||||||
* @param maxSize
|
* @param maxSize
|
||||||
*/
|
*/
|
||||||
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxSize,
|
||||||
const size_t maxSize, spi::SpiModes spiMode, 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
|
||||||
@ -46,7 +45,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxSize,
|
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxSize,
|
||||||
spi::SpiModes spiMode, uint32_t spiSpeed, spi::send_callback_function_t callback,
|
spi::SpiModes spiMode, uint32_t spiSpeed, spi::send_callback_function_t callback,
|
||||||
void *args);
|
void* args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the callback function
|
* Get the callback function
|
||||||
@ -141,8 +140,8 @@ public:
|
|||||||
void activateCsDeselect(bool deselectCs, uint16_t delayUsecs);
|
void activateCsDeselect(bool deselectCs, uint16_t delayUsecs);
|
||||||
|
|
||||||
spi_ioc_transfer* getTransferStructHandle();
|
spi_ioc_transfer* getTransferStructHandle();
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
/**
|
/**
|
||||||
* Internal constructor which initializes every field
|
* Internal constructor which initializes every field
|
||||||
* @param spiAddress
|
* @param spiAddress
|
||||||
@ -178,6 +177,4 @@ private:
|
|||||||
UncommonParameters uncommonParameters;
|
UncommonParameters uncommonParameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* LINUX_SPI_SPICOOKIE_H_ */
|
#endif /* LINUX_SPI_SPICOOKIE_H_ */
|
||||||
|
@ -1,28 +1,25 @@
|
|||||||
#ifndef LINUX_SPI_SPIDEFINITONS_H_
|
#ifndef LINUX_SPI_SPIDEFINITONS_H_
|
||||||
#define LINUX_SPI_SPIDEFINITONS_H_
|
#define LINUX_SPI_SPIDEFINITONS_H_
|
||||||
|
|
||||||
#include "../../common/gpio/gpioDefinitions.h"
|
|
||||||
#include "../../common/spi/spiCommon.h"
|
|
||||||
|
|
||||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
|
||||||
#include <linux/spi/spidev.h>
|
#include <linux/spi/spidev.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "../../common/gpio/gpioDefinitions.h"
|
||||||
|
#include "../../common/spi/spiCommon.h"
|
||||||
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
|
||||||
class SpiCookie;
|
class SpiCookie;
|
||||||
class SpiComIF;
|
class SpiComIF;
|
||||||
|
|
||||||
namespace spi {
|
namespace spi {
|
||||||
|
|
||||||
enum SpiComIfModes {
|
enum SpiComIfModes { REGULAR, CALLBACK };
|
||||||
REGULAR,
|
|
||||||
CALLBACK
|
|
||||||
};
|
|
||||||
|
|
||||||
|
using send_callback_function_t = ReturnValue_t (*)(SpiComIF* comIf, SpiCookie* cookie,
|
||||||
|
const uint8_t* sendData, size_t sendLen,
|
||||||
|
void* args);
|
||||||
|
|
||||||
using send_callback_function_t = ReturnValue_t (*) (SpiComIF* comIf, SpiCookie *cookie,
|
} // namespace spi
|
||||||
const uint8_t *sendData, size_t sendLen, void* args);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* LINUX_SPI_SPIDEFINITONS_H_ */
|
#endif /* LINUX_SPI_SPIDEFINITONS_H_ */
|
||||||
|
@ -1,39 +1,40 @@
|
|||||||
#include "UartComIF.h"
|
#include "UartComIF.h"
|
||||||
#include "OBSWConfig.h"
|
|
||||||
|
|
||||||
#include "fsfw_hal/linux/utility.h"
|
|
||||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
UartComIF::UartComIF(object_id_t objectId): SystemObject(objectId){
|
#include <cstring>
|
||||||
}
|
|
||||||
|
#include "fsfw/FSFW.h"
|
||||||
|
#include "fsfw/serviceinterface.h"
|
||||||
|
#include "fsfw_hal/linux/utility.h"
|
||||||
|
|
||||||
|
UartComIF::UartComIF(object_id_t objectId) : SystemObject(objectId) {}
|
||||||
|
|
||||||
UartComIF::~UartComIF() {}
|
UartComIF::~UartComIF() {}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
|
ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
|
||||||
|
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
UartDeviceMapIter uartDeviceMapIter;
|
UartDeviceMapIter uartDeviceMapIter;
|
||||||
|
|
||||||
if(cookie == nullptr) {
|
if (cookie == nullptr) {
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||||
if (uartCookie == nullptr) {
|
if (uartCookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "UartComIF::initializeInterface: Invalid UART Cookie!" << std::endl;
|
sif::error << "UartComIF::initializeInterface: Invalid UART Cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceFile = uartCookie->getDeviceFile();
|
deviceFile = uartCookie->getDeviceFile();
|
||||||
|
|
||||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||||
if(uartDeviceMapIter == uartDeviceMap.end()) {
|
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
||||||
int fileDescriptor = configureUartPort(uartCookie);
|
int fileDescriptor = configureUartPort(uartCookie);
|
||||||
if (fileDescriptor < 0) {
|
if (fileDescriptor < 0) {
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
@ -42,14 +43,17 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
|
|||||||
UartElements uartElements = {fileDescriptor, std::vector<uint8_t>(maxReplyLen), 0};
|
UartElements uartElements = {fileDescriptor, std::vector<uint8_t>(maxReplyLen), 0};
|
||||||
auto status = uartDeviceMap.emplace(deviceFile, uartElements);
|
auto status = uartDeviceMap.emplace(deviceFile, uartElements);
|
||||||
if (status.second == false) {
|
if (status.second == false) {
|
||||||
sif::warning << "UartComIF::initializeInterface: Failed to insert device " <<
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
deviceFile << "to UART device map" << std::endl;
|
sif::warning << "UartComIF::initializeInterface: Failed to insert device " << deviceFile
|
||||||
|
<< "to UART device map" << std::endl;
|
||||||
|
#endif
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
#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
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,12 +61,11 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
||||||
|
|
||||||
struct termios options = {};
|
struct termios options = {};
|
||||||
|
|
||||||
std::string deviceFile = uartCookie->getDeviceFile();
|
std::string deviceFile = uartCookie->getDeviceFile();
|
||||||
int flags = O_RDWR;
|
int flags = O_RDWR;
|
||||||
if(uartCookie->getUartMode() == UartModes::CANONICAL) {
|
if (uartCookie->getUartMode() == UartModes::CANONICAL) {
|
||||||
// In non-canonical mode, don't specify O_NONBLOCK because these properties will be
|
// In non-canonical mode, don't specify O_NONBLOCK because these properties will be
|
||||||
// controlled by the VTIME and VMIN parameters and O_NONBLOCK would override this
|
// controlled by the VTIME and VMIN parameters and O_NONBLOCK would override this
|
||||||
flags |= O_NONBLOCK;
|
flags |= O_NONBLOCK;
|
||||||
@ -70,15 +73,19 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
|||||||
int fd = open(deviceFile.c_str(), flags);
|
int fd = open(deviceFile.c_str(), flags);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile <<
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
"with error code " << errno << strerror(errno) << std::endl;
|
sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile
|
||||||
|
<< "with error code " << errno << strerror(errno) << std::endl;
|
||||||
|
#endif
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read in existing settings */
|
/* Read in existing settings */
|
||||||
if(tcgetattr(fd, &options) != 0) {
|
if (tcgetattr(fd, &options) != 0) {
|
||||||
sif::warning << "UartComIF::configureUartPort: Error " << errno << "from tcgetattr: "
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
<< strerror(errno) << std::endl;
|
sif::warning << "UartComIF::configureUartPort: Error " << errno
|
||||||
|
<< "from tcgetattr: " << strerror(errno) << std::endl;
|
||||||
|
#endif
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +94,7 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
|||||||
setDatasizeOptions(&options, uartCookie);
|
setDatasizeOptions(&options, uartCookie);
|
||||||
setFixedOptions(&options);
|
setFixedOptions(&options);
|
||||||
setUartMode(&options, *uartCookie);
|
setUartMode(&options, *uartCookie);
|
||||||
if(uartCookie->getInputShouldBeFlushed()) {
|
if (uartCookie->getInputShouldBeFlushed()) {
|
||||||
tcflush(fd, TCIFLUSH);
|
tcflush(fd, TCIFLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,8 +106,10 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
|||||||
|
|
||||||
/* Save option settings */
|
/* Save option settings */
|
||||||
if (tcsetattr(fd, TCSANOW, &options) != 0) {
|
if (tcsetattr(fd, TCSANOW, &options) != 0) {
|
||||||
sif::warning << "UartComIF::configureUartPort: Failed to set options with error " <<
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
errno << ": " << strerror(errno);
|
sif::warning << "UartComIF::configureUartPort: Failed to set options with error " << errno
|
||||||
|
<< ": " << strerror(errno);
|
||||||
|
#endif
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
@ -152,7 +161,9 @@ void UartComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCook
|
|||||||
options->c_cflag |= CS8;
|
options->c_cflag |= CS8;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "UartComIF::setDatasizeOptions: Invalid size specified" << std::endl;
|
sif::warning << "UartComIF::setDatasizeOptions: Invalid size specified" << std::endl;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,7 +184,7 @@ void UartComIF::setFixedOptions(struct termios* options) {
|
|||||||
/* Turn off s/w flow ctrl */
|
/* Turn off s/w flow ctrl */
|
||||||
options->c_iflag &= ~(IXON | IXOFF | IXANY);
|
options->c_iflag &= ~(IXON | IXOFF | IXANY);
|
||||||
/* Disable any special handling of received bytes */
|
/* Disable any special handling of received bytes */
|
||||||
options->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL);
|
options->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL);
|
||||||
/* Prevent special interpretation of output bytes (e.g. newline chars) */
|
/* Prevent special interpretation of output bytes (e.g. newline chars) */
|
||||||
options->c_oflag &= ~OPOST;
|
options->c_oflag &= ~OPOST;
|
||||||
/* Prevent conversion of newline to carriage return/line feed */
|
/* Prevent conversion of newline to carriage return/line feed */
|
||||||
@ -259,62 +270,71 @@ void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCooki
|
|||||||
cfsetospeed(options, B460800);
|
cfsetospeed(options, B460800);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "UartComIF::configureBaudrate: Baudrate not supported" << std::endl;
|
sif::warning << "UartComIF::configureBaudrate: Baudrate not supported" << std::endl;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::sendMessage(CookieIF *cookie,
|
ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
|
||||||
const uint8_t *sendData, size_t sendLen) {
|
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
UartDeviceMapIter uartDeviceMapIter;
|
UartDeviceMapIter uartDeviceMapIter;
|
||||||
|
|
||||||
if(sendLen == 0) {
|
if (sendLen == 0) {
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sendData == nullptr) {
|
if (sendData == nullptr) {
|
||||||
|
#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
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||||
if(uartCookie == nullptr) {
|
if (uartCookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl;
|
sif::warning << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceFile = uartCookie->getDeviceFile();
|
deviceFile = uartCookie->getDeviceFile();
|
||||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||||
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
||||||
sif::debug << "UartComIF::sendMessage: Device file " << deviceFile <<
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
"not in UART map" << std::endl;
|
sif::debug << "UartComIF::sendMessage: Device file " << deviceFile << "not in UART map"
|
||||||
|
<< std::endl;
|
||||||
|
#endif
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = uartDeviceMapIter->second.fileDescriptor;
|
fd = uartDeviceMapIter->second.fileDescriptor;
|
||||||
|
|
||||||
if (write(fd, sendData, sendLen) != (int)sendLen) {
|
if (write(fd, sendData, sendLen) != static_cast<int>(sendLen)) {
|
||||||
sif::error << "UartComIF::sendMessage: Failed to send data with error code " <<
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
errno << ": Error description: " << strerror(errno) << std::endl;
|
sif::error << "UartComIF::sendMessage: Failed to send data with error code " << errno
|
||||||
|
<< ": Error description: " << strerror(errno) << std::endl;
|
||||||
|
#endif
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::getSendSuccess(CookieIF *cookie) {
|
ReturnValue_t UartComIF::getSendSuccess(CookieIF* cookie) { return RETURN_OK; }
|
||||||
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;
|
||||||
UartDeviceMapIter uartDeviceMapIter;
|
UartDeviceMapIter uartDeviceMapIter;
|
||||||
|
|
||||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||||
if(uartCookie == nullptr) {
|
if (uartCookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::debug << "UartComIF::requestReceiveMessage: Invalid Uart Cookie!" << std::endl;
|
sif::debug << "UartComIF::requestReceiveMessage: Invalid Uart Cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,23 +342,23 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF *cookie, size_t requestL
|
|||||||
deviceFile = uartCookie->getDeviceFile();
|
deviceFile = uartCookie->getDeviceFile();
|
||||||
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 RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
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
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uartMode == UartModes::CANONICAL) {
|
if (uartMode == UartModes::CANONICAL) {
|
||||||
return handleCanonicalRead(*uartCookie, uartDeviceMapIter, requestLen);
|
return handleCanonicalRead(*uartCookie, uartDeviceMapIter, requestLen);
|
||||||
}
|
} 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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -356,7 +376,7 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
|
|||||||
iter->second.replyLen = 0;
|
iter->second.replyLen = 0;
|
||||||
do {
|
do {
|
||||||
size_t allowedReadSize = 0;
|
size_t allowedReadSize = 0;
|
||||||
if(currentBytesRead >= maxReplySize) {
|
if (currentBytesRead >= maxReplySize) {
|
||||||
// Overflow risk. Emit warning, trigger event and break. If this happens,
|
// Overflow risk. Emit warning, trigger event and break. If this happens,
|
||||||
// the reception buffer is not large enough or data is not polled often enough.
|
// the reception buffer is not large enough or data is not polled often enough.
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
@ -364,56 +384,56 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
|
|||||||
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
|
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("UartComIF::requestReceiveMessage: "
|
sif::printWarning(
|
||||||
|
"UartComIF::requestReceiveMessage: "
|
||||||
"Next read would cause overflow!");
|
"Next read would cause overflow!");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
result = UART_RX_BUFFER_TOO_SMALL;
|
result = UART_RX_BUFFER_TOO_SMALL;
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
allowedReadSize = maxReplySize - currentBytesRead;
|
allowedReadSize = maxReplySize - currentBytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytesRead = read(fd, bufferPtr, allowedReadSize);
|
bytesRead = read(fd, bufferPtr, allowedReadSize);
|
||||||
if (bytesRead < 0) {
|
if (bytesRead < 0) {
|
||||||
// EAGAIN: No data available in non-blocking mode
|
// EAGAIN: No data available in non-blocking mode
|
||||||
if(errno != EAGAIN) {
|
if (errno != EAGAIN) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "UartComIF::handleCanonicalRead: read failed with code" <<
|
sif::warning << "UartComIF::handleCanonicalRead: read failed with code" << errno << ": "
|
||||||
errno << ": " << strerror(errno) << std::endl;
|
<< strerror(errno) << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("UartComIF::handleCanonicalRead: read failed with code %d: %s\n",
|
sif::printWarning("UartComIF::handleCanonicalRead: read failed with code %d: %s\n", errno,
|
||||||
errno, strerror(errno));
|
strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else if (bytesRead > 0) {
|
||||||
else if(bytesRead > 0) {
|
|
||||||
iter->second.replyLen += bytesRead;
|
iter->second.replyLen += bytesRead;
|
||||||
bufferPtr += bytesRead;
|
bufferPtr += bytesRead;
|
||||||
currentBytesRead += bytesRead;
|
currentBytesRead += bytesRead;
|
||||||
}
|
}
|
||||||
currentReadCycles++;
|
currentReadCycles++;
|
||||||
} while(bytesRead > 0 and currentReadCycles < maxReadCycles);
|
} while (bytesRead > 0 and currentReadCycles < maxReadCycles);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie &uartCookie, UartDeviceMapIter &iter,
|
ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter,
|
||||||
size_t requestLen) {
|
size_t requestLen) {
|
||||||
int fd = iter->second.fileDescriptor;
|
int fd = iter->second.fileDescriptor;
|
||||||
auto bufferPtr = iter->second.replyBuffer.data();
|
auto bufferPtr = iter->second.replyBuffer.data();
|
||||||
// Size check to prevent buffer overflow
|
// Size check to prevent buffer overflow
|
||||||
if(requestLen > uartCookie.getMaxReplyLen()) {
|
if (requestLen > uartCookie.getMaxReplyLen()) {
|
||||||
#if OBSW_VERBOSE_LEVEL >= 1
|
#if OBSW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
|
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("UartComIF::requestReceiveMessage: "
|
sif::printWarning(
|
||||||
|
"UartComIF::requestReceiveMessage: "
|
||||||
"Next read would cause overflow!");
|
"Next read would cause overflow!");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -422,11 +442,12 @@ 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 RETURN_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
|
||||||
sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead <<
|
sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead << " of "
|
||||||
" of " << requestLen << " bytes" << std::endl;
|
<< requestLen << " bytes" << std::endl;
|
||||||
|
#endif
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -434,23 +455,25 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie &uartCookie, UartDevi
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::readReceivedMessage(CookieIF *cookie,
|
ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
|
||||||
uint8_t **buffer, size_t* size) {
|
|
||||||
|
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
UartDeviceMapIter uartDeviceMapIter;
|
UartDeviceMapIter uartDeviceMapIter;
|
||||||
|
|
||||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||||
if(uartCookie == nullptr) {
|
if (uartCookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::debug << "UartComIF::readReceivedMessage: Invalid uart cookie!" << std::endl;
|
sif::debug << "UartComIF::readReceivedMessage: Invalid uart cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceFile = uartCookie->getDeviceFile();
|
deviceFile = uartCookie->getDeviceFile();
|
||||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||||
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
if (uartDeviceMapIter == uartDeviceMap.end()) {
|
||||||
sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile <<
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
" not in uart map" << std::endl;
|
sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile << " not in uart map"
|
||||||
|
<< std::endl;
|
||||||
|
#endif
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,17 +486,19 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF *cookie,
|
|||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF *cookie) {
|
ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) {
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
UartDeviceMapIter uartDeviceMapIter;
|
UartDeviceMapIter uartDeviceMapIter;
|
||||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||||
if(uartCookie == nullptr) {
|
if (uartCookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "UartComIF::flushUartRxBuffer: Invalid uart cookie!" << std::endl;
|
sif::warning << "UartComIF::flushUartRxBuffer: Invalid uart cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
deviceFile = uartCookie->getDeviceFile();
|
deviceFile = uartCookie->getDeviceFile();
|
||||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||||
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 RETURN_OK;
|
return RETURN_OK;
|
||||||
@ -481,17 +506,19 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF *cookie) {
|
|||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) {
|
ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) {
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
UartDeviceMapIter uartDeviceMapIter;
|
UartDeviceMapIter uartDeviceMapIter;
|
||||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||||
if(uartCookie == nullptr) {
|
if (uartCookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "UartComIF::flushUartTxBuffer: Invalid uart cookie!" << std::endl;
|
sif::warning << "UartComIF::flushUartTxBuffer: Invalid uart cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
deviceFile = uartCookie->getDeviceFile();
|
deviceFile = uartCookie->getDeviceFile();
|
||||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||||
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 RETURN_OK;
|
return RETURN_OK;
|
||||||
@ -499,17 +526,19 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) {
|
|||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) {
|
ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) {
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
UartDeviceMapIter uartDeviceMapIter;
|
UartDeviceMapIter uartDeviceMapIter;
|
||||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||||
if(uartCookie == nullptr) {
|
if (uartCookie == nullptr) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "UartComIF::flushUartTxAndRxBuf: Invalid uart cookie!" << std::endl;
|
sif::warning << "UartComIF::flushUartTxAndRxBuf: Invalid uart cookie!" << std::endl;
|
||||||
|
#endif
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
deviceFile = uartCookie->getDeviceFile();
|
deviceFile = uartCookie->getDeviceFile();
|
||||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||||
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 RETURN_OK;
|
return RETURN_OK;
|
||||||
@ -517,13 +546,12 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) {
|
|||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UartComIF::setUartMode(struct termios *options, UartCookie &uartCookie) {
|
void UartComIF::setUartMode(struct termios* options, UartCookie& uartCookie) {
|
||||||
UartModes uartMode = uartCookie.getUartMode();
|
UartModes uartMode = uartCookie.getUartMode();
|
||||||
if(uartMode == UartModes::NON_CANONICAL) {
|
if (uartMode == UartModes::NON_CANONICAL) {
|
||||||
/* Disable canonical mode */
|
/* Disable canonical mode */
|
||||||
options->c_lflag &= ~ICANON;
|
options->c_lflag &= ~ICANON;
|
||||||
}
|
} else if (uartMode == UartModes::CANONICAL) {
|
||||||
else if(uartMode == UartModes::CANONICAL) {
|
|
||||||
options->c_lflag |= ICANON;
|
options->c_lflag |= ICANON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
#ifndef BSP_Q7S_COMIF_UARTCOMIF_H_
|
#ifndef BSP_Q7S_COMIF_UARTCOMIF_H_
|
||||||
#define BSP_Q7S_COMIF_UARTCOMIF_H_
|
#define BSP_Q7S_COMIF_UARTCOMIF_H_
|
||||||
|
|
||||||
#include "UartCookie.h"
|
|
||||||
#include <fsfw/objectmanager/SystemObject.h>
|
|
||||||
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
||||||
|
#include <fsfw/objectmanager/SystemObject.h>
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "UartCookie.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This is the communication interface to access serial ports on linux based operating
|
* @brief This is the communication interface to access serial ports on linux based operating
|
||||||
* systems.
|
* systems.
|
||||||
@ -17,8 +18,8 @@
|
|||||||
*
|
*
|
||||||
* @author J. Meier
|
* @author J. Meier
|
||||||
*/
|
*/
|
||||||
class UartComIF: public DeviceCommunicationIF, public SystemObject {
|
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 =
|
static constexpr ReturnValue_t UART_READ_FAILURE =
|
||||||
@ -32,32 +33,28 @@ public:
|
|||||||
|
|
||||||
virtual ~UartComIF();
|
virtual ~UartComIF();
|
||||||
|
|
||||||
ReturnValue_t initializeInterface(CookieIF * cookie) override;
|
ReturnValue_t initializeInterface(CookieIF* cookie) override;
|
||||||
ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData,
|
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
|
||||||
size_t sendLen) override;
|
ReturnValue_t getSendSuccess(CookieIF* cookie) override;
|
||||||
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
|
||||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
|
||||||
size_t requestLen) override;
|
|
||||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
|
||||||
size_t *size) override;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function discards all data received but not read in the UART buffer.
|
* @brief This function discards all data received but not read in the UART buffer.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t flushUartRxBuffer(CookieIF *cookie);
|
ReturnValue_t flushUartRxBuffer(CookieIF* cookie);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function discards all data in the transmit buffer of the UART driver.
|
* @brief This function discards all data in the transmit buffer of the UART driver.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t flushUartTxBuffer(CookieIF *cookie);
|
ReturnValue_t flushUartTxBuffer(CookieIF* cookie);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function discards both data in the transmit and receive buffer of the UART.
|
* @brief This function discards both data in the transmit and receive buffer of the UART.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t flushUartTxAndRxBuf(CookieIF *cookie);
|
ReturnValue_t flushUartTxAndRxBuf(CookieIF* cookie);
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
using UartDeviceFile_t = std::string;
|
using UartDeviceFile_t = std::string;
|
||||||
|
|
||||||
struct UartElements {
|
struct UartElements {
|
||||||
@ -119,7 +116,6 @@ private:
|
|||||||
size_t requestLen);
|
size_t requestLen);
|
||||||
ReturnValue_t handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter,
|
ReturnValue_t handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter,
|
||||||
size_t requestLen);
|
size_t requestLen);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* BSP_Q7S_COMIF_UARTCOMIF_H_ */
|
#endif /* BSP_Q7S_COMIF_UARTCOMIF_H_ */
|
||||||
|
@ -1,97 +1,65 @@
|
|||||||
#include "fsfw_hal/linux/uart/UartCookie.h"
|
#include "fsfw_hal/linux/uart/UartCookie.h"
|
||||||
|
|
||||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
#include <fsfw/serviceinterface.h>
|
||||||
|
|
||||||
UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode,
|
UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode,
|
||||||
uint32_t baudrate, size_t maxReplyLen):
|
uint32_t baudrate, size_t maxReplyLen)
|
||||||
handlerId(handlerId), deviceFile(deviceFile), uartMode(uartMode),
|
: handlerId(handlerId),
|
||||||
baudrate(baudrate), maxReplyLen(maxReplyLen) {
|
deviceFile(deviceFile),
|
||||||
}
|
uartMode(uartMode),
|
||||||
|
baudrate(baudrate),
|
||||||
|
maxReplyLen(maxReplyLen) {}
|
||||||
|
|
||||||
UartCookie::~UartCookie() {}
|
UartCookie::~UartCookie() {}
|
||||||
|
|
||||||
uint32_t UartCookie::getBaudrate() const {
|
uint32_t UartCookie::getBaudrate() const { return baudrate; }
|
||||||
return baudrate;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t UartCookie::getMaxReplyLen() const {
|
size_t UartCookie::getMaxReplyLen() const { return maxReplyLen; }
|
||||||
return maxReplyLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string UartCookie::getDeviceFile() const {
|
std::string UartCookie::getDeviceFile() const { return deviceFile; }
|
||||||
return deviceFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UartCookie::setParityOdd() {
|
void UartCookie::setParityOdd() { parity = Parity::ODD; }
|
||||||
parity = Parity::ODD;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UartCookie::setParityEven() {
|
void UartCookie::setParityEven() { parity = Parity::EVEN; }
|
||||||
parity = Parity::EVEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
Parity UartCookie::getParity() const {
|
Parity UartCookie::getParity() const { return parity; }
|
||||||
return parity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UartCookie::setBitsPerWord(uint8_t bitsPerWord_) {
|
void UartCookie::setBitsPerWord(uint8_t bitsPerWord_) {
|
||||||
switch(bitsPerWord_) {
|
switch (bitsPerWord_) {
|
||||||
case 5:
|
case 5:
|
||||||
case 6:
|
case 6:
|
||||||
case 7:
|
case 7:
|
||||||
case 8:
|
case 8:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::debug << "UartCookie::setBitsPerWord: Invalid bits per word specified" << std::endl;
|
sif::debug << "UartCookie::setBitsPerWord: Invalid bits per word specified" << std::endl;
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bitsPerWord = bitsPerWord_;
|
bitsPerWord = bitsPerWord_;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t UartCookie::getBitsPerWord() const {
|
uint8_t UartCookie::getBitsPerWord() const { return bitsPerWord; }
|
||||||
return bitsPerWord;
|
|
||||||
}
|
|
||||||
|
|
||||||
StopBits UartCookie::getStopBits() const {
|
StopBits UartCookie::getStopBits() const { return stopBits; }
|
||||||
return stopBits;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UartCookie::setTwoStopBits() {
|
void UartCookie::setTwoStopBits() { stopBits = StopBits::TWO_STOP_BITS; }
|
||||||
stopBits = StopBits::TWO_STOP_BITS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UartCookie::setOneStopBit() {
|
void UartCookie::setOneStopBit() { stopBits = StopBits::ONE_STOP_BIT; }
|
||||||
stopBits = StopBits::ONE_STOP_BIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
UartModes UartCookie::getUartMode() const {
|
UartModes UartCookie::getUartMode() const { return uartMode; }
|
||||||
return uartMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UartCookie::setReadCycles(uint8_t readCycles) {
|
void UartCookie::setReadCycles(uint8_t readCycles) { this->readCycles = readCycles; }
|
||||||
this->readCycles = readCycles;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UartCookie::setToFlushInput(bool enable) {
|
void UartCookie::setToFlushInput(bool enable) { this->flushInput = enable; }
|
||||||
this->flushInput = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t UartCookie::getReadCycles() const {
|
uint8_t UartCookie::getReadCycles() const { return readCycles; }
|
||||||
return readCycles;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UartCookie::getInputShouldBeFlushed() {
|
bool UartCookie::getInputShouldBeFlushed() { return this->flushInput; }
|
||||||
return this->flushInput;
|
|
||||||
}
|
|
||||||
|
|
||||||
object_id_t UartCookie::getHandlerId() const {
|
object_id_t UartCookie::getHandlerId() const { return this->handlerId; }
|
||||||
return this->handlerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UartCookie::setNoFixedSizeReply() {
|
void UartCookie::setNoFixedSizeReply() { replySizeFixed = false; }
|
||||||
replySizeFixed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UartCookie::isReplySizeFixed() {
|
bool UartCookie::isReplySizeFixed() { return replySizeFixed; }
|
||||||
return replySizeFixed;
|
|
||||||
}
|
|
||||||
|
@ -6,21 +6,11 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enum class Parity {
|
enum class Parity { NONE, EVEN, ODD };
|
||||||
NONE,
|
|
||||||
EVEN,
|
|
||||||
ODD
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class StopBits {
|
enum class StopBits { ONE_STOP_BIT, TWO_STOP_BITS };
|
||||||
ONE_STOP_BIT,
|
|
||||||
TWO_STOP_BITS
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class UartModes {
|
enum class UartModes { CANONICAL, NON_CANONICAL };
|
||||||
CANONICAL,
|
|
||||||
NON_CANONICAL
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Cookie for the UartComIF. There are many options available to configure the UART driver.
|
* @brief Cookie for the UartComIF. There are many options available to configure the UART driver.
|
||||||
@ -29,9 +19,8 @@ enum class UartModes {
|
|||||||
*
|
*
|
||||||
* @author J. Meier
|
* @author J. Meier
|
||||||
*/
|
*/
|
||||||
class UartCookie: public CookieIF {
|
class UartCookie : public CookieIF {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructor for the uart cookie.
|
* @brief Constructor for the uart cookie.
|
||||||
* @param deviceFile The device file specifying the uart to use, e.g. "/dev/ttyPS1"
|
* @param deviceFile The device file specifying the uart to use, e.g. "/dev/ttyPS1"
|
||||||
@ -47,8 +36,8 @@ public:
|
|||||||
* 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, UartModes uartMode,
|
UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, uint32_t baudrate,
|
||||||
uint32_t baudrate, size_t maxReplyLen);
|
size_t maxReplyLen);
|
||||||
|
|
||||||
virtual ~UartCookie();
|
virtual ~UartCookie();
|
||||||
|
|
||||||
@ -103,8 +92,7 @@ public:
|
|||||||
|
|
||||||
bool isReplySizeFixed();
|
bool isReplySizeFixed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const object_id_t handlerId;
|
const object_id_t handlerId;
|
||||||
std::string deviceFile;
|
std::string deviceFile;
|
||||||
const UartModes uartMode;
|
const UartModes uartMode;
|
||||||
|
@ -1,26 +1,23 @@
|
|||||||
#include "fsfw/FSFW.h"
|
|
||||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
|
||||||
#include "fsfw_hal/linux/utility.h"
|
#include "fsfw_hal/linux/utility.h"
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "fsfw/FSFW.h"
|
||||||
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
void utility::handleIoctlError(const char* const customPrintout) {
|
void utility::handleIoctlError(const char* const customPrintout) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
if(customPrintout != nullptr) {
|
if (customPrintout != nullptr) {
|
||||||
sif::warning << customPrintout << std::endl;
|
sif::warning << customPrintout << std::endl;
|
||||||
}
|
}
|
||||||
sif::warning << "handleIoctlError: Error code " << errno << ", "<< strerror(errno) <<
|
sif::warning << "handleIoctlError: Error code " << errno << ", " << strerror(errno) << std::endl;
|
||||||
std::endl;
|
|
||||||
#else
|
#else
|
||||||
if(customPrintout != nullptr) {
|
if (customPrintout != nullptr) {
|
||||||
sif::printWarning("%s\n", customPrintout);
|
sif::printWarning("%s\n", customPrintout);
|
||||||
}
|
}
|
||||||
sif::printWarning("handleIoctlError: Error code %d, %s\n", errno, strerror(errno));
|
sif::printWarning("handleIoctlError: Error code %d, %s\n", errno, strerror(errno));
|
||||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define FSFW_HAL_STM32H7_DEFINITIONS_H_
|
#define FSFW_HAL_STM32H7_DEFINITIONS_H_
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "stm32h7xx.h"
|
#include "stm32h7xx.h"
|
||||||
|
|
||||||
namespace stm32h7 {
|
namespace stm32h7 {
|
||||||
@ -11,15 +12,15 @@ namespace stm32h7 {
|
|||||||
* and the second entry is the pin number
|
* and the second entry is the pin number
|
||||||
*/
|
*/
|
||||||
struct GpioCfg {
|
struct GpioCfg {
|
||||||
GpioCfg(): port(nullptr), pin(0), altFnc(0) {};
|
GpioCfg() : port(nullptr), pin(0), altFnc(0){};
|
||||||
|
|
||||||
GpioCfg(GPIO_TypeDef* port, uint16_t pin, uint8_t altFnc = 0):
|
GpioCfg(GPIO_TypeDef* port, uint16_t pin, uint8_t altFnc = 0)
|
||||||
port(port), pin(pin), altFnc(altFnc) {};
|
: port(port), pin(pin), altFnc(altFnc){};
|
||||||
GPIO_TypeDef* port;
|
GPIO_TypeDef* port;
|
||||||
uint16_t pin;
|
uint16_t pin;
|
||||||
uint8_t altFnc;
|
uint8_t altFnc;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace stm32h7
|
||||||
|
|
||||||
#endif /* #ifndef FSFW_HAL_STM32H7_DEFINITIONS_H_ */
|
#endif /* #ifndef FSFW_HAL_STM32H7_DEFINITIONS_H_ */
|
||||||
|
@ -1,51 +1,47 @@
|
|||||||
#include "fsfw_hal/stm32h7/devicetest/GyroL3GD20H.h"
|
#include "fsfw_hal/stm32h7/devicetest/GyroL3GD20H.h"
|
||||||
|
|
||||||
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
|
||||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
|
||||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
|
||||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
|
||||||
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
|
|
||||||
|
|
||||||
#include "fsfw/tasks/TaskFactory.h"
|
|
||||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
|
||||||
|
|
||||||
#include "stm32h7xx_hal_spi.h"
|
|
||||||
#include "stm32h7xx_hal_rcc.h"
|
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
|
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
||||||
|
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||||
|
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||||
|
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||||
|
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
|
||||||
|
#include "stm32h7xx_hal_rcc.h"
|
||||||
|
#include "stm32h7xx_hal_spi.h"
|
||||||
|
|
||||||
alignas(32) std::array<uint8_t, GyroL3GD20H::recvBufferSize> GyroL3GD20H::rxBuffer;
|
alignas(32) std::array<uint8_t, GyroL3GD20H::recvBufferSize> GyroL3GD20H::rxBuffer;
|
||||||
alignas(32) std::array<uint8_t, GyroL3GD20H::txBufferSize>
|
alignas(32) std::array<uint8_t, GyroL3GD20H::txBufferSize> GyroL3GD20H::txBuffer
|
||||||
GyroL3GD20H::txBuffer __attribute__((section(".dma_buffer")));
|
__attribute__((section(".dma_buffer")));
|
||||||
|
|
||||||
TransferStates transferState = TransferStates::IDLE;
|
TransferStates transferState = TransferStates::IDLE;
|
||||||
spi::TransferModes GyroL3GD20H::transferMode = spi::TransferModes::POLLING;
|
spi::TransferModes GyroL3GD20H::transferMode = spi::TransferModes::POLLING;
|
||||||
|
|
||||||
|
GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transferMode_)
|
||||||
GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transferMode_):
|
: spiHandle(spiHandle) {
|
||||||
spiHandle(spiHandle) {
|
|
||||||
txDmaHandle = new DMA_HandleTypeDef();
|
txDmaHandle = new DMA_HandleTypeDef();
|
||||||
rxDmaHandle = new DMA_HandleTypeDef();
|
rxDmaHandle = new DMA_HandleTypeDef();
|
||||||
spi::setSpiHandle(spiHandle);
|
spi::setSpiHandle(spiHandle);
|
||||||
spi::assignSpiUserArgs(spi::SpiBus::SPI_1, spiHandle);
|
spi::assignSpiUserArgs(spi::SpiBus::SPI_1, spiHandle);
|
||||||
transferMode = transferMode_;
|
transferMode = transferMode_;
|
||||||
if(transferMode == spi::TransferModes::DMA) {
|
if (transferMode == spi::TransferModes::DMA) {
|
||||||
mspCfg = new spi::MspDmaConfigStruct();
|
mspCfg = new spi::MspDmaConfigStruct();
|
||||||
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct*>(mspCfg);
|
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct *>(mspCfg);
|
||||||
spi::setDmaHandles(txDmaHandle, rxDmaHandle);
|
spi::setDmaHandles(txDmaHandle, rxDmaHandle);
|
||||||
stm32h7::h743zi::standardDmaCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS,
|
stm32h7::h743zi::standardDmaCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS,
|
||||||
IrqPriorities::HIGHEST_FREERTOS, IrqPriorities::HIGHEST_FREERTOS);
|
IrqPriorities::HIGHEST_FREERTOS,
|
||||||
|
IrqPriorities::HIGHEST_FREERTOS);
|
||||||
spi::setSpiDmaMspFunctions(typedCfg);
|
spi::setSpiDmaMspFunctions(typedCfg);
|
||||||
}
|
} else if (transferMode == spi::TransferModes::INTERRUPT) {
|
||||||
else if(transferMode == spi::TransferModes::INTERRUPT) {
|
|
||||||
mspCfg = new spi::MspIrqConfigStruct();
|
mspCfg = new spi::MspIrqConfigStruct();
|
||||||
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct*>(mspCfg);
|
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct *>(mspCfg);
|
||||||
stm32h7::h743zi::standardInterruptCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS);
|
stm32h7::h743zi::standardInterruptCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS);
|
||||||
spi::setSpiIrqMspFunctions(typedCfg);
|
spi::setSpiIrqMspFunctions(typedCfg);
|
||||||
}
|
} else if (transferMode == spi::TransferModes::POLLING) {
|
||||||
else if(transferMode == spi::TransferModes::POLLING) {
|
|
||||||
mspCfg = new spi::MspPollingConfigStruct();
|
mspCfg = new spi::MspPollingConfigStruct();
|
||||||
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct*>(mspCfg);
|
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct *>(mspCfg);
|
||||||
stm32h7::h743zi::standardPollingCfg(*typedCfg);
|
stm32h7::h743zi::standardPollingCfg(*typedCfg);
|
||||||
spi::setSpiPollingMspFunctions(typedCfg);
|
spi::setSpiPollingMspFunctions(typedCfg);
|
||||||
}
|
}
|
||||||
@ -64,7 +60,7 @@ GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transf
|
|||||||
GyroL3GD20H::~GyroL3GD20H() {
|
GyroL3GD20H::~GyroL3GD20H() {
|
||||||
delete txDmaHandle;
|
delete txDmaHandle;
|
||||||
delete rxDmaHandle;
|
delete rxDmaHandle;
|
||||||
if(mspCfg != nullptr) {
|
if (mspCfg != nullptr) {
|
||||||
delete mspCfg;
|
delete mspCfg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,7 +82,7 @@ ReturnValue_t GyroL3GD20H::initialize() {
|
|||||||
// Recommended setting to avoid glitches
|
// Recommended setting to avoid glitches
|
||||||
spiHandle->Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE;
|
spiHandle->Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE;
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -99,14 +95,14 @@ ReturnValue_t GyroL3GD20H::initialize() {
|
|||||||
txBuffer[0] = WHO_AM_I_REG | STM_READ_MASK;
|
txBuffer[0] = WHO_AM_I_REG | STM_READ_MASK;
|
||||||
txBuffer[1] = 0;
|
txBuffer[1] = 0;
|
||||||
|
|
||||||
switch(transferMode) {
|
switch (transferMode) {
|
||||||
case(spi::TransferModes::DMA): {
|
case (spi::TransferModes::DMA): {
|
||||||
return handleDmaTransferInit();
|
return handleDmaTransferInit();
|
||||||
}
|
}
|
||||||
case(spi::TransferModes::INTERRUPT): {
|
case (spi::TransferModes::INTERRUPT): {
|
||||||
return handleInterruptTransferInit();
|
return handleInterruptTransferInit();
|
||||||
}
|
}
|
||||||
case(spi::TransferModes::POLLING): {
|
case (spi::TransferModes::POLLING): {
|
||||||
return handlePollingTransferInit();
|
return handlePollingTransferInit();
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -118,14 +114,14 @@ ReturnValue_t GyroL3GD20H::initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t GyroL3GD20H::performOperation() {
|
ReturnValue_t GyroL3GD20H::performOperation() {
|
||||||
switch(transferMode) {
|
switch (transferMode) {
|
||||||
case(spi::TransferModes::DMA): {
|
case (spi::TransferModes::DMA): {
|
||||||
return handleDmaSensorRead();
|
return handleDmaSensorRead();
|
||||||
}
|
}
|
||||||
case(spi::TransferModes::POLLING): {
|
case (spi::TransferModes::POLLING): {
|
||||||
return handlePollingSensorRead();
|
return handlePollingSensorRead();
|
||||||
}
|
}
|
||||||
case(spi::TransferModes::INTERRUPT): {
|
case (spi::TransferModes::INTERRUPT): {
|
||||||
return handleInterruptSensorRead();
|
return handleInterruptSensorRead();
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -141,7 +137,7 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
|||||||
in case it overlaps cacheline */
|
in case it overlaps cacheline */
|
||||||
// See https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices
|
// See https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices
|
||||||
HAL_StatusTypeDef result = performDmaTransfer(2);
|
HAL_StatusTypeDef result = performDmaTransfer(2);
|
||||||
if(result != HAL_OK) {
|
if (result != HAL_OK) {
|
||||||
// Transfer error in transmission process
|
// Transfer error in transmission process
|
||||||
sif::printWarning("GyroL3GD20H::initialize: Error transmitting SPI with DMA\n");
|
sif::printWarning("GyroL3GD20H::initialize: Error transmitting SPI with DMA\n");
|
||||||
}
|
}
|
||||||
@ -151,17 +147,19 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
|||||||
TaskFactory::delayTask(1);
|
TaskFactory::delayTask(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(transferState) {
|
switch (transferState) {
|
||||||
case(TransferStates::SUCCESS): {
|
case (TransferStates::SUCCESS): {
|
||||||
uint8_t whoAmIVal = rxBuffer[1];
|
uint8_t whoAmIVal = rxBuffer[1];
|
||||||
if(whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
|
if (whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: "
|
sif::printDebug(
|
||||||
"Read WHO AM I value %d not equal to expected value!\n", whoAmIVal);
|
"GyroL3GD20H::initialize: "
|
||||||
|
"Read WHO AM I value %d not equal to expected value!\n",
|
||||||
|
whoAmIVal);
|
||||||
}
|
}
|
||||||
transferState = TransferStates::IDLE;
|
transferState = TransferStates::IDLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(TransferStates::FAILURE): {
|
case (TransferStates::FAILURE): {
|
||||||
sif::printWarning("Transfer failure\n");
|
sif::printWarning("Transfer failure\n");
|
||||||
transferState = TransferStates::FAILURE;
|
transferState = TransferStates::FAILURE;
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
@ -177,7 +175,7 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
|||||||
prepareConfigRegs(configRegs);
|
prepareConfigRegs(configRegs);
|
||||||
|
|
||||||
result = performDmaTransfer(6);
|
result = performDmaTransfer(6);
|
||||||
if(result != HAL_OK) {
|
if (result != HAL_OK) {
|
||||||
// Transfer error in transmission process
|
// Transfer error in transmission process
|
||||||
sif::printWarning("Error transmitting SPI with DMA\n");
|
sif::printWarning("Error transmitting SPI with DMA\n");
|
||||||
}
|
}
|
||||||
@ -187,13 +185,13 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
|||||||
TaskFactory::delayTask(1);
|
TaskFactory::delayTask(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(transferState) {
|
switch (transferState) {
|
||||||
case(TransferStates::SUCCESS): {
|
case (TransferStates::SUCCESS): {
|
||||||
sif::printInfo("GyroL3GD20H::initialize: Configuration transfer success\n");
|
sif::printInfo("GyroL3GD20H::initialize: Configuration transfer success\n");
|
||||||
transferState = TransferStates::IDLE;
|
transferState = TransferStates::IDLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
@ -203,11 +201,10 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
||||||
std::memset(txBuffer.data() + 1, 0 , 5);
|
std::memset(txBuffer.data() + 1, 0, 5);
|
||||||
result = performDmaTransfer(6);
|
result = performDmaTransfer(6);
|
||||||
if(result != HAL_OK) {
|
if (result != HAL_OK) {
|
||||||
// Transfer error in transmission process
|
// Transfer error in transmission process
|
||||||
sif::printWarning("Error transmitting SPI with DMA\n");
|
sif::printWarning("Error transmitting SPI with DMA\n");
|
||||||
}
|
}
|
||||||
@ -216,20 +213,19 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
|||||||
TaskFactory::delayTask(1);
|
TaskFactory::delayTask(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(transferState) {
|
switch (transferState) {
|
||||||
case(TransferStates::SUCCESS): {
|
case (TransferStates::SUCCESS): {
|
||||||
if(rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
|
if (rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
|
||||||
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
|
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
|
||||||
rxBuffer[5] != configRegs[4]) {
|
rxBuffer[5] != configRegs[4]) {
|
||||||
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
|
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
|
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
|
||||||
}
|
}
|
||||||
transferState = TransferStates::IDLE;
|
transferState = TransferStates::IDLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
@ -243,10 +239,10 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
|
|||||||
|
|
||||||
ReturnValue_t GyroL3GD20H::handleDmaSensorRead() {
|
ReturnValue_t GyroL3GD20H::handleDmaSensorRead() {
|
||||||
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
||||||
std::memset(txBuffer.data() + 1, 0 , 14);
|
std::memset(txBuffer.data() + 1, 0, 14);
|
||||||
|
|
||||||
HAL_StatusTypeDef result = performDmaTransfer(15);
|
HAL_StatusTypeDef result = performDmaTransfer(15);
|
||||||
if(result != HAL_OK) {
|
if (result != HAL_OK) {
|
||||||
// Transfer error in transmission process
|
// Transfer error in transmission process
|
||||||
sif::printDebug("GyroL3GD20H::handleDmaSensorRead: Error transmitting SPI with DMA\n");
|
sif::printDebug("GyroL3GD20H::handleDmaSensorRead: Error transmitting SPI with DMA\n");
|
||||||
}
|
}
|
||||||
@ -255,12 +251,12 @@ ReturnValue_t GyroL3GD20H::handleDmaSensorRead() {
|
|||||||
TaskFactory::delayTask(1);
|
TaskFactory::delayTask(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(transferState) {
|
switch (transferState) {
|
||||||
case(TransferStates::SUCCESS): {
|
case (TransferStates::SUCCESS): {
|
||||||
handleSensorReadout();
|
handleSensorReadout();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
@ -275,8 +271,8 @@ ReturnValue_t GyroL3GD20H::handleDmaSensorRead() {
|
|||||||
HAL_StatusTypeDef GyroL3GD20H::performDmaTransfer(size_t sendSize) {
|
HAL_StatusTypeDef GyroL3GD20H::performDmaTransfer(size_t sendSize) {
|
||||||
transferState = TransferStates::WAIT;
|
transferState = TransferStates::WAIT;
|
||||||
#if STM_USE_PERIPHERAL_TX_BUFFER_MPU_PROTECTION == 0
|
#if STM_USE_PERIPHERAL_TX_BUFFER_MPU_PROTECTION == 0
|
||||||
SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t)txBuffer.data()) & ~(uint32_t)0x1F),
|
SCB_CleanDCache_by_Addr((uint32_t *)(((uint32_t)txBuffer.data()) & ~(uint32_t)0x1F),
|
||||||
txBuffer.size()+32);
|
txBuffer.size() + 32);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Start SPI transfer via DMA
|
// Start SPI transfer via DMA
|
||||||
@ -288,21 +284,23 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
|
|||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||||
auto result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 2, 1000);
|
auto result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 2, 1000);
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
||||||
switch(result) {
|
switch (result) {
|
||||||
case(HAL_OK): {
|
case (HAL_OK): {
|
||||||
sif::printInfo("GyroL3GD20H::initialize: Polling transfer success\n");
|
sif::printInfo("GyroL3GD20H::initialize: Polling transfer success\n");
|
||||||
uint8_t whoAmIVal = rxBuffer[1];
|
uint8_t whoAmIVal = rxBuffer[1];
|
||||||
if(whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
|
if (whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
|
||||||
sif::printDebug("GyroL3GD20H::performOperation: "
|
sif::printDebug(
|
||||||
"Read WHO AM I value %d not equal to expected value!\n", whoAmIVal);
|
"GyroL3GD20H::performOperation: "
|
||||||
|
"Read WHO AM I value %d not equal to expected value!\n",
|
||||||
|
whoAmIVal);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
||||||
return HasReturnvaluesIF::RETURN_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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -319,15 +317,15 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
|
|||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||||
result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 6, 1000);
|
result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 6, 1000);
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
||||||
switch(result) {
|
switch (result) {
|
||||||
case(HAL_OK): {
|
case (HAL_OK): {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
||||||
return HasReturnvaluesIF::RETURN_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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -337,28 +335,27 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
||||||
std::memset(txBuffer.data() + 1, 0 , 5);
|
std::memset(txBuffer.data() + 1, 0, 5);
|
||||||
|
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||||
result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 6, 1000);
|
result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 6, 1000);
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
||||||
switch(result) {
|
switch (result) {
|
||||||
case(HAL_OK): {
|
case (HAL_OK): {
|
||||||
if(rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
|
if (rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
|
||||||
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
|
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
|
||||||
rxBuffer[5] != configRegs[4]) {
|
rxBuffer[5] != configRegs[4]) {
|
||||||
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
|
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
|
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
||||||
return HasReturnvaluesIF::RETURN_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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -371,21 +368,21 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
|
|||||||
|
|
||||||
ReturnValue_t GyroL3GD20H::handlePollingSensorRead() {
|
ReturnValue_t GyroL3GD20H::handlePollingSensorRead() {
|
||||||
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
||||||
std::memset(txBuffer.data() + 1, 0 , 14);
|
std::memset(txBuffer.data() + 1, 0, 14);
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||||
auto result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 15, 1000);
|
auto result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 15, 1000);
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
||||||
|
|
||||||
switch(result) {
|
switch (result) {
|
||||||
case(HAL_OK): {
|
case (HAL_OK): {
|
||||||
handleSensorReadout();
|
handleSensorReadout();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
|
||||||
return HasReturnvaluesIF::RETURN_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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -398,8 +395,8 @@ ReturnValue_t GyroL3GD20H::handlePollingSensorRead() {
|
|||||||
|
|
||||||
ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||||
switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 2)) {
|
switch (HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 2)) {
|
||||||
case(HAL_OK): {
|
case (HAL_OK): {
|
||||||
sif::printInfo("GyroL3GD20H::initialize: Interrupt transfer success\n");
|
sif::printInfo("GyroL3GD20H::initialize: Interrupt transfer success\n");
|
||||||
// Wait for the transfer to complete
|
// Wait for the transfer to complete
|
||||||
while (transferState == TransferStates::WAIT) {
|
while (transferState == TransferStates::WAIT) {
|
||||||
@ -407,15 +404,17 @@ ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t whoAmIVal = rxBuffer[1];
|
uint8_t whoAmIVal = rxBuffer[1];
|
||||||
if(whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
|
if (whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
|
||||||
sif::printDebug("GyroL3GD20H::initialize: "
|
sif::printDebug(
|
||||||
"Read WHO AM I value %d not equal to expected value!\n", whoAmIVal);
|
"GyroL3GD20H::initialize: "
|
||||||
|
"Read WHO AM I value %d not equal to expected value!\n",
|
||||||
|
whoAmIVal);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(HAL_BUSY):
|
case (HAL_BUSY):
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -427,45 +426,44 @@ ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
|||||||
uint8_t configRegs[5];
|
uint8_t configRegs[5];
|
||||||
prepareConfigRegs(configRegs);
|
prepareConfigRegs(configRegs);
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||||
switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 6)) {
|
switch (HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 6)) {
|
||||||
case(HAL_OK): {
|
case (HAL_OK): {
|
||||||
// Wait for the transfer to complete
|
// Wait for the transfer to complete
|
||||||
while (transferState == TransferStates::WAIT) {
|
while (transferState == TransferStates::WAIT) {
|
||||||
TaskFactory::delayTask(1);
|
TaskFactory::delayTask(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(HAL_BUSY):
|
case (HAL_BUSY):
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
||||||
std::memset(txBuffer.data() + 1, 0 , 5);
|
std::memset(txBuffer.data() + 1, 0, 5);
|
||||||
transferState = TransferStates::WAIT;
|
transferState = TransferStates::WAIT;
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||||
switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 6)) {
|
switch (HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 6)) {
|
||||||
case(HAL_OK): {
|
case (HAL_OK): {
|
||||||
// Wait for the transfer to complete
|
// Wait for the transfer to complete
|
||||||
while (transferState == TransferStates::WAIT) {
|
while (transferState == TransferStates::WAIT) {
|
||||||
TaskFactory::delayTask(1);
|
TaskFactory::delayTask(1);
|
||||||
}
|
}
|
||||||
if(rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
|
if (rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
|
||||||
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
|
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
|
||||||
rxBuffer[5] != configRegs[4]) {
|
rxBuffer[5] != configRegs[4]) {
|
||||||
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
|
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
|
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(HAL_BUSY):
|
case (HAL_BUSY):
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -476,10 +474,10 @@ ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
|
|||||||
ReturnValue_t GyroL3GD20H::handleInterruptSensorRead() {
|
ReturnValue_t GyroL3GD20H::handleInterruptSensorRead() {
|
||||||
transferState = TransferStates::WAIT;
|
transferState = TransferStates::WAIT;
|
||||||
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
|
||||||
std::memset(txBuffer.data() + 1, 0 , 14);
|
std::memset(txBuffer.data() + 1, 0, 14);
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||||
switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 15)) {
|
switch (HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 15)) {
|
||||||
case(HAL_OK): {
|
case (HAL_OK): {
|
||||||
// Wait for the transfer to complete
|
// Wait for the transfer to complete
|
||||||
while (transferState == TransferStates::WAIT) {
|
while (transferState == TransferStates::WAIT) {
|
||||||
TaskFactory::delayTask(1);
|
TaskFactory::delayTask(1);
|
||||||
@ -487,9 +485,9 @@ ReturnValue_t GyroL3GD20H::handleInterruptSensorRead() {
|
|||||||
handleSensorReadout();
|
handleSensorReadout();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(HAL_BUSY):
|
case (HAL_BUSY):
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -497,7 +495,7 @@ ReturnValue_t GyroL3GD20H::handleInterruptSensorRead() {
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GyroL3GD20H::prepareConfigRegs(uint8_t* configRegs) {
|
void GyroL3GD20H::prepareConfigRegs(uint8_t *configRegs) {
|
||||||
// Enable sensor
|
// Enable sensor
|
||||||
configRegs[0] = 0b00001111;
|
configRegs[0] = 0b00001111;
|
||||||
configRegs[1] = 0b00000000;
|
configRegs[1] = 0b00000000;
|
||||||
@ -516,7 +514,8 @@ uint8_t GyroL3GD20H::readRegPolling(uint8_t reg) {
|
|||||||
txBuf[0] = reg | STM_READ_MASK;
|
txBuf[0] = reg | STM_READ_MASK;
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||||
auto result = HAL_SPI_TransmitReceive(spiHandle, txBuf, rxBuf, 2, 1000);
|
auto result = HAL_SPI_TransmitReceive(spiHandle, txBuf, rxBuf, 2, 1000);
|
||||||
if(result) {};
|
if (result) {
|
||||||
|
};
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
||||||
return rxBuf[1];
|
return rxBuf[1];
|
||||||
}
|
}
|
||||||
@ -535,13 +534,12 @@ void GyroL3GD20H::handleSensorReadout() {
|
|||||||
sif::printInfo("Gyro Z: %f\n", gyroZ);
|
sif::printInfo("Gyro Z: %f\n", gyroZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GyroL3GD20H::spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void *args) {
|
||||||
void GyroL3GD20H::spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* args) {
|
|
||||||
transferState = TransferStates::SUCCESS;
|
transferState = TransferStates::SUCCESS;
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
|
||||||
if(GyroL3GD20H::transferMode == spi::TransferModes::DMA) {
|
if (GyroL3GD20H::transferMode == spi::TransferModes::DMA) {
|
||||||
// Invalidate cache prior to access by CPU
|
// Invalidate cache prior to access by CPU
|
||||||
SCB_InvalidateDCache_by_Addr ((uint32_t *)GyroL3GD20H::rxBuffer.data(),
|
SCB_InvalidateDCache_by_Addr((uint32_t *)GyroL3GD20H::rxBuffer.data(),
|
||||||
GyroL3GD20H::recvBufferSize);
|
GyroL3GD20H::recvBufferSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -553,6 +551,6 @@ void GyroL3GD20H::spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* arg
|
|||||||
* add your own implementation.
|
* add your own implementation.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void GyroL3GD20H::spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void* args) {
|
void GyroL3GD20H::spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void *args) {
|
||||||
transferState = TransferStates::FAILURE;
|
transferState = TransferStates::FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,26 @@
|
|||||||
#ifndef FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
|
#ifndef FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
|
||||||
#define FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
|
#define FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
|
||||||
|
|
||||||
#include "stm32h7xx_hal.h"
|
#include <array>
|
||||||
#include "stm32h7xx_hal_spi.h"
|
#include <cstdint>
|
||||||
|
|
||||||
#include "../spi/mspInit.h"
|
#include "../spi/mspInit.h"
|
||||||
#include "../spi/spiDefinitions.h"
|
#include "../spi/spiDefinitions.h"
|
||||||
|
|
||||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
#include "stm32h7xx_hal.h"
|
||||||
|
#include "stm32h7xx_hal_spi.h"
|
||||||
|
|
||||||
#include <cstdint>
|
enum class TransferStates { IDLE, WAIT, SUCCESS, FAILURE };
|
||||||
#include <array>
|
|
||||||
|
|
||||||
enum class TransferStates {
|
|
||||||
IDLE,
|
|
||||||
WAIT,
|
|
||||||
SUCCESS,
|
|
||||||
FAILURE
|
|
||||||
};
|
|
||||||
|
|
||||||
class GyroL3GD20H {
|
class GyroL3GD20H {
|
||||||
public:
|
public:
|
||||||
GyroL3GD20H(SPI_HandleTypeDef* spiHandle, spi::TransferModes transferMode);
|
GyroL3GD20H(SPI_HandleTypeDef* spiHandle, spi::TransferModes transferMode);
|
||||||
~GyroL3GD20H();
|
~GyroL3GD20H();
|
||||||
|
|
||||||
ReturnValue_t initialize();
|
ReturnValue_t initialize();
|
||||||
ReturnValue_t performOperation();
|
ReturnValue_t performOperation();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const uint8_t WHO_AM_I_REG = 0b00001111;
|
const uint8_t WHO_AM_I_REG = 0b00001111;
|
||||||
const uint8_t STM_READ_MASK = 0b10000000;
|
const uint8_t STM_READ_MASK = 0b10000000;
|
||||||
const uint8_t STM_AUTO_INCREMENT_MASK = 0b01000000;
|
const uint8_t STM_AUTO_INCREMENT_MASK = 0b01000000;
|
||||||
@ -54,14 +47,12 @@ private:
|
|||||||
|
|
||||||
uint8_t readRegPolling(uint8_t reg);
|
uint8_t readRegPolling(uint8_t reg);
|
||||||
|
|
||||||
static void spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* args);
|
static void spiTransferCompleteCallback(SPI_HandleTypeDef* hspi, void* args);
|
||||||
static void spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void* args);
|
static void spiTransferErrorCallback(SPI_HandleTypeDef* hspi, void* args);
|
||||||
|
|
||||||
|
|
||||||
void prepareConfigRegs(uint8_t* configRegs);
|
void prepareConfigRegs(uint8_t* configRegs);
|
||||||
void handleSensorReadout();
|
void handleSensorReadout();
|
||||||
|
|
||||||
|
|
||||||
DMA_HandleTypeDef* txDmaHandle = {};
|
DMA_HandleTypeDef* txDmaHandle = {};
|
||||||
DMA_HandleTypeDef* rxDmaHandle = {};
|
DMA_HandleTypeDef* rxDmaHandle = {};
|
||||||
spi::MspCfgBase* mspCfg = {};
|
spi::MspCfgBase* mspCfg = {};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include <fsfw_hal/stm32h7/dma.h>
|
#include <fsfw_hal/stm32h7/dma.h>
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
user_handler_t DMA_1_USER_HANDLERS[8];
|
user_handler_t DMA_1_USER_HANDLERS[8];
|
||||||
user_args_t DMA_1_USER_ARGS[8];
|
user_args_t DMA_1_USER_ARGS[8];
|
||||||
@ -11,11 +11,10 @@ user_args_t DMA_2_USER_ARGS[8];
|
|||||||
|
|
||||||
void dma::assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx,
|
void dma::assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx,
|
||||||
user_handler_t user_handler, user_args_t user_args) {
|
user_handler_t user_handler, user_args_t user_args) {
|
||||||
if(dma_idx == DMA_1) {
|
if (dma_idx == DMA_1) {
|
||||||
DMA_1_USER_HANDLERS[stream_idx] = user_handler;
|
DMA_1_USER_HANDLERS[stream_idx] = user_handler;
|
||||||
DMA_1_USER_ARGS[stream_idx] = user_args;
|
DMA_1_USER_ARGS[stream_idx] = user_args;
|
||||||
}
|
} else if (dma_idx == DMA_2) {
|
||||||
else if(dma_idx == DMA_2) {
|
|
||||||
DMA_2_USER_HANDLERS[stream_idx] = user_handler;
|
DMA_2_USER_HANDLERS[stream_idx] = user_handler;
|
||||||
DMA_2_USER_ARGS[stream_idx] = user_args;
|
DMA_2_USER_ARGS[stream_idx] = user_args;
|
||||||
}
|
}
|
||||||
@ -27,58 +26,26 @@ void dma::assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx,
|
|||||||
defined in the startup_stm32h743xx.s files! */
|
defined in the startup_stm32h743xx.s files! */
|
||||||
|
|
||||||
#define GENERIC_DMA_IRQ_HANDLER(DMA_IDX, STREAM_IDX) \
|
#define GENERIC_DMA_IRQ_HANDLER(DMA_IDX, STREAM_IDX) \
|
||||||
if(DMA_##DMA_IDX##_USER_HANDLERS[STREAM_IDX] != NULL) { \
|
if (DMA_##DMA_IDX##_USER_HANDLERS[STREAM_IDX] != NULL) { \
|
||||||
DMA_##DMA_IDX##_USER_HANDLERS[STREAM_IDX](DMA_##DMA_IDX##_USER_ARGS[STREAM_IDX]); \
|
DMA_##DMA_IDX##_USER_HANDLERS[STREAM_IDX](DMA_##DMA_IDX##_USER_ARGS[STREAM_IDX]); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
Default_Handler() \
|
Default_Handler()
|
||||||
|
|
||||||
extern"C" void DMA1_Stream0_IRQHandler() {
|
extern "C" void DMA1_Stream0_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 0); }
|
||||||
GENERIC_DMA_IRQ_HANDLER(1, 0);
|
extern "C" void DMA1_Stream1_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 1); }
|
||||||
}
|
extern "C" void DMA1_Stream2_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 2); }
|
||||||
extern"C" void DMA1_Stream1_IRQHandler() {
|
extern "C" void DMA1_Stream3_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 3); }
|
||||||
GENERIC_DMA_IRQ_HANDLER(1, 1);
|
extern "C" void DMA1_Stream4_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 4); }
|
||||||
}
|
extern "C" void DMA1_Stream5_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 5); }
|
||||||
extern"C" void DMA1_Stream2_IRQHandler() {
|
extern "C" void DMA1_Stream6_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 6); }
|
||||||
GENERIC_DMA_IRQ_HANDLER(1, 2);
|
extern "C" void DMA1_Stream7_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 7); }
|
||||||
}
|
|
||||||
extern"C" void DMA1_Stream3_IRQHandler() {
|
|
||||||
GENERIC_DMA_IRQ_HANDLER(1, 3);
|
|
||||||
}
|
|
||||||
extern"C" void DMA1_Stream4_IRQHandler() {
|
|
||||||
GENERIC_DMA_IRQ_HANDLER(1, 4);
|
|
||||||
}
|
|
||||||
extern"C" void DMA1_Stream5_IRQHandler() {
|
|
||||||
GENERIC_DMA_IRQ_HANDLER(1, 5);
|
|
||||||
}
|
|
||||||
extern"C" void DMA1_Stream6_IRQHandler() {
|
|
||||||
GENERIC_DMA_IRQ_HANDLER(1, 6);
|
|
||||||
}
|
|
||||||
extern"C" void DMA1_Stream7_IRQHandler() {
|
|
||||||
GENERIC_DMA_IRQ_HANDLER(1, 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern"C" void DMA2_Stream0_IRQHandler() {
|
extern "C" void DMA2_Stream0_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 0); }
|
||||||
GENERIC_DMA_IRQ_HANDLER(2, 0);
|
extern "C" void DMA2_Stream1_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 1); }
|
||||||
}
|
extern "C" void DMA2_Stream2_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 2); }
|
||||||
extern"C" void DMA2_Stream1_IRQHandler() {
|
extern "C" void DMA2_Stream3_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 3); }
|
||||||
GENERIC_DMA_IRQ_HANDLER(2, 1);
|
extern "C" void DMA2_Stream4_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 4); }
|
||||||
}
|
extern "C" void DMA2_Stream5_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 5); }
|
||||||
extern"C" void DMA2_Stream2_IRQHandler() {
|
extern "C" void DMA2_Stream6_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 6); }
|
||||||
GENERIC_DMA_IRQ_HANDLER(2, 2);
|
extern "C" void DMA2_Stream7_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 7); }
|
||||||
}
|
|
||||||
extern"C" void DMA2_Stream3_IRQHandler() {
|
|
||||||
GENERIC_DMA_IRQ_HANDLER(2, 3);
|
|
||||||
}
|
|
||||||
extern"C" void DMA2_Stream4_IRQHandler() {
|
|
||||||
GENERIC_DMA_IRQ_HANDLER(2, 4);
|
|
||||||
}
|
|
||||||
extern"C" void DMA2_Stream5_IRQHandler() {
|
|
||||||
GENERIC_DMA_IRQ_HANDLER(2, 5);
|
|
||||||
}
|
|
||||||
extern"C" void DMA2_Stream6_IRQHandler() {
|
|
||||||
GENERIC_DMA_IRQ_HANDLER(2, 6);
|
|
||||||
}
|
|
||||||
extern"C" void DMA2_Stream7_IRQHandler() {
|
|
||||||
GENERIC_DMA_IRQ_HANDLER(2, 7);
|
|
||||||
}
|
|
||||||
|
@ -5,20 +5,15 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "interrupts.h"
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "interrupts.h"
|
||||||
|
|
||||||
namespace dma {
|
namespace dma {
|
||||||
|
|
||||||
enum DMAType {
|
enum DMAType { TX = 0, RX = 1 };
|
||||||
TX = 0,
|
|
||||||
RX = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
enum DMAIndexes: uint8_t {
|
enum DMAIndexes : uint8_t { DMA_1 = 1, DMA_2 = 2 };
|
||||||
DMA_1 = 1,
|
|
||||||
DMA_2 = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum DMAStreams {
|
enum DMAStreams {
|
||||||
STREAM_0 = 0,
|
STREAM_0 = 0,
|
||||||
@ -29,7 +24,7 @@ enum DMAStreams {
|
|||||||
STREAM_5 = 5,
|
STREAM_5 = 5,
|
||||||
STREAM_6 = 6,
|
STREAM_6 = 6,
|
||||||
STREAM_7 = 7,
|
STREAM_7 = 7,
|
||||||
} ;
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign user interrupt handlers for DMA streams, allowing to pass an
|
* Assign user interrupt handlers for DMA streams, allowing to pass an
|
||||||
@ -37,10 +32,10 @@ enum DMAStreams {
|
|||||||
* @param user_handler
|
* @param user_handler
|
||||||
* @param user_args
|
* @param user_args
|
||||||
*/
|
*/
|
||||||
void assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx,
|
void assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx, user_handler_t user_handler,
|
||||||
user_handler_t user_handler, user_args_t user_args);
|
user_args_t user_args);
|
||||||
|
|
||||||
}
|
} // namespace dma
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -4,67 +4,67 @@
|
|||||||
|
|
||||||
void gpio::initializeGpioClock(GPIO_TypeDef* gpioPort) {
|
void gpio::initializeGpioClock(GPIO_TypeDef* gpioPort) {
|
||||||
#ifdef GPIOA
|
#ifdef GPIOA
|
||||||
if(gpioPort == GPIOA) {
|
if (gpioPort == GPIOA) {
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GPIOB
|
#ifdef GPIOB
|
||||||
if(gpioPort == GPIOB) {
|
if (gpioPort == GPIOB) {
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GPIOC
|
#ifdef GPIOC
|
||||||
if(gpioPort == GPIOC) {
|
if (gpioPort == GPIOC) {
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GPIOD
|
#ifdef GPIOD
|
||||||
if(gpioPort == GPIOD) {
|
if (gpioPort == GPIOD) {
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GPIOE
|
#ifdef GPIOE
|
||||||
if(gpioPort == GPIOE) {
|
if (gpioPort == GPIOE) {
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GPIOF
|
#ifdef GPIOF
|
||||||
if(gpioPort == GPIOF) {
|
if (gpioPort == GPIOF) {
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GPIOG
|
#ifdef GPIOG
|
||||||
if(gpioPort == GPIOG) {
|
if (gpioPort == GPIOG) {
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GPIOH
|
#ifdef GPIOH
|
||||||
if(gpioPort == GPIOH) {
|
if (gpioPort == GPIOH) {
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GPIOI
|
#ifdef GPIOI
|
||||||
if(gpioPort == GPIOI) {
|
if (gpioPort == GPIOI) {
|
||||||
__HAL_RCC_GPIOI_CLK_ENABLE();
|
__HAL_RCC_GPIOI_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GPIOJ
|
#ifdef GPIOJ
|
||||||
if(gpioPort == GPIOJ) {
|
if (gpioPort == GPIOJ) {
|
||||||
__HAL_RCC_GPIOJ_CLK_ENABLE();
|
__HAL_RCC_GPIOJ_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GPIOK
|
#ifdef GPIOK
|
||||||
if(gpioPort == GPIOK) {
|
if (gpioPort == GPIOK) {
|
||||||
__HAL_RCC_GPIOK_CLK_ENABLE();
|
__HAL_RCC_GPIOK_CLK_ENABLE();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,14 +12,10 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
extern void Default_Handler();
|
extern void Default_Handler();
|
||||||
|
|
||||||
typedef void (*user_handler_t) (void*);
|
typedef void (*user_handler_t)(void*);
|
||||||
typedef void* user_args_t;
|
typedef void* user_args_t;
|
||||||
|
|
||||||
enum IrqPriorities: uint8_t {
|
enum IrqPriorities : uint8_t { HIGHEST = 0, HIGHEST_FREERTOS = 6, LOWEST = 15 };
|
||||||
HIGHEST = 0,
|
|
||||||
HIGHEST_FREERTOS = 6,
|
|
||||||
LOWEST = 15
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#include "fsfw_hal/stm32h7/spi/SpiComIF.h"
|
#include "fsfw_hal/stm32h7/spi/SpiComIF.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
|
|
||||||
|
|
||||||
#include "fsfw/tasks/SemaphoreFactory.h"
|
#include "fsfw/tasks/SemaphoreFactory.h"
|
||||||
|
#include "fsfw_hal/stm32h7/gpio/gpio.h"
|
||||||
|
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
|
||||||
|
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
|
||||||
#include "fsfw_hal/stm32h7/gpio/gpio.h"
|
|
||||||
|
|
||||||
// FreeRTOS required special Semaphore handling from an ISR. Therefore, we use the concrete
|
// FreeRTOS required special Semaphore handling from an ISR. Therefore, we use the concrete
|
||||||
// instance here, because RTEMS and FreeRTOS are the only relevant OSALs currently
|
// instance here, because RTEMS and FreeRTOS are the only relevant OSALs currently
|
||||||
@ -13,14 +13,14 @@
|
|||||||
#if defined FSFW_OSAL_RTEMS
|
#if defined FSFW_OSAL_RTEMS
|
||||||
#include "fsfw/osal/rtems/BinarySemaphore.h"
|
#include "fsfw/osal/rtems/BinarySemaphore.h"
|
||||||
#elif defined FSFW_OSAL_FREERTOS
|
#elif defined FSFW_OSAL_FREERTOS
|
||||||
#include "fsfw/osal/freertos/TaskManagement.h"
|
|
||||||
#include "fsfw/osal/freertos/BinarySemaphore.h"
|
#include "fsfw/osal/freertos/BinarySemaphore.h"
|
||||||
|
#include "fsfw/osal/freertos/TaskManagement.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "stm32h7xx_hal_gpio.h"
|
#include "stm32h7xx_hal_gpio.h"
|
||||||
|
|
||||||
SpiComIF::SpiComIF(object_id_t objectId): SystemObject(objectId) {
|
SpiComIF::SpiComIF(object_id_t objectId) : SystemObject(objectId) {
|
||||||
void* irqArgsVoided = reinterpret_cast<void*>(&irqArgs);
|
void *irqArgsVoided = reinterpret_cast<void *>(&irqArgs);
|
||||||
spi::assignTransferRxTxCompleteCallback(&spiTransferCompleteCallback, irqArgsVoided);
|
spi::assignTransferRxTxCompleteCallback(&spiTransferCompleteCallback, irqArgsVoided);
|
||||||
spi::assignTransferRxCompleteCallback(&spiTransferRxCompleteCallback, irqArgsVoided);
|
spi::assignTransferRxCompleteCallback(&spiTransferRxCompleteCallback, irqArgsVoided);
|
||||||
spi::assignTransferTxCompleteCallback(&spiTransferTxCompleteCallback, irqArgsVoided);
|
spi::assignTransferTxCompleteCallback(&spiTransferTxCompleteCallback, irqArgsVoided);
|
||||||
@ -35,13 +35,11 @@ void SpiComIF::addDmaHandles(DMA_HandleTypeDef *txHandle, DMA_HandleTypeDef *rxH
|
|||||||
spi::setDmaHandles(txHandle, rxHandle);
|
spi::setDmaHandles(txHandle, rxHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::initialize() {
|
ReturnValue_t SpiComIF::initialize() { return HasReturnvaluesIF::RETURN_OK; }
|
||||||
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);
|
||||||
if(spiCookie == nullptr) {
|
if (spiCookie == nullptr) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error < "SpiComIF::initializeInterface: Invalid cookie" << std::endl;
|
sif::error < "SpiComIF::initializeInterface: Invalid cookie" << std::endl;
|
||||||
#else
|
#else
|
||||||
@ -51,32 +49,34 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
}
|
}
|
||||||
auto transferMode = spiCookie->getTransferMode();
|
auto transferMode = spiCookie->getTransferMode();
|
||||||
|
|
||||||
if(transferMode == spi::TransferModes::DMA) {
|
if (transferMode == spi::TransferModes::DMA) {
|
||||||
DMA_HandleTypeDef *txHandle = nullptr;
|
DMA_HandleTypeDef *txHandle = nullptr;
|
||||||
DMA_HandleTypeDef *rxHandle = nullptr;
|
DMA_HandleTypeDef *rxHandle = nullptr;
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// This semaphore ensures thread-safety for a given bus
|
// This semaphore ensures thread-safety for a given bus
|
||||||
spiSemaphore = dynamic_cast<BinarySemaphore*>(
|
spiSemaphore =
|
||||||
SemaphoreFactory::instance()->createBinarySemaphore());
|
dynamic_cast<BinarySemaphore *>(SemaphoreFactory::instance()->createBinarySemaphore());
|
||||||
address_t spiAddress = spiCookie->getDeviceAddress();
|
address_t spiAddress = spiCookie->getDeviceAddress();
|
||||||
|
|
||||||
auto iter = spiDeviceMap.find(spiAddress);
|
auto iter = spiDeviceMap.find(spiAddress);
|
||||||
if(iter == spiDeviceMap.end()) {
|
if (iter == spiDeviceMap.end()) {
|
||||||
size_t bufferSize = spiCookie->getMaxRecvSize();
|
size_t bufferSize = spiCookie->getMaxRecvSize();
|
||||||
auto statusPair = spiDeviceMap.emplace(spiAddress, SpiInstance(bufferSize));
|
auto statusPair = spiDeviceMap.emplace(spiAddress, SpiInstance(bufferSize));
|
||||||
if (not statusPair.second) {
|
if (not statusPair.second) {
|
||||||
#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::initializeInterface: Failed to insert device with address " <<
|
sif::error << "SpiComIF::initializeInterface: Failed to insert device with address "
|
||||||
spiAddress << "to SPI device map" << std::endl;
|
<< spiAddress << "to SPI device map" << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printError("SpiComIF::initializeInterface: Failed to insert device with address "
|
sif::printError(
|
||||||
"%lu to SPI device map\n", static_cast<unsigned long>(spiAddress));
|
"SpiComIF::initializeInterface: Failed to insert device with address "
|
||||||
|
"%lu to SPI device map\n",
|
||||||
|
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
@ -85,60 +85,56 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
auto gpioPin = spiCookie->getChipSelectGpioPin();
|
auto gpioPin = spiCookie->getChipSelectGpioPin();
|
||||||
auto gpioPort = spiCookie->getChipSelectGpioPort();
|
auto gpioPort = spiCookie->getChipSelectGpioPort();
|
||||||
|
|
||||||
SPI_HandleTypeDef& spiHandle = spiCookie->getSpiHandle();
|
SPI_HandleTypeDef &spiHandle = spiCookie->getSpiHandle();
|
||||||
|
|
||||||
auto spiIdx = spiCookie->getSpiIdx();
|
auto spiIdx = spiCookie->getSpiIdx();
|
||||||
if(spiIdx == spi::SpiBus::SPI_1) {
|
if (spiIdx == spi::SpiBus::SPI_1) {
|
||||||
#ifdef SPI1
|
#ifdef SPI1
|
||||||
spiHandle.Instance = SPI1;
|
spiHandle.Instance = SPI1;
|
||||||
#endif
|
#endif
|
||||||
}
|
} else if (spiIdx == spi::SpiBus::SPI_2) {
|
||||||
else if(spiIdx == spi::SpiBus::SPI_2) {
|
|
||||||
#ifdef SPI2
|
#ifdef SPI2
|
||||||
spiHandle.Instance = SPI2;
|
spiHandle.Instance = SPI2;
|
||||||
#endif
|
#endif
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
printCfgError("SPI Bus Index");
|
printCfgError("SPI Bus Index");
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto mspCfg = spiCookie->getMspCfg();
|
auto mspCfg = spiCookie->getMspCfg();
|
||||||
|
|
||||||
if(transferMode == spi::TransferModes::POLLING) {
|
if (transferMode == spi::TransferModes::POLLING) {
|
||||||
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 HasReturnvaluesIF::RETURN_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 HasReturnvaluesIF::RETURN_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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
// Check DMA handles
|
// Check DMA handles
|
||||||
DMA_HandleTypeDef* txHandle = nullptr;
|
DMA_HandleTypeDef *txHandle = nullptr;
|
||||||
DMA_HandleTypeDef* rxHandle = nullptr;
|
DMA_HandleTypeDef *rxHandle = nullptr;
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
spi::setSpiDmaMspFunctions(typedCfg);
|
spi::setSpiDmaMspFunctions(typedCfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gpioPort != nullptr) {
|
if (gpioPort != nullptr) {
|
||||||
gpio::initializeGpioClock(gpioPort);
|
gpio::initializeGpioClock(gpioPort);
|
||||||
GPIO_InitTypeDef chipSelect = {};
|
GPIO_InitTypeDef chipSelect = {};
|
||||||
chipSelect.Pin = gpioPin;
|
chipSelect.Pin = gpioPin;
|
||||||
@ -147,7 +143,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -158,42 +154,42 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
if(spiCookie == nullptr) {
|
if (spiCookie == nullptr) {
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPI_HandleTypeDef& spiHandle = spiCookie->getSpiHandle();
|
SPI_HandleTypeDef &spiHandle = spiCookie->getSpiHandle();
|
||||||
|
|
||||||
auto iter = spiDeviceMap.find(spiCookie->getDeviceAddress());
|
auto iter = spiDeviceMap.find(spiCookie->getDeviceAddress());
|
||||||
if(iter == spiDeviceMap.end()) {
|
if (iter == spiDeviceMap.end()) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
iter->second.currentTransferLen = sendLen;
|
iter->second.currentTransferLen = sendLen;
|
||||||
|
|
||||||
auto transferMode = spiCookie->getTransferMode();
|
auto transferMode = spiCookie->getTransferMode();
|
||||||
switch(spiCookie->getTransferState()) {
|
switch (spiCookie->getTransferState()) {
|
||||||
case(spi::TransferStates::IDLE): {
|
case (spi::TransferStates::IDLE): {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(spi::TransferStates::WAIT):
|
case (spi::TransferStates::WAIT):
|
||||||
case(spi::TransferStates::FAILURE):
|
case (spi::TransferStates::FAILURE):
|
||||||
case(spi::TransferStates::SUCCESS):
|
case (spi::TransferStates::SUCCESS):
|
||||||
default: {
|
default: {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(transferMode) {
|
switch (transferMode) {
|
||||||
case(spi::TransferModes::POLLING): {
|
case (spi::TransferModes::POLLING): {
|
||||||
return handlePollingSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie,
|
return handlePollingSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie,
|
||||||
sendData, sendLen);
|
sendData, sendLen);
|
||||||
}
|
}
|
||||||
case(spi::TransferModes::INTERRUPT): {
|
case (spi::TransferModes::INTERRUPT): {
|
||||||
return handleInterruptSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie,
|
return handleInterruptSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie,
|
||||||
sendData, sendLen);
|
sendData, sendLen);
|
||||||
}
|
}
|
||||||
case(spi::TransferModes::DMA): {
|
case (spi::TransferModes::DMA): {
|
||||||
return handleDmaSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie,
|
return handleDmaSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie,
|
||||||
sendData, sendLen);
|
sendData, sendLen);
|
||||||
}
|
}
|
||||||
@ -201,23 +197,21 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) {
|
ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) { return HasReturnvaluesIF::RETURN_OK; }
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
|
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
|
||||||
return HasReturnvaluesIF::RETURN_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) {
|
||||||
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
|
SpiCookie *spiCookie = dynamic_cast<SpiCookie *>(cookie);
|
||||||
if(spiCookie == nullptr) {
|
if (spiCookie == nullptr) {
|
||||||
return NULLPOINTER;
|
return NULLPOINTER;
|
||||||
}
|
}
|
||||||
switch(spiCookie->getTransferState()) {
|
switch (spiCookie->getTransferState()) {
|
||||||
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 HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
*buffer = iter->second.replyBuffer.data();
|
*buffer = iter->second.replyBuffer.data();
|
||||||
@ -225,7 +219,7 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
|||||||
spiCookie->setTransferState(spi::TransferStates::IDLE);
|
spiCookie->setTransferState(spi::TransferStates::IDLE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(spi::TransferStates::FAILURE): {
|
case (spi::TransferStates::FAILURE): {
|
||||||
#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::readReceivedMessage: Transfer failure" << std::endl;
|
sif::warning << "SpiComIF::readReceivedMessage: Transfer failure" << std::endl;
|
||||||
@ -236,8 +230,8 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
|||||||
spiCookie->setTransferState(spi::TransferStates::IDLE);
|
spiCookie->setTransferState(spi::TransferStates::IDLE);
|
||||||
return HasReturnvaluesIF::RETURN_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: {
|
||||||
@ -252,35 +246,36 @@ void SpiComIF::setDefaultPollingTimeout(dur_millis_t timeout) {
|
|||||||
this->defaultPollingTimeout = timeout;
|
this->defaultPollingTimeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
|
||||||
SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) {
|
SpiCookie &spiCookie, const uint8_t *sendData,
|
||||||
|
size_t sendLen) {
|
||||||
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 != HasReturnvaluesIF::RETURN_OK) {
|
if (returnval != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return returnval;
|
return returnval;
|
||||||
}
|
}
|
||||||
spiCookie.setTransferState(spi::TransferStates::WAIT);
|
spiCookie.setTransferState(spi::TransferStates::WAIT);
|
||||||
if(gpioPort != nullptr) {
|
if (gpioPort != nullptr) {
|
||||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = HAL_SPI_TransmitReceive(&spiHandle, const_cast<uint8_t*>(sendData),
|
auto result = HAL_SPI_TransmitReceive(&spiHandle, const_cast<uint8_t *>(sendData), recvPtr,
|
||||||
recvPtr, sendLen, defaultPollingTimeout);
|
sendLen, defaultPollingTimeout);
|
||||||
if(gpioPort != nullptr) {
|
if (gpioPort != nullptr) {
|
||||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
||||||
}
|
}
|
||||||
spiSemaphore->release();
|
spiSemaphore->release();
|
||||||
switch(result) {
|
switch (result) {
|
||||||
case(HAL_OK): {
|
case (HAL_OK): {
|
||||||
spiCookie.setTransferState(spi::TransferStates::SUCCESS);
|
spiCookie.setTransferState(spi::TransferStates::SUCCESS);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
#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: Polling Mode | Timeout for SPI device" <<
|
sif::warning << "SpiComIF::sendMessage: Polling Mode | Timeout for SPI device"
|
||||||
spiCookie->getDeviceAddress() << std::endl;
|
<< spiCookie->getDeviceAddress() << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("SpiComIF::sendMessage: Polling Mode | Timeout for SPI device %d\n",
|
sif::printWarning("SpiComIF::sendMessage: Polling Mode | Timeout for SPI device %d\n",
|
||||||
spiCookie.getDeviceAddress());
|
spiCookie.getDeviceAddress());
|
||||||
@ -289,12 +284,12 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleT
|
|||||||
spiCookie.setTransferState(spi::TransferStates::FAILURE);
|
spiCookie.setTransferState(spi::TransferStates::FAILURE);
|
||||||
return spi::HAL_TIMEOUT_RETVAL;
|
return spi::HAL_TIMEOUT_RETVAL;
|
||||||
}
|
}
|
||||||
case(HAL_ERROR):
|
case (HAL_ERROR):
|
||||||
default: {
|
default: {
|
||||||
#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: Polling Mode | HAL error for SPI device" <<
|
sif::warning << "SpiComIF::sendMessage: Polling Mode | HAL error for SPI device"
|
||||||
spiCookie->getDeviceAddress() << std::endl;
|
<< spiCookie->getDeviceAddress() << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("SpiComIF::sendMessage: Polling Mode | HAL error for SPI device %d\n",
|
sif::printWarning("SpiComIF::sendMessage: Polling Mode | HAL error for SPI device %d\n",
|
||||||
spiCookie.getDeviceAddress());
|
spiCookie.getDeviceAddress());
|
||||||
@ -307,41 +302,42 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleT
|
|||||||
return HasReturnvaluesIF::RETURN_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,
|
||||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen) {
|
SpiCookie &spiCookie, const uint8_t *sendData,
|
||||||
|
size_t sendLen) {
|
||||||
return handleIrqSendOperation(recvPtr, spiHandle, spiCookie, sendData, sendLen);
|
return handleIrqSendOperation(recvPtr, spiHandle, spiCookie, sendData, sendLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::handleDmaSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
ReturnValue_t SpiComIF::handleDmaSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
|
||||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen) {
|
SpiCookie &spiCookie, const uint8_t *sendData,
|
||||||
|
size_t sendLen) {
|
||||||
return handleIrqSendOperation(recvPtr, spiHandle, spiCookie, sendData, sendLen);
|
return handleIrqSendOperation(recvPtr, spiHandle, spiCookie, sendData, sendLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SpiComIF::handleIrqSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef& spiHandle,
|
ReturnValue_t SpiComIF::handleIrqSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
|
||||||
SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) {
|
SpiCookie &spiCookie, const uint8_t *sendData,
|
||||||
|
size_t sendLen) {
|
||||||
ReturnValue_t result = genericIrqSendSetup(recvPtr, spiHandle, spiCookie, sendData, sendLen);
|
ReturnValue_t result = genericIrqSendSetup(recvPtr, spiHandle, spiCookie, sendData, sendLen);
|
||||||
if(result != HasReturnvaluesIF::RETURN_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..
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
auto transferMode = spiCookie.getTransferMode();
|
auto transferMode = spiCookie.getTransferMode();
|
||||||
if(transferMode == spi::TransferModes::DMA) {
|
if (transferMode == spi::TransferModes::DMA) {
|
||||||
if(cacheMaintenanceOnTxBuffer) {
|
if (cacheMaintenanceOnTxBuffer) {
|
||||||
/* Clean D-cache. Make sure the address is 32-byte aligned and add 32-bytes to length,
|
/* Clean D-cache. Make sure the address is 32-byte aligned and add 32-bytes to length,
|
||||||
in case it overlaps cacheline */
|
in case it overlaps cacheline */
|
||||||
SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t) sendData ) & ~(uint32_t)0x1F),
|
SCB_CleanDCache_by_Addr((uint32_t *)(((uint32_t)sendData) & ~(uint32_t)0x1F), sendLen + 32);
|
||||||
sendLen + 32);
|
|
||||||
}
|
}
|
||||||
status = HAL_SPI_TransmitReceive_DMA(&spiHandle, const_cast<uint8_t*>(sendData),
|
status = HAL_SPI_TransmitReceive_DMA(&spiHandle, const_cast<uint8_t *>(sendData),
|
||||||
currentRecvPtr, sendLen);
|
currentRecvPtr, sendLen);
|
||||||
|
} else {
|
||||||
|
status = HAL_SPI_TransmitReceive_IT(&spiHandle, const_cast<uint8_t *>(sendData), currentRecvPtr,
|
||||||
|
sendLen);
|
||||||
}
|
}
|
||||||
else {
|
switch (status) {
|
||||||
status = HAL_SPI_TransmitReceive_IT(&spiHandle, const_cast<uint8_t*>(sendData),
|
case (HAL_OK): {
|
||||||
currentRecvPtr, sendLen);
|
|
||||||
}
|
|
||||||
switch(status) {
|
|
||||||
case(HAL_OK): {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -353,22 +349,20 @@ ReturnValue_t SpiComIF::handleIrqSendOperation(uint8_t *recvPtr, SPI_HandleTypeD
|
|||||||
|
|
||||||
ReturnValue_t SpiComIF::halErrorHandler(HAL_StatusTypeDef status, spi::TransferModes transferMode) {
|
ReturnValue_t SpiComIF::halErrorHandler(HAL_StatusTypeDef status, spi::TransferModes transferMode) {
|
||||||
char modeString[10];
|
char modeString[10];
|
||||||
if(transferMode == spi::TransferModes::DMA) {
|
if (transferMode == spi::TransferModes::DMA) {
|
||||||
std::snprintf(modeString, sizeof(modeString), "Dma");
|
std::snprintf(modeString, sizeof(modeString), "Dma");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::snprintf(modeString, sizeof(modeString), "Interrupt");
|
std::snprintf(modeString, sizeof(modeString), "Interrupt");
|
||||||
}
|
}
|
||||||
sif::printWarning("SpiComIF::handle%sSendOperation: HAL error %d occured\n", modeString,
|
sif::printWarning("SpiComIF::handle%sSendOperation: HAL error %d occured\n", modeString, status);
|
||||||
status);
|
switch (status) {
|
||||||
switch(status) {
|
case (HAL_BUSY): {
|
||||||
case(HAL_BUSY): {
|
|
||||||
return spi::HAL_BUSY_RETVAL;
|
return spi::HAL_BUSY_RETVAL;
|
||||||
}
|
}
|
||||||
case(HAL_ERROR): {
|
case (HAL_ERROR): {
|
||||||
return spi::HAL_ERROR_RETVAL;
|
return spi::HAL_ERROR_RETVAL;
|
||||||
}
|
}
|
||||||
case(HAL_TIMEOUT): {
|
case (HAL_TIMEOUT): {
|
||||||
return spi::HAL_TIMEOUT_RETVAL;
|
return spi::HAL_TIMEOUT_RETVAL;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -377,18 +371,20 @@ ReturnValue_t SpiComIF::halErrorHandler(HAL_StatusTypeDef status, spi::TransferM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
|
||||||
ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef& spiHandle,
|
SpiCookie &spiCookie, const uint8_t *sendData,
|
||||||
SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) {
|
size_t sendLen) {
|
||||||
currentRecvPtr = recvPtr;
|
currentRecvPtr = recvPtr;
|
||||||
currentRecvBuffSize = sendLen;
|
currentRecvBuffSize = sendLen;
|
||||||
|
|
||||||
// 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 != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
// Configuration error
|
// Configuration error
|
||||||
sif::printWarning("SpiComIF::handleInterruptSendOperation: Semaphore "
|
sif::printWarning(
|
||||||
"could not be acquired after %d ms\n", timeoutMs);
|
"SpiComIF::handleInterruptSendOperation: Semaphore "
|
||||||
|
"could not be acquired after %d ms\n",
|
||||||
|
timeoutMs);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// Cache the current SPI handle in any case
|
// Cache the current SPI handle in any case
|
||||||
@ -398,8 +394,8 @@ ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef&
|
|||||||
irqArgs.spiCookie = &spiCookie;
|
irqArgs.spiCookie = &spiCookie;
|
||||||
// The SPI handle is passed to the default SPI callback as a void argument. This callback
|
// The SPI handle is passed to the default SPI callback as a void argument. This callback
|
||||||
// is different from the user callbacks specified above!
|
// is different from the user callbacks specified above!
|
||||||
spi::assignSpiUserArgs(spiCookie.getSpiIdx(), reinterpret_cast<void*>(&spiHandle));
|
spi::assignSpiUserArgs(spiCookie.getSpiIdx(), reinterpret_cast<void *>(&spiHandle));
|
||||||
if(spiCookie.getChipSelectGpioPort() != nullptr) {
|
if (spiCookie.getChipSelectGpioPort() != nullptr) {
|
||||||
HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(),
|
HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(),
|
||||||
GPIO_PIN_RESET);
|
GPIO_PIN_RESET);
|
||||||
}
|
}
|
||||||
@ -423,48 +419,46 @@ void SpiComIF::spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void *args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetState) {
|
void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetState) {
|
||||||
IrqArgs* irqArgs = reinterpret_cast<IrqArgs*>(irqArgsVoid);
|
IrqArgs *irqArgs = reinterpret_cast<IrqArgs *>(irqArgsVoid);
|
||||||
if(irqArgs == nullptr) {
|
if (irqArgs == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SpiCookie* spiCookie = irqArgs->spiCookie;
|
SpiCookie *spiCookie = irqArgs->spiCookie;
|
||||||
SpiComIF* comIF = irqArgs->comIF;
|
SpiComIF *comIF = irqArgs->comIF;
|
||||||
if(spiCookie == nullptr or comIF == nullptr) {
|
if (spiCookie == nullptr or comIF == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
spiCookie->setTransferState(targetState);
|
spiCookie->setTransferState(targetState);
|
||||||
|
|
||||||
if(spiCookie->getChipSelectGpioPort() != nullptr) {
|
if (spiCookie->getChipSelectGpioPort() != nullptr) {
|
||||||
// Pull CS pin high again
|
// Pull CS pin high again
|
||||||
HAL_GPIO_WritePin(spiCookie->getChipSelectGpioPort(), spiCookie->getChipSelectGpioPin(),
|
HAL_GPIO_WritePin(spiCookie->getChipSelectGpioPort(), spiCookie->getChipSelectGpioPin(),
|
||||||
GPIO_PIN_SET);
|
GPIO_PIN_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined FSFW_OSAL_FREERTOS
|
#if defined FSFW_OSAL_FREERTOS
|
||||||
// Release the task semaphore
|
// Release the task semaphore
|
||||||
BaseType_t taskWoken = pdFALSE;
|
BaseType_t taskWoken = pdFALSE;
|
||||||
ReturnValue_t result = BinarySemaphore::releaseFromISR(comIF->spiSemaphore->getSemaphore(),
|
ReturnValue_t result =
|
||||||
&taskWoken);
|
BinarySemaphore::releaseFromISR(comIF->spiSemaphore->getSemaphore(), &taskWoken);
|
||||||
#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 != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
// Configuration error
|
// Configuration error
|
||||||
printf("SpiComIF::genericIrqHandler: Failure releasing Semaphore!\n");
|
printf("SpiComIF::genericIrqHandler: Failure releasing Semaphore!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform cache maintenance operation for DMA transfers
|
// Perform cache maintenance operation for DMA transfers
|
||||||
if(spiCookie->getTransferMode() == spi::TransferModes::DMA) {
|
if (spiCookie->getTransferMode() == spi::TransferModes::DMA) {
|
||||||
// Invalidate cache prior to access by CPU
|
// Invalidate cache prior to access by CPU
|
||||||
SCB_InvalidateDCache_by_Addr ((uint32_t *) comIF->currentRecvPtr,
|
SCB_InvalidateDCache_by_Addr((uint32_t *)comIF->currentRecvPtr, comIF->currentRecvBuffSize);
|
||||||
comIF->currentRecvBuffSize);
|
|
||||||
}
|
}
|
||||||
#if defined FSFW_OSAL_FREERTOS
|
#if defined FSFW_OSAL_FREERTOS
|
||||||
/* Request a context switch if the SPI ComIF task was woken up and has a higher priority
|
/* Request a context switch if the SPI ComIF task was woken up and has a higher priority
|
||||||
than the currently running task */
|
than the currently running task */
|
||||||
if(taskWoken == pdTRUE) {
|
if (taskWoken == pdTRUE) {
|
||||||
TaskManagement::requestContextSwitch(CallContext::ISR);
|
TaskManagement::requestContextSwitch(CallContext::ISR);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
#ifndef FSFW_HAL_STM32H7_SPI_SPICOMIF_H_
|
#ifndef FSFW_HAL_STM32H7_SPI_SPICOMIF_H_
|
||||||
#define FSFW_HAL_STM32H7_SPI_SPICOMIF_H_
|
#define FSFW_HAL_STM32H7_SPI_SPICOMIF_H_
|
||||||
|
|
||||||
#include "fsfw/tasks/SemaphoreIF.h"
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
||||||
#include "fsfw/objectmanager/SystemObject.h"
|
#include "fsfw/objectmanager/SystemObject.h"
|
||||||
|
#include "fsfw/tasks/SemaphoreIF.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||||
#include "stm32h7xx_hal_spi.h"
|
|
||||||
#include "stm32h743xx.h"
|
#include "stm32h743xx.h"
|
||||||
|
#include "stm32h7xx_hal_spi.h"
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
class SpiCookie;
|
class SpiCookie;
|
||||||
class BinarySemaphore;
|
class BinarySemaphore;
|
||||||
@ -28,10 +27,8 @@ class BinarySemaphore;
|
|||||||
* implementation limits the transfer mode for a given SPI bus.
|
* implementation limits the transfer mode for a given SPI bus.
|
||||||
* @author R. Mueller
|
* @author R. Mueller
|
||||||
*/
|
*/
|
||||||
class SpiComIF:
|
class SpiComIF : public SystemObject, public DeviceCommunicationIF {
|
||||||
public SystemObject,
|
public:
|
||||||
public DeviceCommunicationIF {
|
|
||||||
public:
|
|
||||||
/**
|
/**
|
||||||
* Create a SPI communication interface for the given SPI peripheral (spiInstance)
|
* Create a SPI communication interface for the given SPI peripheral (spiInstance)
|
||||||
* @param objectId
|
* @param objectId
|
||||||
@ -62,19 +59,17 @@ public:
|
|||||||
ReturnValue_t initialize() override;
|
ReturnValue_t initialize() override;
|
||||||
|
|
||||||
// DeviceCommunicationIF overrides
|
// DeviceCommunicationIF overrides
|
||||||
virtual ReturnValue_t initializeInterface(CookieIF * cookie) override;
|
virtual ReturnValue_t initializeInterface(CookieIF* cookie) override;
|
||||||
virtual ReturnValue_t sendMessage(CookieIF *cookie,
|
virtual ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData,
|
||||||
const uint8_t * sendData, size_t sendLen) override;
|
size_t sendLen) override;
|
||||||
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
virtual ReturnValue_t getSendSuccess(CookieIF* cookie) override;
|
||||||
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
virtual ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
|
||||||
size_t requestLen) override;
|
virtual ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
|
||||||
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
|
size_t* size) override;
|
||||||
uint8_t **buffer, size_t *size) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
|
protected:
|
||||||
struct SpiInstance {
|
struct SpiInstance {
|
||||||
SpiInstance(size_t maxRecvSize): replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
|
SpiInstance(size_t maxRecvSize) : replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
|
||||||
std::vector<uint8_t> replyBuffer;
|
std::vector<uint8_t> replyBuffer;
|
||||||
size_t currentTransferLen = 0;
|
size_t currentTransferLen = 0;
|
||||||
};
|
};
|
||||||
@ -103,27 +98,29 @@ protected:
|
|||||||
SpiDeviceMap spiDeviceMap;
|
SpiDeviceMap spiDeviceMap;
|
||||||
|
|
||||||
ReturnValue_t handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
ReturnValue_t handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
||||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
|
SpiCookie& spiCookie, const uint8_t* sendData,
|
||||||
|
size_t sendLen);
|
||||||
ReturnValue_t handleInterruptSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
ReturnValue_t handleInterruptSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
||||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
|
SpiCookie& spiCookie, const uint8_t* sendData,
|
||||||
|
size_t sendLen);
|
||||||
ReturnValue_t handleDmaSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
ReturnValue_t handleDmaSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
||||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
|
SpiCookie& spiCookie, const uint8_t* sendData,
|
||||||
|
size_t sendLen);
|
||||||
ReturnValue_t handleIrqSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
ReturnValue_t handleIrqSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
||||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
|
SpiCookie& spiCookie, const uint8_t* sendData,
|
||||||
|
size_t sendLen);
|
||||||
ReturnValue_t genericIrqSendSetup(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
ReturnValue_t genericIrqSendSetup(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
|
||||||
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
|
SpiCookie& spiCookie, const uint8_t* sendData, size_t sendLen);
|
||||||
ReturnValue_t halErrorHandler(HAL_StatusTypeDef status, spi::TransferModes transferMode);
|
ReturnValue_t halErrorHandler(HAL_StatusTypeDef status, spi::TransferModes transferMode);
|
||||||
|
|
||||||
static void spiTransferTxCompleteCallback(SPI_HandleTypeDef *hspi, void* args);
|
static void spiTransferTxCompleteCallback(SPI_HandleTypeDef* hspi, void* args);
|
||||||
static void spiTransferRxCompleteCallback(SPI_HandleTypeDef *hspi, void* args);
|
static void spiTransferRxCompleteCallback(SPI_HandleTypeDef* hspi, void* args);
|
||||||
static void spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* args);
|
static void spiTransferCompleteCallback(SPI_HandleTypeDef* hspi, void* args);
|
||||||
static void spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void* args);
|
static void spiTransferErrorCallback(SPI_HandleTypeDef* hspi, void* args);
|
||||||
|
|
||||||
static void genericIrqHandler(void* irqArgs, spi::TransferStates targetState);
|
static void genericIrqHandler(void* irqArgs, spi::TransferStates targetState);
|
||||||
|
|
||||||
void printCfgError(const char* const type);
|
void printCfgError(const char* const type);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* FSFW_HAL_STM32H7_SPI_SPICOMIF_H_ */
|
#endif /* FSFW_HAL_STM32H7_SPI_SPICOMIF_H_ */
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
|
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
|
||||||
|
|
||||||
|
|
||||||
SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
||||||
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
||||||
size_t maxRecvSize, stm32h7::GpioCfg csGpio):
|
size_t maxRecvSize, stm32h7::GpioCfg csGpio)
|
||||||
deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode),
|
: deviceAddress(deviceAddress),
|
||||||
transferMode(transferMode), csGpio(csGpio),
|
spiIdx(spiIdx),
|
||||||
mspCfg(mspCfg), maxRecvSize(maxRecvSize) {
|
spiSpeed(spiSpeed),
|
||||||
|
spiMode(spiMode),
|
||||||
|
transferMode(transferMode),
|
||||||
|
csGpio(csGpio),
|
||||||
|
mspCfg(mspCfg),
|
||||||
|
maxRecvSize(maxRecvSize) {
|
||||||
spiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
|
spiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||||
spiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
spiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||||
spiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
|
spiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||||
@ -23,56 +27,34 @@ SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferM
|
|||||||
spiHandle.Init.BaudRatePrescaler = spi::getPrescaler(HAL_RCC_GetHCLKFreq(), spiSpeed);
|
spiHandle.Init.BaudRatePrescaler = spi::getPrescaler(HAL_RCC_GetHCLKFreq(), spiSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t SpiCookie::getChipSelectGpioPin() const {
|
uint16_t SpiCookie::getChipSelectGpioPin() const { return csGpio.pin; }
|
||||||
return csGpio.pin;
|
|
||||||
}
|
|
||||||
|
|
||||||
GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() {
|
GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() { return csGpio.port; }
|
||||||
return csGpio.port;
|
|
||||||
}
|
|
||||||
|
|
||||||
address_t SpiCookie::getDeviceAddress() const {
|
address_t SpiCookie::getDeviceAddress() const { return deviceAddress; }
|
||||||
return deviceAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
spi::SpiBus SpiCookie::getSpiIdx() const {
|
spi::SpiBus SpiCookie::getSpiIdx() const { return spiIdx; }
|
||||||
return spiIdx;
|
|
||||||
}
|
|
||||||
|
|
||||||
spi::SpiModes SpiCookie::getSpiMode() const {
|
spi::SpiModes SpiCookie::getSpiMode() const { return spiMode; }
|
||||||
return spiMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t SpiCookie::getSpiSpeed() const {
|
uint32_t SpiCookie::getSpiSpeed() const { return spiSpeed; }
|
||||||
return spiSpeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t SpiCookie::getMaxRecvSize() const {
|
size_t SpiCookie::getMaxRecvSize() const { return maxRecvSize; }
|
||||||
return maxRecvSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
SPI_HandleTypeDef& SpiCookie::getSpiHandle() {
|
SPI_HandleTypeDef& SpiCookie::getSpiHandle() { return spiHandle; }
|
||||||
return spiHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
spi::MspCfgBase* SpiCookie::getMspCfg() {
|
spi::MspCfgBase* SpiCookie::getMspCfg() { return mspCfg; }
|
||||||
return mspCfg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::deleteMspCfg() {
|
void SpiCookie::deleteMspCfg() {
|
||||||
if(mspCfg != nullptr) {
|
if (mspCfg != nullptr) {
|
||||||
delete mspCfg;
|
delete mspCfg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spi::TransferModes SpiCookie::getTransferMode() const {
|
spi::TransferModes SpiCookie::getTransferMode() const { return transferMode; }
|
||||||
return transferMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpiCookie::setTransferState(spi::TransferStates transferState) {
|
void SpiCookie::setTransferState(spi::TransferStates transferState) {
|
||||||
this->transferState = transferState;
|
this->transferState = transferState;
|
||||||
}
|
}
|
||||||
|
|
||||||
spi::TransferStates SpiCookie::getTransferState() const {
|
spi::TransferStates SpiCookie::getTransferState() const { return this->transferState; }
|
||||||
return this->transferState;
|
|
||||||
}
|
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
#ifndef FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_
|
#ifndef FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_
|
||||||
#define FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_
|
#define FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_
|
||||||
|
|
||||||
#include "spiDefinitions.h"
|
|
||||||
#include "mspInit.h"
|
|
||||||
#include "../definitions.h"
|
|
||||||
|
|
||||||
#include "fsfw/devicehandlers/CookieIF.h"
|
|
||||||
|
|
||||||
#include "stm32h743xx.h"
|
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "../definitions.h"
|
||||||
|
#include "fsfw/devicehandlers/CookieIF.h"
|
||||||
|
#include "mspInit.h"
|
||||||
|
#include "spiDefinitions.h"
|
||||||
|
#include "stm32h743xx.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SPI cookie implementation for the STM32H7 device family
|
* @brief SPI cookie implementation for the STM32H7 device family
|
||||||
* @details
|
* @details
|
||||||
@ -18,10 +16,10 @@
|
|||||||
* SPI communication interface
|
* SPI communication interface
|
||||||
* @author R. Mueller
|
* @author R. Mueller
|
||||||
*/
|
*/
|
||||||
class SpiCookie: public CookieIF {
|
class SpiCookie : public CookieIF {
|
||||||
friend class SpiComIF;
|
friend class SpiComIF;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
/**
|
/**
|
||||||
* Allows construction of a SPI cookie for a connected SPI device
|
* Allows construction of a SPI cookie for a connected SPI device
|
||||||
* @param deviceAddress
|
* @param deviceAddress
|
||||||
@ -39,8 +37,8 @@ public:
|
|||||||
* @param csGpio Optional CS GPIO definition.
|
* @param csGpio Optional CS GPIO definition.
|
||||||
*/
|
*/
|
||||||
SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
||||||
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode, size_t maxRecvSize,
|
||||||
size_t maxRecvSize, stm32h7::GpioCfg csGpio = stm32h7::GpioCfg(nullptr, 0, 0));
|
stm32h7::GpioCfg csGpio = stm32h7::GpioCfg(nullptr, 0, 0));
|
||||||
|
|
||||||
uint16_t getChipSelectGpioPin() const;
|
uint16_t getChipSelectGpioPin() const;
|
||||||
GPIO_TypeDef* getChipSelectGpioPort();
|
GPIO_TypeDef* getChipSelectGpioPort();
|
||||||
@ -52,7 +50,7 @@ public:
|
|||||||
size_t getMaxRecvSize() const;
|
size_t getMaxRecvSize() const;
|
||||||
SPI_HandleTypeDef& getSpiHandle();
|
SPI_HandleTypeDef& getSpiHandle();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
address_t deviceAddress;
|
address_t deviceAddress;
|
||||||
SPI_HandleTypeDef spiHandle = {};
|
SPI_HandleTypeDef spiHandle = {};
|
||||||
spi::SpiBus spiIdx;
|
spi::SpiBus spiIdx;
|
||||||
@ -75,6 +73,4 @@ private:
|
|||||||
spi::TransferStates getTransferState() const;
|
spi::TransferStates getTransferState() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_ */
|
#endif /* FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_ */
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
#include "fsfw_hal/stm32h7/dma.h"
|
|
||||||
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
|
||||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
|
||||||
|
|
||||||
#include "stm32h743xx.h"
|
|
||||||
#include "stm32h7xx_hal_spi.h"
|
|
||||||
#include "stm32h7xx_hal_dma.h"
|
|
||||||
#include "stm32h7xx_hal_def.h"
|
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include "fsfw_hal/stm32h7/dma.h"
|
||||||
|
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||||
|
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||||
|
#include "stm32h743xx.h"
|
||||||
|
#include "stm32h7xx_hal_def.h"
|
||||||
|
#include "stm32h7xx_hal_dma.h"
|
||||||
|
#include "stm32h7xx_hal_spi.h"
|
||||||
|
|
||||||
spi::msp_func_t mspInitFunc = nullptr;
|
spi::msp_func_t mspInitFunc = nullptr;
|
||||||
spi::MspCfgBase* mspInitArgs = nullptr;
|
spi::MspCfgBase* mspInitArgs = nullptr;
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ spi::MspCfgBase* mspDeinitArgs = nullptr;
|
|||||||
*/
|
*/
|
||||||
void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||||
auto cfg = dynamic_cast<MspDmaConfigStruct*>(cfgBase);
|
auto cfg = dynamic_cast<MspDmaConfigStruct*>(cfgBase);
|
||||||
if(hspi == nullptr or cfg == nullptr) {
|
if (hspi == nullptr or cfg == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSpiHandle(hspi);
|
setSpiHandle(hspi);
|
||||||
@ -36,7 +36,7 @@ void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
|||||||
DMA_HandleTypeDef* hdma_tx = nullptr;
|
DMA_HandleTypeDef* hdma_tx = nullptr;
|
||||||
DMA_HandleTypeDef* hdma_rx = nullptr;
|
DMA_HandleTypeDef* hdma_rx = nullptr;
|
||||||
spi::getDmaHandles(&hdma_tx, &hdma_rx);
|
spi::getDmaHandles(&hdma_tx, &hdma_rx);
|
||||||
if(hdma_tx == nullptr or hdma_rx == nullptr) {
|
if (hdma_tx == nullptr or hdma_rx == nullptr) {
|
||||||
printf("HAL_SPI_MspInit: Invalid DMA handles. Make sure to call setDmaHandles!\n");
|
printf("HAL_SPI_MspInit: Invalid DMA handles. Make sure to call setDmaHandles!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -44,14 +44,14 @@ void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
|||||||
spi::halMspInitInterrupt(hspi, cfg);
|
spi::halMspInitInterrupt(hspi, cfg);
|
||||||
|
|
||||||
// DMA setup
|
// DMA setup
|
||||||
if(cfg->dmaClkEnableWrapper == nullptr) {
|
if (cfg->dmaClkEnableWrapper == nullptr) {
|
||||||
mspErrorHandler("spi::halMspInitDma", "DMA Clock init invalid");
|
mspErrorHandler("spi::halMspInitDma", "DMA Clock init invalid");
|
||||||
}
|
}
|
||||||
cfg->dmaClkEnableWrapper();
|
cfg->dmaClkEnableWrapper();
|
||||||
|
|
||||||
// Configure the DMA
|
// Configure the DMA
|
||||||
/* Configure the DMA handler for Transmission process */
|
/* Configure the DMA handler for Transmission process */
|
||||||
if(hdma_tx->Instance == nullptr) {
|
if (hdma_tx->Instance == nullptr) {
|
||||||
// Assume it was not configured properly
|
// Assume it was not configured properly
|
||||||
mspErrorHandler("spi::halMspInitDma", "DMA TX handle invalid");
|
mspErrorHandler("spi::halMspInitDma", "DMA TX handle invalid");
|
||||||
}
|
}
|
||||||
@ -73,8 +73,7 @@ void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
|||||||
|
|
||||||
/* NVIC configuration for DMA transfer complete interrupt (SPI1_TX) */
|
/* NVIC configuration for DMA transfer complete interrupt (SPI1_TX) */
|
||||||
// Assign the interrupt handler
|
// Assign the interrupt handler
|
||||||
dma::assignDmaUserHandler(cfg->txDmaIndex, cfg->txDmaStream,
|
dma::assignDmaUserHandler(cfg->txDmaIndex, cfg->txDmaStream, &spi::dmaTxIrqHandler, hdma_tx);
|
||||||
&spi::dmaTxIrqHandler, hdma_tx);
|
|
||||||
HAL_NVIC_SetPriority(cfg->txDmaIrqNumber, cfg->txPreEmptPriority, cfg->txSubpriority);
|
HAL_NVIC_SetPriority(cfg->txDmaIrqNumber, cfg->txPreEmptPriority, cfg->txSubpriority);
|
||||||
HAL_NVIC_EnableIRQ(cfg->txDmaIrqNumber);
|
HAL_NVIC_EnableIRQ(cfg->txDmaIrqNumber);
|
||||||
}
|
}
|
||||||
@ -89,17 +88,16 @@ void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
|||||||
*/
|
*/
|
||||||
void spi::halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
void spi::halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||||
auto cfg = dynamic_cast<MspDmaConfigStruct*>(cfgBase);
|
auto cfg = dynamic_cast<MspDmaConfigStruct*>(cfgBase);
|
||||||
if(hspi == nullptr or cfg == nullptr) {
|
if (hspi == nullptr or cfg == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
spi::halMspDeinitInterrupt(hspi, cfgBase);
|
spi::halMspDeinitInterrupt(hspi, cfgBase);
|
||||||
DMA_HandleTypeDef* hdma_tx = NULL;
|
DMA_HandleTypeDef* hdma_tx = NULL;
|
||||||
DMA_HandleTypeDef* hdma_rx = NULL;
|
DMA_HandleTypeDef* hdma_rx = NULL;
|
||||||
spi::getDmaHandles(&hdma_tx, &hdma_rx);
|
spi::getDmaHandles(&hdma_tx, &hdma_rx);
|
||||||
if(hdma_tx == NULL || hdma_rx == NULL) {
|
if (hdma_tx == NULL || hdma_rx == NULL) {
|
||||||
printf("HAL_SPI_MspInit: Invalid DMA handles. Make sure to call setDmaHandles!\n");
|
printf("HAL_SPI_MspInit: Invalid DMA handles. Make sure to call setDmaHandles!\n");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Disable the DMA
|
// Disable the DMA
|
||||||
/* De-Initialize the DMA associated to transmission process */
|
/* De-Initialize the DMA associated to transmission process */
|
||||||
HAL_DMA_DeInit(hdma_tx);
|
HAL_DMA_DeInit(hdma_tx);
|
||||||
@ -110,7 +108,6 @@ void spi::halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
|||||||
// Disable the NVIC for DMA
|
// Disable the NVIC for DMA
|
||||||
HAL_NVIC_DisableIRQ(cfg->txDmaIrqNumber);
|
HAL_NVIC_DisableIRQ(cfg->txDmaIrqNumber);
|
||||||
HAL_NVIC_DisableIRQ(cfg->rxDmaIrqNumber);
|
HAL_NVIC_DisableIRQ(cfg->rxDmaIrqNumber);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::halMspInitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
void spi::halMspInitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||||
@ -156,7 +153,7 @@ void spi::halMspDeinitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
|||||||
|
|
||||||
void spi::halMspInitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
void spi::halMspInitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||||
auto cfg = dynamic_cast<MspIrqConfigStruct*>(cfgBase);
|
auto cfg = dynamic_cast<MspIrqConfigStruct*>(cfgBase);
|
||||||
if(cfg == nullptr or hspi == nullptr) {
|
if (cfg == nullptr or hspi == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,28 +172,20 @@ void spi::halMspDeinitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spi::getMspInitFunction(msp_func_t* init_func, MspCfgBase** args) {
|
void spi::getMspInitFunction(msp_func_t* init_func, MspCfgBase** args) {
|
||||||
if(init_func != NULL && args != NULL) {
|
if (init_func != NULL && args != NULL) {
|
||||||
*init_func = mspInitFunc;
|
*init_func = mspInitFunc;
|
||||||
*args = mspInitArgs;
|
*args = mspInitArgs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::getMspDeinitFunction(msp_func_t* deinit_func, MspCfgBase** args) {
|
void spi::getMspDeinitFunction(msp_func_t* deinit_func, MspCfgBase** args) {
|
||||||
if(deinit_func != NULL && args != NULL) {
|
if (deinit_func != NULL && args != NULL) {
|
||||||
*deinit_func = mspDeinitFunc;
|
*deinit_func = mspDeinitFunc;
|
||||||
*args = mspDeinitArgs;
|
*args = mspDeinitArgs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::setSpiDmaMspFunctions(MspDmaConfigStruct* cfg,
|
void spi::setSpiDmaMspFunctions(MspDmaConfigStruct* cfg, msp_func_t initFunc,
|
||||||
msp_func_t initFunc, msp_func_t deinitFunc) {
|
|
||||||
mspInitFunc = initFunc;
|
|
||||||
mspDeinitFunc = deinitFunc;
|
|
||||||
mspInitArgs = cfg;
|
|
||||||
mspDeinitArgs = cfg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void spi::setSpiIrqMspFunctions(MspIrqConfigStruct *cfg, msp_func_t initFunc,
|
|
||||||
msp_func_t deinitFunc) {
|
msp_func_t deinitFunc) {
|
||||||
mspInitFunc = initFunc;
|
mspInitFunc = initFunc;
|
||||||
mspDeinitFunc = deinitFunc;
|
mspDeinitFunc = deinitFunc;
|
||||||
@ -204,7 +193,15 @@ void spi::setSpiIrqMspFunctions(MspIrqConfigStruct *cfg, msp_func_t initFunc,
|
|||||||
mspDeinitArgs = cfg;
|
mspDeinitArgs = cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::setSpiPollingMspFunctions(MspPollingConfigStruct *cfg, msp_func_t initFunc,
|
void spi::setSpiIrqMspFunctions(MspIrqConfigStruct* cfg, msp_func_t initFunc,
|
||||||
|
msp_func_t deinitFunc) {
|
||||||
|
mspInitFunc = initFunc;
|
||||||
|
mspDeinitFunc = deinitFunc;
|
||||||
|
mspInitArgs = cfg;
|
||||||
|
mspDeinitArgs = cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spi::setSpiPollingMspFunctions(MspPollingConfigStruct* cfg, msp_func_t initFunc,
|
||||||
msp_func_t deinitFunc) {
|
msp_func_t deinitFunc) {
|
||||||
mspInitFunc = initFunc;
|
mspInitFunc = initFunc;
|
||||||
mspDeinitFunc = deinitFunc;
|
mspDeinitFunc = deinitFunc;
|
||||||
@ -222,11 +219,10 @@ void spi::setSpiPollingMspFunctions(MspPollingConfigStruct *cfg, msp_func_t init
|
|||||||
* @param hspi: SPI handle pointer
|
* @param hspi: SPI handle pointer
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
extern "C" void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) {
|
extern "C" void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) {
|
||||||
if(mspInitFunc != NULL) {
|
if (mspInitFunc != NULL) {
|
||||||
mspInitFunc(hspi, mspInitArgs);
|
mspInitFunc(hspi, mspInitArgs);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
printf("HAL_SPI_MspInit: Please call set_msp_functions to assign SPI MSP functions\n");
|
printf("HAL_SPI_MspInit: Please call set_msp_functions to assign SPI MSP functions\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,15 +235,14 @@ extern "C" void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) {
|
|||||||
* @param hspi: SPI handle pointer
|
* @param hspi: SPI handle pointer
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
extern "C" void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi) {
|
extern "C" void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) {
|
||||||
if(mspDeinitFunc != NULL) {
|
if (mspDeinitFunc != NULL) {
|
||||||
mspDeinitFunc(hspi, mspDeinitArgs);
|
mspDeinitFunc(hspi, mspDeinitArgs);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
printf("HAL_SPI_MspDeInit: Please call set_msp_functions to assign SPI MSP functions\n");
|
printf("HAL_SPI_MspDeInit: Please call set_msp_functions to assign SPI MSP functions\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::mspErrorHandler(const char* const function, const char *const message) {
|
void spi::mspErrorHandler(const char* const function, const char* const message) {
|
||||||
printf("%s failure: %s\n", function, message);
|
printf("%s failure: %s\n", function, message);
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
#ifndef FSFW_HAL_STM32H7_SPI_MSPINIT_H_
|
#ifndef FSFW_HAL_STM32H7_SPI_MSPINIT_H_
|
||||||
#define FSFW_HAL_STM32H7_SPI_MSPINIT_H_
|
#define FSFW_HAL_STM32H7_SPI_MSPINIT_H_
|
||||||
|
|
||||||
#include "spiDefinitions.h"
|
#include <cstdint>
|
||||||
|
|
||||||
#include "../definitions.h"
|
#include "../definitions.h"
|
||||||
#include "../dma.h"
|
#include "../dma.h"
|
||||||
|
#include "spiDefinitions.h"
|
||||||
#include "stm32h7xx_hal_spi.h"
|
#include "stm32h7xx_hal_spi.h"
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using mspCb = void (*) (void);
|
using mspCb = void (*)(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This file provides MSP implementation for DMA, IRQ and Polling mode for the
|
* @brief This file provides MSP implementation for DMA, IRQ and Polling mode for the
|
||||||
@ -24,9 +23,8 @@ namespace spi {
|
|||||||
struct MspCfgBase {
|
struct MspCfgBase {
|
||||||
MspCfgBase();
|
MspCfgBase();
|
||||||
MspCfgBase(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
MspCfgBase(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
|
||||||
sck(sck), mosi(mosi), miso(miso), cleanupCb(cleanupCb),
|
: sck(sck), mosi(mosi), miso(miso), cleanupCb(cleanupCb), setupCb(setupCb) {}
|
||||||
setupCb(setupCb) {}
|
|
||||||
|
|
||||||
virtual ~MspCfgBase() = default;
|
virtual ~MspCfgBase() = default;
|
||||||
|
|
||||||
@ -38,20 +36,20 @@ struct MspCfgBase {
|
|||||||
mspCb setupCb = nullptr;
|
mspCb setupCb = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MspPollingConfigStruct: public MspCfgBase {
|
struct MspPollingConfigStruct : public MspCfgBase {
|
||||||
MspPollingConfigStruct(): MspCfgBase() {};
|
MspPollingConfigStruct() : MspCfgBase(){};
|
||||||
MspPollingConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
MspPollingConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
|
||||||
MspCfgBase(sck, mosi, miso, cleanupCb, setupCb) {}
|
: MspCfgBase(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
|
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
|
||||||
argument */
|
argument */
|
||||||
struct MspIrqConfigStruct: public MspPollingConfigStruct {
|
struct MspIrqConfigStruct : public MspPollingConfigStruct {
|
||||||
MspIrqConfigStruct(): MspPollingConfigStruct() {};
|
MspIrqConfigStruct() : MspPollingConfigStruct(){};
|
||||||
MspIrqConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
MspIrqConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
|
||||||
MspPollingConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
: MspPollingConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||||
|
|
||||||
SpiBus spiBus = SpiBus::SPI_1;
|
SpiBus spiBus = SpiBus::SPI_1;
|
||||||
user_handler_t spiIrqHandler = nullptr;
|
user_handler_t spiIrqHandler = nullptr;
|
||||||
@ -65,12 +63,12 @@ struct MspIrqConfigStruct: public MspPollingConfigStruct {
|
|||||||
|
|
||||||
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
|
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
|
||||||
argument */
|
argument */
|
||||||
struct MspDmaConfigStruct: public MspIrqConfigStruct {
|
struct MspDmaConfigStruct : public MspIrqConfigStruct {
|
||||||
MspDmaConfigStruct(): MspIrqConfigStruct() {};
|
MspDmaConfigStruct() : MspIrqConfigStruct(){};
|
||||||
MspDmaConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
MspDmaConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
|
||||||
MspIrqConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
: MspIrqConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||||
void (* dmaClkEnableWrapper) (void) = nullptr;
|
void (*dmaClkEnableWrapper)(void) = nullptr;
|
||||||
|
|
||||||
dma::DMAIndexes txDmaIndex = dma::DMAIndexes::DMA_1;
|
dma::DMAIndexes txDmaIndex = dma::DMAIndexes::DMA_1;
|
||||||
dma::DMAIndexes rxDmaIndex = dma::DMAIndexes::DMA_1;
|
dma::DMAIndexes rxDmaIndex = dma::DMAIndexes::DMA_1;
|
||||||
@ -85,11 +83,10 @@ struct MspDmaConfigStruct: public MspIrqConfigStruct {
|
|||||||
IrqPriorities rxSubpriority = IrqPriorities::LOWEST;
|
IrqPriorities rxSubpriority = IrqPriorities::LOWEST;
|
||||||
};
|
};
|
||||||
|
|
||||||
using msp_func_t = void (*) (SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
|
using msp_func_t = void (*)(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
|
||||||
|
|
||||||
|
void getMspInitFunction(msp_func_t* init_func, MspCfgBase** args);
|
||||||
void getMspInitFunction(msp_func_t* init_func, MspCfgBase **args);
|
void getMspDeinitFunction(msp_func_t* deinit_func, MspCfgBase** args);
|
||||||
void getMspDeinitFunction(msp_func_t* deinit_func, MspCfgBase **args);
|
|
||||||
|
|
||||||
void halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
|
void halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
|
||||||
void halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
|
void halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
|
||||||
@ -107,23 +104,17 @@ void halMspDeinitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
|
|||||||
* @param deinit_func
|
* @param deinit_func
|
||||||
* @param deinit_args
|
* @param deinit_args
|
||||||
*/
|
*/
|
||||||
void setSpiDmaMspFunctions(MspDmaConfigStruct* cfg,
|
void setSpiDmaMspFunctions(MspDmaConfigStruct* cfg, msp_func_t initFunc = &spi::halMspInitDma,
|
||||||
msp_func_t initFunc = &spi::halMspInitDma,
|
msp_func_t deinitFunc = &spi::halMspDeinitDma);
|
||||||
msp_func_t deinitFunc= &spi::halMspDeinitDma
|
void setSpiIrqMspFunctions(MspIrqConfigStruct* cfg, msp_func_t initFunc = &spi::halMspInitInterrupt,
|
||||||
);
|
msp_func_t deinitFunc = &spi::halMspDeinitInterrupt);
|
||||||
void setSpiIrqMspFunctions(MspIrqConfigStruct* cfg,
|
|
||||||
msp_func_t initFunc = &spi::halMspInitInterrupt,
|
|
||||||
msp_func_t deinitFunc= &spi::halMspDeinitInterrupt
|
|
||||||
);
|
|
||||||
void setSpiPollingMspFunctions(MspPollingConfigStruct* cfg,
|
void setSpiPollingMspFunctions(MspPollingConfigStruct* cfg,
|
||||||
msp_func_t initFunc = &spi::halMspInitPolling,
|
msp_func_t initFunc = &spi::halMspInitPolling,
|
||||||
msp_func_t deinitFunc= &spi::halMspDeinitPolling
|
msp_func_t deinitFunc = &spi::halMspDeinitPolling);
|
||||||
);
|
|
||||||
|
|
||||||
void mspErrorHandler(const char* const function, const char *const message);
|
void mspErrorHandler(const char* const function, const char* const message);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} // namespace spi
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||||
|
|
||||||
SPI_HandleTypeDef* spiHandle = nullptr;
|
SPI_HandleTypeDef* spiHandle = nullptr;
|
||||||
DMA_HandleTypeDef* hdmaTx = nullptr;
|
DMA_HandleTypeDef* hdmaTx = nullptr;
|
||||||
DMA_HandleTypeDef* hdmaRx = nullptr;
|
DMA_HandleTypeDef* hdmaRx = nullptr;
|
||||||
@ -18,19 +19,18 @@ void* errorArgs = nullptr;
|
|||||||
|
|
||||||
void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMAIndexes dmaIdx,
|
void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMAIndexes dmaIdx,
|
||||||
dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber);
|
dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber);
|
||||||
void mapSpiBus(DMA_HandleTypeDef *handle, dma::DMAType dmaType, spi::SpiBus spiBus);
|
void mapSpiBus(DMA_HandleTypeDef* handle, dma::DMAType dmaType, spi::SpiBus spiBus);
|
||||||
|
|
||||||
void spi::configureDmaHandle(DMA_HandleTypeDef *handle, spi::SpiBus spiBus, dma::DMAType dmaType,
|
void spi::configureDmaHandle(DMA_HandleTypeDef* handle, spi::SpiBus spiBus, dma::DMAType dmaType,
|
||||||
dma::DMAIndexes dmaIdx, dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber,
|
dma::DMAIndexes dmaIdx, dma::DMAStreams dmaStream,
|
||||||
uint32_t dmaMode, uint32_t dmaPriority) {
|
IRQn_Type* dmaIrqNumber, uint32_t dmaMode, uint32_t dmaPriority) {
|
||||||
using namespace dma;
|
using namespace dma;
|
||||||
mapIndexAndStream(handle, dmaType, dmaIdx, dmaStream, dmaIrqNumber);
|
mapIndexAndStream(handle, dmaType, dmaIdx, dmaStream, dmaIrqNumber);
|
||||||
mapSpiBus(handle, dmaType, spiBus);
|
mapSpiBus(handle, dmaType, spiBus);
|
||||||
|
|
||||||
if(dmaType == DMAType::TX) {
|
if (dmaType == DMAType::TX) {
|
||||||
handle->Init.Direction = DMA_MEMORY_TO_PERIPH;
|
handle->Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
handle->Init.Direction = DMA_PERIPH_TO_MEMORY;
|
handle->Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,48 +58,43 @@ void spi::getDmaHandles(DMA_HandleTypeDef** txHandle, DMA_HandleTypeDef** rxHand
|
|||||||
*rxHandle = hdmaRx;
|
*rxHandle = hdmaRx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::setSpiHandle(SPI_HandleTypeDef *spiHandle_) {
|
void spi::setSpiHandle(SPI_HandleTypeDef* spiHandle_) {
|
||||||
if(spiHandle_ == NULL) {
|
if (spiHandle_ == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
spiHandle = spiHandle_;
|
spiHandle = spiHandle_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::assignTransferRxTxCompleteCallback(spi_transfer_cb_t callback, void *userArgs) {
|
void spi::assignTransferRxTxCompleteCallback(spi_transfer_cb_t callback, void* userArgs) {
|
||||||
rxTxCb = callback;
|
rxTxCb = callback;
|
||||||
rxTxArgs = userArgs;
|
rxTxArgs = userArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::assignTransferRxCompleteCallback(spi_transfer_cb_t callback, void *userArgs) {
|
void spi::assignTransferRxCompleteCallback(spi_transfer_cb_t callback, void* userArgs) {
|
||||||
rxCb = callback;
|
rxCb = callback;
|
||||||
rxArgs = userArgs;
|
rxArgs = userArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::assignTransferTxCompleteCallback(spi_transfer_cb_t callback, void *userArgs) {
|
void spi::assignTransferTxCompleteCallback(spi_transfer_cb_t callback, void* userArgs) {
|
||||||
txCb = callback;
|
txCb = callback;
|
||||||
txArgs = userArgs;
|
txArgs = userArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi::assignTransferErrorCallback(spi_transfer_cb_t callback, void *userArgs) {
|
void spi::assignTransferErrorCallback(spi_transfer_cb_t callback, void* userArgs) {
|
||||||
errorCb = callback;
|
errorCb = callback;
|
||||||
errorArgs = userArgs;
|
errorArgs = userArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPI_HandleTypeDef* spi::getSpiHandle() {
|
SPI_HandleTypeDef* spi::getSpiHandle() { return spiHandle; }
|
||||||
return spiHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TxRx Transfer completed callback.
|
* @brief TxRx Transfer completed callback.
|
||||||
* @param hspi: SPI handle
|
* @param hspi: SPI handle
|
||||||
*/
|
*/
|
||||||
extern "C" void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) {
|
extern "C" void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef* hspi) {
|
||||||
if(rxTxCb != NULL) {
|
if (rxTxCb != NULL) {
|
||||||
rxTxCb(hspi, rxTxArgs);
|
rxTxCb(hspi, rxTxArgs);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
printf("HAL_SPI_TxRxCpltCallback: No user callback specified\n");
|
printf("HAL_SPI_TxRxCpltCallback: No user callback specified\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,11 +103,10 @@ extern "C" void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) {
|
|||||||
* @brief TxRx Transfer completed callback.
|
* @brief TxRx Transfer completed callback.
|
||||||
* @param hspi: SPI handle
|
* @param hspi: SPI handle
|
||||||
*/
|
*/
|
||||||
extern "C" void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
|
extern "C" void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef* hspi) {
|
||||||
if(txCb != NULL) {
|
if (txCb != NULL) {
|
||||||
txCb(hspi, txArgs);
|
txCb(hspi, txArgs);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
printf("HAL_SPI_TxCpltCallback: No user callback specified\n");
|
printf("HAL_SPI_TxCpltCallback: No user callback specified\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,11 +115,10 @@ extern "C" void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
|
|||||||
* @brief TxRx Transfer completed callback.
|
* @brief TxRx Transfer completed callback.
|
||||||
* @param hspi: SPI handle
|
* @param hspi: SPI handle
|
||||||
*/
|
*/
|
||||||
extern "C" void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi) {
|
extern "C" void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef* hspi) {
|
||||||
if(rxCb != nullptr) {
|
if (rxCb != nullptr) {
|
||||||
rxCb(hspi, rxArgs);
|
rxCb(hspi, rxArgs);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
printf("HAL_SPI_RxCpltCallback: No user callback specified\n");
|
printf("HAL_SPI_RxCpltCallback: No user callback specified\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,11 +130,10 @@ extern "C" void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi) {
|
|||||||
* add your own implementation.
|
* add your own implementation.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
extern "C" void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi) {
|
extern "C" void HAL_SPI_ErrorCallback(SPI_HandleTypeDef* hspi) {
|
||||||
if(errorCb != nullptr) {
|
if (errorCb != nullptr) {
|
||||||
errorCb(hspi, rxArgs);
|
errorCb(hspi, rxArgs);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
printf("HAL_SPI_ErrorCallback: No user callback specified\n");
|
printf("HAL_SPI_ErrorCallback: No user callback specified\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,160 +141,159 @@ extern "C" void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi) {
|
|||||||
void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMAIndexes dmaIdx,
|
void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMAIndexes dmaIdx,
|
||||||
dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber) {
|
dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber) {
|
||||||
using namespace dma;
|
using namespace dma;
|
||||||
if(dmaIdx == DMAIndexes::DMA_1) {
|
if (dmaIdx == DMAIndexes::DMA_1) {
|
||||||
#ifdef DMA1
|
#ifdef DMA1
|
||||||
switch(dmaStream) {
|
switch (dmaStream) {
|
||||||
case(DMAStreams::STREAM_0): {
|
case (DMAStreams::STREAM_0): {
|
||||||
#ifdef DMA1_Stream0
|
#ifdef DMA1_Stream0
|
||||||
handle->Instance = DMA1_Stream0;
|
handle->Instance = DMA1_Stream0;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA1_Stream0_IRQn;
|
*dmaIrqNumber = DMA1_Stream0_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_1): {
|
case (DMAStreams::STREAM_1): {
|
||||||
#ifdef DMA1_Stream1
|
#ifdef DMA1_Stream1
|
||||||
handle->Instance = DMA1_Stream1;
|
handle->Instance = DMA1_Stream1;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA1_Stream1_IRQn;
|
*dmaIrqNumber = DMA1_Stream1_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_2): {
|
case (DMAStreams::STREAM_2): {
|
||||||
#ifdef DMA1_Stream2
|
#ifdef DMA1_Stream2
|
||||||
handle->Instance = DMA1_Stream2;
|
handle->Instance = DMA1_Stream2;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA1_Stream2_IRQn;
|
*dmaIrqNumber = DMA1_Stream2_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_3): {
|
case (DMAStreams::STREAM_3): {
|
||||||
#ifdef DMA1_Stream3
|
#ifdef DMA1_Stream3
|
||||||
handle->Instance = DMA1_Stream3;
|
handle->Instance = DMA1_Stream3;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA1_Stream3_IRQn;
|
*dmaIrqNumber = DMA1_Stream3_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_4): {
|
case (DMAStreams::STREAM_4): {
|
||||||
#ifdef DMA1_Stream4
|
#ifdef DMA1_Stream4
|
||||||
handle->Instance = DMA1_Stream4;
|
handle->Instance = DMA1_Stream4;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA1_Stream4_IRQn;
|
*dmaIrqNumber = DMA1_Stream4_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_5): {
|
case (DMAStreams::STREAM_5): {
|
||||||
#ifdef DMA1_Stream5
|
#ifdef DMA1_Stream5
|
||||||
handle->Instance = DMA1_Stream5;
|
handle->Instance = DMA1_Stream5;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA1_Stream5_IRQn;
|
*dmaIrqNumber = DMA1_Stream5_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_6): {
|
case (DMAStreams::STREAM_6): {
|
||||||
#ifdef DMA1_Stream6
|
#ifdef DMA1_Stream6
|
||||||
handle->Instance = DMA1_Stream6;
|
handle->Instance = DMA1_Stream6;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA1_Stream6_IRQn;
|
*dmaIrqNumber = DMA1_Stream6_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_7): {
|
case (DMAStreams::STREAM_7): {
|
||||||
#ifdef DMA1_Stream7
|
#ifdef DMA1_Stream7
|
||||||
handle->Instance = DMA1_Stream7;
|
handle->Instance = DMA1_Stream7;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA1_Stream7_IRQn;
|
*dmaIrqNumber = DMA1_Stream7_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(dmaType == DMAType::TX) {
|
if (dmaType == DMAType::TX) {
|
||||||
handle->Init.Request = DMA_REQUEST_SPI1_TX;
|
handle->Init.Request = DMA_REQUEST_SPI1_TX;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
handle->Init.Request = DMA_REQUEST_SPI1_RX;
|
handle->Init.Request = DMA_REQUEST_SPI1_RX;
|
||||||
}
|
}
|
||||||
#endif /* DMA1 */
|
#endif /* DMA1 */
|
||||||
}
|
}
|
||||||
if(dmaIdx == DMAIndexes::DMA_2) {
|
if (dmaIdx == DMAIndexes::DMA_2) {
|
||||||
#ifdef DMA2
|
#ifdef DMA2
|
||||||
switch(dmaStream) {
|
switch (dmaStream) {
|
||||||
case(DMAStreams::STREAM_0): {
|
case (DMAStreams::STREAM_0): {
|
||||||
#ifdef DMA2_Stream0
|
#ifdef DMA2_Stream0
|
||||||
handle->Instance = DMA2_Stream0;
|
handle->Instance = DMA2_Stream0;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA2_Stream0_IRQn;
|
*dmaIrqNumber = DMA2_Stream0_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_1): {
|
case (DMAStreams::STREAM_1): {
|
||||||
#ifdef DMA2_Stream1
|
#ifdef DMA2_Stream1
|
||||||
handle->Instance = DMA2_Stream1;
|
handle->Instance = DMA2_Stream1;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA2_Stream1_IRQn;
|
*dmaIrqNumber = DMA2_Stream1_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_2): {
|
case (DMAStreams::STREAM_2): {
|
||||||
#ifdef DMA2_Stream2
|
#ifdef DMA2_Stream2
|
||||||
handle->Instance = DMA2_Stream2;
|
handle->Instance = DMA2_Stream2;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA2_Stream2_IRQn;
|
*dmaIrqNumber = DMA2_Stream2_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_3): {
|
case (DMAStreams::STREAM_3): {
|
||||||
#ifdef DMA2_Stream3
|
#ifdef DMA2_Stream3
|
||||||
handle->Instance = DMA2_Stream3;
|
handle->Instance = DMA2_Stream3;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA2_Stream3_IRQn;
|
*dmaIrqNumber = DMA2_Stream3_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_4): {
|
case (DMAStreams::STREAM_4): {
|
||||||
#ifdef DMA2_Stream4
|
#ifdef DMA2_Stream4
|
||||||
handle->Instance = DMA2_Stream4;
|
handle->Instance = DMA2_Stream4;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA2_Stream4_IRQn;
|
*dmaIrqNumber = DMA2_Stream4_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_5): {
|
case (DMAStreams::STREAM_5): {
|
||||||
#ifdef DMA2_Stream5
|
#ifdef DMA2_Stream5
|
||||||
handle->Instance = DMA2_Stream5;
|
handle->Instance = DMA2_Stream5;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA2_Stream5_IRQn;
|
*dmaIrqNumber = DMA2_Stream5_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_6): {
|
case (DMAStreams::STREAM_6): {
|
||||||
#ifdef DMA2_Stream6
|
#ifdef DMA2_Stream6
|
||||||
handle->Instance = DMA2_Stream6;
|
handle->Instance = DMA2_Stream6;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA2_Stream6_IRQn;
|
*dmaIrqNumber = DMA2_Stream6_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(DMAStreams::STREAM_7): {
|
case (DMAStreams::STREAM_7): {
|
||||||
#ifdef DMA2_Stream7
|
#ifdef DMA2_Stream7
|
||||||
handle->Instance = DMA2_Stream7;
|
handle->Instance = DMA2_Stream7;
|
||||||
if(dmaIrqNumber != nullptr) {
|
if (dmaIrqNumber != nullptr) {
|
||||||
*dmaIrqNumber = DMA2_Stream7_IRQn;
|
*dmaIrqNumber = DMA2_Stream7_IRQn;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -313,26 +304,23 @@ void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mapSpiBus(DMA_HandleTypeDef *handle, dma::DMAType dmaType, spi::SpiBus spiBus) {
|
void mapSpiBus(DMA_HandleTypeDef* handle, dma::DMAType dmaType, spi::SpiBus spiBus) {
|
||||||
if(dmaType == dma::DMAType::TX) {
|
if (dmaType == dma::DMAType::TX) {
|
||||||
if(spiBus == spi::SpiBus::SPI_1) {
|
if (spiBus == spi::SpiBus::SPI_1) {
|
||||||
#ifdef DMA_REQUEST_SPI1_TX
|
#ifdef DMA_REQUEST_SPI1_TX
|
||||||
handle->Init.Request = DMA_REQUEST_SPI1_TX;
|
handle->Init.Request = DMA_REQUEST_SPI1_TX;
|
||||||
#endif
|
#endif
|
||||||
}
|
} else if (spiBus == spi::SpiBus::SPI_2) {
|
||||||
else if(spiBus == spi::SpiBus::SPI_2) {
|
|
||||||
#ifdef DMA_REQUEST_SPI2_TX
|
#ifdef DMA_REQUEST_SPI2_TX
|
||||||
handle->Init.Request = DMA_REQUEST_SPI2_TX;
|
handle->Init.Request = DMA_REQUEST_SPI2_TX;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
if (spiBus == spi::SpiBus::SPI_1) {
|
||||||
if(spiBus == spi::SpiBus::SPI_1) {
|
|
||||||
#ifdef DMA_REQUEST_SPI1_RX
|
#ifdef DMA_REQUEST_SPI1_RX
|
||||||
handle->Init.Request = DMA_REQUEST_SPI1_RX;
|
handle->Init.Request = DMA_REQUEST_SPI1_RX;
|
||||||
#endif
|
#endif
|
||||||
}
|
} else if (spiBus == spi::SpiBus::SPI_2) {
|
||||||
else if(spiBus == spi::SpiBus::SPI_2) {
|
|
||||||
#ifdef DMA_REQUEST_SPI2_RX
|
#ifdef DMA_REQUEST_SPI2_RX
|
||||||
handle->Init.Request = DMA_REQUEST_SPI2_RX;
|
handle->Init.Request = DMA_REQUEST_SPI2_RX;
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "fsfw_hal/stm32h7/dma.h"
|
#include "fsfw_hal/stm32h7/dma.h"
|
||||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||||
|
|
||||||
#include "stm32h7xx_hal.h"
|
#include "stm32h7xx_hal.h"
|
||||||
#include "stm32h7xx_hal_dma.h"
|
#include "stm32h7xx_hal_dma.h"
|
||||||
|
|
||||||
@ -11,14 +10,13 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using spi_transfer_cb_t = void (*) (SPI_HandleTypeDef *hspi, void* userArgs);
|
using spi_transfer_cb_t = void (*)(SPI_HandleTypeDef* hspi, void* userArgs);
|
||||||
|
|
||||||
namespace spi {
|
namespace spi {
|
||||||
|
|
||||||
void configureDmaHandle(DMA_HandleTypeDef* handle, spi::SpiBus spiBus,
|
void configureDmaHandle(DMA_HandleTypeDef* handle, spi::SpiBus spiBus, dma::DMAType dmaType,
|
||||||
dma::DMAType dmaType, dma::DMAIndexes dmaIdx,
|
dma::DMAIndexes dmaIdx, dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber,
|
||||||
dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber, uint32_t dmaMode = DMA_NORMAL,
|
uint32_t dmaMode = DMA_NORMAL, uint32_t dmaPriority = DMA_PRIORITY_LOW);
|
||||||
uint32_t dmaPriority = DMA_PRIORITY_LOW);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign DMA handles. Required to use DMA for SPI transfers.
|
* Assign DMA handles. Required to use DMA for SPI transfers.
|
||||||
@ -32,7 +30,7 @@ void getDmaHandles(DMA_HandleTypeDef** txHandle, DMA_HandleTypeDef** rxHandle);
|
|||||||
* Assign SPI handle. Needs to be done before using the SPI
|
* Assign SPI handle. Needs to be done before using the SPI
|
||||||
* @param spiHandle
|
* @param spiHandle
|
||||||
*/
|
*/
|
||||||
void setSpiHandle(SPI_HandleTypeDef *spiHandle);
|
void setSpiHandle(SPI_HandleTypeDef* spiHandle);
|
||||||
|
|
||||||
void assignTransferRxTxCompleteCallback(spi_transfer_cb_t callback, void* userArgs);
|
void assignTransferRxTxCompleteCallback(spi_transfer_cb_t callback, void* userArgs);
|
||||||
void assignTransferRxCompleteCallback(spi_transfer_cb_t callback, void* userArgs);
|
void assignTransferRxCompleteCallback(spi_transfer_cb_t callback, void* userArgs);
|
||||||
@ -45,7 +43,7 @@ void assignTransferErrorCallback(spi_transfer_cb_t callback, void* userArgs);
|
|||||||
*/
|
*/
|
||||||
SPI_HandleTypeDef* getSpiHandle();
|
SPI_HandleTypeDef* getSpiHandle();
|
||||||
|
|
||||||
}
|
} // namespace spi
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||||
|
|
||||||
void spi::assignSpiMode(SpiModes spiMode, SPI_HandleTypeDef& spiHandle) {
|
void spi::assignSpiMode(SpiModes spiMode, SPI_HandleTypeDef& spiHandle) {
|
||||||
switch(spiMode) {
|
switch (spiMode) {
|
||||||
case(SpiModes::MODE_0): {
|
case (SpiModes::MODE_0): {
|
||||||
spiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
|
spiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||||
spiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
|
spiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(SpiModes::MODE_1): {
|
case (SpiModes::MODE_1): {
|
||||||
spiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
|
spiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||||
spiHandle.Init.CLKPhase = SPI_PHASE_2EDGE;
|
spiHandle.Init.CLKPhase = SPI_PHASE_2EDGE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(SpiModes::MODE_2): {
|
case (SpiModes::MODE_2): {
|
||||||
spiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
spiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
||||||
spiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
|
spiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(SpiModes::MODE_3): {
|
case (SpiModes::MODE_3): {
|
||||||
spiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
spiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
||||||
spiHandle.Init.CLKPhase = SPI_PHASE_2EDGE;
|
spiHandle.Init.CLKPhase = SPI_PHASE_2EDGE;
|
||||||
break;
|
break;
|
||||||
@ -30,22 +30,16 @@ uint32_t spi::getPrescaler(uint32_t clock_src_freq, uint32_t baudrate_mbps) {
|
|||||||
uint32_t spi_clk = clock_src_freq;
|
uint32_t spi_clk = clock_src_freq;
|
||||||
uint32_t presc = 0;
|
uint32_t presc = 0;
|
||||||
static const uint32_t baudrate[] = {
|
static const uint32_t baudrate[] = {
|
||||||
SPI_BAUDRATEPRESCALER_2,
|
SPI_BAUDRATEPRESCALER_2, SPI_BAUDRATEPRESCALER_4, SPI_BAUDRATEPRESCALER_8,
|
||||||
SPI_BAUDRATEPRESCALER_4,
|
SPI_BAUDRATEPRESCALER_16, SPI_BAUDRATEPRESCALER_32, SPI_BAUDRATEPRESCALER_64,
|
||||||
SPI_BAUDRATEPRESCALER_8,
|
SPI_BAUDRATEPRESCALER_128, SPI_BAUDRATEPRESCALER_256,
|
||||||
SPI_BAUDRATEPRESCALER_16,
|
|
||||||
SPI_BAUDRATEPRESCALER_32,
|
|
||||||
SPI_BAUDRATEPRESCALER_64,
|
|
||||||
SPI_BAUDRATEPRESCALER_128,
|
|
||||||
SPI_BAUDRATEPRESCALER_256,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
while( spi_clk > baudrate_mbps) {
|
while (spi_clk > baudrate_mbps) {
|
||||||
presc = baudrate[divisor];
|
presc = baudrate[divisor];
|
||||||
if (++divisor > 7)
|
if (++divisor > 7) break;
|
||||||
break;
|
|
||||||
|
|
||||||
spi_clk = ( spi_clk >> 1);
|
spi_clk = (spi_clk >> 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return presc;
|
return presc;
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user