-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[embassy nrf] remove panic on uarte overrun, return error on read instead #4752
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
Conversation
In an ideal world the reader would be told that an overrun happened, rather than an error message. Edit: An example of this is what is done in the mspm0 HAL: embassy/embassy-mspm0/src/uart/buffered.rs Lines 950 to 965 in 35b0ba4
|
Hello, |
8761bb4
to
8299b4e
Compare
embassy-nrf/src/buffered_uarte.rs
Outdated
if s.rx_overrun.load(Ordering::Relaxed) { | ||
s.rx_overrun.store(false, Ordering::Relaxed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can convert these load + store into a swap:
if s.rx_overrun.swap(false, ...) {
}
https://doc.rust-lang.org/std/sync/atomic/struct.AtomicU32.html#method.swap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, done
embassy-nrf/src/buffered_uarte.rs
Outdated
|
||
if errs.overrun() { | ||
panic!("BufferedUarte overrun"); | ||
s.rx_overrun.store(true, Ordering::Relaxed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be Ordering::Acquire since the write is in an interrupt and the read is not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apparently that breaks the build
error: atomic stores cannot have Acquire
or AcqRel
ordering
--> src/buffered_uarte.rs:93:46
|
93 | s.rx_overrun.store(true, Ordering::Acquire);
| ^^^^^^^^^^^^^^^^^
|
= help: consider using ordering modes Release
, SeqCst
or Relaxed
= note: #[deny(invalid_atomic_ordering)]
on by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should I use Release for the store and AcqRel for the swap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, my bad. This one should be Release.
embassy-nrf/src/buffered_uarte.rs
Outdated
compiler_fence(Ordering::SeqCst); | ||
//trace!("poll_read"); | ||
|
||
if s.rx_overrun.swap(false, Ordering::Relaxed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be Ordering::AcqRel?
embassy-nrf/src/buffered_uarte.rs
Outdated
/// we are ready to read if there is data in the buffer | ||
fn read_ready(&self) -> Result<bool, Error> { | ||
let state = self.buffered_state; | ||
if state.rx_overrun.swap(false, Ordering::Relaxed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also Ordering::AcqRel?
690eaaf
to
7b47da5
Compare
I used Release for the interrupt handler, and Acquire for the user code In my understanding, there's no need for AcqRel since we are not polling on the false value ? |
Hmm, yeah. You're right |
fixes #4750
probably not the optimal solution? let me know what to do instead