Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bc36bda94abb
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 09fb4869f340
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Dec 9, 2016

  1. Copy the full SHA
    4422b69 View commit details
  2. Copy the full SHA
    0a9f69a View commit details
  3. Copy the full SHA
    09fb486 View commit details
1 change: 1 addition & 0 deletions artiq/gateware/targets/kc705_drtio_master.py
Original file line number Diff line number Diff line change
@@ -100,6 +100,7 @@ def __init__(self, cfg, medium, **kwargs):
self.submodules += phy
rtio_channels.append(rtio.Channel.from_phy(phy))
self.submodules.rtio_core = rtio.Core(rtio_channels, 3)
self.csr_devices.append("rtio_core")

self.submodules.rtio = rtio.KernelInitiator()
self.submodules.rtio_dma = rtio.DMA(self.get_native_sdram_if())
2 changes: 1 addition & 1 deletion artiq/runtime.rs/libksupport/rtio.rs
Original file line number Diff line number Diff line change
@@ -182,4 +182,4 @@ pub fn log(timestamp: i64, data: &[u8]) {
}

#[cfg(not(has_rtio_log))]
pub fn log(timestamp: i64, data: &[u8]) {}
pub fn log(_timestamp: i64, _data: &[u8]) {}
70 changes: 0 additions & 70 deletions artiq/runtime.rs/src/drtio.rs

This file was deleted.

11 changes: 2 additions & 9 deletions artiq/runtime.rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ extern fn panic_fmt(args: self::core::fmt::Arguments, file: &'static str, line:
mod board;
mod config;
mod clock;
mod rtio_crg;
mod rtio_mgt;
mod mailbox;
mod rpc_queue;

@@ -80,8 +80,6 @@ mod session;
mod moninj;
#[cfg(has_rtio_analyzer)]
mod analyzer;
#[cfg(has_drtio)]
mod drtio;

extern {
fn network_init();
@@ -120,20 +118,15 @@ pub unsafe extern fn rust_main() {
}
info!("continuing boot");

rtio_crg::init();
network_init();

let mut scheduler = sched::Scheduler::new();
rtio_mgt::startup(&scheduler);
scheduler.spawner().spawn(16384, session::thread);
#[cfg(has_rtio_moninj)]
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();
65 changes: 0 additions & 65 deletions artiq/runtime.rs/src/rtio_crg.rs

This file was deleted.

161 changes: 161 additions & 0 deletions artiq/runtime.rs/src/rtio_mgt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
use config;
use board::csr;
use sched::Scheduler;

#[cfg(has_rtio_crg)]
pub mod crg {
use clock;
use board::csr;

pub fn init() {
unsafe { csr::rtio_crg::pll_reset_write(0) }
}

pub fn check() -> bool {
unsafe { csr::rtio_crg::pll_locked_read() != 0 }
}

pub fn switch_clock(clk: u8) -> bool {
unsafe {
let cur_clk = csr::rtio_crg::clock_sel_read();
if clk != cur_clk {
csr::rtio_crg::pll_reset_write(1);
csr::rtio_crg::clock_sel_write(clk);
csr::rtio_crg::pll_reset_write(0);
}
}

clock::spin_us(150);
return check()
}
}

#[cfg(not(has_rtio_crg))]
pub mod crg {
pub fn init() {}
pub fn check() -> bool { true }
pub fn switch_clock(_clk: u8) -> bool { true }
}

#[cfg(has_drtio)]
mod drtio {
use board::csr;
use sched::{Scheduler, Waiter, Spawner};

pub fn init(scheduler: &Scheduler) {
scheduler.spawner().spawn(4096, link_thread);
scheduler.spawner().spawn(4096, error_thread);
}

fn link_is_up() -> bool {
unsafe {
csr::drtio::link_status_read() == 1
}
}

fn sync_tsc() {
unsafe {
csr::drtio::set_time_write(1);
while csr::drtio::set_time_read() == 1 {}
}
}

fn 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 {}
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(link_is_up).unwrap();
info!("link RX is up");

waiter.sleep(600).unwrap();
info!("wait for remote side done");

sync_tsc();
info!("TSC synced");
for channel in 0..16 {
init_channel(channel);
}
info!("link initialization completed");

waiter.until(|| !link_is_up()).unwrap();
info!("link is down");
}
}

fn packet_error_present() -> bool {
unsafe {
csr::drtio::packet_err_present_read() != 0
}
}

fn get_packet_error() -> u8 {
unsafe {
let err = csr::drtio::packet_err_code_read();
csr::drtio::packet_err_present_write(1);
err
}
}

pub fn error_thread(waiter: Waiter, _spawner: Spawner) {
loop {
waiter.until(packet_error_present).unwrap();
error!("DRTIO packet error {}", get_packet_error());
}
}

}

#[cfg(not(has_drtio))]
mod drtio {
use sched::Scheduler;

pub fn init(_scheduler: &Scheduler) {}
}

pub fn startup(scheduler: &Scheduler) {
crg::init();

let mut opt = [b'i'];
let clk;
match config::read("startup_clock", &mut opt) {
Ok(0) | Ok(1) if &opt == b"i" => {
info!("startup RTIO clock: internal");
clk = 0
}
Ok(1) if &opt == b"e" => {
info!("startup RTIO clock: external");
clk = 1
}
_ => {
error!("unrecognized startup_clock configuration entry");
clk = 0
}
};

if !crg::switch_clock(clk) {
error!("startup RTIO clock failed");
warn!("this may cause the system initialization to fail");
warn!("fix clocking and reset the device");
}

drtio::init(scheduler);
init_core()
}

pub fn init_core() {
unsafe {
csr::rtio_core::reset_write(1);
}
}
Loading