mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-27 04:10:28 +00:00
DMA test: Avoid starving out thread-mode executor (#3064)
* Avoid looping without delay * Avoid starving out thread-mode executor * Clean up a bit
This commit is contained in:
parent
e513f1ba8a
commit
6aa17819a5
@ -10,7 +10,7 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use embassy_time::{Duration, Instant, Ticker};
|
||||
use embassy_time::{Duration, Instant, Timer};
|
||||
use esp_hal::{
|
||||
dma::{DmaRxBuf, DmaTxBuf},
|
||||
dma_buffers,
|
||||
@ -37,13 +37,12 @@ macro_rules! mk_static {
|
||||
}};
|
||||
}
|
||||
|
||||
static STOP_INTERRUPT_TASK: AtomicBool = AtomicBool::new(false);
|
||||
static INTERRUPT_TASK_WORKING: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
#[cfg(any(esp32, esp32s2, esp32s3))]
|
||||
#[embassy_executor::task]
|
||||
async fn interrupt_driven_task(spi: esp_hal::spi::master::SpiDma<'static, Blocking>) {
|
||||
let mut ticker = Ticker::every(Duration::from_millis(1));
|
||||
|
||||
let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(128);
|
||||
let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap();
|
||||
let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap();
|
||||
@ -53,29 +52,35 @@ async fn interrupt_driven_task(spi: esp_hal::spi::master::SpiDma<'static, Blocki
|
||||
loop {
|
||||
let mut buffer: [u8; 8] = [0; 8];
|
||||
|
||||
INTERRUPT_TASK_WORKING.fetch_not(portable_atomic::Ordering::Release);
|
||||
INTERRUPT_TASK_WORKING.store(true, portable_atomic::Ordering::Relaxed);
|
||||
spi.transfer_in_place_async(&mut buffer).await.unwrap();
|
||||
INTERRUPT_TASK_WORKING.fetch_not(portable_atomic::Ordering::Acquire);
|
||||
INTERRUPT_TASK_WORKING.store(false, portable_atomic::Ordering::Relaxed);
|
||||
|
||||
ticker.next().await;
|
||||
if STOP_INTERRUPT_TASK.load(portable_atomic::Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
|
||||
Timer::after(Duration::from_millis(1)).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(esp32, esp32s2, esp32s3)))]
|
||||
#[embassy_executor::task]
|
||||
async fn interrupt_driven_task(i2s_tx: esp_hal::i2s::master::I2s<'static, Blocking>) {
|
||||
let mut ticker = Ticker::every(Duration::from_millis(1));
|
||||
|
||||
let mut i2s_tx = i2s_tx.into_async().i2s_tx.build();
|
||||
|
||||
loop {
|
||||
let mut buffer: [u8; 8] = [0; 8];
|
||||
|
||||
INTERRUPT_TASK_WORKING.fetch_not(portable_atomic::Ordering::Release);
|
||||
INTERRUPT_TASK_WORKING.store(true, portable_atomic::Ordering::Relaxed);
|
||||
i2s_tx.write_dma_async(&mut buffer).await.unwrap();
|
||||
INTERRUPT_TASK_WORKING.fetch_not(portable_atomic::Ordering::Acquire);
|
||||
INTERRUPT_TASK_WORKING.store(false, portable_atomic::Ordering::Relaxed);
|
||||
|
||||
ticker.next().await;
|
||||
if STOP_INTERRUPT_TASK.load(portable_atomic::Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
|
||||
Timer::after(Duration::from_millis(1)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,13 +190,15 @@ mod test {
|
||||
assert!(dst_buffer.iter().all(|&v| v == i));
|
||||
|
||||
if start.elapsed() > Duration::from_secs(1) {
|
||||
// make sure the other peripheral didn't get stuck
|
||||
while INTERRUPT_TASK_WORKING.load(portable_atomic::Ordering::Acquire) {}
|
||||
break;
|
||||
}
|
||||
|
||||
i = i.wrapping_add(1);
|
||||
}
|
||||
|
||||
// make sure the other peripheral didn't get stuck
|
||||
STOP_INTERRUPT_TASK.store(true, portable_atomic::Ordering::Relaxed);
|
||||
while INTERRUPT_TASK_WORKING.load(portable_atomic::Ordering::Relaxed) {}
|
||||
}
|
||||
|
||||
// Reproducer of https://github.com/esp-rs/esp-hal/issues/2369
|
||||
@ -320,5 +327,9 @@ mod test {
|
||||
assert_ne!(next, last, "stuck");
|
||||
last = next;
|
||||
}
|
||||
|
||||
// make sure the other peripheral didn't get stuck
|
||||
STOP_INTERRUPT_TASK.store(true, portable_atomic::Ordering::Relaxed);
|
||||
while INTERRUPT_TASK_WORKING.load(portable_atomic::Ordering::Relaxed) {}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user