From 27ef659dec5782c4242a4f1348636e2ea60ed161 Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Tue, 23 Jul 2024 11:41:00 +0200 Subject: [PATCH] ADASModel added and tested --- test/C/Makefile | 6 +- test/C/src/static/ADASModel.lf | 110 +++++++++++++++++++ test/C/src/static/ScheduleTest.lf | 2 + test/C/src/static/SimpleConnection.lf | 11 +- test/C/src/static/patmos/Makefile | 19 +++- test/C/src/static/patmos/lf_patmos_support.c | 2 +- 6 files changed, 137 insertions(+), 13 deletions(-) create mode 100644 test/C/src/static/ADASModel.lf diff --git a/test/C/Makefile b/test/C/Makefile index 7badf22728..e468e4cbf6 100644 --- a/test/C/Makefile +++ b/test/C/Makefile @@ -1,13 +1,15 @@ -APP?=ScheduleTest +APP?=SimpleConnection +FUNC?=_sinkreaction_function_0 SRC_DIR=$(CURDIR)/src/static/patmos DEST_DIR=$(CURDIR)/src-gen/static/$(APP) INCD_DIR=$(CURDIR)/include export LF_PROJECT_ROOT:=$(DEST_DIR) export LF_MAIN_TARGET:=$(APP) +export LF_WCET_FUNC:=$(FUNC) .PHONY: gen copy comp all clean wcet sim lin -all: del gen copy comp sim +all: del gen copy comp lin sim wcet gen: lfc-dev src/static/$(APP).lf copy: diff --git a/test/C/src/static/ADASModel.lf b/test/C/src/static/ADASModel.lf new file mode 100644 index 0000000000..2f4bb8d625 --- /dev/null +++ b/test/C/src/static/ADASModel.lf @@ -0,0 +1,110 @@ +/** FIXME: Turn this program into a test case. */ +target C { + timeout: 1 sec, + scheduler: STATIC, + build-type: Debug, + single-threaded: true +} + +preamble {= + typedef int c_frame_t; + typedef int l_frame_t; +=} + +realtime reactor Camera { + output out: {= c_frame_t =} + state frame: {= c_frame_t =} + timer t(0, 17 msec) // 60 fps + + @wcet("93572 nsec") // RPI4 + reaction(t) -> out {= + // Capture a frame. + //lf_print("Camera reaction"); + self->frame = 1; + lf_set(out, self->frame); + =} +} + +realtime reactor LiDAR { + output out: {= l_frame_t =} + state frame: {= l_frame_t =} + timer t(0, 34 msec) // 30 fps + + @wcet("97942 nsec") // RPI4 + reaction(t) -> out {= + // Capture a frame. + // lf_print("LiDAR Reaction"); + self->frame = 2; + lf_set(out, self->frame); + =} +} + +realtime reactor Brakes { + input inADAS: int + state brakesApplied: int = 0 + + // RPI4 + @wcet("5037 nsec") + reaction(inADAS) {= + // Actuate brakes. + // lf_print("Brakes reaction"); + self->brakesApplied = 1; + =} +} + +reactor ADASProcessor { + input in1: {= l_frame_t =} + input in2: {= c_frame_t =} + input a_in: int + output out1: int + output out2: int + output a_out: int + state requestStop: int + + // RPI4 + @wcet("5592 nsec") + reaction(in1, in2) -> a_out {= + // ... Detect danger + // and request stop. + // lf_print("ADASProcessor reaction 1"); + lf_set_present(a_out); + self->requestStop = 1; + =} + + // RPI4 + @wcet("6741 nsec") + reaction(a_in) -> out1, out2 {= + // lf_print("ADASProcessor reaction 2"); + if (self->requestStop == 1) { + lf_set_present(out1); + lf_set_present(out2); + } + =} deadline(20 msec) {= + // lf_print("Deadline reaction"); + =} +} + +reactor Dashboard { + input in: int + state received: int + + // RPI4 + @wcet("4815 nsec") + reaction(in) {= + // lf_print("Dashboard reaction"); + self->received = 1; + =} +} + +main reactor ADASModel { + c = new Camera() + l = new LiDAR() + p = new ADASProcessor() + b = new Brakes() + d = new Dashboard() + l.out -> p.in1 + c.out -> p.in2 + p.out2 -> d.in + p.out1 -> b.inADAS after 5 msec + p.a_out -> p.a_in after 50 msec +} diff --git a/test/C/src/static/ScheduleTest.lf b/test/C/src/static/ScheduleTest.lf index 71143da13b..5f8c23bb93 100644 --- a/test/C/src/static/ScheduleTest.lf +++ b/test/C/src/static/ScheduleTest.lf @@ -6,7 +6,9 @@ target C { // workers: 2, timeout: 100 sec, fast: true, + build-type: Debug, single-threaded: true, + tracing: false } preamble {= diff --git a/test/C/src/static/SimpleConnection.lf b/test/C/src/static/SimpleConnection.lf index e86394be6c..60ffd5e7d5 100644 --- a/test/C/src/static/SimpleConnection.lf +++ b/test/C/src/static/SimpleConnection.lf @@ -16,7 +16,8 @@ reactor Source { state s:int = 0 reaction(t) -> out {= lf_set(out, self->s); - lf_print("Sent %d @ %lld", self->s++, lf_time_logical_elapsed()); + self->s++; + // lf_print("Sent %d @ %lld", self->s, lf_time_logical_elapsed()); =} reaction(t) -> out {= int v = -1 * self->s; @@ -29,14 +30,14 @@ reactor Sink { state last_received:int = 0 reaction(in) {= self->last_received = in->value; - lf_print("Received %d @ %lld", in->value, lf_time_logical_elapsed()); + // lf_print("Received %d @ %lld", in->value, lf_time_logical_elapsed()); =} reaction(shutdown) {= if (self->last_received != EXPECTED) { - fprintf(stderr, "FAILURE: Expected %d, Received %d\n", EXPECTED, self->last_received); + // fprintf(stderr, "FAILURE: Expected %d, Received %d\n", EXPECTED, self->last_received); exit(1); } else { - lf_print("Successfully received %d", self->last_received); + // lf_print("Successfully received %d", self->last_received); } =} } @@ -45,6 +46,4 @@ main reactor { source = new Source() sink = new Sink() source.out -> sink.in after 2 sec - // source.out -> sink.in after 500 msec - // source.out -> sink.in } \ No newline at end of file diff --git a/test/C/src/static/patmos/Makefile b/test/C/src/static/patmos/Makefile index c725a82428..71569ad167 100644 --- a/test/C/src/static/patmos/Makefile +++ b/test/C/src/static/patmos/Makefile @@ -19,15 +19,26 @@ CC := patmos-clang CFLAGS := $(INCS) -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10 -DLF_REACTION_GRAPH_BREADTH=1 CFLAGS += -DLF_SINGLE_THREADED=0 -DSCHEDULER=SCHED_STATIC -SRC_FILES := _$(LF_MAIN_TARGET_LC)_main.c $(LF_MAIN_TARGET).c lib/schedule.c _sink.c _source.c static_schedule.c -SRC_FILES += core/reactor_common.c core/lf_token.c core/reactor.c core/tag.c core/environment.c +SRC_FILES := _$(LF_MAIN_TARGET_LC)_main.c $(LF_MAIN_TARGET).c + +ifeq ($(LF_MAIN_TARGET), SimpleConnection) + SRC_FILES += _sink.c _source.c static_schedule.c +else ifeq ($(LF_MAIN_TARGET), ScheduleTest) + SRC_FILES += _sink.c _source.c static_schedule.c +else ifeq ($(LF_MAIN_TARGET), Philosophers) + SRC_FILES += _arbitrator.c _broadcast.c _benchmarkrunner.c _philosopher.c +else ifeq ($(LF_MAIN_TARGET), ADASModel) + SRC_FILES += _adasprocessor.c _brakes.c _camera.c _dashboard.c _lidar.c static_schedule.c +endif + +SRC_FILES += lib/schedule.c core/reactor_common.c core/lf_token.c core/reactor.c core/tag.c core/environment.c SRC_FILES += core/utils/util.c core/utils/vector.c core/utils/circular_buffer.c SRC_FILES += core/utils/pqueue.c core/utils/pqueue_tag.c core/utils/pqueue_base.c SRC_FILES += core/utils/hashset/hashset_itr.c core/utils/hashset/hashset.c SRC_FILES += core/clock.c core/platform/lf_atomic_irq.c SRC_FILES += core/platform/lf_patmos_support.c core/platform/lf_atomic_patmos.c -# SRC_FILES += core/threaded/scheduler_adaptive.c core/threaded/scheduler_GEDF_NP.c core/threaded/reactor_threaded.c core/threaded/watchdog.c SRC_FILES += core/threaded/scheduler_instance.c core/threaded/scheduler_static.c +# SRC_FILES += core/threaded/scheduler_adaptive.c core/threaded/scheduler_GEDF_NP.c core/threaded/reactor_threaded.c core/threaded/watchdog.c # core/threaded/scheduler_sync_tag_advance.c core/threaded/scheduler_NP.c # SRC_FILES += core/federated/RTI/rti_local.c OBJ_FILES := $(patsubst %.c,%.o,$(SRC_FILES)) @@ -44,6 +55,6 @@ $(OBJ_FILES): %.o: %.c clean: rm -f $(OBJ_FILES) $(EXE_NAME) wcet: $(EXE_NAME) - platin wcet --disable-ait -i lf.pml -b $(EXE_NAME) -e _sinkreaction_function_0 --report report.txt + platin wcet --disable-ait -i lf.pml -b $(EXE_NAME) -e $(LF_WCET_FUNC) --target-call-return-costs --report report.txt # platin visualize -i lf.pml -f main --show-timings=platin \ No newline at end of file diff --git a/test/C/src/static/patmos/lf_patmos_support.c b/test/C/src/static/patmos/lf_patmos_support.c index 162ca95fd2..91e5f1ccea 100644 --- a/test/C/src/static/patmos/lf_patmos_support.c +++ b/test/C/src/static/patmos/lf_patmos_support.c @@ -65,7 +65,7 @@ void _lf_initialize_clock() int _lf_clock_gettime(instant_t *t) { - assert(t != NULL); + // assert(t != NULL); *t = get_cpu_usecs() * 1000;