forked from M-Labs/artiq
1
0
Fork 0

firmware: implement ConsoleLogger, use it in satman.

This commit is contained in:
whitequark 2018-05-14 10:45:11 +00:00
parent 5d43d457d2
commit 56a29b91fc
6 changed files with 48 additions and 17 deletions

View File

@ -26,6 +26,7 @@ dependencies = [
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp?rev=181083f)",
] ]
@ -253,7 +254,6 @@ dependencies = [
"build_misoc 0.0.0", "build_misoc 0.0.0",
"drtioaux 0.0.0", "drtioaux 0.0.0",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"logger_artiq 0.0.0",
] ]
[[package]] [[package]]

View File

@ -14,6 +14,7 @@ build_misoc = { path = "../libbuild_misoc" }
[dependencies] [dependencies]
byteorder = { version = "1.0", default-features = false } byteorder = { version = "1.0", default-features = false }
log = { version = "0.4", default-features = false, optional = true }
[dependencies.compiler_builtins] [dependencies.compiler_builtins]
git = "https://github.com/m-labs/compiler-builtins" git = "https://github.com/m-labs/compiler-builtins"

View File

@ -3,6 +3,8 @@
extern crate compiler_builtins; extern crate compiler_builtins;
extern crate byteorder; extern crate byteorder;
#[cfg(feature = "log")]
extern crate log;
#[cfg(feature = "smoltcp")] #[cfg(feature = "smoltcp")]
extern crate smoltcp; extern crate smoltcp;
@ -25,5 +27,7 @@ pub mod spiflash;
pub mod config; pub mod config;
#[cfg(feature = "uart_console")] #[cfg(feature = "uart_console")]
pub mod uart_console; pub mod uart_console;
#[cfg(all(feature = "uart_console", feature = "log"))]
pub mod uart_logger;
#[cfg(all(has_ethmac, feature = "smoltcp"))] #[cfg(all(has_ethmac, feature = "smoltcp"))]
pub mod ethmac; pub mod ethmac;

View File

@ -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) {
}
}

View File

@ -15,7 +15,6 @@ build_artiq = { path = "../libbuild_artiq" }
[dependencies] [dependencies]
log = { version = "0.4", default-features = false } log = { version = "0.4", default-features = false }
drtioaux = { path = "../libdrtioaux" } board = { path = "../libboard", features = ["uart_console", "log"] }
board = { path = "../libboard", features = ["uart_console"] }
board_artiq = { path = "../libboard_artiq" } board_artiq = { path = "../libboard_artiq" }
logger_artiq = { path = "../liblogger_artiq" } drtioaux = { path = "../libdrtioaux" }

View File

@ -1,9 +1,8 @@
#![feature(lang_items, global_allocator)] #![feature(lang_items)]
#![no_std] #![no_std]
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate logger_artiq;
#[macro_use] #[macro_use]
extern crate board; extern crate board;
extern crate board_artiq; extern crate board_artiq;
@ -170,7 +169,6 @@ fn process_aux_packets() {
} }
} }
fn process_errors() { fn process_errors() {
let errors; let errors;
unsafe { unsafe {
@ -221,8 +219,11 @@ fn drtio_link_rx_up() -> bool {
} }
} }
fn startup() { #[no_mangle]
pub extern fn main() -> i32 {
board::clock::init(); board::clock::init();
board::uart_logger::ConsoleLogger::register();
info!("ARTIQ satellite manager starting..."); info!("ARTIQ satellite manager starting...");
info!("software version {}", include_str!(concat!(env!("OUT_DIR"), "/git-describe"))); info!("software version {}", include_str!(concat!(env!("OUT_DIR"), "/git-describe")));
info!("gateware version {}", board::ident::read(&mut [0; 64])); 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] #[no_mangle]
pub extern fn exception(vect: u32, _regs: *const u32, pc: u32, ea: u32) { 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) panic!("exception {:?} at PC 0x{:x}, EA 0x{:x}", vect, pc, ea)