From 581d9ffebbf1113ddd749f127a74a2aab6bc63e2 Mon Sep 17 00:00:00 2001 From: morgan Date: Wed, 11 Sep 2024 16:06:16 +0800 Subject: [PATCH] upconn fw: add test packet --- src/libboard_artiq/src/cxp_upconn.rs | 48 ++++++++++++++++++---------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/src/libboard_artiq/src/cxp_upconn.rs b/src/libboard_artiq/src/cxp_upconn.rs index 7f65e76..511455f 100644 --- a/src/libboard_artiq/src/cxp_upconn.rs +++ b/src/libboard_artiq/src/cxp_upconn.rs @@ -31,14 +31,10 @@ pub fn tx_test(timer: &mut GlobalTimer) { csr::cxp::upconn_clk_reset_write(0); // read_u32(0x00).expect("Cannot Write CoaXpress Register"); - send(&Packet::EventAck { packet_tag: 0x04 }); - loop {} - - // csr::cxp::upconn_tx_testmode_en_write(1); - csr::cxp::upconn_tx_enable_write(1); timer.delay_us(2); // send one word - // csr::cxp::upconn_testseq_stb_write(1); + // send(&Packet::EventAck { packet_tag: 0x04 }).expect("Cannot send CoaXpress packet"); + send(&Packet::TestPacket).expect("Cannot send CoaXpress packet"); // timer.delay_us(2); // DEBUG: Trigger packet @@ -48,7 +44,7 @@ pub fn tx_test(timer: &mut GlobalTimer) { // csr::cxp::upconn_trig_stb_write(1); // send trig // DEBUG: Trigger ACK packet - csr::cxp::upconn_ack_write(1); + // csr::cxp::upconn_ack_write(1); timer.delay_us(20); csr::cxp::upconn_tx_enable_write(0); @@ -92,6 +88,7 @@ pub enum Packet { EventAck { packet_tag: u8, }, + TestPacket, } impl Packet { @@ -131,6 +128,7 @@ impl Packet { writer.write(&[0x08; 4])?; writer.write(&[packet_tag; 4])?; } + _ => {} } // Section 9.2.2.2 (CXP-001-2021) // Only Control packet need CRC32 appended in the end of the packet @@ -156,22 +154,38 @@ pub fn send(packet: &Packet) -> Result<(), Error> { // Err(Error::LinkDown)? // } + match *packet { + Packet::TestPacket => send_test_packet(), + _ => send_data_packet(packet), + } +} + +fn send_data_packet(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)?; - print_packet(&buffer); - - // unsafe { - // let len = writer.position(); - // csr::cxp::upconn_command_len_write(len as u8); - // for data in writer.get_ref()[..len].iter() { - // while csr::cxp::upconn_command_writeable_read() == 0 {} - // csr::cxp::upconn_command_data_write(*data); - // } - // } + unsafe { + let len = writer.position(); + csr::cxp::upconn_command_len_write(len as u8); + for data in writer.get_ref()[..len].iter() { + while csr::cxp::upconn_command_writeable_read() == 0 {} + csr::cxp::upconn_command_data_write(*data); + } + } + Ok(()) +} +fn send_test_packet() -> Result<(), Error> { + unsafe { + while csr::cxp::upconn_tx_busy_read() == 1 {} + csr::cxp::upconn_tx_testmode_en_write(1); + // timer.delay_us(2); + csr::cxp::upconn_testseq_stb_write(1); + while csr::cxp::upconn_testseq_busy_read() == 1 {} + csr::cxp::upconn_tx_testmode_en_write(0); + } Ok(()) }