mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-18 05:45:19 +01:00
The great docs update
This commit is contained in:
parent
c8621d78b9
commit
b71df58f2f
106 changed files with 1286 additions and 1429 deletions
|
|
@ -24,6 +24,7 @@ impl BigStruct {
|
|||
mod app {
|
||||
use super::BigStruct;
|
||||
use core::mem::MaybeUninit;
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
|
|
@ -41,6 +42,8 @@ mod app {
|
|||
&mut *cx.local.bs.as_mut_ptr()
|
||||
};
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(
|
||||
Shared {
|
||||
// assign the reference so we can use the resource
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ mod app {
|
|||
|
||||
rtic::pend(Interrupt::UART0);
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
|
|
|
|||
74
examples/cancel-reschedule.rs
Normal file
74
examples/cancel-reschedule.rs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
//! 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 rtic::time::duration::*;
|
||||
use systick_monotonic::Systick;
|
||||
|
||||
#[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
|
||||
let mono = Systick::new(systick, 12_000_000);
|
||||
|
||||
hprintln!("init").ok();
|
||||
|
||||
// Schedule `foo` to run 1 second in the future
|
||||
foo::spawn_after(1.seconds()).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.seconds()).unwrap();
|
||||
bar::spawn_after(1.seconds(), 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.seconds()).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
|
||||
}
|
||||
}
|
||||
|
|
@ -44,6 +44,6 @@ mod app {
|
|||
fn bar(_: bar::Context) {
|
||||
hprintln!("bar").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ mod app {
|
|||
|
||||
#[idle]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
|
|
|
|||
101
examples/common.rs
Normal file
101
examples/common.rs
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
//! 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 rtic::time::duration::*;
|
||||
use systick_monotonic::Systick; // Implements the `Monotonic` trait // Time helpers, such as `N.seconds()`
|
||||
|
||||
// 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;
|
||||
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.seconds()).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.seconds()).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();
|
||||
}
|
||||
}
|
||||
46
examples/declared_locals.rs
Normal file
46
examples/declared_locals.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
//! examples/declared_locals.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [UART0])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init(local = [a: u32 = 0])]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
// Locals in `#[init]` have 'static lifetime
|
||||
let _a: &'static mut u32 = cx.local.a;
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[idle(local = [a: u32 = 0])]
|
||||
fn idle(cx: idle::Context) -> ! {
|
||||
// Locals in `#[idle]` have 'static lifetime
|
||||
let _a: &'static mut u32 = cx.local.a;
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[task(local = [a: u32 = 0])]
|
||||
fn foo(cx: foo::Context) {
|
||||
// Locals in `#[task]`s have a local lifetime
|
||||
let _a: &mut u32 = cx.local.a;
|
||||
|
||||
// error: explicit lifetime required in the type of `cx`
|
||||
// let _a: &'static mut u32 = cx.local.a;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,14 +7,12 @@
|
|||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965)]
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [UART0])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::hprintln;
|
||||
use lm3s6965::Interrupt;
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
// Some resources to work with
|
||||
a: u32,
|
||||
b: u32,
|
||||
c: u32,
|
||||
|
|
@ -25,27 +23,33 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
rtic::pend(Interrupt::UART0);
|
||||
rtic::pend(Interrupt::UART1);
|
||||
foo::spawn().unwrap();
|
||||
bar::spawn().unwrap();
|
||||
|
||||
(Shared { a: 0, b: 0, c: 0 }, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
loop {}
|
||||
}
|
||||
|
||||
// Direct destructure
|
||||
#[task(binds = UART0, shared = [&a, &b, &c])]
|
||||
fn uart0(cx: uart0::Context) {
|
||||
#[task(shared = [&a, &b, &c])]
|
||||
fn foo(cx: foo::Context) {
|
||||
let a = cx.shared.a;
|
||||
let b = cx.shared.b;
|
||||
let c = cx.shared.c;
|
||||
|
||||
hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
||||
hprintln!("foo: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
||||
}
|
||||
|
||||
// De-structure-ing syntax
|
||||
#[task(binds = UART1, shared = [&a, &b, &c])]
|
||||
fn uart1(cx: uart1::Context) {
|
||||
let uart1::SharedResources { a, b, c } = cx.shared;
|
||||
#[task(shared = [&a, &b, &c])]
|
||||
fn bar(cx: bar::Context) {
|
||||
let bar::SharedResources { a, b, c } = cx.shared;
|
||||
|
||||
hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
||||
hprintln!("bar: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
//! examples/double_schedule.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||
mod app {
|
||||
use dwt_systick_monotonic::DwtSystick;
|
||||
use rtic::time::duration::Seconds;
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = DwtSystick<8_000_000>; // 8 MHz
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
task1::spawn().ok();
|
||||
|
||||
let mut dcb = cx.core.DCB;
|
||||
let dwt = cx.core.DWT;
|
||||
let systick = cx.core.SYST;
|
||||
|
||||
let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics(mono))
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn task1(_cx: task1::Context) {
|
||||
task2::spawn_after(Seconds(1_u32)).ok();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn task2(_cx: task2::Context) {
|
||||
task1::spawn_after(Seconds(1_u32)).ok();
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ mod app {
|
|||
|
||||
rtic::pend(Interrupt::UART0);
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use panic_semihosting as _;
|
|||
fn foo(_c: app::foo::Context, x: i32, y: u32) {
|
||||
hprintln!("foo {}, {}", x, y).unwrap();
|
||||
if x == 2 {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
app::foo::spawn(2, 3).unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ mod app {
|
|||
|
||||
rtic::pend(Interrupt::UART1);
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
#[task(binds = UART1, priority = 2, shared = [shared], local = [state: u32 = 0])]
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ mod app {
|
|||
|
||||
rtic::pend(Interrupt::UART0);
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ mod app {
|
|||
|
||||
hprintln!("idle").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ mod app {
|
|||
|
||||
hprintln!("init").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics())
|
||||
}
|
||||
|
|
|
|||
86
examples/locals.rs
Normal file
86
examples/locals.rs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
//! examples/locals.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [UART0, UART1])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {
|
||||
local_to_foo: i64,
|
||||
local_to_bar: i64,
|
||||
local_to_idle: i64,
|
||||
}
|
||||
|
||||
// `#[init]` cannot access locals from the `#[local]` struct as they are initialized here.
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
foo::spawn().unwrap();
|
||||
bar::spawn().unwrap();
|
||||
|
||||
(
|
||||
Shared {},
|
||||
// initial values for the `#[local]` resources
|
||||
Local {
|
||||
local_to_foo: 0,
|
||||
local_to_bar: 0,
|
||||
local_to_idle: 0,
|
||||
},
|
||||
init::Monotonics(),
|
||||
)
|
||||
}
|
||||
|
||||
// `local_to_idle` can only be accessed from this context
|
||||
#[idle(local = [local_to_idle])]
|
||||
fn idle(cx: idle::Context) -> ! {
|
||||
let local_to_idle = cx.local.local_to_idle;
|
||||
*local_to_idle += 1;
|
||||
|
||||
hprintln!("idle: local_to_idle = {}", local_to_idle).unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
// error: no `local_to_foo` field in `idle::LocalResources`
|
||||
// _cx.local.local_to_foo += 1;
|
||||
|
||||
// error: no `local_to_bar` field in `idle::LocalResources`
|
||||
// _cx.local.local_to_bar += 1;
|
||||
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
|
||||
// `local_to_foo` can only be accessed from this context
|
||||
#[task(local = [local_to_foo])]
|
||||
fn foo(cx: foo::Context) {
|
||||
let local_to_foo = cx.local.local_to_foo;
|
||||
*local_to_foo += 1;
|
||||
|
||||
// error: no `local_to_bar` field in `foo::LocalResources`
|
||||
// cx.local.local_to_bar += 1;
|
||||
|
||||
hprintln!("foo: local_to_foo = {}", local_to_foo).unwrap();
|
||||
}
|
||||
|
||||
// `shared` can only be accessed from this context
|
||||
#[task(local = [local_to_bar])]
|
||||
fn bar(cx: bar::Context) {
|
||||
let local_to_bar = cx.local.local_to_bar;
|
||||
*local_to_bar += 1;
|
||||
|
||||
// error: no `local_to_foo` field in `bar::LocalResources`
|
||||
// cx.local.local_to_foo += 1;
|
||||
|
||||
hprintln!("bar: local_to_bar = {}", local_to_bar).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
@ -7,10 +7,9 @@
|
|||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965)]
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
|
|
@ -23,38 +22,28 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
rtic::pend(Interrupt::GPIOA);
|
||||
foo::spawn().unwrap();
|
||||
|
||||
(Shared { counter: 0 }, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(binds = GPIOA, shared = [counter])] // <- same priority
|
||||
fn gpioa(c: gpioa::Context) {
|
||||
hprintln!("GPIOA/start").unwrap();
|
||||
rtic::pend(Interrupt::GPIOB);
|
||||
#[task(shared = [counter])] // <- same priority
|
||||
fn foo(c: foo::Context) {
|
||||
bar::spawn().unwrap();
|
||||
|
||||
*c.shared.counter += 1; // <- no lock API required
|
||||
let counter = *c.shared.counter;
|
||||
hprintln!(" GPIOA/counter = {}", counter).unwrap();
|
||||
|
||||
if counter == 5 {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
hprintln!("GPIOA/end").unwrap();
|
||||
hprintln!(" foo = {}", counter).unwrap();
|
||||
}
|
||||
|
||||
#[task(binds = GPIOB, shared = [counter])] // <- same priority
|
||||
fn gpiob(c: gpiob::Context) {
|
||||
hprintln!("GPIOB/start").unwrap();
|
||||
rtic::pend(Interrupt::GPIOA);
|
||||
#[task(shared = [counter])] // <- same priority
|
||||
fn bar(c: bar::Context) {
|
||||
foo::spawn().unwrap();
|
||||
|
||||
*c.shared.counter += 1; // <- no lock API required
|
||||
let counter = *c.shared.counter;
|
||||
hprintln!(" GPIOB/counter = {}", counter).unwrap();
|
||||
hprintln!(" bar = {}", counter).unwrap();
|
||||
|
||||
if counter == 5 {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
hprintln!("GPIOB/end").unwrap();
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@
|
|||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965)]
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA, GPIOB, GPIOC])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
|
|
@ -22,14 +21,14 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
rtic::pend(Interrupt::GPIOA);
|
||||
foo::spawn().unwrap();
|
||||
|
||||
(Shared { shared: 0 }, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
// when omitted priority is assumed to be `1`
|
||||
#[task(binds = GPIOA, shared = [shared])]
|
||||
fn gpioa(mut c: gpioa::Context) {
|
||||
#[task(shared = [shared])]
|
||||
fn foo(mut c: foo::Context) {
|
||||
hprintln!("A").unwrap();
|
||||
|
||||
// the lower priority task requires a critical section to access the data
|
||||
|
|
@ -37,24 +36,24 @@ mod app {
|
|||
// data can only be modified within this critical section (closure)
|
||||
*shared += 1;
|
||||
|
||||
// GPIOB will *not* run right now due to the critical section
|
||||
rtic::pend(Interrupt::GPIOB);
|
||||
// bar will *not* run right now due to the critical section
|
||||
bar::spawn().unwrap();
|
||||
|
||||
hprintln!("B - shared = {}", *shared).unwrap();
|
||||
|
||||
// GPIOC does not contend for `shared` so it's allowed to run now
|
||||
rtic::pend(Interrupt::GPIOC);
|
||||
// baz does not contend for `shared` so it's allowed to run now
|
||||
baz::spawn().unwrap();
|
||||
});
|
||||
|
||||
// critical section is over: GPIOB can now start
|
||||
// critical section is over: bar can now start
|
||||
|
||||
hprintln!("E").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
#[task(binds = GPIOB, priority = 2, shared = [shared])]
|
||||
fn gpiob(mut c: gpiob::Context) {
|
||||
#[task(priority = 2, shared = [shared])]
|
||||
fn bar(mut c: bar::Context) {
|
||||
// the higher priority task does still need a critical section
|
||||
let shared = c.shared.shared.lock(|shared| {
|
||||
*shared += 1;
|
||||
|
|
@ -65,8 +64,8 @@ mod app {
|
|||
hprintln!("D - shared = {}", shared).unwrap();
|
||||
}
|
||||
|
||||
#[task(binds = GPIOC, priority = 3)]
|
||||
fn gpioc(_: gpioc::Context) {
|
||||
#[task(priority = 3)]
|
||||
fn baz(_: baz::Context) {
|
||||
hprintln!("C").unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ mod app {
|
|||
hprintln!("baz({}, {})", x, y).unwrap();
|
||||
|
||||
if x + y > 4 {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
foo::spawn().unwrap();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//! examples/spawn2.rs
|
||||
//! examples/message_passing.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
|
|
@ -19,23 +19,19 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
foo::spawn(1, 1).unwrap();
|
||||
foo::spawn(1, 2).unwrap();
|
||||
foo::spawn(2, 3).unwrap();
|
||||
assert!(foo::spawn(1, 4).is_err()); // The capacity of `foo` is reached
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task]
|
||||
#[task(capacity = 3)]
|
||||
fn foo(_c: foo::Context, x: i32, y: u32) {
|
||||
hprintln!("foo {}, {}", x, y).unwrap();
|
||||
if x == 2 {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
foo2::spawn(2).unwrap();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn foo2(_c: foo2::Context, x: i32) {
|
||||
hprintln!("foo2 {}", x).unwrap();
|
||||
foo::spawn(x, 0).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
//! examples/mutlilock.rs
|
||||
//!
|
||||
//! The multi-lock feature example.
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
|
|
@ -9,10 +7,9 @@
|
|||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965)]
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
|
|
@ -26,7 +23,7 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
rtic::pend(Interrupt::GPIOA);
|
||||
locks::spawn().unwrap();
|
||||
|
||||
(
|
||||
Shared {
|
||||
|
|
@ -40,47 +37,20 @@ mod app {
|
|||
}
|
||||
|
||||
// when omitted priority is assumed to be `1`
|
||||
#[task(binds = GPIOA, shared = [shared1, shared2, shared3])]
|
||||
#[task(shared = [shared1, shared2, shared3])]
|
||||
fn locks(c: locks::Context) {
|
||||
let mut s1 = c.shared.shared1;
|
||||
let mut s2 = c.shared.shared2;
|
||||
let mut s3 = c.shared.shared3;
|
||||
|
||||
hprintln!("Multiple single locks").unwrap();
|
||||
s1.lock(|s1| {
|
||||
s2.lock(|s2| {
|
||||
s3.lock(|s3| {
|
||||
*s1 += 1;
|
||||
*s2 += 1;
|
||||
*s3 += 1;
|
||||
|
||||
hprintln!(
|
||||
"Multiple single locks, s1: {}, s2: {}, s3: {}",
|
||||
*s1,
|
||||
*s2,
|
||||
*s3
|
||||
)
|
||||
.unwrap();
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
hprintln!("Multilock!").unwrap();
|
||||
let s1 = c.shared.shared1;
|
||||
let s2 = c.shared.shared2;
|
||||
let s3 = c.shared.shared3;
|
||||
|
||||
(s1, s2, s3).lock(|s1, s2, s3| {
|
||||
*s1 += 1;
|
||||
*s2 += 1;
|
||||
*s3 += 1;
|
||||
|
||||
hprintln!(
|
||||
"Multiple single locks, s1: {}, s2: {}, s3: {}",
|
||||
*s1,
|
||||
*s2,
|
||||
*s3
|
||||
)
|
||||
.unwrap();
|
||||
hprintln!("Multiple locks, s1: {}, s2: {}, s3: {}", *s1, *s2, *s3).unwrap();
|
||||
});
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(
|
||||
Shared {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//! examples/static.rs
|
||||
//! examples/only-shared-access.rs
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
|
|
@ -7,10 +7,9 @@
|
|||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965)]
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [UART0, UART1])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
|
|
@ -22,22 +21,22 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
rtic::pend(Interrupt::UART0);
|
||||
rtic::pend(Interrupt::UART1);
|
||||
foo::spawn().unwrap();
|
||||
bar::spawn().unwrap();
|
||||
|
||||
(Shared { key: 0xdeadbeef }, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(binds = UART0, shared = [&key])]
|
||||
fn uart0(cx: uart0::Context) {
|
||||
#[task(shared = [&key])]
|
||||
fn foo(cx: foo::Context) {
|
||||
let key: &u32 = cx.shared.key;
|
||||
hprintln!("UART0(key = {:#x})", key).unwrap();
|
||||
hprintln!("foo(key = {:#x})", key).unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
#[task(binds = UART1, priority = 2, shared = [&key])]
|
||||
fn uart1(cx: uart1::Context) {
|
||||
hprintln!("UART1(key = {:#x})", cx.shared.key).unwrap();
|
||||
#[task(priority = 2, shared = [&key])]
|
||||
fn bar(cx: bar::Context) {
|
||||
hprintln!("bar(key = {:#x})", cx.shared.key).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,12 @@ use panic_semihosting as _;
|
|||
// NOTE: does NOT work on QEMU!
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||
mod app {
|
||||
use dwt_systick_monotonic::DwtSystick;
|
||||
use rtic::time::duration::Seconds;
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use rtic::time::duration::*;
|
||||
use systick_monotonic::Systick;
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = DwtSystick<8_000_000>; // 8 MHz
|
||||
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
|
@ -24,20 +25,25 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
let mut dcb = cx.core.DCB;
|
||||
let dwt = cx.core.DWT;
|
||||
let systick = cx.core.SYST;
|
||||
|
||||
let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
|
||||
let mono = Systick::new(systick, 12_000_000);
|
||||
|
||||
foo::spawn_after(Seconds(1_u32)).unwrap();
|
||||
foo::spawn_after(1.seconds()).unwrap();
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics(mono))
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn foo(_cx: foo::Context) {
|
||||
// Periodic
|
||||
foo::spawn_after(Seconds(1_u32)).unwrap();
|
||||
#[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 ever 1 seconds
|
||||
foo::spawn_after(1.seconds()).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ mod app {
|
|||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
assert!(cortex_m::Peripherals::take().is_none());
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ mod app {
|
|||
// explicitly return the block to the pool
|
||||
drop(x);
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
#[task(priority = 2)]
|
||||
|
|
|
|||
|
|
@ -6,10 +6,9 @@
|
|||
use panic_semihosting as _;
|
||||
use rtic::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
#[app(device = lm3s6965, dispatchers = [SSI0, QEI0])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
|
@ -19,28 +18,28 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
rtic::pend(Interrupt::GPIOA);
|
||||
foo::spawn().unwrap();
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task(binds = GPIOA, priority = 1)]
|
||||
fn gpioa(_: gpioa::Context) {
|
||||
hprintln!("GPIOA - start").unwrap();
|
||||
rtic::pend(Interrupt::GPIOC);
|
||||
hprintln!("GPIOA - end").unwrap();
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
#[task(priority = 1)]
|
||||
fn foo(_: foo::Context) {
|
||||
hprintln!("foo - start").unwrap();
|
||||
baz::spawn().unwrap();
|
||||
hprintln!("foo - end").unwrap();
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
#[task(binds = GPIOB, priority = 2)]
|
||||
fn gpiob(_: gpiob::Context) {
|
||||
hprintln!(" GPIOB").unwrap();
|
||||
#[task(priority = 2)]
|
||||
fn bar(_: bar::Context) {
|
||||
hprintln!(" bar").unwrap();
|
||||
}
|
||||
|
||||
#[task(binds = GPIOC, priority = 2)]
|
||||
fn gpioc(_: gpioc::Context) {
|
||||
hprintln!(" GPIOC - start").unwrap();
|
||||
rtic::pend(Interrupt::GPIOB);
|
||||
hprintln!(" GPIOC - end").unwrap();
|
||||
#[task(priority = 2)]
|
||||
fn baz(_: baz::Context) {
|
||||
hprintln!(" baz - start").unwrap();
|
||||
bar::spawn().unwrap();
|
||||
hprintln!(" baz - end").unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ mod app {
|
|||
fn foo(_: foo::Context) {
|
||||
hprintln!("foo").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
// run this task from RAM
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ mod app {
|
|||
// `shared` cannot be accessed from this context
|
||||
#[idle]
|
||||
fn idle(_cx: idle::Context) -> ! {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
// error: no `shared` field in `idle::Context`
|
||||
// _cx.shared.shared += 1;
|
||||
|
|
|
|||
|
|
@ -1,81 +0,0 @@
|
|||
//! examples/resource.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;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {
|
||||
local_to_uart0: i64,
|
||||
local_to_uart1: i64,
|
||||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
rtic::pend(Interrupt::UART0);
|
||||
rtic::pend(Interrupt::UART1);
|
||||
|
||||
(
|
||||
Shared {},
|
||||
// initial values for the `#[local]` resources
|
||||
Local {
|
||||
local_to_uart0: 0,
|
||||
local_to_uart1: 0,
|
||||
},
|
||||
init::Monotonics(),
|
||||
)
|
||||
}
|
||||
|
||||
// `#[local]` resources cannot be accessed from this context
|
||||
#[idle]
|
||||
fn idle(_cx: idle::Context) -> ! {
|
||||
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;
|
||||
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
|
||||
// `local_to_uart0` can only be accessed from this context
|
||||
// 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();
|
||||
}
|
||||
|
||||
// `shared` can only be accessed from this context
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -7,17 +7,14 @@
|
|||
|
||||
use panic_semihosting as _;
|
||||
|
||||
// NOTE: does NOT work on QEMU!
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::hprintln;
|
||||
use dwt_systick_monotonic::DwtSystick;
|
||||
use rtic::time::duration::Seconds;
|
||||
|
||||
const MONO_HZ: u32 = 8_000_000; // 8 MHz
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use rtic::time::duration::*;
|
||||
use systick_monotonic::Systick;
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = DwtSystick<MONO_HZ>;
|
||||
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
|
@ -27,30 +24,42 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
let mut dcb = cx.core.DCB;
|
||||
let dwt = cx.core.DWT;
|
||||
let systick = cx.core.SYST;
|
||||
|
||||
let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
|
||||
// Initialize the monotonic
|
||||
let mono = Systick::new(systick, 12_000_000);
|
||||
|
||||
hprintln!("init").ok();
|
||||
|
||||
// Schedule `foo` to run 1 second in the future
|
||||
foo::spawn_after(Seconds(1_u32)).ok();
|
||||
foo::spawn_after(1.seconds()).unwrap();
|
||||
|
||||
// Schedule `bar` to run 2 seconds in the future
|
||||
bar::spawn_after(Seconds(2_u32)).ok();
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics(mono))
|
||||
(
|
||||
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.seconds()).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.seconds()).unwrap();
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn baz(_: baz::Context) {
|
||||
hprintln!("baz").ok();
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ mod app {
|
|||
if let Some(byte) = c.shared.c.lock(|c| c.dequeue()) {
|
||||
hprintln!("received message: {}", byte).unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
} else {
|
||||
rtic::pend(Interrupt::UART0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ use rtic::app;
|
|||
|
||||
#[app(device = lm3s6965)]
|
||||
mod app {
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
|
|
@ -16,6 +18,7 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
(Shared {}, Local {}, init::Monotonics())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,17 +19,16 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
foo::spawn(1, 2).unwrap();
|
||||
hprintln!("init").unwrap();
|
||||
foo::spawn().unwrap();
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
#[task()]
|
||||
fn foo(_c: foo::Context, x: i32, y: u32) {
|
||||
hprintln!("foo {}, {}", x, y).unwrap();
|
||||
if x == 2 {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
}
|
||||
foo::spawn(2, 3).unwrap();
|
||||
#[task]
|
||||
fn foo(_: foo::Context) {
|
||||
hprintln!("foo").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,45 +7,53 @@
|
|||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965)]
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [UART0])]
|
||||
mod app {
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use heapless::spsc::{Consumer, Producer, Queue};
|
||||
use lm3s6965::Interrupt;
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {
|
||||
p: Producer<'static, u32, 5>,
|
||||
c: Consumer<'static, u32, 5>,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init(local = [q: Queue<u32, 5> = Queue::new()])]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
// q has 'static life-time so after the split and return of `init`
|
||||
// it will continue to exist and be allocated
|
||||
let (p, c) = cx.local.q.split();
|
||||
|
||||
(Shared { p, c }, Local {}, init::Monotonics())
|
||||
foo::spawn().unwrap();
|
||||
|
||||
(Shared {}, Local { p, c }, init::Monotonics())
|
||||
}
|
||||
|
||||
#[idle(shared = [c])]
|
||||
fn idle(mut c: idle::Context) -> ! {
|
||||
#[idle(local = [c])]
|
||||
fn idle(c: idle::Context) -> ! {
|
||||
loop {
|
||||
if let Some(byte) = c.shared.c.lock(|c| c.dequeue()) {
|
||||
hprintln!("received message: {}", byte).unwrap();
|
||||
// Lock-free access to the same underlying queue!
|
||||
if let Some(data) = c.local.c.dequeue() {
|
||||
hprintln!("received message: {}", data).unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
} else {
|
||||
rtic::pend(Interrupt::UART0);
|
||||
// Run foo until data
|
||||
if data == 3 {
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
} else {
|
||||
foo::spawn().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[task(binds = UART0, shared = [p], local = [kalle: u32 = 0])]
|
||||
fn uart0(mut c: uart0::Context) {
|
||||
*c.local.kalle += 1;
|
||||
c.shared.p.lock(|p| p.enqueue(42).unwrap());
|
||||
#[task(local = [p, state: u32 = 0])]
|
||||
fn foo(c: foo::Context) {
|
||||
*c.local.state += 1;
|
||||
|
||||
// Lock-free access to the same underlying queue!
|
||||
c.local.p.enqueue(*c.local.state).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ use panic_semihosting as _;
|
|||
|
||||
#[rtic::app(device = lm3s6965)]
|
||||
mod app {
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
|
|
@ -17,6 +19,8 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ use panic_semihosting as _;
|
|||
|
||||
#[rtic::app(device = lm3s6965)]
|
||||
mod app {
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
// A conditionally compiled resource behind feature_x
|
||||
|
|
@ -19,6 +21,8 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(
|
||||
Shared {
|
||||
#[cfg(feature = "feature_x")]
|
||||
|
|
|
|||
|
|
@ -24,6 +24,6 @@ mod app {
|
|||
|
||||
#[task(binds = UART0)]
|
||||
fn taskmain(_: taskmain::Context) {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ mod app {
|
|||
|
||||
#[idle]
|
||||
fn taskmain(_: taskmain::Context) -> ! {
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ pub struct NotSend {
|
|||
mod app {
|
||||
use super::NotSend;
|
||||
use core::marker::PhantomData;
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
|
|
@ -39,6 +40,7 @@ mod app {
|
|||
|
||||
#[idle(shared = [x, y])]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ use panic_semihosting as _;
|
|||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||
mod app {
|
||||
use dwt_systick_monotonic::DwtSystick;
|
||||
use cortex_m_semihosting::debug;
|
||||
use rtic::time::duration::Seconds;
|
||||
use systick_monotonic::Systick;
|
||||
|
||||
#[monotonic(binds = SysTick, default = true)]
|
||||
type MyMono = DwtSystick<8_000_000>; // 8 MHz
|
||||
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
|
@ -23,12 +24,17 @@ mod app {
|
|||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||
let mut dcb = cx.core.DCB;
|
||||
let dwt = cx.core.DWT;
|
||||
let systick = cx.core.SYST;
|
||||
|
||||
let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
|
||||
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
|
||||
|
|
@ -120,11 +126,6 @@ mod app {
|
|||
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(Seconds(1_u32), 0, 1);
|
||||
let _: Result<(u32, u32), ()> = handle.unwrap().cancel();
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics(mono))
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
loop {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ use panic_semihosting as _;
|
|||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::debug;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
|
|
@ -21,6 +23,8 @@ mod app {
|
|||
let _: Result<(), u32> = bar::spawn(0);
|
||||
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
|
||||
(Shared {}, Local {}, init::Monotonics())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ mod app {
|
|||
fn bar(_: bar::Context) {
|
||||
hprintln!("bar").unwrap();
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
|
||||
#[task(priority = 2)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue