more code
This commit is contained in:
24
code/Core/Src/crc.c
Normal file
24
code/Core/Src/crc.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* crc.c
|
||||
*
|
||||
* Created on: 19 Dec 2025
|
||||
* Author: janik
|
||||
*/
|
||||
|
||||
#include "crc.h"
|
||||
|
||||
void CRC8_107_add(CRC8_107 *ctx, uint8_t data)
|
||||
{
|
||||
ctx->crc ^= ((uint32_t)data << 8);
|
||||
for (size_t bit_n = 0; bit_n < 8; bit_n++) {
|
||||
if (ctx->crc & 0x8000u) {
|
||||
ctx->crc ^= ((uint32_t)0x1070u << 3); // same as 0x8380
|
||||
}
|
||||
ctx->crc <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t CRC8_107_getChecksum(const CRC8_107 *ctx)
|
||||
{
|
||||
return (uint8_t)(ctx->crc >> 8);
|
||||
}
|
||||
Reference in New Issue
Block a user