1 Reply Latest reply on Sep 20, 2019 6:18 AM by YashwantK_46

    [FX3] Any way to know the numbers of DMA buffer are not occupied


      Hi Cypress,


      I am working on a project on FX3. This application consists of a GPIF interface and a USB BULK IN endpoint. The GPIF interface works as SLAVE. The master writes data to the FX3. And, the PC gets the data from USB BULK IN endpoint. My question is:


      How can I know the exact number of DMA slots are occupied? As if the PC know this number, it can issue exact number of URBs to get the data without continuously polling the USB BULK IN endpoint? Any API can do so?




        • 1. Re: [FX3] Any way to know the numbers of DMA buffer are not occupied

          Hi Jason,

          There's no specific API to get the DMA buffer count.

          If you are using MANUAL channel, there is a possibility of getting the buffer count in a way but if AUTO channel is being used, there's no way to get the count.


          Please follow the steps below to get the buffer count:

          1.) Declare a global array variable ( let's say uint32_t count[32] __attribute__ ((aligned (32))).

          2.)Also, create another global variable to store the buffer counter value ( let's say uint8_t bufCount = 0).

          3.)Change the  dmaCfg.notification = CY_U3P_DMA_CB_PROD_EVENT | CY_U3P_DMA_CB_CONS_EVENT;

          4.) Whenever the master writes data to the GPIF block, a CY_U3P_DMA_CB_PROD_EVENT will be generated in the CyFxSlFifoUtoPDmaCallback () API and that buffer will get committed to the USB block.

          5.) Increment the variable here=> bufCount++ after the commitbuffer API is called and assign the value of bufCount to the first location of the array using count[0] = bufCount .

          6.) Add another if condition in the same API with else if (type == CY_U3P_DMA_CB_CONS_EVENT) and just decrement the variable here => bufCount-- and assign the value ot the first element of the array as count[0] = bufCount .

          7.) In the CyFxSlFifoApplnUSBSetupCB() , create a else if (bType == CY_U3P_USB_VENDOR_RQT).

          8.) In the else if, add if (bRequest == 0xAC) and in that if condition, we will send the data of bufCount to the host by using CyU3PUsbSendEP0Data (8, (uint32_t *)count); and then close the if condition.

          9.) Now, if you send 0xAC ( can be changed to any hex value)  over the control endpoint at any point of time, there will be a count value of the buffers that are yet to be committed which can help you decide how much data should be requested in the URB.