diff options
| author | hathach <[email protected]> | 2018-12-14 15:28:38 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2018-12-14 15:30:54 +0700 |
| commit | 2a60427bdc7d23d7c1ab1e687f5a8d9555a69f15 (patch) | |
| tree | 9a5a170d6cd7dc6e01558922109995c01116aca1 /src/common/binary.h | |
| parent | a3713f801d97b1903593a53c02da682acb3acee0 (diff) | |
rename bit_* helper to tu_bit_*, BIT_* to TU_BIT_* for consistency
Diffstat (limited to 'src/common/binary.h')
| -rw-r--r-- | src/common/binary.h | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/src/common/binary.h b/src/common/binary.h index 7a93ee709..5bc364f2f 100644 --- a/src/common/binary.h +++ b/src/common/binary.h @@ -52,49 +52,38 @@ #include "tusb_compiler.h"
//------------- Bit manipulation -------------//
-#define BIT_(n) (1U << (n)) ///< n-th Bit
-#define BIT_SET_(x, n) ( (x) | BIT_(n) ) ///< set n-th bit of x to 1
-#define BIT_CLR_(x, n) ( (x) & (~BIT_(n)) ) ///< clear n-th bit of x
-#define BIT_TEST_(x, n) ( ((x) & BIT_(n)) ? true : false ) ///< check if n-th bit of x is 1
+#define TU_BIT(n) (1U << (n)) ///< n-th Bit
+#define TU_BIT_SET(x, n) ( (x) | TU_BIT(n) ) ///< set n-th bit of x to 1
+#define TU_BIT_CLEAR(x, n) ( (x) & (~TU_BIT(n)) ) ///< clear n-th bit of x
+#define TU_BIT_TEST(x, n) ( ((x) & TU_BIT(n)) ? true : false ) ///< check if n-th bit of x is 1
-static inline uint32_t bit_set(uint32_t value, uint8_t n)
+static inline uint32_t tu_bit_set(uint32_t value, uint8_t n)
{
- return value | BIT_(n);
+ return value | TU_BIT(n);
}
-static inline uint32_t bit_clear(uint32_t value, uint8_t n)
+static inline uint32_t tu_bit_clear(uint32_t value, uint8_t n)
{
- return value & (~BIT_(n));
+ return value & (~TU_BIT(n));
}
-static inline bool bit_test(uint32_t value, uint8_t n)
+static inline bool tu_bit_test(uint32_t value, uint8_t n)
{
- return (value & BIT_(n)) ? true : false;
+ return (value & TU_BIT(n)) ? true : false;
}
///< create a mask with n-bit lsb set to 1
-static inline uint32_t bit_mask(uint8_t n)
+static inline uint32_t tu_bit_mask(uint8_t n)
{
- return (n < 32) ? ( BIT_(n) - 1 ) : UINT32_MAX;
+ return (n < 32) ? ( TU_BIT(n) - 1 ) : UINT32_MAX;
}
-static inline uint32_t bit_mask_range(uint8_t start, uint32_t end)
-{
- return bit_mask(end+1) & ~ bit_mask(start);
-}
-
-static inline uint32_t bit_set_range(uint32_t value, uint8_t start, uint8_t end, uint32_t pattern)
-{
- return ( value & ~bit_mask_range(start, end) ) | (pattern << start);
-}
-
-
//------------- Binary Constant -------------//
#if defined(__GNUC__) && !defined(__CC_ARM)
-#define BIN8(x) ((uint8_t) (0b##x))
-#define BIN16(b1, b2) ((uint16_t) (0b##b1##b2))
-#define BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4))
+#define TU_BIN8(x) ((uint8_t) (0b##x))
+#define TU_BIN16(b1, b2) ((uint16_t) (0b##b1##b2))
+#define TU_BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4))
#else
@@ -108,13 +97,13 @@ static inline uint32_t bit_set_range(uint32_t value, uint8_t start, uint8_t end, +((x&0x0F000000UL)?64:0) \
+((x&0xF0000000UL)?128:0))
-#define BIN8(d) ((uint8_t) _B8__(0x##d##UL))
-#define BIN16(dmsb,dlsb) (((uint16_t)BIN8(dmsb)<<8) + BIN8(dlsb))
-#define BIN32(dmsb,db2,db3,dlsb) \
- (((uint32_t)BIN8(dmsb)<<24) \
- + ((uint32_t)BIN8(db2)<<16) \
- + ((uint32_t)BIN8(db3)<<8) \
- + BIN8(dlsb))
+#define TU_BIN8(d) ((uint8_t) _B8__(0x##d##UL))
+#define TU_BIN16(dmsb,dlsb) (((uint16_t)TU_BIN8(dmsb)<<8) + TU_BIN8(dlsb))
+#define TU_BIN32(dmsb,db2,db3,dlsb) \
+ (((uint32_t)TU_BIN8(dmsb)<<24) \
+ + ((uint32_t)TU_BIN8(db2)<<16) \
+ + ((uint32_t)TU_BIN8(db3)<<8) \
+ + TU_BIN8(dlsb))
#endif
#ifdef __cplusplus
|
