Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
bitarray.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_SYS_BITARRAY_H_
8#define ZEPHYR_INCLUDE_SYS_BITARRAY_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#include <stddef.h>
15#include <stdint.h>
16
17#include <kernel.h>
18
20 /* Number of bits */
22
23 /* Number of bundles */
25
26 /* Bundle of bits */
28
29 /* Spinlock guarding access to this bit array */
31};
32
34
43#define SYS_BITARRAY_DEFINE(name, total_bits) \
44 uint32_t _sys_bitarray_bundles_##name \
45 [(((total_bits + 8 - 1) / 8) + sizeof(uint32_t) - 1) \
46 / sizeof(uint32_t)] = {0U}; \
47 sys_bitarray_t name = { \
48 .num_bits = total_bits, \
49 .num_bundles = (((total_bits + 8 - 1) / 8) \
50 + sizeof(uint32_t) - 1) \
51 / sizeof(uint32_t), \
52 .bundles = _sys_bitarray_bundles_##name, \
53 }
54
65int sys_bitarray_set_bit(sys_bitarray_t *bitarray, size_t bit);
66
77int sys_bitarray_clear_bit(sys_bitarray_t *bitarray, size_t bit);
78
90int sys_bitarray_test_bit(sys_bitarray_t *bitarray, size_t bit, int *val);
91
103int sys_bitarray_test_and_set_bit(sys_bitarray_t *bitarray, size_t bit, int *prev_val);
104
116int sys_bitarray_test_and_clear_bit(sys_bitarray_t *bitarray, size_t bit, int *prev_val);
117
138 size_t *offset);
139
156 size_t offset);
157
172 size_t offset);
173
188 size_t offset);
189
205 size_t offset);
206
222 size_t offset);
223
224#ifdef __cplusplus
225}
226#endif
227
228#endif /* ZEPHYR_INCLUDE_SYS_BITARRAY_H_ */
bool sys_bitarray_is_region_cleared(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)
int sys_bitarray_test_and_clear_bit(sys_bitarray_t *bitarray, size_t bit, int *prev_val)
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_set_region(sys_bitarray_t *bitarray, size_t num_bits, size_t offset)
int sys_bitarray_alloc(sys_bitarray_t *bitarray, size_t num_bits, size_t *offset)
int sys_bitarray_clear_region(sys_bitarray_t *bitarray, size_t num_bits, size_t offset)
int sys_bitarray_test_and_set_bit(sys_bitarray_t *bitarray, size_t bit, int *prev_val)
int sys_bitarray_test_bit(sys_bitarray_t *bitarray, size_t bit, int *val)
int sys_bitarray_free(sys_bitarray_t *bitarray, size_t num_bits, size_t offset)
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
Kernel Spin Lock.
Definition: spinlock.h:29
Definition: bitarray.h:19
uint32_t num_bits
Definition: bitarray.h:21
struct k_spinlock lock
Definition: bitarray.h:30
uint32_t * bundles
Definition: bitarray.h:27
uint32_t num_bundles
Definition: bitarray.h:24