2010-02-24 19:35:37 +01:00
|
|
|
#ifndef UTILS_H
|
|
|
|
#define UTILS_H
|
|
|
|
|
2010-02-26 22:37:20 +01:00
|
|
|
#define mem32(x) ((volatile uint32_t *)(x))
|
|
|
|
#define mem16(x) ((volatile uint16_t *)(x))
|
|
|
|
|
2010-02-24 19:35:37 +01:00
|
|
|
#define CAT2(x, y, z) x##y##z
|
|
|
|
|
2010-03-03 20:07:00 +01:00
|
|
|
#define STR(x) #x
|
|
|
|
#define STR2(x) STR(x)
|
|
|
|
|
2010-02-24 19:35:37 +01:00
|
|
|
#define bit(bit) (1 << bit)
|
|
|
|
#define bit_is_set(val, bit) (((val & (1 << bit)) >> bit) == 1)
|
|
|
|
#define clear_bit(val, bit) (val = (val & ~(1 << bit)))
|
|
|
|
#define set_bit(val, bit) (val = (val | (1 << bit)))
|
|
|
|
|
2010-03-04 00:46:23 +01:00
|
|
|
#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 )
|
|
|
|
|
2010-02-24 19:35:37 +01:00
|
|
|
#endif /* UTILS_H */
|