Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

USB superspeed peripherals Forum Discussions

EmJo_4807876
Level 1
Level 1
First reply posted First question asked Welcome!

Hi all,

I'm modifying the mass storage example code for the FX3 to include an addtional DMA cannel. This additional DMA channel has the same producer socket id as the mass storage out one. I'm getting a channel create error in my last dma channel creation. My question is , Is it alright or not to create tow DMA channels with the same producer or consumer socket id.

Any help appreciated.

Here is the source code.

The first 3 dma channels are fine. error is created in the fourth one, This has the same producer socket id as the first one( ie CY_U3P_UIB_SOCKET_PROD_1).

void

CyFxMscApplnDmaInit (

        void)

{

    CyU3PDmaChannelConfig_t dmaConfig;

    CyU3PReturnStatus_t status;

    glMscCbwBuffer  = (uint8_t *)CyU3PDmaBufferAlloc (1024);

    glMscCswBuffer  = (uint8_t *)CyU3PDmaBufferAlloc (1024);

    glMscDataBuffer = (uint8_t *)CyU3PDmaBufferAlloc (1024);

    glMscCtrlBuffer = (uint8_t *)CyU3PDmaBufferAlloc (32); /* MRB look at making this smaller for efficiency later?*/

    if ((glMscCbwBuffer == 0) || (glMscCswBuffer == 0) || (glMscDataBuffer == 0) || (glMscCtrlBuffer == 0)) /* MRB modified */

    {

        CyU3PDebugPrint (4, "Failed to allocate scratch buffer\r\n");

        CyFxAppErrorHandler (CY_U3P_ERROR_MEMORY_ERROR);

    }

    /* Both DMA channels are created with SuperSpeed parameters. The CyU3PSetEpPacketSize () API is used

       to reconfigure the endpoints to work with DMA channels with large buffers. */

    dmaConfig.size           = 1024;

    dmaConfig.count          = CY_FX_MSC_DMA_BUF_COUNT;

    dmaConfig.prodSckId      = CY_U3P_UIB_SOCKET_PROD_1;

    dmaConfig.consSckId      = CY_U3P_CPU_SOCKET_CONS;

    dmaConfig.dmaMode        = CY_U3P_DMA_MODE_BYTE;

    dmaConfig.notification   = CY_U3P_DMA_CB_RECV_CPLT;

    dmaConfig.cb             = CyFxMscApplnDmaCb;

    dmaConfig.prodHeader     = 0;

    dmaConfig.prodFooter     = 0;

    dmaConfig.consHeader     = 0;

    dmaConfig.prodAvailCount = 0;

    status = CyU3PDmaChannelCreate (&glChHandleMscOut, CY_U3P_DMA_TYPE_MANUAL_IN, &dmaConfig);

    if (status != CY_U3P_SUCCESS)

    {

        CyU3PDebugPrint (4, "DMA channel create failed1, code=%d\r\n", status);

        CyFxAppErrorHandler (status);

    }

    dmaConfig.prodSckId     = CY_U3P_CPU_SOCKET_PROD;

    dmaConfig.consSckId     = CY_U3P_UIB_SOCKET_CONS_1 ;

    dmaConfig.notification  = CY_U3P_DMA_CB_SEND_CPLT;

    dmaConfig.cb            = CyFxMscApplnDmaCb;

    status = CyU3PDmaChannelCreate (&glChHandleMscIn, CY_U3P_DMA_TYPE_MANUAL_OUT, &dmaConfig);

    if (status != CY_U3P_SUCCESS)

    {

        CyU3PDebugPrint (4, "DMA channel create failed2, code=%d\r\n", status);

        CyFxAppErrorHandler (status);

    }

    /* Create a DMA Channel for moving control data through GPIF to FPGA */

    dmaConfig.size           = 32;

    dmaConfig.count          = 1;

    dmaConfig.prodSckId      = CY_U3P_CPU_SOCKET_PROD; /* Move from CPU */

    dmaConfig.consSckId      = CY_U3P_PIB_SOCKET_1; /* To GPIF via socket 1, addressed via Addr A1:A0 "01" from FPGA */

    dmaConfig.dmaMode        = CY_U3P_DMA_MODE_BYTE;

    dmaConfig.notification   = 0xFF; //CY_U3P_DMA_CB_SEND_CPLT;

    dmaConfig.cb             = CyFxMscApplnDmaCbGpif;

    dmaConfig.prodHeader     = 0;

    dmaConfig.prodFooter     = 0;

    dmaConfig.consHeader     = 0;

    dmaConfig.prodAvailCount = 0;

    status = CyU3PDmaChannelCreate (&glChHandleGpifControl, CY_U3P_DMA_TYPE_MANUAL_OUT, &dmaConfig);

    if (status != CY_U3P_SUCCESS)

    {

        CyU3PDebugPrint (4, "DMA channel create failed, code=%d\r\n", status);

        CyFxAppErrorHandler (status);

    }

 

    dmaConfig.size  = 1024;

    dmaConfig.count = 1;

    dmaConfig.prodSckId = CY_U3P_UIB_SOCKET_PROD_1;

    dmaConfig.consSckId = CY_U3P_PIB_SOCKET_0;

    dmaConfig.dmaMode = CY_U3P_DMA_MODE_BYTE;

       /* Enabling the callback for produce event. */

    dmaConfig.notification = 0;

    dmaConfig.cb = NULL;

    dmaConfig.prodHeader = 0;

    dmaConfig.prodFooter = 0;

    dmaConfig.consHeader = 0;

    dmaConfig.prodAvailCount = 0;

    status = CyU3PDmaChannelCreate (&glChHandleSlFifoUtoP, CY_U3P_DMA_TYPE_AUTO, &dmaConfig);

       if (status != CY_U3P_SUCCESS)

       {

          CyU3PDebugPrint (4, "CyU3PDmaChannelCreate failed4, Error code = %d\n", status);

          CyFxAppErrorHandler(status);

       }

}

0 Likes
1 Solution

Hello,

Another question, if two channels cannot be created with the same producer socket. How are the 2nd an 3rd channels created without any issue, they both have the same producer socket (CY_U3P_CPU_SOCKET_PROD).

>> For MANUAL OUT DMA channels, CPU socket (CY_U3P_CPU_SOCKET_PROD) can be used for more than two DMA channels. In UsbBulksrcSink firmware of the Fx3 SDK, one MANUAL OUT channel is created and the API CyU3PDebugInit is called which internally creates one more MANUAL OUT channel.

In the source of CyU3PDmaChannelCreate API, the sockets are verified, if the same socket is used by some other channel or not. If the producer /consumer socket is used in some other DMA channel then the CY_U3P_ERROR_BAD_ARGUMENT error is returned. This check is not done for producer socket of  CY_U3P_DMA_TYPE_MANUAL_OUT channel  & consumer socket of CY_U3P_DMA_TYPE_MANUAL_IN

Regards,

Rashi

Regards,
Rashi

View solution in original post

0 Likes
3 Replies
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

As the first DMA channel is created between UIB (CY_U3P_UIB_SOCKET_PROD_1) and CPU, the fourth DMA channel (UIB (CY_U3P_UIB_SOCKET_PROD_1) to PIB)  will not be created as the same producer socket being used. DMA channels with the same producer/consumer sockets cannot be created simultaneously.

If you want to use both the channel one channel should be destroyed and only then the other one should be created and can be used

Please let me know if any queries on this

Regards

Rashi

Regards,
Rashi
0 Likes

Hi,

Thanks for the response.

Another question, if two channels cannot be created with the same producer socket. How are the 2nd an 3rd channels created without any issue , they both have the same producer socket (CY_U3P_CPU_SOCKET_PROD).

0 Likes

Hello,

Another question, if two channels cannot be created with the same producer socket. How are the 2nd an 3rd channels created without any issue, they both have the same producer socket (CY_U3P_CPU_SOCKET_PROD).

>> For MANUAL OUT DMA channels, CPU socket (CY_U3P_CPU_SOCKET_PROD) can be used for more than two DMA channels. In UsbBulksrcSink firmware of the Fx3 SDK, one MANUAL OUT channel is created and the API CyU3PDebugInit is called which internally creates one more MANUAL OUT channel.

In the source of CyU3PDmaChannelCreate API, the sockets are verified, if the same socket is used by some other channel or not. If the producer /consumer socket is used in some other DMA channel then the CY_U3P_ERROR_BAD_ARGUMENT error is returned. This check is not done for producer socket of  CY_U3P_DMA_TYPE_MANUAL_OUT channel  & consumer socket of CY_U3P_DMA_TYPE_MANUAL_IN

Regards,

Rashi

Regards,
Rashi
0 Likes