aboutsummaryrefslogtreecommitdiff
path: root/examples/src/bin/dma_scatter_gather.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/src/bin/dma_scatter_gather.rs')
-rw-r--r--examples/src/bin/dma_scatter_gather.rs42
1 files changed, 21 insertions, 21 deletions
diff --git a/examples/src/bin/dma_scatter_gather.rs b/examples/src/bin/dma_scatter_gather.rs
index d78605acc..b5ae00057 100644
--- a/examples/src/bin/dma_scatter_gather.rs
+++ b/examples/src/bin/dma_scatter_gather.rs
@@ -13,12 +13,12 @@
13#![no_main] 13#![no_main]
14 14
15use core::sync::atomic::{AtomicBool, Ordering}; 15use core::sync::atomic::{AtomicBool, Ordering};
16
16use embassy_executor::Spawner; 17use embassy_executor::Spawner;
17use embassy_mcxa::clocks::config::Div8; 18use embassy_mcxa::clocks::config::Div8;
18use embassy_mcxa::dma::{self, DmaChannel, Tcd}; 19use embassy_mcxa::dma::{self, DmaChannel, Tcd};
19use embassy_mcxa::bind_interrupts;
20use embassy_mcxa::lpuart::{Blocking, Config, Lpuart, LpuartTx}; 20use embassy_mcxa::lpuart::{Blocking, Config, Lpuart, LpuartTx};
21use embassy_mcxa::pac; 21use embassy_mcxa::{bind_interrupts, pac};
22use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; 22use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
23 23
24// Source and destination buffers 24// Source and destination buffers
@@ -29,19 +29,21 @@ static mut DST: [u32; 8] = [0; 8];
29#[repr(C, align(32))] 29#[repr(C, align(32))]
30struct TcdPool([Tcd; 2]); 30struct TcdPool([Tcd; 2]);
31 31
32static mut TCD_POOL: TcdPool = TcdPool([Tcd { 32static mut TCD_POOL: TcdPool = TcdPool(
33 saddr: 0, 33 [Tcd {
34 soff: 0, 34 saddr: 0,
35 attr: 0, 35 soff: 0,
36 nbytes: 0, 36 attr: 0,
37 slast: 0, 37 nbytes: 0,
38 daddr: 0, 38 slast: 0,
39 doff: 0, 39 daddr: 0,
40 citer: 0, 40 doff: 0,
41 dlast_sga: 0, 41 citer: 0,
42 csr: 0, 42 dlast_sga: 0,
43 biter: 0, 43 csr: 0,
44}; 2]); 44 biter: 0,
45 }; 2],
46);
45 47
46// AtomicBool to track scatter/gather completion 48// AtomicBool to track scatter/gather completion
47// Note: With ESG=1, DONE bit is cleared by hardware when next TCD loads, 49// Note: With ESG=1, DONE bit is cleared by hardware when next TCD loads,
@@ -53,7 +55,9 @@ static TRANSFER_DONE: AtomicBool = AtomicBool::new(false);
53// (delegates to HAL + sets a flag) and the main task does the actual processing 55// (delegates to HAL + sets a flag) and the main task does the actual processing
54pub struct ScatterGatherDmaHandler; 56pub struct ScatterGatherDmaHandler;
55 57
56impl embassy_mcxa::interrupt::typelevel::Handler<embassy_mcxa::interrupt::typelevel::DMA_CH0> for ScatterGatherDmaHandler { 58impl embassy_mcxa::interrupt::typelevel::Handler<embassy_mcxa::interrupt::typelevel::DMA_CH0>
59 for ScatterGatherDmaHandler
60{
57 unsafe fn on_interrupt() { 61 unsafe fn on_interrupt() {
58 // Delegate to HAL's on_interrupt() which clears INT flag and wakes wakers 62 // Delegate to HAL's on_interrupt() which clears INT flag and wakes wakers
59 dma::on_interrupt(0); 63 dma::on_interrupt(0);
@@ -161,10 +165,7 @@ async fn main(_spawner: Spawner) {
161 // TCD0 transfers first half (SRC[0..4] -> DST[0..4]), then loads TCD1. 165 // TCD0 transfers first half (SRC[0..4] -> DST[0..4]), then loads TCD1.
162 // TCD1 transfers second half (SRC[4..8] -> DST[4..8]), last TCD. 166 // TCD1 transfers second half (SRC[4..8] -> DST[4..8]), last TCD.
163 unsafe { 167 unsafe {
164 let tcds = core::slice::from_raw_parts_mut( 168 let tcds = core::slice::from_raw_parts_mut(core::ptr::addr_of_mut!(TCD_POOL.0) as *mut Tcd, 2);
165 core::ptr::addr_of_mut!(TCD_POOL.0) as *mut Tcd,
166 2,
167 );
168 let src_ptr = core::ptr::addr_of!(SRC) as *const u32; 169 let src_ptr = core::ptr::addr_of!(SRC) as *const u32;
169 let dst_ptr = core::ptr::addr_of_mut!(DST) as *mut u32; 170 let dst_ptr = core::ptr::addr_of_mut!(DST) as *mut u32;
170 171
@@ -262,4 +263,3 @@ async fn main(_spawner: Spawner) {
262 cortex_m::asm::wfe(); 263 cortex_m::asm::wfe();
263 } 264 }
264} 265}
265