diff --git a/Lingo.toml b/Lingo.toml index 62b1ffa..5d3832b 100644 --- a/Lingo.toml +++ b/Lingo.toml @@ -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" } + diff --git a/src/Blink.lf b/src/Blink.lf index 37d365f..08d2cc5 100644 --- a/src/Blink.lf +++ b/src/Blink.lf @@ -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); =} } diff --git a/src/HelloPico.lf b/src/HelloPico.lf index a8bcf10..33d3c2e 100644 --- a/src/HelloPico.lf +++ b/src/HelloPico.lf @@ -1,7 +1,7 @@ target C { - platform: "Rp2040", + platform: "rp2040", threading: false, - timeout: 5 sec, + build-type: "Debug" } preamble {= diff --git a/src/HelloThread.lf b/src/HelloThread.lf index 8943858..c95493d 100644 --- a/src/HelloThread.lf +++ b/src/HelloThread.lf @@ -1,8 +1,10 @@ target C { - platform: "Rp2040", + platform: "rp2040", threading: true, workers: 2, tracing: false, + //logging: "debug", + build-type: "Debug", } /** @@ -12,26 +14,39 @@ target C { * @author Abhi Gundrala **/ -preamble {= - #include - #include -=} +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(); } diff --git a/src/HelloThreadStatic.lf b/src/HelloThreadStatic.lf new file mode 100644 index 0000000..9a889a5 --- /dev/null +++ b/src/HelloThreadStatic.lf @@ -0,0 +1,67 @@ +target C { + platform: "rp2040", + threading: true, + workers: 2, + tracing: false, + scheduler: STATIC, + //logging: "debug", + build-type: "Debug", +} + +preamble {= + #include + #include +=} + +/** +* 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(); +} diff --git a/src/Timer.lf b/src/Timer.lf index 9c1069f..d0c3d6c 100644 --- a/src/Timer.lf +++ b/src/Timer.lf @@ -1,7 +1,7 @@ target C { - platform: "Rp2040", + platform: "rp2040", threading: false, - timeout: 10 sec, + build-type: "Debug" } preamble {= diff --git a/src/lib/Led.lf b/src/lib/Led.lf index f218988..e58e0fa 100644 --- a/src/lib/Led.lf +++ b/src/lib/Led.lf @@ -1,5 +1,5 @@ target C { - platform: "RP2040", + platform: "rp2040", threading: false, } @@ -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); =} }