1
0
Fork 0

proto fw: rename upconn packet

This commit is contained in:
morgan 2024-10-04 12:20:06 +08:00
parent 90fff28b84
commit 4e3193e66c
1 changed files with 19 additions and 19 deletions

View File

@ -108,7 +108,7 @@ fn capture_ctrl_packet(reader: &mut Cursor<&mut [u8]>, with_tag: bool) -> Result
} }
#[derive(Debug)] #[derive(Debug)]
pub enum Packet { pub enum UpConnPacket {
CtrlRead { CtrlRead {
addr: u32, addr: u32,
length: u8, length: u8,
@ -148,28 +148,28 @@ fn read_word(reader: &mut Cursor<&mut [u8]>) -> Result<u32, Error> {
Ok(u32::from_be_bytes(bytes)) Ok(u32::from_be_bytes(bytes))
} }
impl Packet { impl UpConnPacket {
pub fn write_to(&self, writer: &mut Cursor<&mut [u8]>) -> Result<(), Error> { pub fn write_to(&self, writer: &mut Cursor<&mut [u8]>) -> Result<(), Error> {
// CoaXpress use big endian // CoaXpress use big endian
match *self { match *self {
Packet::CtrlRead { addr, length } => { UpConnPacket::CtrlRead { addr, length } => {
writer.write(&[0x02; 4])?; writer.write(&[0x02; 4])?;
writer.write(&[0x00, 0x00, 0x00, length])?; writer.write(&[0x00, 0x00, 0x00, length])?;
writer.write(&addr.to_be_bytes())?; writer.write(&addr.to_be_bytes())?;
} }
Packet::CtrlWrite { addr, length, data } => { UpConnPacket::CtrlWrite { addr, length, data } => {
writer.write(&[0x02; 4])?; writer.write(&[0x02; 4])?;
writer.write(&[0x01, 0x00, 0x00, length])?; writer.write(&[0x01, 0x00, 0x00, length])?;
writer.write(&addr.to_be_bytes())?; writer.write(&addr.to_be_bytes())?;
writer.write(&data[0..length as usize])?; writer.write(&data[0..length as usize])?;
} }
Packet::CtrlReadWithTag { tag, addr, length } => { UpConnPacket::CtrlReadWithTag { tag, addr, length } => {
writer.write(&[0x05; 4])?; writer.write(&[0x05; 4])?;
writer.write(&[tag; 4])?; writer.write(&[tag; 4])?;
writer.write(&[0x00, 0x00, 0x00, length])?; writer.write(&[0x00, 0x00, 0x00, length])?;
writer.write(&addr.to_be_bytes())?; writer.write(&addr.to_be_bytes())?;
} }
Packet::CtrlWriteWithTag { UpConnPacket::CtrlWriteWithTag {
tag, tag,
addr, addr,
length, length,
@ -181,12 +181,12 @@ impl Packet {
writer.write(&addr.to_be_bytes())?; writer.write(&addr.to_be_bytes())?;
writer.write(&data[0..length as usize])?; writer.write(&data[0..length as usize])?;
} }
Packet::EventAck { packet_tag } => { UpConnPacket::EventAck { packet_tag } => {
writer.write(&[0x08; 4])?; writer.write(&[0x08; 4])?;
writer.write(&[packet_tag; 4])?; writer.write(&[packet_tag; 4])?;
} }
// DEBUG: Loopback message // DEBUG: Loopback message
Packet::CtrlAckLoopback { ackcode, length, data } => { UpConnPacket::CtrlAckLoopback { ackcode, length, data } => {
writer.write(&[0x03; 4])?; writer.write(&[0x03; 4])?;
writer.write(&[ackcode; 4])?; writer.write(&[ackcode; 4])?;
@ -202,10 +202,10 @@ impl Packet {
// Section 9.2.2.2 (CXP-001-2021) // Section 9.2.2.2 (CXP-001-2021)
// The crc calculation does not include the first 4 bytes of packet_type // The crc calculation does not include the first 4 bytes of packet_type
match *self { match *self {
Packet::CtrlRead { .. } UpConnPacket::CtrlRead { .. }
| Packet::CtrlWrite { .. } | UpConnPacket::CtrlWrite { .. }
| Packet::CtrlReadWithTag { .. } | UpConnPacket::CtrlReadWithTag { .. }
| Packet::CtrlWriteWithTag { .. } => { | UpConnPacket::CtrlWriteWithTag { .. } => {
writer.write(&get_cxp_crc(&writer.get_ref()[4..writer.position()]).to_be_bytes())?; writer.write(&get_cxp_crc(&writer.get_ref()[4..writer.position()]).to_be_bytes())?;
} }
_ => {} _ => {}
@ -233,18 +233,18 @@ pub fn receive(channel: usize) -> Result<(), Error> {
Ok(()) Ok(())
} }
pub fn send(channel: usize, packet: &Packet) -> Result<(), Error> { pub fn send(channel: usize, packet: &UpConnPacket) -> Result<(), Error> {
if unsafe { (CXP[channel].upconn_tx_enable_read)() } == 0 { if unsafe { (CXP[channel].upconn_tx_enable_read)() } == 0 {
Err(Error::LinkDown)? Err(Error::LinkDown)?
} }
match *packet { match *packet {
Packet::TestPacket => send_test_packet(channel), UpConnPacket::TestPacket => send_test_packet(channel),
_ => send_data_packet(channel, packet), _ => send_data_packet(channel, packet),
} }
} }
fn send_data_packet(channel: usize, packet: &Packet) -> Result<(), Error> { fn send_data_packet(channel: usize, packet: &UpConnPacket) -> Result<(), Error> {
unsafe { unsafe {
// TODO: put this in mem group // TODO: put this in mem group
while (CXP[channel].upconn_command_tx_read)() == 1 {} while (CXP[channel].upconn_command_tx_read)() == 1 {}
@ -278,7 +278,7 @@ pub fn write_u32(channel: usize, addr: u32, data: u32) -> Result<(), Error> {
data_slice[..4].clone_from_slice(&data.to_be_bytes()); data_slice[..4].clone_from_slice(&data.to_be_bytes());
send( send(
channel, channel,
&Packet::CtrlWrite { &UpConnPacket::CtrlWrite {
addr, addr,
length: 4, length: 4,
data: data_slice, data: data_slice,
@ -289,7 +289,7 @@ pub fn write_u32(channel: usize, addr: u32, data: u32) -> Result<(), Error> {
} }
pub fn read_u32(channel: usize, addr: u32) -> Result<(), Error> { pub fn read_u32(channel: usize, addr: u32) -> Result<(), Error> {
send(channel, &Packet::CtrlRead { addr, length: 4 })?; send(channel, &UpConnPacket::CtrlRead { addr, length: 4 })?;
Ok(()) Ok(())
} }
@ -299,7 +299,7 @@ pub fn write_u64(channel: usize, addr: u32, data: u64) -> Result<(), Error> {
data_slice[..8].clone_from_slice(&data.to_be_bytes()); data_slice[..8].clone_from_slice(&data.to_be_bytes());
send( send(
channel, channel,
&Packet::CtrlWrite { &UpConnPacket::CtrlWrite {
addr, addr,
length: 8, length: 8,
data: data_slice, data: data_slice,
@ -344,7 +344,7 @@ pub fn print_packetu32(pak: &[u32], k: &[u8]) {
println!("============================================"); println!("============================================");
} }
pub fn downconn_debug_send(channel: usize, packet: &Packet) -> Result<(), Error> { pub fn downconn_debug_send(channel: usize, packet: &UpConnPacket) -> Result<(), Error> {
unsafe { unsafe {
// TODO: put this in mem group // TODO: put this in mem group
while (CXP[channel].downconn_command_tx_read)() == 1 {} while (CXP[channel].downconn_command_tx_read)() == 1 {}