-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathco_bitmap.c
65 lines (53 loc) · 1.39 KB
/
co_bitmap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
*
* www.rt-labs.com
* Copyright 2017 rt-labs AB, Sweden.
*
* This software is dual-licensed under GPLv3 and a commercial
* license. See the file LICENSE.md distributed with this software for
* full license information.
********************************************************************/
#ifdef UNIT_TEST
#endif
#include "co_bitmap.h"
#include "osal.h"
void co_bitmap_set (uint32_t * bm, int bit)
{
int ix = bit / 32;
int offset = bit % 32;
CC_ASSERT (bit < 128);
bm[ix] |= BIT (offset);
}
void co_bitmap_clear (uint32_t * bm, int bit)
{
int ix = bit / 32;
int offset = bit % 32;
CC_ASSERT (bit < 128);
bm[ix] &= ~BIT (offset);
}
int co_bitmap_get (uint32_t * bm, int bit)
{
int ix = bit / 32;
int offset = bit % 32;
CC_ASSERT (bit < 128);
return (bm[ix] & BIT (offset)) ? 1 : 0;
}
int co_bitmap_next (uint32_t * bm, int bit)
{
int ix;
int offset = bit % 32;
CC_ASSERT (bit < 128);
for (ix = bit / 32; ix < 4; ix++)
{
uint32_t mask = -(int)BIT (offset);
if (bm[ix] & mask)
return __builtin_ctz (bm[ix] & mask) + 32 * ix;
offset = 0;
}
return 0;
}