1 2 3 Previous Next 37 Replies Latest reply on Nov 11, 2019 8:40 PM by JayakrishnaT_76

    Circular Buffer implementation in Fx3

    poas_4520791

      Hi

      The data from PC should transfer to p-port through circular buffer in a continuous manner and data should not repeat.can anyone help me to do this.

        • 1. Re: Circular Buffer implementation in Fx3
          JayakrishnaT_76

          Hello,

           

          Firstly, can you please let us know what did you meant by circular buffer? Is it like a circular queue of  buffer or individual buffers that are circular.

          All the buffers used in the example projects provided with FX3 SDK are circular queues of buffer. That is while we create a DMA channel, we set the size of buffer allocated with the channel and the number of buffers allocated to that channel. When a buffer is filled, the incoming data will be automatically written to the next buffer. In the meanwhile, the first buffer is committed to the consumer socket. After committing the buffer, we discard the buffer data. When the last buffer is filled, the first buffer can be used to store the incoming data. For better understanding can you please go through Page 38 of AN75779 which can be found in the following link.

          https://www.cypress.com/file/123506/download

          Is this what you exactly want?

          If you want the other case, can you please let us know what exactly is the application? Also can you let us know how you can understand when the buffer becomes full and what is the advantage of using such a buffer?

           

          Best Regards,

          Jayakrishna

          • 2. Re: Circular Buffer implementation in Fx3
            poas_4520791

            Hello,

            Thanks for your reply, i'm using array of buffers with two variables to hold index values like this,

             

            #define MAX_LENGTH 32

            unsigned char buffer [MAX_LENGTH];

            unsigned char head;

            unsigned char tail;

             

            The advantage of implementing circular buffer is we can send/receive/store  data of large size by Increasing  MAX_LENGTH value.

             

            Best Regards,

            Aswini

            • 3. Re: Circular Buffer implementation in Fx3
              JayakrishnaT_76

              Hello Aswini,

               

              Please find my comments below:

               

              1. For sending data from U port to P port, we make use of DMA channels.

              2. These DMA channels have buffers allocated with it. So you need not create a separate buffer with 2 variables.

              3. You can configure the DMA channel as shown below

                   CyU3PDmaChannelConfig_t dmaCfg;

                   CyU3PMemSet ((uint8_t *)&dmaCfg, 0, sizeof (dmaCfg));

                   dmaCfg.size  = CY_FX_DMA_BUF_SIZE;              /* This is the buffer size. You can change the size of this buffer according to your need*/

                   dmaCfg.count = CY_FX_DMA_BUF_COUNT;                                           // This is the number of such buffers required

                   dmaCfg.prodSckId = CY_FX_GPIF_PRODUCER_SOCKET;                    // producer socket is any socket associated with U port

                   dmaCfg.consSckId = CY_FX_EP_CONSUMER_SOCKET;                        // consumer socket is any socket associated with P port

                   dmaCfg.dmaMode = CY_U3P_DMA_MODE_BYTE;                              

                   dmaCfg.prodHeader = 0;

                   dmaCfg.prodFooter = 0;

                   dmaCfg.consHeader = 0;

                   dmaCfg.prodAvailCount = 0;

                   dmaCfg.notification = CY_U3P_DMA_CB_CONS_SUSP;

                   dmaCfg.cb = GpifToUsbDmaCallback;

                   apiRetStatus = CyU3PDmaChannelCreate (&glDmaChHandle, CY_U3P_DMA_TYPE_AUTO, &dmaCfg)

                   This creates an AUTO DMA Channel(without any CPU intervention).

              4.The size of the DMA buffers should be multiples of 16 bytes, the maximum size of an individual DMA buffer can be as much as 0xFFF0 bytes. You can configure multiple buffers of such size by changing the CY_FX_DMA_BUF_COUNT value. So that when one buffer is filled, next buffer will be written. This prevents the buffers from getting overwritten.

               

              Best Regards,

              Jayakrish

              • 4. Re: Circular Buffer implementation in Fx3
                poas_4520791

                Hii Jayakrishna,

                 

                Actually  with circular buffer we can send any number of bytes not only multiples of 16 and also doesn't need to shuffle elements when one is consumed,so i'm trying to implement it.I'm getting the data into circular buffer and then data should transfer to consumer socket.can anyone let me know how to do this.

                I used the code which you gave,but i'm not getting the actual output.

                 

                 

                Best Regards,

                Aswini

                • 5. Re: Circular Buffer implementation in Fx3
                  JayakrishnaT_76

                  Hello Aswini,

                   

                  Can you please let me know what exactly is the application. Can you also let me know how you are planning to read the data transmitted from U port to P port?

                   

                  Best Regards,

                  Jayakrishna

                  • 6. Re: Circular Buffer implementation in Fx3
                    poas_4520791

                    Hii,

                     

                    Data from PC  --> circular buffer --> consumer socket --> p-port.

                    This is the flow i'm trying to implement in FX3.

                     

                     

                    Best Regards,

                    Aswini

                    • 7. Re: Circular Buffer implementation in Fx3
                      JayakrishnaT_76

                      Hello,

                       

                      I find that data from PC is routed to the USB port (U Port). From there you need to transfer the data to GPIF or P port. I understand this is your basic application. This do not require the use of buffer with 2 different index values.

                      This can be done by making use of a DMA channel between U port and P Port. The communication between different blocks present in FX3 is done by making use of DMA channels. DMA channel has a logical producer socket which in your case is a USB Socket and a consumer socket which is a P Port Socket. The DMA channel also has buffers associated with it. Each buffer can have a size which is a multiple of 16 bytes. You can make use of multiple buffers to avoid lose of data. This is because if a buffer is full, the producer socket automatically writes data to the next available buffer. In the meanwhile, the filled buffer is committed and emptied.

                      If the data length is less than 16 bytes or not a multiple of 16 bytes, then you can make use of CyU3PDmaChannelSetWrapUp API to commit the last few bytes. The details regarding this API can be found in page 235 of FX3 API Guide.

                      Also please try AN87216. It is used for developing a master interface using FX3 for communicating with an external slave FIFO. The full file and documentation regarding this can be found from the following link:

                      https://www.cypress.com/documentation/application-notes/an87216-designing-gpif-ii-master-interface

                      Please modify this firmware based on your application and let us know the results.

                       

                      Best Regards,

                      Jayakrishna

                      1 of 1 people found this helpful
                      • 8. Re: Circular Buffer implementation in Fx3
                        poas_4520791

                        Hi,

                         

                        Sorry for late reply.Based on your explanation i'm trying to transfer data without using circular buffer. I changed the dma configuration code based on the code which you have sent,but while booting fx3 is not detecting.Kindly,let me know what might be the problem.

                        can you help me to do this?

                         

                        Regards,

                        Aswini

                        • 9. Re: Circular Buffer implementation in Fx3
                          JayakrishnaT_76

                          Hello,

                           

                          Can you please let me know which boot mode you used. Also is it like after loading the code, the device does not enumerate in the Control Center Application?

                           

                          Best Regards,

                          Jayakrishna

                          • 10. Re: Circular Buffer implementation in Fx3
                            poas_4520791

                            Hi,

                            The main problem is,the device is not detecting in control center.

                             

                             

                             

                            Regards,

                            Aswini

                            • 11. Re: Circular Buffer implementation in Fx3
                              JayakrishnaT_76

                              Hello Aswini,

                               

                              I found this thread where you addressed the same problem:

                              FX3 is not detecting

                               

                              I tried loading the firmware using FX3 Explorer kit and found that it was enumerating properly. Please check your board settings.

                               

                              Best Regards,

                              Jayakrishna

                              • 12. Re: Circular Buffer implementation in Fx3
                                poas_4520791

                                Hi,

                                 

                                yeah,it's detecting in control center but i'm getting 997 error.

                                 

                                 

                                Regards,

                                Aswini

                                • 13. Re: Circular Buffer implementation in Fx3
                                  JayakrishnaT_76

                                  Hello,

                                   

                                  Can you let me know whether you are using a vendor command? Also can you share a screenshot of the Control center application when you get the error?

                                   

                                  Best Regards,

                                  Jayakrishna

                                  1 2 3 Previous Next