add bitfield macros
This commit is contained in:
parent
43b57ea41a
commit
80c25e2602
1 changed files with 6 additions and 0 deletions
|
@ -14,4 +14,10 @@
|
|||
#define clear_bit(val, bit) (val = (val & ~(1 << bit)))
|
||||
#define set_bit(val, bit) (val = (val | (1 << bit)))
|
||||
|
||||
#define ones(num) ( (1<<num) - 1 )
|
||||
#define bit_mask(length, shift) (ones(length) << shift)
|
||||
#define get_field(val, field) ((val & field##_MASK) >> field)
|
||||
//#define bitfield(name, length, shift) ( #define #name length #define #name##_MASK bit_mask(length, shift))
|
||||
#define bitfield(name, length, shift) ( define #name length )
|
||||
|
||||
#endif /* UTILS_H */
|
||||
|
|
Loading…
Reference in a new issue