[][src]Struct sunrise_libutils::io::mmio::Mmio

#[repr(packed)]pub struct Mmio<T> {
    value: MaybeUninit<T>,
}

A value that can only be accessed volatilely.

Generally used behind a pointer, as such:

use sunrise_libutils::io::{Io, Mmio};

/// Layout of Mmio registers of a random device.
///
/// This struct is repr packed so its field are not re-ordered,
/// and no undesired padding is added.
///
/// Be careful though, in rust reading an unaligned field is undefined behaviour,
/// so you must make sure it is correctly aligned.
#[repr(packed)]
struct DeviceFooRegisters {
    register_control: Mmio<u16>,
    register_command: Mmio<u16>,
}


let device_address = 0xabcdef00 as *mut DeviceFooRegisters;

let device: &mut DeviceFooRegisters = unsafe {
    // safety: make sure that device_address is valid and we're not violating
    // rust's aliasing rules.
    device_address.as_mut().unwrap()
};

let status = device.register_control.read();
device.register_command.write(0xF00D);

Fields

value: MaybeUninit<T>

The value. Can only be accessed through .read()

Implementations

impl<T> Mmio<T>[src]

pub fn new() -> Self[src]

Create a new Mmio without initializing.

Mostly unused, you would almost always get a Mmio by casting a raw pointer to a &mut Mmio.

Trait Implementations

impl<T> Debug for Mmio<T> where
    T: Copy + Debug
[src]

fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>[src]

Debug volatilely reads value.

impl<T> Io for Mmio<T> where
    T: Copy
[src]

type Value = T

The width of the IO access. Should be a primitive type like u8, u16, u32... Read more

fn read(&self) -> T[src]

Performs a volatile read of the value.

fn write(&mut self, value: T)[src]

Performs a volatile write of the value.

Auto Trait Implementations

impl<T> Send for Mmio<T> where
    T: Send

impl<T> Sync for Mmio<T> where
    T: Sync

impl<T> Unpin for Mmio<T> where
    T: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.