HPM SDK
HPMicro Software Development Kit
hpm_dma_mgr.c File Reference
#include <string.h>
#include "hpm_dma_mgr.h"
#include "hpm_soc.h"

Macros

#define HPM_DMA_MGR   (&s_dma_mngr_ctx)
 

Typedefs

typedef struct _dma_instance_info dma_chn_info_t
 
typedef struct _dma_channel_context dma_chn_context_t
 DMA Channel Context Structure. More...
 
typedef struct _dma_mgr_context dma_mgr_context_t
 DMA Manager Context Structure. More...
 

Functions

static dma_chn_context_tdma_mgr_search_chn_context (const dma_resource_t *resource)
 Search DMA channel context for specified DMA channel resource. More...
 
static uint32_t dma_mgr_enter_critical (void)
 
static void dma_mgr_exit_critical (uint32_t level)
 
void dma_mgr_isr_handler (DMA_Type *ptr, uint32_t instance)
 DMA Manager ISR handler. More...
 
void dma0_isr (void)
 
void dma_mgr_init (void)
 Initialize DMA Manager Context. More...
 
hpm_stat_t dma_mgr_request_resource (dma_resource_t *resource)
 Request DMA resource from DMA Manager. More...
 
hpm_stat_t dma_mgr_release_resource (const dma_resource_t *resource)
 Release DMA resource. More...
 
hpm_stat_t dma_mgr_enable_dma_irq_with_priority (const dma_resource_t *resource, uint32_t priority)
 Enable DMA interrupt with priority. More...
 
hpm_stat_t dma_mgr_disable_dma_irq (const dma_resource_t *resource)
 Disable DMA interrupt NOTE: Each DMA instance consists of several DMA channels, disabling the DMA interrupt will disable the global DMA interrupt for all DMA channels. Please be aware of the impact. More...
 
hpm_stat_t dma_mgr_install_chn_tc_callback (const dma_resource_t *resource, dma_mgr_chn_cb_t callback, void *user_data)
 Install Interrupt Callback for DMA channel transfer complete. More...
 
hpm_stat_t dma_mgr_install_chn_half_tc_callback (const dma_resource_t *resource, dma_mgr_chn_cb_t callback, void *user_data)
 Install Interrupt Callback for DMA channel half transfer complete. More...
 
hpm_stat_t dma_mgr_install_chn_error_callback (const dma_resource_t *resource, dma_mgr_chn_cb_t callback, void *user_data)
 Install Interrupt Callback for DMA channel transfer error. More...
 
hpm_stat_t dma_mgr_install_chn_abort_callback (const dma_resource_t *resource, dma_mgr_chn_cb_t callback, void *user_data)
 Install Interrupt Callback for DMA channel transfer abort. More...
 
void dma_mgr_get_default_chn_config (dma_mgr_chn_conf_t *config)
 Get DMA channel default config. More...
 
hpm_stat_t dma_mgr_setup_channel (const dma_resource_t *resource, dma_mgr_chn_conf_t *config)
 Setup channel config. More...
 
hpm_stat_t dma_mgr_config_linked_descriptor (const dma_resource_t *resource, dma_mgr_chn_conf_t *config, dma_mgr_linked_descriptor_t *descriptor)
 Setup chain linked descriptor config. More...
 
hpm_stat_t dma_mgr_enable_channel (const dma_resource_t *resource)
 Enable DMA channel, start transfer. More...
 
hpm_stat_t dma_mgr_disable_channel (const dma_resource_t *resource)
 Disable DMA channel. More...
 
hpm_stat_t dma_mgr_check_chn_enable (const dma_resource_t *resource, bool *enable)
 Check DMA channel enable status. More...
 
hpm_stat_t dma_mgr_enable_chn_irq (const dma_resource_t *resource, uint32_t irq_mask)
 Enable DMA channel interrupt. More...
 
hpm_stat_t dma_mgr_disable_chn_irq (const dma_resource_t *resource, uint32_t irq_mask)
 Disable DMA channel interrupt. More...
 
hpm_stat_t dma_mgr_set_chn_priority (const dma_resource_t *resource, uint8_t priority)
 Set DMA channel priority. More...
 
hpm_stat_t dma_mgr_set_chn_src_work_mode (const dma_resource_t *resource, uint8_t mode)
 Set DMA channel source work mode. More...
 
hpm_stat_t dma_mgr_set_chn_dst_work_mode (const dma_resource_t *resource, uint8_t mode)
 Set DMA channel destination work mode. More...
 
hpm_stat_t dma_mgr_set_chn_src_burst_size (const dma_resource_t *resource, uint8_t burstsize)
 Set DMA channel source burst size. More...
 
hpm_stat_t dma_mgr_get_chn_remaining_transize (const dma_resource_t *resource, uint32_t *size)
 Get DMA channel remaining transfer size. More...
 
hpm_stat_t dma_mgr_set_chn_transize (const dma_resource_t *resource, uint32_t size)
 Set DMA channel transfer size. More...
 
hpm_stat_t dma_mgr_set_chn_src_width (const dma_resource_t *resource, uint8_t width)
 Set DMA channel source width. More...
 
hpm_stat_t dma_mgr_set_chn_dst_width (const dma_resource_t *resource, uint8_t width)
 Set DMA channel destination width. More...
 
hpm_stat_t dma_mgr_set_chn_src_addr (const dma_resource_t *resource, uint32_t addr)
 Set DMA channel source address. More...
 
hpm_stat_t dma_mgr_set_chn_dst_addr (const dma_resource_t *resource, uint32_t addr)
 Set DMA channel destination address. More...
 
hpm_stat_t dma_mgr_set_chn_src_addr_ctrl (const dma_resource_t *resource, uint8_t addr_ctrl)
 Set DMA channel source address control mode. More...
 
hpm_stat_t dma_mgr_set_chn_dst_addr_ctrl (const dma_resource_t *resource, uint8_t addr_ctrl)
 Set DMA channel destination address control mode. More...
 
hpm_stat_t dma_mgr_set_chn_infinite_loop_mode (const dma_resource_t *resource, bool infinite_loop)
 Set DMA channel infinite loop mode. Attention: only DMAV2 support. More...
 
hpm_stat_t dma_mgr_set_chn_src_busrt_option (const dma_resource_t *resource, uint8_t burst_opt)
 Set DMA channel source burst option. Attention: only DMAV2 support. More...
 
hpm_stat_t dma_mgr_set_chn_handshake_option (const dma_resource_t *resource, uint8_t handshake_opt)
 Set DMA channel handshake option. Attention: only DMAV2 support. More...
 
hpm_stat_t dma_mgr_abort_chn_transfer (const dma_resource_t *resource)
 Abort DMA channel transfer. More...
 
hpm_stat_t dma_mgr_check_chn_transfer_status (const dma_resource_t *resource, uint32_t *status)
 Check DMA channel transfer status. More...
 
hpm_stat_t dma_mgr_set_source_burst_in_fixed_transize_enable (const dma_resource_t *resource, bool enable)
 Set DMA channel source burst in fixed transfer size enable or disable. More...
 
hpm_stat_t dma_mgr_set_destination_burst_in_fix_transize_enable (const dma_resource_t *resource, bool enable)
 Set DMA channel destination burst in fixed transfer size enable or disable. More...
 
hpm_stat_t dma_mgr_set_swap_mode (const dma_resource_t *resource, uint8_t swap_mode)
 Set DMA channel swap mode. More...
 
hpm_stat_t dma_mgr_set_swap_table (const dma_resource_t *resource, uint32_t swap_table)
 Set DMA channel swap table. More...
 

Variables

static dma_mgr_context_t s_dma_mngr_ctx
 

Macro Definition Documentation

◆ HPM_DMA_MGR

#define HPM_DMA_MGR   (&s_dma_mngr_ctx)

Typedef Documentation

◆ dma_chn_context_t

typedef struct _dma_channel_context dma_chn_context_t

DMA Channel Context Structure.

◆ dma_chn_info_t

typedef struct _dma_instance_info dma_chn_info_t

◆ dma_mgr_context_t

typedef struct _dma_mgr_context dma_mgr_context_t

DMA Manager Context Structure.

Function Documentation

◆ dma0_isr()

void dma0_isr ( void  )

◆ dma_mgr_abort_chn_transfer()

hpm_stat_t dma_mgr_abort_chn_transfer ( const dma_resource_t resource)

Abort DMA channel transfer.

Parameters
[in]resourceDMA resource
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_check_chn_enable()

hpm_stat_t dma_mgr_check_chn_enable ( const dma_resource_t resource,
bool *  enable 
)

Check DMA channel enable status.

Parameters
[in]resourceDMA resource
[out]enableenable status
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_check_chn_transfer_status()

hpm_stat_t dma_mgr_check_chn_transfer_status ( const dma_resource_t resource,
uint32_t *  status 
)

Check DMA channel transfer status.

Parameters
[in]resourceDMA resource
[out]statustransfer status DMA_MGR_CHANNEL_STATUS_ONGOING if transfer is still ongoing DMA_MGR_CHANNEL_STATUS_ERROR if any error occurred during transferring DMA_MGR_CHANNEL_STATUS_ABORT if transfer is aborted DMA_MGR_CHANNEL_STATUS_TC if transfer is finished without error DMA_MGR_CHANNEL_STATUS_HALF_TC if half transfer complete without error. Attention: only DMAV2 support
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_config_linked_descriptor()

hpm_stat_t dma_mgr_config_linked_descriptor ( const dma_resource_t resource,
dma_mgr_chn_conf_t config,
dma_mgr_linked_descriptor_t descriptor 
)

Setup chain linked descriptor config.

Parameters
[in]resourceDMA resource
[in]configDMA channel config
[out]descriptorlinked descriptor config data pointer
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_disable_channel()

hpm_stat_t dma_mgr_disable_channel ( const dma_resource_t resource)

Disable DMA channel.

Parameters
[in]resourceDMA resource
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_disable_chn_irq()

hpm_stat_t dma_mgr_disable_chn_irq ( const dma_resource_t resource,
uint32_t  irq_mask 
)

Disable DMA channel interrupt.

Parameters
[in]resourceDMA resource
[in]irq_maskirq mask, refer to DMA_MGR_INTERRUPT_MASK_xxxx
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_disable_dma_irq()

hpm_stat_t dma_mgr_disable_dma_irq ( const dma_resource_t resource)

Disable DMA interrupt NOTE: Each DMA instance consists of several DMA channels, disabling the DMA interrupt will disable the global DMA interrupt for all DMA channels. Please be aware of the impact.

Parameters
[in]resourceDMA resource
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_enable_channel()

hpm_stat_t dma_mgr_enable_channel ( const dma_resource_t resource)

Enable DMA channel, start transfer.

Parameters
[in]resourceDMA resource
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_enable_chn_irq()

hpm_stat_t dma_mgr_enable_chn_irq ( const dma_resource_t resource,
uint32_t  irq_mask 
)

Enable DMA channel interrupt.

Parameters
[in]resourceDMA resource
[in]irq_maskirq mask, refer to DMA_MGR_INTERRUPT_MASK_xxxx
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_enable_dma_irq_with_priority()

hpm_stat_t dma_mgr_enable_dma_irq_with_priority ( const dma_resource_t resource,
uint32_t  priority 
)

Enable DMA interrupt with priority.

Parameters
[in]resourceDMA resource
[in]priorityInterrupt Priority
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_enter_critical()

static uint32_t dma_mgr_enter_critical ( void  )
static

◆ dma_mgr_exit_critical()

static void dma_mgr_exit_critical ( uint32_t  level)
static

◆ dma_mgr_get_chn_remaining_transize()

hpm_stat_t dma_mgr_get_chn_remaining_transize ( const dma_resource_t resource,
uint32_t *  size 
)

Get DMA channel remaining transfer size.

Parameters
[in]resourceDMA resource
[out]sizeremaining transfer size of the channel.
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_get_default_chn_config()

void dma_mgr_get_default_chn_config ( dma_mgr_chn_conf_t config)

Get DMA channel default config.

Parameters
[out]configconfig data pointer

◆ dma_mgr_init()

void dma_mgr_init ( void  )

Initialize DMA Manager Context.

◆ dma_mgr_install_chn_abort_callback()

hpm_stat_t dma_mgr_install_chn_abort_callback ( const dma_resource_t resource,
dma_mgr_chn_cb_t  callback,
void *  user_data 
)

Install Interrupt Callback for DMA channel transfer abort.

Parameters
[in]resourceDMA resource
[in]callbackInterrupt callback for DMA resource
[in]user_dataUser data used in the callback
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_install_chn_error_callback()

hpm_stat_t dma_mgr_install_chn_error_callback ( const dma_resource_t resource,
dma_mgr_chn_cb_t  callback,
void *  user_data 
)

Install Interrupt Callback for DMA channel transfer error.

Parameters
[in]resourceDMA resource
[in]callbackInterrupt callback for DMA resource
[in]user_dataUser data used in the callback
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_install_chn_half_tc_callback()

hpm_stat_t dma_mgr_install_chn_half_tc_callback ( const dma_resource_t resource,
dma_mgr_chn_cb_t  callback,
void *  user_data 
)

Install Interrupt Callback for DMA channel half transfer complete.

Parameters
[in]resourceDMA resource
[in]callbackInterrupt callback for DMA resource
[in]user_dataUser data used in the callback
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_install_chn_tc_callback()

hpm_stat_t dma_mgr_install_chn_tc_callback ( const dma_resource_t resource,
dma_mgr_chn_cb_t  callback,
void *  user_data 
)

Install Interrupt Callback for DMA channel transfer complete.

Parameters
[in]resourceDMA resource
[in]callbackInterrupt callback for DMA resource
[in]user_dataUser data used in the callback
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_isr_handler()

void dma_mgr_isr_handler ( DMA_Type ptr,
uint32_t  instance 
)

DMA Manager ISR handler.

◆ dma_mgr_release_resource()

hpm_stat_t dma_mgr_release_resource ( const dma_resource_t resource)

Release DMA resource.

Parameters
[in]resourceDMA resource
Return values
status_successif no error occurred
status_invalid_argumentif the parameter is invalid

◆ dma_mgr_request_resource()

hpm_stat_t dma_mgr_request_resource ( dma_resource_t resource)

Request DMA resource from DMA Manager.

Parameters
[out]resourceDMA resource
Return values
status_successif no error occurred
status_invalid_argumentif the parameter is invalid
status_dma_mgr_no_resourceif all DMA channels are occupied;

◆ dma_mgr_search_chn_context()

static dma_chn_context_t * dma_mgr_search_chn_context ( const dma_resource_t resource)
static

Search DMA channel context for specified DMA channel resource.

Parameters
[in]resourceDMA Channel resource
Returns
The request DMA channel context if resource is valid or NULL if resource in invalid

◆ dma_mgr_set_chn_dst_addr()

hpm_stat_t dma_mgr_set_chn_dst_addr ( const dma_resource_t resource,
uint32_t  addr 
)

Set DMA channel destination address.

Parameters
[in]resourceDMA resource
[in]addrdestination address
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_dst_addr_ctrl()

hpm_stat_t dma_mgr_set_chn_dst_addr_ctrl ( const dma_resource_t resource,
uint8_t  addr_ctrl 
)

Set DMA channel destination address control mode.

Parameters
[in]resourceDMA resource
[in]addr_ctrldestination address control mode
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_dst_width()

hpm_stat_t dma_mgr_set_chn_dst_width ( const dma_resource_t resource,
uint8_t  width 
)

Set DMA channel destination width.

Parameters
[in]resourceDMA resource
[in]widthtransfer destination width of the channel
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_dst_work_mode()

hpm_stat_t dma_mgr_set_chn_dst_work_mode ( const dma_resource_t resource,
uint8_t  mode 
)

Set DMA channel destination work mode.

Parameters
[in]resourceDMA resource
[in]modeDMA destination work mode
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_handshake_option()

hpm_stat_t dma_mgr_set_chn_handshake_option ( const dma_resource_t resource,
uint8_t  handshake_opt 
)

Set DMA channel handshake option. Attention: only DMAV2 support.

Parameters
[in]resourceDMA resource
[in]handshake_opthandshake option
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_infinite_loop_mode()

hpm_stat_t dma_mgr_set_chn_infinite_loop_mode ( const dma_resource_t resource,
bool  infinite_loop 
)

Set DMA channel infinite loop mode. Attention: only DMAV2 support.

Parameters
[in]resourceDMA resource
[in]infinite_loopfalse - normal mode(single times mode); true - infinite loop mode(cycle mode)
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_priority()

hpm_stat_t dma_mgr_set_chn_priority ( const dma_resource_t resource,
uint8_t  priority 
)

Set DMA channel priority.

Parameters
[in]resourceDMA resource
[in]priorityDMA channel priority
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_src_addr()

hpm_stat_t dma_mgr_set_chn_src_addr ( const dma_resource_t resource,
uint32_t  addr 
)

Set DMA channel source address.

Parameters
[in]resourceDMA resource
[in]addrsource address
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_src_addr_ctrl()

hpm_stat_t dma_mgr_set_chn_src_addr_ctrl ( const dma_resource_t resource,
uint8_t  addr_ctrl 
)

Set DMA channel source address control mode.

Parameters
[in]resourceDMA resource
[in]addr_ctrlsource address control mode
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_src_burst_size()

hpm_stat_t dma_mgr_set_chn_src_burst_size ( const dma_resource_t resource,
uint8_t  burstsize 
)

Set DMA channel source burst size.

Parameters
[in]resourceDMA resource
[in]burstsizeDMA source burst size when BURSTOPT is 0, please reference follows:
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_src_busrt_option()

hpm_stat_t dma_mgr_set_chn_src_busrt_option ( const dma_resource_t resource,
uint8_t  burst_opt 
)

Set DMA channel source burst option. Attention: only DMAV2 support.

Parameters
[in]resourceDMA resource
[in]burst_optburst option
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_src_width()

hpm_stat_t dma_mgr_set_chn_src_width ( const dma_resource_t resource,
uint8_t  width 
)

Set DMA channel source width.

Parameters
[in]resourceDMA resource
[in]widthtransfer source width of the channel
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_src_work_mode()

hpm_stat_t dma_mgr_set_chn_src_work_mode ( const dma_resource_t resource,
uint8_t  mode 
)

Set DMA channel source work mode.

Parameters
[in]resourceDMA resource
[in]modeDMA source work mode
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_chn_transize()

hpm_stat_t dma_mgr_set_chn_transize ( const dma_resource_t resource,
uint32_t  size 
)

Set DMA channel transfer size.

Parameters
[in]resourceDMA resource
[in]sizetransfer size of the channel.
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

◆ dma_mgr_set_destination_burst_in_fix_transize_enable()

hpm_stat_t dma_mgr_set_destination_burst_in_fix_transize_enable ( const dma_resource_t resource,
bool  enable 
)

Set DMA channel destination burst in fixed transfer size enable or disable.

Parameters
[in]resourceDMA resource
[in]enablefalse - disable; true - enable

◆ dma_mgr_set_source_burst_in_fixed_transize_enable()

hpm_stat_t dma_mgr_set_source_burst_in_fixed_transize_enable ( const dma_resource_t resource,
bool  enable 
)

Set DMA channel source burst in fixed transfer size enable or disable.

Parameters
[in]resourceDMA resource
[in]enablefalse - disable; true - enable

◆ dma_mgr_set_swap_mode()

hpm_stat_t dma_mgr_set_swap_mode ( const dma_resource_t resource,
uint8_t  swap_mode 
)

Set DMA channel swap mode.

Parameters
[in]resourceDMA resource
[in]swap_modeswap mode

◆ dma_mgr_set_swap_table()

hpm_stat_t dma_mgr_set_swap_table ( const dma_resource_t resource,
uint32_t  swap_table 
)

Set DMA channel swap table.

Parameters
[in]resourceDMA resource
[in]swap_tableswap table

◆ dma_mgr_setup_channel()

hpm_stat_t dma_mgr_setup_channel ( const dma_resource_t resource,
dma_mgr_chn_conf_t config 
)

Setup channel config.

Parameters
[in]resourceDMA resource
[in]configDMA channel config
Return values
status_successif no error occurred
status_invalid_argumentif any parameters are invalid

Variable Documentation

◆ s_dma_mngr_ctx

dma_mgr_context_t s_dma_mngr_ctx
static