diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-03-27 16:08:22 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-03-27 16:08:22 +0000 |
| commit | 273e6f5b835afe9883a37814a76caba2084d6dc2 (patch) | |
| tree | 3c13c61ab4bb28e6b14bba1157df01ad335fe9ea /src/runner.rs | |
| parent | 07fe37b5ee5d5643eca4bc8db13d8bed5399cefa (diff) | |
| parent | 8926397f4592f22a5ed54f772a979578ca36628f (diff) | |
Merge pull request #47 from kbleeke/pio-irq
Use IRQ instead of polling the status register
Diffstat (limited to 'src/runner.rs')
| -rw-r--r-- | src/runner.rs | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/src/runner.rs b/src/runner.rs index 4abccf48b..abfac3ae3 100644 --- a/src/runner.rs +++ b/src/runner.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | use core::slice; | 1 | use core::slice; |
| 2 | 2 | ||
| 3 | use embassy_futures::select::{select3, Either3}; | 3 | use embassy_futures::select::{select3, Either3}; |
| 4 | use embassy_futures::yield_now; | ||
| 5 | use embassy_net_driver_channel as ch; | 4 | use embassy_net_driver_channel as ch; |
| 6 | use embassy_sync::pubsub::PubSubBehavior; | 5 | use embassy_sync::pubsub::PubSubBehavior; |
| 7 | use embassy_time::{block_for, Duration, Timer}; | 6 | use embassy_time::{block_for, Duration, Timer}; |
| @@ -122,7 +121,11 @@ where | |||
| 122 | while self.bus.read8(FUNC_BACKPLANE, REG_BACKPLANE_CHIP_CLOCK_CSR).await & 0x80 == 0 {} | 121 | while self.bus.read8(FUNC_BACKPLANE, REG_BACKPLANE_CHIP_CLOCK_CSR).await & 0x80 == 0 {} |
| 123 | 122 | ||
| 124 | // "Set up the interrupt mask and enable interrupts" | 123 | // "Set up the interrupt mask and enable interrupts" |
| 125 | self.bus.bp_write32(CHIP.sdiod_core_base_address + 0x24, 0xF0).await; | 124 | // self.bus.bp_write32(CHIP.sdiod_core_base_address + 0x24, 0xF0).await; |
| 125 | |||
| 126 | self.bus | ||
| 127 | .write16(FUNC_BUS, REG_BUS_INTERRUPT_ENABLE, IRQ_F2_PACKET_AVAILABLE) | ||
| 128 | .await; | ||
| 126 | 129 | ||
| 127 | // "Lower F2 Watermark to avoid DMA Hang in F2 when SD Clock is stopped." | 130 | // "Lower F2 Watermark to avoid DMA Hang in F2 when SD Clock is stopped." |
| 128 | // Sounds scary... | 131 | // Sounds scary... |
| @@ -227,22 +230,22 @@ where | |||
| 227 | #[cfg(feature = "firmware-logs")] | 230 | #[cfg(feature = "firmware-logs")] |
| 228 | self.log_read().await; | 231 | self.log_read().await; |
| 229 | 232 | ||
| 230 | let ev = || async { | ||
| 231 | // TODO use IRQs | ||
| 232 | yield_now().await; | ||
| 233 | }; | ||
| 234 | |||
| 235 | if self.has_credit() { | 233 | if self.has_credit() { |
| 236 | let ioctl = self.ioctl_state.wait_pending(); | 234 | let ioctl = self.ioctl_state.wait_pending(); |
| 237 | let tx = self.ch.tx_buf(); | 235 | let tx = self.ch.tx_buf(); |
| 238 | 236 | let ev = self.bus.wait_for_event(); | |
| 239 | match select3(ioctl, tx, ev()).await { | 237 | |
| 240 | Either3::First(PendingIoctl { buf, kind, cmd, iface }) => { | 238 | match select3(ioctl, tx, ev).await { |
| 241 | warn!("ioctl"); | 239 | Either3::First(PendingIoctl { |
| 242 | self.send_ioctl(kind, cmd, iface, unsafe { &*buf }).await; | 240 | buf: iobuf, |
| 241 | kind, | ||
| 242 | cmd, | ||
| 243 | iface, | ||
| 244 | }) => { | ||
| 245 | self.send_ioctl(kind, cmd, iface, unsafe { &*iobuf }).await; | ||
| 246 | self.check_status(&mut buf).await; | ||
| 243 | } | 247 | } |
| 244 | Either3::Second(packet) => { | 248 | Either3::Second(packet) => { |
| 245 | warn!("packet"); | ||
| 246 | trace!("tx pkt {:02x}", Bytes(&packet[..packet.len().min(48)])); | 249 | trace!("tx pkt {:02x}", Bytes(&packet[..packet.len().min(48)])); |
| 247 | 250 | ||
| 248 | let mut buf = [0; 512]; | 251 | let mut buf = [0; 512]; |
| @@ -284,46 +287,47 @@ where | |||
| 284 | 287 | ||
| 285 | self.bus.wlan_write(&buf[..(total_len / 4)]).await; | 288 | self.bus.wlan_write(&buf[..(total_len / 4)]).await; |
| 286 | self.ch.tx_done(); | 289 | self.ch.tx_done(); |
| 290 | self.check_status(&mut buf).await; | ||
| 287 | } | 291 | } |
| 288 | Either3::Third(()) => { | 292 | Either3::Third(()) => { |
| 289 | // Receive stuff | 293 | self.handle_irq(&mut buf).await; |
| 290 | let irq = self.bus.read16(FUNC_BUS, REG_BUS_INTERRUPT).await; | ||
| 291 | |||
| 292 | if irq & IRQ_F2_PACKET_AVAILABLE != 0 { | ||
| 293 | let mut status = 0xFFFF_FFFF; | ||
| 294 | while status == 0xFFFF_FFFF { | ||
| 295 | status = self.bus.read32(FUNC_BUS, REG_BUS_STATUS).await; | ||
| 296 | } | ||
| 297 | |||
| 298 | if status & STATUS_F2_PKT_AVAILABLE != 0 { | ||
| 299 | let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT; | ||
| 300 | self.bus.wlan_read(&mut buf, len).await; | ||
| 301 | trace!("rx {:02x}", Bytes(&slice8_mut(&mut buf)[..(len as usize).min(48)])); | ||
| 302 | self.rx(&slice8_mut(&mut buf)[..len as usize]); | ||
| 303 | } | ||
| 304 | } | ||
| 305 | } | 294 | } |
| 306 | } | 295 | } |
| 307 | } else { | 296 | } else { |
| 308 | warn!("TX stalled"); | 297 | warn!("TX stalled"); |
| 309 | ev().await; | 298 | self.bus.wait_for_event().await; |
| 299 | self.handle_irq(&mut buf).await; | ||
| 300 | } | ||
| 301 | } | ||
| 302 | } | ||
| 310 | 303 | ||
| 311 | // Receive stuff | 304 | /// Wait for IRQ on F2 packet available |
| 312 | let irq = self.bus.read16(FUNC_BUS, REG_BUS_INTERRUPT).await; | 305 | async fn handle_irq(&mut self, buf: &mut [u32; 512]) { |
| 306 | // Receive stuff | ||
| 307 | let irq = self.bus.read16(FUNC_BUS, REG_BUS_INTERRUPT).await; | ||
| 308 | trace!("irq{}", FormatInterrupt(irq)); | ||
| 313 | 309 | ||
| 314 | if irq & IRQ_F2_PACKET_AVAILABLE != 0 { | 310 | if irq & IRQ_F2_PACKET_AVAILABLE != 0 { |
| 315 | let mut status = 0xFFFF_FFFF; | 311 | self.check_status(buf).await; |
| 316 | while status == 0xFFFF_FFFF { | 312 | } |
| 317 | status = self.bus.read32(FUNC_BUS, REG_BUS_STATUS).await; | 313 | } |
| 318 | } | ||
| 319 | 314 | ||
| 320 | if status & STATUS_F2_PKT_AVAILABLE != 0 { | 315 | /// Handle F2 events while status register is set |
| 321 | let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT; | 316 | async fn check_status(&mut self, buf: &mut [u32; 512]) { |
| 322 | self.bus.wlan_read(&mut buf, len).await; | 317 | loop { |
| 323 | trace!("rx {:02x}", Bytes(&slice8_mut(&mut buf)[..(len as usize).min(48)])); | 318 | let mut status = 0xFFFF_FFFF; |
| 324 | self.rx(&slice8_mut(&mut buf)[..len as usize]); | 319 | while status == 0xFFFF_FFFF { |
| 325 | } | 320 | status = self.bus.read32(FUNC_BUS, REG_BUS_STATUS).await; |
| 326 | } | 321 | } |
| 322 | trace!("check status{}", FormatStatus(status)); | ||
| 323 | |||
| 324 | if status & STATUS_F2_PKT_AVAILABLE != 0 { | ||
| 325 | let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT; | ||
| 326 | self.bus.wlan_read(buf, len).await; | ||
| 327 | trace!("rx {:02x}", Bytes(&slice8_mut(buf)[..(len as usize).min(48)])); | ||
| 328 | self.rx(&slice8_mut(buf)[..len as usize]); | ||
| 329 | } else { | ||
| 330 | break; | ||
| 327 | } | 331 | } |
| 328 | } | 332 | } |
| 329 | } | 333 | } |
