nrf/uart: add buffereduart drop, rxonly, txonly tests.
This commit is contained in:
parent
2feed96c91
commit
036f703a4a
2 changed files with 127 additions and 42 deletions
|
@ -15,7 +15,7 @@ bind_interrupts!(struct Irqs {
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
let p = embassy_nrf::init(Default::default());
|
let mut p = embassy_nrf::init(Default::default());
|
||||||
let mut config = uarte::Config::default();
|
let mut config = uarte::Config::default();
|
||||||
config.parity = uarte::Parity::EXCLUDED;
|
config.parity = uarte::Parity::EXCLUDED;
|
||||||
config.baudrate = uarte::Baudrate::BAUD1M;
|
config.baudrate = uarte::Baudrate::BAUD1M;
|
||||||
|
@ -23,55 +23,58 @@ async fn main(_spawner: Spawner) {
|
||||||
let mut tx_buffer = [0u8; 1024];
|
let mut tx_buffer = [0u8; 1024];
|
||||||
let mut rx_buffer = [0u8; 1024];
|
let mut rx_buffer = [0u8; 1024];
|
||||||
|
|
||||||
let u = BufferedUarte::new(
|
// test teardown + recreate of the buffereduarte works fine.
|
||||||
p.UARTE0,
|
for _ in 0..2 {
|
||||||
p.TIMER0,
|
let u = BufferedUarte::new(
|
||||||
p.PPI_CH0,
|
&mut p.UARTE0,
|
||||||
p.PPI_CH1,
|
&mut p.TIMER0,
|
||||||
p.PPI_GROUP0,
|
&mut p.PPI_CH0,
|
||||||
Irqs,
|
&mut p.PPI_CH1,
|
||||||
p.P1_03,
|
&mut p.PPI_GROUP0,
|
||||||
p.P1_02,
|
Irqs,
|
||||||
config.clone(),
|
&mut p.P1_03,
|
||||||
&mut rx_buffer,
|
&mut p.P1_02,
|
||||||
&mut tx_buffer,
|
config.clone(),
|
||||||
);
|
&mut rx_buffer,
|
||||||
|
&mut tx_buffer,
|
||||||
|
);
|
||||||
|
|
||||||
info!("uarte initialized!");
|
info!("uarte initialized!");
|
||||||
|
|
||||||
let (mut rx, mut tx) = u.split();
|
let (mut rx, mut tx) = u.split();
|
||||||
|
|
||||||
const COUNT: usize = 40_000;
|
const COUNT: usize = 40_000;
|
||||||
|
|
||||||
let tx_fut = async {
|
let tx_fut = async {
|
||||||
let mut tx_buf = [0; 215];
|
let mut tx_buf = [0; 215];
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < COUNT {
|
while i < COUNT {
|
||||||
let n = tx_buf.len().min(COUNT - i);
|
let n = tx_buf.len().min(COUNT - i);
|
||||||
let tx_buf = &mut tx_buf[..n];
|
let tx_buf = &mut tx_buf[..n];
|
||||||
for (j, b) in tx_buf.iter_mut().enumerate() {
|
for (j, b) in tx_buf.iter_mut().enumerate() {
|
||||||
*b = (i + j) as u8;
|
*b = (i + j) as u8;
|
||||||
|
}
|
||||||
|
let n = unwrap!(tx.write(tx_buf).await);
|
||||||
|
i += n;
|
||||||
}
|
}
|
||||||
let n = unwrap!(tx.write(tx_buf).await);
|
};
|
||||||
i += n;
|
let rx_fut = async {
|
||||||
}
|
let mut i = 0;
|
||||||
};
|
while i < COUNT {
|
||||||
let rx_fut = async {
|
let buf = unwrap!(rx.fill_buf().await);
|
||||||
let mut i = 0;
|
|
||||||
while i < COUNT {
|
|
||||||
let buf = unwrap!(rx.fill_buf().await);
|
|
||||||
|
|
||||||
for &b in buf {
|
for &b in buf {
|
||||||
assert_eq!(b, i as u8);
|
assert_eq!(b, i as u8);
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let n = buf.len();
|
||||||
|
rx.consume(n);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let n = buf.len();
|
join(rx_fut, tx_fut).await;
|
||||||
rx.consume(n);
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
join(rx_fut, tx_fut).await;
|
|
||||||
|
|
||||||
info!("Test OK");
|
info!("Test OK");
|
||||||
cortex_m::asm::bkpt();
|
cortex_m::asm::bkpt();
|
||||||
|
|
82
tests/nrf52840/src/bin/buffered_uart_halves.rs
Normal file
82
tests/nrf52840/src/bin/buffered_uart_halves.rs
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
teleprobe_meta::target!(b"nrf52840-dk");
|
||||||
|
|
||||||
|
use defmt::{assert_eq, *};
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_futures::join::join;
|
||||||
|
use embassy_nrf::buffered_uarte::{self, BufferedUarteRx, BufferedUarteTx};
|
||||||
|
use embassy_nrf::{bind_interrupts, peripherals, uarte};
|
||||||
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
bind_interrupts!(struct Irqs {
|
||||||
|
UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;
|
||||||
|
UARTE1 => buffered_uarte::InterruptHandler<peripherals::UARTE1>;
|
||||||
|
});
|
||||||
|
|
||||||
|
#[embassy_executor::main]
|
||||||
|
async fn main(_spawner: Spawner) {
|
||||||
|
let mut 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];
|
||||||
|
|
||||||
|
// test teardown + recreate of the buffereduarte works fine.
|
||||||
|
for _ in 0..2 {
|
||||||
|
const COUNT: usize = 40_000;
|
||||||
|
|
||||||
|
let mut tx = BufferedUarteTx::new(&mut p.UARTE1, Irqs, &mut p.P1_02, config.clone(), &mut tx_buffer);
|
||||||
|
|
||||||
|
let mut rx = BufferedUarteRx::new(
|
||||||
|
&mut p.UARTE0,
|
||||||
|
&mut p.TIMER0,
|
||||||
|
&mut p.PPI_CH0,
|
||||||
|
&mut p.PPI_CH1,
|
||||||
|
&mut p.PPI_GROUP0,
|
||||||
|
Irqs,
|
||||||
|
&mut p.P1_03,
|
||||||
|
config.clone(),
|
||||||
|
&mut rx_buffer,
|
||||||
|
);
|
||||||
|
|
||||||
|
let tx_fut = async {
|
||||||
|
info!("tx initialized!");
|
||||||
|
|
||||||
|
let mut tx_buf = [0; 215];
|
||||||
|
let mut i = 0;
|
||||||
|
while i < COUNT {
|
||||||
|
let n = tx_buf.len().min(COUNT - i);
|
||||||
|
let tx_buf = &mut tx_buf[..n];
|
||||||
|
for (j, b) in tx_buf.iter_mut().enumerate() {
|
||||||
|
*b = (i + j) as u8;
|
||||||
|
}
|
||||||
|
let n = unwrap!(tx.write(tx_buf).await);
|
||||||
|
i += n;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let rx_fut = async {
|
||||||
|
info!("rx initialized!");
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
while i < COUNT {
|
||||||
|
let buf = unwrap!(rx.fill_buf().await);
|
||||||
|
|
||||||
|
for &b in buf {
|
||||||
|
assert_eq!(b, i as u8);
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let n = buf.len();
|
||||||
|
rx.consume(n);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
join(rx_fut, tx_fut).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("Test OK");
|
||||||
|
cortex_m::asm::bkpt();
|
||||||
|
}
|
Loading…
Reference in a new issue