Critical Link MityCam SoC Firmware  1.0
Critical Link MityCam SoC Firmware
CRC.h
Go to the documentation of this file.
1 /*
2  ** CRC Calculator by Paul Johnston
3  ** Version 1.0 Copyright 10/9/96 (September)
4  ** Explicitly released to the public domain 30-Oct-1996 by the author
5  */
6 
7 /* Custom Hungarian types:
8  **
9  ** crp - CRC Polynomial
10  ** crgi - CRC reGister Inital value
11  ** crxo - CRC Xor Out value
12  ** crpt - CRC Precalculated Table
13  ** crr - is CRC Reversed
14  ** crst - CRC Standard Type
15  */
16 
17 #ifndef PAJ_CRC
18 #define PAJ_CRC
19 
20 #ifdef _MSC_VER
21 typedef unsigned int uint32_t;
22 #else
23 #include <stdint.h>
24 #endif
25 
26 class PData
27 {
28 public:
29  uint32_t l;
30  void *pData;
31 };
32 
33 uint32_t Reflect(uint32_t toref, char w);
34 
35 enum Crst
36 {
37  Crc16 = 0,
43 };
44 
45 class CheckCalc
46 {
47 public:
48  virtual uint32_t Add(uint32_t crc, char *sCrc)=0;
49  virtual uint32_t Add(uint32_t crc, unsigned char sCrc)=0;
50  virtual uint32_t Add(uint32_t crc, PData sCrc)=0;
51  virtual uint32_t Init()=0;
52 };
53 
55 {
56 private:
57  uint32_t acrpt[256], crp, crgi, crxo;
58  unsigned char fcrr, crwd;
59  void InitCalc(uint32_t crpNew, uint32_t crgiNew,
60  uint32_t crxoNew, unsigned char fcrrNew,
61  unsigned char crwdNew);
62 
63 public:
64  uint32_t Add(uint32_t crc, char *sCrc);
65  uint32_t Add(uint32_t crc, unsigned char sCrc);
66  uint32_t Add(uint32_t crc, PData sCrc);
67  uint32_t Init();
68  CrcCalc(uint32_t crpNew, uint32_t crgiNew = 0,
69  uint32_t crxoNew = 0, unsigned char fcrrNew = 1,
70  unsigned char crwdNew = 32);
71  CrcCalc(Crst crst);
72 };
73 
74 class Crc
75 {
76 private:
77  uint32_t crc;
78  CheckCalc *crccalc;
79 
80 public:
81  uint32_t crcGet()
82  {
83  return crc;
84  }
85  ;
86  void Add(char *sCrc)
87  {
88  crc = crccalc->Add(crc, sCrc);
89  }
90  void Add(char sCrc)
91  {
92  crc = crccalc->Add(crc, sCrc);
93  }
94  void Add(PData sCrc)
95  {
96  crc = crccalc->Add(crc, sCrc);
97  }
98  void NewCrc()
99  {
100  crc = crccalc->Init();
101  }
102 
103  operator uint32_t()
104  {
105  return crcGet();
106  }
107  void operator <<(char *sCrc)
108  {
109  Add(sCrc);
110  }
111  void operator <<(char sCrc)
112  {
113  Add(sCrc);
114  }
115  void operator <<(PData sCrc)
116  {
117  Add(sCrc);
118  }
119  void operator =(int iNew)
120  {
121  if (iNew == 0)
122  NewCrc();
123  }
124 
125  Crc(CheckCalc *crccalcNew)
126  {
127  crccalc = crccalcNew;
128  NewCrc();
129  }
130 };
131 
132 #endif // PAJ_CRC
ZModemCrc16
@ ZModemCrc16
Definition: CRC.h:41
CrcCalc::CrcCalc
CrcCalc(uint32_t crpNew, uint32_t crgiNew=0, uint32_t crxoNew=0, unsigned char fcrrNew=1, unsigned char crwdNew=32)
Definition: CRC.cpp:99
PData::l
uint32_t l
Definition: CRC.h:29
Crc::Add
void Add(char *sCrc)
Definition: CRC.h:86
Crc::operator=
void operator=(int iNew)
Definition: CRC.h:119
PData::pData
void * pData
Definition: CRC.h:30
Crc::crcGet
uint32_t crcGet()
Definition: CRC.h:81
Crc16
@ Crc16
Definition: CRC.h:37
Crc::Add
void Add(char sCrc)
Definition: CRC.h:90
Crc
Definition: CRC.h:74
CheckCalc
Definition: CRC.h:45
CheckCalc::Init
virtual uint32_t Init()=0
JamCrc
@ JamCrc
Definition: CRC.h:39
Crc32
@ Crc32
Definition: CRC.h:38
Crc::operator<<
void operator<<(char *sCrc)
Definition: CRC.h:107
CrcCalc::Init
uint32_t Init()
Definition: CRC.cpp:69
PData
Definition: CRC.h:26
CrcCalc::Add
uint32_t Add(uint32_t crc, char *sCrc)
Definition: CRC.cpp:22
XModemCrc
@ XModemCrc
Definition: CRC.h:40
CrcCalc
Definition: CRC.h:54
Crc::Crc
Crc(CheckCalc *crccalcNew)
Definition: CRC.h:125
Crc::Add
void Add(PData sCrc)
Definition: CRC.h:94
Crc::NewCrc
void NewCrc()
Definition: CRC.h:98
Crst
Crst
Definition: CRC.h:35
CheckCalc::Add
virtual uint32_t Add(uint32_t crc, char *sCrc)=0
ZModemCrc32
@ ZModemCrc32
Definition: CRC.h:42
Reflect
uint32_t Reflect(uint32_t toref, char w)
Definition: CRC.cpp:9