From a3713f801d97b1903593a53c02da682acb3acee0 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 14 Dec 2018 13:08:21 +0700 Subject: [PATCH 1/9] clean up compiler attribute --- .../obsolete/host/src/keyboard_host_app.c | 2 +- examples/obsolete/host/src/msc_cli.c | 2 - lib/fatfs/diskio.c | 2 - src/class/cdc/cdc_rndis_host.h | 2 +- src/class/custom/custom_host.h | 2 +- src/class/hid/hid_host.h | 24 +++---- src/class/msc/msc_host.h | 12 ++-- src/common/binary.h | 8 +-- src/common/compiler/tusb_compiler_gcc.h | 68 ++++--------------- src/common/compiler/tusb_compiler_iar.h | 31 ++------- src/host/hcd.h | 2 +- src/host/hub.h | 2 +- src/host/usbh.c | 4 +- src/tusb.h | 1 + tests/support/tusb_callback.h | 2 +- 15 files changed, 49 insertions(+), 115 deletions(-) diff --git a/examples/obsolete/host/src/keyboard_host_app.c b/examples/obsolete/host/src/keyboard_host_app.c index 77fa8e5d..f6cd20fd 100644 --- a/examples/obsolete/host/src/keyboard_host_app.c +++ b/examples/obsolete/host/src/keyboard_host_app.c @@ -55,7 +55,7 @@ static osal_queue_t queue_kbd_hdl; CFG_TUSB_MEM_SECTION static hid_keyboard_report_t usb_keyboard_report; -static inline uint8_t keycode_to_ascii(uint8_t modifier, uint8_t keycode) ATTR_CONST ATTR_ALWAYS_INLINE; +static inline uint8_t keycode_to_ascii(uint8_t modifier, uint8_t keycode); static inline void process_kbd_report(hid_keyboard_report_t const * report); //--------------------------------------------------------------------+ diff --git a/examples/obsolete/host/src/msc_cli.c b/examples/obsolete/host/src/msc_cli.c index fa1f986a..0ab42e3f 100644 --- a/examples/obsolete/host/src/msc_cli.c +++ b/examples/obsolete/host/src/msc_cli.c @@ -145,7 +145,6 @@ CFG_TUSB_MEM_SECTION uint8_t fileread_buffer[CLI_FILE_READ_BUFFER]; static char cli_buffer[CLI_MAX_BUFFER]; static char volume_label[20]; -static inline void drive_number2letter(char * p_path) ATTR_ALWAYS_INLINE; static inline void drive_number2letter(char * p_path) { if (p_path[1] == ':') @@ -154,7 +153,6 @@ static inline void drive_number2letter(char * p_path) } } -static inline void drive_letter2number(char * p_path) ATTR_ALWAYS_INLINE; static inline void drive_letter2number(char * p_path) { if (p_path[1] == ':') diff --git a/lib/fatfs/diskio.c b/lib/fatfs/diskio.c index 939015c0..7d6b5afd 100644 --- a/lib/fatfs/diskio.c +++ b/lib/fatfs/diskio.c @@ -132,7 +132,6 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff) return RES_OK; } -static inline uint8_t month2number(char* p_ch) ATTR_PURE ATTR_ALWAYS_INLINE; static inline uint8_t month2number(char* p_ch) { char const * const month_str[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; @@ -145,7 +144,6 @@ static inline uint8_t month2number(char* p_ch) return 1; } -static inline uint8_t c2i(char ch) ATTR_CONST ATTR_ALWAYS_INLINE; static inline uint8_t c2i(char ch) { return ch - '0'; diff --git a/src/class/cdc/cdc_rndis_host.h b/src/class/cdc/cdc_rndis_host.h index 3b92d3f2..730df2e2 100644 --- a/src/class/cdc/cdc_rndis_host.h +++ b/src/class/cdc/cdc_rndis_host.h @@ -64,7 +64,7 @@ typedef struct { }rndish_data_t; void rndish_init(void); -tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc) ATTR_WARN_UNUSED_RESULT; +tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc); void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); void rndish_close(uint8_t dev_addr); diff --git a/src/class/custom/custom_host.h b/src/class/custom/custom_host.h index 5f9c25dd..5522db58 100644 --- a/src/class/custom/custom_host.h +++ b/src/class/custom/custom_host.h @@ -72,7 +72,7 @@ tusb_error_t tusbh_custom_write(uint8_t dev_addr, uint16_t vendor_id, uint16_t p #ifdef _TINY_USB_SOURCE_FILE_ void cush_init(void); -tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; +tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length); void cush_isr(pipe_handle_t pipe_hdl, xfer_result_t event); void cush_close(uint8_t dev_addr); diff --git a/src/class/hid/hid_host.h b/src/class/hid/hid_host.h index 7336f5ad..9d4b2b5b 100644 --- a/src/class/hid/hid_host.h +++ b/src/class/hid/hid_host.h @@ -67,7 +67,7 @@ extern uint8_t const hid_keycode_to_ascii_tbl[2][128]; // TODO used weak attr if * \retval true if device supports Keyboard interface * \retval false if device does not support Keyboard interface or is not mounted */ -bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; +bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr); /** \brief Check if the interface is currently busy or not * \param[in] dev_addr device address @@ -76,7 +76,7 @@ bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_ * \note This function is primarily used for polling/waiting result after \ref tuh_hid_keyboard_get_report. * Alternatively, asynchronous event API can be used */ -bool tuh_hid_keyboard_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; +bool tuh_hid_keyboard_is_busy(uint8_t dev_addr); /** \brief Perform a get report from Keyboard interface * \param[in] dev_addr device address @@ -88,7 +88,7 @@ bool tuh_hid_keyboard_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNU * \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct * \note This function is non-blocking and returns immediately. The result of usb transfer will be reported by the interface's callback function */ -tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void * p_report) /*ATTR_WARN_UNUSED_RESULT*/; +tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void * p_report); //------------- Application Callback -------------// /** \brief Callback function that is invoked when an transferring event occurred @@ -132,7 +132,7 @@ void tuh_hid_keyboard_unmounted_cb(uint8_t dev_addr); * \retval true if device supports Mouse interface * \retval false if device does not support Mouse interface or is not mounted */ -bool tuh_hid_mouse_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; +bool tuh_hid_mouse_is_mounted(uint8_t dev_addr); /** \brief Check if the interface is currently busy or not * \param[in] dev_addr device address @@ -141,7 +141,7 @@ bool tuh_hid_mouse_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNU * \note This function is primarily used for polling/waiting result after \ref tuh_hid_mouse_get_report. * Alternatively, asynchronous event API can be used */ -bool tuh_hid_mouse_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; +bool tuh_hid_mouse_is_busy(uint8_t dev_addr); /** \brief Perform a get report from Mouse interface * \param[in] dev_addr device address @@ -153,7 +153,7 @@ bool tuh_hid_mouse_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED * \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct * \note This function is non-blocking and returns immediately. The result of usb transfer will be reported by the interface's callback function */ -tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void* p_report) /*ATTR_WARN_UNUSED_RESULT*/; +tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void* p_report); //------------- Application Callback -------------// /** \brief Callback function that is invoked when an transferring event occurred @@ -192,11 +192,11 @@ void tuh_hid_mouse_unmounted_cb(uint8_t dev_addr); * The interface API includes status checking function, data transferring function and callback functions * @{ */ -bool tuh_hid_generic_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; -tusb_error_t tuh_hid_generic_get_report(uint8_t dev_addr, void* p_report, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; -tusb_error_t tuh_hid_generic_set_report(uint8_t dev_addr, void* p_report, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; -tusb_interface_status_t tuh_hid_generic_get_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT; -tusb_interface_status_t tuh_hid_generic_set_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT; +bool tuh_hid_generic_is_mounted(uint8_t dev_addr); +tusb_error_t tuh_hid_generic_get_report(uint8_t dev_addr, void* p_report, bool int_on_complete); +tusb_error_t tuh_hid_generic_set_report(uint8_t dev_addr, void* p_report, bool int_on_complete); +tusb_interface_status_t tuh_hid_generic_get_status(uint8_t dev_addr); +tusb_interface_status_t tuh_hid_generic_set_status(uint8_t dev_addr); //------------- Application Callback -------------// void tuh_hid_generic_isr(uint8_t dev_addr, xfer_result_t event); @@ -216,7 +216,7 @@ typedef struct { }hidh_interface_info_t; void hidh_init(void); -bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; +bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length); void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); void hidh_close(uint8_t dev_addr); diff --git a/src/class/msc/msc_host.h b/src/class/msc/msc_host.h index 968d221b..9035cb84 100644 --- a/src/class/msc/msc_host.h +++ b/src/class/msc/msc_host.h @@ -60,7 +60,7 @@ * \retval true if device supports * \retval false if device does not support or is not mounted */ -bool tuh_msc_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; +bool tuh_msc_is_mounted(uint8_t dev_addr); /** \brief Check if the interface is currently busy or not * \param[in] dev_addr device address @@ -70,7 +70,7 @@ bool tuh_msc_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RE * can be scheduled. User needs to make sure the corresponding interface is mounted (by \ref tuh_msc_is_mounted) * before calling this function */ -bool tuh_msc_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; +bool tuh_msc_is_busy(uint8_t dev_addr); /** \brief Get SCSI vendor's name of MassStorage device * \param[in] dev_addr device address @@ -113,7 +113,7 @@ tusb_error_t tuh_msc_get_capacity(uint8_t dev_addr, uint32_t* p_last_lba, uint32 * \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct * \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the interface's callback function */ -tusb_error_t tuh_msc_read10 (uint8_t dev_addr, uint8_t lun, void * p_buffer, uint32_t lba, uint16_t block_count) ATTR_WARN_UNUSED_RESULT; +tusb_error_t tuh_msc_read10 (uint8_t dev_addr, uint8_t lun, void * p_buffer, uint32_t lba, uint16_t block_count); /** \brief Perform SCSI WRITE 10 command to write data to MassStorage device * \param[in] dev_addr device address @@ -127,7 +127,7 @@ tusb_error_t tuh_msc_read10 (uint8_t dev_addr, uint8_t lun, void * p_buffer, uin * \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct * \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the interface's callback function */ -tusb_error_t tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * p_buffer, uint32_t lba, uint16_t block_count) ATTR_WARN_UNUSED_RESULT; +tusb_error_t tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * p_buffer, uint32_t lba, uint16_t block_count); /** \brief Perform SCSI REQUEST SENSE command, used to retrieve sense data from MassStorage device * \param[in] dev_addr device address @@ -150,11 +150,11 @@ tusb_error_t tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, uint8_t *p_dat * \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct * \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the interface's callback function */ -tusb_error_t tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, msc_csw_t * p_csw) ATTR_WARN_UNUSED_RESULT; // TODO to be refractor +tusb_error_t tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, msc_csw_t * p_csw); // TODO to be refractor //tusb_error_t tusbh_msc_scsi_send(uint8_t dev_addr, uint8_t lun, bool is_direction_in, // uint8_t const * p_command, uint8_t cmd_len, -// uint8_t * p_response, uint32_t resp_len) ATTR_WARN_UNUSED_RESULT; +// uint8_t * p_response, uint32_t resp_len); //------------- Application Callback -------------// /** \brief Callback function that will be invoked when a device with MassStorage interface is mounted diff --git a/src/common/binary.h b/src/common/binary.h index 3ab87e3f..7a93ee70 100644 --- a/src/common/binary.h +++ b/src/common/binary.h @@ -57,41 +57,35 @@ #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 -static inline uint32_t bit_set(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE; static inline uint32_t bit_set(uint32_t value, uint8_t n) { return value | BIT_(n); } -static inline uint32_t bit_clear(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE; static inline uint32_t bit_clear(uint32_t value, uint8_t n) { return value & (~BIT_(n)); } -static inline bool bit_test(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE; static inline bool bit_test(uint32_t value, uint8_t n) { return (value & BIT_(n)) ? true : false; } ///< create a mask with n-bit lsb set to 1 -static inline uint32_t bit_mask(uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE; static inline uint32_t bit_mask(uint8_t n) { return (n < 32) ? ( BIT_(n) - 1 ) : UINT32_MAX; } -static inline uint32_t bit_mask_range(uint8_t start, uint32_t end) ATTR_CONST ATTR_ALWAYS_INLINE; 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) ATTR_CONST ATTR_ALWAYS_INLINE; 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); + return ( value & ~bit_mask_range(start, end) ) | (pattern << start); } diff --git a/src/common/compiler/tusb_compiler_gcc.h b/src/common/compiler/tusb_compiler_gcc.h index e40ad9c4..6ea89f24 100644 --- a/src/common/compiler/tusb_compiler_gcc.h +++ b/src/common/compiler/tusb_compiler_gcc.h @@ -1,6 +1,6 @@ /**************************************************************************/ /*! - @file compiler_gcc.h + @file tusb_compiler_gcc.h @author hathach (tinyusb.org) @section LICENSE @@ -49,72 +49,34 @@ #define ALIGN_OF(x) __alignof__(x) -/// Normally, the compiler places the objects it generates in sections like data or bss & function in text. Sometimes, however, you need additional sections, or you need certain particular variables to appear in special sections, for example to map to special hardware. The section attribute specifies that a variable (or function) lives in a particular section -#define ATTR_SECTION(sec_name) __attribute__ (( section(#sec_name) )) - -/// If this attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, an error that includes message is diagnosed. This is useful for compile-time checking -#define ATTR_ERROR(Message) __attribute__ ((error(Message))) - -/// If this attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, a warning that includes message is diagnosed. This is useful for compile-time checking -#define ATTR_WARNING(Message) __attribute__ ((warning(Message))) - -/** \defgroup Group_VariableAttr Variable Attributes - * @{ */ - /// This attribute specifies a minimum alignment for the variable or structure field, measured in bytes #define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes))) -/// The packed attribute specifies that a variable or structure field should have the smallest possible alignment—one byte for a variable, and one bit for a field, unless you specify a larger value with the aligned attribute +/// Place variable in a specific section +#define ATTR_SECTION(sec_name) __attribute__ (( section(#sec_name) )) + +/// The packed attribute specifies that a variable or structure field should have +/// the smallest possible alignment—one byte for a variable, and one bit for a field. #define ATTR_PACKED __attribute__ ((packed)) #define ATTR_PREPACKED -/** @} */ - -/** \defgroup Group_FuncAttr Function Attributes - * @{ */ - -/// Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level is specified +/// This attribute inlines the function even if no optimization level is specified #define ATTR_ALWAYS_INLINE __attribute__ ((always_inline)) -/// The nonnull attribute specifies that some function parameters should be non-null pointers. f the compiler determines that a null pointer is passed in an argument slot marked as non-null, and the -Wnonnull option is enabled, a warning is issued. All pointer arguments are marked as non-null -#define ATTR_NON_NULL __attribute__ ((nonull)) +/// The deprecated attribute results in a warning if the function is used anywhere in the source file. +/// This is useful when identifying functions that are expected to be removed in a future version of a program. +#define ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) -/// Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared with the attribute pure -#define ATTR_PURE __attribute__ ((pure)) - -/// \brief Many functions do not examine any values except their arguments, and have no effects except the return value. Basically this is just slightly more strict class than the pure attribute below, since function is not allowed to read global memory. -/// Note that a function that has pointer arguments and examines the data pointed to must not be declared const. Likewise, a function that calls a non-const function usually must not be const. It does not make sense for a const function to return void -#define ATTR_CONST __attribute__ ((const)) - -/// The deprecated attribute results in a warning if the function is used anywhere in the source file. This is useful when identifying functions that are expected to be removed in a future version of a program. The warning also includes the location of the declaration of the deprecated function, to enable users to easily find further information about why the function is deprecated, or what they should do instead. Note that the warnings only occurs for uses -#define ATTR_DEPRECATED __attribute__ ((deprecated)) - -/// Same as the deprecated attribute with optional message in the warning -#define ATTR_DEPRECATED_MESS(mess) __attribute__ ((deprecated(mess))) - -/// The weak attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions that can be overridden in user code +/// The weak attribute causes the declaration to be emitted as a weak symbol rather than a global. +/// This is primarily useful in defining library functions that can be overridden in user code #define ATTR_WEAK __attribute__ ((weak)) -/// The alias attribute causes the declaration to be emitted as an alias for another symbol, which must be specified -#define ATTR_ALIAS(func) __attribute__ ((alias(#func))) - -/// The weakref attribute marks a declaration as a weak reference. It is equivalent with weak + alias attribute, but require function is static -#define ATTR_WEAKREF(func) __attribute__ ((weakref(#func))) - -/// The warn_unused_result attribute causes a warning to be emitted if a caller of the function with this attribute does not use its return value. This is useful for functions where not checking the result is either a security problem or always a bug +/// Warn if a caller of the function with this attribute does not use its return value. #define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) -/// This attribute, attached to a function, means that code must be emitted for the function even if it appears that the function is not referenced. This is useful, for example, when the function is referenced only in inline assembly. -#define ATTR_USED __attribute__ ((used)) - -/// This attribute, attached to a function, means that the function is meant to be possibly unused. GCC does not produce a warning for this function. +/// Function is meant to be possibly unused. GCC does not produce a warning for this function. #define ATTR_UNUSED __attribute__ ((unused)) -/** @} */ - -/** \defgroup Group_BuiltinFunc Built-in Functions -* @{ */ - // TODO mcu specific #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define __n2be(x) __builtin_bswap32(x) ///< built-in function to convert 32-bit from native to Big Endian @@ -124,8 +86,6 @@ #define __be2n_16(u16) __n2be_16(u16) #endif -/** @} */ - #ifdef __cplusplus } #endif diff --git a/src/common/compiler/tusb_compiler_iar.h b/src/common/compiler/tusb_compiler_iar.h index 1f893685..d62a65e2 100644 --- a/src/common/compiler/tusb_compiler_iar.h +++ b/src/common/compiler/tusb_compiler_iar.h @@ -1,6 +1,6 @@ /**************************************************************************/ /*! - @file compiler_iar.h + @file tusb_compiler_iar.h @author hathach (tinyusb.org) @section LICENSE @@ -36,15 +36,6 @@ */ /**************************************************************************/ -/** \file - * \brief IAR Compiler - */ - -/** \ingroup Group_Compiler - * \defgroup Group_IAR IAR ARM - * @{ - */ - #ifndef _TUSB_COMPILER_IAR_H_ #define _TUSB_COMPILER_IAR_H_ @@ -52,24 +43,17 @@ extern "C" { #endif -#define ALIGN_OF(x) __ALIGNOF__(x) -#define ATTR_PREPACKED __packed -#define ATTR_PACKED +#define ALIGN_OF(x) __ALIGNOF__(x) +#define ATTR_ALIGNED(bytes) _Pragma(XSTRING_(data_alignment=##bytes)) //#define ATTR_SECTION(section) _Pragma((#section)) +#define ATTR_PREPACKED __packed +#define ATTR_PACKED -#define ATTR_ALIGNED(bytes) _Pragma(XSTRING_(data_alignment=##bytes)) - -#ifndef ATTR_ALWAYS_INLINE -/// Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level is specified -#define ATTR_ALWAYS_INLINE error -#endif - -#define ATTR_PURE // TODO IAR pure function attribute -#define ATTR_CONST // TODO IAR const function attribute +#define ATTR_ALWAYS_INLINE +#define ATTR_DEPRECATED(mess) #define ATTR_WEAK __weak #define ATTR_WARN_UNUSED_RESULT -#define ATTR_USED #define ATTR_UNUSED // built-in function to convert 32-bit Big-Endian to Little-Endian @@ -86,4 +70,3 @@ #endif /* _TUSB_COMPILER_IAR_H_ */ -/** @} */ diff --git a/src/host/hcd.h b/src/host/hcd.h index e117c20f..8753543d 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -146,7 +146,7 @@ bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], ui bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete); #if 0 -tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT; +tusb_error_t hcd_pipe_cancel(); #endif #ifdef __cplusplus diff --git a/src/host/hub.h b/src/host/hub.h index f8d8a4c6..626cb459 100644 --- a/src/host/hub.h +++ b/src/host/hub.h @@ -195,7 +195,7 @@ bool hub_status_pipe_queue(uint8_t dev_addr); #ifdef _TINY_USB_SOURCE_FILE_ void hub_init(void); -bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; +bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length); void hub_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void hub_close(uint8_t dev_addr); diff --git a/src/host/usbh.c b/src/host/usbh.c index d0b5edb6..4334729e 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -128,8 +128,8 @@ CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4) static uint8_t _usbh_ctrl_buf[CFG_TUSB_HOST //------------- Reporter Task Data -------------// //------------- Helper Function Prototypes -------------// -static inline uint8_t get_new_address(void) ATTR_ALWAYS_INLINE; -static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_desc) ATTR_ALWAYS_INLINE; +static inline uint8_t get_new_address(void); +static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_desc); static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id); //--------------------------------------------------------------------+ diff --git a/src/tusb.h b/src/tusb.h index 3a13bbec..389bf54d 100644 --- a/src/tusb.h +++ b/src/tusb.h @@ -109,6 +109,7 @@ bool tusb_init(void); // backward compatible only. TODO remove later +ATTR_DEPRECATED("Please use either tud_task() or tuh_task()") static inline void tusb_task(void) { #if TUSB_OPT_HOST_ENABLED diff --git a/tests/support/tusb_callback.h b/tests/support/tusb_callback.h index 03fa60b5..bd5a2dac 100644 --- a/tests/support/tusb_callback.h +++ b/tests/support/tusb_callback.h @@ -60,7 +60,7 @@ #include "usbh.h" //------------- core -------------// -uint8_t tusbh_device_attached_cb (tusb_desc_device_t const *p_desc_device) ATTR_WEAK ATTR_WARN_UNUSED_RESULT; +uint8_t tusbh_device_attached_cb (tusb_desc_device_t const *p_desc_device) ATTR_WEAK; void tusbh_device_mount_succeed_cb (uint8_t dev_addr) ATTR_WEAK; void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_desc_device_t const *p_desc_device) ATTR_WEAK; From 2a60427bdc7d23d7c1ab1e687f5a8d9555a69f15 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 14 Dec 2018 15:28:38 +0700 Subject: [PATCH 2/9] rename bit_* helper to tu_bit_*, BIT_* to TU_BIT_* for consistency --- hw/bsp/ea4088qs/board_ea4088qs.c | 6 +- hw/bsp/ea4357/board_ea4357.c | 6 +- hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c | 4 +- hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c | 6 +- hw/bsp/mcb1800/board_mcb1800.c | 6 +- src/class/cdc/cdc_device.c | 4 +- src/class/custom/custom_host.h | 2 +- src/class/hid/hid.h | 36 ++++---- src/class/msc/msc_device.c | 4 +- src/common/binary.h | 55 +++++------- src/common/tusb_types.h | 6 +- src/host/ehci/ehci.c | 14 +-- src/host/ehci/ehci.h | 24 ++--- src/host/hub.c | 4 +- src/host/ohci/ohci.c | 56 ++++++------ src/portable/nordic/nrf5x/dcd_nrf5x.c | 18 ++-- .../nxp/lpc11_13_15/dcd_lpc11_13_15.c | 32 +++---- src/portable/nxp/lpc17_40/dcd_lpc17_40.c | 28 +++--- src/portable/nxp/lpc17_40/dcd_lpc17_40.h | 78 ++++++++--------- src/portable/nxp/lpc18_43/dcd_lpc18_43.c | 10 +-- src/portable/nxp/lpc18_43/dcd_lpc18_43.h | 36 ++++---- tests/lpc175x_6x/test/test_dcd_lpc175x_6x.c | 4 +- .../test/host/cdc/test_cdc_host.c | 6 +- .../test/host/ehci/test_ehci_init.c | 2 +- .../test/host/ehci/test_pipe_interrupt_open.c | 2 +- .../test/host/usbh/test_enum_task.c | 2 +- tests/lpc18xx_43xx/test/host/usbh/test_usbh.c | 4 +- tests/lpc18xx_43xx/test/test_assertion.c | 14 +-- tests/lpc18xx_43xx/test/test_binary.c | 87 ++++++++----------- 29 files changed, 264 insertions(+), 292 deletions(-) diff --git a/hw/bsp/ea4088qs/board_ea4088qs.c b/hw/bsp/ea4088qs/board_ea4088qs.c index 0875a887..d2bf409a 100644 --- a/hw/bsp/ea4088qs/board_ea4088qs.c +++ b/hw/bsp/ea4088qs/board_ea4088qs.c @@ -103,7 +103,7 @@ void board_init(void) Chip_GPIO_SetPinDIROutput(LPC_GPIO, LED_PORT, LED_PIN); //------------- BUTTON -------------// -// for(uint8_t i=0; iwValue, 0), BIT_TEST_(request->wValue, 1)); + if ( tud_cdc_line_state_cb) tud_cdc_line_state_cb(itf, TU_BIT_TEST(request->wValue, 0), TU_BIT_TEST(request->wValue, 1)); break; default: return false; // stall unsupported request diff --git a/src/class/custom/custom_host.h b/src/class/custom/custom_host.h index 5522db58..a5fcb6fb 100644 --- a/src/class/custom/custom_host.h +++ b/src/class/custom/custom_host.h @@ -62,7 +62,7 @@ static inline bool tusbh_custom_is_mounted(uint8_t dev_addr, uint16_t vendor_id, { (void) vendor_id; // TODO check this later (void) product_id; -// return (tusbh_device_get_mounted_class_flag(dev_addr) & BIT_(TUSB_CLASS_MAPPED_INDEX_END-1) ) != 0; +// return (tusbh_device_get_mounted_class_flag(dev_addr) & TU_BIT(TUSB_CLASS_MAPPED_INDEX_END-1) ) != 0; return false; } diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 8bfede2d..2e2b4558 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -173,11 +173,11 @@ typedef struct ATTR_PACKED /// Standard Mouse Buttons Bitmap typedef enum { - MOUSE_BUTTON_LEFT = BIT_(0), ///< Left button - MOUSE_BUTTON_RIGHT = BIT_(1), ///< Right button - MOUSE_BUTTON_MIDDLE = BIT_(2), ///< Middle button - MOUSE_BUTTON_BACKWARD = BIT_(3), ///< Backward button, - MOUSE_BUTTON_FORWARD = BIT_(4), ///< Forward button, + MOUSE_BUTTON_LEFT = TU_BIT(0), ///< Left button + MOUSE_BUTTON_RIGHT = TU_BIT(1), ///< Right button + MOUSE_BUTTON_MIDDLE = TU_BIT(2), ///< Middle button + MOUSE_BUTTON_BACKWARD = TU_BIT(3), ///< Backward button, + MOUSE_BUTTON_FORWARD = TU_BIT(4), ///< Forward button, }hid_mouse_button_bm_t; /// @} @@ -199,23 +199,23 @@ typedef struct ATTR_PACKED /// Keyboard modifier codes bitmap typedef enum { - KEYBOARD_MODIFIER_LEFTCTRL = BIT_(0), ///< Left Control - KEYBOARD_MODIFIER_LEFTSHIFT = BIT_(1), ///< Left Shift - KEYBOARD_MODIFIER_LEFTALT = BIT_(2), ///< Left Alt - KEYBOARD_MODIFIER_LEFTGUI = BIT_(3), ///< Left Window - KEYBOARD_MODIFIER_RIGHTCTRL = BIT_(4), ///< Right Control - KEYBOARD_MODIFIER_RIGHTSHIFT = BIT_(5), ///< Right Shift - KEYBOARD_MODIFIER_RIGHTALT = BIT_(6), ///< Right Alt - KEYBOARD_MODIFIER_RIGHTGUI = BIT_(7) ///< Right Window + KEYBOARD_MODIFIER_LEFTCTRL = TU_BIT(0), ///< Left Control + KEYBOARD_MODIFIER_LEFTSHIFT = TU_BIT(1), ///< Left Shift + KEYBOARD_MODIFIER_LEFTALT = TU_BIT(2), ///< Left Alt + KEYBOARD_MODIFIER_LEFTGUI = TU_BIT(3), ///< Left Window + KEYBOARD_MODIFIER_RIGHTCTRL = TU_BIT(4), ///< Right Control + KEYBOARD_MODIFIER_RIGHTSHIFT = TU_BIT(5), ///< Right Shift + KEYBOARD_MODIFIER_RIGHTALT = TU_BIT(6), ///< Right Alt + KEYBOARD_MODIFIER_RIGHTGUI = TU_BIT(7) ///< Right Window }hid_keyboard_modifier_bm_t; typedef enum { - KEYBOARD_LED_NUMLOCK = BIT_(0), ///< Num Lock LED - KEYBOARD_LED_CAPSLOCK = BIT_(1), ///< Caps Lock LED - KEYBOARD_LED_SCROLLLOCK = BIT_(2), ///< Scroll Lock LED - KEYBOARD_LED_COMPOSE = BIT_(3), ///< Composition Mode - KEYBOARD_LED_KANA = BIT_(4) ///< Kana mode + KEYBOARD_LED_NUMLOCK = TU_BIT(0), ///< Num Lock LED + KEYBOARD_LED_CAPSLOCK = TU_BIT(1), ///< Caps Lock LED + KEYBOARD_LED_SCROLLLOCK = TU_BIT(2), ///< Scroll Lock LED + KEYBOARD_LED_COMPOSE = TU_BIT(3), ///< Composition Mode + KEYBOARD_LED_KANA = TU_BIT(4) ///< Kana mode }hid_keyboard_led_bm_t; /// @} diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index d4d115bc..5d275841 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -385,7 +385,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t p_csw->status = MSC_CSW_STATUS_PASSED; } } - else if ( !BIT_TEST_(p_cbw->dir, 7) ) + else if ( !TU_BIT_TEST(p_cbw->dir, 7) ) { // OUT transfer TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) ); @@ -426,7 +426,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t case MSC_STAGE_DATA: // OUT transfer, invoke callback if needed - if ( !BIT_TEST_(p_cbw->dir, 7) ) + if ( !TU_BIT_TEST(p_cbw->dir, 7) ) { if ( SCSI_CMD_WRITE_10 != p_cbw->command[0] ) { diff --git a/src/common/binary.h b/src/common/binary.h index 7a93ee70..5bc364f2 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 diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index 6f016789..9a6d5a52 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -170,9 +170,9 @@ typedef enum }misc_protocol_type_t; enum { - TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = BIT_(5), - TUSB_DESC_CONFIG_ATT_SELF_POWER = BIT_(6), - TUSB_DESC_CONFIG_ATT_BUS_POWER = BIT_(7) + TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = TU_BIT(5), + TUSB_DESC_CONFIG_ATT_SELF_POWER = TU_BIT(6), + TUSB_DESC_CONFIG_ATT_BUS_POWER = TU_BIT(7) }; #define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2) diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index b46c9bc6..b8f72412 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -260,9 +260,9 @@ static bool ehci_init(uint8_t rhport) regs->nxp_tt_control = 0; //------------- USB CMD Register -------------// - regs->command |= BIT_(EHCI_USBCMD_POS_RUN_STOP) | BIT_(EHCI_USBCMD_POS_ASYNC_ENABLE) - | BIT_(EHCI_USBCMD_POS_PERIOD_ENABLE) // TODO enable period list only there is int/iso endpoint - | ((EHCI_CFG_FRAMELIST_SIZE_BITS & BIN8(011)) << EHCI_USBCMD_POS_FRAMELIST_SZIE) + regs->command |= TU_BIT(EHCI_USBCMD_POS_RUN_STOP) | TU_BIT(EHCI_USBCMD_POS_ASYNC_ENABLE) + | TU_BIT(EHCI_USBCMD_POS_PERIOD_ENABLE) // TODO enable period list only there is int/iso endpoint + | ((EHCI_CFG_FRAMELIST_SIZE_BITS & TU_BIN8(011)) << EHCI_USBCMD_POS_FRAMELIST_SZIE) | ((EHCI_CFG_FRAMELIST_SIZE_BITS >> 2) << EHCI_USBCMD_POS_NXP_FRAMELIST_SIZE_MSB); //------------- ConfigFlag Register (skip) -------------// @@ -791,19 +791,19 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c if ( interval < 4) // sub milisecond interval { p_qhd->interval_ms = 0; - p_qhd->int_smask = (interval == 1) ? BIN8(11111111) : - (interval == 2) ? BIN8(10101010) : BIN8(01000100); + p_qhd->int_smask = (interval == 1) ? TU_BIN8(11111111) : + (interval == 2) ? TU_BIN8(10101010) : TU_BIN8(01000100); }else { p_qhd->interval_ms = (uint8_t) tu_min16( 1 << (interval-4), 255 ); - p_qhd->int_smask = BIT_(interval % 8); + p_qhd->int_smask = TU_BIT(interval % 8); } }else { TU_ASSERT( 0 != interval, ); // Full/Low: 4.12.2.1 (EHCI) case 1 schedule start split at 1 us & complete split at 2,3,4 uframes p_qhd->int_smask = 0x01; - p_qhd->fl_int_cmask = BIN8(11100); + p_qhd->fl_int_cmask = TU_BIN8(11100); p_qhd->interval_ms = interval; } }else diff --git a/src/host/ehci/ehci.h b/src/host/ehci/ehci.h index c1c27479..23bbb310 100644 --- a/src/host/ehci/ehci.h +++ b/src/host/ehci/ehci.h @@ -294,17 +294,17 @@ TU_VERIFY_STATIC( sizeof(ehci_sitd_t) == 32, "size is not correct" ); // EHCI Operational Register //--------------------------------------------------------------------+ enum ehci_interrupt_mask_{ - EHCI_INT_MASK_USB = BIT_(0), - EHCI_INT_MASK_ERROR = BIT_(1), - EHCI_INT_MASK_PORT_CHANGE = BIT_(2), + EHCI_INT_MASK_USB = TU_BIT(0), + EHCI_INT_MASK_ERROR = TU_BIT(1), + EHCI_INT_MASK_PORT_CHANGE = TU_BIT(2), - EHCI_INT_MASK_FRAMELIST_ROLLOVER = BIT_(3), - EHCI_INT_MASK_PCI_HOST_SYSTEM_ERROR = BIT_(4), - EHCI_INT_MASK_ASYNC_ADVANCE = BIT_(5), - EHCI_INT_MASK_NXP_SOF = BIT_(7), + EHCI_INT_MASK_FRAMELIST_ROLLOVER = TU_BIT(3), + EHCI_INT_MASK_PCI_HOST_SYSTEM_ERROR = TU_BIT(4), + EHCI_INT_MASK_ASYNC_ADVANCE = TU_BIT(5), + EHCI_INT_MASK_NXP_SOF = TU_BIT(7), - EHCI_INT_MASK_NXP_ASYNC = BIT_(18), - EHCI_INT_MASK_NXP_PERIODIC = BIT_(19), + EHCI_INT_MASK_NXP_ASYNC = TU_BIT(18), + EHCI_INT_MASK_NXP_PERIODIC = TU_BIT(19), EHCI_INT_MASK_ALL = EHCI_INT_MASK_USB | EHCI_INT_MASK_ERROR | EHCI_INT_MASK_PORT_CHANGE | @@ -323,9 +323,9 @@ enum ehci_usbcmd_pos_ { }; enum ehci_portsc_change_mask_{ - EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE = BIT_(1), - EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE = BIT_(3), - EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE = BIT_(5), + EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE = TU_BIT(1), + EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE = TU_BIT(3), + EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE = TU_BIT(5), EHCI_PORTSC_MASK_ALL = EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE | diff --git a/src/host/hub.c b/src/host/hub.c index 6b87e935..16560a81 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -97,7 +97,7 @@ bool hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t hub_port_status_response_t * p_port_status; p_port_status = (hub_port_status_response_t *) hub_enum_buffer; - TU_ASSERT( !BIT_TEST_(p_port_status->status_change.value, feature-16) ); + TU_ASSERT( !TU_BIT_TEST(p_port_status->status_change.value, feature-16) ); return true; } @@ -225,7 +225,7 @@ void hub_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xf for (uint8_t port=1; port <= p_hub->port_number; port++) { // TODO HUB ignore bit0 hub_status_change - if ( BIT_TEST_(p_hub->status_change, port) ) + if ( TU_BIT_TEST(p_hub->status_change, port) ) { hcd_event_t event = { diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index bebb8a2e..887b3e56 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -65,10 +65,10 @@ enum { enum { OHCI_CONTROL_CONTROL_BULK_RATIO = 3, ///< This specifies the service ratio between Control and Bulk EDs. 0 = 1:1, 3 = 4:1 - OHCI_CONTROL_LIST_PERIODIC_ENABLE_MASK = BIT_(2), - OHCI_CONTROL_LIST_ISOCHRONOUS_ENABLE_MASK = BIT_(3), - OHCI_CONTROL_LIST_CONTROL_ENABLE_MASK = BIT_(4), - OHCI_CONTROL_LIST_BULK_ENABLE_MASK = BIT_(5), + OHCI_CONTROL_LIST_PERIODIC_ENABLE_MASK = TU_BIT(2), + OHCI_CONTROL_LIST_ISOCHRONOUS_ENABLE_MASK = TU_BIT(3), + OHCI_CONTROL_LIST_CONTROL_ENABLE_MASK = TU_BIT(4), + OHCI_CONTROL_LIST_BULK_ENABLE_MASK = TU_BIT(5), }; enum { @@ -81,33 +81,33 @@ enum { }; enum { - OHCI_INT_SCHEDULING_OVERUN_MASK = BIT_(0), - OHCI_INT_WRITEBACK_DONEHEAD_MASK = BIT_(1), - OHCI_INT_SOF_MASK = BIT_(2), - OHCI_INT_RESUME_DETECTED_MASK = BIT_(3), - OHCI_INT_UNRECOVERABLE_ERROR_MASK = BIT_(4), - OHCI_INT_FRAME_OVERFLOW_MASK = BIT_(5), - OHCI_INT_RHPORT_STATUS_CHANGE_MASK = BIT_(6), + OHCI_INT_SCHEDULING_OVERUN_MASK = TU_BIT(0), + OHCI_INT_WRITEBACK_DONEHEAD_MASK = TU_BIT(1), + OHCI_INT_SOF_MASK = TU_BIT(2), + OHCI_INT_RESUME_DETECTED_MASK = TU_BIT(3), + OHCI_INT_UNRECOVERABLE_ERROR_MASK = TU_BIT(4), + OHCI_INT_FRAME_OVERFLOW_MASK = TU_BIT(5), + OHCI_INT_RHPORT_STATUS_CHANGE_MASK = TU_BIT(6), - OHCI_INT_OWNERSHIP_CHANGE_MASK = BIT_(30), - OHCI_INT_MASTER_ENABLE_MASK = BIT_(31), + OHCI_INT_OWNERSHIP_CHANGE_MASK = TU_BIT(30), + OHCI_INT_MASTER_ENABLE_MASK = TU_BIT(31), }; enum { - OHCI_RHPORT_CURRENT_CONNECT_STATUS_MASK = BIT_(0), - OHCI_RHPORT_PORT_ENABLE_STATUS_MASK = BIT_(1), - OHCI_RHPORT_PORT_SUSPEND_STATUS_MASK = BIT_(2), - OHCI_RHPORT_PORT_OVER_CURRENT_INDICATOR_MASK = BIT_(3), - OHCI_RHPORT_PORT_RESET_STATUS_MASK = BIT_(4), ///< write '1' to reset port + OHCI_RHPORT_CURRENT_CONNECT_STATUS_MASK = TU_BIT(0), + OHCI_RHPORT_PORT_ENABLE_STATUS_MASK = TU_BIT(1), + OHCI_RHPORT_PORT_SUSPEND_STATUS_MASK = TU_BIT(2), + OHCI_RHPORT_PORT_OVER_CURRENT_INDICATOR_MASK = TU_BIT(3), + OHCI_RHPORT_PORT_RESET_STATUS_MASK = TU_BIT(4), ///< write '1' to reset port - OHCI_RHPORT_PORT_POWER_STATUS_MASK = BIT_(8), - OHCI_RHPORT_LOW_SPEED_DEVICE_ATTACHED_MASK = BIT_(9), + OHCI_RHPORT_PORT_POWER_STATUS_MASK = TU_BIT(8), + OHCI_RHPORT_LOW_SPEED_DEVICE_ATTACHED_MASK = TU_BIT(9), - OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK = BIT_(16), - OHCI_RHPORT_PORT_ENABLE_CHANGE_MASK = BIT_(17), - OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK = BIT_(18), - OHCI_RHPORT_OVER_CURRENT_CHANGE_MASK = BIT_(19), - OHCI_RHPORT_PORT_RESET_CHANGE_MASK = BIT_(20), + OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK = TU_BIT(16), + OHCI_RHPORT_PORT_ENABLE_CHANGE_MASK = TU_BIT(17), + OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK = TU_BIT(18), + OHCI_RHPORT_OVER_CURRENT_CHANGE_MASK = TU_BIT(19), + OHCI_RHPORT_PORT_RESET_CHANGE_MASK = TU_BIT(20), OHCI_RHPORT_ALL_CHANGE_MASK = OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK | OHCI_RHPORT_PORT_ENABLE_CHANGE_MASK | OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK | OHCI_RHPORT_OVER_CURRENT_CHANGE_MASK | OHCI_RHPORT_PORT_RESET_CHANGE_MASK @@ -131,7 +131,7 @@ enum { enum { OHCI_INT_ON_COMPLETE_YES = 0, - OHCI_INT_ON_COMPLETE_NO = BIN8(111) + OHCI_INT_ON_COMPLETE_NO = TU_BIN8(111) }; //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION @@ -300,7 +300,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet gtd_init(p_setup, (void*) setup_packet, 8); p_setup->index = dev_addr; p_setup->pid = OHCI_PID_SETUP; - p_setup->data_toggle = BIN8(10); // DATA0 + p_setup->data_toggle = TU_BIN8(10); // DATA0 p_setup->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; //------------- Attach TDs list to Control Endpoint -------------// @@ -328,7 +328,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * p_data->index = dev_addr; p_data->pid = dir ? OHCI_PID_IN : OHCI_PID_OUT; - p_data->data_toggle = BIN8(11); // DATA1 + p_data->data_toggle = TU_BIN8(11); // DATA1 p_data->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; p_ed->td_head.address = (uint32_t) p_data; diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index ad5090eb..7d13ef8c 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -232,12 +232,12 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt) if ( dir == TUSB_DIR_OUT ) { - NRF_USBD->INTENSET = BIT_(USBD_INTEN_ENDEPOUT0_Pos + epnum); - NRF_USBD->EPOUTEN |= BIT_(epnum); + NRF_USBD->INTENSET = TU_BIT(USBD_INTEN_ENDEPOUT0_Pos + epnum); + NRF_USBD->EPOUTEN |= TU_BIT(epnum); }else { - NRF_USBD->INTENSET = BIT_(USBD_INTEN_ENDEPIN0_Pos + epnum); - NRF_USBD->EPINEN |= BIT_(epnum); + NRF_USBD->INTENSET = TU_BIT(USBD_INTEN_ENDEPIN0_Pos + epnum); + NRF_USBD->EPINEN |= TU_BIT(epnum); } __ISB(); __DSB(); @@ -368,9 +368,9 @@ void USBD_IRQHandler(void) for(uint8_t i=0; iEPOUT[epnum].AMOUNT; @@ -485,7 +485,7 @@ void USBD_IRQHandler(void) // CBI In: Endpoint -> Host (transaction complete) for(uint8_t epnum=0; epnum<8; epnum++) { - if ( BIT_TEST_(data_status, epnum ) || ( epnum == 0 && is_control_in) ) + if ( TU_BIT_TEST(data_status, epnum ) || ( epnum == 0 && is_control_in) ) { xfer_td_t* xfer = get_td(epnum, TUSB_DIR_IN); @@ -506,7 +506,7 @@ void USBD_IRQHandler(void) // CBI OUT: Host -> Endpoint for(uint8_t epnum=0; epnum<8; epnum++) { - if ( BIT_TEST_(data_status, 16+epnum ) || ( epnum == 0 && is_control_out) ) + if ( TU_BIT_TEST(data_status, 16+epnum ) || ( epnum == 0 && is_control_out) ) { xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT); diff --git a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c index c910bf1e..26ecaf8b 100644 --- a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c +++ b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c @@ -64,20 +64,20 @@ enum { }; enum { - INT_SOF_MASK = BIT_(30), - INT_DEVICE_STATUS_MASK = BIT_(31) + INT_SOF_MASK = TU_BIT(30), + INT_DEVICE_STATUS_MASK = TU_BIT(31) }; enum { - CMDSTAT_DEVICE_ADDR_MASK = BIT_(7 )-1, - CMDSTAT_DEVICE_ENABLE_MASK = BIT_(7 ), - CMDSTAT_SETUP_RECEIVED_MASK = BIT_(8 ), - CMDSTAT_DEVICE_CONNECT_MASK = BIT_(16), ///< reflect the softconnect only, does not reflect the actual attached state - CMDSTAT_DEVICE_SUSPEND_MASK = BIT_(17), - CMDSTAT_CONNECT_CHANGE_MASK = BIT_(24), - CMDSTAT_SUSPEND_CHANGE_MASK = BIT_(25), - CMDSTAT_RESET_CHANGE_MASK = BIT_(26), - CMDSTAT_VBUS_DEBOUNCED_MASK = BIT_(28), + CMDSTAT_DEVICE_ADDR_MASK = TU_BIT(7 )-1, + CMDSTAT_DEVICE_ENABLE_MASK = TU_BIT(7 ), + CMDSTAT_SETUP_RECEIVED_MASK = TU_BIT(8 ), + CMDSTAT_DEVICE_CONNECT_MASK = TU_BIT(16), ///< reflect the softconnect only, does not reflect the actual attached state + CMDSTAT_DEVICE_SUSPEND_MASK = TU_BIT(17), + CMDSTAT_CONNECT_CHANGE_MASK = TU_BIT(24), + CMDSTAT_SUSPEND_CHANGE_MASK = TU_BIT(25), + CMDSTAT_RESET_CHANGE_MASK = TU_BIT(26), + CMDSTAT_VBUS_DEBOUNCED_MASK = TU_BIT(28), }; typedef struct ATTR_PACKED @@ -237,7 +237,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) _dcd.ep[ep_id][0].is_iso = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS); // Enable EP interrupt - LPC_USB->INTEN |= BIT_(ep_id); + LPC_USB->INTEN |= TU_BIT(ep_id); return true; } @@ -296,14 +296,14 @@ static void bus_reset(void) LPC_USB->INTSTAT = LPC_USB->INTSTAT; // clear all pending interrupt LPC_USB->DEVCMDSTAT |= CMDSTAT_SETUP_RECEIVED_MASK; // clear setup received interrupt - LPC_USB->INTEN = INT_DEVICE_STATUS_MASK | BIT_(0) | BIT_(1); // enable device status & control endpoints + LPC_USB->INTEN = INT_DEVICE_STATUS_MASK | TU_BIT(0) | TU_BIT(1); // enable device status & control endpoints } static void process_xfer_isr(uint32_t int_status) { for(uint8_t ep_id = 0; ep_id < EP_COUNT; ep_id++ ) { - if ( BIT_TEST_(int_status, ep_id) ) + if ( TU_BIT_TEST(int_status, ep_id) ) { ep_cmd_sts_t * ep_cs = &_dcd.ep[ep_id][0]; xfer_dma_t* xfer_dma = &_dcd.dma[ep_id]; @@ -378,7 +378,7 @@ void USB_IRQHandler(void) } // Setup Receive - if ( BIT_TEST_(int_status, 0) && (dev_cmd_stat & CMDSTAT_SETUP_RECEIVED_MASK) ) + if ( TU_BIT_TEST(int_status, 0) && (dev_cmd_stat & CMDSTAT_SETUP_RECEIVED_MASK) ) { // Follow UM flowchart to clear Active & Stall on both Control IN/OUT endpoints _dcd.ep[0][0].active = _dcd.ep[1][0].active = 0; @@ -392,7 +392,7 @@ void USB_IRQHandler(void) _dcd.ep[0][1].buffer_offset = get_buf_offset(_dcd.setup_packet); // clear bit0 - int_status = BIT_CLR_(int_status, 0); + int_status = TU_BIT_CLEAR(int_status, 0); } // Endpoint transfer complete interrupt diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index 82d3c3ca..fca2c355 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -148,7 +148,7 @@ static inline uint8_t ep_addr2idx(uint8_t ep_addr) static void set_ep_size(uint8_t ep_id, uint16_t max_packet_size) { // follows example in 11.10.4.2 - LPC_USB->ReEp |= BIT_(ep_id); + LPC_USB->ReEp |= TU_BIT(ep_id); LPC_USB->EpInd = ep_id; // select index before setting packet size LPC_USB->MaxPSize = max_packet_size; @@ -419,15 +419,15 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t t if ( ep_id % 2 ) { // Clear EP interrupt before Enable DMA - LPC_USB->EpIntEn &= ~BIT_(ep_id); - LPC_USB->EpDMAEn = BIT_(ep_id); + LPC_USB->EpIntEn &= ~TU_BIT(ep_id); + LPC_USB->EpDMAEn = TU_BIT(ep_id); // endpoint IN need to actively raise DMA request - LPC_USB->DMARSet = BIT_(ep_id); + LPC_USB->DMARSet = TU_BIT(ep_id); }else { // Enable DMA - LPC_USB->EpDMAEn = BIT_(ep_id); + LPC_USB->EpDMAEn = TU_BIT(ep_id); } return true; @@ -442,11 +442,11 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t t static void control_xfer_isr(uint8_t rhport, uint32_t ep_int_status) { // Control out complete - if ( ep_int_status & BIT_(0) ) + if ( ep_int_status & TU_BIT(0) ) { bool is_setup = sie_read(SIE_CMDCODE_ENDPOINT_SELECT+0) & SIE_SELECT_ENDPOINT_SETUP_RECEIVED_MASK; - LPC_USB->EpIntClr = BIT_(0); + LPC_USB->EpIntClr = TU_BIT(0); if (is_setup) { @@ -472,9 +472,9 @@ static void control_xfer_isr(uint8_t rhport, uint32_t ep_int_status) } // Control In complete - if ( ep_int_status & BIT_(1) ) + if ( ep_int_status & TU_BIT(1) ) { - LPC_USB->EpIntClr = BIT_(1); + LPC_USB->EpIntClr = TU_BIT(1); dcd_event_xfer_complete(rhport, TUSB_DIR_IN_MASK, _dcd.control.in_bytes, XFER_RESULT_SUCCESS, true); } } @@ -546,12 +546,12 @@ void hal_dcd_isr(uint8_t rhport) { for ( uint8_t ep_id = 3; ep_id < DCD_ENDPOINT_MAX; ep_id += 2 ) { - if ( BIT_TEST_(ep_int_status, ep_id) ) + if ( TU_BIT_TEST(ep_int_status, ep_id) ) { - LPC_USB->EpIntClr = BIT_(ep_id); + LPC_USB->EpIntClr = TU_BIT(ep_id); // Clear Ep interrupt for next DMA - LPC_USB->EpIntEn &= ~BIT_(ep_id); + LPC_USB->EpIntEn &= ~TU_BIT(ep_id); dd_complete_isr(rhport, ep_id); } @@ -569,12 +569,12 @@ void hal_dcd_isr(uint8_t rhport) for ( uint8_t ep_id = 2; ep_id < DCD_ENDPOINT_MAX; ep_id++ ) { - if ( BIT_TEST_(eot, ep_id) ) + if ( TU_BIT_TEST(eot, ep_id) ) { if ( ep_id & 0x01 ) { // IN enable EpInt for end of usb transfer - LPC_USB->EpIntEn |= BIT_(ep_id); + LPC_USB->EpIntEn |= TU_BIT(ep_id); }else { // OUT diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.h b/src/portable/nxp/lpc17_40/dcd_lpc17_40.h index d6b76fcd..eac8ec99 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.h +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.h @@ -51,45 +51,45 @@ //------------- USB Interrupt USBIntSt -------------// //enum { -// DCD_USB_REQ_LOW_PRIO_MASK = BIT_(0), -// DCD_USB_REQ_HIGH_PRIO_MASK = BIT_(1), -// DCD_USB_REQ_DMA_MASK = BIT_(2), -// DCD_USB_REQ_NEED_CLOCK_MASK = BIT_(8), -// DCD_USB_REQ_ENABLE_MASK = BIT_(31) +// DCD_USB_REQ_LOW_PRIO_MASK = TU_BIT(0), +// DCD_USB_REQ_HIGH_PRIO_MASK = TU_BIT(1), +// DCD_USB_REQ_DMA_MASK = TU_BIT(2), +// DCD_USB_REQ_NEED_CLOCK_MASK = TU_BIT(8), +// DCD_USB_REQ_ENABLE_MASK = TU_BIT(31) //}; //------------- Device Interrupt USBDevInt -------------// enum { - DEV_INT_FRAME_MASK = BIT_(0), - DEV_INT_ENDPOINT_FAST_MASK = BIT_(1), - DEV_INT_ENDPOINT_SLOW_MASK = BIT_(2), - DEV_INT_DEVICE_STATUS_MASK = BIT_(3), - DEV_INT_COMMAND_CODE_EMPTY_MASK = BIT_(4), - DEV_INT_COMMAND_DATA_FULL_MASK = BIT_(5), - DEV_INT_RX_ENDPOINT_PACKET_MASK = BIT_(6), - DEV_INT_TX_ENDPOINT_PACKET_MASK = BIT_(7), - DEV_INT_ENDPOINT_REALIZED_MASK = BIT_(8), - DEV_INT_ERROR_MASK = BIT_(9) + DEV_INT_FRAME_MASK = TU_BIT(0), + DEV_INT_ENDPOINT_FAST_MASK = TU_BIT(1), + DEV_INT_ENDPOINT_SLOW_MASK = TU_BIT(2), + DEV_INT_DEVICE_STATUS_MASK = TU_BIT(3), + DEV_INT_COMMAND_CODE_EMPTY_MASK = TU_BIT(4), + DEV_INT_COMMAND_DATA_FULL_MASK = TU_BIT(5), + DEV_INT_RX_ENDPOINT_PACKET_MASK = TU_BIT(6), + DEV_INT_TX_ENDPOINT_PACKET_MASK = TU_BIT(7), + DEV_INT_ENDPOINT_REALIZED_MASK = TU_BIT(8), + DEV_INT_ERROR_MASK = TU_BIT(9) }; //------------- DMA Interrupt USBDMAInt-------------// enum { - DMA_INT_END_OF_XFER_MASK = BIT_(0), - DMA_INT_NEW_DD_REQUEST_MASK = BIT_(1), - DMA_INT_ERROR_MASK = BIT_(2) + DMA_INT_END_OF_XFER_MASK = TU_BIT(0), + DMA_INT_NEW_DD_REQUEST_MASK = TU_BIT(1), + DMA_INT_ERROR_MASK = TU_BIT(2) }; //------------- USBCtrl -------------// enum { - USBCTRL_READ_ENABLE_MASK = BIT_(0), - USBCTRL_WRITE_ENABLE_MASK = BIT_(1), + USBCTRL_READ_ENABLE_MASK = TU_BIT(0), + USBCTRL_WRITE_ENABLE_MASK = TU_BIT(1), }; //------------- USBRxPLen -------------// enum { - USBRXPLEN_PACKET_LENGTH_MASK = (BIT_(10)-1), - USBRXPLEN_DATA_VALID_MASK = BIT_(10), - USBRXPLEN_PACKET_READY_MASK = BIT_(11), + USBRXPLEN_PACKET_LENGTH_MASK = (TU_BIT(10)-1), + USBRXPLEN_DATA_VALID_MASK = TU_BIT(10), + USBRXPLEN_PACKET_READY_MASK = TU_BIT(11), }; //------------- SIE Command Code -------------// @@ -121,30 +121,30 @@ enum { //------------- SIE Device Status (get/set from SIE_CMDCODE_DEVICE_STATUS) -------------// enum { - SIE_DEV_STATUS_CONNECT_STATUS_MASK = BIT_(0), - SIE_DEV_STATUS_CONNECT_CHANGE_MASK = BIT_(1), - SIE_DEV_STATUS_SUSPEND_MASK = BIT_(2), - SIE_DEV_STATUS_SUSPEND_CHANGE_MASK = BIT_(3), - SIE_DEV_STATUS_RESET_MASK = BIT_(4) + SIE_DEV_STATUS_CONNECT_STATUS_MASK = TU_BIT(0), + SIE_DEV_STATUS_CONNECT_CHANGE_MASK = TU_BIT(1), + SIE_DEV_STATUS_SUSPEND_MASK = TU_BIT(2), + SIE_DEV_STATUS_SUSPEND_CHANGE_MASK = TU_BIT(3), + SIE_DEV_STATUS_RESET_MASK = TU_BIT(4) }; //------------- SIE Select Endpoint Command -------------// enum { - SIE_SELECT_ENDPOINT_FULL_EMPTY_MASK = BIT_(0), // 0: empty, 1 full. IN endpoint checks empty, OUT endpoint check full - SIE_SELECT_ENDPOINT_STALL_MASK = BIT_(1), - SIE_SELECT_ENDPOINT_SETUP_RECEIVED_MASK = BIT_(2), // clear by SIE_CMDCODE_ENDPOINT_SELECT_CLEAR_INTERRUPT - SIE_SELECT_ENDPOINT_PACKET_OVERWRITTEN_MASK = BIT_(3), // previous packet is overwritten by a SETUP packet - SIE_SELECT_ENDPOINT_NAK_MASK = BIT_(4), // last packet response is NAK (auto clear by an ACK) - SIE_SELECT_ENDPOINT_BUFFER1_FULL_MASK = BIT_(5), - SIE_SELECT_ENDPOINT_BUFFER2_FULL_MASK = BIT_(6) + SIE_SELECT_ENDPOINT_FULL_EMPTY_MASK = TU_BIT(0), // 0: empty, 1 full. IN endpoint checks empty, OUT endpoint check full + SIE_SELECT_ENDPOINT_STALL_MASK = TU_BIT(1), + SIE_SELECT_ENDPOINT_SETUP_RECEIVED_MASK = TU_BIT(2), // clear by SIE_CMDCODE_ENDPOINT_SELECT_CLEAR_INTERRUPT + SIE_SELECT_ENDPOINT_PACKET_OVERWRITTEN_MASK = TU_BIT(3), // previous packet is overwritten by a SETUP packet + SIE_SELECT_ENDPOINT_NAK_MASK = TU_BIT(4), // last packet response is NAK (auto clear by an ACK) + SIE_SELECT_ENDPOINT_BUFFER1_FULL_MASK = TU_BIT(5), + SIE_SELECT_ENDPOINT_BUFFER2_FULL_MASK = TU_BIT(6) }; typedef enum { - SIE_SET_ENDPOINT_STALLED_MASK = BIT_(0), - SIE_SET_ENDPOINT_DISABLED_MASK = BIT_(5), - SIE_SET_ENDPOINT_RATE_FEEDBACK_MASK = BIT_(6), - SIE_SET_ENDPOINT_CONDITION_STALLED_MASK = BIT_(7), + SIE_SET_ENDPOINT_STALLED_MASK = TU_BIT(0), + SIE_SET_ENDPOINT_DISABLED_MASK = TU_BIT(5), + SIE_SET_ENDPOINT_RATE_FEEDBACK_MASK = TU_BIT(6), + SIE_SET_ENDPOINT_CONDITION_STALLED_MASK = TU_BIT(7), }sie_endpoint_set_status_mask_t; //------------- DMA Descriptor Status -------------// diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c index 70b34d84..7761d547 100644 --- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c @@ -94,7 +94,7 @@ static dcd_data_t* const dcd_data_ptr[2] = //--------------------------------------------------------------------+ void dcd_set_address(uint8_t rhport, uint8_t dev_addr) { - LPC_USB[rhport]->DEVICEADDR = (dev_addr << 25) | BIT_(24); + LPC_USB[rhport]->DEVICEADDR = (dev_addr << 25) | TU_BIT(24); } void dcd_set_config(uint8_t rhport, uint8_t config_num) @@ -158,7 +158,7 @@ bool dcd_init(uint8_t rhport) lpc_usb->USBINTR_D = INT_MASK_USB | INT_MASK_ERROR | INT_MASK_PORT_CHANGE | INT_MASK_RESET | INT_MASK_SUSPEND | INT_MASK_SOF; lpc_usb->USBCMD_D &= ~0x00FF0000; // Interrupt Threshold Interval = 0 - lpc_usb->USBCMD_D |= BIT_(0); // connect + lpc_usb->USBCMD_D |= TU_BIT(0); // connect return true; } @@ -284,7 +284,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t t { // follows UM 24.10.8.1.1 Setup packet handling using setup lockout mechanism // wait until ENDPTSETUPSTAT before priming data/status in response TODO add time out - while(LPC_USB[rhport]->ENDPTSETUPSTAT & BIT_(0)) {} + while(LPC_USB[rhport]->ENDPTSETUPSTAT & TU_BIT(0)) {} } dcd_qhd_t * p_qhd = &dcd_data_ptr[rhport]->qhd[ep_idx]; @@ -296,7 +296,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t t p_qhd->qtd_overlay.next = (uint32_t) p_qtd; // link qtd to qhd // start transfer - LPC_USB[rhport]->ENDPTPRIME = BIT_( ep_idx2bit(ep_idx) ) ; + LPC_USB[rhport]->ENDPTPRIME = TU_BIT( ep_idx2bit(ep_idx) ) ; return true; } @@ -363,7 +363,7 @@ void hal_dcd_isr(uint8_t rhport) { for(uint8_t ep_idx = 0; ep_idx < QHD_MAX; ep_idx++) { - if ( BIT_TEST_(edpt_complete, ep_idx2bit(ep_idx)) ) + if ( TU_BIT_TEST(edpt_complete, ep_idx2bit(ep_idx)) ) { // 23.10.12.3 Failed QTD also get ENDPTCOMPLETE set dcd_qtd_t * p_qtd = &dcd_data_ptr[rhport]->qtd[ep_idx]; diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.h b/src/portable/nxp/lpc18_43/dcd_lpc18_43.h index faf0e3b0..c380be72 100644 --- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.h +++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.h @@ -55,37 +55,37 @@ /*---------- ENDPTCTRL ----------*/ enum { - ENDPTCTRL_MASK_STALL = BIT_(0), - ENDPTCTRL_MASK_TOGGLE_INHIBIT = BIT_(5), ///< used for test only - ENDPTCTRL_MASK_TOGGLE_RESET = BIT_(6), - ENDPTCTRL_MASK_ENABLE = BIT_(7) + ENDPTCTRL_MASK_STALL = TU_BIT(0), + ENDPTCTRL_MASK_TOGGLE_INHIBIT = TU_BIT(5), ///< used for test only + ENDPTCTRL_MASK_TOGGLE_RESET = TU_BIT(6), + ENDPTCTRL_MASK_ENABLE = TU_BIT(7) }; /*---------- USBCMD ----------*/ enum { - USBCMD_MASK_RUN_STOP = BIT_(0), - USBCMD_MASK_RESET = BIT_(1), - USBCMD_MASK_SETUP_TRIPWIRE = BIT_(13), - USBCMD_MASK_ADD_QTD_TRIPWIRE = BIT_(14) ///< This bit is used as a semaphore to ensure the to proper addition of a new dTD to an active (primed) endpoint’s linked list. This bit is set and cleared by software during the process of adding a new dTD + USBCMD_MASK_RUN_STOP = TU_BIT(0), + USBCMD_MASK_RESET = TU_BIT(1), + USBCMD_MASK_SETUP_TRIPWIRE = TU_BIT(13), + USBCMD_MASK_ADD_QTD_TRIPWIRE = TU_BIT(14) ///< This bit is used as a semaphore to ensure the to proper addition of a new dTD to an active (primed) endpoint’s linked list. This bit is set and cleared by software during the process of adding a new dTD }; // Interrupt Threshold bit 23:16 /*---------- USBSTS, USBINTR ----------*/ enum { - INT_MASK_USB = BIT_(0), - INT_MASK_ERROR = BIT_(1), - INT_MASK_PORT_CHANGE = BIT_(2), - INT_MASK_RESET = BIT_(6), - INT_MASK_SOF = BIT_(7), - INT_MASK_SUSPEND = BIT_(8), - INT_MASK_NAK = BIT_(16) + INT_MASK_USB = TU_BIT(0), + INT_MASK_ERROR = TU_BIT(1), + INT_MASK_PORT_CHANGE = TU_BIT(2), + INT_MASK_RESET = TU_BIT(6), + INT_MASK_SOF = TU_BIT(7), + INT_MASK_SUSPEND = TU_BIT(8), + INT_MASK_NAK = TU_BIT(16) }; //------------- PORTSC -------------// enum { - PORTSC_CURRENT_CONNECT_STATUS_MASK = BIT_(0), - PORTSC_FORCE_PORT_RESUME_MASK = BIT_(6), - PORTSC_SUSPEND_MASK = BIT_(7) + PORTSC_CURRENT_CONNECT_STATUS_MASK = TU_BIT(0), + PORTSC_FORCE_PORT_RESUME_MASK = TU_BIT(6), + PORTSC_SUSPEND_MASK = TU_BIT(7) }; typedef struct diff --git a/tests/lpc175x_6x/test/test_dcd_lpc175x_6x.c b/tests/lpc175x_6x/test/test_dcd_lpc175x_6x.c index 31baa5f5..f61556c2 100644 --- a/tests/lpc175x_6x/test/test_dcd_lpc175x_6x.c +++ b/tests/lpc175x_6x/test/test_dcd_lpc175x_6x.c @@ -99,7 +99,7 @@ void test_dcd_init(void) dcd_init(); //------------- slave check -------------// - TEST_ASSERT_EQUAL_HEX( BIN8(11), LPC_USB->USBEpIntEn ); + TEST_ASSERT_EQUAL_HEX( TU_BIN8(11), LPC_USB->USBEpIntEn ); TEST_ASSERT_EQUAL_HEX( DEV_INT_DEVICE_STATUS_MASK | DEV_INT_ENDPOINT_SLOW_MASK | DEV_INT_ERROR_MASK, LPC_USB->USBDevIntEn ); TEST_ASSERT_EQUAL_HEX( 0, LPC_USB->USBEpIntPri); @@ -135,7 +135,7 @@ void test_dcd_configure_endpoint_in(void) dcd_pipe_open(0, &desc_endpoint); uint8_t const phy_ep = 2*3 + 1; - TEST_ASSERT_EQUAL_HEX( BIT_(phy_ep), LPC_USB->USBReEp); + TEST_ASSERT_EQUAL_HEX( TU_BIT(phy_ep), LPC_USB->USBReEp); TEST_ASSERT_EQUAL_HEX( phy_ep, LPC_USB->USBEpInd); TEST_ASSERT_EQUAL( desc_endpoint.wMaxPacketSize.size, LPC_USB->USBMaxPSize); diff --git a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c index 1f841046..25d74d86 100644 --- a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c +++ b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c @@ -216,7 +216,7 @@ void test_cdc_serial_is_mounted_not_configured(void) void test_cdc_serial_is_mounted_protocol_zero(void) { - tusbh_device_get_mounted_class_flag_ExpectAndReturn(dev_addr, BIT_(TUSB_CLASS_CDC) ); + tusbh_device_get_mounted_class_flag_ExpectAndReturn(dev_addr, TU_BIT(TUSB_CLASS_CDC) ); cdch_data[0].interface_protocol = 0; TEST_ASSERT_FALSE( tusbh_cdc_serial_is_mounted(dev_addr) ); @@ -224,7 +224,7 @@ void test_cdc_serial_is_mounted_protocol_zero(void) void test_cdc_serial_is_mounted_protocol_is_vendor(void) { - tusbh_device_get_mounted_class_flag_ExpectAndReturn(dev_addr, BIT_(TUSB_CLASS_CDC) ); + tusbh_device_get_mounted_class_flag_ExpectAndReturn(dev_addr, TU_BIT(TUSB_CLASS_CDC) ); cdch_data[0].interface_protocol = 0xff; TEST_ASSERT_FALSE( tusbh_cdc_serial_is_mounted(dev_addr) ); @@ -232,7 +232,7 @@ void test_cdc_serial_is_mounted_protocol_is_vendor(void) void test_cdc_serial_is_mounted_protocol_is_at_command(void) { - tusbh_device_get_mounted_class_flag_ExpectAndReturn(dev_addr, BIT_(TUSB_CLASS_CDC) ); + tusbh_device_get_mounted_class_flag_ExpectAndReturn(dev_addr, TU_BIT(TUSB_CLASS_CDC) ); cdch_data[0].interface_protocol = CDC_COMM_PROTOCOL_ATCOMMAND; TEST_ASSERT( tusbh_cdc_serial_is_mounted(dev_addr) ); diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_ehci_init.c b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_init.c index 8d552cb8..5047e98c 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_ehci_init.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_init.c @@ -167,7 +167,7 @@ void test_hcd_init_usbcmd(void) TEST_ASSERT(regs->usb_cmd_bit.periodic_enable); //------------- Framelist size (NXP specific) -------------// - TEST_ASSERT_BITS(BIN8(11), EHCI_CFG_FRAMELIST_SIZE_BITS, regs->usb_cmd_bit.framelist_size); + TEST_ASSERT_BITS(TU_BIN8(11), EHCI_CFG_FRAMELIST_SIZE_BITS, regs->usb_cmd_bit.framelist_size); TEST_ASSERT_EQUAL(EHCI_CFG_FRAMELIST_SIZE_BITS >> 2, regs->usb_cmd_bit.nxp_framelist_size_msb); } diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c index ff6dfef8..24fddf65 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c @@ -166,7 +166,7 @@ void test_open_interrupt_hs_interval_1(void) p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(0 , p_int_qhd->interval_ms); - TEST_ASSERT_EQUAL(BIN8(11111111) , p_int_qhd->interrupt_smask); + TEST_ASSERT_EQUAL(TU_BIN8(11111111) , p_int_qhd->interrupt_smask); check_int_endpoint_link(period_head_arr, p_int_qhd); } diff --git a/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c b/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c index 096e10ac..262dbe9e 100644 --- a/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c +++ b/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c @@ -334,6 +334,6 @@ void test_enum_set_configure(void) usbh_enumeration_task(NULL); - TEST_ASSERT_EQUAL( BIT_(TUSB_CLASS_HID) | BIT_(TUSB_CLASS_MSC) | BIT_(TUSB_CLASS_CDC), + TEST_ASSERT_EQUAL( TU_BIT(TUSB_CLASS_HID) | TU_BIT(TUSB_CLASS_MSC) | TU_BIT(TUSB_CLASS_CDC), _usbh_devices[1].flag_supported_class); // TODO change later } diff --git a/tests/lpc18xx_43xx/test/host/usbh/test_usbh.c b/tests/lpc18xx_43xx/test/host/usbh/test_usbh.c index 5a673fb0..7b5d06c3 100644 --- a/tests/lpc18xx_43xx/test/host/usbh/test_usbh.c +++ b/tests/lpc18xx_43xx/test/host/usbh/test_usbh.c @@ -162,7 +162,7 @@ void test_hcd_event_device_remove(void) _usbh_devices[dev_addr].core_id = 0; _usbh_devices[dev_addr].hub_addr = 0; _usbh_devices[dev_addr].hub_port = 0; - _usbh_devices[dev_addr].flag_supported_class = BIT_(TUSB_CLASS_HID); + _usbh_devices[dev_addr].flag_supported_class = TU_BIT(TUSB_CLASS_HID); hidh_close_Expect(dev_addr); hcd_pipe_control_close_ExpectAndReturn(dev_addr, TUSB_ERROR_NONE); @@ -181,7 +181,7 @@ void test_usbh_device_unplugged_multple_class(void) _usbh_devices[dev_addr].core_id = 0; _usbh_devices[dev_addr].hub_addr = 0; _usbh_devices[dev_addr].hub_port = 0; - _usbh_devices[dev_addr].flag_supported_class = BIT_(TUSB_CLASS_HID) | BIT_(TUSB_CLASS_MSC) | BIT_(TUSB_CLASS_CDC); + _usbh_devices[dev_addr].flag_supported_class = TU_BIT(TUSB_CLASS_HID) | TU_BIT(TUSB_CLASS_MSC) | TU_BIT(TUSB_CLASS_CDC); cdch_close_Expect(dev_addr); hidh_close_Expect(dev_addr); diff --git a/tests/lpc18xx_43xx/test/test_assertion.c b/tests/lpc18xx_43xx/test/test_assertion.c index 2b465d07..a01c41d1 100644 --- a/tests/lpc18xx_43xx/test/test_assertion.c +++ b/tests/lpc18xx_43xx/test/test_assertion.c @@ -274,17 +274,17 @@ void test_assert_bin_equal(void) { Try { - ASSERT_BIN8 (BIN8(11110000), BIN8(11110000), __LINE__); - ASSERT_BIN8_EQUAL (BIN8(00001111), BIN8(00001111), __LINE__); + ASSERT_BIN8 (TU_BIN8(11110000), TU_BIN8(11110000), __LINE__); + ASSERT_BIN8_EQUAL (TU_BIN8(00001111), TU_BIN8(00001111), __LINE__); // test side effect - uint32_t x = BIN8(11001100); - uint32_t y = BIN8(11001100); + uint32_t x = TU_BIN8(11001100); + uint32_t y = TU_BIN8(11001100); ASSERT_BIN8 (x++, y++, __LINE__); - TEST_ASSERT_EQUAL(BIN8(11001101), x); - TEST_ASSERT_EQUAL(BIN8(11001101), y); + TEST_ASSERT_EQUAL(TU_BIN8(11001101), x); + TEST_ASSERT_EQUAL(TU_BIN8(11001101), y); - ASSERT_BIN8(BIN8(11001111), BIN8(11111100), 0); + ASSERT_BIN8(TU_BIN8(11001111), TU_BIN8(11111100), 0); } Catch(e) { diff --git a/tests/lpc18xx_43xx/test/test_binary.c b/tests/lpc18xx_43xx/test/test_binary.c index fb61df0f..fbe2083b 100644 --- a/tests/lpc18xx_43xx/test/test_binary.c +++ b/tests/lpc18xx_43xx/test/test_binary.c @@ -50,77 +50,60 @@ void tearDown(void) void test_binary_8(void) { - TEST_ASSERT_EQUAL_HEX8(0x00, BIN8(00000000)); - TEST_ASSERT_EQUAL_HEX8(0x01, BIN8(00000001)); - TEST_ASSERT_EQUAL_HEX8(0x02, BIN8(00000010)); - TEST_ASSERT_EQUAL_HEX8(0x04, BIN8(00000100)); - TEST_ASSERT_EQUAL_HEX8(0x08, BIN8(00001000)); - TEST_ASSERT_EQUAL_HEX8(0x10, BIN8(00010000)); - TEST_ASSERT_EQUAL_HEX8(0x20, BIN8(00100000)); - TEST_ASSERT_EQUAL_HEX8(0x40, BIN8(01000000)); - TEST_ASSERT_EQUAL_HEX8(0x80, BIN8(10000000)); + TEST_ASSERT_EQUAL_HEX8(0x00, TU_BIN8(00000000)); + TEST_ASSERT_EQUAL_HEX8(0x01, TU_BIN8(00000001)); + TEST_ASSERT_EQUAL_HEX8(0x02, TU_BIN8(00000010)); + TEST_ASSERT_EQUAL_HEX8(0x04, TU_BIN8(00000100)); + TEST_ASSERT_EQUAL_HEX8(0x08, TU_BIN8(00001000)); + TEST_ASSERT_EQUAL_HEX8(0x10, TU_BIN8(00010000)); + TEST_ASSERT_EQUAL_HEX8(0x20, TU_BIN8(00100000)); + TEST_ASSERT_EQUAL_HEX8(0x40, TU_BIN8(01000000)); + TEST_ASSERT_EQUAL_HEX8(0x80, TU_BIN8(10000000)); - TEST_ASSERT_EQUAL_HEX8(0x0f, BIN8(00001111)); - TEST_ASSERT_EQUAL_HEX8(0xf0, BIN8(11110000)); - TEST_ASSERT_EQUAL_HEX8(0xff, BIN8(11111111)); + TEST_ASSERT_EQUAL_HEX8(0x0f, TU_BIN8(00001111)); + TEST_ASSERT_EQUAL_HEX8(0xf0, TU_BIN8(11110000)); + TEST_ASSERT_EQUAL_HEX8(0xff, TU_BIN8(11111111)); } void test_binary_16(void) { - TEST_ASSERT_EQUAL_HEX16(0x0000, BIN16(00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX16(0x000f, BIN16(00000000, 00001111)); - TEST_ASSERT_EQUAL_HEX16(0x00f0, BIN16(00000000, 11110000)); - TEST_ASSERT_EQUAL_HEX16(0x0f00, BIN16(00001111, 00000000)); - TEST_ASSERT_EQUAL_HEX16(0xf000, BIN16(11110000, 00000000)); - TEST_ASSERT_EQUAL_HEX16(0xffff, BIN16(11111111, 11111111)); + TEST_ASSERT_EQUAL_HEX16(0x0000, TU_BIN16(00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX16(0x000f, TU_BIN16(00000000, 00001111)); + TEST_ASSERT_EQUAL_HEX16(0x00f0, TU_BIN16(00000000, 11110000)); + TEST_ASSERT_EQUAL_HEX16(0x0f00, TU_BIN16(00001111, 00000000)); + TEST_ASSERT_EQUAL_HEX16(0xf000, TU_BIN16(11110000, 00000000)); + TEST_ASSERT_EQUAL_HEX16(0xffff, TU_BIN16(11111111, 11111111)); } void test_binary_32(void) { - TEST_ASSERT_EQUAL_HEX32(0x00000000, BIN32(00000000, 00000000, 00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0x0000000f, BIN32(00000000, 00000000, 00000000, 00001111)); - TEST_ASSERT_EQUAL_HEX32(0x000000f0, BIN32(00000000, 00000000, 00000000, 11110000)); - TEST_ASSERT_EQUAL_HEX32(0x00000f00, BIN32(00000000, 00000000, 00001111, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0x0000f000, BIN32(00000000, 00000000, 11110000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0x000f0000, BIN32(00000000, 00001111, 00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0x00f00000, BIN32(00000000, 11110000, 00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0x0f000000, BIN32(00001111, 00000000, 00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0xf0000000, BIN32(11110000, 00000000, 00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0xffffffff, BIN32(11111111, 11111111, 11111111, 11111111)); + TEST_ASSERT_EQUAL_HEX32(0x00000000, TU_BIN32(00000000, 00000000, 00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0x0000000f, TU_BIN32(00000000, 00000000, 00000000, 00001111)); + TEST_ASSERT_EQUAL_HEX32(0x000000f0, TU_BIN32(00000000, 00000000, 00000000, 11110000)); + TEST_ASSERT_EQUAL_HEX32(0x00000f00, TU_BIN32(00000000, 00000000, 00001111, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0x0000f000, TU_BIN32(00000000, 00000000, 11110000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0x000f0000, TU_BIN32(00000000, 00001111, 00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0x00f00000, TU_BIN32(00000000, 11110000, 00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0x0f000000, TU_BIN32(00001111, 00000000, 00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0xf0000000, TU_BIN32(11110000, 00000000, 00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0xffffffff, TU_BIN32(11111111, 11111111, 11111111, 11111111)); } void test_bit_set(void) { - TEST_ASSERT_EQUAL_HEX32( BIN8(00001101), bit_set( BIN8(00001001), 2)); - TEST_ASSERT_EQUAL_HEX32( BIN8(10001101), bit_set( BIN8(00001101), 7)); + TEST_ASSERT_EQUAL_HEX32( TU_BIN8(00001101), tu_bit_set( TU_BIN8(00001001), 2)); + TEST_ASSERT_EQUAL_HEX32( TU_BIN8(10001101), tu_bit_set( TU_BIN8(00001101), 7)); } void test_bit_clear(void) { - TEST_ASSERT_EQUAL_HEX32( BIN8(00001001), bit_clear( BIN8(00001101), 2)); - TEST_ASSERT_EQUAL_HEX32( BIN8(00001101), bit_clear( BIN8(10001101), 7)); + TEST_ASSERT_EQUAL_HEX32( TU_BIN8(00001001), tu_bit_clear( TU_BIN8(00001101), 2)); + TEST_ASSERT_EQUAL_HEX32( TU_BIN8(00001101), tu_bit_clear( TU_BIN8(10001101), 7)); } void test_bit_mask(void) { - TEST_ASSERT_EQUAL_HEX32(0x0000ffff, bit_mask(16)); - TEST_ASSERT_EQUAL_HEX32(0x00ffffff, bit_mask(24)); - TEST_ASSERT_EQUAL_HEX32(0xffffffff, bit_mask(32)); -} - -void test_bit_range(void) -{ - TEST_ASSERT_EQUAL_HEX32(BIN8(00001111), bit_mask_range(0, 3)); - TEST_ASSERT_EQUAL_HEX32(BIN8(01100000), bit_mask_range(5, 6)); - - TEST_ASSERT_EQUAL_HEX32(BIN16(00001111, 00000000), bit_mask_range(8, 11)); - TEST_ASSERT_EQUAL_HEX32(0xf0000000, bit_mask_range(28, 31)); -} - -void test_bit_set_range(void) -{ - TEST_ASSERT_EQUAL_HEX32(BIN8(01011001), bit_set_range(BIN8(00001001), 4, 6, BIN8(101))); - - TEST_ASSERT_EQUAL_HEX32(BIN32(11001011, 10100000, 00000000, 00001001), - bit_set_range(BIN8(00001001), 21, 31, BIN16(110, 01011101))); + TEST_ASSERT_EQUAL_HEX32(0x0000ffff, tu_bit_mask(16)); + TEST_ASSERT_EQUAL_HEX32(0x00ffffff, tu_bit_mask(24)); + TEST_ASSERT_EQUAL_HEX32(0xffffffff, tu_bit_mask(32)); } From 351f0d7d7891f5494d761e7782fe2c7a34a4ad90 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 14 Dec 2018 15:45:49 +0700 Subject: [PATCH 3/9] merge binary.h into tusb_common.h --- src/common/binary.h | 115 ------------------- src/common/tusb_common.h | 156 ++++++++++++++++---------- tests/lpc18xx_43xx/test/test_binary.c | 7 -- 3 files changed, 95 insertions(+), 183 deletions(-) delete mode 100644 src/common/binary.h diff --git a/src/common/binary.h b/src/common/binary.h deleted file mode 100644 index 5bc364f2..00000000 --- a/src/common/binary.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************/ -/*! - @file binary.h - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -/** \ingroup Group_Common - * \defgroup Group_Binary Binary - * @{ */ - -#ifndef _TUSB_BINARY_H_ -#define _TUSB_BINARY_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -#include -#include -#include "tusb_compiler.h" - -//------------- Bit manipulation -------------// -#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 tu_bit_set(uint32_t value, uint8_t n) -{ - return value | TU_BIT(n); -} - -static inline uint32_t tu_bit_clear(uint32_t value, uint8_t n) -{ - return value & (~TU_BIT(n)); -} - -static inline bool tu_bit_test(uint32_t value, uint8_t n) -{ - return (value & TU_BIT(n)) ? true : false; -} - -///< create a mask with n-bit lsb set to 1 -static inline uint32_t tu_bit_mask(uint8_t n) -{ - return (n < 32) ? ( TU_BIT(n) - 1 ) : UINT32_MAX; -} - -//------------- 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 - -#endif /* _TUSB_BINARY_H_ */ - -/** @} */ diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index f4fac96b..22eddd91 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -47,30 +47,8 @@ extern "C" { #endif -//--------------------------------------------------------------------+ -// INCLUDES -//--------------------------------------------------------------------+ - -//------------- Standard Header -------------// -#include -#include -#include -#include -#include - -//------------- TUSB Option Header -------------// -#include "tusb_option.h" - -//------------- Common Header -------------// -#include "tusb_compiler.h" -#include "tusb_verify.h" -#include "binary.h" -#include "tusb_error.h" -#include "tusb_timeout.h" -#include "tusb_types.h" - -//--------------------------------------------------------------------+ -// MACROS + //--------------------------------------------------------------------+ +// Macros Helper //--------------------------------------------------------------------+ #define TU_ARRAY_SZIE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) ) #define TU_MIN(_x, _y) ( (_x) < (_y) ) ? (_x) : (_y) ) @@ -89,54 +67,77 @@ #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_LE(u32) U32_B4_U8(u32), U32_B3_U8(u32), U32_B2_U8(u32), U32_B1_U8(u32) +//------------- Bit -------------// +#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 + //------------- Endian Conversion -------------// #define ENDIAN_BE(u32) \ (uint32_t) ( (((u32) & 0xFF) << 24) | (((u32) & 0xFF00) << 8) | (((u32) >> 8) & 0xFF00) | (((u32) >> 24) & 0xFF) ) #define ENDIAN_BE16(le16) ((uint16_t) ((U16_LOW_U8(le16) << 8) | U16_HIGH_U8(le16)) ) -#ifndef __n2be_16 -#define __n2be_16(u16) ((uint16_t) ((U16_LOW_U8(u16) << 8) | U16_HIGH_U8(u16)) ) -#define __be2n_16(u16) __n2be_16(u16) -#endif +//------------- 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_) -/*------------------------------------------------------------------*/ -/* Count number of arguments of __VA_ARGS__ - * - reference https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s - * - _GET_NTH_ARG() takes args >= N (64) but only expand to Nth one (64th) - * - _RSEQ_N() is reverse sequential to N to add padding to have - * Nth position is the same as the number of arguments - * - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma) - *------------------------------------------------------------------*/ -#ifndef VA_ARGS_NUM_ +//--------------------------------------------------------------------+ +// INCLUDES +//--------------------------------------------------------------------+ -#define VA_ARGS_NUM_(...) NARG_(_0, ##__VA_ARGS__,_RSEQ_N()) -#define NARG_(...) _GET_NTH_ARG(__VA_ARGS__) -#define _GET_NTH_ARG( \ - _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \ - _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \ - _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \ - _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \ - _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \ - _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \ - _61,_62,_63,N,...) N -#define _RSEQ_N() \ - 62,61,60, \ - 59,58,57,56,55,54,53,52,51,50, \ - 49,48,47,46,45,44,43,42,41,40, \ - 39,38,37,36,35,34,33,32,31,30, \ - 29,28,27,26,25,24,23,22,21,20, \ - 19,18,17,16,15,14,13,12,11,10, \ - 9,8,7,6,5,4,3,2,1,0 -#endif +// Standard Headers +#include +#include +#include +#include +#include + +// Tinyusb Common Headers +#include "tusb_option.h" +#include "tusb_compiler.h" +#include "tusb_verify.h" +//#include "binary.h" +#include "tusb_error.h" +#include "tusb_timeout.h" +#include "tusb_types.h" //--------------------------------------------------------------------+ // INLINE FUNCTION //--------------------------------------------------------------------+ +#ifndef __n2be_16 // TODO clean up +#define __n2be_16(u16) ((uint16_t) ((U16_LOW_U8(u16) << 8) | U16_HIGH_U8(u16)) ) +#define __be2n_16(u16) __n2be_16(u16) +#endif + #define tu_memclr(buffer, size) memset((buffer), 0, (size)) #define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var))) @@ -188,10 +189,7 @@ static inline uint32_t tu_align4k (uint32_t value) { return (value & 0xFFFFF000U static inline uint32_t tu_offset4k(uint32_t value) { return (value & 0xFFFUL); } //------------- Mathematics -------------// -static inline uint32_t tu_abs(int32_t value) -{ - return (value < 0) ? (-value) : value; -} +static inline uint32_t tu_abs(int32_t value) { return (value < 0) ? (-value) : value; } /// inclusive range checking static inline bool tu_within(uint32_t lower, uint32_t value, uint32_t upper) @@ -199,10 +197,11 @@ static inline bool tu_within(uint32_t lower, uint32_t value, uint32_t upper) return (lower <= value) && (value <= upper); } +// log2 of a value is its MSB's position // TODO use clz static inline uint8_t tu_log2(uint32_t value) { - uint8_t result = 0; // log2 of a value is its MSB's position + uint8_t result = 0; while (value >>= 1) { @@ -211,6 +210,41 @@ static inline uint8_t tu_log2(uint32_t value) return result; } +// Bit +static inline uint32_t tu_bit_set(uint32_t value, uint8_t n) { return value | TU_BIT(n); } +static inline uint32_t tu_bit_clear(uint32_t value, uint8_t n) { return value & (~TU_BIT(n)); } +static inline bool tu_bit_test(uint32_t value, uint8_t n) { return (value & TU_BIT(n)) ? true : false; } + +/*------------------------------------------------------------------*/ +/* Count number of arguments of __VA_ARGS__ + * - reference https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s + * - _GET_NTH_ARG() takes args >= N (64) but only expand to Nth one (64th) + * - _RSEQ_N() is reverse sequential to N to add padding to have + * Nth position is the same as the number of arguments + * - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma) + *------------------------------------------------------------------*/ +#ifndef VA_ARGS_NUM_ + +#define VA_ARGS_NUM_(...) NARG_(_0, ##__VA_ARGS__,_RSEQ_N()) +#define NARG_(...) _GET_NTH_ARG(__VA_ARGS__) +#define _GET_NTH_ARG( \ + _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \ + _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \ + _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \ + _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \ + _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \ + _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \ + _61,_62,_63,N,...) N +#define _RSEQ_N() \ + 62,61,60, \ + 59,58,57,56,55,54,53,52,51,50, \ + 49,48,47,46,45,44,43,42,41,40, \ + 39,38,37,36,35,34,33,32,31,30, \ + 29,28,27,26,25,24,23,22,21,20, \ + 19,18,17,16,15,14,13,12,11,10, \ + 9,8,7,6,5,4,3,2,1,0 +#endif + #ifdef __cplusplus } #endif diff --git a/tests/lpc18xx_43xx/test/test_binary.c b/tests/lpc18xx_43xx/test/test_binary.c index fbe2083b..cd9bd1e5 100644 --- a/tests/lpc18xx_43xx/test/test_binary.c +++ b/tests/lpc18xx_43xx/test/test_binary.c @@ -100,10 +100,3 @@ void test_bit_clear(void) TEST_ASSERT_EQUAL_HEX32( TU_BIN8(00001001), tu_bit_clear( TU_BIN8(00001101), 2)); TEST_ASSERT_EQUAL_HEX32( TU_BIN8(00001101), tu_bit_clear( TU_BIN8(10001101), 7)); } - -void test_bit_mask(void) -{ - TEST_ASSERT_EQUAL_HEX32(0x0000ffff, tu_bit_mask(16)); - TEST_ASSERT_EQUAL_HEX32(0x00ffffff, tu_bit_mask(24)); - TEST_ASSERT_EQUAL_HEX32(0xffffffff, tu_bit_mask(32)); -} From 10021eda67f20e16a00415aa37d41a8cfe3efd48 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 15 Dec 2018 13:13:22 +0700 Subject: [PATCH 4/9] minor readme update --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cfea553a..18ae98d7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # TinyUSB -TinyUSB is an cross-platform open-source USB Host/Device stack for embedded system. +TinyUSB is an open-source cross-platform USB Host/Device stack for embedded system. ![tinyusb](https://user-images.githubusercontent.com/249515/49858616-f60c9700-fe27-11e8-8627-e76936352ff7.png) @@ -9,9 +9,9 @@ Folder | Description docs | Documentation examples| Sample applications are kept with Makefile and Segger Embedded build support hw/bsp | Source files of supported boards -hw/mcu | Low level mcu core & peripheral drivers (e.g CMSIS ) +hw/mcu | Low level mcu core & peripheral drivers lib | Source files from 3rd party such as freeRTOS, fatfs etc ... -src | All sources files for tinyusb stack itself. +src | All sources files for TinyUSB stack itself. tests | Unit tests for the stack tools | Files used internally From 455da57f9d66a342383334f3af82c27b57feb6cd Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Dec 2018 12:08:11 +0700 Subject: [PATCH 5/9] docs clean up --- docs/changelog.md | 1 - docs/coding_standard.md | 80 ----------------------------------------- docs/configuration.txt | 76 --------------------------------------- docs/getting_started.md | 38 +++++--------------- docs/group_def.txt | 22 ------------ docs/header.html | 58 ------------------------------ docs/started_demo.md | 48 ------------------------- 7 files changed, 9 insertions(+), 314 deletions(-) delete mode 100644 docs/changelog.md delete mode 100644 docs/coding_standard.md delete mode 100644 docs/configuration.txt delete mode 100644 docs/group_def.txt delete mode 100644 docs/header.html delete mode 100644 docs/started_demo.md diff --git a/docs/changelog.md b/docs/changelog.md deleted file mode 100644 index 420e6f23..00000000 --- a/docs/changelog.md +++ /dev/null @@ -1 +0,0 @@ -# Change Log diff --git a/docs/coding_standard.md b/docs/coding_standard.md deleted file mode 100644 index 3eb3c0d7..00000000 --- a/docs/coding_standard.md +++ /dev/null @@ -1,80 +0,0 @@ -# Coding Standards # - -C is a dangerous language by itself, plus tinyusb make use of goodies features of C99, which saves a tons of code lines (also means save a tons of bugs). However, those features can be misused and pave the way for bugs sneaking into. Therefore, to minimize bugs, the author try to comply with published Coding Standards like: - -- [MISRA-C](http://www.misra-c.com/Activities/MISRAC/tabid/160/Default.aspx) -- [Power of 10](http://spinroot.com/p10/) -- [Jet Propulsion Laboratory (JPL) for C](http://lars-lab.jpl.nasa.gov) - -Where is possible, standards are followed but it is almost impossible to follow all of these without making some exceptions. I am pretty sure this code base violates more than what are described below, if you can find any, please report it to me or file an issue on github. - -## MISRA-C 2004 Exceptions ## - -MISRA-C is well respected & a bar for industrial coding standard. - -- **Rule 2.2: use only** - - It has long passed the day that C99 comment style // will cause any issues, especially compiler's C99 mode is required to build tinyusb. - -- **Rule 8.5: No definitions of objects or function in a header file** - - function definitions in header files are used to allow 'inlining' - -- **Rule 14.7: A function shall have a single point of exit at the end of the function** - - Unfortunately, following this rule will have a lot of nesting if-else, I prefer to exit as soon as possible with assert style and flatten if-else. - -- **Rule 18.4: Unions shall not be used** - - sorry MISRA, union is required to effectively mapped to MCU's registers - -- expect to have more & more exceptions. - -## Power of 10 ## - -is a small & easy to remember but yet powerful coding guideline. Most (if not all) of the rules here are included in JPL. Because it is very small, all the rules will be listed here, those with *italic* are compliant, **bold** are violated. - -1. *Restrict to simple control flow constructs* - - yes, I hate goto statement, therefore there is none of those here - -2. *Give all loops a fixed upper-bound* - - one of my favorite rule - -3. *Do not use dynamic memory allocation after initialization* - - the tinyusb uses the static memory for all of its data. - -4. **Limit functions to no more than 60 lines of text** - - 60 is a little bit too strict, I will update the relaxing number later - -5. *Use minimally two assertions per function on average* - - not sure the exact number, but I use a tons of those assert - -6. *Declare data objects at the smallest possible level of scope* - - one of the best & easiest rule to follow - -7. *Check the return value of non-void functions, and check the validity of function parameters* - - I did check all of the public application API's parameters. For internal API, calling function needs to trust their caller to reduce duplicated check. - -8. **Limit the use of the preprocessor to file inclusion and simple macros** - - Although I prefer inline function, however C macros are far powerful than that. I simply cannot hold myself to use, for example X-Macro technique to simplify code. - -9. *Limit the use of pointers. Use no more than two levels of dereferencing per expression* - - never intend to get in trouble with complex pointer dereferencing. - -10. *Compile with all warnings enabled, and use one or more source code analyzers* - - I try to use all the defensive options of gnu, let me know if I miss some. - >-Wextra -Wswitch-default -Wunsafe-loop-optimizations -Wcast-align -Wlogical-op -Wpacked-bitfield-compat -Wnested-externs -Wredundant-decls -Winline - -## JPL ## - -coming soon ... diff --git a/docs/configuration.txt b/docs/configuration.txt deleted file mode 100644 index 7850827f..00000000 --- a/docs/configuration.txt +++ /dev/null @@ -1,76 +0,0 @@ -/** \addtogroup group_configuration - * @{ */ - -//--------------------------------------------------------------------+ -// COMMON CONFIGURATION -//--------------------------------------------------------------------+ - -/// \brief tell the stack which mode (host/device/otg) the usb controller0 will be operated on. Possible value is -/// from \ref group_mode. Note the hardware usb controller must support the selected mode. -#define CFG_TUSB_RHPORT0_MODE - -/** USB controller in MCU often has limited access to specific RAM section. The Stack will use this macro to place internal variables - into the USB RAM section as follows. if your mcu's usb controller has no such limit, define CFG_TUSB_MEM_SECTION as empty macro. - - @code - CFG_TUSB_MEM_SECTION uint8_t usb_xfer_buffer[10]; - @endcode - */ -#define CFG_TUSB_MEM_SECTION - -#define CFG_TUSB_MCU ///< Select one of the supported MCU, the value must be from \ref group_mcu -#define CFG_TUSB_OS ///< Select one of the supported RTOS, the value must be from \ref group_supported_os. - -//--------------------------------------------------------------------+ -// HOST CONFIGURATION -//--------------------------------------------------------------------+ -/** \defgroup CFG_TUSB_HOST Host Options - * @{ */ - -/** \brief Maximum number of device host stack can manage - * \n If hub class is not enabled, set this equal to number of controllers in host mode - * \n If hub class is enabled, make sure hub is also counted */ -#define CFG_TUSB_HOST_DEVICE_MAX - -/// \brief Buffer size used for getting device configuration descriptor. You may want to increase this from default (256) -/// to support lengthy composite device especially with Audio or Video class -#define CFG_TUSB_HOST_ENUM_BUFFER_SIZE - -/** \defgroup config_host_class Class Driver - * \brief For each Class Driver a value of 1 means enable, value of 0 mean disable - * @{ */ -#define CFG_TUH_HUB ///< Enable Hub Class -#define CFG_TUH_HID_KEYBOARD ///< Enable HID Class for Keyboard -#define CFG_TUH_HID_MOUSE ///< Enable HID Class for Mouse -#define CFG_TUSB_HOST_HID_GENERIC ///< Enable HID Class for Generic (not supported yet) -#define CFG_TUH_MSC ///< Enable Mass Storage Class (SCSI subclass only) -#define CFG_TUH_CDC ///< Enable Virtual Serial (Communication Device Class) -/** @} */ - -/** @} */ // group Host - -//--------------------------------------------------------------------+ -// DEVICE CONFIGURATION -//--------------------------------------------------------------------+ -/** \defgroup CFG_TUSB_DEVICE Device Options - * @{ */ - -#define CFG_TUD_ENDOINT0_SIZE ///< Max packet size of Cotnrol Endpoint, default is 64 - -/// Application MUST define this variable and initialize its pointers's member to all required USB descriptors including -/// Device Descriptor, Configuration Descriptor, String Descriptors, HID Report Descriptors etc ... -tud_desc_init_t tusbd_descriptor_pointers; - -/** \defgroup config_device_class Class Driver - * \brief For each Class Driver a value of 1 means enable, value of 0 mean disable - * @{ */ -#define CFG_TUD_HID_KEYBOARD ///< Enable HID Class for Keyboard -#define CFG_TUD_HID_MOUSE ///< Enable HID Class for Mouse -#define CFG_TUD_HID_GENERIC ///< Enable HID Class for Generic (not supported yet) -#define CFG_TUD_MSC ///< Enable Mass Storage Class (SCSI subclass only) -#define CFG_TUD_CDC ///< Enable Virtual Serial (Communication Device Class) -/** @} */ - -/** @} */ // group Device - -/** @} */ diff --git a/docs/getting_started.md b/docs/getting_started.md index 723e6d86..123a9d2a 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -1,32 +1,12 @@ # Getting Started # - - -**Table of Contents** +## Get -- [Download](#download) -- [Add tinyusb to your project](#add-tinyusb-to-your-project) - - - -## Download - -tinyusb uses github as online repository https://github.com/hathach/tinyusb since it is the best place for open source project. - -If you are using Linux, you already know how to what to do. But If Windows is your OS, I would suggest to install [git](http://git-scm.com/) and front-end gui such as [tortoisegit](http://code.google.com/p/tortoisegit) to begin with. - -After downloading/cloning, the code base is composed of - -Folder | Description ------ | ------------- -doxygen | Documentation -examples| Folder where test examples are kept with Makefile and Segger Embedded build support -hw/bsp | Source files of supported boards -hw/mcu | Low level mcu core & peripheral drivers (e.g CMSIS ) -lib | Source files from 3rd party such as freeRTOS, fatfs etc ... -src | All sources files for tinyusb stack itself. -tests | Unit tests for the stack -tools | Files used internally +``` +git clone git@github.com:hathach/tinyusb.git tinyusb +cd tinyusb +git submodule update --init +``` *examples* is the folder where all the application & project files are located. There are demos for both device and hosts. For each, there are different projects for each of supported RTOS. Click to have more information on how to [build](../examples/readme.md) and run [device](../examples/device/readme.md) demos. @@ -59,6 +39,6 @@ int main(void) } ~~~ -[//]: # (\subpage md_boards_readme) -[//]: # (\subpage md_doxygen_started_demo) -[//]: # (\subpage md_tools_readme) +[//]: # "\subpage md_boards_readme" +[//]: # "\subpage md_doxygen_started_demo" +[//]: # "\subpage md_tools_readme" diff --git a/docs/group_def.txt b/docs/group_def.txt deleted file mode 100644 index 0f541981..00000000 --- a/docs/group_def.txt +++ /dev/null @@ -1,22 +0,0 @@ -// define all the modules group to have the desired ordering since doxygen order module group by -// the order of files it is feed - -/// \defgroup group_demo Demos - -/// \defgroup group_class Application - Class Driver API - -/// \defgroup group_application_api Application - Stack API -/// \brief Non-Class driver API - -/// \defgroup group_configuration Configuration tusb_config.h - -/// \defgroup group_usbd USB Device Core (USBD) - -/// \defgroup group_usbh USB Host Core (USBH) - -/// \defgroup group_osal OS Abstraction Layer (OSAL) - -/// \defgroup group_usb_definitions USB Definitions - -/// \defgroup Group_Common Common Files - diff --git a/docs/header.html b/docs/header.html deleted file mode 100644 index e75be44d..00000000 --- a/docs/header.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - -$projectname: $title -$title - - - -$treeview -$search -$mathjax - -$extrastylesheet - - -
- - -
- - - - - - - - - - - - - - - - - - - - - - -
-
$projectname -  $projectnumber -
-
$projectbrief
-
- Click here to lend your support to tinyusb donation and make a donation at pledgie.com - -
$projectbrief
-
$searchbox
-
- - diff --git a/docs/started_demo.md b/docs/started_demo.md deleted file mode 100644 index 7e82596f..00000000 --- a/docs/started_demo.md +++ /dev/null @@ -1,48 +0,0 @@ -# Demos # - -For simplicity and user's convenience, there are only 2 basic application demos which are *Device* and *Host* respectively. Each application demo, however, has a few projects, each for its supported RTOS. For instance, in addition to the *src* folder, you will also find in the /demo/device - -- device\_os\_none for no RTOS -- device\_freertos for freeRTOS -- device\_cmsis_rtx for ARM CMSIS with RTX implemenation - -To be able to have the same application code running across RTOSes, the application make use of the "internal" **OSAL layer**. Thus this makes the application code a bit weird and over-complicated than it should be in some (many) cases. This is absolutely not necessary in product development. User can just use the native API function of supported RTOS or a state machine or blocking wait in case of none OS. For example, instead of the blinking task in application - -~~~{.c} -OSAL_TASK_FUNCTION( led_blinking_task , p_task_para) -{ - OSAL_TASK_LOOP_BEGIN - - static uint32_t led_on_mask = 0; - - osal_task_delay(led_blink_interval_ms); - - board_leds(led_on_mask, 1 - led_on_mask); - led_on_mask = 1 - led_on_mask; // toggle - - OSAL_TASK_LOOP_END -} -~~~ - -can be written in FreeRTOS's native API - -~~~{.c} -void led_blinking_task( void * p_task_para ) -{ - while(1) - { - static uint32_t led_on_mask = 0; - - // FreeRTOS API's vTaskDelay is used in place of osal_task_delay. Note it takes input parameter in tick - vTaskDelay( (led_blink_interval_ms * CFG_TUSB_TICKS_HZ) / 1000); - - board_leds(led_on_mask, 1 - led_on_mask); - led_on_mask = 1 - led_on_mask; // toggle - } -} -~~~ - - -[//]: # (\subpage md_demos_readme) -[//]: # (\subpage md_demos_device_readme) -[//]: # (\subpage md_demos_host_readme) \ No newline at end of file From 902697ca079a179221da92f8cb9f873768a5d0d7 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Dec 2018 12:14:11 +0700 Subject: [PATCH 6/9] add dcd_get_microframe() --- src/class/hid/hid_device.c | 2 ++ src/class/hid/hid_device.h | 1 - src/common/tusb_timeout.h | 10 ------- src/device/dcd.h | 4 +++ src/portable/microchip/samd21/dcd_samd21.c | 6 ++++ src/portable/microchip/samd51/dcd_samd51.c | 6 ++++ src/portable/nordic/nrf5x/dcd_nrf5x.c | 11 +++++++- .../nxp/lpc11_13_15/dcd_lpc11_13_15.c | 7 +++++ src/portable/nxp/lpc17_40/dcd_lpc17_40.c | 6 ++++ src/portable/nxp/lpc18_43/dcd_lpc18_43.c | 28 +++++++++++-------- 10 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 70aa7370..3b882f70 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -207,6 +207,7 @@ bool tud_hid_keyboard_key_press(char ch) return tud_hid_keyboard_keycode(modifier, keycode); } +#if 0 // should be at application bool tud_hid_keyboard_key_sequence(const char* str, uint32_t interval_ms) { // Send each key in string @@ -231,6 +232,7 @@ bool tud_hid_keyboard_key_sequence(const char* str, uint32_t interval_ms) return true; } +#endif #endif // CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 885f3344..f3d5087a 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -95,7 +95,6 @@ static inline bool tud_hid_keyboard_key_release(void) { return tud_hid_keyboard_ #if CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP bool tud_hid_keyboard_key_press(char ch); -bool tud_hid_keyboard_key_sequence(const char* str, uint32_t interval_ms); typedef struct{ uint8_t shift; diff --git a/src/common/tusb_timeout.h b/src/common/tusb_timeout.h index 9d80f5fe..06d5ff5b 100644 --- a/src/common/tusb_timeout.h +++ b/src/common/tusb_timeout.h @@ -79,16 +79,6 @@ static inline void tu_timeout_restart(tu_timeout_t* tt) tt->start = tusb_hal_millis(); } - -static inline void tu_timeout_wait(uint32_t msec) -{ - tu_timeout_t tt; - tu_timeout_set(&tt, msec); - - // blocking delay - while ( !tu_timeout_expired(&tt) ) { } -} - #ifdef __cplusplus } #endif diff --git a/src/device/dcd.h b/src/device/dcd.h index 6b1356cb..40892274 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -93,12 +93,16 @@ TU_VERIFY_STATIC(sizeof(dcd_event_t) <= 12, "size is not correct"); /* Device API *------------------------------------------------------------------*/ bool dcd_init (uint8_t rhport); + void dcd_int_enable (uint8_t rhport); void dcd_int_disable(uint8_t rhport); void dcd_set_address(uint8_t rhport, uint8_t dev_addr); void dcd_set_config (uint8_t rhport, uint8_t config_num); +// Get current micro-frame number +uint32_t dcd_get_microframe(uint8_t rhport); + /*------------------------------------------------------------------*/ /* Event Function * Called by DCD to notify USBD diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c index af0721ec..0865f2bd 100644 --- a/src/portable/microchip/samd21/dcd_samd21.c +++ b/src/portable/microchip/samd21/dcd_samd21.c @@ -124,6 +124,12 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num) // Nothing to do } +uint32_t dcd_get_microframe(uint8_t rhport) +{ + (void) rhport; + return USB->DEVICE.FNUM & (TU_BIT(14) - 1); +} + /*------------------------------------------------------------------*/ /* DCD Endpoint port *------------------------------------------------------------------*/ diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c index ce66b824..fc3d31de 100644 --- a/src/portable/microchip/samd51/dcd_samd51.c +++ b/src/portable/microchip/samd51/dcd_samd51.c @@ -129,6 +129,12 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num) // Nothing to do } +uint32_t dcd_get_microframe(uint8_t rhport) +{ + (void) rhport; + return USB->DEVICE.FNUM & (TU_BIT(14) - 1); +} + /*------------------------------------------------------------------*/ /* DCD Endpoint port *------------------------------------------------------------------*/ diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 7d13ef8c..1e0c3474 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -187,7 +187,7 @@ static void xact_in_prepare(uint8_t epnum) } //--------------------------------------------------------------------+ -// Tinyusb DCD API +// Controller API //--------------------------------------------------------------------+ bool dcd_init (uint8_t rhport) { @@ -221,6 +221,15 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num) // Nothing to do } +uint32_t dcd_get_microframe(uint8_t rhport) +{ + (void) rhport; + return NRF_USBD->FRAMECNTR << 3; +} + +//--------------------------------------------------------------------+ +// Endpoint API +//--------------------------------------------------------------------+ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt) { (void) rhport; diff --git a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c index 26ecaf8b..23522b94 100644 --- a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c +++ b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c @@ -165,6 +165,13 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr) LPC_USB->DEVCMDSTAT |= dev_addr; } +uint32_t dcd_get_microframe(uint8_t rhport) +{ + (void) rhport; + + return (LPC_USB->INFO & (TU_BIT(11) - 1)) << 3; +} + bool dcd_init(uint8_t rhport) { (void) rhport; diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index fca2c355..7406d177 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -227,6 +227,12 @@ void dcd_set_config(uint8_t rhport, uint8_t config_num) sie_write(SIE_CMDCODE_CONFIGURE_DEVICE, 1, 1); } +uint32_t dcd_get_microframe(uint8_t rhport) +{ + (void) rhport; + return ((uint32_t) sie_read(SIE_CMDCODE_READ_FRAME_NUMBER)) << 3; +} + //--------------------------------------------------------------------+ // CONTROL HELPER //--------------------------------------------------------------------+ diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c index 7761d547..796c8c4b 100644 --- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c @@ -92,17 +92,6 @@ static dcd_data_t* const dcd_data_ptr[2] = //--------------------------------------------------------------------+ // CONTROLLER API //--------------------------------------------------------------------+ -void dcd_set_address(uint8_t rhport, uint8_t dev_addr) -{ - LPC_USB[rhport]->DEVICEADDR = (dev_addr << 25) | TU_BIT(24); -} - -void dcd_set_config(uint8_t rhport, uint8_t config_num) -{ - (void) rhport; - (void) config_num; - // nothing to do -} /// follows LPC43xx User Manual 23.10.3 static void bus_reset(uint8_t rhport) @@ -173,6 +162,23 @@ void dcd_int_disable(uint8_t rhport) NVIC_DisableIRQ(rhport ? USB1_IRQn : USB0_IRQn); } +void dcd_set_address(uint8_t rhport, uint8_t dev_addr) +{ + LPC_USB[rhport]->DEVICEADDR = (dev_addr << 25) | TU_BIT(24); +} + +void dcd_set_config(uint8_t rhport, uint8_t config_num) +{ + (void) rhport; + (void) config_num; + // nothing to do +} + +uint32_t dcd_get_microframe(uint8_t rhport) +{ + return LPC_USB[rhport]->FRINDEX_D; +} + //--------------------------------------------------------------------+ // HELPER //--------------------------------------------------------------------+ From 426064201a2a28bf9c21f2cb05f9bd0fe2213ac7 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Dec 2018 13:16:42 +0700 Subject: [PATCH 7/9] fix samd build --- src/portable/microchip/samd21/dcd_samd21.c | 2 +- src/portable/microchip/samd51/dcd_samd51.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c index 0865f2bd..be1f4495 100644 --- a/src/portable/microchip/samd21/dcd_samd21.c +++ b/src/portable/microchip/samd21/dcd_samd21.c @@ -127,7 +127,7 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num) uint32_t dcd_get_microframe(uint8_t rhport) { (void) rhport; - return USB->DEVICE.FNUM & (TU_BIT(14) - 1); + return USB->DEVICE.FNUM.reg & (TU_BIT(14) - 1); } /*------------------------------------------------------------------*/ diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c index fc3d31de..3dd6c88d 100644 --- a/src/portable/microchip/samd51/dcd_samd51.c +++ b/src/portable/microchip/samd51/dcd_samd51.c @@ -132,7 +132,7 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num) uint32_t dcd_get_microframe(uint8_t rhport) { (void) rhport; - return USB->DEVICE.FNUM & (TU_BIT(14) - 1); + return USB->DEVICE.FNUM.reg & (TU_BIT(14) - 1); } /*------------------------------------------------------------------*/ From 6f17b4e01973185beb2876f827a76e4200ee0ef3 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 21 Dec 2018 12:46:20 +0700 Subject: [PATCH 8/9] change to dcd_get_frame_number --- src/device/dcd.h | 4 ++-- src/portable/microchip/samd21/dcd_samd21.c | 4 ++-- src/portable/microchip/samd51/dcd_samd51.c | 4 ++-- src/portable/nordic/nrf5x/dcd_nrf5x.c | 4 ++-- src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c | 4 ++-- src/portable/nxp/lpc17_40/dcd_lpc17_40.c | 4 ++-- src/portable/nxp/lpc18_43/dcd_lpc18_43.c | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/device/dcd.h b/src/device/dcd.h index 40892274..abd85a70 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -100,8 +100,8 @@ void dcd_int_disable(uint8_t rhport); void dcd_set_address(uint8_t rhport, uint8_t dev_addr); void dcd_set_config (uint8_t rhport, uint8_t config_num); -// Get current micro-frame number -uint32_t dcd_get_microframe(uint8_t rhport); +// Get current frame number +uint32_t dcd_get_frame_number(uint8_t rhport); /*------------------------------------------------------------------*/ /* Event Function diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c index be1f4495..7b2a57ee 100644 --- a/src/portable/microchip/samd21/dcd_samd21.c +++ b/src/portable/microchip/samd21/dcd_samd21.c @@ -124,10 +124,10 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num) // Nothing to do } -uint32_t dcd_get_microframe(uint8_t rhport) +uint32_t dcd_get_frame_number(uint8_t rhport) { (void) rhport; - return USB->DEVICE.FNUM.reg & (TU_BIT(14) - 1); + return USB->DEVICE.FNUM.bit.FNUM; } /*------------------------------------------------------------------*/ diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c index 3dd6c88d..1de3fadb 100644 --- a/src/portable/microchip/samd51/dcd_samd51.c +++ b/src/portable/microchip/samd51/dcd_samd51.c @@ -129,10 +129,10 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num) // Nothing to do } -uint32_t dcd_get_microframe(uint8_t rhport) +uint32_t dcd_get_frame_number(uint8_t rhport) { (void) rhport; - return USB->DEVICE.FNUM.reg & (TU_BIT(14) - 1); + return USB->DEVICE.FNUM.bit.FNUM; } /*------------------------------------------------------------------*/ diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 1e0c3474..49984eae 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -221,10 +221,10 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num) // Nothing to do } -uint32_t dcd_get_microframe(uint8_t rhport) +uint32_t dcd_get_frame_number(uint8_t rhport) { (void) rhport; - return NRF_USBD->FRAMECNTR << 3; + return NRF_USBD->FRAMECNTR; } //--------------------------------------------------------------------+ diff --git a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c index 23522b94..a9ba5e33 100644 --- a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c +++ b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c @@ -165,11 +165,11 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr) LPC_USB->DEVCMDSTAT |= dev_addr; } -uint32_t dcd_get_microframe(uint8_t rhport) +uint32_t dcd_get_frame_number(uint8_t rhport) { (void) rhport; - return (LPC_USB->INFO & (TU_BIT(11) - 1)) << 3; + return LPC_USB->INFO & (TU_BIT(11) - 1); } bool dcd_init(uint8_t rhport) diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index 7406d177..e3286b1c 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -227,10 +227,10 @@ void dcd_set_config(uint8_t rhport, uint8_t config_num) sie_write(SIE_CMDCODE_CONFIGURE_DEVICE, 1, 1); } -uint32_t dcd_get_microframe(uint8_t rhport) +uint32_t dcd_get_frame_number(uint8_t rhport) { (void) rhport; - return ((uint32_t) sie_read(SIE_CMDCODE_READ_FRAME_NUMBER)) << 3; + return (uint32_t) sie_read(SIE_CMDCODE_READ_FRAME_NUMBER); } //--------------------------------------------------------------------+ diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c index 796c8c4b..65b0728e 100644 --- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c @@ -174,9 +174,9 @@ void dcd_set_config(uint8_t rhport, uint8_t config_num) // nothing to do } -uint32_t dcd_get_microframe(uint8_t rhport) +uint32_t dcd_get_frame_number(uint8_t rhport) { - return LPC_USB[rhport]->FRINDEX_D; + return LPC_USB[rhport]->FRINDEX_D >> 3; } //--------------------------------------------------------------------+ From 257d60fe1a2f72803fd7fa28cde691f5ca34a046 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 21 Dec 2018 12:58:53 +0700 Subject: [PATCH 9/9] white spaces --- src/class/hid/hid.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 2e2b4558..6abc71e0 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -173,9 +173,9 @@ typedef struct ATTR_PACKED /// Standard Mouse Buttons Bitmap typedef enum { - MOUSE_BUTTON_LEFT = TU_BIT(0), ///< Left button - MOUSE_BUTTON_RIGHT = TU_BIT(1), ///< Right button - MOUSE_BUTTON_MIDDLE = TU_BIT(2), ///< Middle button + MOUSE_BUTTON_LEFT = TU_BIT(0), ///< Left button + MOUSE_BUTTON_RIGHT = TU_BIT(1), ///< Right button + MOUSE_BUTTON_MIDDLE = TU_BIT(2), ///< Middle button MOUSE_BUTTON_BACKWARD = TU_BIT(3), ///< Backward button, MOUSE_BUTTON_FORWARD = TU_BIT(4), ///< Forward button, }hid_mouse_button_bm_t; @@ -199,14 +199,14 @@ typedef struct ATTR_PACKED /// Keyboard modifier codes bitmap typedef enum { - KEYBOARD_MODIFIER_LEFTCTRL = TU_BIT(0), ///< Left Control - KEYBOARD_MODIFIER_LEFTSHIFT = TU_BIT(1), ///< Left Shift - KEYBOARD_MODIFIER_LEFTALT = TU_BIT(2), ///< Left Alt - KEYBOARD_MODIFIER_LEFTGUI = TU_BIT(3), ///< Left Window - KEYBOARD_MODIFIER_RIGHTCTRL = TU_BIT(4), ///< Right Control - KEYBOARD_MODIFIER_RIGHTSHIFT = TU_BIT(5), ///< Right Shift - KEYBOARD_MODIFIER_RIGHTALT = TU_BIT(6), ///< Right Alt - KEYBOARD_MODIFIER_RIGHTGUI = TU_BIT(7) ///< Right Window + KEYBOARD_MODIFIER_LEFTCTRL = TU_BIT(0), ///< Left Control + KEYBOARD_MODIFIER_LEFTSHIFT = TU_BIT(1), ///< Left Shift + KEYBOARD_MODIFIER_LEFTALT = TU_BIT(2), ///< Left Alt + KEYBOARD_MODIFIER_LEFTGUI = TU_BIT(3), ///< Left Window + KEYBOARD_MODIFIER_RIGHTCTRL = TU_BIT(4), ///< Right Control + KEYBOARD_MODIFIER_RIGHTSHIFT = TU_BIT(5), ///< Right Shift + KEYBOARD_MODIFIER_RIGHTALT = TU_BIT(6), ///< Right Alt + KEYBOARD_MODIFIER_RIGHTGUI = TU_BIT(7) ///< Right Window }hid_keyboard_modifier_bm_t; typedef enum