mirror of
https://github.com/openhwgroup/cvw
synced 2025-01-23 21:14:37 +00:00
Corrected the CRC7 code with the right sequence of instructions.
This commit is contained in:
parent
c7d869bc96
commit
e91d2c8b14
@ -1,12 +1,15 @@
|
||||
#include "sd.h"
|
||||
#include "spi.h"
|
||||
|
||||
// Parallel byte update CRC7-CCITT algorithm.
|
||||
// The result is the CRC7 result, left shifted over by 1
|
||||
// which is perfect, since we append a 1 at the end anyway
|
||||
uint8_t crc7(uint8_t prev, uint8_t in) {
|
||||
// CRC polynomial 0x89
|
||||
uint8_t remainder = prev & in;
|
||||
uint8_t remainder = prev ^ in;
|
||||
remainder ^= (remainder >> 4) ^ (remainder >> 7);
|
||||
remainder ^= remainder << 4;
|
||||
return remainder & 0x7f;
|
||||
remainder = (remainder << 1) ^ (remainder << 4);
|
||||
return remainder & 0xff;
|
||||
}
|
||||
|
||||
uint16_t crc16(uint16_t crc, uint8_t data) {
|
||||
|
Loading…
Reference in New Issue
Block a user