DMA
概述
DMA( Direct Memory Access, 直接存储访问)能够支持存储器与外设之间,存储器与存储器之间的多通道数据传输。
功能特性
DMA 支持如下特性:
字( word )地址不对齐传输和字节传输。
多通道传输(通道的优先级可配置)。
支持 DMA 描述链表结构。
三种传输方向:存储器 → 存储器( MEM → MEM )、外设 → 存储器( PERI → MEM )、和存储器 → 外设( MEM → PERI )。所有通道均支持传输方向自定义。
按固定地址访问( FIFO 模式)或按数据位宽地址增加访问。
每个通道都可指定任意硬件请求作为外设请求。
架构图
用法流程
初始化
wq_dma_init()内存复制
wq_dma_memcpy()内存组复制
wq_dma_memcpy_group()
注:各外设与内存数据交互皆调用各外设特定的dma传输函数(内含调用除 wq_dma_init 和 wq_dma_deinit 以外的函数)
参考示例
/examples/dma_demo/
API 介绍
Typedefs
-
typedef struct wq_dma_buf_entry wq_dma_buf_entry_t
-
typedef void (*wq_dma_memcpy_done_cb)(void *dst, void *src, uint32_t length, void *param)
dma memory copy done callback func. Invoke when dma memory copy is done.
- Param dst:
is the destination memory pointer to the dma transfer.
- Param src:
is the source memory pointer to the dma transfer.
- Param length:
is the length of dma transfer.
- Param param:
is a pointer to the returned parameter.
Functions
-
WQ_RET wq_dma_init(void)
This function is to initialize dma.
备注
This function needs to be called before all functions that use dma are called.
- 返回:
WQ_RET_OK Success.
-
WQ_RET wq_dma_memcpy(void *dst, const void *src, uint32_t length, wq_dma_memcpy_done_cb cb, void *param)
This function is to copy data form memory to memory by dma.
- 参数:
dst -- is the destination memory pointer to the dma transfer.
src -- is the source memory pointer to the dma transfer.
length -- is the length of dma transfer.
cb -- is the dma memory copy done callback function.
param -- is a pointer to the returned parameter.
- 返回:
WQ_RET_OK Success.
WQ_RET_NOMEM No memory to save dma transfer cfg.
-
uint32_t wq_dma_memcpy_group(const wq_dma_buf_entry_t src_bufs[], const wq_dma_buf_entry_t dst_bufs[], wq_dma_memcpy_done_cb cb, void *param)
This function is to copy data group form memory to memory by dma.
- 参数:
src_bufs -- is the buffers of the information of source memory transfer by dma.
dst_bufs -- is the buffers of the information of destination memory transfer by dma.
cb -- is the dma memory copy done callback function.
param -- is a pointer to the returned parameter.
- 返回:
WQ_RET_OK Success.
WQ_RET_INVAL The sum of src lengths is not equal to the sum of dst lengths./The sum of src or dst lengths is 0.
WQ_RET_NOMEM No memory to save dma transfer cfg.
-
struct wq_dma_buf_entry