Compare commits

...

7 Commits

5 changed files with 151 additions and 183 deletions

View File

@ -8,11 +8,6 @@ const MAX_PACKET: usize = 1024;
pub const SAT_PAYLOAD_MAX_SIZE: usize = /*max size*/MAX_PACKET - /*CRC*/4 - /*packet ID*/1 - /*last*/1 - /*length*/2; pub const SAT_PAYLOAD_MAX_SIZE: usize = /*max size*/MAX_PACKET - /*CRC*/4 - /*packet ID*/1 - /*last*/1 - /*length*/2;
// used by DDMA, subkernel program data (need to provide extra ID and destination) // used by DDMA, subkernel program data (need to provide extra ID and destination)
pub const MASTER_PAYLOAD_MAX_SIZE: usize = SAT_PAYLOAD_MAX_SIZE - /*source*/1 - /*destination*/1 - /*ID*/4; pub const MASTER_PAYLOAD_MAX_SIZE: usize = SAT_PAYLOAD_MAX_SIZE - /*source*/1 - /*destination*/1 - /*ID*/4;
// used by core device management, core_mgmt packet
// FIXME: packet size
pub const CORE_MGMT_PAYLOAD_MAX_SIZE: usize = MASTER_PAYLOAD_MAX_SIZE;
// pub const CORE_MGMT_CONFIG_MAX_SIZE: usize = /*max size*/MAX_PACKET - /*destination*/1 - /*last*/1 - /*length*/2;
pub const CORE_MGMT_CONFIG_MAX_SIZE: usize = MASTER_PAYLOAD_MAX_SIZE;
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
@ -297,11 +292,6 @@ pub enum Packet {
destination: u8, destination: u8,
clear: bool, clear: bool,
}, },
CoreMgmtGetLogReply {
last: bool,
length: u16,
data: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE],
},
CoreMgmtClearLogRequest { CoreMgmtClearLogRequest {
destination: u8, destination: u8,
}, },
@ -316,27 +306,21 @@ pub enum Packet {
CoreMgmtConfigReadRequest { CoreMgmtConfigReadRequest {
destination: u8, destination: u8,
length: u16, length: u16,
key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE], key: [u8; MASTER_PAYLOAD_MAX_SIZE],
}, },
CoreMgmtConfigReadContinue { CoreMgmtConfigReadContinue {
destination: u8, destination: u8,
}, },
CoreMgmtConfigReadReply {
succeeded: bool,
length: u16,
last: bool,
value: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE],
},
CoreMgmtConfigWriteRequest { CoreMgmtConfigWriteRequest {
destination: u8, destination: u8,
length: u16,
last: bool, last: bool,
data: [u8; CORE_MGMT_CONFIG_MAX_SIZE], length: u16,
data: [u8; MASTER_PAYLOAD_MAX_SIZE],
}, },
CoreMgmtConfigRemoveRequest { CoreMgmtConfigRemoveRequest {
destination: u8, destination: u8,
length: u16, length: u16,
key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE], key: [u8; MASTER_PAYLOAD_MAX_SIZE],
}, },
CoreMgmtConfigEraseRequest { CoreMgmtConfigEraseRequest {
destination: u8, destination: u8,
@ -347,9 +331,18 @@ pub enum Packet {
CoreMgmtAllocatorDebugRequest { CoreMgmtAllocatorDebugRequest {
destination: u8, destination: u8,
}, },
CoreMgmtAck { CoreMgmtGetLogReply {
succeeded: bool, 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 { impl Packet {
@ -630,32 +623,21 @@ impl Packet {
destination: reader.read_u8()?, destination: reader.read_u8()?,
clear: reader.read_bool()?, clear: reader.read_bool()?,
}, },
0xd1 => { 0xd1 => Packet::CoreMgmtClearLogRequest {
let last = reader.read_bool()?;
let length = reader.read_u16()?;
let mut data: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
reader.read_exact(&mut data[0..length as usize])?;
Packet::CoreMgmtGetLogReply {
last: last,
length: length,
data: data,
}
}
0xd2 => Packet::CoreMgmtClearLogRequest {
destination: reader.read_u8()?, destination: reader.read_u8()?,
}, },
0xd5 => Packet::CoreMgmtSetLogLevelRequest { 0xd2 => Packet::CoreMgmtSetLogLevelRequest {
destination: reader.read_u8()?, destination: reader.read_u8()?,
log_level: reader.read_u8()?, log_level: reader.read_u8()?,
}, },
0xd6 => Packet::CoreMgmtSetUartLogLevelRequest { 0xd3 => Packet::CoreMgmtSetUartLogLevelRequest {
destination: reader.read_u8()?, destination: reader.read_u8()?,
log_level: reader.read_u8()?, log_level: reader.read_u8()?,
}, },
0xd7 => { 0xd4 => {
let destination = reader.read_u8()?; let destination = reader.read_u8()?;
let length = reader.read_u16()?; let length = reader.read_u16()?;
let mut key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; let mut key: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
reader.read_exact(&mut key[0..length as usize])?; reader.read_exact(&mut key[0..length as usize])?;
Packet::CoreMgmtConfigReadRequest { Packet::CoreMgmtConfigReadRequest {
destination: destination, destination: destination,
@ -663,36 +645,26 @@ impl Packet {
key: key, key: key,
} }
} }
0xd8 => { 0xd5 => Packet::CoreMgmtConfigReadContinue {
let succeeded = reader.read_bool()?; destination: reader.read_u8()?,
let length = reader.read_u16()?; },
let last = reader.read_bool()?; 0xd6 => {
let mut value: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
reader.read_exact(&mut value[0..length as usize])?;
Packet::CoreMgmtConfigReadReply {
succeeded: succeeded,
length: length,
last: last,
value: value,
}
}
0xd9 => {
let destination = reader.read_u8()?; let destination = reader.read_u8()?;
let length = reader.read_u16()?;
let last = reader.read_bool()?; let last = reader.read_bool()?;
let mut data: [u8; CORE_MGMT_CONFIG_MAX_SIZE] = [0; CORE_MGMT_CONFIG_MAX_SIZE]; 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])?; reader.read_exact(&mut data[0..length as usize])?;
Packet::CoreMgmtConfigWriteRequest { Packet::CoreMgmtConfigWriteRequest {
destination: destination, destination: destination,
length: length,
last: last, last: last,
length: length,
data: data, data: data,
} }
} }
0xda => { 0xd7 => {
let destination = reader.read_u8()?; let destination = reader.read_u8()?;
let length = reader.read_u16()?; let length = reader.read_u16()?;
let mut key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; let mut key: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
reader.read_exact(&mut key[0..length as usize])?; reader.read_exact(&mut key[0..length as usize])?;
Packet::CoreMgmtConfigRemoveRequest { Packet::CoreMgmtConfigRemoveRequest {
destination: destination, destination: destination,
@ -700,21 +672,39 @@ impl Packet {
key: key, key: key,
} }
} }
0xdb => Packet::CoreMgmtConfigEraseRequest { 0xd8 => Packet::CoreMgmtConfigEraseRequest {
destination: reader.read_u8()?, destination: reader.read_u8()?,
}, },
0xdc => Packet::CoreMgmtRebootRequest { 0xd9 => Packet::CoreMgmtRebootRequest {
destination: reader.read_u8()?, destination: reader.read_u8()?,
}, },
0xdd => Packet::CoreMgmtAllocatorDebugRequest { 0xda => Packet::CoreMgmtAllocatorDebugRequest {
destination: reader.read_u8()?,
},
0xde => Packet::CoreMgmtAck {
succeeded: reader.read_bool()?,
},
0xdf => Packet::CoreMgmtConfigReadContinue {
destination: reader.read_u8()?, 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)), ty => return Err(Error::UnknownPacket(ty)),
}) })
@ -1091,28 +1081,23 @@ impl Packet {
writer.write_u8(0xcc)?; writer.write_u8(0xcc)?;
writer.write_u8(destination)?; writer.write_u8(destination)?;
} }
Packet::CoreMgmtGetLogRequest { destination, clear } => { Packet::CoreMgmtGetLogRequest { destination, clear } => {
writer.write_u8(0xd0)?; writer.write_u8(0xd0)?;
writer.write_u8(destination)?; writer.write_u8(destination)?;
writer.write_bool(clear)?; writer.write_bool(clear)?;
} }
Packet::CoreMgmtGetLogReply { last, length, data } => {
writer.write_u8(0xd1)?;
writer.write_bool(last)?;
writer.write_u16(length)?;
writer.write_all(&data[0..length as usize])?;
}
Packet::CoreMgmtClearLogRequest { destination } => { Packet::CoreMgmtClearLogRequest { destination } => {
writer.write_u8(0xd2)?; writer.write_u8(0xd1)?;
writer.write_u8(destination)?; writer.write_u8(destination)?;
} }
Packet::CoreMgmtSetLogLevelRequest { destination, log_level } => { Packet::CoreMgmtSetLogLevelRequest { destination, log_level } => {
writer.write_u8(0xd5)?; writer.write_u8(0xd2)?;
writer.write_u8(destination)?; writer.write_u8(destination)?;
writer.write_u8(log_level)?; writer.write_u8(log_level)?;
} }
Packet::CoreMgmtSetUartLogLevelRequest { destination, log_level } => { Packet::CoreMgmtSetUartLogLevelRequest { destination, log_level } => {
writer.write_u8(0xd6)?; writer.write_u8(0xd3)?;
writer.write_u8(destination)?; writer.write_u8(destination)?;
writer.write_u8(log_level)?; writer.write_u8(log_level)?;
} }
@ -1120,66 +1105,64 @@ impl Packet {
destination, destination,
length, length,
key, 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(0xd7)?;
writer.write_u8(destination)?; writer.write_u8(destination)?;
writer.write_u16(length)?; writer.write_u16(length)?;
writer.write_all(&key[0..length as usize])?; writer.write_all(&key[0..length as usize])?;
} }
Packet::CoreMgmtConfigReadReply {
succeeded,
length,
last,
value,
} => {
writer.write_u8(0xd8)?;
writer.write_bool(succeeded)?;
writer.write_u16(length)?;
writer.write_bool(last)?;
writer.write_all(&value[0..length as usize])?;
}
Packet::CoreMgmtConfigWriteRequest {
destination,
length,
last,
data,
} => {
writer.write_u8(0xd9)?;
writer.write_u8(destination)?;
writer.write_u16(length)?;
writer.write_bool(last)?;
writer.write_all(&data[0..length as usize])?;
}
Packet::CoreMgmtConfigRemoveRequest {
destination,
length,
key,
} => {
writer.write_u8(0xda)?;
writer.write_u8(destination)?;
writer.write_u16(length)?;
writer.write_all(&key[0..length as usize])?;
}
Packet::CoreMgmtConfigEraseRequest { destination } => { Packet::CoreMgmtConfigEraseRequest { destination } => {
writer.write_u8(0xdb)?; writer.write_u8(0xd8)?;
writer.write_u8(destination)?; writer.write_u8(destination)?;
} }
Packet::CoreMgmtRebootRequest { destination } => { Packet::CoreMgmtRebootRequest { destination } => {
writer.write_u8(0xdc)?; writer.write_u8(0xd9)?;
writer.write_u8(destination)?; writer.write_u8(destination)?;
} }
Packet::CoreMgmtAllocatorDebugRequest { destination } => { Packet::CoreMgmtAllocatorDebugRequest { destination } => {
writer.write_u8(0xdd)?; writer.write_u8(0xda)?;
writer.write_u8(destination)?; writer.write_u8(destination)?;
} }
Packet::CoreMgmtAck { succeeded } => { Packet::CoreMgmtGetLogReply { last, length, data } => {
writer.write_u8(0xde)?; writer.write_u8(0xdb)?;
writer.write_bool(succeeded)?; writer.write_bool(last)?;
writer.write_u16(length)?;
writer.write_all(&data[0..length as usize])?;
} }
Packet::CoreMgmtConfigReadContinue { destination } => { Packet::CoreMgmtConfigReadReply { last, length, value } => {
writer.write_u8(0xdf)?; writer.write_u8(0xdc)?;
writer.write_u8(destination)?; 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(()) Ok(())
} }

View File

@ -139,7 +139,7 @@ async fn read_key(stream: &mut TcpStream) -> Result<String> {
#[cfg(has_drtio)] #[cfg(has_drtio)]
mod remote_coremgmt { mod remote_coremgmt {
use io::{Cursor, ProtoWrite}; use io::{Cursor, ProtoWrite};
use libboard_artiq::drtioaux_proto::{Packet, CORE_MGMT_PAYLOAD_MAX_SIZE}; use libboard_artiq::drtioaux_proto::{Packet, MASTER_PAYLOAD_MAX_SIZE};
use super::*; use super::*;
use crate::rtio_mgt::drtio; use crate::rtio_mgt::drtio;
@ -200,7 +200,7 @@ mod remote_coremgmt {
.await?; .await?;
match reply { match reply {
Packet::CoreMgmtAck { succeeded: true } => { Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }
@ -277,7 +277,7 @@ mod remote_coremgmt {
.await?; .await?;
match reply { match reply {
Packet::CoreMgmtAck { succeeded: true } => { Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }
@ -310,7 +310,7 @@ mod remote_coremgmt {
.await?; .await?;
match reply { match reply {
Packet::CoreMgmtAck { succeeded: true } => { Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }
@ -331,7 +331,7 @@ mod remote_coremgmt {
_cfg: &Rc<Config>, _cfg: &Rc<Config>,
key: &String, key: &String,
) -> Result<()> { ) -> Result<()> {
let mut config_key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; let mut config_key: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
let len = key.len(); let len = key.len();
config_key[..len].clone_from_slice(key.as_bytes()); config_key[..len].clone_from_slice(key.as_bytes());
@ -351,17 +351,12 @@ mod remote_coremgmt {
let mut buffer = Vec::<u8>::new(); let mut buffer = Vec::<u8>::new();
loop { loop {
match reply { match reply {
Packet::CoreMgmtConfigReadReply { Packet::CoreMgmtConfigReadReply { last, length, value } => {
succeeded: true,
length,
last,
value,
} => {
buffer.extend(&value[..length as usize]); buffer.extend(&value[..length as usize]);
if last { if last {
write_i8(stream, Reply::ConfigData as i8).await?; write_i8(stream, Reply::ConfigData as i8).await?;
write_chunk(stream, &value).await?; write_chunk(stream, &buffer).await?;
return Ok(()); return Ok(());
} }
@ -408,12 +403,12 @@ mod remote_coremgmt {
message.get_ref(), message.get_ref(),
|slice, status, len: usize| Packet::CoreMgmtConfigWriteRequest { |slice, status, len: usize| Packet::CoreMgmtConfigWriteRequest {
destination: destination, destination: destination,
length: len as u16,
last: status.is_last(), last: status.is_last(),
length: len as u16,
data: *slice, data: *slice,
}, },
|reply| match reply { |reply| match reply {
Packet::CoreMgmtAck { succeeded: true } => Ok(()), Packet::CoreMgmtAck => Ok(()),
_ => { _ => {
error!("received unknown packet"); error!("received unknown packet");
Err(drtio::Error::UnexpectedReply.into()) Err(drtio::Error::UnexpectedReply.into())
@ -443,7 +438,7 @@ mod remote_coremgmt {
_cfg: &Rc<Config>, _cfg: &Rc<Config>,
key: &String, key: &String,
) -> Result<()> { ) -> Result<()> {
let mut config_key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; let mut config_key: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
let len = key.len(); let len = key.len();
config_key[..len].clone_from_slice(key.as_bytes()); config_key[..len].clone_from_slice(key.as_bytes());
@ -461,7 +456,7 @@ mod remote_coremgmt {
.await?; .await?;
match reply { match reply {
Packet::CoreMgmtAck { succeeded: true } => { Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }
@ -492,7 +487,7 @@ mod remote_coremgmt {
.await?; .await?;
match reply { match reply {
Packet::CoreMgmtAck { succeeded: true } => { Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }
@ -524,7 +519,7 @@ mod remote_coremgmt {
.await?; .await?;
match reply { match reply {
Packet::CoreMgmtAck { succeeded: true } => { Packet::CoreMgmtAck => {
write_i8(stream, Reply::RebootImminent as i8).await?; write_i8(stream, Reply::RebootImminent as i8).await?;
Ok(()) Ok(())
} }
@ -556,7 +551,7 @@ mod remote_coremgmt {
.await?; .await?;
match reply { match reply {
Packet::CoreMgmtAck { succeeded: true } => { Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }

View File

@ -36,7 +36,7 @@ use libboard_artiq::si5324;
#[cfg(has_si549)] #[cfg(has_si549)]
use libboard_artiq::si549; use libboard_artiq::si549;
use libboard_artiq::{drtio_routing, drtioaux, use libboard_artiq::{drtio_routing, drtioaux,
drtioaux_proto::{CORE_MGMT_PAYLOAD_MAX_SIZE, MASTER_PAYLOAD_MAX_SIZE, SAT_PAYLOAD_MAX_SIZE}, drtioaux_proto::{MASTER_PAYLOAD_MAX_SIZE, SAT_PAYLOAD_MAX_SIZE},
identifier_read, logger, identifier_read, logger,
pl::csr}; pl::csr};
#[cfg(feature = "target_kasli_soc")] #[cfg(feature = "target_kasli_soc")]
@ -1030,7 +1030,7 @@ fn process_aux_packet(
&packet, &packet,
timer timer
); );
let mut data_slice: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; let mut data_slice = [0; SAT_PAYLOAD_MAX_SIZE];
let meta = core_manager.log_get_slice(&mut data_slice); let meta = core_manager.log_get_slice(&mut data_slice);
if clear && meta.status.is_first() { if clear && meta.status.is_first() {
mgmt::clear_log(); mgmt::clear_log();
@ -1058,7 +1058,7 @@ fn process_aux_packet(
timer timer
); );
mgmt::clear_log(); mgmt::clear_log();
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: true }) drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
} }
drtioaux::Packet::CoreMgmtSetLogLevelRequest { drtioaux::Packet::CoreMgmtSetLogLevelRequest {
destination: _destination, destination: _destination,
@ -1076,11 +1076,11 @@ fn process_aux_packet(
); );
if let Ok(level_filter) = mgmt::byte_to_level_filter(log_level) { if let Ok(level_filter) = mgmt::byte_to_level_filter(log_level) {
info!("Changing log level to {}", log_level); info!("Changing log level to {}", level_filter);
log::set_max_level(level_filter); log::set_max_level(level_filter);
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: true }) drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
} else { } else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: false }) drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
} }
} }
drtioaux::Packet::CoreMgmtSetUartLogLevelRequest { drtioaux::Packet::CoreMgmtSetUartLogLevelRequest {
@ -1099,16 +1099,16 @@ fn process_aux_packet(
); );
if let Ok(level_filter) = mgmt::byte_to_level_filter(log_level) { if let Ok(level_filter) = mgmt::byte_to_level_filter(log_level) {
info!("Changing log level to {}", log_level); info!("Changing log level to {}", level_filter);
unsafe { unsafe {
logger::BufferLogger::get_logger() logger::BufferLogger::get_logger()
.as_ref() .as_ref()
.unwrap() .unwrap()
.set_uart_log_level(level_filter); .set_uart_log_level(level_filter);
} }
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: true }) drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
} else { } else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: false }) drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
} }
} }
drtioaux::Packet::CoreMgmtConfigReadRequest { drtioaux::Packet::CoreMgmtConfigReadRequest {
@ -1127,20 +1127,12 @@ fn process_aux_packet(
timer timer
); );
let mut value_slice = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; let mut value_slice = [0; SAT_PAYLOAD_MAX_SIZE];
let key_slice = &key[..length as usize]; let key_slice = &key[..length as usize];
if !key_slice.is_ascii() { if !key_slice.is_ascii() {
error!("invalid key"); error!("invalid key");
drtioaux::send( drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
0,
&drtioaux::Packet::CoreMgmtConfigReadReply {
succeeded: false,
length: 0,
last: true,
value: value_slice,
},
)
} else { } else {
let key = core::str::from_utf8(key_slice).unwrap(); let key = core::str::from_utf8(key_slice).unwrap();
if core_manager.fetch_config_value(key).is_ok() { if core_manager.fetch_config_value(key).is_ok() {
@ -1148,22 +1140,13 @@ fn process_aux_packet(
drtioaux::send( drtioaux::send(
0, 0,
&drtioaux::Packet::CoreMgmtConfigReadReply { &drtioaux::Packet::CoreMgmtConfigReadReply {
succeeded: true,
length: meta.len as u16,
last: meta.status.is_last(), last: meta.status.is_last(),
length: meta.len as u16,
value: value_slice, value: value_slice,
}, },
) )
} else { } else {
drtioaux::send( drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
0,
&drtioaux::Packet::CoreMgmtConfigReadReply {
succeeded: false,
length: 0,
last: true,
value: value_slice,
},
)
} }
} }
} }
@ -1181,22 +1164,21 @@ fn process_aux_packet(
timer timer
); );
let mut value_slice = [0; CORE_MGMT_PAYLOAD_MAX_SIZE]; let mut value_slice = [0; SAT_PAYLOAD_MAX_SIZE];
let meta = core_manager.get_config_value_slice(&mut value_slice); let meta = core_manager.get_config_value_slice(&mut value_slice);
drtioaux::send( drtioaux::send(
0, 0,
&drtioaux::Packet::CoreMgmtConfigReadReply { &drtioaux::Packet::CoreMgmtConfigReadReply {
succeeded: true,
length: meta.len as u16,
last: meta.status.is_last(), last: meta.status.is_last(),
length: meta.len as u16,
value: value_slice, value: value_slice,
}, },
) )
} }
drtioaux::Packet::CoreMgmtConfigWriteRequest { drtioaux::Packet::CoreMgmtConfigWriteRequest {
destination: _destination, destination: _destination,
length,
last, last,
length,
data, data,
} => { } => {
forward!( forward!(
@ -1218,7 +1200,11 @@ fn process_aux_packet(
core_manager.clear_data(); core_manager.clear_data();
} }
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: succeeded }) if succeeded {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
} else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
}
} }
drtioaux::Packet::CoreMgmtConfigRemoveRequest { drtioaux::Packet::CoreMgmtConfigRemoveRequest {
destination: _destination, destination: _destination,
@ -1239,11 +1225,14 @@ fn process_aux_packet(
let key_slice = &key[..length as usize]; let key_slice = &key[..length as usize];
if !key_slice.is_ascii() { if !key_slice.is_ascii() {
error!("invalid key"); error!("invalid key");
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: false }) drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
} else { } else {
let key = core::str::from_utf8(key_slice).unwrap(); let key = core::str::from_utf8(key_slice).unwrap();
let succeeded = core_manager.remove_config(key).is_ok(); if core_manager.remove_config(key).is_ok() {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded }) drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
} else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
}
} }
} }
drtioaux::Packet::CoreMgmtConfigEraseRequest { drtioaux::Packet::CoreMgmtConfigEraseRequest {
@ -1278,7 +1267,7 @@ fn process_aux_packet(
timer timer
); );
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck { succeeded: true })?; drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)?;
info!("reboot imminent"); info!("reboot imminent");
slcr::reboot(); slcr::reboot();
Ok(()) Ok(())

View File

@ -1,7 +1,7 @@
use alloc::vec::Vec; use alloc::vec::Vec;
use io::{Cursor, ProtoRead, ProtoWrite}; use io::{Cursor, ProtoRead, ProtoWrite};
use libboard_artiq::{drtioaux_proto::CORE_MGMT_PAYLOAD_MAX_SIZE, use libboard_artiq::{drtioaux_proto::SAT_PAYLOAD_MAX_SIZE,
logger::{BufferLogger, LogBufferRef}}; logger::{BufferLogger, LogBufferRef}};
use libconfig::Config; use libconfig::Config;
use log::{self, debug, error, info, warn, LevelFilter}; use log::{self, debug, error, info, warn, LevelFilter};
@ -60,13 +60,13 @@ impl<'a> Manager<'_> {
} }
} }
pub fn log_get_slice(&mut self, data_slice: &mut [u8; CORE_MGMT_PAYLOAD_MAX_SIZE]) -> SliceMeta { pub fn log_get_slice(&mut self, data_slice: &mut [u8; SAT_PAYLOAD_MAX_SIZE]) -> SliceMeta {
// Populate buffer if depleted // Populate buffer if depleted
if self.last_log.at_end() { if self.last_log.at_end() {
self.last_log.extend(get_logger_buffer().extract().as_bytes()); self.last_log.extend(get_logger_buffer().extract().as_bytes());
} }
self.last_log.get_slice_core_mgmt(data_slice) self.last_log.get_slice_satellite(data_slice)
} }
pub fn fetch_config_value(&mut self, key: &str) -> Result<()> { pub fn fetch_config_value(&mut self, key: &str) -> Result<()> {
@ -79,8 +79,8 @@ impl<'a> Manager<'_> {
.map_err(|_| warn!("read error: no such key")) .map_err(|_| warn!("read error: no such key"))
} }
pub fn get_config_value_slice(&mut self, data_slice: &mut [u8; CORE_MGMT_PAYLOAD_MAX_SIZE]) -> SliceMeta { pub fn get_config_value_slice(&mut self, data_slice: &mut [u8; SAT_PAYLOAD_MAX_SIZE]) -> SliceMeta {
self.last_value.get_slice_core_mgmt(data_slice) self.last_value.get_slice_satellite(data_slice)
} }
pub fn add_data(&mut self, data: &[u8], data_len: usize) { pub fn add_data(&mut self, data: &[u8], data_len: usize) {
@ -97,6 +97,7 @@ impl<'a> Manager<'_> {
.current_payload .current_payload
.read_string() .read_string()
.map_err(|_err| error!("error on reading key"))?; .map_err(|_err| error!("error on reading key"))?;
debug!("write key: {}", key);
let value = self.current_payload.read_bytes().unwrap(); let value = self.current_payload.read_bytes().unwrap();
self.cfg self.cfg

View File

@ -4,7 +4,7 @@ use core::cmp::min;
#[cfg(has_drtio_routing)] #[cfg(has_drtio_routing)]
use libboard_artiq::pl::csr; use libboard_artiq::pl::csr;
use libboard_artiq::{drtio_routing, drtioaux, use libboard_artiq::{drtio_routing, drtioaux,
drtioaux_proto::{PayloadStatus, CORE_MGMT_PAYLOAD_MAX_SIZE, MASTER_PAYLOAD_MAX_SIZE}}; drtioaux_proto::{PayloadStatus, MASTER_PAYLOAD_MAX_SIZE, SAT_PAYLOAD_MAX_SIZE}};
pub struct SliceMeta { pub struct SliceMeta {
pub destination: u8, pub destination: u8,
@ -58,7 +58,7 @@ impl Sliceable {
} }
get_slice_fn!(get_slice_master, MASTER_PAYLOAD_MAX_SIZE); get_slice_fn!(get_slice_master, MASTER_PAYLOAD_MAX_SIZE);
get_slice_fn!(get_slice_core_mgmt, CORE_MGMT_PAYLOAD_MAX_SIZE); get_slice_fn!(get_slice_satellite, SAT_PAYLOAD_MAX_SIZE);
} }
// Packets from downstream (further satellites) are received and routed appropriately. // Packets from downstream (further satellites) are received and routed appropriately.