Skip to content

Instantly share code, notes, and snippets.

@bluecmd
Last active June 28, 2019 11:45
Show Gist options
  • Select an option

  • Save bluecmd/f9e38c6b73d6615d912496c0abbdd809 to your computer and use it in GitHub Desktop.

Select an option

Save bluecmd/f9e38c6b73d6615d912496c0abbdd809 to your computer and use it in GitHub Desktop.
u16550.rs
use crate::model::*;
use register::mmio::{ReadOnly, ReadWrite, WriteOnly};
use register::{register_bitfields, Field};
#[allow(non_snake_case)]
#[repr(C)]
union UartRegister0 {
// Activate when DLAB = 0
UARTRBR: ReadOnly<u32, UARTRBR::Register>,
UARTTHR: WriteOnly<u32, UARTTHR::Register>,
// Activate when DLAB = 1
UARTDLL: ReadWrite<u32, UARTDLL::Register>,
}
#[allow(non_snake_case)]
#[repr(C)]
union UartRegister1 {
// Activate when DLAB = 0
UARTIER: ReadWrite<u32, UARTIER::Register>,
// Activate when DLAB = 1
UARTDLM: ReadWrite<u32, UARTDLM::Register>,
}
#[allow(non_snake_case)]
#[repr(C)]
union UartRegister2 {
UARTIIR: ReadOnly<u32, UARTIIR::Register>,
UARTFCR: WriteOnly<u32, UARTFCR::Register>,
}
#[allow(non_snake_case)]
#[repr(C)]
union UartRegister3 {
UARTLCR: ReadWrite<u32, UARTLCR::Register>,
}
#[allow(non_snake_case)]
#[repr(C)]
union UartRegister4 {
UARTMCR: ReadWrite<u32, UARTMCR::Register>,
}
#[allow(non_snake_case)]
#[repr(C)]
union UartRegister5 {
UARTLSR: ReadOnly<u32, UARTLSR::Register>,
}
#[allow(non_snake_case)]
#[repr(C)]
union UartRegister6 {
UARTMSR: ReadOnly<u32, UARTMSR::Register>,
}
#[allow(non_snake_case)]
#[repr(C)]
union UartRegister7 {
UARTSCR: ReadWrite<u32, UARTSCR::Register>,
}
#[repr(C)]
struct RegisterBlock {
R0: UartRegister0,
R1: UartRegister1,
R2: UartRegister2,
R3: UartRegister3,
R4: UartRegister4,
R5: UartRegister5,
R6: UartRegister6,
R7: UartRegister7,
}
pub struct U16550 {
regs: *const RegisterBlock,
baudrate: u32,
}
impl U16550 {
pub fn new(base : usize, baudrate : u32) -> U16550 {
U16550 {
regs: base as *const RegisterBlock,
baudrate: baudrate,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment