How do I free MANUAL or MANUAL_IN related buffers?

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

cross mob
maVa_1182686
Level 3
Level 3
Welcome!

One of the interfaces on my firmware has a BULK_out endpoint to transfer data from the host to the FX3.

The problem is that I can only transfer the amount of data that fits into the allocated buffers. They don't seem to be reused.

When I allocate 16 buffers (1024 bytes) and send a 16kByte file, it works. 17kByte gives an error.

If I do 1byte messages, I can send 16 of them, the 17th will fail.

This leads me to believe I fail to reuse and empty the buffers.

I have it setup either in MANUAL or MANUAL_IN

     dmaCfg.size  = DMA_BUF_SIZE* size;

     dmaCfg.count = CY_FX_SLFIFO_DMA_BUF_COUNT_U_2_P;

     dmaCfg.prodSckId = CY_FX_PRODUCER_USB_SOCKET;

     //dmaCfg.consSckId = CY_FX_CONSUMER_PPORT_SOCKET;

     dmaCfg.consSckId = CY_U3P_CPU_SOCKET_CONS; //TEST MANUAL_IN instead of MANUAL

     dmaCfg.dmaMode = CY_U3P_DMA_MODE_BYTE;

     /* Enabling the callback for produce event. */

     dmaCfg.notification = CY_U3P_DMA_CB_PROD_EVENT;

     dmaCfg.cb = CyFxSlFifoUtoPDmaCallback;

     dmaCfg.prodHeader = 0;

     dmaCfg.prodFooter = 0;

     dmaCfg.consHeader = 0;

     dmaCfg.prodAvailCount = 0;

  apiRetStatus = CyU3PDmaChannelCreate (&glChHandleSlFifoUtoP,

          CY_U3P_DMA_TYPE_MANUAL_IN, &dmaCfg);

with a callback

void

CyFxSlFifoUtoPDmaCallback (

        CyU3PDmaChannel   *chHandle,

        CyU3PDmaCbType_t  type,

        CyU3PDmaCBInput_t *input

        )

{

uint16_t index;

    CyU3PReturnStatus_t status = CY_U3P_SUCCESS;

    CyU3PDebugPrint (4, "_____DATA RECEIVED_____");

    if (type == CY_U3P_DMA_CB_PROD_EVENT)

    {

        /* This is a produce event notification to the CPU. This notification is

         * received upon reception of every buffer. The buffer will not be sent

         * out unless it is explicitly committed. The call shall fail if there

         * is a bus reset / usb disconnect or if there is any application error. */

        status = CyU3PDmaChannelCommitBuffer (chHandle, input->buffer_p.count, 0);

        switch (input->buffer_p.buffer[0]){

        case 0xFF: //Message for FPGA...copy message into ConfigBuffer

        //CyU3PDebugPrint (4,"COPY TO CONFIGBUFFER REQUESTED");

        for ( index = 0; index < input->buffer_p.count; index++){

        ConfigBuffer[index] = input->buffer_p.buffer[index];

        }

        Broadcast_to_fpga_flag = 1;

        break;

        case 0x00: //Command for FX3 Request RESET TODO

        CyU3PDebugPrint (4, "reset request");

        Reset_to_fpga_flag = 1;

        break;

        case 0x01: //Request FPGA start measurement TODO

        CyU3PDebugPrint (4, "FPGA start measurement request");

            break;

        case 0x02: //Request FPGA start measurement TODO

        CyU3PDebugPrint (4, "FPGA stop measurement request");

            break;

        //case...... All the request implemented here

        }

        glDMARxCount++;

    }

}

Where should I expect the BUFFER to be cleared again?

I assumed the commit does that?

Thanks!

0 Likes
1 Solution
Hemanth
Moderator
Moderator
Moderator
First like given First question asked 750 replies posted

Hi,

CyU3PDmaChannelDiscardBuffer() can be used in callback.

So, before calling this API, make sure it is used as required OR If it cannot be used within the callback, then you can copy that to a local buffer.

Note: It is not recommended to use CyU3PDebugPrint() in dma callback

Regards,

Hemanth

Hemanth

View solution in original post

0 Likes
3 Replies
Hemanth
Moderator
Moderator
Moderator
First like given First question asked 750 replies posted

Hi,

After the data buffer that is made available through input->buffer_p.buffer is used in the dma callback, call CyU3PDmaChannelDiscardBuffer() to make the buffer available again for the producer (in your case USB).

For MANUAL_IN channel CyU3PDmaChannelCommitBuffer() call is not needed, as data is already available to CPU when you get the callback.

Regards,

Hemanth

Hemanth
0 Likes

But you can't use CyU3PDmaChannelDiscardBuffer() inside the Call Back routine.

Where do you use it then?

0 Likes
Hemanth
Moderator
Moderator
Moderator
First like given First question asked 750 replies posted

Hi,

CyU3PDmaChannelDiscardBuffer() can be used in callback.

So, before calling this API, make sure it is used as required OR If it cannot be used within the callback, then you can copy that to a local buffer.

Note: It is not recommended to use CyU3PDebugPrint() in dma callback

Regards,

Hemanth

Hemanth
0 Likes