added .no to not yet supported examples

This commit is contained in:
Per Lindgren 2021-03-11 23:27:54 +01:00
parent fc1c9bda3f
commit 4b370c3d60
17 changed files with 9 additions and 826 deletions

View file

@ -23,9 +23,9 @@ name = "rtic"
name = "periodic"
required-features = ["__v7"]
[[example]]
name = "pool"
required-features = ["__v7"]
# [[example]]
# name = "pool"
# required-features = ["__v7"]
[[example]]
name = "spawn_after"

View file

@ -1,51 +0,0 @@
//! examples/binds.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_semihosting as _;
// `examples/interrupt.rs` rewritten to use `binds`
#[rtic::app(device = lm3s6965)]
mod app {
use cortex_m_semihosting::{debug, hprintln};
use lm3s6965::Interrupt;
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
rtic::pend(Interrupt::UART0);
hprintln!("init").unwrap();
(init::LateResources {}, init::Monotonics())
}
#[idle]
fn idle(_: idle::Context) -> ! {
hprintln!("idle").unwrap();
rtic::pend(Interrupt::UART0);
debug::exit(debug::EXIT_SUCCESS);
loop {
cortex_m::asm::nop();
}
}
#[task(binds = UART0)]
fn foo(_: foo::Context) {
static mut TIMES: u32 = 0;
*TIMES += 1;
hprintln!(
"foo called {} time{}",
*TIMES,
if *TIMES > 1 { "s" } else { "" }
)
.unwrap();
}
}

View file

@ -1,51 +0,0 @@
//! examples/destructure.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
use cortex_m_semihosting::hprintln;
use lm3s6965::Interrupt;
#[resources]
struct Resources {
// Some resources to work with
#[init(0)]
a: u32,
#[init(0)]
b: u32,
#[init(0)]
c: u32,
}
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
rtic::pend(Interrupt::UART0);
rtic::pend(Interrupt::UART1);
(init::LateResources {}, init::Monotonics())
}
// Direct destructure
#[task(binds = UART0, resources = [&a, &b, &c])]
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
#[task(binds = UART1, resources = [&a, &b, &c])]
fn uart1(cx: uart1::Context) {
let uart1::Resources { a, b, c } = cx.resources;
hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap();
}
}

View file

@ -1,67 +0,0 @@
//! examples/generics.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use cortex_m_semihosting::hprintln;
use panic_semihosting as _;
use rtic::Mutex;
#[rtic::app(device = lm3s6965)]
mod app {
use cortex_m_semihosting::{debug, hprintln};
use lm3s6965::Interrupt;
#[resources]
struct Resources {
#[init(0)]
shared: u32,
}
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
rtic::pend(Interrupt::UART0);
rtic::pend(Interrupt::UART1);
(init::LateResources {}, init::Monotonics())
}
#[task(binds = UART0, resources = [shared])]
fn uart0(c: uart0::Context) {
static mut STATE: u32 = 0;
hprintln!("UART0(STATE = {})", *STATE).unwrap();
// second argument has type `resources::shared`
super::advance(STATE, c.resources.shared);
rtic::pend(Interrupt::UART1);
debug::exit(debug::EXIT_SUCCESS);
}
#[task(binds = UART1, priority = 2, resources = [shared])]
fn uart1(c: uart1::Context) {
static mut STATE: u32 = 0;
hprintln!("UART1(STATE = {})", *STATE).unwrap();
// second argument has type `resources::shared`
super::advance(STATE, c.resources.shared);
}
}
// the second parameter is generic: it can be any type that implements the `Mutex` trait
fn advance(state: &mut u32, mut shared: impl Mutex<T = u32>) {
*state += 1;
let (old, new) = shared.lock(|shared: &mut u32| {
let old = *shared;
*shared += *state;
(old, *shared)
});
hprintln!("shared: {} -> {}", old, new).unwrap();
}

View file

@ -1,55 +0,0 @@
//! 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;
#[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)]
fn uart0(_: uart0::Context) {
static mut TIMES: u32 = 0;
// Safe access to local `static mut` variable
*TIMES += 1;
hprintln!(
"UART0 called {} time{}",
*TIMES,
if *TIMES > 1 { "s" } else { "" }
)
.unwrap();
}
}

View file

@ -1,36 +0,0 @@
//! examples/idle.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};
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
hprintln!("init").unwrap();
(init::LateResources {}, init::Monotonics())
}
#[idle]
fn idle(_: idle::Context) -> ! {
static mut X: u32 = 0;
// Safe access to local `static mut` variable
let _x: &'static mut u32 = X;
hprintln!("idle").unwrap();
debug::exit(debug::EXIT_SUCCESS);
loop {
cortex_m::asm::nop();
}
}
}

View file

@ -1,37 +0,0 @@
//! examples/init.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_semihosting as _;
#[rtic::app(device = lm3s6965, peripherals = true)]
mod app {
use cortex_m_semihosting::{debug, hprintln};
#[init]
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
static mut X: u32 = 0;
// Cortex-M peripherals
let _core: cortex_m::Peripherals = cx.core;
// Device specific peripherals
let _device: lm3s6965::Peripherals = cx.device;
// Safe access to local `static mut` variable
let _x: &'static mut u32 = X;
// Access to the critical section token,
// to indicate that this is a critical seciton
let _cs_token: bare_metal::CriticalSection = cx.cs;
hprintln!("init").unwrap();
debug::exit(debug::EXIT_SUCCESS);
(init::LateResources {}, init::Monotonics())
}
}

View file

@ -1,54 +0,0 @@
//! examples/late.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 heapless::{
consts::*,
i,
spsc::{Consumer, Producer, Queue},
};
use lm3s6965::Interrupt;
// Late resources
#[resources]
struct Resources {
p: Producer<'static, u32, U4>,
c: Consumer<'static, u32, U4>,
}
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
static mut Q: Queue<u32, U4> = Queue(i::Queue::new());
let (p, c) = Q.split();
// Initialization of late resources
(init::LateResources { p, c }, init::Monotonics())
}
#[idle(resources = [c])]
fn idle(mut c: idle::Context) -> ! {
loop {
if let Some(byte) = c.resources.c.lock(|c| c.dequeue()) {
hprintln!("received message: {}", byte).unwrap();
debug::exit(debug::EXIT_SUCCESS);
} else {
rtic::pend(Interrupt::UART0);
}
}
}
#[task(binds = UART0, resources = [p])]
fn uart0(mut c: uart0::Context) {
c.resources.p.lock(|p| p.enqueue(42).unwrap());
}
}

View file

@ -1,48 +0,0 @@
//! 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};
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
foo::spawn(/* no message */).unwrap();
(init::LateResources {}, init::Monotonics())
}
#[task]
fn foo(_: foo::Context) {
static mut COUNT: u32 = 0;
hprintln!("foo").unwrap();
bar::spawn(*COUNT).unwrap();
*COUNT += 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();
}
}

View file

@ -1,43 +0,0 @@
//! `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;
}
}

View file

@ -1,40 +0,0 @@
//! examples/static.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 {
key: u32,
}
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
rtic::pend(Interrupt::UART0);
rtic::pend(Interrupt::UART1);
(init::LateResources { key: 0xdeadbeef }, init::Monotonics())
}
#[task(binds = UART0, resources = [&key])]
fn uart0(cx: uart0::Context) {
let key: &u32 = cx.resources.key;
hprintln!("UART0(key = {:#x})", key).unwrap();
debug::exit(debug::EXIT_SUCCESS);
}
#[task(binds = UART1, priority = 2, resources = [&key])]
fn uart1(cx: uart1::Context) {
hprintln!("UART1(key = {:#x})", cx.resources.key).unwrap();
}
}

View file

@ -1,68 +0,0 @@
//! examples/pool.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use heapless::{
pool,
pool::singleton::{Box, Pool},
};
use panic_semihosting as _;
use rtic::app;
// Declare a pool of 128-byte memory blocks
pool!(P: [u8; 128]);
#[app(device = lm3s6965, dispatchers = [SSI0, QEI0])]
mod app {
use crate::{Box, Pool};
use cortex_m_semihosting::{debug, hprintln};
use lm3s6965::Interrupt;
// Import the memory pool into scope
use super::P;
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
static mut MEMORY: [u8; 512] = [0; 512];
// Increase the capacity of the memory pool by ~4
P::grow(MEMORY);
rtic::pend(Interrupt::I2C0);
(init::LateResources {}, init::Monotonics())
}
#[task(binds = I2C0, priority = 2)]
fn i2c0(_: i2c0::Context) {
// claim a memory block, leave it uninitialized and ..
let x = P::alloc().unwrap().freeze();
// .. send it to the `foo` task
foo::spawn(x).ok().unwrap();
// send another block to the task `bar`
bar::spawn(P::alloc().unwrap().freeze()).ok().unwrap();
}
#[task]
fn foo(_: foo::Context, x: Box<P>) {
hprintln!("foo({:?})", x.as_ptr()).unwrap();
// explicitly return the block to the pool
drop(x);
debug::exit(debug::EXIT_SUCCESS);
}
#[task(priority = 2)]
fn bar(_: bar::Context, x: Box<P>) {
hprintln!("bar({:?})", x.as_ptr()).unwrap();
// this is done automatically so we can omit the call to `drop`
// drop(x);
}
}

View file

@ -1,57 +0,0 @@
//! examples/static.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 heapless::{
consts::*,
i,
spsc::{Consumer, Producer, Queue},
};
use lm3s6965::Interrupt;
// Late resources
#[resources]
struct Resources {
p: Producer<'static, u32, U4>,
c: Consumer<'static, u32, U4>,
}
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
static mut Q: Queue<u32, U4> = Queue(i::Queue::new());
let (p, c) = Q.split();
// Initialization of late resources
(init::LateResources { p, c }, init::Monotonics())
}
#[idle(resources = [c])]
fn idle(mut c: idle::Context) -> ! {
loop {
if let Some(byte) = c.resources.c.lock(|c| c.dequeue()) {
hprintln!("received message: {}", byte).unwrap();
debug::exit(debug::EXIT_SUCCESS);
} else {
rtic::pend(Interrupt::UART0);
}
}
}
#[task(binds = UART0, resources = [p])]
fn uart0(mut c: uart0::Context) {
static mut KALLE: u32 = 0;
*KALLE += 1;
c.resources.p.lock(|p| p.enqueue(42).unwrap());
}
}

View file

@ -1,42 +0,0 @@
//! [compile-pass] late resources don't need to be `Send` if they are owned by `idle`
#![no_main]
#![no_std]
use core::marker::PhantomData;
use panic_semihosting as _;
pub struct NotSend {
_0: PhantomData<*const ()>,
}
#[rtic::app(device = lm3s6965)]
mod app {
use super::NotSend;
use core::marker::PhantomData;
#[resources]
struct Resources {
x: NotSend,
#[init(None)]
y: Option<NotSend>,
}
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
(
init::LateResources {
x: NotSend { _0: PhantomData },
},
init::Monotonics(),
)
}
#[idle(resources = [x, y])]
fn idle(_: idle::Context) -> ! {
loop {
cortex_m::asm::nop();
}
}
}

View file

@ -1,81 +0,0 @@
//! [compile-pass] Check code generation of resources
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[resources]
struct Resources {
#[init(0)]
o1: u32, // init
#[init(0)]
o2: u32, // idle
#[init(0)]
o3: u32, // EXTI0
#[init(0)]
o4: u32, // idle
#[init(0)]
o5: u32, // EXTI1
#[init(0)]
o6: u32, // init
#[init(0)]
s1: u32, // idle & uart0
#[init(0)]
s2: u32, // uart0 & uart1
#[init(0)]
s3: u32, // idle & uart0
}
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
(init::LateResources {}, init::Monotonics())
}
#[idle(resources = [o2, &o4, s1, &s3])]
fn idle(mut c: idle::Context) -> ! {
// owned by `idle` == `&'static mut`
let _: resources::o2 = c.resources.o2;
// owned by `idle` == `&'static` if read-only
let _: &u32 = c.resources.o4;
// shared with `idle` == `Mutex`
c.resources.s1.lock(|_| {});
// `&` if read-only
let _: &u32 = c.resources.s3;
loop {
cortex_m::asm::nop();
}
}
#[task(binds = UART0, resources = [o3, s1, s2, &s3])]
fn uart0(c: uart0::Context) {
// owned by interrupt == `&mut`
let _: resources::o3 = c.resources.o3;
// no `Mutex` proxy when access from highest priority task
let _: resources::s1 = c.resources.s1;
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks
let _: resources::s2 = c.resources.s2;
// `&` if read-only
let _: &u32 = c.resources.s3;
}
#[task(binds = UART1, resources = [s2, &o5])]
fn uart1(c: uart1::Context) {
// owned by interrupt == `&` if read-only
let _: &u32 = c.resources.o5;
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks
let _: resources::s2 = c.resources.s2;
}
}

View file

@ -1,6 +1,6 @@
//! examples/task-local_minimal.rs
#![deny(unsafe_code)]
#![deny(warnings)]
//#![deny(warnings)]
#![no_main]
#![no_std]
@ -14,18 +14,18 @@ mod app {
struct Resources {
// A local (move), late resource
#[task_local]
l: u32,
task_local: u32,
}
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
(init::LateResources { l: 42 }, init::Monotonics())
(init::LateResources { task_local: 42 }, init::Monotonics())
}
// l is task_local
#[idle(resources =[l])]
// task_local is task_local
#[idle(resources =[task_local])]
fn idle(cx: idle::Context) -> ! {
hprintln!("IDLE:l = {}", cx.resources.l).unwrap();
hprintln!("IDLE:l = {}", cx.resources.task_local).unwrap();
debug::exit(debug::EXIT_SUCCESS);
loop {
cortex_m::asm::nop();

View file

@ -1,87 +0,0 @@
//! examples/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};
use lm3s6965::Interrupt;
#[resources]
struct Resources {
// An early resource
#[init(0)]
shared: u32,
// A local (move), early resource
#[task_local]
#[init(1)]
l1: u32,
// An exclusive, early resource
#[lock_free]
#[init(1)]
e1: u32,
// A local (move), late resource
#[task_local]
l2: u32,
// An exclusive, late resource
#[lock_free]
e2: u32,
}
#[init]
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
rtic::pend(Interrupt::UART0);
rtic::pend(Interrupt::UART1);
(init::LateResources { e2: 2, l2: 2 }, init::Monotonics())
}
// `shared` cannot be accessed from this context
// l1 ok (task_local)
// e2 ok (lock_free)
#[idle(resources =[l1, e2])]
fn idle(cx: idle::Context) -> ! {
hprintln!("IDLE:l1 = {}", cx.resources.l1).unwrap();
hprintln!("IDLE:e2 = {}", cx.resources.e2).unwrap();
debug::exit(debug::EXIT_SUCCESS);
loop {
cortex_m::asm::nop();
}
}
// `shared` can be accessed from this context
// l2 ok (task_local)
// e1 ok (lock_free)
#[task(priority = 1, binds = UART0, resources = [shared, l2, e1])]
fn uart0(mut cx: uart0::Context) {
let shared = cx.resources.shared.lock(|shared| {
*shared += 1;
*shared
});
*cx.resources.e1 += 10;
hprintln!("UART0: shared = {}", shared).unwrap();
hprintln!("UART0:l2 = {}", cx.resources.l2).unwrap();
hprintln!("UART0:e1 = {}", cx.resources.e1).unwrap();
}
// `shared` can be accessed from this context
// e1 ok (lock_free)
#[task(priority = 1, binds = UART1, resources = [shared, e1])]
fn uart1(mut cx: uart1::Context) {
let shared = cx.resources.shared.lock(|shared| {
*shared += 1;
*shared
});
hprintln!("UART1: shared = {}", shared).unwrap();
hprintln!("UART1:e1 = {}", cx.resources.e1).unwrap();
}
}