reflow-oven-control-sw/error-mem-viewer/src/crc.c

26 lines
410 B
C
Raw Normal View History

2020-11-29 17:18:28 +01:00
#include <error-mem-viewer/crc.h>
2021-08-24 21:50:57 +02:00
static uint32_t do_crc(uint32_t init, uint32_t data)
2020-11-29 17:18:28 +01:00
{
uint32_t crc = init;
uint32_t cnt;
2021-08-24 21:50:57 +02:00
for (cnt=0; cnt < 32; cnt++) {
2020-11-29 17:18:28 +01:00
crc = ((int32_t)(crc ^ data))<0 ? (crc << 1) ^ 0x04C11DB7 : crc << 1;
data <<=1;
}
return crc;
}
uint32_t calculate_stm_crc(uint32_t *data, size_t len)
{
uint32_t crc = ~0U;
2021-08-24 21:50:57 +02:00
while (len--) {
2020-11-29 17:18:28 +01:00
crc = do_crc(crc, *data++);
}
return crc;
}