Click here to Skip to main content
15,888,300 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created a buffer...

char buffer[8]="mindflow";

and i tried to copy this buffer contents into another buffer buffer_p.count which is defined in nested structure....

/* DMA callback function to handle the produce events for P to U transfers. */
void
CyFxSlFifoPtoUDmaCallback (
CyU3PDmaChannel *chHandle,
CyU3PDmaCbType_t type,
CyU3PDmaCBInput_t *input

)
{
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;

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. */
char buffer[9]= "MIND FLOW";

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

if (status != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelCommitBuffer failed, Error code = %d\n", status);
}

/* Increment the counter. */
glDMATxCount++;
}
}

What I have tried:

/* DMA callback function to handle the produce events for P to U transfers. */
void
CyFxSlFifoPtoUDmaCallback (
        CyU3PDmaChannel   *chHandle,
        CyU3PDmaCbType_t  type,
        CyU3PDmaCBInput_t *input

        )
{
    CyU3PReturnStatus_t status = CY_U3P_SUCCESS;

    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. */
    	char buffer[9]= "MIND FLOW";

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

        if (status != CY_U3P_SUCCESS)
        {
            CyU3PDebugPrint (4, "CyU3PDmaChannelCommitBuffer failed, Error code = %d\n", status);
        }

        /* Increment the counter. */
        glDMATxCount++;
    }
}
Posted
Updated 29-Aug-17 1:37am
Comments
Mohibur Rashid 30-Aug-17 4:27am    
You will have issue with this statement
char buffer[9]= "MIND FLOW";
Change it to
char buffer[10]= "MIND FLOW";

You might use the memcpy[^] function for the purpose.

Please note you have first to allocate (possibly dynamic) memory for the destination buffer (and then you have to release the dynamically allocated memory).
 
Share this answer
 
v2
To answer that the declaration of input->buffer_p[.count] must be known and how many bytes should be copied from where to where. Note that I have put the .count into brackets because the name indicates that it is a count/size value and not a buffer.

Okay, I searched for it and found it at https://github.com/nickdademo/cypress-fx3-sdk-linux/blob/master/firmware/u3p_firmware/inc/cyu3dma.h[^]:
typedef struct CyU3PDmaBuffer_t
{
    uint8_t *buffer;    /**< Pointer to the data buffer. */
    uint16_t count;     /**< Byte count of valid data in buffer. */
    uint16_t size;      /**< Actual size of the buffer in bytes. Should be a multiple of 16. */
    uint16_t status;    /**< Buffer status. This is a four bit data field defined by 
                             CY_U3P_DMA_BUFFER_STATUS_MASK. This holds information like
                             whether the buffer is occupied, whether the buffer holds the
                             end of packet and whether the buffer encountered a DMA error. */
} CyU3PDmaBuffer_t;

/** \brief DMA channel callback input.
    **Description**\n
    This data structure is used to provide event specific information when a DMA callback
    is called. This structure is defined as a union to facilitate future updates to the
    DMA manager.
    **\see
    *\see CyU3PDmaBuffer_t
    *\see CyU3PDmaCallback_t
 */
typedef union CyU3PDmaCBInput_t
{
    CyU3PDmaBuffer_t buffer_p;  /**< Data about the DMA buffer that caused the callback to be called. */
} CyU3PDmaCBInput_t;

According to that you can copy the data to your buffer with
C++
memcpy(buffer, input->buffer_p.buffer, input->buffer_p.count);
provided that your buffer is large enough (size >= input->buffer_p.count).

To copy data to the input->buffer_p, copy in the reverse direction and set the other structure members accordingly (count, status) after checking for sufficient size.
[EDIT: Example]
C++
uint16_t bufSize = sizeof(buffer); // or whatever the actual size is
if (bufSize <= input->buffer_p.size)
{
    input->buffer_p.count = bufSize;
    input->buffer_p.status = theStatus; // 
    memcpy(input->buffer_p.buffer, buffer, bufSize);
}
But you have to comply with the specifications of the SDK
[/EDIT]

I'm not sure for which direction the callback is issued here. But you should know when doing such low level stuff.
 
Share this answer
 
v2
Comments
Veerendra-13142768 30-Aug-17 2:41am    
here im trying to call back from processor to usb.
Jochen Arndt 30-Aug-17 2:58am    
See my updated answer.
But you have to know what you do and comply with the specifications of the SDK.
Veerendra-13142768 30-Aug-17 4:52am    
Thanks for ur reply. I have seen ur recent reply. Here i have created own buffer with 8 bytes, i want to copy those bytes to buffer p to u(buffer_P). But that buffer is declared in structures of different file location. I cant edit structure of defined buffer there, don't know how to copy the buffer contents.

Here im attaching the file link for your reference....

Thank you...
Jochen Arndt 30-Aug-17 5:19am    
What is the problem?
If you have a buffer_p structure, do it as in my solution by just removing the "input->".

To copy data from one buffer to another you need:
- A pointer to the source buffer (buffer)
- A pointer to the destination buffer (buffer_p.buffer)
- The number of bytes to be copied (8)
- Ensure that the destination buffer is large enough (here: buffer_p.size >= 8)
- Then call memcpy()
- In this special case set also buffer_p.count to indicate how many data bytes are actually stored in the buffer. It might be also necessary to set the status member.

You don't have to edit the structure declaration. You just have to use the existing structure (input->buffer_p) as in my example code. The necessary information is contained in the structure declaration and my solution is based on that. That is why I posted it in my solution because it is essential in this case.

To be honest, if you don't get that you should not use such low level SDK stuff (especially because there is usually not much documentation and understanding the SDK requires reading and understanding the SDK source code).

There may be however another problem when the passed input->buffer_p is not allocated (buffer member NULL or size member zero). Then you might have to allocate the buffer (size should be a multiple of 16; see the comment at the structure declaration). But that should be mentioned somewhere in the SDK documentation or the source code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900