nrf/buffered_uarte: add test for recovering from buffer full.

This commit is contained in:
Dario Nieuwenhuis 2023-11-14 00:00:39 +01:00
parent c46418f123
commit 6ccd8c051e
2 changed files with 73 additions and 1 deletions

View File

@ -12,7 +12,7 @@ embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["de
embassy-executor = { version = "0.3.1", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "nightly", "integrated-timers"] }
embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] }
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
embedded-io-async = { version = "0.6.0" }
embedded-io-async = { version = "0.6.0", features = ["defmt-03"] }
embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] }
embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] }
embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] }

View File

@ -0,0 +1,72 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
teleprobe_meta::target!(b"nrf52840-dk");
use defmt::{assert_eq, *};
use embassy_executor::Spawner;
use embassy_nrf::buffered_uarte::{self, BufferedUarte};
use embassy_nrf::{bind_interrupts, peripherals, uarte};
use embedded_io_async::{Read, Write};
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;
});
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_nrf::init(Default::default());
let mut config = uarte::Config::default();
config.parity = uarte::Parity::EXCLUDED;
config.baudrate = uarte::Baudrate::BAUD1M;
let mut tx_buffer = [0u8; 1024];
let mut rx_buffer = [0u8; 1024];
let mut u = BufferedUarte::new(
p.UARTE0,
p.TIMER0,
p.PPI_CH0,
p.PPI_CH1,
p.PPI_GROUP0,
Irqs,
p.P1_03,
p.P1_02,
config.clone(),
&mut rx_buffer,
&mut tx_buffer,
);
info!("uarte initialized!");
let (mut rx, mut tx) = u.split();
let mut buf = [0; 1024];
for (j, b) in buf.iter_mut().enumerate() {
*b = j as u8;
}
// Write 1024b. This causes the rx buffer to get exactly full.
unwrap!(tx.write_all(&buf).await);
unwrap!(tx.flush().await);
// Read those 1024b.
unwrap!(rx.read_exact(&mut buf).await);
for (j, b) in buf.iter().enumerate() {
assert_eq!(*b, j as u8);
}
// The buffer should now be unclogged. Write 1024b again.
unwrap!(tx.write_all(&buf).await);
unwrap!(tx.flush().await);
// Read should work again.
unwrap!(rx.read_exact(&mut buf).await);
for (j, b) in buf.iter().enumerate() {
assert_eq!(*b, j as u8);
}
info!("Test OK");
cortex_m::asm::bkpt();
}