17 releases

0.3.1 Jul 3, 2025
0.3.0 Mar 14, 2025
0.2.2 Feb 21, 2025
0.2.0 Dec 10, 2024
0.1.10 Nov 26, 2024

#893 in Embedded development

Download history 44/week @ 2025-03-21 15/week @ 2025-03-28 7/week @ 2025-04-04 7/week @ 2025-04-11 9/week @ 2025-04-18 12/week @ 2025-04-25 16/week @ 2025-05-02 40/week @ 2025-05-09 40/week @ 2025-05-16 399/week @ 2025-05-23 75/week @ 2025-05-30 48/week @ 2025-06-06 247/week @ 2025-06-13 259/week @ 2025-06-20 182/week @ 2025-06-27 110/week @ 2025-07-04

804 downloads per month
Used in 5 crates (2 directly)

MIT license

18KB
469 lines

DMA API

Rust

Example

use dma_api::*;

// ----- Driver Side -----

// use global allocator to alloc `to device` type memory
let mut dma: DVec<u32> = DVec::zeros(10, 0x1000, Direction::ToDevice).unwrap();
// flush cache to memory.
dma.set(0, 1);

// do nothing with cache
let o = dma.get(0).unwrap();

assert_eq!(o, 1);


// ----- OS Side -----

struct Impled;

impl Impl for Impled {
    fn map(addr: std::ptr::NonNull<u8>, size: usize, direction: Direction) -> u64 {
        println!("map @{:?}, size {size:#x}, {direction:?}", addr);
        addr.as_ptr() as usize as _
    }

    fn unmap(addr: std::ptr::NonNull<u8>, size: usize) {
        println!("unmap @{:?}, size {size:#x}", addr);
    }

    fn flush(addr: std::ptr::NonNull<u8>, size: usize) {
        println!("flush @{:?}, size {size:#x}", addr);
    }

    fn invalidate(addr: std::ptr::NonNull<u8>, size: usize) {
        println!("invalidate @{:?}, size {size:#x}", addr);
    }
}

set_impl!(Impled);

// then you can do some thing with the driver.

Dependencies

~74KB