-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbits.h
36 lines (25 loc) · 861 Bytes
/
bits.h
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
/** @file bits.h
@author M. P. Hayes, UCECE
@date 15 May 2007
@brief
*/
#ifndef BITS_H
#define BITS_H
#ifdef __cplusplus
extern "C" {
#endif
#define WORD_HIGHBIT (sizeof(unsigned) * 8 - 1)
#define BITS_MASK(first, last) (((unsigned) -1 >> (WORD_HIGHBIT - (last))) & ~((1U << (first)) - 1))
#define BITS_CLR(reg, first, last) ((reg) &= BITS_MASK ((first), (last)))
#define BITS_SET(reg, first, last) ((reg) |= BITS_MASK ((first), (last)))
#define BITS_EXTRACT(reg, first, last) \
(((reg) & BITS_MASK ((first), (last))) >> (first))
#define BITS_INSERT(reg, val, first, last) \
(reg) = ((reg) & ~BITS_MASK ((first), (last))) \
| (((val) & BITS_MASK (0, (last) - (first))) << (first))
#define BITS(val, first, last) \
(((val) & BITS_MASK (0, (last) - (first))) << (first))
#ifdef __cplusplus
}
#endif
#endif