Skip to content

Commit 18c1af6

Browse files
magnmaeherlingrj
andauthored
Add very basic support for FlexPRET platform (#29)
* Add very basic support for FlexPRET platform * Remove unused members of struct * Update CMake file to support FlexPRET again * Add missing ctor declaration to flexpret's platform.h * Format * Minor changes and move files to correspond with main branch * Fix include path * Update to new API, add example. Example does not work properly * Bring code generator back from the dead * Formatting * Add LF tests back to the CI * Fix up connection handling and add another test * Fix some examples * Support more tests * Formatting * Add the notion of an TriggerObserver and update macros and all tests * More LF smoke tests * Remove unused * Add a simple example of how to us LF with zephyr. * Run formatter * Add some FIXMEs to the actiongenerator * LFC cleanup * Rename CONTAINED_ to CHILD_ * Update FlexPRET support * Format * Improve env scripts * Remove one of the FlexPRET test programs * Add simple CI smoke test for FlexPRET * Fix env export * Typo * Configure the correct lf environment * Add CI caching of riscv-none-elf-gcc * Typo --------- Co-authored-by: erlingrj <[email protected]>
1 parent a528f44 commit 18c1af6

File tree

17 files changed

+290
-13
lines changed

17 files changed

+290
-13
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Install FlexPRET dependencies
2+
description: Install FlexPRET dependencies
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Clone FlexPRET
7+
uses: actions/checkout@v3
8+
with:
9+
repository: pretis/flexpret
10+
path: flexpret
11+
submodules: recursive
12+
- name: Setup Scala
13+
uses: olafurpg/setup-scala@v10
14+
with:
15+
java-version: [email protected]
16+
- name: Cache Scala
17+
uses: coursier/cache-action@v5
18+
- name: Install dependencies
19+
run: sudo apt install verilator cmake -y
20+
shell: bash
21+
22+
- name: Cache riscv-none-elf-gcc
23+
id: cache-gcc
24+
uses: actions/cache@v4
25+
with:
26+
path: /opt/xpack-riscv-none-elf-gcc-14.2.0-2
27+
key: flexpret-gcc-${{ runner.os }}
28+
29+
- name: Install riscv-none-elf-gcc
30+
if: steps.cache-gcc.outputs.cache-hit != 'true'
31+
run: |
32+
wget -q --show-progress https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v14.2.0-2/xpack-riscv-none-elf-gcc-14.2.0-2-linux-x64.tar.gz -O gcc.tar.gz
33+
tar xvf gcc.tar.gz --directory=/opt
34+
shell: bash
35+
36+
- name: Build emulator and SDK
37+
run: cd flexpret && source env.bash && cmake -Bbuild && cd build && make all install
38+
shell: bash
39+
- name: Set environmental variables
40+
run: |
41+
echo "PATH=$PATH:$PWD/flexpret/build/emulator" >> $GITHUB_ENV
42+
echo "FP_PATH=$PWD/flexpret" >> $GITHUB_ENV
43+
echo "FP_SDK_PATH=$PWD/flexpret/sdk" >> $GITHUB_ENV
44+
echo "RISCV_TOOL_PATH_PREFIX=/opt/xpack-riscv-none-elf-gcc-14.2.0-2" >> $GITHUB_ENV
45+
shell: bash
46+
47+

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
run: |
2424
sudo apt-get install lcov
2525
- name: Setup java and gradle for compiling lfc
26-
uses: ./.github/actions/prepare-build-env
26+
uses: ./.github/actions/lingua-franca
2727
# Uncomment to SSH into the runner.
2828
# - name: Setup upterm session
2929
# uses: lhotari/action-upterm@v1

.github/workflows/flexpret.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: FlexPRET examples
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
ci:
8+
name: Build FlexPRET examples
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
with:
14+
submodules: recursive
15+
- name: Install dependencies
16+
uses: ./.github/actions/flexpret
17+
- name: Setup java and gradle for compiling lfc
18+
uses: ./.github/actions/lingua-franca
19+
- name: Build examples
20+
run: |
21+
source env.bash
22+
cd examples/flexpret
23+
./buildAll.sh
24+

CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,16 @@ if(BUILD_TESTS)
4141
endif()
4242
endif()
4343

44-
4544
file(GLOB SOURCES "src/*.c" "external/proto/*.c")
46-
4745
set(NANOPB_PATH external/nanopb)
4846

4947
if (PLATFORM STREQUAL "POSIX")
5048
add_library(reactor-uc STATIC ${SOURCES})
51-
# Add nanopb library manually
52-
add_library(nanopb ${NANOPB_PATH}/pb_common.c ${NANOPB_PATH}/pb_encode.c ${NANOPB_PATH}/pb_decode.c)
53-
set_target_properties(nanopb PROPERTIES C_CLANG_TIDY "") # Disable clang-tidy for this external lib.
54-
55-
target_link_libraries(reactor-uc PRIVATE pthread nanopb)
49+
target_link_libraries(reactor-uc PRIVATE pthread)
50+
elseif (PLATFORM STREQUAL "FLEXPRET")
51+
add_library(reactor-uc STATIC ${SOURCES})
52+
add_subdirectory($ENV{FP_SDK_PATH} BINARY_DIR)
53+
target_link_libraries(reactor-uc PUBLIC fp-sdk)
5654
elseif (PLATFORM STREQUAL "ZEPHYR")
5755
zephyr_library_named(reactor-uc)
5856
zephyr_library_sources(${SOURCES})
@@ -69,6 +67,12 @@ else ()
6967
message(FATAL_ERROR "No valid platform specified")
7068
endif ()
7169

70+
# Add nanopb library. Note that for Zephyr it is built customly above.
71+
if (NOT PLATFORM STREQUAL "ZEPHYR")
72+
add_library(nanopb ${NANOPB_PATH}/pb_common.c ${NANOPB_PATH}/pb_encode.c ${NANOPB_PATH}/pb_decode.c)
73+
set_target_properties(nanopb PROPERTIES C_CLANG_TIDY "") # Disable clang-tidy for this external lib.
74+
target_link_libraries(reactor-uc PRIVATE nanopb)
75+
endif()
7276

7377
# Add compile definitions for platform and network channel specifics.
7478
target_compile_definitions(reactor-uc PRIVATE "PLATFORM_${PLATFORM}")
@@ -85,7 +89,11 @@ if(NETWORK_CHANNEL_TCP_POSIX)
8589
endif()
8690

8791
target_compile_options(reactor-uc PRIVATE -Wall -Wextra -Werror)
88-
# target_compile_options(reactor-uc PUBLIC -Wno-zero-length-bounds)
92+
93+
# Disable selected warnings
94+
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
95+
target_compile_options(reactor-uc PUBLIC -Wno-zero-length-bounds -Wno-stack-usage)
96+
endif()
8997

9098

9199
add_compile_options (-fdiagnostics-color=always)

env.bash

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
2-
32
# From https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script
4-
export REACTOR_UC_PATH=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
53

6-
alias lfcg='${REACTOR_UC_PATH}/lfc/bin/lfc-dev'
4+
curdir=$(pwd)
5+
export REACTOR_UC_PATH=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
6+
alias lfcg='${REACTOR_UC_PATH}/lfc/bin/lfc-dev'
7+
cd $curdir

env.fish

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# From: https://stackoverflow.com/questions/19672673/can-a-fish-script-tell-what-directory-its-stored-in
2+
set curdir (pwd)
23
set -x REACTOR_UC_PATH (cd (dirname (status -f)); and pwd)
4+
cd $curdir
35

46
# Define the function
57
function do_lfc

examples/flexpret/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
if(NOT DEFINED ENV{FP_SDK_PATH})
4+
message(FATAL_ERROR "FP_SDK_PATH environment variable not set!")
5+
endif()
6+
7+
include($ENV{FP_SDK_PATH}/cmake/riscv-toolchain.cmake)
8+
include($ENV{FP_SDK_PATH}/cmake/fp-app.cmake)
9+
10+
project(fp-lf)
11+
12+
add_executable(fp-smoke src/main.c)
13+
add_subdirectory(src-gen/Smoke)
14+
target_link_libraries(fp-smoke PUBLIC Smoke)
15+
fp_add_outputs(fp-smoke)

examples/flexpret/buildAll.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set -e
2+
${REACTOR_UC_PATH}/lfc/bin/lfc-dev src/Smoke.lf
3+
cmake -Bbuild
4+
make -C build
5+
bin/fp-smoke

examples/flexpret/src/Smoke.lf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
target uC {
2+
platform: FlexPRET
3+
}
4+
5+
reactor R1 {
6+
output out: int
7+
8+
reaction(startup) -> out {=
9+
lf_set(out, 42);
10+
=}
11+
}
12+
13+
reactor R2 {
14+
input in: int
15+
16+
reaction(startup) {=
17+
printf("Hello from R2, FlexPRET!\n");
18+
=}
19+
20+
reaction(in) {=
21+
printf("Received: %d\n", in->value);
22+
validate(in->value == 42);
23+
=}
24+
}
25+
26+
main reactor {
27+
r1 = new R1()
28+
r2 = new R2()
29+
r1.out -> r2.in
30+
}

0 commit comments

Comments
 (0)