6 releases

0.3.3 Aug 18, 2021
0.3.2 Aug 4, 2021
0.3.0 Jan 29, 2021
0.2.0 Jan 26, 2021
0.1.0 Jan 24, 2021

#420 in Operating systems

Download history 28/week @ 2025-11-09 50/week @ 2025-11-16 65/week @ 2025-11-23 58/week @ 2025-11-30 41/week @ 2025-12-07 44/week @ 2025-12-14 62/week @ 2025-12-21 39/week @ 2025-12-28 35/week @ 2026-01-04 35/week @ 2026-01-11 59/week @ 2026-01-18 112/week @ 2026-01-25 48/week @ 2026-02-01 10/week @ 2026-02-08 33/week @ 2026-02-15 52/week @ 2026-02-22

158 downloads per month
Used in 3 crates (via xhci)

MIT/Apache

24KB
436 lines

accessor

GitHub Actions Crates.io Crates.io docs.rs

Accessors to access physical memory.

This crate provides accessors to values at a specific memory address. When an accessor is created, physical memory is mapped to virtual memory. The methods of the accessors can access a value at the specified physical address. Once an accessor is dropped, the mapped memory is unmapped.

This crate is intended to access memory-mapped I/O. Reading and writing are done volatilely.

The accessed type must implement Copy because reading and writing values need to copy it.

This crate is #[no_std] compatible.

use accessor::array;
use accessor::mapper::Mapper;
use accessor::single;
use core::num::NonZeroUsize;

struct M;
impl Mapper for M {
    unsafe fn map(&mut self, phys_start: usize, bytes: usize) -> NonZeroUsize {
        todo!()
    }

    fn unmap(&mut self, phys_start: usize, bytes: usize) {
        todo!()
    }
}

// Create an accessor to an i32 value at the physical address 0x1000.
let mut a = unsafe { single::ReadWrite::<i32, M>::new(0x1000, M) };

// Read a value.
a.read_volatile();

// Write a value.
a.write_volatile(3);

// Create an accessor to an array at the physical address 0x2000 of the type i32 that has 5 elements.
let mut arr = unsafe { array::ReadWrite::<i32, M>::new(0x2000, 5, M) };

// Read the 2nd element.
arr.read_volatile_at(2);

// Write 42 as the 0th element.
arr.write_volatile_at(0, 42);

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps