Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Arrays of bits in plain memory, without atomicity or locking. More...

Files

file  bitmap.h
 Header file for the bitmap API.

Macros

#define SYS_BITMAP_SIZE(num_bits)
 Number of bytes of a bitmap with num_bits bits.
#define SYS_BITMAP_DEFINE(name, num_bits)
 Define a bitmap.
#define SYS_BITMAP_FOR_EACH_SET_BIT(bitmap, num_bits, bit)
 Iterate over the set bits of a bitmap, in ascending order.

Functions

static bool sys_bitmap_test_bit (const uint8_t *bitmap, size_t bit)
 Test a bit.
static void sys_bitmap_set_bit (uint8_t *bitmap, size_t bit)
 Set a bit.
static void sys_bitmap_clear_bit (uint8_t *bitmap, size_t bit)
 Clear a bit.
static void sys_bitmap_set_bit_to (uint8_t *bitmap, size_t bit, bool val)
 Set a bit to a given value.
static bool sys_bitmap_test_and_set_bit (uint8_t *bitmap, size_t bit)
 Set a bit and return its old value.
static bool sys_bitmap_test_and_clear_bit (uint8_t *bitmap, size_t bit)
 Clear a bit and return its old value.
size_t sys_bitmap_find_next_set (const uint8_t *bitmap, size_t num_bits, size_t start)
 Find the next set bit.
size_t sys_bitmap_find_next_clear (const uint8_t *bitmap, size_t num_bits, size_t start)
 Find the next cleared bit.
size_t sys_bitmap_count_set (const uint8_t *bitmap, size_t num_bits)
 Count the set bits.

Detailed Description

Arrays of bits in plain memory, without atomicity or locking.

Since
4.6
Version
0.1.0

Bit n of a bitmap is bit n % 8 of byte n / 8, where bit 0 of a byte is its least significant bit. This is the layout of little-endian bit masks in protocol messages, so these functions also work on such byte arrays. They take no lock: the caller serializes access. The single-bit functions do not check bounds; the caller passes them only bit numbers below the size of the bitmap.

Macro Definition Documentation

◆ SYS_BITMAP_DEFINE

#define SYS_BITMAP_DEFINE ( name,
num_bits )

#include <zephyr/sys/bitmap.h>

Value:
uint8_t name[SYS_BITMAP_SIZE(num_bits)]
#define SYS_BITMAP_SIZE(num_bits)
Number of bytes of a bitmap with num_bits bits.
Definition bitmap.h:47
__UINT8_TYPE__ uint8_t
Definition stdint.h:88

Define a bitmap.

Defines an array of bytes that holds at least num_bits bits. At file scope the bits start cleared; inside a function they start uninitialized. A num_bits of 0 defines a zero-length array, a GNU C extension.

Parameters
nameName of the bitmap.
num_bitsNumber of bits.

◆ SYS_BITMAP_FOR_EACH_SET_BIT

#define SYS_BITMAP_FOR_EACH_SET_BIT ( bitmap,
num_bits,
bit )

#include <zephyr/sys/bitmap.h>

Value:
for ((bit) = sys_bitmap_find_next_set(bitmap, num_bits, 0); (bit) < (num_bits); \
(bit) = sys_bitmap_find_next_set(bitmap, num_bits, (bit) + 1U))
size_t sys_bitmap_find_next_set(const uint8_t *bitmap, size_t num_bits, size_t start)
Find the next set bit.

Iterate over the set bits of a bitmap, in ascending order.

Parameters
bitmapBitmap.
num_bitsNumber of bits in the bitmap.
bitVariable of type size_t that holds the number of the current bit.

◆ SYS_BITMAP_SIZE

#define SYS_BITMAP_SIZE ( num_bits)

#include <zephyr/sys/bitmap.h>

Value:
#define BITS_PER_BYTE
Number of bits in a byte.
Definition util.h:62
#define DIV_ROUND_UP(n, d)
Divide and round up.
Definition util.h:336

Number of bytes of a bitmap with num_bits bits.

Parameters
num_bitsNumber of bits.

Function Documentation

◆ sys_bitmap_clear_bit()

void sys_bitmap_clear_bit ( uint8_t * bitmap,
size_t bit )
inlinestatic

#include <zephyr/sys/bitmap.h>

Clear a bit.

Parameters
bitmapBitmap.
bitBit number, starting from 0.

◆ sys_bitmap_count_set()

size_t sys_bitmap_count_set ( const uint8_t * bitmap,
size_t num_bits )

#include <zephyr/sys/bitmap.h>

Count the set bits.

Parameters
bitmapBitmap.
num_bitsNumber of bits in the bitmap.
Returns
Number of set bits below num_bits.

◆ sys_bitmap_find_next_clear()

size_t sys_bitmap_find_next_clear ( const uint8_t * bitmap,
size_t num_bits,
size_t start )

#include <zephyr/sys/bitmap.h>

Find the next cleared bit.

Parameters
bitmapBitmap.
num_bitsNumber of bits in the bitmap.
startBit number to start the search from.
Returns
Number of the first cleared bit at or after start, or num_bits if there is none.

◆ sys_bitmap_find_next_set()

size_t sys_bitmap_find_next_set ( const uint8_t * bitmap,
size_t num_bits,
size_t start )

#include <zephyr/sys/bitmap.h>

Find the next set bit.

Parameters
bitmapBitmap.
num_bitsNumber of bits in the bitmap.
startBit number to start the search from.
Returns
Number of the first set bit at or after start, or num_bits if there is none.

◆ sys_bitmap_set_bit()

void sys_bitmap_set_bit ( uint8_t * bitmap,
size_t bit )
inlinestatic

#include <zephyr/sys/bitmap.h>

Set a bit.

Parameters
bitmapBitmap.
bitBit number, starting from 0.

◆ sys_bitmap_set_bit_to()

void sys_bitmap_set_bit_to ( uint8_t * bitmap,
size_t bit,
bool val )
inlinestatic

#include <zephyr/sys/bitmap.h>

Set a bit to a given value.

Parameters
bitmapBitmap.
bitBit number, starting from 0.
valtrue to set the bit, false to clear it.

◆ sys_bitmap_test_and_clear_bit()

bool sys_bitmap_test_and_clear_bit ( uint8_t * bitmap,
size_t bit )
inlinestatic

#include <zephyr/sys/bitmap.h>

Clear a bit and return its old value.

Parameters
bitmapBitmap.
bitBit number, starting from 0.
Return values
trueThe bit was set.
falseThe bit was already cleared.

◆ sys_bitmap_test_and_set_bit()

bool sys_bitmap_test_and_set_bit ( uint8_t * bitmap,
size_t bit )
inlinestatic

#include <zephyr/sys/bitmap.h>

Set a bit and return its old value.

Parameters
bitmapBitmap.
bitBit number, starting from 0.
Return values
trueThe bit was already set.
falseThe bit was cleared.

◆ sys_bitmap_test_bit()

bool sys_bitmap_test_bit ( const uint8_t * bitmap,
size_t bit )
inlinestatic

#include <zephyr/sys/bitmap.h>

Test a bit.

Parameters
bitmapBitmap.
bitBit number, starting from 0.
Return values
trueThe bit is set.
falseThe bit is cleared.