Microchip® Advanced Software Framework

dma.c File Reference
#include <string.h>
#include "dma.h"
#include "clock.h"
#include "system_interrupt.h"

Data Structures

struct  _dma_module
 

Macros

#define DMA_CHANNEL_MASK   (0x1f)
 DMA channel mask. More...
 
#define MAX_JOB_RESUME_COUNT   10000
 Maximum retry counter for resuming a job transfer. More...
 

Functions

static uint8_t _dma_find_first_free_channel_and_allocate (void)
 Find a free channel for a DMA resource. More...
 
static void _dma_release_channel (uint8_t channel)
 Release an allocated DMA channel. More...
 
static void _dma_set_config (struct dma_resource *resource, struct dma_resource_config *resource_config)
 Configure the DMA resource. More...
 
void dma_abort_job (struct dma_resource *resource)
 Abort a DMA transfer. More...
 
enum status_code dma_add_descriptor (struct dma_resource *resource, DmacDescriptor *descriptor)
 Add a DMA transfer descriptor to a DMA resource. More...
 
enum status_code dma_allocate (struct dma_resource *resource, struct dma_resource_config *config)
 Allocate a DMA with configurations. More...
 
void dma_descriptor_create (DmacDescriptor *descriptor, struct dma_descriptor_config *config)
 Create a DMA transfer descriptor with configurations. More...
 
enum status_code dma_free (struct dma_resource *resource)
 Free an allocated DMA resource. More...
 
void dma_get_config_defaults (struct dma_resource_config *config)
 Initializes config with predefined default values. More...
 
void dma_resume_job (struct dma_resource *resource)
 Resume a suspended DMA transfer. More...
 
enum status_code dma_start_transfer_job (struct dma_resource *resource)
 Start a DMA transfer. More...
 
void dma_suspend_job (struct dma_resource *resource)
 Suspend a DMA transfer. More...
 
void DMAC_Handler (void)
 DMA interrupt service routine. More...
 

Variables

static struct dma_resource_dma_active_resource [CONF_MAX_USED_CHANNEL_NUM]
 Internal DMA resource pool. More...
 
struct _dma_module _dma_inst
 
uint8_t g_chan_interrupt_flag [CONF_MAX_USED_CHANNEL_NUM] ={0}
 
DmacDescriptor
descriptor_section[CONF_MAX_USED_CHANNEL_NUM] 
SECTION_DMAC_DESCRIPTOR
 Initial write back memory section. More...
 

#define DMA_CHANNEL_MASK   (0x1f)

DMA channel mask.

#define MAX_JOB_RESUME_COUNT   10000

Maximum retry counter for resuming a job transfer.

Referenced by dma_resume_job().

static uint8_t _dma_find_first_free_channel_and_allocate ( void  )
static

Find a free channel for a DMA resource.

Find a channel for the requested DMA resource.

Returns
Status of channel allocation.
Return values
DMA_INVALID_CHANNELNo channel available
countAllocated channel for the DMA resource

References _dma_module::allocated_channels, DMA_INVALID_CHANNEL, _dma_module::free_channels, system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

Referenced by dma_allocate().

static void _dma_release_channel ( uint8_t  channel)
static

Release an allocated DMA channel.

Parameters
[in]channelChannel id to be released

References _dma_module::allocated_channels, and _dma_module::free_channels.

Referenced by dma_free().

static void _dma_set_config ( struct dma_resource resource,
struct dma_resource_config resource_config 
)
static

Configure the DMA resource.

Parameters
[in]dma_resourcePointer to a DMA resource instance
[out]resource_configConfigurations of the DMA resource

Select the DMA channel and clear software trigger

Enable event output, the event output selection is configured in each transfer descriptor

References Assert, dma_resource::channel_id, dma_resource_config::event_config, dma_events_config::event_output_enable, dma_events_config::input_action, dma_resource_config::peripheral_trigger, dma_resource_config::priority, system_interrupt_enter_critical_section(), system_interrupt_leave_critical_section(), and dma_resource_config::trigger_action.

Referenced by dma_allocate().

struct dma_resource* _dma_active_resource[CONF_MAX_USED_CHANNEL_NUM]
static

Internal DMA resource pool.

Referenced by dma_allocate(), dma_free(), and DMAC_Handler().

struct _dma_module _dma_inst
Initial value:
= {
._dma_init = false,
.allocated_channels = 0,
.free_channels = CONF_MAX_USED_CHANNEL_NUM,
}
DmacDescriptor _write_back_section [CONF_MAX_USED_CHANNEL_NUM] SECTION_DMAC_DESCRIPTOR

Initial write back memory section.