mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
more examples
This commit is contained in:
parent
5606ba3cf3
commit
9a4f97ca5e
42 changed files with 192 additions and 151 deletions
11
Cargo.toml
11
Cargo.toml
|
@ -49,10 +49,7 @@ codegen-units = 1
|
||||||
lto = true
|
lto = true
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = ["macros", "xtask"]
|
||||||
"macros",
|
|
||||||
"xtask",
|
|
||||||
]
|
|
||||||
|
|
||||||
# do not optimize proc-macro deps or build scripts
|
# do not optimize proc-macro deps or build scripts
|
||||||
[profile.dev.build-override]
|
[profile.dev.build-override]
|
||||||
|
@ -76,6 +73,6 @@ lm3s6965 = { git = "https://github.com/japaric/lm3s6965" }
|
||||||
[features]
|
[features]
|
||||||
test-critical-section = ["cortex-m/critical-section-single-core"]
|
test-critical-section = ["cortex-m/critical-section-single-core"]
|
||||||
|
|
||||||
[[example]]
|
# [[example]]
|
||||||
name = "pool"
|
# name = "pool"
|
||||||
required-features = ["test-critical-section"]
|
# required-features = ["test-critical-section"]
|
||||||
|
|
|
@ -19,18 +19,14 @@ mod app {
|
||||||
type MyMono = Systick<100>;
|
type MyMono = Systick<100>;
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local) {
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
foo::spawn().ok();
|
foo::spawn().ok();
|
||||||
bar::spawn().ok();
|
bar::spawn().ok();
|
||||||
baz::spawn().ok();
|
baz::spawn().ok();
|
||||||
|
|
||||||
(
|
(Shared {}, Local {})
|
||||||
Shared {},
|
|
||||||
Local {},
|
|
||||||
init::Monotonics(Systick::new(cx.core.SYST, 12_000_000)),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
|
@ -19,16 +19,12 @@ mod app {
|
||||||
type MyMono = Systick<100>;
|
type MyMono = Systick<100>;
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local) {
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
foo::spawn().ok();
|
foo::spawn().ok();
|
||||||
|
|
||||||
(
|
(Shared {}, Local {})
|
||||||
Shared {},
|
|
||||||
Local {},
|
|
||||||
init::Monotonics(Systick::new(cx.core.SYST, 12_000_000)),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
|
@ -6,14 +6,13 @@ use panic_semihosting as _;
|
||||||
|
|
||||||
// NOTES:
|
// NOTES:
|
||||||
//
|
//
|
||||||
// - Async tasks cannot have `#[lock_free]` resources, as they can interleve and each async
|
// - Async tasks cannot have `#[lock_free]` resources, as they can interleave and each async
|
||||||
// task can have a mutable reference stored.
|
// task can have a mutable reference stored.
|
||||||
// - Spawning an async task equates to it being polled once.
|
// - Spawning an async task equates to it being polled once.
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0, UART0, UART1], peripherals = true)]
|
#[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0])]
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use systick_monotonic::*;
|
|
||||||
|
|
||||||
#[shared]
|
#[shared]
|
||||||
struct Shared {
|
struct Shared {
|
||||||
|
@ -24,53 +23,71 @@ mod app {
|
||||||
#[local]
|
#[local]
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[monotonic(binds = SysTick, default = true)]
|
|
||||||
type MyMono = Systick<100>;
|
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local) {
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
normal_task::spawn().ok();
|
async_task1::spawn().ok();
|
||||||
async_task::spawn().ok();
|
|
||||||
normal_task2::spawn().ok();
|
|
||||||
async_task2::spawn().ok();
|
async_task2::spawn().ok();
|
||||||
|
async_task3::spawn().ok();
|
||||||
|
async_task4::spawn().ok();
|
||||||
|
|
||||||
(
|
(Shared { a: 0, b: 0 }, Local {})
|
||||||
Shared { a: 0, b: 0 },
|
|
||||||
Local {},
|
|
||||||
init::Monotonics(Systick::new(cx.core.SYST, 12_000_000)),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
fn idle(_: idle::Context) -> ! {
|
fn idle(_: idle::Context) -> ! {
|
||||||
// debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
loop {
|
loop {
|
||||||
// hprintln!("idle");
|
hprintln!("idle");
|
||||||
cortex_m::asm::wfi(); // put the MCU in sleep mode until interrupt occurs
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 1, shared = [a, b])]
|
#[task(priority = 1, shared = [a, b])]
|
||||||
fn normal_task(_cx: normal_task::Context) {
|
async fn async_task1(mut cx: async_task1::Context) {
|
||||||
hprintln!("hello from normal 1").ok();
|
hprintln!(
|
||||||
|
"hello from async 1 a {}",
|
||||||
|
cx.shared.a.lock(|a| {
|
||||||
|
*a += 1;
|
||||||
|
*a
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 1, shared = [a, b])]
|
#[task(priority = 1, shared = [a, b])]
|
||||||
async fn async_task(_cx: async_task::Context) {
|
async fn async_task2(mut cx: async_task2::Context) {
|
||||||
hprintln!("hello from async 1").ok();
|
hprintln!(
|
||||||
|
"hello from async 2 a {}",
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
cx.shared.a.lock(|a| {
|
||||||
|
*a += 1;
|
||||||
|
*a
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 2, shared = [a, b])]
|
#[task(priority = 2, shared = [a, b])]
|
||||||
fn normal_task2(_cx: normal_task2::Context) {
|
async fn async_task3(mut cx: async_task3::Context) {
|
||||||
hprintln!("hello from normal 2").ok();
|
hprintln!(
|
||||||
|
"hello from async 3 a {}",
|
||||||
|
cx.shared.a.lock(|a| {
|
||||||
|
*a += 1;
|
||||||
|
*a
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 2, shared = [a, b])]
|
#[task(priority = 2, shared = [a, b])]
|
||||||
async fn async_task2(_cx: async_task2::Context) {
|
async fn async_task4(mut cx: async_task4::Context) {
|
||||||
hprintln!("hello from async 2").ok();
|
hprintln!(
|
||||||
|
"hello from async 4 a {}",
|
||||||
|
cx.shared.a.lock(|a| {
|
||||||
|
*a += 1;
|
||||||
|
*a
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,9 @@ mod app {
|
||||||
|
|
||||||
#[idle(shared = [a])]
|
#[idle(shared = [a])]
|
||||||
fn idle(_: idle::Context) -> ! {
|
fn idle(_: idle::Context) -> ! {
|
||||||
// debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
loop {
|
loop {
|
||||||
// hprintln!("idle");
|
hprintln!("idle");
|
||||||
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
cortex_m::asm::wfi(); // put the MCU in sleep mode until interrupt occurs
|
cortex_m::asm::wfi(); // put the MCU in sleep mode until interrupt occurs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,6 @@ mod app {
|
||||||
async fn async_task(cx: async_task::Context) {
|
async fn async_task(cx: async_task::Context) {
|
||||||
let async_task::SharedResources { a: _, .. } = cx.shared;
|
let async_task::SharedResources { a: _, .. } = cx.shared;
|
||||||
hprintln!("hello from async").ok();
|
hprintln!("hello from async").ok();
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 2, shared = [a])]
|
#[task(priority = 2, shared = [a])]
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
|
@ -20,11 +21,12 @@ impl BigStruct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||||
mod app {
|
mod app {
|
||||||
use super::BigStruct;
|
use super::BigStruct;
|
||||||
use core::mem::MaybeUninit;
|
use core::mem::MaybeUninit;
|
||||||
use cortex_m_semihosting::debug;
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
#[shared]
|
#[shared]
|
||||||
struct Shared {
|
struct Shared {
|
||||||
|
@ -35,25 +37,43 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init(local = [bs: MaybeUninit<BigStruct> = MaybeUninit::uninit()])]
|
#[init(local = [bs: MaybeUninit<BigStruct> = MaybeUninit::uninit()])]
|
||||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local) {
|
||||||
let big_struct = unsafe {
|
let big_struct = unsafe {
|
||||||
// write directly into the static storage
|
// write directly into the static storage
|
||||||
cx.local.bs.as_mut_ptr().write(BigStruct::new());
|
cx.local.bs.as_mut_ptr().write(BigStruct::new());
|
||||||
&mut *cx.local.bs.as_mut_ptr()
|
&mut *cx.local.bs.as_mut_ptr()
|
||||||
};
|
};
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
rtic::pend(Interrupt::UART0);
|
||||||
|
async_task::spawn().unwrap();
|
||||||
(
|
(
|
||||||
Shared {
|
Shared {
|
||||||
// assign the reference so we can use the resource
|
// assign the reference so we can use the resource
|
||||||
big_struct,
|
big_struct,
|
||||||
},
|
},
|
||||||
Local {},
|
Local {},
|
||||||
init::Monotonics(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[idle]
|
||||||
|
fn idle(_: idle::Context) -> ! {
|
||||||
|
loop {
|
||||||
|
hprintln!("idle");
|
||||||
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[task(binds = UART0, shared = [big_struct])]
|
#[task(binds = UART0, shared = [big_struct])]
|
||||||
fn task(_: task::Context) {}
|
fn uart0(mut cx: uart0::Context) {
|
||||||
|
cx.shared
|
||||||
|
.big_struct
|
||||||
|
.lock(|b| hprintln!("uart0 data:{:?}", &b.data[0..5]).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[task(shared = [big_struct], priority = 2)]
|
||||||
|
async fn async_task(mut cx: async_task::Context) {
|
||||||
|
cx.shared
|
||||||
|
.big_struct
|
||||||
|
.lock(|b| hprintln!("async_task data:{:?}", &b.data[0..5]).unwrap());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,12 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
|
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
|
|
@ -24,7 +24,7 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -34,7 +34,6 @@ mod app {
|
||||||
s4: 0,
|
s4: 0,
|
||||||
},
|
},
|
||||||
Local {},
|
Local {},
|
||||||
init::Monotonics(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [UART0])]
|
#[rtic::app(device = lm3s6965)]
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::debug;
|
use cortex_m_semihosting::debug;
|
||||||
|
|
||||||
|
@ -18,13 +18,13 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init(local = [a: u32 = 0])]
|
#[init(local = [a: u32 = 0])]
|
||||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local) {
|
||||||
// Locals in `#[init]` have 'static lifetime
|
// Locals in `#[init]` have 'static lifetime
|
||||||
let _a: &'static mut u32 = cx.local.a;
|
let _a: &'static mut u32 = cx.local.a;
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle(local = [a: u32 = 0])]
|
#[idle(local = [a: u32 = 0])]
|
||||||
|
@ -35,7 +35,7 @@ mod app {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [a: u32 = 0])]
|
#[task(binds = UART0, local = [a: u32 = 0])]
|
||||||
fn foo(cx: foo::Context) {
|
fn foo(cx: foo::Context) {
|
||||||
// Locals in `#[task]`s have a local lifetime
|
// Locals in `#[task]`s have a local lifetime
|
||||||
let _a: &mut u32 = cx.local.a;
|
let _a: &mut u32 = cx.local.a;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
|
@ -22,11 +23,11 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
bar::spawn().unwrap();
|
bar::spawn().unwrap();
|
||||||
|
|
||||||
(Shared { a: 0, b: 0, c: 0 }, Local {}, init::Monotonics())
|
(Shared { a: 0, b: 1, c: 2 }, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
@ -37,7 +38,7 @@ mod app {
|
||||||
|
|
||||||
// Direct destructure
|
// Direct destructure
|
||||||
#[task(shared = [&a, &b, &c])]
|
#[task(shared = [&a, &b, &c])]
|
||||||
fn foo(cx: foo::Context) {
|
async fn foo(cx: foo::Context) {
|
||||||
let a = cx.shared.a;
|
let a = cx.shared.a;
|
||||||
let b = cx.shared.b;
|
let b = cx.shared.b;
|
||||||
let c = cx.shared.c;
|
let c = cx.shared.c;
|
||||||
|
@ -47,8 +48,8 @@ mod app {
|
||||||
|
|
||||||
// De-structure-ing syntax
|
// De-structure-ing syntax
|
||||||
#[task(shared = [&a, &b, &c])]
|
#[task(shared = [&a, &b, &c])]
|
||||||
fn bar(cx: bar::Context) {
|
async fn bar(cx: bar::Context) {
|
||||||
let bar::SharedResources { a, b, c } = cx.shared;
|
let bar::SharedResources { a, b, c, .. } = cx.shared;
|
||||||
|
|
||||||
hprintln!("bar: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
hprintln!("bar: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,12 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
|
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
|
|
@ -4,17 +4,16 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
// Free function implementing the spawnable task `foo`.
|
// Free function implementing the spawnable task `foo`.
|
||||||
fn foo(_c: app::foo::Context, x: i32, y: u32) {
|
// Notice, you need to indicate an anonymous lifetime <'a_>
|
||||||
hprintln!("foo {}, {}", x, y).unwrap();
|
async fn foo(_c: app::foo::Context<'_>) {
|
||||||
if x == 2 {
|
hprintln!("foo").unwrap();
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
}
|
|
||||||
app::foo::spawn(2, 3).unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||||
|
@ -28,14 +27,14 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
foo::spawn(1, 2).unwrap();
|
foo::spawn().unwrap();
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "Rust" {
|
extern "Rust" {
|
||||||
#[task()]
|
#[task()]
|
||||||
fn foo(_c: foo::Context, _x: i32, _y: u32);
|
async fn foo(_c: foo::Context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,11 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
rtic::pend(Interrupt::UART1);
|
rtic::pend(Interrupt::UART1);
|
||||||
|
|
||||||
(Shared { shared: 0 }, Local {}, init::Monotonics())
|
(Shared { shared: 0 }, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART0, shared = [shared], local = [state: u32 = 0])]
|
#[task(binds = UART0, shared = [shared], local = [state: u32 = 0])]
|
||||||
|
|
|
@ -19,14 +19,14 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
// Pends the UART0 interrupt but its handler won't run until *after*
|
// Pends the UART0 interrupt but its handler won't run until *after*
|
||||||
// `init` returns because interrupts are disabled
|
// `init` returns because interrupts are disabled
|
||||||
rtic::pend(Interrupt::UART0); // equivalent to NVIC::pend
|
rtic::pend(Interrupt::UART0); // equivalent to NVIC::pend
|
||||||
|
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
|
|
@ -4,12 +4,14 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
pub struct NotSync {
|
pub struct NotSync {
|
||||||
_0: PhantomData<*const ()>,
|
_0: PhantomData<*const ()>,
|
||||||
|
data: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for NotSync {}
|
unsafe impl Send for NotSync {}
|
||||||
|
@ -18,7 +20,7 @@ unsafe impl Send for NotSync {}
|
||||||
mod app {
|
mod app {
|
||||||
use super::NotSync;
|
use super::NotSync;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use cortex_m_semihosting::debug;
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
|
|
||||||
#[shared]
|
#[shared]
|
||||||
struct Shared {
|
struct Shared {
|
||||||
|
@ -29,25 +31,37 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
|
foo::spawn().unwrap();
|
||||||
|
bar::spawn().unwrap();
|
||||||
(
|
(
|
||||||
Shared {
|
Shared {
|
||||||
shared: NotSync { _0: PhantomData },
|
shared: NotSync {
|
||||||
|
_0: PhantomData,
|
||||||
|
data: 13,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Local {},
|
Local {},
|
||||||
init::Monotonics(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(shared = [&shared])]
|
#[idle]
|
||||||
fn foo(c: foo::Context) {
|
fn idle(_: idle::Context) -> ! {
|
||||||
let _: &NotSync = c.shared.shared;
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(shared = [&shared])]
|
#[task(shared = [&shared])]
|
||||||
fn bar(c: bar::Context) {
|
async fn foo(c: foo::Context) {
|
||||||
let _: &NotSync = c.shared.shared;
|
let shared: &NotSync = c.shared.shared;
|
||||||
|
hprintln!("foo a {}", shared.data).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[task(shared = [&shared])]
|
||||||
|
async fn bar(c: bar::Context) {
|
||||||
|
let shared: &NotSync = c.shared.shared;
|
||||||
|
hprintln!("foo a {}", shared.data).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
|
@ -20,15 +21,15 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
bar::spawn().unwrap();
|
bar::spawn().unwrap();
|
||||||
|
|
||||||
(Shared { key: 0xdeadbeef }, Local {}, init::Monotonics())
|
(Shared { key: 0xdeadbeef }, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(shared = [&key])]
|
#[task(shared = [&key])]
|
||||||
fn foo(cx: foo::Context) {
|
async fn foo(cx: foo::Context) {
|
||||||
let key: &u32 = cx.shared.key;
|
let key: &u32 = cx.shared.key;
|
||||||
hprintln!("foo(key = {:#x})", key).unwrap();
|
hprintln!("foo(key = {:#x})", key).unwrap();
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 2, shared = [&key])]
|
#[task(priority = 2, shared = [&key])]
|
||||||
fn bar(cx: bar::Context) {
|
async fn bar(cx: bar::Context) {
|
||||||
hprintln!("bar(key = {:#x})", cx.shared.key).unwrap();
|
hprintln!("bar(key = {:#x})", cx.shared.key).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,10 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
assert!(cortex_m::Peripherals::take().is_none());
|
assert!(cortex_m::Peripherals::take().is_none());
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,17 +31,17 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init(local = [memory: [u8; 512] = [0; 512]])]
|
#[init(local = [memory: [u8; 512] = [0; 512]])]
|
||||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local) {
|
||||||
// Increase the capacity of the memory pool by ~4
|
// Increase the capacity of the memory pool by ~4
|
||||||
P::grow(cx.local.memory);
|
P::grow(cx.local.memory);
|
||||||
|
|
||||||
rtic::pend(Interrupt::I2C0);
|
rtic::pend(Interrupt::I2C0);
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = I2C0, priority = 2)]
|
#[task(binds = I2C0, priority = 2)]
|
||||||
fn i2c0(_: i2c0::Context) {
|
async fn i2c0(_: i2c0::Context) {
|
||||||
// claim a memory block, initialize it and ..
|
// claim a memory block, initialize it and ..
|
||||||
let x = P::alloc().unwrap().init([0u8; 128]);
|
let x = P::alloc().unwrap().init([0u8; 128]);
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
fn foo(_: foo::Context, _x: Box<P>) {
|
async fn foo(_: foo::Context, _x: Box<P>) {
|
||||||
// explicitly return the block to the pool
|
// explicitly return the block to the pool
|
||||||
drop(_x);
|
drop(_x);
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 2)]
|
#[task(priority = 2)]
|
||||||
fn bar(_: bar::Context, _x: Box<P>) {
|
async fn bar(_: bar::Context, _x: Box<P>) {
|
||||||
// this is done automatically so we can omit the call to `drop`
|
// this is done automatically so we can omit the call to `drop`
|
||||||
// drop(x);
|
// drop(_x);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
use rtic::app;
|
use rtic::app;
|
||||||
|
@ -17,14 +18,14 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 1)]
|
#[task(priority = 1)]
|
||||||
fn foo(_: foo::Context) {
|
async fn foo(_: foo::Context) {
|
||||||
hprintln!("foo - start").unwrap();
|
hprintln!("foo - start").unwrap();
|
||||||
baz::spawn().unwrap();
|
baz::spawn().unwrap();
|
||||||
hprintln!("foo - end").unwrap();
|
hprintln!("foo - end").unwrap();
|
||||||
|
@ -32,12 +33,12 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 2)]
|
#[task(priority = 2)]
|
||||||
fn bar(_: bar::Context) {
|
async fn bar(_: bar::Context) {
|
||||||
hprintln!(" bar").unwrap();
|
hprintln!(" bar").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 2)]
|
#[task(priority = 2)]
|
||||||
fn baz(_: baz::Context) {
|
async fn baz(_: baz::Context) {
|
||||||
hprintln!(" baz - start").unwrap();
|
hprintln!(" baz - start").unwrap();
|
||||||
bar::spawn().unwrap();
|
bar::spawn().unwrap();
|
||||||
hprintln!(" baz - end").unwrap();
|
hprintln!(" baz - end").unwrap();
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
#[rtic::app(
|
#[rtic::app(
|
||||||
|
@ -24,15 +24,15 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[task]
|
#[task]
|
||||||
fn foo(_: foo::Context) {
|
async fn foo(_: foo::Context) {
|
||||||
hprintln!("foo").unwrap();
|
hprintln!("foo").unwrap();
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
|
@ -42,7 +42,7 @@ mod app {
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[link_section = ".data.bar"]
|
#[link_section = ".data.bar"]
|
||||||
#[task(priority = 2)]
|
#[task(priority = 2)]
|
||||||
fn bar(_: bar::Context) {
|
async fn bar(_: bar::Context) {
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,11 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
rtic::pend(Interrupt::UART1);
|
rtic::pend(Interrupt::UART1);
|
||||||
|
|
||||||
(Shared { shared: 0 }, Local {}, init::Monotonics())
|
(Shared { shared: 0 }, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
// `shared` cannot be accessed from this context
|
// `shared` cannot be accessed from this context
|
||||||
|
|
|
@ -23,11 +23,11 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init(local = [q: Queue<u32, 5> = Queue::new()])]
|
#[init(local = [q: Queue<u32, 5> = Queue::new()])]
|
||||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local) {
|
||||||
let (p, c) = cx.local.q.split();
|
let (p, c) = cx.local.q.split();
|
||||||
|
|
||||||
// Initialization of shared resources
|
// Initialization of shared resources
|
||||||
(Shared { p, c }, Local {}, init::Monotonics())
|
(Shared { p, c }, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle(shared = [c])]
|
#[idle(shared = [c])]
|
||||||
|
|
|
@ -17,8 +17,8 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
|
@ -18,15 +19,15 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
fn foo(_: foo::Context) {
|
async fn foo(_: foo::Context) {
|
||||||
hprintln!("foo").unwrap();
|
hprintln!("foo").unwrap();
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
|
@ -22,14 +23,14 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[init(local = [q: Queue<u32, 5> = Queue::new()])]
|
#[init(local = [q: Queue<u32, 5> = Queue::new()])]
|
||||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local) {
|
||||||
// q has 'static life-time so after the split and return of `init`
|
// q has 'static life-time so after the split and return of `init`
|
||||||
// it will continue to exist and be allocated
|
// it will continue to exist and be allocated
|
||||||
let (p, c) = cx.local.q.split();
|
let (p, c) = cx.local.q.split();
|
||||||
|
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
|
|
||||||
(Shared {}, Local { p, c }, init::Monotonics())
|
(Shared {}, Local { p, c })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle(local = [c])]
|
#[idle(local = [c])]
|
||||||
|
@ -50,7 +51,7 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [p, state: u32 = 0])]
|
#[task(local = [p, state: u32 = 0])]
|
||||||
fn foo(c: foo::Context) {
|
async fn foo(c: foo::Context) {
|
||||||
*c.local.state += 1;
|
*c.local.state += 1;
|
||||||
|
|
||||||
// Lock-free access to the same underlying queue!
|
// Lock-free access to the same underlying queue!
|
||||||
|
|
|
@ -18,10 +18,10 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cortex-M exception
|
// Cortex-M exception
|
||||||
|
|
|
@ -20,7 +20,7 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -29,7 +29,6 @@ mod app {
|
||||||
x: 0,
|
x: 0,
|
||||||
},
|
},
|
||||||
Local {},
|
Local {},
|
||||||
init::Monotonics(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
rtic::pend(lm3s6965::Interrupt::UART0);
|
rtic::pend(lm3s6965::Interrupt::UART0);
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART0)]
|
#[task(binds = UART0)]
|
||||||
|
|
|
@ -16,8 +16,8 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
|
|
@ -27,14 +27,13 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
(
|
(
|
||||||
Shared {
|
Shared {
|
||||||
x: NotSend { _0: PhantomData },
|
x: NotSend { _0: PhantomData },
|
||||||
y: None,
|
y: None,
|
||||||
},
|
},
|
||||||
Local {},
|
Local {},
|
||||||
init::Monotonics(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
|
@ -18,14 +19,14 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
let _: Result<(), ()> = foo::spawn();
|
let _: Result<(), ()> = foo::spawn();
|
||||||
let _: Result<(), u32> = bar::spawn(0);
|
let _: Result<(), u32> = bar::spawn(0);
|
||||||
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
@ -54,15 +55,15 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
fn foo(_: foo::Context) {
|
async fn foo(_: foo::Context) {
|
||||||
let _: Result<(), ()> = foo::spawn();
|
let _: Result<(), ()> = foo::spawn();
|
||||||
let _: Result<(), u32> = bar::spawn(0);
|
let _: Result<(), u32> = bar::spawn(0);
|
||||||
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
fn bar(_: bar::Context, _x: u32) {}
|
async fn bar(_: bar::Context, _x: u32) {}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
fn baz(_: baz::Context, _x: u32, _y: u32) {}
|
async fn baz(_: baz::Context, _x: u32, _y: u32) {}
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
|
@ -18,14 +19,14 @@ mod app {
|
||||||
struct Local {}
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local) {
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
|
|
||||||
(Shared {}, Local {}, init::Monotonics())
|
(Shared {}, Local {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
fn foo(_: foo::Context) {
|
async fn foo(_: foo::Context) {
|
||||||
hprintln!("foo - start").unwrap();
|
hprintln!("foo - start").unwrap();
|
||||||
|
|
||||||
// spawns `bar` onto the task scheduler
|
// spawns `bar` onto the task scheduler
|
||||||
|
@ -43,14 +44,14 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
fn bar(_: bar::Context) {
|
async fn bar(_: bar::Context) {
|
||||||
hprintln!("bar").unwrap();
|
hprintln!("bar").unwrap();
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 2)]
|
#[task(priority = 2)]
|
||||||
fn baz(_: baz::Context) {
|
async fn baz(_: baz::Context) {
|
||||||
hprintln!("baz").unwrap();
|
hprintln!("baz").unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue