CHG: had to move the SwapBits method.
This commit is contained in:
12
common/crc.c
12
common/crc.c
@@ -7,7 +7,6 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "crc.h"
|
||||
#include "util.h"
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -44,8 +43,7 @@ uint32_t crc_finish(crc_t *crc)
|
||||
}
|
||||
|
||||
//credits to iceman
|
||||
uint32_t CRC8Maxim(uint8_t *buff, size_t size)
|
||||
{
|
||||
uint32_t CRC8Maxim(uint8_t *buff, size_t size) {
|
||||
crc_t crc;
|
||||
crc_init(&crc, 9, 0x8c, 0x00, 0x00);
|
||||
crc_clear(&crc);
|
||||
@@ -68,10 +66,4 @@ uint32_t CRC8Legic(uint8_t *buff, size_t size) {
|
||||
return SwapBits(crc_finish(&crc), 8);
|
||||
}
|
||||
|
||||
uint32_t SwapBits(uint32_t value, int nrbits) {
|
||||
uint32_t newvalue = 0;
|
||||
for(int i = 0; i < nrbits; i++) {
|
||||
newvalue ^= ((value >> i) & 1) << (nrbits - 1 - i);
|
||||
}
|
||||
return newvalue;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ uint32_t CRC8Maxim(uint8_t *buff, size_t size);
|
||||
|
||||
// Calculate CRC-8/Legic checksum
|
||||
uint32_t CRC8Legic(uint8_t *buff, size_t size);
|
||||
uint32_t SwapBits(uint32_t value, int nrbits);
|
||||
|
||||
/* Static initialization of a crc structure */
|
||||
#define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \
|
||||
|
||||
Reference in New Issue
Block a user