mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
more examples updated
This commit is contained in:
parent
ff0c6a8d01
commit
50581ea1fe
4 changed files with 160 additions and 1 deletions
61
examples/hardware.rs
Normal file
61
examples/hardware.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
//! examples/hardware.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965)]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
|
||||
#[resources]
|
||||
struct Resources {
|
||||
#[task_local]
|
||||
#[init(0)]
|
||||
times: u32,
|
||||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
||||
// Pends the UART0 interrupt but its handler won't run until *after*
|
||||
// `init` returns because interrupts are disabled
|
||||
rtic::pend(Interrupt::UART0); // equivalent to NVIC::pend
|
||||
|
||||
hprintln!("init").unwrap();
|
||||
|
||||
(init::LateResources {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
// interrupts are enabled again; the `UART0` handler runs at this point
|
||||
|
||||
hprintln!("idle").unwrap();
|
||||
|
||||
rtic::pend(Interrupt::UART0);
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
|
||||
#[task(binds = UART0, resources = [times])]
|
||||
fn uart0(cx: uart0::Context) {
|
||||
let times = cx.resources.times;
|
||||
// Safe access to local `static mut` variable
|
||||
*times += 1;
|
||||
|
||||
hprintln!(
|
||||
"UART0 called {} time{}",
|
||||
*times,
|
||||
if *times > 1 { "s" } else { "" }
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
//! examples/late.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
// #![deny(warnings)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
|
|
55
examples/message.rs
Normal file
55
examples/message.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
//! examples/message.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
|
||||
#[resources]
|
||||
struct Resources {
|
||||
#[task_local]
|
||||
#[init(0)]
|
||||
times: u32,
|
||||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
||||
foo::spawn(/* no message */).unwrap();
|
||||
|
||||
(init::LateResources {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(resources = [times])]
|
||||
fn foo(cx: foo::Context) {
|
||||
let times = cx.resources.times;
|
||||
|
||||
hprintln!("foo").unwrap();
|
||||
|
||||
bar::spawn(*times).unwrap();
|
||||
*times += 1;
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn bar(_: bar::Context, x: u32) {
|
||||
hprintln!("bar({})", x).unwrap();
|
||||
|
||||
baz::spawn(x + 1, x + 2).unwrap();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn baz(_: baz::Context, x: u32, y: u32) {
|
||||
hprintln!("baz({}, {})", x, y).unwrap();
|
||||
|
||||
if x + y > 4 {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
foo::spawn().unwrap();
|
||||
}
|
||||
}
|
43
examples/not-sync.rs
Normal file
43
examples/not-sync.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
//! `examples/not-sync.rs`
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use core::marker::PhantomData;
|
||||
use panic_semihosting as _;
|
||||
|
||||
pub struct NotSync {
|
||||
_0: PhantomData<*const ()>,
|
||||
}
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||
mod app {
|
||||
use super::NotSync;
|
||||
use core::marker::PhantomData;
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[resources]
|
||||
struct Resources {
|
||||
#[init(NotSync { _0: PhantomData })]
|
||||
shared: NotSync,
|
||||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
(init::LateResources {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(resources = [&shared])]
|
||||
fn foo(c: foo::Context) {
|
||||
let _: &NotSync = c.resources.shared;
|
||||
}
|
||||
|
||||
#[task(resources = [&shared])]
|
||||
fn bar(c: bar::Context) {
|
||||
let _: &NotSync = c.resources.shared;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue