aboutsummaryrefslogtreecommitdiff
path: root/examples/lock.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/lock.rs')
-rw-r--r--examples/lock.rs50
1 files changed, 27 insertions, 23 deletions
diff --git a/examples/lock.rs b/examples/lock.rs
index 4ca862e3..669b1aed 100644
--- a/examples/lock.rs
+++ b/examples/lock.rs
@@ -5,38 +5,42 @@
#![no_main]
#![no_std]
-extern crate panic_semihosting;
-
use cortex_m_semihosting::{debug, hprintln};
use lm3s6965::Interrupt;
-use rtfm::app;
-
-#[app(device = lm3s6965)]
-const APP: () = {
- static mut SHARED: u32 = 0;
+use panic_semihosting as _;
+
+#[rtic::app(device = lm3s6965)]
+mod app {
+ #[resources]
+ struct Resources {
+ #[init(0)]
+ shared: u32,
+ }
#[init]
- fn init() {
- rtfm::pend(Interrupt::GPIOA);
+ fn init(_: init::Context) -> init::LateResources {
+ rtic::pend(Interrupt::GPIOA);
+
+ init::LateResources {}
}
// when omitted priority is assumed to be `1`
- #[interrupt(resources = [SHARED])]
- fn GPIOA() {
+ #[task(binds = GPIOA, resources = [shared])]
+ fn gpioa(mut c: gpioa::Context) {
hprintln!("A").unwrap();
// the lower priority task requires a critical section to access the data
- resources.SHARED.lock(|shared| {
+ c.resources.shared.lock(|shared| {
// data can only be modified within this critical section (closure)
*shared += 1;
// GPIOB will *not* run right now due to the critical section
- rtfm::pend(Interrupt::GPIOB);
+ rtic::pend(Interrupt::GPIOB);
- hprintln!("B - SHARED = {}", *shared).unwrap();
+ hprintln!("B - shared = {}", *shared).unwrap();
- // GPIOC does not contend for `SHARED` so it's allowed to run now
- rtfm::pend(Interrupt::GPIOC);
+ // GPIOC does not contend for `shared` so it's allowed to run now
+ rtic::pend(Interrupt::GPIOC);
});
// critical section is over: GPIOB can now start
@@ -46,16 +50,16 @@ const APP: () = {
debug::exit(debug::EXIT_SUCCESS);
}
- #[interrupt(priority = 2, resources = [SHARED])]
- fn GPIOB() {
+ #[task(binds = GPIOB, priority = 2, resources = [shared])]
+ fn gpiob(c: gpiob::Context) {
// the higher priority task does *not* need a critical section
- *resources.SHARED += 1;
+ *c.resources.shared += 1;
- hprintln!("D - SHARED = {}", *resources.SHARED).unwrap();
+ hprintln!("D - shared = {}", *c.resources.shared).unwrap();
}
- #[interrupt(priority = 3)]
- fn GPIOC() {
+ #[task(binds = GPIOC, priority = 3)]
+ fn gpioc(_: gpioc::Context) {
hprintln!("C").unwrap();
}
-};
+}