Kestrel Interface
Loading...
Searching...
No Matches
kest_hfunc.h
Go to the documentation of this file.
1#ifndef KEST_INT_HELPER_FUNCTIONS_H_
2#define KEST_INT_HELPER_FUNCTIONS_H_
3
4/* Helper functions! Yay! */
5
6#define binary_max(x, y) ((x > y) ? x : y)
7#define binary_min(x, y) ((x > y) ? y : x)
8
9#define sqr(x) (x * x)
10
11// For some reason, printf on esp32 does not support %b
12char *binary_print_n (uint32_t x, int n);
13
14char *binary_print_8 (uint8_t x);
15char *binary_print_16(uint16_t x);
16char *binary_print_24(uint32_t x);
17char *binary_print_32(uint32_t x);
18
19// IBM = "initial bit mask"; 0b000..0111...1 with "x" 1s
20#define IBM(x) ((1u << (x)) - 1)
21// Extracts n bits, starting at x, and shifted to the start
22#define range_bits(x, n, start) (((x) >> (start)) & IBM(n))
23// Gives a word with bits y to x being the initial bits of "val"
24#define place_bits(x, y, val) ((IBM((x)-(y)+1) & ((uint32_t)val)) << y)
25
26inline static uint32_t hash(const char *str)
27{
28 if (!str) return 0;
29
30 uint32_t x = 5381;
31 int c;
32
33 while ((c = *str++))
34 x = ((x << 5) + x) + c;
35
36 return x;
37}
38
39int format_float(char *buf, float val, int max_len);
40
41#endif
char * binary_print_16(uint16_t x)
Definition kest_hfunc.c:30
char * binary_print_8(uint8_t x)
Definition kest_hfunc.c:25
int format_float(char *buf, float val, int max_len)
Definition kest_hfunc.c:47
char * binary_print_32(uint32_t x)
Definition kest_hfunc.c:42
char * binary_print_24(uint32_t x)
Definition kest_hfunc.c:37
char * binary_print_n(uint32_t x, int n)
Definition kest_hfunc.c:8