Skip to content
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
21 changes: 21 additions & 0 deletions uart_sifive/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,97 +85,118 @@ impl MmioUartSifive {
self.reg().rx.read()
}

/// Read Tx Status
#[inline]
pub fn read_tx(&self) -> u32 {
self.reg().tx.read()
}

/// Write Tx FIFO
#[inline]
pub fn write_tx(&self, value: u32) {
unsafe { self.reg().tx.write(value) }
}

/// Read RxCtrl
#[inline]
pub fn read_rxctrl(&self) -> u32 {
self.reg().rxctrl.read()
}

/// Write RxCtrl
#[inline]
pub fn write_rxctrl(&self, value: u32) {
unsafe { self.reg().rxctrl.write(value) }
}

/// Read TxCtrl
#[inline]
pub fn read_txctrl(&self) -> u32 {
self.reg().txctrl.read()
}

/// Write TxCtrl
#[inline]
pub fn write_txctrl(&self, value: u32) {
unsafe { self.reg().txctrl.write(value) }
}

/// Read ip register
#[inline]
pub fn read_ip(&self) -> InterruptRegister {
InterruptRegister::from_bits_truncate(self.reg().ip.read())
}

/// Read ie register
#[inline]
pub fn read_ie(&self) -> InterruptRegister {
InterruptRegister::from_bits_truncate(self.reg().ie.read())
}

/// Write ie register
#[inline]
pub fn write_ie(&self, value: u32) {
unsafe { self.reg().ie.write(value) }
}

/// Read div register
#[inline]
pub fn read_div(&self) -> u32 {
self.reg().div.read()
}

/// Write div register
#[inline]
pub fn write_div(&self, value: u32) {
unsafe { self.reg().div.write(value) }
}

/// Check if tx FIFO is full
pub fn is_tx_fifo_full(&self) -> bool {
TxData::from_bits_truncate(self.read_tx()).contains(TxData::FULL)
}

/// Check if read interrupt has been enable
pub fn is_read_interrupt_enabled(&self) -> bool {
self.read_ie().contains(InterruptRegister::RXWM)
}

/// Check if write interrupt has been enable
pub fn is_write_interrupt_enabled(&self) -> bool {
self.read_ie().contains(InterruptRegister::TXWM)
}

/// Enable write
pub fn enable_write(&self) {
self.write_txctrl(self.read_txctrl() | TxControl::ENABLE.bits())
}

/// Enable read
pub fn enable_read(&self) {
self.write_rxctrl(self.read_rxctrl() | RxControl::ENABLE.bits())
}

/// Disable write
pub fn disable_write(&self) {
self.write_txctrl(self.read_txctrl() & !TxControl::ENABLE.bits())
}

/// Disable read
pub fn disable_read(&self) {
self.write_rxctrl(self.read_rxctrl() & !RxControl::ENABLE.bits())
}

/// Disable all interrupt
pub fn disable_interrupt(&self) {
self.write_ie(0)
}

/// Enable read interrupt (and keep other bit in ie register)
pub fn enable_read_interrupt(&self) {
self.write_ie((self.read_ie() | InterruptRegister::RXWM).bits() as u32)
}

/// Enable write interrupt (and keep other bit in ie register)
pub fn enable_write_interrupt(&self) {
self.write_ie((self.read_ie() | InterruptRegister::TXWM).bits() as u32)
}
Expand Down
Loading