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 board_misoc::{csr, clock};
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])
}
}
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());
fn debug_print(rtm: bool) {
debug!("AMC serwb settings:");
debug!(" bitslip: {}", unsafe { csr::serwb_phy_amc::control_bitslip_read() });
debug!(" ready: {}", unsafe { csr::serwb_phy_amc::control_ready_read() });
debug!(" error: {}", unsafe { csr::serwb_phy_amc::control_error_read() });
if rtm {
info!("RTM serwb settings:");
info!(" bitslip: {}", csr::serwb_phy_rtm::control_bitslip_read());
info!(" ready: {}", csr::serwb_phy_rtm::control_ready_read());
info!(" error: {}", csr::serwb_phy_rtm::control_error_read());
debug!("RTM serwb settings:");
debug!(" bitslip: {}", unsafe { csr::serwb_phy_rtm::control_bitslip_read() });
debug!(" ready: {}", unsafe { csr::serwb_phy_rtm::control_ready_read() });
debug!(" error: {}", unsafe { csr::serwb_phy_rtm::control_error_read() });
}
}
fn prbs_test() {
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 {
info!("RTM to AMC Link test");
csr::serwb_phy_amc::control_prbs_cycles_write(prbs_test_cycles);
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_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() {
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() {
@ -91,26 +126,13 @@ pub fn wait_init() {
}
}
}
info!("done.");
info!(" ...done.");
// PRBS test
prbs_test();
// Wishbone test
magic_test();
wishbone_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
}
unsafe {
debug_print(true);
}
debug_print(true);
info!("RTM gateware version {}", read_rtm_ident(&mut [0; 64]));
}