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_bbf.h
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-fast
15 *
16 * This file defines the functions crc_16_dnp_bbf_init(),
17 * crc_16_dnp_bbf_update() and crc_16_dnp_bbf_finalize().
18 *
19 * The crc_16_dnp_bbf_init() function returns the inital \c crc value and must
20 * be called before the first call to crc_16_dnp_bbf_update(). Similarly, the
21 * crc_16_dnp_bbf_finalize() function must be called after the last call to
22 * crc_16_dnp_bbf_update(), before the \c crc is being used. is being used.
23 *
24 * The crc_16_dnp_bbf_update() function can be called any number of times
25 * (including zero times) in between the crc_16_dnp_bbf_init() and
26 * crc_16_dnp_bbf_finalize() calls.
27 *
28 * This pseudo-code shows an example usage of the API:
29 * \code{.c}
30 * crc_16_dnp_bbf_t crc;
31 * unsigned char data[MAX_DATA_LEN];
32 * size_t data_len;
33 *
34 * crc = crc_16_dnp_bbf_init();
35 * while ((data_len = read_data(data, MAX_DATA_LEN)) > 0) {
36 * crc = crc_16_dnp_bbf_update(crc, data, data_len);
37 * }
38 * crc = crc_16_dnp_bbf_finalize(crc);
39 * \endcode
40 */
41#ifndef CRC_16_DNP_BBF_H
42#define CRC_16_DNP_BBF_H
43
44#include <stdint.h>
45#include <stdlib.h>
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/**
52 * The definition of the used algorithm.
53 *
54 * This is not used anywhere in the generated code, but it may be used by the
55 * application code to call algorithm-specific code, if desired.
56 */
57#define CRC_ALGO_BIT_BY_BIT_FAST 1
58
59/**
60 * The type of the CRC values.
61 *
62 * This type must be big enough to contain at least 16 bits.
63 */
64typedef uint_fast16_t crc_16_dnp_bbf_t;
65
66/**
67 * Reflect all bits of a \a data word of \a data_len bytes.
68 *
69 * \param[in] data The data word to be reflected.
70 * \param[in] data_len The width of \a data expressed in number of bits.
71 * \return The reflected data.
72 */
74
75/**
76 * Calculate the initial crc value.
77 *
78 * \return The initial crc value.
79 */
80static inline crc_16_dnp_bbf_t crc_16_dnp_bbf_init(void) { return 0x0000; }
81
82/**
83 * Update the crc value with new data.
84 *
85 * \param[in] crc The current crc value.
86 * \param[in] data Pointer to a buffer of \a data_len bytes.
87 * \param[in] data_len Number of bytes in the \a data buffer.
88 * \return The updated crc value.
89 */
91 size_t data_len);
92
93/**
94 * Calculate the final crc value.
95 *
96 * \param[in] crc The current crc value.
97 * \return The final crc value.
98 */
100 return crc_16_dnp_bbf_reflect(crc, 16) ^ 0xffff;
101}
102
103#ifdef __cplusplus
104} /* closing brace for extern "C" */
105#endif
106
107#endif /* CRC_16_DNP_BBF_H */
crc_16_dnp_bbf_t crc_16_dnp_bbf_update(crc_16_dnp_bbf_t crc, const void *data, size_t data_len)
crc_16_dnp_bbf_t crc_16_dnp_bbf_reflect(crc_16_dnp_bbf_t data, size_t data_len)
uint_fast16_t crc_16_dnp_bbf_t
static crc_16_dnp_bbf_t crc_16_dnp_bbf_init(void)
static crc_16_dnp_bbf_t crc_16_dnp_bbf_finalize(crc_16_dnp_bbf_t crc)