summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-05-12 19:32:32 +0700
committerhathach <[email protected]>2013-05-12 19:32:32 +0700
commitcc496074347543d19bbcc691dd46d05db2817b51 (patch)
tree1b5e3651d3ddb47b9a0c2f73b09427e0216ee996
parent81780008e977fc2093155bfb7be63e00447ad3be (diff)
test refractor
-rw-r--r--tests/readme.md1
-rw-r--r--tests/test/host/ehci/test_ehci_structure.c31
-rw-r--r--tinyusb/common/common.h20
3 files changed, 20 insertions, 32 deletions
diff --git a/tests/readme.md b/tests/readme.md
index 0f6e370bc..d96b8c64b 100644
--- a/tests/readme.md
+++ b/tests/readme.md
@@ -13,3 +13,4 @@ More detail on TDD can be found at
comming soon
<!-- https://travis-ci.org/hathach/tinyusb -->
+[![Build Status](https://travis-ci.org/hathach/tinyusb.png?branch=master)](https://travis-ci.org/hathach/tinyusb)
diff --git a/tests/test/host/ehci/test_ehci_structure.c b/tests/test/host/ehci/test_ehci_structure.c
index 467bb92a2..8298f102a 100644
--- a/tests/test/host/ehci/test_ehci_structure.c
+++ b/tests/test/host/ehci/test_ehci_structure.c
@@ -55,9 +55,8 @@ usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1];
//--------------------------------------------------------------------+
// Setup/Teardown + helper declare
//--------------------------------------------------------------------+
-int8_t first_pos_of_high_bit(uint32_t value);
-uint8_t number_of_high_bits(uint32_t value);
+// log2_of a value is equivalent to its highest set bit's position
#define BITFIELD_OFFSET_OF_MEMBER(struct_type, member, bitfield_member) \
({\
uint32_t value=0;\
@@ -65,7 +64,7 @@ uint8_t number_of_high_bits(uint32_t value);
memclr_((void*)&str, sizeof(struct_type));\
str.member.bitfield_member = 1;\
memcpy(&value, (void*)&str.member, sizeof(str.member));\
- first_pos_of_high_bit( value );\
+ log2_of( value );\
})
#define BITFIELD_OFFSET_OF_UINT32(struct_type, offset, bitfield_member) \
@@ -73,7 +72,7 @@ uint8_t number_of_high_bits(uint32_t value);
struct_type str;\
memclr_(&str, sizeof(struct_type));\
str.bitfield_member = 1;\
- first_pos_of_high_bit( ((uint32_t*) &str)[offset] );\
+ log2_of( ((uint32_t*) &str)[offset] );\
})
void setUp(void)
@@ -322,27 +321,3 @@ void test_ehci_data(void)
// TODO more tests on ehci_data
}
-
-//--------------------------------------------------------------------+
-// Helper
-//--------------------------------------------------------------------+
-int8_t first_pos_of_high_bit(uint32_t value)
-{
- for (int8_t i=0; i<32; i++)
- {
- if (value & BIT_(i))
- return i;
- }
- return (-1);
-}
-
-uint8_t number_of_high_bits(uint32_t value)
-{
- uint8_t result=0;
- for(uint8_t i=0; i<32; i++)
- {
- if (value & BIT_(i))
- result++;
- }
- return result;
-}
diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h
index fd1d2b293..63ba26d56 100644
--- a/tinyusb/common/common.h
+++ b/tinyusb/common/common.h
@@ -83,14 +83,14 @@
#define STRING_CONCAT_(a, b) a##b // concat without expand
#define XSTRING_CONCAT_(a, b) STRING_CONCAT_(a, b) // expand then concat
-#define U16_HIGH_U8(u16) ((uint8_t) (((u16) > 8) & 0x00ff))
+#define U16_HIGH_U8(u16) ((uint8_t) (((u16) >> 8) & 0x00ff))
#define U16_LOW_U8(u16) ((uint8_t) ((u16) & 0x00ff))
#define U16_TO_U8S_BE(u16) U16_HIGH_U8(u16), U16_LOW_U8(u16)
#define U16_TO_U8S_LE(u16) U16_LOW_U8(u16), U16_HIGH_U8(u16)
-#define U32_B1_U8(u32) ((uint8_t) (((u32) > 24) & 0x000000ff)) // MSB
-#define U32_B2_U8(u32) ((uint8_t) (((u32) > 16) & 0x000000ff))
-#define U32_B3_U8(u32) ((uint8_t) (((u32) > 8) & 0x000000ff))
+#define U32_B1_U8(u32) ((uint8_t) (((u32) >> 24) & 0x000000ff)) // MSB
+#define U32_B2_U8(u32) ((uint8_t) (((u32) >> 16) & 0x000000ff))
+#define U32_B3_U8(u32) ((uint8_t) (((u32) >> 8) & 0x000000ff))
#define U32_B4_U8(u32) ((uint8_t) ((u32) & 0x000000ff)) // LSB
#define U32_TO_U8S_BE(u32) U32_B1_U8(u32), U32_B2_U8(u32), U32_B3_U8(u32), U32_B4_U8(u32)
@@ -109,6 +109,18 @@ static inline uint32_t u32_from_u8(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b
return (b1 << 24) + (b2 << 16) + (b3 << 8) + b4;
}
+static inline uint8_t u16_high_u8(uint16_t u16) ATTR_CONST ATTR_ALWAYS_INLINE;
+static inline uint8_t u16_high_u8(uint16_t u16)
+{
+ return (uint8_t) ((u16 >> 8) & 0x00ff);
+}
+
+static inline uint8_t u16_low_u8(uint16_t u16) ATTR_CONST ATTR_ALWAYS_INLINE;
+static inline uint8_t u16_low_u8(uint16_t u16)
+{
+ return (uint8_t) (u16 & 0x00ff);
+}
+
//------------- Min -------------//
static inline uint8_t min8_of(uint8_t x, uint8_t y) ATTR_ALWAYS_INLINE ATTR_CONST;
static inline uint8_t min8_of(uint8_t x, uint8_t y)