forked from M-Labs/artiq
1
0
Fork 0

runtime: allow #[cfg(not(has_rtio))] builds.

This commit is contained in:
whitequark 2017-11-03 15:49:12 +00:00
parent b3e920b3c8
commit 2404a0d8c8
6 changed files with 235 additions and 171 deletions

View File

@ -372,6 +372,7 @@ extern fn dma_retrieve(name: CSlice<u8>) -> DmaTrace {
}) })
} }
#[cfg(has_rtio)]
extern fn dma_playback(timestamp: i64, ptr: i32) { extern fn dma_playback(timestamp: i64, ptr: i32) {
assert!(ptr % 64 == 0); assert!(ptr % 64 == 0);
@ -404,6 +405,11 @@ extern fn dma_playback(timestamp: i64, ptr: i32) {
} }
} }
#[cfg(not(has_rtio))]
extern fn dma_playback(timestamp: i64, ptr: i32) {
unimplemented!("not(has_rtio)")
}
unsafe fn attribute_writeback(typeinfo: *const ()) { unsafe fn attribute_writeback(typeinfo: *const ()) {
struct Attr { struct Attr {
offset: usize, offset: usize,

View File

@ -1,5 +1,9 @@
#[cfg(has_rtio)]
mod imp {
use core::ptr::{read_volatile, write_volatile}; use core::ptr::{read_volatile, write_volatile};
use cslice::CSlice; use cslice::CSlice;
use board::csr; use board::csr;
use ::send; use ::send;
use kernel_proto::*; use kernel_proto::*;
@ -155,14 +159,51 @@ pub fn log(timestamp: i64, data: &[u8]) {
} }
#[cfg(not(has_rtio_log))] #[cfg(not(has_rtio_log))]
pub fn log(_timestamp: i64, _data: &[u8]) {} pub fn log(_timestamp: i64, _data: &[u8]) {
unimplemented!("not(has_rtio_log)")
}
}
#[cfg(not(has_rtio))]
mod imp {
use cslice::CSlice;
pub extern fn init() {
unimplemented!("not(has_rtio)")
}
pub extern fn get_counter() -> i64 {
unimplemented!("not(has_rtio)")
}
pub extern fn output(_timestamp: i64, _channel: i32, _addr: i32, _data: i32) {
unimplemented!("not(has_rtio)")
}
pub extern fn output_wide(_timestamp: i64, _channel: i32, _addr: i32, _data: CSlice<i32>) {
unimplemented!("not(has_rtio)")
}
pub extern fn input_timestamp(_timeout: i64, _channel: i32) -> u64 {
unimplemented!("not(has_rtio)")
}
pub extern fn input_data(_channel: i32) -> i32 {
unimplemented!("not(has_rtio)")
}
pub fn log(_timestamp: i64, _data: &[u8]) {
unimplemented!("not(has_rtio)")
}
}
pub use self::imp::*;
pub mod drtio_dbg { pub mod drtio_dbg {
use ::send; use ::send;
use ::recv; use ::recv;
use kernel_proto::*; use kernel_proto::*;
#[repr(C)] #[repr(C)]
pub struct ChannelState(i32, i64); pub struct ChannelState(i32, i64);

View File

@ -1,8 +1,9 @@
use session::{kern_acknowledge, kern_send};
use rtio_mgt;
use kernel_proto as kern;
use std::io; use std::io;
use kernel_proto as kern;
use sched::Io; use sched::Io;
use session::{kern_acknowledge, kern_send};
#[cfg(has_rtio)]
use rtio_mgt;
#[cfg(has_drtio)] #[cfg(has_drtio)]
mod drtio_i2c { mod drtio_i2c {
@ -317,29 +318,35 @@ mod spi {
pub fn process_kern_hwreq(io: &Io, request: &kern::Message) -> io::Result<bool> { pub fn process_kern_hwreq(io: &Io, request: &kern::Message) -> io::Result<bool> {
match request { match request {
#[cfg(has_rtio)]
&kern::RtioInitRequest => { &kern::RtioInitRequest => {
info!("resetting RTIO"); info!("resetting RTIO");
rtio_mgt::init_core(); rtio_mgt::init_core();
kern_acknowledge() kern_acknowledge()
} }
#[cfg(has_rtio)]
&kern::DrtioChannelStateRequest { channel } => { &kern::DrtioChannelStateRequest { channel } => {
let (fifo_space, last_timestamp) = rtio_mgt::drtio_dbg::get_channel_state(channel); let (fifo_space, last_timestamp) = rtio_mgt::drtio_dbg::get_channel_state(channel);
kern_send(io, &kern::DrtioChannelStateReply { fifo_space: fifo_space, kern_send(io, &kern::DrtioChannelStateReply { fifo_space: fifo_space,
last_timestamp: last_timestamp }) last_timestamp: last_timestamp })
} }
#[cfg(has_rtio)]
&kern::DrtioResetChannelStateRequest { channel } => { &kern::DrtioResetChannelStateRequest { channel } => {
rtio_mgt::drtio_dbg::reset_channel_state(channel); rtio_mgt::drtio_dbg::reset_channel_state(channel);
kern_acknowledge() kern_acknowledge()
} }
#[cfg(has_rtio)]
&kern::DrtioGetFifoSpaceRequest { channel } => { &kern::DrtioGetFifoSpaceRequest { channel } => {
rtio_mgt::drtio_dbg::get_fifo_space(channel); rtio_mgt::drtio_dbg::get_fifo_space(channel);
kern_acknowledge() kern_acknowledge()
} }
#[cfg(has_rtio)]
&kern::DrtioPacketCountRequest { linkno } => { &kern::DrtioPacketCountRequest { linkno } => {
let (tx_cnt, rx_cnt) = rtio_mgt::drtio_dbg::get_packet_counts(linkno); let (tx_cnt, rx_cnt) = rtio_mgt::drtio_dbg::get_packet_counts(linkno);
kern_send(io, &kern::DrtioPacketCountReply { tx_cnt: tx_cnt, rx_cnt: rx_cnt }) kern_send(io, &kern::DrtioPacketCountReply { tx_cnt: tx_cnt, rx_cnt: rx_cnt })
} }
#[cfg(has_rtio)]
&kern::DrtioFifoSpaceReqCountRequest { linkno } => { &kern::DrtioFifoSpaceReqCountRequest { linkno } => {
let cnt = rtio_mgt::drtio_dbg::get_fifo_space_req_count(linkno); let cnt = rtio_mgt::drtio_dbg::get_fifo_space_req_count(linkno);
kern_send(io, &kern::DrtioFifoSpaceReqCountReply { cnt: cnt }) kern_send(io, &kern::DrtioFifoSpaceReqCountReply { cnt: cnt })

View File

@ -37,6 +37,7 @@ macro_rules! borrow_mut {
mod config; mod config;
mod ethmac; mod ethmac;
#[cfg(has_rtio)]
mod rtio_mgt; mod rtio_mgt;
mod urc; mod urc;
@ -123,6 +124,7 @@ fn startup() {
let mut scheduler = sched::Scheduler::new(); let mut scheduler = sched::Scheduler::new();
let io = scheduler.io(); let io = scheduler.io();
#[cfg(has_rtio)]
rtio_mgt::startup(&io); rtio_mgt::startup(&io);
io.spawn(4096, mgmt::thread); io.spawn(4096, mgmt::thread);
io.spawn(16384, session::thread); io.spawn(16384, session::thread);

View File

@ -303,16 +303,3 @@ pub mod drtio_dbg {
} }
} }
} }
#[cfg(not(has_drtio))]
pub mod drtio_dbg {
pub fn get_channel_state(_channel: u32) -> (u16, u64) { (0, 0) }
pub fn reset_channel_state(_channel: u32) {}
pub fn get_fifo_space(_channel: u32) {}
pub fn get_packet_counts(_linkno: u8) -> (u32, u32) { (0, 0) }
pub fn get_fifo_space_req_count(_linkno: u8) -> u32 { 0 }
}

View File

@ -3,19 +3,23 @@ use std::{mem, str};
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use std::error::Error; use std::error::Error;
use {config, rtio_mgt, mailbox, rpc_queue, kernel}; use byteorder::{ByteOrder, NetworkEndian};
use cache::Cache;
use rtio_dma::Manager as DmaManager;
use urc::Urc; use urc::Urc;
use sched::{ThreadHandle, Io}; use sched::{ThreadHandle, Io};
use sched::{TcpListener, TcpStream}; use sched::{TcpListener, TcpStream};
use byteorder::{ByteOrder, NetworkEndian};
use board; use board;
use {config, mailbox, rpc_queue, kernel};
#[cfg(has_rtio)]
use rtio_mgt;
use rtio_dma::Manager as DmaManager;
use cache::Cache;
#[cfg(has_rtio)]
use kern_hwreq;
use rpc_proto as rpc; use rpc_proto as rpc;
use session_proto as host; use session_proto as host;
use kernel_proto as kern; use kernel_proto as kern;
use kern_hwreq;
macro_rules! unexpected { macro_rules! unexpected {
($($arg:tt)*) => { ($($arg:tt)*) => {
@ -268,6 +272,8 @@ fn process_host_message(io: &Io,
unexpected!("attempted to switch RTIO clock while a kernel was running") unexpected!("attempted to switch RTIO clock while a kernel was running")
} }
#[cfg(has_rtio)]
{
if rtio_mgt::crg::switch_clock(clk) { if rtio_mgt::crg::switch_clock(clk) {
host_write(stream, host::Reply::ClockSwitchCompleted) host_write(stream, host::Reply::ClockSwitchCompleted)
} else { } else {
@ -275,6 +281,10 @@ fn process_host_message(io: &Io,
} }
} }
#[cfg(not(has_rtio))]
host_write(stream, host::Reply::ClockSwitchFailed)
}
host::Request::LoadKernel(kernel) => host::Request::LoadKernel(kernel) =>
match unsafe { kern_load(io, session, &kernel) } { match unsafe { kern_load(io, session, &kernel) } {
Ok(()) => host_write(stream, host::Reply::LoadCompleted), Ok(()) => host_write(stream, host::Reply::LoadCompleted),
@ -365,9 +375,14 @@ fn process_kern_message(io: &Io, mut stream: Option<&mut TcpStream>,
} }
kern_recv_dotrace(request); kern_recv_dotrace(request);
#[cfg(has_rtio)]
{
if kern_hwreq::process_kern_hwreq(io, request)? { if kern_hwreq::process_kern_hwreq(io, request)? {
return Ok(false) return Ok(false)
} }
}
match request { match request {
&kern::Log(args) => { &kern::Log(args) => {
use std::fmt::Write; use std::fmt::Write;
@ -541,11 +556,14 @@ fn host_kernel_worker(io: &Io,
return Err(io_error("watchdog expired")) return Err(io_error("watchdog expired"))
} }
#[cfg(has_rtio)]
{
if !rtio_mgt::crg::check() { if !rtio_mgt::crg::check() {
host_write(stream, host::Reply::ClockFailure)?; host_write(stream, host::Reply::ClockFailure)?;
return Err(io_error("RTIO clock failure")) return Err(io_error("RTIO clock failure"))
} }
} }
}
io.relinquish()? io.relinquish()?
} }
@ -583,9 +601,12 @@ fn flash_kernel_worker(io: &Io,
return Err(io_error("watchdog expired")) return Err(io_error("watchdog expired"))
} }
#[cfg(has_rtio)]
{
if !rtio_mgt::crg::check() { if !rtio_mgt::crg::check() {
return Err(io_error("RTIO clock failure")) return Err(io_error("RTIO clock failure"))
} }
}
io.relinquish()? io.relinquish()?
} }