diff --git a/libs/xous-bio-bdma/src/bio_tests/dma.rs b/libs/xous-bio-bdma/src/bio_tests/dma.rs index 63e5a6614..fbc3b5775 100644 --- a/libs/xous-bio-bdma/src/bio_tests/dma.rs +++ b/libs/xous-bio-bdma/src/bio_tests/dma.rs @@ -41,9 +41,17 @@ fn cache_flush() { /// Single-core, simple bus copy between main memory and peripheral space segments /// Less efficient than multi-core implementation, but uses less cores -pub fn dma_basic() -> usize { +/// +/// The `concurrent` flag causes the CPU to do concurrent traffic during the test to +/// exercise contention on AXI bus. +pub fn dma_basic(concurrent: bool) -> usize { + const TEST_LEN: usize = 64; let mut passing = 0; - print!("DMA basic\r"); + if !concurrent { + print!("DMA basic\r"); + } else { + print!("DMA cpu+dma concurrent\r"); + } // clear prior test config state let mut test_cfg = CSR::new(utra::csrtest::HW_CSRTEST_BASE as *mut u32); test_cfg.wo(utra::csrtest::WTEST, 0); @@ -62,31 +70,35 @@ pub fn dma_basic() -> usize { // start the machine bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x111); - let mut main_mem_src: [u32; 16] = [0u32; 16]; - let mut main_mem_dst: [u32; 16] = [0u32; 16]; + let mut main_mem_src: [u32; TEST_LEN] = [0u32; TEST_LEN]; + let mut main_mem_dst: [u32; TEST_LEN] = [0u32; TEST_LEN]; // just conjure some locations out of thin air. Yes, these are weird addresses in decimal, meant to // just poke into some not page aligned location in IFRAM. let ifram_src = - unsafe { core::slice::from_raw_parts_mut((utralib::HW_IFRAM0_MEM + 8200) as *mut u32, 16) }; + unsafe { core::slice::from_raw_parts_mut((utralib::HW_IFRAM0_MEM + 8200) as *mut u32, TEST_LEN) }; let ifram_dst = - unsafe { core::slice::from_raw_parts_mut((utralib::HW_IFRAM1_MEM + 10000) as *mut u32, 16) }; + unsafe { core::slice::from_raw_parts_mut((utralib::HW_IFRAM1_MEM + 10000) as *mut u32, TEST_LEN) }; ifram_src.fill(0); ifram_dst.fill(0); - passing += basic_u32(&mut bio_ss, &mut main_mem_src, &mut main_mem_dst, 0, "Main->main"); + passing += basic_u32(&mut bio_ss, &mut main_mem_src, &mut main_mem_dst, 0, "Main->main", concurrent); main_mem_src.fill(0); main_mem_dst.fill(0); - passing += basic_u32(&mut bio_ss, ifram_src, &mut main_mem_dst, 0x40, "ifram0->main"); + passing += basic_u32(&mut bio_ss, ifram_src, &mut main_mem_dst, 0x40, "ifram0->main", concurrent); ifram_src.fill(0); main_mem_dst.fill(0); - passing += basic_u32(&mut bio_ss, &mut main_mem_src, ifram_dst, 0x80, "Main->ifram1"); + passing += basic_u32(&mut bio_ss, &mut main_mem_src, ifram_dst, 0x80, "Main->ifram1", concurrent); main_mem_src.fill(0); ifram_dst.fill(0); - passing += basic_u32(&mut bio_ss, ifram_src, ifram_dst, 0xC0, "ifram0->ifram1"); + passing += basic_u32(&mut bio_ss, ifram_src, ifram_dst, 0xC0, "ifram0->ifram1", concurrent); - print!("DMA basic done.\r"); + if !concurrent { + print!("DMA basic done.\r"); + } else { + print!("DMA cpu+dma concurrent done.\r"); + } passing } @@ -96,6 +108,7 @@ fn basic_u32( dst: &mut [u32], seed: u32, name: &'static str, + concurrent: bool, ) -> usize { assert!(src.len() == dst.len()); let mut tp = TestPattern::new(Some(seed)); @@ -105,17 +118,41 @@ fn basic_u32( for d in dst.iter_mut() { *d = tp.next(); } + let mut pass = 1; bio_ss.bio.wo(utra::bio_bdma::SFR_TXF2, src.as_ptr() as u32); // src address bio_ss.bio.wo(utra::bio_bdma::SFR_TXF1, dst.as_ptr() as u32); // dst address - bio_ss.bio.wo(utra::bio_bdma::SFR_TXF0, (src.len() * size_of::()) as u32); // bytes to move - while bio_ss.bio.r(utra::bio_bdma::SFR_EVENT_STATUS) & 0x1 == 0 {} - cache_flush(); - let mut pass = 1; - for (i, &d) in src.iter().enumerate() { - let rbk = unsafe { dst.as_ptr().add(i).read_volatile() }; - if rbk != d { - print!("{} DMA err @{}, {:x} rbk: {:x}\r", name, i, d, rbk); - pass = 0; + if !concurrent { + bio_ss.bio.wo(utra::bio_bdma::SFR_TXF0, (src.len() * size_of::()) as u32); // bytes to move + while bio_ss.bio.r(utra::bio_bdma::SFR_EVENT_STATUS) & 0x1 == 0 {} + cache_flush(); + for (i, &d) in src.iter().enumerate() { + let rbk = unsafe { dst.as_ptr().add(i).read_volatile() }; + if rbk != d { + print!("{} DMA err @{}, {:x} rbk: {:x}\r", name, i, d, rbk); + pass = 0; + } + } + } else { + // this flushes any read data from the cache, so that the CPU copy is forced to fetch + // the data from memory + cache_flush(); + let len = src.len(); + // note this kicks off a copy of only the first half of the slice + bio_ss.bio.wo(utra::bio_bdma::SFR_TXF0, (src.len() * size_of::()) as u32 / 2); + // the second half of the slice is copied by the CPU, simultaneously + dst[len / 2..].copy_from_slice(&src[len / 2..]); + cache_flush(); + // run it twice to generate more traffic + dst[len / 2..].copy_from_slice(&src[len / 2..]); + // ... and wait for DMA to finish, if it has not already + while bio_ss.bio.r(utra::bio_bdma::SFR_EVENT_STATUS) & 0x1 == 0 {} + cache_flush(); + for (i, &d) in src.iter().enumerate() { + let rbk = unsafe { dst.as_ptr().add(i).read_volatile() }; + if rbk != d { + print!("(c) {} DMA err @{}, {:x} rbk: {:x}\r", name, i, d, rbk); + pass = 0; + } } } pass diff --git a/libs/xous-bio-bdma/src/bio_tests/units.rs b/libs/xous-bio-bdma/src/bio_tests/units.rs index 9522fb499..0336f7c77 100644 --- a/libs/xous-bio-bdma/src/bio_tests/units.rs +++ b/libs/xous-bio-bdma/src/bio_tests/units.rs @@ -25,14 +25,17 @@ pub fn hello_world() -> usize { } #[rustfmt::skip] bio_code!(hello_world_code, HELLO_START, HELLO_END, - "add x1, zero, 0x10", - // "li x2, 0xFFFFFFFF", // set all pins to outputs - // "mv x24, x2", - "0:", - "add x1, x1, 0x1", - "mv x21, x1", + "li t0, 0xFFFFFFFF", // set all pins to outputs + "mv x24, t0", + "li a0, 1", + "20:", + "mv x21, a0", + "slli a0, a0, 1", + "bne a0, zero, 21f", + "li a0, 1", // if a0 is 0, reset its value to 1 + "21:", "mv x20, zero", - "j 0b", + "j 20b", "nop" ); @@ -397,6 +400,9 @@ pub fn host_fifo_tests() -> usize { } #[rustfmt::skip] bio_code!(fifo_host0_bitbang, FIFO_HOST0_BITBANG_START, FIFO_HOST0_BITBANG_END, + "li t0, 0xFFFFFFFF", + "mv x26, t0", // ensure mask is disabled + "mv x25, t0", // set all pins to inputs "90:", "mv x21, x16", "mv x20, zero",