mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 11:18:27 +08:00
firmware: implement ConsoleLogger, use it in satman.
This commit is contained in:
parent
5d43d457d2
commit
56a29b91fc
2
artiq/firmware/Cargo.lock
generated
2
artiq/firmware/Cargo.lock
generated
@ -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]]
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
35
artiq/firmware/libboard/uart_logger.rs
Normal file
35
artiq/firmware/libboard/uart_logger.rs
Normal 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) {
|
||||
}
|
||||
}
|
||||
|
@ -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" }
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user