DRV_DMA
DRV_DMA API Status
API |
|---|
DRV_DMA API Reference
Header File
Functions
-
int32_t drv_dma_device_init(uint32_t dev_index)
init a dma device.
初始化dma设备,通常是在系统开始初始化的时候调用一次
- 参数:
dev_index – [in] device index, from 0(the first device)
- 返回值:
0 – success [BK_RET_OK]
other – fail
- 返回:
result
-
int32_t drv_dma_device_deinit(uint32_t dev_index)
deinit a dma device.
反初始化dma设备,所有的dma channel都没用的时候才能返回成功,通常可能不会被调用
- 参数:
dev_index – [in] device index, same as drv_dma_device_init()
- 返回值:
0 – success [BK_RET_OK]
other – fail
- 返回:
result
-
uint32_t drv_dma_chn_alloc(uint32_t dev_index, int32_t req_chn_index)
alloc a dma channel.
从这个dma设备中分配出一个dma channel,后续操作dma channel需要用到该函数的返回值
- 参数:
dev_index – [in] device index, from 0(the first device)
req_chn_index – [in] -1: 不指定,随机分配 >=0: 指定对应的channel
- 返回值:
0 – fail
other – success
- 返回:
dma channel instance
-
int32_t drv_dma_chn_free(uint32_t chn_instance)
free dma channel.
释放dma channel,当不再使用该channel时需要调用该函数以让该channel被其他人使用
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
- 返回值:
0 – success [BK_RET_OK]
other – fail
- 返回:
result
-
int32_t drv_dma_cfg_callback(uint32_t chn_instance, int32_t priority, pfunc_dma_cb_t pfn_half, pfunc_dma_cb_t pfn_finish, void *pv_cb_arg)
config dma channel callback.
配置dma搬移完成的callback,如果不想处理callback,对应的参数传NULL即可 如果不想处理callback,也应该调用该函数,避免误调上次使用该channel的人的callback
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
priority – [in] 该channel的优先级(0~7), 7是最高优先级
pfn_half – [in] 搬移完成一半的时候出的callback
pfn_finish – [in] 全部搬移完成出的callback
pv_cb_arg – [in] callback带的参数
- 返回值:
0 – success [BK_RET_OK]
other – fail
- 返回:
result
-
int32_t drv_dma_cfg_param(uint32_t chn_instance, dma_mode_e mode, dma_data_width_e src_data_width, dma_data_width_e dst_data_width, dma_burst_type_e src_burst_len, dma_burst_type_e dst_burst_len)
config dma channel parameter.
配置该dma channel的一些参数, 需要在 drv_dma_load() 之前调用
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
mode – [in] see dma_mode_e
src_data_width – [in] source data width, see dma_data_width_e
dst_data_width – [in] destination data width, see dma_data_width_e
src_burst_len – [in] source burst length, see dma_burst_type_e
dst_burst_len – [in] destination burst length, see dma_burst_type_e
- 返回值:
0 – success [BK_RET_OK]
other – fail
- 返回:
result
-
int32_t drv_dma_cfg_hw_request(uint32_t chn_instance, dma_from_to_e e_src_dst, dma_req_mux_e e_req)
config HW request for this dma channel.
对该dma channel的源和目标选择对应的硬件request信号,外设使用dma的时候需要进行配置
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
e_src_dst – [in] 选择源还是目标,see dma_from_to_e
e_req – [in] dma request, see dma_req_mux_e
- 返回值:
0 – success [BK_RET_OK]
other – fail
- 返回:
result
-
int32_t drv_dma_load(uint32_t chn_instance, uint32_t transmit_bytes, uint32_t src_addr_start, uint32_t dst_addr_start, uint32_t src_addr_end, uint32_t dst_addr_end)
load dma address and length.
加载dma搬移的长度和地址,end地址也需要配置,用来判断是否是不动的FIFO地址 调用该函数前应该先调用 drv_dma_cfg_param() 和 drv_dma_cfg_hw_request()
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
transmit_bytes – [in] 以byte为单位的搬移长度
src_addr_start – [in] 搬移源的开始地址,需要和data width对齐
dst_addr_start – [in] 搬移目标的开始地址,需要和data width对齐
src_addr_end – [in] 搬移源的结束地址,对于memory to memory, 该地址等于transmit_bytes + src_addr_start
dst_addr_end – [in] 搬移目标的结束地址,对于memory to memory, 该地址等于transmit_bytes + dst_addr_start
- 返回值:
0 – success [BK_RET_OK]
other – fail
- 返回:
result
-
int32_t drv_dma_update_loop_pause_addr(uint32_t chn_instance, dma_from_to_e e_src_dst, uint32_t addr)
config pause address in loop mode.
对于循环重复搬移的情况,涉及到读写数据的同步问题,该地址用来告诉dma读写的时候不用越过它 例如,将memory数据循环搬到codec中,如果软件动作太慢,则dma会搬到一些软件还未填写的数据 如果软件配置了pause address,则dma会在到达这个地址后等到软件填了数据,更新地址后再进行搬数
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
e_src_dst – [in] 配置源还是目标,see dma_from_to_e
addr – [in] pause address for dma
- 返回值:
0 – success [BK_RET_OK]
other – fail
- 返回:
result
-
int32_t drv_dma_chn_enable(uint32_t chn_instance, bool enable)
enable dma channel or not.
使能该dma channel
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
enable – [in] true: enable false: disable
- 返回值:
0 – success [BK_RET_OK]
other – fail
- 返回:
result
-
bool drv_dma_chn_is_enabled(uint32_t chn_instance)
check the dma channel is enabled or not.
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
- 返回值:
true – dma channel is enabled
false – dma channel is not enabled
- 返回:
is enabled
-
uint32_t drv_dma_get_remain_len(uint32_t chn_instance)
get remain length.
dma还未完成搬移,通过该函数可以知道还剩多少数据未搬
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
- 返回:
left size in bytes.
-
uint32_t drv_dma_get_src_read_addr(uint32_t chn_instance)
get source read address.
获取此时dma搬移源的读地址(下一个要读的地址)
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
- 返回:
source read pointer
-
uint32_t drv_dma_get_dst_write_addr(uint32_t chn_instance)
get destination write address.
获取此时dma搬移目标的写地址(下一个要写的地址)
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
- 返回:
destination write pointer
-
int32_t drv_dma_flush_unaligned_data(uint32_t chn_instance)
flush unaligned data in dma channel.
如果因为对齐原因导致dma无法送出部分数据,可以调用该接口
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
- 返回值:
0 – success [BK_RET_OK]
other – fail
- 返回:
result
-
void drv_dma_wait_flush_unaligned_data_done(uint32_t chn_instance)
wait flush unaligned data finish.
该函数会阻塞直到dma将flush动作完成,实际上是很快完成的的,通常不会在该函数中while住
- 参数:
chn_instance – [in] return value of drv_dma_chn_alloc()
- 返回:
N/A
-
int32_t drv_dma_get_loop_pause_addr(uint32_t chn_instance, dma_from_to_e e_src_dst)
drv_dma_get_loop_pause_addr brief description
得到当前的pause地址
参见
备注
- 参数:
chn_instance – [in]
e_src_dst – [in]
- 返回值:
0 – success
other – fail
- 返回:
result
Macros
-
DMA_DEVICE_NUM
Type Definitions
-
typedef enum _dma_mode_e dma_mode_e
-
typedef enum _dma_from_to_e dma_from_to_e
-
typedef enum _dma_data_width_e dma_data_width_e
-
typedef enum _dma_burst_type_e dma_burst_type_e
-
typedef void (*pfunc_dma_cb_t)(uint32_t chn_instance, void *pv_arg)
Enumerations
-
enum _dma_mode_e
Values:
-
enumerator DRV_DMA_SINGLE_XFER
-
enumerator DRV_DMA_LOOP_REPEAT
single transfer
repeat forever
-
enumerator DRV_DMA_SINGLE_XFER
-
enum _dma_from_to_e
Values:
-
enumerator DRV_DMA_SOURCE
-
enumerator DRV_DMA_DESTINATION
from source
to destination
-
enumerator DRV_DMA_SOURCE