Loading...
Searching...
No Matches
bit_lib.h
1#pragma once
2#include <stdint.h>
3#include <stdlib.h>
4#include <stdbool.h>
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#define TOPBIT(X) (1 << ((X) - 1))
11
12typedef enum {
13 BitLibParityEven,
14 BitLibParityOdd,
15 BitLibParityAlways0,
16 BitLibParityAlways1,
17} BitLibParity;
18
23#define bit_lib_increment_index(index, length) (index = (((index) + 1) % (length)))
24
29#define bit_lib_bit_is_set(data, index) (((data) & (1 << (index))) != 0)
30
35#define bit_lib_bit_is_not_set(data, index) (((data) & (1 << (index))) == 0)
36
42void bit_lib_push_bit(uint8_t* data, size_t data_size, bool bit);
43
49void bit_lib_set_bit(uint8_t* data, size_t position, bool bit);
50
57void bit_lib_set_bits(uint8_t* data, size_t position, uint8_t byte, uint8_t length);
58
64bool bit_lib_get_bit(const uint8_t* data, size_t position);
65
73uint8_t bit_lib_get_bits(const uint8_t* data, size_t position, uint8_t length);
74
82uint16_t bit_lib_get_bits_16(const uint8_t* data, size_t position, uint8_t length);
83
91uint32_t bit_lib_get_bits_32(const uint8_t* data, size_t position, uint8_t length);
92
100uint64_t bit_lib_get_bits_64(const uint8_t* data, size_t position, uint8_t length);
101
108bool bit_lib_test_parity_32(uint32_t bits, BitLibParity parity);
109
121bool bit_lib_test_parity(
122 const uint8_t* data,
123 size_t position,
124 uint8_t length,
125 BitLibParity parity,
126 uint8_t parity_length);
127
140size_t bit_lib_add_parity(
141 const uint8_t* data,
142 size_t position,
143 uint8_t* dest,
144 size_t dest_position,
145 uint8_t source_length,
146 uint8_t parity_length,
147 BitLibParity parity);
148
158size_t bit_lib_remove_bit_every_nth(uint8_t* data, size_t position, uint8_t length, uint8_t n);
159
169void bit_lib_copy_bits(
170 uint8_t* data,
171 size_t position,
172 size_t length,
173 const uint8_t* source,
174 size_t source_position);
175
183void bit_lib_reverse_bits(uint8_t* data, size_t position, uint8_t length);
184
191uint8_t bit_lib_get_bit_count(uint32_t data);
192
199void bit_lib_print_bits(const uint8_t* data, size_t length);
200
201typedef struct {
202 const char mark;
203 const size_t start;
204 const size_t length;
206
215void bit_lib_print_regions(
216 const BitLibRegion* regions,
217 size_t region_count,
218 const uint8_t* data,
219 size_t length);
220
227uint16_t bit_lib_reverse_16_fast(uint16_t data);
228
235uint8_t bit_lib_reverse_8_fast(uint8_t byte);
236
249uint16_t bit_lib_crc8(
250 uint8_t const* data,
251 size_t data_size,
252 uint8_t polynom,
253 uint8_t init,
254 bool ref_in,
255 bool ref_out,
256 uint8_t xor_out);
257
270uint16_t bit_lib_crc16(
271 uint8_t const* data,
272 size_t data_size,
273 uint16_t polynom,
274 uint16_t init,
275 bool ref_in,
276 bool ref_out,
277 uint16_t xor_out);
278
287void bit_lib_num_to_bytes_be(uint64_t src, uint8_t len, uint8_t* dest);
288
297void bit_lib_num_to_bytes_le(uint64_t src, uint8_t len, uint8_t* dest);
298
306uint64_t bit_lib_bytes_to_num_be(const uint8_t* src, uint8_t len);
307
315uint64_t bit_lib_bytes_to_num_le(const uint8_t* src, uint8_t len);
316
325uint64_t bit_lib_bytes_to_num_bcd(const uint8_t* src, uint8_t len, bool* is_bcd);
326
327#ifdef __cplusplus
328}
329#endif
Definition bit_lib.h:201