forked from M-Labs/artiq
1
0
Fork 0

firmware/serwb: cleanup and improve messaging

This commit is contained in:
Sebastien Bourdeauducq 2018-06-19 15:11:03 +08:00
parent c862471165
commit 574892a4e5
1 changed files with 69 additions and 47 deletions

View File

@ -1,53 +1,71 @@
use core::{cmp, str}; use core::{cmp, str};
use board_misoc::{csr, clock}; use board_misoc::{csr, clock};
fn read_rtm_ident(buf: &mut [u8]) -> &str { fn debug_print(rtm: bool) {
unsafe { debug!("AMC serwb settings:");
csr::rtm_identifier::address_write(0); debug!(" bitslip: {}", unsafe { csr::serwb_phy_amc::control_bitslip_read() });
let len = csr::rtm_identifier::data_read(); debug!(" ready: {}", unsafe { csr::serwb_phy_amc::control_ready_read() });
let len = cmp::min(len, buf.len() as u8); debug!(" error: {}", unsafe { csr::serwb_phy_amc::control_error_read() });
for i in 0..len {
csr::rtm_identifier::address_write(1 + i);
buf[i as usize] = csr::rtm_identifier::data_read();
}
str::from_utf8_unchecked(&buf[..len as usize])
}
}
unsafe fn debug_print(rtm: bool) {
info!("AMC serwb settings:");
info!(" bitslip: {}", csr::serwb_phy_amc::control_bitslip_read());
info!(" ready: {}", csr::serwb_phy_amc::control_ready_read());
info!(" error: {}", csr::serwb_phy_amc::control_error_read());
if rtm { if rtm {
info!("RTM serwb settings:"); debug!("RTM serwb settings:");
info!(" bitslip: {}", csr::serwb_phy_rtm::control_bitslip_read()); debug!(" bitslip: {}", unsafe { csr::serwb_phy_rtm::control_bitslip_read() });
info!(" ready: {}", csr::serwb_phy_rtm::control_ready_read()); debug!(" ready: {}", unsafe { csr::serwb_phy_rtm::control_ready_read() });
info!(" error: {}", csr::serwb_phy_rtm::control_error_read()); debug!(" error: {}", unsafe { csr::serwb_phy_rtm::control_error_read() });
} }
} }
fn prbs_test() { fn prbs_test() {
let prbs_test_cycles : u32 = 1<<22; let prbs_test_cycles : u32 = 1<<22;
let prbs_test_us : u64 = ((prbs_test_cycles as u64)*40)/125; // 40 bits @125MHz linerate // 40 bits @125MHz linerate
let prbs_test_us : u64 = ((prbs_test_cycles as u64)*40)/125;
info!("RTM to AMC link test...");
unsafe { unsafe {
info!("RTM to AMC Link test");
csr::serwb_phy_amc::control_prbs_cycles_write(prbs_test_cycles); csr::serwb_phy_amc::control_prbs_cycles_write(prbs_test_cycles);
csr::serwb_phy_amc::control_prbs_start_write(1); csr::serwb_phy_amc::control_prbs_start_write(1);
clock::spin_us(prbs_test_us*110/100); // PRBS test time + 10% }
info!("{} errors", csr::serwb_phy_amc::control_prbs_errors_read()); clock::spin_us(prbs_test_us*110/100); // PRBS test time + 10%
let errors = unsafe {
csr::serwb_phy_amc::control_prbs_errors_read()
};
if errors == 0 {
info!(" ...passed")
} else {
error!(" {} errors found", errors);
}
info!("AMC to RTM Link test"); info!("AMC to RTM link test...");
unsafe {
csr::serwb_phy_rtm::control_prbs_cycles_write(prbs_test_cycles); csr::serwb_phy_rtm::control_prbs_cycles_write(prbs_test_cycles);
csr::serwb_phy_rtm::control_prbs_start_write(1); csr::serwb_phy_rtm::control_prbs_start_write(1);
clock::spin_us(prbs_test_us*110/100); // PRBS test time + 10% }
info!("{} errors", csr::serwb_phy_rtm::control_prbs_errors_read()); clock::spin_us(prbs_test_us*110/100); // PRBS test time + 10%
let errors = unsafe {
csr::serwb_phy_rtm::control_prbs_errors_read()
};
if errors == 0 {
info!(" ...passed");
} else {
error!(" {} errors found", errors);
} }
} }
fn prng32(seed: &mut u32) -> u32 { *seed = 1664525 * *seed + 1013904223; *seed } fn magic_test() {
// Try reading the magic number register on the other side of the bridge.
let rtm_magic = unsafe {
csr::rtm_magic::magic_read()
};
if rtm_magic != 0x5352544d {
error!("incorrect RTM magic number: 0x{:08x}", rtm_magic);
// proceed anyway
}
}
fn prng32(seed: &mut u32) -> u32 {
*seed = 1664525 * *seed + 1013904223;
*seed
}
fn wishbone_test() { fn wishbone_test() {
let test_length: u32 = 512; let test_length: u32 = 512;
@ -76,7 +94,24 @@ fn wishbone_test() {
} }
} }
} }
info!("{} errors", test_errors); if test_errors == 0 {
info!(" ...passed");
} else {
error!(" {} errors found", test_errors);
}
}
fn read_rtm_ident(buf: &mut [u8]) -> &str {
unsafe {
csr::rtm_identifier::address_write(0);
let len = csr::rtm_identifier::data_read();
let len = cmp::min(len, buf.len() as u8);
for i in 0..len {
csr::rtm_identifier::address_write(1 + i);
buf[i as usize] = csr::rtm_identifier::data_read();
}
str::from_utf8_unchecked(&buf[..len as usize])
}
} }
pub fn wait_init() { pub fn wait_init() {
@ -91,26 +126,13 @@ pub fn wait_init() {
} }
} }
} }
info!("done."); info!(" ...done.");
// PRBS test
prbs_test(); prbs_test();
magic_test();
// Wishbone test
wishbone_test(); wishbone_test();
// Try reading the magic number register on the other side of the bridge. debug_print(true);
let rtm_magic = unsafe {
csr::rtm_magic::magic_read()
};
if rtm_magic != 0x5352544d {
error!("incorrect RTM magic number: 0x{:08x}", rtm_magic);
// proceed anyway
}
unsafe {
debug_print(true);
}
info!("RTM gateware version {}", read_rtm_ident(&mut [0; 64])); info!("RTM gateware version {}", read_rtm_ident(&mut [0; 64]));
} }