diff options
Diffstat (limited to 'embassy-rp/src/uart/buffered.rs')
| -rw-r--r-- | embassy-rp/src/uart/buffered.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs index 02649ad81..fdb8ce776 100644 --- a/embassy-rp/src/uart/buffered.rs +++ b/embassy-rp/src/uart/buffered.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | //! Buffered UART driver. | 1 | //! Buffered UART driver. |
| 2 | use core::future::Future; | 2 | use core::future::Future; |
| 3 | use core::slice; | 3 | use core::slice; |
| 4 | use core::sync::atomic::{AtomicU8, Ordering}; | ||
| 4 | 5 | ||
| 5 | use atomic_polyfill::AtomicU8; | ||
| 6 | use embassy_hal_internal::atomic_ring_buffer::RingBuffer; | 6 | use embassy_hal_internal::atomic_ring_buffer::RingBuffer; |
| 7 | 7 | ||
| 8 | use super::*; | 8 | use super::*; |
| @@ -241,7 +241,11 @@ impl BufferedUartRx { | |||
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | fn get_rx_error(state: &State) -> Option<Error> { | 243 | fn get_rx_error(state: &State) -> Option<Error> { |
| 244 | let errs = state.rx_error.swap(0, Ordering::Relaxed); | 244 | let errs = critical_section::with(|_| { |
| 245 | let val = state.rx_error.load(Ordering::Relaxed); | ||
| 246 | state.rx_error.store(0, Ordering::Relaxed); | ||
| 247 | val | ||
| 248 | }); | ||
| 245 | if errs & RXE_OVERRUN != 0 { | 249 | if errs & RXE_OVERRUN != 0 { |
| 246 | Some(Error::Overrun) | 250 | Some(Error::Overrun) |
| 247 | } else if errs & RXE_BREAK != 0 { | 251 | } else if errs & RXE_BREAK != 0 { |
| @@ -555,7 +559,10 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for BufferedInterr | |||
| 555 | } | 559 | } |
| 556 | let dr = r.uartdr().read(); | 560 | let dr = r.uartdr().read(); |
| 557 | if (dr.0 >> 8) != 0 { | 561 | if (dr.0 >> 8) != 0 { |
| 558 | s.rx_error.fetch_or((dr.0 >> 8) as u8, Ordering::Relaxed); | 562 | critical_section::with(|_| { |
| 563 | let val = s.rx_error.load(Ordering::Relaxed); | ||
| 564 | s.rx_error.store(val | ((dr.0 >> 8) as u8), Ordering::Relaxed); | ||
| 565 | }); | ||
| 559 | error = true; | 566 | error = true; |
| 560 | // only fill the buffer with valid characters. the current character is fine | 567 | // only fill the buffer with valid characters. the current character is fine |
| 561 | // if the error is an overrun, but if we add it to the buffer we'll report | 568 | // if the error is an overrun, but if we add it to the buffer we'll report |
