mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-12-25 19:39:32 +01:00
examples polished
This commit is contained in:
parent
2493860078
commit
a8d890db3d
62 changed files with 135 additions and 1165 deletions
|
@ -1,9 +1,10 @@
|
|||
//! examples/async-channel-done.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
//! examples/async-channel-no-receiver.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
//! examples/async-channel-no-sender.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
//! examples/async-channel-try.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
//! examples/async-channel.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0], peripherals = true)]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use systick_monotonic::*;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = Systick<100>;
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local) {
|
||||
hprintln!("init").unwrap();
|
||||
|
||||
foo::spawn().ok();
|
||||
|
||||
(Shared {}, Local {})
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
loop {
|
||||
cortex_m::asm::wfi(); // put the MCU in sleep mode until interrupt occurs
|
||||
}
|
||||
}
|
||||
|
||||
// Infinite loops are not allowed in RTIC, however in async tasks they are - if there is an
|
||||
// await inside the loop.
|
||||
#[task]
|
||||
async fn foo(_cx: foo::Context) {
|
||||
let mut i = 0;
|
||||
loop {
|
||||
if i == 5 {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
hprintln!("hello from async {}", i).ok();
|
||||
monotonics::delay(100.millis()).await; // This makes it okey!
|
||||
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
// NOTES:
|
||||
//
|
||||
// - Async tasks cannot have `#[lock_free]` resources, as they can interleve and each async
|
||||
// task can have a mutable reference stored.
|
||||
// - Spawning an async task equates to it being polled once.
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0], peripherals = true)]
|
||||
mod app {
|
||||
use core::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use systick_monotonic::*;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = Systick<100>;
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
hprintln!("init").unwrap();
|
||||
|
||||
foo::spawn().ok();
|
||||
bar::spawn().ok();
|
||||
|
||||
(
|
||||
Shared {},
|
||||
Local {},
|
||||
init::Monotonics(Systick::new(cx.core.SYST, 12_000_000)),
|
||||
)
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
loop {
|
||||
cortex_m::asm::wfi(); // put the MCU in sleep mode until interrupt occurs
|
||||
}
|
||||
}
|
||||
|
||||
#[task]
|
||||
async fn foo(_cx: foo::Context) {
|
||||
hprintln!("hello from foo").ok();
|
||||
|
||||
// This will not timeout
|
||||
match monotonics::timeout_after(monotonics::delay(100.millis()), 200.millis()).await {
|
||||
Ok(_) => hprintln!("foo no timeout").ok(),
|
||||
Err(_) => hprintln!("foo timeout").ok(),
|
||||
};
|
||||
}
|
||||
|
||||
#[task]
|
||||
async fn bar(_cx: bar::Context) {
|
||||
hprintln!("hello from bar").ok();
|
||||
|
||||
// This will timeout
|
||||
match monotonics::timeout_after(NeverEndingFuture {}, 300.millis()).await {
|
||||
Ok(_) => hprintln!("bar no timeout").ok(),
|
||||
Err(_) => hprintln!("bar timeout").ok(),
|
||||
};
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
pub struct NeverEndingFuture {}
|
||||
|
||||
impl Future for NeverEndingFuture {
|
||||
type Output = ();
|
||||
|
||||
fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
// Never finish
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
//! examples/binds.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
//! examples/cancel-reschedule.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};
|
||||
use systick_monotonic::*;
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
let systick = cx.core.SYST;
|
||||
|
||||
// Initialize the monotonic (SysTick rate in QEMU is 12 MHz)
|
||||
let mono = Systick::new(systick, 12_000_000);
|
||||
|
||||
hprintln!("init").ok();
|
||||
|
||||
// Schedule `foo` to run 1 second in the future
|
||||
foo::spawn_after(1.secs()).unwrap();
|
||||
|
||||
(
|
||||
Shared {},
|
||||
Local {},
|
||||
init::Monotonics(mono), // Give the monotonic to RTIC
|
||||
)
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn foo(_: foo::Context) {
|
||||
hprintln!("foo").ok();
|
||||
|
||||
// Schedule `bar` to run 2 seconds in the future (1 second after foo runs)
|
||||
let spawn_handle = baz::spawn_after(2.secs()).unwrap();
|
||||
bar::spawn_after(1.secs(), spawn_handle, false).unwrap(); // Change to true
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn bar(_: bar::Context, baz_handle: baz::SpawnHandle, do_reschedule: bool) {
|
||||
hprintln!("bar").ok();
|
||||
|
||||
if do_reschedule {
|
||||
// Reschedule baz 2 seconds from now, instead of the original 1 second
|
||||
// from now.
|
||||
baz_handle.reschedule_after(2.secs()).unwrap();
|
||||
// Or baz_handle.reschedule_at(/* time */)
|
||||
} else {
|
||||
// Or cancel it
|
||||
baz_handle.cancel().unwrap();
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn baz(_: baz::Context) {
|
||||
hprintln!("baz").ok();
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
//! examples/capacity.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};
|
||||
use lm3s6965::Interrupt;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
rtic::pend(Interrupt::UART0);
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(binds = UART0)]
|
||||
fn uart0(_: uart0::Context) {
|
||||
foo::spawn(0).unwrap();
|
||||
foo::spawn(1).unwrap();
|
||||
foo::spawn(2).unwrap();
|
||||
foo::spawn(3).unwrap();
|
||||
|
||||
bar::spawn().unwrap();
|
||||
}
|
||||
|
||||
#[task(capacity = 4)]
|
||||
fn foo(_: foo::Context, x: u32) {
|
||||
hprintln!("foo({})", x).unwrap();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn bar(_: bar::Context) {
|
||||
hprintln!("bar").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
//! examples/cfg-whole-task.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::debug;
|
||||
#[cfg(debug_assertions)]
|
||||
use cortex_m_semihosting::hprintln;
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
count: u32,
|
||||
#[cfg(never)]
|
||||
unused: u32,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
foo::spawn().unwrap();
|
||||
foo::spawn().unwrap();
|
||||
|
||||
(
|
||||
Shared {
|
||||
count: 0,
|
||||
#[cfg(never)]
|
||||
unused: 1,
|
||||
},
|
||||
Local {},
|
||||
init::Monotonics(),
|
||||
)
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
|
||||
#[task(capacity = 2, shared = [count])]
|
||||
fn foo(mut _cx: foo::Context) {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
_cx.shared.count.lock(|count| *count += 1);
|
||||
|
||||
log::spawn(_cx.shared.count.lock(|count| *count)).unwrap();
|
||||
}
|
||||
|
||||
// this wouldn't compile in `release` mode
|
||||
// *_cx.shared.count += 1;
|
||||
|
||||
// ..
|
||||
}
|
||||
|
||||
// The whole task should disappear,
|
||||
// currently still present in the Tasks enum
|
||||
#[cfg(never)]
|
||||
#[task(capacity = 2, shared = [count])]
|
||||
fn foo2(mut _cx: foo2::Context) {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
_cx.shared.count.lock(|count| *count += 10);
|
||||
|
||||
log::spawn(_cx.shared.count.lock(|count| *count)).unwrap();
|
||||
}
|
||||
|
||||
// this wouldn't compile in `release` mode
|
||||
// *_cx.shared.count += 1;
|
||||
|
||||
// ..
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
#[task(capacity = 2)]
|
||||
fn log(_: log::Context, n: u32) {
|
||||
hprintln!(
|
||||
"foo has been called {} time{}",
|
||||
n,
|
||||
if n == 1 { "" } else { "s" }
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
//! examples/common.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use systick_monotonic::*; // Implements the `Monotonic` trait
|
||||
|
||||
// A monotonic timer to enable scheduling in RTIC
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
||||
|
||||
// Resources shared between tasks
|
||||
#[shared]
|
||||
struct Shared {
|
||||
s1: u32,
|
||||
s2: i32,
|
||||
}
|
||||
|
||||
// Local resources to specific tasks (cannot be shared)
|
||||
#[local]
|
||||
struct Local {
|
||||
l1: u8,
|
||||
l2: i8,
|
||||
}
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
let systick = cx.core.SYST;
|
||||
|
||||
// Initialize the monotonic (SysTick rate in QEMU is 12 MHz)
|
||||
let mono = Systick::new(systick, 12_000_000);
|
||||
|
||||
// Spawn the task `foo` directly after `init` finishes
|
||||
foo::spawn().unwrap();
|
||||
|
||||
// Spawn the task `bar` 1 second after `init` finishes, this is enabled
|
||||
// by the `#[monotonic(..)]` above
|
||||
bar::spawn_after(1.secs()).unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(
|
||||
// Initialization of shared resources
|
||||
Shared { s1: 0, s2: 1 },
|
||||
// Initialization of task local resources
|
||||
Local { l1: 2, l2: 3 },
|
||||
// Move the monotonic timer to the RTIC run-time, this enables
|
||||
// scheduling
|
||||
init::Monotonics(mono),
|
||||
)
|
||||
}
|
||||
|
||||
// Background task, runs whenever no other tasks are running
|
||||
#[idle]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
loop {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Software task, not bound to a hardware interrupt.
|
||||
// This task takes the task local resource `l1`
|
||||
// The resources `s1` and `s2` are shared between all other tasks.
|
||||
#[task(shared = [s1, s2], local = [l1])]
|
||||
fn foo(_: foo::Context) {
|
||||
// This task is only spawned once in `init`, hence this task will run
|
||||
// only once
|
||||
|
||||
hprintln!("foo").ok();
|
||||
}
|
||||
|
||||
// Software task, also not bound to a hardware interrupt
|
||||
// This task takes the task local resource `l2`
|
||||
// The resources `s1` and `s2` are shared between all other tasks.
|
||||
#[task(shared = [s1, s2], local = [l2])]
|
||||
fn bar(_: bar::Context) {
|
||||
hprintln!("bar").ok();
|
||||
|
||||
// Run `bar` once per second
|
||||
bar::spawn_after(1.secs()).unwrap();
|
||||
}
|
||||
|
||||
// Hardware task, bound to a hardware interrupt
|
||||
// The resources `s1` and `s2` are shared between all other tasks.
|
||||
#[task(binds = UART0, priority = 3, shared = [s1, s2])]
|
||||
fn uart0_interrupt(_: uart0_interrupt::Context) {
|
||||
// This task is bound to the interrupt `UART0` and will run
|
||||
// whenever the interrupt fires
|
||||
|
||||
// Note that RTIC does NOT clear the interrupt flag, this is up to the
|
||||
// user
|
||||
|
||||
hprintln!("UART0 interrupt!").ok();
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
//! examples/common.rs
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![deny(warnings)]
|
||||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/complex.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/declared_locals.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/destructure.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/extern_binds.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use cortex_m_semihosting::hprintln;
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/extern_spawn.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/generics.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use cortex_m_semihosting::hprintln;
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/hardware.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/idle-wfi.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/idle.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/init.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
//! examples/locals.rs
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
//! examples/lock-free.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
#[lock_free] // <- lock-free shared resource
|
||||
counter: u64,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local) {
|
||||
foo::spawn().unwrap();
|
||||
|
||||
(Shared { counter: 0 }, Local {})
|
||||
}
|
||||
|
||||
#[task(shared = [counter])] // <- same priority
|
||||
async fn foo(c: foo::Context) {
|
||||
bar::spawn().unwrap();
|
||||
|
||||
*c.shared.counter += 1; // <- no lock API required
|
||||
let counter = *c.shared.counter;
|
||||
hprintln!(" foo = {}", counter).unwrap();
|
||||
}
|
||||
|
||||
#[task(shared = [counter])] // <- same priority
|
||||
async fn bar(c: bar::Context) {
|
||||
foo::spawn().unwrap();
|
||||
|
||||
*c.shared.counter += 1; // <- no lock API required
|
||||
let counter = *c.shared.counter;
|
||||
hprintln!(" bar = {}", counter).unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
//! examples/lock-free.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/lock.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,52 +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};
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
foo::spawn(/* no message */).unwrap();
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(local = [count: u32 = 0])]
|
||||
fn foo(cx: foo::Context) {
|
||||
hprintln!("foo").unwrap();
|
||||
|
||||
bar::spawn(*cx.local.count).unwrap();
|
||||
*cx.local.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); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
foo::spawn().unwrap();
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/mutlilock.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
//! `examples/not-sync.rs`
|
||||
|
||||
// #![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use core::marker::PhantomData;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/only-shared-access.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
//! examples/periodic-at.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};
|
||||
use systick_monotonic::*;
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
let systick = cx.core.SYST;
|
||||
|
||||
// Initialize the monotonic (SysTick rate in QEMU is 12 MHz)
|
||||
let mut mono = Systick::new(systick, 12_000_000);
|
||||
|
||||
foo::spawn_after(1.secs(), mono.now()).unwrap();
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics(mono))
|
||||
}
|
||||
|
||||
#[task(local = [cnt: u32 = 0])]
|
||||
fn foo(cx: foo::Context, instant: fugit::TimerInstantU64<100>) {
|
||||
hprintln!("foo {:?}", instant).ok();
|
||||
*cx.local.cnt += 1;
|
||||
|
||||
if *cx.local.cnt == 4 {
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
// Periodic every 100 milliseconds
|
||||
let next_instant = instant + 100.millis();
|
||||
foo::spawn_at(next_instant, next_instant).unwrap();
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//! examples/periodic-at2.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};
|
||||
use systick_monotonic::*;
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
let systick = cx.core.SYST;
|
||||
|
||||
// Initialize the monotonic (SysTick rate in QEMU is 12 MHz)
|
||||
let mut mono = Systick::new(systick, 12_000_000);
|
||||
|
||||
foo::spawn_after(200.millis(), mono.now()).unwrap();
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics(mono))
|
||||
}
|
||||
|
||||
// Using the explicit type of the timer implementation
|
||||
#[task(local = [cnt: u32 = 0])]
|
||||
fn foo(cx: foo::Context, instant: fugit::TimerInstantU64<100>) {
|
||||
hprintln!("foo {:?}", instant).ok();
|
||||
*cx.local.cnt += 1;
|
||||
|
||||
if *cx.local.cnt == 4 {
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
// Spawn a new message with 100 ms offset to spawned time
|
||||
let next_instant = instant + 100.millis();
|
||||
bar::spawn_at(next_instant, next_instant).unwrap();
|
||||
}
|
||||
|
||||
// Using the Instant from the Monotonic trait
|
||||
// This remains agnostic to the timer implementation
|
||||
#[task(local = [cnt: u32 = 0])]
|
||||
fn bar(_cx: bar::Context, instant: <MyMono as rtic_monotonic::Monotonic>::Instant) {
|
||||
hprintln!("bar {:?}", instant).ok();
|
||||
|
||||
// Spawn a new message with 200ms offset to spawned time
|
||||
let next_instant = instant + 200.millis();
|
||||
foo::spawn_at(next_instant, next_instant).unwrap();
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
//! examples/periodic.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};
|
||||
use systick_monotonic::*;
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
let systick = cx.core.SYST;
|
||||
|
||||
// Initialize the monotonic (SysTick rate in QEMU is 12 MHz)
|
||||
let mono = Systick::new(systick, 12_000_000);
|
||||
|
||||
foo::spawn_after(100.millis()).unwrap();
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics(mono))
|
||||
}
|
||||
|
||||
#[task(local = [cnt: u32 = 0])]
|
||||
fn foo(cx: foo::Context) {
|
||||
hprintln!("foo").ok();
|
||||
*cx.local.cnt += 1;
|
||||
|
||||
if *cx.local.cnt == 4 {
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
// Periodic every 100ms
|
||||
foo::spawn_after(100.millis()).unwrap();
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/peripherals-taken.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
//! examples/pool.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use heapless::{
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
use rtic::app;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
//! examples/ramfunc.rs
|
||||
//! TODO: verify that ram-sections are properly used
|
||||
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/resource.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
//! examples/schedule.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};
|
||||
use systick_monotonic::*;
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
let systick = cx.core.SYST;
|
||||
|
||||
// Initialize the monotonic (SysTick rate in QEMU is 12 MHz)
|
||||
let mono = Systick::new(systick, 12_000_000);
|
||||
|
||||
hprintln!("init").ok();
|
||||
|
||||
// Schedule `foo` to run 1 second in the future
|
||||
foo::spawn_after(1.secs()).unwrap();
|
||||
|
||||
(
|
||||
Shared {},
|
||||
Local {},
|
||||
init::Monotonics(mono), // Give the monotonic to RTIC
|
||||
)
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn foo(_: foo::Context) {
|
||||
hprintln!("foo").ok();
|
||||
|
||||
// Schedule `bar` to run 2 seconds in the future (1 second after foo runs)
|
||||
bar::spawn_after(1.secs()).unwrap();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn bar(_: bar::Context) {
|
||||
hprintln!("bar").ok();
|
||||
|
||||
// Schedule `baz` to run 1 seconds from now, but with a specific time instant.
|
||||
baz::spawn_at(monotonics::now() + 1.secs()).unwrap();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn baz(_: baz::Context) {
|
||||
hprintln!("baz").ok();
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/late.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _; // panic handler
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/spawn.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
//! examples/message_passing.rs
|
||||
//! examples/spawn_arguments.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/spawn.rs
|
||||
//! examples/spawn_err.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/spawn.rs
|
||||
//! examples/spawn_loop.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/static.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! [compile-pass] Check that `binds` works as advertised
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/h-task-main.rs
|
||||
//! examples/t-task-main.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/t-idle-main.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use core::marker::PhantomData;
|
||||
|
|
|
@ -1,136 +0,0 @@
|
|||
//! [compile-pass] Check `schedule` code generation
|
||||
|
||||
#![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;
|
||||
use systick_monotonic::*;
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
let systick = cx.core.SYST;
|
||||
|
||||
// Initialize the monotonic (SysTick rate in QEMU is 12 MHz)
|
||||
let mono = Systick::new(systick, 12_000_000);
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics(mono))
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
// Task without message passing
|
||||
|
||||
// Not default
|
||||
let _: Result<foo::MyMono::SpawnHandle, ()> =
|
||||
foo::MyMono::spawn_at(monotonics::MyMono::now());
|
||||
let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(1.secs());
|
||||
let _: Result<foo::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
|
||||
|
||||
let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(1.secs());
|
||||
let _: Result<foo::MyMono::SpawnHandle, ()> =
|
||||
handle.unwrap().reschedule_at(monotonics::MyMono::now());
|
||||
|
||||
let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(1.secs());
|
||||
let _: Result<(), ()> = handle.unwrap().cancel();
|
||||
|
||||
// Using default
|
||||
let _: Result<foo::SpawnHandle, ()> = foo::spawn_at(monotonics::now());
|
||||
let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(1.secs());
|
||||
let _: Result<foo::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
|
||||
|
||||
let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(1.secs());
|
||||
let _: Result<foo::SpawnHandle, ()> =
|
||||
handle.unwrap().reschedule_at(monotonics::MyMono::now());
|
||||
|
||||
let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(1.secs());
|
||||
let _: Result<(), ()> = handle.unwrap().cancel();
|
||||
|
||||
// Task with single message passing
|
||||
|
||||
// Not default
|
||||
let _: Result<bar::MyMono::SpawnHandle, u32> =
|
||||
bar::MyMono::spawn_at(monotonics::MyMono::now(), 0);
|
||||
let handle: Result<bar::MyMono::SpawnHandle, u32> = bar::MyMono::spawn_after(1.secs(), 1);
|
||||
let _: Result<bar::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
|
||||
|
||||
let handle: Result<bar::MyMono::SpawnHandle, u32> = bar::MyMono::spawn_after(1.secs(), 1);
|
||||
let _: Result<bar::MyMono::SpawnHandle, ()> =
|
||||
handle.unwrap().reschedule_at(monotonics::MyMono::now());
|
||||
|
||||
let handle: Result<bar::MyMono::SpawnHandle, u32> = bar::MyMono::spawn_after(1.secs(), 1);
|
||||
let _: Result<u32, ()> = handle.unwrap().cancel();
|
||||
|
||||
// Using default
|
||||
let _: Result<bar::SpawnHandle, u32> = bar::spawn_at(monotonics::MyMono::now(), 0);
|
||||
let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(1.secs(), 1);
|
||||
let _: Result<bar::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
|
||||
|
||||
let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(1.secs(), 1);
|
||||
let _: Result<bar::SpawnHandle, ()> =
|
||||
handle.unwrap().reschedule_at(monotonics::MyMono::now());
|
||||
|
||||
let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(1.secs(), 1);
|
||||
let _: Result<u32, ()> = handle.unwrap().cancel();
|
||||
|
||||
// Task with multiple message passing
|
||||
|
||||
// Not default
|
||||
let _: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
|
||||
baz::MyMono::spawn_at(monotonics::MyMono::now(), 0, 1);
|
||||
let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
|
||||
baz::MyMono::spawn_after(1.secs(), 1, 2);
|
||||
let _: Result<baz::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
|
||||
|
||||
let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
|
||||
baz::MyMono::spawn_after(1.secs(), 1, 2);
|
||||
let _: Result<baz::MyMono::SpawnHandle, ()> =
|
||||
handle.unwrap().reschedule_at(monotonics::MyMono::now());
|
||||
|
||||
let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
|
||||
baz::MyMono::spawn_after(1.secs(), 1, 2);
|
||||
let _: Result<(u32, u32), ()> = handle.unwrap().cancel();
|
||||
|
||||
// Using default
|
||||
let _: Result<baz::SpawnHandle, (u32, u32)> =
|
||||
baz::spawn_at(monotonics::MyMono::now(), 0, 1);
|
||||
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(1.secs(), 1, 2);
|
||||
let _: Result<baz::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
|
||||
|
||||
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(1.secs(), 1, 2);
|
||||
let _: Result<baz::SpawnHandle, ()> =
|
||||
handle.unwrap().reschedule_at(monotonics::MyMono::now());
|
||||
|
||||
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(1.secs(), 1, 2);
|
||||
let _: Result<(u32, u32), ()> = handle.unwrap().cancel();
|
||||
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn foo(_: foo::Context) {}
|
||||
|
||||
#[task]
|
||||
fn bar(_: bar::Context, _x: u32) {}
|
||||
|
||||
#[task]
|
||||
fn baz(_: baz::Context, _x: u32, _y: u32) {}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
//! [compile-pass] Check code generation of `spawn`
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local) {
|
||||
let _: Result<(), ()> = foo::spawn();
|
||||
let _: Result<(), u32> = bar::spawn(0);
|
||||
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(Shared {}, Local {})
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
let _: Result<(), ()> = foo::spawn();
|
||||
let _: Result<(), u32> = bar::spawn(0);
|
||||
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
||||
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
|
||||
#[task(binds = SVCall)]
|
||||
fn svcall(_: svcall::Context) {
|
||||
let _: Result<(), ()> = foo::spawn();
|
||||
let _: Result<(), u32> = bar::spawn(0);
|
||||
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
||||
}
|
||||
|
||||
#[task(binds = UART0)]
|
||||
fn uart0(_: uart0::Context) {
|
||||
let _: Result<(), ()> = foo::spawn();
|
||||
let _: Result<(), u32> = bar::spawn(0);
|
||||
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
||||
}
|
||||
|
||||
#[task]
|
||||
async fn foo(_: foo::Context) {
|
||||
let _: Result<(), ()> = foo::spawn();
|
||||
let _: Result<(), u32> = bar::spawn(0);
|
||||
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
||||
}
|
||||
|
||||
#[task]
|
||||
async fn bar(_: bar::Context, _x: u32) {}
|
||||
|
||||
#[task]
|
||||
async fn baz(_: baz::Context, _x: u32, _y: u32) {}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
//! examples/task.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![deny(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(missing_docs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use core::marker::PhantomData;
|
||||
use panic_semihosting as _;
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
//! examples/zero-prio-task.rs
|
||||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use core::marker::PhantomData;
|
||||
use panic_semihosting as _;
|
||||
|
||||
/// Does not impl send
|
||||
pub struct NotSend {
|
||||
_0: PhantomData<*const ()>,
|
||||
}
|
||||
|
||||
#[rtic::app(device = lm3s6965, peripherals = true)]
|
||||
mod app {
|
||||
use super::NotSend;
|
||||
use core::marker::PhantomData;
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
x: NotSend,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {
|
||||
y: NotSend,
|
||||
}
|
||||
|
||||
#[init]
|
||||
fn init(_cx: init::Context) -> (Shared, Local) {
|
||||
hprintln!("init");
|
||||
|
||||
async_task::spawn().unwrap();
|
||||
async_task2::spawn().unwrap();
|
||||
|
||||
(
|
||||
Shared {
|
||||
x: NotSend { _0: PhantomData },
|
||||
},
|
||||
Local {
|
||||
y: NotSend { _0: PhantomData },
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[task(priority = 0, shared = [x], local = [y])]
|
||||
async fn async_task(_: async_task::Context) {
|
||||
hprintln!("hello from async");
|
||||
}
|
||||
|
||||
#[task(priority = 0, shared = [x])]
|
||||
async fn async_task2(_: async_task2::Context) {
|
||||
hprintln!("hello from async2");
|
||||
}
|
||||
|
||||
#[idle(shared = [x])]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
hprintln!("hello from idle");
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
loop {}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue