pub struct UniqueMmioPointer<'a, T>(/* private fields */)
where
T: ?Sized;Expand description
A unique owned pointer to the registers of some MMIO device.
It is guaranteed to be valid and unique; no other access to the MMIO space of the device may
happen for the lifetime 'a.
A UniqueMmioPointer may be created from a mutable reference, but this should only be used for
testing purposes, as references should never be constructed for real MMIO address space.
Implementations§
Source§impl<T> UniqueMmioPointer<'_, T>
impl<T> UniqueMmioPointer<'_, T>
Sourcepub unsafe fn read_unsafe(&mut self) -> T
pub unsafe fn read_unsafe(&mut self) -> T
Performs an MMIO read and returns the value.
If T is exactly 1, 2, 4 or 8 bytes long then this will be a single operation. Otherwise
it will be split into several, reading chunks as large as possible.
Note that this takes &mut self rather than &self because an MMIO read may cause
side-effects that change the state of the device.
§Safety
This field must be safe to perform an MMIO read from.
Source§impl<T> UniqueMmioPointer<'_, T>
impl<T> UniqueMmioPointer<'_, T>
Sourcepub unsafe fn write_unsafe(&self, value: T)
pub unsafe fn write_unsafe(&self, value: T)
Performs an MMIO write of the given value.
If T is exactly 1, 2, 4 or 8 bytes long then this will be a single operation. Otherwise
it will be split into several, writing chunks as large as possible.
§Safety
This field must be safe to perform an MMIO write to.
Source§impl<T> UniqueMmioPointer<'_, T>where
T: ?Sized,
impl<T> UniqueMmioPointer<'_, T>where
T: ?Sized,
Sourcepub const unsafe fn new(regs: NonNull<T>) -> UniqueMmioPointer<'_, T>
pub const unsafe fn new(regs: NonNull<T>) -> UniqueMmioPointer<'_, T>
Creates a new UniqueMmioPointer from a non-null raw pointer.
§Safety
regs must be a properly aligned and valid pointer to some MMIO address space of type T,
which is mapped as device memory and valid to read and write from any thread with volatile
operations. There must not be any other aliases which are used to access the same MMIO
region while this UniqueMmioPointer exists.
If T contains any fields wrapped in ReadOnly, WriteOnly or ReadWrite then they
must indeed be safe to perform MMIO reads or writes on.
Sourcepub const unsafe fn child<U>(
&mut self,
regs: NonNull<U>,
) -> UniqueMmioPointer<'_, U>where
U: ?Sized,
pub const unsafe fn child<U>(
&mut self,
regs: NonNull<U>,
) -> UniqueMmioPointer<'_, U>where
U: ?Sized,
Sourcepub const fn ptr_nonnull(&mut self) -> NonNull<T>
pub const fn ptr_nonnull(&mut self) -> NonNull<T>
Returns a NonNull<T> pointer to the MMIO registers.
Sourcepub const fn reborrow(&mut self) -> UniqueMmioPointer<'_, T>
pub const fn reborrow(&mut self) -> UniqueMmioPointer<'_, T>
Returns a new UniqueMmioPointer with a lifetime no greater than this one.
Source§impl<'a, T> UniqueMmioPointer<'a, T>where
T: ?Sized,
impl<'a, T> UniqueMmioPointer<'a, T>where
T: ?Sized,
Sourcepub const unsafe fn split_child<U>(
&mut self,
regs: NonNull<U>,
) -> UniqueMmioPointer<'a, U>where
U: ?Sized,
pub const unsafe fn split_child<U>(
&mut self,
regs: NonNull<U>,
) -> UniqueMmioPointer<'a, U>where
U: ?Sized,
Creates a new UniqueMmioPointer with the same lifetime as this one, but not tied to the
lifetime this one is borrowed for.
This is used internally by the split_fields! macro and shouldn’t be called directly.
§Safety
regs must be a properly aligned and valid pointer to some MMIO address space of type T,
within the allocation that self points to. split_child must not be called for the same
child field more than once, and the original UniqueMmioPointer must not be used after
split_child has been called for one or more of its fields.
Source§impl<T> UniqueMmioPointer<'_, ReadWrite<T>>
impl<T> UniqueMmioPointer<'_, ReadWrite<T>>
Source§impl<T> UniqueMmioPointer<'_, ReadWrite<T>>
impl<T> UniqueMmioPointer<'_, ReadWrite<T>>
Source§impl<T> UniqueMmioPointer<'_, ReadPureWrite<T>>
impl<T> UniqueMmioPointer<'_, ReadPureWrite<T>>
Source§impl<T> UniqueMmioPointer<'_, ReadOnly<T>>
impl<T> UniqueMmioPointer<'_, ReadOnly<T>>
Source§impl<T> UniqueMmioPointer<'_, WriteOnly<T>>
impl<T> UniqueMmioPointer<'_, WriteOnly<T>>
Source§impl<'a, T> UniqueMmioPointer<'a, [T]>
impl<'a, T> UniqueMmioPointer<'a, [T]>
Sourcepub const fn get(&mut self, index: usize) -> Option<UniqueMmioPointer<'_, T>>
pub const fn get(&mut self, index: usize) -> Option<UniqueMmioPointer<'_, T>>
Returns a UniqueMmioPointer to an element of this slice, or None if the index is out of
bounds.
§Example
use safe_mmio::{UniqueMmioPointer, fields::ReadWrite};
let mut slice: UniqueMmioPointer<[ReadWrite<u32>]>;
let mut element = slice.get(1).unwrap();
element.write(42);Sourcepub const fn take(self, index: usize) -> Option<UniqueMmioPointer<'a, T>>
pub const fn take(self, index: usize) -> Option<UniqueMmioPointer<'a, T>>
Returns a UniqueMmioPointer to an element of this slice, or None if the index is out of
bounds.
Unlike UniqueMmioPointer::get this takes ownership of the original pointer. This is
useful when you want to store the resulting pointer without keeping the original pointer
around.
§Example
use safe_mmio::{UniqueMmioPointer, fields::ReadWrite};
let mut slice: UniqueMmioPointer<[ReadWrite<u32>]>;
let mut element = slice.take(1).unwrap();
element.write(42);
// `slice` can no longer be used at this point.Source§impl<'a, T, const LEN: usize> UniqueMmioPointer<'a, [T; LEN]>
impl<'a, T, const LEN: usize> UniqueMmioPointer<'a, [T; LEN]>
Sourcepub fn split(&mut self) -> [UniqueMmioPointer<'_, T>; LEN]
pub fn split(&mut self) -> [UniqueMmioPointer<'_, T>; LEN]
Splits a UniqueMmioPointer to an array into an array of UniqueMmioPointers.
Sourcepub const fn as_mut_slice(&mut self) -> UniqueMmioPointer<'_, [T]>
pub const fn as_mut_slice(&mut self) -> UniqueMmioPointer<'_, [T]>
Converts this array pointer to an equivalent slice pointer.
Sourcepub const fn get(&mut self, index: usize) -> Option<UniqueMmioPointer<'_, T>>
pub const fn get(&mut self, index: usize) -> Option<UniqueMmioPointer<'_, T>>
Returns a UniqueMmioPointer to an element of this array, or None if the index is out of
bounds.
§Example
use safe_mmio::{UniqueMmioPointer, fields::ReadWrite};
let mut slice: UniqueMmioPointer<[ReadWrite<u32>; 3]>;
let mut element = slice.get(1).unwrap();
element.write(42);
slice.get(2).unwrap().write(100);Sourcepub const fn take(self, index: usize) -> Option<UniqueMmioPointer<'a, T>>
pub const fn take(self, index: usize) -> Option<UniqueMmioPointer<'a, T>>
Returns a UniqueMmioPointer to an element of this array, or None if the index is out of
bounds.
Unlike UniqueMmioPointer::get this takes ownership of the original pointer. This is
useful when you want to store the resulting pointer without keeping the original pointer
around.
§Example
use safe_mmio::{UniqueMmioPointer, fields::ReadWrite};
let mut array: UniqueMmioPointer<[ReadWrite<u32>; 3]>;
let mut element = array.take(1).unwrap();
element.write(42);
// `array` can no longer be used at this point.