Author: KandlaguntaR_36 Version: **
Translation - Japanese: FX3/CX3のオーバーライドモードのDMAチャネル - KBA229098
Question 1:
Why should a DMA channel be configured in override mode FX3/CX3?
Answer:
Applications/Use case of DMA Channel in Override Mode
DMA channel can be used in override mode when the user-defined buffer is to be sent along with the data, which will be transferred through the DMA channel.
Configuring a DMA channel in override mode means sending and receiving the contents of user-defined buffer to and from the consumer socket and the producer socket of the DMA channel respectively.
Consider an example where the DMA channel is configured from processor interface block (PIB) to USB interface block (UIB) and you want to send data, which does not come from the PIB socket, to UIB. In this case, user-defined buffer can be sent by configuring this DMA channel in override mode.
The other application of DMA channel in override mode can be a USB Video Class Device application where you want to send independent buffers for header and footer without changing the GPIF II state machine. See the threads, https://community.cypress.com/thread/49788, https://community.cypress.com/thread/50601 for similar applications.
Mass storage class examples in the SDK also implement DMA channel in override mode.
Question 2:
How can a DMA channel be configured in override mode in FX3/CX3?
Answer:
A DMA channel is created between a producer socket and a consumer socket. A DMA channel can be in either of the following DMA states:
Table 1. APIs to Configure DMA Channel in Override Mode
API | Description |
CyU3PDmaChannelSetupRecvBuffer (CyU3PDmaChannel *handle, CyU3PDmaBuffer_t * buffer_p) CyU3PDmaMultiChannelSetupRecvBuffer (CyU3PDmaMultiChannel *handle, CyU3PDmaBuffer_t * buffer_p, uint16_t multiSckOffset) | This function initiates the reading of data incoming from a DMA producer to the user defined buffer |
CyU3PDmaChannelSetupSendBuffer (CyU3PDmaChannel *handle, CyU3PDmaBuffer_t *buffer_p) CyU3PDmaMultiChannelSetupSendBuffer (CyU3PDmaMultiChannel *handle, CyU3PDmaBuffer_t * buffer_p, uint16_t multiSckOffset) | This function initiates the sending of the content of a user-provided buffer to the consumer of a DMA channel. |
Note: For more details of these APIs, see the FX3APIGuide available in the SDK.
Note:
Table 2. APIs to Check Completion of Data Transfers in Override Mode
API | Description |
CyU3PDmaMultiChannelWaitForCompletion (CyU3PDmaMultiChannel * handle, uint32_t waitOption ) CyU3PDmaChannelWaitForCompletion (CyU3PDmaChannel _ handle, uint32_t waitOption ) | This function waits for the current DMA transaction to complete. |
CyU3PDmaChannelWaitForRecvBuffer (CyU3PDmaChannel *handle, CyU3PDmaBuffer_t *buffer_p, uint32_t waitOption ) CyU3PDmaMultiChannelWaitForRecvBuffer (CyU3PDmaMultiChannel *handle, CyU3PDmaBuffer_t * buffer_p, uint32_t waitOption ) | This function waits until an override read operation is completed. |
Note: For more details of these APIs, see the FX3APIGuide available in the SDK.
CY_U3P_DMA_CB_SEND_CPLTorCY_U3P_DMA_CB_RECV_CPLT callback events can be registered in the DMA channel configuration while creating the DMA channel. These events can be handled in the callback function, which would be called when SendBuffer or ReceiveBuffer (transfer) call has been completed respectively.
Question 3:
Is there any FX3 example to configure DMA channel in override mode?
Answer:
See the GpifToUsb example attached with this knowledge base article (KBA), which overrides the DMA channel to send user-defined buffer in addition to the normal data transfer, that is from GPIF block to USB block.
The functionality of this example is to send a user-defined buffer through the DMA channel in the override mode during the normal data transfers from GPIF to USB.
The CY_U3P_DMA_TYPE_MANUAL channel is created between the PIB block and the UIB block. PIB socket is configured as producer and one UIB socket is configured as the consumer.
The user-defined buffer is sent by calling the SendDebugMessage() function before calling the CyU3PDmaChannelSetXfer API.
The second parameter of the CyU3PDmaChannelSetXfer and CyU3PDmaMultiChannelSetXfer APIs indicate the desired transaction size in units, associated with the selected DMA mode. Channel will revert to idle state after the specified amount of data has been transferred.
There is a difference in the implementation of these APIs:
Completion of the transfer of data in user-defined buffer can be checked using CY_U3P_DMA_CB_SEND_CPLT. This event is registered for the callback. This would register a callback when the user-provided buffer is sent. On receiving this event, the CyU3PDmaChannelSetXfer API is called with the fixed amount of data transfer (32).
In the CyFxAppThread_Entry function, DMA_Override variable is tracked. When the DMA channel is switched from DMA override mode to normal mode, the CyU3PDmaChannelWaitForCompletion API is called to wait for the transfers through the CyU3PDmaChannelSetXfer API to complete. When these transfers are completed, the DMA channel is switched back to DMA override mode by calling the SendDebugMessage() function
For more details, see the msc_examples which implement the DMA channel in override mode. You can find msc_examples at C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\msc_examples.