Repository navigation
serial_v2: align DMA buffers to cache line boundary #12084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1099,6 +1099,10 @@ static rt_err_t rt_serial_rx_enable(struct rt_device *dev, | |
| struct rt_serial_device *serial; | ||
| struct rt_serial_rx_fifo *rx_fifo = RT_NULL; | ||
| rt_size_t rx_fifo_size = 0; | ||
| #ifdef RT_SERIAL_USING_DMA | ||
| rt_size_t dma_ping_offset = 0; | ||
| rt_uint8_t *dma_ping = RT_NULL; | ||
| #endif | ||
|
|
||
| RT_ASSERT(dev != RT_NULL); | ||
| serial = (struct rt_serial_device *)dev; | ||
|
|
@@ -1127,7 +1131,9 @@ static rt_err_t rt_serial_rx_enable(struct rt_device *dev, | |
| #ifdef RT_SERIAL_USING_DMA | ||
| if (serial->config.dma_ping_bufsz < RT_SERIAL_RX_MINBUFSZ / 2) | ||
| serial->config.dma_ping_bufsz = RT_SERIAL_RX_MINBUFSZ / 2; | ||
| rx_fifo_size = sizeof(struct rt_serial_rx_fifo) + serial->config.rx_bufsz + serial->config.dma_ping_bufsz; | ||
|
|
||
| dma_ping_offset = sizeof(struct rt_serial_rx_fifo) + serial->config.rx_bufsz; | ||
| rx_fifo_size = dma_ping_offset + RT_ALIGN(serial->config.dma_ping_bufsz, RT_CPU_CACHE_LINE_SZ) + RT_CPU_CACHE_LINE_SZ; | ||
| #else | ||
| rx_fifo_size = sizeof(struct rt_serial_rx_fifo) + serial->config.rx_bufsz; | ||
| #endif | ||
|
|
@@ -1141,8 +1147,9 @@ static rt_err_t rt_serial_rx_enable(struct rt_device *dev, | |
| serial->config.rx_bufsz); | ||
|
|
||
| #ifdef RT_SERIAL_USING_DMA | ||
| dma_ping = (rt_uint8_t *)RT_ALIGN((rt_ubase_t)rx_fifo + dma_ping_offset, RT_CPU_CACHE_LINE_SZ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HPM6880 的 RX 重分配只检查主 ring。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已为BSP添加-DRT_CPU_CACHE_LINE_SZ=64声明 |
||
| rt_ringbuffer_init(&rx_fifo->dma_ping_rb, | ||
| (rt_uint8_t *)rx_fifo + sizeof(struct rt_serial_rx_fifo) + serial->config.rx_bufsz, | ||
| dma_ping, | ||
| serial->config.dma_ping_bufsz); | ||
| #endif | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里只看全局
RT_SERIAL_USING_DMA。例如at32f455-start的 UART1 默认走中断接收,打开时也会多申请 32 字节。上面两处 TX 分配也会增加纯中断模式的堆开销。请只在需要缓存维护的 DMA 路径预留对齐空间。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
取消了tx的修改,因为其实没有需要保护的实际场景