2021-05-18 09:57:25 +08:00
|
|
|
/*
|
2022-12-03 12:07:44 +08:00
|
|
|
* Copyright (c) 2006-2020, RT-Thread Development Team
|
2021-05-18 09:57:25 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-05-21 17:03:30 +08:00
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2021-05-18 09:57:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DRV_UART_H__
|
|
|
|
#define __DRV_UART_H__
|
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
#include "riscv_io.h"
|
2021-05-21 17:03:30 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
/**
|
|
|
|
* uart ns16550a
|
|
|
|
* http://byterunner.com/16550.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TRANSMIT AND RECEIVE HOLDING REGISTER */
|
|
|
|
#define UART_RHR 0
|
|
|
|
#define UART_THR 0
|
|
|
|
|
|
|
|
/* INTERRUPT ENABLE REGISTER */
|
|
|
|
#define UART_IER 1
|
|
|
|
#define UART_IER_RX_ENABLE (1 << 0)
|
|
|
|
#define UART_IER_TX_ENABLE (1 << 1)
|
|
|
|
|
|
|
|
/* FIFO CONTROL REGISTER */
|
|
|
|
#define UART_FCR 2
|
|
|
|
#define UART_FCR_FIFO_ENABLE (1 << 0)
|
|
|
|
#define UART_FCR_FIFO_CLEAR (3 << 1)
|
|
|
|
|
|
|
|
/* INTERRUPT STATUS REGISTER */
|
|
|
|
#define UART_ISR 2
|
2021-05-21 17:03:30 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
/* LINE CONTROL REGISTER */
|
|
|
|
#define UART_LCR 3
|
|
|
|
#define UART_LCR_EIGHT_BITS (3 << 0)
|
|
|
|
// special mode to set baud rate
|
|
|
|
#define UART_LCR_BAUD_LATCH (1 << 7)
|
2021-05-21 17:03:30 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
/* LINE STATUS REGISTER */
|
|
|
|
#define UART_LSR 5
|
|
|
|
// input is waiting to be read from RHR
|
|
|
|
#define UART_LSR_RX_READY (1 << 0)
|
|
|
|
// THR can accept another character to send
|
|
|
|
#define UART_LSR_TX_IDLE (1 << 5)
|
2021-05-21 17:03:30 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
#define UART_REFERENCE_CLOCK 1843200
|
|
|
|
#define UART_DEFAULT_BAUDRATE 115200
|
2021-05-21 17:03:30 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
extern void *uart0_base;
|
2021-05-21 17:03:30 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
#define write8_uart0(idx, value) __raw_writeb(((rt_uint8_t)value), (void*)((size_t)uart0_base + (idx)))
|
|
|
|
#define read8_uart0(idx) __raw_readb((void*)((size_t)uart0_base + (idx)))
|
2021-05-21 17:03:30 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
void rt_hw_uart_start_rx_thread();
|
2021-05-18 09:57:25 +08:00
|
|
|
int rt_hw_uart_init(void);
|
2022-12-03 12:07:44 +08:00
|
|
|
void drv_uart_puts(char *str); // for syscall
|
2021-05-18 09:57:25 +08:00
|
|
|
|
|
|
|
#endif /* __DRV_UART_H__ */
|