Skip to content

Commit

Permalink
Basic federated support on Zephyr (#73)
Browse files Browse the repository at this point in the history
* first sketch of tcp/ip bundle on unix

* fixed bug in bundle and added errors

* factoring out encoding and decoding of protobuf

* working state with extra function to toggle blocking vs non-blocking

* Add nanopb to external. USe its CMake system. Address some compiler warnings

* clang-format

* Move generated files out of `include`

* Address all compiler warnings

* Getting it to compile on Zephyr and CI

* Federated dump

* Removing some clang-tidy warnings and add thread_func implementation

* Temporary dump

* Trying to get a simple fed_conn example running

* Add tag field to protobuf message

* Fix typo in TcpIpBundle

* Add function lf_time_add

* Add simple blocking federated support without clock sync or start tag agreement or shutdown agreement.

* Add makefile target to generate proto source flies

* Undo change to CMakeLists

* Improve protobuf structure

* Dump temporary work on getting basic federation working on Zephyr

* Formatting

* Dump

* Remove ioctl from TcpIpChannel

* Make NetworkcChannel blocking. Fix some typos. Remove some debug prints.

* Reorganization, works with single TCP federate

* Reorganize the basic_federated Zephyr test

* Add Platform_vprintf to the Platform API to let boards control logging

* include logging.h in reactor-uc.h

* Add some preliminary support for actions without type

* Add a guard region around the stack of the TcpIpChannel receive pthread

* Use Platform_vprintf in our logging system

* Make sure we dont try to sleep of physical clock is already at wakup time (not only if it is passed it)

* Uncomment

* Add macros for federated

* Make unit tests run a little shorter

* Typo

* CMake formatting

* Port Zephyr examples to use macro-madness

* Define board in Cmake

* Format

* Fix typo

* Add flag for posix-tcp

* Format

* CMake

* Cmake

* Some debug prints

* Fix minor mistakes. Typeless Actions still not supported

* Make some minor edits and improve docs

* Formatting

* CI update clang-format

* CI debug

* Undo

* Use ubuntu24 in CI

* Final formatting

* Improve Zephyr examples

* Set logging to debug by default

* Make physical action test more deterministic

* Ops, found mistake in the port implementation

* Make federated zephyr reliable by adding waits (stupid)

* Format

* Add error to throw()

* Formatting

---------

Co-authored-by: tanneberger <github@tanneberger.me>
Co-authored-by: Lasse Rosenow <lasse.j.rosenow@gmail.com>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent c0d75de commit fa23939
Show file tree
Hide file tree
Showing 53 changed files with 954 additions and 400 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ permissions:
jobs:
ci:
name: ci
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install deps
run: sudo apt-get install lcov
run: |
sudo apt-get install lcov
- name: Setup java and gradle for compiling lfc
uses: ./.github/actions/prepare-build-env
# Uncomment to SSH into the runner.
Expand Down
24 changes: 17 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ set(BUILD_UNIT_TESTS OFF CACHE BOOL "Build unit tests")
set(TEST_COVERAGE OFF CACHE BOOL "Compute test coverage")
set(ASAN OFF CACHE BOOL "Compile with AddressSanitizer")
set(PLATFORM "POSIX" CACHE STRING "Platform to target")

set(EVENT_QUEUE_SIZE 10 CACHE STRING "Static size of the event queue")
set(REACTION_QUEUE_SIZE 10 CACHE STRING "Static size of the reaction queue")
set(NETWORK_POSIX_TCP OFF CACHE BOOL "Use POSIX TCP NetworkChannel")

# Code coverage setup
if(TEST_COVERAGE)
Expand Down Expand Up @@ -39,23 +39,30 @@ if(BUILD_TESTS)
endif()
endif()

# Add nanopb library manually
set(NANOPB_PATH external/nanopb)
add_library(nanopb ${NANOPB_PATH}/pb_common.c ${NANOPB_PATH}/pb_encode.c ${NANOPB_PATH}/pb_decode.c)
set_target_properties(nanopb PROPERTIES C_CLANG_TIDY "") # Disable clang-tidy for this external lib.

file(GLOB SOURCES "src/*.c" "external/proto/*.c")

set(NANOPB_PATH external/nanopb)

if (PLATFORM STREQUAL "POSIX")
add_library(reactor-uc STATIC ${SOURCES})
target_link_libraries(reactor-uc PRIVATE pthread)
# Add nanopb library manually
add_library(nanopb ${NANOPB_PATH}/pb_common.c ${NANOPB_PATH}/pb_encode.c ${NANOPB_PATH}/pb_decode.c)
set_target_properties(nanopb PROPERTIES C_CLANG_TIDY "") # Disable clang-tidy for this external lib.

target_link_libraries(reactor-uc PRIVATE pthread nanopb)
if(BUILD_EXAMPLES)
add_subdirectory(examples/posix)
endif ()
elseif (PLATFORM STREQUAL "ZEPHYR")
zephyr_library_named(reactor-uc)
zephyr_library_sources(${SOURCES})
zephyr_library_link_libraries(kernel)

zephyr_library_named(nanopb)
zephyr_library_sources(${NANOPB_PATH}/pb_common.c ${NANOPB_PATH}/pb_encode.c ${NANOPB_PATH}/pb_decode.c)
target_link_libraries(reactor-uc PRIVATE nanopb)

elseif (PLATFORM STREQUAL "PICO")
add_library(reactor-uc STATIC ${SOURCES})
target_link_libraries(reactor-uc PUBLIC pico_stdlib pico_sync)
Expand All @@ -64,8 +71,11 @@ else ()
endif ()

add_compile_definitions("PLATFORM_${PLATFORM}")
# TODO: Improve this here
if(NETWORK_POSIX_TCP)
target_compile_definitions(reactor-uc PRIVATE NETWORK_POSIX_TCP)
endif()

target_link_libraries(reactor-uc PRIVATE nanopb)
target_compile_options(reactor-uc PRIVATE -Wall -Wextra -Werror)
add_compile_options (-fdiagnostics-color=always)
target_include_directories(reactor-uc PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include ${CMAKE_CURRENT_LIST_DIR}/external)
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ Zehyr environment, with West installed in a Python virtual environment which is
activated:

```
cd examples/zephyr
cd examples/zephyr/hello
west build -b qemu_cortex_m3 -p always -t run
```

```
cd examples/zephyr/blinky
west build -b frdm_k64f -p always
west flash
```

For more information on running LF programs using the reactor-uc runtime on
Zephyr take a look at this template: https://github.com/lf-lang/lf-west-template/tree/reactor-uc

Expand Down Expand Up @@ -108,6 +114,11 @@ which enable distributed embedded systems.

## Troubleshooting

### Formatting
We are using `clang-format` version 18.1.3 which is default with Ubuntu 24.04 for formatting in CI.

### LFC

If you get the following CMake error when calling `lfc/bin/lfc-dev`
```
CMake Error at CMakeLists.txt:7 (message):
Expand Down
Empty file removed examples/CMakeLists.txt
Empty file.
6 changes: 3 additions & 3 deletions examples/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.20.0)
set(PLATFORM "POSIX" CACHE STRING "Platform to target")

# TODO: Make this more nicer
target_compile_definitions(reactor-uc PRIVATE NETWORK_POSIX_TCP)

# Find all .c files in the src directory
file(GLOB C_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
Expand Down Expand Up @@ -27,5 +29,3 @@ add_custom_target(examples
COMMAND ${CMAKE_COMMAND} -E echo "Running all executables"
DEPENDS ${EXECUTABLES}
)

# Add each executable to the custom target
Loading

0 comments on commit fa23939

Please sign in to comment.