1
0
Fork 0

upconn fw: add test packet

This commit is contained in:
morgan 2024-09-11 16:06:16 +08:00
parent 6943a2b17e
commit 581d9ffebb
1 changed files with 31 additions and 17 deletions

View File

@ -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(())
}