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