diff options
| author | kbleeke <[email protected]> | 2023-03-02 19:02:32 +0100 |
|---|---|---|
| committer | kbleeke <[email protected]> | 2023-03-27 13:18:59 +0200 |
| commit | b58cc2aa239e4adba2c32462cc89133bb7d9f698 (patch) | |
| tree | 236352d7335f0f81cea03a6e9c4646d643acceae /src/runner.rs | |
| parent | a2272dda08a2d1625eef0b79fcd80afc8a1e174a (diff) | |
use irqs to wait for events
Diffstat (limited to 'src/runner.rs')
| -rw-r--r-- | src/runner.rs | 94 |
1 files changed, 51 insertions, 43 deletions
diff --git a/src/runner.rs b/src/runner.rs index 4abccf48b..a1de0770e 100644 --- a/src/runner.rs +++ b/src/runner.rs | |||
| @@ -122,7 +122,11 @@ where | |||
| 122 | while self.bus.read8(FUNC_BACKPLANE, REG_BACKPLANE_CHIP_CLOCK_CSR).await & 0x80 == 0 {} | 122 | while self.bus.read8(FUNC_BACKPLANE, REG_BACKPLANE_CHIP_CLOCK_CSR).await & 0x80 == 0 {} |
| 123 | 123 | ||
| 124 | // "Set up the interrupt mask and enable interrupts" | 124 | // "Set up the interrupt mask and enable interrupts" |
| 125 | self.bus.bp_write32(CHIP.sdiod_core_base_address + 0x24, 0xF0).await; | 125 | // self.bus.bp_write32(CHIP.sdiod_core_base_address + 0x24, 0xF0).await; |
| 126 | |||
| 127 | self.bus | ||
| 128 | .write16(FUNC_BUS, REG_BUS_INTERRUPT_ENABLE, IRQ_F2_PACKET_AVAILABLE) | ||
| 129 | .await; | ||
| 126 | 130 | ||
| 127 | // "Lower F2 Watermark to avoid DMA Hang in F2 when SD Clock is stopped." | 131 | // "Lower F2 Watermark to avoid DMA Hang in F2 when SD Clock is stopped." |
| 128 | // Sounds scary... | 132 | // Sounds scary... |
| @@ -227,22 +231,22 @@ where | |||
| 227 | #[cfg(feature = "firmware-logs")] | 231 | #[cfg(feature = "firmware-logs")] |
| 228 | self.log_read().await; | 232 | self.log_read().await; |
| 229 | 233 | ||
| 230 | let ev = || async { | ||
| 231 | // TODO use IRQs | ||
| 232 | yield_now().await; | ||
| 233 | }; | ||
| 234 | |||
| 235 | if self.has_credit() { | 234 | if self.has_credit() { |
| 236 | let ioctl = self.ioctl_state.wait_pending(); | 235 | let ioctl = self.ioctl_state.wait_pending(); |
| 237 | let tx = self.ch.tx_buf(); | 236 | let tx = self.ch.tx_buf(); |
| 238 | 237 | let ev = self.bus.wait_for_event(); | |
| 239 | match select3(ioctl, tx, ev()).await { | 238 | |
| 240 | Either3::First(PendingIoctl { buf, kind, cmd, iface }) => { | 239 | match select3(ioctl, tx, ev).await { |
| 241 | warn!("ioctl"); | 240 | Either3::First(PendingIoctl { |
| 242 | self.send_ioctl(kind, cmd, iface, unsafe { &*buf }).await; | 241 | buf: iobuf, |
| 242 | kind, | ||
| 243 | cmd, | ||
| 244 | iface, | ||
| 245 | }) => { | ||
| 246 | self.send_ioctl(kind, cmd, iface, unsafe { &*iobuf }).await; | ||
| 247 | self.check_status(&mut buf).await; | ||
| 243 | } | 248 | } |
| 244 | Either3::Second(packet) => { | 249 | Either3::Second(packet) => { |
| 245 | warn!("packet"); | ||
| 246 | trace!("tx pkt {:02x}", Bytes(&packet[..packet.len().min(48)])); | 250 | trace!("tx pkt {:02x}", Bytes(&packet[..packet.len().min(48)])); |
| 247 | 251 | ||
| 248 | let mut buf = [0; 512]; | 252 | let mut buf = [0; 512]; |
| @@ -284,47 +288,51 @@ where | |||
| 284 | 288 | ||
| 285 | self.bus.wlan_write(&buf[..(total_len / 4)]).await; | 289 | self.bus.wlan_write(&buf[..(total_len / 4)]).await; |
| 286 | self.ch.tx_done(); | 290 | self.ch.tx_done(); |
| 291 | self.check_status(&mut buf).await; | ||
| 287 | } | 292 | } |
| 288 | Either3::Third(()) => { | 293 | Either3::Third(()) => { |
| 289 | // Receive stuff | 294 | 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 | } | 295 | } |
| 306 | } | 296 | } |
| 307 | } else { | 297 | } else { |
| 308 | warn!("TX stalled"); | 298 | warn!("TX stalled"); |
| 309 | ev().await; | 299 | self.bus.wait_for_event().await; |
| 300 | self.handle_irq(&mut buf).await; | ||
| 301 | } | ||
| 302 | } | ||
| 303 | } | ||
| 310 | 304 | ||
| 311 | // Receive stuff | 305 | /// Wait for IRQ on F2 packet available |
| 312 | let irq = self.bus.read16(FUNC_BUS, REG_BUS_INTERRUPT).await; | 306 | async fn handle_irq(&mut self, buf: &mut [u32; 512]) { |
| 307 | self.bus.clear_event(); | ||
| 308 | // Receive stuff | ||
| 309 | let irq = self.bus.read16(FUNC_BUS, REG_BUS_INTERRUPT).await; | ||
| 310 | trace!("irq{}", FormatInterrupt(irq)); | ||
| 313 | 311 | ||
| 314 | if irq & IRQ_F2_PACKET_AVAILABLE != 0 { | 312 | if irq & IRQ_F2_PACKET_AVAILABLE != 0 { |
| 315 | let mut status = 0xFFFF_FFFF; | 313 | self.check_status(buf).await; |
| 316 | while status == 0xFFFF_FFFF { | 314 | } |
| 317 | status = self.bus.read32(FUNC_BUS, REG_BUS_STATUS).await; | 315 | } |
| 318 | } | ||
| 319 | 316 | ||
| 320 | if status & STATUS_F2_PKT_AVAILABLE != 0 { | 317 | /// Handle F2 events while status register is set |
| 321 | let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT; | 318 | async fn check_status(&mut self, buf: &mut [u32; 512]) { |
| 322 | self.bus.wlan_read(&mut buf, len).await; | 319 | loop { |
| 323 | trace!("rx {:02x}", Bytes(&slice8_mut(&mut buf)[..(len as usize).min(48)])); | 320 | let mut status = 0xFFFF_FFFF; |
| 324 | self.rx(&slice8_mut(&mut buf)[..len as usize]); | 321 | while status == 0xFFFF_FFFF { |
| 325 | } | 322 | status = self.bus.read32(FUNC_BUS, REG_BUS_STATUS).await; |
| 326 | } | ||
| 327 | } | 323 | } |
| 324 | trace!("check status{}", FormatStatus(status)); | ||
| 325 | |||
| 326 | if status & STATUS_F2_PKT_AVAILABLE != 0 { | ||
| 327 | let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT; | ||
| 328 | self.bus.wlan_read(buf, len).await; | ||
| 329 | trace!("rx {:02x}", Bytes(&slice8_mut(buf)[..(len as usize).min(48)])); | ||
| 330 | self.rx(&slice8_mut(buf)[..len as usize]); | ||
| 331 | } else { | ||
| 332 | break; | ||
| 333 | } | ||
| 334 | |||
| 335 | yield_now().await; | ||
| 328 | } | 336 | } |
| 329 | } | 337 | } |
| 330 | 338 | ||
