Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add very basic support for FlexPRET platform #29

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
28d2c59
Add very basic support for FlexPRET platform
magnmaeh Oct 1, 2024
25e56a9
Remove unused members of struct
magnmaeh Oct 1, 2024
4eb7dda
Merge branch 'main' into 22-add-platform-support-for-flexpret
magnmaeh Oct 3, 2024
0728dd2
Update CMake file to support FlexPRET again
magnmaeh Oct 3, 2024
422bca3
Add missing ctor declaration to flexpret's platform.h
magnmaeh Oct 3, 2024
eb7db9d
Format
magnmaeh Oct 3, 2024
e36f876
Fix merge conflicts
magnmaeh Oct 12, 2024
76cd531
Minor changes and move files to correspond with main branch
magnmaeh Oct 12, 2024
7ba372d
Solve merge conflicts with main
magnmaeh Oct 16, 2024
b4d060c
Fix include path
magnmaeh Oct 16, 2024
4500d5d
Update to new API, add example. Example does not work properly
magnmaeh Oct 16, 2024
1c83839
Bring code generator back from the dead
erlingrj Nov 14, 2024
46d48b1
Formatting
erlingrj Nov 14, 2024
beb7051
Add LF tests back to the CI
erlingrj Nov 14, 2024
72d4114
Fix up connection handling and add another test
erlingrj Nov 14, 2024
cfa6393
Fix some examples
erlingrj Nov 14, 2024
2c1d621
Support more tests
erlingrj Nov 15, 2024
56c29a0
Formatting
erlingrj Nov 15, 2024
dc1c8f6
Add the notion of an TriggerObserver and update macros and all tests
erlingrj Nov 16, 2024
3f57bca
More LF smoke tests
erlingrj Nov 16, 2024
d056c99
Remove unused
erlingrj Nov 16, 2024
0413fbb
Add a simple example of how to us LF with zephyr.
erlingrj Nov 16, 2024
14a3afa
Run formatter
erlingrj Nov 16, 2024
66572aa
Add some FIXMEs to the actiongenerator
erlingrj Nov 16, 2024
db219b7
LFC cleanup
erlingrj Nov 16, 2024
f1b82fc
Rename CONTAINED_ to CHILD_
erlingrj Nov 16, 2024
9b4fa6a
Merge branch 'bring-back-lfc' into 22-add-platform-support-for-flexpret
erlingrj Nov 16, 2024
1ff057c
Update FlexPRET support
erlingrj Nov 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ jobs:
- name: Install deps
run: |
sudo apt-get install lcov
# Commented out because we dont do LFC tests at the moment.
# - name: Setup java and gradle for compiling lfc
# uses: ./.github/actions/prepare-build-env
- name: Setup java and gradle for compiling lfc
uses: ./.github/actions/prepare-build-env
# Uncomment to SSH into the runner.
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1
Expand All @@ -33,6 +32,7 @@ jobs:
source env.bash
make format-check
make unit-test
make lf-test
make examples
make coverage
- name: Coverage
Expand Down
20 changes: 13 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,16 @@ if(BUILD_TESTS)
endif()
endif()


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

set(NANOPB_PATH external/nanopb)

if (PLATFORM STREQUAL "POSIX")
add_library(reactor-uc STATIC ${SOURCES})
# 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)
target_link_libraries(reactor-uc PRIVATE pthread)
elseif (PLATFORM STREQUAL "FLEXPRET")
add_library(reactor-uc STATIC ${SOURCES})
add_subdirectory($ENV{FP_SDK_PATH} BINARY_DIR)
target_link_libraries(reactor-uc PUBLIC fp-sdk)
elseif (PLATFORM STREQUAL "ZEPHYR")
zephyr_library_named(reactor-uc)
zephyr_library_sources(${SOURCES})
Expand All @@ -68,6 +66,13 @@ else ()
message(FATAL_ERROR "No valid platform specified")
endif ()

# Add nanopb library. Note that for Zephyr it is built customly above.
if (NOT PLATFORM STREQUAL "ZEPHYR")
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 nanopb)
endif()

# Add compile definitions for platform and network channel specifics.
target_compile_definitions(reactor-uc PRIVATE "PLATFORM_${PLATFORM}")

Expand All @@ -80,6 +85,7 @@ if(NETWORK_CHANNEL_TCP_POSIX)
endif()

target_compile_options(reactor-uc PRIVATE -Wall -Wextra -Werror)
target_compile_options(reactor-uc PUBLIC -Wno-zero-length-bounds -Wno-stack-usage)


add_compile_options (-fdiagnostics-color=always)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: clean test coverage asan format format-check ci lf-test lib proto examples

test: unit-test examples
test: unit-test lf-test examples

# Generate protobuf code
proto:
Expand Down
6 changes: 3 additions & 3 deletions examples/common/timer_source.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "reactor-uc/reactor-uc.h"

DEFINE_TIMER_STRUCT(TimerSource, t, 1);
DEFINE_TIMER_CTOR(TimerSource, t, 1);
DEFINE_REACTION_STRUCT(TimerSource, r, 1);
DEFINE_TIMER_STRUCT(TimerSource, t, 1, 0);
DEFINE_TIMER_CTOR(TimerSource, t, 1, 0);
DEFINE_REACTION_STRUCT(TimerSource, r, 0);
DEFINE_REACTION_CTOR(TimerSource, r, 0);

typedef struct {
Expand Down
21 changes: 21 additions & 0 deletions examples/flexpret/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.22)

if(NOT DEFINED ENV{FP_SDK_PATH})
message(FATAL_ERROR "FP_SDK_PATH environment variable not set!")
endif()

include($ENV{FP_SDK_PATH}/cmake/riscv-toolchain.cmake)
include($ENV{FP_SDK_PATH}/cmake/fp-app.cmake)

project(fp-lf)

# add_executable(fp-hello src/main.c)
# add_subdirectory(src-gen/HelloFlexPRET)
# target_link_libraries(fp-hello PUBLIC HelloFlexPRET)
# fp_add_outputs(fp-hello)


add_executable(fp-smoke src/main.c)
add_subdirectory(src-gen/Smoke)
target_link_libraries(fp-smoke PUBLIC Smoke)
fp_add_outputs(fp-smoke)
9 changes: 9 additions & 0 deletions examples/flexpret/src/HelloFlexPRET.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
target uC {
platform: FlexPRET
}

main reactor {
reaction(startup) {=
printf("Hello, FlexPRET!\n");
=}
}
30 changes: 30 additions & 0 deletions examples/flexpret/src/Smoke.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
target uC {
platform: FlexPRET
}

reactor R1 {
output out: int

reaction(startup) -> out {=
lf_set(out, 42);
=}
}

reactor R2 {
input in: int

reaction(startup) {=
printf("Hello from R2, FlexPRET!\n");
=}

reaction(in) {=
printf("Received: %d\n", in->value);
validate(in->value == 42);
=}
}

main reactor {
r1 = new R1()
r2 = new R2()
r1.out -> r2.in
}
5 changes: 5 additions & 0 deletions examples/flexpret/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "lf_main.h"

int main() {
lf_start();
}
9 changes: 0 additions & 9 deletions examples/lf/src/HelloUc.lf

This file was deleted.

14 changes: 8 additions & 6 deletions examples/posix/federated/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ lf_ret_t deserialize_msg_t(void *user_struct, const unsigned char *msg_buf, size

DEFINE_REACTION_STRUCT(Receiver, r, 0);
DEFINE_REACTION_CTOR(Receiver, r, 0);
DEFINE_INPUT_STRUCT(Receiver, in, 1, msg_t, 0);
DEFINE_INPUT_CTOR(Receiver, in, 1, msg_t, 0);
DEFINE_INPUT_STRUCT(Receiver, in, 1, 0, msg_t, 0);
DEFINE_INPUT_CTOR(Receiver, in, 1, 0, msg_t, 0);

typedef struct {
Reactor super;
Expand All @@ -40,14 +40,14 @@ DEFINE_REACTION_BODY(Receiver, r) {
in->value.size);
}

REACTOR_CTOR_SIGNATURE(Receiver) {
REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs in_external) {
REACTOR_CTOR_PREAMBLE();
REACTOR_CTOR(Receiver);
INITIALIZE_REACTION(Receiver, r);
INITIALIZE_INPUT(Receiver, in);
INITIALIZE_INPUT(Receiver, in, in_external);

// Register reaction as an effect of in
INPUT_REGISTER_EFFECT(in, r);
PORT_REGISTER_EFFECT(in, r);
}

DEFINE_FEDERATED_INPUT_CONNECTION(Receiver, in, msg_t, 5, MSEC(100), false);
Expand All @@ -71,12 +71,14 @@ typedef struct {
CHILD_REACTOR_INSTANCE(Receiver, receiver);
FEDERATED_CONNECTION_BUNDLE_INSTANCE(Receiver, Sender);
FEDERATE_BOOKKEEPING_INSTANCES(0,0,1,1);
CHILD_INPUT_SOURCES(receiver, in, 0);
} MainRecv;

REACTOR_CTOR_SIGNATURE(MainRecv) {
FEDERATE_CTOR_PREAMBLE();
REACTOR_CTOR(MainRecv);
INITIALIZE_CHILD_REACTOR(Receiver, receiver);
DEFINE_CHILD_INPUT_ARGS(receiver, in);
INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Receiver, receiver, _receiver_in_args);
INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Receiver, Sender);
BUNDLE_REGISTER_DOWNSTREAM(Receiver, Sender, receiver, in);
}
Expand Down
19 changes: 11 additions & 8 deletions examples/posix/federated/sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ size_t serialize_msg_t(const void *user_struct, size_t user_struct_size, unsigne
return sizeof(msg->size) + msg->size;
}

DEFINE_TIMER_STRUCT(Sender, t, 1)
DEFINE_TIMER_CTOR(Sender, t, 1)
DEFINE_TIMER_STRUCT(Sender, t, 1, 0)
DEFINE_TIMER_CTOR(Sender, t, 1, 0)
DEFINE_REACTION_STRUCT(Sender, r, 1)
DEFINE_REACTION_CTOR(Sender, r, 0)
DEFINE_OUTPUT_STRUCT(Sender, out, 1)
DEFINE_OUTPUT_STRUCT(Sender, out, 1, interval_t)
DEFINE_OUTPUT_CTOR(Sender, out, 1)

typedef struct {
Expand All @@ -48,16 +48,16 @@ DEFINE_REACTION_BODY(Sender, r) {
lf_set(out, val);
}

REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, Connection **conn_out, size_t conn_out_num) {
REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, OutputExternalCtorArgs out_external) {
REACTOR_CTOR_PREAMBLE();
REACTOR_CTOR(Sender);
INITIALIZE_REACTION(Sender, r);
INITIALIZE_TIMER(Sender, t, MSEC(0), SEC(1));
INITIALIZE_OUTPUT(Sender, out, conn_out, conn_out_num);
INITIALIZE_OUTPUT(Sender, out, out_external);

TIMER_REGISTER_EFFECT(t, r);
REACTION_REGISTER_EFFECT(r, out);
OUTPUT_REGISTER_SOURCE(out, r);
PORT_REGISTER_SOURCE(out, r);
}

DEFINE_FEDERATED_OUTPUT_CONNECTION(Sender, out, msg_t, 1)
Expand Down Expand Up @@ -85,12 +85,15 @@ typedef struct {
FEDERATED_CONNECTION_BUNDLE_INSTANCE(Sender, Receiver);
TcpIpChannel channel;
FEDERATE_BOOKKEEPING_INSTANCES(0,0,1,1);
CONTAINED_OUTPUT_CONNECTIONS(sender, out, 1);
CHILD_OUTPUT_CONNECTIONS(sender, out, 1);
CHILD_OUTPUT_EFFECTS(sender, out, 0);
CHILD_OUTPUT_OBSERVERS(sender, out, 0);
} MainSender;

REACTOR_CTOR_SIGNATURE(MainSender) {
FEDERATE_CTOR_PREAMBLE();
INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Sender, sender, self->_conns_sender_out_out, 1);
DEFINE_CHILD_OUTPUT_ARGS(sender, out);
INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Sender, sender, _sender_out_args);
INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Sender, Receiver);
BUNDLE_REGISTER_UPSTREAM(Sender, Receiver, sender, out);
REACTOR_CTOR(MainSender);
Expand Down
14 changes: 8 additions & 6 deletions examples/zephyr/basic_federated/common/receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ typedef struct {
DEFINE_REACTION_STRUCT(Receiver, r, 0);
DEFINE_REACTION_CTOR(Receiver, r, 0)

DEFINE_INPUT_STRUCT(Receiver, in, 1, msg_t, 0)
DEFINE_INPUT_CTOR(Receiver, in, 1, msg_t, 0)
DEFINE_INPUT_STRUCT(Receiver, in, 1, 0, msg_t, 0)
DEFINE_INPUT_CTOR(Receiver, in, 1, 0, msg_t, 0)

typedef struct {
Reactor super;
Expand All @@ -54,14 +54,14 @@ DEFINE_REACTION_BODY(Receiver, r) {
env->get_logical_time(env), env->get_physical_time(env));
}

REACTOR_CTOR_SIGNATURE(Receiver) {
REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs in_external) {
REACTOR_CTOR_PREAMBLE();
REACTOR_CTOR(Receiver);
INITIALIZE_REACTION(Receiver, r);
INITIALIZE_INPUT(Receiver, in);
INITIALIZE_INPUT(Receiver, in, in_external);

// Register reaction as an effect of in
INPUT_REGISTER_EFFECT(in, r);
PORT_REGISTER_EFFECT(in, r);
}


Expand All @@ -87,12 +87,14 @@ typedef struct {
CHILD_REACTOR_INSTANCE(Receiver, receiver);
FEDERATED_CONNECTION_BUNDLE_INSTANCE(Receiver, Sender);
FEDERATE_BOOKKEEPING_INSTANCES(0,0,1,1);
CHILD_INPUT_SOURCES(receiver, in, 0);
} MainRecv;

REACTOR_CTOR_SIGNATURE(MainRecv) {
FEDERATE_CTOR_PREAMBLE();
REACTOR_CTOR(MainRecv);
INITIALIZE_CHILD_REACTOR(Receiver, receiver);
DEFINE_CHILD_INPUT_ARGS(receiver, in);
INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Receiver, receiver, _receiver_in_args);
INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Receiver, Sender);
BUNDLE_REGISTER_DOWNSTREAM(Receiver, Sender, receiver, in);
}
Expand Down
28 changes: 16 additions & 12 deletions examples/zephyr/basic_federated/federated_sender/src/sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, {
static struct gpio_callback button_cb_data;
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

DEFINE_ACTION_STRUCT(Sender, act, PHYSICAL_ACTION, 1, 0, 10, bool);
DEFINE_ACTION_CTOR(Sender, act, PHYSICAL_ACTION, 1, 0, 10, bool);
typedef struct {
char msg[32];
} msg_t;

DEFINE_ACTION_STRUCT(Sender, act, PHYSICAL_ACTION, 1, 0, 0, 10, bool);
DEFINE_ACTION_CTOR(Sender, act, PHYSICAL_ACTION, 1, 0, 0, 10, bool);
DEFINE_REACTION_STRUCT(Sender, r, 1);
DEFINE_REACTION_CTOR(Sender, r, 0);

DEFINE_OUTPUT_STRUCT(Sender, out, 1)
DEFINE_OUTPUT_STRUCT(Sender, out, 1, msg_t)
DEFINE_OUTPUT_CTOR(Sender, out, 1)

Sender_act *action_ptr = NULL;
Expand Down Expand Up @@ -62,9 +66,6 @@ void setup_led() {
gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
}

typedef struct {
char msg[32];
} msg_t;

typedef struct {
Reactor super;
Expand All @@ -86,16 +87,16 @@ DEFINE_REACTION_BODY(Sender, r) {
lf_set(out, val);
}

REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, Connection **conn_out, size_t conn_out_num) {
REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, OutputExternalCtorArgs out_external) {
REACTOR_CTOR_PREAMBLE();
REACTOR_CTOR(Sender);
INITIALIZE_REACTION(Sender, r);
INITIALIZE_ACTION(Sender, act, MSEC(0));
INITIALIZE_OUTPUT(Sender, out, conn_out, conn_out_num);
INITIALIZE_OUTPUT(Sender, out, out_external);

ACTION_REGISTER_EFFECT(act, r);
REACTION_REGISTER_EFFECT(r, out);
OUTPUT_REGISTER_SOURCE(out, r);
PORT_REGISTER_SOURCE(out, r);
}

DEFINE_FEDERATED_OUTPUT_CONNECTION(Sender, out, msg_t, 1)
Expand Down Expand Up @@ -138,15 +139,18 @@ typedef struct {
CHILD_REACTOR_INSTANCE(Sender, sender);
FEDERATED_CONNECTION_BUNDLE_INSTANCE(Sender, Receiver1);
FEDERATED_CONNECTION_BUNDLE_INSTANCE(Sender, Receiver2);
CONTAINED_OUTPUT_CONNECTIONS(sender, out, 2);
CHILD_OUTPUT_CONNECTIONS(sender, out, 2);
CHILD_OUTPUT_EFFECTS(sender, out, 0);
CHILD_OUTPUT_OBSERVERS(sender, out, 0);
FEDERATE_BOOKKEEPING_INSTANCES(0,0,1,2);
} MainSender;

REACTOR_CTOR_SIGNATURE(MainSender) {
FEDERATE_CTOR_PREAMBLE();
REACTOR_CTOR(MainSender);

INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Sender, sender, self->_conns_sender_out_out, 2);

DEFINE_CHILD_OUTPUT_ARGS(sender, out);
INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Sender, sender, _sender_out_args);
INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Sender, Receiver1);
INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Sender, Receiver2);

Expand Down
7 changes: 7 additions & 0 deletions examples/zephyr/hello_lf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(HelloLF)

target_sources(app PRIVATE src/main.c)
add_subdirectory(src-gen/HelloLF)
target_link_libraries(app PRIVATE HelloLF)
Loading
Loading