rtic/examples/resource.rs

81 lines
2 KiB
Rust
Raw Normal View History

2018-11-03 17:02:41 +01:00
//! examples/resource.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_semihosting as _;
2018-11-03 17:02:41 +01:00
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::{debug, hprintln};
use lm3s6965::Interrupt;
2021-07-07 22:50:59 +02:00
#[shared]
struct Shared {}
2018-11-03 17:02:41 +01:00
2021-07-07 22:50:59 +02:00
#[local]
struct Local {
local_to_uart0: i64,
local_to_uart1: i64,
}
2021-07-07 22:50:59 +02:00
2018-11-03 17:02:41 +01:00
#[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
(
Shared {},
Local {
local_to_uart0: 0,
local_to_uart1: 0,
},
init::Monotonics(),
)
2018-11-03 17:02:41 +01:00
}
// `#[local]` resources cannot be accessed from this context
2018-11-03 17:02:41 +01:00
#[idle]
2019-08-21 10:17:27 +02:00
fn idle(_cx: idle::Context) -> ! {
2018-11-03 17:02:41 +01:00
debug::exit(debug::EXIT_SUCCESS);
// error: no `local` field in `idle::Context`
// _cx.local.local_to_uart0 += 1;
// error: no `local` field in `idle::Context`
// _cx.local.local_to_uart1 += 1;
2018-11-03 17:02:41 +01:00
loop {
cortex_m::asm::nop();
}
2018-11-03 17:02:41 +01:00
}
// `local_to_uart0` can only be accessed from this context
2020-11-12 18:55:11 +01:00
// defaults to priority 1
#[task(binds = UART0, local = [local_to_uart0])]
fn uart0(cx: uart0::Context) {
*cx.local.local_to_uart0 += 1;
let local_to_uart0 = cx.local.local_to_uart0;
// error: no `local_to_uart1` field in `uart0::LocalResources`
cx.local.local_to_uart1 += 1;
hprintln!("UART0: local_to_uart0 = {}", local_to_uart0).unwrap();
2018-11-03 17:02:41 +01:00
}
// `shared` can only be accessed from this context
2020-11-12 18:55:11 +01:00
// explicitly set to priority 2
#[task(binds = UART1, local = [local_to_uart1], priority = 2)]
fn uart1(cx: uart1::Context) {
*cx.local.local_to_uart1 += 1;
let local_to_uart1 = cx.local.local_to_uart1;
// error: no `local_to_uart0` field in `uart1::LocalResources`
// cx.local.local_to_uart0 += 1;
hprintln!("UART1: local_to_uart1 = {}", local_to_uart1).unwrap();
2018-11-03 17:02:41 +01:00
}
2020-04-22 12:58:14 +02:00
}