rtic/examples/destructure.rs

52 lines
1.1 KiB
Rust
Raw Normal View History

//! examples/destructure.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_semihosting as _;
2020-06-11 19:18:29 +02:00
#[rtic::app(device = lm3s6965)]
2020-05-19 20:00:13 +02:00
mod app {
2020-10-15 18:50:17 +02:00
use cortex_m_semihosting::hprintln;
use lm3s6965::Interrupt;
2021-07-07 22:50:59 +02:00
#[shared]
struct Shared {
// Some resources to work with
a: u32,
b: u32,
c: u32,
}
2021-07-07 22:50:59 +02:00
#[local]
struct Local {}
#[init]
2021-07-07 22:50:59 +02:00
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
2020-06-11 19:18:29 +02:00
rtic::pend(Interrupt::UART0);
rtic::pend(Interrupt::UART1);
2020-10-01 19:38:49 +02:00
2021-07-07 22:50:59 +02:00
(Shared { a: 0, b: 0, c: 0 }, Local {}, init::Monotonics())
}
// Direct destructure
2021-07-07 22:50:59 +02:00
#[task(binds = UART0, shared = [&a, &b, &c])]
fn uart0(cx: uart0::Context) {
2021-07-07 22:50:59 +02:00
let a = cx.shared.a;
let b = cx.shared.b;
let c = cx.shared.c;
hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap();
}
// De-structure-ing syntax
2021-07-07 22:50:59 +02:00
#[task(binds = UART1, shared = [&a, &b, &c])]
fn uart1(cx: uart1::Context) {
2021-07-07 22:50:59 +02:00
let uart1::SharedResources { a, b, c } = cx.shared;
hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap();
}
2020-04-22 12:58:14 +02:00
}