Solaris Software
Loading...
Searching...
No Matches
crc.c
Go to the documentation of this file.
1/**
2 * @file crc.c
3 * @brief CRC-16/CCITT implementation.
4 */
5
6#include "spp/util/crc.h"
7
9{
11
12 for (spp_uint32_t i = 0U; i < length; i++)
13 {
14 crc ^= (spp_uint16_t)((spp_uint16_t)p_data[i] << 8U);
15 for (spp_uint8_t bit = 0U; bit < 8U; bit++)
16 {
17 if ((crc & 0x8000U) != 0U)
18 {
19 crc = (spp_uint16_t)((crc << 1U) ^ K_SPP_CRC_POLY);
20 }
21 else
22 {
23 crc = (spp_uint16_t)(crc << 1U);
24 }
25 }
26 }
27 return crc;
28}
spp_uint16_t SPP_UTIL_crc16(const spp_uint8_t *p_data, spp_uint32_t length)
Compute a CRC-16/CCITT checksum over a byte buffer.
Definition crc.c:8
CRC-16/CCITT checksum utility.
#define K_SPP_CRC_POLY
CRC-16/CCITT polynomial (0x1021).
Definition crc.h:20
#define K_SPP_CRC_INIT
CRC-16 initial value.
Definition crc.h:23
uint16_t spp_uint16_t
Definition types.h:29
uint32_t spp_uint32_t
Definition types.h:31
uint8_t spp_uint8_t
Definition types.h:27