From b48fc06fa3f9462c5a21a60054c5322e3f09a9e8 Mon Sep 17 00:00:00 2001 From: morgan Date: Wed, 25 Sep 2024 16:59:11 +0800 Subject: [PATCH] proto FW: add memory write test proto FW: fix compilation error --- src/libboard_artiq/src/cxp_proto.rs | 38 ++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/libboard_artiq/src/cxp_proto.rs b/src/libboard_artiq/src/cxp_proto.rs index 141bb0e..a51995f 100644 --- a/src/libboard_artiq/src/cxp_proto.rs +++ b/src/libboard_artiq/src/cxp_proto.rs @@ -1,10 +1,12 @@ +use core::slice; + use core_io::{Error as IoError, Write}; use crc::crc32; use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs; use io::Cursor; use libboard_zynq::{println, timer::GlobalTimer}; -use crate::pl::csr; +use crate::{mem::mem::CXP_MEM, pl::csr}; const MAX_PACKET: usize = 128; const DATA_MAXSIZE: usize = /*max size*/MAX_PACKET - /*Tag*/4 - /*Op code & length*/4 - /*addr*/4 - /*CRC*/4 ; @@ -243,3 +245,37 @@ pub fn downconn_send_test_packet() { while csr::cxp::downconn_testseq_busy_read() == 1 {} } } + +pub fn ram_writer_send(packet: &Packet) -> Result<(), Error> { + unsafe { + // TODO: put this in mem group + while csr::cxp::transmitter_cxp_tx_read() == 1 {} + let ptr = CXP_MEM[0].base as *mut u32; + let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, 0x200 as usize)); + + packet.write_to(&mut writer)?; + + csr::cxp::transmitter_cxp_tx_word_len_write(writer.position() as u8 / 4); + csr::cxp::transmitter_cxp_tx_write(1); + while csr::cxp::transmitter_cxp_tx_read() == 1 {} + + // read the fifo + const LEN: usize = 10; + let mut pak_arr: [u32; LEN] = [0; LEN]; + let mut k_arr: [u8; LEN] = [0; LEN]; + let mut i: usize = 0; + while csr::cxp::transmitter_debug_out_dout_valid_read() == 1 { + pak_arr[i] = csr::cxp::transmitter_debug_out_dout_pak_read(); + k_arr[i] = csr::cxp::transmitter_debug_out_kout_pak_read(); + // println!("received {:#04X}", pak_arr[i]); + csr::cxp::transmitter_debug_out_inc_write(1); + i += 1; + if i == LEN { + break; + } + } + print_packetu32(&pak_arr, &k_arr); + } + + Ok(()) +}