High level interface for interacting with the direct memory access (DMA).
The DMA driver allows for setting up the DMA object in order to trigger data transfers to and from memory and peripherals. The transfers occur independently of the CPU and can be triggered by software or hardware. Multiple channels can be active at the same time each with their own user-selectable priority and transfer characteristics.
The operational flow of the driver is listed below. This shows the basic order in which each of the functions would generally be called.
See Snippet 1: Simple DMA initialization and transfer for a code snippet that sets up a DMA transfer to move memory from one location to another.
The following snippet initializes a DMA channel and uses it to transfer a a single block of memory. mtb_hal_dma_set_src_addr, mtb_hal_dma_set_dst_addr, mtb_hal_dma_set_length can be used after DMA initialization to handle a variety of memory layouts.
DMA events like transfer complete or error events can be used to trigger a callback function.
This snippet uses mtb_hal_dma_enable_event() to enable the transfer complete event to trigger the callback function registered by mtb_hal_dma_register_callback().
If CPU D-cache is enabled, DMA transfers must be handled using cache management API when dealing with cacheable memory in order to maintain CPU data cache coherency. Regarding the CPU data cache coherence with DMA, the general rules are,
The following snippet initializes a DMA channel and uses it to transfer a single block from one cacheable memory to another cacheable memory. Cleaning D-cache of DMA descriptor is done by calling mtb_hal_dma_set_src_addr, mtb_hal_dma_set_dst_addr, mtb_hal_dma_set_length and mtb_hal_dma_setup. Cleaning D-cache of source's buffer and Invalidating D-cahe of destination's buffer should be done explicitly.
Refer to DCACHE_Management for more information.
API Reference | |
DMA HAL Results | |
DMA specific return codes. | |
Typedefs | |
typedef void(* | mtb_hal_dma_event_callback_t) (void *callback_arg, mtb_hal_dma_event_t event) |
Event handler for DMA interrupts. | |
Enumerations | |
enum | mtb_hal_dma_event_t { MTB_HAL_DMA_NO_INTR = 0 , MTB_HAL_DMA_TRANSFER_COMPLETE = 1 << 0 , MTB_HAL_DMA_DESCRIPTOR_COMPLETE = 1 << 1 , MTB_HAL_DMA_SRC_BUS_ERROR = 1 << 2 , MTB_HAL_DMA_DST_BUS_ERROR = 1 << 3 , MTB_HAL_DMA_SRC_MISAL = 1 << 4 , MTB_HAL_DMA_DST_MISAL = 1 << 5 , MTB_HAL_DMA_CURR_PTR_NULL = 1 << 6 , MTB_HAL_DMA_ACTIVE_CH_DISABLED = 1 << 7 , MTB_HAL_DMA_DESCR_BUS_ERROR = 1 << 8 , MTB_HAL_DMA_GENERIC_ERROR = 1 << 9 } |
Flags enum of DMA events. More... | |
Functions | |
cy_rslt_t | mtb_hal_dma_setup (mtb_hal_dma_t *obj, const mtb_hal_dma_configurator_t *config) |
Sets up a HAL instance to use the specified hardware resource. More... | |
cy_rslt_t | mtb_hal_dma_set_src_addr (mtb_hal_dma_t *obj, uint32_t src_addr) |
Set the source address for the DMA transfer. More... | |
cy_rslt_t | mtb_hal_dma_set_dst_addr (mtb_hal_dma_t *obj, uint32_t dst_addr) |
Set the destination address for the DMA transfer. More... | |
cy_rslt_t | mtb_hal_dma_set_length (mtb_hal_dma_t *obj, uint32_t length) |
Set the length for the DMA transfer. More... | |
cy_rslt_t | mtb_hal_dma_enable (mtb_hal_dma_t *obj) |
Enable the DMA transfer so that it can start transferring data when triggered. More... | |
cy_rslt_t | mtb_hal_dma_disable (mtb_hal_dma_t *obj) |
Disable the DMA transfer so that it does not continue to trigger. More... | |
cy_rslt_t | mtb_hal_dma_start_transfer (mtb_hal_dma_t *obj) |
Initiates DMA channel transfer for specified DMA object. More... | |
bool | mtb_hal_dma_is_busy (mtb_hal_dma_t *obj) |
Checks if the transfer has been triggered, but not yet complete (eg: is pending, blocked or running) More... | |
cy_rslt_t | mtb_hal_dma_process_interrupt (mtb_hal_dma_t *obj) |
Process interrupts related related to a DMA instance. More... | |
void | mtb_hal_dma_register_callback (mtb_hal_dma_t *obj, mtb_hal_dma_event_callback_t callback, void *callback_arg) |
Register a DMA callback handler. More... | |
void | mtb_hal_dma_enable_event (mtb_hal_dma_t *obj, mtb_hal_dma_event_t event, bool enable) |
Configure DMA event enablement. More... | |
uint32_t | mtb_hal_dma_get_max_elements_per_burst (mtb_hal_dma_t *obj) |
Max number of elements, that can be transferred by one burst. More... | |
enum mtb_hal_dma_event_t |
Flags enum of DMA events.
Multiple events can be enabled via mtb_hal_dma_enable_event and the callback from mtb_hal_dma_register_callback will be run to notify.
cy_rslt_t mtb_hal_dma_setup | ( | mtb_hal_dma_t * | obj, |
const mtb_hal_dma_configurator_t * | config | ||
) |
Sets up a HAL instance to use the specified hardware resource.
This hardware resource must have already been configured via the PDL.
[out] | obj | The HAL driver instance object. The caller must allocate the memory for this object, but the HAL will initialize its contents |
[in] | config | The configurator-generated HAL config structure for this peripheral instance |
cy_rslt_t mtb_hal_dma_set_src_addr | ( | mtb_hal_dma_t * | obj, |
uint32_t | src_addr | ||
) |
Set the source address for the DMA transfer.
[in] | obj | The DMA object |
[in] | src_addr | The source address |
cy_rslt_t mtb_hal_dma_set_dst_addr | ( | mtb_hal_dma_t * | obj, |
uint32_t | dst_addr | ||
) |
Set the destination address for the DMA transfer.
[in] | obj | The DMA object |
[in] | dst_addr | The destination address |
cy_rslt_t mtb_hal_dma_set_length | ( | mtb_hal_dma_t * | obj, |
uint32_t | length | ||
) |
Set the length for the DMA transfer.
[in] | obj | The DMA object |
[in] | length | The transfer length, in bytes |
cy_rslt_t mtb_hal_dma_enable | ( | mtb_hal_dma_t * | obj | ) |
Enable the DMA transfer so that it can start transferring data when triggered.
A trigger is caused either by calling mtb_hal_dma_start_transfer or by hardware as a result of connection made using the interconnect components in the device configurator. The DMA can be disabled by calling mtb_hal_dma_disable
[in] | obj | The DMA object |
cy_rslt_t mtb_hal_dma_disable | ( | mtb_hal_dma_t * | obj | ) |
Disable the DMA transfer so that it does not continue to trigger.
It can be reenabled by calling mtb_hal_dma_enable
[in] | obj | The DMA object |
cy_rslt_t mtb_hal_dma_start_transfer | ( | mtb_hal_dma_t * | obj | ) |
Initiates DMA channel transfer for specified DMA object.
This should only be done after the channel has been configured and setup and any necessary event callbacks setup (mtb_hal_dma_register_callback mtb_hal_dma_enable_event)
[in] | obj | The DMA object |
bool mtb_hal_dma_is_busy | ( | mtb_hal_dma_t * | obj | ) |
Checks if the transfer has been triggered, but not yet complete (eg: is pending, blocked or running)
[in] | obj | The DMA object |
cy_rslt_t mtb_hal_dma_process_interrupt | ( | mtb_hal_dma_t * | obj | ) |
Process interrupts related related to a DMA instance.
obj | HAL object for which the interrupt should be processed |
void mtb_hal_dma_register_callback | ( | mtb_hal_dma_t * | obj, |
mtb_hal_dma_event_callback_t | callback, | ||
void * | callback_arg | ||
) |
Register a DMA callback handler.
This function will be called when one of the events enabled by mtb_hal_dma_enable_event occurs.
[in] | obj | The DMA object |
[in] | callback | The callback handler which will be invoked when an event triggers |
[in] | callback_arg | Generic argument that will be provided to the callback when called |
void mtb_hal_dma_enable_event | ( | mtb_hal_dma_t * | obj, |
mtb_hal_dma_event_t | event, | ||
bool | enable | ||
) |
Configure DMA event enablement.
When an enabled event occurs, the function specified by mtb_hal_dma_register_callback will be called.
[in] | obj | The DMA object |
[in] | event | The DMA event type recent call will take precedence, i.e all events will have the same priority. |
[in] | enable | True to turn on interrupts, False to turn off |
uint32_t mtb_hal_dma_get_max_elements_per_burst | ( | mtb_hal_dma_t * | obj | ) |
Max number of elements, that can be transferred by one burst.
[in] | obj | The DMA object |