[feat] add uart_put_char and uart_get_char function
This commit is contained in:
parent
8fb032ebb5
commit
2d399802a2
@ -148,6 +148,28 @@
|
||||
#define UART_UARTDMACR_TXDMAE (1 << 1U)
|
||||
#define UART_UARTDMACR_DMAONERR (1 << 2U)
|
||||
|
||||
typedef struct {
|
||||
io_rw_32 dr;
|
||||
io_rw_32 rsr;
|
||||
uint32_t _pad0[4];
|
||||
io_rw_32 fr;
|
||||
uint32_t _pad1;
|
||||
io_rw_32 ilpr;
|
||||
io_rw_32 ibrd;
|
||||
io_rw_32 fbrd;
|
||||
io_rw_32 lcr_h;
|
||||
io_rw_32 cr;
|
||||
io_rw_32 ifls;
|
||||
io_rw_32 imsc;
|
||||
io_rw_32 ris;
|
||||
io_rw_32 mis;
|
||||
io_rw_32 icr;
|
||||
io_rw_32 dmacr;
|
||||
} uart_hw_t;
|
||||
|
||||
#define uart0_hw ((uart_hw_t *const)UART0_BASE)
|
||||
#define uart1_hw ((uart_hw_t *const)UART1_BASE)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@ -74,6 +74,8 @@ void uart_init(uint8_t uart_id, struct uart_cfg_s *cfg);
|
||||
void uart_set_baudrate(uint8_t uart_id, uint32_t src_clk, uint32_t baudrate);
|
||||
uint32_t uart_get_flags(uint8_t uart_id);
|
||||
void uart_write_block(uint8_t uart_id, uint8_t *data, uint32_t length);
|
||||
int uart_put_char(uint8_t uart_id, uint8_t c);
|
||||
int uart_get_char(uint8_t uart_id);
|
||||
|
||||
uint32_t uart_int_get_raw_status(uint8_t uart_id);
|
||||
uint32_t uart_int_get_status(uint8_t uart_id);
|
||||
|
||||
@ -132,6 +132,32 @@ void uart_write_block(uint8_t uart_id, uint8_t *data, uint32_t length)
|
||||
}
|
||||
}
|
||||
|
||||
int uart_put_char(uint8_t uart_id, uint8_t c)
|
||||
{
|
||||
uint32_t addr;
|
||||
|
||||
if (uart_get_flags(UART_ID_0) & UART_FLAG_TXFF) {
|
||||
return -1;
|
||||
}
|
||||
addr = UART0_BASE + UART_UARTDR_OFFSET + (UART1_BASE - UART0_BASE) * uart_id;
|
||||
putreg32(c, addr);
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
int uart_get_char(uint8_t uart_id)
|
||||
{
|
||||
uint32_t addr, val;
|
||||
|
||||
if (uart_get_flags(UART_ID_0) & UART_FLAG_RXFE) {
|
||||
return -1;
|
||||
}
|
||||
addr = UART0_BASE + UART_UARTDR_OFFSET + (UART1_BASE - UART0_BASE) * uart_id;
|
||||
val = getreg32(addr);
|
||||
val &= UART_UARTDR_DATA_MASK;
|
||||
val >>= UART_UARTDR_DATA_POS;
|
||||
return (int)val;
|
||||
}
|
||||
|
||||
uint32_t uart_int_get_raw_status(uint8_t uart_id)
|
||||
{
|
||||
uint32_t addr, val;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user