summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <ikj1234i@yahoo.com>2017-12-22 18:24:05 -0500
committerMax <ikj1234i@yahoo.com>2017-12-22 18:24:05 -0500
commit5f264c68bf104f1814031b43a210351066902f8d (patch)
tree04b7c5ec9fa15d0e3bdac3e12c36510dd9515f20
parentb055a0b6d0f972fa5de952dcc8405d346d90a12d (diff)
bit utils
-rw-r--r--op25/gr-op25_repeater/lib/bit_utils.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/op25/gr-op25_repeater/lib/bit_utils.h b/op25/gr-op25_repeater/lib/bit_utils.h
new file mode 100644
index 0000000..e8c9daa
--- /dev/null
+++ b/op25/gr-op25_repeater/lib/bit_utils.h
@@ -0,0 +1,59 @@
+//
+// This file is part of OP25
+//
+// OP25 is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// OP25 is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+// License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with OP25; see the file COPYING. If not, write to the Free
+// Software Foundation, Inc., 51 Franklin Street, Boston, MA
+// 02110-1301, USA.
+
+#ifndef INCLUDED_OP25_REPEATER_BIT_UTILS_H
+#define INCLUDED_OP25_REPEATER_BIT_UTILS_H
+
+#include <stdint.h>
+
+static inline void store_i(int reg, uint8_t val[], int len) {
+ for (int i=0; i<len; i++){
+ val[i] = (reg >> (len-1-i)) & 1;
+ }
+}
+
+static inline int load_i(const uint8_t val[], int len) {
+ int acc = 0;
+ for (int i=0; i<len; i++){
+ acc = (acc << 1) + (val[i] & 1);
+ }
+ return acc;
+}
+
+static inline uint64_t load_reg64(const uint8_t val[], int len) {
+ uint64_t acc = 0;
+ for (int i=0; i<len; i++){
+ acc = (acc << 1) + (val[i] & 1);
+ }
+ return acc;
+}
+
+static inline void dibits_to_bits(uint8_t * bits, const uint8_t * dibits, const int n_dibits) {
+ for (int i=0; i<n_dibits; i++) {
+ bits[i*2] = (dibits[i] >> 1) & 1;
+ bits[i*2+1] = dibits[i] & 1;
+ }
+}
+
+static inline void bits_to_dibits(uint8_t* dest, const uint8_t* src, int n_dibits) {
+ for (int i=0; i<n_dibits; i++) {
+ dest[i] = src[i*2] * 2 + src[i*2+1];
+ }
+}
+
+#endif /* INCLUDED_OP25_REPEATER_BIT_UTILS_H */