mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-12-24 19:09:33 +01:00
added working examples
This commit is contained in:
parent
abd917ceff
commit
d4d5713e5a
9 changed files with 141 additions and 5 deletions
|
@ -1,4 +1,4 @@
|
|||
//! examples/idle.rs
|
||||
//! examples/minimal-early-resource.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
|
@ -9,6 +9,7 @@ use panic_semihosting as _;
|
|||
|
||||
#[rtic::app(device = lm3s6965)]
|
||||
mod app {
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[resources]
|
||||
struct Resources {
|
||||
|
@ -18,6 +19,7 @@ mod app {
|
|||
|
||||
#[idle(resources = [resource_x])]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
//! examples/minimal_late_resource.rs
|
||||
//! examples/minimal-late-resource.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
|
@ -9,6 +9,7 @@ use panic_semihosting as _;
|
|||
|
||||
#[rtic::app(device = lm3s6965)]
|
||||
mod app {
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[resources]
|
||||
struct Resources {
|
||||
|
@ -22,6 +23,7 @@ mod app {
|
|||
|
||||
#[idle(resources = [resource_x])]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
//! examples/minmal-task-local-early.rs
|
||||
//! examples/minimal-task-local-early.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
|
@ -12,7 +13,7 @@ mod app {
|
|||
|
||||
#[resources]
|
||||
struct Resources {
|
||||
// A local (move), late resource
|
||||
// A local (move), early resource
|
||||
#[task_local]
|
||||
#[init(42)]
|
||||
early: u32,
|
||||
|
@ -26,7 +27,7 @@ mod app {
|
|||
// task_local is task_local
|
||||
#[idle(resources = [early])]
|
||||
fn idle(cx: idle::Context) -> ! {
|
||||
hprintln!("IDLE:l = {}", cx.resources.early).unwrap();
|
||||
hprintln!("IDLE:early = {}", cx.resources.early).unwrap();
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
//! examples/minimal-task-local-late.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
|
|
38
examples/minimal-task-local-to-shared.rs
Normal file
38
examples/minimal-task-local-to-shared.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
//! examples/minimal-task-local-early.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};
|
||||
|
||||
#[resources]
|
||||
struct Resources {
|
||||
shared: u32,
|
||||
|
||||
#[task_local]
|
||||
#[init(42)]
|
||||
init_resource: u32,
|
||||
}
|
||||
|
||||
#[init(resources = [ init_resource ])]
|
||||
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
|
||||
let ir = *cx.resources.init_resource;
|
||||
(init::LateResources { shared: ir }, init::Monotonics())
|
||||
}
|
||||
|
||||
// task_local is task_local
|
||||
#[idle(resources = [shared])]
|
||||
fn idle(mut cx: idle::Context) -> ! {
|
||||
hprintln!("IDLE:shared = {}", cx.resources.shared.lock(|s| *s)).unwrap();
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
}
|
39
examples/minimal-task-local-to-task-local.rs
Normal file
39
examples/minimal-task-local-to-task-local.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
//! examples/minimal-task-local-to-task-local.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};
|
||||
|
||||
#[resources]
|
||||
struct Resources {
|
||||
#[task_local]
|
||||
shared: u32,
|
||||
|
||||
#[task_local]
|
||||
#[init(42)]
|
||||
init_resource: u32,
|
||||
}
|
||||
|
||||
#[init(resources = [ init_resource ])]
|
||||
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
|
||||
let ir = *cx.resources.init_resource;
|
||||
(init::LateResources { shared: ir }, init::Monotonics())
|
||||
}
|
||||
|
||||
// task_local is task_local
|
||||
#[idle(resources = [shared])]
|
||||
fn idle(cx: idle::Context) -> ! {
|
||||
hprintln!("IDLE:shared = {}", cx.resources.shared).unwrap();
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
//! examples/minimal-task-local-type-early.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
//! examples/minimal-task-local-type-late.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
|
|
51
examples/minimal-task-local-type-to-task-local-type.rs
Normal file
51
examples/minimal-task-local-type-to-task-local-type.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
//! examples/minmal-task-local-to-task-local.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};
|
||||
|
||||
pub struct InitType {
|
||||
x: u32,
|
||||
}
|
||||
|
||||
pub struct TaskLocal {
|
||||
y: u32,
|
||||
}
|
||||
|
||||
#[resources]
|
||||
struct Resources {
|
||||
#[task_local]
|
||||
#[init(InitType { x: 0 })]
|
||||
init_resource: InitType,
|
||||
|
||||
#[task_local]
|
||||
local: crate::app::TaskLocal,
|
||||
}
|
||||
|
||||
#[init(resources = [ init_resource ])]
|
||||
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
|
||||
let y = cx.resources.init_resource.x;
|
||||
(
|
||||
init::LateResources {
|
||||
local: TaskLocal { y },
|
||||
},
|
||||
init::Monotonics(),
|
||||
)
|
||||
}
|
||||
|
||||
// task_local is task_local
|
||||
#[idle(resources = [local])]
|
||||
fn idle(cx: idle::Context) -> ! {
|
||||
hprintln!("IDLE:shared = {}", cx.resources.local.y).unwrap();
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue