From a87208effed882439aa18c41cf8e9da32022dcd2 Mon Sep 17 00:00:00 2001 From: morgan Date: Thu, 12 Sep 2024 16:54:17 +0800 Subject: [PATCH] proto fw: add rx downconn debug in --- src/libboard_artiq/src/cxp_proto.rs | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/libboard_artiq/src/cxp_proto.rs b/src/libboard_artiq/src/cxp_proto.rs index 8f4898e..58b82fb 100644 --- a/src/libboard_artiq/src/cxp_proto.rs +++ b/src/libboard_artiq/src/cxp_proto.rs @@ -191,3 +191,48 @@ pub fn print_packet(pak: &[u8]) { println!("]"); println!("============================================"); } + +pub fn downconn_debug_main() { + downconn_debug_send(&Packet::CtrlRead { + addr: 0x00, + length: 0x04, + }); + + const LEN: usize = 100; + let mut pak_arr: [u32; LEN] = [0; LEN]; + let mut i: usize = 0; + unsafe { + while csr::cxp::downconn_debug_out_dout_valid_read() == 1 { + pak_arr[i] = csr::cxp::downconn_debug_out_dout_pak_read(); + // println!("received {:#04X}", pak_arr[i]); + csr::cxp::downconn_debug_out_inc_write(1); + i += 1; + if i == LEN { + break; + } + } + } + + // TODO: turn the u32 slice back to u8 + + println!("{:#010X?}", pak_arr) +} + +pub fn downconn_debug_send(packet: &Packet) -> Result<(), Error> { + let mut buffer: [u8; MAX_PACKET] = [0; MAX_PACKET]; + let mut writer = Cursor::new(&mut buffer[..]); + + packet.write_to(&mut writer)?; + + unsafe { + let len = writer.position(); + csr::cxp::downconn_debug_src_len_write(len as u8); + for data in writer.get_ref()[..len].iter() { + while csr::cxp::downconn_debug_src_writeable_read() == 0 {} + csr::cxp::upconn_command_data_write(*data); + csr::cxp::downconn_debug_src_data_write(*data); + } + } + + Ok(()) +}