#ifndef __uartregs_h__
#define __uartregs_h__

/* Interrupt Enable Register */

#define IER_RX_DATA   (lpc210x_reg)0x01
#define IER_THRE      (lpc210x_reg)0x02
#define IER_RX_LSR    (lpc210x_reg)0x04
#define IER_MSR       (lpc210x_reg)0x08

/* Interrupt Identification (cause) Register */

#define IIR_MASK      (lpc210x_reg)0x0f
#define IIR_MSR       (lpc210x_reg)0x00
#define IIR_NO_IRQ    (lpc210x_reg)0x01
#define IIR_THRE      (lpc210x_reg)0x02
#define IIR_RX_DATA   (lpc210x_reg)0x04
#define IIR_RX_LSR    (lpc210x_reg)0x06
#define IIR_CH_TMOUT  (lpc210x_reg)0x0a

/* FIFO Control Register -- control */

#define FIFO_ENABLE   (lpc210x_reg)0x01
#define FIFO_RX_RESET (lpc210x_reg)0x02
#define FIFO_TX_RESET (lpc210x_reg)0x04

/* FIFO Control Register -- rx trigger levels */

#define FIFO_RX_TRG_MASK (lpc210x_reg)0xc0
#define FIFO_RX_TRG_N_1  (lpc210x_reg)0x00
#define FIFO_RX_TRG_N_4  (lpc210x_reg)0x40
#define FIFO_RX_TRG_N_8  (lpc210x_reg)0x80
#define FIFO_RX_TRG_N_14 (lpc210x_reg)0xc0

/* Line Control Register -- word length */

#define LCR_WORDLEN_MASK  (lpc210x_reg)0x03
#define LCR_WORDLEN_5BITS (lpc210x_reg)0x00
#define LCR_WORDLEN_6BITS (lpc210x_reg)0x01
#define LCR_WORDLEN_7BITS (lpc210x_reg)0x02
#define LCR_WORDLEN_8BITS (lpc210x_reg)0x03

/* Line Control Register -- word length */

#define LCR_STOPBIT_MASK  (lpc210x_reg)0x04
#define LCR_STOPBIT_NONE  (lpc210x_reg)0x00
#define LCR_STOPBIT_1BIT  (lpc210x_reg)0x04

/* Line Control Register -- parity */

#define LCR_PARITY_MASK  (lpc210x_reg)0x38
#define LCR_PARITY_NONE  (lpc210x_reg)0x00
#define LCR_PARITY_ODD   (lpc210x_reg)0x08
#define LCR_PARITY_EVEN  (lpc210x_reg)0x18

#define LCR_BREAK_SEND   (lpc210x_reg)0x40

#define LCR_DLAB_MASK    (lpc210x_reg)0x80
#define LCR_DLAB_ENABLE  (lpc210x_reg)0x80
#define LCR_DLAB_DISABLE (lpc210x_reg)0x00

/* Modem Control Register -- UART1 only on LPC210x */

#define MCR_MASK         (lpc210x_reg)0x13
#define MCR_SET_DTR      (lpc210x_reg)0x01
#define MCR_SET_RTS      (lpc210x_reg)0x02
#define MCR_SET_LOOPBACK (lpc210x_reg)0x10

/* Line Status Register */

#define LSR_RX_DATA      (lpc210x_reg)0x01

#define LSR_ERROR_MASK   (lpc210x_reg)0x8f

#define LSR_OE           (lpc210x_reg)0x02
#define LSR_PE           (lpc210x_reg)0x04
#define LSR_FE           (lpc210x_reg)0x08
#define LSR_RXFE         (lpc210x_reg)0x80 // RX FIFO error

#define LSR_BI           (lpc210x_reg)0x10

#define LSR_THR_EMPTY    (lpc210x_reg)0x20 // write THR to clear
#define LSR_TX_EMPTY     (lpc210x_reg)0x40 // both THR and TSR are empty -- OK to shutdown port

/* Modem Status Register -- UART1 only on LPC210x */

#define MSR_DELTA_CTS    (lpc210x_reg)0x01
#define MSR_DELTA_DSR    (lpc210x_reg)0x02
#define MSR_RI_EDGE      (lpc210x_reg)0x04
#define MSR_DELTA_DCD    (lpc210x_reg)0x08
#define MSR_CTS_STATE    (lpc210x_reg)0x10
#define MSR_DSR_STATE    (lpc210x_reg)0x20
#define MSR_RI_STATE     (lpc210x_reg)0x40
#define MSR_DCD_STATE    (lpc210x_reg)0x80

#endif /* __uartregs_h__ */

