Skip to content

Add typestate-based control over the PIO RX buffer access #936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

horazont
Copy link
Contributor

@horazont horazont commented Jun 5, 2025

Fixes #935.

Open Questions:

  • StateMachine::clear_fifos is probably not sound with a non-FIFO RX buffer. It is not fully clear according to the reference manual though.

    The reference manual states that enabling the PUT/GET modes will cause the joining (which clear_fifos uses) to be disabled, but it doesn't say what happens if you enable joining while in non-FIFO mode.

    My proposal to fix this is to move the clear_fifos method onto the Rx<_> struct and constrain it to only be available in RxFifo mode.

    The other option would be to actually carry the RxFifoConfig type state through to the StateMachine to hide the clear_fifos method in such cases. That can probably be done, but has implications on the state machine groups (which will also have to carry that typestate).

    I can do either variant, but I'd like a judgement call from the maintainers on which way to go here.

TODOs:

  • I will add an example which uses this feature later, as well as fix the existing example. Fixed example and added my original LED matrix code as another example.

@horazont horazont force-pushed the feature/pio-rxputget branch 4 times, most recently from 41e7be5 to 47c08cd Compare June 5, 2025 16:01
@horazont horazont force-pushed the feature/pio-rxputget branch from 47c08cd to 5de80b4 Compare June 5, 2025 16:06
@jannic
Copy link
Member

jannic commented Jun 8, 2025

StateMachine::clear_fifos is probably not sound with a non-FIFO RX buffer. It is not fully clear according to the reference manual though.

I propose to find out what actually happens in that case. Either experimentally or by asking the Raspberry engineers.
My guess would be that clear_fifos only clears the FIFO pointers, and not the memory cells. Rationale: When used as FIFO, the actually memory contents are irrelevant when the FIFO pointers say that the FIFO is empty. And the datasheet states "the data returned by reading from an empty FIFO is undefined". Therefore, why waste hardware resources to clear the memory cells?

If that's true, then our clear_fifos method is not unsound in PUT/GET modes. Instead, it just has no observable effect. In that case, I would not change the code at all. Maybe add an explanation to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for putget to PIO
2 participants