2019-11-07 14:12:16 +01:00
|
|
|
//! 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;
|
|
|
|
|
2020-06-04 17:24:21 +02:00
|
|
|
#[resources]
|
2019-11-07 14:12:16 +01:00
|
|
|
struct Resources {
|
|
|
|
// Some resources to work with
|
|
|
|
#[init(0)]
|
|
|
|
a: u32,
|
|
|
|
#[init(0)]
|
|
|
|
b: u32,
|
|
|
|
#[init(0)]
|
|
|
|
c: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[init]
|
2020-10-01 19:38:49 +02:00
|
|
|
fn init(_: init::Context) -> init::LateResources {
|
2020-06-11 19:18:29 +02:00
|
|
|
rtic::pend(Interrupt::UART0);
|
|
|
|
rtic::pend(Interrupt::UART1);
|
2020-10-01 19:38:49 +02:00
|
|
|
|
|
|
|
init::LateResources {}
|
2019-11-07 14:12:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Direct destructure
|
2020-10-22 21:36:32 +02:00
|
|
|
#[task(binds = UART0, resources = [&a, &b, &c])]
|
2019-11-07 14:12:16 +01:00
|
|
|
fn uart0(cx: uart0::Context) {
|
|
|
|
let a = cx.resources.a;
|
|
|
|
let b = cx.resources.b;
|
|
|
|
let c = cx.resources.c;
|
|
|
|
|
|
|
|
hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
// De-structure-ing syntax
|
2020-10-22 21:36:32 +02:00
|
|
|
#[task(binds = UART1, resources = [&a, &b, &c])]
|
2019-11-07 14:12:16 +01:00
|
|
|
fn uart1(cx: uart1::Context) {
|
|
|
|
let uart1::Resources { a, b, c } = cx.resources;
|
|
|
|
|
|
|
|
hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
|
|
|
}
|
2020-04-22 12:58:14 +02:00
|
|
|
}
|