Skip to content
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

Add check owner support to DMA buffers #2337

Merged
merged 5 commits into from
Nov 2, 2024
Merged

Conversation

Dominaezzz
Copy link
Collaborator

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • I have added necessary changes to user code to the Migration Guide.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

Allows buffer implementations to configure the "check owner" bit of the DMA channel.
This is something that must be specified by buffer implementations for correct behavior.

No changelog as the Preparation struct isn't public yet and users shouldn't observe any different behaviour from this.

Testing

HIL tests

@Dominaezzz Dominaezzz added the skip-changelog No changelog modification needed label Oct 10, 2024
@Dominaezzz Dominaezzz mentioned this pull request Oct 10, 2024
20 tasks
Copy link
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

esp-hal/src/dma/buffers.rs Show resolved Hide resolved
///
/// Note: If the DMA channel doesn't support the provided option,
/// preparation will fail.
pub(super) check_owner: Option<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHy is this optional, what's the difference between None and Some(false)? The comment uses a lot of words to not explain this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Some(true): DMA channel must the owner bit
  • Some(false): DMA channel must NOT the owner bit
  • None: DMA channel can do whatever it likes/supports.

I can add this after the "This field allows buffer implementation to configure this behaviour." comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is somewhat problematic, though, isn't it? It preserves some random previous setting in the current implementation, can't that cause problems?

Copy link
Collaborator Author

@Dominaezzz Dominaezzz Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehhh, it does preserve some random previous setting, which I admit is a bit weird but I couldn't decide on a default haha. Like the doc says, for some buffer implementations, it doesn't matter whether the DMA channel checks or not. (And besides, the buffer trait is unsafe so we're trusting the user to pick the right option)

The main reason this None option exists is because SPI DMA (at least, I haven't checked all the other PDMA channels) doesn't support configuring check_owner, and I wanted a way for buffers to say "I don't care about this setting".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And besides, the buffer trait is unsafe so we're trusting the user to pick the right option)

The user can't implement the buffer traits anyway because the fields of Preparation aren't pub 🙃

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah 😅 I'm working towards that. (Still have to decide on builder pattern vs plain struct)

Copy link
Contributor

@bugadani bugadani Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK I think "Some(false): DMA channel must NOT [check?] the owner bit" sounds like a reasonable default instead of "None = whatever". You obviously know more here, so I would appreciate you explaining why accidentally owner-checking based on past use is a better option.

I think if the answer is "it makes no difference" then less options might be better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's two parts of the equation:

  1. What behavior the buffer implementation needs
  2. What the DMA channel can provide

For 1, None needs to exist as an option because choosing either true or false means some DMA channels just won't work with the buffer implementation. If the buffer says true, DMA channels that cannot check will fail to prepare the buffer. If the buffer says false, DMA channels that can't not check will fail to prepare the buffer.
Having None means the buffer can work with any channel.

For 2, SPI DMA doesn't support configuring the "check owner" bit, so it'll reject false. Every other DMA channel (that is in the hal atm 😄) supports configuring this. In the None case, I left it as "past use" for simplicity but I can set it to true by default I suppose.

To eliminate the "accidentally owner-checking based on past use" I can configure the "check owner" bit to true when the buffer says it doesn't care. Then the behavior would be consistent.

Copy link
Contributor

@bugadani bugadani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we should be able to get away with a single bool instead of Option<bool> but maybe I'm just stubbornly not being to understand something. Let's move on, thanks for the PR.

@bugadani bugadani added this pull request to the merge queue Nov 2, 2024
Merged via the queue into esp-rs:main with commit b953f17 Nov 2, 2024
28 checks passed
@Dominaezzz Dominaezzz deleted the check_owner branch November 3, 2024 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog No changelog modification needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants