Skip to content

Commit

Permalink
ADASModel added and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
EhsanKhodadad committed Jul 23, 2024
1 parent 863401e commit 27ef659
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 13 deletions.
6 changes: 4 additions & 2 deletions test/C/Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
110 changes: 110 additions & 0 deletions test/C/src/static/ADASModel.lf
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions test/C/src/static/ScheduleTest.lf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ target C {
// workers: 2,
timeout: 100 sec,
fast: true,
build-type: Debug,
single-threaded: true,
tracing: false
}

preamble {=
Expand Down
11 changes: 5 additions & 6 deletions test/C/src/static/SimpleConnection.lf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
=}
}
Expand All @@ -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
}
19 changes: 15 additions & 4 deletions test/C/src/static/patmos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

2 changes: 1 addition & 1 deletion test/C/src/static/patmos/lf_patmos_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 27ef659

Please sign in to comment.