Toggle navigation
Documentation
The friendly Operating System for the Internet of Things
bitfield.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2015 INRIA
3
*
4
* This file is subject to the terms and conditions of the GNU Lesser
5
* General Public License v2.1. See the file LICENSE in the top level
6
* directory for more details.
7
*/
8
29
#ifndef BITFIELD_H
30
#define BITFIELD_H
31
32
#include <stdint.h>
33
#include <stdbool.h>
34
#include <stddef.h>
35
36
#ifdef __cplusplus
37
extern
"C"
{
38
#endif
39
46
#define BITFIELD(NAME, SIZE) uint8_t NAME[((SIZE) + 7) / 8]
47
54
static
inline
void
bf_set
(uint8_t field[],
size_t
idx)
55
{
56
field[idx / 8] |= (1u << (7 - (idx % 8)));
57
}
58
65
static
inline
void
bf_unset
(uint8_t field[],
size_t
idx)
66
{
67
field[idx / 8] &= ~(1u << (7 - (idx % 8)));
68
}
69
76
static
inline
void
bf_toggle
(uint8_t field[],
size_t
idx)
77
{
78
field[idx / 8] ^= (1u << (7 - (idx % 8)));
79
}
80
87
static
inline
bool
bf_isset
(uint8_t field[],
size_t
idx)
88
{
89
return
(field[idx / 8] & (1u << (7 - (idx % 8))));
90
}
91
103
int
bf_get_unset
(uint8_t field[],
int
size);
104
105
#ifdef __cplusplus
106
}
107
#endif
108
110
#endif
/* BITFIELD_H */
bf_isset
static bool bf_isset(uint8_t field[], size_t idx)
Check if the bet is set.
Definition:
bitfield.h:87
bf_get_unset
int bf_get_unset(uint8_t field[], int size)
Atomically get the number of an unset bit and set it.
bf_unset
static void bf_unset(uint8_t field[], size_t idx)
Clear the bit.
Definition:
bitfield.h:65
bf_set
static void bf_set(uint8_t field[], size_t idx)
Set the bit to 1.
Definition:
bitfield.h:54
bf_toggle
static void bf_toggle(uint8_t field[], size_t idx)
Toggle the bit.
Definition:
bitfield.h:76
Generated on Tue Nov 24 2020 19:46:51 by
1.8.17