Skip to content

Instantly share code, notes, and snippets.

@gauravjuvekar
Forked from andresv/ax25_crc16.c
Last active August 29, 2015 14:21
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 gauravjuvekar/dd0ad0006c3da206a0ed to your computer and use it in GitHub Desktop.
Save gauravjuvekar/dd0ad0006c3da206a0ed to your computer and use it in GitHub Desktop.
uint16_t ax25crc16(unsigned char *data_p, uint16_t lenght) {
uint16_t crc = 0xFFFF;
uint32_t data;
uint16_t crc16_table[] = {
0x0000, 0x1081, 0x2102, 0x3183,
0x4204, 0x5285, 0x6306, 0x7387,
0x8408, 0x9489, 0xa50a, 0xb58b,
0xc60c, 0xd68d, 0xe70e, 0xf78f
};
while(lenght--){
crc = ( crc >> 4 ) ^ crc16_table[(crc & 0xf) ^ (*data_p & 0xf)];
crc = ( crc >> 4 ) ^ crc16_table[(crc & 0xf) ^ (*data_p++ >> 4)];
}
data = crc;
crc = (crc << 8) | (data >> 8 & 0xff); // do byte swap here that is needed by AX25 standard
return (~crc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment