Skip to main content

Reg

Struct Reg 

Source
pub struct Reg<T: Register, A: Access> { /* private fields */ }
Expand description

Register abstraction used to read, write, and modify register values

Implementations§

Source§

impl<T: Register, A: Access> Reg<T, A>

Source

pub const unsafe fn from_ptr(ptr: *mut T::Regwidth) -> Self

§Safety

The caller must guarantee that the provided address points to a hardware register of type T with access A.

Source

pub const fn as_ptr(&self) -> *mut T

Source§

impl<T: Register, A: Read> Reg<T, A>

Source

pub fn read(&self) -> T

Read a register value.

If the register is to be modified (i.e., a read-modify-write), use the Reg::modify method instead.

§Example
let reg1_val = registers.regfile().register1().read();
let field1_val = reg1_val.field1();
let field2_val = reg1_val.field2();
Source§

impl<T: Register, A: Write> Reg<T, A>

Source

pub fn write_value(&self, val: T)

Write a register value.

Typically one would use Reg::write or Reg::modify to update a register’s contents, but this method has a few different use cases such as updating a register with a stored value, or updating one register with the contents of another.

§Example
let reg0 = registers.regfile().reg_array()[0].read();
registers.regfile().reg_array()[1].write_value(reg0);
Source§

impl<T: Default + Register, A: Write> Reg<T, A>

Source

pub fn write<R>(&self, f: impl FnOnce(&mut T) -> R) -> R

Write a register.

This method takes a closure. The input to the closure is a mutable reference to the default value of the register. It can be updated in the closure. The updated value is then written to the hardware register.

§Example
registers.regfile().register1().write(|r| {
    // r contains the default (reset) value of the register
    r.set_field1(0x1);
    r.set_field2(0x0);
});
Source§

impl<T: Register, A: Read + Write> Reg<T, A>

Source

pub fn modify<R>(&self, f: impl FnOnce(&mut T) -> R) -> R

Modify a register.

This method takes a closure. The input to the closure is a mutable reference to the current value of the register. It can be updated in the closure. The updated value is then written back to the hardware register.

§Example
let orig_r = registers.regfile().register1().modify(|r| {
    // r contains the current value of the register
    orig_r = r.clone()
    r.set_field1(r.field1());
    r.set_field2(0x0);
    // whatever value the closure returns is returned by the .modify() method
    orig_r
});

Trait Implementations§

Source§

impl<T: Clone + Register, A: Clone + Access> Clone for Reg<T, A>
where T::Regwidth: Clone,

Source§

fn clone(&self) -> Reg<T, A>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Register, A: Debug + Access> Debug for Reg<T, A>
where T::Regwidth: Debug,

Source§

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

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

impl<T: PartialEq + Register, A: PartialEq + Access> PartialEq for Reg<T, A>
where T::Regwidth: PartialEq,

Source§

fn eq(&self, other: &Reg<T, A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Copy + Register, A: Copy + Access> Copy for Reg<T, A>
where T::Regwidth: Copy,

Source§

impl<T: Eq + Register, A: Eq + Access> Eq for Reg<T, A>
where T::Regwidth: Eq,

Source§

impl<T: Register, A: Access> Send for Reg<T, A>

Source§

impl<T: Register, A: Access> StructuralPartialEq for Reg<T, A>

Source§

impl<T: Register, A: Access> Sync for Reg<T, A>

Auto Trait Implementations§

§

impl<T, A> Freeze for Reg<T, A>

§

impl<T, A> RefUnwindSafe for Reg<T, A>

§

impl<T, A> Unpin for Reg<T, A>
where A: Unpin,

§

impl<T, A> UnsafeUnpin for Reg<T, A>

§

impl<T, A> UnwindSafe for Reg<T, A>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.