esp-hal/hil-test/tests/dma_macros.rs
Sergio Gasquez Arcos b5f0246129
Reordered RX-TX pairs to be consistent (#2074)
* feat: Update rx-tx order in i2s

* feat: Update rx-tx order in dma macros

* feat: Update rx-tx order in spi

* feat: Update rx-tx order in aes

* feat: Update rx-tx order in mem2mem

* feat: Update rx-tx order in twai and split methods

* feat: Update rx-tx order in twai

* feat: Update rx-tx order in twai and uart docs

* docs: Add sentence about order

* docs: Update changelog

* feat: Update rx-tx order in embassy_interrupt_spi_dma tests

* style: Rustfmt

* docs: Migrating guide

* fix: Typo

Co-authored-by: Dániel Buga <bugadani@gmail.com>

* fix: Diff

Co-authored-by: Dániel Buga <bugadani@gmail.com>

* fix: Tests rx-tx order

* fix: Update new_with_default_pins order

* feat: Update rx/tx order in hil_test::common_test_pins!

* feat: Update dma_extmem2mem example

* fix: Revert deleted input arg

* style: rustfmt

* feat: Disable test_asymmetric_dma_transfer for S2

---------

Co-authored-by: Dániel Buga <bugadani@gmail.com>
2024-09-06 09:56:10 +00:00

205 lines
7.0 KiB
Rust

//! DMA Mem2Mem Tests
//% CHIPS: esp32s3 esp32c2 esp32c3 esp32c6 esp32h2
#![no_std]
#![no_main]
use hil_test as _;
const DATA_SIZE: usize = 1024 * 10;
pub(crate) const fn compute_size(size: usize, chunk_size: usize) -> usize {
size.div_ceil(chunk_size)
}
pub(crate) const fn compute_circular_size(size: usize, chunk_size: usize) -> usize {
if size > chunk_size * 2 {
size.div_ceil(chunk_size)
} else {
3
}
}
#[cfg(test)]
#[embedded_test::tests]
mod tests {
use defmt::assert_eq;
use super::*;
#[init]
fn init() {}
#[test]
fn test_dma_descriptors_same_size() {
use esp_hal::dma::CHUNK_SIZE;
let (rx_descriptors, tx_descriptors) = esp_hal::dma_descriptors!(DATA_SIZE);
assert_eq!(rx_descriptors.len(), tx_descriptors.len());
assert_eq!(rx_descriptors.len(), compute_size(DATA_SIZE, CHUNK_SIZE));
assert_eq!(tx_descriptors.len(), compute_size(DATA_SIZE, CHUNK_SIZE));
}
#[test]
fn test_dma_descriptors_different_size() {
use esp_hal::dma::CHUNK_SIZE;
const RX_SIZE: usize = DATA_SIZE / 2;
const TX_SIZE: usize = DATA_SIZE;
let (rx_descriptors, tx_descriptors) = esp_hal::dma_descriptors!(RX_SIZE, TX_SIZE);
assert_eq!(rx_descriptors.len(), compute_size(RX_SIZE, CHUNK_SIZE));
assert_eq!(tx_descriptors.len(), compute_size(TX_SIZE, CHUNK_SIZE));
}
#[test]
fn test_dma_circular_descriptors_same_size() {
use esp_hal::dma::CHUNK_SIZE;
let (rx_descriptors, tx_descriptors) = esp_hal::dma_circular_descriptors!(DATA_SIZE);
assert_eq!(rx_descriptors.len(), tx_descriptors.len());
assert_eq!(
rx_descriptors.len(),
compute_circular_size(DATA_SIZE, CHUNK_SIZE)
);
assert_eq!(
tx_descriptors.len(),
compute_circular_size(DATA_SIZE, CHUNK_SIZE)
);
}
#[test]
fn test_dma_circular_descriptors_different_size() {
use esp_hal::dma::CHUNK_SIZE;
const RX_SIZE: usize = DATA_SIZE / 2;
const TX_SIZE: usize = CHUNK_SIZE * 2;
let (rx_descriptors, tx_descriptors) = esp_hal::dma_circular_descriptors!(RX_SIZE, TX_SIZE);
assert_eq!(
rx_descriptors.len(),
compute_circular_size(RX_SIZE, CHUNK_SIZE)
);
assert_eq!(
tx_descriptors.len(),
compute_circular_size(TX_SIZE, CHUNK_SIZE)
);
}
#[test]
fn test_dma_buffers_same_size() {
use esp_hal::dma::CHUNK_SIZE;
let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) =
esp_hal::dma_buffers!(DATA_SIZE);
assert_eq!(rx_buffer.len(), DATA_SIZE);
assert_eq!(tx_buffer.len(), DATA_SIZE);
assert_eq!(tx_descriptors.len(), rx_descriptors.len());
assert_eq!(rx_descriptors.len(), compute_size(DATA_SIZE, CHUNK_SIZE));
assert_eq!(tx_descriptors.len(), compute_size(DATA_SIZE, CHUNK_SIZE));
}
#[test]
fn test_dma_buffers_different_size() {
use esp_hal::dma::CHUNK_SIZE;
const RX_SIZE: usize = DATA_SIZE / 2;
const TX_SIZE: usize = DATA_SIZE;
let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) =
esp_hal::dma_buffers!(RX_SIZE, TX_SIZE);
assert_eq!(rx_buffer.len(), RX_SIZE);
assert_eq!(tx_buffer.len(), TX_SIZE);
assert_eq!(rx_descriptors.len(), compute_size(RX_SIZE, CHUNK_SIZE));
assert_eq!(tx_descriptors.len(), compute_size(TX_SIZE, CHUNK_SIZE));
}
#[test]
fn test_dma_circular_buffers_same_size() {
use esp_hal::dma::CHUNK_SIZE;
let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) =
esp_hal::dma_circular_buffers!(DATA_SIZE);
assert_eq!(rx_buffer.len(), DATA_SIZE);
assert_eq!(tx_buffer.len(), DATA_SIZE);
assert_eq!(rx_descriptors.len(), tx_descriptors.len());
assert_eq!(
rx_descriptors.len(),
compute_circular_size(DATA_SIZE, CHUNK_SIZE)
);
assert_eq!(
tx_descriptors.len(),
compute_circular_size(DATA_SIZE, CHUNK_SIZE)
);
}
#[test]
fn test_dma_circular_buffers_different_size() {
use esp_hal::dma::CHUNK_SIZE;
const RX_SIZE: usize = CHUNK_SIZE * 2;
const TX_SIZE: usize = CHUNK_SIZE * 4;
let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) =
esp_hal::dma_circular_buffers!(RX_SIZE, TX_SIZE);
assert_eq!(rx_buffer.len(), RX_SIZE);
assert_eq!(tx_buffer.len(), TX_SIZE);
assert_eq!(
rx_descriptors.len(),
compute_circular_size(RX_SIZE, CHUNK_SIZE)
);
assert_eq!(
tx_descriptors.len(),
compute_circular_size(TX_SIZE, CHUNK_SIZE)
);
}
#[test]
fn test_dma_descriptors_chunk_size_same_size() {
const CHUNK_SIZE: usize = 2048;
let (rx_descriptors, tx_descriptors) =
esp_hal::dma_descriptors_chunk_size!(DATA_SIZE, CHUNK_SIZE);
assert_eq!(rx_descriptors.len(), tx_descriptors.len());
assert_eq!(rx_descriptors.len(), compute_size(DATA_SIZE, CHUNK_SIZE));
assert_eq!(tx_descriptors.len(), compute_size(DATA_SIZE, CHUNK_SIZE));
}
#[test]
fn test_dma_descriptors_chunk_size_different_size() {
const CHUNK_SIZE: usize = 2048;
const RX_SIZE: usize = DATA_SIZE / 2;
const TX_SIZE: usize = DATA_SIZE;
let (rx_descriptors, tx_descriptors) =
esp_hal::dma_descriptors_chunk_size!(RX_SIZE, TX_SIZE, CHUNK_SIZE);
assert_eq!(rx_descriptors.len(), compute_size(RX_SIZE, CHUNK_SIZE));
assert_eq!(tx_descriptors.len(), compute_size(TX_SIZE, CHUNK_SIZE));
}
#[test]
fn test_dma_circular_buffers_chunk_size_same_size() {
const CHUNK_SIZE: usize = 2048;
let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) =
esp_hal::dma_circular_buffers_chunk_size!(DATA_SIZE, CHUNK_SIZE);
assert_eq!(rx_buffer.len(), DATA_SIZE);
assert_eq!(tx_buffer.len(), DATA_SIZE);
assert_eq!(rx_descriptors.len(), tx_descriptors.len());
assert_eq!(
rx_descriptors.len(),
compute_circular_size(DATA_SIZE, CHUNK_SIZE)
);
assert_eq!(
tx_descriptors.len(),
compute_circular_size(DATA_SIZE, CHUNK_SIZE)
);
}
#[test]
fn test_dma_circular_buffers_chunk_size_different_size() {
const CHUNK_SIZE: usize = 2048;
const RX_SIZE: usize = DATA_SIZE / 2;
const TX_SIZE: usize = DATA_SIZE;
let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) =
esp_hal::dma_circular_buffers_chunk_size!(RX_SIZE, TX_SIZE, CHUNK_SIZE);
assert_eq!(rx_buffer.len(), RX_SIZE);
assert_eq!(tx_buffer.len(), TX_SIZE);
assert_eq!(
rx_descriptors.len(),
compute_circular_size(RX_SIZE, CHUNK_SIZE)
);
assert_eq!(
tx_descriptors.len(),
compute_circular_size(TX_SIZE, CHUNK_SIZE)
);
}
}