From cbc88a1ce3d21817eeb3b542b6b839092ff9a416 Mon Sep 17 00:00:00 2001 From: Daniel Kouchekinia <kouchekiniad@microsoft.com> Date: Thu, 7 Nov 2024 16:52:12 -0800 Subject: [PATCH] feat(mmio): add `new_with_stride` --- src/mmio.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/mmio.rs b/src/mmio.rs index 3d55e61..090d337 100644 --- a/src/mmio.rs +++ b/src/mmio.rs @@ -23,14 +23,24 @@ impl MmioSerialPort { /// really points to a serial port device. #[rustversion::attr(since(1.61), const)] pub unsafe fn new(base: usize) -> Self { + Self::new_with_stride(base, 1) + } + + /// Creates a new UART interface on the given memory mapped address with a given + /// register stride. + /// + /// This function is unsafe because the caller must ensure that the given base address + /// really points to a serial port device. + #[rustversion::attr(since(1.61), const)] + pub unsafe fn new_with_stride(base: usize, stride: usize) -> Self { let base_pointer = base as *mut u8; Self { data: AtomicPtr::new(base_pointer), - int_en: AtomicPtr::new(base_pointer.add(1)), - fifo_ctrl: AtomicPtr::new(base_pointer.add(2)), - line_ctrl: AtomicPtr::new(base_pointer.add(3)), - modem_ctrl: AtomicPtr::new(base_pointer.add(4)), - line_sts: AtomicPtr::new(base_pointer.add(5)), + int_en: AtomicPtr::new(base_pointer.add(1 * stride)), + fifo_ctrl: AtomicPtr::new(base_pointer.add(2 * stride)), + line_ctrl: AtomicPtr::new(base_pointer.add(3 * stride)), + modem_ctrl: AtomicPtr::new(base_pointer.add(4 * stride)), + line_sts: AtomicPtr::new(base_pointer.add(5 * stride)), } }