11th feb i2c checking chaitu's code
Dependencies: SimpleDMA eeprom mbed-rtos mbed
Fork of CDMS_CODE_FM_28JAN2017 by
Diff: crc.h
- Revision:
- 145:fb800fecf128
- Parent:
- 6:79d422d1ed42
--- a/crc.h Thu Mar 10 15:26:50 2016 +0000 +++ b/crc.h Sat Apr 02 11:54:50 2016 +0000 @@ -74,4 +74,39 @@ } return remainder; -} \ No newline at end of file +} + +uint16_t crc16_gen1( char message[], unsigned int nBytes){ + crctype16 remainder = 0xffff; + int byte; + char bit; + + for( byte = 0 ; byte < nBytes ; byte++ ){ + /* + Bring the data byte by byte + each time only one byte is brought + 0 xor x = x + */ + remainder = remainder ^ ( message[byte] << 8 ); + + for( bit = 8 ; bit > 0 ; bit--){ + /* + for each bit, xor the remainder with polynomial + if the MSB is 1 + */ + if(remainder & TOPBIT16){ + remainder = (remainder << 1) ^ POLYNOMIAL16; + /* + each time the remainder is xor-ed with polynomial, the MSB is made zero + hence the first digit of the remainder is ignored in the loop + */ + } + else{ + remainder = (remainder << 1); + } + } + } + + return remainder; +} +