From 7c699e2f801c8e134d1f4d60b6c80159fa0f054c Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 11 Jan 2017 13:48:14 -0600 Subject: [PATCH] drtio: add FIFO space request count debug API --- artiq/coredevice/drtio_dbg.py | 4 ++++ artiq/firmware/libksupport/api.rs | 1 + artiq/firmware/libksupport/rtio.rs | 6 ++++++ artiq/firmware/runtime/kernel_proto.rs | 2 ++ artiq/firmware/runtime/rtio_mgt.rs | 8 ++++++++ artiq/firmware/runtime/session.rs | 4 ++++ artiq/gateware/drtio/rt_controller.py | 6 ++++++ 7 files changed, 31 insertions(+) diff --git a/artiq/coredevice/drtio_dbg.py b/artiq/coredevice/drtio_dbg.py index 9ff06bc19..a3b8d01fe 100644 --- a/artiq/coredevice/drtio_dbg.py +++ b/artiq/coredevice/drtio_dbg.py @@ -20,3 +20,7 @@ def drtio_get_fifo_space(channel: TInt32) -> TNone: @syscall(flags={"nounwind", "nowrite"}) def drtio_get_packet_counts() -> TTuple([TInt32, TInt32]): raise NotImplementedError("syscall not simulated") + +@syscall(flags={"nounwind", "nowrite"}) +def drtio_get_fifo_space_req_count() -> TInt32: + raise NotImplementedError("syscall not simulated") diff --git a/artiq/firmware/libksupport/api.rs b/artiq/firmware/libksupport/api.rs index c987de59a..43e44e032 100644 --- a/artiq/firmware/libksupport/api.rs +++ b/artiq/firmware/libksupport/api.rs @@ -110,6 +110,7 @@ static mut API: &'static [(&'static str, *const ())] = &[ 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!(drtio_get_fifo_space_req_count = ::rtio::drtio_dbg::get_fifo_space_req_count), api!(i2c_start = ::i2c_start), api!(i2c_stop = ::i2c_stop), diff --git a/artiq/firmware/libksupport/rtio.rs b/artiq/firmware/libksupport/rtio.rs index 2ba2d619f..76b05fb8a 100644 --- a/artiq/firmware/libksupport/rtio.rs +++ b/artiq/firmware/libksupport/rtio.rs @@ -215,4 +215,10 @@ pub mod drtio_dbg { recv!(&DRTIOPacketCountReply { tx_cnt, rx_cnt } => PacketCounts(tx_cnt as i32, rx_cnt as i32)) } + + pub extern fn get_fifo_space_req_count() -> i32 { + send(&DRTIOFIFOSpaceReqCountRequest); + recv!(&DRTIOFIFOSpaceReqCountReply { cnt } + => cnt as i32) + } } diff --git a/artiq/firmware/runtime/kernel_proto.rs b/artiq/firmware/runtime/kernel_proto.rs index d631a7fd5..5b3c11c34 100644 --- a/artiq/firmware/runtime/kernel_proto.rs +++ b/artiq/firmware/runtime/kernel_proto.rs @@ -38,6 +38,8 @@ pub enum Message<'a> { DRTIOGetFIFOSpaceRequest { channel: u32 }, DRTIOPacketCountRequest, DRTIOPacketCountReply { tx_cnt: u32, rx_cnt: u32 }, + DRTIOFIFOSpaceReqCountRequest, + DRTIOFIFOSpaceReqCountReply { cnt: u32 }, RunFinished, RunException { diff --git a/artiq/firmware/runtime/rtio_mgt.rs b/artiq/firmware/runtime/rtio_mgt.rs index 1184491fa..0a77be5e2 100644 --- a/artiq/firmware/runtime/rtio_mgt.rs +++ b/artiq/firmware/runtime/rtio_mgt.rs @@ -227,6 +227,12 @@ pub mod drtio_dbg { (csr::drtio::packet_cnt_tx_read(), csr::drtio::packet_cnt_rx_read()) } } + + pub fn get_fifo_space_req_count() -> u32 { + unsafe { + csr::drtio::o_dbg_fifo_space_req_cnt_read() + } + } } #[cfg(not(has_drtio))] @@ -238,4 +244,6 @@ pub mod drtio_dbg { pub fn get_fifo_space(_channel: u32) {} pub fn get_packet_counts() -> (u32, u32) { (0, 0) } + + pub fn get_fifo_space_req_count() -> u32 { 0 } } diff --git a/artiq/firmware/runtime/session.rs b/artiq/firmware/runtime/session.rs index 5168dd9dc..30cead501 100644 --- a/artiq/firmware/runtime/session.rs +++ b/artiq/firmware/runtime/session.rs @@ -401,6 +401,10 @@ fn process_kern_message(waiter: Waiter, 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::DRTIOFIFOSpaceReqCountRequest => { + let cnt = rtio_mgt::drtio_dbg::get_fifo_space_req_count(); + kern_send(waiter, &kern::DRTIOFIFOSpaceReqCountReply { cnt: cnt }) + } &kern::WatchdogSetRequest { ms } => { let id = try!(session.watchdog_set.set_ms(ms) diff --git a/artiq/gateware/drtio/rt_controller.py b/artiq/gateware/drtio/rt_controller.py index f7ae6a378..ad541a6ef 100644 --- a/artiq/gateware/drtio/rt_controller.py +++ b/artiq/gateware/drtio/rt_controller.py @@ -24,6 +24,7 @@ class _CSRs(AutoCSR): self.o_get_fifo_space = CSR() self.o_dbg_fifo_space = CSRStatus(16) self.o_dbg_last_timestamp = CSRStatus(64) + self.o_dbg_fifo_space_req_cnt = CSRStatus(32) self.o_reset_channel_status = CSR() self.o_wait = CSRStatus() self.o_fifo_space_timeout = CSR() @@ -207,6 +208,11 @@ class RTController(Module): last_timestamps.we.eq(1) ) ] + self.sync += \ + If((rt_packets.write_stb & rt_packets.write_ack & rt_packets_fifo_request), + self.csrs.o_dbg_fifo_space_req_cnt.status.eq( + self.csrs.o_dbg_fifo_space_req_cnt.status + 1) + ) def get_csrs(self): return self.csrs.get_csrs()