esp-hal/hil-test/tests/dma_macros.rs
Dániel Buga d4e463b3ff
Slight general cleanup, enable dma-macros test, allow using virtual mem2mem channel on c2 (#2200)
* Cfg features, not devices

* Remove InterruptBinder

* Clean up allow(declare_interior_mutable_const)

* Small embassy cleanup

* Enable dma-macros for 32 and S2

* Use MEM2MEM1 on C2

* Remove esp32-specific code from test
2024-09-20 15:04:18 +00:00

205 lines
7.0 KiB
Rust

//! DMA macro tests
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
#![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)
);
}
}