DMA API

[中文]

DMA (Direct Memory Access) API interface.

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.

Returns

  • 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.

Returns

  • 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.

Parameters

user_id – DMA channel applicant

Returns

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.

Parameters
  • user_id – DMA channel applicant, the same as in bk_dma_alloc.

  • id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

uint32_t bk_dma_user(dma_id_t id)

get the user of DMA channel

Parameters

id – DMA channel

Returns

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

Parameters
  • id – DMA channel

  • config – DMA configuration

Returns

  • 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

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_start(dma_id_t id)

Start a DMA channel.

Parameters

id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_stop(dma_id_t id)

Stop a DMA channel.

Parameters

id – DMA channel

Returns

  • 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.

Parameters
  • id – DMA channel

  • data – DMA transfer data

  • size – data size

Returns

  • 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.

Parameters
  • id – DMA channel

  • data – DMA transfer data

  • size – data size

Returns

  • 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.

Parameters

id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_disable_finish_interrupt(dma_id_t id)

Disable DMA finish intterrup.

Parameters

id – DMA channel

Returns

  • 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.

Parameters

id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_disable_half_finish_interrupt(dma_id_t id)

Disable DMA half finish intterrup.

Parameters

id – DMA channel

Returns

  • 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.

Parameters
  • id – DMA channel

  • half_finish_isr – DMA half finish callback

  • finish_isr – DMA finish callback

Returns

  • 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.

Parameters

id – DMA channel

Returns

  • 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.

Parameters
  • id – DMA channel

  • tran_len – DMA transfer length, the tran_len should be <= bk_dma_get_transfer_len_max() bytes.

Returns

  • 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)

Parameters
  • id – DMA channel

  • start_addr – DMA source start address

  • end_addr – DMA source end address

Returns

  • 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.

Parameters
  • id – DMA channel

  • start_addr – DMA source start address

Returns

  • 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)

Parameters
  • id – DMA channel

  • start_addr – DMA dest start address

  • end_addr – DMA dest end address

Returns

  • 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.

Parameters
  • id – DMA channel

  • start_addr – DMA dest start address

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_enable_src_addr_increase(dma_id_t id)

Enable DMA source address increase.

Parameters

id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_disable_src_addr_increase(dma_id_t id)

Disable DMA source address increase.

Parameters

id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_enable_src_addr_loop(dma_id_t id)

Enable DMA source address loop.

Parameters

id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_disable_src_addr_loop(dma_id_t id)

Disable DMA source address loop.

Parameters

id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_enable_dest_addr_increase(dma_id_t id)

Enable DMA dest address increase.

Parameters

id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_disable_dest_addr_increase(dma_id_t id)

Disable DMA dest address increase.

Parameters

id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_enable_dest_addr_loop(dma_id_t id)

Enable DMA dest address loop.

Parameters

id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma_disable_dest_addr_loop(dma_id_t id)

Disable DMA dest address loop.

Parameters

id – DMA channel

Returns

  • BK_OK: succeed

  • others: other errors.

uint32_t bk_dma_get_remain_len(dma_id_t id)

Get DMA transfer remain length.

Parameters

id – DMA channel

Returns

DMA transfer remain length

uint32_t bk_dma_get_enable_status(dma_id_t id)

Gets the current DMA channel working status.

Parameters

id – DMA channel

Returns

  • 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.

Parameters
  • id – DMA channel

  • attr – DMA privileged attr

Returns

  • 0: Channel idle state

  • others: Channel busy state.