work in progress

Dependencies:   FastAnalogIn FastIO USBDevice mbed FastPWM SimpleDMA

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Tue Jul 22 04:33:47 2014 +0000
Revision:
2:c174f9ee414a
Before change to ISR for accelerometer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjr 2:c174f9ee414a 1 #include "crc32.h"
mjr 2:c174f9ee414a 2
mjr 2:c174f9ee414a 3 #define CRC32_POLYNOMIAL 0xEDB88320L
mjr 2:c174f9ee414a 4
mjr 2:c174f9ee414a 5 void CRC32Value(unsigned long &CRC, unsigned char c)
mjr 2:c174f9ee414a 6 {
mjr 2:c174f9ee414a 7 /////////////////////////////////////////////////////////////////////////////////////
mjr 2:c174f9ee414a 8 //CRC must be initialized as zero
mjr 2:c174f9ee414a 9 //c is a character from the sequence that is used to form the CRC
mjr 2:c174f9ee414a 10 //this code is a modification of the code from the Novatel OEM615 specification
mjr 2:c174f9ee414a 11 /////////////////////////////////////////////////////////////////////////////////////
mjr 2:c174f9ee414a 12 unsigned long ulTemp1 = ( CRC >> 8 ) & 0x00FFFFFFL;
mjr 2:c174f9ee414a 13 unsigned long ulCRC = ((int) CRC ^ c ) & 0xff ;
mjr 2:c174f9ee414a 14 for (int j = 8 ; j > 0; j-- )
mjr 2:c174f9ee414a 15 {
mjr 2:c174f9ee414a 16 if ( ulCRC & 1 )
mjr 2:c174f9ee414a 17 {
mjr 2:c174f9ee414a 18 ulCRC = ( ulCRC >> 1 ) ^ CRC32_POLYNOMIAL;
mjr 2:c174f9ee414a 19 }
mjr 2:c174f9ee414a 20 else
mjr 2:c174f9ee414a 21 {
mjr 2:c174f9ee414a 22 ulCRC >>= 1;
mjr 2:c174f9ee414a 23 }
mjr 2:c174f9ee414a 24 }
mjr 2:c174f9ee414a 25 CRC = ulTemp1 ^ ulCRC;
mjr 2:c174f9ee414a 26 }
mjr 2:c174f9ee414a 27
mjr 2:c174f9ee414a 28 /* --------------------------------------------------------------------------
mjr 2:c174f9ee414a 29 Calculates the CRC-32 of a block of data all at once
mjr 2:c174f9ee414a 30 //the CRC is from the complete message (header plus data)
mjr 2:c174f9ee414a 31 //but excluding (of course) the CRC at the end
mjr 2:c174f9ee414a 32 -------------------------------------------------------------------------- */
mjr 2:c174f9ee414a 33 unsigned long CRC32(const void *data, int len)
mjr 2:c174f9ee414a 34 {
mjr 2:c174f9ee414a 35 //////////////////////////////////////////////////////////////////////
mjr 2:c174f9ee414a 36 //the below code tests the CRC32Value procedure used in a markov form
mjr 2:c174f9ee414a 37 //////////////////////////////////////////////////////////////////////
mjr 2:c174f9ee414a 38 unsigned long CRC = 0;
mjr 2:c174f9ee414a 39 const unsigned char *p = (const unsigned char *)data;
mjr 2:c174f9ee414a 40 for (int i = 0 ; i < len ; i++)
mjr 2:c174f9ee414a 41 CRC32Value(CRC, *p++);
mjr 2:c174f9ee414a 42
mjr 2:c174f9ee414a 43 return CRC;
mjr 2:c174f9ee414a 44 }
mjr 2:c174f9ee414a 45
mjr 2:c174f9ee414a 46 /*
mjr 2:c174f9ee414a 47 unsigned long CalculateBlockCRC32(
mjr 2:c174f9ee414a 48 unsigned long ulCount,
mjr 2:c174f9ee414a 49 unsigned char *ucBuffer )
mjr 2:c174f9ee414a 50 {
mjr 2:c174f9ee414a 51 ////////////////////////////////////////////
mjr 2:c174f9ee414a 52 //original code from the OEM615 manual
mjr 2:c174f9ee414a 53 ////////////////////////////////////////////
mjr 2:c174f9ee414a 54 unsigned long ulTemp1;
mjr 2:c174f9ee414a 55 unsigned long ulTemp2;
mjr 2:c174f9ee414a 56 unsigned long ulCRC = 0;
mjr 2:c174f9ee414a 57 while ( ulCount-- != 0 )
mjr 2:c174f9ee414a 58 {
mjr 2:c174f9ee414a 59 ulTemp1 = ( ulCRC >> 8 ) & 0x00FFFFFFL;
mjr 2:c174f9ee414a 60 ulTemp2 = CRC32Value( ((int) ulCRC ^ *ucBuffer++ ) & 0xff );
mjr 2:c174f9ee414a 61 ulCRC = ulTemp1 ^ ulTemp2;
mjr 2:c174f9ee414a 62 }
mjr 2:c174f9ee414a 63 return( ulCRC );
mjr 2:c174f9ee414a 64 }
mjr 2:c174f9ee414a 65 */