dma.h File Reference
#include "pico.h"
#include "hardware/structs/dma.h"
#include "hardware/regs/dreq.h"
#include "pico/assert.h"
Include dependency graph for dma.h:

Go to the source code of this file.

Data Structures

struct  dma_channel_config
 

Macros

#define DREQ_DMA_TIMER0   DMA_CH0_CTRL_TRIG_TREQ_SEL_VALUE_TIMER0
 
#define DREQ_DMA_TIMER1   DMA_CH0_CTRL_TRIG_TREQ_SEL_VALUE_TIMER1
 
#define DREQ_DMA_TIMER2   DMA_CH0_CTRL_TRIG_TREQ_SEL_VALUE_TIMER2
 
#define DREQ_DMA_TIMER3   DMA_CH0_CTRL_TRIG_TREQ_SEL_VALUE_TIMER3
 
#define DREQ_FORCE   DMA_CH0_CTRL_TRIG_TREQ_SEL_VALUE_PERMANENT
 
#define PARAM_ASSERTIONS_ENABLED_DMA   0
 

Enumerations

enum  dma_channel_transfer_size { DMA_SIZE_8 = 0, DMA_SIZE_16 = 1, DMA_SIZE_32 = 2 }
 Enumeration of available DMA channel transfer sizes.Names indicate the number of bits. More...
 

Functions

static void check_dma_channel_param (__unused uint channel)
 
static void check_dma_timer_param (__unused uint timer_num)
 
static dma_channel_hw_tdma_channel_hw_addr (uint channel)
 
void dma_channel_claim (uint channel)
 Mark a dma channel as usedMethod for cooperative claiming of hardware. Will cause a panic if the channel is already claimed. Use of this method by libraries detects accidental configurations that would fail in unpredictable ways. More...
 
void dma_claim_mask (uint32_t channel_mask)
 Mark multiple dma channels as usedMethod for cooperative claiming of hardware. Will cause a panic if any of the channels are already claimed. Use of this method by libraries detects accidental configurations that would fail in unpredictable ways. More...
 
void dma_channel_unclaim (uint channel)
 Mark a dma channel as no longer used. More...
 
void dma_unclaim_mask (uint32_t channel_mask)
 Mark multiple dma channels as no longer used. More...
 
int dma_claim_unused_channel (bool required)
 Claim a free dma channel. More...
 
bool dma_channel_is_claimed (uint channel)
 Determine if a dma channel is claimed. More...
 
static void channel_config_set_read_increment (dma_channel_config *c, bool incr)
 Set DMA channel read increment in a channel configuration object. More...
 
static void channel_config_set_write_increment (dma_channel_config *c, bool incr)
 Set DMA channel write increment in a channel configuration object. More...
 
static void channel_config_set_dreq (dma_channel_config *c, uint dreq)
 Select a transfer request signal in a channel configuration objectThe channel uses the transfer request signal to pace its data transfer rate. Sources for TREQ signals are internal (TIMERS) or external (DREQ, a Data Request from the system). 0x0 to 0x3a -> select DREQ n as TREQ 0x3b -> Select Timer 0 as TREQ 0x3c -> Select Timer 1 as TREQ 0x3d -> Select Timer 2 as TREQ (Optional) 0x3e -> Select Timer 3 as TREQ (Optional) 0x3f -> Permanent request, for unpaced transfers. More...
 
static void channel_config_set_chain_to (dma_channel_config *c, uint chain_to)
 Set DMA channel chain_to channel in a channel configuration objectWhen this channel completes, it will trigger the channel indicated by chain_to. Disable by setting chain_to to itself (the same channel) More...
 
static void channel_config_set_transfer_data_size (dma_channel_config *c, enum dma_channel_transfer_size size)
 Set the size of each DMA bus transfer in a channel configuration objectSet the size of each bus transfer (byte/halfword/word). The read and write addresses advance by the specific amount (1/2/4 bytes) with each transfer. More...
 
static void channel_config_set_ring (dma_channel_config *c, bool write, uint size_bits)
 Set address wrapping parameters in a channel configuration objectSize of address wrap region. If 0, don’t wrap. For values n > 0, only the lower n bits of the address will change. This wraps the address on a (1 << n) byte boundary, facilitating access to naturally-aligned ring buffers. Ring sizes between 2 and 32768 bytes are possible (size_bits from 1 - 15) More...
 
static void channel_config_set_bswap (dma_channel_config *c, bool bswap)
 Set DMA byte swapping config in a channel configuration objectNo effect for byte data, for halfword data, the two bytes of each halfword are swapped. For word data, the four bytes of each word are swapped to reverse their order. More...
 
static void channel_config_set_irq_quiet (dma_channel_config *c, bool irq_quiet)
 Set IRQ quiet mode in a channel configuration objectIn QUIET mode, the channel does not generate IRQs at the end of every transfer block. Instead, an IRQ is raised when NULL is written to a trigger register, indicating the end of a control block chain. More...
 
static void channel_config_set_high_priority (dma_channel_config *c, bool high_priority)
 Set the channel priority in a channel configuration objectWhen true, gives a channel preferential treatment in issue scheduling: in each scheduling round, all high priority channels are considered first, and then only a single low priority channel, before returning to the high priority channels. More...
 
static void channel_config_set_enable (dma_channel_config *c, bool enable)
 Enable/Disable the DMA channel in a channel configuration objectWhen false, the channel will ignore triggers, stop issuing transfers, and pause the current transfer sequence (i.e. BUSY will remain high if already high) More...
 
static void channel_config_set_sniff_enable (dma_channel_config *c, bool sniff_enable)
 Enable access to channel by sniff hardware in a channel configuration objectSniff HW must be enabled and have this channel selected. More...
 
static dma_channel_config dma_channel_get_default_config (uint channel)
 Get the default channel configuration for a given channel
Setting Default
Read Increment true
Write Increment false
DReq DREQ_FORCE
Chain to self
Data size DMA_SIZE_32
Ring write=false, size=0 (i.e. off)
Byte Swap false
Quiet IRQs false
High Priority false
Channel Enable true
Sniff Enable false
More...
 
static dma_channel_config dma_get_channel_config (uint channel)
 Get the current configuration for the specified channel. More...
 
static uint32_t channel_config_get_ctrl_value (const dma_channel_config *config)
 Get the raw configuration register from a channel configuration. More...
 
static void dma_channel_set_config (uint channel, const dma_channel_config *config, bool trigger)
 Set a channel configuration. More...
 
static void dma_channel_set_read_addr (uint channel, const volatile void *read_addr, bool trigger)
 Set the DMA initial read address. More...
 
static void dma_channel_set_write_addr (uint channel, volatile void *write_addr, bool trigger)
 Set the DMA initial write address. More...
 
static void dma_channel_set_trans_count (uint channel, uint32_t trans_count, bool trigger)
 Set the number of bus transfers the channel will do. More...
 
static void dma_channel_configure (uint channel, const dma_channel_config *config, volatile void *write_addr, const volatile void *read_addr, uint transfer_count, bool trigger)
 Configure all DMA parameters and optionally start transfer. More...
 
static void dma_channel_transfer_from_buffer_now (uint channel, const volatile void *read_addr, uint32_t transfer_count)
 Start a DMA transfer from a buffer immediately. More...
 
static void dma_channel_transfer_to_buffer_now (uint channel, volatile void *write_addr, uint32_t transfer_count)
 Start a DMA transfer to a buffer immediately. More...
 
static void dma_start_channel_mask (uint32_t chan_mask)
 Start one or more channels simultaneously. More...
 
static void dma_channel_start (uint channel)
 Start a single DMA channel. More...
 
static void dma_channel_abort (uint channel)
 Stop a DMA transferFunction will only return once the DMA has stopped. More...
 
static void dma_channel_set_irq0_enabled (uint channel, bool enabled)
 Enable single DMA channel's interrupt via DMA_IRQ_0. More...
 
static void dma_set_irq0_channel_mask_enabled (uint32_t channel_mask, bool enabled)
 Enable multiple DMA channels' interrupts via DMA_IRQ_0. More...
 
static void dma_channel_set_irq1_enabled (uint channel, bool enabled)
 Enable single DMA channel's interrupt via DMA_IRQ_1. More...
 
static void dma_set_irq1_channel_mask_enabled (uint32_t channel_mask, bool enabled)
 Enable multiple DMA channels' interrupts via DMA_IRQ_1. More...
 
static void dma_irqn_set_channel_enabled (uint irq_index, uint channel, bool enabled)
 Enable single DMA channel interrupt on either DMA_IRQ_0 or DMA_IRQ_1. More...
 
static void dma_irqn_set_channel_mask_enabled (uint irq_index, uint32_t channel_mask, bool enabled)
 Enable multiple DMA channels' interrupt via either DMA_IRQ_0 or DMA_IRQ_1. More...
 
static bool dma_channel_get_irq0_status (uint channel)
 Determine if a particular channel is a cause of DMA_IRQ_0. More...
 
static bool dma_channel_get_irq1_status (uint channel)
 Determine if a particular channel is a cause of DMA_IRQ_1. More...
 
static bool dma_irqn_get_channel_status (uint irq_index, uint channel)
 Determine if a particular channel is a cause of DMA_IRQ_N. More...
 
static void dma_channel_acknowledge_irq0 (uint channel)
 Acknowledge a channel IRQ, resetting it as the cause of DMA_IRQ_0. More...
 
static void dma_channel_acknowledge_irq1 (uint channel)
 Acknowledge a channel IRQ, resetting it as the cause of DMA_IRQ_1. More...
 
static void dma_irqn_acknowledge_channel (uint irq_index, uint channel)
 Acknowledge a channel IRQ, resetting it as the cause of DMA_IRQ_N. More...
 
static bool dma_channel_is_busy (uint channel)
 Check if DMA channel is busy. More...
 
static void dma_channel_wait_for_finish_blocking (uint channel)
 Wait for a DMA channel transfer to complete. More...
 
static void dma_sniffer_enable (uint channel, uint mode, bool force_channel_enable)
 Enable the DMA sniffing targeting the specified channelThe mode can be one of the following: More...
 
static void dma_sniffer_set_byte_swap_enabled (bool swap)
 Enable the Sniffer byte swap functionLocally perform a byte reverse on the sniffed data, before feeding into checksum. More...
 
static void dma_sniffer_set_output_invert_enabled (bool invert)
 Enable the Sniffer output invert functionIf enabled, the sniff data result appears bit-inverted when read. This does not affect the way the checksum is calculated. More...
 
static void dma_sniffer_set_output_reverse_enabled (bool reverse)
 Enable the Sniffer output bit reversal functionIf enabled, the sniff data result appears bit-reversed when read. This does not affect the way the checksum is calculated. More...
 
static void dma_sniffer_disable (void)
 Disable the DMA sniffer.
 
static void dma_sniffer_set_data_accumulator (uint32_t seed_value)
 Set the sniffer's data accumulator with initial valueGenerally, CRC algorithms are used with the data accumulator initially seeded with 0xFFFF or 0xFFFFFFFF (for crc16 and crc32 algorithms) More...
 
static uint32_t dma_sniffer_get_data_accumulator (void)
 Get the sniffer's data accumulator valueRead value calculated by the hardware from sniffing the DMA stream.
 
void dma_timer_claim (uint timer)
 Mark a dma timer as usedMethod for cooperative claiming of hardware. Will cause a panic if the timer is already claimed. Use of this method by libraries detects accidental configurations that would fail in unpredictable ways. More...
 
void dma_timer_unclaim (uint timer)
 Mark a dma timer as no longer usedMethod for cooperative claiming of hardware. More...
 
int dma_claim_unused_timer (bool required)
 Claim a free dma timer. More...
 
bool dma_timer_is_claimed (uint timer)
 Determine if a dma timer is claimed. More...
 
static void dma_timer_set_fraction (uint timer, uint16_t numerator, uint16_t denominator)
 Set the divider for the given DMA timerThe timer will run at the system_clock_freq * numerator / denominator, so this is the speed that data elements will be transferred at via a DMA channel using this timer as a DREQ. More...
 
static uint dma_get_timer_dreq (uint timer_num)
 Return the DREQ number for a given DMA timer. More...
 
void print_dma_ctrl (dma_channel_hw_t *channel)