Skip to content

Instantly share code, notes, and snippets.

@sbourdeauducq
Created June 23, 2018 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbourdeauducq/97b19e164e653a3ea0b96fd83468e160 to your computer and use it in GitHub Desktop.
Save sbourdeauducq/97b19e164e653a3ea0b96fd83468e160 to your computer and use it in GitHub Desktop.
track runtime corruption
diff --git a/artiq/firmware/runtime/Cargo.toml b/artiq/firmware/runtime/Cargo.toml
index f7eb87ac..6c36c0fa 100644
--- a/artiq/firmware/runtime/Cargo.toml
+++ b/artiq/firmware/runtime/Cargo.toml
@@ -19,6 +19,7 @@ failure_derive = { version = "0.1", default-features = false }
byteorder = { version = "1.0", default-features = false }
cslice = { version = "0.3" }
log = { version = "0.4", default-features = false }
+crc = { version = "1.7", default-features = false }
managed = { version = "0.6", default-features = false, features = ["alloc", "map"] }
unwind_backtrace = { path = "../libunwind_backtrace" }
io = { path = "../libio", features = ["byteorder"] }
diff --git a/artiq/firmware/runtime/main.rs b/artiq/firmware/runtime/main.rs
index a0af6667..34bb1ca0 100644
--- a/artiq/firmware/runtime/main.rs
+++ b/artiq/firmware/runtime/main.rs
@@ -14,6 +14,7 @@ extern crate byteorder;
extern crate fringe;
extern crate managed;
extern crate smoltcp;
+extern crate crc;
extern crate alloc_list;
extern crate unwind_backtrace;
@@ -24,10 +25,11 @@ extern crate board_artiq;
extern crate logger_artiq;
extern crate proto_artiq;
+use core::slice;
use core::convert::TryFrom;
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr};
-use board_misoc::{csr, irq, ident, clock, boot, config};
+use board_misoc::{csr, irq, ident, clock, boot, config, mem};
#[cfg(has_ethmac)]
use board_misoc::ethmac;
#[cfg(has_drtio)]
@@ -61,6 +63,13 @@ const SYSREF_PHASE_FPGA: u16 = 20;
#[cfg(has_ad9154)]
const SYSREF_PHASE_DAC: u16 = 31;
+fn runtime_crc() {
+ // typical runtime size is 660k
+ let crc_area = unsafe { slice::from_raw_parts(mem::MAIN_RAM_BASE as *mut u8, 327680) };
+ let crc_val = crc::crc32::checksum_ieee(crc_area);
+ info!("runtime CRC: 0x{:08x}", crc_val);
+}
+
fn startup() {
irq::set_mask(0);
irq::set_ie(true);
@@ -69,6 +78,8 @@ fn startup() {
info!("software version {}", include_str!(concat!(env!("OUT_DIR"), "/git-describe")));
info!("gateware version {}", ident::read(&mut [0; 64]));
+ runtime_crc();
+
match config::read_str("log_level", |r| r.map(|s| s.parse())) {
Ok(Ok(log_level_filter)) => {
info!("log level set to {} by `log_level` config key",
@@ -89,8 +100,10 @@ fn startup() {
#[cfg(has_slave_fpga_cfg)]
board_artiq::slave_fpga::load().expect("cannot load RTM FPGA gateware");
+ runtime_crc();
#[cfg(has_serwb_phy_amc)]
board_artiq::serwb::wait_init();
+ runtime_crc();
#[cfg(has_uart)] {
let t = clock::get_ms();
@@ -110,13 +123,17 @@ fn startup() {
board_artiq::i2c::init();
#[cfg(si5324_as_synthesizer)]
setup_si5324_as_synthesizer();
+ runtime_crc();
#[cfg(has_hmc830_7043)]
/* must be the first SPI init because of HMC830 SPI mode selection */
board_artiq::hmc830_7043::init().expect("cannot initialize HMC830/7043");
+ runtime_crc();
#[cfg(has_ad9154)]
board_artiq::ad9154::init(SYSREF_PHASE_FPGA, SYSREF_PHASE_DAC);
+ runtime_crc();
#[cfg(has_allaki_atts)]
board_artiq::hmc542::program_all(8/*=4dB*/);
+ runtime_crc();
#[cfg(has_ethmac)]
startup_ethernet();
@@ -223,6 +240,8 @@ fn startup_ethernet() {
let mut net_device = unsafe { ethmac::EthernetDevice::new() };
net_device.reset_phy_if_any();
+ runtime_crc();
+
let net_device = {
use smoltcp::wire::PrettyPrinter;
use smoltcp::wire::EthernetFrame;
@@ -253,6 +272,8 @@ fn startup_ethernet() {
.ip_addrs([IpCidr::new(protocol_addr, 0)])
.finalize();
+ runtime_crc();
+
let mut scheduler = sched::Scheduler::new();
let io = scheduler.io();
#[cfg(has_rtio_core)]
@@ -266,10 +287,20 @@ fn startup_ethernet() {
#[cfg(has_grabber)]
io.spawn(4096, grabber_thread);
+ runtime_crc();
+
+ let mut t = clock::get_ms();
+
let mut net_stats = ethmac::EthernetStatistics::new();
loop {
scheduler.run();
+ let now = clock::get_ms();
+ if now > t + 1000 {
+ runtime_crc();
+ t = now;
+ }
+
{
let sockets = &mut *scheduler.sockets().borrow_mut();
loop {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment