00001 //====================================================================== 00029 //====================================================================== 00030 00031 #ifndef CRC_h_ 00032 #define CRC_h_ 00033 00034 #include "sdhlibrary_settings.h" 00035 00036 //---------------------------------------------------------------------- 00037 // System Includes - include with <> 00038 //---------------------------------------------------------------------- 00039 00040 00041 //---------------------------------------------------------------------- 00042 // Project Includes - include with "" 00043 //---------------------------------------------------------------------- 00044 00045 #include "basisdef.h" 00046 00047 //---------------------------------------------------------------------- 00048 // Defines, enums, unions, structs 00049 //---------------------------------------------------------------------- 00050 00051 NAMESPACE_SDH_START 00052 00053 00054 typedef UInt16 tCRCValue; 00055 00056 //---------------------------------------------------------------------- 00057 // Global variables (declarations) 00058 //---------------------------------------------------------------------- 00059 00060 00061 //---------------------------------------------------------------------- 00062 // External functions (function declarations) 00063 //---------------------------------------------------------------------- 00064 00065 00066 //---------------------------------------------------------------------- 00067 // Function prototypes (function declarations) 00068 //---------------------------------------------------------------------- 00069 00070 00071 //---------------------------------------------------------------------- 00072 // Class declarations 00073 //---------------------------------------------------------------------- 00074 00080 class cCRC 00081 { 00082 protected: 00084 tCRCValue current_crc; 00085 00087 tCRCValue initial_value; 00088 00090 tCRCValue const* crc_table; 00091 00092 public: 00094 cCRC( tCRCValue const* _crc_table, tCRCValue _initial_value ) 00095 { 00096 crc_table = _crc_table; 00097 initial_value = _initial_value; 00098 current_crc = initial_value; 00099 } 00100 00102 tCRCValue AddByte( unsigned char byte ) 00103 { 00104 current_crc = ( (current_crc & 0xFF00) >> 8 ) ^ crc_table[ ( current_crc & 0x00FF ) ^ (byte & 0x00FF)]; 00105 return current_crc; 00106 } 00107 00109 inline tCRCValue GetCRC() 00110 { 00111 return current_crc; 00112 } 00113 00115 inline UInt8 GetCRC_LB() 00116 { 00117 return current_crc & 0x00ff; 00118 } 00119 00121 inline UInt8 GetCRC_HB() 00122 { 00123 return (current_crc >> 8) & 0x00ff; 00124 } 00125 00127 inline tCRCValue Reset() 00128 { 00129 current_crc = initial_value; 00130 return current_crc; 00131 } 00132 }; 00133 //---------------------------------------------------------------------- 00134 //---------------------------------------------------------------------- 00135 00137 class cCRC_DSACON32m : public cCRC 00138 { 00139 protected: 00141 static tCRCValue const crc_table_dsacon32m[256]; 00142 00143 public: 00145 inline cCRC_DSACON32m( void ) 00146 : cCRC( crc_table_dsacon32m, 0xffff ) 00147 { 00148 // nothing more to do 00149 } 00150 }; 00151 //---------------------------------------------------------------------- 00152 //---------------------------------------------------------------------- 00153 00154 NAMESPACE_SDH_END 00155 00156 #endif 00157 00158 00159 //====================================================================== 00160 /* 00161 Here are some settings for the emacs/xemacs editor (and can be safely ignored): 00162 (e.g. to explicitely set C++ mode for *.h header files) 00163 00164 Local Variables: 00165 mode:C 00166 mode:ELSE 00167 End: 00168 */ 00169 //======================================================================}