ASCII Serial Com
Serial communication library between computers, microcontrollers, FPGAs, etc. Uses only ASCII. Not the most efficient protocol, but meant to be easy to read
Loading...
Searching...
No Matches
crc_16_dnp_bbb.c
Go to the documentation of this file.
1/**
2 * \file
3 * Functions and types for CRC checks.
4 *
5 * Generated on Mon Aug 24 06:27:49 2020
6 * by pycrc v0.9.2, https://pycrc.org
7 * using the configuration:
8 * - Width = 16
9 * - Poly = 0x3d65
10 * - XorIn = 0x0000
11 * - ReflectIn = True
12 * - XorOut = 0xffff
13 * - ReflectOut = True
14 * - Algorithm = bit-by-bit
15 */
16#include "crc_16_dnp_bbb.h" /* include the header file generated with pycrc */
17#include <stdbool.h>
18#include <stdint.h>
19#include <stdlib.h>
20
21static crc_16_dnp_bbb_t crc_16_dnp_bbb_reflect(crc_16_dnp_bbb_t data,
22 size_t data_len);
23
24crc_16_dnp_bbb_t crc_16_dnp_bbb_reflect(crc_16_dnp_bbb_t data,
25 size_t data_len) {
26 unsigned int i;
28
29 ret = data & 0x01;
30 for (i = 1; i < data_len; i++) {
31 data >>= 1;
32 ret = (ret << 1) | (data & 0x01);
33 }
34 return ret;
35}
36
38 size_t data_len) {
39 const unsigned char *d = (const unsigned char *)data;
40 unsigned int i;
41 bool bit;
42 unsigned char c;
43
44 while (data_len--) {
45 c = crc_16_dnp_bbb_reflect(*d++, 8);
46 for (i = 0; i < 8; i++) {
47 bit = crc & 0x8000;
48 crc = (crc << 1) | ((c >> (7 - i)) & 0x01);
49 if (bit) {
50 crc ^= 0x3d65;
51 }
52 }
53 crc &= 0xffff;
54 }
55 return crc & 0xffff;
56}
57
59 unsigned int i;
60 bool bit;
61
62 for (i = 0; i < 16; i++) {
63 bit = crc & 0x8000;
64 crc <<= 1;
65 if (bit) {
66 crc ^= 0x3d65;
67 }
68 }
69 crc = crc_16_dnp_bbb_reflect(crc, 16);
70 return (crc ^ 0xffff) & 0xffff;
71}
crc_16_dnp_bbb_t crc_16_dnp_bbb_update(crc_16_dnp_bbb_t crc, const void *data, size_t data_len)
crc_16_dnp_bbb_t crc_16_dnp_bbb_finalize(crc_16_dnp_bbb_t crc)
uint_fast16_t crc_16_dnp_bbb_t