Skip to content

Instantly share code, notes, and snippets.

@profi200
Created February 29, 2024 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save profi200/6379364d07824c0374618163e1b839b4 to your computer and use it in GitHub Desktop.
Save profi200/6379364d07824c0374618163e1b839b4 to your computer and use it in GitHub Desktop.
static u8 crc7(const u8 *data, u32 len)
{
u32 crc = 0; // u32 to avoid "and rX, rX, #0xFF" in the bit loop.
while(len--)
{
crc ^= *data++;
for(u32 i = 0; i < 8; i++)
{
if(crc & 0x80u) crc ^= 0x89u;
crc <<= 1;
}
}
return crc | 1u;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment