CRC POLYNOME = x8 + x5 + x4 + 1 = 1001 1000 = 0x8C
| 72 | |
| 73 | // CRC POLYNOME = x8 + x5 + x4 + 1 = 1001 1000 = 0x8C |
| 74 | uint8_t crc8(const uint8_t *array, uint16_t length, const uint8_t polynome, |
| 75 | const uint8_t startmask, const uint8_t endmask, |
| 76 | const bool reverseIn, const bool reverseOut) |
| 77 | { |
| 78 | uint8_t crc = startmask; |
| 79 | while (length--) |
| 80 | { |
| 81 | if ((length & 0xFF) == 0) yield(); // RTOS |
| 82 | uint8_t data = *array++; |
| 83 | if (reverseIn) data = reverse8(data); |
| 84 | crc ^= data; |
| 85 | for (uint8_t i = 8; i; i--) |
| 86 | { |
| 87 | if (crc & 0x80) |
| 88 | { |
| 89 | crc <<= 1; |
| 90 | crc ^= polynome; |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | crc <<= 1; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | crc ^= endmask; |
| 99 | if (reverseOut) crc = reverse8(crc); |
| 100 | return crc; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | // CRC POLYNOME = x12 + x3 + x2 + 1 = 0000 1000 0000 1101 = 0x80D |