kernel: debug: don't print out if not initialized

This allows us to use println early on even before it's initialized,
which will allow us to ignore prints to an uninitialized port.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-03-03 21:13:03 +08:00
parent 93d295b93b
commit 506bd381b2
2 changed files with 9 additions and 2 deletions

View file

@ -6,6 +6,8 @@ use core::fmt::{Error, Write};
#[cfg(baremetal)]
use utralib::generated::*;
static mut INITIALIZED: bool = false;
#[macro_use]
#[cfg(all(
not(test),
@ -67,12 +69,17 @@ pub struct Uart {
#[cfg(baremetal)]
impl Uart {
#[allow(dead_code)]
pub fn enable_rx(self) {
pub fn init(self) {
unsafe { INITIALIZED = true };
let mut uart_csr = CSR::new(0xffcf_0000 as *mut u32);
uart_csr.rmwf(utra::uart::EV_ENABLE_RX, 1);
}
pub fn putc(&self, c: u8) {
if unsafe { INITIALIZED != true } {
return;
}
let mut uart_csr = CSR::new(0xffcf_0000 as *mut u32);
// Wait until TXFULL is `0`
while uart_csr.r(utra::uart::TXFULL) != 0 {

View file

@ -76,8 +76,8 @@ pub extern "C" fn init(arg_offset: *const u32, init_offset: *const u32, rpt_offs
)
.expect("unable to map serial port")
});
debug::Uart{}.init();
println!("KMAIN: Supervisor mode started...");
debug::Uart{}.enable_rx();
println!("Claiming IRQ {} via syscall...", utra::uart::UART_IRQ);
xous_kernel::claim_interrupt(utra::uart::UART_IRQ, debug::irq, 0 as *mut usize)
.expect("Couldn't claim debug interrupt");