From 5e76f7c0b49ada474f3233136aeceecda835551e Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 23 Jul 2021 11:28:16 +0200 Subject: [PATCH] moved proto, moved logger, updated runtime --- .../drtioaux_proto.rs | 0 src/libproto_artiq/Cargo.toml | 20 --- src/libproto_artiq/lib.rs | 18 --- src/runtime/src/logger.rs | 123 ------------------ src/runtime/src/main.rs | 3 +- src/runtime/src/mgmt.rs | 2 +- src/satman/Cargo.toml | 9 +- 7 files changed, 9 insertions(+), 166 deletions(-) rename src/{libproto_artiq => libboard_artiq}/drtioaux_proto.rs (100%) delete mode 100644 src/libproto_artiq/Cargo.toml delete mode 100644 src/libproto_artiq/lib.rs delete mode 100644 src/runtime/src/logger.rs diff --git a/src/libproto_artiq/drtioaux_proto.rs b/src/libboard_artiq/drtioaux_proto.rs similarity index 100% rename from src/libproto_artiq/drtioaux_proto.rs rename to src/libboard_artiq/drtioaux_proto.rs diff --git a/src/libproto_artiq/Cargo.toml b/src/libproto_artiq/Cargo.toml deleted file mode 100644 index 92d5e0d0..00000000 --- a/src/libproto_artiq/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -authors = ["M-Labs"] -name = "proto_artiq" -version = "0.0.0" - -[lib] -name = "proto_artiq" -path = "lib.rs" - -[dependencies] -failure = { version = "0.1", default-features = false } -failure_derive = { version = "0.1", default-features = false } -byteorder = { version = "1.0", default-features = false } -cslice = { version = "0.3" } -log = { version = "0.4", default-features = false, optional = true } -io = { path = "../libio", features = ["byteorder"] } -dyld = { path = "../libdyld" } - -[features] -alloc = ["io/alloc"] diff --git a/src/libproto_artiq/lib.rs b/src/libproto_artiq/lib.rs deleted file mode 100644 index e2dcd8bd..00000000 --- a/src/libproto_artiq/lib.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![no_std] -#![cfg_attr(feature = "alloc", feature(alloc))] - -extern crate failure; -#[macro_use] -extern crate failure_derive; -#[cfg(feature = "alloc")] -extern crate alloc; -extern crate cslice; -#[cfg(feature = "log")] -#[macro_use] -extern crate log; - -extern crate io; -extern crate dyld; - -// Internal protocols. -pub mod drtioaux_proto; diff --git a/src/runtime/src/logger.rs b/src/runtime/src/logger.rs deleted file mode 100644 index 3ae96438..00000000 --- a/src/runtime/src/logger.rs +++ /dev/null @@ -1,123 +0,0 @@ -use core::cell::Cell; -use core::fmt::Write; -use log::{Log, LevelFilter}; -use log_buffer::LogBuffer; -use libcortex_a9::mutex::{Mutex, MutexGuard}; -use libboard_zynq::{println, timer::GlobalTimer}; - -pub struct LogBufferRef<'a> { - buffer: MutexGuard<'a, LogBuffer<&'static mut [u8]>>, - old_log_level: LevelFilter -} - -impl<'a> LogBufferRef<'a> { - fn new(buffer: MutexGuard<'a, LogBuffer<&'static mut [u8]>>) -> LogBufferRef<'a> { - let old_log_level = log::max_level(); - log::set_max_level(LevelFilter::Off); - LogBufferRef { buffer, old_log_level } - } - - pub fn is_empty(&self) -> bool { - self.buffer.is_empty() - } - - pub fn clear(&mut self) { - self.buffer.clear() - } - - pub fn extract(&mut self) -> &str { - self.buffer.extract() - } -} - -impl<'a> Drop for LogBufferRef<'a> { - fn drop(&mut self) { - log::set_max_level(self.old_log_level) - } -} - -pub struct BufferLogger { - buffer: Mutex>, - uart_filter: Cell, - buffer_filter: Cell, -} - -static mut LOGGER: Option = None; - -impl BufferLogger { - pub fn new(buffer: &'static mut [u8]) -> BufferLogger { - BufferLogger { - buffer: Mutex::new(LogBuffer::new(buffer)), - uart_filter: Cell::new(LevelFilter::Info), - buffer_filter: Cell::new(LevelFilter::Trace), - } - } - - pub fn register(self) { - unsafe { - LOGGER = Some(self); - log::set_logger(LOGGER.as_ref().unwrap()) - .expect("global logger can only be initialized once"); - } - } - - pub unsafe fn get_logger() -> &'static mut Option { - &mut LOGGER - } - - pub fn buffer<'a>(&'a self) -> Option> { - self.buffer - .try_lock() - .map(LogBufferRef::new) - } - - pub fn uart_log_level(&self) -> LevelFilter { - self.uart_filter.get() - } - - pub fn set_uart_log_level(&self, max_level: LevelFilter) { - self.uart_filter.set(max_level) - } - - pub fn buffer_log_level(&self) -> LevelFilter { - self.buffer_filter.get() - } - - /// this should be reserved for mgmt module - pub fn set_buffer_log_level(&self, max_level: LevelFilter) { - self.buffer_filter.set(max_level) - } -} - -// required for impl Log -unsafe impl Sync for BufferLogger {} - -impl Log for BufferLogger { - fn enabled(&self, _metadata: &log::Metadata) -> bool { - true - } - - fn log(&self, record: &log::Record) { - if self.enabled(record.metadata()) { - let timestamp = unsafe { - GlobalTimer::get() - }.get_us().0; - let seconds = timestamp / 1_000_000; - let micros = timestamp % 1_000_000; - - if record.level() <= self.buffer_log_level() { - let mut buffer = self.buffer.lock(); - writeln!(buffer, "[{:6}.{:06}s] {:>5}({}): {}", seconds, micros, - record.level(), record.target(), record.args()).unwrap(); - } - - if record.level() <= self.uart_log_level() { - println!("[{:6}.{:06}s] {:>5}({}): {}", seconds, micros, - record.level(), record.target(), record.args()); - } - } - } - - fn flush(&self) { - } -} diff --git a/src/runtime/src/main.rs b/src/runtime/src/main.rs index dbc21fd4..d51c5df2 100644 --- a/src/runtime/src/main.rs +++ b/src/runtime/src/main.rs @@ -24,7 +24,7 @@ use libconfig::Config; use libregister::RegisterW; use libcortex_a9::l2c::enable_l2_cache; #[cfg(feature = "target_kasli_soc")] -use libboard_artiq::si5324; +use libboard_artiq::{si5324, logger}; mod proto_core_io; mod proto_async; @@ -42,7 +42,6 @@ mod kernel; mod moninj; mod eh_artiq; mod panic; -mod logger; mod mgmt; mod analyzer; mod irq; diff --git a/src/runtime/src/mgmt.rs b/src/runtime/src/mgmt.rs index 06ed8d53..51adeebc 100644 --- a/src/runtime/src/mgmt.rs +++ b/src/runtime/src/mgmt.rs @@ -6,7 +6,7 @@ use core::cell::RefCell; use alloc::{rc::Rc, vec::Vec, string::String}; use log::{self, info, debug, warn, error, LevelFilter}; -use crate::logger::{BufferLogger, LogBufferRef}; +use libboard_artiq::logger::{BufferLogger, LogBufferRef}; use crate::proto_async::*; use num_derive::FromPrimitive; use num_traits::FromPrimitive; diff --git a/src/satman/Cargo.toml b/src/satman/Cargo.toml index fdccaf27..08199d13 100644 --- a/src/satman/Cargo.toml +++ b/src/satman/Cargo.toml @@ -14,5 +14,10 @@ build_misoc = { path = "../libbuild_misoc" } [dependencies] log = { version = "0.4", default-features = false } -board_misoc = { path = "../libboard_misoc", features = ["uart_console", "log"] } -board_artiq = { path = "../libboard_artiq" } +libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git", features = ["ipv6"]} +libsupport_zynq = { default-features = false, features = ["alloc_core"], git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" } +libcortex_a9 = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" } +libasync = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" } +libregister = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" } +libconfig = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git", features = ["ipv6"] } +libboard_artiq = { path = "../libboard_artiq" }