implement CRC-7 as used in SD-Card command packets More...
#include <stdint.h>Go to the source code of this file.
Functions | |
| uint8_t | _crc7_update (uint8_t crc, uint8_t data) |
| CRC-7 calculation as used in SD-Card command packets. | |
implement CRC-7 as used in SD-Card command packets
| uint8_t _crc7_update | ( | uint8_t | crc, | |
| uint8_t | data | |||
| ) | [inline] |
CRC-7 calculation as used in SD-Card command packets.
| crc | calculated CRC from bytes read so far (or 0 for first byte) | |
| data | byte to put into CRC |
returning CRC in upper bits:
{
#if 0
/* bit-wise algorithm */
int i;
for (i = 8; i > 0; i--) {
uint8_t b = (data >> 7) ^ ((crc & 0x80) >> 7);
crc = (crc ^ b ^ (b << 3)) << 1;
crc &= 0xfe;
data <<= 1;
}
return crc;
#else
/* no need to do &= 0xfe, as that bit will not be used anyway */
/*crc &= 0x7f;*/
data ^= crc;
crc = data >> 4;
data ^= crc ^ (crc >> 3);
return /*0xfe & */((uint8_t)(data<<1) ^ (uint8_t)(data << 4));
#endif
}
1.7.1