jelly-mem_access

Crates.iojelly-mem_access
lib.rsjelly-mem_access
version0.2.0
sourcesrc
created_at2021-12-18 02:07:15.784288
updated_at2024-07-15 10:07:19.128188
descriptionMemory Mapped I/O access library
homepage
repositoryhttps://github.com/ryuz/jelly-mem_access
max_upload_size
id499887
size88,283
Ryuji Fuchikami (@Ryuz88) (ryuz)

documentation

README

Memory Mapped I/O Access Library

Crates.io MIT licensed

Overview

This library is designed for accessing memory-mapped I/O.

It assists with register access using UIO (User Space I/O) and offers bare-metal access with no_std.

It also assists access using u-dma-buf.

MMIO(Memory Mapped I/O)

MMIO access in bare-metal programming can be written as follows:

    type RegisterWordSize = u64;
    let mmio_acc = MmioAccessor::<RegisterWordSize>::new(0xffff0000, 0x10000);
    mmio_acc.write_mem_u8(0x00, 0x12);        // addr : 0xffff0000
    mmio_acc.write_mem_u16(0x02, 0x1234);     // addr : 0xffff0002
    mmio_acc.write_reg_u32(0x10, 0x12345678); // addr : 0xffff0080 <= 0x10 * size_of<RegisterWordSize>()
    mmio_acc.read_reg_u32(0x10);              // addr : 0xffff0080 <= 0x10 * size_of<RegisterWordSize>()

UIO(Userspace I/O)

UIO access in Linux programming can be written as follows:

    type RegisterWordSize = usize;
    let uio_num = 1;  // ex.) /dev/uio1
    let uio_acc = MmioAccessor::<RegisterWordSize>::new(uio_num);
    uio_acc.set_irq_enable(true);
    uio_acc.write_reg_u32(0x00, 0x1);
    uio_acc.wait_irq();

You can also open it by specifying a name obtained from /sys/class/uio:

    let uio_acc = MmioAccessor::<u32>::new_with_name("uio-sample");

u-dma-buf

u-dma-buf access in Linux programming can be written as follows:

    let udmabuf_num = 4;  // ex.) /dev/udmabuf4
    let udmabuf_acc = UdmabufAccessor::<usize>::new("udmabuf4", false).unwrap();
    println!("udmabuf4 phys addr : 0x{:x}", udmabuf_acc.phys_addr());
    println!("udmabuf4 size      : 0x{:x}", udmabuf_acc.size());
    udmabuf_acc.write_mem_u32(0x00, 0x1234);
Commit count: 1914

cargo fmt