Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mmio): add new_with_stride #36

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}

Expand Down