Skip to content
Snippets Groups Projects
Commit 676af77f authored by Per Lindgren's avatar Per Lindgren
Browse files

without rtfm

parent ed1c4fec
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
//! ``` //! ```
#![deny(unsafe_code)] #![deny(unsafe_code)]
#![deny(warnings)] // #![deny(warnings)]
#![no_main] #![no_main]
#![no_std] #![no_std]
...@@ -25,6 +25,10 @@ use panic_udf as _; // panic handler ...@@ -25,6 +25,10 @@ use panic_udf as _; // panic handler
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
// task A // task A
hprintln!("here").ok();
//loop { continue; }
task::spawn(async { task::spawn(async {
loop { loop {
hprintln!("A: yield").ok(); hprintln!("A: yield").ok();
...@@ -35,19 +39,21 @@ fn main() -> ! { ...@@ -35,19 +39,21 @@ fn main() -> ! {
// task B // task B
task::block_on(async { task::block_on(async {
hprintln!("B: yield").ok(); loop {
hprintln!("B1: yield").ok();
// context switch to A // context switch to A
task::r#yield().await; task::r#yield().await;
hprintln!("B: yield").ok(); hprintln!("B2: yield").ok();
task::r#yield().await; task::r#yield().await;
hprintln!("DONE").ok(); hprintln!("DONE").ok();
loop { // loop {
asm::bkpt(); // asm::bkpt();
// }
} }
}) })
} }
...@@ -39,33 +39,44 @@ use panic_udf as _; // panic handler ...@@ -39,33 +39,44 @@ use panic_udf as _; // panic handler
fn main() -> ! { fn main() -> ! {
static mut X: Mutex<i64> = Mutex::new(0); static mut X: Mutex<i64> = Mutex::new(0);
let mut lock = X.try_lock().unwrap(); task::block_on(async {
loop {
hprintln!("A: before lock").ok();
let mut lock = X.lock().await;
task::spawn(async { hprintln!("A: before write {}", *lock).ok();
hprintln!("A: before write").ok(); *lock += 1;
*lock = 42;
drop(lock); drop(lock);
hprintln!("A: after releasing the lock").ok(); hprintln!("A: after releasing the lock").ok();
loop { hprintln!("A: manual yield").ok();
hprintln!("A: yield").ok();
task::r#yield().await; task::r#yield().await;
} }
}); });
task::block_on(async { task::block_on(async {
loop {
hprintln!("B: before lock").ok(); hprintln!("B: before lock").ok();
// cannot immediately make progress; context switch to A // cannot immediately make progress; context switch to A
let lock = X.lock().await; let mut lock = X.lock().await;
hprintln!("B: {}", *lock).ok(); hprintln!("B: {}", *lock).ok();
*lock += 1;
hprintln!("DONE").ok(); if *lock == 10 {
loop { loop {
asm::bkpt(); asm::bkpt();
} }
}) } else {
drop(lock);
hprintln!("X: yield").ok();
task::r#yield().await;
}
}
});
loop { continue; }
} }
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use async_cortex_m::{task, unsync::Mutex};
use cortex_m::asm;
use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use nrf52 as _; // memory layout
use panic_udf as _; // panic handler
#[entry]
fn main() -> ! {
static mut X: Mutex<i64> = Mutex::new(0);
let c: &'static _ = X;
task::spawn(async move {
loop {
hprintln!("A: before lock").ok();
let mut lock = c.lock().await;
hprintln!("A: before write {}", *lock).ok();
*lock += 1;
drop(lock);
hprintln!("A: after releasing the lock").ok();
hprintln!("A: manual yield").ok();
task::r#yield().await;
}
});
task::block_on(async {
loop {
hprintln!("B: before lock").ok();
// cannot immediately make progress; context switch to A
let mut lock = c.lock().await;
hprintln!("B: {}", *lock).ok();
*lock += 1;
if *lock > 10 {
loop {
asm::bkpt();
}
} else {
drop(lock);
hprintln!("B: yield").ok();
task::r#yield().await;
}
}
});
loop { continue; }
}
\ No newline at end of file
...@@ -26,9 +26,9 @@ fn main() -> ! { ...@@ -26,9 +26,9 @@ fn main() -> ! {
timer.wait(dur).await; timer.wait(dur).await;
Red.off(); Red.off();
timer.wait(dur).await; timer.wait(dur).await;
Red.on(); // Red.on();
timer.wait(dur).await; // timer.wait(dur).await;
Red.off(); // Red.off();
timer.wait(12 * dur).await; timer.wait(12 * dur).await;
} }
}); });
......
...@@ -2,5 +2,5 @@ MEMORY ...@@ -2,5 +2,5 @@ MEMORY
{ {
/* NOTE 1 K = 1 KiBi = 1024 bytes */ /* NOTE 1 K = 1 KiBi = 1024 bytes */
FLASH : ORIGIN = 0x00000000, LENGTH = 1M FLASH : ORIGIN = 0x00000000, LENGTH = 1M
RAM : ORIGIN = 0x20000000, LENGTH = 256K RAM : ORIGIN = 0x20000000, LENGTH = 32K
} }
source [find interface/cmsis-dap.cfg] #source [find interface/cmsis-dap.cfg]
source [find interface/jlink.cfg]
transport select swd
source [find target/nrf52.cfg] source [find target/nrf52.cfg]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment