[bsp][gd32] 修复串口驱动中由于可能的中断嵌套而导致RB索引异常的问题

This commit is contained in:
Junjie Wang 2024-05-03 06:57:18 +08:00 committed by GitHub
parent 2c9b7c10b9
commit b632dc1aaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 2 deletions

View File

@ -233,13 +233,14 @@ static void dma_recv_isr (struct rt_serial_device *serial)
{
struct gd32_uart *uart;
rt_size_t recv_len, counter;
rt_base_t level;
RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct gd32_uart, serial);
recv_len = 0;
level = rt_hw_interrupt_disable();
counter = dma_transfer_number_get(uart->dma.rx.periph, uart->dma.rx.channel);
if (counter <= uart->dma.last_index)
{
recv_len = uart->dma.last_index - counter;
@ -248,10 +249,11 @@ static void dma_recv_isr (struct rt_serial_device *serial)
{
recv_len = serial->config.rx_bufsz + uart->dma.last_index - counter;
}
uart->dma.last_index = counter;
rt_hw_interrupt_enable(level);
if (recv_len)
{
uart->dma.last_index = counter;
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_DMADONE | (recv_len << 8));
}
}