aboutsummaryrefslogtreecommitdiff
path: root/src/bus.rs
diff options
context:
space:
mode:
authorkbleeke <[email protected]>2023-03-21 19:26:01 +0100
committerkbleeke <[email protected]>2023-03-21 19:26:24 +0100
commit3034e8fb458cae0ff84d1ca07b4a64bced815f0c (patch)
tree0b95bc5a05d7d48e1ba8d1629d093f6d76d19648 /src/bus.rs
parentb4b8d829801e149c90f9f0fc85736be3549dff87 (diff)
document response delay quirks in bus code
Diffstat (limited to 'src/bus.rs')
-rw-r--r--src/bus.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/bus.rs b/src/bus.rs
index 90990f35a..262b9e0d4 100644
--- a/src/bus.rs
+++ b/src/bus.rs
@@ -16,7 +16,8 @@ pub trait SpiBusCyw43 {
16 /// Issues a read command on the bus 16 /// Issues a read command on the bus
17 /// `write` is expected to be a 32 bit cmd word 17 /// `write` is expected to be a 32 bit cmd word
18 /// `read` will contain the response of the device 18 /// `read` will contain the response of the device
19 /// 19 /// Backplane reads have a response delay that produces one extra unspecified word at the beginning of `read`.
20 /// Callers that want to read `n` word from the backplane, have to provide a slice that is `n+1` words long.
20 async fn cmd_read(&mut self, write: u32, read: &mut [u32]); 21 async fn cmd_read(&mut self, write: u32, read: &mut [u32]);
21} 22}
22 23
@@ -108,6 +109,7 @@ where
108 // To simplify, enforce 4-align for now. 109 // To simplify, enforce 4-align for now.
109 assert!(addr % 4 == 0); 110 assert!(addr % 4 == 0);
110 111
112 // Backplane read buffer has one extra word for the response delay.
111 let mut buf = [0u32; BACKPLANE_MAX_TRANSFER_SIZE / 4 + 1]; 113 let mut buf = [0u32; BACKPLANE_MAX_TRANSFER_SIZE / 4 + 1];
112 114
113 while !data.is_empty() { 115 while !data.is_empty() {
@@ -121,8 +123,10 @@ where
121 123
122 let cmd = cmd_word(READ, INC_ADDR, FUNC_BACKPLANE, window_offs, len as u32); 124 let cmd = cmd_word(READ, INC_ADDR, FUNC_BACKPLANE, window_offs, len as u32);
123 125
126 // round `buf` to word boundary, add one extra word for the response delay
124 self.spi.cmd_read(cmd, &mut buf[..(len + 3) / 4 + 1]).await; 127 self.spi.cmd_read(cmd, &mut buf[..(len + 3) / 4 + 1]).await;
125 128
129 // when writing out the data, we skip the response-delay byte
126 data[..len].copy_from_slice(&slice8_mut(&mut buf[1..])[..len]); 130 data[..len].copy_from_slice(&slice8_mut(&mut buf[1..])[..len]);
127 131
128 // Advance ptr. 132 // Advance ptr.
@@ -266,10 +270,12 @@ where
266 async fn readn(&mut self, func: u32, addr: u32, len: u32) -> u32 { 270 async fn readn(&mut self, func: u32, addr: u32, len: u32) -> u32 {
267 let cmd = cmd_word(READ, INC_ADDR, func, addr, len); 271 let cmd = cmd_word(READ, INC_ADDR, func, addr, len);
268 let mut buf = [0; 2]; 272 let mut buf = [0; 2];
273 // if we are reading from the backplane, we need an extra word for the response delay
269 let len = if func == FUNC_BACKPLANE { 2 } else { 1 }; 274 let len = if func == FUNC_BACKPLANE { 2 } else { 1 };
270 275
271 self.spi.cmd_read(cmd, &mut buf[..len]).await; 276 self.spi.cmd_read(cmd, &mut buf[..len]).await;
272 277
278 // if we read from the backplane, the result is in the second word, after the response delay
273 if func == FUNC_BACKPLANE { 279 if func == FUNC_BACKPLANE {
274 buf[1] 280 buf[1]
275 } else { 281 } else {