From 836e266a3684b25426a093e88f0576554b3d70cd Mon Sep 17 00:00:00 2001 From: mwojcik Date: Tue, 9 Jul 2024 16:28:32 +0800 Subject: [PATCH] allow toggling SED spread with flash config key --- src/gateware/kasli_soc.py | 5 ++++- src/gateware/zc706.py | 4 ++++ src/runtime/src/comms.rs | 2 +- src/runtime/src/rtio_mgt.rs | 26 ++++++++++++++++++++++++++ src/satman/src/main.rs | 30 ++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/gateware/kasli_soc.py b/src/gateware/kasli_soc.py index 45183ad..98d6f41 100755 --- a/src/gateware/kasli_soc.py +++ b/src/gateware/kasli_soc.py @@ -560,7 +560,10 @@ class GenericSatellite(SoCCore): self.submodules.local_io = SyncRTIO( self.rtio_tsc, self.rtio_channels, lane_count=description["sed_lanes"] ) - self.comb += self.drtiosat.async_errors.eq(self.local_io.async_errors) + self.comb += [ + self.drtiosat.async_errors.eq(self.local_io.async_errors), + self.local_io.sed_spread_enable.eq(self.drtiosat.sed_spread_enable.storage) + ] self.submodules.cri_con = rtio.CRIInterconnectShared( [self.drtiosat.cri, self.rtio_dma.cri, self.rtio.cri], diff --git a/src/gateware/zc706.py b/src/gateware/zc706.py index 92c9208..395d6c6 100755 --- a/src/gateware/zc706.py +++ b/src/gateware/zc706.py @@ -487,6 +487,10 @@ class _SatelliteBase(SoCCore): self.csr_devices.append("rtio_dma") self.submodules.local_io = SyncRTIO(self.rtio_tsc, rtio_channels) + self.comb += [ + self.drtiosat.async_errors.eq(self.local_io.async_errors), + self.local_io.sed_spread_enable.eq(self.drtiosat.sed_spread_enable.storage) + ] self.submodules.cri_con = rtio.CRIInterconnectShared( [self.drtiosat.cri, self.rtio_dma.cri, self.rtio.cri], [self.local_io.cri] + self.drtio_cri, diff --git a/src/runtime/src/comms.rs b/src/runtime/src/comms.rs index 7747850..3ee3201 100644 --- a/src/runtime/src/comms.rs +++ b/src/runtime/src/comms.rs @@ -771,7 +771,7 @@ pub fn main(timer: GlobalTimer, cfg: Config) { #[cfg(has_drtio_routing)] drtio_routing::interconnect_disable_all(); - rtio_mgt::startup(&aux_mutex, &drtio_routing_table, &up_destinations, timer); + rtio_mgt::startup(&aux_mutex, &drtio_routing_table, &up_destinations, &cfg, timer); ksupport::setup_device_map(&cfg); analyzer::start(&aux_mutex, &drtio_routing_table, &up_destinations, timer); diff --git a/src/runtime/src/rtio_mgt.rs b/src/runtime/src/rtio_mgt.rs index 60e2fbb..8644e90 100644 --- a/src/runtime/src/rtio_mgt.rs +++ b/src/runtime/src/rtio_mgt.rs @@ -3,7 +3,9 @@ use core::cell::RefCell; use libboard_artiq::{drtio_routing, drtio_routing::RoutingTable, pl::csr}; use libboard_zynq::timer::GlobalTimer; +use libconfig::Config; use libcortex_a9::mutex::Mutex; +use log::{info, warn}; #[cfg(has_drtio)] pub mod drtio { @@ -898,12 +900,36 @@ pub mod drtio { pub fn reset(_aux_mutex: Rc>, _routing_table: &RoutingTable, mut _timer: GlobalTimer) {} } +fn toggle_sed_spread(val: u8) { + unsafe { + csr::rtio_core::sed_spread_enable_write(val); + } +} + +fn setup_sed_spread(cfg: &Config) { + if let Ok(spread_enable) = cfg.read_str("sed_spread_enable") { + match spread_enable.as_ref() { + "1" => toggle_sed_spread(1), + "0" => toggle_sed_spread(0), + _ => { + warn!("sed_spread_enable value not supported (only 1, 0 allowed), disabling by default"); + toggle_sed_spread(0) + } + }; + } else { + info!("SED spreading disabled by default"); + toggle_sed_spread(0); + } +} + pub fn startup( aux_mutex: &Rc>, routing_table: &Rc>, up_destinations: &Rc>, + cfg: &Config, timer: GlobalTimer, ) { + setup_sed_spread(cfg); drtio::startup(aux_mutex, routing_table, up_destinations, timer); unsafe { csr::rtio_core::reset_phy_write(1); diff --git a/src/satman/src/main.rs b/src/satman/src/main.rs index bb41fda..eb986ed 100644 --- a/src/satman/src/main.rs +++ b/src/satman/src/main.rs @@ -12,6 +12,7 @@ extern crate io; extern crate ksupport; extern crate libboard_artiq; extern crate libboard_zynq; +extern crate libconfig; extern crate libcortex_a9; extern crate libregister; extern crate libsupport_zynq; @@ -38,6 +39,7 @@ use libboard_artiq::{drtio_routing, drtioaux, #[cfg(feature = "target_kasli_soc")] use libboard_zynq::error_led::ErrorLED; use libboard_zynq::{i2c::I2c, print, println, time::Milliseconds, timer::GlobalTimer}; +use libconfig::Config; use libcortex_a9::{l2c::enable_l2_cache, regs::MPIDR}; use libregister::RegisterR; use libsupport_zynq::{exception_vectors, ram}; @@ -81,6 +83,12 @@ fn drtiosat_tsc_loaded() -> bool { } } +fn toggle_sed_spread(val: u8) { + unsafe { + csr::drtiosat::sed_spread_enable_write(val); + } +} + #[cfg(has_drtio_routing)] macro_rules! forward { ($routing_table:expr, $destination:expr, $rank:expr, $repeaters:expr, $packet:expr, $timer:expr) => {{ @@ -920,6 +928,28 @@ pub extern "C" fn main_core0() -> i32 { #[cfg(has_si549)] si549::helper_setup(&mut timer, &SI549_SETTINGS).expect("cannot initialize helper Si549"); + let cfg = match Config::new() { + Ok(cfg) => cfg, + Err(err) => { + warn!("config initialization failed: {}", err); + Config::new_dummy() + } + }; + + if let Ok(spread_enable) = cfg.read_str("sed_spread_enable") { + match spread_enable.as_ref() { + "1" => toggle_sed_spread(1), + "0" => toggle_sed_spread(0), + _ => { + warn!("sed_spread_enable value not supported (only 1, 0 allowed), disabling by default"); + toggle_sed_spread(0) + } + }; + } else { + info!("SED spreading disabled by default"); + toggle_sed_spread(0); + } + #[cfg(has_drtio_routing)] let mut repeaters = [repeater::Repeater::default(); csr::DRTIOREP.len()]; #[cfg(not(has_drtio_routing))]