-INLINE void uart_disable(size_t base)
-{
- /* Disable the FIFO */
- HWREG(base + UART_O_LCRH) &= ~UART_LCRH_FEN;
- /* Disable the UART */
- HWREG(base + UART_O_CTL) &=
- ~(UART_CTL_UARTEN | UART_CTL_TXE | UART_CTL_RXE);
-}
-
-INLINE void uart_enable(size_t base)
-{
- /* Enable the FIFO */
- HWREG(base + UART_O_LCRH) |= UART_LCRH_FEN;
- /* Enable RX, TX, and the UART */
- HWREG(base + UART_O_CTL) |=
- UART_CTL_UARTEN | UART_CTL_TXE | UART_CTL_RXE;
-}
-
-INLINE void uart_config(size_t base, uint32_t baud, reg32_t config)
-{
- unsigned long div;
- bool hi_speed;
-
- if (baud * 16 > CPU_FREQ)
- {
- hi_speed = true;
- baud /= 2;
- }
- div = (CPU_FREQ * 8 / baud + 1) / 2;
-
- uart_disable(base);
-
- if (hi_speed)
- HWREG(base + UART_O_CTL) |= UART_CTL_HSE;
- else
- HWREG(base + UART_O_CTL) &= ~UART_CTL_HSE;
-
- /* Set the baud rate */
- HWREG(base + UART_O_IBRD) = div / 64;
- HWREG(base + UART_O_FBRD) = div % 64;
-
- /* Set parity, data length, and number of stop bits. */
- HWREG(base + UART_O_LCRH) = config;
-
- /* Clear the flags register */
- HWREG(base + UART_O_FR) = 0;
-
- uart_enable(base);
-}