Async Transfer Utility Library provides an implementation of data transfer functions in which the calling application initiates the data transfer on the desired communication peripheral and then the data transfer happens in the background without the application involvement.
This library does not have direct knowledge of the underlying communication peripheral being used and the users of the library shall set up the necessary interface needed to support the background transfer on the specific communication peripheral
Features:
Setup the interfaces necessary to communicate to the underlying hardware. mtb_async_transfer_interface_t.
Allocate the memory for the context structure and set-up the underlying communication inteface's using mtb_async_transfer_init
For CPU based transfers, the user of async transfer must arrange for mtb_async_transfer_process_fifo_level_event to be invoked, (e.g. by registering an interrupt handler) when FIFO reaches the desired level on the underlying communications interface.
For DMA based transfers, the user of async transfer must arrange for mtb_async_transfer_process_dma_complete to be invoked, (e.g. by registering an interrupt handler) when FIFO reaches the desired level on the underlying communications interface.
Set up the callback to be invoked when the async transfer is complete using mtb_async_transfer_register_callback
Init sequence for configuring the async tranfer in CPU mode
Init sequence for configuring the async tranfer in DMA mode
Read operation
Write operation
API Reference | |
Enumerated Types | |
Function Pointers | |
Data Structures | |
Functions | |
cy_rslt_t | mtb_async_transfer_init (mtb_async_transfer_context_t *context, const mtb_async_transfer_interface_t *iface) |
Initializes an async transfer library instance. More... | |
cy_rslt_t | mtb_async_transfer_read (mtb_async_transfer_context_t *context, void *dest, size_t length) |
Reads data from the peripheral to the memory in the background. More... | |
cy_rslt_t | mtb_async_transfer_write (mtb_async_transfer_context_t *context, void *source, uint32_t length) |
Writes data from memory to the peripheral in the background. More... | |
bool | mtb_async_transfer_available_read (const mtb_async_transfer_context_t *context) |
Checks whether the async-transfer instance is available to start a read transfer. More... | |
bool | mtb_async_transfer_available_write (const mtb_async_transfer_context_t *context) |
Checks whether the async-transfer instance is available to start a write transfer. More... | |
cy_rslt_t | mtb_async_transfer_abort_read (mtb_async_transfer_context_t *context) |
Stops an in-progress read transfer. More... | |
cy_rslt_t | mtb_async_transfer_abort_write (mtb_async_transfer_context_t *context) |
Stops an in-progress write transfer. More... | |
cy_rslt_t | mtb_async_transfer_register_callback (mtb_async_transfer_context_t *context, mtb_async_transfer_event_callback_t callback, void *arg) |
Register a callback to be invoked when a transfer is complete. More... | |
cy_rslt_t | mtb_async_transfer_process_fifo_level_event (mtb_async_transfer_context_t *context, mtb_async_transfer_direction_t direction) |
Handler for when the FIFO in the peripheral reaches the trigger level. More... | |
cy_rslt_t | mtb_async_transfer_process_dma_complete (mtb_async_transfer_context_t *context, mtb_async_transfer_direction_t direction) |
Handler for when a DMA transfer is complete. More... | |
cy_rslt_t mtb_async_transfer_init | ( | mtb_async_transfer_context_t * | context, |
const mtb_async_transfer_interface_t * | iface | ||
) |
Initializes an async transfer library instance.
[in,out] | context | Stores state that async-transfer needs to track between calls. The caller must allocate memory for this struct but should not depend on its contents. |
[in] | iface | Defines the interaction between this async-transfer instance and the peripheral that it is transferring data to/from. |
iface
or let it go out of scope after this function returns cy_rslt_t mtb_async_transfer_read | ( | mtb_async_transfer_context_t * | context, |
void * | dest, | ||
size_t | length | ||
) |
Reads data from the peripheral to the memory in the background.
If D-cache is enabled and DMA is used, the user needs to make sure that the dest pointer passed to the mtb_async_transfer_read function points to a buffer which is aligned to the cache line size (__SCB_DCACHE_LINE_SIZE). The length of buffer data must be a multiple of the cache line size to ensure cache coherency. CY_ALIGN(__SCB_DCACHE_LINE_SIZE) macro can be used for alignment.
Refer to DCACHE_Management for more information.
[in,out] | context | The context object for this peripheral that was populated by mtb_async_transfer_init |
[in,out] | dest | Pointer to the buffer to which the data read from the peripheral should be stored. |
[in] | length | Length, in bytes, of the data that is to be read |
cy_rslt_t mtb_async_transfer_write | ( | mtb_async_transfer_context_t * | context, |
void * | source, | ||
uint32_t | length | ||
) |
Writes data from memory to the peripheral in the background.
If D-cache is enabled and DMA is used, the user needs to make sure that the source pointer passed to the mtb_async_transfer_write function points to a buffer which is aligned to the cache line size (__SCB_DCACHE_LINE_SIZE). The length of buffer data must be a multiple of the cache line size to ensure cache coherency. CY_ALIGN(__SCB_DCACHE_LINE_SIZE) macro can be used for alignment.
Refer to DCACHE_Management for more information.
[in,out] | context | The context object for this peripheral that was populated by mtb_async_transfer_init |
[in] | source | Pointer to the data that is to be written to the peripheral |
[in] | length | Length, in bytes, of the data that is to be written to the peripheral |
bool mtb_async_transfer_available_read | ( | const mtb_async_transfer_context_t * | context | ) |
Checks whether the async-transfer instance is available to start a read transfer.
An instance is available to start a read transfer if there is no read transfer currently waiting to complete
[in,out] | context | The context object for this peripheral that was populated by mtb_async_transfer_init |
bool mtb_async_transfer_available_write | ( | const mtb_async_transfer_context_t * | context | ) |
Checks whether the async-transfer instance is available to start a write transfer.
An instance is available to start a write transfer if there is no write transfer currently waiting to complete
[in,out] | context | The context object for this peripheral that was populated by mtb_async_transfer_init |
cy_rslt_t mtb_async_transfer_abort_read | ( | mtb_async_transfer_context_t * | context | ) |
Stops an in-progress read transfer.
[in,out] | context | The context object for this peripheral that was populated by mtb_async_transfer_init |
cy_rslt_t mtb_async_transfer_abort_write | ( | mtb_async_transfer_context_t * | context | ) |
Stops an in-progress write transfer.
[in,out] | context | The context object for this peripheral that was populated by mtb_async_transfer_init |
cy_rslt_t mtb_async_transfer_register_callback | ( | mtb_async_transfer_context_t * | context, |
mtb_async_transfer_event_callback_t | callback, | ||
void * | arg | ||
) |
Register a callback to be invoked when a transfer is complete.
[in,out] | context | The context object for this peripheral that was populated by mtb_async_transfer_init |
[in] | callback | The callback to register. This will replace any previously registered callback. A value of NULL for this parameter will result in no callback being registered. |
[in,out] | arg | An arbitrary pointer, which will be passed to the callback when it is invoked. |
Register a callback to be invoked when a transfer is complete.
cy_rslt_t mtb_async_transfer_process_fifo_level_event | ( | mtb_async_transfer_context_t * | context, |
mtb_async_transfer_direction_t | direction | ||
) |
Handler for when the FIFO in the peripheral reaches the trigger level.
The user of async-transfer must arrange for this function to be invoked (e.g. by registering an interrupt handler) when this event occurs
[in,out] | context | The context object for this peripheral that was populated by mtb_async_transfer_init |
[in] | direction | The direction (read or write) in which this event occurred |
cy_rslt_t mtb_async_transfer_process_dma_complete | ( | mtb_async_transfer_context_t * | context, |
mtb_async_transfer_direction_t | direction | ||
) |
Handler for when a DMA transfer is complete.
The user of async-transfer must arrange for this function to be invoked (e.g. by registering an interrupt handler) when this event occurs
[in,out] | context | The context object for this peripheral that was populated by mtb_async_transfer_init |
[in] | direction | The direction (read or write) in which this event occurred |