diff --git a/artiq/firmware/Cargo.lock b/artiq/firmware/Cargo.lock index ff4780279..4d6a5a473 100644 --- a/artiq/firmware/Cargo.lock +++ b/artiq/firmware/Cargo.lock @@ -26,6 +26,7 @@ dependencies = [ "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "compiler_builtins 0.1.0 (git+https://github.com/m-labs/compiler-builtins?rev=ca06a5e)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp?rev=181083f)", ] @@ -253,7 +254,6 @@ dependencies = [ "build_misoc 0.0.0", "drtioaux 0.0.0", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "logger_artiq 0.0.0", ] [[package]] diff --git a/artiq/firmware/libboard/Cargo.toml b/artiq/firmware/libboard/Cargo.toml index c47f8eecb..abd97a682 100644 --- a/artiq/firmware/libboard/Cargo.toml +++ b/artiq/firmware/libboard/Cargo.toml @@ -14,6 +14,7 @@ build_misoc = { path = "../libbuild_misoc" } [dependencies] byteorder = { version = "1.0", default-features = false } +log = { version = "0.4", default-features = false, optional = true } [dependencies.compiler_builtins] git = "https://github.com/m-labs/compiler-builtins" diff --git a/artiq/firmware/libboard/lib.rs b/artiq/firmware/libboard/lib.rs index 369a38d8c..690f29e99 100644 --- a/artiq/firmware/libboard/lib.rs +++ b/artiq/firmware/libboard/lib.rs @@ -3,6 +3,8 @@ extern crate compiler_builtins; extern crate byteorder; +#[cfg(feature = "log")] +extern crate log; #[cfg(feature = "smoltcp")] extern crate smoltcp; @@ -25,5 +27,7 @@ pub mod spiflash; pub mod config; #[cfg(feature = "uart_console")] pub mod uart_console; +#[cfg(all(feature = "uart_console", feature = "log"))] +pub mod uart_logger; #[cfg(all(has_ethmac, feature = "smoltcp"))] pub mod ethmac; diff --git a/artiq/firmware/libboard/uart_logger.rs b/artiq/firmware/libboard/uart_logger.rs new file mode 100644 index 000000000..c9308f34f --- /dev/null +++ b/artiq/firmware/libboard/uart_logger.rs @@ -0,0 +1,35 @@ +use core::fmt::Write; +use log::{Log, Metadata, Record, set_logger}; + +use clock; +use uart_console::Console; + +pub struct ConsoleLogger; + +impl ConsoleLogger { + pub fn register() { + static LOGGER: ConsoleLogger = ConsoleLogger; + set_logger(&LOGGER).expect("global logger can only be initialized once") + } +} + +impl Log for ConsoleLogger { + fn enabled(&self, _metadata: &Metadata) -> bool { + true + } + + fn log(&self, record: &Record) { + if self.enabled(record.metadata()) { + let timestamp = clock::get_us(); + let seconds = timestamp / 1_000_000; + let micros = timestamp % 1_000_000; + + let _ = write!(Console, "[{:6}.{:06}s] {:>5}({}): {}", + seconds, micros, record.level(), record.target(), record.args()); + } + } + + fn flush(&self) { + } +} + diff --git a/artiq/firmware/satman/Cargo.toml b/artiq/firmware/satman/Cargo.toml index 65f6127b0..a227e58e2 100644 --- a/artiq/firmware/satman/Cargo.toml +++ b/artiq/firmware/satman/Cargo.toml @@ -15,7 +15,6 @@ build_artiq = { path = "../libbuild_artiq" } [dependencies] log = { version = "0.4", default-features = false } -drtioaux = { path = "../libdrtioaux" } -board = { path = "../libboard", features = ["uart_console"] } +board = { path = "../libboard", features = ["uart_console", "log"] } board_artiq = { path = "../libboard_artiq" } -logger_artiq = { path = "../liblogger_artiq" } +drtioaux = { path = "../libdrtioaux" } diff --git a/artiq/firmware/satman/main.rs b/artiq/firmware/satman/main.rs index 5434edc01..da20bba29 100644 --- a/artiq/firmware/satman/main.rs +++ b/artiq/firmware/satman/main.rs @@ -1,9 +1,8 @@ -#![feature(lang_items, global_allocator)] +#![feature(lang_items)] #![no_std] #[macro_use] extern crate log; -extern crate logger_artiq; #[macro_use] extern crate board; extern crate board_artiq; @@ -170,7 +169,6 @@ fn process_aux_packets() { } } - fn process_errors() { let errors; unsafe { @@ -221,8 +219,11 @@ fn drtio_link_rx_up() -> bool { } } -fn startup() { +#[no_mangle] +pub extern fn main() -> i32 { board::clock::init(); + board::uart_logger::ConsoleLogger::register(); + info!("ARTIQ satellite manager starting..."); info!("software version {}", include_str!(concat!(env!("OUT_DIR"), "/git-describe"))); info!("gateware version {}", board::ident::read(&mut [0; 64])); @@ -260,15 +261,6 @@ fn startup() { } } -#[no_mangle] -pub extern fn main() -> i32 { - unsafe { - static mut LOG_BUFFER: [u8; 1024] = [0; 1024]; - logger_artiq::BufferLogger::new(&mut LOG_BUFFER[..]).register(startup); - 0 - } -} - #[no_mangle] pub extern fn exception(vect: u32, _regs: *const u32, pc: u32, ea: u32) { panic!("exception {:?} at PC 0x{:x}, EA 0x{:x}", vect, pc, ea)