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

cross mob
mcn
Level 2
Level 2
10 replies posted 5 questions asked 10 sign-ins

I have a MANUAL_IN DMA channel and am getting callbacks on CY_U3P_DMA_CB_PROD_EVENT. I need to process these buffers for some extended period of time. Rather than blocking in the callback function, I'm doing the following:

  1. In the DMA callback: set an event, do not do anything with the buffer
  2. When the event goes off in the mainloop, call:
while ((status = CyU3PDmaChannelGetBuffer(&gbl.dmaFwChannel, &buf, CYU3P_NO_WAIT)) == CY_U3P_SUCCESS) {
    process_buffer(buf.buffer, buf.count);
    CyU3PDmaChannelDiscardBuffer(&gbl.dmaFwChannel);
}​

Does this seem correct? I get a consistent crash after processing a few buffers.

Can CyU3PDmaChannelDiscardBuffer() be called from the main loop without issue?

Is there an example to demonstrate this better?

Thanks!

0 Likes
1 Solution
JiangJing
Moderator
Moderator
Moderator
First like given 250 sign-ins 250 replies posted

Hi,

      Sorry for the late reply. It is not recommended to pend buffer for a long time, because the DMA buffer might have got full (as you are not discarding the data or consuming the data through any available port).

View solution in original post

0 Likes
5 Replies
JiangJing
Moderator
Moderator
Moderator
First like given 250 sign-ins 250 replies posted

Hi,

     CyU3PDmaChannelDiscardBuffer() can be used in callback.  If it cannot be used within the callback,  you can copy that to a local buffer. And you can refer to the  USBBulkSourceSink firmware in the FX3 SDK.

 

0 Likes
mcn
Level 2
Level 2
10 replies posted 5 questions asked 10 sign-ins

When you say it "can be used in the callback", I think you mean it "MUST" be used in the callback or else the buffer needs to be copied to a local buffer. Is that right? In other words, in the PROD event callback, you must immediately dispose of the buffer--you cannot "save" it for later processing in the mainloop and discard it there.

Is that true? Buffers must be immediately disposed in the PROD callback?

The USBBulkSourceSink firmware is not relevant to this question. It does not pend buffers for later processing (or in fact do anything with the buffers it receives except immediately discard them).

Thanks for your comments.

0 Likes
JiangJing
Moderator
Moderator
Moderator
First like given 250 sign-ins 250 replies posted

Hi,

      Sorry for the late reply. It is not recommended to pend buffer for a long time, because the DMA buffer might have got full (as you are not discarding the data or consuming the data through any available port).

0 Likes
mcn
Level 2
Level 2
10 replies posted 5 questions asked 10 sign-ins

Thanks for the follow-up. I'm still confused as to whether I *can* do this (pend a DMA buffer from an interrupt into the main thread and then, in the main thread,  CyU3PDmaChannelDiscardBuffer() it).

Filling the DMA buffers is exactly what I want to happen while I process the data that's been uploaded (I mean, copying the data for later processing will quickly exhaust memory after all). Imagine an application that encrypts a stream of data that's being uploaded through USB. Doing this in the Dma callback function is probably going to cause problems (just like Debug printing). Allowing the DMA engine to queue packets for me that I process one at a time seems ideal. As I slowly process packets and discard the buffers, more uploads will occur automatically by the DMA engine--at least that's the idea.

So, bottom line--is it possible to pend received DMA buffers from the callback to be Discarded in the main thread?

Thanks!

0 Likes
JiangJing
Moderator
Moderator
Moderator
First like given 250 sign-ins 250 replies posted

Hi,

      What I mean is that it may cause a buffer overflow error if pending the buffer for a long time. And also, when all the DMA buffers are filled, you won't get the PROD Event,  and after discarding buffers, the socket would again point to the first buffer which is already filled ( not discarded), so it cannot write to the first buffer and hence no PROD event. I think that's why you got a consistent crash after processing a few buffers . And this is no different from handling it in callback function. So, I think it is impossible to pend the buffer for a long time. 

In addition, FX3 just acts as a pass-through for the data from the host, so don't perform the encryption/decryption of data in FX3.

Thanks

0 Likes