Interface

Struct Interface 

Source
pub struct Interface {
    pub name: String,
    pub base_address: u64,
    pub size: usize,
    pub registers: Vec<Register>,
    pub map_ptr: Option<*mut u8>,
    pub file: Option<File>,
    pub offset: isize,
    pub lock_file: Option<File>,
}
Expand description

The main interface for managing mapped registers and safe access.

Create an Interface to manage a group of registers, handle mapping/unmapping, and provide safe concurrent access.

Fields§

§name: String

Name of the interface (for identification)

§base_address: u64

Physical base address of the mapped region

§size: usize

Size of the mapped region in bytes

§registers: Vec<Register>

List of registers managed by this interface

§map_ptr: Option<*mut u8>

Pointer to mapped memory (if mapped)

§file: Option<File>

File handle for /dev/mem (if mapped)

§offset: isize

Offset from base address to mapped region

§lock_file: Option<File>

File handle for lock file (if locked)

Implementations§

Source§

impl Interface

Source

pub fn new( name: &str, base_address: u64, size: usize, registers: Vec<Register>, ) -> Self

Create a new Interface for a set of registers at a given base address.

§Example
use mmreg::{Interface, Register};
let iface = Interface::new("mydev", 0x4000_0000, 0x1000, vec![Register::new("reg", 0, vec![])]);
Source

pub fn is_mapped(&self) -> bool

Returns true if the interface is currently mapped and locked.

§Example
if iface.is_mapped() { /* ... */ }
Source

pub fn map(&mut self) -> Result<(), String>

Maps the interface’s memory region and acquires a lock for safe access.

§Returns
  • Ok(()) on success
  • Err(String) if mapping or locking fails
§Example
iface.map()?;
Source

pub fn unmap(&mut self)

Unmaps the interface’s memory region and releases the lock.

§Example
iface.unmap();
Source

pub fn write_register(&mut self, name: &str, value: u32) -> Result<(), String>

Writes a 32-bit value to a register by name. Automatically maps/unmaps if needed.

§Arguments
  • name - Register name
  • value - Value to write
§Example
iface.write_register("reg", 0xDEADBEEF)?;
Source

pub fn read_register(&mut self, name: &str) -> Result<u32, String>

Reads a 32-bit value from a register by name. Automatically maps/unmaps if needed.

§Arguments
  • name - Register name
§Returns
  • Ok(u32) - Value read
  • Err(String) - Error message
§Example
let val = iface.read_register("reg")?;
Source

pub fn read_subregister( &mut self, reg_name: &str, sub_name: &str, ) -> Result<u32, String>

Reads a subregister (bitfield) value by register and subregister name. Automatically maps/unmaps and refreshes from memory.

§Arguments
  • reg_name - Register name
  • sub_name - Subregister name
§Returns
  • Ok(u32) - Value read
  • Err(String) - Error message
§Example
let bits = iface.read_subregister("reg", "status")?;
Source

pub fn write_subregister( &mut self, reg_name: &str, sub_name: &str, value: u32, ) -> Result<(), String>

Writes a value to a subregister (bitfield) by register and subregister name. Automatically maps/unmaps and refreshes from memory.

§Arguments
  • reg_name - Register name
  • sub_name - Subregister name
  • value - Value to write
§Example
iface.write_subregister("reg", "status", 0x1)?;
Source

pub fn parse_subregister( &self, reg_name: &str, sub_name: &str, ) -> Result<u32, String>

Parses a subregister (bitfield) value from the local raw value (no refresh, no mapping).

§Arguments
  • reg_name - Register name
  • sub_name - Subregister name
§Returns
  • Ok(u32) - Value parsed from local raw
  • Err(String) - Error message
§Example
let bits = iface.parse_subregister("reg", "status")?;

Auto Trait Implementations§

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> 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, 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.