padding UVC header at the end

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

cross mob
Yunhua
Level 1
Level 1
First reply posted First question asked Welcome!

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

 CyFxUVCAddHeader (dmaBuffer.buffer - CY_FX_UVC_MAX_HEADER, CY_FX_UVC_HEADER_FRAME);

#define CY_FX_UVC_MAX_HEADER    (12)

this means GPIF process data, and left 1st 12 byte empty, then Pass to DMA callback, we use CyFxUVCAddHeader to add 12 bytes UVC header at beginning of each 16384 bytes. 

My question is: how can I let GPIF put image data at very beginning of the DMA buffer, then I can padding UVC header at the end of the image data in the DMA buffer. I know this is valid UVC spec. but since I'm develop my own camera device which running on my own design Host hardware. by doing so, I can avoid extra copy on Host for image data re-construction.  thanks.

0 Likes
1 Solution
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

To add header after the image/video data you can make the following modifications:

- Change the dmaCfg.prodHeader = 0; in the DMA channel configuration

- Change the  dmaCfg.prodFooter = 12+4; (DMA buffer should be multiple of 16 bytes)

- The DMA Buffer size dmaCfg.size = 16384;

- Initialize the GPIF counter to  ((16384-16)/ GPIF bus width (bytes) ) - 1

Add header towards the end of buffer

#define CY_FX_UVC_MAXHEADER (16)

 CyFxUVCAddHeader (dmaBuffer.buffer + dmaBuffer.size - CY_FX_UVC_MAXHEADER , CY_FX_UVC_HEADER_FRAME);

Regards,
Rashi

View solution in original post

5 Replies
Giraffe1492
Level 5
Level 5
25 sign-ins 25 likes received 10 solutions authored

In order to achieve your goal of placing the image data at the very beginning of the DMA buffer and adding the UVC header at the end of the image data, you can modify the GPIF II state machine and the DMA channel configuration. Here's how you can do it:


  1. Modify the GPIF II state machine to start writing data at the beginning of the DMA buffer. You can do this by changing the initial address value in the GPIF II Designer tool.
  2. Configure the DMA channel with a buffer size equal to the size of the image data plus the UVC header size (CY_FX_UVC_MAX_HEADER). This will ensure that the entire image data and the UVC header fit within the DMA buffer.
  3. In the DMA callback function, after receiving the buffer with the image data, add the UVC header at the end of the image data. You can calculate the address for the UVC header by adding the size of the image data to the buffer address.

Here's a code snippet to add the UVC header at the end of the image data in the DMA buffer:


 uint32_t uvcHeaderAddress = (uint32_t)(dmaBuffer.buffer + imageSize); CyFxUVCAddHeader((uint8_t *)uvcHeaderAddress, CY_FX_UVC_HEADER_FRAME); 

Make sure to replace 'imageSize' with the actual size of the image data in bytes. This approach should help you avoid the extra copy on the host side for image data re-construction.

https://www.infineon.com/cms/en/product/universal-serial-bus/usb-c-high-voltage-microcontrollers/ez-...
https://www.infineon.com/cms/en/product/universal-serial-bus/usb-c-high-voltage-microcontrollers/ez-...
https://www.infineon.com/cms/en/product/universal-serial-bus/usb-c-high-voltage-microcontrollers/ez-...
https://www.infineon.com/cms/en/product/promopages/makeradar/makeradar-school/programming-tutorial/
https://www.infineon.com/cms/en/product/universal-serial-bus/usb-c-high-voltage-microcontrollers/ez-...

 

0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

To add header after the image/video data you can make the following modifications:

- Change the dmaCfg.prodHeader = 0; in the DMA channel configuration

- Change the  dmaCfg.prodFooter = 12+4; (DMA buffer should be multiple of 16 bytes)

- The DMA Buffer size dmaCfg.size = 16384;

- Initialize the GPIF counter to  ((16384-16)/ GPIF bus width (bytes) ) - 1

Add header towards the end of buffer

#define CY_FX_UVC_MAXHEADER (16)

 CyFxUVCAddHeader (dmaBuffer.buffer + dmaBuffer.size - CY_FX_UVC_MAXHEADER , CY_FX_UVC_HEADER_FRAME);

Regards,
Rashi

Thank you @Giraffe1492 and @Rashi_Vatsa 

in @Rashi_Vatsa 's reply. 

- Initialize the GPIF counter to  ((16384-16)/ GPIF bus width (bytes) ) - 1

I couldn't find where is the source code to initialize this. for other changes, it is easy to find, e.g. https://github.com/stawel/cypress_fx3_OV5642/blob/master/src/uvc.c#L787

Since I couldn't find it. My question is: what is the default value before I make this change. if it is same, and my current camera works(UVC header at beginning). then I don't need make this change.

0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

In the cyfxgpif2config.h  0x00003FEF, /* CY_U3P_PIB_GPIF_DATA_COUNT_LIMIT */ and 0x00003FEF, /* CY_U3P_PIB_GPIF_ADDR_COUNT_LIMIT */ are set ta 16367 (16384 / 1(GPIF bus width) -16)  -1 

Regards,
Rashi
0 Likes
Yunhua
Level 1
Level 1
First reply posted First question asked Welcome!

thanks. @Rashi_Vatsa 

we will test this soon. 

0 Likes