31,7 → 31,7 |
*/ |
|
/** @file |
* General CRC computation implementation. |
* General CRC and checksum computation implementation. |
*/ |
|
#include <sys/types.h> |
100,5 → 100,28 |
return seed; |
} |
|
uint32_t compute_checksum( uint32_t seed, uint8_t * data, int length ){ |
int index; |
|
// sum all the 16 bit fields |
for( index = 0; index < length - 1; index += 2 ){ |
seed += ( data[ index ] << 8 ) + data[ index + 1 ]; |
} |
|
// last odd byte with zero padding |
if( index == length - 1 ){ |
seed += data[ index ] << 8; |
} |
|
return seed; |
} |
|
uint16_t compact_checksum( uint32_t sum ){ |
// shorten to the 16 bits |
while( sum >> 16 ) sum = ( sum & 0xFFFF ) + ( sum >> 16 ); |
|
return ( uint16_t ) sum; |
} |
|
/** @} |
*/ |