runtime: basic DRTIO init code

This commit is contained in:
Sebastien Bourdeauducq 2016-11-07 19:34:34 +08:00
parent 266ae292d9
commit 78f18a12eb
2 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,67 @@
use board::csr;
use sched::{Waiter, Spawner};
fn drtio_link_is_up() -> bool {
unsafe {
csr::drtio::link_status_read() == 4
}
}
fn drtio_sync_tsc() {
unsafe {
csr::drtio::set_time_write(1);
while csr::drtio::set_time_read() == 1 {}
}
}
fn drtio_init_channel(channel: u16) {
unsafe {
csr::drtio::chan_sel_override_write(channel);
csr::drtio::chan_sel_override_en_write(1);
csr::drtio::o_reset_channel_status_write(1);
csr::drtio::o_get_fifo_space_write(1);
while csr::drtio::o_wait_read() == 1 {} // TODO: timeout
info!("FIFO space on channel {} is {}", channel, csr::drtio::o_dbg_fifo_space_read());
csr::drtio::chan_sel_override_en_write(0);
}
}
pub fn link_thread(waiter: Waiter, _spawner: Spawner) {
loop {
waiter.until(drtio_link_is_up).unwrap();
info!("link is up");
drtio_sync_tsc();
info!("TSC synced");
for channel in 0..16 {
drtio_init_channel(channel);
}
info!("link initialization completed");
waiter.until(|| !drtio_link_is_up()).unwrap();
info!("link is down");
}
}
fn drtio_error_present() -> bool {
unsafe {
csr::drtio::err_present_read() != 0
}
}
fn drtio_get_error() -> u8 {
unsafe {
let err = csr::drtio::err_code_read();
csr::drtio::err_present_write(1);
err
}
}
pub fn error_thread(waiter: Waiter, _spawner: Spawner) {
loop {
waiter.until(drtio_error_present).unwrap();
error!("DRTIO error {}", drtio_get_error());
}
}

View File

@ -79,6 +79,8 @@ mod session;
mod moninj;
#[cfg(has_rtio_analyzer)]
mod analyzer;
#[cfg(has_drtio)]
mod drtio;
extern {
fn network_init();
@ -114,6 +116,11 @@ pub unsafe extern fn rust_main() {
scheduler.spawner().spawn(4096, moninj::thread);
#[cfg(has_rtio_analyzer)]
scheduler.spawner().spawn(4096, analyzer::thread);
#[cfg(has_drtio)]
{
scheduler.spawner().spawn(4096, drtio::link_thread);
scheduler.spawner().spawn(4096, drtio::error_thread);
}
loop {
scheduler.run();