test refractor
This commit is contained in:
		| @@ -13,3 +13,4 @@ More detail on TDD can be found at | |||||||
|  |  | ||||||
| comming soon | comming soon | ||||||
| <!-- https://travis-ci.org/hathach/tinyusb -->  | <!-- https://travis-ci.org/hathach/tinyusb -->  | ||||||
|  | [](https://travis-ci.org/hathach/tinyusb) | ||||||
|   | |||||||
| @@ -55,9 +55,8 @@ usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; | |||||||
| //--------------------------------------------------------------------+ | //--------------------------------------------------------------------+ | ||||||
| // Setup/Teardown + helper declare | // 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) \ | #define BITFIELD_OFFSET_OF_MEMBER(struct_type, member, bitfield_member) \ | ||||||
|   ({\ |   ({\ | ||||||
|     uint32_t value=0;\ |     uint32_t value=0;\ | ||||||
| @@ -65,7 +64,7 @@ uint8_t number_of_high_bits(uint32_t value); | |||||||
|     memclr_((void*)&str, sizeof(struct_type));\ |     memclr_((void*)&str, sizeof(struct_type));\ | ||||||
|     str.member.bitfield_member = 1;\ |     str.member.bitfield_member = 1;\ | ||||||
|     memcpy(&value, (void*)&str.member, sizeof(str.member));\ |     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) \ | #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;\ |     struct_type str;\ | ||||||
|     memclr_(&str, sizeof(struct_type));\ |     memclr_(&str, sizeof(struct_type));\ | ||||||
|     str.bitfield_member = 1;\ |     str.bitfield_member = 1;\ | ||||||
|     first_pos_of_high_bit( ((uint32_t*) &str)[offset] );\ |     log2_of( ((uint32_t*) &str)[offset] );\ | ||||||
|   }) |   }) | ||||||
|  |  | ||||||
| void setUp(void) | void setUp(void) | ||||||
| @@ -322,27 +321,3 @@ void test_ehci_data(void) | |||||||
|  |  | ||||||
|   // TODO more tests on ehci_data |   // 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; |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -83,14 +83,14 @@ | |||||||
| #define STRING_CONCAT_(a, b) a##b                  // concat without expand | #define STRING_CONCAT_(a, b) a##b                  // concat without expand | ||||||
| #define XSTRING_CONCAT_(a, b) STRING_CONCAT_(a, b) // expand then concat | #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_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_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 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_B1_U8(u32) ((uint8_t) (((u32) >> 24) & 0x000000ff)) // MSB | ||||||
| #define U32_B2_U8(u32) ((uint8_t) (((u32) > 16) & 0x000000ff)) | #define U32_B2_U8(u32) ((uint8_t) (((u32) >> 16) & 0x000000ff)) | ||||||
| #define U32_B3_U8(u32) ((uint8_t) (((u32) >  8) & 0x000000ff)) | #define U32_B3_U8(u32) ((uint8_t) (((u32) >>  8) & 0x000000ff)) | ||||||
| #define U32_B4_U8(u32) ((uint8_t) ((u32)        & 0x000000ff)) // LSB | #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) | #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; |   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 -------------// | //------------- 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) ATTR_ALWAYS_INLINE ATTR_CONST; | ||||||
| static inline uint8_t min8_of(uint8_t x, uint8_t y) | static inline uint8_t min8_of(uint8_t x, uint8_t y) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach