From 6135019230dd5e6c1c8cb17c83d20fabb500228d Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 14 May 2019 11:46:22 +0700 Subject: [PATCH] clean up --- examples/device/cdc_msc_hid/src/tusb_config.h | 2 +- .../cdc_msc_hid_freertos/src/tusb_config.h | 2 +- .../hid_generic_inout/src/tusb_config.h | 2 +- .../device/msc_dual_lun/src/tusb_config.h | 2 +- examples/host/cdc_msc_hid/src/tusb_config.h | 2 +- examples/obsolete/host/src/tusb_config.h | 2 +- src/class/cdc/cdc_rndis_host.c | 2 +- src/class/hid/hid_host.c | 2 +- src/class/msc/msc_device.c | 3 +- src/common/tusb_common.h | 59 ++++++++++--------- src/common/tusb_compiler.h | 8 --- src/common/tusb_verify.h | 2 +- src/host/hub.c | 4 +- src/tusb_option.h | 9 +-- tests/support/tusb_config.h | 6 +- 15 files changed, 48 insertions(+), 59 deletions(-) diff --git a/examples/device/cdc_msc_hid/src/tusb_config.h b/examples/device/cdc_msc_hid/src/tusb_config.h index e909a0d4a..40374e8ea 100644 --- a/examples/device/cdc_msc_hid/src/tusb_config.h +++ b/examples/device/cdc_msc_hid/src/tusb_config.h @@ -46,7 +46,7 @@ #endif #define CFG_TUSB_OS OPT_OS_NONE -#define CFG_TUSB_DEBUG 2 +#define CFG_TUSB_DEBUG 1 /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. * Tinyusb use follows macros to declare transferring memory so that they can be put diff --git a/examples/device/cdc_msc_hid_freertos/src/tusb_config.h b/examples/device/cdc_msc_hid_freertos/src/tusb_config.h index c377798c1..7d43f7fed 100644 --- a/examples/device/cdc_msc_hid_freertos/src/tusb_config.h +++ b/examples/device/cdc_msc_hid_freertos/src/tusb_config.h @@ -46,7 +46,7 @@ #endif #define CFG_TUSB_OS OPT_OS_FREERTOS -#define CFG_TUSB_DEBUG 2 +#define CFG_TUSB_DEBUG 1 /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. * Tinyusb use follows macros to declare transferring memory so that they can be put diff --git a/examples/device/hid_generic_inout/src/tusb_config.h b/examples/device/hid_generic_inout/src/tusb_config.h index baf418d94..1868804fd 100644 --- a/examples/device/hid_generic_inout/src/tusb_config.h +++ b/examples/device/hid_generic_inout/src/tusb_config.h @@ -46,7 +46,7 @@ #endif #define CFG_TUSB_OS OPT_OS_NONE -#define CFG_TUSB_DEBUG 2 +#define CFG_TUSB_DEBUG 1 /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. * Tinyusb use follows macros to declare transferring memory so that they can be put diff --git a/examples/device/msc_dual_lun/src/tusb_config.h b/examples/device/msc_dual_lun/src/tusb_config.h index 939919739..1ba8102ef 100644 --- a/examples/device/msc_dual_lun/src/tusb_config.h +++ b/examples/device/msc_dual_lun/src/tusb_config.h @@ -46,7 +46,7 @@ #endif #define CFG_TUSB_OS OPT_OS_NONE -#define CFG_TUSB_DEBUG 2 +#define CFG_TUSB_DEBUG 1 /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. * Tinyusb use follows macros to declare transferring memory so that they can be put diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index aa081f9db..2bc6a85ce 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -46,7 +46,7 @@ #define CFG_TUSB_RHPORT0_MODE OPT_MODE_HOST #endif -#define CFG_TUSB_DEBUG 2 +#define CFG_TUSB_DEBUG 1 #define CFG_TUSB_OS OPT_OS_NONE /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. diff --git a/examples/obsolete/host/src/tusb_config.h b/examples/obsolete/host/src/tusb_config.h index c7dd89e07..110472d73 100644 --- a/examples/obsolete/host/src/tusb_config.h +++ b/examples/obsolete/host/src/tusb_config.h @@ -54,7 +54,7 @@ //--------------------------------------------------------------------+ // COMMON CONFIGURATION //--------------------------------------------------------------------+ -#define CFG_TUSB_DEBUG 2 +#define CFG_TUSB_DEBUG 1 //#define CFG_TUSB_OS OPT_OS_NONE // defined using eclipse build //#define CFG_TUD_TASK_PRIO 0 // defined using eclipse build diff --git a/src/class/cdc/cdc_rndis_host.c b/src/class/cdc/cdc_rndis_host.c index 587e9ddc8..e5ae34b52 100644 --- a/src/class/cdc/cdc_rndis_host.c +++ b/src/class/cdc/cdc_rndis_host.c @@ -43,7 +43,7 @@ CFG_TUSB_MEM_SECTION static uint8_t msg_notification[CFG_TUSB_HOST_DEVICE_MAX][8]; CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4) static uint8_t msg_payload[RNDIS_MSG_PAYLOAD_MAX]; -STATIC_VAR rndish_data_t rndish_data[CFG_TUSB_HOST_DEVICE_MAX]; +static rndish_data_t rndish_data[CFG_TUSB_HOST_DEVICE_MAX]; // TODO Microsoft requires message length for any get command must be at least 4096 bytes diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 5aabbc01f..0e6437a20 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -111,7 +111,7 @@ bool tuh_hid_keyboard_is_busy(uint8_t dev_addr) //--------------------------------------------------------------------+ #if CFG_TUH_HID_MOUSE -STATIC_VAR hidh_interface_info_t mouseh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1 +static hidh_interface_info_t mouseh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1 //------------- Public API -------------// bool tuh_hid_mouse_is_mounted(uint8_t dev_addr) diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index c486d5e04..a07c926d7 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -80,7 +80,8 @@ static inline uint32_t rdwr10_get_lba(uint8_t const command[]) uint32_t lba; memcpy(&lba, &p_rdwr10->lba, 4); - return __be2n(lba); + // lba is in Big Endian format + return __be2n(lba); } static inline uint16_t rdwr10_get_blockcount(uint8_t const command[]) diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index e687b8983..1f55a0fc0 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -67,34 +67,6 @@ #define ENDIAN_BE16(le16) ((uint16_t) ((U16_LOW_U8(le16) << 8) | U16_HIGH_U8(le16)) ) -//------------- Binary constant -------------// -#if defined(__GNUC__) && !defined(__CC_ARM) - -#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 - -// internal macro of B8, B16, B32 -#define _B8__(x) (((x&0x0000000FUL)?1:0) \ - +((x&0x000000F0UL)?2:0) \ - +((x&0x00000F00UL)?4:0) \ - +((x&0x0000F000UL)?8:0) \ - +((x&0x000F0000UL)?16:0) \ - +((x&0x00F00000UL)?32:0) \ - +((x&0x0F000000UL)?64:0) \ - +((x&0xF0000000UL)?128:0)) - -#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 - // for declaration of reserved field, make use of _TU_COUNTER_ #define TU_RESERVED XSTRING_CONCAT_(reserved, _TU_COUNTER_) @@ -190,7 +162,7 @@ static inline bool tu_within(uint32_t lower, uint32_t value, uint32_t upper) } // log2 of a value is its MSB's position -// TODO use clz +// TODO use clz TODO remove static inline uint8_t tu_log2(uint32_t value) { uint8_t result = 0; @@ -237,6 +209,35 @@ static inline bool tu_bit_test(uint32_t value, uint8_t n) { return (value & TU_B 9,8,7,6,5,4,3,2,1,0 #endif +// To be removed +//------------- Binary constant -------------// +#if defined(__GNUC__) && !defined(__CC_ARM) + +#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 + +// internal macro of B8, B16, B32 +#define _B8__(x) (((x&0x0000000FUL)?1:0) \ + +((x&0x000000F0UL)?2:0) \ + +((x&0x00000F00UL)?4:0) \ + +((x&0x0000F000UL)?8:0) \ + +((x&0x000F0000UL)?16:0) \ + +((x&0x00F00000UL)?32:0) \ + +((x&0x0F000000UL)?64:0) \ + +((x&0xF0000000UL)?128:0)) + +#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 } #endif diff --git a/src/common/tusb_compiler.h b/src/common/tusb_compiler.h index 613db4d3d..c0813e8ef 100644 --- a/src/common/tusb_compiler.h +++ b/src/common/tusb_compiler.h @@ -52,14 +52,6 @@ #define TU_VERIFY_STATIC(const_expr, _mess) enum { XSTRING_CONCAT_(_verify_static_, _TU_COUNTER_) = 1/(!!(const_expr)) } #endif -// allow debugger to watch any module-wide variables anywhere -#if CFG_TUSB_DEBUG -#define STATIC_VAR -#else -#define STATIC_VAR static -#endif - - #if defined(__GNUC__) #include "compiler/tusb_compiler_gcc.h" #elif defined __ICCARM__ diff --git a/src/common/tusb_verify.h b/src/common/tusb_verify.h index 74bc41230..05af66205 100644 --- a/src/common/tusb_verify.h +++ b/src/common/tusb_verify.h @@ -50,7 +50,7 @@ //--------------------------------------------------------------------+ // TU_VERIFY Helper //--------------------------------------------------------------------+ -#if CFG_TUSB_DEBUG >= 1 +#if CFG_TUSB_DEBUG #include #define _MESS_ERR(_err) printf("%s: %d: failed, error = %s\n", __func__, __LINE__, tusb_strerr[_err]) #define _MESS_FAILED() printf("%s: %d: failed\n", __func__, __LINE__) diff --git a/src/host/hub.c b/src/host/hub.c index 157a77937..92a16ae0f 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -44,8 +44,8 @@ typedef struct uint8_t status_change; // data from status change interrupt endpoint }usbh_hub_t; -CFG_TUSB_MEM_SECTION STATIC_VAR usbh_hub_t hub_data[CFG_TUSB_HOST_DEVICE_MAX]; -ATTR_ALIGNED(4) CFG_TUSB_MEM_SECTION STATIC_VAR uint8_t hub_enum_buffer[sizeof(descriptor_hub_desc_t)]; +CFG_TUSB_MEM_SECTION static usbh_hub_t hub_data[CFG_TUSB_HOST_DEVICE_MAX]; +ATTR_ALIGNED(4) CFG_TUSB_MEM_SECTION static uint8_t hub_enum_buffer[sizeof(descriptor_hub_desc_t)]; //OSAL_SEM_DEF(hub_enum_semaphore); //static osal_semaphore_handle_t hub_enum_sem_hdl; diff --git a/src/tusb_option.h b/src/tusb_option.h index 4e55132b1..492e1c574 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -119,13 +119,8 @@ //--------------------------------------------------------------------+ // COMMON OPTIONS //--------------------------------------------------------------------+ -/** - determines the debug level for the stack - - Level 3: TBD - - Level 2: TBD - - Level 1: Print out if Assert failed. STATIC_VAR is NULL --> accessible when debugging - - Level 0: no debug information is generated -*/ + +// Debug enable to print out error message #ifndef CFG_TUSB_DEBUG #define CFG_TUSB_DEBUG 0 #endif diff --git a/tests/support/tusb_config.h b/tests/support/tusb_config.h index 0c8957fff..86a68df7e 100644 --- a/tests/support/tusb_config.h +++ b/tests/support/tusb_config.h @@ -47,7 +47,7 @@ #define CFG_TUH_HID_KEYBOARD 1 #define CFG_TUH_HID_MOUSE 1 #define CFG_TUH_MSC 1 -#define CFG_TUSB_HOST_HID_GENERIC 0 +#define CFG_TUSB_HOST_HID_GENERIC 0 #define CFG_TUH_CDC 1 #define CFG_TUH_CDC_RNDIS 0 @@ -71,9 +71,9 @@ // COMMON CONFIGURATION //--------------------------------------------------------------------+ -#define CFG_TUSB_DEBUG 3 +#define CFG_TUSB_DEBUG 1 -#define CFG_TUSB_OS OPT_OS_NONE +#define CFG_TUSB_OS OPT_OS_NONE #define CFG_TUSB_MEM_SECTION #ifdef __cplusplus