Skip to main content

Register

Struct Register 

Source
pub struct Register<Layout, Access, Io>
where Io: IoHandle, Layout: LayoutOver<<Io as IoHandle>::Base>, Access: Accessible,
{ /* private fields */ }
Expand description

Register represents a structured register layout, and its access interface and permissions. This is the core abstraction of the crate.

If Access expresses unsafe-writability, then all write methods are marked as unsafe.

Implementations§

Source§

impl<Spec, Layout> Register<Layout, <Spec as SystemRegisterSpec>::Access, SysRegIo<Spec>>
where Spec: SystemRegisterSpec, Layout: LayoutOver<u64>,

Source

pub const fn new() -> Self

Constructs a new system register instance.

Source§

impl<Layout, Base, Access> Register<Layout, Access, MmioPtr<Base, Access>>
where Layout: LayoutOver<Base>, Base: Copy, Access: Accessible,

Source

pub const fn new<InputAccess>(ptr: MmioPtr<Base, InputAccess>) -> Self
where InputAccess: AccessRestrictsTo<Access>,

Constructs a new memory-backed register from a pointer wrapper.

Source§

impl<Encoding, Layout> Register<Layout, <Encoding as ControlAndStatusRegisterEncoding>::Access, CsrIo<Encoding>>
where Encoding: ControlAndStatusRegisterEncoding, Layout: LayoutOver<u64>,

Source

pub const fn new() -> Self

Constructs a new CSR instance.

Source§

impl<const N: u32, Layout> Register<Layout, <CrIo<N> as ControlRegister>::Access, CrIo<N>>
where CrIo<N>: ControlRegister, Layout: LayoutOver<u64>,

Source

pub const fn new() -> Self

Constructs an x86-64 control register instance.

Source§

impl<const N: u32, Layout> Register<Layout, <XcrIo<N> as ControlRegister>::Access, XcrIo<N>>
where XcrIo<N>: ControlRegister, Layout: LayoutOver<u64>,

Source

pub const fn new() -> Self

Constructs an x86-64 control register instance.

Source§

impl<const ID: u32, Layout, Access> Register<Layout, Access, MsrIo<ID>>
where Layout: LayoutOver<u64>, Access: Accessible,

Source

pub const fn new() -> Self

Constructs an x86-64 MSR instance.

Source§

impl<Layout, Base, Access> Register<Layout, Access, PortIo<Base, Access>>
where Layout: LayoutOver<Base>, Base: Copy, Access: Accessible,

Source

pub const fn new(port: u16) -> Self

Constructs a new port register directly from a port address.

Source§

impl<Layout, Access, Io> Register<Layout, Access, Io>
where Io: IoHandle, Layout: LayoutOver<<Io as IoHandle>::Base>, Access: Accessible,

Source

pub const unsafe fn from_io(io: Io) -> Self

Constructs a new register from an I/O handle.

§Safety

The caller must guarantee…

  • that the provided I/O handle meets the implementation-specific access safety preconditions for the duration of the lifetimes of the register instance and any copies of it (e.g., in the case of an MMIO pointer, that the pointer is aligned and the memory it points to remains mapped for those lifetimes);

  • and that Access correctly models the safe nature of access in this context.

Source

pub const fn io(&self) -> &Io

Source

pub fn into_io(self) -> Io

Source

pub fn read(&self) -> Layout
where Access: Readable, Io: ReadHandle,

Reads from the register, if the backend and register permit it.

Source§

impl<Layout, R, Io> Register<Layout, (R, SafeWrite), Io>
where Io: WriteHandle, Layout: LayoutOver<<Io as IoHandle>::Base>, (R, SafeWrite): Writable,

Source

pub fn write(&self, value: Layout)

Writes to the register, if the backend and register permit it.

Source

pub fn modify<ModifyFn, Ret>(&self, cb: ModifyFn) -> Ret
where (R, SafeWrite): Readable, Io: ReadHandle, ModifyFn: FnOnce(&mut Layout) -> Ret,

Modifies the contents of the register, if the register and backend admit both reads and writes, returning whatever state the modification callback wanted to forward.

Source

pub fn atomic_swap(&self, value: Layout) -> Layout

Atomically swaps the contents of the register with the provided value, returning the original contents.

Source

pub fn atomic_set_bits(&self, bits: Layout) -> Layout

Atomically sets the provided bits on the contents of the register, returning the original contents.

Source

pub fn atomic_clear_bits(&self, bits: Layout) -> Layout

Atomically clears the provided bits on the contents of the register, returning the original contents.

Source§

impl<Layout, R, Io> Register<Layout, (R, UnsafeWrite), Io>
where Io: WriteHandle, Layout: LayoutOver<<Io as IoHandle>::Base>, (R, UnsafeWrite): Writable,

Source

pub unsafe fn write(&self, value: Layout)

Writes to the register, if the backend and register permit it.

§Safety

The caller must guarantee that the write does not result in undefined behaviour.

Source

pub unsafe fn modify<ModifyFn, Ret>(&self, cb: ModifyFn) -> Ret
where (R, UnsafeWrite): Readable, Io: ReadHandle, ModifyFn: FnOnce(&mut Layout) -> Ret,

Modifies the contents of the register, if the register and backend admit both reads and writes, returning whatever state the modification callback wanted to forward.

§Safety

The caller must guarantee that the write does not result in undefined behaviour.

Source

pub unsafe fn atomic_swap(&self, value: Layout) -> Layout

Atomically swaps the contents of the register with the provided value, returning the original contents.

§Safety

The caller must guarantee that the write does not result in undefined behaviour.

Source

pub unsafe fn atomic_set_bits(&self, bits: Layout) -> Layout

Atomically sets the provided bits on the contents of the register, returning the original contents.

§Safety

The caller must guarantee that the write does not result in undefined behaviour.

Source

pub unsafe fn atomic_clear_bits(&self, bits: Layout) -> Layout

Atomically clears the provided bits on the contents of the register, returning the original contents.

§Safety

The caller must guarantee that the write does not result in undefined behaviour.

Trait Implementations§

Source§

impl<Layout, Access, Io> Clone for Register<Layout, Access, Io>
where Io: IoHandle + Clone, Layout: LayoutOver<<Io as IoHandle>::Base> + Clone, Access: Accessible + Clone,

Source§

fn clone(&self) -> Register<Layout, Access, Io>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable)§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Layout, Access, Io> Copy for Register<Layout, Access, Io>
where Io: IoHandle + Copy, Layout: LayoutOver<<Io as IoHandle>::Base> + Copy, Access: Accessible + Copy,

Source§

impl<Layout, Access, Io> Debug for Register<Layout, Access, Io>
where Io: IoHandle + Debug, Layout: LayoutOver<<Io as IoHandle>::Base> + Debug, Access: Accessible + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Layout, Access, Io> ReadReg<Layout> for Register<Layout, Access, Io>
where Layout: LayoutOver<<Io as IoHandle>::Base>, Access: Readable, Io: ReadHandle,

Source§

fn read(&self) -> Layout

Source§

impl<Layout, R, Io> SafeWriteReg<Layout> for Register<Layout, (R, SafeWrite), Io>
where Layout: LayoutOver<<Io as IoHandle>::Base>, (R, SafeWrite): Writable, Io: WriteHandle,

Source§

fn write(&self, value: Layout)

Source§

fn modify<ModifyFn, Ret>(&self, cb: ModifyFn) -> Ret
where ModifyFn: FnOnce(&mut Layout) -> Ret, Self: ReadReg<Layout>,

Source§

impl<Layout, R, Io> UnsafeWriteReg<Layout> for Register<Layout, (R, UnsafeWrite), Io>
where Layout: LayoutOver<<Io as IoHandle>::Base>, (R, UnsafeWrite): Writable, Io: WriteHandle,

Source§

unsafe fn write(&self, value: Layout)

Safety Read more
Source§

unsafe fn modify<ModifyFn, Ret>(&self, cb: ModifyFn) -> Ret
where ModifyFn: FnOnce(&mut Layout) -> Ret, Self: ReadReg<Layout>,

Safety Read more

Auto Trait Implementations§

§

impl<Layout, Access, Io> Freeze for Register<Layout, Access, Io>
where Io: Freeze,

§

impl<Layout, Access, Io> RefUnwindSafe for Register<Layout, Access, Io>
where Io: RefUnwindSafe, Layout: RefUnwindSafe, Access: RefUnwindSafe,

§

impl<Layout, Access, Io> Send for Register<Layout, Access, Io>
where Io: Send, Layout: Send, Access: Send,

§

impl<Layout, Access, Io> Sync for Register<Layout, Access, Io>
where Io: Sync, Layout: Sync, Access: Sync,

§

impl<Layout, Access, Io> Unpin for Register<Layout, Access, Io>
where Io: Unpin, Layout: Unpin, Access: Unpin,

§

impl<Layout, Access, Io> UnsafeUnpin for Register<Layout, Access, Io>
where Io: UnsafeUnpin,

§

impl<Layout, Access, Io> UnwindSafe for Register<Layout, Access, Io>
where Io: UnwindSafe, Layout: UnwindSafe, Access: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

Source§

impl<Layout, Base> LayoutOver<Base> for Layout
where Layout: Copy + From<Base> + Into<Base>,

Source§

impl<Layout, R> RwSafeReg<Layout> for R
where R: ReadReg<Layout> + SafeWriteReg<Layout>,

Source§

impl<Layout, R> RwUnsafeReg<Layout> for R
where R: ReadReg<Layout> + UnsafeWriteReg<Layout>,

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = !

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.