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: StringName of the interface (for identification)
base_address: u64Physical base address of the mapped region
size: usizeSize 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: isizeOffset from base address to mapped region
lock_file: Option<File>File handle for lock file (if locked)
Implementations§
Source§impl Interface
impl Interface
Sourcepub fn new(
name: &str,
base_address: u64,
size: usize,
registers: Vec<Register>,
) -> Self
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![])]);Sourcepub fn is_mapped(&self) -> bool
pub fn is_mapped(&self) -> bool
Returns true if the interface is currently mapped and locked.
§Example
if iface.is_mapped() { /* ... */ }Sourcepub fn read_subregister(
&mut self,
reg_name: &str,
sub_name: &str,
) -> Result<u32, String>
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 namesub_name- Subregister name
§Returns
Ok(u32)- Value readErr(String)- Error message
§Example
let bits = iface.read_subregister("reg", "status")?;Sourcepub fn write_subregister(
&mut self,
reg_name: &str,
sub_name: &str,
value: u32,
) -> Result<(), String>
pub fn write_subregister( &mut self, reg_name: &str, sub_name: &str, value: u32, ) -> Result<(), String>
Auto Trait Implementations§
impl Freeze for Interface
impl RefUnwindSafe for Interface
impl !Send for Interface
impl !Sync for Interface
impl Unpin for Interface
impl UnwindSafe for Interface
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more