2020-04-11 20:19:39 +08:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
2023-02-22 11:02:43 +08:00
|
|
|
#![recursion_limit = "1024"] // for futures_util::select!
|
2020-07-02 13:10:11 +08:00
|
|
|
#![feature(alloc_error_handler)]
|
|
|
|
#![feature(panic_info_message)]
|
2020-07-20 14:10:46 +08:00
|
|
|
#![feature(c_variadic)]
|
2020-07-25 12:12:56 +08:00
|
|
|
#![feature(const_btree_new)]
|
2020-08-04 10:15:57 +08:00
|
|
|
#![feature(const_in_array_repeat_expressions)]
|
2021-01-18 10:38:50 +08:00
|
|
|
#![feature(naked_functions)]
|
2021-01-18 16:43:49 +08:00
|
|
|
#![feature(asm)]
|
2020-04-11 20:19:39 +08:00
|
|
|
|
2023-01-09 12:35:56 +08:00
|
|
|
#[macro_use]
|
2020-04-11 20:19:39 +08:00
|
|
|
extern crate alloc;
|
|
|
|
|
2023-02-22 11:02:43 +08:00
|
|
|
use libasync::{block_async, task};
|
|
|
|
#[cfg(feature = "target_kasli_soc")]
|
|
|
|
use libboard_artiq::io_expander;
|
|
|
|
use libboard_artiq::{identifier_read, logger, pl};
|
|
|
|
use libboard_zynq::{gic, mpcore, timer::GlobalTimer};
|
|
|
|
use libconfig::Config;
|
|
|
|
use libcortex_a9::l2c::enable_l2_cache;
|
2020-05-01 08:18:36 +08:00
|
|
|
use libsupport_zynq::ram;
|
2023-02-22 11:02:43 +08:00
|
|
|
use log::{error, info, warn};
|
2020-07-13 16:06:05 +08:00
|
|
|
use nb;
|
|
|
|
use void::Void;
|
2020-04-11 21:32:44 +08:00
|
|
|
|
2022-06-20 17:41:08 +08:00
|
|
|
const ASYNC_ERROR_COLLISION: u8 = 1 << 0;
|
|
|
|
const ASYNC_ERROR_BUSY: u8 = 1 << 1;
|
|
|
|
const ASYNC_ERROR_SEQUENCE_ERROR: u8 = 1 << 2;
|
|
|
|
|
2023-02-22 11:02:43 +08:00
|
|
|
mod analyzer;
|
2020-04-13 13:48:08 +08:00
|
|
|
mod comms;
|
2023-02-22 11:02:43 +08:00
|
|
|
mod eh_artiq;
|
|
|
|
mod i2c;
|
|
|
|
mod irq;
|
|
|
|
mod kernel;
|
|
|
|
mod mgmt;
|
|
|
|
mod moninj;
|
|
|
|
mod panic;
|
|
|
|
mod proto_async;
|
2020-06-01 18:02:21 +08:00
|
|
|
mod rpc;
|
2020-08-04 13:15:26 +08:00
|
|
|
#[cfg(ki_impl = "csr")]
|
|
|
|
#[path = "rtio_csr.rs"]
|
|
|
|
mod rtio;
|
|
|
|
#[cfg(ki_impl = "acp")]
|
|
|
|
#[path = "rtio_acp.rs"]
|
2020-04-12 20:15:01 +08:00
|
|
|
mod rtio;
|
2021-11-29 11:17:59 +08:00
|
|
|
mod rtio_clocking;
|
2023-02-22 11:02:43 +08:00
|
|
|
mod rtio_mgt;
|
2020-07-08 19:58:13 +08:00
|
|
|
|
2021-12-06 17:38:55 +08:00
|
|
|
static mut SEEN_ASYNC_ERRORS: u8 = 0;
|
|
|
|
|
|
|
|
pub unsafe fn get_async_errors() -> u8 {
|
|
|
|
let errors = SEEN_ASYNC_ERRORS;
|
|
|
|
SEEN_ASYNC_ERRORS = 0;
|
|
|
|
errors
|
|
|
|
}
|
2021-10-06 13:05:45 +08:00
|
|
|
|
2020-07-13 16:06:05 +08:00
|
|
|
fn wait_for_async_rtio_error() -> nb::Result<(), Void> {
|
|
|
|
unsafe {
|
|
|
|
if pl::csr::rtio_core::async_error_read() != 0 {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(nb::Error::WouldBlock)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn report_async_rtio_errors() {
|
|
|
|
loop {
|
|
|
|
let _ = block_async!(wait_for_async_rtio_error()).await;
|
|
|
|
unsafe {
|
|
|
|
let errors = pl::csr::rtio_core::async_error_read();
|
2022-06-20 17:41:08 +08:00
|
|
|
if errors & ASYNC_ERROR_COLLISION != 0 {
|
2023-01-09 12:35:56 +08:00
|
|
|
let channel = pl::csr::rtio_core::collision_channel_read();
|
2023-02-22 11:02:43 +08:00
|
|
|
error!(
|
|
|
|
"RTIO collision involving channel 0x{:04x}:{}",
|
|
|
|
channel,
|
|
|
|
rtio_mgt::resolve_channel_name(channel as u32)
|
|
|
|
);
|
2020-07-13 16:06:05 +08:00
|
|
|
}
|
2022-06-20 17:41:08 +08:00
|
|
|
if errors & ASYNC_ERROR_BUSY != 0 {
|
2023-01-09 12:35:56 +08:00
|
|
|
let channel = pl::csr::rtio_core::busy_channel_read();
|
2023-02-22 11:02:43 +08:00
|
|
|
error!(
|
|
|
|
"RTIO busy error involving channel 0x{:04x}:{}",
|
|
|
|
channel,
|
|
|
|
rtio_mgt::resolve_channel_name(channel as u32)
|
|
|
|
);
|
2020-07-13 16:06:05 +08:00
|
|
|
}
|
2022-06-20 17:41:08 +08:00
|
|
|
if errors & ASYNC_ERROR_SEQUENCE_ERROR != 0 {
|
2023-01-09 12:35:56 +08:00
|
|
|
let channel = pl::csr::rtio_core::sequence_error_channel_read();
|
2023-02-22 11:02:43 +08:00
|
|
|
error!(
|
|
|
|
"RTIO sequence error involving channel 0x{:04x}:{}",
|
|
|
|
channel,
|
|
|
|
rtio_mgt::resolve_channel_name(channel as u32)
|
|
|
|
);
|
2020-07-13 16:06:05 +08:00
|
|
|
}
|
2021-12-06 17:38:55 +08:00
|
|
|
SEEN_ASYNC_ERRORS = errors;
|
2020-07-13 16:06:05 +08:00
|
|
|
pl::csr::rtio_core::async_error_write(errors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-22 11:02:43 +08:00
|
|
|
static mut LOG_BUFFER: [u8; 1 << 17] = [0; 1 << 17];
|
2020-07-13 14:59:56 +08:00
|
|
|
|
2020-07-08 19:58:13 +08:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn main_core0() {
|
2021-01-26 12:38:09 +08:00
|
|
|
enable_l2_cache(0x8);
|
2020-07-23 05:58:55 +08:00
|
|
|
let mut timer = GlobalTimer::start();
|
2020-07-13 14:59:56 +08:00
|
|
|
|
2023-02-22 11:02:43 +08:00
|
|
|
let buffer_logger = unsafe { logger::BufferLogger::new(&mut LOG_BUFFER[..]) };
|
2020-09-01 17:11:21 +08:00
|
|
|
buffer_logger.set_uart_log_level(log::LevelFilter::Info);
|
2020-07-13 14:59:56 +08:00
|
|
|
buffer_logger.register();
|
2020-09-01 17:11:21 +08:00
|
|
|
log::set_max_level(log::LevelFilter::Info);
|
2020-07-13 14:59:56 +08:00
|
|
|
|
2020-07-08 19:58:13 +08:00
|
|
|
info!("NAR3/Zynq7000 starting...");
|
|
|
|
|
2020-08-04 10:15:57 +08:00
|
|
|
ram::init_alloc_core0();
|
2020-08-18 01:17:15 +08:00
|
|
|
gic::InterruptController::gic(mpcore::RegisterBlock::mpcore()).enable_interrupts();
|
2020-07-08 19:58:13 +08:00
|
|
|
|
2022-10-21 12:08:11 +08:00
|
|
|
info!("gateware ident: {}", identifier_read(&mut [0; 64]));
|
2020-09-06 00:11:19 +08:00
|
|
|
|
|
|
|
i2c::init();
|
|
|
|
|
2023-02-15 17:44:01 +08:00
|
|
|
#[cfg(feature = "target_kasli_soc")]
|
|
|
|
{
|
2023-02-17 17:19:30 +08:00
|
|
|
let i2c = unsafe { (&mut i2c::I2C_BUS).as_mut().unwrap() };
|
2023-02-17 17:49:36 +08:00
|
|
|
for expander_i in 0..=1 {
|
2023-02-17 17:19:30 +08:00
|
|
|
let mut io_expander = io_expander::IoExpander::new(i2c, expander_i).unwrap();
|
|
|
|
io_expander.init().expect("I2C I/O expander #0 initialization failed");
|
|
|
|
// Actively drive TX_DISABLE to false on SFP0..3
|
|
|
|
io_expander.set_oe(0, 1 << 1).unwrap();
|
|
|
|
io_expander.set_oe(1, 1 << 1).unwrap();
|
|
|
|
io_expander.set(0, 1, false);
|
|
|
|
io_expander.set(1, 1, false);
|
|
|
|
io_expander.service().unwrap();
|
|
|
|
}
|
2023-02-15 17:44:01 +08:00
|
|
|
}
|
|
|
|
|
2020-09-01 14:43:16 +08:00
|
|
|
let cfg = match Config::new() {
|
2020-07-08 19:24:26 +08:00
|
|
|
Ok(cfg) => cfg,
|
|
|
|
Err(err) => {
|
|
|
|
warn!("config initialization failed: {}", err);
|
2020-09-01 14:43:16 +08:00
|
|
|
Config::new_dummy()
|
2020-07-08 19:24:26 +08:00
|
|
|
}
|
|
|
|
};
|
2023-02-22 11:02:43 +08:00
|
|
|
|
2021-11-29 11:17:59 +08:00
|
|
|
rtio_clocking::init(&mut timer, &cfg);
|
2021-10-06 13:05:45 +08:00
|
|
|
|
2020-07-13 16:06:05 +08:00
|
|
|
task::spawn(report_async_rtio_errors());
|
2020-07-08 19:58:13 +08:00
|
|
|
|
2023-02-15 18:14:05 +08:00
|
|
|
comms::main(timer, cfg);
|
2020-04-11 20:19:39 +08:00
|
|
|
}
|