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 
00025 namespace evb {
00026 
00027   extern const uint16_t crcTable[1024];
00028 
00029 
00030   class CRCCalculator
00031   {
00032   public:
00033 
00034     CRCCalculator();
00035 
00039     uint16_t compute(const uint8_t* buffer, size_t bufSize) const;
00040 
00044     void compute(uint16_t& crc, const uint8_t* buffer, size_t bufSize) const;
00045 
00049     uint32_t crc32c(uint32_t crc, const unsigned char *buf, size_t len) const;
00050 
00051 
00052   private:
00053 
00054     static inline void computeCRC_8bit(uint16_t& crc, const uint8_t data)
00055     {
00056       crc = (crc << 8) ^ crcTable[((crc >> 8) & 0xff) ^ data];
00057     }
00058 
00059     static inline void computeCRC_32bit(uint16_t& crc, uint32_t data)
00060     {
00061       crc ^= data >> 16;
00062       crc =
00063         crcTable[data & 0xff] ^
00064         crcTable[((data >> 8) & 0xff) + 0x100] ^
00065         crcTable[(crc & 0xff) + 0x200] ^
00066         crcTable[((crc >> 8) & 0xff) + 0x300];
00067     }
00068 
00069     const bool havePCLMULQDQ_;
00070     const bool haveSSE42_;
00071 
00072   };
00073 
00074   extern "C"
00075   {
00076     uint16_t crc16_T10DIF_128x_extended
00077     (
00078       uint16_t init_crc,            // initial CRC value, 16 bits
00079       const unsigned char *buffer,  // buffer pointer to calculate CRC on
00080       size_t bufSize                // buffer length in bytes (64-bit data)
00081     );
00082   }
00083 
00084 } // namespace evb
00085 
00086 extern uint32_t crc32c_sw(uint32_t crc, const unsigned char *buf, size_t len);
00087 extern uint32_t crc32c_hw(uint32_t crc, const unsigned char *buf, size_t len);
00088 
00089 #endif // _evb_CRCCalculator_h_
00090 

Generated on 16 Dec 2016 for ”CMSOnlineSoftware(XDAQ)” by  doxygen 1.6.1