@@ -134,7 +134,7 @@ static void rt_hw_uart_isr(int irqno, void *param)
134134
135135 RT_ASSERT (uart != RT_NULL );
136136
137- if (! (UART_FR (uart -> hw_base ) & UARTFR_RXFE ) && (UART_IMSC (uart -> hw_base ) & UARTIMSC_RXIM ))
137+ if ((UART_FR (uart -> hw_base ) & UARTFR_RXFF ) && (UART_IMSC (uart -> hw_base ) & UARTIMSC_RXIM ))
138138 {
139139
140140 struct rt_serial_rx_fifo * rx_fifo ;
@@ -143,10 +143,32 @@ static void rt_hw_uart_isr(int irqno, void *param)
143143
144144 RT_ASSERT (rx_fifo != RT_NULL );
145145
146- char rec_ch = UART_DR (uart -> hw_base ) & 0xff ;
146+ char rec_ch ;
147+ while (!(UART_FR (uart -> hw_base ) & UARTFR_RXFE ))
148+ {
149+ rec_ch = UART_DR (uart -> hw_base ) & 0xff ;
150+ rt_hw_serial_control_isr (serial , RT_HW_SERIAL_CTRL_PUTC , & rec_ch );
151+
152+ }
153+ rt_hw_serial_isr (serial ,RT_SERIAL_EVENT_RX_IND );
154+
155+ }
156+ else if (UART_IMSC (uart -> hw_base ) & UARTIMSC_RTIM )
157+ {
158+ struct rt_serial_rx_fifo * rx_fifo ;
159+
160+ rx_fifo = (struct rt_serial_rx_fifo * )serial -> serial_rx ;
161+
162+ RT_ASSERT (rx_fifo != RT_NULL );
147163
148- rt_ringbuffer_putchar (& (rx_fifo -> rb ),rec_ch );
164+ char rec_ch ;
165+
166+ while (!(UART_FR (uart -> hw_base ) & UARTFR_RXFE ))
167+ {
168+ rec_ch = UART_DR (uart -> hw_base ) & 0xff ;
169+ rt_hw_serial_control_isr (serial , RT_HW_SERIAL_CTRL_PUTC , & rec_ch );
149170
171+ }
150172 rt_hw_serial_isr (serial ,RT_SERIAL_EVENT_RX_IND );
151173 }
152174 else if ((UART_IMSC (uart -> hw_base ) & UARTIMSC_TXIM ))
@@ -188,6 +210,7 @@ static rt_err_t uart_control(struct rt_serial_device *serial, int cmd, void *arg
188210 {
189211 /* disable rx irq */
190212 UART_IMSC (uart -> hw_base ) &= ~UARTIMSC_RXIM ;
213+ UART_IMSC (uart -> hw_base ) &= ~UARTIMSC_RTIM ;
191214 }
192215 else if (ctrl_arg == RT_DEVICE_FLAG_INT_TX )
193216 {
@@ -201,6 +224,7 @@ static rt_err_t uart_control(struct rt_serial_device *serial, int cmd, void *arg
201224 {
202225 /* enable rx irq */
203226 UART_IMSC (uart -> hw_base ) |= UARTIMSC_RXIM ;
227+ UART_IMSC (uart -> hw_base ) |= UARTIMSC_RTIM ;
204228 rt_hw_interrupt_umask (uart -> irqno );
205229
206230 } else if (ctrl_arg == RT_DEVICE_FLAG_INT_TX )
@@ -256,7 +280,6 @@ static rt_ssize_t uart_transmit(struct rt_serial_device *serial,
256280 RT_ASSERT (serial != RT_NULL );
257281 RT_ASSERT (buf != RT_NULL );
258282 RT_ASSERT (size );
259- uint32_t fifo_size = 0 , tx_size = 0 ;
260283 struct hw_uart_device * uart = (struct hw_uart_device * )serial -> parent .user_data ;
261284 struct rt_serial_tx_fifo * tx_fifo ;
262285 tx_fifo = (struct rt_serial_tx_fifo * ) serial -> serial_tx ;
@@ -342,7 +365,12 @@ int rt_hw_uart_init(void)
342365 rt_hw_interrupt_install (_uart_device [i ].irqno , rt_hw_uart_isr , _uart_device [i ].serial , _uart_device [i ].device_name );
343366 /* enable Rx and Tx of UART */
344367 UART_CR (_uart_device [i ].hw_base ) = (1 << 0 ) | (1 << 8 ) | (1 << 9 );
368+
345369 UART_LCR_H (_uart_device [i ].hw_base ) = (1 << 4 );
370+
371+ UART_IFLS (_uart_device [i ].hw_base ) = 0 ;
372+ UART_IFLS (_uart_device [i ].hw_base ) = (1 << 3 );
373+
346374 }
347375
348376 return err ;
0 commit comments