mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 08:12:30 +00:00
tests/nrf: generalize buffereduart tests for all chips.
This commit is contained in:
parent
1ce9418bca
commit
b870e7f257
@ -32,12 +32,13 @@ portable-atomic = { version = "1.6.0" }
|
||||
[features]
|
||||
nrf51422 = ["embassy-nrf/nrf51", "portable-atomic/unsafe-assume-single-core"]
|
||||
nrf52832 = ["embassy-nrf/nrf52832", "easydma"]
|
||||
nrf52833 = ["embassy-nrf/nrf52833", "easydma"]
|
||||
nrf52840 = ["embassy-nrf/nrf52840", "easydma"]
|
||||
nrf5340 = ["embassy-nrf/nrf5340-app-s", "easydma"]
|
||||
nrf9160 = ["embassy-nrf/nrf9160-s", "easydma"]
|
||||
nrf52833 = ["embassy-nrf/nrf52833", "easydma", "two-uarts"]
|
||||
nrf52840 = ["embassy-nrf/nrf52840", "easydma", "two-uarts"]
|
||||
nrf5340 = ["embassy-nrf/nrf5340-app-s", "easydma", "two-uarts"]
|
||||
nrf9160 = ["embassy-nrf/nrf9160-s", "easydma", "two-uarts"]
|
||||
|
||||
easydma = []
|
||||
two-uarts = []
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
@ -53,22 +54,22 @@ overflow-checks = false
|
||||
[[bin]]
|
||||
name = "buffered_uart"
|
||||
path = "src/bin/buffered_uart.rs"
|
||||
required-features = [ "nrf52840",]
|
||||
required-features = [ "easydma",]
|
||||
|
||||
[[bin]]
|
||||
name = "buffered_uart_full"
|
||||
path = "src/bin/buffered_uart_full.rs"
|
||||
required-features = [ "nrf52840",]
|
||||
required-features = [ "easydma",]
|
||||
|
||||
[[bin]]
|
||||
name = "buffered_uart_halves"
|
||||
path = "src/bin/buffered_uart_halves.rs"
|
||||
required-features = [ "nrf52840",]
|
||||
required-features = [ "two-uarts",]
|
||||
|
||||
[[bin]]
|
||||
name = "buffered_uart_spam"
|
||||
path = "src/bin/buffered_uart_spam.rs"
|
||||
required-features = [ "nrf52840",]
|
||||
required-features = [ "two-uarts",]
|
||||
|
||||
[[bin]]
|
||||
name = "ethernet_enc28j60_perf"
|
||||
|
@ -1,19 +1,17 @@
|
||||
// required-features: nrf52840
|
||||
// required-features: easydma
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
teleprobe_meta::target!(b"nrf52840-dk");
|
||||
|
||||
use defmt::{assert_eq, *};
|
||||
#[path = "../common.rs"]
|
||||
mod common;
|
||||
|
||||
use defmt::{panic, *};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_futures::join::join;
|
||||
use embassy_nrf::buffered_uarte::{self, BufferedUarte};
|
||||
use embassy_nrf::{bind_interrupts, peripherals, uarte};
|
||||
use embassy_nrf::{peripherals, uarte};
|
||||
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 mut p = embassy_nrf::init(Default::default());
|
||||
@ -27,14 +25,14 @@ async fn main(_spawner: Spawner) {
|
||||
// test teardown + recreate of the buffereduarte works fine.
|
||||
for _ in 0..2 {
|
||||
let u = BufferedUarte::new(
|
||||
&mut p.UARTE0,
|
||||
&mut peri!(p, UART0),
|
||||
&mut p.TIMER0,
|
||||
&mut p.PPI_CH0,
|
||||
&mut p.PPI_CH1,
|
||||
&mut p.PPI_GROUP0,
|
||||
Irqs,
|
||||
&mut p.P1_03,
|
||||
&mut p.P1_02,
|
||||
irqs!(UART0_BUFFERED),
|
||||
&mut peri!(p, PIN_A),
|
||||
&mut peri!(p, PIN_B),
|
||||
config.clone(),
|
||||
&mut rx_buffer,
|
||||
&mut tx_buffer,
|
||||
@ -65,7 +63,9 @@ async fn main(_spawner: Spawner) {
|
||||
let buf = unwrap!(rx.fill_buf().await);
|
||||
|
||||
for &b in buf {
|
||||
assert_eq!(b, i as u8);
|
||||
if b != i as u8 {
|
||||
panic!("mismatch {} vs {}, index {}", b, i as u8, i);
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,17 @@
|
||||
// required-features: nrf52840
|
||||
// required-features: easydma
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
teleprobe_meta::target!(b"nrf52840-dk");
|
||||
|
||||
#[path = "../common.rs"]
|
||||
mod common;
|
||||
|
||||
use defmt::{assert_eq, *};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::buffered_uarte::{self, BufferedUarte};
|
||||
use embassy_nrf::{bind_interrupts, peripherals, uarte};
|
||||
use embassy_nrf::{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());
|
||||
@ -21,18 +19,18 @@ async fn main(_spawner: Spawner) {
|
||||
config.parity = uarte::Parity::EXCLUDED;
|
||||
config.baudrate = uarte::Baudrate::BAUD1M;
|
||||
|
||||
let mut tx_buffer = [0u8; 1024];
|
||||
let mut rx_buffer = [0u8; 1024];
|
||||
let mut tx_buffer = [0u8; 500];
|
||||
let mut rx_buffer = [0u8; 500];
|
||||
|
||||
let u = BufferedUarte::new(
|
||||
p.UARTE0,
|
||||
peri!(p, UART0),
|
||||
p.TIMER0,
|
||||
p.PPI_CH0,
|
||||
p.PPI_CH1,
|
||||
p.PPI_GROUP0,
|
||||
Irqs,
|
||||
p.P1_03,
|
||||
p.P1_02,
|
||||
irqs!(UART0_BUFFERED),
|
||||
peri!(p, PIN_A),
|
||||
peri!(p, PIN_B),
|
||||
config.clone(),
|
||||
&mut rx_buffer,
|
||||
&mut tx_buffer,
|
||||
@ -42,22 +40,22 @@ async fn main(_spawner: Spawner) {
|
||||
|
||||
let (mut rx, mut tx) = u.split();
|
||||
|
||||
let mut buf = [0; 1024];
|
||||
let mut buf = [0; 500];
|
||||
for (j, b) in buf.iter_mut().enumerate() {
|
||||
*b = j as u8;
|
||||
}
|
||||
|
||||
// Write 1024b. This causes the rx buffer to get exactly full.
|
||||
// Write 500b. This causes the rx buffer to get exactly full.
|
||||
unwrap!(tx.write_all(&buf).await);
|
||||
unwrap!(tx.flush().await);
|
||||
|
||||
// Read those 1024b.
|
||||
// Read those 500b.
|
||||
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.
|
||||
// The buffer should now be unclogged. Write 500b again.
|
||||
unwrap!(tx.write_all(&buf).await);
|
||||
unwrap!(tx.flush().await);
|
||||
|
||||
|
@ -1,20 +1,17 @@
|
||||
// required-features: nrf52840
|
||||
// required-features: two-uarts
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
teleprobe_meta::target!(b"nrf52840-dk");
|
||||
|
||||
#[path = "../common.rs"]
|
||||
mod common;
|
||||
|
||||
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 embassy_nrf::{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());
|
||||
@ -29,16 +26,22 @@ async fn main(_spawner: Spawner) {
|
||||
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 tx = BufferedUarteTx::new(
|
||||
&mut peri!(p, UART1),
|
||||
irqs!(UART1_BUFFERED),
|
||||
&mut peri!(p, PIN_A),
|
||||
config.clone(),
|
||||
&mut tx_buffer,
|
||||
);
|
||||
|
||||
let mut rx = BufferedUarteRx::new(
|
||||
&mut p.UARTE0,
|
||||
&mut peri!(p, UART0),
|
||||
&mut p.TIMER0,
|
||||
&mut p.PPI_CH0,
|
||||
&mut p.PPI_CH1,
|
||||
&mut p.PPI_GROUP0,
|
||||
Irqs,
|
||||
&mut p.P1_03,
|
||||
irqs!(UART0_BUFFERED),
|
||||
&mut peri!(p, PIN_B),
|
||||
config.clone(),
|
||||
&mut rx_buffer,
|
||||
);
|
||||
|
@ -1,26 +1,23 @@
|
||||
// required-features: nrf52840
|
||||
// required-features: two-uarts
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
teleprobe_meta::target!(b"nrf52840-dk");
|
||||
|
||||
#[path = "../common.rs"]
|
||||
mod common;
|
||||
|
||||
use core::mem;
|
||||
use core::ptr::NonNull;
|
||||
|
||||
use defmt::{assert_eq, *};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::buffered_uarte::{self, BufferedUarte};
|
||||
use embassy_nrf::buffered_uarte::{self, BufferedUarteRx};
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_nrf::ppi::{Event, Ppi, Task};
|
||||
use embassy_nrf::uarte::Uarte;
|
||||
use embassy_nrf::{bind_interrupts, pac, peripherals, uarte};
|
||||
use embassy_nrf::uarte::UarteTx;
|
||||
use embassy_nrf::{pac, peripherals, uarte};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;
|
||||
UARTE1 => uarte::InterruptHandler<peripherals::UARTE1>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut p = embassy_nrf::init(Default::default());
|
||||
@ -28,23 +25,20 @@ async fn main(_spawner: Spawner) {
|
||||
config.parity = uarte::Parity::EXCLUDED;
|
||||
config.baudrate = uarte::Baudrate::BAUD1M;
|
||||
|
||||
let mut tx_buffer = [0u8; 1024];
|
||||
let mut rx_buffer = [0u8; 1024];
|
||||
|
||||
mem::forget(Output::new(&mut p.P1_02, Level::High, OutputDrive::Standard));
|
||||
mem::forget(Output::new(&mut peri!(p, PIN_A), Level::High, OutputDrive::Standard));
|
||||
|
||||
let mut u = BufferedUarte::new(
|
||||
p.UARTE0,
|
||||
let mut u = BufferedUarteRx::new(
|
||||
peri!(p, UART0),
|
||||
p.TIMER0,
|
||||
p.PPI_CH0,
|
||||
p.PPI_CH1,
|
||||
p.PPI_GROUP0,
|
||||
Irqs,
|
||||
p.P1_03,
|
||||
p.P1_04,
|
||||
irqs!(UART0_BUFFERED),
|
||||
peri!(p, PIN_B),
|
||||
config.clone(),
|
||||
&mut rx_buffer,
|
||||
&mut tx_buffer,
|
||||
);
|
||||
|
||||
info!("uarte initialized!");
|
||||
@ -55,7 +49,7 @@ async fn main(_spawner: Spawner) {
|
||||
// Tx spam in a loop.
|
||||
const NSPAM: usize = 17;
|
||||
static mut TX_BUF: [u8; NSPAM] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
|
||||
let _spam = Uarte::new(p.UARTE1, Irqs, p.P1_01, p.P1_02, config.clone());
|
||||
let _spam = UarteTx::new(peri!(p, UART1), irqs!(UART1), peri!(p, PIN_A), config.clone());
|
||||
let spam_peri: pac::UARTE1 = unsafe { mem::transmute(()) };
|
||||
let event = unsafe { Event::new_unchecked(NonNull::new_unchecked(&spam_peri.events_endtx as *const _ as _)) };
|
||||
let task = unsafe { Task::new_unchecked(NonNull::new_unchecked(&spam_peri.tasks_starttx as *const _ as _)) };
|
||||
|
@ -50,16 +50,53 @@ macro_rules! define_peris {
|
||||
define_peris!(PIN_A = P0_13, PIN_B = P0_14,);
|
||||
|
||||
#[cfg(feature = "nrf52832")]
|
||||
define_peris!(PIN_A = P0_11, PIN_B = P0_12,);
|
||||
define_peris!(
|
||||
PIN_A = P0_11, PIN_B = P0_12,
|
||||
UART0 = UARTE0,
|
||||
@irq UART0 = {UARTE0_UART0 => uarte::InterruptHandler<peripherals::UARTE0>;},
|
||||
@irq UART0_BUFFERED = {UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;},
|
||||
);
|
||||
|
||||
#[cfg(feature = "nrf52833")]
|
||||
define_peris!(PIN_A = P1_01, PIN_B = P1_02,);
|
||||
define_peris!(
|
||||
PIN_A = P1_01, PIN_B = P1_02,
|
||||
UART0 = UARTE0,
|
||||
UART1 = UARTE1,
|
||||
@irq UART0 = {UARTE0_UART0 => uarte::InterruptHandler<peripherals::UARTE0>;},
|
||||
@irq UART1 = {UARTE1 => uarte::InterruptHandler<peripherals::UARTE1>;},
|
||||
@irq UART0_BUFFERED = {UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;},
|
||||
@irq UART1_BUFFERED = {UARTE1 => buffered_uarte::InterruptHandler<peripherals::UARTE1>;},
|
||||
);
|
||||
|
||||
#[cfg(feature = "nrf52840")]
|
||||
define_peris!(PIN_A = P1_02, PIN_B = P1_03,);
|
||||
define_peris!(
|
||||
PIN_A = P1_02, PIN_B = P1_03,
|
||||
UART0 = UARTE0,
|
||||
UART1 = UARTE1,
|
||||
@irq UART0 = {UARTE0_UART0 => uarte::InterruptHandler<peripherals::UARTE0>;},
|
||||
@irq UART1 = {UARTE1 => uarte::InterruptHandler<peripherals::UARTE1>;},
|
||||
@irq UART0_BUFFERED = {UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;},
|
||||
@irq UART1_BUFFERED = {UARTE1 => buffered_uarte::InterruptHandler<peripherals::UARTE1>;},
|
||||
);
|
||||
|
||||
#[cfg(feature = "nrf5340")]
|
||||
define_peris!(PIN_A = P1_00, PIN_B = P1_01,);
|
||||
define_peris!(
|
||||
PIN_A = P1_08, PIN_B = P1_09,
|
||||
UART0 = SERIAL0,
|
||||
UART1 = SERIAL1,
|
||||
@irq UART0 = {SERIAL0 => uarte::InterruptHandler<peripherals::SERIAL0>;},
|
||||
@irq UART1 = {SERIAL1 => uarte::InterruptHandler<peripherals::SERIAL1>;},
|
||||
@irq UART0_BUFFERED = {SERIAL0 => buffered_uarte::InterruptHandler<peripherals::SERIAL0>;},
|
||||
@irq UART1_BUFFERED = {SERIAL1 => buffered_uarte::InterruptHandler<peripherals::SERIAL1>;},
|
||||
);
|
||||
|
||||
#[cfg(feature = "nrf9160")]
|
||||
define_peris!(PIN_A = P0_00, PIN_B = P0_01,);
|
||||
define_peris!(
|
||||
PIN_A = P0_00, PIN_B = P0_01,
|
||||
UART0 = SERIAL0,
|
||||
UART1 = SERIAL1,
|
||||
@irq UART0 = {UARTE0_SPIM0_SPIS0_TWIM0_TWIS0 => uarte::InterruptHandler<peripherals::SERIAL0>;},
|
||||
@irq UART1 = {UARTE1_SPIM1_SPIS1_TWIM1_TWIS1 => uarte::InterruptHandler<peripherals::SERIAL1>;},
|
||||
@irq UART0_BUFFERED = {UARTE0_SPIM0_SPIS0_TWIM0_TWIS0 => buffered_uarte::InterruptHandler<peripherals::SERIAL0>;},
|
||||
@irq UART1_BUFFERED = {UARTE1_SPIM1_SPIS1_TWIM1_TWIS1 => buffered_uarte::InterruptHandler<peripherals::SERIAL1>;},
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user