See Quick start guide for the XMEGA DMA driver.
This is a driver for configuration, enabling, disabling and use of the on-chip XMEGA Direct Memory Access (DMA) controller.
The direct memory access controller depends on the following modules:
Modules | |
Related Project(s) | |
In this section you can find all the projects related to the Direct Memory Access controller (DMA). | |
Quick Start Guide(s) | |
In this section you can find a list of all Quick Start guides related to the Direct Memory Access controller (DMA). | |
Data Structures | |
struct | dma_channel_config |
DMA channel configuration struct. More... | |
Macros | |
#define | dma_get_channel_address_from_num(num) ((DMA_CH_t *)((uintptr_t)(&DMA.CH0) + (sizeof(DMA_CH_t) * num))) |
Helper macro to get the channel offset given the channel number. More... | |
#define | DMA_NUMBER_OF_CHANNELS 2 |
Number of available DMA channels, device dependent. More... | |
Typedefs | |
typedef uint8_t | dma_channel_num_t |
DMA channel number type. More... | |
Enumerations | |
enum | dma_channel_status { DMA_CH_FREE = 0, DMA_CH_PENDING, DMA_CH_BUSY, DMA_CH_TRANSFER_COMPLETED, DMA_CH_TRANSFER_ERROR } |
DMA channel status. More... | |
enum | dma_int_level_t { DMA_INT_LVL_OFF = 0x00, DMA_INT_LVL_LO = 0x01, DMA_INT_LVL_MED = 0x02, DMA_INT_LVL_HI = 0x03 } |
DMA interrupt levels. More... | |
Functions | |
void | dma_disable (void) |
Disable DMA controller. More... | |
void | dma_enable (void) |
Enable DMA controller. More... | |
DMA Controller Management | |
static void | dma_set_priority_mode (DMA_PRIMODE_t primode) |
Set DMA channel priority mode. More... | |
static void | dma_set_double_buffer_mode (DMA_DBUFMODE_t dbufmode) |
Set DMA channel double buffering mode. More... | |
DMA Channel Management | |
typedef void(* | dma_callback_t )(enum dma_channel_status status) |
Callback definition for DMA channel interrupts. More... | |
void | dma_channel_write_config (dma_channel_num_t num, struct dma_channel_config *config) |
Write DMA channel configuration to hardware. More... | |
void | dma_channel_read_config (dma_channel_num_t num, struct dma_channel_config *config) |
Read DMA channel configuration from hardware. More... | |
static void | dma_channel_enable (dma_channel_num_t num) |
Enable a DMA channel. More... | |
static void | dma_channel_disable (dma_channel_num_t num) |
Disable a DMA channel. More... | |
static bool | dma_channel_is_enabled (dma_channel_num_t num) |
Check if DMA channel is enabled. More... | |
static bool | dma_channel_is_busy (dma_channel_num_t num) |
Check if DMA channel is busy. More... | |
static enum dma_channel_status | dma_get_channel_status (dma_channel_num_t num) |
Get channel status. More... | |
static void | dma_channel_trigger_block_transfer (dma_channel_num_t num) |
DMA channel trigger block transfer. More... | |
static void | dma_channel_reset (dma_channel_num_t num) |
Reset a DMA channel. More... | |
void | dma_set_callback (dma_channel_num_t num, dma_callback_t callback) |
Set callback for given DMA channel. More... | |
DMA Channel Direct Configuration Functions | |
These functions allows direct configuration on the DMA channels, not going through a dma_channel_config struct. This allows update of the most commonly changed DMA channel properties. | |
static void | dma_channel_write_burst_length (dma_channel_num_t num, DMA_CH_BURSTLEN_t burst_length) |
Write DMA channel burst length to hardware. More... | |
static void | dma_channel_write_transfer_count (dma_channel_num_t num, uint16_t count) |
Write DMA channel transfer count to hardware. More... | |
static void | dma_channel_write_repeats (dma_channel_num_t num, uint8_t repeats) |
Write DMA channel number of transfer repeats to hardware. More... | |
static void | dma_channel_write_destination (dma_channel_num_t num, uint16_t destination) |
Write DMA channel 16-bit destination address to hardware. More... | |
static void | dma_channel_write_source (dma_channel_num_t num, uint16_t source) |
Write DMA channel 16-bit source address to hardware. More... | |
DMA Channel Configuration Helper Functions | |
static void | dma_channel_set_burst_length (struct dma_channel_config *config, DMA_CH_BURSTLEN_t burst_length) |
Set DMA channel burst length. More... | |
static void | dma_channel_set_single_shot (struct dma_channel_config *config) |
Set DMA channel in single shot transfer mode. More... | |
static void | dma_channel_unset_single_shot (struct dma_channel_config *config) |
Unset DMA channel from single shot transfer mode. More... | |
static void | dma_channel_set_interrupt_level (struct dma_channel_config *config, enum dma_int_level_t level) |
Set DMA channel interrupt level. More... | |
static void | dma_channel_set_src_reload_mode (struct dma_channel_config *config, DMA_CH_SRCRELOAD_t mode) |
Set DMA channel source address reload mode. More... | |
static void | dma_channel_set_dest_reload_mode (struct dma_channel_config *config, DMA_CH_DESTRELOAD_t mode) |
Set DMA channel destination address reload mode. More... | |
static void | dma_channel_set_src_dir_mode (struct dma_channel_config *config, DMA_CH_SRCDIR_t mode) |
Set DMA channel source addressing mode. More... | |
static void | dma_channel_set_dest_dir_mode (struct dma_channel_config *config, DMA_CH_DESTDIR_t mode) |
Set DMA channel destination addressing mode. More... | |
static void | dma_channel_set_trigger_source (struct dma_channel_config *config, DMA_CH_TRIGSRC_t source) |
Set DMA channel trigger source. More... | |
static void | dma_channel_set_transfer_count (struct dma_channel_config *config, uint16_t count) |
Set DMA channel transfer count. More... | |
static void | dma_channel_set_repeats (struct dma_channel_config *config, uint8_t repeats) |
Set DMA channel number of transfer repeats. More... | |
static void | dma_channel_set_destination_address (struct dma_channel_config *config, uint16_t destination) |
Set DMA channel 16-bit destination address. More... | |
static void | dma_channel_set_source_address (struct dma_channel_config *config, uint16_t source) |
Set DMA channel 16-bit source address. More... | |
#define dma_get_channel_address_from_num | ( | num | ) | ((DMA_CH_t *)((uintptr_t)(&DMA.CH0) + (sizeof(DMA_CH_t) * num))) |
Helper macro to get the channel offset given the channel number.
num | DMA channel number |
Referenced by dma_channel_disable(), dma_channel_enable(), dma_channel_is_enabled(), dma_channel_read_config(), dma_channel_reset(), dma_channel_trigger_block_transfer(), dma_channel_write_burst_length(), dma_channel_write_config(), dma_channel_write_destination(), dma_channel_write_repeats(), dma_channel_write_source(), dma_channel_write_transfer_count(), and dma_interrupt().
#define DMA_NUMBER_OF_CHANNELS 2 |
Number of available DMA channels, device dependent.
Referenced by run_dma_config_interface_test(), run_dma_direction_test(), and run_dma_memory_copy_burst_length_test().
typedef void(* dma_callback_t)(enum dma_channel_status status) |
Callback definition for DMA channel interrupts.
status | Status of DMA channel block transfer |
typedef uint8_t dma_channel_num_t |
DMA channel number type.
enum dma_channel_status |
DMA channel status.
enum dma_int_level_t |
|
inlinestatic |
Disable a DMA channel.
This function disables a DMA channel. If the DMA channel was already enabled the DMA channel is not disabled before the internal transfer buffer is empty and the DMA transfer is aborted.
num | DMA channel to disable |
References cpu_irq_restore(), cpu_irq_save(), and dma_get_channel_address_from_num.
Referenced by run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_error_handling_test(), and run_dma_memory_copy_burst_length_test().
|
inlinestatic |
Enable a DMA channel.
This function enables a DMA channel, depending on the configuration the DMA channel will start the block transfer upon a dma_channel_trigger_block_transfer() or when other hardware modules trigger the DMA hardware.
num | DMA channel to enable |
References cpu_irq_restore(), cpu_irq_save(), and dma_get_channel_address_from_num.
Referenced by aes_dma_input(), aes_dma_output(), main(), run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_error_handling_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Check if DMA channel is busy.
This function checks if a DMA channel is busy doing or going to do (pending) a block transfer.
num | DMA channel number to query |
true | DMA channel is busy or have a block transfer pending |
false | DMA channel is not busy or have a block transfer pending |
Referenced by run_dma_error_handling_test().
|
inlinestatic |
Check if DMA channel is enabled.
This function checks if a DMA channel is enabled.
num | DMA channel number to query |
true | DMA channel is enabled |
false | DMA channel is disabled |
References dma_get_channel_address_from_num.
Referenced by run_dma_double_buffering_test().
void dma_channel_read_config | ( | dma_channel_num_t | num, |
struct dma_channel_config * | config | ||
) |
Read DMA channel configuration from hardware.
This function will read the DMA channel configuration into a dma_channel_config.
num | DMA channel number to read configuration from |
config | Pointer to a DMA channel config, given by a dma_channel_config |
References dma_channel_config::addrctrl, cpu_irq_restore(), cpu_irq_save(), dma_channel_config::ctrla, dma_channel_config::ctrlb, dma_channel_config::destaddr16, dma_get_channel_address_from_num, dma_channel_config::repcnt, dma_channel_config::srcaddr16, dma_channel_config::trfcnt, and dma_channel_config::trigsrc.
Referenced by run_dma_config_interface_test().
|
inlinestatic |
Reset a DMA channel.
This function resets a given DMA channel.
num | DMA channel number to trigger block transfer for |
References cpu_irq_restore(), cpu_irq_save(), and dma_get_channel_address_from_num.
Referenced by run_dma_config_interface_test(), run_dma_direction_test(), run_dma_error_handling_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel burst length.
This function helps the caller setting the DMA channel burst length. The burst lengths are defined in the toolchain header files in the form of DMA_CH_BURSTLEN_*_gc, where * represents the various available burst lengths.
config | Pointer to a dma_channel_config variable |
burst_length | DMA channel burst length given by a DMA_CH_BURSTLEN_t type |
References dma_channel_config::ctrla.
Referenced by aes_dma_input(), aes_dma_output(), main(), run_dma_config_interface_test(), run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel destination addressing mode.
This function helps the caller setting the DMA channel destination addressing mode. The reload modes are defined in the toolchain header files in the form of DMA_CH_DESTDIR_*_gc, where * is FIXED, INC, DEC.
config | Pointer to a dma_channel_config variable |
mode | DMA channel destination addressing mode given by an DMA_CH_DESTDIR_t type |
References dma_channel_config::addrctrl.
Referenced by aes_dma_input(), aes_dma_output(), main(), run_dma_config_interface_test(), run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel destination address reload mode.
This function helps the caller setting the DMA channel destination address reload mode. The reload modes are defined in the toolchain header files in the form of DMA_CH_DESTRELOAD_*_gc, where * is NONE, BLOCK, BURST, TRANSACTION.
config | Pointer to a dma_channel_config variable |
mode | DMA channel destination address reload mode given by an DMA_CH_DESTRELOAD_t type |
References dma_channel_config::addrctrl.
Referenced by aes_dma_input(), aes_dma_output(), main(), run_dma_config_interface_test(), run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel 16-bit destination address.
This function helps the caller setting the DMA channel destination 16-bit LSB address.
config | Pointer to a dma_channel_config variable |
destination | 16-bit LSB destination address |
References dma_channel_config::destaddr16, and destination.
Referenced by aes_dma_input(), aes_dma_output(), main(), run_dma_config_interface_test(), run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel interrupt level.
This function helps the caller setting the DMA channel interrupt level for transaction complete and channel error.
config | Pointer to a dma_channel_config variable |
level | Interrupt level given by a dma_int_level_t type |
References dma_channel_config::ctrlb.
Referenced by main(), run_dma_config_interface_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel number of transfer repeats.
This function helps the caller setting the DMA channel number of block transfer repeats. It will also enable the repeat feature.
config | Pointer to a dma_channel_config variable |
repeats | Number of block transfer repeats |
References dma_channel_config::ctrla, and dma_channel_config::repcnt.
Referenced by run_dma_config_interface_test(), and run_dma_double_buffering_test().
|
inlinestatic |
Set DMA channel in single shot transfer mode.
This function helps the caller setting the DMA channel in single shot transfer mode.
config | Pointer to a dma_channel_config variable |
References dma_channel_config::ctrla.
Referenced by run_dma_config_interface_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel 16-bit source address.
This function helps the caller setting the DMA channel source 16-bit LSB address.
config | Pointer to a dma_channel_config variable |
source | 16-bit LSB source address |
References source, and dma_channel_config::srcaddr16.
Referenced by aes_dma_input(), aes_dma_output(), main(), run_dma_config_interface_test(), run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel source addressing mode.
This function helps the caller setting the DMA channel source addressing mode. The addressing modes are defined in the toolchain header files in the form of DMA_CH_SRCDIR_*_gc, where * is FIXED, INC, DEC.
config | Pointer to a dma_channel_config variable |
mode | DMA channel source addressing mode given by an DMA_CH_SRCDIR_t type |
References dma_channel_config::addrctrl.
Referenced by aes_dma_input(), aes_dma_output(), main(), run_dma_config_interface_test(), run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel source address reload mode.
This function helps the caller setting the DMA channel source address reload mode. The reload modes are defined in the toolchain header files in the form of DMA_CH_SRCRELOAD_*_gc, where * is NONE, BLOCK, BURST, TRANSACTION.
config | Pointer to a dma_channel_config variable |
mode | DMA channel source address reload mode given by an DMA_CH_SRCRELOAD_t type |
References dma_channel_config::addrctrl.
Referenced by aes_dma_input(), aes_dma_output(), main(), run_dma_config_interface_test(), run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel transfer count.
This function helps the caller setting the DMA channel number of bytes in each block transfer.
config | Pointer to a dma_channel_config variable |
count | Number of bytes in each block transfer |
References dma_channel_config::trfcnt.
Referenced by aes_dma_input(), aes_dma_output(), main(), run_dma_config_interface_test(), run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel trigger source.
This function helps the caller setting the DMA channel trigger source. The trigger sources are defined in the toolchain header files in the form of DMA_CH_TRIGSRC_*_gc, where * represents the various sources.
config | Pointer to a dma_channel_config variable |
source | DMA channel trigger source given by a DMA_CH_TRIGSRC_t type |
References source, and dma_channel_config::trigsrc.
Referenced by run_dma_config_interface_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
DMA channel trigger block transfer.
This function triggers a start of a block transfer on a given DMA channel.
num | DMA channel number to trigger block transfer for |
References cpu_irq_restore(), cpu_irq_save(), and dma_get_channel_address_from_num.
Referenced by aes_dma_input(), aes_dma_output(), dma_transfer_block(), main(), run_dma_double_buffering_test(), and run_dma_error_handling_test().
|
inlinestatic |
Unset DMA channel from single shot transfer mode.
This function helps the caller clear the DMA channel single shot transfer mode feature.
config | Pointer to a dma_channel_config variable |
References dma_channel_config::ctrla.
Referenced by run_dma_config_interface_test().
|
inlinestatic |
Write DMA channel burst length to hardware.
This function writes the DMA channel burst length directly to hardware. The burst lengths are defined in the toolchain header files in the form of DMA_CH_BURSTLEN_*_gc, where * represents the various available burst lengths.
num | DMA channel number to write burst length for |
burst_length | DMA channel burst length given by a DMA_CH_BURSTLEN_t type |
References cpu_irq_restore(), cpu_irq_save(), and dma_get_channel_address_from_num.
Referenced by run_dma_config_interface_test(), and run_dma_error_handling_test().
void dma_channel_write_config | ( | dma_channel_num_t | num, |
struct dma_channel_config * | config | ||
) |
Write DMA channel configuration to hardware.
This function will write the DMA channel configuration, provided by a dma_channel_config.
num | DMA channel number to write configuration to |
config | Pointer to a DMA channel config, given by a dma_channel_config |
References dma_channel_config::addrctrl, cpu_irq_restore(), cpu_irq_save(), dma_channel_config::ctrla, dma_channel_config::ctrlb, dma_channel_config::destaddr16, dma_get_channel_address_from_num, dma_channel_config::repcnt, dma_channel_config::srcaddr16, dma_channel_config::trfcnt, dma_channel_config::trigsrc, XMEGA_A, and XMEGA_AU.
Referenced by aes_dma_input(), aes_dma_output(), main(), run_dma_config_interface_test(), run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Write DMA channel 16-bit destination address to hardware.
This function writes a DMA channel destination 16-bit LSB address to hardware.
num | DMA channel number to write 16-bit destination address for |
destination | 16-bit LSB destination address |
References cpu_irq_restore(), cpu_irq_save(), destination, and dma_get_channel_address_from_num.
Referenced by run_dma_config_interface_test(), and run_dma_error_handling_test().
|
inlinestatic |
Write DMA channel number of transfer repeats to hardware.
This function writes the DMA channel number of block transfer repeats to hardware. It will also enable the repeat feature.
num | DMA channel number to write transfer repeats for |
repeats | Number of block transfer repeats |
References cpu_irq_restore(), cpu_irq_save(), and dma_get_channel_address_from_num.
Referenced by run_dma_config_interface_test().
|
inlinestatic |
Write DMA channel 16-bit source address to hardware.
This function writes a DMA channel source 16-bit LSB address to hardware.
num | DMA channel number to write 16-bit source address for |
source | 16-bit LSB source address |
References cpu_irq_restore(), cpu_irq_save(), dma_get_channel_address_from_num, and source.
Referenced by run_dma_config_interface_test(), and run_dma_error_handling_test().
|
inlinestatic |
Write DMA channel transfer count to hardware.
This function writes the DMA channel number of bytes in each block transfer to hardware.
num | DMA channel number to write transfer count for |
count | Number of bytes in each block transfer |
References cpu_irq_restore(), cpu_irq_save(), and dma_get_channel_address_from_num.
Referenced by run_dma_config_interface_test(), and run_dma_error_handling_test().
void dma_disable | ( | void | ) |
Disable DMA controller.
References SLEEPMGR_IDLE, sleepmgr_unlock_mode(), sysclk_disable_module(), SYSCLK_DMA, and SYSCLK_PORT_GEN.
Referenced by aes_dma_output(), run_dma_config_interface_test(), run_dma_direction_test(), run_dma_error_handling_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
void dma_enable | ( | void | ) |
Enable DMA controller.
References SLEEPMGR_IDLE, sleepmgr_lock_mode(), SYSCLK_DMA, sysclk_enable_module(), and SYSCLK_PORT_GEN.
Referenced by aes_dma_input(), aes_dma_output(), main(), run_dma_config_interface_test(), run_dma_direction_test(), run_dma_double_buffering_test(), run_dma_error_handling_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().
|
inlinestatic |
Get channel status.
This function returns the current channel status.
num | DMA channel number |
References DMA_CH_BUSY, DMA_CH_FREE, DMA_CH_PENDING, DMA_CH_TRANSFER_COMPLETED, and DMA_CH_TRANSFER_ERROR.
Referenced by dma_interrupt(), dma_transfer_block(), run_dma_double_buffering_test(), and run_dma_error_handling_test().
void dma_set_callback | ( | dma_channel_num_t | num, |
dma_callback_t | callback | ||
) |
Set callback for given DMA channel.
num | dma_channel_num_t |
callback | dma_callback_t |
References dma_data.
Referenced by main(), and run_dma_triggered_with_callback().
|
inlinestatic |
Set DMA channel double buffering mode.
This function modifies which channels should be in double buffer mode. The modes are defined in the toolchain header files in the form of DMA_DBUFMODE_*_gc for devices with more than 2 channels, or DMA_DBUFMODE_*_bm for dual channel devices.
dbufmode | Double buffer channel configuration given by a DMA_DBUFMODE_t type |
References Assert, cpu_irq_restore(), and cpu_irq_save().
Referenced by run_dma_double_buffering_test().
|
inlinestatic |
Set DMA channel priority mode.
This functions sets the channel priority mode. Users can select between fixed priority, round-robin or a mix of both.
The modes are defined in the toolchain header files in the form of DMA_PRIMODE_*_gc for devices with more than 2 channels, or DMA_PRIMODE_*_bm for dual channel devices.
primode | DMA channel priority mode given by a DMA_PRIMODE_t type |
References Assert, cpu_irq_restore(), and cpu_irq_save().