From 960864c84762a700d5eb099bb2f58b0bae38298f Mon Sep 17 00:00:00 2001 From: occheung Date: Wed, 28 Aug 2024 13:35:18 +0800 Subject: [PATCH] drtio-proto: add coremgmt-over-drtio messages --- src/libboard_artiq/src/drtioaux_proto.rs | 225 +++++++++++++++++++++++ 1 file changed, 225 insertions(+) diff --git a/src/libboard_artiq/src/drtioaux_proto.rs b/src/libboard_artiq/src/drtioaux_proto.rs index acea1d72..11e9cea4 100644 --- a/src/libboard_artiq/src/drtioaux_proto.rs +++ b/src/libboard_artiq/src/drtioaux_proto.rs @@ -288,6 +288,62 @@ pub enum Packet { SubkernelMessageAck { destination: u8, }, + + CoreMgmtGetLogRequest { + destination: u8, + clear: bool, + }, + CoreMgmtClearLogRequest { + destination: u8, + }, + CoreMgmtSetLogLevelRequest { + destination: u8, + log_level: u8, + }, + CoreMgmtSetUartLogLevelRequest { + destination: u8, + log_level: u8, + }, + CoreMgmtConfigReadRequest { + destination: u8, + length: u16, + key: [u8; MASTER_PAYLOAD_MAX_SIZE], + }, + CoreMgmtConfigReadContinue { + destination: u8, + }, + CoreMgmtConfigWriteRequest { + destination: u8, + last: bool, + length: u16, + data: [u8; MASTER_PAYLOAD_MAX_SIZE], + }, + CoreMgmtConfigRemoveRequest { + destination: u8, + length: u16, + key: [u8; MASTER_PAYLOAD_MAX_SIZE], + }, + CoreMgmtConfigEraseRequest { + destination: u8, + }, + CoreMgmtRebootRequest { + destination: u8, + }, + CoreMgmtAllocatorDebugRequest { + destination: u8, + }, + CoreMgmtGetLogReply { + last: bool, + length: u16, + data: [u8; SAT_PAYLOAD_MAX_SIZE], + }, + CoreMgmtConfigReadReply { + last: bool, + length: u16, + value: [u8; SAT_PAYLOAD_MAX_SIZE], + }, + CoreMgmtAck, + CoreMgmtNack, } impl Packet { @@ -565,6 +621,93 @@ impl Packet { destination: reader.read_u8()?, }, + 0xd0 => Packet::CoreMgmtGetLogRequest { + destination: reader.read_u8()?, + clear: reader.read_bool()?, + }, + 0xd1 => Packet::CoreMgmtClearLogRequest { + destination: reader.read_u8()?, + }, + 0xd2 => Packet::CoreMgmtSetLogLevelRequest { + destination: reader.read_u8()?, + log_level: reader.read_u8()?, + }, + 0xd3 => Packet::CoreMgmtSetUartLogLevelRequest { + destination: reader.read_u8()?, + log_level: reader.read_u8()?, + }, + 0xd4 => { + let destination = reader.read_u8()?; + let length = reader.read_u16()?; + let mut key: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE]; + reader.read_exact(&mut key[0..length as usize])?; + Packet::CoreMgmtConfigReadRequest { + destination: destination, + length: length, + key: key, + } + } + 0xd5 => Packet::CoreMgmtConfigReadContinue { + destination: reader.read_u8()?, + }, + 0xd6 => { + let destination = reader.read_u8()?; + let last = reader.read_bool()?; + let length = reader.read_u16()?; + let mut data: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE]; + reader.read_exact(&mut data[0..length as usize])?; + Packet::CoreMgmtConfigWriteRequest { + destination: destination, + last: last, + length: length, + data: data, + } + } + 0xd7 => { + let destination = reader.read_u8()?; + let length = reader.read_u16()?; + let mut key: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE]; + reader.read_exact(&mut key[0..length as usize])?; + Packet::CoreMgmtConfigRemoveRequest { + destination: destination, + length: length, + key: key, + } + } + 0xd8 => Packet::CoreMgmtConfigEraseRequest { + destination: reader.read_u8()?, + }, + 0xd9 => Packet::CoreMgmtRebootRequest { + destination: reader.read_u8()?, + }, + 0xda => Packet::CoreMgmtAllocatorDebugRequest { + destination: reader.read_u8()?, + }, + 0xdb => { + let last = reader.read_bool()?; + let length = reader.read_u16()?; + let mut data: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE]; + reader.read_exact(&mut data[0..length as usize])?; + Packet::CoreMgmtGetLogReply { + last: last, + length: length, + data: data, + } + } + 0xdc => { + let last = reader.read_bool()?; + let length = reader.read_u16()?; + let mut value: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE]; + reader.read_exact(&mut value[0..length as usize])?; + Packet::CoreMgmtConfigReadReply { + last: last, + length: length, + value: value, + } + } + 0xdd => Packet::CoreMgmtAck, + 0xde => Packet::CoreMgmtNack, + ty => return Err(Error::UnknownPacket(ty)), }) } @@ -942,6 +1085,88 @@ impl Packet { writer.write_u8(0xcc)?; writer.write_u8(destination)?; } + + Packet::CoreMgmtGetLogRequest { destination, clear } => { + writer.write_u8(0xd0)?; + writer.write_u8(destination)?; + writer.write_bool(clear)?; + } + Packet::CoreMgmtClearLogRequest { destination } => { + writer.write_u8(0xd1)?; + writer.write_u8(destination)?; + } + Packet::CoreMgmtSetLogLevelRequest { destination, log_level } => { + writer.write_u8(0xd2)?; + writer.write_u8(destination)?; + writer.write_u8(log_level)?; + } + Packet::CoreMgmtSetUartLogLevelRequest { destination, log_level } => { + writer.write_u8(0xd3)?; + writer.write_u8(destination)?; + writer.write_u8(log_level)?; + } + Packet::CoreMgmtConfigReadRequest { + destination, + length, + key, + } => { + writer.write_u8(0xd4)?; + writer.write_u8(destination)?; + writer.write_u16(length)?; + writer.write_all(&key[0..length as usize])?; + } + Packet::CoreMgmtConfigReadContinue { destination } => { + writer.write_u8(0xd5)?; + writer.write_u8(destination)?; + } + Packet::CoreMgmtConfigWriteRequest { + destination, + last, + length, + data, + } => { + writer.write_u8(0xd6)?; + writer.write_u8(destination)?; + writer.write_bool(last)?; + writer.write_u16(length)?; + writer.write_all(&data[0..length as usize])?; + } + Packet::CoreMgmtConfigRemoveRequest { + destination, + length, + key, + } => { + writer.write_u8(0xd7)?; + writer.write_u8(destination)?; + writer.write_u16(length)?; + writer.write_all(&key[0..length as usize])?; + } + Packet::CoreMgmtConfigEraseRequest { destination } => { + writer.write_u8(0xd8)?; + writer.write_u8(destination)?; + } + Packet::CoreMgmtRebootRequest { destination } => { + writer.write_u8(0xd9)?; + writer.write_u8(destination)?; + } + Packet::CoreMgmtAllocatorDebugRequest { destination } => { + writer.write_u8(0xda)?; + writer.write_u8(destination)?; + } + Packet::CoreMgmtGetLogReply { last, length, data } => { + writer.write_u8(0xdb)?; + writer.write_bool(last)?; + writer.write_u16(length)?; + writer.write_all(&data[0..length as usize])?; + } + Packet::CoreMgmtConfigReadReply { last, length, value } => { + writer.write_u8(0xdc)?; + writer.write_bool(last)?; + writer.write_u16(length)?; + writer.write_all(&value[0..length as usize])?; + } + Packet::CoreMgmtAck => writer.write_u8(0xdd)?, + Packet::CoreMgmtNack => writer.write_u8(0xde)?, } Ok(()) }