+/*
+ * Ugly!.. reformat it.
+ */
+/**
+ * Test if a range of bit is full.
+ *
+ * \param bitx BitArray context
+ * \param idx Starting bit
+ * \param offset Number of bits to test
+ * \return True if range is full, false otherwise
+ */
+INLINE bool bitarray_isRangeFull(BitArray *bitx, int idx, int offset)
+{
+ ASSERT((size_t)(idx + offset) <= bitx->bitarray_len);
+
+ for (int i = idx; i <= idx + offset; i++)
+ if (!bitarray_test(bitx, i))
+ return 0;
+
+ return 1;
+}
+
+/*
+ * Ugly!.. reformat it.
+ */
+/**
+ * Test if a range of bit is empty.
+ *
+ * \param bitx BitArray context
+ * \param idx Starting bit
+ * \param offset Number of bits to test
+ * \return True if range is empty, false otherwise
+ */
+INLINE bool bitarray_isRangeEmpty(BitArray *bitx, int idx, int offset)
+{
+ ASSERT((size_t)(idx + offset) <= bitx->bitarray_len);
+
+ for (int i = idx; i <= idx + offset; i++)
+ if (bitarray_test(bitx, i))
+ return 0;
+
+ return 1;
+}
+
+/**
+ * Print on debug serial a BitArray.
+ * \note This module does not use the logging module, so you
+ * can't decide the logging level.
+ * \param bitx BitArray to be printed.
+ */
+INLINE void bitarray_dump(BitArray *bitx)
+{
+ kprintf("bitarray size[%zu]bits on [%zu]bytes\n", bitx->bitarray_len, bitx->size);
+
+ int i = 0;
+ int j = 0;
+ int count = bitx->bitarray_len;
+
+ while (count--)
+ {
+ kprintf("%d", bitarray_test(bitx, i++));
+ if (j == 7)
+ {
+ kprintf("..%02x [%d]\n", bitx->array[(i / 8) - 1], i);
+ j = 0;
+ continue;
+ }
+ j++;
+ }
+
+ if (j != 0)
+ kprintf("..%02x [%d]\n", bitx->array[i / 8], i);
+}
+
+int bitarray_firstSetBit(BitArray *bitx);
+
+/**
+ * Init a BitArray.
+ *
+ * The BitArray uses an external array for storage. You can use the macro
+ * BITARRAY_ALLOC to declare an appropriate memory size. Example usage:
+ * \code
+ * BITARRAY_ALLOC(bits_mem, 17);
+ * BitArray bits;
+ * bitarray_init(&bits, 17, bits_mem, sizeof(bits_mem))
+ * \endcode
+ *
+ * \param bitx BitArray context
+ * \param bitarray_len Number of bits in the BitArray
+ * \param array Memory area for the BitArray
+ * \param size Size (in bytes) of the memory area \a array
+ */
+INLINE void bitarray_init(BitArray *bitx, size_t bitarray_len, uint8_t *array, size_t size)
+{
+ bitx->size = size;
+ bitx->array = array;
+ bitx->bitarray_len = bitarray_len;
+}
+
+
+int bitarray_testSetup(void);
+int bitarray_testRun(void);
+int bitarray_testTearDown(void);
+