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

Properly report break conditions #712

Merged
merged 3 commits into from
Jan 6, 2024
Merged

Conversation

jannic
Copy link
Member

@jannic jannic commented Nov 2, 2023

A break condition is also a framing error. As it is the more specific code, return the break error.

A break condition is also a framing error. As it is the more specifc code, return the break error.
@jannic
Copy link
Member Author

jannic commented Nov 2, 2023

I wonder what error should be returned if both FE and PE are set. Is one of them more specific and should be preferred?

@jannic
Copy link
Member Author

jannic commented Nov 2, 2023

embassy-rp uses this order of precedence, which looks sensible:

            if dr.oe() {
                Err(nb::Error::Other(Error::Overrun))
            } else if dr.be() {
                Err(nb::Error::Other(Error::Break))
            } else if dr.pe() {
                Err(nb::Error::Other(Error::Parity))
            } else if dr.fe() {
                Err(nb::Error::Other(Error::Framing))
            } else {
                Ok(dr.data())
            }

If multiple status bits are set, report the most serious or most specific condition.
@9names
Copy link
Member

9names commented Nov 10, 2023

I wonder what error should be returned if both FE and PE are set. Is one of them more specific and should be preferred?

FWIW I would have frame error as a higher priority.
Sure, your data is corrupt either way but a parity error only tells you that an odd number of bits are wrong, a framing error tells you why the sum of bits is wrong.

@jannic
Copy link
Member Author

jannic commented Nov 10, 2023

I don't agree that the framing error tells you why the parity was wrong. Both flags can be set because of a single bit-error. (If one, or an odd number of, data/parity bits are wrong, you get a parity error. If the stop bit is wrong, you get a framing error.)
But I agree that the framing error should probably have priority: It's more specific. You exactly know which bit was wrong. So it tells you slightly more than the parity error.
Now the difference between the two choices is so small that consistency with other implementations seems to be more important to me. I'll check what the C SDK does.

@ithinuel ithinuel merged commit 6b040de into rp-rs:main Jan 6, 2024
8 checks passed
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.

3 participants