aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias <[email protected]>2022-09-27 07:45:10 +0200
committerMathias <[email protected]>2022-09-27 07:45:10 +0200
commite129a97d48a00d7923886ab3faa82357b2369f13 (patch)
treee2aa1833e25562d5efa176db52c2b68456165100
parent93354b812c89c1b0d56f93181eae8484c625fe89 (diff)
Fix bufferedUart read and write tests
-rw-r--r--embassy-rp/src/uart/buffered.rs88
-rw-r--r--embassy-rp/src/uart/mod.rs7
-rw-r--r--tests/rp/src/bin/uart_buffered.rs9
3 files changed, 51 insertions, 53 deletions
diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs
index 81ac61ee4..87e16f0eb 100644
--- a/embassy-rp/src/uart/buffered.rs
+++ b/embassy-rp/src/uart/buffered.rs
@@ -228,39 +228,39 @@ where
228 fn on_interrupt(&mut self) { 228 fn on_interrupt(&mut self) {
229 let r = T::regs(); 229 let r = T::regs();
230 unsafe { 230 unsafe {
231 let ris = r.uartmis().read(); 231 let ris = r.uartris().read();
232 // Clear interrupt flags 232 // Clear interrupt flags
233 r.uarticr().modify(|w| { 233 r.uarticr().modify(|w| {
234 w.set_rxic(true); 234 w.set_rxic(true);
235 w.set_rtic(true); 235 w.set_rtic(true);
236 }); 236 });
237 237
238 if ris.rxmis() { 238 if ris.peris() {
239 if ris.pemis() { 239 warn!("Parity error");
240 warn!("Parity error"); 240 r.uarticr().modify(|w| {
241 r.uarticr().modify(|w| { 241 w.set_peic(true);
242 w.set_peic(true); 242 });
243 }); 243 }
244 } 244 if ris.feris() {
245 if ris.femis() { 245 warn!("Framing error");
246 warn!("Framing error"); 246 r.uarticr().modify(|w| {
247 r.uarticr().modify(|w| { 247 w.set_feic(true);
248 w.set_feic(true); 248 });
249 }); 249 }
250 } 250 if ris.beris() {
251 if ris.bemis() { 251 warn!("Break error");
252 warn!("Break error"); 252 r.uarticr().modify(|w| {
253 r.uarticr().modify(|w| { 253 w.set_beic(true);
254 w.set_beic(true); 254 });
255 }); 255 }
256 } 256 if ris.oeris() {
257 if ris.oemis() { 257 warn!("Overrun error");
258 warn!("Overrun error"); 258 r.uarticr().modify(|w| {
259 r.uarticr().modify(|w| { 259 w.set_oeic(true);
260 w.set_oeic(true); 260 });
261 }); 261 }
262 }
263 262
263 if !r.uartfr().read().rxfe() {
264 let buf = self.buf.push_buf(); 264 let buf = self.buf.push_buf();
265 if !buf.is_empty() { 265 if !buf.is_empty() {
266 buf[0] = r.uartdr().read().data(); 266 buf[0] = r.uartdr().read().data();
@@ -274,7 +274,7 @@ where
274 } 274 }
275 } 275 }
276 276
277 if ris.rtmis() { 277 if ris.rtris() {
278 self.waker.wake(); 278 self.waker.wake();
279 }; 279 };
280 } 280 }
@@ -318,27 +318,19 @@ where
318 fn on_interrupt(&mut self) { 318 fn on_interrupt(&mut self) {
319 let r = T::regs(); 319 let r = T::regs();
320 unsafe { 320 unsafe {
321 let ris = r.uartris().read(); 321 let buf = self.buf.pop_buf();
322 // Clear interrupt flags 322 if !buf.is_empty() {
323 r.uarticr().write(|w| { 323 r.uartimsc().modify(|w| {
324 w.set_rtic(true); 324 w.set_txim(true);
325 }); 325 });
326 326 r.uartdr().write(|w| w.set_data(buf[0].into()));
327 if ris.txris() { 327 self.buf.pop(1);
328 let buf = self.buf.pop_buf(); 328 self.waker.wake();
329 if !buf.is_empty() { 329 } else {
330 r.uartimsc().modify(|w| { 330 // Disable interrupt until we have something to transmit again
331 w.set_txim(true); 331 r.uartimsc().modify(|w| {
332 }); 332 w.set_txim(false);
333 r.uartdr().write(|w| w.set_data(buf[0].into())); 333 });
334 self.buf.pop(1);
335 self.waker.wake();
336 } else {
337 // Disable interrupt until we have something to transmit again
338 r.uartimsc().modify(|w| {
339 w.set_txim(false);
340 });
341 }
342 } 334 }
343 } 335 }
344 } 336 }
diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs
index 76ecdf7ac..d9285ee51 100644
--- a/embassy-rp/src/uart/mod.rs
+++ b/embassy-rp/src/uart/mod.rs
@@ -343,7 +343,12 @@ impl<'d, T: Instance, M: Mode> Uart<'d, T, M> {
343 w.set_stp2(config.stop_bits == StopBits::STOP2); 343 w.set_stp2(config.stop_bits == StopBits::STOP2);
344 w.set_pen(pen); 344 w.set_pen(pen);
345 w.set_eps(eps); 345 w.set_eps(eps);
346 w.set_fen(false); 346 w.set_fen(true);
347 });
348
349 r.uartifls().write(|w| {
350 w.set_rxiflsel(0b000);
351 w.set_txiflsel(0b000);
347 }); 352 });
348 353
349 r.uartcr().write(|w| { 354 r.uartcr().write(|w| {
diff --git a/tests/rp/src/bin/uart_buffered.rs b/tests/rp/src/bin/uart_buffered.rs
index 4313ee3dd..9cc20bb98 100644
--- a/tests/rp/src/bin/uart_buffered.rs
+++ b/tests/rp/src/bin/uart_buffered.rs
@@ -20,8 +20,8 @@ async fn main(_spawner: Spawner) {
20 let uart = Uart::new_blocking(uart, tx, rx, config); 20 let uart = Uart::new_blocking(uart, tx, rx, config);
21 21
22 let irq = interrupt::take!(UART0_IRQ); 22 let irq = interrupt::take!(UART0_IRQ);
23 let tx_buf = &mut [0u8; 32]; 23 let tx_buf = &mut [0u8; 16];
24 let rx_buf = &mut [0u8; 32]; 24 let rx_buf = &mut [0u8; 16];
25 let mut state = State::new(); 25 let mut state = State::new();
26 let mut uart = BufferedUart::new(&mut state, uart, irq, tx_buf, rx_buf); 26 let mut uart = BufferedUart::new(&mut state, uart, irq, tx_buf, rx_buf);
27 27
@@ -32,10 +32,11 @@ async fn main(_spawner: Spawner) {
32 1_u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 32 1_u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
33 30, 31, 32, 33 30, 31, 32,
34 ]; 34 ];
35 uart.write(&data).await.unwrap(); 35 uart.write_all(&data).await.unwrap();
36 info!("Done writing");
36 37
37 let mut buf = [0; 32]; 38 let mut buf = [0; 32];
38 uart.read(&mut buf).await.unwrap(); 39 uart.read_exact(&mut buf).await.unwrap();
39 assert_eq!(buf, data); 40 assert_eq!(buf, data);
40 41
41 info!("Test OK"); 42 info!("Test OK");