From 56b50f8b62024ba5bfccfa69381e6d98f8b108b5 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 25 Dec 2022 22:02:20 +0100 Subject: [PATCH] fix bp_read. It was broken since the switch from u8 to u32. --- src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ba8acd347..8e30522be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1071,13 +1071,15 @@ where } #[allow(unused)] - async fn bp_read(&mut self, mut addr: u32, mut data: &mut [u32]) { + async fn bp_read(&mut self, mut addr: u32, mut data: &mut [u8]) { // It seems the HW force-aligns the addr // to 2 if data.len() >= 2 // to 4 if data.len() >= 4 // To simplify, enforce 4-align for now. assert!(addr % 4 == 0); + let mut buf = [0u32; BACKPLANE_MAX_TRANSFER_SIZE / 4]; + while !data.is_empty() { // Ensure transfer doesn't cross a window boundary. let window_offs = addr & BACKPLANE_ADDRESS_MASK; @@ -1097,15 +1099,17 @@ where bus.read(&mut junk).await?; // Read data - bus.read(&mut data[..len / 4]).await?; + bus.read(&mut buf[..(len + 3) / 4]).await?; Ok(()) }) .await .unwrap(); + data[..len].copy_from_slice(&slice8_mut(&mut buf)[..len]); + // Advance ptr. addr += len as u32; - data = &mut data[len / 4..]; + data = &mut data[len..]; } }