mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
format services/xous-log
This commit is contained in:
parent
4f6f595b2f
commit
931309590f
9 changed files with 83 additions and 130 deletions
|
|
@ -7,8 +7,8 @@ use xous_api_log::api;
|
|||
mod platform;
|
||||
|
||||
use core::fmt::Write;
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
use num_traits::FromPrimitive;
|
||||
use platform::implementation;
|
||||
|
||||
/// A page-aligned stack allocation for connection requests (used by USB resolver)
|
||||
|
|
@ -21,13 +21,7 @@ struct ConnectRequest {
|
|||
}
|
||||
#[cfg(feature = "usb")]
|
||||
impl Default for ConnectRequest {
|
||||
fn default() -> Self {
|
||||
ConnectRequest {
|
||||
name: [0u8; 64],
|
||||
len: 0,
|
||||
_padding: [0u8; 4096 - 4 - 64],
|
||||
}
|
||||
}
|
||||
fn default() -> Self { ConnectRequest { name: [0u8; 64], len: 0, _padding: [0u8; 4096 - 4 - 64] } }
|
||||
}
|
||||
|
||||
#[cfg(feature = "usb")]
|
||||
|
|
@ -39,10 +33,7 @@ pub struct UsbString {
|
|||
|
||||
#[cfg(feature = "usb")]
|
||||
fn usb_send_str(conn: xous::CID, s: &str) {
|
||||
let serializer = UsbString {
|
||||
s: xous_ipc::String::<4000>::from_str(s),
|
||||
sent: None,
|
||||
};
|
||||
let serializer = UsbString { s: xous_ipc::String::<4000>::from_str(s), sent: None };
|
||||
let buf = xous_ipc::Buffer::into_buf(serializer).expect("usb error");
|
||||
// failures to send are silent & ignored; also, this API doesn't block.
|
||||
buf.send(conn, 8192 /* LogString */).expect("usb error");
|
||||
|
|
@ -125,10 +116,12 @@ fn reader_thread(arg: usize) {
|
|||
#[cfg(feature = "usb")]
|
||||
if let Some(conn) = usb_serial {
|
||||
if usb_str.len() > 0 {
|
||||
// test length so we aren't constantly copying 4096 bytes of 0's clearing an already cleared structure.
|
||||
// test length so we aren't constantly copying 4096 bytes of 0's clearing an
|
||||
// already cleared structure.
|
||||
usb_str.clear();
|
||||
}
|
||||
// duplicate the above code because doing repeated calls to the USB stack is inefficient
|
||||
// duplicate the above code because doing repeated calls to the USB stack is
|
||||
// inefficient
|
||||
write!(usb_str, "{}:", level).ok();
|
||||
for c in module_slice {
|
||||
usb_str.push_byte(*c).ok();
|
||||
|
|
@ -181,8 +174,8 @@ fn reader_thread(arg: usize) {
|
|||
#[cfg(feature = "usb")]
|
||||
if let Some(conn) = usb_serial {
|
||||
// safety: this routine will just blow up if you try to pass non utf-8 to it,
|
||||
// so it's not very safe. On the other hand, it's fast and shame on you for sending
|
||||
// non-utf8 to this API.
|
||||
// so it's not very safe. On the other hand, it's fast and shame on you for
|
||||
// sending non-utf8 to this API.
|
||||
usb_send_str(conn, unsafe { std::str::from_utf8_unchecked(buffer) });
|
||||
}
|
||||
}
|
||||
|
|
@ -343,10 +336,7 @@ fn main() -> ! {
|
|||
let mut writer = output.get_writer();
|
||||
println!("LOG: my PID is {}", xous::process::id());
|
||||
println!("LOG: Creating the reader thread");
|
||||
xous::create_thread_1(
|
||||
reader_thread,
|
||||
&mut writer as *mut implementation::OutputWriter as usize,
|
||||
)
|
||||
xous::create_thread_1(reader_thread, &mut writer as *mut implementation::OutputWriter as usize)
|
||||
.expect("create reader thread");
|
||||
println!("LOG: Running the output");
|
||||
output.run();
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
// SPDX-FileCopyrightText: 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use atsama5d27::{
|
||||
uart::{Uart as UartHw, Uart1, UART_BASE_ADDRESS},
|
||||
};
|
||||
use core::fmt::{Error, Write};
|
||||
|
||||
use atsama5d27::uart::{Uart as UartHw, Uart1, UART_BASE_ADDRESS};
|
||||
#[cfg(feature = "lcd-console")]
|
||||
use atsama5d27::{lcdc::Lcdc, console::DisplayAndUartConsole, display::FramebufDisplay};
|
||||
use atsama5d27::{console::DisplayAndUartConsole, display::FramebufDisplay, lcdc::Lcdc};
|
||||
#[cfg(feature = "lcd-console")]
|
||||
use utralib::HW_LCDC_BASE;
|
||||
|
||||
use core::fmt::{Error, Write};
|
||||
|
||||
const UART_NUMBER: usize = 1;
|
||||
pub type UartType = UartHw<Uart1>; // Make sure this matches the UART_NUMBER above
|
||||
pub const HW_UART_BASE: u32 = UART_BASE_ADDRESS[UART_NUMBER];
|
||||
|
|
@ -52,12 +49,8 @@ impl Console<UartType> {
|
|||
// Allocate a page for DMA descriptor
|
||||
#[cfg(feature = "lcd-console")]
|
||||
let inner = {
|
||||
let dma_desc_addr = xous::syscall::map_memory(
|
||||
None,
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
let dma_desc_addr =
|
||||
xous::syscall::map_memory(None, None, 4096, xous::MemoryFlags::R | xous::MemoryFlags::W)
|
||||
.expect("couldn't map LCDC DMA descriptor");
|
||||
|
||||
// Access the address of the page to get it physically allocated
|
||||
|
|
@ -65,8 +58,7 @@ impl Console<UartType> {
|
|||
dma_desc_addr.as_mut_ptr().write_volatile(0);
|
||||
}
|
||||
let dma_desc_addr = dma_desc_addr.as_ptr() as _;
|
||||
let dma_desc_addr_phys =
|
||||
xous::syscall::virt_to_phys(dma_desc_addr).expect("can't convert v2p");
|
||||
let dma_desc_addr_phys = xous::syscall::virt_to_phys(dma_desc_addr).expect("can't convert v2p");
|
||||
|
||||
// Allocate framebuffer pages
|
||||
let fb_addr = xous::syscall::map_memory(
|
||||
|
|
@ -79,7 +71,9 @@ impl Console<UartType> {
|
|||
|
||||
// Access the addresses of the framebuffer pages to give them
|
||||
// a continuous physical backing
|
||||
unsafe { fb_addr.as_mut_ptr().write_volatile(0x00); }
|
||||
unsafe {
|
||||
fb_addr.as_mut_ptr().write_volatile(0x00);
|
||||
}
|
||||
let fb_addr = fb_addr.as_ptr() as _;
|
||||
for page in (0..FB_SIZE_BYTES).into_iter().step_by(4096) {
|
||||
unsafe {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use core::fmt::{Error, Write};
|
||||
|
||||
use crate::platform::console::ConsoleSingleton;
|
||||
|
||||
pub struct Output {}
|
||||
|
|
@ -17,9 +18,7 @@ pub fn init() -> Output {
|
|||
}
|
||||
|
||||
impl Output {
|
||||
pub fn get_writer(&self) -> OutputWriter {
|
||||
OutputWriter {}
|
||||
}
|
||||
pub fn get_writer(&self) -> OutputWriter { OutputWriter {} }
|
||||
|
||||
pub fn run(&mut self) {
|
||||
loop {
|
||||
|
|
@ -32,8 +31,8 @@ impl Output {
|
|||
fn handle_console_irq(_irq_no: usize, _arg: *mut usize) {
|
||||
if cfg!(feature = "logging") {
|
||||
// let mut inject_csr = CSR::new(arg as *mut u32);
|
||||
//let mut uart_csr = crate::platform::debug::UartType::with_alt_base_addr(unsafe { crate::platform::debug::DEFAULT_UART_ADDR as u32 });
|
||||
// TODO:
|
||||
//let mut uart_csr = crate::platform::debug::UartType::with_alt_base_addr(unsafe {
|
||||
// crate::platform::debug::DEFAULT_UART_ADDR as u32 }); TODO:
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -56,14 +55,9 @@ impl OutputWriter {
|
|||
buf.len()
|
||||
}
|
||||
|
||||
pub fn write_all(&mut self, buf: &[u8]) -> core::result::Result<usize, ()> {
|
||||
Ok(self.write(buf))
|
||||
}
|
||||
pub fn write_all(&mut self, buf: &[u8]) -> core::result::Result<usize, ()> { Ok(self.write(buf)) }
|
||||
}
|
||||
|
||||
impl Write for OutputWriter {
|
||||
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
||||
ConsoleSingleton {}.write_str(s)
|
||||
fn write_str(&mut self, s: &str) -> Result<(), Error> { ConsoleSingleton {}.write_str(s) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use core::fmt::{Error, Write};
|
||||
|
||||
use utralib::generated::*;
|
||||
|
||||
pub struct Output {}
|
||||
|
|
@ -15,7 +16,8 @@ pub fn init() -> Output {
|
|||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map serial port");
|
||||
// TODO: migrate this to a "proper" UART that is available on SoC hardware, but for now all we have access to is the DUART.
|
||||
// TODO: migrate this to a "proper" UART that is available on SoC hardware, but for now all we have access
|
||||
// to is the DUART.
|
||||
#[cfg(feature = "cramium-soc")]
|
||||
let uart = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::udma_uart_0::HW_UDMA_UART_0_BASE),
|
||||
|
|
@ -123,9 +125,7 @@ pub fn init() -> Output {
|
|||
}
|
||||
|
||||
impl Output {
|
||||
pub fn get_writer(&self) -> OutputWriter {
|
||||
OutputWriter {}
|
||||
}
|
||||
pub fn get_writer(&self) -> OutputWriter { OutputWriter {} }
|
||||
|
||||
pub fn run(&mut self) {
|
||||
loop {
|
||||
|
|
@ -142,10 +142,7 @@ fn handle_console_irq(_irq_no: usize, arg: *mut usize) {
|
|||
// println!("rxe {}", uart_csr.rf(utra::uart::RXEMPTY_RXEMPTY));
|
||||
while uart_csr.rf(utra::uart::RXEMPTY_RXEMPTY) == 0 {
|
||||
// I really rather think this is more readable, than the "Rusty" version below.
|
||||
inject_csr.wfo(
|
||||
utra::keyinject::UART_CHAR_CHAR,
|
||||
uart_csr.rf(utra::uart::RXTX_RXTX),
|
||||
);
|
||||
inject_csr.wfo(utra::keyinject::UART_CHAR_CHAR, uart_csr.rf(utra::uart::RXTX_RXTX));
|
||||
uart_csr.wfo(utra::uart::EV_PENDING_RX, 1);
|
||||
|
||||
// I guess this is how you would do it if you were "really doing Rust"
|
||||
|
|
@ -182,10 +179,10 @@ impl OutputWriter {
|
|||
while uart_csr.r(utra::duart::SFR_SR) != 0 {}
|
||||
uart_csr.wo(utra::duart::SFR_TXD, c as u32);
|
||||
|
||||
// there's a race condition in the handler, if a new character comes in while handling the interrupt,
|
||||
// the pending bit never clears. If the console seems to freeze, uncomment this line.
|
||||
// This kind of works around that, at the expense of maybe losing some Rx characters.
|
||||
// uart_csr.wfo(utra::uart::EV_PENDING_RX, 1);
|
||||
// there's a race condition in the handler, if a new character comes in while handling the
|
||||
// interrupt, the pending bit never clears. If the console seems to freeze, uncomment
|
||||
// this line. This kind of works around that, at the expense of maybe losing some Rx
|
||||
// characters. uart_csr.wfo(utra::uart::EV_PENDING_RX, 1);
|
||||
}
|
||||
#[cfg(feature = "cramium-soc")]
|
||||
{
|
||||
|
|
@ -256,9 +253,7 @@ impl OutputWriter {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn write_all(&mut self, buf: &[u8]) -> core::result::Result<usize, ()> {
|
||||
Ok(self.write(buf))
|
||||
}
|
||||
pub fn write_all(&mut self, buf: &[u8]) -> core::result::Result<usize, ()> { Ok(self.write(buf)) }
|
||||
}
|
||||
|
||||
impl Write for OutputWriter {
|
||||
|
|
|
|||
|
|
@ -16,11 +16,7 @@ pub struct Output {
|
|||
pub fn init() -> Output {
|
||||
let (tx, rx) = channel();
|
||||
|
||||
Output {
|
||||
tx,
|
||||
rx,
|
||||
stdout: std::io::stdout(),
|
||||
}
|
||||
Output { tx, rx, stdout: std::io::stdout() }
|
||||
}
|
||||
|
||||
impl Output {
|
||||
|
|
@ -42,17 +38,11 @@ impl Output {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_writer(&self) -> OutputWriter {
|
||||
OutputWriter {
|
||||
tx: self.tx.clone(),
|
||||
}
|
||||
}
|
||||
pub fn get_writer(&self) -> OutputWriter { OutputWriter { tx: self.tx.clone() } }
|
||||
}
|
||||
|
||||
impl Drop for Output {
|
||||
fn drop(&mut self) {
|
||||
self.tx.send(ControlMessage::Exit).unwrap();
|
||||
}
|
||||
fn drop(&mut self) { self.tx.send(ControlMessage::Exit).unwrap(); }
|
||||
}
|
||||
|
||||
impl Write for Output {
|
||||
|
|
@ -68,9 +58,7 @@ pub struct OutputWriter {
|
|||
}
|
||||
|
||||
impl OutputWriter {
|
||||
pub fn putc(&self, c: u8) {
|
||||
self.tx.send(ControlMessage::Byte(c)).unwrap();
|
||||
}
|
||||
pub fn putc(&self, c: u8) { self.tx.send(ControlMessage::Byte(c)).unwrap(); }
|
||||
}
|
||||
|
||||
impl Write for OutputWriter {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ pub mod precursor;
|
|||
|
||||
#[cfg(any(feature = "precursor", feature = "renode"))]
|
||||
pub use precursor::debug;
|
||||
|
||||
#[cfg(any(feature = "precursor", feature = "renode"))]
|
||||
pub use precursor::implementation;
|
||||
|
||||
|
|
@ -19,12 +18,10 @@ pub use hosted::implementation;
|
|||
#[macro_use]
|
||||
pub mod atsama5d2;
|
||||
|
||||
#[cfg(feature="atsama5d27")]
|
||||
pub use atsama5d2::debug;
|
||||
|
||||
#[cfg(feature = "atsama5d27")]
|
||||
pub use atsama5d2::console;
|
||||
|
||||
#[cfg(feature = "atsama5d27")]
|
||||
pub use atsama5d2::debug;
|
||||
#[cfg(feature = "atsama5d27")]
|
||||
pub use atsama5d2::implementation;
|
||||
|
||||
|
|
@ -34,6 +31,5 @@ pub mod cramium;
|
|||
|
||||
#[cfg(any(feature = "cramium-soc", feature = "cramium-fpga"))]
|
||||
pub use cramium::debug;
|
||||
|
||||
#[cfg(any(feature = "cramium-soc", feature = "cramium-fpga"))]
|
||||
pub use cramium::implementation;
|
||||
|
|
|
|||
|
|
@ -60,13 +60,13 @@ impl Uart {
|
|||
while uart_csr.r(utra::uart::TXFULL) != 0 {}
|
||||
uart_csr.wo(utra::uart::RXTX, c as u32);
|
||||
}
|
||||
|
||||
/// This is an abstraction violation, but this call is actually relied upon by the
|
||||
/// non-debug path to re-enable UART RX during a resume. This should be cleaned up.
|
||||
pub fn enable_rx(&self) {
|
||||
let mut uart_csr = CSR::new(unsafe { DEFAULT_UART_ADDR as *mut u32 });
|
||||
uart_csr.rmwf(utra::uart::EV_ENABLE_RX, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Write for Uart {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use core::fmt::{Error, Write};
|
||||
|
||||
use utralib::generated::*;
|
||||
|
||||
pub struct Output {}
|
||||
|
|
@ -41,9 +42,7 @@ pub fn init() -> Output {
|
|||
}
|
||||
|
||||
impl Output {
|
||||
pub fn get_writer(&self) -> OutputWriter {
|
||||
OutputWriter {}
|
||||
}
|
||||
pub fn get_writer(&self) -> OutputWriter { OutputWriter {} }
|
||||
|
||||
pub fn run(&mut self) {
|
||||
loop {
|
||||
|
|
@ -59,10 +58,7 @@ fn handle_console_irq(_irq_no: usize, arg: *mut usize) {
|
|||
// println!("rxe {}", uart_csr.rf(utra::uart::RXEMPTY_RXEMPTY));
|
||||
while uart_csr.rf(utra::uart::RXEMPTY_RXEMPTY) == 0 {
|
||||
// I really rather think this is more readable, than the "Rusty" version below.
|
||||
inject_csr.wfo(
|
||||
utra::keyinject::UART_CHAR_CHAR,
|
||||
uart_csr.rf(utra::uart::RXTX_RXTX),
|
||||
);
|
||||
inject_csr.wfo(utra::keyinject::UART_CHAR_CHAR, uart_csr.rf(utra::uart::RXTX_RXTX));
|
||||
uart_csr.wfo(utra::uart::EV_PENDING_RX, 1);
|
||||
|
||||
// I guess this is how you would do it if you were "really doing Rust"
|
||||
|
|
@ -99,10 +95,10 @@ impl OutputWriter {
|
|||
while uart_csr.r(utra::uart::TXFULL) != 0 {}
|
||||
uart_csr.wo(utra::uart::RXTX, c as u32);
|
||||
|
||||
// there's a race condition in the handler, if a new character comes in while handling the interrupt,
|
||||
// the pending bit never clears. If the console seems to freeze, uncomment this line.
|
||||
// This kind of works around that, at the expense of maybe losing some Rx characters.
|
||||
// uart_csr.wfo(utra::uart::EV_PENDING_RX, 1);
|
||||
// there's a race condition in the handler, if a new character comes in while handling the
|
||||
// interrupt, the pending bit never clears. If the console seems to freeze, uncomment
|
||||
// this line. This kind of works around that, at the expense of maybe losing some Rx
|
||||
// characters. uart_csr.wfo(utra::uart::EV_PENDING_RX, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue