DMA API
DMA (Direct Memory Access) 直接内存访问API接口。
Header File
Functions
-
bk_err_t bk_dma_driver_init(void)
Init the DMA driver.
This API init the resoure common to all dma channels:
Init dma driver control memory
This API should be called before any other dma APIs.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_driver_deinit(void)
Deinit the DMA driver.
This API free all resource related to dma and power down all dma channels.
- 返回
BK_OK: succeed
others: other errors.
-
dma_id_t bk_dma_alloc(u16 user_id)
Allocate a DMA channel.
This API should be called before any other dma channel APIs.
- Attention
: This API can only be called in task context,
and can’t be called in context that interrupt is disabled.
- 参数
user_id – DMA channel applicant
- 返回
DMA channel id.
> DMA_ID_MAX: no free DMA channel.
-
bk_err_t bk_dma_free(u16 user_id, dma_id_t id)
Free the DMA channel.
- Attention
: This API can only be called in task context,
and can’t be called in context that interrupt is disabled.
- 参数
user_id – DMA channel applicant, the same as in bk_dma_alloc.
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
uint32_t bk_dma_user(dma_id_t id)
get the user of DMA channel
- 参数
id – DMA channel
- 返回
DMA channel user_id.
u32: high u16 is the CPU_ID, low 16 bits is the applicant_id.
-
bk_err_t bk_dma_init(dma_id_t id, const dma_config_t *config)
Init the DMA channel.
- Attention
1. the higher channel priority value, the higher the priority
- 参数
id – DMA channel
config – DMA configuration
- 返回
BK_OK: succeed
BK_ERR_DMA_NOT_INIT: DMA driver not init
BK_ERR_NULL_PARAM: config is NULL
BK_ERR_DMA_ID: invalid DMA channel
BK_ERR_DMA_INVALID_ADDR: invalid DMA address
others: other errors.
-
bk_err_t bk_dma_deinit(dma_id_t id)
Deinit a DMA channel.
This API deinit the DMA channel:
Stop the DMA channel
Reset all configuration of DMA channel to default value
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_start(dma_id_t id)
Start a DMA channel.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_stop(dma_id_t id)
Stop a DMA channel.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_write(dma_id_t id, const uint8_t *data, uint32_t size)
Transfer data from memory to peripheral.
- 参数
id – DMA channel
data – DMA transfer data
size – data size
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_read(dma_id_t id, uint8_t *data, uint32_t size)
Transfer data from peripheral to memory.
- 参数
id – DMA channel
data – DMA transfer data
size – data size
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_enable_finish_interrupt(dma_id_t id)
Enable DMA finish intterrup.
@NOTES before enable interrupt, please confirm have called bk_dma_register_isr.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_disable_finish_interrupt(dma_id_t id)
Disable DMA finish intterrup.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_enable_half_finish_interrupt(dma_id_t id)
Enable DMA half finish intterrup.
@NOTES before enable interrupt, please confirm have called bk_dma_register_isr.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_disable_half_finish_interrupt(dma_id_t id)
Disable DMA half finish intterrup.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_register_isr(dma_id_t id, dma_isr_t half_finish_isr, dma_isr_t finish_isr)
Register the interrupt service routine for DMA channel.
This API regist dma isr callback function.
- 参数
id – DMA channel
half_finish_isr – DMA half finish callback
finish_isr – DMA finish callback
- 返回
BK_OK: succeed
others: other errors.
-
uint32_t bk_dma_get_transfer_len_max(dma_id_t id)
get DMA transfer max length in one round, default value is 65536 bytes.
- 参数
id – DMA channel
- 返回
max len: how many bytes can be copy by DMA in one round.
-
bk_err_t bk_dma_set_transfer_len(dma_id_t id, uint32_t tran_len)
Set DMA transfer length.
- 参数
id – DMA channel
tran_len – DMA transfer length, the tran_len should be <= bk_dma_get_transfer_len_max() bytes.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_set_src_addr(dma_id_t id, uint32_t start_addr, uint32_t end_addr)
Set DMA source address.
- Attention
1. address should be zero when there is no value, e.g. bk_dma_set_src_addr(1, 0x80210C, 0)
- 参数
id – DMA channel
start_addr – DMA source start address
end_addr – DMA source end address
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_set_src_start_addr(dma_id_t id, uint32_t start_addr)
Set DMA source start address.
- 参数
id – DMA channel
start_addr – DMA source start address
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_set_dest_addr(dma_id_t id, uint32_t start_addr, uint32_t end_addr)
Set DMA dest address.
- Attention
1. address should be zero when there is no value, e.g. bk_dma_set_dest_addr(1, 0x80210C, 0)
- 参数
id – DMA channel
start_addr – DMA dest start address
end_addr – DMA dest end address
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_set_dest_start_addr(dma_id_t id, uint32_t start_addr)
Set DMA dest start address.
- 参数
id – DMA channel
start_addr – DMA dest start address
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_enable_src_addr_increase(dma_id_t id)
Enable DMA source address increase.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_disable_src_addr_increase(dma_id_t id)
Disable DMA source address increase.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_enable_src_addr_loop(dma_id_t id)
Enable DMA source address loop.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_disable_src_addr_loop(dma_id_t id)
Disable DMA source address loop.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_enable_dest_addr_increase(dma_id_t id)
Enable DMA dest address increase.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_disable_dest_addr_increase(dma_id_t id)
Disable DMA dest address increase.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_enable_dest_addr_loop(dma_id_t id)
Enable DMA dest address loop.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_dma_disable_dest_addr_loop(dma_id_t id)
Disable DMA dest address loop.
- 参数
id – DMA channel
- 返回
BK_OK: succeed
others: other errors.
-
uint32_t bk_dma_get_remain_len(dma_id_t id)
Get DMA transfer remain length.
- 参数
id – DMA channel
- 返回
DMA transfer remain length
-
uint32_t bk_dma_get_enable_status(dma_id_t id)
Gets the current DMA channel working status.
- 参数
id – DMA channel
- 返回
0: Channel idle state
others: Channel busy state.
-
bk_err_t bk_dma_flush_src_buffer(dma_id_t id)
flush reserved data in dma internal buffer I.E:If source data width is not 4bytes, and data size isn’t 4bytes align, but dest data width is 4bytes, then maybe 1~3 bytes data reserved in dma internal buffer, then the left 1~3 bytes data not copy to dest address.
- 参数
id – DMA channel
attr – DMA privileged attr
- 返回
0: Channel idle state
others: Channel busy state.