Skip to content

feat(lpc): drive SCT+DMA chunk progression via poll() — no busy-wait (#3459) - #3498

Merged
zackees merged 1 commit into
masterfrom
feat/3459-async-poll
Jul 1, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/3459-async-poll

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #3459 acceptance criterion 3: state machine transitions READY → BUSY → DRAINING → READY are now driven by poll() — no busy-wait inside 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 blocked show() 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.
  • New pollAndAdvance() public method — the engine's poll() calls this each tick. If the chunk is still active, returns false (engine stays DRAINING). If done + bytes remain, encodes+kicks the next chunk in the same call and returns false. If done + all bytes sent, marks idle and returns true (engine transitions to READY).
  • Internal kickNextChunk() file-scope helper shares the encode+arm+release-HALT sequence.

Engine poll() now delegates to pollAndAdvance(). Legacy isDone() stays for backwards compat, documented as legacy.

Host stub still populates mTxCapture synchronously — 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 tracks mTransmissionActive correctly across frames.

Results

  • bash test --cpp --clean → 344/344 passed.
  • C++ lint (Python path) → clean.

Still open on #3459

Refs #3459.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added non-blocking progress for DMA transmissions, allowing frames to advance incrementally instead of waiting in a blocking loop.
    • Improved support for multi-chunk transfers so longer frames can complete reliably over repeated polling.
  • Bug Fixes

    • Fixed state handling between back-to-back transmissions to prevent leftover data from affecting the next frame.
    • Improved completion handling so idle transmissions and synchronous host behavior remain consistent.
  • Tests

    • Added coverage for polling-based transmission progression and consecutive frame handling.

…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]>
@zackees
zackees merged commit 8a4643e into master Jul 1, 2026
5 of 8 checks passed
@zackees
zackees deleted the feat/3459-async-poll branch July 1, 2026 08:30
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5588729d-e93d-4719-9eb8-89fb7eabccee

📥 Commits

Reviewing files that changed from the base of the PR and between b66907e and d263f0b.

📒 Files selected for processing (4)
  • src/platforms/arm/lpc/drivers/sct_dma/channel_engine_lpc_sct_dma.cpp.hpp
  • src/platforms/arm/lpc/drivers/sct_dma/lpc_sct_dma_runtime.cpp.hpp
  • src/platforms/arm/lpc/drivers/sct_dma/lpc_sct_dma_runtime.h
  • tests/platforms/arm/lpc/drivers/sct_dma/channel_engine_lpc_sct_dma.cpp

📝 Walkthrough

Walkthrough

Refactors the LPC845 SCT/DMA transmit path from a blocking per-chunk loop into an incremental, poll-driven state machine. Adds pollAndAdvance() to LpcSctDmaTransmitter, updates transmit()/isDone() semantics, updates ChannelEngineLpcSctDma::poll() to use the new method, and adds host-side tests.

Changes

Poll-driven SCT/DMA transmit state machine

Layer / File(s) Summary
Transmitter API contract
src/platforms/arm/lpc/drivers/sct_dma/lpc_sct_dma_runtime.h
Declares pollAndAdvance(), redocuments async LPC845 vs synchronous host semantics for transmit()/isDone(), and adds private chunk-progression state fields.
Runtime chunk-kick and poll advance
src/platforms/arm/lpc/drivers/sct_dma/lpc_sct_dma_runtime.cpp.hpp
Adds kickNextChunk helper; reworks transmit() to latch state and kick only the first chunk; pollAndAdvance() checks DMA ACTIVE, halts SCT, advances chunks, and marks completion; updates host/stub behavior for synchronous completion.
Channel engine poll() wiring
src/platforms/arm/lpc/drivers/sct_dma/channel_engine_lpc_sct_dma.cpp.hpp
poll() now calls mTransmitter.pollAndAdvance() instead of isDone(), preserving DRAINING/READY branching.
Host-side state machine tests
tests/platforms/arm/lpc/drivers/sct_dma/channel_engine_lpc_sct_dma.cpp
Adds tests for idle pollAndAdvance() idempotence and a bounded multi-frame enqueue/show/poll loop validating TX byte capture correctness.

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
Loading

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3460: Aligns with this PR's poll() update in the same channel_engine_lpc_sct_dma.cpp.hpp scaffold.
  • FastLED/FastLED#3466: Earlier wiring of show()/poll() to the LpcSctDmaTransmitter completion probing that this PR builds upon.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/3459-async-poll

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant