|
13 | 13 | #include "board.h" |
14 | 14 | #include "drv_uart.h" |
15 | 15 | #include "riscv_io.h" |
16 | | -#include "board.h" |
17 | 16 |
|
18 | 17 | #define UART_DEFAULT_BAUDRATE 115200 |
19 | 18 | #define UART_CLK 50000000 |
20 | | -#define UART_ADDR 0x91403000UL |
21 | | -#define UART_IRQ 0x13 |
| 19 | +#define UART_ADDR UART0_BASE_ADDR |
| 20 | +#define UART_IRQ 0x10 |
22 | 21 |
|
23 | 22 |
|
24 | 23 | #define UART_RBR (0x00) /* receive buffer register */ |
|
94 | 93 | struct device_uart |
95 | 94 | { |
96 | 95 | rt_ubase_t hw_base; |
| 96 | + void* pa_base; |
97 | 97 | rt_uint32_t irqno; |
98 | 98 | }; |
99 | 99 |
|
@@ -251,7 +251,7 @@ static rt_err_t uart_control(struct rt_serial_device *serial, int cmd, void *arg |
251 | 251 | return -RT_ENOMEM; |
252 | 252 | } |
253 | 253 |
|
254 | | - mmap2->ret = lwp_map_user_phy(lwp_self(), RT_NULL, (void*)(uart->hw_base), mmap2->length, 0); |
| 254 | + mmap2->ret = lwp_map_user_phy(lwp_self(), RT_NULL, uart->pa_base, mmap2->length, 0); |
255 | 255 | } |
256 | 256 | break; |
257 | 257 | } |
@@ -311,12 +311,16 @@ static void rt_hw_uart_isr(int irq, void *param) |
311 | 311 | } |
312 | 312 | else if (lsr & (UART_LSR_DR | UART_LSR_BI)) |
313 | 313 | { |
314 | | - #ifdef RT_USING_SERIAL_V2 |
315 | 314 | struct rt_serial_rx_fifo *rx_fifo; |
316 | | - uint8_t data; |
317 | | - |
318 | 315 | rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx; |
319 | | - RT_ASSERT(rx_fifo != RT_NULL); |
| 316 | + |
| 317 | + if (rx_fifo == NULL) |
| 318 | + { |
| 319 | + readb((void*)(uart_base + UART_RBR)); |
| 320 | + return; |
| 321 | + } |
| 322 | + #ifdef RT_USING_SERIAL_V2 |
| 323 | + uint8_t data; |
320 | 324 |
|
321 | 325 | do { |
322 | 326 | data = readb((void*)(uart_base + UART_RBR)); |
@@ -352,7 +356,8 @@ int rt_hw_uart_init(void) |
352 | 356 | serial->config = config; |
353 | 357 | serial->config.baud_rate = UART_DEFAULT_BAUDRATE; |
354 | 358 |
|
355 | | - uart->hw_base = (rt_base_t)rt_ioremap((void *)UART_ADDR, 0x1000); |
| 359 | + uart->pa_base = (void *)UART_ADDR; |
| 360 | + uart->hw_base = (rt_base_t)rt_ioremap(uart->pa_base, 0x1000); |
356 | 361 | uart->irqno = UART_IRQ; |
357 | 362 |
|
358 | 363 | _uart_init((void*)(uart->hw_base)); |
|
0 commit comments