forked from M-Labs/artiq-zynq
upconn fw: add test packet
This commit is contained in:
parent
6943a2b17e
commit
581d9ffebb
|
@ -31,14 +31,10 @@ pub fn tx_test(timer: &mut GlobalTimer) {
|
||||||
csr::cxp::upconn_clk_reset_write(0);
|
csr::cxp::upconn_clk_reset_write(0);
|
||||||
|
|
||||||
// read_u32(0x00).expect("Cannot Write CoaXpress Register");
|
// 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);
|
csr::cxp::upconn_tx_enable_write(1);
|
||||||
timer.delay_us(2); // send one word
|
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);
|
// timer.delay_us(2);
|
||||||
// DEBUG: Trigger packet
|
// DEBUG: Trigger packet
|
||||||
|
@ -48,7 +44,7 @@ pub fn tx_test(timer: &mut GlobalTimer) {
|
||||||
// csr::cxp::upconn_trig_stb_write(1); // send trig
|
// csr::cxp::upconn_trig_stb_write(1); // send trig
|
||||||
|
|
||||||
// DEBUG: Trigger ACK packet
|
// DEBUG: Trigger ACK packet
|
||||||
csr::cxp::upconn_ack_write(1);
|
// csr::cxp::upconn_ack_write(1);
|
||||||
timer.delay_us(20);
|
timer.delay_us(20);
|
||||||
csr::cxp::upconn_tx_enable_write(0);
|
csr::cxp::upconn_tx_enable_write(0);
|
||||||
|
|
||||||
|
@ -92,6 +88,7 @@ pub enum Packet {
|
||||||
EventAck {
|
EventAck {
|
||||||
packet_tag: u8,
|
packet_tag: u8,
|
||||||
},
|
},
|
||||||
|
TestPacket,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Packet {
|
impl Packet {
|
||||||
|
@ -131,6 +128,7 @@ impl Packet {
|
||||||
writer.write(&[0x08; 4])?;
|
writer.write(&[0x08; 4])?;
|
||||||
writer.write(&[packet_tag; 4])?;
|
writer.write(&[packet_tag; 4])?;
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
// Section 9.2.2.2 (CXP-001-2021)
|
// Section 9.2.2.2 (CXP-001-2021)
|
||||||
// Only Control packet need CRC32 appended in the end of the packet
|
// 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)?
|
// 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 buffer: [u8; MAX_PACKET] = [0; MAX_PACKET];
|
||||||
let mut writer = Cursor::new(&mut buffer[..]);
|
let mut writer = Cursor::new(&mut buffer[..]);
|
||||||
|
|
||||||
packet.write_to(&mut writer)?;
|
packet.write_to(&mut writer)?;
|
||||||
|
|
||||||
print_packet(&buffer);
|
unsafe {
|
||||||
|
let len = writer.position();
|
||||||
// unsafe {
|
csr::cxp::upconn_command_len_write(len as u8);
|
||||||
// let len = writer.position();
|
for data in writer.get_ref()[..len].iter() {
|
||||||
// csr::cxp::upconn_command_len_write(len as u8);
|
while csr::cxp::upconn_command_writeable_read() == 0 {}
|
||||||
// for data in writer.get_ref()[..len].iter() {
|
csr::cxp::upconn_command_data_write(*data);
|
||||||
// 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue