Skip to content

Commit 59f8830

Browse files
Ryan-CW-Codehydevcode
authored andcommitted
[utest][serial_v2] 适配DMA乒乓缓冲
1 parent 3d95a3a commit 59f8830

File tree

10 files changed

+33
-6
lines changed

10 files changed

+33
-6
lines changed

examples/utest/testcases/drivers/serial_v2/uart_flush_rx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ static rt_bool_t uart_api()
6767
config.baud_rate = BAUD_RATE_115200;
6868
config.rx_bufsz = RT_SERIAL_TC_RXBUF_SIZE;
6969
config.tx_bufsz = RT_SERIAL_TC_TXBUF_SIZE;
70+
#ifdef RT_SERIAL_USING_DMA
71+
config.dma_ping_bufsz = RT_SERIAL_TC_RXBUF_SIZE / 2;
72+
#endif
7073
rt_device_control(&serial->parent, RT_DEVICE_CTRL_CONFIG, &config);
7174

7275
result = rt_device_open(&serial->parent, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);

examples/utest/testcases/drivers/serial_v2/uart_flush_txb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ static rt_bool_t uart_api()
7777
config.baud_rate = BAUD_RATE_115200;
7878
config.rx_bufsz = RT_SERIAL_TC_RXBUF_SIZE;
7979
config.tx_bufsz = RT_SERIAL_TC_TXBUF_SIZE * 5 + 10;
80+
#ifdef RT_SERIAL_USING_DMA
81+
config.dma_ping_bufsz = RT_SERIAL_TC_RXBUF_SIZE / 2;
82+
#endif
8083
rt_device_control(&serial->parent, RT_DEVICE_CTRL_CONFIG, &config);
8184

8285
result = rt_device_open(&serial->parent, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);

examples/utest/testcases/drivers/serial_v2/uart_flush_txnb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ static rt_bool_t uart_api()
7676
config.baud_rate = BAUD_RATE_115200;
7777
config.rx_bufsz = RT_SERIAL_TC_RXBUF_SIZE;
7878
config.tx_bufsz = RT_SERIAL_TC_RXBUF_SIZE * 5 + 10;
79+
#ifdef RT_SERIAL_USING_DMA
80+
config.dma_ping_bufsz = RT_SERIAL_TC_RXBUF_SIZE / 2;
81+
#endif
7982
rt_device_control(&serial->parent, RT_DEVICE_CTRL_CONFIG, &config);
8083

8184
result = rt_device_open(&serial->parent, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_NON_BLOCKING);

examples/utest/testcases/drivers/serial_v2/uart_get_unread_bytes_count.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static rt_err_t test_item(rt_uint8_t *uart_write_buffer, rt_uint32_t size)
4040
rt_ssize_t buf_data_len;
4141

4242
send_len = rt_device_write(&serial->parent, 0, uart_write_buffer, size);
43-
4443
if (size > RT_SERIAL_TC_RXBUF_SIZE)
4544
{
4645
size = RT_SERIAL_TC_RXBUF_SIZE;
@@ -53,11 +52,7 @@ static rt_err_t test_item(rt_uint8_t *uart_write_buffer, rt_uint32_t size)
5352
return -RT_ERROR;
5453
}
5554

56-
57-
if (size != rt_device_read(&serial->parent, 0, uart_write_buffer, size))
58-
{
59-
return -RT_ERROR;
60-
}
55+
rt_device_control(&serial->parent, RT_SERIAL_CTRL_RX_FLUSH, RT_NULL);
6156

6257
rt_device_control(&serial->parent, RT_SERIAL_CTRL_GET_UNREAD_BYTES_COUNT, (void *)&buf_data_len);
6358
if (0 != buf_data_len)
@@ -83,6 +78,9 @@ static rt_bool_t uart_api()
8378
config.baud_rate = BAUD_RATE_115200;
8479
config.rx_bufsz = RT_SERIAL_TC_RXBUF_SIZE;
8580
config.tx_bufsz = RT_SERIAL_TC_TXBUF_SIZE;
81+
#ifdef RT_SERIAL_USING_DMA
82+
config.dma_ping_bufsz = RT_SERIAL_TC_RXBUF_SIZE / 2;
83+
#endif
8684
rt_device_control(&serial->parent, RT_DEVICE_CTRL_CONFIG, &config);
8785

8886
result = rt_device_open(&serial->parent, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);

examples/utest/testcases/drivers/serial_v2/uart_overflow_rxb_txb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ static rt_err_t uart_api(rt_uint16_t length)
130130
config.baud_rate = BAUD_RATE_115200;
131131
config.rx_bufsz = RT_SERIAL_TC_RXBUF_SIZE;
132132
config.tx_bufsz = RT_SERIAL_TC_TXBUF_SIZE;
133+
#ifdef RT_SERIAL_USING_DMA
134+
config.dma_ping_bufsz = RT_SERIAL_TC_RXBUF_SIZE / 2;
135+
#endif
133136
rt_device_control(&serial->parent, RT_DEVICE_CTRL_CONFIG, &config);
134137

135138
result = rt_device_open(&serial->parent, RT_DEVICE_FLAG_RX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);

examples/utest/testcases/drivers/serial_v2/uart_rxb_txb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ static rt_err_t uart_api(rt_uint16_t length)
139139
config.baud_rate = BAUD_RATE_115200;
140140
config.rx_bufsz = RT_SERIAL_TC_RXBUF_SIZE;
141141
config.tx_bufsz = RT_SERIAL_TC_TXBUF_SIZE;
142+
#ifdef RT_SERIAL_USING_DMA
143+
config.dma_ping_bufsz = RT_SERIAL_TC_RXBUF_SIZE / 2;
144+
#endif
142145
rt_device_control(&serial->parent, RT_DEVICE_CTRL_CONFIG, &config);
143146

144147
result = rt_device_open(&serial->parent, RT_DEVICE_FLAG_RX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);

examples/utest/testcases/drivers/serial_v2/uart_rxb_txnb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ static rt_err_t uart_api(rt_uint16_t test_buf)
160160
config.baud_rate = BAUD_RATE_115200;
161161
config.rx_bufsz = RT_SERIAL_TC_RXBUF_SIZE;
162162
config.tx_bufsz = RT_SERIAL_TC_TXBUF_SIZE;
163+
#ifdef RT_SERIAL_USING_DMA
164+
config.dma_ping_bufsz = RT_SERIAL_TC_RXBUF_SIZE / 2;
165+
#endif
163166
rt_device_control(&serial->parent, RT_DEVICE_CTRL_CONFIG, &config);
164167

165168
result = rt_device_open(&serial->parent, RT_DEVICE_FLAG_RX_BLOCKING | RT_DEVICE_FLAG_TX_NON_BLOCKING);

examples/utest/testcases/drivers/serial_v2/uart_rxnb_txb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ static rt_err_t uart_api(rt_uint16_t test_buf)
163163
config.baud_rate = BAUD_RATE_115200;
164164
config.rx_bufsz = RT_SERIAL_TC_RXBUF_SIZE;
165165
config.tx_bufsz = RT_SERIAL_TC_TXBUF_SIZE;
166+
#ifdef RT_SERIAL_USING_DMA
167+
config.dma_ping_bufsz = RT_SERIAL_TC_RXBUF_SIZE / 2;
168+
#endif
166169
rt_device_control(&serial->parent, RT_DEVICE_CTRL_CONFIG, &config);
167170

168171
result = rt_device_open(&serial->parent, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);

examples/utest/testcases/drivers/serial_v2/uart_rxnb_txnb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ static rt_err_t uart_api(rt_uint16_t test_buf)
182182
config.baud_rate = BAUD_RATE_115200;
183183
config.rx_bufsz = RT_SERIAL_TC_RXBUF_SIZE;
184184
config.tx_bufsz = RT_SERIAL_TC_TXBUF_SIZE;
185+
#ifdef RT_SERIAL_USING_DMA
186+
config.dma_ping_bufsz = RT_SERIAL_TC_RXBUF_SIZE / 2;
187+
#endif
185188
rt_device_control(&serial->parent, RT_DEVICE_CTRL_CONFIG, &config);
186189

187190
result = rt_device_open(&serial->parent, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_NON_BLOCKING);

examples/utest/testcases/drivers/serial_v2/uart_timeout_rxb_txb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static void uart_rec_entry(void *parameter)
9393
uart_write_flag = RT_FALSE;
9494
uart_result = RT_FALSE;
9595
rt_free(uart_write_buffer);
96+
rt_thread_mdelay(60);
9697
return;
9798
}
9899

@@ -142,6 +143,9 @@ static rt_bool_t uart_api()
142143
config.baud_rate = BAUD_RATE_115200;
143144
config.rx_bufsz = RT_SERIAL_TC_RXBUF_SIZE;
144145
config.tx_bufsz = RT_SERIAL_TC_TXBUF_SIZE;
146+
#ifdef RT_SERIAL_USING_DMA
147+
config.dma_ping_bufsz = RT_SERIAL_TC_RXBUF_SIZE / 2;
148+
#endif
145149
rt_device_control(&serial->parent, RT_DEVICE_CTRL_CONFIG, &config);
146150

147151
result = rt_device_open(&serial->parent, RT_DEVICE_FLAG_RX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);
@@ -182,6 +186,7 @@ static rt_bool_t uart_api()
182186
}
183187

184188
__exit:
189+
rt_thread_mdelay(5);
185190
rt_device_close(&serial->parent);
186191
return result == RT_EOK ? RT_TRUE : RT_FALSE;
187192
}

0 commit comments

Comments
 (0)