Repository navigation
feat(lpc): drive SCT+DMA chunk progression via poll() — no busy-wait (#3459) - #3498
Conversation
…3459) Closes #3459 acceptance criterion 3: "State machine transitions READY → BUSY → DRAINING → READY driven by poll(); no busy-wait in show()." The previous `LpcSctDmaTransmitter::transmit()` looped internally, kicking each chunk's DMA and then busy-waiting on `DMA0->COMMON[0].ACTIVE` before moving to the next chunk. That worked but blocked `show()` for the entire frame duration — for a 200-LED WS2812 that is ~6 ms of CPU-blocked time and the driver inherited every `TODO(2842)` from the legacy template's `waitDmaChunk()`. ## Refactor shape Split `transmit()` into a kick-and-return primitive and a poll-driven advance: - `transmit(bytes, len, is_rgbw)` — on LPC845, latches the buffer + progression state (`mCurrentBytes` / `mCurrentLen` / `mBytesSent` / `mTransmitInProgress`), encodes the first chunk into `mChannelBuf`, arms the 3 DMA channels, releases SCT HALT, and returns immediately. On host `transmit()` completes synchronously (copies to `mTxCapture`) — same observable behaviour as before. - `pollAndAdvance()` (new public method) — the engine's `poll()` calls this on every tick. If the current chunk is still active, returns false (engine stays in DRAINING). If done AND bytes remain, encodes and kicks the next chunk in the same call and returns false (still DRAINING). If done AND all bytes sent, marks the transmitter idle and returns true (engine transitions to READY). Internal `kickNextChunk()` helper (file-scope anonymous namespace) holds the encode + arm + release-HALT sequence so `transmit()` and `pollAndAdvance()` share the same code path. ## Engine change `ChannelEngineLpcSctDma::poll()` now delegates to `mTransmitter.pollAndAdvance()` instead of `mTransmitter.isDone()`. `isDone()` stays as a public method for backwards compat but is now documented as legacy — the docstring calls out that callers using it won't get chunk auto-advance (multi-chunk frames would stall after chunk 1). ## Host preservation Host stub's `transmit()` still populates `mTxCapture` synchronously so the #3468 TX→RX readback tests continue to work unchanged. `pollAndAdvance()` returns true immediately on host (no DMA to wait on). All existing tests pass. ## New tests Added two cases to `tests/platforms/arm/lpc/drivers/sct_dma/channel_engine_lpc_sct_dma.cpp`: - `"#3459 item 3: pollAndAdvance() returns true when idle"` — idempotency contract when no transmission is active. - `"#3459 item 3: show() does not busy-wait; multiple frames drain via poll()"` — three back-to-back frames driven through the show() → poll()-until-READY → show() loop. Pins that the state machine tracks `mTransmissionActive` correctly across frames and doesn't leak state. ## Tests + lint - `bash test --cpp --clean` → 344/344 passed (was 344 before; two new test cases sit inside the existing test file so the file-count aggregate is unchanged). - C++ lint (Python path) → clean. ## What's still open on #3459 - **Item 2** — `addLeds<WS2812, PIN, GRB>` routes through `ChannelEngineLpcSctDma::show()` (not the legacy template). Requires either a new `ClocklessController` specialization that forwards to the channels-API engine or removing the legacy template specialization when the channels-API path is available. Deferred pending silicon validation of the current engine. - Silicon bench validation (inherits every `TODO(2842)` marker from `clockless_arm_lpc_pwm_dma.h` — SCT/DMA register layout, INMUX wiring, SRAMBASE allocation, WFI + DMA-done IRQ replacement for the last remaining spin-wait inside `pollAndAdvance()` between chunks). Tracked separately on #3300 / #3450. Refs #3459. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughRefactors the LPC845 SCT/DMA transmit path from a blocking per-chunk loop into an incremental, poll-driven state machine. Adds ChangesPoll-driven SCT/DMA transmit state machine
Estimated code review effort: 3 (Moderate) | ~30 minutes Sequence Diagram(s)sequenceDiagram
participant ChannelEngineLpcSctDma
participant LpcSctDmaTransmitter
participant DMASCT as DMA/SCT Hardware
ChannelEngineLpcSctDma->>LpcSctDmaTransmitter: transmit(bytes, len, is_rgbw)
LpcSctDmaTransmitter->>DMASCT: encode + kick first chunk, release SCT HALT
loop until transmission complete
ChannelEngineLpcSctDma->>LpcSctDmaTransmitter: poll() -> pollAndAdvance()
LpcSctDmaTransmitter->>DMASCT: check DMA ACTIVE status
alt chunk not yet complete
LpcSctDmaTransmitter-->>ChannelEngineLpcSctDma: false
ChannelEngineLpcSctDma-->>ChannelEngineLpcSctDma: DriverState::DRAINING
else chunk complete, more bytes remain
LpcSctDmaTransmitter->>DMASCT: halt SCT, kick next chunk
LpcSctDmaTransmitter-->>ChannelEngineLpcSctDma: false
else all bytes sent
LpcSctDmaTransmitter-->>ChannelEngineLpcSctDma: true
ChannelEngineLpcSctDma-->>ChannelEngineLpcSctDma: DriverState::READY
end
end
Possibly related issues
Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Closes #3459 acceptance criterion 3: state machine transitions
READY → BUSY → DRAINING → READYare now driven bypoll()— no busy-wait insideshow().The previous
LpcSctDmaTransmitter::transmit()looped internally, kicking each chunk's DMA and then busy-waiting onDMA0->COMMON[0].ACTIVEbefore moving to the next chunk. That blockedshow()for the entire frame duration (~6 ms per 200-LED WS2812 frame).Refactor shape
transmit(bytes, len, is_rgbw)on LPC845 latches progression state (mCurrentBytes/mCurrentLen/mBytesSent/mTransmitInProgress), encodes+kicks the first chunk, and returns.pollAndAdvance()public method — the engine'spoll()calls this each tick. If the chunk is still active, returnsfalse(engine stays DRAINING). If done + bytes remain, encodes+kicks the next chunk in the same call and returnsfalse. If done + all bytes sent, marks idle and returnstrue(engine transitions to READY).kickNextChunk()file-scope helper shares the encode+arm+release-HALT sequence.Engine
poll()now delegates topollAndAdvance(). LegacyisDone()stays for backwards compat, documented as legacy.Host stub still populates
mTxCapturesynchronously — all existing #3468 TX→RX readback tests pass unchanged.New tests
"#3459 item 3: pollAndAdvance() returns true when idle"— idempotency contract."#3459 item 3: show() does not busy-wait; multiple frames drain via poll()"— three back-to-back frames through the show()→poll()-until-READY→show() loop pins the state machine tracksmTransmissionActivecorrectly across frames.Results
bash test --cpp --clean→ 344/344 passed.Still open on #3459
addLeds<WS2812, PIN, GRB>routes throughChannelEngineLpcSctDma::show()(not the legacy template). Requires either a newClocklessControllerspecialization forwarding to the channels-API engine or removing the legacy template specialization when the channels-API path is available. Deferred pending silicon validation.Refs #3459.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests