From 2b2b345eb9d2e60b5df93efd1ccee9dc032febf2 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 6 Sep 2017 11:07:07 +0800 Subject: [PATCH] firmware: wait for serwb to be ready before proceeding further --- artiq/firmware/libboard/lib.rs | 2 ++ artiq/firmware/libboard/serwb.rs | 18 ++++++++++++++++++ artiq/firmware/runtime/lib.rs | 3 +++ artiq/firmware/satman/lib.rs | 3 +++ 4 files changed, 26 insertions(+) create mode 100644 artiq/firmware/libboard/serwb.rs diff --git a/artiq/firmware/libboard/lib.rs b/artiq/firmware/libboard/lib.rs index edeef1e69..738740273 100644 --- a/artiq/firmware/libboard/lib.rs +++ b/artiq/firmware/libboard/lib.rs @@ -25,6 +25,8 @@ pub mod spi; #[cfg(has_si5324)] pub mod si5324; +#[cfg(has_serwb_phy)] +pub mod serwb; #[cfg(has_ad9516)] #[allow(dead_code)] mod ad9516_reg; diff --git a/artiq/firmware/libboard/serwb.rs b/artiq/firmware/libboard/serwb.rs new file mode 100644 index 000000000..ce7fbf2cf --- /dev/null +++ b/artiq/firmware/libboard/serwb.rs @@ -0,0 +1,18 @@ +use csr; + +pub fn wait_init() { + info!("waiting for AMC/RTM serwb bridge to be ready..."); + unsafe { + while csr::serwb_phy::control_ready_read() != 0 {} + } + info!("done."); + + // Try reading the identifier register on the other side of the bridge. + let rtm_identifier = unsafe { + csr::rtm_identifier::identifier_read() + }; + if rtm_identifier != 0x5352544d { + error!("incorrect RTM identifier: 0x{:08x}", rtm_identifier); + // proceed anyway + } +} diff --git a/artiq/firmware/runtime/lib.rs b/artiq/firmware/runtime/lib.rs index 80b780497..e09cf321d 100644 --- a/artiq/firmware/runtime/lib.rs +++ b/artiq/firmware/runtime/lib.rs @@ -63,6 +63,9 @@ fn startup() { info!("software version {}", include_str!(concat!(env!("OUT_DIR"), "/git-describe"))); info!("gateware version {}", board::ident(&mut [0; 64])); + #[cfg(has_serwb_phy)] + board::serwb::wait_init(); + let t = board::clock::get_ms(); info!("press 'e' to erase startup and idle kernels..."); while board::clock::get_ms() < t + 1000 { diff --git a/artiq/firmware/satman/lib.rs b/artiq/firmware/satman/lib.rs index 3137e7e04..95fbb6e59 100644 --- a/artiq/firmware/satman/lib.rs +++ b/artiq/firmware/satman/lib.rs @@ -195,6 +195,9 @@ fn startup() { info!("software version {}", include_str!(concat!(env!("OUT_DIR"), "/git-describe"))); info!("gateware version {}", board::ident(&mut [0; 64])); + #[cfg(has_serwb_phy)] + board::serwb::wait_init(); + #[cfg(has_ad9516)] board::ad9516::init().expect("cannot initialize AD9516"); #[cfg(has_hmc830_7043)]