Skip to content
Draft
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
24 changes: 24 additions & 0 deletions Lingo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,27 @@ dependencies = {}
[app.properties]
# platform = { name = "RP2040", board = "pico:usb" }

# HelloThread
# Periodically print from either core using two workers
[[app]]
name = "HelloThread"
target = "C"
platform = "RP2040"
main_reactor = "src/HelloThread.lf"
dependencies = {}

[app.properties]
# platform = { name = "RP2040", board = "pico:usb" }

# HelloThreadStatic
# Periodically print from either core using two workers
[[app]]
name = "HelloThreadStatic"
target = "C"
platform = "RP2040"
main_reactor = "src/HelloThreadStatic.lf"
dependencies = {}

[app.properties]
# platform = { name = "RP2040", board = "pico:usb" }

15 changes: 10 additions & 5 deletions src/Blink.lf
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
target C {
platform: "Rp2040",
threading: false
platform: "rp2040",
threading: false,
build-type: "Debug"
}

import Led from "./lib/Led.lf";

main reactor {
timer t1(0, 100 msec);
led = new Led();
reaction(t1) -> led.tog {=
lf_set(led.tog, true);
red_led = new Led(pin=21);
yellow_led = new Led(pin=20);
green_led = new Led(pin=19);
reaction(t1) -> red_led.tog, yellow_led.tog, green_led.tog {=
lf_set(red_led.tog, true);
lf_set(yellow_led.tog, true);
lf_set(green_led.tog, true);
=}
}
4 changes: 2 additions & 2 deletions src/HelloPico.lf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
target C {
platform: "Rp2040",
platform: "rp2040",
threading: false,
timeout: 5 sec,
build-type: "Debug"
}

preamble {=
Expand Down
49 changes: 32 additions & 17 deletions src/HelloThread.lf
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
target C {
platform: "Rp2040",
platform: "rp2040",
threading: true,
workers: 2,
tracing: false,
//logging: "debug",
build-type: "Debug",
}

/**
Expand All @@ -12,26 +14,39 @@ target C {
* @author Abhi Gundrala
**/

preamble {=
#include <pico/stdlib.h>
#include <stdio.h>
=}
import Led from "./lib/Led.lf";

reactor Hello {
input trig:bool;
reaction(trig) {=
printf("Hello, from core %d",
get_core_num());
reactor GroupOne {
timer t0(0, 200 msec);

green_led = new Led(pin=19);

reaction(t0) -> green_led.tog {=
// toggle led
lf_set(green_led.tog, true);
// print core number
printf("core %d\n",
get_core_num());
=}
}

main reactor {
timer t1(0, 100 msec);
hell0 = new Hello();
hell1 = new Hello();
reaction(t1) -> hell0.trig, hell1.trig {=
lf_set(hell0.trig, true);
lf_set(hell1.trig, true);
reactor GroupTwo {
timer t1(0, 300 msec);

red_led = new Led(pin=21);
yellow_led = new Led(pin=20);

reaction(t1) -> yellow_led.tog, red_led.tog {=
// toggle leds
lf_set(red_led.tog, true);
lf_set(yellow_led.tog, true);
// print core number
printf("core %d\n",
get_core_num());
=}
}

main reactor {
g1 = new GroupOne();
g2 = new GroupTwo();
}
67 changes: 67 additions & 0 deletions src/HelloThreadStatic.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
target C {
platform: "rp2040",
threading: true,
workers: 2,
tracing: false,
scheduler: STATIC,
//logging: "debug",
build-type: "Debug",
}

preamble {=
#include <pico/stdlib.h>
#include <hardware/gpio.h>
=}

/**
* Multicore test that attempts to concurrently
* print from both cores using parallel reactors
*
* @author Abhi Gundrala
**/

reactor GroupOne {
timer t0(0, 200 msec);
state led:bool;

reaction(startup) {=
gpio_init(19);
gpio_set_dir(19, GPIO_OUT);
=}

reaction(t0) {=
self->led = !self->led;
gpio_put(19, self->led);
// print core number
printf("core %d\n",
get_core_num());
=}
}

reactor GroupTwo {
timer t1(0, 300 msec);
state rled:bool;
state yled:bool;

reaction(startup) {=
gpio_init(21);
gpio_set_dir(21, GPIO_OUT);
gpio_init(20);
gpio_set_dir(20, GPIO_OUT);
=}

reaction(t1) {=
self->rled = !self->rled;
gpio_put(21, self->rled);
self->yled = !self->yled;
gpio_put(20, self->yled);
// print core number
printf("core %d\n",
get_core_num());
=}
}

main reactor {
g1 = new GroupOne();
g2 = new GroupTwo();
}
4 changes: 2 additions & 2 deletions src/Timer.lf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
target C {
platform: "Rp2040",
platform: "rp2040",
threading: false,
timeout: 10 sec,
build-type: "Debug"
}

preamble {=
Expand Down
12 changes: 6 additions & 6 deletions src/lib/Led.lf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
target C {
platform: "RP2040",
platform: "rp2040",
threading: false,
}

Expand All @@ -12,23 +12,23 @@ preamble {=
* Led reactor that keeps track of led state.
* Can either be toggled or set using different signals
**/
reactor Led {
reactor Led(pin: uint = 25) {
input tog:bool; // when is_present, will toggle the led
input set:bool; // when is_present, set the led state to the input value
state led:bool;

reaction(startup) {=
gpio_init(25);
gpio_set_dir(25, GPIO_OUT);
gpio_init(self->pin);
gpio_set_dir(self->pin, GPIO_OUT);
=}

reaction(tog) {=
self->led = !self->led;
gpio_put(25, self->led);
gpio_put(self->pin, self->led);
=}

reaction(set) {=
self->led = set->value;
gpio_put(25, self->led);
gpio_put(self->pin, self->led);
=}
}