From 285645759f6196919e96d33ce559e9e284ef830d Mon Sep 17 00:00:00 2001 From: mwojcik Date: Thu, 25 Aug 2022 16:10:18 +0800 Subject: [PATCH 01/16] kasli_soc: add error_led --- src/gateware/kasli_soc.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/gateware/kasli_soc.py b/src/gateware/kasli_soc.py index d45bfc4..3e871c0 100755 --- a/src/gateware/kasli_soc.py +++ b/src/gateware/kasli_soc.py @@ -11,6 +11,7 @@ from migen_axi.integration.soc_core import SoCCore from migen_axi.platforms import kasli_soc from misoc.interconnect.csr import * from misoc.integration import cpu_interface +from misoc.cores import gpio from artiq.coredevice import jsondesc from artiq.gateware import rtio, eem_7series @@ -126,6 +127,10 @@ class GenericStandalone(SoCCore): platform.add_platform_command("create_clock -name clk_fpga_0 -period 8 [get_pins \"PS7/FCLKCLK[0]\"]") platform.add_platform_command("set_input_jitter clk_fpga_0 0.24") + self.submodules.error_led = gpio.GPIOOut(Cat( + self.platform.request("error_led"))) + self.csr_devices.append("error_led") + self.submodules += SMAClkinForward(self.platform) self.rustc_cfg["has_si5324"] = None @@ -214,6 +219,10 @@ class GenericMaster(SoCCore): self.submodules += SMAClkinForward(self.platform) + self.submodules.error_led = gpio.GPIOOut(Cat( + self.platform.request("error_led"))) + self.csr_devices.append("error_led") + data_pads = [platform.request("sfp", i) for i in range(4)] self.submodules.drtio_transceiver = gtx_7series.GTX( @@ -337,6 +346,10 @@ class GenericSatellite(SoCCore): platform.add_platform_command("create_clock -name clk_fpga_0 -period 8 [get_pins \"PS7/FCLKCLK[0]\"]") platform.add_platform_command("set_input_jitter clk_fpga_0 0.24") + self.submodules.error_led = gpio.GPIOOut(Cat( + self.platform.request("error_led"))) + self.csr_devices.append("error_led") + self.crg = self.ps7 # HACK for eem_7series to find the clock self.submodules.rtio_crg = RTIOClockMultiplier(rtio_clk_freq) self.csr_devices.append("rtio_crg") -- 2.42.0 From e5158ae9c8428782981736188e62c339cbfcbdec Mon Sep 17 00:00:00 2001 From: mwojcik Date: Thu, 25 Aug 2022 16:23:10 +0800 Subject: [PATCH 02/16] enable error LED on pll lock fail --- src/runtime/src/rtio_clocking.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/runtime/src/rtio_clocking.rs b/src/runtime/src/rtio_clocking.rs index bda8bb7..f1cec16 100644 --- a/src/runtime/src/rtio_clocking.rs +++ b/src/runtime/src/rtio_clocking.rs @@ -96,6 +96,11 @@ fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) { info!("RTIO PLL locked"); } else { error!("RTIO PLL failed to lock"); + #[cfg(feature = "target_kasli_soc")] + { + pl::csr::error_led::out_write(1); + // try "soft" panic + } } unsafe { -- 2.42.0 From 93bd962f9b2fba1e92db5a4837ce524c8627e63c Mon Sep 17 00:00:00 2001 From: mwojcik Date: Thu, 25 Aug 2022 16:55:12 +0800 Subject: [PATCH 03/16] rtio_clocking: soft panic if PLL fails to lock --- src/runtime/src/rtio_clocking.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/runtime/src/rtio_clocking.rs b/src/runtime/src/rtio_clocking.rs index f1cec16..60e960f 100644 --- a/src/runtime/src/rtio_clocking.rs +++ b/src/runtime/src/rtio_clocking.rs @@ -1,6 +1,7 @@ use log::{info, warn, error}; use libboard_zynq::timer::GlobalTimer; use embedded_hal::blocking::delay::DelayMs; +use libasync::task; use libconfig::Config; use libboard_artiq::pl; #[cfg(has_si5324)] @@ -9,6 +10,7 @@ use libboard_zynq::i2c::I2c; use crate::i2c; #[cfg(has_si5324)] use libboard_artiq::si5324; +use crate::mgmt; #[derive(Debug, PartialEq, Copy, Clone)] #[allow(non_camel_case_types)] @@ -98,7 +100,10 @@ fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) { error!("RTIO PLL failed to lock"); #[cfg(feature = "target_kasli_soc")] { - pl::csr::error_led::out_write(1); + unsafe { + pl::csr::error_led::out_write(1); + } + soft_panic(); // try "soft" panic } } @@ -256,4 +261,17 @@ pub fn init(timer: &mut GlobalTimer, cfg: &Config) { init_rtio(timer, clk); +} + +#[cfg(feature = "target_kasli_soc")] +fn soft_panic() { + // start mgmt service but nothing else + let cfg = match Config::new() { + Ok(cfg) => cfg, + Err(_) => Config::new_dummy() + }; + mgmt::start(cfg); + loop { + task::block_on(task::r#yield()); + } } \ No newline at end of file -- 2.42.0 From d46acfabc5df46f6f5ba129314824ab3ef8bc063 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Wed, 31 Aug 2022 14:43:23 +0800 Subject: [PATCH 04/16] rtio_clocking: add error led support * config functions return Result instead of being void --- src/gateware/kasli_soc.py | 12 ---------- src/runtime/src/rtio_clocking.rs | 40 ++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/gateware/kasli_soc.py b/src/gateware/kasli_soc.py index 3e871c0..1c95a37 100755 --- a/src/gateware/kasli_soc.py +++ b/src/gateware/kasli_soc.py @@ -127,10 +127,6 @@ class GenericStandalone(SoCCore): platform.add_platform_command("create_clock -name clk_fpga_0 -period 8 [get_pins \"PS7/FCLKCLK[0]\"]") platform.add_platform_command("set_input_jitter clk_fpga_0 0.24") - self.submodules.error_led = gpio.GPIOOut(Cat( - self.platform.request("error_led"))) - self.csr_devices.append("error_led") - self.submodules += SMAClkinForward(self.platform) self.rustc_cfg["has_si5324"] = None @@ -219,10 +215,6 @@ class GenericMaster(SoCCore): self.submodules += SMAClkinForward(self.platform) - self.submodules.error_led = gpio.GPIOOut(Cat( - self.platform.request("error_led"))) - self.csr_devices.append("error_led") - data_pads = [platform.request("sfp", i) for i in range(4)] self.submodules.drtio_transceiver = gtx_7series.GTX( @@ -346,10 +338,6 @@ class GenericSatellite(SoCCore): platform.add_platform_command("create_clock -name clk_fpga_0 -period 8 [get_pins \"PS7/FCLKCLK[0]\"]") platform.add_platform_command("set_input_jitter clk_fpga_0 0.24") - self.submodules.error_led = gpio.GPIOOut(Cat( - self.platform.request("error_led"))) - self.csr_devices.append("error_led") - self.crg = self.ps7 # HACK for eem_7series to find the clock self.submodules.rtio_crg = RTIOClockMultiplier(rtio_clk_freq) self.csr_devices.append("rtio_crg") diff --git a/src/runtime/src/rtio_clocking.rs b/src/runtime/src/rtio_clocking.rs index 60e960f..e1b9a03 100644 --- a/src/runtime/src/rtio_clocking.rs +++ b/src/runtime/src/rtio_clocking.rs @@ -4,6 +4,8 @@ use embedded_hal::blocking::delay::DelayMs; use libasync::task; use libconfig::Config; use libboard_artiq::pl; +#[cfg(feature = "target_kasli_soc")] +use libboard_zynq::error_led::ErrorLED; #[cfg(has_si5324)] use libboard_zynq::i2c::I2c; #[cfg(has_si5324)] @@ -69,7 +71,7 @@ fn get_rtio_clock_cfg(cfg: &Config) -> RtioClock { } -fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) { +fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) -> Result<()> { #[cfg(has_rtio_crg_clock_sel)] let clock_sel = match _clk { RtioClock::Ext0_Bypass => { @@ -98,19 +100,14 @@ fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) { info!("RTIO PLL locked"); } else { error!("RTIO PLL failed to lock"); - #[cfg(feature = "target_kasli_soc")] - { - unsafe { - pl::csr::error_led::out_write(1); - } - soft_panic(); - // try "soft" panic - } + return Err("RTIO PLL failed to lock"); } unsafe { pl::csr::rtio_core::reset_phy_write(1); } + + Ok(()) } #[cfg(has_drtio)] @@ -126,7 +123,7 @@ fn init_drtio(timer: &mut GlobalTimer) } #[cfg(has_si5324)] -fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) { +fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) -> Result<()> { let (si5324_settings, si5324_ref_input) = match clk { RtioClock::Ext0_Synth0_10to125 => { // 125 MHz output from 10 MHz CLKINx reference, 504 Hz BW info!("using 10MHz reference to make 125MHz RTIO clock with PLL"); @@ -241,7 +238,7 @@ fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) { ) } }; - si5324::setup(i2c, &si5324_settings, si5324_ref_input, timer).expect("cannot initialize Si5324"); + si5324::setup(i2c, &si5324_settings, si5324_ref_input, timer) } pub fn init(timer: &mut GlobalTimer, cfg: &Config) { @@ -251,26 +248,39 @@ pub fn init(timer: &mut GlobalTimer, cfg: &Config) { { let i2c = unsafe { (&mut i2c::I2C_BUS).as_mut().unwrap() }; let si5324_ext_input = si5324::Input::Ckin1; - match clk { - RtioClock::Ext0_Bypass => si5324::bypass(i2c, si5324_ext_input, timer).expect("cannot bypass Si5324"), + let res = match clk { + RtioClock::Ext0_Bypass => si5324::bypass(i2c, si5324_ext_input, timer), _ => setup_si5324(i2c, timer, clk), } + if res.is_err() { + soft_panic(); + } } #[cfg(has_drtio)] init_drtio(timer); - init_rtio(timer, clk); + if init_rtio(timer, clk).is_err() { + soft_panic(); + } } -#[cfg(feature = "target_kasli_soc")] + fn soft_panic() { + error!("Error setting up RTIO clocking. Only mgmt interface will be available."); // start mgmt service but nothing else let cfg = match Config::new() { Ok(cfg) => cfg, Err(_) => Config::new_dummy() }; mgmt::start(cfg); + + #[cfg(feature = "target_kasli_soc")] + { + let mut err_led = ErrorLED::error_led(); + err_led.toggle(true); + } + loop { task::block_on(task::r#yield()); } -- 2.42.0 From 0e6bf6103460275d58330589bda83637192fb3c9 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Thu, 1 Sep 2022 11:33:51 +0800 Subject: [PATCH 05/16] comms: add soft_panic setup rtio_clocking: return error instead of panic --- src/gateware/kasli_soc.py | 1 - src/runtime/src/comms.rs | 58 ++++++++++++++++++++++++++++++++ src/runtime/src/main.rs | 8 ++--- src/runtime/src/rtio_clocking.rs | 44 ++++-------------------- 4 files changed, 69 insertions(+), 42 deletions(-) diff --git a/src/gateware/kasli_soc.py b/src/gateware/kasli_soc.py index 1c95a37..d45bfc4 100755 --- a/src/gateware/kasli_soc.py +++ b/src/gateware/kasli_soc.py @@ -11,7 +11,6 @@ from migen_axi.integration.soc_core import SoCCore from migen_axi.platforms import kasli_soc from misoc.interconnect.csr import * from misoc.integration import cpu_interface -from misoc.cores import gpio from artiq.coredevice import jsondesc from artiq.gateware import rtio, eem_7series diff --git a/src/runtime/src/comms.rs b/src/runtime/src/comms.rs index 13a4a24..fe0e042 100644 --- a/src/runtime/src/comms.rs +++ b/src/runtime/src/comms.rs @@ -17,6 +17,8 @@ use libboard_zynq::{ }, timer::GlobalTimer, }; +#[cfg(feature = "target_kasli_soc")] +use libboard_zynq::error_led::ErrorLED; use libcortex_a9::{semaphore::Semaphore, mutex::Mutex, sync_channel::{Sender, Receiver}}; use futures::{select_biased, future::FutureExt}; use libasync::{smoltcp::{Sockets, TcpStream}, task}; @@ -490,3 +492,59 @@ pub fn main(timer: GlobalTimer, cfg: Config) { Instant::from_millis(timer.get_time().0 as i32) }); } + + +pub fn soft_panic_setup(timer: GlobalTimer, cfg: Config) { + let net_addresses = net_settings::get_addresses(&cfg); + info!("network addresses: {}", net_addresses); + + error!("There has been an error configuring the device. Only mgmt interface will be available."); + #[cfg(feature = "target_kasli_soc")] + { + let mut err_led = ErrorLED::error_led(); + err_led.toggle(true); + } + + let eth = zynq::eth::Eth::eth0(net_addresses.hardware_addr.0.clone()); + const RX_LEN: usize = 64; + // Number of transmission buffers (minimum is two because with + // one, duplicate packet transmission occurs) + const TX_LEN: usize = 64; + let eth = eth.start_rx(RX_LEN); + let mut eth = eth.start_tx(TX_LEN); + + let neighbor_cache = NeighborCache::new(alloc::collections::BTreeMap::new()); + let mut iface = match net_addresses.ipv6_addr { + Some(addr) => { + let ip_addrs = [ + IpCidr::new(net_addresses.ipv4_addr, 0), + IpCidr::new(net_addresses.ipv6_ll_addr, 0), + IpCidr::new(addr, 0) + ]; + EthernetInterfaceBuilder::new(&mut eth) + .ethernet_addr(net_addresses.hardware_addr) + .ip_addrs(ip_addrs) + .neighbor_cache(neighbor_cache) + .finalize() + } + None => { + let ip_addrs = [ + IpCidr::new(net_addresses.ipv4_addr, 0), + IpCidr::new(net_addresses.ipv6_ll_addr, 0) + ]; + EthernetInterfaceBuilder::new(&mut eth) + .ethernet_addr(net_addresses.hardware_addr) + .ip_addrs(ip_addrs) + .neighbor_cache(neighbor_cache) + .finalize() + } + }; + + Sockets::init(32); + + mgmt::start(cfg); + + Sockets::run(&mut iface, || { + Instant::from_millis(timer.get_time().0 as i32) + }); +} \ No newline at end of file diff --git a/src/runtime/src/main.rs b/src/runtime/src/main.rs index a08c979..2078dd2 100644 --- a/src/runtime/src/main.rs +++ b/src/runtime/src/main.rs @@ -120,10 +120,10 @@ pub fn main_core0() { Config::new_dummy() } }; - - rtio_clocking::init(&mut timer, &cfg); - task::spawn(report_async_rtio_errors()); - comms::main(timer, cfg); + match rtio_clocking::init(&mut timer, &cfg) { + Ok(()) => { comms::main(timer, cfg); } + Err(_) => { comms::soft_panic_setup(timer, cfg)} + }; } diff --git a/src/runtime/src/rtio_clocking.rs b/src/runtime/src/rtio_clocking.rs index e1b9a03..61a50e1 100644 --- a/src/runtime/src/rtio_clocking.rs +++ b/src/runtime/src/rtio_clocking.rs @@ -1,18 +1,14 @@ use log::{info, warn, error}; use libboard_zynq::timer::GlobalTimer; use embedded_hal::blocking::delay::DelayMs; -use libasync::task; use libconfig::Config; use libboard_artiq::pl; -#[cfg(feature = "target_kasli_soc")] -use libboard_zynq::error_led::ErrorLED; #[cfg(has_si5324)] use libboard_zynq::i2c::I2c; #[cfg(has_si5324)] use crate::i2c; #[cfg(has_si5324)] use libboard_artiq::si5324; -use crate::mgmt; #[derive(Debug, PartialEq, Copy, Clone)] #[allow(non_camel_case_types)] @@ -71,7 +67,7 @@ fn get_rtio_clock_cfg(cfg: &Config) -> RtioClock { } -fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) -> Result<()> { +fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) -> Result<(), &'static str> { #[cfg(has_rtio_crg_clock_sel)] let clock_sel = match _clk { RtioClock::Ext0_Bypass => { @@ -123,7 +119,7 @@ fn init_drtio(timer: &mut GlobalTimer) } #[cfg(has_si5324)] -fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) -> Result<()> { +fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) -> Result<(), &'static str> { let (si5324_settings, si5324_ref_input) = match clk { RtioClock::Ext0_Synth0_10to125 => { // 125 MHz output from 10 MHz CLKINx reference, 504 Hz BW info!("using 10MHz reference to make 125MHz RTIO clock with PLL"); @@ -241,47 +237,21 @@ fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) -> Resul si5324::setup(i2c, &si5324_settings, si5324_ref_input, timer) } -pub fn init(timer: &mut GlobalTimer, cfg: &Config) { +pub fn init(timer: &mut GlobalTimer, cfg: &Config) -> Result<(), &'static str> { let clk = get_rtio_clock_cfg(cfg); #[cfg(has_si5324)] { let i2c = unsafe { (&mut i2c::I2C_BUS).as_mut().unwrap() }; let si5324_ext_input = si5324::Input::Ckin1; - let res = match clk { + match clk { RtioClock::Ext0_Bypass => si5324::bypass(i2c, si5324_ext_input, timer), _ => setup_si5324(i2c, timer, clk), - } - if res.is_err() { - soft_panic(); - } + }?; } #[cfg(has_drtio)] init_drtio(timer); + init_rtio(timer, clk)?; - if init_rtio(timer, clk).is_err() { - soft_panic(); - } - -} - - -fn soft_panic() { - error!("Error setting up RTIO clocking. Only mgmt interface will be available."); - // start mgmt service but nothing else - let cfg = match Config::new() { - Ok(cfg) => cfg, - Err(_) => Config::new_dummy() - }; - mgmt::start(cfg); - - #[cfg(feature = "target_kasli_soc")] - { - let mut err_led = ErrorLED::error_led(); - err_led.toggle(true); - } - - loop { - task::block_on(task::r#yield()); - } + Ok(()) } \ No newline at end of file -- 2.42.0 From 3d6b80b94d6e0f4f0dd4b329b4992a3a53823336 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Thu, 1 Sep 2022 12:02:44 +0800 Subject: [PATCH 06/16] soft_panic: print the reason --- src/runtime/src/comms.rs | 4 ++-- src/runtime/src/main.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime/src/comms.rs b/src/runtime/src/comms.rs index fe0e042..dc1226a 100644 --- a/src/runtime/src/comms.rs +++ b/src/runtime/src/comms.rs @@ -494,11 +494,11 @@ pub fn main(timer: GlobalTimer, cfg: Config) { } -pub fn soft_panic_setup(timer: GlobalTimer, cfg: Config) { +pub fn soft_panic_setup(timer: GlobalTimer, cfg: Config, reason: &'static str) { let net_addresses = net_settings::get_addresses(&cfg); info!("network addresses: {}", net_addresses); - error!("There has been an error configuring the device. Only mgmt interface will be available."); + error!("There has been an error configuring the device: {}. Only mgmt interface will be available.", reason); #[cfg(feature = "target_kasli_soc")] { let mut err_led = ErrorLED::error_led(); diff --git a/src/runtime/src/main.rs b/src/runtime/src/main.rs index 2078dd2..5c957a6 100644 --- a/src/runtime/src/main.rs +++ b/src/runtime/src/main.rs @@ -124,6 +124,6 @@ pub fn main_core0() { match rtio_clocking::init(&mut timer, &cfg) { Ok(()) => { comms::main(timer, cfg); } - Err(_) => { comms::soft_panic_setup(timer, cfg)} + Err(reason) => { comms::soft_panic_setup(timer, cfg, reason); } }; } -- 2.42.0 From 3ba6555bb06fcc5b905fcabba31b768c7c0b172c Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 2 Sep 2022 14:08:52 +0800 Subject: [PATCH 07/16] soft panic first in panic, more generic --- src/runtime/src/comms.rs | 25 ++++++++++++++--------- src/runtime/src/main.rs | 10 ++++----- src/runtime/src/panic.rs | 44 +++++++++++++++++++++++++++++++++------- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/runtime/src/comms.rs b/src/runtime/src/comms.rs index dc1226a..2619d87 100644 --- a/src/runtime/src/comms.rs +++ b/src/runtime/src/comms.rs @@ -17,13 +17,13 @@ use libboard_zynq::{ }, timer::GlobalTimer, }; -#[cfg(feature = "target_kasli_soc")] -use libboard_zynq::error_led::ErrorLED; use libcortex_a9::{semaphore::Semaphore, mutex::Mutex, sync_channel::{Sender, Receiver}}; use futures::{select_biased, future::FutureExt}; use libasync::{smoltcp::{Sockets, TcpStream}, task}; use libconfig::{Config, net_settings}; use libboard_artiq::drtio_routing; +#[cfg(feature = "target_kasli_soc")] +use libboard_zynq::error_led::ErrorLED; use crate::proto_async::*; use crate::kernel; @@ -86,6 +86,7 @@ enum Reply { static CACHE_STORE: Mutex>> = Mutex::new(BTreeMap::new()); static DMA_RECORD_STORE: Mutex, i64)>> = Mutex::new(BTreeMap::new()); +static mut MGMT_STARTED: bool = false; async fn write_header(stream: &TcpStream, reply: Reply) -> Result<()> { stream.send_slice(&[0x5a, 0x5a, 0x5a, 0x5a, reply.to_u8().unwrap()]).await?; @@ -442,6 +443,9 @@ pub fn main(timer: GlobalTimer, cfg: Config) { } mgmt::start(cfg); + unsafe { + MGMT_STARTED = true; + } task::spawn(async move { let connection = Rc::new(Semaphore::new(1, 1)); @@ -494,17 +498,11 @@ pub fn main(timer: GlobalTimer, cfg: Config) { } -pub fn soft_panic_setup(timer: GlobalTimer, cfg: Config, reason: &'static str) { +pub fn soft_panic_main(timer: GlobalTimer, cfg: Config) -> ! { + let net_addresses = net_settings::get_addresses(&cfg); info!("network addresses: {}", net_addresses); - error!("There has been an error configuring the device: {}. Only mgmt interface will be available.", reason); - #[cfg(feature = "target_kasli_soc")] - { - let mut err_led = ErrorLED::error_led(); - err_led.toggle(true); - } - let eth = zynq::eth::Eth::eth0(net_addresses.hardware_addr.0.clone()); const RX_LEN: usize = 64; // Number of transmission buffers (minimum is two because with @@ -544,6 +542,13 @@ pub fn soft_panic_setup(timer: GlobalTimer, cfg: Config, reason: &'static str) { mgmt::start(cfg); + //getting eth settings disables the LED - need enable it here + #[cfg(feature = "target_kasli_soc")] + { + let mut err_led = ErrorLED::error_led(); + err_led.toggle(true); + } + Sockets::run(&mut iface, || { Instant::from_millis(timer.get_time().0 as i32) }); diff --git a/src/runtime/src/main.rs b/src/runtime/src/main.rs index 5c957a6..f065088 100644 --- a/src/runtime/src/main.rs +++ b/src/runtime/src/main.rs @@ -122,8 +122,8 @@ pub fn main_core0() { }; task::spawn(report_async_rtio_errors()); - match rtio_clocking::init(&mut timer, &cfg) { - Ok(()) => { comms::main(timer, cfg); } - Err(reason) => { comms::soft_panic_setup(timer, cfg, reason); } - }; -} + rtio_clocking::init(&mut timer, &cfg).expect("Could not set up RTIO PLL"); + + comms::main(timer, cfg); + +} \ No newline at end of file diff --git a/src/runtime/src/panic.rs b/src/runtime/src/panic.rs index a972be1..f8ca85e 100644 --- a/src/runtime/src/panic.rs +++ b/src/runtime/src/panic.rs @@ -3,19 +3,26 @@ use libregister::RegisterR; use libcortex_a9::regs::MPIDR; use unwind::backtrace; +#[cfg(feature = "target_kasli_soc")] +use libboard_zynq::error_led::ErrorLED; +use crate::comms::soft_panic_main; +use libboard_zynq::timer::GlobalTimer; +use libconfig::Config; + static mut PANICKED: [bool; 2] = [false; 2]; +static mut SOFT_PANICKED: bool = false; #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { let id = MPIDR.read().cpu_id() as usize; print!("Core {} ", id); - unsafe { - if PANICKED[id] { - println!("nested panic!"); - loop {} - } - PANICKED[id] = true; + #[cfg(feature = "target_kasli_soc")] + { + let mut err_led = ErrorLED::error_led(); + err_led.toggle(true); } + let soft_panicked = unsafe { SOFT_PANICKED }; + print!("panic at "); if let Some(location) = info.location() { print!("{}:{}:{}", location.file(), location.line(), location.column()); @@ -27,6 +34,18 @@ fn panic(info: &core::panic::PanicInfo) -> ! { } else { println!(""); } + unsafe { + if PANICKED[id] && (SOFT_PANICKED || id == 1) { + println!("nested panic!"); + loop {} + } + SOFT_PANICKED = true; + PANICKED[id] = true; + } + + if !soft_panicked && id == 0 { + soft_panic(); + } println!("Backtrace: "); let _ = backtrace(|ip| { // Backtrace gives us the return address, i.e. the address after the delay slot, @@ -34,6 +53,17 @@ fn panic(info: &core::panic::PanicInfo) -> ! { print!("{:#08x} ", ip - 2 * 4); }); println!("\nEnd backtrace"); - loop {} } + +fn soft_panic() -> ! { + + let timer = GlobalTimer::start(); + let cfg = match Config::new() { + Ok(cfg) => cfg, + Err(_) => { + Config::new_dummy() + } + }; + soft_panic_main(timer, cfg); +} \ No newline at end of file -- 2.42.0 From dfc0cc7c9a60715cc3018ce0a20ed448d2f66dfa Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 2 Sep 2022 14:50:11 +0800 Subject: [PATCH 08/16] soft_panic: log error message --- src/runtime/src/panic.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/runtime/src/panic.rs b/src/runtime/src/panic.rs index f8ca85e..967f0bb 100644 --- a/src/runtime/src/panic.rs +++ b/src/runtime/src/panic.rs @@ -6,6 +6,7 @@ use unwind::backtrace; #[cfg(feature = "target_kasli_soc")] use libboard_zynq::error_led::ErrorLED; use crate::comms::soft_panic_main; +use log::error; use libboard_zynq::timer::GlobalTimer; use libconfig::Config; @@ -15,15 +16,8 @@ static mut SOFT_PANICKED: bool = false; #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { let id = MPIDR.read().cpu_id() as usize; - print!("Core {} ", id); - #[cfg(feature = "target_kasli_soc")] - { - let mut err_led = ErrorLED::error_led(); - err_led.toggle(true); - } let soft_panicked = unsafe { SOFT_PANICKED }; - - print!("panic at "); + print!("Core {} panic at ", id); if let Some(location) = info.location() { print!("{}:{}:{}", location.file(), location.line(), location.column()); } else { @@ -35,6 +29,7 @@ fn panic(info: &core::panic::PanicInfo) -> ! { println!(""); } unsafe { + // soft panics only allowed for core 0 if PANICKED[id] && (SOFT_PANICKED || id == 1) { println!("nested panic!"); loop {} @@ -42,9 +37,13 @@ fn panic(info: &core::panic::PanicInfo) -> ! { SOFT_PANICKED = true; PANICKED[id] = true; } - if !soft_panicked && id == 0 { - soft_panic(); + soft_panic(info); + } + #[cfg(feature = "target_kasli_soc")] + { + let mut err_led = ErrorLED::error_led(); + err_led.toggle(true); } println!("Backtrace: "); let _ = backtrace(|ip| { @@ -56,8 +55,16 @@ fn panic(info: &core::panic::PanicInfo) -> ! { loop {} } -fn soft_panic() -> ! { - +fn soft_panic(info: &core::panic::PanicInfo) -> ! { + // log panic info to log (prints not visible in coremgmt logs) + if let Some(location) = info.location() { + error!("panic at {}:{}:{}", location.file(), location.line(), location.column()); + } else { + error!("panic at unknown location"); + } + if let Some(message) = info.message() { + error!("panic message: {}", message); + } let timer = GlobalTimer::start(); let cfg = match Config::new() { Ok(cfg) => cfg, -- 2.42.0 From 052cae9df784acb7457890586a6fee1b7c82a489 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 2 Sep 2022 15:10:56 +0800 Subject: [PATCH 09/16] rtio_clocking: panic at RTIO failed to lock --- src/runtime/src/main.rs | 2 +- src/runtime/src/rtio_clocking.rs | 33 +++++++++----------------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/runtime/src/main.rs b/src/runtime/src/main.rs index f065088..3433f85 100644 --- a/src/runtime/src/main.rs +++ b/src/runtime/src/main.rs @@ -122,7 +122,7 @@ pub fn main_core0() { }; task::spawn(report_async_rtio_errors()); - rtio_clocking::init(&mut timer, &cfg).expect("Could not set up RTIO PLL"); + rtio_clocking::init(&mut timer, &cfg); comms::main(timer, cfg); diff --git a/src/runtime/src/rtio_clocking.rs b/src/runtime/src/rtio_clocking.rs index 61a50e1..97bcc5e 100644 --- a/src/runtime/src/rtio_clocking.rs +++ b/src/runtime/src/rtio_clocking.rs @@ -1,4 +1,4 @@ -use log::{info, warn, error}; +use log::{info, warn}; use libboard_zynq::timer::GlobalTimer; use embedded_hal::blocking::delay::DelayMs; use libconfig::Config; @@ -9,7 +9,6 @@ use libboard_zynq::i2c::I2c; use crate::i2c; #[cfg(has_si5324)] use libboard_artiq::si5324; - #[derive(Debug, PartialEq, Copy, Clone)] #[allow(non_camel_case_types)] pub enum RtioClock { @@ -22,7 +21,6 @@ pub enum RtioClock { Ext0_Synth0_100to125, Ext0_Synth0_125to125, } - #[allow(unreachable_code)] fn get_rtio_clock_cfg(cfg: &Config) -> RtioClock { let mut res = RtioClock::Default; @@ -65,9 +63,7 @@ fn get_rtio_clock_cfg(cfg: &Config) -> RtioClock { } res } - - -fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) -> Result<(), &'static str> { +fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) { #[cfg(has_rtio_crg_clock_sel)] let clock_sel = match _clk { RtioClock::Ext0_Bypass => { @@ -83,7 +79,6 @@ fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) -> Result<(), &'static st 0 } }; - unsafe { pl::csr::rtio_crg::pll_reset_write(1); #[cfg(has_rtio_crg_clock_sel)] @@ -95,17 +90,12 @@ fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) -> Result<(), &'static st if locked { info!("RTIO PLL locked"); } else { - error!("RTIO PLL failed to lock"); - return Err("RTIO PLL failed to lock"); + panic!("RTIO PLL failed to lock"); } - unsafe { pl::csr::rtio_core::reset_phy_write(1); } - - Ok(()) } - #[cfg(has_drtio)] fn init_drtio(timer: &mut GlobalTimer) { @@ -117,9 +107,8 @@ fn init_drtio(timer: &mut GlobalTimer) pl::csr::drtio_transceiver::txenable_write(0xffffffffu32 as _); } } - #[cfg(has_si5324)] -fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) -> Result<(), &'static str> { +fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) { let (si5324_settings, si5324_ref_input) = match clk { RtioClock::Ext0_Synth0_10to125 => { // 125 MHz output from 10 MHz CLKINx reference, 504 Hz BW info!("using 10MHz reference to make 125MHz RTIO clock with PLL"); @@ -234,24 +223,20 @@ fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) -> Resul ) } }; - si5324::setup(i2c, &si5324_settings, si5324_ref_input, timer) + si5324::setup(i2c, &si5324_settings, si5324_ref_input, timer).expect("cannot initialize Si5324"); } - -pub fn init(timer: &mut GlobalTimer, cfg: &Config) -> Result<(), &'static str> { - +pub fn init(timer: &mut GlobalTimer, cfg: &Config) { let clk = get_rtio_clock_cfg(cfg); #[cfg(has_si5324)] { let i2c = unsafe { (&mut i2c::I2C_BUS).as_mut().unwrap() }; let si5324_ext_input = si5324::Input::Ckin1; match clk { - RtioClock::Ext0_Bypass => si5324::bypass(i2c, si5324_ext_input, timer), + RtioClock::Ext0_Bypass => si5324::bypass(i2c, si5324_ext_input, timer).expect("cannot bypass Si5324"), _ => setup_si5324(i2c, timer, clk), - }?; + } } #[cfg(has_drtio)] init_drtio(timer); - init_rtio(timer, clk)?; - - Ok(()) + init_rtio(timer, clk); } \ No newline at end of file -- 2.42.0 From f94c291c688123b4325bf7043b737f1c7767d675 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Wed, 5 Oct 2022 17:26:58 +0800 Subject: [PATCH 10/16] remove unnecessary MGMT_STARTED --- src/runtime/src/comms.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/runtime/src/comms.rs b/src/runtime/src/comms.rs index 2619d87..b3ccb3a 100644 --- a/src/runtime/src/comms.rs +++ b/src/runtime/src/comms.rs @@ -86,7 +86,6 @@ enum Reply { static CACHE_STORE: Mutex>> = Mutex::new(BTreeMap::new()); static DMA_RECORD_STORE: Mutex, i64)>> = Mutex::new(BTreeMap::new()); -static mut MGMT_STARTED: bool = false; async fn write_header(stream: &TcpStream, reply: Reply) -> Result<()> { stream.send_slice(&[0x5a, 0x5a, 0x5a, 0x5a, reply.to_u8().unwrap()]).await?; @@ -443,10 +442,7 @@ pub fn main(timer: GlobalTimer, cfg: Config) { } mgmt::start(cfg); - unsafe { - MGMT_STARTED = true; - } - + task::spawn(async move { let connection = Rc::new(Semaphore::new(1, 1)); let terminate = Rc::new(Semaphore::new(0, 1)); -- 2.42.0 From 401bc6bcb3423f59a231d4d5ef89db32d2b86b7b Mon Sep 17 00:00:00 2001 From: mwojcik Date: Mon, 10 Oct 2022 14:59:40 +0800 Subject: [PATCH 11/16] better documentation for error led enabling --- src/runtime/src/comms.rs | 3 ++- src/runtime/src/panic.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/runtime/src/comms.rs b/src/runtime/src/comms.rs index b3ccb3a..d282560 100644 --- a/src/runtime/src/comms.rs +++ b/src/runtime/src/comms.rs @@ -538,7 +538,8 @@ pub fn soft_panic_main(timer: GlobalTimer, cfg: Config) -> ! { mgmt::start(cfg); - //getting eth settings disables the LED - need enable it here + // getting eth settings disables the LED as it resets GPIO + // need to re-enable it here #[cfg(feature = "target_kasli_soc")] { let mut err_led = ErrorLED::error_led(); diff --git a/src/runtime/src/panic.rs b/src/runtime/src/panic.rs index 967f0bb..c0566fc 100644 --- a/src/runtime/src/panic.rs +++ b/src/runtime/src/panic.rs @@ -37,14 +37,14 @@ fn panic(info: &core::panic::PanicInfo) -> ! { SOFT_PANICKED = true; PANICKED[id] = true; } - if !soft_panicked && id == 0 { - soft_panic(info); - } #[cfg(feature = "target_kasli_soc")] { let mut err_led = ErrorLED::error_led(); err_led.toggle(true); } + if !soft_panicked && id == 0 { + soft_panic(info); + } println!("Backtrace: "); let _ = backtrace(|ip| { // Backtrace gives us the return address, i.e. the address after the delay slot, -- 2.42.0 From 4034be5da8d62ccb5dd9e354585a9ceda43f7b10 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Mon, 10 Oct 2022 16:04:07 +0800 Subject: [PATCH 12/16] check core before looking for kernel image --- src/runtime/src/kernel/core1.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/runtime/src/kernel/core1.rs b/src/runtime/src/kernel/core1.rs index 7094205..074eb68 100644 --- a/src/runtime/src/kernel/core1.rs +++ b/src/runtime/src/kernel/core1.rs @@ -5,11 +5,13 @@ use alloc::borrow::ToOwned; use log::{debug, info, error}; use cslice::CSlice; +use libregister::RegisterR; use libcortex_a9::{ enable_fpu, cache::{dcci_slice, iciallu, bpiall}, asm::{dsb, isb}, sync_channel, + regs::MPIDR }; use libboard_zynq::{mpcore, gic}; use libsupport_zynq::ram; @@ -219,7 +221,9 @@ extern fn dl_unwind_find_exidx(pc: *const u32, len_ptr: *mut u32) -> *const u32 let length; let start: *const EXIDX_Entry; unsafe { - if &__text_start as *const u32 <= pc && pc < &__text_end as *const u32 { + let id = MPIDR.read().cpu_id() as usize; + // try to look up kernel for core 1 only + if (&__text_start as *const u32 <= pc && pc < &__text_end as *const u32) || id == 0 { length = (&__exidx_end as *const EXIDX_Entry).offset_from(&__exidx_start) as u32; start = &__exidx_start; } else { -- 2.42.0 From 31ceee7e22586a4f57a3875af9e6bfaa0e1ea763 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Mon, 10 Oct 2022 16:04:38 +0800 Subject: [PATCH 13/16] backtracing should be safe now --- src/runtime/src/panic.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime/src/panic.rs b/src/runtime/src/panic.rs index c0566fc..58365ba 100644 --- a/src/runtime/src/panic.rs +++ b/src/runtime/src/panic.rs @@ -42,9 +42,6 @@ fn panic(info: &core::panic::PanicInfo) -> ! { let mut err_led = ErrorLED::error_led(); err_led.toggle(true); } - if !soft_panicked && id == 0 { - soft_panic(info); - } println!("Backtrace: "); let _ = backtrace(|ip| { // Backtrace gives us the return address, i.e. the address after the delay slot, @@ -52,6 +49,9 @@ fn panic(info: &core::panic::PanicInfo) -> ! { print!("{:#08x} ", ip - 2 * 4); }); println!("\nEnd backtrace"); + if !soft_panicked && id == 0 { + soft_panic(info); + } loop {} } -- 2.42.0 From 93bd98f6c0791f6227a4073b56f3b304abd0292d Mon Sep 17 00:00:00 2001 From: mwojcik Date: Wed, 12 Oct 2022 16:21:26 +0800 Subject: [PATCH 14/16] better way of handling incorrect pc address --- src/runtime/src/kernel/core1.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/runtime/src/kernel/core1.rs b/src/runtime/src/kernel/core1.rs index 074eb68..7836784 100644 --- a/src/runtime/src/kernel/core1.rs +++ b/src/runtime/src/kernel/core1.rs @@ -10,8 +10,7 @@ use libcortex_a9::{ enable_fpu, cache::{dcci_slice, iciallu, bpiall}, asm::{dsb, isb}, - sync_channel, - regs::MPIDR + sync_channel }; use libboard_zynq::{mpcore, gic}; use libsupport_zynq::ram; @@ -221,17 +220,18 @@ extern fn dl_unwind_find_exidx(pc: *const u32, len_ptr: *mut u32) -> *const u32 let length; let start: *const EXIDX_Entry; unsafe { - let id = MPIDR.read().cpu_id() as usize; - // try to look up kernel for core 1 only - if (&__text_start as *const u32 <= pc && pc < &__text_end as *const u32) || id == 0 { + if (&__text_start as *const u32 <= pc && pc < &__text_end as *const u32) { length = (&__exidx_end as *const EXIDX_Entry).offset_from(&__exidx_start) as u32; start = &__exidx_start; - } else { + } else if KERNEL_IMAGE != ptr::null() { let exidx = KERNEL_IMAGE.as_ref() .expect("dl_unwind_find_exidx kernel image") .library.get().as_ref().unwrap().exidx(); length = exidx.len() as u32; start = exidx.as_ptr(); + } else { + *len_ptr = 0; + return 0 as *const u32; } *len_ptr = length; } -- 2.42.0 From d080c65519b05d10fcef66874ba745e34b76d7cb Mon Sep 17 00:00:00 2001 From: mwojcik Date: Wed, 12 Oct 2022 16:31:27 +0800 Subject: [PATCH 15/16] fix warnings, give empty section if nothing found --- src/runtime/src/kernel/core1.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/runtime/src/kernel/core1.rs b/src/runtime/src/kernel/core1.rs index 7836784..661a603 100644 --- a/src/runtime/src/kernel/core1.rs +++ b/src/runtime/src/kernel/core1.rs @@ -5,7 +5,6 @@ use alloc::borrow::ToOwned; use log::{debug, info, error}; use cslice::CSlice; -use libregister::RegisterR; use libcortex_a9::{ enable_fpu, cache::{dcci_slice, iciallu, bpiall}, @@ -220,7 +219,7 @@ extern fn dl_unwind_find_exidx(pc: *const u32, len_ptr: *mut u32) -> *const u32 let length; let start: *const EXIDX_Entry; unsafe { - if (&__text_start as *const u32 <= pc && pc < &__text_end as *const u32) { + if &__text_start as *const u32 <= pc && pc < &__text_end as *const u32 { length = (&__exidx_end as *const EXIDX_Entry).offset_from(&__exidx_start) as u32; start = &__exidx_start; } else if KERNEL_IMAGE != ptr::null() { @@ -230,8 +229,8 @@ extern fn dl_unwind_find_exidx(pc: *const u32, len_ptr: *mut u32) -> *const u32 length = exidx.len() as u32; start = exidx.as_ptr(); } else { - *len_ptr = 0; - return 0 as *const u32; + length = 0; + start = ptr::null(); } *len_ptr = length; } -- 2.42.0 From c6d173a5c509bdf36dfdce97117edbe368264ffc Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 21 Oct 2022 17:18:48 +0800 Subject: [PATCH 16/16] cleanup, reword comment --- src/runtime/src/comms.rs | 2 +- src/runtime/src/kernel/core1.rs | 2 +- src/runtime/src/main.rs | 6 +++--- src/runtime/src/panic.rs | 2 +- src/runtime/src/rtio_clocking.rs | 12 ++++++++++++ 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/runtime/src/comms.rs b/src/runtime/src/comms.rs index d282560..504d637 100644 --- a/src/runtime/src/comms.rs +++ b/src/runtime/src/comms.rs @@ -442,7 +442,7 @@ pub fn main(timer: GlobalTimer, cfg: Config) { } mgmt::start(cfg); - + task::spawn(async move { let connection = Rc::new(Semaphore::new(1, 1)); let terminate = Rc::new(Semaphore::new(0, 1)); diff --git a/src/runtime/src/kernel/core1.rs b/src/runtime/src/kernel/core1.rs index 661a603..52a2928 100644 --- a/src/runtime/src/kernel/core1.rs +++ b/src/runtime/src/kernel/core1.rs @@ -9,7 +9,7 @@ use libcortex_a9::{ enable_fpu, cache::{dcci_slice, iciallu, bpiall}, asm::{dsb, isb}, - sync_channel + sync_channel, }; use libboard_zynq::{mpcore, gic}; use libsupport_zynq::ram; diff --git a/src/runtime/src/main.rs b/src/runtime/src/main.rs index 3433f85..a08c979 100644 --- a/src/runtime/src/main.rs +++ b/src/runtime/src/main.rs @@ -120,10 +120,10 @@ pub fn main_core0() { Config::new_dummy() } }; - task::spawn(report_async_rtio_errors()); rtio_clocking::init(&mut timer, &cfg); - comms::main(timer, cfg); + task::spawn(report_async_rtio_errors()); -} \ No newline at end of file + comms::main(timer, cfg); +} diff --git a/src/runtime/src/panic.rs b/src/runtime/src/panic.rs index 58365ba..9d5ba3b 100644 --- a/src/runtime/src/panic.rs +++ b/src/runtime/src/panic.rs @@ -56,7 +56,7 @@ fn panic(info: &core::panic::PanicInfo) -> ! { } fn soft_panic(info: &core::panic::PanicInfo) -> ! { - // log panic info to log (prints not visible in coremgmt logs) + // write panic info to log, so coremgmt can also read it if let Some(location) = info.location() { error!("panic at {}:{}:{}", location.file(), location.line(), location.column()); } else { diff --git a/src/runtime/src/rtio_clocking.rs b/src/runtime/src/rtio_clocking.rs index 97bcc5e..02de137 100644 --- a/src/runtime/src/rtio_clocking.rs +++ b/src/runtime/src/rtio_clocking.rs @@ -9,6 +9,7 @@ use libboard_zynq::i2c::I2c; use crate::i2c; #[cfg(has_si5324)] use libboard_artiq::si5324; + #[derive(Debug, PartialEq, Copy, Clone)] #[allow(non_camel_case_types)] pub enum RtioClock { @@ -21,6 +22,7 @@ pub enum RtioClock { Ext0_Synth0_100to125, Ext0_Synth0_125to125, } + #[allow(unreachable_code)] fn get_rtio_clock_cfg(cfg: &Config) -> RtioClock { let mut res = RtioClock::Default; @@ -63,6 +65,8 @@ fn get_rtio_clock_cfg(cfg: &Config) -> RtioClock { } res } + + fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) { #[cfg(has_rtio_crg_clock_sel)] let clock_sel = match _clk { @@ -79,6 +83,7 @@ fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) { 0 } }; + unsafe { pl::csr::rtio_crg::pll_reset_write(1); #[cfg(has_rtio_crg_clock_sel)] @@ -92,10 +97,12 @@ fn init_rtio(timer: &mut GlobalTimer, _clk: RtioClock) { } else { panic!("RTIO PLL failed to lock"); } + unsafe { pl::csr::rtio_core::reset_phy_write(1); } } + #[cfg(has_drtio)] fn init_drtio(timer: &mut GlobalTimer) { @@ -107,6 +114,7 @@ fn init_drtio(timer: &mut GlobalTimer) pl::csr::drtio_transceiver::txenable_write(0xffffffffu32 as _); } } + #[cfg(has_si5324)] fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) { let (si5324_settings, si5324_ref_input) = match clk { @@ -225,7 +233,9 @@ fn setup_si5324(i2c: &mut I2c, timer: &mut GlobalTimer, clk: RtioClock) { }; si5324::setup(i2c, &si5324_settings, si5324_ref_input, timer).expect("cannot initialize Si5324"); } + pub fn init(timer: &mut GlobalTimer, cfg: &Config) { + let clk = get_rtio_clock_cfg(cfg); #[cfg(has_si5324)] { @@ -238,5 +248,7 @@ pub fn init(timer: &mut GlobalTimer, cfg: &Config) { } #[cfg(has_drtio)] init_drtio(timer); + init_rtio(timer, clk); + } \ No newline at end of file -- 2.42.0