satman: log drtio packets, display on connection break

This commit is contained in:
mwojcik 2024-11-25 16:21:06 +08:00
parent 2c633409b8
commit 5969e34e7a
4 changed files with 36 additions and 2 deletions

View File

@ -5,10 +5,15 @@ use crc;
use io::{proto::{ProtoRead, ProtoWrite}, use io::{proto::{ProtoRead, ProtoWrite},
Cursor}; Cursor};
use libboard_zynq::{time::Milliseconds, timer::GlobalTimer}; use libboard_zynq::{time::Milliseconds, timer::GlobalTimer};
use log::info;
pub use crate::drtioaux_proto::Packet; pub use crate::drtioaux_proto::Packet;
use crate::{drtioaux_proto::Error as ProtocolError, mem::mem::DRTIOAUX_MEM, pl::csr::DRTIOAUX}; use crate::{drtioaux_proto::Error as ProtocolError, mem::mem::DRTIOAUX_MEM, pl::csr::DRTIOAUX};
const DRTIO_LOG_N: usize = 2048;
static mut DRTIO_LOG: [(bool, u8, Packet); DRTIO_LOG_N] = [(false, 255, Packet::EchoRequest); DRTIO_LOG_N];
static mut DRTIO_LOG_I: usize = 0;
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
GatewareError, GatewareError,
@ -93,6 +98,10 @@ pub fn recv(linkno: u8) -> Result<Option<Packet>, Error> {
if reader.read_u32()? != checksum { if reader.read_u32()? != checksum {
return Err(Error::CorruptedPacket); return Err(Error::CorruptedPacket);
} }
unsafe {
DRTIO_LOG[DRTIO_LOG_I] = (false, linkno, packet.clone());
DRTIO_LOG_I = (DRTIO_LOG_I + 1) % 2048;
}
Ok(packet) Ok(packet)
}) })
} }
@ -125,7 +134,10 @@ where F: FnOnce(&mut [u8]) -> Result<usize, Error> {
pub fn send(linkno: u8, packet: &Packet) -> Result<(), Error> { pub fn send(linkno: u8, packet: &Packet) -> Result<(), Error> {
transmit(linkno, |buffer| { transmit(linkno, |buffer| {
let mut writer = Cursor::new(buffer); let mut writer = Cursor::new(buffer);
unsafe {
DRTIO_LOG[DRTIO_LOG_I] = (true, linkno, packet.clone());
DRTIO_LOG_I = (DRTIO_LOG_I + 1) % 2048;
}
packet.write_to(&mut writer)?; packet.write_to(&mut writer)?;
// Pad till offset 4, insert checksum there // Pad till offset 4, insert checksum there
@ -140,3 +152,23 @@ pub fn send(linkno: u8, packet: &Packet) -> Result<(), Error> {
Ok(writer.position()) Ok(writer.position())
}) })
} }
pub fn log_readout() {
unsafe {
DRTIO_LOG_I = 0;
for i in 0..DRTIO_LOG_N {
let (send, linkno, packet) = &DRTIO_LOG[i];
if *linkno == 255 {
break;
}
if *send {
info!("<-{}- {:?}", *linkno, packet);
} else {
info!("-{}-> {:?}", *linkno, packet);
}
DRTIO_LOG[i] = (false, 255, Packet::EchoRequest);
}
}
}

View File

@ -61,7 +61,7 @@ impl PayloadStatus {
} }
} }
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug, Clone)]
pub enum Packet { pub enum Packet {
EchoRequest, EchoRequest,
EchoReply, EchoReply,

View File

@ -2,6 +2,7 @@
#![feature(never_type)] #![feature(never_type)]
#![feature(naked_functions)] #![feature(naked_functions)]
#![feature(asm)] #![feature(asm)]
#![feature(const_in_array_repeat_expressions)]
extern crate core_io; extern crate core_io;
extern crate crc; extern crate crc;

View File

@ -1408,6 +1408,7 @@ pub extern "C" fn main_core0() -> i32 {
si5324::siphaser::select_recovered_clock(&mut i2c, false, &mut timer).expect("failed to switch clocks"); si5324::siphaser::select_recovered_clock(&mut i2c, false, &mut timer).expect("failed to switch clocks");
#[cfg(has_wrpll)] #[cfg(has_wrpll)]
si549::wrpll::select_recovered_clock(false, &mut timer); si549::wrpll::select_recovered_clock(false, &mut timer);
drtioaux::log_readout();
} }
} }