Skip to content

Commit a0cccbd

Browse files
committed
[bsp][qemu] 适配串口v2并开启fifo
1 parent 40f2d67 commit a0cccbd

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

bsp/qemu-vexpress-a9/drivers/Kconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ menu "Onboard Peripheral Drivers"
2424
int "Set UART0 RX buffer size"
2525
range 64 65535
2626
depends on RT_USING_SERIAL_V2
27-
default 10240
27+
default 1024
2828

2929
config BSP_UART0_TX_BUFSIZE
3030
int "Set UART0 TX buffer size"
@@ -41,7 +41,7 @@ menu "Onboard Peripheral Drivers"
4141
int "Set UART1 RX buffer size"
4242
range 64 65535
4343
depends on RT_USING_SERIAL_V2
44-
default 10240
44+
default 1024
4545

4646
config BSP_UART1_TX_BUFSIZE
4747
int "Set UART1 TX buffer size"
@@ -58,7 +58,7 @@ menu "Onboard Peripheral Drivers"
5858
int "Set UART2 RX buffer size"
5959
range 64 65535
6060
depends on RT_USING_SERIAL_V2
61-
default 10240
61+
default 1024
6262

6363
config BSP_UART2_TX_BUFSIZE
6464
int "Set UART2 TX buffer size"
@@ -75,7 +75,7 @@ menu "Onboard Peripheral Drivers"
7575
int "Set UART3 RX buffer size"
7676
range 64 65535
7777
depends on RT_USING_SERIAL_V2
78-
default 10240
78+
default 1024
7979

8080
config BSP_UART3_TX_BUFSIZE
8181
int "Set UART3 TX buffer size"

bsp/qemu-vexpress-a9/drivers/drv_uart_v2.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

examples/utest/testcases/drivers/serial_v2/qemu/uart_qemu_echo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static rt_bool_t echo_test()
101101
sendTotalCount += sendCount;
102102

103103
// Wait for the cross-send to complete
104-
rt_thread_mdelay(15);
104+
rt_thread_mdelay(UART_SEND_TIMES);
105105

106106
if (count % 50 == 0)
107107
{

0 commit comments

Comments
 (0)