Remove unwrap() from hprintln!()

sd 'hprintln(.*).unwrap\(\)' 'hprintln' (fd -e rs .)
This commit is contained in:
Henrik Tjäder 2023-01-11 21:33:44 +01:00
parent 67cccbd481
commit 1fe587c516
26 changed files with 56 additions and 56 deletions

View file

@ -23,14 +23,14 @@ mod app {
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
rtic::pend(Interrupt::UART0); rtic::pend(Interrupt::UART0);
hprintln!("init").unwrap(); hprintln!("init");
(Shared {}, Local {}, init::Monotonics()) (Shared {}, Local {}, init::Monotonics())
} }
#[idle] #[idle]
fn idle(_: idle::Context) -> ! { fn idle(_: idle::Context) -> ! {
hprintln!("idle").unwrap(); hprintln!("idle");
rtic::pend(Interrupt::UART0); rtic::pend(Interrupt::UART0);

View file

@ -37,12 +37,12 @@ mod app {
#[task(capacity = 4)] #[task(capacity = 4)]
fn foo(_: foo::Context, x: u32) { fn foo(_: foo::Context, x: u32) {
hprintln!("foo({})", x).unwrap(); hprintln!("foo({})", x);
} }
#[task] #[task]
fn bar(_: bar::Context) { fn bar(_: bar::Context) {
hprintln!("bar").unwrap(); hprintln!("bar");
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
} }

View file

@ -25,7 +25,7 @@ mod app {
#[init] #[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
hprintln!("init").unwrap(); hprintln!("init");
( (
Shared { Shared {

View file

@ -42,7 +42,7 @@ mod app {
let b = cx.shared.b; let b = cx.shared.b;
let c = cx.shared.c; let c = cx.shared.c;
hprintln!("foo: a = {}, b = {}, c = {}", a, b, c).unwrap(); hprintln!("foo: a = {}, b = {}, c = {}", a, b, c);
} }
// De-structure-ing syntax // De-structure-ing syntax
@ -50,6 +50,6 @@ mod app {
fn bar(cx: bar::Context) { 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);
} }
} }

View file

@ -29,14 +29,14 @@ mod app {
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
rtic::pend(Interrupt::UART0); rtic::pend(Interrupt::UART0);
hprintln!("init").unwrap(); hprintln!("init");
(Shared {}, Local {}, init::Monotonics()) (Shared {}, Local {}, init::Monotonics())
} }
#[idle] #[idle]
fn idle(_: idle::Context) -> ! { fn idle(_: idle::Context) -> ! {
hprintln!("idle").unwrap(); hprintln!("idle");
rtic::pend(Interrupt::UART0); rtic::pend(Interrupt::UART0);

View file

@ -10,7 +10,7 @@ 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) { fn foo(_c: app::foo::Context, x: i32, y: u32) {
hprintln!("foo {}, {}", x, y).unwrap(); hprintln!("foo {}, {}", x, y);
if x == 2 { if x == 2 {
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
} }

View file

@ -32,7 +32,7 @@ mod app {
#[task(binds = UART0, shared = [shared], local = [state: u32 = 0])] #[task(binds = UART0, shared = [shared], local = [state: u32 = 0])]
fn uart0(c: uart0::Context) { fn uart0(c: uart0::Context) {
hprintln!("UART0(STATE = {})", *c.local.state).unwrap(); hprintln!("UART0(STATE = {})", *c.local.state);
// second argument has type `shared::shared` // second argument has type `shared::shared`
super::advance(c.local.state, c.shared.shared); super::advance(c.local.state, c.shared.shared);
@ -44,7 +44,7 @@ mod app {
#[task(binds = UART1, priority = 2, shared = [shared], local = [state: u32 = 0])] #[task(binds = UART1, priority = 2, shared = [shared], local = [state: u32 = 0])]
fn uart1(c: uart1::Context) { fn uart1(c: uart1::Context) {
hprintln!("UART1(STATE = {})", *c.local.state).unwrap(); hprintln!("UART1(STATE = {})", *c.local.state);
// second argument has type `shared::shared` // second argument has type `shared::shared`
super::advance(c.local.state, c.shared.shared); super::advance(c.local.state, c.shared.shared);
@ -61,5 +61,5 @@ fn advance(state: &mut u32, mut shared: impl Mutex<T = u32>) {
(old, *shared) (old, *shared)
}); });
hprintln!("shared: {} -> {}", old, new).unwrap(); hprintln!("shared: {} -> {}", old, new);
} }

View file

@ -24,7 +24,7 @@ mod app {
// `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");
(Shared {}, Local {}, init::Monotonics()) (Shared {}, Local {}, init::Monotonics())
} }
@ -33,7 +33,7 @@ mod app {
fn idle(_: idle::Context) -> ! { fn idle(_: idle::Context) -> ! {
// interrupts are enabled again; the `UART0` handler runs at this point // interrupts are enabled again; the `UART0` handler runs at this point
hprintln!("idle").unwrap(); hprintln!("idle");
rtic::pend(Interrupt::UART0); rtic::pend(Interrupt::UART0);

View file

@ -19,7 +19,7 @@ mod app {
#[init] #[init]
fn init(mut cx: init::Context) -> (Shared, Local, init::Monotonics) { fn init(mut cx: init::Context) -> (Shared, Local, init::Monotonics) {
hprintln!("init").unwrap(); hprintln!("init");
// Set the ARM SLEEPONEXIT bit to go to sleep after handling interrupts // Set the ARM SLEEPONEXIT bit to go to sleep after handling interrupts
// See https://developer.arm.com/docs/100737/0100/power-management/sleep-mode/sleep-on-exit-bit // See https://developer.arm.com/docs/100737/0100/power-management/sleep-mode/sleep-on-exit-bit
@ -33,7 +33,7 @@ mod app {
// Locals in idle have lifetime 'static // Locals in idle have lifetime 'static
let _x: &'static mut u32 = cx.local.x; let _x: &'static mut u32 = cx.local.x;
hprintln!("idle").unwrap(); hprintln!("idle");
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator

View file

@ -19,7 +19,7 @@ mod app {
#[init] #[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
hprintln!("init").unwrap(); hprintln!("init");
(Shared {}, Local {}, init::Monotonics()) (Shared {}, Local {}, init::Monotonics())
} }
@ -29,7 +29,7 @@ mod app {
// Locals in idle have lifetime 'static // Locals in idle have lifetime 'static
let _x: &'static mut u32 = cx.local.x; let _x: &'static mut u32 = cx.local.x;
hprintln!("idle").unwrap(); hprintln!("idle");
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator

View file

@ -32,7 +32,7 @@ mod app {
// to indicate that this is a critical seciton // to indicate that this is a critical seciton
let _cs_token: bare_metal::CriticalSection = cx.cs; let _cs_token: bare_metal::CriticalSection = cx.cs;
hprintln!("init").unwrap(); hprintln!("init");
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator

View file

@ -45,7 +45,7 @@ mod app {
let local_to_idle = cx.local.local_to_idle; let local_to_idle = cx.local.local_to_idle;
*local_to_idle += 1; *local_to_idle += 1;
hprintln!("idle: local_to_idle = {}", local_to_idle).unwrap(); hprintln!("idle: local_to_idle = {}", local_to_idle);
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
@ -69,7 +69,7 @@ mod app {
// error: no `local_to_bar` field in `foo::LocalResources` // error: no `local_to_bar` field in `foo::LocalResources`
// cx.local.local_to_bar += 1; // cx.local.local_to_bar += 1;
hprintln!("foo: local_to_foo = {}", local_to_foo).unwrap(); hprintln!("foo: local_to_foo = {}", local_to_foo);
} }
// `local_to_bar` can only be accessed from this context // `local_to_bar` can only be accessed from this context
@ -81,6 +81,6 @@ mod app {
// error: no `local_to_foo` field in `bar::LocalResources` // error: no `local_to_foo` field in `bar::LocalResources`
// cx.local.local_to_foo += 1; // cx.local.local_to_foo += 1;
hprintln!("bar: local_to_bar = {}", local_to_bar).unwrap(); hprintln!("bar: local_to_bar = {}", local_to_bar);
} }
} }

View file

@ -33,7 +33,7 @@ mod app {
*c.shared.counter += 1; // <- no lock API required *c.shared.counter += 1; // <- no lock API required
let counter = *c.shared.counter; let counter = *c.shared.counter;
hprintln!(" foo = {}", counter).unwrap(); hprintln!(" foo = {}", counter);
} }
#[task(shared = [counter])] // <- same priority #[task(shared = [counter])] // <- same priority
@ -42,7 +42,7 @@ mod app {
*c.shared.counter += 1; // <- no lock API required *c.shared.counter += 1; // <- no lock API required
let counter = *c.shared.counter; let counter = *c.shared.counter;
hprintln!(" bar = {}", counter).unwrap(); hprintln!(" bar = {}", counter);
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
} }

View file

@ -29,7 +29,7 @@ mod app {
// when omitted priority is assumed to be `1` // when omitted priority is assumed to be `1`
#[task(shared = [shared])] #[task(shared = [shared])]
fn foo(mut c: foo::Context) { fn foo(mut c: foo::Context) {
hprintln!("A").unwrap(); hprintln!("A");
// the lower priority task requires a critical section to access the data // the lower priority task requires a critical section to access the data
c.shared.shared.lock(|shared| { c.shared.shared.lock(|shared| {
@ -39,7 +39,7 @@ mod app {
// bar will *not* run right now due to the critical section // bar will *not* run right now due to the critical section
bar::spawn().unwrap(); bar::spawn().unwrap();
hprintln!("B - shared = {}", *shared).unwrap(); hprintln!("B - shared = {}", *shared);
// baz does not contend for `shared` so it's allowed to run now // baz does not contend for `shared` so it's allowed to run now
baz::spawn().unwrap(); baz::spawn().unwrap();
@ -47,7 +47,7 @@ mod app {
// critical section is over: bar can now start // critical section is over: bar can now start
hprintln!("E").unwrap(); hprintln!("E");
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
} }
@ -61,11 +61,11 @@ mod app {
*shared *shared
}); });
hprintln!("D - shared = {}", shared).unwrap(); hprintln!("D - shared = {}", shared);
} }
#[task(priority = 3)] #[task(priority = 3)]
fn baz(_: baz::Context) { fn baz(_: baz::Context) {
hprintln!("C").unwrap(); hprintln!("C");
} }
} }

View file

@ -26,7 +26,7 @@ mod app {
#[task(local = [count: u32 = 0])] #[task(local = [count: u32 = 0])]
fn foo(cx: foo::Context) { fn foo(cx: foo::Context) {
hprintln!("foo").unwrap(); hprintln!("foo");
bar::spawn(*cx.local.count).unwrap(); bar::spawn(*cx.local.count).unwrap();
*cx.local.count += 1; *cx.local.count += 1;
@ -34,14 +34,14 @@ mod app {
#[task] #[task]
fn bar(_: bar::Context, x: u32) { fn bar(_: bar::Context, x: u32) {
hprintln!("bar({})", x).unwrap(); hprintln!("bar({})", x);
baz::spawn(x + 1, x + 2).unwrap(); baz::spawn(x + 1, x + 2).unwrap();
} }
#[task] #[task]
fn baz(_: baz::Context, x: u32, y: u32) { fn baz(_: baz::Context, x: u32, y: u32) {
hprintln!("baz({}, {})", x, y).unwrap(); hprintln!("baz({}, {})", x, y);
if x + y > 4 { if x + y > 4 {
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator

View file

@ -29,7 +29,7 @@ mod app {
#[task(capacity = 3)] #[task(capacity = 3)]
fn foo(_c: foo::Context, x: i32, y: u32) { fn foo(_c: foo::Context, x: i32, y: u32) {
hprintln!("foo {}, {}", x, y).unwrap(); hprintln!("foo {}, {}", x, y);
if x == 2 { if x == 2 {
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
} }

View file

@ -48,7 +48,7 @@ mod app {
*s2 += 1; *s2 += 1;
*s3 += 1; *s3 += 1;
hprintln!("Multiple locks, s1: {}, s2: {}, s3: {}", *s1, *s2, *s3).unwrap(); hprintln!("Multiple locks, s1: {}, s2: {}, s3: {}", *s1, *s2, *s3);
}); });
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator

View file

@ -30,13 +30,13 @@ mod app {
#[task(shared = [&key])] #[task(shared = [&key])]
fn foo(cx: foo::Context) { 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);
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
} }
#[task(priority = 2, shared = [&key])] #[task(priority = 2, shared = [&key])]
fn bar(cx: bar::Context) { fn bar(cx: bar::Context) {
hprintln!("bar(key = {:#x})", cx.shared.key).unwrap(); hprintln!("bar(key = {:#x})", cx.shared.key);
} }
} }

View file

@ -56,7 +56,7 @@ mod app {
#[task] #[task]
fn foo(_: foo::Context, x: Box<P>) { fn foo(_: foo::Context, x: Box<P>) {
hprintln!("foo({:?})", x.as_ptr()).unwrap(); hprintln!("foo({:?})", x.as_ptr());
// explicitly return the block to the pool // explicitly return the block to the pool
drop(x); drop(x);
@ -66,7 +66,7 @@ mod app {
#[task(priority = 2)] #[task(priority = 2)]
fn bar(_: bar::Context, x: Box<P>) { fn bar(_: bar::Context, x: Box<P>) {
hprintln!("bar({:?})", x.as_ptr()).unwrap(); hprintln!("bar({:?})", x.as_ptr());
// 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);

View file

@ -25,21 +25,21 @@ mod app {
#[task(priority = 1)] #[task(priority = 1)]
fn foo(_: foo::Context) { fn foo(_: foo::Context) {
hprintln!("foo - start").unwrap(); hprintln!("foo - start");
baz::spawn().unwrap(); baz::spawn().unwrap();
hprintln!("foo - end").unwrap(); hprintln!("foo - end");
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
} }
#[task(priority = 2)] #[task(priority = 2)]
fn bar(_: bar::Context) { fn bar(_: bar::Context) {
hprintln!(" bar").unwrap(); hprintln!(" bar");
} }
#[task(priority = 2)] #[task(priority = 2)]
fn baz(_: baz::Context) { fn baz(_: baz::Context) {
hprintln!(" baz - start").unwrap(); hprintln!(" baz - start");
bar::spawn().unwrap(); bar::spawn().unwrap();
hprintln!(" baz - end").unwrap(); hprintln!(" baz - end");
} }
} }

View file

@ -33,7 +33,7 @@ mod app {
#[inline(never)] #[inline(never)]
#[task] #[task]
fn foo(_: foo::Context) { fn foo(_: foo::Context) {
hprintln!("foo").unwrap(); hprintln!("foo");
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
} }

View file

@ -55,7 +55,7 @@ mod app {
*shared *shared
}); });
hprintln!("UART0: shared = {}", shared).unwrap(); hprintln!("UART0: shared = {}", shared);
} }
// `shared` can be accessed from this context // `shared` can be accessed from this context
@ -66,6 +66,6 @@ mod app {
*shared *shared
}); });
hprintln!("UART1: shared = {}", shared).unwrap(); hprintln!("UART1: shared = {}", shared);
} }
} }

View file

@ -34,7 +34,7 @@ mod app {
fn idle(mut c: idle::Context) -> ! { fn idle(mut c: idle::Context) -> ! {
loop { loop {
if let Some(byte) = c.shared.c.lock(|c| c.dequeue()) { if let Some(byte) = c.shared.c.lock(|c| c.dequeue()) {
hprintln!("received message: {}", byte).unwrap(); hprintln!("received message: {}", byte);
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
} else { } else {

View file

@ -19,7 +19,7 @@ mod app {
#[init] #[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
hprintln!("init").unwrap(); hprintln!("init");
foo::spawn().unwrap(); foo::spawn().unwrap();
(Shared {}, Local {}, init::Monotonics()) (Shared {}, Local {}, init::Monotonics())
@ -27,7 +27,7 @@ mod app {
#[task] #[task]
fn foo(_: foo::Context) { fn foo(_: foo::Context) {
hprintln!("foo").unwrap(); hprintln!("foo");
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
} }

View file

@ -37,7 +37,7 @@ mod app {
loop { loop {
// Lock-free access to the same underlying queue! // Lock-free access to the same underlying queue!
if let Some(data) = c.local.c.dequeue() { if let Some(data) = c.local.c.dequeue() {
hprintln!("received message: {}", data).unwrap(); hprintln!("received message: {}", data);
// Run foo until data // Run foo until data
if data == 3 { if data == 3 {

View file

@ -26,31 +26,31 @@ mod app {
#[task] #[task]
fn foo(_: foo::Context) { fn foo(_: foo::Context) {
hprintln!("foo - start").unwrap(); hprintln!("foo - start");
// spawns `bar` onto the task scheduler // spawns `bar` onto the task scheduler
// `foo` and `bar` have the same priority so `bar` will not run until // `foo` and `bar` have the same priority so `bar` will not run until
// after `foo` terminates // after `foo` terminates
bar::spawn().unwrap(); bar::spawn().unwrap();
hprintln!("foo - middle").unwrap(); hprintln!("foo - middle");
// spawns `baz` onto the task scheduler // spawns `baz` onto the task scheduler
// `baz` has higher priority than `foo` so it immediately preempts `foo` // `baz` has higher priority than `foo` so it immediately preempts `foo`
baz::spawn().unwrap(); baz::spawn().unwrap();
hprintln!("foo - end").unwrap(); hprintln!("foo - end");
} }
#[task] #[task]
fn bar(_: bar::Context) { fn bar(_: bar::Context) {
hprintln!("bar").unwrap(); hprintln!("bar");
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) { fn baz(_: baz::Context) {
hprintln!("baz").unwrap(); hprintln!("baz");
} }
} }