aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorIan McIntyre <ianpmcintyre@gmail.com>2022-08-02 06:21:12 -0400
committerIan McIntyre <ianpmcintyre@gmail.com>2022-12-01 20:21:05 -0500
commitc7a9b9f3d4b9e71303c7b988d2bd916c2e4df9bc (patch)
tree6d41ea7e433cac328fa165d45d1bc0cd71a1bf8f /examples
First commit
Diffstat (limited to 'examples')
-rw-r--r--examples/blink-blocking.rs18
-rw-r--r--examples/blink-rtic.rs42
2 files changed, 60 insertions, 0 deletions
diff --git a/examples/blink-blocking.rs b/examples/blink-blocking.rs
new file mode 100644
index 0000000..a3a71b9
--- /dev/null
+++ b/examples/blink-blocking.rs
@@ -0,0 +1,18 @@
+//! Slowly blink an LED while blocking on a timer.
+//!
+//! Use this as the minimum-viable runtime support. You don't
+//! need interrupts for this example.
+
+#![no_std]
+#![no_main]
+
+const PIT_PERIOD_US: u32 = 1_000_000;
+
+#[imxrt_rt::entry]
+fn main() -> ! {
+ let board::Resources { mut pit, led, .. } = board::prepare(PIT_PERIOD_US).unwrap();
+ loop {
+ led.toggle();
+ pit.blocking_delay();
+ }
+}
diff --git a/examples/blink-rtic.rs b/examples/blink-rtic.rs
new file mode 100644
index 0000000..04446e3
--- /dev/null
+++ b/examples/blink-rtic.rs
@@ -0,0 +1,42 @@
+//! Slowly blink an LED when a timer interrupt fires.
+//!
+//! This example is a little more complex, and shows that the
+//! vector table is placed and known to the processor.
+
+#![no_std]
+#![no_main]
+
+use imxrt_rt as _;
+
+/// A static that forces this binary to include a .data section.
+/// This is checked in an automated test.
+static mut DATA: u32 = 5;
+
+#[rtic::app(device = board::rtic_support, peripherals = false)]
+mod app {
+ const PIT_PERIOD_US: u32 = 1_000_000;
+
+ #[local]
+ struct Local {
+ led: board::Led,
+ pit: board::Pit,
+ }
+
+ #[shared]
+ struct Shared {}
+
+ #[init]
+ fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
+ let board::Resources { mut pit, led, .. } = board::prepare(PIT_PERIOD_US).unwrap();
+ pit.loop_with_interrupts();
+ led.set();
+ (Shared {}, Local { led, pit }, init::Monotonics())
+ }
+
+ #[task(binds = PIT, local = [led, pit])]
+ fn pit(cx: pit::Context) {
+ unsafe { crate::DATA += 1 };
+ cx.local.led.toggle();
+ cx.local.pit.clear_interrupts();
+ }
+}