forked from M-Labs/artiq-zynq
cxp upconn fw: add crc & packet type insert in fw
This commit is contained in:
parent
4e2d194b2c
commit
168c75eaf6
|
@ -1,4 +1,5 @@
|
||||||
use core_io::{Error as IoError, Read, Write};
|
use core_io::{Error as IoError, Read, Write};
|
||||||
|
use crc::crc32;
|
||||||
use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs;
|
use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs;
|
||||||
use io::Cursor;
|
use io::Cursor;
|
||||||
use libboard_zynq::{println, timer::GlobalTimer};
|
use libboard_zynq::{println, timer::GlobalTimer};
|
||||||
|
@ -139,12 +140,18 @@ impl Packet {
|
||||||
pub fn write_to<W>(&self, writer: &mut W) -> Result<(), IoError>
|
pub fn write_to<W>(&self, writer: &mut W) -> Result<(), IoError>
|
||||||
where W: Write {
|
where W: Write {
|
||||||
match *self {
|
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(&[0x01, 0x00, 0x00, 0x04])?;
|
||||||
writer.write(&addr.to_be_bytes())?;
|
writer.write(&addr.to_be_bytes())?;
|
||||||
writer.write(&data.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(&[0x00, 0x00, 0x00, 0x04])?;
|
||||||
writer.write(&addr.to_be_bytes())?;
|
writer.write(&addr.to_be_bytes())?;
|
||||||
}
|
}
|
||||||
|
@ -170,28 +177,19 @@ pub fn send(packet: &Packet) -> Result<(), IoError> {
|
||||||
// writer.write_u8(0)?;
|
// writer.write_u8(0)?;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// let checksum = crc::crc32::checksum_ieee(&writer.get_ref()[0..writer.position()]);
|
// Section 9.2.2.2 (CXP-001-2021)
|
||||||
// writer.write_u32(checksum)?;
|
// 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];
|
let checksum = crc32::checksum_ieee(&writer.get_ref()[4..writer.position()]);
|
||||||
// res.clone_from_slice(&mut write);
|
writer.write(&(!checksum).to_le_bytes())?;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let len = writer.position();
|
let len = writer.position();
|
||||||
csr::cxp::upconn_command_din_len_write(len as u8);
|
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() {
|
for data in writer.get_ref()[..len].iter() {
|
||||||
while csr::cxp::upconn_command_din_ready_read() == 0 {}
|
while csr::cxp::upconn_command_din_ready_read() == 0 {}
|
||||||
csr::cxp::upconn_command_din_data_write(*data);
|
csr::cxp::upconn_command_din_data_write(*data);
|
||||||
println!("{:#04X}", *data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue