aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/hardware.rs61
-rw-r--r--examples/late.rs2
-rw-r--r--examples/message.rs55
-rw-r--r--examples/not-sync.rs43
4 files changed, 160 insertions, 1 deletions
diff --git a/examples/hardware.rs b/examples/hardware.rs
new file mode 100644
index 00000000..b8060021
--- /dev/null
+++ b/examples/hardware.rs
@@ -0,0 +1,61 @@
+//! examples/hardware.rs
+
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use panic_semihosting as _;
+
+#[rtic::app(device = lm3s6965)]
+mod app {
+ use cortex_m_semihosting::{debug, hprintln};
+ use lm3s6965::Interrupt;
+
+ #[resources]
+ struct Resources {
+ #[task_local]
+ #[init(0)]
+ times: u32,
+ }
+
+ #[init]
+ fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
+ // Pends the UART0 interrupt but its handler won't run until *after*
+ // `init` returns because interrupts are disabled
+ rtic::pend(Interrupt::UART0); // equivalent to NVIC::pend
+
+ hprintln!("init").unwrap();
+
+ (init::LateResources {}, init::Monotonics())
+ }
+
+ #[idle]
+ fn idle(_: idle::Context) -> ! {
+ // interrupts are enabled again; the `UART0` handler runs at this point
+
+ hprintln!("idle").unwrap();
+
+ rtic::pend(Interrupt::UART0);
+
+ debug::exit(debug::EXIT_SUCCESS);
+
+ loop {
+ cortex_m::asm::nop();
+ }
+ }
+
+ #[task(binds = UART0, resources = [times])]
+ fn uart0(cx: uart0::Context) {
+ let times = cx.resources.times;
+ // Safe access to local `static mut` variable
+ *times += 1;
+
+ hprintln!(
+ "UART0 called {} time{}",
+ *times,
+ if *times > 1 { "s" } else { "" }
+ )
+ .unwrap();
+ }
+}
diff --git a/examples/late.rs b/examples/late.rs
index b53daac8..5c10b66f 100644
--- a/examples/late.rs
+++ b/examples/late.rs
@@ -1,7 +1,7 @@
//! examples/late.rs
#![deny(unsafe_code)]
-// #![deny(warnings)]
+#![deny(warnings)]
#![no_main]
#![no_std]
diff --git a/examples/message.rs b/examples/message.rs
new file mode 100644
index 00000000..871058d8
--- /dev/null
+++ b/examples/message.rs
@@ -0,0 +1,55 @@
+//! examples/message.rs
+
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use panic_semihosting as _;
+
+#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
+mod app {
+ use cortex_m_semihosting::{debug, hprintln};
+
+ #[resources]
+ struct Resources {
+ #[task_local]
+ #[init(0)]
+ times: u32,
+ }
+
+ #[init]
+ fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
+ foo::spawn(/* no message */).unwrap();
+
+ (init::LateResources {}, init::Monotonics())
+ }
+
+ #[task(resources = [times])]
+ fn foo(cx: foo::Context) {
+ let times = cx.resources.times;
+
+ hprintln!("foo").unwrap();
+
+ bar::spawn(*times).unwrap();
+ *times += 1;
+ }
+
+ #[task]
+ fn bar(_: bar::Context, x: u32) {
+ hprintln!("bar({})", x).unwrap();
+
+ baz::spawn(x + 1, x + 2).unwrap();
+ }
+
+ #[task]
+ fn baz(_: baz::Context, x: u32, y: u32) {
+ hprintln!("baz({}, {})", x, y).unwrap();
+
+ if x + y > 4 {
+ debug::exit(debug::EXIT_SUCCESS);
+ }
+
+ foo::spawn().unwrap();
+ }
+}
diff --git a/examples/not-sync.rs b/examples/not-sync.rs
new file mode 100644
index 00000000..f01d4043
--- /dev/null
+++ b/examples/not-sync.rs
@@ -0,0 +1,43 @@
+//! `examples/not-sync.rs`
+
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use core::marker::PhantomData;
+use panic_semihosting as _;
+
+pub struct NotSync {
+ _0: PhantomData<*const ()>,
+}
+
+#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
+mod app {
+ use super::NotSync;
+ use core::marker::PhantomData;
+ use cortex_m_semihosting::debug;
+
+ #[resources]
+ struct Resources {
+ #[init(NotSync { _0: PhantomData })]
+ shared: NotSync,
+ }
+
+ #[init]
+ fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
+ debug::exit(debug::EXIT_SUCCESS);
+
+ (init::LateResources {}, init::Monotonics())
+ }
+
+ #[task(resources = [&shared])]
+ fn foo(c: foo::Context) {
+ let _: &NotSync = c.resources.shared;
+ }
+
+ #[task(resources = [&shared])]
+ fn bar(c: bar::Context) {
+ let _: &NotSync = c.resources.shared;
+ }
+}