1
0
Fork 0

cxp upconn fw: add crc & packet type insert in fw

This commit is contained in:
morgan 2024-09-04 14:49:52 +08:00
parent 4e2d194b2c
commit 168c75eaf6
1 changed files with 14 additions and 16 deletions

View File

@ -1,4 +1,5 @@
use core_io::{Error as IoError, Read, Write};
use crc::crc32;
use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs;
use io::Cursor;
use libboard_zynq::{println, timer::GlobalTimer};
@ -139,12 +140,18 @@ impl Packet {
pub fn write_to<W>(&self, writer: &mut W) -> Result<(), IoError>
where W: Write {
match *self {
Packet::ControlWrite_u32_no_tag { addr, data, .. } => {
Packet::ControlWrite_u32_no_tag {
addr,
data,
packet_type,
} => {
writer.write(&[packet_type; 4])?;
writer.write(&[0x01, 0x00, 0x00, 0x04])?;
writer.write(&addr.to_be_bytes())?;
writer.write(&data.to_be_bytes())?;
}
Packet::ControlRead_u32_no_tag { addr, .. } => {
Packet::ControlRead_u32_no_tag { addr, packet_type } => {
writer.write(&[packet_type; 4])?;
writer.write(&[0x00, 0x00, 0x00, 0x04])?;
writer.write(&addr.to_be_bytes())?;
}
@ -170,28 +177,19 @@ pub fn send(packet: &Packet) -> Result<(), IoError> {
// writer.write_u8(0)?;
// }
// let checksum = crc::crc32::checksum_ieee(&writer.get_ref()[0..writer.position()]);
// writer.write_u32(checksum)?;
// Section 9.2.2.2 (CXP-001-2021)
// CoaXpress use the polynomial of IEEE-802.3 (Ethernet) CRC but the checksum calculation is different
// Also, the calculation does not include the first 4 bytes of packet_type
// let mut res: [u8; LEN] = [0; LEN];
// res.clone_from_slice(&mut write);
let checksum = crc32::checksum_ieee(&writer.get_ref()[4..writer.position()]);
writer.write(&(!checksum).to_le_bytes())?;
unsafe {
let len = writer.position();
csr::cxp::upconn_command_din_len_write(len as u8);
match *packet {
Packet::ControlWrite_u32_no_tag { packet_type, .. }
| Packet::ControlRead_u32_no_tag { packet_type, .. } => {
csr::cxp::upconn_command_packet_type_write(packet_type);
}
_ => {
println!("packet_type is not inserted!!!!");
}
}
for data in writer.get_ref()[..len].iter() {
while csr::cxp::upconn_command_din_ready_read() == 0 {}
csr::cxp::upconn_command_din_data_write(*data);
println!("{:#04X}", *data);
}
}