CRCCalculator.h

Go to the documentation of this file.
00001 /*
00002  * crc.h
00003  *
00004  * Algorithm based on universal_crc by Danjel McGougan
00005  *
00006  * CRC parameters used:
00007  *   bits:       16
00008  *   poly:       0x8005
00009  *   init:       0xffff
00010  *   xor:        0x0000
00011  *   reverse:    false
00012  *   non-direct: false
00013  *
00014  * CRC of the string "123456789" is 0xaee7
00015  */
00016 
00017 #ifndef _evb_CRCCalculator_h_
00018 #define _evb_CRCCalculator_h_
00019 
00020 #include <cassert>
00021 #include <stddef.h>
00022 #include <stdint.h>
00023 
00024 #include <boost/scoped_ptr.hpp>
00025 
00026 namespace evb {
00027 
00028   extern const uint16_t crcTable[1024];
00029 
00030 
00031   class CRCCalculator
00032   {
00033   public:
00034 
00035     CRCCalculator();
00036 
00040     uint16_t compute(const uint8_t* buffer, size_t bufSize) const;
00041 
00045     void compute(uint16_t& crc, const uint8_t* buffer, size_t bufSize) const;
00046 
00047   private:
00048 
00049     static inline void computeCRC_8bit(uint16_t& crc, const uint8_t data)
00050     {
00051       crc = (crc << 8) ^ crcTable[((crc >> 8) & 0xff) ^ data];
00052     }
00053 
00054     static inline void computeCRC_32bit(uint16_t& crc, uint32_t data)
00055     {
00056       crc ^= data >> 16;
00057       crc =
00058         crcTable[data & 0xff] ^
00059         crcTable[((data >> 8) & 0xff) + 0x100] ^
00060         crcTable[(crc & 0xff) + 0x200] ^
00061         crcTable[((crc >> 8) & 0xff) + 0x300];
00062     }
00063 
00064     const bool havePCLMULQDQ_;
00065 
00066   };
00067 
00068   extern "C"
00069   {
00070     uint16_t crc16_T10DIF_128x_extended
00071     (
00072       uint16_t init_crc,            // initial CRC value, 16 bits
00073       const unsigned char *buffer,  // buffer pointer to calculate CRC on
00074       size_t bufSize                // buffer length in bytes (64-bit data)
00075     );
00076   }
00077 
00078 } // namespace evb
00079 
00080 #endif // _evb_CRCCalculator_h_
00081 

Generated on 11 Jun 2014 for ”CMSOnlineSoftware(XDAQ)” by  doxygen 1.6.1