Store and manipulate bits in a bit array.
More...
|
#define | SYS_BITARRAY_DEFINE(name, total_bits) _SYS_BITARRAY_DEFINE(name, total_bits,) |
| Create a bitarray object.
|
|
#define | SYS_BITARRAY_DEFINE_STATIC(name, total_bits) _SYS_BITARRAY_DEFINE(name, total_bits, static) |
| Create a static bitarray object.
|
|
|
int | sys_bitarray_set_bit (sys_bitarray_t *bitarray, size_t bit) |
| Set a bit in a bit array.
|
|
int | sys_bitarray_clear_bit (sys_bitarray_t *bitarray, size_t bit) |
| Clear a bit in a bit array.
|
|
int | sys_bitarray_test_bit (sys_bitarray_t *bitarray, size_t bit, int *val) |
| Test whether a bit is set or not.
|
|
int | sys_bitarray_test_and_set_bit (sys_bitarray_t *bitarray, size_t bit, int *prev_val) |
| Test the bit and set it.
|
|
int | sys_bitarray_test_and_clear_bit (sys_bitarray_t *bitarray, size_t bit, int *prev_val) |
| Test the bit and clear it.
|
|
int | sys_bitarray_alloc (sys_bitarray_t *bitarray, size_t num_bits, size_t *offset) |
| Allocate bits in a bit array.
|
|
int | sys_bitarray_free (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) |
| Free bits in a bit array.
|
|
bool | sys_bitarray_is_region_set (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) |
| Test if bits in a region is all set.
|
|
bool | sys_bitarray_is_region_cleared (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) |
| Test if bits in a region is all cleared.
|
|
int | sys_bitarray_set_region (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) |
| Set all bits in a region.
|
|
int | sys_bitarray_test_and_set_region (sys_bitarray_t *bitarray, size_t num_bits, size_t offset, bool to_set) |
| Test if all bits in a region are cleared/set and set/clear them in a single atomic operation.
|
|
int | sys_bitarray_clear_region (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) |
| Clear all bits in a region.
|
|
Store and manipulate bits in a bit array.
◆ SYS_BITARRAY_DEFINE
#define SYS_BITARRAY_DEFINE |
( |
|
name, |
|
|
|
total_bits |
|
) |
| _SYS_BITARRAY_DEFINE(name, total_bits,) |
#include <include/zephyr/sys/bitarray.h>
Create a bitarray object.
- Parameters
-
name | Name of the bitarray object. |
total_bits | Total number of bits in this bitarray object. |
◆ SYS_BITARRAY_DEFINE_STATIC
#define SYS_BITARRAY_DEFINE_STATIC |
( |
|
name, |
|
|
|
total_bits |
|
) |
| _SYS_BITARRAY_DEFINE(name, total_bits, static) |
#include <include/zephyr/sys/bitarray.h>
Create a static bitarray object.
- Parameters
-
name | Name of the bitarray object. |
total_bits | Total number of bits in this bitarray object. |
◆ sys_bitarray_t
◆ sys_bitarray_alloc()
#include <include/zephyr/sys/bitarray.h>
Allocate bits in a bit array.
This finds a number of bits (num_bits
) in a contiguous of previously unallocated region. If such a region exists, the bits are marked as allocated and the offset to the start of this region is returned via offset
.
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | num_bits | Number of bits to allocate |
[out] | offset | Offset to the start of allocated region if successful |
- Return values
-
0 | Allocation successful |
-EINVAL | Invalid argument (e.g. allocating more bits than the bitarray has, trying to allocate 0 bits, etc.) |
-ENOSPC | No contiguous region big enough to accommodate the allocation |
◆ sys_bitarray_clear_bit()
#include <include/zephyr/sys/bitarray.h>
Clear a bit in a bit array.
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | bit | The bit to be cleared |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to clear exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_clear_region()
#include <include/zephyr/sys/bitarray.h>
Clear all bits in a region.
This clears the number of bits (num_bits
) in region starting from offset
.
- Parameters
-
bitarray | Bitarray struct |
num_bits | Number of bits to test |
offset | Starting bit position to test |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to set exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_free()
#include <include/zephyr/sys/bitarray.h>
Free bits in a bit array.
This marks the number of bits (num_bits
) starting from offset
as no longer allocated.
- Parameters
-
bitarray | Bitarray struct |
num_bits | Number of bits to free |
offset | Starting bit position to free |
- Return values
-
0 | Free is successful |
-EINVAL | Invalid argument (e.g. try to free more bits than the bitarray has, trying to free 0 bits, etc.) |
-EFAULT | The bits in the indicated region are not all allocated. |
◆ sys_bitarray_is_region_cleared()
#include <include/zephyr/sys/bitarray.h>
Test if bits in a region is all cleared.
This tests if the number of bits (num_bits
) in region starting from offset
are all cleared.
- Parameters
-
bitarray | Bitarray struct |
num_bits | Number of bits to test |
offset | Starting bit position to test |
- Return values
-
true | All bits are cleared. |
false | Not all bits are cleared. |
◆ sys_bitarray_is_region_set()
#include <include/zephyr/sys/bitarray.h>
Test if bits in a region is all set.
This tests if the number of bits (num_bits
) in region starting from offset
are all set.
- Parameters
-
bitarray | Bitarray struct |
num_bits | Number of bits to test |
offset | Starting bit position to test |
- Return values
-
true | All bits are set. |
false | Not all bits are set. |
◆ sys_bitarray_set_bit()
#include <include/zephyr/sys/bitarray.h>
Set a bit in a bit array.
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | bit | The bit to be set |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to set exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_set_region()
#include <include/zephyr/sys/bitarray.h>
Set all bits in a region.
This sets the number of bits (num_bits
) in region starting from offset
.
- Parameters
-
bitarray | Bitarray struct |
num_bits | Number of bits to test |
offset | Starting bit position to test |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to set exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_test_and_clear_bit()
#include <include/zephyr/sys/bitarray.h>
Test the bit and clear it.
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | bit | The bit to be tested and cleared |
[out] | prev_val | Previous value of the bit (0 or 1) |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to test exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_test_and_set_bit()
#include <include/zephyr/sys/bitarray.h>
Test the bit and set it.
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | bit | The bit to be tested and set |
[out] | prev_val | Previous value of the bit (0 or 1) |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to test exceeds the number of bits in bit array, etc.) |
◆ sys_bitarray_test_and_set_region()
#include <include/zephyr/sys/bitarray.h>
Test if all bits in a region are cleared/set and set/clear them in a single atomic operation.
This checks if all the bits (num_bits
) in region starting from offset
are in required state. If even one bit is not, -EEXIST is returned. If the whole region is set/cleared it is set to opposite state. The check and set is performed as a single atomic operation.
- Parameters
-
bitarray | Bitarray struct |
num_bits | Number of bits to test and set |
offset | Starting bit position to test and set |
to_set | if true the region will be set if all bits are cleared if false the region will be cleard if all bits are set |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to set exceeds the number of bits in bit array, etc.) |
-EEXIST | at least one bit in the region is set/cleared, operation cancelled |
◆ sys_bitarray_test_bit()
#include <include/zephyr/sys/bitarray.h>
Test whether a bit is set or not.
- Parameters
-
[in] | bitarray | Bitarray struct |
[in] | bit | The bit to be tested |
[out] | val | The value of the bit (0 or 1) |
- Return values
-
0 | Operation successful |
-EINVAL | Invalid argument (e.g. bit to test exceeds the number of bits in bit array, etc.) |