From 6eafcf10e944fb5875c086631dde7fad6f0a7b3b Mon Sep 17 00:00:00 2001 From: Per Date: Wed, 4 Mar 2020 15:06:03 +0100 Subject: task_local and lock_free analysis (take 1) --- examples/static.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 examples/static.rs (limited to 'examples/static.rs') diff --git a/examples/static.rs b/examples/static.rs new file mode 100644 index 0000000..ddcb11e --- /dev/null +++ b/examples/static.rs @@ -0,0 +1,54 @@ +//! examples/late.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::{debug, hprintln}; +use heapless::{ + consts::*, + i, + spsc::{Consumer, Producer, Queue}, +}; +use lm3s6965::Interrupt; +use panic_semihosting as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + // Late resources + struct Resources { + p: Producer<'static, u32, U4>, + c: Consumer<'static, u32, U4>, + } + + #[init] + fn init(_: init::Context) -> init::LateResources { + static mut Q: Queue = Queue(i::Queue::new()); + + let (p, c) = Q.split(); + + // Initialization of late resources + init::LateResources { p, c } + } + + #[idle(resources = [c])] + fn idle(c: idle::Context) -> ! { + loop { + if let Some(byte) = c.resources.c.dequeue() { + hprintln!("received message: {}", byte).unwrap(); + + debug::exit(debug::EXIT_SUCCESS); + } else { + rtfm::pend(Interrupt::UART0); + } + } + } + + #[task(binds = UART0, resources = [p])] + fn uart0(c: uart0::Context) { + static mut KALLE: u32 = 0; + *KALLE += 1; + c.resources.p.enqueue(42).unwrap(); + } +}; -- cgit v1.2.3 From e2364aae3eebf3326534bd4818d0312a03817538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 8 Sep 2020 17:51:10 +0000 Subject: Updated examples and rtic-name --- examples/static.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'examples/static.rs') diff --git a/examples/static.rs b/examples/static.rs index ddcb11e..9c3110c 100644 --- a/examples/static.rs +++ b/examples/static.rs @@ -1,4 +1,4 @@ -//! examples/late.rs +//! examples/static.rs #![deny(unsafe_code)] #![deny(warnings)] @@ -14,9 +14,14 @@ use heapless::{ use lm3s6965::Interrupt; use panic_semihosting as _; -#[rtfm::app(device = lm3s6965)] -const APP: () = { +#[rtic::app(device = lm3s6965)] +mod app { + + use crate::U4; + use crate::{Consumer, Producer}; + // Late resources + #[resources] struct Resources { p: Producer<'static, u32, U4>, c: Consumer<'static, u32, U4>, @@ -40,7 +45,7 @@ const APP: () = { debug::exit(debug::EXIT_SUCCESS); } else { - rtfm::pend(Interrupt::UART0); + rtic::pend(Interrupt::UART0); } } } @@ -51,4 +56,4 @@ const APP: () = { *KALLE += 1; c.resources.p.enqueue(42).unwrap(); } -}; +} -- cgit v1.2.3