Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions docs/assets/code/c/src/DecentralizedTimerAfter.lf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ reactor PrintTimer extends Print {

federated reactor {
c = new Count()
@maxwait(0)
p = new PrintTimer()
c.out -> p.in after 10 ms
}
1 change: 1 addition & 0 deletions docs/assets/code/c/src/DecentralizedZeroDelayLoop.lf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ reactor Double {
}

federated reactor {
@maxwait(0)
c = new CountPrint()
p = new Double()
c.out -> p.in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ reactor CountPrintWithChecker extends CountPrint {
}

federated reactor {
@maxwait(0)
c = new CountPrintWithChecker()
p = new Double()
c.out -> p.in
Expand Down
1 change: 1 addition & 0 deletions docs/assets/code/py/src/DecentralizedTimerAfter.lf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ reactor PrintTimer extends Print {

federated reactor {
c = new Count()
@maxwait(0)
p = new PrintTimer()
c.out -> p.inp after 10 ms
}
1 change: 1 addition & 0 deletions docs/assets/code/py/src/DecentralizedZeroDelayLoop.lf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ reactor Double {
}

federated reactor {
@maxwait(0)
c = new CountPrint()
p = new Double()
c.out -> p.inp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ reactor CountPrintWithChecker extends CountPrint {
}

federated reactor {
@maxwait(0)
c = new CountPrintWithChecker()
p = new Double()
c.out -> p.inp
Expand Down
3 changes: 3 additions & 0 deletions docs/assets/code/uc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin
src-gen
include
22 changes: 22 additions & 0 deletions docs/assets/code/uc/src/Alignment.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
target uC

@platform("Native")
@timeout(3 sec)
main reactor Alignment {
state s: int = 0
timer t1(100 msec, 100 msec)
timer t2(200 msec, 200 msec)
timer t4(400 msec, 400 msec)

reaction(t1) {=
self->s += 1;
=}

reaction(t2) {=
self->s -= 2;
=}

reaction(t4) {=
printf("s = %d\n", self->s);
=}
}
30 changes: 30 additions & 0 deletions docs/assets/code/uc/src/Asynchronous.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
target uC

@platform("Native")
@keepalive(true)
main reactor {
preamble {=
#include <unistd.h>
// Schedule an event roughly every 200 msec.

void* external(void* ptr) {
Action* physical_action = (Action*)ptr;
while (true) {
usleep(200000);
lf_schedule(physical_action, SEC(0), 0);
}
}
=}

state thread: pthread_t
physical action a(100 msec): int

reaction(startup) -> a {=
pthread_create(&self->thread, NULL, &external, a);
=}

reaction(a) {=
interval_t elapsed_time = env->get_elapsed_logical_time(env);
printf("Action triggered at logical time %lld nsec after start.\n", elapsed_time);
=}
}
11 changes: 11 additions & 0 deletions docs/assets/code/uc/src/BankIndex.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target uC;
reactor A(bank_index:int = 0, value:int = 0) {
reaction (startup) {=
printf("bank_index: %d, value: %d\n", self->bank_index, self->value);
=}
}
main reactor(
table: int[] = {4, 3, 2, 1}
) {
a = new[4] A(value = {= self->table[bank_index] =});
}
22 changes: 22 additions & 0 deletions docs/assets/code/uc/src/CheckDeadline.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
target uC;

reactor Count {
output out:int;
reaction(startup) -> out {=
int count = 0;
while (!lf_check_deadline(self, true)) {
count++;
}
lf_set(out, count);
=} deadline (3 msec) {=
printf("Stopped counting.\n");
=}
}

@platform("Native")
main reactor {
c = new Count();
reaction(c.out) {=
printf("Counted to %d\n", c.out->value);
=}
}
17 changes: 17 additions & 0 deletions docs/assets/code/uc/src/ChildBank.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
target uC;
reactor Child (
bank_index:int = 0
) {
reaction(startup) {=
printf("My bank index: %d.\n", self->bank_index);
=}
}
reactor Parent (
bank_index:int = 0
) {
c = new[2] Child();
}
@platform("Native")
main reactor {
p = new[2] Parent();
}
19 changes: 19 additions & 0 deletions docs/assets/code/uc/src/ChildParentBank.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
target uC

reactor Child(bank_index: int = 0, parent_bank_index: int = 0) {
reaction(startup) {=
printf(
"My bank index: %d. My parent's bank index: %d.\n",
self->bank_index, self->parent_bank_index
);
=}
}

reactor Parent(bank_index: int = 0) {
c = new[2] Child(parent_bank_index=bank_index)
}

@platform("Native")
main reactor {
p = new[2] Parent()
}
24 changes: 24 additions & 0 deletions docs/assets/code/uc/src/ChildParentBank2.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target uC

reactor Child(bank_index: int = 0, parent_bank_index: int = 0) {
output out: int

reaction(startup) -> out {=
lf_set(out, self->parent_bank_index * 2 + self->bank_index);
=}
}

reactor Parent(bank_index: int = 0) {
c = new[2] Child(parent_bank_index=bank_index)

reaction(c.out) {=
for (int i=0; i < c_width; i++) {
printf("Received %d from child %d.\n", c[i].out->value, i);
}
=}
}

@platform("Native")
main reactor {
p = new[2] Parent()
}
15 changes: 15 additions & 0 deletions docs/assets/code/uc/src/Contained.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
target uC

import Overwriting from "Overwriting.lf"

@platform("Native")
main reactor {
s = new Overwriting()

reaction(s.y) {=
if (s.y->value != 0 && s.y->value != 1) {
printf("ERROR: Outputs should only be 0 or 1!\n");
exit(1);
}
=}
}
11 changes: 11 additions & 0 deletions docs/assets/code/uc/src/Count.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target uC

reactor Count {
state count: int = 0
output y: int
timer t(0, 100 msec)

reaction(t) -> y {=
lf_set(y, self->count++);
=}
}
25 changes: 25 additions & 0 deletions docs/assets/code/uc/src/Cycle.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
target uC;
reactor A {
input x:int;
output y:int;
reaction(x) -> y {=
// ... something here ...
=}
}
reactor B {
input x:int;
output y:int;
reaction(x) {=
// ... something here ...
=}
reaction(startup) -> y {=
// ... something here ...
=}
}
@platform("Native")
main reactor {
a = new A();
b = new B();
a.y -> b.x;
b.y -> a.x;
}
24 changes: 24 additions & 0 deletions docs/assets/code/uc/src/CycleReordered.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target uC;
reactor A {
input x:int;
output y:int;
reaction(x) -> y {=
// ... something here ...
=}
}
reactor B {
input x:int;
output y:int;
reaction(startup) -> y {=
// ... something here ...
=}
reaction(x) {=
// ... something here ...
=}
}
main reactor {
a = new A();
b = new B();
a.y -> b.x;
b.y -> a.x;
}
25 changes: 25 additions & 0 deletions docs/assets/code/uc/src/CycleWithDelay.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
target uC;
reactor A {
input x:int;
output y:int;
reaction(x) -> y {=
// ... something here ...
=}
}
reactor B {
input x:int;
output y:int;
reaction(x) {=
// ... something here ...
=}
reaction(startup) -> y {=
// ... something here ...
=}
}
@platform("Native")
main reactor {
a = new A();
b = new B();
a.y -> b.x after 0;
b.y -> a.x;
}
13 changes: 13 additions & 0 deletions docs/assets/code/uc/src/Deadline.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
target uC;

@platform("Native")
reactor Deadline {
input x:int;
output d:int; // Produced if the deadline is violated.
reaction(x) -> d {=
printf("Normal reaction.\n");
=} deadline(10 msec) {=
printf("Deadline violation detected.\n");
lf_set(d, x->value);
=}
}
28 changes: 28 additions & 0 deletions docs/assets/code/uc/src/DeadlineTest.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
target uC

import Deadline from "Deadline.lf"

preamble {=
// For lf_sleep(), a reactor-c function.
#include "reactor-uc/reactor-c.h"
=}

@platform("Native")
main reactor {
logical action a
d = new Deadline()

reaction(startup) -> d.x, a {=
lf_set(d.x, 0);
lf_schedule(a, 0);
=}

reaction(a) -> d.x {=
lf_set(d.x, 0);
lf_sleep(MSEC(20));
=}

reaction(d.d) {=
printf("Deadline reactor produced an output.\n");
=}
}
12 changes: 12 additions & 0 deletions docs/assets/code/uc/src/Decentralized.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
target uC

import Count, Print from "Federated.lf"

@timeout(5sec)
@platform("native")
federated reactor {
c = new Count();
@maxwait(10 ms)
p = new Print();
c.out -> p.in;
}
Loading
Loading