Loading...
Searching...
No Matches
math.h
1#pragma once
2
3#include <stdbool.h>
4#include <stdint.h>
5#include <stddef.h>
6
7#define bit_read(value, bit) (((value) >> (bit)) & 0x01)
8#define bit_set(value, bit) \
9 ({ \
10 __typeof__(value) _one = (1); \
11 (value) |= (_one << (bit)); \
12 })
13#define bit_clear(value, bit) \
14 ({ \
15 __typeof__(value) _one = (1); \
16 (value) &= ~(_one << (bit)); \
17 })
18#define bit_write(value, bit, bitvalue) (bitvalue ? bit_set(value, bit) : bit_clear(value, bit))
19#define DURATION_DIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y)))
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
32uint64_t subghz_protocol_blocks_reverse_key(uint64_t key, uint8_t bit_count);
33
41uint8_t subghz_protocol_blocks_get_parity(uint64_t key, uint8_t bit_count);
42
52uint8_t subghz_protocol_blocks_crc4(
53 uint8_t const message[],
54 size_t size,
55 uint8_t polynomial,
56 uint8_t init);
57
67uint8_t subghz_protocol_blocks_crc7(
68 uint8_t const message[],
69 size_t size,
70 uint8_t polynomial,
71 uint8_t init);
72
84uint8_t subghz_protocol_blocks_crc8(
85 uint8_t const message[],
86 size_t size,
87 uint8_t polynomial,
88 uint8_t init);
89
100uint8_t subghz_protocol_blocks_crc8le(
101 uint8_t const message[],
102 size_t size,
103 uint8_t polynomial,
104 uint8_t init);
105
116uint16_t subghz_protocol_blocks_crc16lsb(
117 uint8_t const message[],
118 size_t size,
119 uint16_t polynomial,
120 uint16_t init);
121
131uint16_t subghz_protocol_blocks_crc16(
132 uint8_t const message[],
133 size_t size,
134 uint16_t polynomial,
135 uint16_t init);
136
147uint8_t subghz_protocol_blocks_lfsr_digest8(
148 uint8_t const message[],
149 size_t size,
150 uint8_t gen,
151 uint8_t key);
152
163uint8_t subghz_protocol_blocks_lfsr_digest8_reflect(
164 uint8_t const message[],
165 size_t size,
166 uint8_t gen,
167 uint8_t key);
168
179uint16_t subghz_protocol_blocks_lfsr_digest16(
180 uint8_t const message[],
181 size_t size,
182 uint16_t gen,
183 uint16_t key);
184
192uint8_t subghz_protocol_blocks_add_bytes(uint8_t const message[], size_t size);
193
200uint8_t subghz_protocol_blocks_parity8(uint8_t byte);
201
209uint8_t subghz_protocol_blocks_parity_bytes(uint8_t const message[], size_t size);
210
218uint8_t subghz_protocol_blocks_xor_bytes(uint8_t const message[], size_t size);
219
220#ifdef __cplusplus
221}
222#endif