1 Reply Latest reply on Mar 22, 2020 9:01 PM by JayakrishnaT_76

    CX3: How come streaming is not running infinite?

    NiEn_2817821

      I have following code:

       

       

      static int32_t DmaUsbCommitCount = 0;

       

      void DmaCallback(

         CyU3PDmaMultiChannel* chHandle,

         CyU3PDmaCbType_t  type,

         CyU3PDmaCBInput_t* input

      )

      {

         CyU3PDmaBuffer_t dmaBuffer;

         CyU3PReturnStatus_t status = CY_U3P_SUCCESS;

       

         if (CY_U3P_DMA_CB_PROD_EVENT & type)

         {

            status = CyU3PDmaMultiChannelGetBuffer(chHandle, &dmaBuffer, CYU3P_NO_WAIT);

            // add header

            if (3 < DmaUsbCommitCount) {

      /* Discard Buffer */

      status = CyU3PDmaMultiChannelDiscardBuffer(chHandle);

      if (status != CY_U3P_SUCCESS) {

      // error handling

      }

            }

            else {

      /* Commit Buffer to USB*/

      status = CyU3PDmaMultiChannelCommitBuffer(chHandle, (dmaBuffer.count + SD_PROD_HEADER), 0);

      if (status != CY_U3P_SUCCESS) {

      // error handling

      }

      else

      {

      DmaUsbCommitCount++;

      }

            }

         }

         if (CY_U3P_DMA_CB_CONS_EVENT & type)

         {

      DmaUsbCommitCount--;

         }

      }

       

      As I have 6 DMA buffers, I assumed that the above code would keep the producer running (swapping between 2 buffers) while 4 buffers get stocked as committed to the USB, when the host stops reading data on the USB.

      But what happens, is either that the DmaCallback stops getting called with producer events, or sometimes CyU3PDmaMultiChannelGetBuffer returns 0x45 (CY_U3P_ERROR_TIMEOUT) and then no more events are received.

       

      How do I keep the producer running, when the USB commits are stocked?

       

      When streaming and NOT running into the above USB stocked scenario, the DmaCallback gets called with the event type 5 (CY_U3P_DMA_CB_XFER_CPLT + CY_U3P_DMA_CB_RECV_CPLT) after steaming for a short while.

      How can that be, when I call CyU3PDmaMultiChannelSetXfer(&DmaStreamingHandle, 0, 0) just before starting streaming? Shouldn’t it then run infinite?