2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
24 * These functions expect array to be 4-byte aligned since they alias array
25 * to an uint32_t pointer in order to work fast. Use the BITARRAY_DECLARE()
26 * macro to declare a bit array that can be safely used by them.
29 typedef uint32_t bitarrayElement_t
;
31 #define BITARRAY_DECLARE(name, bits) bitarrayElement_t name[(bits + 31) / 32]
33 bool bitArrayGet(const bitarrayElement_t
*array
, unsigned bit
);
34 void bitArraySet(bitarrayElement_t
*array
, unsigned bit
);
35 void bitArrayClr(bitarrayElement_t
*array
, unsigned bit
);
37 void bitArraySetAll(bitarrayElement_t
*array
, size_t size
);
38 void bitArrayClrAll(bitarrayElement_t
*array
, size_t size
);
40 #define BITARRAY_SET_ALL(array) bitArraySetAll(array, sizeof(array))
41 #define BITARRAY_CLR_ALL(array) bitArrayClrAll(array, sizeof(array))
43 // Returns the first set bit with pos >= start_bit, or -1 if all bits
44 // are zero. Note that size must indicate the size of array in bytes.
45 // In most cases, you should use the BITARRAY_FIND_FIRST_SET() macro
46 // to call this function.
47 int bitArrayFindFirstSet(const bitarrayElement_t
*array
, unsigned start_bit
, size_t size
);
49 #define BITARRAY_FIND_FIRST_SET(array, start_bit) bitArrayFindFirstSet(array, start_bit, sizeof(array))