add bitfield macros

This commit is contained in:
Mariano Alvira 2010-03-03 18:46:23 -05:00
parent 43b57ea41a
commit 80c25e2602

View file

@ -14,4 +14,10 @@
#define clear_bit(val, bit) (val = (val & ~(1 << bit))) #define clear_bit(val, bit) (val = (val & ~(1 << bit)))
#define set_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 */ #endif /* UTILS_H */