mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-16 12:55:23 +01:00
Add example
This commit is contained in:
parent
578bcbff12
commit
964642bf8c
2 changed files with 41 additions and 2 deletions
39
examples/lm3s6965/examples/spawn_local.rs
Normal file
39
examples/lm3s6965/examples/spawn_local.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||
mod app {
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use super::*;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_cx: init::Context) -> (Shared, Local) {
|
||||
task1::spawn().unwrap();
|
||||
//task2::spawn(Default::default()).ok(); <--- This is rejected since not all args are Send and Sync
|
||||
(Shared {}, Local {})
|
||||
}
|
||||
|
||||
#[task(priority = 1)]
|
||||
async fn task1(cx: task1::Context) {
|
||||
hprintln!("Hello from task1!");
|
||||
cx.local_spawner.task2(Default::default()).unwrap();
|
||||
}
|
||||
|
||||
// Task where some args are !Send/!Sync
|
||||
#[task(priority = 1)]
|
||||
async fn task2(_cx: task2::Context, _nsns: NotSendNotSync) {
|
||||
hprintln!("Hello from task2!");
|
||||
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
struct NotSendNotSync(core::marker::PhantomData<*mut u8>);
|
||||
|
|
@ -28,8 +28,8 @@ mod app {
|
|||
fn init(cx: init::Context) -> (Shared, Local) {
|
||||
Mono::start(cx.core.SYST, 12_000_000);
|
||||
|
||||
incrementer::spawn(cx.local.wait_queue).ok().unwrap();
|
||||
waiter::spawn(cx.local.wait_queue).ok().unwrap();
|
||||
incrementer::spawn(&*cx.local.wait_queue).ok().unwrap();
|
||||
waiter::spawn(&*cx.local.wait_queue).ok().unwrap();
|
||||
|
||||
let count = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue