Author Topic: CRC DMA PIC32  (Read 4942 times)

0 Members and 1 Guest are viewing this topic.

Offline MilanTopic starter

  • Contributor
  • Posts: 12
  • Country: cs
    • CNC MASINE
CRC DMA PIC32
« on: April 28, 2014, 12:45:02 am »
Hello,
is this right way to calculate CRC 16?

Calculation results on PIC and PC are not same  |O

Code: [Select]
extern BYTE Buffer[5000];


unsigned int DmaDoCrcExample(void)
{


       unsigned int hwCrc;

       int chn=2;

       DmaTxferRes res;


       mCrcConfigure(0x11021, 16, 0xffff);


       res = DmaChnMemCrc(&hwCrc, Buffer, sizeof(Buffer), chn, DMA_CHN_PRI2);

              if(res!=DMA_TXFER_OK)
                     return 0;   // DMA calculation failed



       return hwCrc;

}

Milan
skype: mladenovic.milan.kg
www.cncmasine.com

The greatest enemy of knowledge is not ignorance,it is the illusion of knowledge.
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: CRC DMA PIC32
« Reply #1 on: April 28, 2014, 01:44:24 am »
From another post I replied a long ago:

All you want to know about CRC algorithms with many different implementations and approaches:

http://www.csm.ornl.gov/~dunigan/crc.html

Another link of someone's implementation for embedded systems based on that paper linked above:

http://www.barrgroup.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
 

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 824
  • Country: es
Re: CRC DMA PIC32
« Reply #2 on: April 28, 2014, 10:53:43 am »
Check that following things in PC code match your PIC setup: polynomial (there are other possibilities than 0x1021), initial value (some code uses 0, some 0xFFFF), final inversion - any difference in these things will produce different results.
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: CRC DMA PIC32
« Reply #3 on: April 28, 2014, 03:39:28 pm »
Check that following things in PC code match your PIC setup: polynomial (there are other possibilities than 0x1021), initial value (some code uses 0, some 0xFFFF), final inversion - any difference in these things will produce different results.

aha! You found it!
 mCrcConfigure(0x11021, 16, 0xffff);

Btw values for CRC CCITT is 0x1021 for CRC-16 is 0x8005
 

Offline MilanTopic starter

  • Contributor
  • Posts: 12
  • Country: cs
    • CNC MASINE
Re: CRC DMA PIC32
« Reply #4 on: April 28, 2014, 06:55:05 pm »
@miguelvp
@abyrvalg


Thanks for help.


Best Regards
Milan
« Last Edit: April 28, 2014, 07:28:19 pm by Milan »
skype: mladenovic.milan.kg
www.cncmasine.com

The greatest enemy of knowledge is not ignorance,it is the illusion of knowledge.
 

Offline MilanTopic starter

  • Contributor
  • Posts: 12
  • Country: cs
    • CNC MASINE
Re: CRC DMA PIC32
« Reply #5 on: April 28, 2014, 08:36:39 pm »
After two days I decided to stop trying to make HW CRC working.
I decide to use SW CRC on both sides, It is not efficient but it works.

If someone have  idea how to set up HW CRC I will be thankful.

Best Regards
Milan

Code: [Select]
UINT16 Calc_CRC_C_ARC(BYTE *Buff, UINT16 Len)
{

   int i = 0;
   UINT16 crc = 0xFFFF;
   UINT counter = 0;

   UINT16 polynomial = 0xA001;

                  for(counter=0; counter<Len; counter++)
                  {
                        for (i = 0; i < 8; i++)
                        {
                              BIT bit = ((Buff[counter] >> (7 - i) & 1) == 1);
                              BIT c15 = ((crc >> 15 & 1) == 1);
                              crc <<= 1;
                              if (c15 ^ bit) crc ^= polynomial;
                        }
                  }

                  crc &= 0xffff;
                  return crc;
}
skype: mladenovic.milan.kg
www.cncmasine.com

The greatest enemy of knowledge is not ignorance,it is the illusion of knowledge.
 

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 824
  • Country: es
Re: CRC DMA PIC32
« Reply #6 on: April 29, 2014, 10:01:38 am »
Milan, can you post some sample data? Input buffer contents and hw crc result. I can try guessing the parameters for PC side code.

For sw way there is more efficient table-based approach that works on bytes instead of bits. See http://lxr.free-electrons.com/source/include/linux/crc16.h http://lxr.free-electrons.com/source/lib/crc16.c
That table is for 8005 (IBM) polynomial, but it's easy to find 1021 (HDLC) version.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf