2019-05-05 20:56:23 +08:00
|
|
|
use volatile_register::{RO, WO, RW};
|
|
|
|
|
2019-08-11 06:55:27 +08:00
|
|
|
use crate::{register, register_bit, register_bits, register_bits_typed, register_at};
|
2019-05-07 05:56:53 +08:00
|
|
|
|
2019-05-24 00:23:51 +08:00
|
|
|
#[repr(u8)]
|
2019-05-21 07:30:54 +08:00
|
|
|
pub enum ChannelMode {
|
2019-05-22 07:42:24 +08:00
|
|
|
Normal = 0b00,
|
|
|
|
AutomaticEcho = 0b01,
|
|
|
|
LocalLoopback = 0b10,
|
2019-05-21 07:30:54 +08:00
|
|
|
RemoteLoopback = 0b11,
|
|
|
|
}
|
|
|
|
|
2019-05-24 00:23:51 +08:00
|
|
|
#[repr(u8)]
|
2019-05-21 08:53:59 +08:00
|
|
|
pub enum ParityMode {
|
|
|
|
EvenParity = 0b000,
|
|
|
|
OddParity = 0b001,
|
|
|
|
ForceTo0 = 0b010,
|
|
|
|
ForceTo1 = 0b011,
|
2019-05-22 07:42:24 +08:00
|
|
|
None = 0b100,
|
2019-05-21 08:53:59 +08:00
|
|
|
}
|
|
|
|
|
2019-05-24 00:23:51 +08:00
|
|
|
#[repr(u8)]
|
2019-05-22 07:42:24 +08:00
|
|
|
pub enum StopBits {
|
|
|
|
One = 0b00,
|
|
|
|
OneAndHalf = 0b01,
|
|
|
|
Two = 0b10,
|
|
|
|
}
|
2019-05-21 08:53:59 +08:00
|
|
|
|
2019-05-07 06:05:38 +08:00
|
|
|
#[repr(C)]
|
2019-05-05 20:56:23 +08:00
|
|
|
pub struct RegisterBlock {
|
2019-05-07 23:46:37 +08:00
|
|
|
pub control: Control,
|
|
|
|
pub mode: Mode,
|
|
|
|
pub intrpt_en: RW<u32>,
|
|
|
|
pub intrpt_dis: RW<u32>,
|
|
|
|
pub intrpt_mask: RO<u32>,
|
|
|
|
pub chnl_int_sts: WO<u32>,
|
|
|
|
pub baud_rate_gen: BaudRateGen,
|
|
|
|
pub rcvr_timeout: RW<u32>,
|
|
|
|
pub rcvr_fifo_trigger_level: RW<u32>,
|
|
|
|
pub modem_ctrl: RW<u32>,
|
|
|
|
pub modem_sts: RW<u32>,
|
|
|
|
pub channel_sts: ChannelSts,
|
|
|
|
pub tx_rx_fifo: TxRxFifo,
|
|
|
|
pub baud_rate_divider: BaudRateDiv,
|
|
|
|
pub flow_delay: RW<u32>,
|
|
|
|
pub unused0: RO<u32>,
|
|
|
|
pub unused1: RO<u32>,
|
|
|
|
pub tx_fifo_trigger_level: RW<u32>,
|
2019-05-05 20:56:23 +08:00
|
|
|
}
|
2019-05-21 05:01:50 +08:00
|
|
|
register_at!(RegisterBlock, 0xE0000000, uart0);
|
|
|
|
register_at!(RegisterBlock, 0xE0001000, uart1);
|
2019-05-05 20:56:23 +08:00
|
|
|
|
2019-05-07 06:32:45 +08:00
|
|
|
register!(control, Control, RW, u32);
|
2019-05-07 05:56:53 +08:00
|
|
|
register_bit!(control, rxrst, 0);
|
|
|
|
register_bit!(control, txrst, 1);
|
|
|
|
register_bit!(control, rxen, 2);
|
|
|
|
register_bit!(control, rxdis, 3);
|
|
|
|
register_bit!(control, txen, 4);
|
|
|
|
register_bit!(control, txdis, 5);
|
2019-05-21 07:30:54 +08:00
|
|
|
register_bit!(control, rstto, 6);
|
|
|
|
register_bit!(control, sttbrk, 7);
|
|
|
|
register_bit!(control, stpbrk, 8);
|
2019-05-07 05:56:53 +08:00
|
|
|
|
2019-05-07 06:32:45 +08:00
|
|
|
register!(mode, Mode, RW, u32);
|
2019-05-25 05:49:49 +08:00
|
|
|
register_bits_typed!(mode,
|
|
|
|
/// Channel mode: Defines the mode of operation of the UART.
|
|
|
|
chmode, u8, ChannelMode, 8, 9);
|
|
|
|
register_bits_typed!(mode,
|
|
|
|
/// Number of stop bits
|
|
|
|
nbstop, u8, StopBits, 6, 7);
|
|
|
|
register_bits_typed!(mode,
|
|
|
|
/// Parity type select
|
|
|
|
par, u8, ParityMode, 3, 5);
|
|
|
|
register_bits!(mode,
|
|
|
|
/// Character length select
|
|
|
|
chrl, u8, 1, 2);
|
|
|
|
register_bit!(mode,
|
|
|
|
/// Clock source select
|
|
|
|
clks, 0);
|
2019-05-07 05:56:53 +08:00
|
|
|
|
2019-05-07 06:32:45 +08:00
|
|
|
register!(baud_rate_gen, BaudRateGen, RW, u32);
|
2019-05-07 05:56:53 +08:00
|
|
|
register_bits!(baud_rate_gen, cd, u16, 0, 15);
|
|
|
|
|
2019-05-07 06:32:45 +08:00
|
|
|
register!(channel_sts, ChannelSts, RO, u32);
|
2019-05-25 05:49:49 +08:00
|
|
|
register_bit!(channel_sts,
|
|
|
|
/// Transmitter FIFO Nearly Full
|
|
|
|
tnful, 14);
|
|
|
|
register_bit!(channel_sts,
|
|
|
|
/// Tx FIFO fill level is greater than or equal to TTRIG?
|
|
|
|
ttrig, 13);
|
|
|
|
register_bit!(channel_sts,
|
|
|
|
/// Rx FIFO fill level is greater than or equal to FDEL?
|
|
|
|
flowdel, 12);
|
|
|
|
register_bit!(channel_sts,
|
|
|
|
/// Transmitter state machine active?
|
|
|
|
tactive, 11);
|
|
|
|
register_bit!(channel_sts,
|
|
|
|
/// Receiver state machine active?
|
|
|
|
ractive, 10);
|
|
|
|
register_bit!(channel_sts,
|
|
|
|
/// Tx FIFO is full?
|
|
|
|
txfull, 4);
|
|
|
|
register_bit!(channel_sts,
|
|
|
|
/// Tx FIFO is empty?
|
|
|
|
txempty, 3);
|
|
|
|
register_bit!(channel_sts,
|
|
|
|
/// Rx FIFO is full?
|
|
|
|
rxfull, 2);
|
|
|
|
register_bit!(channel_sts,
|
|
|
|
/// Rx FIFO is empty?
|
|
|
|
rxempty, 1);
|
|
|
|
register_bit!(channel_sts,
|
|
|
|
/// Rx FIFO fill level is greater than or equal to RTRIG?
|
|
|
|
rxovr, 0);
|
2019-05-07 05:56:53 +08:00
|
|
|
|
2019-05-07 06:32:45 +08:00
|
|
|
register!(tx_rx_fifo, TxRxFifo, RW, u32);
|
2019-05-07 05:56:53 +08:00
|
|
|
register_bits!(tx_rx_fifo, data, u32, 0, 31);
|
|
|
|
|
2019-05-07 06:32:45 +08:00
|
|
|
register!(baud_rate_div, BaudRateDiv, RW, u32);
|
2019-05-07 05:56:53 +08:00
|
|
|
register_bits!(baud_rate_div, bdiv, u8, 0, 7);
|