Implement proper Drop for BufferedUarte

This commit is contained in:
Zoey Riordan 2022-09-21 10:47:49 +02:00
parent 11da25800b
commit 3d708a459c

View File

@ -27,7 +27,7 @@ use futures::future::poll_fn;
// Re-export SVD variants to allow user to directly set values // Re-export SVD variants to allow user to directly set values
pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
use crate::gpio::Pin as GpioPin; use crate::gpio::{self, Pin as GpioPin};
use crate::interrupt::InterruptExt; use crate::interrupt::InterruptExt;
use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
use crate::timer::{Frequency, Instance as TimerInstance, Timer}; use crate::timer::{Frequency, Instance as TimerInstance, Timer};
@ -427,23 +427,26 @@ impl<'u, 'd: 'u, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write
impl<'a, U: UarteInstance, T: TimerInstance> Drop for StateInner<'a, U, T> { impl<'a, U: UarteInstance, T: TimerInstance> Drop for StateInner<'a, U, T> {
fn drop(&mut self) { fn drop(&mut self) {
debug!("oh no, dropping uarte");
let r = U::regs(); let r = U::regs();
// TODO this probably deadlocks. do like Uarte instead. // TODO this probably deadlocks. do like Uarte instead.
r.inten.reset();
r.events_rxto.reset();
r.tasks_stoprx.write(|w| w.tasks_stoprx().set_bit());
self.timer.stop(); r.events_txstopped.reset();
if let RxState::Receiving = self.rx_state { r.tasks_stoptx.write(|w| w.tasks_stoptx().set_bit());
r.tasks_stoprx.write(|w| unsafe { w.bits(1) }); while !r.events_txstopped.read().events_txstopped().bit_is_set() {}
}
if let TxState::Transmitting(_) = self.tx_state { while !r.events_rxto.read().events_rxto().bit_is_set() {}
r.tasks_stoptx.write(|w| unsafe { w.bits(1) });
} r.enable.write(|w| w.enable().disabled());
if let RxState::Receiving = self.rx_state {
low_power_wait_until(|| r.events_endrx.read().bits() == 1); gpio::deconfigure_pin(r.psel.rxd.read().bits());
} gpio::deconfigure_pin(r.psel.txd.read().bits());
if let TxState::Transmitting(_) = self.tx_state { gpio::deconfigure_pin(r.psel.rts.read().bits());
low_power_wait_until(|| r.events_endtx.read().bits() == 1); gpio::deconfigure_pin(r.psel.cts.read().bits());
}
} }
} }