#include <stddef.h>
#include <stdint.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/util.h>
 
Go to the source code of this file.
 | 
| int  | sys_bitarray_set_bit (sys_bitarray_t *bitarray, size_t bit) | 
|   | 
| int  | sys_bitarray_clear_bit (sys_bitarray_t *bitarray, size_t bit) | 
|   | 
| int  | sys_bitarray_test_bit (sys_bitarray_t *bitarray, size_t bit, int *val) | 
|   | 
| int  | sys_bitarray_test_and_set_bit (sys_bitarray_t *bitarray, size_t bit, int *prev_val) | 
|   | 
| int  | sys_bitarray_test_and_clear_bit (sys_bitarray_t *bitarray, size_t bit, int *prev_val) | 
|   | 
| int  | sys_bitarray_alloc (sys_bitarray_t *bitarray, size_t num_bits, size_t *offset) | 
|   | 
| int  | sys_bitarray_free (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) | 
|   | 
| bool  | sys_bitarray_is_region_set (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) | 
|   | 
| bool  | sys_bitarray_is_region_cleared (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) | 
|   | 
| int  | sys_bitarray_set_region (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) | 
|   | 
| int  | sys_bitarray_test_and_set_region (sys_bitarray_t *bitarray, size_t num_bits, size_t offset, bool to_set) | 
|   | 
| int  | sys_bitarray_clear_region (sys_bitarray_t *bitarray, size_t num_bits, size_t offset) | 
|   | 
◆ SYS_BITARRAY_DEFINE
      
        
          | #define SYS_BITARRAY_DEFINE | 
          ( | 
            | 
          name,  | 
        
        
           | 
           | 
            | 
          total_bits  | 
        
        
           | 
          ) | 
           |    	_SYS_BITARRAY_DEFINE(name, total_bits,) | 
        
      
 
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) | 
        
      
 
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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.)  |