From 245f4f9b6e32006e0be8f4751aaf10efd3a68d26 Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Sat, 13 Jun 2020 02:02:42 +0200 Subject: [PATCH] wip4, benchmark --- examples/lock2.rs | 2 +- examples/lock2_minimal.rs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 examples/lock2_minimal.rs diff --git a/examples/lock2.rs b/examples/lock2.rs index 809d4dcc66..b505bf3b9f 100644 --- a/examples/lock2.rs +++ b/examples/lock2.rs @@ -25,7 +25,7 @@ const APP: () = { // when omitted priority is assumed to be `1` #[task(binds = GPIOA, resources = [shared, shared2])] - fn gpioa(mut c: gpioa::Context) { + fn gpioa(c: gpioa::Context) { c.resources.shared.lock(|shared| { *shared += 1; rtic::pend(Interrupt::GPIOB); diff --git a/examples/lock2_minimal.rs b/examples/lock2_minimal.rs new file mode 100644 index 0000000000..c1c6cccf81 --- /dev/null +++ b/examples/lock2_minimal.rs @@ -0,0 +1,39 @@ +//! examples/lock2.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::debug; +use lm3s6965::Interrupt; +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965)] +const APP: () = { + struct Resources { + #[init(0)] + shared: u32, + #[init(0)] + shared2: u32, + } + + #[init] + fn init(_: init::Context) { + rtic::pend(Interrupt::GPIOA); + debug::exit(debug::EXIT_SUCCESS); + } + + // when omitted priority is assumed to be `1` + #[task(binds = GPIOA, resources = [shared, shared2])] + fn gpioa(c: gpioa::Context) { + c.resources.shared.lock(|shared| { + *shared += 1; + }); + } + + #[task(binds = GPIOB, priority = 2, resources = [shared, shared2])] + fn gpiob(c: gpiob::Context) { + *c.resources.shared += 1; + } +};