artiq-zynq/src/runtime/src/main.rs

87 lines
2.4 KiB
Rust
Raw Normal View History

2020-04-11 20:19:39 +08:00
#![no_std]
#![no_main]
2020-04-25 20:45:25 +08:00
#![recursion_limit="1024"] // for futures_util::select!
2020-06-07 15:12:34 +08:00
#![feature(llvm_asm)]
2020-04-11 20:19:39 +08:00
extern crate alloc;
2020-04-11 21:32:44 +08:00
use core::{cmp, str};
2020-06-25 11:27:50 +08:00
use log::{info, error};
2020-04-11 22:24:23 +08:00
2020-05-04 22:27:15 +08:00
use libboard_zynq::{timer::GlobalTimer, logger, devc};
2020-05-01 08:18:36 +08:00
use libsupport_zynq::ram;
2020-04-11 21:32:44 +08:00
2020-06-13 15:33:17 +08:00
mod sd_reader;
2020-06-13 16:44:54 +08:00
mod config;
mod proto_core_io;
mod proto_async;
2020-04-13 13:48:08 +08:00
mod comms;
2020-06-01 18:02:21 +08:00
mod rpc;
2020-05-07 13:52:40 +08:00
#[path = "../../../build/pl.rs"]
2020-04-11 21:32:44 +08:00
mod pl;
2020-04-12 20:15:01 +08:00
mod rtio;
2020-04-13 13:48:08 +08:00
mod kernel;
2020-04-24 14:37:16 +08:00
mod moninj;
mod load_pl;
2020-04-11 21:32:44 +08:00
fn identifier_read(buf: &mut [u8]) -> &str {
unsafe {
pl::csr::identifier::address_write(0);
let len = pl::csr::identifier::data_read();
let len = cmp::min(len, buf.len() as u8);
for i in 0..len {
pl::csr::identifier::address_write(1 + i);
buf[i as usize] = pl::csr::identifier::data_read();
}
str::from_utf8_unchecked(&buf[..len as usize])
}
}
2020-04-11 20:19:39 +08:00
#[no_mangle]
pub fn main_core0() {
2020-04-25 12:59:57 +08:00
let timer = GlobalTimer::start();
2020-04-22 07:03:58 +08:00
let _ = logger::init();
log::set_max_level(log::LevelFilter::Debug);
2020-05-07 12:43:53 +08:00
info!("NAR3/Zynq7000 starting...");
2020-04-11 22:24:23 +08:00
2020-04-28 19:07:49 +08:00
ram::init_alloc_linker();
2020-04-11 22:24:23 +08:00
2020-06-25 11:27:50 +08:00
match config::Config::new() {
Ok(mut cfg) => {
match cfg.read_str("FOO") {
Ok(val) => info!("FOO = {}", val),
Err(error) => info!("failed to read config FOO: {}", error),
}
match cfg.read_str("BAR") {
Ok(val) => info!("BAR = {}", val),
Err(error) => info!("failed to read config BAR: {}", error),
}
match cfg.read_str("FOOBAR") {
Ok(val) => info!("read FOOBAR = {}", val),
Err(error) => info!("failed to read config FOOBAR: {}", error),
}
},
Err(error) => error!("config failed: {}", error)
2020-06-13 16:44:54 +08:00
}
if devc::DevC::new().is_done() {
2020-05-04 22:27:15 +08:00
info!("gateware already loaded");
2020-05-07 12:43:53 +08:00
// Do not load again: assume that the gateware already present is
// what we want (e.g. gateware configured via JTAG before PS
// startup, or by FSBL).
2020-05-04 22:27:15 +08:00
} else {
// Load from SD card
match load_pl::load_bitstream_from_sd() {
Ok(_) => info!("Bitstream loaded successfully!"),
Err(e) => info!("Failure loading bitstream: {}", e),
}
2020-05-04 22:27:15 +08:00
}
info!("detected gateware: {}", identifier_read(&mut [0; 64]));
2020-04-11 22:24:23 +08:00
2020-04-26 11:51:21 +08:00
unsafe {
pl::csr::rtio_core::reset_phy_write(1);
}
2020-04-25 12:59:57 +08:00
comms::main(timer);
2020-04-11 20:19:39 +08:00
}