Skip to content

Commit

Permalink
[SC64][SW] Optimized memory usage in the sc64deployer
Browse files Browse the repository at this point in the history
  • Loading branch information
Polprzewodnikowy committed Jul 23, 2024
1 parent e9ee025 commit d8976de
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 161 deletions.
16 changes: 6 additions & 10 deletions sw/deployer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,19 +892,15 @@ fn handle_test_command(connection: Connection) -> Result<(), sc64::Error> {

println!("{}: USB", "[SC64 Tests]".bold());

print!(" Performing USB write speed test... ");
print!(" Performing USB read speed test... ");
stdout().flush().unwrap();
println!(
"{}",
format!("{:.2} MiB/s", sc64.test_usb_speed(true)?).bright_green()
);
let read_speed = sc64.test_usb_speed(sc64::SpeedTestDirection::Read)?;
println!("{}", format!("{read_speed:.2} MiB/s",).bright_green());

print!(" Performing USB read speed test... ");
print!(" Performing USB write speed test... ");
stdout().flush().unwrap();
println!(
"{}",
format!("{:.2} MiB/s", sc64.test_usb_speed(false)?).bright_green()
);
let write_speed = sc64.test_usb_speed(sc64::SpeedTestDirection::Write)?;
println!("{}", format!("{write_speed:.2} MiB/s",).bright_green());

println!("{}: SDRAM (pattern)", "[SC64 Tests]".bold());

Expand Down
45 changes: 23 additions & 22 deletions sw/deployer/src/sc64/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ impl TryFrom<u32> for DataType {
}
}

pub struct Command {
pub id: u8,
pub args: [u32; 2],
pub data: Vec<u8>,
}

pub struct Response {
pub id: u8,
pub data: Vec<u8>,
Expand Down Expand Up @@ -167,14 +161,14 @@ pub trait Backend {
}
}

fn send_command(&mut self, command: &Command) -> std::io::Result<()> {
fn send_command(&mut self, id: u8, args: [u32; 2], data: &[u8]) -> std::io::Result<()> {
self.write_all(b"CMD")?;
self.write_all(&command.id.to_be_bytes())?;
self.write_all(&id.to_be_bytes())?;

self.write_all(&command.args[0].to_be_bytes())?;
self.write_all(&command.args[1].to_be_bytes())?;
self.write_all(&args[0].to_be_bytes())?;
self.write_all(&args[1].to_be_bytes())?;

self.write_all(&command.data)?;
self.write_all(data)?;

self.flush()?;

Expand Down Expand Up @@ -332,17 +326,17 @@ impl Backend for TcpBackend {
self.stream.shutdown(std::net::Shutdown::Both).ok();
}

fn send_command(&mut self, command: &Command) -> std::io::Result<()> {
fn send_command(&mut self, id: u8, args: [u32; 2], data: &[u8]) -> std::io::Result<()> {
let payload_data_type: u32 = DataType::Command.into();
self.write_all(&payload_data_type.to_be_bytes())?;

self.write_all(&command.id.to_be_bytes())?;
self.write_all(&command.args[0].to_be_bytes())?;
self.write_all(&command.args[1].to_be_bytes())?;
self.write_all(&id.to_be_bytes())?;
self.write_all(&args[0].to_be_bytes())?;
self.write_all(&args[1].to_be_bytes())?;

let command_data_length = command.data.len() as u32;
let command_data_length = data.len() as u32;
self.write_all(&command_data_length.to_be_bytes())?;
self.write_all(&command.data)?;
self.write_all(data)?;

self.flush()?;

Expand Down Expand Up @@ -445,22 +439,29 @@ pub struct Link {
}

impl Link {
pub fn execute_command(&mut self, command: &Command) -> Result<Vec<u8>, Error> {
self.execute_command_raw(command, false, false)
pub fn execute_command(
&mut self,
id: u8,
args: [u32; 2],
data: &[u8],
) -> Result<Vec<u8>, Error> {
self.execute_command_raw(id, args, data, false, false)
}

pub fn execute_command_raw(
&mut self,
command: &Command,
id: u8,
args: [u32; 2],
data: &[u8],
no_response: bool,
ignore_error: bool,
) -> Result<Vec<u8>, Error> {
self.backend.send_command(command)?;
self.backend.send_command(id, args, data)?;
if no_response {
return Ok(vec![]);
}
let response = self.receive_response()?;
if command.id != response.id {
if id != response.id {
return Err(Error::new("Command response ID didn't match"));
}
if !ignore_error && response.error {
Expand Down
Loading

0 comments on commit d8976de

Please sign in to comment.