From 78a47ab4bad785eb1c7d63f401d89a4e008ee9ef Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 23 Nov 2020 16:13:19 +0800 Subject: [PATCH] services: ticktimer: fix debug warnings on hardware These appeared in Rust 1.48. Signed-off-by: Sean Cross --- services/ticktimer-server/src/debug.rs | 30 +++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/services/ticktimer-server/src/debug.rs b/services/ticktimer-server/src/debug.rs index b1274560b..30695887c 100644 --- a/services/ticktimer-server/src/debug.rs +++ b/services/ticktimer-server/src/debug.rs @@ -7,7 +7,7 @@ macro_rules! print { ($($args:tt)+) => ({ use core::fmt::Write; - let _ = write!(crate::debug::DEFAULT, $($args)+); + let _ = write!(crate::debug::Uart {}, $($args)+); }); } #[macro_export] @@ -24,11 +24,10 @@ macro_rules! println }); } - fn handle_irq(irq_no: usize, arg: *mut usize) { print!("Handling IRQ {} (arg: {:08x}): ", irq_no, arg as usize); - - while let Some(c) = crate::debug::DEFAULT.getc() { + let u = crate::debug::Uart {}; + while let Some(c) = u.getc() { print!("{}", c as char); } println!(); @@ -39,8 +38,6 @@ pub struct Uart {} // this is a hack to bypass an explicit initialization/allocation step for the debug structure pub static mut DEFAULT_UART_ADDR: *mut usize = 0x0000_0000 as *mut usize; -pub const DEFAULT: Uart = Uart {}; - impl Uart { fn map_uart(&self) { /* @@ -54,21 +51,28 @@ impl Uart { xous::MemoryFlags::R | xous::MemoryFlags::W, ) .expect("couldn't map debug uart"); - unsafe{ DEFAULT_UART_ADDR = uart.as_mut_ptr() as _; } + unsafe { + DEFAULT_UART_ADDR = uart.as_mut_ptr() as _; + } println!("Mapped UART @ {:08x}", uart.addr.get()); // core::mem::forget(uart); println!("Allocating IRQ..."); - xous::claim_interrupt(utra::server1::SERVER1_IRQ, handle_irq, core::ptr::null_mut::()).expect("unable to allocate IRQ"); + xous::claim_interrupt( + utra::server1::SERVER1_IRQ, + handle_irq, + core::ptr::null_mut::(), + ) + .expect("unable to allocate IRQ"); self.enable_rx(); } pub fn putc(&self, c: u8) { if cfg!(feature = "debugprint") { - if unsafe{DEFAULT_UART_ADDR} as usize == 0 { + if unsafe { DEFAULT_UART_ADDR } as usize == 0 { self.map_uart(); } - let mut uart_csr = CSR::new(unsafe{ DEFAULT_UART_ADDR as *mut u32}); + let mut uart_csr = CSR::new(unsafe { DEFAULT_UART_ADDR as *mut u32 }); // Wait until TXFULL is `0` while uart_csr.r(utra::uart::TXFULL) != 0 {} @@ -78,17 +82,17 @@ impl Uart { pub fn enable_rx(&self) { if cfg!(feature = "debugprint") { - let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32}); + let mut uart_csr = CSR::new(unsafe { DEFAULT_UART_ADDR as *mut u32 }); uart_csr.rmwf(utra::uart::EV_ENABLE_RX, 1); } } pub fn getc(&self) -> Option { if cfg!(feature = "debugprint") { - if unsafe{DEFAULT_UART_ADDR} as usize == 0 { + if unsafe { DEFAULT_UART_ADDR } as usize == 0 { self.map_uart(); } - let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32}); + let mut uart_csr = CSR::new(unsafe { DEFAULT_UART_ADDR as *mut u32 }); match uart_csr.rf(utra::uart::EV_PENDING_RX) { 0 => None, ack => {