diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 83fa8ca..b036dd2 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -2,7 +2,10 @@ #![no_main] extern crate alloc; -use hopter::{debug::semihosting, hprintln, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + task::main, +}; // Attribute `#[main]` marks the function as the entry function for the main // task. The function name can be arbitrary. The main function should accept @@ -11,7 +14,7 @@ use hopter::{debug::semihosting, hprintln, task::main}; fn main(_: cortex_m::Peripherals) { // Print via semihosting. When using QEMU with semihosting option enabled, // the characters will appear on the QEMU console. - hprintln!("hello world!"); + dbg_println!("hello world!"); // When running with QEMU, this will cause the QEMU process to terminate. // Do not include this line when running with OpenOCD, because it will diff --git a/examples/sleep.rs b/examples/sleep.rs index 03393fe..b482042 100644 --- a/examples/sleep.rs +++ b/examples/sleep.rs @@ -2,7 +2,11 @@ #![no_main] extern crate alloc; -use hopter::{debug::semihosting, hprintln, task::main, time}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + task::main, + time, +}; // Attribute `#[main]` marks the function as the entry function for the main // task. The function name can be arbitrary. The main function should accept @@ -14,7 +18,7 @@ fn main(_: cortex_m::Peripherals) { time::sleep_ms(1000); // Print via semihosting. When using QEMU with semihosting option enabled, // the characters will appear on the QEMU console. - hprintln!("hello"); + dbg_println!("hello"); } // When running with QEMU, this will cause the QEMU process to terminate. diff --git a/examples/task_panic_restart.rs b/examples/task_panic_restart.rs index 4babece..c0d5dbc 100644 --- a/examples/task_panic_restart.rs +++ b/examples/task_panic_restart.rs @@ -3,7 +3,11 @@ extern crate alloc; use core::sync::atomic::{AtomicUsize, Ordering}; -use hopter::{debug::semihosting, hprintln, schedule, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + schedule, task, + task::main, +}; // Attribute `#[main]` marks the function as the entry function for the main // task. The function name can be arbitrary. The main function should accept @@ -26,7 +30,7 @@ fn will_panic() { // Every time the task runs we increment it by 1. let cnt = CNT.fetch_add(1, Ordering::SeqCst); - hprintln!("Current count: {}", cnt); + dbg_println!("Current count: {}", cnt); // Panic and get restarted for 5 times. if cnt < 5 { diff --git a/examples/tests/debug/cpu_load/load_40_percent.rs b/examples/tests/debug/cpu_load/load_40_percent.rs index adb3628..e50f8fd 100644 --- a/examples/tests/debug/cpu_load/load_40_percent.rs +++ b/examples/tests/debug/cpu_load/load_40_percent.rs @@ -9,9 +9,8 @@ use alloc::sync::Arc; use hopter::{ debug::{ cpu_load::{LoadInspector, MicrosecPrecision}, - semihosting, + semihosting::{self, dbg_println}, }, - hprintln, interrupt::declare::irq, sync::SpinIrqSafe, task, @@ -75,7 +74,7 @@ fn print_load() { time::sleep_ms(500); if let Some(usage) = LOAD_INSPECTOR.lock().as_ref() { let (x, y) = usage.get_cpu_load(); - hprintln!("CPU load {}.{}%", x, y); + dbg_println!("CPU load {}.{}%", x, y); } } semihosting::terminate(true); diff --git a/examples/tests/interrupt/unwind/simple.rs b/examples/tests/interrupt/unwind/simple.rs index 82a3269..a04360d 100644 --- a/examples/tests/interrupt/unwind/simple.rs +++ b/examples/tests/interrupt/unwind/simple.rs @@ -8,8 +8,7 @@ extern crate alloc; use core::sync::atomic::{AtomicUsize, Ordering}; use hopter::{ - debug::semihosting, - hprintln, + debug::semihosting::{self, dbg_println}, interrupt::declare::{handler, irq}, sync::SpinIrqSafe, task::main, @@ -62,7 +61,7 @@ extern "C" fn tim2_handler() { panic!(); } - hprintln!("TIM2 IRQ count {}", prev_cnt); + dbg_println!("TIM2 IRQ count {}", prev_cnt); if prev_cnt >= 5 { semihosting::terminate(true); @@ -73,6 +72,6 @@ struct PrintOnDrop(&'static str); impl Drop for PrintOnDrop { fn drop(&mut self) { - hprintln!("{}", self.0); + dbg_println!("{}", self.0); } } diff --git a/examples/tests/sync/channel/concurrency_and_stress.rs b/examples/tests/sync/channel/concurrency_and_stress.rs index 17f8141..c9f9a17 100644 --- a/examples/tests/sync/channel/concurrency_and_stress.rs +++ b/examples/tests/sync/channel/concurrency_and_stress.rs @@ -10,7 +10,13 @@ extern crate alloc; use alloc::vec; use alloc::vec::Vec; use core::sync::atomic::{AtomicUsize, Ordering}; -use hopter::{debug::semihosting, hprintln, sync, sync::Producer, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync, + sync::Producer, + task, + task::main, +}; const NUM_TASKS: usize = 4; const NUM_ITEMS: usize = 3; // Number of items each task will produce @@ -65,10 +71,10 @@ fn main(_: cortex_m::Peripherals) { // Check if the produced results match the expected sequence if results != compare_vec { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } diff --git a/examples/tests/sync/channel/multiple_consumers.rs b/examples/tests/sync/channel/multiple_consumers.rs index 936898d..cc165ec 100644 --- a/examples/tests/sync/channel/multiple_consumers.rs +++ b/examples/tests/sync/channel/multiple_consumers.rs @@ -6,7 +6,13 @@ #![no_std] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync, sync::Consumer, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync, + sync::Consumer, + task, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -41,14 +47,14 @@ fn main(_: cortex_m::Peripherals) { // Check if the channel is empty after both consumers have finished if consumer.try_consume_allow_isr() != None { - hprintln!("Channel not empty"); + dbg_println!("Channel not empty"); semihosting::terminate(false); } - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } fn consume_function(consumer: &mut Consumer) { - hprintln!("{}", consumer.consume()); - hprintln!("{}", consumer.consume()); + dbg_println!("{}", consumer.consume()); + dbg_println!("{}", consumer.consume()); } diff --git a/examples/tests/sync/channel/multiple_producers.rs b/examples/tests/sync/channel/multiple_producers.rs index 9c5d9fd..c1bb0f5 100644 --- a/examples/tests/sync/channel/multiple_producers.rs +++ b/examples/tests/sync/channel/multiple_producers.rs @@ -6,7 +6,13 @@ #![no_std] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync, sync::Producer, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync, + sync::Producer, + task, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -42,10 +48,10 @@ fn main(_: cortex_m::Peripherals) { // Verify the consumed values against the expected order if values != [1, 2, 3, 4] { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } diff --git a/examples/tests/sync/channel/produce_consume_single_task.rs b/examples/tests/sync/channel/produce_consume_single_task.rs index 23b0f01..00561be 100644 --- a/examples/tests/sync/channel/produce_consume_single_task.rs +++ b/examples/tests/sync/channel/produce_consume_single_task.rs @@ -4,7 +4,11 @@ #![no_std] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -21,10 +25,10 @@ fn main(_: cortex_m::Peripherals) { for i in 0..4 { let value = consumer.consume(); if value != 23 + i { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } } - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } diff --git a/examples/tests/sync/channel/try_consume_from_isr.rs b/examples/tests/sync/channel/try_consume_from_isr.rs index a7bd3b4..96e050f 100644 --- a/examples/tests/sync/channel/try_consume_from_isr.rs +++ b/examples/tests/sync/channel/try_consume_from_isr.rs @@ -9,8 +9,7 @@ extern crate alloc; use core::sync::atomic::{AtomicUsize, Ordering}; use hopter::{ config, - debug::semihosting, - hprintln, + debug::semihosting::{self, dbg_println}, interrupt::declare::{handler, irq}, sync, sync::{Consumer, Producer, SpinIrqSafe}, @@ -90,23 +89,23 @@ extern "C" fn tim2_handler() { match result { // The first 5 consume attempt should be successful. Some(value) => { - hprintln!("Consumed {}", value); + dbg_println!("Consumed {}", value); if COUNT.load(Ordering::SeqCst) > 5 { semihosting::terminate(false); } } // The 6th consume attempt should be unsuccessful. None => { - hprintln!("Failed to consume"); + dbg_println!("Failed to consume"); if COUNT.load(Ordering::SeqCst) == 6 { semihosting::terminate(true); } - hprintln!("Unexpectedly succeed to consume"); + dbg_println!("Unexpectedly succeed to consume"); semihosting::terminate(false); } } } else { - hprintln!("Consumer not initialized!"); + dbg_println!("Consumer not initialized!"); semihosting::terminate(false); } } diff --git a/examples/tests/sync/channel/try_consume_from_task.rs b/examples/tests/sync/channel/try_consume_from_task.rs index c3588ed..e798284 100644 --- a/examples/tests/sync/channel/try_consume_from_task.rs +++ b/examples/tests/sync/channel/try_consume_from_task.rs @@ -3,7 +3,11 @@ #![no_std] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -15,7 +19,7 @@ fn main(_: cortex_m::Peripherals) { // Check against expected behavior if result != None { - hprintln!("consumed from an empty channel"); + dbg_println!("consumed from an empty channel"); semihosting::terminate(false); } @@ -29,7 +33,7 @@ fn main(_: cortex_m::Peripherals) { for _i in 0..4 { let result = consumer.try_consume_allow_isr(); if result == None { - hprintln!("failed to consume from a non-empty channel"); + dbg_println!("failed to consume from a non-empty channel"); semihosting::terminate(false); } } @@ -38,11 +42,11 @@ fn main(_: cortex_m::Peripherals) { let final_result = consumer.try_consume_allow_isr(); match final_result { None => { - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } Some(_t) => { - hprintln!("consumed from an empty channel"); + dbg_println!("consumed from an empty channel"); semihosting::terminate(false); } } diff --git a/examples/tests/sync/channel/try_produce_from_isr.rs b/examples/tests/sync/channel/try_produce_from_isr.rs index 6c01a19..58c61ac 100644 --- a/examples/tests/sync/channel/try_produce_from_isr.rs +++ b/examples/tests/sync/channel/try_produce_from_isr.rs @@ -10,8 +10,7 @@ extern crate alloc; use core::sync::atomic::{AtomicUsize, Ordering}; use hopter::{ config, - debug::semihosting, - hprintln, + debug::semihosting::{self, dbg_println}, interrupt::declare::{handler, irq}, sync, sync::{Consumer, Producer, SpinIrqSafe}, @@ -74,7 +73,7 @@ fn consume_function(consumer: Consumer) { // should be able to hold two more values produced. for _ in 0..3 { let val = consumer.consume(); - hprintln!("Consumed {}", val); + dbg_println!("Consumed {}", val); } } @@ -98,16 +97,16 @@ extern "C" fn tim2_handler() { } // The 6th produce attempt should be unsuccessful. Err(_) => { - hprintln!("Failed to produce"); + dbg_println!("Failed to produce"); if COUNT.load(Ordering::SeqCst) == 6 { semihosting::terminate(true); } - hprintln!("Unexpectedly succeed to produce"); + dbg_println!("Unexpectedly succeed to produce"); semihosting::terminate(false); } } } else { - hprintln!("Producer not initialized!"); + dbg_println!("Producer not initialized!"); semihosting::terminate(false); } } diff --git a/examples/tests/sync/channel/try_produce_from_task.rs b/examples/tests/sync/channel/try_produce_from_task.rs index f5e7e95..d5d9665 100644 --- a/examples/tests/sync/channel/try_produce_from_task.rs +++ b/examples/tests/sync/channel/try_produce_from_task.rs @@ -4,7 +4,7 @@ #![no_std] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync, task::main}; +use hopter::{debug::semihosting::{self, dbg_println}, sync, task::main}; #[main] fn main(_: cortex_m::Peripherals) { @@ -21,7 +21,7 @@ fn main(_: cortex_m::Peripherals) { for i in 4..=7 { let result = producer.try_produce_allow_isr(i); if result != Err(i) { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } } @@ -30,10 +30,10 @@ fn main(_: cortex_m::Peripherals) { for i in 0..4 { let value = consumer.consume(); if value != i { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } } - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } diff --git a/examples/tests/sync/mailbox/notify_by_task.rs b/examples/tests/sync/mailbox/notify_by_task.rs index 7fa5c1c..4ac9957 100644 --- a/examples/tests/sync/mailbox/notify_by_task.rs +++ b/examples/tests/sync/mailbox/notify_by_task.rs @@ -5,7 +5,13 @@ #![no_main] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Mailbox, task, task::main, time}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Mailbox, + task, + task::main, + time, +}; static MAILBOX: Mailbox = Mailbox::new(); @@ -25,7 +31,7 @@ fn notifier() { fn listener() { for _ in 0..5 { MAILBOX.wait(); - hprintln!("received"); + dbg_println!("received"); } semihosting::terminate(true); diff --git a/examples/tests/sync/mailbox/notify_from_isr.rs b/examples/tests/sync/mailbox/notify_from_isr.rs index bb94c64..b70d2b1 100644 --- a/examples/tests/sync/mailbox/notify_from_isr.rs +++ b/examples/tests/sync/mailbox/notify_from_isr.rs @@ -9,8 +9,7 @@ extern crate alloc; use core::sync::atomic::{AtomicUsize, Ordering}; use hopter::{ config, - debug::semihosting, - hprintln, + debug::semihosting::{self, dbg_println}, interrupt::declare::{handler, irq}, sync::{Mailbox, SpinIrqSafe}, task, @@ -66,9 +65,9 @@ fn main(_cp: cortex_m::Peripherals) { fn listener_function() { for _ in 0..3 { - hprintln!("Waiting"); + dbg_println!("Waiting"); MAILBOX.wait(); - hprintln!("Recieved"); + dbg_println!("Recieved"); } semihosting::terminate(true); } @@ -79,7 +78,7 @@ extern "C" fn tim2_handler() { static IRQ_CNT: AtomicUsize = AtomicUsize::new(0); MAILBOX.notify_allow_isr(); - hprintln!("Notified"); + dbg_println!("Notified"); let prev_cnt = IRQ_CNT.fetch_add(1, Ordering::SeqCst); diff --git a/examples/tests/sync/mailbox/notify_in_advance.rs b/examples/tests/sync/mailbox/notify_in_advance.rs index e8a6579..d99c331 100644 --- a/examples/tests/sync/mailbox/notify_in_advance.rs +++ b/examples/tests/sync/mailbox/notify_in_advance.rs @@ -5,7 +5,11 @@ #![no_main] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Mailbox, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Mailbox, + task::main, +}; static MAILBOX: Mailbox = Mailbox::new(); @@ -17,7 +21,7 @@ fn main(_: cortex_m::Peripherals) { for _ in 0..5 { MAILBOX.wait(); - hprintln!("received"); + dbg_println!("received"); } semihosting::terminate(true); diff --git a/examples/tests/sync/mailbox/notify_in_advance_after_timeout.rs b/examples/tests/sync/mailbox/notify_in_advance_after_timeout.rs index e739b6d..d6e9f9d 100644 --- a/examples/tests/sync/mailbox/notify_in_advance_after_timeout.rs +++ b/examples/tests/sync/mailbox/notify_in_advance_after_timeout.rs @@ -4,7 +4,12 @@ #![no_main] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Mailbox, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Mailbox, + task, + task::main, +}; static MAILBOX: Mailbox = Mailbox::new(); @@ -16,7 +21,7 @@ fn main(_: cortex_m::Peripherals) { fn listener() { let notified = MAILBOX.wait_until_timeout(500); if notified { - hprintln!("Unexpected notification."); + dbg_println!("Unexpected notification."); semihosting::terminate(false); } @@ -24,7 +29,7 @@ fn listener() { let notified = MAILBOX.wait_until_timeout(500); if !notified { - hprintln!("Unexpected timeout."); + dbg_println!("Unexpected timeout."); semihosting::terminate(false); } diff --git a/examples/tests/sync/mailbox/task_not_timeout.rs b/examples/tests/sync/mailbox/task_not_timeout.rs index 795f409..e6f43ab 100644 --- a/examples/tests/sync/mailbox/task_not_timeout.rs +++ b/examples/tests/sync/mailbox/task_not_timeout.rs @@ -4,7 +4,13 @@ #![no_main] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Mailbox, task, task::main, time}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Mailbox, + task, + task::main, + time, +}; static MAILBOX: Mailbox = Mailbox::new(); @@ -28,13 +34,13 @@ fn main(_: cortex_m::Peripherals) { fn listener() { let notified = MAILBOX.wait_until_timeout(1000); if !notified { - hprintln!("Unexpected timeout."); + dbg_println!("Unexpected timeout."); semihosting::terminate(false); } let notified = MAILBOX.wait_until_timeout(1000); if !notified { - hprintln!("Unexpected timeout."); + dbg_println!("Unexpected timeout."); semihosting::terminate(false); } diff --git a/examples/tests/sync/mailbox/task_timeout.rs b/examples/tests/sync/mailbox/task_timeout.rs index 04017a1..3b09e94 100644 --- a/examples/tests/sync/mailbox/task_timeout.rs +++ b/examples/tests/sync/mailbox/task_timeout.rs @@ -4,7 +4,12 @@ #![no_main] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Mailbox, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Mailbox, + task, + task::main, +}; static MAILBOX: Mailbox = Mailbox::new(); @@ -16,7 +21,7 @@ fn main(_: cortex_m::Peripherals) { fn listener() { let notified = MAILBOX.wait_until_timeout(1000); if notified { - hprintln!("Unexpected notification."); + dbg_println!("Unexpected notification."); semihosting::terminate(false); } semihosting::terminate(true); diff --git a/examples/tests/sync/mutex/basic.rs b/examples/tests/sync/mutex/basic.rs index 9424817..0a406c9 100644 --- a/examples/tests/sync/mutex/basic.rs +++ b/examples/tests/sync/mutex/basic.rs @@ -5,7 +5,11 @@ extern crate alloc; use alloc::string::String; -use hopter::{debug::semihosting, hprintln, sync::Mutex, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Mutex, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -13,7 +17,7 @@ fn main(_: cortex_m::Peripherals) { let mutex = Mutex::new(String::from("Hello, World")); // Test `into_inner`. - hprintln!("Data: {}", mutex.into_inner()); + dbg_println!("Data: {}", mutex.into_inner()); // Test `try_lock`. let mutex = Mutex::new(()); @@ -21,18 +25,18 @@ fn main(_: cortex_m::Peripherals) { match gaurd { Some(_) => { - hprintln!("First try lock success"); + dbg_println!("First try lock success"); let guard = mutex.try_lock(); if guard.is_none() { - hprintln!("Second try lock failed"); + dbg_println!("Second try lock failed"); semihosting::terminate(true); } else { - hprintln!("Second try lock success"); + dbg_println!("Second try lock success"); semihosting::terminate(false); } } None => { - hprintln!("First try lock failed"); + dbg_println!("First try lock failed"); semihosting::terminate(false); } } diff --git a/examples/tests/sync/mutex/poison.rs b/examples/tests/sync/mutex/poison.rs index d144f5e..32ae61f 100644 --- a/examples/tests/sync/mutex/poison.rs +++ b/examples/tests/sync/mutex/poison.rs @@ -4,7 +4,13 @@ #![no_std] extern crate alloc; -use hopter::{config, debug::semihosting, hprintln, sync::Mutex, task, task::main}; +use hopter::{ + config, + debug::semihosting::{self, dbg_println}, + sync::Mutex, + task, + task::main, +}; static MTX: Mutex<()> = Mutex::new(()); @@ -13,10 +19,10 @@ fn main(_: cortex_m::Peripherals) { task::build().set_entry(will_panic).spawn().unwrap(); task::change_current_priority(config::UNWIND_PRIORITY + 1).unwrap(); if MTX.is_poisoned() { - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } else { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } } diff --git a/examples/tests/sync/mutex/priority.rs b/examples/tests/sync/mutex/priority.rs index 40e5430..b7f195a 100644 --- a/examples/tests/sync/mutex/priority.rs +++ b/examples/tests/sync/mutex/priority.rs @@ -5,7 +5,13 @@ #![no_std] extern crate alloc; -use hopter::{config, debug::semihosting, hprintln, sync::Mutex, task, task::main}; +use hopter::{ + config, + debug::semihosting::{self, dbg_println}, + sync::Mutex, + task, + task::main, +}; static MUTEX: Mutex<()> = Mutex::new(()); @@ -43,15 +49,15 @@ fn main(_: cortex_m::Peripherals) { fn high_task() { let _gaurd = MUTEX.lock(); - hprintln!("High priority task locking data"); + dbg_println!("High priority task locking data"); } fn middle_task() { let _gaurd = MUTEX.lock(); - hprintln!("Middle priority task locking data"); + dbg_println!("Middle priority task locking data"); } fn low_task() { let _gaurd = MUTEX.lock(); - hprintln!("Low priority task locking data"); + dbg_println!("Low priority task locking data"); } diff --git a/examples/tests/sync/mutex/priority_inversion.rs b/examples/tests/sync/mutex/priority_inversion.rs index 527f5d3..50f21bf 100644 --- a/examples/tests/sync/mutex/priority_inversion.rs +++ b/examples/tests/sync/mutex/priority_inversion.rs @@ -4,7 +4,13 @@ #![no_main] extern crate alloc; -use hopter::{config, debug::semihosting, hprintln, sync::Mutex, task, task::main}; +use hopter::{ + config, + debug::semihosting::{self, dbg_println}, + sync::Mutex, + task, + task::main, +}; // Define a global mutex static MUTEX: Mutex<()> = Mutex::new(()); @@ -22,7 +28,7 @@ fn main(_: cortex_m::Peripherals) { fn low_task() { // Attempt to acquire the mutex let guard = MUTEX.lock(); - hprintln!("Low priority task locked mutex"); + dbg_println!("Low priority task locked mutex"); // Spawn a high priority task task::build() @@ -31,8 +37,8 @@ fn low_task() { .spawn() .unwrap(); - hprintln!("High priority task blocked by mutex and low priority task continued"); - hprintln!("Low priority task got elevated to high priority"); + dbg_println!("High priority task blocked by mutex and low priority task continued"); + dbg_println!("Low priority task got elevated to high priority"); // Spawn a middle priority task task::build() @@ -41,22 +47,22 @@ fn low_task() { .spawn() .unwrap(); - hprintln!("Middle priority task was not able to run for now"); + dbg_println!("Middle priority task was not able to run for now"); // Drop the mutex. Low priority task should be reduced back to low priority. core::mem::drop(guard); - hprintln!("Low priority task finished last"); + dbg_println!("Low priority task finished last"); semihosting::terminate(true); } fn high_task() { - hprintln!("High priority task trying to lock mutex"); + dbg_println!("High priority task trying to lock mutex"); let _guard = MUTEX.lock(); - hprintln!("High priority task locked mutex"); + dbg_println!("High priority task locked mutex"); } fn middle_task() { - hprintln!("Middle priority task executed"); + dbg_println!("Middle priority task executed"); } diff --git a/examples/tests/sync/mutex/stress.rs b/examples/tests/sync/mutex/stress.rs index c47c585..e8bc716 100644 --- a/examples/tests/sync/mutex/stress.rs +++ b/examples/tests/sync/mutex/stress.rs @@ -5,7 +5,13 @@ #![no_main] extern crate alloc; -use hopter::{config, debug::semihosting, hprintln, sync::Mutex, task, task::main}; +use hopter::{ + config, + debug::semihosting::{self, dbg_println}, + sync::Mutex, + task, + task::main, +}; static MUTEX: Mutex = Mutex::new(0); const ITERATIONS: usize = 10; @@ -24,10 +30,10 @@ fn main(_: cortex_m::Peripherals) { task::change_current_priority(config::DEFAULT_TASK_PRIORITY + 1).unwrap(); if *MUTEX.lock() == ITERATIONS * NUM_TASK { - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } else { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } } diff --git a/examples/tests/sync/semaphore/10_tasks_100_up_down.rs b/examples/tests/sync/semaphore/10_tasks_100_up_down.rs index 5a95671..ddfd5f2 100644 --- a/examples/tests/sync/semaphore/10_tasks_100_up_down.rs +++ b/examples/tests/sync/semaphore/10_tasks_100_up_down.rs @@ -3,7 +3,12 @@ extern crate alloc; use core::sync::atomic::{AtomicUsize, Ordering}; -use hopter::{debug::semihosting, hprintln, sync::Semaphore, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Semaphore, + task, + task::main, +}; static SEMAPHORE: Semaphore = Semaphore::new(10, 5); static TASK_COMPLETION_COUNTER: AtomicUsize = AtomicUsize::new(0); @@ -37,10 +42,10 @@ fn check() { let final_count = SEMAPHORE.count(); // Check if the count matches the initial value if final_count == 5 { - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } else { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } } diff --git a/examples/tests/sync/semaphore/2_tasks_5_down_5_up.rs b/examples/tests/sync/semaphore/2_tasks_5_down_5_up.rs index f4deb00..0955e83 100644 --- a/examples/tests/sync/semaphore/2_tasks_5_down_5_up.rs +++ b/examples/tests/sync/semaphore/2_tasks_5_down_5_up.rs @@ -2,7 +2,12 @@ #![no_std] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Semaphore, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Semaphore, + task, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -17,19 +22,19 @@ fn main(_: cortex_m::Peripherals) { static SEMAPHORE: Semaphore = Semaphore::new(3, 3); fn task1() { - hprintln!("Task 1 started"); + dbg_println!("Task 1 started"); for i in 1..6 { SEMAPHORE.down(); - hprintln!("Down {}", i); + dbg_println!("Down {}", i); } - hprintln!("Task1 completed"); + dbg_println!("Task1 completed"); } fn task2() { - hprintln!("Task 2 started"); + dbg_println!("Task 2 started"); for i in 1..6 { SEMAPHORE.up(); - hprintln!("Up {}", i); + dbg_println!("Up {}", i); } - hprintln!("Task2 completed"); + dbg_println!("Task2 completed"); } diff --git a/examples/tests/sync/semaphore/4_tasks_down_contend_init_3.rs b/examples/tests/sync/semaphore/4_tasks_down_contend_init_3.rs index d1873b9..f696d23 100644 --- a/examples/tests/sync/semaphore/4_tasks_down_contend_init_3.rs +++ b/examples/tests/sync/semaphore/4_tasks_down_contend_init_3.rs @@ -2,7 +2,13 @@ #![no_std] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Semaphore, task, task::main, time}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Semaphore, + task, + task::main, + time, +}; static SEMAPHORE: Semaphore = Semaphore::new(3, 3); @@ -18,57 +24,57 @@ fn main(_: cortex_m::Peripherals) { } fn task1() { - hprintln!("Task 1 started"); + dbg_println!("Task 1 started"); SEMAPHORE.down(); - hprintln!("Task 1 acquired semaphore"); + dbg_println!("Task 1 acquired semaphore"); time::sleep_ms(1000); - hprintln!("Task 1 releasing semaphore"); + dbg_println!("Task 1 releasing semaphore"); SEMAPHORE.up(); - hprintln!("Task 1 completed"); + dbg_println!("Task 1 completed"); } fn task2() { - hprintln!("Task 2 started"); + dbg_println!("Task 2 started"); SEMAPHORE.down(); - hprintln!("Task 2 acquired semaphore"); + dbg_println!("Task 2 acquired semaphore"); time::sleep_ms(1000); - hprintln!("Task 2 releasing semaphore"); + dbg_println!("Task 2 releasing semaphore"); SEMAPHORE.up(); - hprintln!("Task 2 completed"); + dbg_println!("Task 2 completed"); } fn task3() { - hprintln!("Task 3 started"); + dbg_println!("Task 3 started"); SEMAPHORE.down(); - hprintln!("Task 3 acquired semaphore"); + dbg_println!("Task 3 acquired semaphore"); time::sleep_ms(1000); - hprintln!("Task 3 releasing semaphore"); + dbg_println!("Task 3 releasing semaphore"); SEMAPHORE.up(); - hprintln!("Task 3 completed"); + dbg_println!("Task 3 completed"); } fn task4() { - hprintln!("Task 4 started"); + dbg_println!("Task 4 started"); SEMAPHORE.down(); - hprintln!("Task 4 acquired semaphore"); + dbg_println!("Task 4 acquired semaphore"); time::sleep_ms(1000); - hprintln!("Task 4 releasing semaphore"); + dbg_println!("Task 4 releasing semaphore"); SEMAPHORE.up(); - hprintln!("Task 4 completed"); + dbg_println!("Task 4 completed"); } diff --git a/examples/tests/sync/semaphore/down_0_then_try_down.rs b/examples/tests/sync/semaphore/down_0_then_try_down.rs index 0d723af..a3678fe 100644 --- a/examples/tests/sync/semaphore/down_0_then_try_down.rs +++ b/examples/tests/sync/semaphore/down_0_then_try_down.rs @@ -2,7 +2,11 @@ #![no_main] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Semaphore, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Semaphore, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -17,11 +21,11 @@ fn main(_: cortex_m::Peripherals) { match result { Ok(()) => { - hprintln!("Decremented at 0"); + dbg_println!("Decremented at 0"); semihosting::terminate(false); } Err(()) => { - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } } diff --git a/examples/tests/sync/semaphore/down_priority_scheduling.rs b/examples/tests/sync/semaphore/down_priority_scheduling.rs index a7d86ae..b7463ac 100644 --- a/examples/tests/sync/semaphore/down_priority_scheduling.rs +++ b/examples/tests/sync/semaphore/down_priority_scheduling.rs @@ -2,7 +2,13 @@ #![no_std] extern crate alloc; -use hopter::{config, debug::semihosting, hprintln, sync::Semaphore, task, task::main}; +use hopter::{ + config, + debug::semihosting::{self, dbg_println}, + sync::Semaphore, + task, + task::main, +}; static SEMAPHORE: Semaphore = Semaphore::new(1, 0); @@ -39,15 +45,15 @@ fn main(_: cortex_m::Peripherals) { fn high_task() { SEMAPHORE.down(); - hprintln!("High priority task executed"); + dbg_println!("High priority task executed"); } fn middle_task() { SEMAPHORE.down(); - hprintln!("Middle priority task executed"); + dbg_println!("Middle priority task executed"); } fn low_task() { SEMAPHORE.down(); - hprintln!("Low priority task executed"); + dbg_println!("Low priority task executed"); } diff --git a/examples/tests/sync/semaphore/init_0_blocking_down.rs b/examples/tests/sync/semaphore/init_0_blocking_down.rs index fea9146..5e009a2 100644 --- a/examples/tests/sync/semaphore/init_0_blocking_down.rs +++ b/examples/tests/sync/semaphore/init_0_blocking_down.rs @@ -2,7 +2,12 @@ #![no_std] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Semaphore, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Semaphore, + task, + task::main, +}; static SEMAPHORE: Semaphore = Semaphore::new(1, 0); @@ -13,13 +18,13 @@ fn main(_: cortex_m::Peripherals) { } fn acquire() { - hprintln!("attempting to acquire semaphore.."); + dbg_println!("attempting to acquire semaphore.."); SEMAPHORE.down(); - hprintln!("semaphore acquired"); + dbg_println!("semaphore acquired"); semihosting::terminate(true); } fn release() { SEMAPHORE.up(); - hprintln!("semaphore released"); + dbg_println!("semaphore released"); } diff --git a/examples/tests/sync/semaphore/initialization.rs b/examples/tests/sync/semaphore/initialization.rs index 5d212c9..62618fe 100644 --- a/examples/tests/sync/semaphore/initialization.rs +++ b/examples/tests/sync/semaphore/initialization.rs @@ -2,7 +2,7 @@ #![no_std] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Semaphore, task::main}; +use hopter::{debug::semihosting::{self, dbg_println}, sync::Semaphore, task::main}; #[main] fn main(_: cortex_m::Peripherals) { @@ -10,11 +10,11 @@ fn main(_: cortex_m::Peripherals) { for j in 5..10 { let semaphore = Semaphore::new(j, i); if semaphore.count() != i || semaphore.max_count() != j { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } } } - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } diff --git a/examples/tests/sync/semaphore/try_down_from_isr.rs b/examples/tests/sync/semaphore/try_down_from_isr.rs index 88fec09..5f095d5 100644 --- a/examples/tests/sync/semaphore/try_down_from_isr.rs +++ b/examples/tests/sync/semaphore/try_down_from_isr.rs @@ -9,8 +9,7 @@ extern crate alloc; use core::sync::atomic::{AtomicUsize, Ordering}; use hopter::{ config, - debug::semihosting, - hprintln, + debug::semihosting::{self, dbg_println}, interrupt::declare::{handler, irq}, sync::{Semaphore, SpinIrqSafe}, task, @@ -66,9 +65,9 @@ fn main(_cp: cortex_m::Peripherals) { fn up_function() { for _ in 0..3 { - hprintln!("Before task blocking"); + dbg_println!("Before task blocking"); SEMAPHORE.up(); - hprintln!("After task resuming"); + dbg_println!("After task resuming"); } semihosting::terminate(true); } @@ -89,10 +88,10 @@ extern "C" fn tim2_handler() { let result = SEMAPHORE.try_down_allow_isr(); match result { Ok(_) => { - hprintln!("Semaphore down to {}", SEMAPHORE.count()) + dbg_println!("Semaphore down to {}", SEMAPHORE.count()) } Err(_) => { - hprintln!("Failed to down"); + dbg_println!("Failed to down"); semihosting::terminate(false); } } diff --git a/examples/tests/sync/semaphore/try_down_ok_then_err.rs b/examples/tests/sync/semaphore/try_down_ok_then_err.rs index 99dce46..0341505 100644 --- a/examples/tests/sync/semaphore/try_down_ok_then_err.rs +++ b/examples/tests/sync/semaphore/try_down_ok_then_err.rs @@ -2,7 +2,7 @@ #![no_std] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Semaphore, task::main}; +use hopter::{debug::semihosting::{self, dbg_println}, sync::Semaphore, task::main}; static SEMAPHORE: Semaphore = Semaphore::new(5, 3); @@ -13,7 +13,7 @@ fn main(_: cortex_m::Peripherals) { match result { Ok(()) => {} Err(()) => { - hprintln!("Did not decrement"); + dbg_println!("Did not decrement"); semihosting::terminate(false); } } @@ -27,11 +27,11 @@ fn main(_: cortex_m::Peripherals) { match second_result { Ok(()) => { - hprintln!("Decremented at 0"); + dbg_println!("Decremented at 0"); semihosting::terminate(false); } Err(()) => { - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } } diff --git a/examples/tests/sync/semaphore/try_up_from_isr.rs b/examples/tests/sync/semaphore/try_up_from_isr.rs index eeb11ad..c5ff07a 100644 --- a/examples/tests/sync/semaphore/try_up_from_isr.rs +++ b/examples/tests/sync/semaphore/try_up_from_isr.rs @@ -9,8 +9,7 @@ extern crate alloc; use core::sync::atomic::{AtomicUsize, Ordering}; use hopter::{ config, - debug::semihosting, - hprintln, + debug::semihosting::{self, dbg_println}, interrupt::declare::{handler, irq}, sync::{Semaphore, SpinIrqSafe}, task, @@ -66,9 +65,9 @@ fn main(_cp: cortex_m::Peripherals) { fn down_function() { for _ in 0..3 { - hprintln!("Before task blocking"); + dbg_println!("Before task blocking"); SEMAPHORE.down(); - hprintln!("After task resuming"); + dbg_println!("After task resuming"); } semihosting::terminate(true); } @@ -89,10 +88,10 @@ extern "C" fn tim2_handler() { let result = SEMAPHORE.try_up_allow_isr(); match result { Ok(_) => { - hprintln!("Semaphore up to {}", SEMAPHORE.count()) + dbg_println!("Semaphore up to {}", SEMAPHORE.count()) } Err(_) => { - hprintln!("Failed to up"); + dbg_println!("Failed to up"); semihosting::terminate(false); } } diff --git a/examples/tests/sync/semaphore/try_up_ok_then_err.rs b/examples/tests/sync/semaphore/try_up_ok_then_err.rs index c3d4f52..d34d67c 100644 --- a/examples/tests/sync/semaphore/try_up_ok_then_err.rs +++ b/examples/tests/sync/semaphore/try_up_ok_then_err.rs @@ -2,7 +2,7 @@ #![no_std] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Semaphore, task::main}; +use hopter::{debug::semihosting::{self, dbg_println}, sync::Semaphore, task::main}; static SEMAPHORE: Semaphore = Semaphore::new(5, 2); @@ -13,7 +13,7 @@ fn main(_: cortex_m::Peripherals) { match result { Ok(()) => {} Err(()) => { - hprintln!("Did not increment"); + dbg_println!("Did not increment"); semihosting::terminate(false); } } @@ -27,11 +27,11 @@ fn main(_: cortex_m::Peripherals) { match second_result { Ok(()) => { - hprintln!("incremented at max"); + dbg_println!("incremented at max"); semihosting::terminate(false); } Err(()) => { - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } } diff --git a/examples/tests/sync/semaphore/up_max_then_try_up.rs b/examples/tests/sync/semaphore/up_max_then_try_up.rs index cb5121f..9f799dc 100644 --- a/examples/tests/sync/semaphore/up_max_then_try_up.rs +++ b/examples/tests/sync/semaphore/up_max_then_try_up.rs @@ -2,7 +2,11 @@ #![no_main] extern crate alloc; -use hopter::{debug::semihosting, hprintln, sync::Semaphore, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + sync::Semaphore, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -16,11 +20,11 @@ fn main(_: cortex_m::Peripherals) { match result { Ok(()) => { - hprintln!("Incremented when at max count"); + dbg_println!("Incremented when at max count"); semihosting::terminate(false); } Err(()) => { - hprintln!("Test Passed"); + dbg_println!("Test Passed"); semihosting::terminate(true); } } diff --git a/examples/tests/sync/semaphore/up_priority_scheduling.rs b/examples/tests/sync/semaphore/up_priority_scheduling.rs index 136a517..05b05a9 100644 --- a/examples/tests/sync/semaphore/up_priority_scheduling.rs +++ b/examples/tests/sync/semaphore/up_priority_scheduling.rs @@ -2,7 +2,13 @@ #![no_std] extern crate alloc; -use hopter::{config, debug::semihosting, hprintln, sync::Semaphore, task, task::main}; +use hopter::{ + config, + debug::semihosting::{self, dbg_println}, + sync::Semaphore, + task, + task::main, +}; static SEMAPHORE: Semaphore = Semaphore::new(1, 1); @@ -39,15 +45,15 @@ fn main(_: cortex_m::Peripherals) { fn high_task() { SEMAPHORE.up(); - hprintln!("High priority task executed"); + dbg_println!("High priority task executed"); } fn middle_task() { SEMAPHORE.up(); - hprintln!("Middle priority task executed"); + dbg_println!("Middle priority task executed"); } fn low_task() { SEMAPHORE.up(); - hprintln!("Low priority task executed"); + dbg_println!("Low priority task executed"); } diff --git a/examples/tests/task/context_switch/fp_registers.rs b/examples/tests/task/context_switch/fp_registers.rs index fcb5600..44b14c5 100644 --- a/examples/tests/task/context_switch/fp_registers.rs +++ b/examples/tests/task/context_switch/fp_registers.rs @@ -6,7 +6,12 @@ extern crate alloc; use core::{arch::asm, sync::atomic::AtomicBool}; -use hopter::{config, debug::semihosting, hprintln, task, task::main}; +use hopter::{ + config, + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; /// Whether the verifier task is running. static TEST_STARTED: AtomicBool = AtomicBool::new(false); @@ -190,11 +195,11 @@ extern "C" fn compare_fp_regs() { } extern "C" fn error() -> ! { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } extern "C" fn success() -> ! { - hprintln!("Test Succeeded"); + dbg_println!("Test Succeeded"); semihosting::terminate(true); } diff --git a/examples/tests/task/context_switch/gp_registers.rs b/examples/tests/task/context_switch/gp_registers.rs index ef5a8f9..10c9497 100644 --- a/examples/tests/task/context_switch/gp_registers.rs +++ b/examples/tests/task/context_switch/gp_registers.rs @@ -6,7 +6,12 @@ extern crate alloc; use core::{arch::asm, sync::atomic::AtomicBool}; -use hopter::{config, debug::semihosting, hprintln, task, task::main}; +use hopter::{ + config, + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; /// Whether the verifier task is running. static TEST_STARTED: AtomicBool = AtomicBool::new(false); @@ -167,11 +172,11 @@ extern "C" fn clobber_all_gp_regs() -> ! { } extern "C" fn error() -> ! { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } extern "C" fn success() -> ! { - hprintln!("Test Succeeded"); + dbg_println!("Test Succeeded"); semihosting::terminate(true); } diff --git a/examples/tests/task/priority/reduce_priority.rs b/examples/tests/task/priority/reduce_priority.rs index 7e47cc2..a6c6831 100644 --- a/examples/tests/task/priority/reduce_priority.rs +++ b/examples/tests/task/priority/reduce_priority.rs @@ -5,18 +5,22 @@ #![no_main] extern crate alloc; -use hopter::{debug::semihosting, hprintln, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; /// The main task always starts with the highest priority (numerical value 0). #[main] fn main(_: cortex_m::Peripherals) { task::build().set_entry(task).spawn().unwrap(); - hprintln!("one"); + dbg_println!("one"); task::change_current_priority(10).unwrap(); - hprintln!("three"); + dbg_println!("three"); semihosting::terminate(true); } fn task() { - hprintln!("two"); + dbg_println!("two"); } diff --git a/examples/tests/task/priority/unwind_priority.rs b/examples/tests/task/priority/unwind_priority.rs index 82a3223..9bd2040 100644 --- a/examples/tests/task/priority/unwind_priority.rs +++ b/examples/tests/task/priority/unwind_priority.rs @@ -7,7 +7,12 @@ extern crate alloc; use alloc::string::String; -use hopter::{config, debug::semihosting, hprintln, task, task::main}; +use hopter::{ + config, + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; struct DataPointer { data: String, @@ -15,7 +20,7 @@ struct DataPointer { impl Drop for DataPointer { fn drop(&mut self) { - hprintln!("Dropping {}", self.data); + dbg_println!("Dropping {}", self.data); } } @@ -47,7 +52,7 @@ fn high_task() { let _resource = DataPointer { data: String::from("High priority resource"), }; - hprintln!("High priority task going to panic"); + dbg_println!("High priority task going to panic"); panic!(); } @@ -55,12 +60,12 @@ fn middle_task() { let _resource = DataPointer { data: String::from("Middle priority resource"), }; - hprintln!("Middle priority task executed"); + dbg_println!("Middle priority task executed"); } fn low_task() { let _resource = DataPointer { data: String::from("Low priority resource"), }; - hprintln!("Low priority task executed"); + dbg_println!("Low priority task executed"); } diff --git a/examples/tests/task/segmented_stack/function_arguments.rs b/examples/tests/task/segmented_stack/function_arguments.rs index 3065fce..6f5888a 100644 --- a/examples/tests/task/segmented_stack/function_arguments.rs +++ b/examples/tests/task/segmented_stack/function_arguments.rs @@ -7,7 +7,11 @@ extern crate alloc; use core::arch::asm; -use hopter::{debug::semihosting, hprintln, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; #[naked] extern "C" fn prepare_regs_stack() { @@ -114,11 +118,11 @@ extern "C" fn verify_arguments() { } extern "C" fn success() { - hprintln!("Test Passed"); + dbg_println!("Test Passed"); } extern "C" fn error() { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } diff --git a/examples/tests/task/segmented_stack/return_values.rs b/examples/tests/task/segmented_stack/return_values.rs index 643fb23..9eed4f6 100644 --- a/examples/tests/task/segmented_stack/return_values.rs +++ b/examples/tests/task/segmented_stack/return_values.rs @@ -6,7 +6,11 @@ extern crate alloc; use core::arch::asm; -use hopter::{debug::semihosting, hprintln, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; #[naked] extern "C" fn callee() { @@ -88,11 +92,11 @@ extern "C" fn caller() { } extern "C" fn success() { - hprintln!("Test Passed"); + dbg_println!("Test Passed"); } extern "C" fn error() { - hprintln!("Test Failed"); + dbg_println!("Test Failed"); semihosting::terminate(false); } diff --git a/examples/tests/task/unwind/concurrent_restart.rs b/examples/tests/task/unwind/concurrent_restart.rs index 443fe48..65caf3a 100644 --- a/examples/tests/task/unwind/concurrent_restart.rs +++ b/examples/tests/task/unwind/concurrent_restart.rs @@ -8,7 +8,12 @@ extern crate alloc; use core::sync::atomic::{AtomicBool, Ordering}; -use hopter::{config, debug::semihosting, hprintln, task, task::main}; +use hopter::{ + config, + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -34,13 +39,13 @@ fn will_panic() { panic!() } - hprintln!("Second run completed"); + dbg_println!("Second run completed"); } struct PrintOnDrop(&'static str); impl Drop for PrintOnDrop { fn drop(&mut self) { - hprintln!("{}", self.0) + dbg_println!("{}", self.0) } } diff --git a/examples/tests/task/unwind/deferred_direct_drop.rs b/examples/tests/task/unwind/deferred_direct_drop.rs index 1c6a8a5..50e0df1 100644 --- a/examples/tests/task/unwind/deferred_direct_drop.rs +++ b/examples/tests/task/unwind/deferred_direct_drop.rs @@ -10,7 +10,11 @@ use core::{ mem::MaybeUninit, sync::atomic::{AtomicUsize, Ordering}, }; -use hopter::{debug::semihosting, hprintln, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -43,11 +47,11 @@ fn test_task() { if cnt == 0 { // The task should have been unwound so this print should not be // reachable. - hprintln!("Should not print this."); + dbg_println!("Should not print this."); } if cnt > 0 { - hprintln!("Task successfully restarted after a deferred forced unwinding."); + dbg_println!("Task successfully restarted after a deferred forced unwinding."); semihosting::terminate(true); } else { semihosting::terminate(false); @@ -61,7 +65,7 @@ impl Drop for HasDrop { #[inline(never)] fn drop(&mut self) { let _padding = StackFramePadding::new(); - hprintln!("Drop executed."); + dbg_println!("Drop executed."); } } diff --git a/examples/tests/task/unwind/deferred_indirect_drop.rs b/examples/tests/task/unwind/deferred_indirect_drop.rs index 720d339..dc879c2 100644 --- a/examples/tests/task/unwind/deferred_indirect_drop.rs +++ b/examples/tests/task/unwind/deferred_indirect_drop.rs @@ -10,7 +10,11 @@ use core::{ mem::MaybeUninit, sync::atomic::{AtomicUsize, Ordering}, }; -use hopter::{debug::semihosting, hprintln, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -43,11 +47,11 @@ fn test_task() { if cnt == 0 { // The task should have been unwound so this print should not be // reachable. - hprintln!("Should not print this."); + dbg_println!("Should not print this."); } if cnt > 0 { - hprintln!("Task successfully restarted after a deferred forced unwinding."); + dbg_println!("Task successfully restarted after a deferred forced unwinding."); semihosting::terminate(true); } else { semihosting::terminate(false); @@ -57,7 +61,7 @@ fn test_task() { #[inline(never)] fn large_func() { let _padding = StackFramePadding::new(); - hprintln!("Large function executed."); + dbg_println!("Large function executed."); } struct HasDrop; @@ -67,7 +71,7 @@ impl Drop for HasDrop { #[inline(never)] fn drop(&mut self) { large_func(); - hprintln!("Drop executed."); + dbg_println!("Drop executed."); } } diff --git a/examples/tests/task/unwind/deferred_nested_drop.rs b/examples/tests/task/unwind/deferred_nested_drop.rs index 34a0656..68b880e 100644 --- a/examples/tests/task/unwind/deferred_nested_drop.rs +++ b/examples/tests/task/unwind/deferred_nested_drop.rs @@ -12,7 +12,11 @@ use core::{ mem::MaybeUninit, sync::atomic::{AtomicUsize, Ordering}, }; -use hopter::{debug::semihosting, hprintln, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -45,11 +49,11 @@ fn test_task() { if cnt == 0 { // The task should have been unwound so this print should not be // reachable. - hprintln!("Should not print this."); + dbg_println!("Should not print this."); } if cnt > 0 { - hprintln!("Task successfully restarted after a deferred forced unwinding."); + dbg_println!("Task successfully restarted after a deferred forced unwinding."); semihosting::terminate(true); } else { semihosting::terminate(false); @@ -62,7 +66,7 @@ struct OuterDrop(InnerDrop); impl Drop for OuterDrop { #[inline(never)] fn drop(&mut self) { - hprintln!("Outter drop executed."); + dbg_println!("Outter drop executed."); } } @@ -73,7 +77,7 @@ impl Drop for InnerDrop { #[inline(never)] fn drop(&mut self) { let _padding = StackFramePadding::new(); - hprintln!("Inner drop executed."); + dbg_println!("Inner drop executed."); } } diff --git a/examples/tests/task/unwind/diverted.rs b/examples/tests/task/unwind/diverted.rs index 2579f66..543d638 100644 --- a/examples/tests/task/unwind/diverted.rs +++ b/examples/tests/task/unwind/diverted.rs @@ -9,7 +9,11 @@ use core::{ mem::MaybeUninit, sync::atomic::{AtomicUsize, Ordering}, }; -use hopter::{debug::semihosting, hprintln, task, task::main}; +use hopter::{ + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -38,11 +42,11 @@ fn test_task() { if cnt == 0 { // The task should have been unwound so this print should not be // reachable. - hprintln!("Should not print this."); + dbg_println!("Should not print this."); } if cnt > 0 { - hprintln!("Task successfully restarted after a diverted forced unwinding."); + dbg_println!("Task successfully restarted after a diverted forced unwinding."); semihosting::terminate(true); } else { semihosting::terminate(false); diff --git a/examples/tests/task/unwind/failed_concurrent_restart.rs b/examples/tests/task/unwind/failed_concurrent_restart.rs index ae1f5e7..6172de9 100644 --- a/examples/tests/task/unwind/failed_concurrent_restart.rs +++ b/examples/tests/task/unwind/failed_concurrent_restart.rs @@ -7,7 +7,12 @@ extern crate alloc; use core::sync::atomic::{AtomicBool, Ordering}; -use hopter::{config, debug::semihosting, hprintln, task, task::main}; +use hopter::{ + config, + debug::semihosting::{self, dbg_println}, + task, + task::main, +}; #[main] fn main(_: cortex_m::Peripherals) { @@ -51,13 +56,13 @@ fn will_panic() { panic!() } - hprintln!("Second run completed"); + dbg_println!("Second run completed"); } struct PrintOnDrop(&'static str); impl Drop for PrintOnDrop { fn drop(&mut self) { - hprintln!("{}", self.0) + dbg_println!("{}", self.0) } } diff --git a/src/debug/semihosting.rs b/src/debug/semihosting.rs index db0ccae..fa432e9 100644 --- a/src/debug/semihosting.rs +++ b/src/debug/semihosting.rs @@ -14,7 +14,7 @@ //! cause HardFault if the segmented stack tries to extend when the interrupt is //! globally masked. //! -//! Original license: https://opensource.org/license/mit +//! Original license: use crate::{interrupt::mask::AllIrqExceptSvc, sync::SpinSchedIrqSafe}; use core::fmt::{self, Write}; @@ -76,8 +76,9 @@ pub fn hstderr_fmt(args: fmt::Arguments) { /// /// This is similar to the `print!` macro in the standard library. Both will panic on any failure to /// print. +#[doc(hidden)] #[macro_export] -macro_rules! hprint { +macro_rules! __macro_impl_dbg_print { ($s:expr) => { $crate::debug::semihosting::hstdout_str($s) }; @@ -90,8 +91,9 @@ macro_rules! hprint { /// /// This is similar to the `println!` macro in the standard library. Both will panic on any failure to /// print. +#[doc(hidden)] #[macro_export] -macro_rules! hprintln { +macro_rules! __macro_impl_dbg_println { () => { $crate::debug::semihosting::hstdout_str("\n") }; @@ -107,8 +109,9 @@ macro_rules! hprintln { /// /// This is similar to the `eprint!` macro in the standard library. Both will panic on any failure /// to print. +#[doc(hidden)] #[macro_export] -macro_rules! heprint { +macro_rules! __macro_impl_dbg_eprint { ($s:expr) => { $crate::debug::semihosting::hstderr_str($s) }; @@ -121,8 +124,9 @@ macro_rules! heprint { /// /// This is similar to the `eprintln!` macro in the standard library. Both will panic on any failure /// to print. +#[doc(hidden)] #[macro_export] -macro_rules! heprintln { +macro_rules! __macro_impl_dbg_eprintln { () => { $crate::debug::semihosting::hstderr_str("\n") }; @@ -133,3 +137,12 @@ macro_rules! heprintln { $crate::debug::semihosting::hstderr_fmt(format_args!(concat!($s, "\n"), $($tt)*)) }; } + +#[doc(inline)] +pub use __macro_impl_dbg_eprint as dbg_eprint; +#[doc(inline)] +pub use __macro_impl_dbg_eprintln as dbg_eprintln; +#[doc(inline)] +pub use __macro_impl_dbg_print as dbg_print; +#[doc(inline)] +pub use __macro_impl_dbg_println as dbg_println; diff --git a/src/interrupt/declare.rs b/src/interrupt/declare.rs index cc427dd..2fe05b2 100644 --- a/src/interrupt/declare.rs +++ b/src/interrupt/declare.rs @@ -24,7 +24,7 @@ pub use paste as __paste; /// ``` #[doc(hidden)] #[macro_export] -macro_rules! __declare_irq { +macro_rules! __macro_impl_declare_irq { ($name:ident, $irq:path) => { $crate::interrupt::declare::__paste::paste! { #[allow(non_upper_case_globals)] @@ -55,7 +55,7 @@ macro_rules! __declare_irq { } #[doc(inline)] -pub use __declare_irq as irq; +pub use __macro_impl_declare_irq as irq; #[doc(inline)] pub use hopter_proc_macro::handler;