From 81275bfa4f41e2066770087f3a33cad4227eab41 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 13 Jun 2019 23:56:59 +0200 Subject: rtfm-syntax refactor + heterogeneous multi-core support --- examples/generics.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'examples/generics.rs') diff --git a/examples/generics.rs b/examples/generics.rs index e624da3..a35ba23 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -5,11 +5,10 @@ #![no_main] #![no_std] -extern crate panic_semihosting; - use cortex_m_semihosting::{debug, hprintln}; use lm3s6965::Interrupt; -use rtfm::Mutex; +use panic_semihosting as _; +use rtfm::{Exclusive, Mutex}; #[rtfm::app(device = lm3s6965)] const APP: () = { @@ -35,17 +34,15 @@ const APP: () = { } #[interrupt(priority = 2, resources = [SHARED])] - fn UART1(mut c: UART1::Context) { + fn UART1(c: UART1::Context) { static mut STATE: u32 = 0; hprintln!("UART1(STATE = {})", *STATE).unwrap(); - // just to show that `SHARED` can be accessed directly and .. + // just to show that `SHARED` can be accessed directly *c.resources.SHARED += 0; - // .. also through a (no-op) `lock` - c.resources.SHARED.lock(|shared| *shared += 0); - advance(STATE, c.resources.SHARED); + advance(STATE, Exclusive(c.resources.SHARED)); } }; -- cgit v1.2.3 From 4e51bb68b976c6bb6a9a989dc560d2a8123a84ca Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 20 Jun 2019 06:19:59 +0200 Subject: RFC #207 --- examples/generics.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'examples/generics.rs') diff --git a/examples/generics.rs b/examples/generics.rs index a35ba23..562470d 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -20,8 +20,8 @@ const APP: () = { rtfm::pend(Interrupt::UART1); } - #[interrupt(resources = [SHARED])] - fn UART0(c: UART0::Context) { + #[task(binds = UART0, resources = [SHARED])] + fn uart0(c: uart0::Context) { static mut STATE: u32 = 0; hprintln!("UART0(STATE = {})", *STATE).unwrap(); @@ -33,8 +33,8 @@ const APP: () = { debug::exit(debug::EXIT_SUCCESS); } - #[interrupt(priority = 2, resources = [SHARED])] - fn UART1(c: UART1::Context) { + #[task(binds = UART1, priority = 2, resources = [SHARED])] + fn uart1(c: uart1::Context) { static mut STATE: u32 = 0; hprintln!("UART1(STATE = {})", *STATE).unwrap(); -- cgit v1.2.3 From 9195038c87703fc94b6e99f6de593886d51c2b19 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 10 Jul 2019 22:42:44 +0200 Subject: implement RFC #212 --- examples/generics.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'examples/generics.rs') diff --git a/examples/generics.rs b/examples/generics.rs index 562470d..f0632d9 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -12,7 +12,10 @@ use rtfm::{Exclusive, Mutex}; #[rtfm::app(device = lm3s6965)] const APP: () = { - static mut SHARED: u32 = 0; + struct Resources { + #[init(0)] + shared: u32, + } #[init] fn init(_: init::Context) { @@ -20,29 +23,29 @@ const APP: () = { rtfm::pend(Interrupt::UART1); } - #[task(binds = UART0, resources = [SHARED])] + #[task(binds = UART0, resources = [shared])] fn uart0(c: uart0::Context) { static mut STATE: u32 = 0; hprintln!("UART0(STATE = {})", *STATE).unwrap(); - advance(STATE, c.resources.SHARED); + advance(STATE, c.resources.shared); rtfm::pend(Interrupt::UART1); debug::exit(debug::EXIT_SUCCESS); } - #[task(binds = UART1, priority = 2, resources = [SHARED])] + #[task(binds = UART1, priority = 2, resources = [shared])] fn uart1(c: uart1::Context) { static mut STATE: u32 = 0; hprintln!("UART1(STATE = {})", *STATE).unwrap(); - // just to show that `SHARED` can be accessed directly - *c.resources.SHARED += 0; + // just to show that `shared` can be accessed directly + *c.resources.shared += 0; - advance(STATE, Exclusive(c.resources.SHARED)); + advance(STATE, Exclusive(c.resources.shared)); } }; @@ -55,5 +58,5 @@ fn advance(state: &mut u32, mut shared: impl Mutex) { (old, *shared) }); - hprintln!("SHARED: {} -> {}", old, new).unwrap(); + hprintln!("shared: {} -> {}", old, new).unwrap(); } -- cgit v1.2.3 From 07b2b4d83078d0fd260d5f0812e8d5a34d02b793 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 21 Aug 2019 10:17:27 +0200 Subject: doc up --- examples/generics.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'examples/generics.rs') diff --git a/examples/generics.rs b/examples/generics.rs index f0632d9..eafc630 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -29,6 +29,7 @@ const APP: () = { hprintln!("UART0(STATE = {})", *STATE).unwrap(); + // second argument has type `resources::shared` advance(STATE, c.resources.shared); rtfm::pend(Interrupt::UART1); @@ -45,14 +46,16 @@ const APP: () = { // just to show that `shared` can be accessed directly *c.resources.shared += 0; + // second argument has type `Exclusive` advance(STATE, Exclusive(c.resources.shared)); } }; +// the second parameter is generic: it can be any type that implements the `Mutex` trait fn advance(state: &mut u32, mut shared: impl Mutex) { *state += 1; - let (old, new) = shared.lock(|shared| { + let (old, new) = shared.lock(|shared: &mut u32| { let old = *shared; *shared += *state; (old, *shared) -- cgit v1.2.3