aboutsummaryrefslogtreecommitdiff
path: root/mc/examples
diff options
context:
space:
mode:
Diffstat (limited to 'mc/examples')
-rw-r--r--mc/examples/smallest.rs7
-rw-r--r--mc/examples/x-init-2.rs39
-rw-r--r--mc/examples/x-init.rs26
-rw-r--r--mc/examples/x-schedule.rs36
-rw-r--r--mc/examples/x-spawn.rs20
5 files changed, 128 insertions, 0 deletions
diff --git a/mc/examples/smallest.rs b/mc/examples/smallest.rs
new file mode 100644
index 00000000..792935a8
--- /dev/null
+++ b/mc/examples/smallest.rs
@@ -0,0 +1,7 @@
+#![no_main]
+#![no_std]
+
+use panic_halt as _;
+
+#[rtfm::app(cores = 2, device = mc)]
+const APP: () = {};
diff --git a/mc/examples/x-init-2.rs b/mc/examples/x-init-2.rs
new file mode 100644
index 00000000..ff48b110
--- /dev/null
+++ b/mc/examples/x-init-2.rs
@@ -0,0 +1,39 @@
+//! [compile-pass] Cross initialization of late resources
+
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use panic_halt as _;
+
+#[rtfm::app(cores = 2, device = mc)]
+const APP: () = {
+ extern "C" {
+ // owned by core #1 but initialized by core #0
+ static mut X: u32;
+
+ // owned by core #0 but initialized by core #1
+ static mut Y: u32;
+ }
+
+ #[init(core = 0, late = [X])]
+ fn a(_: a::Context) -> a::LateResources {
+ a::LateResources { X: 0 }
+ }
+
+ #[idle(core = 0, resources = [Y])]
+ fn b(_: b::Context) -> ! {
+ loop {}
+ }
+
+ #[init(core = 1)]
+ fn c(_: c::Context) -> c::LateResources {
+ c::LateResources { Y: 0 }
+ }
+
+ #[idle(core = 1, resources = [X])]
+ fn d(_: d::Context) -> ! {
+ loop {}
+ }
+};
diff --git a/mc/examples/x-init.rs b/mc/examples/x-init.rs
new file mode 100644
index 00000000..3f26c5c9
--- /dev/null
+++ b/mc/examples/x-init.rs
@@ -0,0 +1,26 @@
+//! [compile-pass] Split initialization of late resources
+
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use panic_halt as _;
+
+#[rtfm::app(cores = 2, device = mc)]
+const APP: () = {
+ extern "C" {
+ static mut X: u32;
+ static mut Y: u32;
+ }
+
+ #[init(core = 0, late = [X])]
+ fn a(_: a::Context) -> a::LateResources {
+ a::LateResources { X: 0 }
+ }
+
+ #[init(core = 1)]
+ fn b(_: b::Context) -> b::LateResources {
+ b::LateResources { Y: 0 }
+ }
+};
diff --git a/mc/examples/x-schedule.rs b/mc/examples/x-schedule.rs
new file mode 100644
index 00000000..76e70acf
--- /dev/null
+++ b/mc/examples/x-schedule.rs
@@ -0,0 +1,36 @@
+#![no_main]
+#![no_std]
+
+use panic_halt as _;
+
+#[rtfm::app(cores = 2, device = mc, monotonic = mc::MT)]
+const APP: () = {
+ #[init(core = 0, spawn = [ping])]
+ fn init(c: init::Context) {
+ c.spawn.ping().ok();
+ }
+
+ #[task(core = 0, schedule = [ping])]
+ fn pong(c: pong::Context) {
+ c.schedule.ping(c.scheduled + 1_000_000).ok();
+ }
+
+ #[task(core = 1, schedule = [pong])]
+ fn ping(c: ping::Context) {
+ c.schedule.pong(c.scheduled + 1_000_000).ok();
+ }
+
+ extern "C" {
+ #[core = 0]
+ fn I0();
+
+ #[core = 0]
+ fn I1();
+
+ #[core = 1]
+ fn I0();
+
+ #[core = 1]
+ fn I1();
+ }
+};
diff --git a/mc/examples/x-spawn.rs b/mc/examples/x-spawn.rs
new file mode 100644
index 00000000..749918fd
--- /dev/null
+++ b/mc/examples/x-spawn.rs
@@ -0,0 +1,20 @@
+#![no_main]
+#![no_std]
+
+use panic_halt as _;
+
+#[rtfm::app(cores = 2, device = mc)]
+const APP: () = {
+ #[init(core = 0, spawn = [foo])]
+ fn init(c: init::Context) {
+ c.spawn.foo().ok();
+ }
+
+ #[task(core = 1)]
+ fn foo(_: foo::Context) {}
+
+ extern "C" {
+ #[core = 1]
+ fn I0();
+ }
+};