* this function will called when uart interrupt occur! */
| 789 | * this function will called when uart interrupt occur! |
| 790 | */ |
| 791 | static void uart_irq_handler(int vector, void *param) |
| 792 | { |
| 793 | size_t uart_base; |
| 794 | uint32_t iir, lsr; |
| 795 | struct rt_serial_device *serial; |
| 796 | struct sunxi_uart *uart; |
| 797 | |
| 798 | LOG_D("serial3:%p, uart3:%p\n", &serial3, &uart3); |
| 799 | serial = (struct rt_serial_device *)param; |
| 800 | uart = (struct sunxi_uart *)serial->parent.user_data; |
| 801 | |
| 802 | LOG_D("isr serial:%p, uart:%p, name:%s\n", serial, uart, serial->parent.parent.name); |
| 803 | |
| 804 | uart_base = SUNXI_UART0_BASE + uart->uart_port * 0x400; |
| 805 | iir = hal_readb(uart_base + UART_IIR) & UART_IIR_IID_MASK; |
| 806 | lsr = hal_readb(uart_base + UART_LSR); |
| 807 | |
| 808 | LOG_D("IRQ uart%d lsr is %08x \n", uart->uart_port, lsr); |
| 809 | if (iir == UART_IIR_IID_BUSBSY) |
| 810 | { |
| 811 | (void)hal_readb(uart_base + UART_USR); |
| 812 | |
| 813 | /* |
| 814 | * Before reseting lcr, we should ensure than uart is not in busy |
| 815 | * state. Otherwise, a new busy interrupt will be introduced. |
| 816 | * It is wise to set uart into loopback mode, since it can cut down the |
| 817 | * serial in, then we should reset fifo(in my test, busy state |
| 818 | * (UART_USR_BUSY) can't be cleard until the fifo is empty). |
| 819 | */ |
| 820 | hal_writeb(hal_readb(uart_base + UART_MCR) | UART_MCR_LOOP, uart_base + UART_MCR); |
| 821 | |
| 822 | hal_writeb(UART_FCR_FIFO_EN, uart_base + UART_FCR); |
| 823 | hal_writeb(UART_FCR_TXFIFO_RST | UART_FCR_RXFIFO_RST | UART_FCR_FIFO_EN, uart_base + UART_FCR); |
| 824 | hal_writeb(0, uart_base + UART_FCR); |
| 825 | |
| 826 | uart_set_fifo(uart->uart_port); |
| 827 | (void)hal_readb(uart_base + UART_FCR); |
| 828 | |
| 829 | hal_writeb(hal_readb(uart_base + UART_MCR) & ~UART_MCR_LOOP, uart_base + UART_MCR); /* exit loopback mode. */ |
| 830 | } |
| 831 | else |
| 832 | { |
| 833 | if (lsr & (UART_LSR_DR | UART_LSR_BI)) |
| 834 | { |
| 835 | #ifdef RT_USING_SERIAL_V2 |
| 836 | struct rt_serial_rx_fifo *rx_fifo; |
| 837 | uint8_t data; |
| 838 | |
| 839 | rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx; |
| 840 | RT_ASSERT(rx_fifo != RT_NULL); |
| 841 | |
| 842 | do |
| 843 | { |
| 844 | data = hal_readb(uart_base + UART_RBR); |
| 845 | rt_ringbuffer_putchar(&(rx_fifo->rb), data); |
| 846 | lsr = hal_readb(uart_base + UART_LSR); |
| 847 | } while (lsr & UART_LSR_DR); |
| 848 |
nothing calls this directly
no test coverage detected