#dma #alloc #collection #api #memory #flush #cache

no-std dma-api

Trait for DMA alloc and some collections

13 releases

0.2.0 Dec 10, 2024
0.1.11 Dec 3, 2024
0.1.10 Nov 26, 2024

#500 in Embedded development

Download history 316/week @ 2024-11-16 473/week @ 2024-11-23 275/week @ 2024-11-30 207/week @ 2024-12-07 45/week @ 2024-12-14 22/week @ 2024-12-21 10/week @ 2024-12-28 24/week @ 2025-01-04 76/week @ 2025-01-11 70/week @ 2025-01-18 29/week @ 2025-01-25 53/week @ 2025-02-01 29/week @ 2025-02-08

195 downloads per month
Used in 5 crates (3 directly)

MIT license

16KB
407 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.

No runtime deps

Features