forked from M-Labs/artiq
drtio: add debug syscalls
This commit is contained in:
parent
1b49affd18
commit
fdfaa377db
|
@ -0,0 +1,22 @@
|
||||||
|
from artiq.language.core import syscall
|
||||||
|
from artiq.language.types import TTuple, TInt32, TInt64, TNone
|
||||||
|
|
||||||
|
|
||||||
|
@syscall(flags={"nounwind", "nowrite"})
|
||||||
|
def drtio_get_channel_state(channel: TInt32) -> TTuple([TInt32, TInt64]):
|
||||||
|
raise NotImplementedError("syscall not simulated")
|
||||||
|
|
||||||
|
|
||||||
|
@syscall(flags={"nounwind", "nowrite"})
|
||||||
|
def drtio_reset_channel_state(channel: TInt32) -> TNone:
|
||||||
|
raise NotImplementedError("syscall not simulated")
|
||||||
|
|
||||||
|
|
||||||
|
@syscall(flags={"nounwind", "nowrite"})
|
||||||
|
def drtio_get_fifo_space(channel: TInt32) -> TNone:
|
||||||
|
raise NotImplementedError("syscall not simulated")
|
||||||
|
|
||||||
|
|
||||||
|
@syscall(flags={"nounwind", "nowrite"})
|
||||||
|
def drtio_get_packet_counts() -> TTuple([TInt32, TInt32]):
|
||||||
|
raise NotImplementedError("syscall not simulated")
|
|
@ -106,6 +106,11 @@ static mut API: &'static [(&'static str, *const ())] = &[
|
||||||
api!(rtio_input_timestamp = ::rtio::input_timestamp),
|
api!(rtio_input_timestamp = ::rtio::input_timestamp),
|
||||||
api!(rtio_input_data = ::rtio::input_data),
|
api!(rtio_input_data = ::rtio::input_data),
|
||||||
|
|
||||||
|
api!(drtio_get_channel_state = ::rtio::drtio_dbg::get_channel_state),
|
||||||
|
api!(drtio_reset_channel_state = ::rtio::drtio_dbg::reset_channel_state),
|
||||||
|
api!(drtio_get_fifo_space = ::rtio::drtio_dbg::get_fifo_space),
|
||||||
|
api!(drtio_get_packet_counts = ::rtio::drtio_dbg::get_packet_counts),
|
||||||
|
|
||||||
api!(i2c_start = ::i2c_start),
|
api!(i2c_start = ::i2c_start),
|
||||||
api!(i2c_stop = ::i2c_stop),
|
api!(i2c_stop = ::i2c_stop),
|
||||||
api!(i2c_write = ::i2c_write),
|
api!(i2c_write = ::i2c_write),
|
||||||
|
|
|
@ -47,8 +47,6 @@ macro_rules! artiq_raise {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
mod rtio;
|
|
||||||
|
|
||||||
use core::{mem, ptr, slice, str};
|
use core::{mem, ptr, slice, str};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use libc::{c_char, size_t};
|
use libc::{c_char, size_t};
|
||||||
|
@ -91,6 +89,7 @@ macro_rules! println {
|
||||||
|
|
||||||
#[path = "../runtime/rpc_queue.rs"]
|
#[path = "../runtime/rpc_queue.rs"]
|
||||||
mod rpc_queue;
|
mod rpc_queue;
|
||||||
|
mod rtio;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[lang = "panic_fmt"]
|
#[lang = "panic_fmt"]
|
||||||
|
|
|
@ -183,3 +183,36 @@ 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]) {}
|
||||||
|
|
||||||
|
pub mod drtio_dbg {
|
||||||
|
use ::send;
|
||||||
|
use ::recv;
|
||||||
|
use kernel_proto::*;
|
||||||
|
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct ChannelState(i32, i64);
|
||||||
|
|
||||||
|
pub extern fn get_channel_state(channel: i32) -> ChannelState {
|
||||||
|
send(&DRTIOChannelStateRequest { channel: channel as u32 });
|
||||||
|
recv!(&DRTIOChannelStateReply { fifo_space, last_timestamp }
|
||||||
|
=> ChannelState(fifo_space as i32, last_timestamp as i64))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub extern fn reset_channel_state(channel: i32) {
|
||||||
|
send(&DRTIOResetChannelStateRequest { channel: channel as u32 })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub extern fn get_fifo_space(channel: i32) {
|
||||||
|
send(&DRTIOGetFIFOSpaceRequest { channel: channel as u32 })
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct PacketCounts(i32, i32);
|
||||||
|
|
||||||
|
pub extern fn get_packet_counts() -> PacketCounts {
|
||||||
|
send(&DRTIOPacketCountRequest);
|
||||||
|
recv!(&DRTIOPacketCountReply { tx_cnt, rx_cnt }
|
||||||
|
=> PacketCounts(tx_cnt as i32, rx_cnt as i32))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,13 @@ pub enum Message<'a> {
|
||||||
|
|
||||||
RTIOInitRequest,
|
RTIOInitRequest,
|
||||||
|
|
||||||
|
DRTIOChannelStateRequest { channel: u32 },
|
||||||
|
DRTIOChannelStateReply { fifo_space: u16, last_timestamp: u64 },
|
||||||
|
DRTIOResetChannelStateRequest { channel: u32 },
|
||||||
|
DRTIOGetFIFOSpaceRequest { channel: u32 },
|
||||||
|
DRTIOPacketCountRequest,
|
||||||
|
DRTIOPacketCountReply { tx_cnt: u32, rx_cnt: u32 },
|
||||||
|
|
||||||
RunFinished,
|
RunFinished,
|
||||||
RunException {
|
RunException {
|
||||||
exception: Exception<'a>,
|
exception: Exception<'a>,
|
||||||
|
|
|
@ -177,3 +177,55 @@ pub fn init_core() {
|
||||||
}
|
}
|
||||||
drtio::init()
|
drtio::init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(has_drtio)]
|
||||||
|
pub mod drtio_dbg {
|
||||||
|
use board::csr;
|
||||||
|
|
||||||
|
pub fn get_channel_state(channel: u32) -> (u16, u64) {
|
||||||
|
unsafe {
|
||||||
|
csr::drtio::chan_sel_override_write(channel as u16);
|
||||||
|
csr::drtio::chan_sel_override_en_write(1);
|
||||||
|
let fifo_space = csr::drtio::o_dbg_fifo_space_read();
|
||||||
|
let last_timestamp = csr::drtio::o_dbg_last_timestamp_read();
|
||||||
|
csr::drtio::chan_sel_override_en_write(0);
|
||||||
|
(fifo_space, last_timestamp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reset_channel_state(channel: u32) {
|
||||||
|
unsafe {
|
||||||
|
csr::drtio::chan_sel_override_write(channel as u16);
|
||||||
|
csr::drtio::chan_sel_override_en_write(1);
|
||||||
|
csr::drtio::o_reset_channel_status_write(1);
|
||||||
|
csr::drtio::chan_sel_override_en_write(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_fifo_space(channel: u32) {
|
||||||
|
unsafe {
|
||||||
|
csr::drtio::chan_sel_override_write(channel as u16);
|
||||||
|
csr::drtio::chan_sel_override_en_write(1);
|
||||||
|
csr::drtio::o_get_fifo_space_write(1);
|
||||||
|
csr::drtio::chan_sel_override_en_write(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_packet_counts() -> (u32, u32) {
|
||||||
|
unsafe {
|
||||||
|
csr::drtio::update_packet_cnt_write(1);
|
||||||
|
(csr::drtio::packet_cnt_tx_read(), csr::drtio::packet_cnt_rx_read())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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() -> (u32, u32) { (0, 0) }
|
||||||
|
}
|
||||||
|
|
|
@ -384,6 +384,24 @@ fn process_kern_message(waiter: Waiter,
|
||||||
kern_acknowledge()
|
kern_acknowledge()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&kern::DRTIOChannelStateRequest { channel } => {
|
||||||
|
let (fifo_space, last_timestamp) = rtio_mgt::drtio_dbg::get_channel_state(channel);
|
||||||
|
kern_send(waiter, &kern::DRTIOChannelStateReply { fifo_space: fifo_space,
|
||||||
|
last_timestamp: last_timestamp })
|
||||||
|
}
|
||||||
|
&kern::DRTIOResetChannelStateRequest { channel } => {
|
||||||
|
rtio_mgt::drtio_dbg::reset_channel_state(channel);
|
||||||
|
kern_acknowledge()
|
||||||
|
}
|
||||||
|
&kern::DRTIOGetFIFOSpaceRequest { channel } => {
|
||||||
|
rtio_mgt::drtio_dbg::get_fifo_space(channel);
|
||||||
|
kern_acknowledge()
|
||||||
|
}
|
||||||
|
&kern::DRTIOPacketCountRequest => {
|
||||||
|
let (tx_cnt, rx_cnt) = rtio_mgt::drtio_dbg::get_packet_counts();
|
||||||
|
kern_send(waiter, &kern::DRTIOPacketCountReply { tx_cnt: tx_cnt, rx_cnt: rx_cnt })
|
||||||
|
}
|
||||||
|
|
||||||
&kern::WatchdogSetRequest { ms } => {
|
&kern::WatchdogSetRequest { ms } => {
|
||||||
let id = try!(session.watchdog_set.set_ms(ms)
|
let id = try!(session.watchdog_set.set_ms(ms)
|
||||||
.map_err(|()| io_error("out of watchdogs")));
|
.map_err(|()| io_error("out of watchdogs")));
|
||||||
|
|
Loading…
Reference in New Issue