Fixed length for wlan_read.

The length provided in command word for FUNC_WLAN READ, should
describe the actual bytes requested, not the size of the buffer
which is sized in u32.
This commit is contained in:
Mattias Grönlund 2022-12-31 16:25:37 +01:00
parent 1b6799d93f
commit 871700f05d
2 changed files with 5 additions and 4 deletions

View File

@ -48,11 +48,12 @@ where
assert_eq!(val, TEST_PATTERN); assert_eq!(val, TEST_PATTERN);
} }
pub async fn wlan_read(&mut self, buf: &mut [u32]) { pub async fn wlan_read(&mut self, buf: &mut [u32], len_in_u8: u32) {
let cmd = cmd_word(READ, INC_ADDR, FUNC_WLAN, 0, buf.len() as u32 * 4); let cmd = cmd_word(READ, INC_ADDR, FUNC_WLAN, 0, len_in_u8);
let len_in_u32 = (len_in_u8 as usize + 3) / 4;
transaction!(&mut self.spi, |bus| async { transaction!(&mut self.spi, |bus| async {
bus.write(&[cmd]).await?; bus.write(&[cmd]).await?;
bus.read(buf).await?; bus.read(&mut buf[..len_in_u32]).await?;
Ok(()) Ok(())
}) })
.await .await

View File

@ -687,7 +687,7 @@ where
if status & STATUS_F2_PKT_AVAILABLE != 0 { if status & STATUS_F2_PKT_AVAILABLE != 0 {
let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT; let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT;
self.bus.wlan_read(&mut buf[..(len as usize + 3) / 4]).await; self.bus.wlan_read(&mut buf, len).await;
trace!("rx {:02x}", &slice8_mut(&mut buf)[..(len as usize).min(48)]); trace!("rx {:02x}", &slice8_mut(&mut buf)[..(len as usize).min(48)]);
self.rx(&slice8_mut(&mut buf)[..len as usize]); self.rx(&slice8_mut(&mut buf)[..len as usize]);
} }