From 064eec5dd8e27b1f8e88b24a5d5071bbd8458a29 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 26 Nov 2018 12:25:28 +0700 Subject: clean up warnings --- src/class/cdc/cdc_device.c | 12 +++++++----- src/class/cdc/cdc_device.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index b68a6a7ff..040c8d4f4 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -302,6 +302,8 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface // return false to stall control endpoint (e.g Host send non-sense DATA) bool cdcd_control_request_complete(uint8_t rhport, tusb_control_request_t const * request) { + (void) rhport; + //------------- Class Specific Request -------------// TU_VERIFY (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS); @@ -358,8 +360,10 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request return true; } -tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) +tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) { + (void) result; + // TODO Support multiple interfaces uint8_t const itf = 0; cdcd_interface_t* p_cdc = &_cdcd_itf[itf]; @@ -367,16 +371,14 @@ tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, // receive new data if ( ep_addr == p_cdc->ep_out ) { - char const wanted = p_cdc->wanted_char; - for(uint32_t i=0; irx_ff, &p_cdc->epout_buf[i]); // Check for wanted char and invoke callback if needed - if ( tud_cdc_rx_wanted_cb && ( wanted != -1 ) && ( wanted == p_cdc->epout_buf[i] ) ) + if ( tud_cdc_rx_wanted_cb && ( ((signed char) p_cdc->wanted_char) != -1 ) && ( p_cdc->wanted_char == p_cdc->epout_buf[i] ) ) { - tud_cdc_rx_wanted_cb(itf, wanted); + tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char); } } diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index ad1100e9c..0a17aa916 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -116,7 +116,7 @@ void cdcd_init (void); tusb_error_t cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool cdcd_control_request (uint8_t rhport, tusb_control_request_t const * p_request); bool cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes); +tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes); void cdcd_reset (uint8_t rhport); #endif -- cgit v1.3.1 From 5f7d7a34f576dabd94c10fad05fe5fa85d4ef1e0 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Dec 2018 00:38:00 +0700 Subject: able to complete enumeration with os none blocking --- examples/host/cdc_msc_hid/src/main.c | 23 +++++++++++++++++++++-- examples/host/cdc_msc_hid/src/tusb_config.h | 2 +- src/class/cdc/cdc_host.c | 4 ++-- src/osal/osal_none.h | 15 +++++++-------- 4 files changed, 31 insertions(+), 13 deletions(-) (limited to 'src/class/cdc') diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c index 2459ec329..c888f7bf7 100644 --- a/examples/host/cdc_msc_hid/src/main.c +++ b/examples/host/cdc_msc_hid/src/main.c @@ -66,7 +66,7 @@ int main(void) led_blinking_task(); -#if CFG_TUD_CDC +#if CFG_TUSB_HOST_CDC virtual_com_task(); #endif @@ -81,7 +81,26 @@ int main(void) //--------------------------------------------------------------------+ // USB CDC //--------------------------------------------------------------------+ -#if CFG_TUD_CDC +#if CFG_TUSB_HOST_CDC + +void tuh_cdc_mounted_cb(uint8_t dev_addr) +{ + // application set-up + printf("\na CDC device (address %d) is mounted\n", dev_addr); +} + +void tuh_cdc_unmounted_cb(uint8_t dev_addr) +{ + // application tear-down + printf("\na CDC device (address %d) is unmounted \n", dev_addr); +} + +// invoked ISR context +void tuh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes) +{ + +} + void virtual_com_task(void) { diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index 9fef03af8..4b39d6d18 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -88,7 +88,7 @@ #define CFG_TUSB_HOST_HID_MOUSE 0 #define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) #define CFG_TUSB_HOST_MSC 0 -#define CFG_TUSB_HOST_CDC 0 +#define CFG_TUSB_HOST_CDC 1 #define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUSB_HOST_HUB ? 5 : 1) // normal hub has 4 ports diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 0a3661878..27ef502e0 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -144,7 +144,7 @@ void cdch_init(void) tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) { - OSAL_SUBTASK_BEGIN + //OSAL_SUBTASK_BEGIN // TODO change following assert to subtask_assert if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != p_interface_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS; @@ -218,7 +218,7 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ tuh_cdc_mounted_cb(dev_addr); } - OSAL_SUBTASK_END + //OSAL_SUBTASK_END } void cdch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 042c7a6e8..61ed0d45e 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -96,15 +96,14 @@ static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) sem_hdl->count = 0; } -static inline tusb_error_t osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) { +static inline tusb_error_t osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) +{ (void) msec; - while (true) { - while (sem_hdl->count == 0) { } - if (sem_hdl->count == 0) { - sem_hdl->count--; - break; - } - } + + // TODO blocking for now + while (sem_hdl->count == 0) { } + sem_hdl->count--; + return TUSB_ERROR_NONE; } -- cgit v1.3.1 From 7d3ff7aff6aed13377a4cd12f1d8f2ad91720f80 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Dec 2018 22:24:31 +0700 Subject: rename CFG_TUSB_HOST_CDC/MSC to CFG_TUH_CDC/MSC --- docs/configuration.txt | 4 ++-- examples/host/cdc_msc_hid/src/main.c | 4 ++-- examples/host/cdc_msc_hid/src/tusb_config.h | 4 ++-- examples/obsolete/host/src/cdc_serial_host_app.c | 2 +- examples/obsolete/host/src/cdc_serial_host_app.h | 2 +- examples/obsolete/host/src/main.c | 4 ++-- examples/obsolete/host/src/msc_cli.c | 2 +- examples/obsolete/host/src/msc_host_app.c | 2 +- examples/obsolete/host/src/msc_host_app.h | 2 +- examples/obsolete/host/src/rndis_host_app.c | 2 +- examples/obsolete/host/src/rndis_host_app.h | 2 +- examples/obsolete/host/src/tusb_config.h | 4 ++-- lib/fatfs/ccsbcs.c | 4 ++-- lib/fatfs/diskio.c | 4 ++-- lib/fatfs/ff.c | 4 ++-- src/class/cdc/cdc_host.c | 2 +- src/class/cdc/cdc_rndis_host.c | 2 +- src/class/msc/msc_host.c | 2 +- src/host/hcd.h | 2 +- src/tusb.h | 4 ++-- tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c | 2 +- tests/lpc18xx_43xx/test/host/host_helper.h | 4 ++-- tests/support/tusb_config.h | 6 +++--- 23 files changed, 35 insertions(+), 35 deletions(-) (limited to 'src/class/cdc') diff --git a/docs/configuration.txt b/docs/configuration.txt index 896c9da6c..33eb4efbf 100644 --- a/docs/configuration.txt +++ b/docs/configuration.txt @@ -44,8 +44,8 @@ #define CFG_TUSB_HOST_HID_KEYBOARD ///< Enable HID Class for Keyboard #define CFG_TUSB_HOST_HID_MOUSE ///< Enable HID Class for Mouse #define CFG_TUSB_HOST_HID_GENERIC ///< Enable HID Class for Generic (not supported yet) -#define CFG_TUSB_HOST_MSC ///< Enable Mass Storage Class (SCSI subclass only) -#define CFG_TUSB_HOST_CDC ///< Enable Virtual Serial (Communication Device Class) +#define CFG_TUH_MSC ///< Enable Mass Storage Class (SCSI subclass only) +#define CFG_TUH_CDC ///< Enable Virtual Serial (Communication Device Class) /** @} */ /** @} */ // group Host diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c index c888f7bf7..81e8a172c 100644 --- a/examples/host/cdc_msc_hid/src/main.c +++ b/examples/host/cdc_msc_hid/src/main.c @@ -66,7 +66,7 @@ int main(void) led_blinking_task(); -#if CFG_TUSB_HOST_CDC +#if CFG_TUH_CDC virtual_com_task(); #endif @@ -81,7 +81,7 @@ int main(void) //--------------------------------------------------------------------+ // USB CDC //--------------------------------------------------------------------+ -#if CFG_TUSB_HOST_CDC +#if CFG_TUH_CDC void tuh_cdc_mounted_cb(uint8_t dev_addr) { diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index 8d3e39c64..a77d9ba5e 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -84,11 +84,11 @@ //-------------------------------------------------------------------- #define CFG_TUH_HUB 1 +#define CFG_TUH_CDC 1 #define CFG_TUSB_HOST_HID_KEYBOARD 0 #define CFG_TUSB_HOST_HID_MOUSE 0 #define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) -#define CFG_TUSB_HOST_MSC 0 -#define CFG_TUSB_HOST_CDC 1 +#define CFG_TUH_MSC 0 #define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports diff --git a/examples/obsolete/host/src/cdc_serial_host_app.c b/examples/obsolete/host/src/cdc_serial_host_app.c index 85604dcdf..1be2e9d8b 100644 --- a/examples/obsolete/host/src/cdc_serial_host_app.c +++ b/examples/obsolete/host/src/cdc_serial_host_app.c @@ -39,7 +39,7 @@ #include "cdc_serial_host_app.h" #include "app_os_prio.h" -#if CFG_TUSB_HOST_CDC +#if CFG_TUH_CDC #define QUEUE_SERIAL_DEPTH 100 diff --git a/examples/obsolete/host/src/cdc_serial_host_app.h b/examples/obsolete/host/src/cdc_serial_host_app.h index eef00bb55..f95cbbdab 100644 --- a/examples/obsolete/host/src/cdc_serial_host_app.h +++ b/examples/obsolete/host/src/cdc_serial_host_app.h @@ -53,7 +53,7 @@ extern "C" { #endif -#if CFG_TUSB_HOST_CDC +#if CFG_TUH_CDC void cdc_serial_host_app_init(void); void cdc_serial_host_app_task(void* param); diff --git a/examples/obsolete/host/src/main.c b/examples/obsolete/host/src/main.c index 0f2905fc6..320e1c8f5 100644 --- a/examples/obsolete/host/src/main.c +++ b/examples/obsolete/host/src/main.c @@ -138,6 +138,6 @@ void print_greeting(void) if (CFG_TUH_HUB ) puts(" - Hub (1 level only)"); if (CFG_TUSB_HOST_HID_MOUSE ) puts(" - HID Mouse"); if (CFG_TUSB_HOST_HID_KEYBOARD ) puts(" - HID Keyboard"); - if (CFG_TUSB_HOST_MSC ) puts(" - Mass Storage"); - if (CFG_TUSB_HOST_CDC ) puts(" - Communication Device Class"); + if (CFG_TUH_MSC ) puts(" - Mass Storage"); + if (CFG_TUH_CDC ) puts(" - Communication Device Class"); } diff --git a/examples/obsolete/host/src/msc_cli.c b/examples/obsolete/host/src/msc_cli.c index 75dbb1c01..fa1f986a5 100644 --- a/examples/obsolete/host/src/msc_cli.c +++ b/examples/obsolete/host/src/msc_cli.c @@ -39,7 +39,7 @@ #include "msc_cli.h" #include "ctype.h" -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC #include "ff.h" #include "diskio.h" diff --git a/examples/obsolete/host/src/msc_host_app.c b/examples/obsolete/host/src/msc_host_app.c index 1cfe9ec60..89993cefe 100644 --- a/examples/obsolete/host/src/msc_host_app.c +++ b/examples/obsolete/host/src/msc_host_app.c @@ -42,7 +42,7 @@ #include "msc_host_app.h" #include "app_os_prio.h" -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC #include "msc_cli.h" #include "ff.h" diff --git a/examples/obsolete/host/src/msc_host_app.h b/examples/obsolete/host/src/msc_host_app.h index c6e508e6c..0e153fc1d 100644 --- a/examples/obsolete/host/src/msc_host_app.h +++ b/examples/obsolete/host/src/msc_host_app.h @@ -54,7 +54,7 @@ extern "C" { #endif -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC void msc_host_app_init(void); void msc_host_app_task(void* param); diff --git a/examples/obsolete/host/src/rndis_host_app.c b/examples/obsolete/host/src/rndis_host_app.c index 5bb60182c..374e13a2a 100644 --- a/examples/obsolete/host/src/rndis_host_app.c +++ b/examples/obsolete/host/src/rndis_host_app.c @@ -39,7 +39,7 @@ #include "rndis_host_app.h" #include "app_os_prio.h" -#if CFG_TUSB_HOST_CDC && CFG_TUSB_HOST_CDC_RNDIS +#if CFG_TUH_CDC && CFG_TUH_CDC_RNDIS //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF diff --git a/examples/obsolete/host/src/rndis_host_app.h b/examples/obsolete/host/src/rndis_host_app.h index 9fa19351e..2e8437651 100644 --- a/examples/obsolete/host/src/rndis_host_app.h +++ b/examples/obsolete/host/src/rndis_host_app.h @@ -53,7 +53,7 @@ extern "C" { #endif -#if CFG_TUSB_HOST_CDC && CFG_TUSB_HOST_CDC_RNDIS +#if CFG_TUH_CDC && CFG_TUH_CDC_RNDIS void rndis_host_app_init(void); void rndis_host_app_task(void* param); diff --git a/examples/obsolete/host/src/tusb_config.h b/examples/obsolete/host/src/tusb_config.h index 3d0d5f3db..e555c8f35 100644 --- a/examples/obsolete/host/src/tusb_config.h +++ b/examples/obsolete/host/src/tusb_config.h @@ -58,8 +58,8 @@ #define CFG_TUSB_HOST_HID_KEYBOARD 1 #define CFG_TUSB_HOST_HID_MOUSE 1 #define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) -#define CFG_TUSB_HOST_MSC 1 -#define CFG_TUSB_HOST_CDC 1 +#define CFG_TUH_MSC 1 +#define CFG_TUH_CDC 1 #define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports diff --git a/lib/fatfs/ccsbcs.c b/lib/fatfs/ccsbcs.c index 5cf0dd503..07d6f0983 100644 --- a/lib/fatfs/ccsbcs.c +++ b/lib/fatfs/ccsbcs.c @@ -27,7 +27,7 @@ #include "ff.h" -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC #if _CODE_PAGE == 437 #define _TBLDEF 1 @@ -540,4 +540,4 @@ WCHAR ff_wtoupper ( /* Upper converted character */ return tbl_lower[i] ? tbl_upper[i] : chr; } -#endif // CFG_TUSB_HOST_MSC +#endif // CFG_TUH_MSC diff --git a/lib/fatfs/diskio.c b/lib/fatfs/diskio.c index 54a228019..939015c00 100644 --- a/lib/fatfs/diskio.c +++ b/lib/fatfs/diskio.c @@ -38,7 +38,7 @@ #include "tusb.h" -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ @@ -204,4 +204,4 @@ DWORD get_fattime (void) return timestamp.value; } -#endif // CFG_TUSB_HOST_MSC +#endif // CFG_TUH_MSC diff --git a/lib/fatfs/ff.c b/lib/fatfs/ff.c index 897965332..79414af07 100644 --- a/lib/fatfs/ff.c +++ b/lib/fatfs/ff.c @@ -99,7 +99,7 @@ #include "ff.h" /* FatFs configurations and declarations */ #include "diskio.h" /* Declarations of low level disk I/O functions */ -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC /*-------------------------------------------------------------------------- Module Private Definitions @@ -4327,4 +4327,4 @@ int f_printf ( #endif /* !_FS_READONLY */ #endif /* _USE_STRFUNC */ -#endif // CFG_TUSB_HOST_MSC +#endif // CFG_TUH_MSC diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 27ef502e0..2cf288a93 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && CFG_TUSB_HOST_CDC) +#if (MODE_HOST_SUPPORTED && CFG_TUH_CDC) #define _TINY_USB_SOURCE_FILE_ diff --git a/src/class/cdc/cdc_rndis_host.c b/src/class/cdc/cdc_rndis_host.c index 89ea3b32f..df4a29938 100644 --- a/src/class/cdc/cdc_rndis_host.c +++ b/src/class/cdc/cdc_rndis_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && CFG_TUSB_HOST_CDC && CFG_TUSB_HOST_CDC_RNDIS) +#if (MODE_HOST_SUPPORTED && CFG_TUH_CDC && CFG_TUH_CDC_RNDIS) #define _TINY_USB_SOURCE_FILE_ diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index baef7ff44..12bffdf2d 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if MODE_HOST_SUPPORTED & CFG_TUSB_HOST_MSC +#if MODE_HOST_SUPPORTED & CFG_TUH_MSC #define _TINY_USB_SOURCE_FILE_ diff --git a/src/host/hcd.h b/src/host/hcd.h index a6b1b7027..9637ca661 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -82,7 +82,7 @@ typedef struct // Max number of endpoints per device enum { HCD_MAX_ENDPOINT = CFG_TUH_HUB + CFG_TUSB_HOST_HID_KEYBOARD + CFG_TUSB_HOST_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC + - CFG_TUSB_HOST_MSC*2 + CFG_TUSB_HOST_CDC*3, + CFG_TUH_MSC*2 + CFG_TUH_CDC*3, HCD_MAX_XFER = HCD_MAX_ENDPOINT*2, }; diff --git a/src/tusb.h b/src/tusb.h index 4f8918ce5..e31513f87 100644 --- a/src/tusb.h +++ b/src/tusb.h @@ -59,11 +59,11 @@ #include "class/hid/hid_host.h" #endif - #if CFG_TUSB_HOST_MSC + #if CFG_TUH_MSC #include "class/msc/msc_host.h" #endif - #if CFG_TUSB_HOST_CDC + #if CFG_TUH_CDC #include "class/cdc/cdc_host.h" #endif 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 12dce0528..fe7d05516 100644 --- a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c +++ b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c @@ -51,7 +51,7 @@ #include "descriptor_cdc.h" #include "cdc_host.h" -#if CFG_TUSB_HOST_CDC_RNDIS // TODO enable +#if CFG_TUH_CDC_RNDIS // TODO enable #include "cdc_rndis_host.h" #endif diff --git a/tests/lpc18xx_43xx/test/host/host_helper.h b/tests/lpc18xx_43xx/test/host/host_helper.h index c293ec748..b8095b9aa 100644 --- a/tests/lpc18xx_43xx/test/host/host_helper.h +++ b/tests/lpc18xx_43xx/test/host/host_helper.h @@ -42,7 +42,7 @@ static inline void helper_class_init_expect(void) { // class code number order -#if CFG_TUSB_HOST_CDC +#if CFG_TUH_CDC cdch_init_Expect(); #endif @@ -50,7 +50,7 @@ static inline void helper_class_init_expect(void) hidh_init_Expect(); #endif -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC msch_init_Expect(); #endif diff --git a/tests/support/tusb_config.h b/tests/support/tusb_config.h index 3e5721019..3aacdabdc 100644 --- a/tests/support/tusb_config.h +++ b/tests/support/tusb_config.h @@ -58,10 +58,10 @@ #define CFG_TUH_HUB 0 #define CFG_TUSB_HOST_HID_KEYBOARD 1 #define CFG_TUSB_HOST_HID_MOUSE 1 -#define CFG_TUSB_HOST_MSC 1 +#define CFG_TUH_MSC 1 #define CFG_TUSB_HOST_HID_GENERIC 0 -#define CFG_TUSB_HOST_CDC 1 -#define CFG_TUSB_HOST_CDC_RNDIS 0 +#define CFG_TUH_CDC 1 +#define CFG_TUH_CDC_RNDIS 0 // Test support #define TEST_CONTROLLER_HOST_START_INDEX \ -- cgit v1.3.1 From 07c3fd5e1e6faf75c206a2abb8be739b78db801b Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Dec 2018 22:47:49 +0700 Subject: clean up hub --- examples/host/cdc_msc_hid/src/tusb_config.h | 2 +- src/class/cdc/cdc_host.c | 14 ++--- src/class/cdc/cdc_host.h | 8 +-- src/host/hub.c | 98 ++++++++++------------------- src/host/hub.h | 12 ++-- src/host/usbh.c | 60 +++++++++--------- src/host/usbh.h | 2 +- 7 files changed, 78 insertions(+), 118 deletions(-) (limited to 'src/class/cdc') diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index a77d9ba5e..ef0b55ef9 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -83,7 +83,7 @@ // DEVICE CONFIGURATION //-------------------------------------------------------------------- -#define CFG_TUH_HUB 1 +#define CFG_TUH_HUB 1 // not tested #define CFG_TUH_CDC 1 #define CFG_TUSB_HOST_HID_KEYBOARD 0 #define CFG_TUSB_HOST_HID_MOUSE 0 diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 2cf288a93..7bf23f37f 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -142,11 +142,9 @@ void cdch_init(void) tu_memclr(cdch_data, sizeof(cdch_data_t)*CFG_TUSB_HOST_DEVICE_MAX); } -tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) +bool cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) { - //OSAL_SUBTASK_BEGIN // TODO change following assert to subtask_assert - if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != p_interface_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS; if ( !(tu_within(CDC_COMM_PROTOCOL_ATCOMMAND, p_interface_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) || @@ -185,7 +183,7 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ (*p_length) += p_desc[DESC_OFFSET_LEN]; p_desc = descriptor_next(p_desc); - TU_ASSERT(pipehandle_is_valid(p_cdc->pipe_notification), TUSB_ERROR_HCD_OPEN_PIPE_FAILED); + TU_ASSERT(pipehandle_is_valid(p_cdc->pipe_notification)); } //------------- Data Interface (if any) -------------// @@ -199,14 +197,14 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ for(uint32_t i=0; i<2; i++) { tusb_desc_endpoint_t const *p_endpoint = (tusb_desc_endpoint_t const *) p_desc; - TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType, TUSB_ERROR_USBH_DESCRIPTOR_CORRUPTED); - TU_ASSERT(TUSB_XFER_BULK == p_endpoint->bmAttributes.xfer, TUSB_ERROR_USBH_DESCRIPTOR_CORRUPTED); + TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType); + TU_ASSERT(TUSB_XFER_BULK == p_endpoint->bmAttributes.xfer); pipe_handle_t * p_pipe_hdl = ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK ) ? &p_cdc->pipe_in : &p_cdc->pipe_out; (*p_pipe_hdl) = hcd_pipe_open(dev_addr, p_endpoint, TUSB_CLASS_CDC); - TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED ); + TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl) ); (*p_length) += p_desc[DESC_OFFSET_LEN]; p_desc = descriptor_next( p_desc ); @@ -218,7 +216,7 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ tuh_cdc_mounted_cb(dev_addr); } - //OSAL_SUBTASK_END + return true; } void cdch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h index 0b863bb61..3252aa48d 100644 --- a/src/class/cdc/cdc_host.h +++ b/src/class/cdc/cdc_host.h @@ -149,10 +149,10 @@ typedef struct { extern cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX]; // TODO consider to move to cdch internal header file -void cdch_init(void); -tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; -void cdch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); -void cdch_close(uint8_t dev_addr); +void cdch_init(void); +bool cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; +void cdch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); +void cdch_close(uint8_t dev_addr); #endif diff --git a/src/host/hub.c b/src/host/hub.c index 485e47147..a418774f6 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -67,76 +67,53 @@ ATTR_ALIGNED(4) CFG_TUSB_MEM_SECTION STATIC_VAR uint8_t hub_enum_buffer[sizeof(d //--------------------------------------------------------------------+ // HUB //--------------------------------------------------------------------+ -tusb_error_t hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t feature) +bool hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t feature) { - tusb_error_t error; - - OSAL_SUBTASK_BEGIN - - STASK_ASSERT(HUB_FEATURE_PORT_CONNECTION_CHANGE <= feature && - feature <= HUB_FEATURE_PORT_RESET_CHANGE); + TU_ASSERT(HUB_FEATURE_PORT_CONNECTION_CHANGE <= feature && feature <= HUB_FEATURE_PORT_RESET_CHANGE); //------------- Clear Port Feature request -------------// - STASK_INVOKE( - usbh_control_xfer_subtask( hub_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), - HUB_REQUEST_CLEAR_FEATURE, feature, hub_port, - 0, NULL ), - error - ); - STASK_ASSERT_ERR( error ); + TU_ASSERT( usbh_control_xfer_subtask( hub_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), + HUB_REQUEST_CLEAR_FEATURE, feature, hub_port, + 0, NULL ) ); //------------- Get Port Status to check if feature is cleared -------------// - STASK_INVOKE( - usbh_control_xfer_subtask( hub_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), - HUB_REQUEST_GET_STATUS, 0, hub_port, - 4, hub_enum_buffer ), - error - ); - STASK_ASSERT_ERR( error ); + TU_ASSERT( usbh_control_xfer_subtask( hub_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), + HUB_REQUEST_GET_STATUS, 0, hub_port, + 4, hub_enum_buffer ) ); //------------- Check if feature is cleared -------------// hub_port_status_response_t * p_port_status; p_port_status = (hub_port_status_response_t *) hub_enum_buffer; - STASK_ASSERT( !BIT_TEST_(p_port_status->status_change.value, feature-16) ); + TU_ASSERT( !BIT_TEST_(p_port_status->status_change.value, feature-16) ); - OSAL_SUBTASK_END + return true; } -tusb_error_t hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port) +bool hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port) { enum { RESET_DELAY = 200 }; // USB specs say only 50ms but many devices require much longer tusb_error_t error; - OSAL_SUBTASK_BEGIN - //------------- Set Port Reset -------------// - STASK_INVOKE( - usbh_control_xfer_subtask( hub_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), + TU_ASSERT( usbh_control_xfer_subtask( hub_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), HUB_REQUEST_SET_FEATURE, HUB_FEATURE_PORT_RESET, hub_port, - 0, NULL ), - error - ); - STASK_ASSERT_ERR( error ); + 0, NULL ) ); osal_task_delay(RESET_DELAY); // TODO Hub wait for Status Endpoint on Reset Change //------------- Get Port Status to check if port is enabled, powered and reset_change -------------// - STASK_INVOKE( - usbh_control_xfer_subtask( hub_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), - HUB_REQUEST_GET_STATUS, 0, hub_port, - 4, hub_enum_buffer ), - error - ); - STASK_ASSERT_ERR( error ); + TU_ASSERT( usbh_control_xfer_subtask( hub_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), + HUB_REQUEST_GET_STATUS, 0, hub_port, + 4, hub_enum_buffer ) ); hub_port_status_response_t * p_port_status; p_port_status = (hub_port_status_response_t *) hub_enum_buffer; - STASK_ASSERT ( p_port_status->status_change.reset && p_port_status->status_current.connect_status && - p_port_status->status_current.port_power && p_port_status->status_current.port_enable); + TU_ASSERT ( p_port_status->status_change.reset && p_port_status->status_current.connect_status && + p_port_status->status_current.port_power && p_port_status->status_current.port_enable); - OSAL_SUBTASK_END + return true; } // can only get the speed RIGHT AFTER hub_port_reset_subtask call @@ -156,36 +133,28 @@ void hub_init(void) // hub_enum_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(hub_enum_semaphore) ); } -tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) +bool hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) { - tusb_error_t error; - - OSAL_SUBTASK_BEGIN - // not support multiple TT yet - if ( p_interface_desc->bInterfaceProtocol > 1 ) return TUSB_ERROR_HUB_FEATURE_NOT_SUPPORTED; + if ( p_interface_desc->bInterfaceProtocol > 1 ) return false; //------------- Open Interrupt Status Pipe -------------// tusb_desc_endpoint_t const *p_endpoint; p_endpoint = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_interface_desc ); - STASK_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType); - STASK_ASSERT(TUSB_XFER_INTERRUPT == p_endpoint->bmAttributes.xfer); + TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType); + TU_ASSERT(TUSB_XFER_INTERRUPT == p_endpoint->bmAttributes.xfer); hub_data[dev_addr-1].pipe_status = hcd_pipe_open(dev_addr, p_endpoint, TUSB_CLASS_HUB); - STASK_ASSERT( pipehandle_is_valid(hub_data[dev_addr-1].pipe_status) ); + TU_ASSERT( pipehandle_is_valid(hub_data[dev_addr-1].pipe_status) ); hub_data[dev_addr-1].interface_number = p_interface_desc->bInterfaceNumber; (*p_length) = sizeof(tusb_desc_interface_t) + sizeof(tusb_desc_endpoint_t); //------------- Get Hub Descriptor -------------// - STASK_INVOKE( - usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_DEVICE), - HUB_REQUEST_GET_DESCRIPTOR, 0, 0, - sizeof(descriptor_hub_desc_t), hub_enum_buffer ), - error - ); - STASK_ASSERT_ERR(error); + TU_ASSERT( usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_DEVICE), + HUB_REQUEST_GET_DESCRIPTOR, 0, 0, + sizeof(descriptor_hub_desc_t), hub_enum_buffer ) ); // only care about this field in hub descriptor hub_data[dev_addr-1].port_number = ((descriptor_hub_desc_t*) hub_enum_buffer)->bNbrPorts; @@ -194,18 +163,15 @@ tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_i static uint8_t i; for(i=1; i <= hub_data[dev_addr-1].port_number; i++) { - STASK_INVOKE( - usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), - HUB_REQUEST_SET_FEATURE, HUB_FEATURE_PORT_POWER, i, - 0, NULL ), - error - ); + TU_ASSERT( usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), + HUB_REQUEST_SET_FEATURE, HUB_FEATURE_PORT_POWER, i, + 0, NULL ) ); } //------------- Queue the initial Status endpoint transfer -------------// - STASK_ASSERT_ERR ( hcd_pipe_xfer(hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true) ); + TU_ASSERT( TUSB_ERROR_NONE == hcd_pipe_xfer(hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true) ); - OSAL_SUBTASK_END + return true; } // is the response of interrupt endpoint polling diff --git a/src/host/hub.h b/src/host/hub.h index 9376a2698..b949be384 100644 --- a/src/host/hub.h +++ b/src/host/hub.h @@ -184,8 +184,8 @@ typedef struct { TU_VERIFY_STATIC( sizeof(hub_port_status_response_t) == 4, "size is not correct"); -tusb_error_t hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port); -tusb_error_t hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t feature); +bool hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port); +bool hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t feature); tusb_speed_t hub_port_get_speed(void); tusb_error_t hub_status_pipe_queue(uint8_t dev_addr); @@ -194,10 +194,10 @@ tusb_error_t hub_status_pipe_queue(uint8_t dev_addr); //--------------------------------------------------------------------+ #ifdef _TINY_USB_SOURCE_FILE_ -void hub_init(void); -tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; -void hub_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); -void hub_close(uint8_t dev_addr); +void hub_init(void); +bool hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; +void hub_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); +void hub_close(uint8_t dev_addr); #endif diff --git a/src/host/usbh.c b/src/host/usbh.c index dc13030c3..b18714635 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -76,7 +76,7 @@ static host_class_driver_t const usbh_class_drivers[] = }, #endif - #if CFG_TUSB_HOST_CDC + #if CFG_TUH_CDC [TUSB_CLASS_CDC] = { .init = cdch_init, .open_subtask = cdch_open_subtask, @@ -85,7 +85,7 @@ static host_class_driver_t const usbh_class_drivers[] = }, #endif - #if CFG_TUSB_HOST_MSC + #if CFG_TUH_MSC [TUSB_CLASS_MSC] = { .init = msch_init, .open_subtask = msch_open_subtask, @@ -404,40 +404,37 @@ bool usbh_task_body(void) else { //------------- Get Port Status -------------// - STASK_INVOKE( - usbh_control_xfer_subtask( usbh_devices[0].hub_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), - HUB_REQUEST_GET_STATUS, 0, usbh_devices[0].hub_port, - 4, enum_data_buffer ), - error - ); -// STASK_ASSERT_ERR( error ); - STASK_ASSERT_ERR_HDLR(error, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor + TU_VERIFY_HDLR( usbh_control_xfer_subtask( usbh_devices[0].hub_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), + HUB_REQUEST_GET_STATUS, 0, usbh_devices[0].hub_port, + 4, enum_data_buffer ) + , hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor // Acknowledge Port Connection Change - STASK_INVOKE( hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_CONNECTION_CHANGE), error ); + hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_CONNECTION_CHANGE); hub_port_status_response_t * p_port_status; p_port_status = ((hub_port_status_response_t *) enum_data_buffer); - if ( ! p_port_status->status_change.connect_status ) STASK_RETURN(TUSB_ERROR_NONE); // only handle connection change + if ( ! p_port_status->status_change.connect_status ) return true; // only handle connection change if ( ! p_port_status->status_current.connect_status ) - { // Disconnection event + { + // Disconnection event usbh_device_unplugged(usbh_devices[0].core_id, usbh_devices[0].hub_addr, usbh_devices[0].hub_port); (void) hub_status_pipe_queue( usbh_devices[0].hub_addr ); // done with hub, waiting for next data on status pipe - STASK_RETURN(TUSB_ERROR_NONE); // restart task + return true; // restart task } else - { // Connection Event - STASK_INVOKE ( hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port), error ); -// STASK_ASSERT_ERR( error ); - STASK_ASSERT_ERR_HDLR(error, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor + { + // Connection Event + TU_VERIFY_HDLR(hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port), + hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor usbh_devices[0].speed = hub_port_get_speed(); // Acknowledge Port Reset Change - STASK_INVOKE( hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE), error ); + hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE); } } #endif @@ -446,27 +443,28 @@ bool usbh_task_body(void) usbh_devices[0].state = TUSB_DEVICE_STATE_ADDRESSED; //------------- Get first 8 bytes of device descriptor to get Control Endpoint Size -------------// - // TODO some slow device is observed to fail the very fist controller xfer, can try more times - TU_ASSERT(usbh_control_xfer_subtask(0, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE), - TUSB_REQ_GET_DESCRIPTOR, - (TUSB_DESC_DEVICE << 8), 0, 8, enum_data_buffer)); + bool is_ok = usbh_control_xfer_subtask(0, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE), + TUSB_REQ_GET_DESCRIPTOR, + (TUSB_DESC_DEVICE << 8), 0, 8, enum_data_buffer); //------------- Reset device again before Set Address -------------// if (usbh_devices[0].hub_addr == 0) { // connected directly to roothub + TU_ASSERT(is_ok); // TODO some slow device is observed to fail the very fist controller xfer, can try more times hcd_port_reset( usbh_devices[0].core_id ); // reset port after 8 byte descriptor osal_task_delay(RESET_DELAY); } #if CFG_TUH_HUB else - { // connected via a hub - STASK_ASSERT_ERR_HDLR(error, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor - STASK_INVOKE ( hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port), error ); + { + // connected via a hub + TU_VERIFY_HDLR(is_ok, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor - if ( TUSB_ERROR_NONE == error ) - { // Acknowledge Port Reset Change if Reset Successful - STASK_INVOKE( hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE), error ); + if ( hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port) ) + { + // Acknowledge Port Reset Change if Reset Successful + hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE); } (void) hub_status_pipe_queue( usbh_devices[0].hub_addr ); // done with hub, waiting for next data on status pipe @@ -560,9 +558,7 @@ bool usbh_task_body(void) static uint16_t length; length = 0; - error = usbh_class_drivers[class_index].open_subtask( new_addr, (tusb_desc_interface_t*) p_desc, &length ); - - if (error == TUSB_ERROR_NONE) + if ( usbh_class_drivers[class_index].open_subtask(new_addr, (tusb_desc_interface_t*) p_desc, &length) ) { TU_ASSERT( length >= sizeof(tusb_desc_interface_t) ); usbh_devices[new_addr].flag_supported_class |= BIT_(class_index); diff --git a/src/host/usbh.h b/src/host/usbh.h index 4909eb8a7..bcbf2902c 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -65,7 +65,7 @@ typedef enum tusb_interface_status_{ typedef struct { void (* const init) (void); - tusb_error_t (* const open_subtask)(uint8_t, tusb_desc_interface_t const *, uint16_t*); + bool (* const open_subtask)(uint8_t, tusb_desc_interface_t const *, uint16_t*); void (* const isr) (pipe_handle_t, xfer_result_t, uint32_t); void (* const close) (uint8_t); } host_class_driver_t; -- cgit v1.3.1 From ac829c0a873a252ea9256aade275892b4ae509a5 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Dec 2018 22:50:19 +0700 Subject: minor clean up --- src/class/cdc/cdc_host.c | 9 +----- src/host/usbh.c | 75 ++++++++++++++++++++++-------------------------- src/host/usbh_hcd.h | 4 --- 3 files changed, 35 insertions(+), 53 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 7bf23f37f..2aafdb934 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -69,13 +69,7 @@ static inline cdc_pipeid_t get_app_pipeid(pipe_handle_t pipe_hdl) static inline bool tusbh_cdc_is_mounted(uint8_t dev_addr) { -// FIXME cannot use mounted class flag as at the point _open_sublass is called, the flag is not set yet -#ifdef _TEST_ - return (tusbh_device_get_mounted_class_flag(dev_addr) & BIT_(TUSB_CLASS_CDC)) != 0; -#else - return pipehandle_is_valid(cdch_data[dev_addr-1].pipe_in) && - pipehandle_is_valid(cdch_data[dev_addr-1].pipe_out); -#endif + return pipehandle_is_valid(cdch_data[dev_addr-1].pipe_in) && pipehandle_is_valid(cdch_data[dev_addr-1].pipe_out); } bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) @@ -100,7 +94,6 @@ bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) } } - //--------------------------------------------------------------------+ // APPLICATION API (parameter validation needed) //--------------------------------------------------------------------+ diff --git a/src/host/usbh.c b/src/host/usbh.c index b18714635..215f4e05e 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -361,7 +361,6 @@ bool usbh_task_body(void) RESET_DELAY = 200 // USB specs say only 50ms but many devices require much longer }; - tusb_error_t error; usbh_enumerate_t enum_entry; // for OSAL_NONE local variable won't retain value after blocking service sem_wait/queue_recv @@ -371,31 +370,33 @@ bool usbh_task_body(void) if ( !osal_queue_receive(_usbh_q, &enum_entry) ) return false; - usbh_devices[0].core_id = enum_entry.core_id; // TODO refractor integrate to device_pool - usbh_devices[0].hub_addr = enum_entry.hub_addr; - usbh_devices[0].hub_port = enum_entry.hub_port; - usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG; + usbh_device_info_t* dev0 = &usbh_devices[0]; + + dev0->core_id = enum_entry.core_id; // TODO refractor integrate to device_pool + dev0->hub_addr = enum_entry.hub_addr; + dev0->hub_port = enum_entry.hub_port; + dev0->state = TUSB_DEVICE_STATE_UNPLUG; //------------- connected/disconnected directly with roothub -------------// - if ( usbh_devices[0].hub_addr == 0) + if ( dev0->hub_addr == 0) { - if( hcd_port_connect_status(usbh_devices[0].core_id) ) + if( hcd_port_connect_status(dev0->core_id) ) { // connection event osal_task_delay(POWER_STABLE_DELAY); // wait until device is stable. Increase this if the first 8 bytes is failed to get // exit if device unplugged while delaying - if ( !hcd_port_connect_status(usbh_devices[0].core_id) ) return true; + if ( !hcd_port_connect_status(dev0->core_id) ) return true; - hcd_port_reset( usbh_devices[0].core_id ); // port must be reset to have correct speed operation + hcd_port_reset( dev0->core_id ); // port must be reset to have correct speed operation osal_task_delay(RESET_DELAY); - usbh_devices[0].speed = hcd_port_speed_get( usbh_devices[0].core_id ); + dev0->speed = hcd_port_speed_get( dev0->core_id ); } else { // disconnection event - usbh_device_unplugged(usbh_devices[0].core_id, 0, 0); + usbh_device_unplugged(dev0->core_id, 0, 0); return true; // restart task } } @@ -404,13 +405,13 @@ bool usbh_task_body(void) else { //------------- Get Port Status -------------// - TU_VERIFY_HDLR( usbh_control_xfer_subtask( usbh_devices[0].hub_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), - HUB_REQUEST_GET_STATUS, 0, usbh_devices[0].hub_port, + TU_VERIFY_HDLR( usbh_control_xfer_subtask( dev0->hub_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), + HUB_REQUEST_GET_STATUS, 0, dev0->hub_port, 4, enum_data_buffer ) - , hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor + , hub_status_pipe_queue( dev0->hub_addr) ); // TODO hub refractor // Acknowledge Port Connection Change - hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_CONNECTION_CHANGE); + hub_port_clear_feature_subtask(dev0->hub_addr, dev0->hub_port, HUB_FEATURE_PORT_CONNECTION_CHANGE); hub_port_status_response_t * p_port_status; p_port_status = ((hub_port_status_response_t *) enum_data_buffer); @@ -420,27 +421,27 @@ bool usbh_task_body(void) if ( ! p_port_status->status_current.connect_status ) { // Disconnection event - usbh_device_unplugged(usbh_devices[0].core_id, usbh_devices[0].hub_addr, usbh_devices[0].hub_port); + usbh_device_unplugged(dev0->core_id, dev0->hub_addr, dev0->hub_port); - (void) hub_status_pipe_queue( usbh_devices[0].hub_addr ); // done with hub, waiting for next data on status pipe + (void) hub_status_pipe_queue( dev0->hub_addr ); // done with hub, waiting for next data on status pipe return true; // restart task } else { // Connection Event - TU_VERIFY_HDLR(hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port), - hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor + TU_VERIFY_HDLR(hub_port_reset_subtask(dev0->hub_addr, dev0->hub_port), + hub_status_pipe_queue( dev0->hub_addr) ); // TODO hub refractor - usbh_devices[0].speed = hub_port_get_speed(); + dev0->speed = hub_port_get_speed(); // Acknowledge Port Reset Change - hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE); + hub_port_clear_feature_subtask(dev0->hub_addr, dev0->hub_port, HUB_FEATURE_PORT_RESET_CHANGE); } } #endif TU_ASSERT_ERR( usbh_pipe_control_open(0, 8) ); - usbh_devices[0].state = TUSB_DEVICE_STATE_ADDRESSED; + dev0->state = TUSB_DEVICE_STATE_ADDRESSED; //------------- Get first 8 bytes of device descriptor to get Control Endpoint Size -------------// bool is_ok = usbh_control_xfer_subtask(0, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE), @@ -448,26 +449,26 @@ bool usbh_task_body(void) (TUSB_DESC_DEVICE << 8), 0, 8, enum_data_buffer); //------------- Reset device again before Set Address -------------// - if (usbh_devices[0].hub_addr == 0) + if (dev0->hub_addr == 0) { // connected directly to roothub TU_ASSERT(is_ok); // TODO some slow device is observed to fail the very fist controller xfer, can try more times - hcd_port_reset( usbh_devices[0].core_id ); // reset port after 8 byte descriptor + hcd_port_reset( dev0->core_id ); // reset port after 8 byte descriptor osal_task_delay(RESET_DELAY); } #if CFG_TUH_HUB else { // connected via a hub - TU_VERIFY_HDLR(is_ok, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor + TU_VERIFY_HDLR(is_ok, hub_status_pipe_queue( dev0->hub_addr) ); // TODO hub refractor - if ( hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port) ) + if ( hub_port_reset_subtask(dev0->hub_addr, dev0->hub_port) ) { // Acknowledge Port Reset Change if Reset Successful - hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE); + hub_port_clear_feature_subtask(dev0->hub_addr, dev0->hub_port, HUB_FEATURE_PORT_RESET_CHANGE); } - (void) hub_status_pipe_queue( usbh_devices[0].hub_addr ); // done with hub, waiting for next data on status pipe + (void) hub_status_pipe_queue( dev0->hub_addr ); // done with hub, waiting for next data on status pipe } #endif @@ -480,14 +481,14 @@ bool usbh_task_body(void) 0, NULL )); //------------- update port info & close control pipe of addr0 -------------// - usbh_devices[new_addr].core_id = usbh_devices[0].core_id; - usbh_devices[new_addr].hub_addr = usbh_devices[0].hub_addr; - usbh_devices[new_addr].hub_port = usbh_devices[0].hub_port; - usbh_devices[new_addr].speed = usbh_devices[0].speed; + usbh_devices[new_addr].core_id = dev0->core_id; + usbh_devices[new_addr].hub_addr = dev0->hub_addr; + usbh_devices[new_addr].hub_port = dev0->hub_port; + usbh_devices[new_addr].speed = dev0->speed; usbh_devices[new_addr].state = TUSB_DEVICE_STATE_ADDRESSED; usbh_pipe_control_close(0); - usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG; + dev0->state = TUSB_DEVICE_STATE_UNPLUG; // open control pipe for new address TU_ASSERT_ERR ( usbh_pipe_control_open(new_addr, ((tusb_desc_device_t*) enum_data_buffer)->bMaxPacketSize0 ) ); @@ -599,14 +600,6 @@ void usbh_task(void* param) #endif } -//--------------------------------------------------------------------+ -// REPORTER TASK & ITS DATA -//--------------------------------------------------------------------+ - - - - - //--------------------------------------------------------------------+ // INTERNAL HELPER //--------------------------------------------------------------------+ diff --git a/src/host/usbh_hcd.h b/src/host/usbh_hcd.h index cd2a712e4..19a9f2286 100644 --- a/src/host/usbh_hcd.h +++ b/src/host/usbh_hcd.h @@ -52,10 +52,6 @@ #include "common/tusb_common.h" #include "osal/osal.h" -#ifdef _TEST_ -#include "hcd.h" -#endif - //--------------------------------------------------------------------+ // USBH-HCD common data structure //--------------------------------------------------------------------+ -- cgit v1.3.1 From 9b74f0e98f267c5fe650f501b500c2b8413f4e27 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 7 Dec 2018 15:07:00 +0700 Subject: add connect to cdc for testing --- src/class/cdc/cdc_host.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 2aafdb934..c4ec88416 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -66,7 +66,6 @@ static inline cdc_pipeid_t get_app_pipeid(pipe_handle_t pipe_hdl) pipehandle_is_equal( pipe_hdl, p_cdc->pipe_out ) ? CDC_PIPE_DATA_OUT : CDC_PIPE_ERROR; } - static inline bool tusbh_cdc_is_mounted(uint8_t dev_addr) { return pipehandle_is_valid(cdch_data[dev_addr-1].pipe_in) && pipehandle_is_valid(cdch_data[dev_addr-1].pipe_out); @@ -204,10 +203,20 @@ bool cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac } } + // FIXME mounted class flag is not set yet + tuh_cdc_mounted_cb(dev_addr); + + // FIXME move to seperate API : connect + tusb_control_request_t request = { - // FIXME mounted class flag is not set yet - tuh_cdc_mounted_cb(dev_addr); - } + .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_INTERFACE, .type = TUSB_REQ_TYPE_CLASS, .direction = TUSB_DIR_OUT }, + .bRequest = CDC_REQUEST_SET_CONTROL_LINE_STATE, + .wValue = 0x03, // dtr on, cst on + .wIndex = p_cdc->interface_number, + .wLength = 0 + }; + + TU_ASSERT( usbh_control_xfer(dev_addr, &request, NULL) ); return true; } -- cgit v1.3.1 From e6e367913664140729fa88605da7f1dc52439e16 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 7 Dec 2018 17:37:54 +0700 Subject: simple cdc host demo work --- examples/host/cdc_msc_hid/src/main.c | 6 ++++++ examples/host/cdc_msc_hid/src/tusb_config.h | 6 +++--- src/class/cdc/cdc_host.h | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src/class/cdc') diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c index 88d7cd4de..7f8b9d6e2 100644 --- a/examples/host/cdc_msc_hid/src/main.c +++ b/examples/host/cdc_msc_hid/src/main.c @@ -82,11 +82,14 @@ int main(void) // USB CDC //--------------------------------------------------------------------+ #if CFG_TUH_CDC +CFG_TUSB_MEM_SECTION static char serial_in_buffer[64] = { 0 }; void tuh_cdc_mounted_cb(uint8_t dev_addr) { // application set-up printf("\na CDC device (address %d) is mounted\n", dev_addr); + + tuh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true); // schedule first transfer } void tuh_cdc_unmounted_cb(uint8_t dev_addr) @@ -98,7 +101,10 @@ void tuh_cdc_unmounted_cb(uint8_t dev_addr) // invoked ISR context void tuh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes) { + printf(serial_in_buffer); + tu_memclr(serial_in_buffer, sizeof(serial_in_buffer)); + tuh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true); // waiting for next data } void virtual_com_task(void) diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index b7a766796..ea411d3f4 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -82,10 +82,10 @@ #define CFG_TUH_HUB 1 // not tested #define CFG_TUH_CDC 1 -#define CFG_TUH_HID_KEYBOARD 1 -#define CFG_TUH_HID_MOUSE 1 +#define CFG_TUH_HID_KEYBOARD 0 +#define CFG_TUH_HID_MOUSE 0 #define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) -#define CFG_TUH_MSC 1 +#define CFG_TUH_MSC 0 #define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h index 3252aa48d..13d7b710c 100644 --- a/src/class/cdc/cdc_host.h +++ b/src/class/cdc/cdc_host.h @@ -62,7 +62,7 @@ * \retval true if device supports * \retval false if device does not support or is not mounted */ -bool tuh_cdc_serial_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; +bool tuh_cdc_serial_is_mounted(uint8_t dev_addr); /** \brief Check if the interface is currently busy or not * \param[in] dev_addr device address @@ -73,7 +73,7 @@ bool tuh_cdc_serial_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESU * can be scheduled. User needs to make sure the corresponding interface is mounted * (by \ref tuh_cdc_serial_is_mounted) before calling this function. */ -bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) ATTR_PURE ATTR_WARN_UNUSED_RESULT; +bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid); /** \brief Perform USB OUT transfer to device * \param[in] dev_addr device address -- cgit v1.3.1 From 607658d047a3c27a096b9f6a25ea0a76f3d8735d Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 7 Dec 2018 23:38:52 +0700 Subject: rename MODE_HOST_SUPPORTED to TUSB_OPT_HOST_ENABLED --- hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c | 2 +- src/class/cdc/cdc_host.c | 2 +- src/class/cdc/cdc_rndis_host.c | 2 +- src/class/custom/custom_host.c | 2 +- src/class/hid/hid_host.c | 2 +- src/class/msc/msc_host.c | 2 +- src/host/ehci/ehci.c | 2 +- src/host/hcd.h | 2 +- src/host/hub.c | 2 +- src/host/ohci/ohci.c | 2 +- src/host/usbh.c | 2 +- src/osal/osal_none.h | 6 +++--- src/portable/nxp/lpc17_40/hal_lpc17_40.c | 2 +- src/portable/nxp/lpc18_43/hal_lpc18_43.c | 4 ++-- src/tusb.c | 4 ++-- src/tusb.h | 2 +- src/tusb_option.h | 11 ++--------- 17 files changed, 22 insertions(+), 29 deletions(-) (limited to 'src/class/cdc') diff --git a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c index 0c5f5189c..427e8733c 100644 --- a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c +++ b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c @@ -148,7 +148,7 @@ void board_init(void) LPC_USB->OTGClkCtrl = clk_en; while ( (LPC_USB->OTGClkSt & clk_en) != clk_en ); -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED // set portfunc to host !!! LPC_USB->StCtrl = 0x3; // should be 1 #endif diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index c4ec88416..8d7c2bd40 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && CFG_TUH_CDC) +#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_CDC) #define _TINY_USB_SOURCE_FILE_ diff --git a/src/class/cdc/cdc_rndis_host.c b/src/class/cdc/cdc_rndis_host.c index df4a29938..ae61bf8b5 100644 --- a/src/class/cdc/cdc_rndis_host.c +++ b/src/class/cdc/cdc_rndis_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && CFG_TUH_CDC && CFG_TUH_CDC_RNDIS) +#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_CDC && CFG_TUH_CDC_RNDIS) #define _TINY_USB_SOURCE_FILE_ diff --git a/src/class/custom/custom_host.c b/src/class/custom/custom_host.c index 9f0b70afb..2a8206e36 100644 --- a/src/class/custom/custom_host.c +++ b/src/class/custom/custom_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && CFG_TUSB_HOST_CUSTOM_CLASS) +#if (TUSB_OPT_HOST_ENABLED && CFG_TUSB_HOST_CUSTOM_CLASS) #define _TINY_USB_SOURCE_FILE_ diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 14398aa67..980381bf5 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && HOST_CLASS_HID) +#if (TUSB_OPT_HOST_ENABLED && HOST_CLASS_HID) #define _TINY_USB_SOURCE_FILE_ //--------------------------------------------------------------------+ diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 0c52011df..57a409ffd 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if MODE_HOST_SUPPORTED & CFG_TUH_MSC +#if TUSB_OPT_HOST_ENABLED & CFG_TUH_MSC #define _TINY_USB_SOURCE_FILE_ diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index 8e40804d5..d18f19195 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -38,7 +38,7 @@ #include "common/tusb_common.h" -#if MODE_HOST_SUPPORTED && (CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX) +#if TUSB_OPT_HOST_ENABLED && (CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX) //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ diff --git a/src/host/hcd.h b/src/host/hcd.h index db80994c0..387fbcf1c 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -79,7 +79,7 @@ typedef struct } hcd_event_t; -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED // Max number of endpoints per device enum { HCD_MAX_ENDPOINT = CFG_TUH_HUB + CFG_TUH_HID_KEYBOARD + CFG_TUH_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC + diff --git a/src/host/hub.c b/src/host/hub.c index 28814ebd7..04618d448 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && CFG_TUH_HUB) +#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_HUB) #define _TINY_USB_SOURCE_FILE_ diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index 3944d72d0..2c22a3c98 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -38,7 +38,7 @@ #include -#if MODE_HOST_SUPPORTED && (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC40XX) +#if TUSB_OPT_HOST_ENABLED && (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC40XX) //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ diff --git a/src/host/usbh.c b/src/host/usbh.c index 4c4fd5319..d97b4b0d3 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -38,7 +38,7 @@ #include "common/tusb_common.h" -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED #define _TINY_USB_SOURCE_FILE_ diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 4da5cffc8..ff37113c6 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -134,7 +134,7 @@ extern void dcd_int_disable(uint8_t rhport); extern void dcd_int_enable(uint8_t rhport); #endif -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED extern void hcd_int_disable(uint8_t rhport); extern void hcd_int_enable(uint8_t rhport); #endif @@ -167,7 +167,7 @@ static inline void _osal_q_lock(osal_queue_t qhdl) if (qhdl->role == OPT_MODE_DEVICE) dcd_int_disable(TUD_OPT_RHPORT); #endif -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED if (qhdl->role == OPT_MODE_HOST) hcd_int_disable(TUH_OPT_RHPORT); #endif } @@ -179,7 +179,7 @@ static inline void _osal_q_unlock(osal_queue_t qhdl) if (qhdl->role == OPT_MODE_DEVICE) dcd_int_enable(TUD_OPT_RHPORT); #endif -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED if (qhdl->role == OPT_MODE_HOST) hcd_int_enable(TUH_OPT_RHPORT); #endif } diff --git a/src/portable/nxp/lpc17_40/hal_lpc17_40.c b/src/portable/nxp/lpc17_40/hal_lpc17_40.c index 2acd19f6e..04aebf920 100644 --- a/src/portable/nxp/lpc17_40/hal_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/hal_lpc17_40.c @@ -47,7 +47,7 @@ extern void hal_dcd_isr(uint8_t rhport); void USB_IRQHandler(void) { - #if MODE_HOST_SUPPORTED + #if TUSB_OPT_HOST_ENABLED hal_hcd_isr(0); #endif diff --git a/src/portable/nxp/lpc18_43/hal_lpc18_43.c b/src/portable/nxp/lpc18_43/hal_lpc18_43.c index 48a25f99a..ef3977995 100644 --- a/src/portable/nxp/lpc18_43/hal_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/hal_lpc18_43.c @@ -48,7 +48,7 @@ extern void hal_hcd_isr(uint8_t hostid); #if CFG_TUSB_RHPORT0_MODE void USB0_IRQHandler(void) { - #if MODE_HOST_SUPPORTED + #if TUSB_OPT_HOST_ENABLED hal_hcd_isr(0); #endif @@ -61,7 +61,7 @@ void USB0_IRQHandler(void) #if CFG_TUSB_RHPORT1_MODE void USB1_IRQHandler(void) { - #if MODE_HOST_SUPPORTED + #if TUSB_OPT_HOST_ENABLED hal_hcd_isr(1); #endif diff --git a/src/tusb.c b/src/tusb.c index 931cc0ebe..4f7996664 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -55,7 +55,7 @@ bool tusb_init(void) // skip if already initialized if (_initialized) return true; -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED TU_VERIFY( usbh_init() ); // init host stack #endif @@ -71,7 +71,7 @@ bool tusb_init(void) #if CFG_TUSB_OS == OPT_OS_NONE void tusb_task(void) { - #if MODE_HOST_SUPPORTED + #if TUSB_OPT_HOST_ENABLED usbh_task(NULL); #endif diff --git a/src/tusb.h b/src/tusb.h index e31513f87..4d65c80e1 100644 --- a/src/tusb.h +++ b/src/tusb.h @@ -52,7 +52,7 @@ #include "common/tusb_fifo.h" //------------- HOST -------------// -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED #include "host/usbh.h" #if HOST_CLASS_HID diff --git a/src/tusb_option.h b/src/tusb_option.h index ad5025235..e8baf4149 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -109,13 +109,6 @@ #error "tinyusb does not support same modes on more than 1 roothub port" #endif -// TODO remove -#define CONTROLLER_HOST_NUMBER (\ - ((CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST) ? 1 : 0) + \ - ((CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST) ? 1 : 0)) - -#define MODE_HOST_SUPPORTED (CONTROLLER_HOST_NUMBER > 0) - // Which roothub port is configured as host #define TUH_OPT_RHPORT ( (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST) ? 0 : ((CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST) ? 1 : -1) ) #define TUSB_OPT_HOST_ENABLED ( TUH_OPT_RHPORT >= 0 ) @@ -206,7 +199,7 @@ //-------------------------------------------------------------------- // HOST OPTIONS //-------------------------------------------------------------------- -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED #ifndef CFG_TUSB_HOST_DEVICE_MAX #define CFG_TUSB_HOST_DEVICE_MAX 1 #warning CFG_TUSB_HOST_DEVICE_MAX is not defined, default value is 1 @@ -228,7 +221,7 @@ #endif //------------- CLASS -------------// -#endif // MODE_HOST_SUPPORTED +#endif // TUSB_OPT_HOST_ENABLED //------------------------------------------------------------------ -- cgit v1.3.1 From 05913a73501c8e2ea1a88299f6b900f92307aaa7 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 9 Dec 2018 12:34:05 +0700 Subject: change usbh class driver open signature --- src/class/cdc/cdc_host.c | 6 +- src/class/cdc/cdc_host.h | 2 +- src/host/ehci/ehci.c | 117 ++++++++++++--------- src/host/ehci/ehci.h | 2 +- src/host/hcd.h | 2 +- src/host/hub.c | 6 +- src/host/hub.h | 2 +- src/host/usbh.c | 30 +++--- src/host/usbh.h | 2 +- src/host/usbh_hcd.h | 2 +- tests/lpc18xx_43xx/test/host/host_helper.h | 2 +- tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c | 24 ++--- tests/support/ehci_controller_fake.c | 4 +- 13 files changed, 111 insertions(+), 90 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 8d7c2bd40..5e410fbf9 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -134,7 +134,7 @@ void cdch_init(void) tu_memclr(cdch_data, sizeof(cdch_data_t)*CFG_TUSB_HOST_DEVICE_MAX); } -bool cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) +bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) { // TODO change following assert to subtask_assert if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != p_interface_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS; @@ -170,7 +170,7 @@ bool cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE]) { // notification endpoint if any - p_cdc->pipe_notification = hcd_pipe_open(dev_addr, (tusb_desc_endpoint_t const *) p_desc, TUSB_CLASS_CDC); + p_cdc->pipe_notification = hcd_pipe_open(rhport, dev_addr, (tusb_desc_endpoint_t const *) p_desc, TUSB_CLASS_CDC); (*p_length) += p_desc[DESC_OFFSET_LEN]; p_desc = descriptor_next(p_desc); @@ -195,7 +195,7 @@ bool cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac pipe_handle_t * p_pipe_hdl = ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK ) ? &p_cdc->pipe_in : &p_cdc->pipe_out; - (*p_pipe_hdl) = hcd_pipe_open(dev_addr, p_endpoint, TUSB_CLASS_CDC); + (*p_pipe_hdl) = hcd_pipe_open(rhport, dev_addr, p_endpoint, TUSB_CLASS_CDC); TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl) ); (*p_length) += p_desc[DESC_OFFSET_LEN]; diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h index 13d7b710c..faf4cfe93 100644 --- a/src/class/cdc/cdc_host.h +++ b/src/class/cdc/cdc_host.h @@ -150,7 +150,7 @@ typedef struct { extern cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX]; // TODO consider to move to cdch internal header file void cdch_init(void); -bool cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; +bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; void cdch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); void cdch_close(uint8_t dev_addr); diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index 1d2ad5787..dadd377bc 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -100,15 +100,15 @@ static inline ehci_qhd_t* qhd_find_free (uint8_t dev_addr) ATTR_PURE ATTR_ALW static inline tusb_xfer_type_t qhd_get_xfer_type(ehci_qhd_t const * p_qhd) ATTR_ALWAYS_INLINE ATTR_PURE; static inline ehci_qhd_t* qhd_get_from_pipe_handle(pipe_handle_t pipe_hdl) ATTR_PURE ATTR_ALWAYS_INLINE; static inline pipe_handle_t qhd_create_pipe_handle(ehci_qhd_t const * p_qhd, tusb_xfer_type_t xfer_type) ATTR_PURE ATTR_ALWAYS_INLINE; + // determine if a queue head has bus-related error -static inline bool qhd_has_xact_error(ehci_qhd_t * p_qhd) ATTR_ALWAYS_INLINE ATTR_PURE; static inline bool qhd_has_xact_error(ehci_qhd_t * p_qhd) { return ( p_qhd->qtd_overlay.buffer_err ||p_qhd->qtd_overlay.babble_err || p_qhd->qtd_overlay.xact_err ); //p_qhd->qtd_overlay.non_hs_period_missed_uframe || p_qhd->qtd_overlay.pingstate_err TODO split transaction error } -static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_size, uint8_t endpoint_addr, uint8_t xfer_type, uint8_t interval); +static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); static inline ehci_qtd_t* qtd_find_free(uint8_t dev_addr) ATTR_PURE ATTR_ALWAYS_INLINE; @@ -123,7 +123,6 @@ static ehci_link_t* list_find_previous_item(ehci_link_t* p_head, ehci_link_t* p static tusb_error_t list_remove_qhd(ehci_link_t* p_head, ehci_link_t* p_remove); static bool ehci_init(uint8_t hostid); -static tusb_error_t hcd_controller_stop(uint8_t hostid) ATTR_WARN_UNUSED_RESULT ATTR_UNUSED; //--------------------------------------------------------------------+ // USBH-HCD API @@ -279,21 +278,21 @@ static tusb_error_t hcd_controller_stop(uint8_t hostid) //--------------------------------------------------------------------+ // CONTROL PIPE API //--------------------------------------------------------------------+ -bool hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) -{ - ehci_qhd_t * const p_qhd = get_control_qhd(dev_addr); - - qhd_init(p_qhd, dev_addr, max_packet_size, 0, TUSB_XFER_CONTROL, 1); // TODO binterval of control is ignored - - if (dev_addr != 0) - { - //------------- insert to async list -------------// - list_insert( (ehci_link_t*) get_async_head(_usbh_devices[dev_addr].core_id), - (ehci_link_t*) p_qhd, EHCI_QUEUE_ELEMENT_QHD); - } - - return true; -} +//bool hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) +//{ +// ehci_qhd_t * const p_qhd = get_control_qhd(dev_addr); +// +// qhd_init(p_qhd, dev_addr, max_packet_size, 0, TUSB_XFER_CONTROL, 1); // TODO binterval of control is ignored +// +// if (dev_addr != 0) +// { +// //------------- insert to async list -------------// +// list_insert( (ehci_link_t*) get_async_head(_usbh_devices[dev_addr].core_id), +// (ehci_link_t*) p_qhd, EHCI_QUEUE_ELEMENT_QHD); +// } +// +// return true; +//} //bool hcd_pipe_control_xfer(uint8_t dev_addr, tusb_control_request_t const * p_request, uint8_t data[]) //{ @@ -345,7 +344,7 @@ bool hcd_pipe_control_close(uint8_t dev_addr) if (dev_addr != 0) { - TU_ASSERT_ERR( list_remove_qhd( (ehci_link_t*) get_async_head( _usbh_devices[dev_addr].core_id ), + TU_ASSERT_ERR( list_remove_qhd( (ehci_link_t*) get_async_head( _usbh_devices[dev_addr].rhport ), (ehci_link_t*) p_qhd) ); } @@ -356,7 +355,9 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const* { // FIXME control only for now (void) rhport; - return hcd_pipe_control_open(dev_addr, ep_desc->wMaxPacketSize.size); + hcd_pipe_open(rhport, dev_addr, ep_desc, 0); + + return true; } bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) @@ -418,42 +419,59 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet //--------------------------------------------------------------------+ // BULK/INT/ISO PIPE API //--------------------------------------------------------------------+ -pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_desc_endpoint_t const * p_endpoint_desc, uint8_t class_code) +pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc, uint8_t class_code) { pipe_handle_t const null_handle = { .dev_addr = 0, .xfer_type = 0, .index = 0 }; - TU_ASSERT(dev_addr > 0, null_handle); - - if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) - return null_handle; // TODO not support ISO yet + // TODO not support ISO yet + if (ep_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) return null_handle; //------------- Prepare Queue Head -------------// - ehci_qhd_t * const p_qhd = qhd_find_free(dev_addr); + ehci_qhd_t * p_qhd; + + if ( ep_desc->bEndpointAddress == 0 ) + { + p_qhd = get_control_qhd(dev_addr); + }else + { + p_qhd = qhd_find_free(dev_addr); + } TU_ASSERT(p_qhd, null_handle); - qhd_init( p_qhd, dev_addr, p_endpoint_desc->wMaxPacketSize.size, p_endpoint_desc->bEndpointAddress, - p_endpoint_desc->bmAttributes.xfer, p_endpoint_desc->bInterval ); + qhd_init( p_qhd, dev_addr, ep_desc); p_qhd->class_code = class_code; //------------- Insert to Async List -------------// ehci_link_t * list_head; - if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_BULK) + switch (ep_desc->bmAttributes.xfer) { - list_head = (ehci_link_t*) get_async_head(_usbh_devices[dev_addr].core_id); - } - #if EHCI_PERIODIC_LIST // TODO refractor/group this together - else if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_INTERRUPT) - { - list_head = get_period_head(_usbh_devices[dev_addr].core_id, p_qhd->interval_ms); + case TUSB_XFER_CONTROL: + list_head = (ehci_link_t*) get_async_head(_usbh_devices[dev_addr].rhport); + break; + + case TUSB_XFER_BULK: + list_head = (ehci_link_t*) get_async_head(_usbh_devices[dev_addr].rhport); + break; + + #if EHCI_PERIODIC_LIST // TODO refractor/group this together + case TUSB_XFER_INTERRUPT: + list_head = get_period_head(_usbh_devices[dev_addr].rhport, p_qhd->interval_ms); + break; + #endif + + case TUSB_XFER_ISOCHRONOUS: + // TODO iso is not supported + break; + + default: break; } - #endif - //------------- insert to async/period list TODO might need to disable async/period list -------------// - list_insert( list_head, - (ehci_link_t*) p_qhd, EHCI_QUEUE_ELEMENT_QHD); + //------------- insert to async/period list -------------// + // TODO might need to disable async/period list + list_insert( list_head, (ehci_link_t*) p_qhd, EHCI_QUEUE_ELEMENT_QHD); - return (pipe_handle_t) { .dev_addr = dev_addr, .xfer_type = p_endpoint_desc->bmAttributes.xfer, .index = qhd_get_index(p_qhd) }; + return (pipe_handle_t) { .dev_addr = dev_addr, .xfer_type = ep_desc->bmAttributes.xfer, .index = qhd_get_index(p_qhd) }; } tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) @@ -507,14 +525,14 @@ tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) if ( pipe_hdl.xfer_type == TUSB_XFER_BULK ) { TU_ASSERT_ERR( list_remove_qhd( - (ehci_link_t*) get_async_head( _usbh_devices[pipe_hdl.dev_addr].core_id ), + (ehci_link_t*) get_async_head( _usbh_devices[pipe_hdl.dev_addr].rhport ), (ehci_link_t*) p_qhd) ); } #if EHCI_PERIODIC_LIST // TODO refractor/group this together else { TU_ASSERT_ERR( list_remove_qhd( - get_period_head( _usbh_devices[pipe_hdl.dev_addr].core_id, p_qhd->interval_ms ), + get_period_head( _usbh_devices[pipe_hdl.dev_addr].rhport, p_qhd->interval_ms ), (ehci_link_t*) p_qhd) ); } #endif @@ -882,7 +900,7 @@ static inline ehci_link_t* get_period_head(uint8_t hostid, uint8_t interval_ms) static inline ehci_qhd_t* get_control_qhd(uint8_t dev_addr) { return (dev_addr == 0) ? - get_async_head( _usbh_devices[dev_addr].core_id ) : + get_async_head( _usbh_devices[dev_addr].rhport ) : &ehci_data.device[dev_addr-1].control.qhd; } static inline ehci_qtd_t* get_control_qtds(uint8_t dev_addr) @@ -978,7 +996,7 @@ static inline void qtd_insert_to_qhd(ehci_qhd_t *p_qhd, ehci_qtd_t *p_qtd_new) } } -static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_size, uint8_t endpoint_addr, uint8_t xfer_type, uint8_t interval) +static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) { // address 0 is used as async head, which always on the list --> cannot be cleared (ehci halted otherwise) if (dev_addr != 0) @@ -986,14 +1004,17 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si tu_memclr(p_qhd, sizeof(ehci_qhd_t)); } + uint8_t const xfer_type = ep_desc->bmAttributes.xfer; + uint8_t const interval = ep_desc->bInterval; + p_qhd->device_address = dev_addr; p_qhd->non_hs_period_inactive_next_xact = 0; - p_qhd->endpoint_number = endpoint_addr & 0x0F; + p_qhd->endpoint_number = edpt_number(ep_desc->bEndpointAddress); p_qhd->endpoint_speed = _usbh_devices[dev_addr].speed; p_qhd->data_toggle_control = (xfer_type == TUSB_XFER_CONTROL) ? 1 : 0; p_qhd->head_list_flag = (dev_addr == 0) ? 1 : 0; // addr0's endpoint is the static asyn list head - p_qhd->max_package_size = max_packet_size; - p_qhd->non_hs_control_endpoint = ((TUSB_XFER_CONTROL == xfer_type) && (p_qhd->endpoint_speed != TUSB_SPEED_HIGH)) ? 1 : 0; + p_qhd->max_package_size = ep_desc->wMaxPacketSize.size; + p_qhd->non_hs_control_endpoint = ((xfer_type == TUSB_XFER_CONTROL) && (p_qhd->endpoint_speed != TUSB_SPEED_HIGH)) ? 1 : 0; p_qhd->nak_count_reload = 0; // Bulk/Control -> smask = cmask = 0 @@ -1035,7 +1056,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si p_qhd->is_removing = 0; p_qhd->p_qtd_list_head = NULL; p_qhd->p_qtd_list_tail = NULL; - p_qhd->pid_non_control = (endpoint_addr & 0x80) ? EHCI_PID_IN : EHCI_PID_OUT; // PID for TD under this endpoint + p_qhd->pid_non_control = edpt_dir(ep_desc->bEndpointAddress) ? EHCI_PID_IN : EHCI_PID_OUT; // PID for TD under this endpoint //------------- active, but no TD list -------------// p_qhd->qtd_overlay.halted = 0; diff --git a/src/host/ehci/ehci.h b/src/host/ehci/ehci.h index 4f6a721fd..b06a6f8b1 100644 --- a/src/host/ehci/ehci.h +++ b/src/host/ehci/ehci.h @@ -467,7 +467,7 @@ typedef struct ehci_qtd_t qtd; }control; - ehci_qhd_t qhd[HCD_MAX_ENDPOINT] ; ///< Queue Head Pool + ehci_qhd_t qhd[HCD_MAX_ENDPOINT] ; ///< Queue Head Pool ehci_qtd_t qtd[HCD_MAX_XFER] ATTR_ALIGNED(32) ; ///< Queue Element Transfer Pool // ehci_itd_t itd[EHCI_MAX_ITD] ; ///< Iso Transfer Pool // ehci_sitd_t sitd[EHCI_MAX_SITD] ; ///< Split (FS) Isochronous Transfer Pool diff --git a/src/host/hcd.h b/src/host/hcd.h index a5ee63c8c..6c7a3e98c 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -140,7 +140,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * //--------------------------------------------------------------------+ // TODO control xfer should be used via usbh layer -pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_desc_endpoint_t const * endpoint_desc, uint8_t class_code) ATTR_WARN_UNUSED_RESULT; +pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * endpoint_desc, uint8_t class_code) ATTR_WARN_UNUSED_RESULT; tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) /*ATTR_WARN_UNUSED_RESULT*/; diff --git a/src/host/hub.c b/src/host/hub.c index bc1434471..0b909bef0 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -155,7 +155,7 @@ void hub_init(void) // hub_enum_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(hub_enum_semaphore) ); } -bool hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) +bool hub_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) { // not support multiple TT yet if ( p_interface_desc->bInterfaceProtocol > 1 ) return false; @@ -167,7 +167,7 @@ bool hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType); TU_ASSERT(TUSB_XFER_INTERRUPT == p_endpoint->bmAttributes.xfer); - hub_data[dev_addr-1].pipe_status = hcd_pipe_open(dev_addr, p_endpoint, TUSB_CLASS_HUB); + hub_data[dev_addr-1].pipe_status = hcd_pipe_open(rhport, dev_addr, p_endpoint, TUSB_CLASS_HUB); TU_ASSERT( pipehandle_is_valid(hub_data[dev_addr-1].pipe_status) ); hub_data[dev_addr-1].interface_number = p_interface_desc->bInterfaceNumber; @@ -226,7 +226,7 @@ void hub_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes { hcd_event_t event = { - .rhport = _usbh_devices[pipe_hdl.dev_addr].core_id, + .rhport = _usbh_devices[pipe_hdl.dev_addr].rhport, .event_id = HCD_EVENT_DEVICE_ATTACH }; diff --git a/src/host/hub.h b/src/host/hub.h index b949be384..8d1fece4b 100644 --- a/src/host/hub.h +++ b/src/host/hub.h @@ -195,7 +195,7 @@ tusb_error_t hub_status_pipe_queue(uint8_t dev_addr); #ifdef _TINY_USB_SOURCE_FILE_ void hub_init(void); -bool hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; +bool hub_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; void hub_isr(pipe_handle_t pipe_hdl, 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 c3a56031f..4e3643aac 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -193,7 +193,7 @@ bool usbh_init(void) bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8_t* data) { usbh_device_t* dev = &_usbh_devices[dev_addr]; - const uint8_t rhport = dev->core_id; + const uint8_t rhport = dev->rhport; TU_ASSERT(osal_mutex_lock(dev->control.mutex_hdl, OSAL_TIMEOUT_NORMAL)); @@ -242,14 +242,14 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) .bInterval = 0 }; - hcd_edpt_open(_usbh_devices[dev_addr].core_id, dev_addr, &ep0_desc); + hcd_edpt_open(_usbh_devices[dev_addr].rhport, dev_addr, &ep0_desc); return TUSB_ERROR_NONE; } static inline tusb_error_t usbh_pipe_control_close(uint8_t dev_addr) { - hcd_edpt_close(_usbh_devices[dev_addr].core_id, dev_addr, 0); + hcd_edpt_close(_usbh_devices[dev_addr].rhport, dev_addr, 0); return TUSB_ERROR_NONE; } @@ -338,7 +338,7 @@ static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_ //------------- find the all devices (star-network) under port that is unplugged -------------// for (uint8_t dev_addr = 0; dev_addr <= CFG_TUSB_HOST_DEVICE_MAX; dev_addr ++) { - if (_usbh_devices[dev_addr].core_id == hostid && + if (_usbh_devices[dev_addr].rhport == hostid && (hub_addr == 0 || _usbh_devices[dev_addr].hub_addr == hub_addr) && // hub_addr == 0 & hub_port == 0 means roothub (hub_port == 0 || _usbh_devices[dev_addr].hub_port == hub_port) && _usbh_devices[dev_addr].state != TUSB_DEVICE_STATE_UNPLUG) @@ -365,7 +365,7 @@ static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_ } } - if (is_found) hcd_port_unplug(_usbh_devices[0].core_id); // TODO hack + if (is_found) hcd_port_unplug(_usbh_devices[0].rhport); // TODO hack } @@ -393,7 +393,7 @@ bool enum_task(hcd_event_t* event) usbh_device_t* dev0 = &_usbh_devices[0]; tusb_control_request_t request; - dev0->core_id = event->rhport; // TODO refractor integrate to device_pool + dev0->rhport = event->rhport; // TODO refractor integrate to device_pool dev0->hub_addr = event->attach.hub_addr; dev0->hub_port = event->attach.hub_port; dev0->state = TUSB_DEVICE_STATE_UNPLUG; @@ -401,23 +401,23 @@ bool enum_task(hcd_event_t* event) //------------- connected/disconnected directly with roothub -------------// if ( dev0->hub_addr == 0) { - if( hcd_port_connect_status(dev0->core_id) ) + if( hcd_port_connect_status(dev0->rhport) ) { // connection event osal_task_delay(POWER_STABLE_DELAY); // wait until device is stable. Increase this if the first 8 bytes is failed to get // exit if device unplugged while delaying - if ( !hcd_port_connect_status(dev0->core_id) ) return true; + if ( !hcd_port_connect_status(dev0->rhport) ) return true; - hcd_port_reset( dev0->core_id ); // port must be reset to have correct speed operation + hcd_port_reset( dev0->rhport ); // port must be reset to have correct speed operation osal_task_delay(RESET_DELAY); - dev0->speed = hcd_port_speed_get( dev0->core_id ); + dev0->speed = hcd_port_speed_get( dev0->rhport ); } else { // disconnection event - usbh_device_unplugged(dev0->core_id, 0, 0); + usbh_device_unplugged(dev0->rhport, 0, 0); return true; // restart task } } @@ -447,7 +447,7 @@ bool enum_task(hcd_event_t* event) if ( ! p_port_status->status_current.connect_status ) { // Disconnection event - usbh_device_unplugged(dev0->core_id, dev0->hub_addr, dev0->hub_port); + usbh_device_unplugged(dev0->rhport, dev0->hub_addr, dev0->hub_port); (void) hub_status_pipe_queue( dev0->hub_addr ); // done with hub, waiting for next data on status pipe return true; // restart task @@ -484,7 +484,7 @@ bool enum_task(hcd_event_t* event) { // connected directly to roothub TU_ASSERT(is_ok); // TODO some slow device is observed to fail the very fist controller xfer, can try more times - hcd_port_reset( dev0->core_id ); // reset port after 8 byte descriptor + hcd_port_reset( dev0->rhport ); // reset port after 8 byte descriptor osal_task_delay(RESET_DELAY); } #if CFG_TUH_HUB @@ -518,7 +518,7 @@ bool enum_task(hcd_event_t* event) //------------- update port info & close control pipe of addr0 -------------// usbh_device_t* new_dev = &_usbh_devices[new_addr]; - new_dev->core_id = dev0->core_id; + new_dev->rhport = dev0->rhport; new_dev->hub_addr = dev0->hub_addr; new_dev->hub_port = dev0->hub_port; new_dev->speed = dev0->speed; @@ -606,7 +606,7 @@ bool enum_task(hcd_event_t* event) static uint16_t length; length = 0; - if ( usbh_class_drivers[class_index].open_subtask(new_addr, (tusb_desc_interface_t*) p_desc, &length) ) + if ( usbh_class_drivers[class_index].open_subtask(new_dev->rhport, new_addr, (tusb_desc_interface_t*) p_desc, &length) ) { TU_ASSERT( length >= sizeof(tusb_desc_interface_t) ); new_dev->flag_supported_class |= BIT_(class_index); diff --git a/src/host/usbh.h b/src/host/usbh.h index 039997a24..584d8cdbd 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -65,7 +65,7 @@ typedef enum tusb_interface_status_{ typedef struct { void (* const init) (void); - bool (* const open_subtask)(uint8_t, tusb_desc_interface_t const *, uint16_t*); + bool (* const open_subtask)(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *, uint16_t* outlen); void (* const isr) (pipe_handle_t, xfer_result_t, uint32_t); void (* const close) (uint8_t); } host_class_driver_t; diff --git a/src/host/usbh_hcd.h b/src/host/usbh_hcd.h index 66a0e2d93..7ccbe3a25 100644 --- a/src/host/usbh_hcd.h +++ b/src/host/usbh_hcd.h @@ -57,7 +57,7 @@ //--------------------------------------------------------------------+ typedef struct { //------------- port -------------// - uint8_t core_id; + uint8_t rhport; uint8_t hub_addr; uint8_t hub_port; uint8_t speed; diff --git a/tests/lpc18xx_43xx/test/host/host_helper.h b/tests/lpc18xx_43xx/test/host/host_helper.h index 13996d1ce..183254e7e 100644 --- a/tests/lpc18xx_43xx/test/host/host_helper.h +++ b/tests/lpc18xx_43xx/test/host/host_helper.h @@ -69,7 +69,7 @@ static inline void helper_usbh_init_expect(void) static inline void helper_usbh_device_emulate(uint8_t dev_addr, uint8_t hub_addr, uint8_t hub_port, uint8_t hostid, tusb_speed_t speed) { - _usbh_devices[dev_addr].core_id = hostid; + _usbh_devices[dev_addr].rhport = hostid; _usbh_devices[dev_addr].hub_addr = hub_addr; _usbh_devices[dev_addr].hub_port = hub_port; _usbh_devices[dev_addr].speed = speed; 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 5c11c3011..85f9cf813 100644 --- a/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c +++ b/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c @@ -55,7 +55,7 @@ extern usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; extern uint8_t enum_data_buffer[CFG_TUSB_HOST_ENUM_BUFFER_SIZE]; usbh_enumerate_t const enum_connect = { - .core_id = 0, + .rhport = 0, .hub_addr = 0, .hub_port = 0, }; @@ -82,12 +82,12 @@ void setUp(void) osal_mutex_release_IgnoreAndReturn(TUSB_ERROR_NONE); hcd_pipe_control_xfer_StubWithCallback(control_xfer_stub); - hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); + hcd_port_connect_status_ExpectAndReturn(enum_connect.rhport, true); osal_task_delay_Expect(POWER_STABLE_DELAY); - hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); - hcd_port_reset_Expect(enum_connect.core_id); + hcd_port_connect_status_ExpectAndReturn(enum_connect.rhport, true); + hcd_port_reset_Expect(enum_connect.rhport); osal_task_delay_Expect(RESET_DELAY); - hcd_port_speed_get_ExpectAndReturn(enum_connect.core_id, device_speed); + hcd_port_speed_get_ExpectAndReturn(enum_connect.rhport, device_speed); osal_semaphore_reset_Expect( _usbh_devices[0].control.sem_hdl ); osal_mutex_reset_Expect( _usbh_devices[0].control.mutex_hdl ); @@ -229,7 +229,7 @@ void test_addr0_failed_dev_desc(void) void test_addr0_failed_set_address(void) { osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(1)); - hcd_port_reset_Expect( _usbh_devices[0].core_id ); + hcd_port_reset_Expect( _usbh_devices[0].rhport ); osal_task_delay_Expect(RESET_DELAY); // tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); @@ -242,7 +242,7 @@ void test_addr0_failed_set_address(void) void test_enum_failed_get_full_dev_desc(void) { osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(2)); - hcd_port_reset_Expect( _usbh_devices[0].core_id ); + hcd_port_reset_Expect( _usbh_devices[0].rhport ); osal_task_delay_Expect(RESET_DELAY); hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); @@ -256,7 +256,7 @@ void test_enum_failed_get_full_dev_desc(void) TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, _usbh_devices[0].state); TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, _usbh_devices[1].state); TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, _usbh_devices[1].speed); - TEST_ASSERT_EQUAL(enum_connect.core_id, _usbh_devices[1].core_id); + TEST_ASSERT_EQUAL(enum_connect.rhport, _usbh_devices[1].rhport); TEST_ASSERT_EQUAL(enum_connect.hub_addr, _usbh_devices[1].hub_addr); TEST_ASSERT_EQUAL(enum_connect.hub_port, _usbh_devices[1].hub_port); } @@ -264,7 +264,7 @@ void test_enum_failed_get_full_dev_desc(void) void test_enum_failed_get_9byte_config_desc(void) { osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(3)); - hcd_port_reset_Expect( _usbh_devices[0].core_id ); + hcd_port_reset_Expect( _usbh_devices[0].rhport ); osal_task_delay_Expect(RESET_DELAY); hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); osal_semaphore_reset_Expect( _usbh_devices[0].control.sem_hdl ); @@ -284,7 +284,7 @@ void test_enum_failed_get_9byte_config_desc(void) void test_enum_failed_get_full_config_desc(void) { osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(4)); - hcd_port_reset_Expect( _usbh_devices[0].core_id ); + hcd_port_reset_Expect( _usbh_devices[0].rhport ); osal_task_delay_Expect(RESET_DELAY); hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); osal_semaphore_reset_Expect( _usbh_devices[0].control.sem_hdl ); @@ -299,7 +299,7 @@ void test_enum_failed_get_full_config_desc(void) void test_enum_parse_config_desc(void) { osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(5)); - hcd_port_reset_Expect( _usbh_devices[0].core_id ); + hcd_port_reset_Expect( _usbh_devices[0].rhport ); osal_task_delay_Expect(RESET_DELAY); hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); osal_semaphore_reset_Expect( _usbh_devices[0].control.sem_hdl ); @@ -317,7 +317,7 @@ void test_enum_parse_config_desc(void) void test_enum_set_configure(void) { osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(6)); - hcd_port_reset_Expect( _usbh_devices[0].core_id ); + hcd_port_reset_Expect( _usbh_devices[0].rhport ); osal_task_delay_Expect(RESET_DELAY); hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); osal_semaphore_reset_Expect( _usbh_devices[0].control.sem_hdl ); diff --git a/tests/support/ehci_controller_fake.c b/tests/support/ehci_controller_fake.c index 2c6c919a7..eed72e20c 100644 --- a/tests/support/ehci_controller_fake.c +++ b/tests/support/ehci_controller_fake.c @@ -67,7 +67,7 @@ void ehci_controller_init(void) void ehci_controller_control_xfer_proceed(uint8_t dev_addr, uint8_t p_data[]) { - ehci_registers_t* const regs = get_operational_register( _usbh_devices[dev_addr].core_id ); + ehci_registers_t* const regs = get_operational_register( _usbh_devices[dev_addr].rhport ); ehci_qhd_t * p_qhd = get_control_qhd(dev_addr); ehci_qtd_t * p_qtd_setup = get_control_qtds(dev_addr); ehci_qtd_t * p_qtd_data = p_qtd_setup + 1; @@ -86,7 +86,7 @@ void ehci_controller_control_xfer_proceed(uint8_t dev_addr, uint8_t p_data[]) regs->usb_sts = EHCI_INT_MASK_NXP_ASYNC | EHCI_INT_MASK_NXP_PERIODIC; - hcd_isr( _usbh_devices[dev_addr].core_id ); + hcd_isr( _usbh_devices[dev_addr].rhport ); } void complete_qtd_in_qhd(ehci_qhd_t *p_qhd) -- cgit v1.3.1 From a31f83dbb0d123d15dcc393dd9d926a4cc7352b6 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Dec 2018 05:40:02 +0700 Subject: removing pipe handle --- src/class/cdc/cdc_host.c | 13 ++----------- src/class/cdc/cdc_host.h | 2 +- src/host/ehci/ehci.c | 4 ++-- src/host/hub.c | 8 ++++---- src/host/hub.h | 2 +- src/host/usbh.c | 7 +++---- src/host/usbh.h | 2 +- src/host/usbh_hcd.h | 2 +- 8 files changed, 15 insertions(+), 25 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 5e410fbf9..6eadca23d 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -57,15 +57,6 @@ //--------------------------------------------------------------------+ STATIC_VAR cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX]; // TODO to be static -static inline cdc_pipeid_t get_app_pipeid(pipe_handle_t pipe_hdl) -{ - cdch_data_t const * p_cdc = &cdch_data[pipe_hdl.dev_addr-1]; - - return pipehandle_is_equal( pipe_hdl, p_cdc->pipe_notification ) ? CDC_PIPE_NOTIFICATION : - pipehandle_is_equal( pipe_hdl, p_cdc->pipe_in ) ? CDC_PIPE_DATA_IN : - pipehandle_is_equal( pipe_hdl, p_cdc->pipe_out ) ? CDC_PIPE_DATA_OUT : CDC_PIPE_ERROR; -} - static inline bool tusbh_cdc_is_mounted(uint8_t dev_addr) { return pipehandle_is_valid(cdch_data[dev_addr-1].pipe_in) && pipehandle_is_valid(cdch_data[dev_addr-1].pipe_out); @@ -221,9 +212,9 @@ bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t c return true; } -void cdch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) +void cdch_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes) { - tuh_cdc_xfer_isr( pipe_hdl.dev_addr, event, get_app_pipeid(pipe_hdl), xferred_bytes ); + tuh_cdc_xfer_isr( dev_addr, event, 0, xferred_bytes ); } void cdch_close(uint8_t dev_addr) diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h index faf4cfe93..02eaa16e4 100644 --- a/src/class/cdc/cdc_host.h +++ b/src/class/cdc/cdc_host.h @@ -151,7 +151,7 @@ extern cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX]; // TODO consider to move void cdch_init(void); bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; -void cdch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); +void cdch_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes); void cdch_close(uint8_t dev_addr); #endif diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index 2186bfcdf..445210c8b 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -647,7 +647,7 @@ static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd) { // end of request // call USBH callback - usbh_xfer_isr( qhd_create_pipe_handle(p_qhd), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes); + usbh_xfer_isr(p_qhd->device_address, edpt_addr(p_qhd->endpoint_number, p_qhd->pid_non_control == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes); p_qhd->total_xferred_bytes = 0; } @@ -741,7 +741,7 @@ static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd) } // call USBH callback - usbh_xfer_isr( qhd_create_pipe_handle(p_qhd), error_event, p_qhd->total_xferred_bytes); + usbh_xfer_isr(p_qhd->device_address, edpt_addr(p_qhd->endpoint_number, p_qhd->pid_non_control == EHCI_PID_IN ? 1 : 0), error_event, p_qhd->total_xferred_bytes); p_qhd->total_xferred_bytes = 0; } diff --git a/src/host/hub.c b/src/host/hub.c index 0b909bef0..5612f6cda 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -211,11 +211,11 @@ bool hub_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t co // is the response of interrupt endpoint polling #include "usbh_hcd.h" // FIXME remove -void hub_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) +void hub_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes) { (void) xferred_bytes; // TODO can be more than 1 for hub with lots of ports - usbh_hub_t * p_hub = &hub_data[pipe_hdl.dev_addr-1]; + usbh_hub_t * p_hub = &hub_data[dev_addr-1]; if ( event == XFER_RESULT_SUCCESS ) { @@ -226,11 +226,11 @@ void hub_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes { hcd_event_t event = { - .rhport = _usbh_devices[pipe_hdl.dev_addr].rhport, + .rhport = _usbh_devices[dev_addr].rhport, .event_id = HCD_EVENT_DEVICE_ATTACH }; - event.attach.hub_addr = pipe_hdl.dev_addr; + event.attach.hub_addr = dev_addr; event.attach.hub_port = port; hcd_event_handler(&event, true); diff --git a/src/host/hub.h b/src/host/hub.h index 8d1fece4b..8e8416d8f 100644 --- a/src/host/hub.h +++ b/src/host/hub.h @@ -196,7 +196,7 @@ tusb_error_t hub_status_pipe_queue(uint8_t dev_addr); void hub_init(void); bool hub_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; -void hub_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); +void hub_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes); void hub_close(uint8_t dev_addr); #endif diff --git a/src/host/usbh.c b/src/host/usbh.c index 0df7c1dc8..a9e825f70 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -256,10 +256,9 @@ static inline tusb_error_t usbh_pipe_control_close(uint8_t dev_addr) // USBH-HCD ISR/Callback API //--------------------------------------------------------------------+ // interrupt caused by a TD (with IOC=1) in pipe of class class_code -void usbh_xfer_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) +void usbh_xfer_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { - usbh_device_t* dev = &_usbh_devices[ pipe_hdl.dev_addr ]; - uint8_t ep_addr = pipe_hdl.ep_addr; + usbh_device_t* dev = &_usbh_devices[ dev_addr ]; if (0 == edpt_number(ep_addr)) { @@ -274,7 +273,7 @@ void usbh_xfer_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred if (usbh_class_drivers[drv_id].isr) { - usbh_class_drivers[drv_id].isr(pipe_hdl, event, xferred_bytes); + usbh_class_drivers[drv_id].isr(dev_addr , event, xferred_bytes); } else { diff --git a/src/host/usbh.h b/src/host/usbh.h index b04328e40..de43c8a4f 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -68,7 +68,7 @@ typedef struct { void (* const init) (void); bool (* const open_subtask)(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *, uint16_t* outlen); - void (* const isr) (pipe_handle_t, xfer_result_t, uint32_t); + void (* const isr) (uint8_t dev_addr, xfer_result_t, uint32_t); void (* const close) (uint8_t); } host_class_driver_t; //--------------------------------------------------------------------+ diff --git a/src/host/usbh_hcd.h b/src/host/usbh_hcd.h index ce4469233..3c1c1511d 100644 --- a/src/host/usbh_hcd.h +++ b/src/host/usbh_hcd.h @@ -96,7 +96,7 @@ extern usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zer //--------------------------------------------------------------------+ // callback from HCD ISR //--------------------------------------------------------------------+ -void usbh_xfer_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); +void usbh_xfer_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); #ifdef __cplusplus -- cgit v1.3.1 From a486da33eeddc3f2d5be948905132723fb2cb9c8 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Dec 2018 05:55:02 +0700 Subject: usbh clean up --- src/class/cdc/cdc_host.c | 14 +++++++------- src/class/cdc/cdc_host.h | 4 +--- src/host/usbh.c | 2 +- src/host/usbh.h | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 6eadca23d..2968fb576 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -55,16 +55,16 @@ //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ -STATIC_VAR cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX]; // TODO to be static +static cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX]; // TODO to be static -static inline bool tusbh_cdc_is_mounted(uint8_t dev_addr) +static inline bool tuh_cdc_mounted(uint8_t dev_addr) { return pipehandle_is_valid(cdch_data[dev_addr-1].pipe_in) && pipehandle_is_valid(cdch_data[dev_addr-1].pipe_out); } bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) { - if ( !tusbh_cdc_is_mounted(dev_addr) ) return false; + if ( !tuh_cdc_mounted(dev_addr) ) return false; cdch_data_t const * p_cdc = &cdch_data[dev_addr-1]; @@ -90,14 +90,14 @@ bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) bool tuh_cdc_serial_is_mounted(uint8_t dev_addr) { // TODO consider all AT Command as serial candidate - return tusbh_cdc_is_mounted(dev_addr) && + return tuh_cdc_mounted(dev_addr) && (CDC_COMM_PROTOCOL_ATCOMMAND <= cdch_data[dev_addr-1].interface_protocol) && (cdch_data[dev_addr-1].interface_protocol <= CDC_COMM_PROTOCOL_ATCOMMAND_CDMA); } tusb_error_t tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify) { - TU_ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); + TU_ASSERT( tuh_cdc_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); TU_ASSERT( p_data != NULL && length, TUSB_ERROR_INVALID_PARA); pipe_handle_t pipe_out = cdch_data[dev_addr-1].pipe_out; @@ -108,7 +108,7 @@ tusb_error_t tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length tusb_error_t tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify) { - TU_ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); + TU_ASSERT( tuh_cdc_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); TU_ASSERT( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA); pipe_handle_t pipe_in = cdch_data[dev_addr-1].pipe_in; @@ -212,7 +212,7 @@ bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t c return true; } -void cdch_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes) +void cdch_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { tuh_cdc_xfer_isr( dev_addr, event, 0, xferred_bytes ); } diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h index 02eaa16e4..2fbd40f40 100644 --- a/src/class/cdc/cdc_host.h +++ b/src/class/cdc/cdc_host.h @@ -147,11 +147,9 @@ typedef struct { } cdch_data_t; -extern cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX]; // TODO consider to move to cdch internal header file - void cdch_init(void); bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; -void cdch_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes); +void cdch_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void cdch_close(uint8_t dev_addr); #endif diff --git a/src/host/usbh.c b/src/host/usbh.c index ff9ca9666..c345ddf0d 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -273,7 +273,7 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev if (usbh_class_drivers[drv_id].isr) { - usbh_class_drivers[drv_id].isr(dev_addr , event, xferred_bytes); + usbh_class_drivers[drv_id].isr(dev_addr, ep_addr, event, xferred_bytes); } else { diff --git a/src/host/usbh.h b/src/host/usbh.h index de43c8a4f..390b04053 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -67,8 +67,8 @@ typedef struct { uint8_t class_code; void (* const init) (void); - bool (* const open_subtask)(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *, uint16_t* outlen); - void (* const isr) (uint8_t dev_addr, xfer_result_t, uint32_t); + bool (* const open_subtask)(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const * itf_desc, uint16_t* outlen); + void (* const isr) (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t len); void (* const close) (uint8_t); } host_class_driver_t; //--------------------------------------------------------------------+ -- cgit v1.3.1 From 0ae8a1aa896a1c258ccf8637f6c7bbfdf0adb356 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Dec 2018 16:58:17 +0700 Subject: remove pipe handle.dev_addr --- src/class/cdc/cdc_host.c | 20 ++++++++-------- src/host/ehci/ehci.c | 62 ++++++++++++++++++++++-------------------------- src/host/hcd.h | 25 ++++++++++--------- src/host/hub.c | 6 ++--- 4 files changed, 54 insertions(+), 59 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 2968fb576..290cbfb44 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -71,13 +71,13 @@ bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) switch (pipeid) { case CDC_PIPE_NOTIFICATION: - return hcd_pipe_is_busy( p_cdc->pipe_notification ); + return hcd_pipe_is_busy(dev_addr, p_cdc->pipe_notification ); case CDC_PIPE_DATA_IN: - return hcd_pipe_is_busy( p_cdc->pipe_in ); + return hcd_pipe_is_busy(dev_addr, p_cdc->pipe_in ); case CDC_PIPE_DATA_OUT: - return hcd_pipe_is_busy( p_cdc->pipe_out ); + return hcd_pipe_is_busy(dev_addr, p_cdc->pipe_out ); default: return false; @@ -101,9 +101,9 @@ tusb_error_t tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length TU_ASSERT( p_data != NULL && length, TUSB_ERROR_INVALID_PARA); pipe_handle_t pipe_out = cdch_data[dev_addr-1].pipe_out; - if ( hcd_pipe_is_busy(pipe_out) ) return TUSB_ERROR_INTERFACE_IS_BUSY; + if ( hcd_pipe_is_busy(dev_addr, pipe_out) ) return TUSB_ERROR_INTERFACE_IS_BUSY; - return hcd_pipe_xfer( pipe_out, (void *) p_data, length, is_notify); + return hcd_pipe_xfer(dev_addr, pipe_out, (void *) p_data, length, is_notify); } tusb_error_t tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify) @@ -112,9 +112,9 @@ tusb_error_t tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, TU_ASSERT( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA); pipe_handle_t pipe_in = cdch_data[dev_addr-1].pipe_in; - if ( hcd_pipe_is_busy(pipe_in) ) return TUSB_ERROR_INTERFACE_IS_BUSY; + if ( hcd_pipe_is_busy(dev_addr, pipe_in) ) return TUSB_ERROR_INTERFACE_IS_BUSY; - return hcd_pipe_xfer( pipe_in, p_buffer, length, is_notify); + return hcd_pipe_xfer(dev_addr, pipe_in, p_buffer, length, is_notify); } //--------------------------------------------------------------------+ @@ -221,9 +221,9 @@ void cdch_close(uint8_t dev_addr) { cdch_data_t * p_cdc = &cdch_data[dev_addr-1]; - (void) hcd_pipe_close(p_cdc->pipe_notification); - (void) hcd_pipe_close(p_cdc->pipe_in); - (void) hcd_pipe_close(p_cdc->pipe_out); + hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->pipe_notification); + hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->pipe_in); + hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->pipe_out); tu_memclr(p_cdc, sizeof(cdch_data_t)); diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index f21e4cee2..4989c74a0 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -98,7 +98,7 @@ static inline uint8_t qhd_get_index(ehci_qhd_t const * p_qhd) ATTR_ALWAYS static inline ehci_qhd_t* qhd_next(ehci_qhd_t const * p_qhd) ATTR_ALWAYS_INLINE ATTR_PURE; static inline ehci_qhd_t* qhd_find_free (uint8_t dev_addr) ATTR_PURE ATTR_ALWAYS_INLINE; static inline tusb_xfer_type_t qhd_get_xfer_type(ehci_qhd_t const * p_qhd) ATTR_ALWAYS_INLINE ATTR_PURE; -static inline ehci_qhd_t* qhd_get_from_pipe_handle(pipe_handle_t pipe_hdl) ATTR_PURE ATTR_ALWAYS_INLINE; +static inline ehci_qhd_t* qhd_get_from_pipe_handle(uint8_t dev_addr, pipe_handle_t pipe_hdl); static inline pipe_handle_t qhd_create_pipe_handle(ehci_qhd_t const * p_qhd); // determine if a queue head has bus-related error @@ -421,7 +421,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet //--------------------------------------------------------------------+ pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc, uint8_t class_code) { - pipe_handle_t const null_handle = { .dev_addr = 0, .index = 0 }; + pipe_handle_t const null_handle = { .index = 0 }; // TODO not support ISO yet if (ep_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) return null_handle; @@ -470,16 +470,16 @@ pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint // TODO might need to disable async/period list list_insert( list_head, (ehci_link_t*) p_qhd, EHCI_QUEUE_ELEMENT_QHD); - return (pipe_handle_t) { .dev_addr = dev_addr, .index = qhd_get_index(p_qhd) }; + return (pipe_handle_t) { .index = qhd_get_index(p_qhd) }; } -tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) +tusb_error_t hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) { //------------- TODO pipe handle validate -------------// //------------- set up QTD -------------// - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl); - ehci_qtd_t *p_qtd = qtd_find_free(pipe_hdl.dev_addr); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); + ehci_qtd_t *p_qtd = qtd_find_free(dev_addr); TU_ASSERT(p_qtd, TUSB_ERROR_EHCI_NOT_ENOUGH_QTD); @@ -492,11 +492,11 @@ tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint return TUSB_ERROR_NONE; } -tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) +tusb_error_t hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) { - TU_ASSERT_ERR ( hcd_pipe_queue_xfer(pipe_hdl, buffer, total_bytes) ); + TU_ASSERT_ERR ( hcd_pipe_queue_xfer(dev_addr, pipe_hdl, buffer, total_bytes) ); - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); if ( int_on_complete ) { // the just added qtd is pointed by list_tail @@ -508,11 +508,9 @@ tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t t } /// pipe_close should only be called as a part of unmount/safe-remove process -tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) +bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, pipe_handle_t pipe_hdl) { - TU_ASSERT(pipe_hdl.dev_addr > 0, TUSB_ERROR_INVALID_PARA); - - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl ); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); // async list needs async advance handshake to make sure host controller has released cached data // non-control does not use async advance, it will eventually free by control pipe close @@ -522,48 +520,48 @@ tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) if ( p_qhd->xfer_type == TUSB_XFER_BULK ) { TU_ASSERT_ERR( list_remove_qhd( - (ehci_link_t*) get_async_head( _usbh_devices[pipe_hdl.dev_addr].rhport ), - (ehci_link_t*) p_qhd) ); + (ehci_link_t*) get_async_head( _usbh_devices[dev_addr].rhport ), + (ehci_link_t*) p_qhd), false ); } #if EHCI_PERIODIC_LIST // TODO refractor/group this together else { TU_ASSERT_ERR( list_remove_qhd( - get_period_head( _usbh_devices[pipe_hdl.dev_addr].rhport, p_qhd->interval_ms ), - (ehci_link_t*) p_qhd) ); + get_period_head( _usbh_devices[dev_addr].rhport, p_qhd->interval_ms ), + (ehci_link_t*) p_qhd), false ); } #endif - return TUSB_ERROR_NONE; + return true; } -bool hcd_pipe_is_busy(pipe_handle_t pipe_hdl) +bool hcd_pipe_is_busy(uint8_t dev_addr, pipe_handle_t pipe_hdl) { - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl ); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); return !p_qhd->qtd_overlay.halted && (p_qhd->p_qtd_list_head != NULL); } -bool hcd_pipe_is_error(pipe_handle_t pipe_hdl) +bool hcd_pipe_is_error(uint8_t dev_addr, pipe_handle_t pipe_hdl) { - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl ); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); return p_qhd->qtd_overlay.halted; } -bool hcd_pipe_is_stalled(pipe_handle_t pipe_hdl) +bool hcd_pipe_is_stalled(uint8_t dev_addr, pipe_handle_t pipe_hdl) { - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl ); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); return p_qhd->qtd_overlay.halted && !qhd_has_xact_error(p_qhd); } -uint8_t hcd_pipe_get_endpoint_addr(pipe_handle_t pipe_hdl) +uint8_t hcd_pipe_get_endpoint_addr(uint8_t dev_addr, pipe_handle_t pipe_hdl) { - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl ); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); return p_qhd->endpoint_number + ( (p_qhd->pid_non_control == EHCI_PID_IN) ? TUSB_DIR_IN_MASK : 0); } -tusb_error_t hcd_pipe_clear_stall(pipe_handle_t pipe_hdl) +tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, pipe_handle_t pipe_hdl) { - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl ); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); p_qhd->qtd_overlay.halted = 0; // TODO reset data toggle ? return TUSB_ERROR_NONE; @@ -927,16 +925,14 @@ static inline ehci_qhd_t* qhd_next(ehci_qhd_t const * p_qhd) return (ehci_qhd_t*) tu_align32(p_qhd->next.address); } -static inline ehci_qhd_t* qhd_get_from_pipe_handle(pipe_handle_t pipe_hdl) +static inline ehci_qhd_t* qhd_get_from_pipe_handle(uint8_t dev_addr, pipe_handle_t pipe_hdl) { - return &ehci_data.device[ pipe_hdl.dev_addr-1 ].qhd[ pipe_hdl.index ]; + return &ehci_data.device[dev_addr-1].qhd[pipe_hdl.index]; } static inline pipe_handle_t qhd_create_pipe_handle(ehci_qhd_t const * p_qhd) { - pipe_handle_t pipe_hdl = { - .dev_addr = p_qhd->device_address, - }; + pipe_handle_t pipe_hdl = { }; // TODO Isochronous transfer support if (TUSB_XFER_CONTROL != p_qhd->xfer_type) // qhd index for control is meaningless diff --git a/src/host/hcd.h b/src/host/hcd.h index 31a1876b4..6d86ae9e5 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -93,20 +93,19 @@ enum { // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ typedef struct { - uint8_t dev_addr; - uint8_t reserved; - uint8_t index; uint8_t ep_addr; + uint8_t index; + uint8_t reserved[2]; } pipe_handle_t; static inline bool pipehandle_is_valid(pipe_handle_t pipe_hdl) { - return pipe_hdl.dev_addr > 0; + return true ; // pipe_hdl.dev_addr > 0; } static inline bool pipehandle_is_equal(pipe_handle_t x, pipe_handle_t y) { - return (x.dev_addr == y.dev_addr) && (x.index == y.index); + return (x.index == y.index); } //--------------------------------------------------------------------+ @@ -144,16 +143,16 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * // TODO control xfer should be used via usbh layer pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * endpoint_desc, uint8_t class_code) ATTR_WARN_UNUSED_RESULT; -tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet -tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; -tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) /*ATTR_WARN_UNUSED_RESULT*/; +tusb_error_t hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet +tusb_error_t hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; +bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, pipe_handle_t pipe_hdl); -bool hcd_pipe_is_busy(pipe_handle_t pipe_hdl) ATTR_PURE; -bool hcd_pipe_is_error(pipe_handle_t pipe_hdl) ATTR_PURE; -bool hcd_pipe_is_stalled(pipe_handle_t pipe_hdl) ATTR_PURE; // stalled also counted as error +bool hcd_pipe_is_busy(uint8_t dev_addr, pipe_handle_t pipe_hdl); +bool hcd_pipe_is_error(uint8_t dev_addr, pipe_handle_t pipe_hdl); +bool hcd_pipe_is_stalled(uint8_t dev_addr, pipe_handle_t pipe_hdl); // stalled also counted as error +tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, pipe_handle_t pipe_hdl); -uint8_t hcd_pipe_get_endpoint_addr(pipe_handle_t pipe_hdl) ATTR_PURE; -tusb_error_t hcd_pipe_clear_stall(pipe_handle_t pipe_hdl); +uint8_t hcd_pipe_get_endpoint_addr(uint8_t dev_addr, pipe_handle_t pipe_hdl); #if 0 tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT; diff --git a/src/host/hub.c b/src/host/hub.c index 5612f6cda..2a71c45fc 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -204,7 +204,7 @@ bool hub_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t co } //------------- Queue the initial Status endpoint transfer -------------// - TU_ASSERT( TUSB_ERROR_NONE == hcd_pipe_xfer(hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true) ); + TU_ASSERT( TUSB_ERROR_NONE == hcd_pipe_xfer(dev_addr, hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true) ); return true; } @@ -248,7 +248,7 @@ void hub_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes) void hub_close(uint8_t dev_addr) { - (void) hcd_pipe_close(hub_data[dev_addr-1].pipe_status); + hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, hub_data[dev_addr-1].pipe_status); tu_memclr(&hub_data[dev_addr-1], sizeof(usbh_hub_t)); // osal_semaphore_reset(hub_enum_sem_hdl); @@ -256,7 +256,7 @@ void hub_close(uint8_t dev_addr) tusb_error_t hub_status_pipe_queue(uint8_t dev_addr) { - return hcd_pipe_xfer(hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true); + return hcd_pipe_xfer(dev_addr, hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true); } -- cgit v1.3.1 From 9c4c7975024e9b971a43a866c1feffb419dd8f5b Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Dec 2018 19:01:28 +0700 Subject: add ep addr to host cdc --- src/class/cdc/cdc_device.c | 7 +- src/class/cdc/cdc_host.c | 83 +++++++++++++-------- src/class/cdc/cdc_host.h | 12 +-- src/common/tusb_common.h | 61 ++++----------- src/device/usbd.c | 16 ++-- src/host/ehci/ehci.c | 86 +++++----------------- src/host/ehci/ehci.h | 8 +- .../test/host/ehci/test_ehci_structure.c | 2 +- 8 files changed, 104 insertions(+), 171 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index 040c8d4f4..d477a0d23 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -41,9 +41,7 @@ #if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_CDC) #define _TINY_USB_SOURCE_FILE_ -//--------------------------------------------------------------------+ -// INCLUDE -//--------------------------------------------------------------------+ + #include "cdc_device.h" #include "device/usbd_pvt.h" @@ -236,8 +234,7 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != p_interface_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS; // Only support AT commands, no protocol and vendor specific commands. - if ( !(tu_within(CDC_COMM_PROTOCOL_ATCOMMAND, p_interface_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) || - p_interface_desc->bInterfaceProtocol == CDC_COMM_PROTOCOL_NONE || + if ( !(tu_within(CDC_COMM_PROTOCOL_NONE, p_interface_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) || p_interface_desc->bInterfaceProtocol == 0xff ) ) { return TUSB_ERROR_CDC_UNSUPPORTED_PROTOCOL; diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 290cbfb44..0d0378920 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -42,24 +42,35 @@ #define _TINY_USB_SOURCE_FILE_ -//--------------------------------------------------------------------+ -// INCLUDE -//--------------------------------------------------------------------+ #include "common/tusb_common.h" #include "cdc_host.h" //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ +typedef struct { + uint8_t itf_num; + uint8_t itf_protocol; + + cdc_acm_capability_t acm_capability; + + pipe_handle_t pipe_notification, pipe_out, pipe_in; + + uint8_t ep_notif; + uint8_t ep_in; + uint8_t ep_out; + +} cdch_data_t; //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ -static cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX]; // TODO to be static +static cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX]; -static inline bool tuh_cdc_mounted(uint8_t dev_addr) +bool tuh_cdc_mounted(uint8_t dev_addr) { - return pipehandle_is_valid(cdch_data[dev_addr-1].pipe_in) && pipehandle_is_valid(cdch_data[dev_addr-1].pipe_out); + cdch_data_t* cdc = &cdch_data[dev_addr-1]; + return cdc->ep_in && cdc->ep_out; } bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) @@ -91,8 +102,8 @@ bool tuh_cdc_serial_is_mounted(uint8_t dev_addr) { // TODO consider all AT Command as serial candidate return tuh_cdc_mounted(dev_addr) && - (CDC_COMM_PROTOCOL_ATCOMMAND <= cdch_data[dev_addr-1].interface_protocol) && - (cdch_data[dev_addr-1].interface_protocol <= CDC_COMM_PROTOCOL_ATCOMMAND_CDMA); + (CDC_COMM_PROTOCOL_ATCOMMAND <= cdch_data[dev_addr-1].itf_protocol) && + (cdch_data[dev_addr-1].itf_protocol <= CDC_COMM_PROTOCOL_ATCOMMAND_CDMA); } tusb_error_t tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify) @@ -125,33 +136,33 @@ void cdch_init(void) tu_memclr(cdch_data, sizeof(cdch_data_t)*CFG_TUSB_HOST_DEVICE_MAX); } -bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) +bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length) { - // TODO change following assert to subtask_assert - if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != p_interface_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS; + // Only support ACM + TU_VERIFY( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL == itf_desc->bInterfaceSubClass); - if ( !(tu_within(CDC_COMM_PROTOCOL_ATCOMMAND, p_interface_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) || - 0xff == p_interface_desc->bInterfaceProtocol) ) - { - return TUSB_ERROR_CDC_UNSUPPORTED_PROTOCOL; - } + // Only support AT commands, no protocol and vendor specific commands. + TU_VERIFY(tu_within(CDC_COMM_PROTOCOL_NONE, itf_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) || + 0xff == itf_desc->bInterfaceProtocol); uint8_t const * p_desc; cdch_data_t * p_cdc; - p_desc = descriptor_next ( (uint8_t const *) p_interface_desc ); - p_cdc = &cdch_data[dev_addr-1]; // non-static variable cannot be used after OS service call + p_desc = descriptor_next ( (uint8_t const *) itf_desc ); + p_cdc = &cdch_data[dev_addr-1]; - p_cdc->interface_number = p_interface_desc->bInterfaceNumber; - p_cdc->interface_protocol = p_interface_desc->bInterfaceProtocol; // TODO 0xff is consider as rndis candidate, other is virtual Com + p_cdc->itf_num = itf_desc->bInterfaceNumber; + p_cdc->itf_protocol = itf_desc->bInterfaceProtocol; // TODO 0xff is consider as rndis candidate, other is virtual Com //------------- Communication Interface -------------// (*p_length) = sizeof(tusb_desc_interface_t); + // Communication Functional Descriptors while( TUSB_DESC_CLASS_SPECIFIC == p_desc[DESC_OFFSET_TYPE] ) - { // Communication Functional Descriptors + { if ( CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT == cdc_functional_desc_typeof(p_desc) ) - { // save ACM bmCapabilities + { + // save ACM bmCapabilities p_cdc->acm_capability = ((cdc_desc_func_acm_t const *) p_desc)->bmCapabilities; } @@ -160,8 +171,12 @@ bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t c } if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE]) - { // notification endpoint if any - p_cdc->pipe_notification = hcd_pipe_open(rhport, dev_addr, (tusb_desc_endpoint_t const *) p_desc, TUSB_CLASS_CDC); + { + // notification endpoint if any + tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) p_desc; + p_cdc->pipe_notification = hcd_pipe_open(rhport, dev_addr, ep_desc, TUSB_CLASS_CDC); + + p_cdc->ep_notif = ep_desc->bEndpointAddress; (*p_length) += p_desc[DESC_OFFSET_LEN]; p_desc = descriptor_next(p_desc); @@ -179,16 +194,24 @@ bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t c // data endpoints expected to be in pairs for(uint32_t i=0; i<2; i++) { - tusb_desc_endpoint_t const *p_endpoint = (tusb_desc_endpoint_t const *) p_desc; - TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType); - TU_ASSERT(TUSB_XFER_BULK == p_endpoint->bmAttributes.xfer); + tusb_desc_endpoint_t const *ep_desc = (tusb_desc_endpoint_t const *) p_desc; + TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); + TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer); - pipe_handle_t * p_pipe_hdl = ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK ) ? + pipe_handle_t * p_pipe_hdl = ( ep_desc->bEndpointAddress & TUSB_DIR_IN_MASK ) ? &p_cdc->pipe_in : &p_cdc->pipe_out; - (*p_pipe_hdl) = hcd_pipe_open(rhport, dev_addr, p_endpoint, TUSB_CLASS_CDC); + (*p_pipe_hdl) = hcd_pipe_open(rhport, dev_addr, ep_desc, TUSB_CLASS_CDC); TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl) ); + if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) + { + p_cdc->ep_in = ep_desc->bEndpointAddress; + }else + { + p_cdc->ep_out = ep_desc->bEndpointAddress; + } + (*p_length) += p_desc[DESC_OFFSET_LEN]; p_desc = descriptor_next( p_desc ); } @@ -203,7 +226,7 @@ bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t c .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_INTERFACE, .type = TUSB_REQ_TYPE_CLASS, .direction = TUSB_DIR_OUT }, .bRequest = CDC_REQUEST_SET_CONTROL_LINE_STATE, .wValue = 0x03, // dtr on, cst on - .wIndex = p_cdc->interface_number, + .wIndex = p_cdc->itf_num, .wLength = 0 }; diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h index 2fbd40f40..eceec3ee3 100644 --- a/src/class/cdc/cdc_host.h +++ b/src/class/cdc/cdc_host.h @@ -137,18 +137,8 @@ void tuh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_i //--------------------------------------------------------------------+ #ifdef _TINY_USB_SOURCE_FILE_ -typedef struct { - uint8_t interface_number; - uint8_t interface_protocol; - - cdc_acm_capability_t acm_capability; - - pipe_handle_t pipe_notification, pipe_out, pipe_in; - -} cdch_data_t; - void cdch_init(void); -bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; +bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length); void cdch_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void cdch_close(uint8_t dev_addr); diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 3c5402e59..f4fac96b8 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -73,6 +73,8 @@ // MACROS //--------------------------------------------------------------------+ #define TU_ARRAY_SZIE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) ) +#define TU_MIN(_x, _y) ( (_x) < (_y) ) ? (_x) : (_y) ) +#define TU_MAX(_x, _y) ( (_x) > (_y) ) ? (_x) : (_y) ) #define U16_HIGH_U8(u16) ((uint8_t) (((u16) >> 8) & 0x00ff)) #define U16_LOW_U8(u16) ((uint8_t) ((u16) & 0x00ff)) @@ -167,53 +169,23 @@ static inline uint16_t tu_u16_le2be(uint16_t u16) return ((uint16_t)(tu_u16_low(u16) << 8)) | tu_u16_high(u16); } -//------------- Min -------------// -static inline uint8_t tu_min8(uint8_t x, uint8_t y) -{ - return (x < y) ? x : y; -} - -static inline uint16_t tu_min16(uint16_t x, uint16_t y) -{ - return (x < y) ? x : y; -} - -static inline uint32_t tu_min32(uint32_t x, uint32_t y) -{ - return (x < y) ? x : y; -} - -//------------- Max -------------// -static inline uint32_t tu_max32(uint32_t x, uint32_t y) -{ - return (x > y) ? x : y; -} - -//------------- Align -------------// -static inline uint32_t tu_align32 (uint32_t value) -{ - return (value & 0xFFFFFFE0UL); -} - -static inline uint32_t tu_align16 (uint32_t value) -{ - return (value & 0xFFFFFFF0UL); -} +// Min +static inline uint8_t tu_min8(uint8_t x, uint8_t y) { return (x < y) ? x : y; } +static inline uint16_t tu_min16(uint16_t x, uint16_t y) { return (x < y) ? x : y; } +static inline uint32_t tu_min32(uint32_t x, uint32_t y) { return (x < y) ? x : y; } -static inline uint32_t tu_align_n (uint32_t alignment, uint32_t value) -{ - return value & ((uint32_t) ~(alignment-1)); -} +// Max +static inline uint8_t tu_max8(uint8_t x, uint8_t y) { return (x > y) ? x : y; } +static inline uint16_t tu_max16(uint16_t x, uint16_t y) { return (x > y) ? x : y; } +static inline uint32_t tu_max32(uint32_t x, uint32_t y) { return (x > y) ? x : y; } -static inline uint32_t tu_align4k (uint32_t value) -{ - return (value & 0xFFFFF000UL); -} +// Align +static inline uint32_t tu_align32 (uint32_t value) { return (value & 0xFFFFFFE0UL); } +static inline uint32_t tu_align16 (uint32_t value) { return (value & 0xFFFFFFF0UL); } +static inline uint32_t tu_align_n (uint32_t alignment, uint32_t value) { return value & ((uint32_t) ~(alignment-1)); } +static inline uint32_t tu_align4k (uint32_t value) { return (value & 0xFFFFF000UL); } -static inline uint32_t tu_offset4k(uint32_t value) -{ - return (value & 0xFFFUL); -} +static inline uint32_t tu_offset4k(uint32_t value) { return (value & 0xFFFUL); } //------------- Mathematics -------------// static inline uint32_t tu_abs(int32_t value) @@ -221,7 +193,6 @@ 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) { diff --git a/src/device/usbd.c b/src/device/usbd.c index 5262d6c73..d1b708a0d 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -623,24 +623,24 @@ void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_ //--------------------------------------------------------------------+ // Helper to parse an pair of endpoint descriptors (IN & OUT) -tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_desc_ep, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in) +tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* ep_desc, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in) { for(int i=0; i<2; i++) { - TU_ASSERT(TUSB_DESC_ENDPOINT == p_desc_ep->bDescriptorType && - xfer_type == p_desc_ep->bmAttributes.xfer, TUSB_ERROR_DESCRIPTOR_CORRUPTED); + TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType && + xfer_type == ep_desc->bmAttributes.xfer, TUSB_ERROR_DESCRIPTOR_CORRUPTED); - TU_ASSERT( dcd_edpt_open(rhport, p_desc_ep), TUSB_ERROR_DCD_OPEN_PIPE_FAILED ); + TU_ASSERT( dcd_edpt_open(rhport, ep_desc), TUSB_ERROR_DCD_OPEN_PIPE_FAILED ); - if ( edpt_dir(p_desc_ep->bEndpointAddress) == TUSB_DIR_IN ) + if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { - (*ep_in) = p_desc_ep->bEndpointAddress; + (*ep_in) = ep_desc->bEndpointAddress; }else { - (*ep_out) = p_desc_ep->bEndpointAddress; + (*ep_out) = ep_desc->bEndpointAddress; } - p_desc_ep = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_desc_ep ); + ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) ep_desc ); } return TUSB_ERROR_NONE; diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index 4989c74a0..2e9090db2 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -58,26 +58,8 @@ //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ -CFG_TUSB_MEM_SECTION static ehci_data_t ehci_data; - -#if EHCI_PERIODIC_LIST - - #if (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST) - CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4096) static ehci_link_t period_frame_list0[EHCI_FRAMELIST_SIZE]; - - #ifndef __ICCARM__ // IAR cannot able to determine the alignment with datalignment pragma - TU_VERIFY_STATIC( ALIGN_OF(period_frame_list0) == 4096, "Period Framelist must be 4k alginment"); // validation - #endif - #endif - - #if (CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST) - CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4096) STATIC_VAR ehci_link_t period_frame_list1[EHCI_FRAMELIST_SIZE]; - - #ifndef __ICCARM__ // IAR cannot able to determine the alignment with datalignment pragma - TU_VERIFY_STATIC( ALIGN_OF(period_frame_list1) == 4096, "Period Framelist must be 4k alginment"); // validation - #endif - #endif -#endif +// Periodic frame list must be 4K alignment +CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4096) static ehci_data_t ehci_data; //------------- Validation -------------// // TODO static assert for memory placement on some known MCU such as lpc43xx @@ -86,7 +68,6 @@ CFG_TUSB_MEM_SECTION static ehci_data_t ehci_data; // PROTOTYPE //--------------------------------------------------------------------+ static inline ehci_registers_t* get_operational_register(uint8_t hostid) ATTR_PURE ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT; -static inline ehci_link_t* get_period_frame_list(uint8_t hostid) ATTR_PURE ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT; static inline ehci_qhd_t* get_async_head(uint8_t hostid) ATTR_ALWAYS_INLINE ATTR_PURE ATTR_WARN_UNUSED_RESULT; static inline ehci_link_t* get_period_head(uint8_t hostid, uint8_t interval_ms) ATTR_ALWAYS_INLINE ATTR_PURE ATTR_WARN_UNUSED_RESULT; @@ -112,9 +93,9 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c static inline ehci_qtd_t* qtd_find_free(uint8_t dev_addr) ATTR_PURE ATTR_ALWAYS_INLINE; -static inline ehci_qtd_t* qtd_next(ehci_qtd_t const * p_qtd ) ATTR_PURE ATTR_ALWAYS_INLINE; -static inline void qtd_insert_to_qhd(ehci_qhd_t *p_qhd, ehci_qtd_t *p_qtd_new) ATTR_ALWAYS_INLINE; -static inline void qtd_remove_1st_from_qhd(ehci_qhd_t *p_qhd) ATTR_ALWAYS_INLINE; +static inline ehci_qtd_t* qtd_next(ehci_qtd_t const * p_qtd ) ATTR_PURE ATTR_ALWAYS_INLINE; +static inline void qtd_insert_to_qhd(ehci_qhd_t *p_qhd, ehci_qtd_t *p_qtd_new) ATTR_ALWAYS_INLINE; +static inline void qtd_remove_1st_from_qhd(ehci_qhd_t *p_qhd) ATTR_ALWAYS_INLINE; static void qtd_init(ehci_qtd_t* p_qtd, uint32_t data_ptr, uint16_t total_bytes); static inline void list_insert(ehci_link_t *current, ehci_link_t *new, uint8_t new_type) ATTR_ALWAYS_INLINE; @@ -129,18 +110,8 @@ static bool ehci_init(uint8_t hostid); //--------------------------------------------------------------------+ bool hcd_init(void) { - //------------- Data Structure init -------------// tu_memclr(&ehci_data, sizeof(ehci_data_t)); - - #if (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST) - TU_VERIFY(ehci_init(0)); - #endif - - #if (CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST) - TU_VERIFY(ehci_init(1)); - #endif - - return true; + return ehci_init(TUH_OPT_RHPORT); } //--------------------------------------------------------------------+ @@ -148,7 +119,7 @@ bool hcd_init(void) //--------------------------------------------------------------------+ void hcd_port_reset(uint8_t hostid) { - ehci_registers_t* const regs = get_operational_register(hostid); + ehci_registers_t* regs = ehci_data.regs; regs->portsc_bit.port_enable = 0; // disable port before reset regs->portsc_bit.port_reset = 1; @@ -156,19 +127,18 @@ void hcd_port_reset(uint8_t hostid) bool hcd_port_connect_status(uint8_t hostid) { - return get_operational_register(hostid)->portsc_bit.current_connect_status; + return ehci_data.regs->portsc_bit.current_connect_status; } tusb_speed_t hcd_port_speed_get(uint8_t hostid) { - return (tusb_speed_t) get_operational_register(hostid)->portsc_bit.nxp_port_speed; // NXP specific port speed + return (tusb_speed_t) ehci_data.regs->portsc_bit.nxp_port_speed; // NXP specific port speed } // TODO refractor abtract later void hcd_port_unplug(uint8_t hostid) { - ehci_registers_t* const regs = get_operational_register(hostid); - regs->usb_cmd_bit.advacne_async = 1; // Async doorbell check EHCI 4.8.2 for operational details + ehci_data.regs->usb_cmd_bit.advance_async = 1; // Async doorbell check EHCI 4.8.2 for operational details } //--------------------------------------------------------------------+ @@ -176,7 +146,9 @@ void hcd_port_unplug(uint8_t hostid) //--------------------------------------------------------------------+ static bool ehci_init(uint8_t hostid) { - ehci_registers_t* const regs = get_operational_register(hostid); + ehci_data.regs = get_operational_register(hostid); + + ehci_registers_t* regs = ehci_data.regs; //------------- CTRLDSSEGMENT Register (skip) -------------// //------------- USB INT Register -------------// @@ -211,7 +183,7 @@ static bool ehci_init(uint8_t hostid) ehci_data.period_head_arr[i].qtd_overlay.halted = 1; // dummy node, always inactive } - ehci_link_t * const framelist = get_period_frame_list(hostid); + ehci_link_t * const framelist = ehci_data.period_framelist; ehci_link_t * const period_1ms = get_period_head(hostid, 1); // all links --> period_head_arr[0] (1ms) // 0, 2, 4, 6 etc --> period_head_arr[1] (2ms) @@ -264,11 +236,11 @@ static bool ehci_init(uint8_t hostid) static tusb_error_t hcd_controller_stop(uint8_t hostid) { - ehci_registers_t* const regs = get_operational_register(hostid); - tu_timeout_t timeout; + ehci_registers_t* regs = ehci_data.regs; regs->usb_cmd_bit.run_stop = 0; + tu_timeout_t timeout; tu_timeout_set(&timeout, 2); // USB Spec: controller has to stop within 16 uframe = 2 frames while( regs->usb_sts_bit.hc_halted == 0 && !tu_timeout_expired(&timeout)) {} @@ -613,10 +585,8 @@ static void async_advance_isr(ehci_qhd_t * const async_head) static void port_connect_status_change_isr(uint8_t hostid) { - ehci_registers_t* const regs = get_operational_register(hostid); - // NOTE There is an sequence plug->unplug->…..-> plug if device is powering with pre-plugged device - if (regs->portsc_bit.current_connect_status) + if (ehci_data.regs->portsc_bit.current_connect_status) { hcd_port_reset(hostid); hcd_event_device_attach(hostid); @@ -797,7 +767,7 @@ static void xfer_error_isr(uint8_t hostid) //------------- Host Controller Driver's Interrupt Handler -------------// void hal_hcd_isr(uint8_t hostid) { - ehci_registers_t* const regs = get_operational_register(hostid); + ehci_registers_t* regs = ehci_data.regs; uint32_t int_status = regs->usb_sts; int_status &= regs->usb_int_enable; @@ -854,26 +824,6 @@ static inline ehci_registers_t* get_operational_register(uint8_t hostid) return (ehci_registers_t*) (hostid ? (&LPC_USB1->USBCMD_H) : (&LPC_USB0->USBCMD_H) ); } -#if EHCI_PERIODIC_LIST // TODO refractor/group this together -static inline ehci_link_t* get_period_frame_list(uint8_t hostid) -{ - switch(hostid) - { -#if (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST) - case 0: - return period_frame_list0; -#endif - -#if (CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST) - case 1: - return period_frame_list1; -#endif - - default: return NULL; - } -} -#endif - //------------- queue head helper -------------// static inline ehci_qhd_t* get_async_head(uint8_t hostid) { diff --git a/src/host/ehci/ehci.h b/src/host/ehci/ehci.h index 48e0c34e5..4534c4cd3 100644 --- a/src/host/ehci/ehci.h +++ b/src/host/ehci/ehci.h @@ -352,7 +352,7 @@ typedef volatile struct { uint32_t framelist_size : 2 ; ///< This field is R/W only if Programmable Frame List Flagin the HCCPARAMS registers is set to a one. This field specifies the size of the frame list.00b 1024 elements (4096 bytes) Default value 01b 512 elements (2048 bytes) 10b 256 elements (1024 bytes) uint32_t periodic_enable : 1 ; ///< This bit controls whether the host controller skips processing the Periodic Schedule. Values mean: 0b Do not process the Periodic Schedule 1b Use the PERIODICLISTBASE register to access the Periodic Schedule. uint32_t async_enable : 1 ; ///< This bit controls whether the host controller skips processing the Asynchronous Schedule. Values mean: 0b Do not process the Asynchronous Schedule 1b Use the ASYNCLISTADDR register to access the Asynchronous Schedule. - uint32_t advacne_async : 1 ; ///< This bit is used as a doorbell by software to tell the host controller to issue an interrupt the next time it advances asynchronous schedule. Software must write a 1 to this bit to ringthe doorbell. When the host controller has evicted all appropriate cached schedule state, it sets the Interrupt on Async Advancestatus bit in the USBSTS register. If the Interrupt on Async Advance Enablebit in the USBINTR register is a one then the host controller will assert an interrupt at the next interrupt threshold. See Section 4.8.2 for operational details. The host controller sets this bit to a zero after it has set the Interrupt on Async Advance status bit in the USBSTS register to a one. Software should not write a one to this bit when the asynchronous schedule is disabled. Doing so will yield undefined results. + uint32_t advance_async : 1 ; ///< This bit is used as a doorbell by software to tell the host controller to issue an interrupt the next time it advances asynchronous schedule. Software must write a 1 to this bit to ringthe doorbell. When the host controller has evicted all appropriate cached schedule state, it sets the Interrupt on Async Advancestatus bit in the USBSTS register. If the Interrupt on Async Advance Enablebit in the USBINTR register is a one then the host controller will assert an interrupt at the next interrupt threshold. See Section 4.8.2 for operational details. The host controller sets this bit to a zero after it has set the Interrupt on Async Advance status bit in the USBSTS register to a one. Software should not write a one to this bit when the asynchronous schedule is disabled. Doing so will yield undefined results. uint32_t light_reset : 1 ; ///< This control bit is not required. If implemented, it allows the driver to reset the EHCI controller without affecting the state of the ports or the relationship to the companion host controllers. For example, the PORSTC registers should not be reset to their default values and the CF bit setting should not go to zero (retaining port ownership relationships). A host software read of this bit as zero indicates the Light Host Controller Reset has completed and it is safe for host software to re-initialize the host controller. A host software read of this bit as a one indicates the Light Host Controller Reset has not yet completed. uint32_t async_park : 2 ; ///< It contains a count of the number of successive transactions the host controller is allowed to execute from a high-speed queue head on the Asynchronous schedule before continuing traversal of the Asynchronous schedule. See Section 4.10.3.2 for full operational details. Valid values are 1h to 3h. Software must not write a zero to this bit when Park Mode Enableis a one as this will result in undefined behavior. uint32_t : 1 ; ///< reserved @@ -450,11 +450,11 @@ typedef volatile struct { //--------------------------------------------------------------------+ typedef struct { -#if EHCI_PERIODIC_LIST + ehci_link_t period_framelist[EHCI_FRAMELIST_SIZE]; + // for NXP ECHI, only implement 1 ms & 2 ms & 4 ms, 8 ms (framelist) // [0] : 1ms, [1] : 2ms, [2] : 4ms, [3] : 8 ms ehci_qhd_t period_head_arr[4]; -#endif struct { ehci_qhd_t qhd; // also used as head of async list (each for 1 controller), always exists @@ -472,6 +472,8 @@ typedef struct // ehci_itd_t itd[EHCI_MAX_ITD] ; ///< Iso Transfer Pool // ehci_sitd_t sitd[EHCI_MAX_SITD] ; ///< Split (FS) Isochronous Transfer Pool }device[CFG_TUSB_HOST_DEVICE_MAX]; + + ehci_registers_t* regs; }ehci_data_t; #ifdef __cplusplus diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_ehci_structure.c b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_structure.c index 7eaabcd51..39e15b227 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_ehci_structure.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_structure.c @@ -225,7 +225,7 @@ void test_register_usbcmd(void) TEST_ASSERT_EQUAL( 2 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, framelist_size) ); TEST_ASSERT_EQUAL( 4 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, periodic_enable) ); TEST_ASSERT_EQUAL( 5 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, async_enable) ); - TEST_ASSERT_EQUAL( 6 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, advacne_async) ); + TEST_ASSERT_EQUAL( 6 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, advance_async) ); TEST_ASSERT_EQUAL( 7 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, light_reset) ); TEST_ASSERT_EQUAL( 8 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, async_park) ); TEST_ASSERT_EQUAL( 11 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, async_park_enable) ); -- cgit v1.3.1 From 4e7596ca9cdde3bd1197cf1853c370d8da48d7a2 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Dec 2018 19:25:57 +0700 Subject: add tuh_mount_cb/tuh_umount_cb --- examples/host/cdc_msc_hid/src/main.c | 4 ++-- src/class/cdc/cdc_host.c | 8 +------- src/class/cdc/cdc_host.h | 13 +------------ src/device/usbd.c | 5 +++-- src/host/usbh.c | 11 +++++------ src/host/usbh.h | 8 ++++++-- tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c | 16 ++++++++-------- 7 files changed, 26 insertions(+), 39 deletions(-) (limited to 'src/class/cdc') diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c index 4d197a16a..ebb540782 100644 --- a/examples/host/cdc_msc_hid/src/main.c +++ b/examples/host/cdc_msc_hid/src/main.c @@ -84,7 +84,7 @@ int main(void) #if CFG_TUH_CDC CFG_TUSB_MEM_SECTION static char serial_in_buffer[64] = { 0 }; -void tuh_cdc_mounted_cb(uint8_t dev_addr) +void tuh_mount_cb(uint8_t dev_addr) { // application set-up printf("\na CDC device (address %d) is mounted\n", dev_addr); @@ -92,7 +92,7 @@ void tuh_cdc_mounted_cb(uint8_t dev_addr) tuh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true); // schedule first transfer } -void tuh_cdc_unmounted_cb(uint8_t dev_addr) +void tuh_umount_cb(uint8_t dev_addr) { // application tear-down printf("\na CDC device (address %d) is unmounted \n", dev_addr); diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 0d0378920..9e1ca0e7a 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -136,7 +136,7 @@ void cdch_init(void) tu_memclr(cdch_data, sizeof(cdch_data_t)*CFG_TUSB_HOST_DEVICE_MAX); } -bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length) +bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length) { // Only support ACM TU_VERIFY( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL == itf_desc->bInterfaceSubClass); @@ -217,9 +217,6 @@ bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t c } } - // FIXME mounted class flag is not set yet - tuh_cdc_mounted_cb(dev_addr); - // FIXME move to seperate API : connect tusb_control_request_t request = { @@ -249,9 +246,6 @@ void cdch_close(uint8_t dev_addr) hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->pipe_out); tu_memclr(p_cdc, sizeof(cdch_data_t)); - - tuh_cdc_unmounted_cb(dev_addr); - } #endif diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h index eceec3ee3..8d0b1d28d 100644 --- a/src/class/cdc/cdc_host.h +++ b/src/class/cdc/cdc_host.h @@ -104,17 +104,6 @@ tusb_error_t tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, //--------------------------------------------------------------------+ // CDC APPLICATION CALLBACKS //--------------------------------------------------------------------+ -/** \brief Callback function that will be invoked when a device with CDC Abstract Control Model interface is mounted - * \param[in] dev_addr Address of newly mounted device - * \note This callback should be used by Application to set-up interface-related data - */ -void tuh_cdc_mounted_cb(uint8_t dev_addr); - -/** \brief Callback function that will be invoked when a device with CDC Abstract Control Model interface is unmounted - * \param[in] dev_addr Address of newly unmounted device - * \note This callback should be used by Application to tear-down interface-related data - */ -void tuh_cdc_unmounted_cb(uint8_t dev_addr); /** \brief Callback function that is invoked when an transferring event occurred * \param[in] dev_addr Address of device @@ -138,7 +127,7 @@ void tuh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_i #ifdef _TINY_USB_SOURCE_FILE_ void cdch_init(void); -bool cdch_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length); +bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length); void cdch_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void cdch_close(uint8_t dev_addr); diff --git a/src/device/usbd.c b/src/device/usbd.c index d1b708a0d..ad40e3c9f 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -272,7 +272,8 @@ static void usbd_task_body(void) // TODO remove since if task is too slow, we could clear the event of the new attached osal_queue_reset(_usbd_q); - tud_umount_cb(); // invoke callback + // invoke callback + if (tud_umount_cb) tud_umount_cb(); break; case DCD_EVENT_SOF: @@ -467,7 +468,7 @@ static bool process_set_config(uint8_t rhport) } // invoke callback - tud_mount_cb(); + if (tud_mount_cb) tud_mount_cb(); return TUSB_ERROR_NONE; } diff --git a/src/host/usbh.c b/src/host/usbh.c index c345ddf0d..2c2286698 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -71,7 +71,7 @@ static host_class_driver_t const usbh_class_drivers[] = { .class_code = TUSB_CLASS_CDC, .init = cdch_init, - .open_subtask = cdch_open_subtask, + .open_subtask = cdch_open, .isr = cdch_isr, .close = cdch_close }, @@ -218,10 +218,6 @@ bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8 if ( XFER_RESULT_STALLED == dev->control.pipe_status ) return false; if ( XFER_RESULT_FAILED == dev->control.pipe_status ) return false; -// STASK_ASSERT_HDLR(TUSB_ERROR_NONE == error && -// XFER_RESULT_SUCCESS == dev->control.pipe_status, -// tuh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) ); - return true; } @@ -336,6 +332,9 @@ static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_ (hub_port == 0 || dev->hub_port == hub_port) && dev->state != TUSB_DEVICE_STATE_UNPLUG) { + // Invoke callback before close driver + if (tuh_umount_cb) tuh_umount_cb(dev_addr); + // TODO Hub multiple level // Close class driver for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++) usbh_class_drivers[drv_id].close(dev_addr); @@ -624,7 +623,7 @@ bool enum_task(hcd_event_t* event) } } - tuh_device_mount_succeed_cb(new_addr); + if (tuh_mount_cb) tuh_mount_cb(new_addr); return true; } diff --git a/src/host/usbh.h b/src/host/usbh.h index 390b04053..a2e196c9a 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -90,8 +90,12 @@ static inline bool tuh_device_is_configured(uint8_t dev_addr) // APPLICATION CALLBACK //--------------------------------------------------------------------+ ATTR_WEAK uint8_t tuh_device_attached_cb (tusb_desc_device_t const *p_desc_device) ATTR_WARN_UNUSED_RESULT; -ATTR_WEAK void tuh_device_mount_succeed_cb (uint8_t dev_addr); -ATTR_WEAK void tuh_device_mount_failed_cb(tusb_error_t error, tusb_desc_device_t const *p_desc_device); // TODO refractor remove desc_device + +/** Callback invoked when device is mounted (configured) */ +ATTR_WEAK void tuh_mount_cb (uint8_t dev_addr); + +/** Callback invoked when device is unmounted (bus reset/unplugged) */ +ATTR_WEAK void tuh_umount_cb(uint8_t dev_addr); //--------------------------------------------------------------------+ // CLASS-USBH & INTERNAL API 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 fe7d05516..1b73e649f 100644 --- a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c +++ b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c @@ -89,7 +89,7 @@ void test_cdch_open_failed_to_open_notification_endpoint(void) hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, null_hdl); //------------- CUT -------------// - TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open_subtask(dev_addr, p_comm_interface, &length)); + TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length)); } @@ -102,7 +102,7 @@ void test_cdch_open_failed_to_open_data_endpoint_out(void) hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, null_hdl); //------------- CUT -------------// - TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open_subtask(dev_addr, p_comm_interface, &length)); + TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length)); } @@ -116,7 +116,7 @@ void test_cdch_open_failed_to_open_data_endpoint_in(void) hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, null_hdl); //------------- CUT -------------// - TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open_subtask(dev_addr, p_comm_interface, &length)); + TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length)); } @@ -135,7 +135,7 @@ void test_cdch_open_length_check(void) tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// - TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open_subtask(dev_addr, p_comm_interface, &length) ); + TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) ); TEST_ASSERT_EQUAL(expected_length, length); } @@ -147,7 +147,7 @@ void test_cdch_open_interface_number_check(void) tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// - TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open_subtask(dev_addr, p_comm_interface, &length) ); + TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) ); TEST_ASSERT_EQUAL(1, p_cdc->interface_number); @@ -160,7 +160,7 @@ void test_cdch_open_protocol_check(void) tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// - TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open_subtask(dev_addr, p_comm_interface, &length) ); + TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) ); TEST_ASSERT_EQUAL(p_comm_interface->bInterfaceProtocol, p_cdc->interface_protocol); @@ -173,7 +173,7 @@ void test_cdch_open_acm_capacity_check(void) tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// - TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open_subtask(dev_addr, p_comm_interface, &length) ); + TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) ); TEST_ASSERT_EQUAL_MEMORY(&cdc_config_descriptor.cdc_acm.bmCapabilities, &p_cdc->acm_capability, 1); } @@ -192,7 +192,7 @@ void test_cdch_close_device(void) hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_int); tusbh_cdc_mounted_cb_Expect(dev_addr); - TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open_subtask(dev_addr, p_comm_interface, &length) ); + TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) ); hcd_pipe_close_ExpectAndReturn(pipe_notification , TUSB_ERROR_NONE); hcd_pipe_close_ExpectAndReturn(pipe_int , TUSB_ERROR_NONE); -- cgit v1.3.1 From dffe9b335ee38a7720adff9a819f17b2899e38d1 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Dec 2018 20:26:47 +0700 Subject: clean up host pipe api --- examples/host/cdc_msc_hid/src/tusb_config.h | 2 +- src/class/cdc/cdc_host.c | 4 +-- src/class/msc/msc_host.c | 2 +- src/host/ehci/ehci.c | 43 +++++++++-------------------- src/host/hcd.h | 5 +--- src/host/hub.c | 2 +- src/host/ohci/ohci.c | 12 -------- 7 files changed, 19 insertions(+), 51 deletions(-) (limited to 'src/class/cdc') diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index be584b181..07764fa90 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -80,7 +80,7 @@ // DEVICE CONFIGURATION //-------------------------------------------------------------------- -#define CFG_TUH_HUB 1 // not tested +#define CFG_TUH_HUB 1 #define CFG_TUH_CDC 1 #define CFG_TUH_HID_KEYBOARD 0 #define CFG_TUH_HID_MOUSE 0 diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 9e1ca0e7a..c6378e546 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -174,7 +174,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it { // notification endpoint if any tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) p_desc; - p_cdc->pipe_notification = hcd_pipe_open(rhport, dev_addr, ep_desc, TUSB_CLASS_CDC); + p_cdc->pipe_notification = hcd_pipe_open(rhport, dev_addr, ep_desc); p_cdc->ep_notif = ep_desc->bEndpointAddress; @@ -201,7 +201,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it pipe_handle_t * p_pipe_hdl = ( ep_desc->bEndpointAddress & TUSB_DIR_IN_MASK ) ? &p_cdc->pipe_in : &p_cdc->pipe_out; - (*p_pipe_hdl) = hcd_pipe_open(rhport, dev_addr, ep_desc, TUSB_CLASS_CDC); + (*p_pipe_hdl) = hcd_pipe_open(rhport, dev_addr, ep_desc); TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl) ); if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 57a409ffd..4f5f0c599 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -368,7 +368,7 @@ bool msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_ENDPOINT, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_OUT }, .bRequest = TUSB_REQ_CLEAR_FEATURE, .wValue = 0, - .wIndex = hcd_pipe_get_endpoint_addr(msch_data[dev_addr-1].bulk_in), + .wIndex = hcd_pipe_get_endpoint_addr(msch_data[dev_addr-1].bulk_in), // FIXME use ep addr .wLength = 0 }; diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index e71b817aa..dd19a5224 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -325,7 +325,7 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const* { // FIXME control only for now (void) rhport; - hcd_pipe_open(rhport, dev_addr, ep_desc, 0); + hcd_pipe_open(rhport, dev_addr, ep_desc); return true; } @@ -344,23 +344,23 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * // FIXME control only for now if ( epnum == 0 ) { - ehci_qhd_t * const p_qhd = get_control_qhd(dev_addr); - ehci_qtd_t *p_data = get_control_qtds(dev_addr); + ehci_qhd_t* qhd = get_control_qhd(dev_addr); + ehci_qtd_t* qtd = get_control_qtds(dev_addr); - qtd_init(p_data, (uint32_t) buffer, buflen); + qtd_init(qtd, (uint32_t) buffer, buflen); // first first data toggle is always 1 (data & setup stage) - p_data->data_toggle = 1; - p_data->pid = dir ? EHCI_PID_IN : EHCI_PID_OUT; - p_data->int_on_complete = 1; - p_data->next.terminate = 1; + qtd->data_toggle = 1; + qtd->pid = dir ? EHCI_PID_IN : EHCI_PID_OUT; + qtd->int_on_complete = 1; + qtd->next.terminate = 1; // sw region - p_qhd->p_qtd_list_head = p_data; - p_qhd->p_qtd_list_tail = p_data; + qhd->p_qtd_list_head = qtd; + qhd->p_qtd_list_tail = qtd; // attach TD - p_qhd->qtd_overlay.next.address = (uint32_t) p_data; + qhd->qtd_overlay.next.address = (uint32_t) qtd; } return true; @@ -389,7 +389,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet //--------------------------------------------------------------------+ // BULK/INT/ISO PIPE API //--------------------------------------------------------------------+ -pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc, uint8_t class_code) +pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) { pipe_handle_t const null_handle = { .index = 0 }; @@ -511,24 +511,12 @@ bool hcd_pipe_is_busy(uint8_t dev_addr, pipe_handle_t pipe_hdl) return !p_qhd->qtd_overlay.halted && (p_qhd->p_qtd_list_head != NULL); } -bool hcd_pipe_is_error(uint8_t dev_addr, pipe_handle_t pipe_hdl) -{ - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); - return p_qhd->qtd_overlay.halted; -} - bool hcd_pipe_is_stalled(uint8_t dev_addr, pipe_handle_t pipe_hdl) { ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); return p_qhd->qtd_overlay.halted && !qhd_has_xact_error(p_qhd); } -uint8_t hcd_pipe_get_endpoint_addr(uint8_t dev_addr, pipe_handle_t pipe_hdl) -{ - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); - return p_qhd->endpoint_number + ( (p_qhd->pid_non_control == EHCI_PID_IN) ? TUSB_DIR_IN_MASK : 0); -} - tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, pipe_handle_t pipe_hdl) { ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); @@ -596,11 +584,8 @@ static void port_connect_status_change_isr(uint8_t hostid) static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd) { - uint8_t max_loop = 0; - // free all TDs from the head td to the first active TD - while(p_qhd->p_qtd_list_head != NULL && !p_qhd->p_qtd_list_head->active - && max_loop < HCD_MAX_XFER) + while(p_qhd->p_qtd_list_head != NULL && !p_qhd->p_qtd_list_head->active) { // TD need to be freed and removed from qhd, before invoking callback bool is_ioc = (p_qhd->p_qtd_list_head->int_on_complete != 0); @@ -616,8 +601,6 @@ static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd) hcd_event_xfer_complete(p_qhd->device_address, edpt_addr(p_qhd->endpoint_number, p_qhd->pid_non_control == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes); p_qhd->total_xferred_bytes = 0; } - - max_loop++; } } diff --git a/src/host/hcd.h b/src/host/hcd.h index 0f83838e9..9ea86a5fe 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -144,18 +144,15 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * //--------------------------------------------------------------------+ // TODO control xfer should be used via usbh layer -pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * endpoint_desc, uint8_t class_code) ATTR_WARN_UNUSED_RESULT; +pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); tusb_error_t hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet tusb_error_t hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, pipe_handle_t pipe_hdl); bool hcd_pipe_is_busy(uint8_t dev_addr, pipe_handle_t pipe_hdl); -bool hcd_pipe_is_error(uint8_t dev_addr, pipe_handle_t pipe_hdl); bool hcd_pipe_is_stalled(uint8_t dev_addr, pipe_handle_t pipe_hdl); // stalled also counted as error tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, pipe_handle_t pipe_hdl); -uint8_t hcd_pipe_get_endpoint_addr(uint8_t dev_addr, pipe_handle_t pipe_hdl); - #if 0 tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT; #endif diff --git a/src/host/hub.c b/src/host/hub.c index 2a71c45fc..bc0592a97 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -167,7 +167,7 @@ bool hub_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t co TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType); TU_ASSERT(TUSB_XFER_INTERRUPT == p_endpoint->bmAttributes.xfer); - hub_data[dev_addr-1].pipe_status = hcd_pipe_open(rhport, dev_addr, p_endpoint, TUSB_CLASS_HUB); + hub_data[dev_addr-1].pipe_status = hcd_pipe_open(rhport, dev_addr, p_endpoint); TU_ASSERT( pipehandle_is_valid(hub_data[dev_addr-1].pipe_status) ); hub_data[dev_addr-1].interface_number = p_interface_desc->bInterfaceNumber; diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index 08d562e0d..5923be936 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -589,24 +589,12 @@ bool hcd_pipe_is_busy(pipe_handle_t pipe_hdl) return tu_align16(p_ed->td_head.address) != tu_align16(p_ed->td_tail.address); } -bool hcd_pipe_is_error(pipe_handle_t pipe_hdl) -{ - ohci_ed_t const * const p_ed = ed_from_pipe_handle(pipe_hdl); - return p_ed->td_head.halted; -} - bool hcd_pipe_is_stalled(pipe_handle_t pipe_hdl) { ohci_ed_t const * const p_ed = ed_from_pipe_handle(pipe_hdl); return p_ed->td_head.halted && p_ed->is_stalled; } -uint8_t hcd_pipe_get_endpoint_addr(pipe_handle_t pipe_hdl) -{ - ohci_ed_t const * const p_ed = ed_from_pipe_handle(pipe_hdl); - return p_ed->endpoint_number | (p_ed->direction == OHCI_PID_IN ? TUSB_DIR_IN_MASK : 0 ); -} - tusb_error_t hcd_pipe_clear_stall(pipe_handle_t pipe_hdl) { ohci_ed_t * const p_ed = ed_from_pipe_handle(pipe_hdl); -- cgit v1.3.1 From 9c3c782b64d196daf97d12732611fb5e16c80008 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Dec 2018 22:06:48 +0700 Subject: host msc built but got hardfault with inquiry command --- src/class/cdc/cdc_host.h | 2 +- src/class/msc/msc_host.c | 102 ++++++++++++----------- src/class/msc/msc_host.h | 9 +- src/host/ehci/ehci.h | 4 +- src/host/usbh.c | 2 +- tests/lpc18xx_43xx/test/host/msc/test_msc_host.c | 8 +- 6 files changed, 68 insertions(+), 59 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h index 8d0b1d28d..192842dfa 100644 --- a/src/class/cdc/cdc_host.h +++ b/src/class/cdc/cdc_host.h @@ -127,7 +127,7 @@ void tuh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_i #ifdef _TINY_USB_SOURCE_FILE_ void cdch_init(void); -bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length); +bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length); void cdch_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void cdch_close(uint8_t dev_addr); diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 4f5f0c599..f2b4deb73 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -76,7 +76,7 @@ bool tuh_msc_is_mounted(uint8_t dev_addr) bool tuh_msc_is_busy(uint8_t dev_addr) { return msch_data[dev_addr-1].is_initialized && - hcd_pipe_is_busy(msch_data[dev_addr-1].bulk_in); + hcd_pipe_is_busy(dev_addr, msch_data[dev_addr-1].bulk_in); } uint8_t const* tuh_msc_get_vendor_name(uint8_t dev_addr) @@ -110,23 +110,22 @@ static inline void msc_cbw_add_signature(msc_cbw_t *p_cbw, uint8_t lun) p_cbw->lun = lun; } -static tusb_error_t msch_command_xfer(msch_interface_t * p_msch, void* p_buffer) ATTR_WARN_UNUSED_RESULT; -static tusb_error_t msch_command_xfer(msch_interface_t * p_msch, void* p_buffer) +static tusb_error_t msch_command_xfer(uint8_t dev_addr, msch_interface_t * p_msch, void* p_buffer) { if ( NULL != p_buffer) { // there is data phase if (p_msch->cbw.dir & TUSB_DIR_IN_MASK) { - TU_ASSERT_ERR( hcd_pipe_xfer(p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t), false) ); - TU_ASSERT_ERR( hcd_pipe_queue_xfer(p_msch->bulk_in , p_buffer, p_msch->cbw.total_bytes) ); + TU_ASSERT_ERR( hcd_pipe_xfer(dev_addr, p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t), false) ); + TU_ASSERT_ERR( hcd_pipe_queue_xfer(dev_addr, p_msch->bulk_in , p_buffer, p_msch->cbw.total_bytes) ); }else { - TU_ASSERT_ERR( hcd_pipe_queue_xfer(p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t)) ); - TU_ASSERT_ERR( hcd_pipe_xfer(p_msch->bulk_out , p_buffer, p_msch->cbw.total_bytes, false) ); + TU_ASSERT_ERR( hcd_pipe_queue_xfer(dev_addr, p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t)) ); + TU_ASSERT_ERR( hcd_pipe_xfer(dev_addr, p_msch->bulk_out , p_buffer, p_msch->cbw.total_bytes, false) ); } } - TU_ASSERT_ERR( hcd_pipe_xfer(p_msch->bulk_in , (uint8_t*) &p_msch->csw, sizeof(msc_csw_t), true) ); + TU_ASSERT_ERR( hcd_pipe_xfer(dev_addr, p_msch->bulk_in , (uint8_t*) &p_msch->csw, sizeof(msc_csw_t), true) ); return TUSB_ERROR_NONE; } @@ -150,7 +149,7 @@ tusb_error_t tusbh_msc_inquiry(uint8_t dev_addr, uint8_t lun, uint8_t *p_data) memcpy(p_msch->cbw.command, &cmd_inquiry, p_msch->cbw.cmd_len); - TU_ASSERT_ERR ( msch_command_xfer(p_msch, p_data) ); + TU_ASSERT_ERR ( msch_command_xfer(dev_addr, p_msch, p_data) ); return TUSB_ERROR_NONE; } @@ -175,7 +174,7 @@ tusb_error_t tusbh_msc_read_capacity10(uint8_t dev_addr, uint8_t lun, uint8_t *p memcpy(p_msch->cbw.command, &cmd_read_capacity10, p_msch->cbw.cmd_len); - TU_ASSERT_ERR ( msch_command_xfer(p_msch, p_data) ); + TU_ASSERT_ERR ( msch_command_xfer(dev_addr, p_msch, p_data) ); return TUSB_ERROR_NONE; } @@ -200,7 +199,7 @@ tusb_error_t tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, uint8_t *p_dat memcpy(p_msch->cbw.command, &cmd_request_sense, p_msch->cbw.cmd_len); - TU_ASSERT_ERR ( msch_command_xfer(p_msch, p_data) ); + TU_ASSERT_ERR ( msch_command_xfer(dev_addr, p_msch, p_data) ); return TUSB_ERROR_NONE; } @@ -226,8 +225,8 @@ tusb_error_t tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, msc_csw_t * memcpy(p_msch->cbw.command, &cmd_test_unit_ready, p_msch->cbw.cmd_len); // TODO MSCH refractor test uinit ready - TU_ASSERT_ERR( hcd_pipe_xfer(p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t), false) ); - TU_ASSERT_ERR( hcd_pipe_xfer(p_msch->bulk_in , (uint8_t*) p_csw, sizeof(msc_csw_t), true) ); + TU_ASSERT_ERR( hcd_pipe_xfer(dev_addr, p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t), false) ); + TU_ASSERT_ERR( hcd_pipe_xfer(dev_addr, p_msch->bulk_in , (uint8_t*) p_csw, sizeof(msc_csw_t), true) ); return TUSB_ERROR_NONE; } @@ -253,7 +252,7 @@ tusb_error_t tuh_msc_read10(uint8_t dev_addr, uint8_t lun, void * p_buffer, uin memcpy(p_msch->cbw.command, &cmd_read10, p_msch->cbw.cmd_len); - TU_ASSERT_ERR ( msch_command_xfer(p_msch, p_buffer)); + TU_ASSERT_ERR ( msch_command_xfer(dev_addr, p_msch, p_buffer)); return TUSB_ERROR_NONE; } @@ -279,7 +278,7 @@ tusb_error_t tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * p_buffe memcpy(p_msch->cbw.command, &cmd_write10, p_msch->cbw.cmd_len); - TU_ASSERT_ERR ( msch_command_xfer(p_msch, (void*) p_buffer)); + TU_ASSERT_ERR ( msch_command_xfer(dev_addr, p_msch, (void*) p_buffer)); return TUSB_ERROR_NONE; } @@ -293,47 +292,52 @@ void msch_init(void) msch_sem_hdl = osal_semaphore_create(&msch_sem_def); } -bool msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) +bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length) { - if (! ( MSC_SUBCLASS_SCSI == p_interface_desc->bInterfaceSubClass && - MSC_PROTOCOL_BOT == p_interface_desc->bInterfaceProtocol ) ) - { - return TUSB_ERROR_MSC_UNSUPPORTED_PROTOCOL; - } + TU_VERIFY (MSC_SUBCLASS_SCSI == itf_desc->bInterfaceSubClass && + MSC_PROTOCOL_BOT == itf_desc->bInterfaceProtocol); + + msch_interface_t* p_msc = &msch_data[dev_addr-1]; //------------- Open Data Pipe -------------// - tusb_desc_endpoint_t const *p_endpoint; - p_endpoint = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_interface_desc ); + tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) itf_desc ); for(uint32_t i=0; i<2; i++) { - TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType); - TU_ASSERT(TUSB_XFER_BULK == p_endpoint->bmAttributes.xfer); + TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); + TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer); - pipe_handle_t * p_pipe_hdl = ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK ) ? - &msch_data[dev_addr-1].bulk_in : &msch_data[dev_addr-1].bulk_out; + pipe_handle_t * p_pipe_hdl = ( ep_desc->bEndpointAddress & TUSB_DIR_IN_MASK ) ? + &p_msc->bulk_in : &p_msc->bulk_out; - (*p_pipe_hdl) = hcd_pipe_open(dev_addr, p_endpoint, TUSB_CLASS_MSC); + (*p_pipe_hdl) = hcd_pipe_open(dev_addr, ep_desc, TUSB_CLASS_MSC); TU_ASSERT( pipehandle_is_valid(*p_pipe_hdl) ); - p_endpoint = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_endpoint ); + if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) + { + p_msc->ep_in = ep_desc->bEndpointAddress; + }else + { + p_msc->ep_out = ep_desc->bEndpointAddress; + } + + ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) ep_desc ); } - msch_data[dev_addr-1].interface_number = p_interface_desc->bInterfaceNumber; + p_msc->itf_numr = itf_desc->bInterfaceNumber; (*p_length) += sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); - //------------- Get Max Lun -------------// tusb_control_request_t request = { .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_INTERFACE, .type = TUSB_REQ_TYPE_CLASS, .direction = TUSB_DIR_IN }, .bRequest = MSC_REQ_GET_MAX_LUN, .wValue = 0, - .wIndex = msch_data[dev_addr-1].interface_number, + .wIndex = p_msc->itf_numr, .wLength = 1 }; // TODO STALL means zero TU_ASSERT( usbh_control_xfer( dev_addr, &request, msch_buffer ) ); - msch_data[dev_addr-1].max_lun = msch_buffer[0]; + p_msc->max_lun = msch_buffer[0]; #if 0 //------------- Reset -------------// @@ -341,7 +345,7 @@ bool msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_INTERFACE, .type = TUSB_REQ_TYPE_CLASS, .direction = TUSB_DIR_OUT }, .bRequest = MSC_REQ_RESET, .wValue = 0, - .wIndex = msch_data[dev_addr-1].interface_number, + .wIndex = p_msc->itf_numr, .wLength = 0 }; TU_ASSERT( usbh_control_xfer( dev_addr, &request, NULL ) ); @@ -352,8 +356,8 @@ bool msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac tusbh_msc_inquiry(dev_addr, 0, msch_buffer); TU_ASSERT( osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT) ); - memcpy(msch_data[dev_addr-1].vendor_id , ((scsi_inquiry_resp_t*) msch_buffer)->vendor_id , 8); - memcpy(msch_data[dev_addr-1].product_id, ((scsi_inquiry_resp_t*) msch_buffer)->product_id, 16); + memcpy(p_msc->vendor_id , ((scsi_inquiry_resp_t*) msch_buffer)->vendor_id , 8); + memcpy(p_msc->product_id, ((scsi_inquiry_resp_t*) msch_buffer)->product_id, 16); //------------- SCSI Read Capacity 10 -------------// tusbh_msc_read_capacity10(dev_addr, 0, msch_buffer); @@ -361,20 +365,20 @@ bool msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac // NOTE: my toshiba thumb-drive stall the first Read Capacity and require the sequence // Read Capacity --> Stalled --> Clear Stall --> Request Sense --> Read Capacity (2) to work - if ( hcd_pipe_is_stalled(msch_data[dev_addr-1].bulk_in) ) + if ( hcd_pipe_is_stalled(dev_addr, p_msc->bulk_in) ) { // clear stall TODO abstract clear stall function request = (tusb_control_request_t) { .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_ENDPOINT, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_OUT }, .bRequest = TUSB_REQ_CLEAR_FEATURE, .wValue = 0, - .wIndex = hcd_pipe_get_endpoint_addr(msch_data[dev_addr-1].bulk_in), // FIXME use ep addr + .wIndex = p_msc->ep_in, .wLength = 0 }; TU_ASSERT(usbh_control_xfer( dev_addr, &request, NULL )); - hcd_pipe_clear_stall(msch_data[dev_addr-1].bulk_in); + hcd_pipe_clear_stall(dev_addr, p_msc->bulk_in); TU_ASSERT( osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT) ); // wait for SCSI status //------------- SCSI Request Sense -------------// @@ -386,22 +390,24 @@ bool msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac TU_ASSERT(osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT)); } - msch_data[dev_addr-1].last_lba = __be2n( ((scsi_read_capacity10_resp_t*)msch_buffer)->last_lba ); - msch_data[dev_addr-1].block_size = (uint16_t) __be2n( ((scsi_read_capacity10_resp_t*)msch_buffer)->block_size ); + p_msc->last_lba = __be2n( ((scsi_read_capacity10_resp_t*)msch_buffer)->last_lba ); + p_msc->block_size = (uint16_t) __be2n( ((scsi_read_capacity10_resp_t*)msch_buffer)->block_size ); + + p_msc->is_initialized = true; - msch_data[dev_addr-1].is_initialized = true; tuh_msc_mounted_cb(dev_addr); return true; } -void msch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) +void msch_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { - if ( pipehandle_is_equal(pipe_hdl, msch_data[pipe_hdl.dev_addr-1].bulk_in) ) + msch_interface_t* p_msc = &msch_data[dev_addr-1]; + if ( ep_addr == p_msc->ep_in ) { - if (msch_data[pipe_hdl.dev_addr-1].is_initialized) + if (p_msc->is_initialized) { - tuh_msc_isr(pipe_hdl.dev_addr, event, xferred_bytes); + tuh_msc_isr(dev_addr, event, xferred_bytes); }else { // still initializing under open subtask osal_semaphore_post(msch_sem_hdl, true); @@ -411,8 +417,8 @@ void msch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_byte void msch_close(uint8_t dev_addr) { - (void) hcd_pipe_close(msch_data[dev_addr-1].bulk_in); - (void) hcd_pipe_close(msch_data[dev_addr-1].bulk_out); + (void) hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, msch_data[dev_addr-1].bulk_in); + (void) hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, msch_data[dev_addr-1].bulk_out); tu_memclr(&msch_data[dev_addr-1], sizeof(msch_interface_t)); osal_semaphore_reset(msch_sem_hdl); diff --git a/src/class/msc/msc_host.h b/src/class/msc/msc_host.h index 5c5068eb3..a77b494ed 100644 --- a/src/class/msc/msc_host.h +++ b/src/class/msc/msc_host.h @@ -189,7 +189,10 @@ void tuh_msc_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes); typedef struct { pipe_handle_t bulk_in, bulk_out; - uint8_t interface_number; + + uint8_t itf_numr; + uint8_t ep_in; + uint8_t ep_out; uint8_t max_lun; uint16_t block_size; @@ -204,8 +207,8 @@ typedef struct { }msch_interface_t; void msch_init(void); -bool msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; -void msch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); +bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length); +void msch_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void msch_close(uint8_t dev_addr); #endif diff --git a/src/host/ehci/ehci.h b/src/host/ehci/ehci.h index fdb1936d3..8db923edf 100644 --- a/src/host/ehci/ehci.h +++ b/src/host/ehci/ehci.h @@ -458,8 +458,8 @@ typedef struct // Note control qhd of dev0 is used as head of async list, always exists struct { - ehci_qhd_t qhd; - ehci_qtd_t qtd; + ehci_qhd_t qhd; + ehci_qtd_t qtd; }control[CFG_TUSB_HOST_DEVICE_MAX+1]; struct { diff --git a/src/host/usbh.c b/src/host/usbh.c index 1c698cb35..9fe16e5d1 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -81,7 +81,7 @@ static host_class_driver_t const usbh_class_drivers[] = { .class_code = TUSB_CLASS_MSC, .init = msch_init, - .open_subtask = msch_open_subtask, + .open_subtask = msch_open, .isr = msch_isr, .close = msch_close }, diff --git a/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c b/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c index 3f4f9102b..b89a716c2 100644 --- a/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c +++ b/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c @@ -86,7 +86,7 @@ void test_open_pipe_in_failed(void) { hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_null); - TEST_ASSERT(TUSB_ERROR_NONE != msch_open_subtask(dev_addr, p_msc_interface_desc, &length)); + TEST_ASSERT(TUSB_ERROR_NONE != msch_open(dev_addr, p_msc_interface_desc, &length)); } void test_open_pipe_out_failed(void) @@ -94,7 +94,7 @@ void test_open_pipe_out_failed(void) hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, (pipe_handle_t) {1} ); hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_null); - TEST_ASSERT(TUSB_ERROR_NONE != msch_open_subtask(dev_addr, p_msc_interface_desc, &length)); + TEST_ASSERT(TUSB_ERROR_NONE != msch_open(dev_addr, p_msc_interface_desc, &length)); } tusb_error_t stub_control_xfer(uint8_t dev_addr, uint8_t bmRequestType, uint8_t bRequest, @@ -129,7 +129,7 @@ void test_open_desc_length(void) hcd_pipe_queue_xfer_IgnoreAndReturn(TUSB_ERROR_NONE); //------------- Code Under Test -------------// - TEST_ASSERT_STATUS( msch_open_subtask(dev_addr, p_msc_interface_desc, &length) ); + TEST_ASSERT_STATUS( msch_open(dev_addr, p_msc_interface_desc, &length) ); TEST_ASSERT_EQUAL(sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t), length); @@ -144,7 +144,7 @@ void test_open_ok(void) usbh_control_xfer_subtask_StubWithCallback(stub_control_xfer); //------------- Code Under Test -------------// - TEST_ASSERT_STATUS( msch_open_subtask(dev_addr, p_msc_interface_desc, &length) ); + TEST_ASSERT_STATUS( msch_open(dev_addr, p_msc_interface_desc, &length) ); TEST_ASSERT_EQUAL(p_msc_interface_desc->bInterfaceNumber, p_msc->interface_number); } -- cgit v1.3.1 From 212deaf2f8102208099279562b0c6ce04cb60515 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Dec 2018 22:19:01 +0700 Subject: usbh name change --- src/class/cdc/cdc_host.c | 16 ++++++++-------- src/class/cdc/cdc_host.h | 4 ++-- src/class/msc/msc_host.c | 14 +++++++------- src/host/ehci/ehci.c | 12 ++++++------ src/host/hcd.h | 4 ++-- src/host/hub.c | 6 +++--- src/host/hub.h | 4 ++-- src/host/usbh.c | 12 ++++++------ src/host/usbh.h | 2 +- 9 files changed, 37 insertions(+), 37 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index c6378e546..a44a0b97c 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -106,24 +106,24 @@ bool tuh_cdc_serial_is_mounted(uint8_t dev_addr) (cdch_data[dev_addr-1].itf_protocol <= CDC_COMM_PROTOCOL_ATCOMMAND_CDMA); } -tusb_error_t tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify) +bool tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify) { - TU_ASSERT( tuh_cdc_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); - TU_ASSERT( p_data != NULL && length, TUSB_ERROR_INVALID_PARA); + TU_VERIFY( tuh_cdc_mounted(dev_addr) ); + TU_VERIFY( p_data != NULL && length, TUSB_ERROR_INVALID_PARA); pipe_handle_t pipe_out = cdch_data[dev_addr-1].pipe_out; - if ( hcd_pipe_is_busy(dev_addr, pipe_out) ) return TUSB_ERROR_INTERFACE_IS_BUSY; + if ( hcd_pipe_is_busy(dev_addr, pipe_out) ) return false; return hcd_pipe_xfer(dev_addr, pipe_out, (void *) p_data, length, is_notify); } -tusb_error_t tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify) +bool tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify) { - TU_ASSERT( tuh_cdc_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); - TU_ASSERT( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA); + TU_VERIFY( tuh_cdc_mounted(dev_addr) ); + TU_VERIFY( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA); pipe_handle_t pipe_in = cdch_data[dev_addr-1].pipe_in; - if ( hcd_pipe_is_busy(dev_addr, pipe_in) ) return TUSB_ERROR_INTERFACE_IS_BUSY; + if ( hcd_pipe_is_busy(dev_addr, pipe_in) ) return false; return hcd_pipe_xfer(dev_addr, pipe_in, p_buffer, length, is_notify); } diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h index 192842dfa..5388a8f60 100644 --- a/src/class/cdc/cdc_host.h +++ b/src/class/cdc/cdc_host.h @@ -86,7 +86,7 @@ bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid); * \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the * interface's callback function. \a p_data must be declared with \ref CFG_TUSB_MEM_SECTION. */ -tusb_error_t tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify); +bool tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify); /** \brief Perform USB IN transfer to get data from device * \param[in] dev_addr device address @@ -99,7 +99,7 @@ tusb_error_t tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length * \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the * interface's callback function. \a p_data must be declared with \ref CFG_TUSB_MEM_SECTION. */ -tusb_error_t tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify); +bool tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify); //--------------------------------------------------------------------+ // CDC APPLICATION CALLBACKS diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index f2b4deb73..b61256805 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -116,16 +116,16 @@ static tusb_error_t msch_command_xfer(uint8_t dev_addr, msch_interface_t * p_msc { // there is data phase if (p_msch->cbw.dir & TUSB_DIR_IN_MASK) { - TU_ASSERT_ERR( hcd_pipe_xfer(dev_addr, p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t), false) ); - TU_ASSERT_ERR( hcd_pipe_queue_xfer(dev_addr, p_msch->bulk_in , p_buffer, p_msch->cbw.total_bytes) ); + TU_ASSERT( hcd_pipe_xfer(dev_addr, p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t), false), TUSB_ERROR_FAILED ); + TU_ASSERT( hcd_pipe_queue_xfer(dev_addr, p_msch->bulk_in , p_buffer, p_msch->cbw.total_bytes), TUSB_ERROR_FAILED ); }else { - TU_ASSERT_ERR( hcd_pipe_queue_xfer(dev_addr, p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t)) ); - TU_ASSERT_ERR( hcd_pipe_xfer(dev_addr, p_msch->bulk_out , p_buffer, p_msch->cbw.total_bytes, false) ); + TU_ASSERT( hcd_pipe_queue_xfer(dev_addr, p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t)), TUSB_ERROR_FAILED ); + TU_ASSERT( hcd_pipe_xfer(dev_addr, p_msch->bulk_out , p_buffer, p_msch->cbw.total_bytes, false), TUSB_ERROR_FAILED ); } } - TU_ASSERT_ERR( hcd_pipe_xfer(dev_addr, p_msch->bulk_in , (uint8_t*) &p_msch->csw, sizeof(msc_csw_t), true) ); + TU_ASSERT( hcd_pipe_xfer(dev_addr, p_msch->bulk_in , (uint8_t*) &p_msch->csw, sizeof(msc_csw_t), true), TUSB_ERROR_FAILED); return TUSB_ERROR_NONE; } @@ -225,8 +225,8 @@ tusb_error_t tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, msc_csw_t * memcpy(p_msch->cbw.command, &cmd_test_unit_ready, p_msch->cbw.cmd_len); // TODO MSCH refractor test uinit ready - TU_ASSERT_ERR( hcd_pipe_xfer(dev_addr, p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t), false) ); - TU_ASSERT_ERR( hcd_pipe_xfer(dev_addr, p_msch->bulk_in , (uint8_t*) p_csw, sizeof(msc_csw_t), true) ); + TU_ASSERT( hcd_pipe_xfer(dev_addr, p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cbw_t), false), TUSB_ERROR_FAILED ); + TU_ASSERT( hcd_pipe_xfer(dev_addr, p_msch->bulk_in , (uint8_t*) p_csw, sizeof(msc_csw_t), true), TUSB_ERROR_FAILED ); return TUSB_ERROR_NONE; } diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index dd19a5224..bfdc4e4f7 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -443,7 +443,7 @@ pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint return (pipe_handle_t) { .index = qhd_get_index(p_qhd) }; } -tusb_error_t hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) +bool hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) { //------------- TODO pipe handle validate -------------// @@ -451,7 +451,7 @@ tusb_error_t hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); ehci_qtd_t *p_qtd = qtd_find_free(dev_addr); - TU_ASSERT(p_qtd, TUSB_ERROR_EHCI_NOT_ENOUGH_QTD); + TU_ASSERT(p_qtd); qtd_init(p_qtd, (uint32_t) buffer, total_bytes); p_qtd->pid = p_qhd->pid_non_control; @@ -459,12 +459,12 @@ tusb_error_t hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint //------------- insert TD to TD list -------------// qtd_insert_to_qhd(p_qhd, p_qtd); - return TUSB_ERROR_NONE; + return true; } -tusb_error_t hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) +bool hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) { - TU_ASSERT_ERR ( hcd_pipe_queue_xfer(dev_addr, pipe_hdl, buffer, total_bytes) ); + TU_ASSERT ( hcd_pipe_queue_xfer(dev_addr, pipe_hdl, buffer, total_bytes) ); ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); @@ -474,7 +474,7 @@ tusb_error_t hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t bu } p_qhd->qtd_overlay.next.address = (uint32_t) p_qhd->p_qtd_list_head; // attach head QTD to QHD start transferring - return TUSB_ERROR_NONE; + return true; } /// pipe_close should only be called as a part of unmount/safe-remove process diff --git a/src/host/hcd.h b/src/host/hcd.h index 9ea86a5fe..0449754c7 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -145,8 +145,8 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * // TODO control xfer should be used via usbh layer pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); -tusb_error_t hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet -tusb_error_t hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; +bool hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet +bool hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, pipe_handle_t pipe_hdl); bool hcd_pipe_is_busy(uint8_t dev_addr, pipe_handle_t pipe_hdl); diff --git a/src/host/hub.c b/src/host/hub.c index bc0592a97..a5b0d2e99 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -155,7 +155,7 @@ void hub_init(void) // hub_enum_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(hub_enum_semaphore) ); } -bool hub_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) +bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) { // not support multiple TT yet if ( p_interface_desc->bInterfaceProtocol > 1 ) return false; @@ -204,7 +204,7 @@ bool hub_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t co } //------------- Queue the initial Status endpoint transfer -------------// - TU_ASSERT( TUSB_ERROR_NONE == hcd_pipe_xfer(dev_addr, hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true) ); + TU_ASSERT( hcd_pipe_xfer(dev_addr, hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true) ); return true; } @@ -254,7 +254,7 @@ void hub_close(uint8_t dev_addr) // osal_semaphore_reset(hub_enum_sem_hdl); } -tusb_error_t hub_status_pipe_queue(uint8_t dev_addr) +bool hub_status_pipe_queue(uint8_t dev_addr) { return hcd_pipe_xfer(dev_addr, hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true); } diff --git a/src/host/hub.h b/src/host/hub.h index 8e8416d8f..dc26a098c 100644 --- a/src/host/hub.h +++ b/src/host/hub.h @@ -187,7 +187,7 @@ TU_VERIFY_STATIC( sizeof(hub_port_status_response_t) == 4, "size is not correct" bool hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port); bool hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t feature); tusb_speed_t hub_port_get_speed(void); -tusb_error_t hub_status_pipe_queue(uint8_t dev_addr); +bool hub_status_pipe_queue(uint8_t dev_addr); //--------------------------------------------------------------------+ // USBH-CLASS DRIVER API @@ -195,7 +195,7 @@ tusb_error_t hub_status_pipe_queue(uint8_t dev_addr); #ifdef _TINY_USB_SOURCE_FILE_ void hub_init(void); -bool hub_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_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) ATTR_WARN_UNUSED_RESULT; void hub_isr(uint8_t dev_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 9fe16e5d1..127d0f8fd 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -71,7 +71,7 @@ static host_class_driver_t const usbh_class_drivers[] = { .class_code = TUSB_CLASS_CDC, .init = cdch_init, - .open_subtask = cdch_open, + .open = cdch_open, .isr = cdch_isr, .close = cdch_close }, @@ -81,7 +81,7 @@ static host_class_driver_t const usbh_class_drivers[] = { .class_code = TUSB_CLASS_MSC, .init = msch_init, - .open_subtask = msch_open, + .open = msch_open, .isr = msch_isr, .close = msch_close }, @@ -91,7 +91,7 @@ static host_class_driver_t const usbh_class_drivers[] = { .class_code = TUSB_CLASS_HID, .init = hidh_init, - .open_subtask = hidh_open_subtask, + .open = hidh_open_subtask, .isr = hidh_isr, .close = hidh_close }, @@ -101,7 +101,7 @@ static host_class_driver_t const usbh_class_drivers[] = { .class_code = TUSB_CLASS_HUB, .init = hub_init, - .open_subtask = hub_open_subtask, + .open = hub_open, .isr = hub_isr, .close = hub_close }, @@ -111,7 +111,7 @@ static host_class_driver_t const usbh_class_drivers[] = { .class_code = TUSB_CLASS_VENDOR_SPECIFIC, .init = cush_init, - .open_subtask = cush_open_subtask, + .open = cush_open_subtask, .isr = cush_isr, .close = cush_close } @@ -611,7 +611,7 @@ bool enum_task(hcd_event_t* event) { uint16_t itf_len = 0; - if ( usbh_class_drivers[drv_id].open_subtask(new_dev->rhport, new_addr, desc_itf, &itf_len) ) + if ( usbh_class_drivers[drv_id].open(new_dev->rhport, new_addr, desc_itf, &itf_len) ) { mark_interface_endpoint(new_dev->ep2drv, p_desc, itf_len, drv_id); } diff --git a/src/host/usbh.h b/src/host/usbh.h index a2e196c9a..3656b9a0d 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -67,7 +67,7 @@ typedef struct { uint8_t class_code; void (* const init) (void); - bool (* const open_subtask)(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const * itf_desc, uint16_t* outlen); + bool (* const open)(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const * itf_desc, uint16_t* outlen); void (* const isr) (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t len); void (* const close) (uint8_t); } host_class_driver_t; -- cgit v1.3.1 From 7a626dbc8b7edcf3303deb100f713f12038fefbe Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 11 Dec 2018 00:56:21 +0700 Subject: completely remove pipe handle for cdc/hub/ehci --- src/class/cdc/cdc_host.c | 44 ++++++++----------- src/host/ehci/ehci.c | 111 ++++++++++++++++++++++------------------------- src/host/ehci/ehci.h | 8 +--- src/host/hcd.h | 32 +++++--------- src/host/hub.c | 31 +++++++------ src/host/hub.h | 2 +- src/host/usbh.c | 2 +- 7 files changed, 102 insertions(+), 128 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index a44a0b97c..78b338f15 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -52,14 +52,12 @@ typedef struct { uint8_t itf_num; uint8_t itf_protocol; - cdc_acm_capability_t acm_capability; - - pipe_handle_t pipe_notification, pipe_out, pipe_in; - uint8_t ep_notif; uint8_t ep_in; uint8_t ep_out; + cdc_acm_capability_t acm_capability; + } cdch_data_t; //--------------------------------------------------------------------+ @@ -82,13 +80,13 @@ bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) switch (pipeid) { case CDC_PIPE_NOTIFICATION: - return hcd_pipe_is_busy(dev_addr, p_cdc->pipe_notification ); + return hcd_pipe_is_busy(dev_addr, p_cdc->ep_notif ); case CDC_PIPE_DATA_IN: - return hcd_pipe_is_busy(dev_addr, p_cdc->pipe_in ); + return hcd_pipe_is_busy(dev_addr, p_cdc->ep_in ); case CDC_PIPE_DATA_OUT: - return hcd_pipe_is_busy(dev_addr, p_cdc->pipe_out ); + return hcd_pipe_is_busy(dev_addr, p_cdc->ep_out ); default: return false; @@ -111,10 +109,10 @@ bool tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool i TU_VERIFY( tuh_cdc_mounted(dev_addr) ); TU_VERIFY( p_data != NULL && length, TUSB_ERROR_INVALID_PARA); - pipe_handle_t pipe_out = cdch_data[dev_addr-1].pipe_out; - if ( hcd_pipe_is_busy(dev_addr, pipe_out) ) return false; + uint8_t const ep_out = cdch_data[dev_addr-1].ep_out; + if ( hcd_pipe_is_busy(dev_addr, ep_out) ) return false; - return hcd_pipe_xfer(dev_addr, pipe_out, (void *) p_data, length, is_notify); + return hcd_pipe_xfer(dev_addr, ep_out, (void *) p_data, length, is_notify); } bool tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify) @@ -122,10 +120,10 @@ bool tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is TU_VERIFY( tuh_cdc_mounted(dev_addr) ); TU_VERIFY( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA); - pipe_handle_t pipe_in = cdch_data[dev_addr-1].pipe_in; - if ( hcd_pipe_is_busy(dev_addr, pipe_in) ) return false; + uint8_t const ep_in = cdch_data[dev_addr-1].ep_in; + if ( hcd_pipe_is_busy(dev_addr, ep_in) ) return false; - return hcd_pipe_xfer(dev_addr, pipe_in, p_buffer, length, is_notify); + return hcd_pipe_xfer(dev_addr, ep_in, p_buffer, length, is_notify); } //--------------------------------------------------------------------+ @@ -172,21 +170,19 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE]) { - // notification endpoint if any + // notification endpoint tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) p_desc; - p_cdc->pipe_notification = hcd_pipe_open(rhport, dev_addr, ep_desc); + TU_ASSERT( hcd_pipe_open(rhport, dev_addr, ep_desc) ); p_cdc->ep_notif = ep_desc->bEndpointAddress; (*p_length) += p_desc[DESC_OFFSET_LEN]; p_desc = descriptor_next(p_desc); - - TU_ASSERT(pipehandle_is_valid(p_cdc->pipe_notification)); } //------------- Data Interface (if any) -------------// if ( (TUSB_DESC_INTERFACE == p_desc[DESC_OFFSET_TYPE]) && - (TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) ) + (TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) ) { (*p_length) += p_desc[DESC_OFFSET_LEN]; p_desc = descriptor_next(p_desc); @@ -198,11 +194,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer); - pipe_handle_t * p_pipe_hdl = ( ep_desc->bEndpointAddress & TUSB_DIR_IN_MASK ) ? - &p_cdc->pipe_in : &p_cdc->pipe_out; - - (*p_pipe_hdl) = hcd_pipe_open(rhport, dev_addr, ep_desc); - TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl) ); + TU_ASSERT(hcd_pipe_open(rhport, dev_addr, ep_desc)); if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { @@ -241,9 +233,9 @@ void cdch_close(uint8_t dev_addr) { cdch_data_t * p_cdc = &cdch_data[dev_addr-1]; - hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->pipe_notification); - hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->pipe_in); - hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->pipe_out); + hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->ep_notif); + hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->ep_in); + hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->ep_out); tu_memclr(p_cdc, sizeof(cdch_data_t)); } diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index fbc110b83..f9b9db797 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -77,9 +77,9 @@ static inline ehci_qtd_t* get_control_qtds(uint8_t dev_addr) ATTR_ALWAYS_INLINE static inline uint8_t qhd_get_index(ehci_qhd_t const * p_qhd) ATTR_ALWAYS_INLINE ATTR_PURE; static inline ehci_qhd_t* qhd_next(ehci_qhd_t const * p_qhd) ATTR_ALWAYS_INLINE ATTR_PURE; -static inline ehci_qhd_t* qhd_find_free (uint8_t dev_addr) ATTR_PURE ATTR_ALWAYS_INLINE; +static inline ehci_qhd_t* qhd_find_free (void); static inline tusb_xfer_type_t qhd_get_xfer_type(ehci_qhd_t const * p_qhd) ATTR_ALWAYS_INLINE ATTR_PURE; -static inline ehci_qhd_t* qhd_get_from_pipe_handle(uint8_t dev_addr, pipe_handle_t pipe_hdl); +static inline ehci_qhd_t* qhd_get_from_pipe_handle(uint8_t dev_addr, uint8_t ep_addr); // determine if a queue head has bus-related error static inline bool qhd_has_xact_error(ehci_qhd_t * p_qhd) @@ -321,15 +321,6 @@ bool hcd_pipe_control_close(uint8_t dev_addr) return true; } -bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const* ep_desc) -{ - // FIXME control only for now - (void) rhport; - hcd_pipe_open(rhport, dev_addr, ep_desc); - - return true; -} - bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { // FIXME control only for now @@ -389,12 +380,10 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet //--------------------------------------------------------------------+ // BULK/INT/ISO PIPE API //--------------------------------------------------------------------+ -pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) +bool hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) { - pipe_handle_t const null_handle = { .index = 0 }; - // TODO not support ISO yet - if (ep_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) return null_handle; + TU_ASSERT (ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS); //------------- Prepare Queue Head -------------// ehci_qhd_t * p_qhd; @@ -404,11 +393,11 @@ pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint p_qhd = get_control_qhd(dev_addr); }else { - p_qhd = qhd_find_free(dev_addr); + p_qhd = qhd_find_free(); } - TU_ASSERT(p_qhd, null_handle); + TU_ASSERT(p_qhd); - qhd_init( p_qhd, dev_addr, ep_desc); + qhd_init(p_qhd, dev_addr, ep_desc); //------------- Insert to Async List -------------// ehci_link_t * list_head; @@ -440,15 +429,13 @@ pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint // TODO might need to disable async/period list list_insert( list_head, (ehci_link_t*) p_qhd, EHCI_QUEUE_ELEMENT_QHD); - return (pipe_handle_t) { .index = qhd_get_index(p_qhd) }; + return true; } -bool hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) +bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes) { - //------------- TODO pipe handle validate -------------// - //------------- set up QTD -------------// - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, ep_addr); ehci_qtd_t *p_qtd = qtd_find_free(dev_addr); TU_ASSERT(p_qtd); @@ -462,11 +449,11 @@ bool hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffe return true; } -bool hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) +bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) { - TU_ASSERT ( hcd_pipe_queue_xfer(dev_addr, pipe_hdl, buffer, total_bytes) ); + TU_ASSERT ( hcd_pipe_queue_xfer(dev_addr, ep_addr, buffer, total_bytes) ); - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, ep_addr); if ( int_on_complete ) { // the just added qtd is pointed by list_tail @@ -478,9 +465,9 @@ bool hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], u } /// pipe_close should only be called as a part of unmount/safe-remove process -bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, pipe_handle_t pipe_hdl) +bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, ep_addr); // async list needs async advance handshake to make sure host controller has released cached data // non-control does not use async advance, it will eventually free by control pipe close @@ -505,21 +492,21 @@ bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, pipe_handle_t pipe_hdl) return true; } -bool hcd_pipe_is_busy(uint8_t dev_addr, pipe_handle_t pipe_hdl) +bool hcd_pipe_is_busy(uint8_t dev_addr, uint8_t ep_addr) { - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, ep_addr); return !p_qhd->qtd_overlay.halted && (p_qhd->p_qtd_list_head != NULL); } -bool hcd_pipe_is_stalled(uint8_t dev_addr, pipe_handle_t pipe_hdl) +bool hcd_pipe_is_stalled(uint8_t dev_addr, uint8_t ep_addr) { - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, ep_addr); return p_qhd->qtd_overlay.halted && !qhd_has_xact_error(p_qhd); } -tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, pipe_handle_t pipe_hdl) +tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, uint8_t ep_addr) { - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, ep_addr); p_qhd->qtd_overlay.halted = 0; // TODO reset data toggle ? return TUSB_ERROR_NONE; @@ -553,18 +540,22 @@ static void async_advance_isr(ehci_qhd_t * const async_head) p_control_qhd->used = 0; // Host Controller has cleaned up its cached data for this device, set state to unplug - _usbh_devices[dev_addr+1].state = TUSB_DEVICE_STATE_UNPLUG; + _usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_UNPLUG; for (uint8_t i=0; idevice_address-1].qhd; + return NULL; } static inline tusb_xfer_type_t qhd_get_xfer_type(ehci_qhd_t const * p_qhd) @@ -854,21 +839,31 @@ static inline ehci_qhd_t* qhd_next(ehci_qhd_t const * p_qhd) return (ehci_qhd_t*) tu_align32(p_qhd->next.address); } -static inline ehci_qhd_t* qhd_get_from_pipe_handle(uint8_t dev_addr, pipe_handle_t pipe_hdl) +static inline ehci_qhd_t* qhd_get_from_pipe_handle(uint8_t dev_addr, uint8_t ep_addr) { - return &ehci_data.device[dev_addr-1].qhd[pipe_hdl.index]; + ehci_qhd_t* qhd_pool = ehci_data.qhd_pool; + + for(uint32_t i=0; i 0; -} - -static inline bool pipehandle_is_equal(pipe_handle_t x, pipe_handle_t y) -{ - return (x.index == y.index); -} - //--------------------------------------------------------------------+ // USBH-HCD API //--------------------------------------------------------------------+ @@ -134,7 +123,6 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev //--------------------------------------------------------------------+ // Endpoints API //--------------------------------------------------------------------+ -bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const* ep_desc); bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]); bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen); @@ -144,14 +132,14 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * //--------------------------------------------------------------------+ // TODO control xfer should be used via usbh layer -pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); -bool hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet -bool hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; -bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, pipe_handle_t pipe_hdl); +bool hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); +bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes); // only queue, not transferring yet +bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete); +bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); // TODO remove -bool hcd_pipe_is_busy(uint8_t dev_addr, pipe_handle_t pipe_hdl); -bool hcd_pipe_is_stalled(uint8_t dev_addr, pipe_handle_t pipe_hdl); // stalled also counted as error -tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, pipe_handle_t pipe_hdl); +bool hcd_pipe_is_busy(uint8_t dev_addr, uint8_t ep_addr); +bool hcd_pipe_is_stalled(uint8_t dev_addr, uint8_t ep_addr); // stalled also counted as error +tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, uint8_t ep_addr); #if 0 tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT; diff --git a/src/host/hub.c b/src/host/hub.c index a5b0d2e99..f755928e8 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -50,9 +50,10 @@ //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ -typedef struct { - pipe_handle_t pipe_status; - uint8_t interface_number; +typedef struct +{ + uint8_t itf_num; + uint8_t ep_status; uint8_t port_number; uint8_t status_change; // data from status change interrupt endpoint }usbh_hub_t; @@ -161,15 +162,16 @@ bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_i if ( p_interface_desc->bInterfaceProtocol > 1 ) return false; //------------- Open Interrupt Status Pipe -------------// - tusb_desc_endpoint_t const *p_endpoint; - p_endpoint = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_interface_desc ); + tusb_desc_endpoint_t const *ep_desc; + ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_interface_desc ); + + TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); + TU_ASSERT(TUSB_XFER_INTERRUPT == ep_desc->bmAttributes.xfer); - TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType); - TU_ASSERT(TUSB_XFER_INTERRUPT == p_endpoint->bmAttributes.xfer); + TU_ASSERT(hcd_pipe_open(rhport, dev_addr, ep_desc)); - hub_data[dev_addr-1].pipe_status = hcd_pipe_open(rhport, dev_addr, p_endpoint); - TU_ASSERT( pipehandle_is_valid(hub_data[dev_addr-1].pipe_status) ); - hub_data[dev_addr-1].interface_number = p_interface_desc->bInterfaceNumber; + hub_data[dev_addr-1].itf_num = p_interface_desc->bInterfaceNumber; + hub_data[dev_addr-1].ep_status = ep_desc->bEndpointAddress; (*p_length) = sizeof(tusb_desc_interface_t) + sizeof(tusb_desc_endpoint_t); @@ -204,16 +206,17 @@ bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_i } //------------- Queue the initial Status endpoint transfer -------------// - TU_ASSERT( hcd_pipe_xfer(dev_addr, hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true) ); + TU_ASSERT( hcd_pipe_xfer(dev_addr, hub_data[dev_addr-1].ep_status, &hub_data[dev_addr-1].status_change, 1, true) ); return true; } // is the response of interrupt endpoint polling #include "usbh_hcd.h" // FIXME remove -void hub_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes) +void hub_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { (void) xferred_bytes; // TODO can be more than 1 for hub with lots of ports + (void) ep_addr; usbh_hub_t * p_hub = &hub_data[dev_addr-1]; @@ -248,7 +251,7 @@ void hub_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes) void hub_close(uint8_t dev_addr) { - hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, hub_data[dev_addr-1].pipe_status); + hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, hub_data[dev_addr-1].ep_status); tu_memclr(&hub_data[dev_addr-1], sizeof(usbh_hub_t)); // osal_semaphore_reset(hub_enum_sem_hdl); @@ -256,7 +259,7 @@ void hub_close(uint8_t dev_addr) bool hub_status_pipe_queue(uint8_t dev_addr) { - return hcd_pipe_xfer(dev_addr, hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true); + return hcd_pipe_xfer(dev_addr, hub_data[dev_addr-1].ep_status, &hub_data[dev_addr-1].status_change, 1, true); } diff --git a/src/host/hub.h b/src/host/hub.h index dc26a098c..f8d8a4c6a 100644 --- a/src/host/hub.h +++ b/src/host/hub.h @@ -196,7 +196,7 @@ bool hub_status_pipe_queue(uint8_t dev_addr); 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; -void hub_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes); +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); #endif diff --git a/src/host/usbh.c b/src/host/usbh.c index e1c0600d5..8e03d97d1 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -236,7 +236,7 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) .bInterval = 0 }; - hcd_edpt_open(_usbh_devices[dev_addr].rhport, dev_addr, &ep0_desc); + hcd_pipe_open(_usbh_devices[dev_addr].rhport, dev_addr, &ep0_desc); return TUSB_ERROR_NONE; } -- cgit v1.3.1 From 0d04e6eb96935723f17969bf43a33532fcebcbf6 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 11 Dec 2018 13:12:21 +0700 Subject: rename to hcd_edpt_open() --- src/class/cdc/cdc_host.c | 4 ++-- src/class/custom/custom_host.c | 2 +- src/class/hid/hid_host.c | 2 +- src/class/msc/msc_host.c | 2 +- src/host/ehci/ehci.c | 2 +- src/host/hcd.h | 6 ++--- src/host/hub.c | 2 +- src/host/ohci/ohci.c | 2 +- src/host/usbh.c | 2 +- tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c | 26 +++++++++++----------- .../test/host/cdc/test_cdc_rndis_host.c | 6 ++--- .../host/ehci/test_ehci_usbh_hcd_integration.c | 2 +- .../test/host/ehci/test_pipe_bulk_open.c | 6 ++--- .../test/host/ehci/test_pipe_bulk_xfer.c | 4 ++-- .../test/host/ehci/test_pipe_interrupt_open.c | 26 +++++++++++----------- .../test/host/ehci/test_pipe_interrupt_xfer.c | 4 ++-- .../test/host/ehci/test_pipe_isochronous_open.c | 2 +- tests/lpc18xx_43xx/test/host/hid/test_hid_host.c | 2 +- .../test/host/hid/test_hidh_keyboard.c | 2 +- tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c | 2 +- tests/lpc18xx_43xx/test/host/msc/test_msc_host.c | 14 ++++++------ 21 files changed, 60 insertions(+), 60 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 78b338f15..f889c8c90 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -173,7 +173,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it // notification endpoint tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) p_desc; - TU_ASSERT( hcd_pipe_open(rhport, dev_addr, ep_desc) ); + TU_ASSERT( hcd_edpt_open(rhport, dev_addr, ep_desc) ); p_cdc->ep_notif = ep_desc->bEndpointAddress; (*p_length) += p_desc[DESC_OFFSET_LEN]; @@ -194,7 +194,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer); - TU_ASSERT(hcd_pipe_open(rhport, dev_addr, ep_desc)); + TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { diff --git a/src/class/custom/custom_host.c b/src/class/custom/custom_host.c index 2a8206e36..e840a2829 100644 --- a/src/class/custom/custom_host.c +++ b/src/class/custom/custom_host.c @@ -121,7 +121,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ pipe_handle_t * p_pipe_hdl = ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK ) ? &custom_interface[dev_addr-1].pipe_in : &custom_interface[dev_addr-1].pipe_out; - *p_pipe_hdl = hcd_pipe_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC); + *p_pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC); TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED ); p_desc = descriptor_next(p_desc); diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 980381bf5..8d7dce70a 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -56,7 +56,7 @@ //--------------------------------------------------------------------+ static inline bool hidh_interface_open(uint8_t dev_addr, uint8_t interface_number, tusb_desc_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid) { - p_hid->pipe_hdl = hcd_pipe_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID); + p_hid->pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID); p_hid->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor p_hid->interface_number = interface_number; diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 1053d42d2..8e51debcf 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -307,7 +307,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer); - TU_ASSERT(hcd_pipe_open(rhport, dev_addr, ep_desc)); + TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index ce74476bb..94796c9dd 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -313,7 +313,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet //--------------------------------------------------------------------+ // BULK/INT/ISO PIPE API //--------------------------------------------------------------------+ -bool hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) +bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) { // TODO not support ISO yet TU_ASSERT (ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS); diff --git a/src/host/hcd.h b/src/host/hcd.h index dcc2bdf53..9b7b99321 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -128,15 +128,15 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev //--------------------------------------------------------------------+ // Endpoints API //--------------------------------------------------------------------+ -bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]); -bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen); +bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); +bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); +bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen); //--------------------------------------------------------------------+ // PIPE API //--------------------------------------------------------------------+ // TODO control xfer should be used via usbh layer -bool hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes); // only queue, not transferring yet bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete); bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); // TODO remove diff --git a/src/host/hub.c b/src/host/hub.c index f755928e8..411e1ae95 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -168,7 +168,7 @@ bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_i TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); TU_ASSERT(TUSB_XFER_INTERRUPT == ep_desc->bmAttributes.xfer); - TU_ASSERT(hcd_pipe_open(rhport, dev_addr, ep_desc)); + TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); hub_data[dev_addr-1].itf_num = p_interface_desc->bInterfaceNumber; hub_data[dev_addr-1].ep_status = ep_desc->bEndpointAddress; diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index 5923be936..37de86c60 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -481,7 +481,7 @@ static void ed_list_remove(ohci_ed_t * p_head, ohci_ed_t * p_ed) p_ed->used = 0; // free ED } -pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_desc_endpoint_t const * p_endpoint_desc, uint8_t class_code) +pipe_handle_t hcd_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const * p_endpoint_desc, uint8_t class_code) { pipe_handle_t const null_handle = { .dev_addr = 0, .xfer_type = 0, .index = 0 }; diff --git a/src/host/usbh.c b/src/host/usbh.c index 3ab3bd71e..ff4343fd2 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -236,7 +236,7 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) .bInterval = 0 }; - hcd_pipe_open(_usbh_devices[dev_addr].rhport, dev_addr, &ep0_desc); + hcd_edpt_open(_usbh_devices[dev_addr].rhport, dev_addr, &ep0_desc); return TUSB_ERROR_NONE; } 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 1b73e649f..1f8410461 100644 --- a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c +++ b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c @@ -86,7 +86,7 @@ void test_cdch_open_failed_to_open_notification_endpoint(void) { pipe_handle_t null_hdl = {0}; - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, null_hdl); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, null_hdl); //------------- CUT -------------// TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length)); @@ -98,8 +98,8 @@ void test_cdch_open_failed_to_open_data_endpoint_out(void) pipe_handle_t dummy_hld = { .dev_addr = 1 }; pipe_handle_t null_hdl = {0}; - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, dummy_hld); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, null_hdl); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, dummy_hld); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, null_hdl); //------------- CUT -------------// TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length)); @@ -111,9 +111,9 @@ void test_cdch_open_failed_to_open_data_endpoint_in(void) pipe_handle_t dummy_hld = { .dev_addr = 1 }; pipe_handle_t null_hdl = {0}; - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, dummy_hld); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, dummy_hld); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, null_hdl); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, dummy_hld); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, dummy_hld); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, null_hdl); //------------- CUT -------------// TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length)); @@ -131,7 +131,7 @@ void test_cdch_open_length_check(void) sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); pipe_handle_t dummy_hld = { .dev_addr = 1 }; - hcd_pipe_open_IgnoreAndReturn(dummy_hld); + hcd_edpt_open_IgnoreAndReturn(dummy_hld); tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// @@ -143,7 +143,7 @@ void test_cdch_open_length_check(void) void test_cdch_open_interface_number_check(void) { pipe_handle_t dummy_hld = { .dev_addr = 1 }; - hcd_pipe_open_IgnoreAndReturn(dummy_hld); + hcd_edpt_open_IgnoreAndReturn(dummy_hld); tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// @@ -156,7 +156,7 @@ void test_cdch_open_interface_number_check(void) void test_cdch_open_protocol_check(void) { pipe_handle_t dummy_hld = { .dev_addr = 1 }; - hcd_pipe_open_IgnoreAndReturn(dummy_hld); + hcd_edpt_open_IgnoreAndReturn(dummy_hld); tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// @@ -169,7 +169,7 @@ void test_cdch_open_protocol_check(void) void test_cdch_open_acm_capacity_check(void) { pipe_handle_t dummy_hld = { .dev_addr = 1 }; - hcd_pipe_open_IgnoreAndReturn(dummy_hld); + hcd_edpt_open_IgnoreAndReturn(dummy_hld); tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// @@ -187,9 +187,9 @@ void test_cdch_close_device(void) pipe_handle_t pipe_out = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 0 }; pipe_handle_t pipe_int = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 1 }; - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, pipe_notification); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, pipe_out); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_int); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, pipe_notification); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, pipe_out); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_int); tusbh_cdc_mounted_cb_Expect(dev_addr); TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) ); diff --git a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_rndis_host.c b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_rndis_host.c index 86d6c2890..ca478b129 100644 --- a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_rndis_host.c +++ b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_rndis_host.c @@ -103,9 +103,9 @@ void setUp(void) osal_mutex_wait_StubWithCallback(stub_mutex_wait); osal_mutex_release_IgnoreAndReturn(TUSB_ERROR_NONE); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, pipe_notification); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, pipe_out); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_in); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, pipe_notification); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, pipe_out); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_in); } void tearDown(void) diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_ehci_usbh_hcd_integration.c b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_usbh_hcd_integration.c index e17b2ba74..8fa5af5d5 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_ehci_usbh_hcd_integration.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_usbh_hcd_integration.c @@ -168,7 +168,7 @@ void test_bulk_pipe_close(void) }; uint8_t xfer_data[100]; - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); + pipe_handle_t pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl, xfer_data, sizeof(xfer_data), 100) ); TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl, xfer_data, sizeof(xfer_data), 50) ); diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c index 52cf40555..5b86750ef 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c @@ -155,7 +155,7 @@ void test_open_bulk_qhd_data(void) tusb_desc_endpoint_t const * desc_endpoint = &desc_ept_bulk_in; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); + pipe_hdl = hcd_edpt_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); TEST_ASSERT_EQUAL(TUSB_XFER_BULK, pipe_hdl.xfer_type); @@ -175,7 +175,7 @@ void test_open_bulk_hs_out_pingstate(void) pipe_handle_t pipe_hdl; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC); + pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC); p_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1 ].qhd[ pipe_hdl.index ]; TEST_ASSERT(p_qhd->qtd_overlay.pingstate_err); @@ -187,7 +187,7 @@ void test_open_bulk_hs_out_pingstate(void) void test_bulk_close(void) { tusb_desc_endpoint_t const * desc_endpoint = &desc_ept_bulk_in; - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); + pipe_handle_t pipe_hdl = hcd_edpt_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); ehci_qhd_t *p_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; //------------- Code Under TEST -------------// diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c index 634184ee2..47e8177a3 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c @@ -102,7 +102,7 @@ void setUp(void) async_head = get_async_head( hostid ); //------------- pipe open -------------// - pipe_hdl_bulk = hcd_pipe_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); + pipe_hdl_bulk = hcd_edpt_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); TEST_ASSERT_EQUAL(dev_addr, pipe_hdl_bulk.dev_addr); TEST_ASSERT_EQUAL(TUSB_XFER_BULK, pipe_hdl_bulk.xfer_type); @@ -148,7 +148,7 @@ void test_bulk_xfer_hs_ping_out(void) { _usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH; - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC); + pipe_handle_t pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC); ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl); //------------- Code Under Test -------------// 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 f48b2c7f4..ff6dfef8f 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 @@ -144,7 +144,7 @@ void check_int_endpoint_link(ehci_qhd_t *p_prev, ehci_qhd_t *p_qhd) void test_open_interrupt_qhd_hs(void) { //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl.xfer_type); @@ -162,7 +162,7 @@ void test_open_interrupt_hs_interval_1(void) int_edp_interval.bInterval = 1; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(0 , p_int_qhd->interval_ms); @@ -177,7 +177,7 @@ void test_open_interrupt_hs_interval_2(void) int_edp_interval.bInterval = 2; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(0 , p_int_qhd->interval_ms); @@ -191,7 +191,7 @@ void test_open_interrupt_hs_interval_3(void) int_edp_interval.bInterval = 3; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(0, p_int_qhd->interval_ms); @@ -205,7 +205,7 @@ void test_open_interrupt_hs_interval_4(void) int_edp_interval.bInterval = 4; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(1, p_int_qhd->interval_ms); @@ -219,7 +219,7 @@ void test_open_interrupt_hs_interval_5(void) int_edp_interval.bInterval = 5; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(2, p_int_qhd->interval_ms); @@ -233,7 +233,7 @@ void test_open_interrupt_hs_interval_6(void) int_edp_interval.bInterval = 6; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(4, p_int_qhd->interval_ms); @@ -247,7 +247,7 @@ void test_open_interrupt_hs_interval_7(void) int_edp_interval.bInterval = 7; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(8, p_int_qhd->interval_ms); @@ -261,7 +261,7 @@ void test_open_interrupt_hs_interval_8(void) int_edp_interval.bInterval = 16; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(255, p_int_qhd->interval_ms); @@ -275,7 +275,7 @@ void test_open_interrupt_qhd_non_hs(void) _usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl.xfer_type); @@ -297,7 +297,7 @@ void test_open_interrupt_qhd_non_hs_9(void) _usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(int_edp_interval.bInterval, p_int_qhd->interval_ms); @@ -310,7 +310,7 @@ void test_open_interrupt_qhd_non_hs_9(void) //--------------------------------------------------------------------+ void test_interrupt_close(void) { - pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); p_int_qhd = qhd_get_from_pipe_handle(pipe_hdl); //------------- Code Under TEST -------------// @@ -328,7 +328,7 @@ void test_interrupt_256ms_close(void) tusb_desc_endpoint_t int_edp_interval = desc_ept_interrupt_out; int_edp_interval.bInterval = 9; - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = qhd_get_from_pipe_handle(pipe_hdl); //------------- Code Under TEST -------------// diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c index b55ec1d9a..d6a5e396c 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c @@ -104,7 +104,7 @@ void setUp(void) period_head_arr = (ehci_qhd_t*) get_period_head( hostid, 1 ); //------------- pipe open -------------// - pipe_hdl_interrupt = hcd_pipe_open(dev_addr, &desc_ept_interrupt_in, TUSB_CLASS_HID); + pipe_hdl_interrupt = hcd_edpt_open(dev_addr, &desc_ept_interrupt_in, TUSB_CLASS_HID); TEST_ASSERT_EQUAL(dev_addr, pipe_hdl_interrupt.dev_addr); TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl_interrupt.xfer_type); @@ -220,7 +220,7 @@ void test_interrupt_xfer_complete_isr_interval_2ms(void) tusb_desc_endpoint_t desc_endpoint_2ms = desc_ept_interrupt_in; desc_endpoint_2ms.bInterval = 5; - pipe_handle_t pipe_hdl_2ms = hcd_pipe_open(dev_addr, &desc_endpoint_2ms, TUSB_CLASS_HID); + pipe_handle_t pipe_hdl_2ms = hcd_edpt_open(dev_addr, &desc_endpoint_2ms, TUSB_CLASS_HID); ehci_qhd_t * p_qhd_2ms = &ehci_data.device[ dev_addr -1].qhd[ pipe_hdl_2ms.index ]; TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_2ms, xfer_data, sizeof(xfer_data), false) ); diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c index 51381381f..92dd2b474 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c @@ -94,6 +94,6 @@ tusb_desc_endpoint_t const desc_ept_iso_in = void test_open_isochronous(void) { - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_iso_in, TUSB_CLASS_AUDIO); + pipe_handle_t pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_iso_in, TUSB_CLASS_AUDIO); TEST_ASSERT_EQUAL(0, pipe_hdl.dev_addr); } diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c b/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c index 59ad54c88..963c344ab 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c @@ -75,7 +75,7 @@ void tearDown(void) // uint16_t length=0; // // // TODO expect get HID report descriptor -// hcd_pipe_open_IgnoreAndReturn( pipe_hdl ); +// hcd_edpt_open_IgnoreAndReturn( pipe_hdl ); // // //------------- Code Under TEST -------------// // TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, p_kbd_interface_desc, &length) ); diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c b/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c index de3581423..49bb26342 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c @@ -146,7 +146,7 @@ void test_keyboard_open_ok(void) usbh_control_xfer_subtask_ExpectAndReturn(dev_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RECIPIENT_INTERFACE), HID_REQ_CONTROL_SET_IDLE, 0, p_kbd_interface_desc->bInterfaceNumber, 0, NULL, TUSB_ERROR_NONE); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_kdb_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_kdb_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); tusbh_hid_keyboard_mounted_cb_Expect(dev_addr); //------------- Code Under TEST -------------// diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c b/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c index 541c2caef..bf71a7438 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c @@ -117,7 +117,7 @@ void test_mouse_open_ok(void) usbh_control_xfer_subtask_ExpectAndReturn(dev_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RECIPIENT_INTERFACE), HID_REQ_CONTROL_SET_IDLE, 0, p_mouse_interface_desc->bInterfaceNumber, 0, NULL, TUSB_ERROR_NONE); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_mouse_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_mouse_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); tusbh_hid_mouse_mounted_cb_Expect(dev_addr); //------------- Code Under TEST -------------// diff --git a/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c b/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c index b89a716c2..abdcbaf1f 100644 --- a/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c +++ b/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c @@ -84,15 +84,15 @@ void tearDown(void) void test_open_pipe_in_failed(void) { - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_null); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_null); TEST_ASSERT(TUSB_ERROR_NONE != msch_open(dev_addr, p_msc_interface_desc, &length)); } void test_open_pipe_out_failed(void) { - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, (pipe_handle_t) {1} ); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_null); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, (pipe_handle_t) {1} ); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_null); TEST_ASSERT(TUSB_ERROR_NONE != msch_open(dev_addr, p_msc_interface_desc, &length)); } @@ -121,8 +121,8 @@ tusb_error_t stub_control_xfer(uint8_t dev_addr, uint8_t bmRequestType, uint8_t #if 0 // TODO TEST enable this void test_open_desc_length(void) { - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_in); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_out); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_in); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_out); usbh_control_xfer_subtask_IgnoreAndReturn(TUSB_ERROR_NONE); hcd_pipe_xfer_IgnoreAndReturn(TUSB_ERROR_NONE); @@ -137,8 +137,8 @@ void test_open_desc_length(void) void test_open_ok(void) { - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_in); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_out); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_in); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_out); //------------- get max lun -------------// usbh_control_xfer_subtask_StubWithCallback(stub_control_xfer); -- cgit v1.3.1 From dbc560658a900525acd11ffcae2e59839d9c6fe5 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 11 Dec 2018 13:15:05 +0700 Subject: more hcd_pipe to hcd_edpt rename --- src/class/cdc/cdc_host.c | 10 +++++----- src/class/hid/hid_host.c | 6 +++--- src/class/msc/msc_host.c | 6 +++--- src/host/ehci/ehci.c | 6 +++--- src/host/hcd.h | 10 ++++++---- src/host/ohci/ohci.c | 6 +++--- tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c | 6 +++--- tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c | 6 +++--- 8 files changed, 29 insertions(+), 27 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index f889c8c90..df07e0683 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -80,13 +80,13 @@ bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) switch (pipeid) { case CDC_PIPE_NOTIFICATION: - return hcd_pipe_is_busy(dev_addr, p_cdc->ep_notif ); + return hcd_edpt_busy(dev_addr, p_cdc->ep_notif ); case CDC_PIPE_DATA_IN: - return hcd_pipe_is_busy(dev_addr, p_cdc->ep_in ); + return hcd_edpt_busy(dev_addr, p_cdc->ep_in ); case CDC_PIPE_DATA_OUT: - return hcd_pipe_is_busy(dev_addr, p_cdc->ep_out ); + return hcd_edpt_busy(dev_addr, p_cdc->ep_out ); default: return false; @@ -110,7 +110,7 @@ bool tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool i TU_VERIFY( p_data != NULL && length, TUSB_ERROR_INVALID_PARA); uint8_t const ep_out = cdch_data[dev_addr-1].ep_out; - if ( hcd_pipe_is_busy(dev_addr, ep_out) ) return false; + if ( hcd_edpt_busy(dev_addr, ep_out) ) return false; return hcd_pipe_xfer(dev_addr, ep_out, (void *) p_data, length, is_notify); } @@ -121,7 +121,7 @@ bool tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is TU_VERIFY( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA); uint8_t const ep_in = cdch_data[dev_addr-1].ep_in; - if ( hcd_pipe_is_busy(dev_addr, ep_in) ) return false; + if ( hcd_edpt_busy(dev_addr, ep_in) ) return false; return hcd_pipe_xfer(dev_addr, ep_in, p_buffer, length, is_notify); } diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 8d7dce70a..aa93f7837 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -78,7 +78,7 @@ tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_int // TODO change to use is configured function TU_ASSERT (TUSB_DEVICE_STATE_CONFIGURED == tuh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY); TU_VERIFY (report, TUSB_ERROR_INVALID_PARA); - TU_ASSERT (!hcd_pipe_is_busy(p_hid->pipe_hdl), TUSB_ERROR_INTERFACE_IS_BUSY); + TU_ASSERT (!hcd_edpt_busy(p_hid->pipe_hdl), TUSB_ERROR_INTERFACE_IS_BUSY); TU_ASSERT_ERR( hcd_pipe_xfer(p_hid->pipe_hdl, report, p_hid->report_size, true) ) ; @@ -118,7 +118,7 @@ tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void* p_report) bool tuh_hid_keyboard_is_busy(uint8_t dev_addr) { return tuh_hid_keyboard_is_mounted(dev_addr) && - hcd_pipe_is_busy( keyboardh_data[dev_addr-1].pipe_hdl ); + hcd_edpt_busy( keyboardh_data[dev_addr-1].pipe_hdl ); } #endif @@ -139,7 +139,7 @@ bool tuh_hid_mouse_is_mounted(uint8_t dev_addr) bool tuh_hid_mouse_is_busy(uint8_t dev_addr) { return tuh_hid_mouse_is_mounted(dev_addr) && - hcd_pipe_is_busy( mouseh_data[dev_addr-1].pipe_hdl ); + hcd_edpt_busy( mouseh_data[dev_addr-1].pipe_hdl ); } tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void * report) diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 8e51debcf..0b1359264 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -76,7 +76,7 @@ bool tuh_msc_is_mounted(uint8_t dev_addr) bool tuh_msc_is_busy(uint8_t dev_addr) { return msch_data[dev_addr-1].is_initialized && - hcd_pipe_is_busy(dev_addr, msch_data[dev_addr-1].ep_in); + hcd_edpt_busy(dev_addr, msch_data[dev_addr-1].ep_in); } uint8_t const* tuh_msc_get_vendor_name(uint8_t dev_addr) @@ -361,7 +361,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it // NOTE: my toshiba thumb-drive stall the first Read Capacity and require the sequence // Read Capacity --> Stalled --> Clear Stall --> Request Sense --> Read Capacity (2) to work - if ( hcd_pipe_is_stalled(dev_addr, p_msc->ep_in) ) + if ( hcd_edpt_stalled(dev_addr, p_msc->ep_in) ) { // clear stall TODO abstract clear stall function request = (tusb_control_request_t) { @@ -374,7 +374,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it TU_ASSERT(usbh_control_xfer( dev_addr, &request, NULL )); - hcd_pipe_clear_stall(dev_addr, p_msc->ep_in); + hcd_edpt_clear_stall(dev_addr, p_msc->ep_in); TU_ASSERT( osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT) ); // wait for SCSI status //------------- SCSI Request Sense -------------// diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index 94796c9dd..3833a46d7 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -420,19 +420,19 @@ bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) return true; } -bool hcd_pipe_is_busy(uint8_t dev_addr, uint8_t ep_addr) +bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr) { ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr); return !p_qhd->qtd_overlay.halted && (p_qhd->p_qtd_list_head != NULL); } -bool hcd_pipe_is_stalled(uint8_t dev_addr, uint8_t ep_addr) +bool hcd_edpt_stalled(uint8_t dev_addr, uint8_t ep_addr) { ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr); return p_qhd->qtd_overlay.halted && !qhd_has_xact_error(p_qhd); } -bool hcd_pipe_clear_stall(uint8_t dev_addr, uint8_t ep_addr) +bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr) { ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr); p_qhd->qtd_overlay.halted = 0; diff --git a/src/host/hcd.h b/src/host/hcd.h index 9b7b99321..257a7da59 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -131,8 +131,14 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]); bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); +bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr); +bool hcd_edpt_stalled(uint8_t dev_addr, uint8_t ep_addr); +bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr); + +// TODO remove bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen); + //--------------------------------------------------------------------+ // PIPE API //--------------------------------------------------------------------+ @@ -141,10 +147,6 @@ 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); bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); // TODO remove -bool hcd_pipe_is_busy(uint8_t dev_addr, uint8_t ep_addr); -bool hcd_pipe_is_stalled(uint8_t dev_addr, uint8_t ep_addr); // stalled also counted as error -bool hcd_pipe_clear_stall(uint8_t dev_addr, uint8_t ep_addr); - #if 0 tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT; #endif diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index 37de86c60..4c54c5eaa 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -583,19 +583,19 @@ tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) return TUSB_ERROR_FAILED; } -bool hcd_pipe_is_busy(pipe_handle_t pipe_hdl) +bool hcd_edpt_busy(pipe_handle_t pipe_hdl) { ohci_ed_t const * const p_ed = ed_from_pipe_handle(pipe_hdl); return tu_align16(p_ed->td_head.address) != tu_align16(p_ed->td_tail.address); } -bool hcd_pipe_is_stalled(pipe_handle_t pipe_hdl) +bool hcd_edpt_stalled(pipe_handle_t pipe_hdl) { ohci_ed_t const * const p_ed = ed_from_pipe_handle(pipe_hdl); return p_ed->td_head.halted && p_ed->is_stalled; } -tusb_error_t hcd_pipe_clear_stall(pipe_handle_t pipe_hdl) +tusb_error_t hcd_edpt_clear_stall(pipe_handle_t pipe_hdl) { ohci_ed_t * const p_ed = ed_from_pipe_handle(pipe_hdl); diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c b/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c index 49bb26342..e5f33574a 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c @@ -187,7 +187,7 @@ void test_keyboard_get_device_not_ready(void) void test_keyboard_get_report_xfer_failed() { tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - hcd_pipe_is_busy_ExpectAndReturn(p_hidh_kbd->pipe_hdl, false); + hcd_edpt_busy_ExpectAndReturn(p_hidh_kbd->pipe_hdl, false); hcd_pipe_xfer_ExpectAndReturn(p_hidh_kbd->pipe_hdl, (uint8_t*) &report, p_hidh_kbd->report_size, true, TUSB_ERROR_INVALID_PARA); //------------- Code Under TEST -------------// @@ -197,7 +197,7 @@ void test_keyboard_get_report_xfer_failed() void test_keyboard_get_report_xfer_failed_busy() { tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - hcd_pipe_is_busy_ExpectAndReturn(p_hidh_kbd->pipe_hdl, true); + hcd_edpt_busy_ExpectAndReturn(p_hidh_kbd->pipe_hdl, true); TEST_ASSERT_EQUAL(TUSB_ERROR_INTERFACE_IS_BUSY, tusbh_hid_keyboard_get_report(dev_addr, &report)); } @@ -206,7 +206,7 @@ void test_keyboard_get_ok() { tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); // TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, tusbh_hid_keyboard_status(dev_addr)); - hcd_pipe_is_busy_ExpectAndReturn(p_hidh_kbd->pipe_hdl, false); + hcd_edpt_busy_ExpectAndReturn(p_hidh_kbd->pipe_hdl, false); hcd_pipe_xfer_ExpectAndReturn(p_hidh_kbd->pipe_hdl, (uint8_t*) &report, p_hidh_kbd->report_size, true, TUSB_ERROR_NONE); //------------- Code Under TEST -------------// diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c b/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c index bf71a7438..9aca982b8 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c @@ -159,7 +159,7 @@ void test_mouse_get_device_not_ready(void) void test_mouse_get_report_xfer_failed() { tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - hcd_pipe_is_busy_ExpectAndReturn(p_hidh_mouse->pipe_hdl, false); + hcd_edpt_busy_ExpectAndReturn(p_hidh_mouse->pipe_hdl, false); hcd_pipe_xfer_ExpectAndReturn(p_hidh_mouse->pipe_hdl, (uint8_t*) &report, p_hidh_mouse->report_size, true, TUSB_ERROR_INVALID_PARA); //------------- Code Under TEST -------------// @@ -169,7 +169,7 @@ void test_mouse_get_report_xfer_failed() void test_mouse_get_report_xfer_failed_busy() { tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - hcd_pipe_is_busy_ExpectAndReturn(p_hidh_mouse->pipe_hdl, true); + hcd_edpt_busy_ExpectAndReturn(p_hidh_mouse->pipe_hdl, true); TEST_ASSERT_EQUAL(TUSB_ERROR_INTERFACE_IS_BUSY, tusbh_hid_mouse_get_report(dev_addr, &report)); } @@ -178,7 +178,7 @@ void test_mouse_get_ok() { tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); // TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, tusbh_hid_mouse_status(dev_addr)); - hcd_pipe_is_busy_ExpectAndReturn(p_hidh_mouse->pipe_hdl, false); + hcd_edpt_busy_ExpectAndReturn(p_hidh_mouse->pipe_hdl, false); hcd_pipe_xfer_ExpectAndReturn(p_hidh_mouse->pipe_hdl, (uint8_t*) &report, p_hidh_mouse->report_size, true, TUSB_ERROR_NONE); //------------- Code Under TEST -------------// -- cgit v1.3.1 From 600fac1845abec7630adda4dc7487f7711a58300 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 11 Dec 2018 16:18:56 +0700 Subject: fix build error with ohci --- src/class/cdc/cdc_host.c | 1 + src/common/tusb_types.h | 4 +- src/host/ohci/ohci.c | 245 +++++++++++++++++------------------------------ src/host/ohci/ohci.h | 28 +++--- src/host/usbh.c | 2 +- 5 files changed, 101 insertions(+), 179 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index df07e0683..53f62d684 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -226,6 +226,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it void cdch_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { + (void) ep_addr; tuh_cdc_xfer_isr( dev_addr, event, 0, xferred_bytes ); } diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index 6ba713084..8be1e87f6 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -392,9 +392,9 @@ static inline uint8_t edpt_number(uint8_t addr) return addr & (~TUSB_DIR_IN_MASK); } -static inline uint8_t edpt_addr(uint8_t num, tusb_dir_t dir) +static inline uint8_t edpt_addr(uint8_t num, uint8_t dir) { - return num | (dir == TUSB_DIR_IN ? TUSB_DIR_IN_MASK : 0); + return num | (dir ? TUSB_DIR_IN_MASK : 0); } //--------------------------------------------------------------------+ diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index 4c54c5eaa..5593cd55d 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -136,7 +136,7 @@ enum { //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ -CFG_TUSB_MEM_SECTION ATTR_ALIGNED(256) STATIC_VAR ohci_data_t ohci_data; +CFG_TUSB_MEM_SECTION ATTR_ALIGNED(256) static ohci_data_t ohci_data; static ohci_ed_t * const p_ed_head[] = { @@ -216,11 +216,11 @@ tusb_speed_t hcd_port_speed_get(uint8_t hostid) return OHCI_REG->rhport_status_bit[0].low_speed_device_attached ? TUSB_SPEED_LOW : TUSB_SPEED_FULL; } -// TODO refractor abtract later -void hcd_port_unplug(uint8_t hostid) +void hcd_device_remove(uint8_t rhport, uint8_t dev_addr) { // TODO OHCI - (void) hostid; + (void) rhport; + (void) dev_addr; } //--------------------------------------------------------------------+ @@ -273,67 +273,6 @@ static void gtd_init(ohci_gtd_t* p_td, void* data_ptr, uint16_t total_bytes) p_td->buffer_end = total_bytes ? (((uint8_t*) data_ptr) + total_bytes-1) : NULL; } - -bool hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) -{ - ohci_ed_t* p_ed = &ohci_data.control[dev_addr].ed; - - ed_init(p_ed, dev_addr, max_packet_size, 0, TUSB_XFER_CONTROL, 0); // TODO binterval of control is ignored - - if ( dev_addr != 0 ) - { // insert to control head - ed_list_insert( p_ed_head[TUSB_XFER_CONTROL], p_ed); - }else - { - p_ed->skip = 0; // addr0 is used as static control head --> only need to clear skip bit - } - - return true; -} - -//bool hcd_pipe_control_xfer(uint8_t dev_addr, tusb_control_request_t const * p_request, uint8_t data[]) -//{ -// ohci_ed_t* const p_ed = &ohci_data.control[dev_addr].ed; -// -// ohci_gtd_t *p_setup = &ohci_data.control[dev_addr].gtd[0]; -// ohci_gtd_t *p_data = p_setup + 1; -// ohci_gtd_t *p_status = p_setup + 2; -// -// //------------- SETUP Phase -------------// -// gtd_init(p_setup, (void*) p_request, 8); -// p_setup->index = dev_addr; -// p_setup->pid = OHCI_PID_SETUP; -// p_setup->data_toggle = BIN8(10); // DATA0 -// p_setup->next_td = (uint32_t) p_data; -// -// //------------- DATA Phase -------------// -// if (p_request->wLength > 0) -// { -// gtd_init(p_data, data, p_request->wLength); -// p_data->index = dev_addr; -// p_data->pid = p_request->bmRequestType_bit.direction ? OHCI_PID_IN : OHCI_PID_OUT; -// p_data->data_toggle = BIN8(11); // DATA1 -// }else -// { -// p_data = p_setup; -// } -// p_data->next_td = (uint32_t) p_status; -// -// //------------- STATUS Phase -------------// -// gtd_init(p_status, NULL, 0); // zero-length data -// p_status->index = dev_addr; -// p_status->pid = p_request->bmRequestType_bit.direction ? OHCI_PID_OUT : OHCI_PID_IN; // reverse direction of data phase -// p_status->data_toggle = BIN8(11); // DATA1 -// p_status->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; -// -// //------------- Attach TDs list to Control Endpoint -------------// -// p_ed->td_head.address = (uint32_t) p_setup; -// -// OHCI_REG->command_status_bit.control_list_filled = 1; -// -// return true; -//} - bool hcd_pipe_control_close(uint8_t dev_addr) { ohci_ed_t* const p_ed = &ohci_data.control[dev_addr].ed; @@ -352,13 +291,6 @@ bool hcd_pipe_control_close(uint8_t dev_addr) return true; } -bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const* ep_desc) -{ - // FIXME control only for now - (void) rhport; - return hcd_pipe_control_open(dev_addr, ep_desc->wMaxPacketSize.size); -} - bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { // FIXME control only for now @@ -373,7 +305,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet (void) rhport; ohci_ed_t* p_ed = &ohci_data.control[dev_addr].ed; - ohci_gtd_t *p_setup = &ohci_data.control[dev_addr].gtd[0]; + ohci_gtd_t *p_setup = &ohci_data.control[dev_addr].gtd; gtd_init(p_setup, (void*) setup_packet, 8); p_setup->index = dev_addr; @@ -400,7 +332,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * if ( epnum == 0 ) { ohci_ed_t* const p_ed = &ohci_data.control[dev_addr].ed; - ohci_gtd_t *p_data = &ohci_data.control[dev_addr].gtd[0]; + ohci_gtd_t *p_data = &ohci_data.control[dev_addr].gtd; gtd_init(p_data, buffer, buflen); @@ -420,27 +352,31 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * //--------------------------------------------------------------------+ // BULK/INT/ISO PIPE API //--------------------------------------------------------------------+ -static inline uint8_t ed_get_index(ohci_ed_t const * const p_ed) ATTR_PURE ATTR_ALWAYS_INLINE; -static inline uint8_t ed_get_index(ohci_ed_t const * const p_ed) +static inline ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr) { - return p_ed - ohci_data.device[p_ed->device_address-1].ed; -} + if ( edpt_number(ep_addr) == 0 ) return &ohci_data.control[dev_addr].ed; -static inline ohci_ed_t * ed_from_pipe_handle(pipe_handle_t pipe_hdl) ATTR_PURE ATTR_ALWAYS_INLINE; -static inline ohci_ed_t * ed_from_pipe_handle(pipe_handle_t pipe_hdl) -{ - return &ohci_data.device[pipe_hdl.dev_addr-1].ed[pipe_hdl.index]; + ohci_ed_t* ed_pool = ohci_data.ed_pool; + + for(uint32_t i=0; iused = 0; // free ED } -pipe_handle_t hcd_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const * p_endpoint_desc, uint8_t class_code) +bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) { - pipe_handle_t const null_handle = { .dev_addr = 0, .xfer_type = 0, .index = 0 }; + (void) rhport; // TODO iso support - TU_ASSERT(p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS, null_handle ); + TU_ASSERT(ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS); //------------- Prepare Queue Head -------------// - ohci_ed_t * const p_ed = ed_find_free(dev_addr); - TU_ASSERT(p_ed, null_handle); + ohci_ed_t * p_ed; - ed_init( p_ed, dev_addr, p_endpoint_desc->wMaxPacketSize.size, p_endpoint_desc->bEndpointAddress, - p_endpoint_desc->bmAttributes.xfer, p_endpoint_desc->bInterval ); - p_ed->td_tail.class_code = class_code; + if ( ep_desc->bEndpointAddress == 0 ) + { + p_ed = &ohci_data.control[dev_addr].ed; + }else + { + p_ed = ed_find_free(); + } + TU_ASSERT(p_ed); - ed_list_insert( p_ed_head[p_endpoint_desc->bmAttributes.xfer], p_ed ); + ed_init( p_ed, dev_addr, ep_desc->wMaxPacketSize.size, ep_desc->bEndpointAddress, + ep_desc->bmAttributes.xfer, ep_desc->bInterval ); - return (pipe_handle_t) + // control of dev0 is used as static async head + if ( dev_addr == 0 ) { - .dev_addr = dev_addr, - .xfer_type = p_endpoint_desc->bmAttributes.xfer, - .index = ed_get_index(p_ed) - }; + p_ed->skip = 0; // only need to clear skip bit + return true; + } + + ed_list_insert( p_ed_head[ep_desc->bmAttributes.xfer], p_ed ); + + return true; } -static ohci_gtd_t * gtd_find_free(uint8_t dev_addr) +static ohci_gtd_t * gtd_find_free(void) { for(uint8_t i=0; i < HCD_MAX_XFER; i++) { - if (!ohci_data.device[dev_addr-1].gtd[i].used) - { - return &ohci_data.device[dev_addr-1].gtd[i]; - } + if ( !ohci_data.gtd_pool[i].used ) return &ohci_data.gtd_pool[i]; } return NULL; @@ -532,72 +474,71 @@ static void td_insert_to_ed(ohci_ed_t* p_ed, ohci_gtd_t * p_gtd) } } -static tusb_error_t pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) +static bool pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) { - ohci_ed_t* const p_ed = ed_from_pipe_handle(pipe_hdl); + ohci_ed_t* const p_ed = ed_from_addr(dev_addr, ep_addr); - if ( !p_ed->is_iso ) - { - ohci_gtd_t * const p_gtd = gtd_find_free(pipe_hdl.dev_addr); - TU_ASSERT(p_gtd, TUSB_ERROR_EHCI_NOT_ENOUGH_QTD); // TODO refractor error code + // not support ISO yet + TU_VERIFY ( !p_ed->is_iso ); - gtd_init(p_gtd, buffer, total_bytes); - p_gtd->index = pipe_hdl.index; - if ( int_on_complete ) p_gtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; + ohci_gtd_t * const p_gtd = gtd_find_free(); + TU_ASSERT(p_gtd); // not enough gtd - td_insert_to_ed(p_ed, p_gtd); - }else - { - TU_ASSERT_ERR(TUSB_ERROR_NOT_SUPPORTED_YET); - } + gtd_init(p_gtd, buffer, total_bytes); + p_gtd->index = p_ed-ohci_data.ed_pool; + + if ( int_on_complete ) p_gtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES; + + td_insert_to_ed(p_ed, p_gtd); - return TUSB_ERROR_NONE; + return true; } -tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) +bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes) { - return pipe_queue_xfer(pipe_hdl, buffer, total_bytes, false); + return pipe_queue_xfer(dev_addr, ep_addr, buffer, total_bytes, false); } -tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) +bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) { (void) int_on_complete; - TU_ASSERT_ERR( pipe_queue_xfer(pipe_hdl, buffer, total_bytes, true) ); + TU_ASSERT( pipe_queue_xfer(dev_addr, ep_addr, buffer, total_bytes, true) ); - tusb_xfer_type_t xfer_type = ed_get_xfer_type( ed_from_pipe_handle(pipe_hdl) ); + tusb_xfer_type_t xfer_type = ed_get_xfer_type( ed_from_addr(dev_addr, ep_addr) ); if (TUSB_XFER_BULK == xfer_type) OHCI_REG->command_status_bit.bulk_list_filled = 1; - return TUSB_ERROR_NONE; + return true; } /// pipe_close should only be called as a part of unmount/safe-remove process // endpoints are tied to an address, which only reclaim after a long delay when enumerating // thus there is no need to make sure ED is not in HC's cahed as it will not for sure -tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) +bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { - ohci_ed_t * const p_ed = ed_from_pipe_handle(pipe_hdl); + (void) rhport; + ohci_ed_t * const p_ed = ed_from_addr(dev_addr, ep_addr); ed_list_remove( p_ed_head[ ed_get_xfer_type(p_ed)], p_ed ); - return TUSB_ERROR_FAILED; + return true; } -bool hcd_edpt_busy(pipe_handle_t pipe_hdl) +bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr) { - ohci_ed_t const * const p_ed = ed_from_pipe_handle(pipe_hdl); + ohci_ed_t const * const p_ed = ed_from_addr(dev_addr, ep_addr); return tu_align16(p_ed->td_head.address) != tu_align16(p_ed->td_tail.address); } -bool hcd_edpt_stalled(pipe_handle_t pipe_hdl) +bool hcd_edpt_stalled(uint8_t dev_addr, uint8_t ep_addr) { - ohci_ed_t const * const p_ed = ed_from_pipe_handle(pipe_hdl); + ohci_ed_t const * const p_ed = ed_from_addr(dev_addr, ep_addr); return p_ed->td_head.halted && p_ed->is_stalled; } -tusb_error_t hcd_edpt_clear_stall(pipe_handle_t pipe_hdl) +bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr) { - ohci_ed_t * const p_ed = ed_from_pipe_handle(pipe_hdl); + ohci_ed_t * const p_ed = ed_from_addr(dev_addr, ep_addr); p_ed->is_stalled = 0; p_ed->td_tail.address &= 0x0Ful; // set tail pointer back to NULL @@ -607,7 +548,7 @@ tusb_error_t hcd_edpt_clear_stall(pipe_handle_t pipe_hdl) if ( TUSB_XFER_BULK == ed_get_xfer_type(p_ed) ) OHCI_REG->command_status_bit.bulk_list_filled = 1; - return TUSB_ERROR_NONE; + return true; } @@ -632,13 +573,11 @@ static ohci_td_item_t* list_reverse(ohci_td_item_t* td_head) return td_reverse_head; } -static inline bool gtd_is_control(ohci_gtd_t const * const p_qtd) ATTR_CONST ATTR_ALWAYS_INLINE; static inline bool gtd_is_control(ohci_gtd_t const * const p_qtd) { - return ((uint32_t) p_qtd) < ((uint32_t) ohci_data.device); // check ohci_data_t for memory layout + return ((uint32_t) p_qtd) < ((uint32_t) ohci_data.gtd_pool); // check ohci_data_t for memory layout } -static inline ohci_ed_t* gtd_get_ed(ohci_gtd_t const * const p_qtd) ATTR_PURE ATTR_ALWAYS_INLINE; static inline ohci_ed_t* gtd_get_ed(ohci_gtd_t const * const p_qtd) { if ( gtd_is_control(p_qtd) ) @@ -646,13 +585,10 @@ static inline ohci_ed_t* gtd_get_ed(ohci_gtd_t const * const p_qtd) return &ohci_data.control[p_qtd->index].ed; }else { - uint8_t dev_addr_idx = (((uint32_t)p_qtd) - ((uint32_t)ohci_data.device)) / sizeof(ohci_data.device[0]); - - return &ohci_data.device[dev_addr_idx].ed[p_qtd->index]; + return &ohci_data.ed_pool[p_qtd->index]; } } -static inline uint32_t gtd_xfer_byte_left(uint32_t buffer_end, uint32_t current_buffer) ATTR_CONST ATTR_ALWAYS_INLINE; static inline uint32_t gtd_xfer_byte_left(uint32_t buffer_end, uint32_t current_buffer) { // 5.2.9 OHCI sample code return (tu_align4k(buffer_end ^ current_buffer) ? 0x1000 : 0) + @@ -663,18 +599,16 @@ static void done_queue_isr(uint8_t hostid) { (void) hostid; - uint8_t max_loop = (CFG_TUSB_HOST_DEVICE_MAX+1)*(HCD_MAX_XFER+OHCI_MAX_ITD); - // done head is written in reversed order of completion --> need to reverse the done queue first ohci_td_item_t* td_head = list_reverse ( (ohci_td_item_t*) tu_align16(ohci_data.hcca.done_head) ); - while( td_head != NULL && max_loop > 0) + while( td_head != NULL ) { // TODO check if td_head is iso td //------------- Non ISO transfer -------------// ohci_gtd_t * const p_qtd = (ohci_gtd_t *) td_head; xfer_result_t const event = (p_qtd->condition_code == OHCI_CCODE_NO_ERROR) ? XFER_RESULT_SUCCESS : - (p_qtd->condition_code == OHCI_CCODE_STALL) ? XFER_RESULT_STALLED : XFER_RESULT_FAILED; + (p_qtd->condition_code == OHCI_CCODE_STALL) ? XFER_RESULT_STALLED : XFER_RESULT_FAILED; p_qtd->used = 0; // free TD if ( (p_qtd->delay_interrupt == OHCI_INT_ON_COMPLETE_YES) || (event != XFER_RESULT_SUCCESS) ) @@ -697,19 +631,12 @@ static void done_queue_isr(uint8_t hostid) if ( event == XFER_RESULT_STALLED ) p_ed->is_stalled = 1; } - pipe_handle_t pipe_hdl = - { - .dev_addr = p_ed->device_address, - .xfer_type = ed_get_xfer_type(p_ed), - }; - - if ( pipe_hdl.xfer_type != TUSB_XFER_CONTROL) pipe_hdl.index = ed_get_index(p_ed); - - hcd_event_xfer_complete(pipe_hdl, p_ed->td_tail.class_code, event, xferred_bytes); + hcd_event_xfer_complete(p_ed->device_address, + edpt_addr(p_ed->endpoint_number, p_ed->direction == OHCI_PID_IN), + event, xferred_bytes); } td_head = (ohci_td_item_t*) td_head->next_td; - max_loop--; } } diff --git a/src/host/ohci/ohci.h b/src/host/ohci/ohci.h index c407b8ac1..f68500703 100644 --- a/src/host/ohci/ohci.h +++ b/src/host/ohci/ohci.h @@ -88,8 +88,9 @@ typedef struct { }ohci_td_item_t; -typedef struct ATTR_ALIGNED(16) { - //------------- Word 0 -------------// +typedef struct ATTR_ALIGNED(16) +{ + // Word 0 uint32_t used : 1; uint32_t index : 4; // endpoint index the td belongs to, or device address in case of control xfer uint32_t expected_bytes : 13; // TODO available for hcd @@ -100,15 +101,14 @@ typedef struct ATTR_ALIGNED(16) { volatile uint32_t data_toggle : 2; volatile uint32_t error_count : 2; volatile uint32_t condition_code : 4; - /*---------- End Word 1 ----------*/ - //------------- Word 1 -------------// + // Word 1 volatile uint8_t* current_buffer_pointer; - //------------- Word 2 -------------// + // Word 2 volatile uint32_t next_td; - //------------- Word 3 -------------// + // Word 3 uint8_t* buffer_end; } ohci_gtd_t; @@ -132,11 +132,7 @@ typedef struct ATTR_ALIGNED(16) { //------------- Word 1 -------------// union { - uint32_t address; // 4 lsb bits are free to use - struct { - uint32_t class_code : 4; // FIXME refractor to use interface number instead - uint32_t : 28; - }; + uint32_t address; }td_tail; //------------- Word 2 -------------// @@ -190,14 +186,12 @@ typedef struct ATTR_ALIGNED(256) { // control endpoints has reserved resources struct { ohci_ed_t ed; - ohci_gtd_t gtd[3]; // setup, data, status + ohci_gtd_t gtd; }control[CFG_TUSB_HOST_DEVICE_MAX+1]; - struct { - // ochi_itd_t itd[OHCI_MAX_ITD]; // itd requires alignment of 32 - ohci_ed_t ed[HCD_MAX_ENDPOINT]; - ohci_gtd_t gtd[HCD_MAX_XFER]; - }device[CFG_TUSB_HOST_DEVICE_MAX]; + // ochi_itd_t itd[OHCI_MAX_ITD]; // itd requires alignment of 32 + ohci_ed_t ed_pool[HCD_MAX_ENDPOINT]; + ohci_gtd_t gtd_pool[HCD_MAX_XFER]; } ohci_data_t; diff --git a/src/host/usbh.c b/src/host/usbh.c index ff4343fd2..456eff531 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -515,7 +515,7 @@ bool enum_task(hcd_event_t* event) new_dev->speed = dev0->speed; new_dev->state = TUSB_DEVICE_STATE_ADDRESSED; - usbh_pipe_control_close(0); + usbh_pipe_control_close(0); // hcd_device_remove(rhport, 0); // close device 0 dev0->state = TUSB_DEVICE_STATE_UNPLUG; // open control pipe for new address -- cgit v1.3.1 From 67d6d753d66ffb821e9cfc4831d44f6b2f8549b8 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 11 Dec 2018 23:57:53 +0700 Subject: replace all hcd pipe close by hcd_device_remove --- src/class/cdc/cdc_host.c | 5 -- src/class/hid/hid_host.c | 1 - src/class/msc/msc_host.c | 3 - src/common/tusb_types.h | 5 -- src/host/ehci/ehci.c | 223 +++++++++++++++++------------------------------ src/host/ehci/ehci.h | 8 +- src/host/hcd.h | 6 +- src/host/hub.c | 2 - src/host/usbh.c | 32 ++----- 9 files changed, 94 insertions(+), 191 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 53f62d684..159a13990 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -233,11 +233,6 @@ void cdch_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t x void cdch_close(uint8_t dev_addr) { cdch_data_t * p_cdc = &cdch_data[dev_addr-1]; - - hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->ep_notif); - hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->ep_in); - hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, p_cdc->ep_out); - tu_memclr(p_cdc, sizeof(cdch_data_t)); } diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index aa93f7837..1e44055ec 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -67,7 +67,6 @@ static inline bool hidh_interface_open(uint8_t dev_addr, uint8_t interface_numbe static inline void hidh_interface_close(hidh_interface_info_t *p_hid) { - (void) hcd_pipe_close(p_hid->pipe_hdl); tu_memclr(p_hid, sizeof(hidh_interface_info_t)); } diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 0b1359264..2c9b2dec7 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -413,9 +413,6 @@ void msch_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t x void msch_close(uint8_t dev_addr) { - (void) hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, msch_data[dev_addr-1].ep_in); - (void) hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, msch_data[dev_addr-1].ep_out); - tu_memclr(&msch_data[dev_addr-1], sizeof(msch_interface_t)); osal_semaphore_reset(msch_sem_hdl); diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index 8be1e87f6..d0a10acef 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -184,11 +184,6 @@ typedef enum TUSB_DEVICE_STATE_ADDRESSED , TUSB_DEVICE_STATE_CONFIGURED , TUSB_DEVICE_STATE_SUSPENDED , - - TUSB_DEVICE_STATE_REMOVING , - TUSB_DEVICE_STATE_SAFE_REMOVE , - - TUSB_DEVICE_STATE_INVALID_PARAMETER }tusb_device_state_t; typedef enum diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index 1b5289333..91a87f9d2 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -113,7 +113,7 @@ static inline ehci_qtd_t* qtd_find_free(uint8_t dev_addr) ATTR_PURE ATTR_ALWAYS static inline ehci_qtd_t* qtd_next(ehci_qtd_t const * p_qtd ) ATTR_PURE ATTR_ALWAYS_INLINE; static inline void qtd_insert_to_qhd(ehci_qhd_t *p_qhd, ehci_qtd_t *p_qtd_new) ATTR_ALWAYS_INLINE; static inline void qtd_remove_1st_from_qhd(ehci_qhd_t *p_qhd) ATTR_ALWAYS_INLINE; -static void qtd_init(ehci_qtd_t* p_qtd, uint32_t data_ptr, uint16_t total_bytes); +static void qtd_init (ehci_qtd_t* p_qtd, void* buffer, uint16_t total_bytes); static inline void list_insert(ehci_link_t *current, ehci_link_t *new, uint8_t new_type) ATTR_ALWAYS_INLINE; static inline ehci_link_t* list_next(ehci_link_t *p_link_pointer) ATTR_PURE ATTR_ALWAYS_INLINE; @@ -149,10 +149,53 @@ tusb_speed_t hcd_port_speed_get(uint8_t hostid) return (tusb_speed_t) ehci_data.regs->portsc_bm.nxp_port_speed; // NXP specific port speed } -// TODO refractor abtract later +static void list_remove_qhd_by_addr(ehci_link_t* list_head, uint8_t dev_addr) +{ + for(ehci_link_t* prev = list_head; + !prev->terminate && (tu_align32(prev->address) != (uint32_t) list_head); + prev = list_next(prev) ) + { + // TODO check type for ISO iTD and siTD + ehci_qhd_t* qhd = (ehci_qhd_t*) list_next(prev); + if ( qhd->dev_addr == dev_addr ) + { + // TODO deactive all TD, wait for QHD to inactive before removal + prev->address = qhd->next.address; + + // EHCI 4.8.2 link the removed qhd to async head (which always reachable by Host Controller) + qhd->next.address = ((uint32_t) list_head) | (EHCI_QTYPE_QHD << 1); + + if ( qhd->int_smask ) + { + // period list queue element is guarantee to be free in the next frame (1 ms) + qhd->used = 0; + }else + { + // async list use async advance handshake + // mark as removing, will completely re-usable when async advance isr occurs + qhd->removing = 1; + } + } + } +} + +// Close all opened endpoint belong to this device void hcd_device_remove(uint8_t rhport, uint8_t dev_addr) { - ehci_data.regs->command_bm.async_adv_doorbell = 1; // Async doorbell check EHCI 4.8.2 for operational details + // skip dev0 + if (dev_addr == 0) return; + + // Remove from async list + list_remove_qhd_by_addr( (ehci_link_t*) qhd_async_head(rhport), dev_addr ); + + // Remove from all interval period list + for(uint8_t i = 0; i < TU_ARRAY_SZIE(ehci_data.period_head_arr); i++) + { + list_remove_qhd_by_addr( (ehci_link_t*) &ehci_data.period_head_arr[i], dev_addr); + } + + // Async doorbell (EHCI 4.8.2 for operational details) + ehci_data.regs->command_bm.async_adv_doorbell = 1; } // EHCI controller init @@ -184,7 +227,6 @@ static bool ehci_init(uint8_t hostid) //------------- Periodic List -------------// // Build the polling interval tree with 1 ms, 2 ms, 4 ms and 8 ms (framesize) only - for(uint32_t i=0; i<4; i++) { ehci_data.period_head_arr[i].int_smask = 1; // queue head in period list must have smask non-zero @@ -252,28 +294,6 @@ static tusb_error_t hcd_controller_stop(uint8_t hostid) //--------------------------------------------------------------------+ // CONTROL PIPE API //--------------------------------------------------------------------+ -bool hcd_pipe_control_close(uint8_t dev_addr) -{ - //------------- TODO pipe handle validate -------------// - ehci_qhd_t* p_qhd = qhd_control(dev_addr); - - p_qhd->removing = 1; - - if (dev_addr != 0) - { - TU_ASSERT( list_remove_qhd( (ehci_link_t*) qhd_async_head( _usbh_devices[dev_addr].rhport ), - (ehci_link_t*) p_qhd) ); - } - - return true; -} - -bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) -{ - // FIXME control only for now - return hcd_pipe_control_close(dev_addr); -} - bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen) { uint8_t const epnum = edpt_number(ep_addr); @@ -285,7 +305,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * ehci_qhd_t* qhd = qhd_control(dev_addr); ehci_qtd_t* qtd = qtd_control(dev_addr); - qtd_init(qtd, (uint32_t) buffer, buflen); + qtd_init(qtd, buffer, buflen); // first first data toggle is always 1 (data & setup stage) qtd->data_toggle = 1; @@ -306,20 +326,20 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]) { - ehci_qhd_t* p_qhd = qhd_control(dev_addr); - ehci_qtd_t* p_setup = qtd_control(dev_addr); + ehci_qhd_t* qhd = &ehci_data.control[dev_addr].qhd; + ehci_qtd_t* td = &ehci_data.control[dev_addr].qtd; - qtd_init(p_setup, (uint32_t) setup_packet, 8); - p_setup->pid = EHCI_PID_SETUP; - p_setup->int_on_complete = 1; - p_setup->next.terminate = 1; + qtd_init(td, setup_packet, 8); + td->pid = EHCI_PID_SETUP; + td->int_on_complete = 1; + td->next.terminate = 1; // sw region - p_qhd->p_qtd_list_head = p_setup; - p_qhd->p_qtd_list_tail = p_setup; + qhd->p_qtd_list_head = td; + qhd->p_qtd_list_tail = td; // attach TD - p_qhd->qtd_overlay.next.address = (uint32_t) p_setup; + qhd->qtd_overlay.next.address = (uint32_t) td; return true; } @@ -384,8 +404,8 @@ bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], ui TU_ASSERT(p_qtd); - qtd_init(p_qtd, (uint32_t) buffer, total_bytes); - p_qtd->pid = p_qhd->pid_non_control; + qtd_init(p_qtd, buffer, total_bytes); + p_qtd->pid = p_qhd->pid; //------------- insert TD to TD list -------------// qtd_insert_to_qhd(p_qhd, p_qtd); @@ -408,31 +428,6 @@ bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t return true; } -/// pipe_close should only be called as a part of unmount/safe-remove process -bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) -{ - ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr); - - // async list needs async advance handshake to make sure host controller has released cached data - // non-control does not use async advance, it will eventually free by control pipe close - // period list queue element is guarantee to be free in the next frame (1 ms) - p_qhd->removing = 1; // TODO redundant, only apply to control queue head - - if ( p_qhd->int_smask == 0 ) - { - // Async list - TU_ASSERT( list_remove_qhd( (ehci_link_t*) qhd_async_head( _usbh_devices[dev_addr].rhport ), - (ehci_link_t*) p_qhd), false ); - } - else - { - TU_ASSERT( list_remove_qhd( get_period_head( _usbh_devices[dev_addr].rhport, p_qhd->interval_ms ), - (ehci_link_t*) p_qhd), false ); - } - - return true; -} - bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr) { ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr); @@ -457,47 +452,20 @@ bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr) // EHCI Interrupt Handler //--------------------------------------------------------------------+ -// async_advance is handshake between sw stack & ehci controller where ehci free all memory from an deleted queue head. -// In tinyusb, queue head is only removed when device is unplugged. So only control queue head is checked if removing -static void async_advance_isr(ehci_qhd_t * const async_head) +// async_advance is handshake between usb stack & ehci controller. +// This isr mean it is safe to modify previously removed queue head from async list. +// In tinyusb, queue head is only removed when device is unplugged. +static void async_advance_isr(uint8_t rhport) { - // TODO do we need to close addr0 - if (async_head->removing) // closing control pipe of addr0 - { - async_head->removing = 0; - async_head->p_qtd_list_head = async_head->p_qtd_list_tail = NULL; - async_head->qtd_overlay.halted = 1; - - _usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG; - } + (void) rhport; - for(uint8_t dev_addr=1; dev_addr < CFG_TUSB_HOST_DEVICE_MAX; dev_addr++) + ehci_qhd_t* qhd_pool = ehci_data.qhd_pool; + for(uint32_t i = 0; i < HCD_MAX_ENDPOINT; i++) { - // check if control endpoint is removing - ehci_qhd_t *p_control_qhd = qhd_control(dev_addr); - - if ( p_control_qhd->removing ) + if ( qhd_pool[i].removing ) { - p_control_qhd->removing = 0; - p_control_qhd->used = 0; - - // Host Controller has cleaned up its cached data for this device, set state to unplug - _usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_UNPLUG; - - for (uint8_t i=0; idev_addr, edpt_addr(p_qhd->ep_number, p_qhd->pid_non_control == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes); + hcd_event_xfer_complete(p_qhd->dev_addr, edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes); p_qhd->total_xferred_bytes = 0; } } @@ -621,7 +589,7 @@ static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd) } // call USBH callback - hcd_event_xfer_complete(p_qhd->dev_addr, edpt_addr(p_qhd->ep_number, p_qhd->pid_non_control == EHCI_PID_IN ? 1 : 0), error_event, p_qhd->total_xferred_bytes); + hcd_event_xfer_complete(p_qhd->dev_addr, edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), error_event, p_qhd->total_xferred_bytes); p_qhd->total_xferred_bytes = 0; } @@ -675,7 +643,7 @@ static void xfer_error_isr(uint8_t hostid) } //------------- Host Controller Driver's Interrupt Handler -------------// -void hal_hcd_isr(uint8_t hostid) +void hal_hcd_isr(uint8_t rhport) { ehci_registers_t* regs = ehci_data.regs; @@ -692,7 +660,7 @@ void hal_hcd_isr(uint8_t hostid) if (regs->portsc_bm.connect_status_change) { - port_connect_status_change_isr(hostid); + port_connect_status_change_isr(rhport); } regs->portsc |= port_status; // Acknowledge change bits in portsc @@ -700,27 +668,27 @@ void hal_hcd_isr(uint8_t hostid) if (int_status & EHCI_INT_MASK_ERROR) { - xfer_error_isr(hostid); + xfer_error_isr(rhport); } //------------- some QTD/SITD/ITD with IOC set is completed -------------// if (int_status & EHCI_INT_MASK_NXP_ASYNC) { - async_list_xfer_complete_isr( qhd_async_head(hostid) ); + async_list_xfer_complete_isr( qhd_async_head(rhport) ); } if (int_status & EHCI_INT_MASK_NXP_PERIODIC) { for (uint8_t i=1; i <= EHCI_FRAMELIST_SIZE; i *= 2) { - period_list_xfer_complete_isr( hostid, i ); + period_list_xfer_complete_isr( rhport, i ); } } //------------- There is some removed async previously -------------// if (int_status & EHCI_INT_MASK_ASYNC_ADVANCE) // need to place after EHCI_INT_MASK_NXP_ASYNC { - async_advance_isr( qhd_async_head(hostid) ); + async_advance_isr(rhport); } } @@ -758,7 +726,7 @@ static inline ehci_qhd_t* qhd_get_from_addr(uint8_t dev_addr, uint8_t ep_addr) for(uint32_t i=0; iremoving = 0; p_qhd->p_qtd_list_head = NULL; p_qhd->p_qtd_list_tail = NULL; - p_qhd->pid_non_control = edpt_dir(ep_desc->bEndpointAddress) ? EHCI_PID_IN : EHCI_PID_OUT; // PID for TD under this endpoint + p_qhd->pid = edpt_dir(ep_desc->bEndpointAddress) ? EHCI_PID_IN : EHCI_PID_OUT; // PID for TD under this endpoint //------------- active, but no TD list -------------// p_qhd->qtd_overlay.halted = 0; p_qhd->qtd_overlay.next.terminate = 1; p_qhd->qtd_overlay.alternate.terminate = 1; - if (TUSB_XFER_BULK == xfer_type && p_qhd->ep_speed == TUSB_SPEED_HIGH && p_qhd->pid_non_control == EHCI_PID_OUT) + if (TUSB_XFER_BULK == xfer_type && p_qhd->ep_speed == TUSB_SPEED_HIGH && p_qhd->pid == EHCI_PID_OUT) { p_qhd->qtd_overlay.ping_err = 1; // do PING for Highspeed Bulk OUT, EHCI section 4.11 } } -static void qtd_init(ehci_qtd_t* p_qtd, uint32_t data_ptr, uint16_t total_bytes) +static void qtd_init(ehci_qtd_t* p_qtd, void* buffer, uint16_t total_bytes) { tu_memclr(p_qtd, sizeof(ehci_qtd_t)); @@ -892,7 +860,7 @@ static void qtd_init(ehci_qtd_t* p_qtd, uint32_t data_ptr, uint16_t total_bytes) p_qtd->total_bytes = total_bytes; p_qtd->expected_bytes = total_bytes; - p_qtd->buffer[0] = data_ptr; + p_qtd->buffer[0] = (uint32_t) buffer; for(uint8_t i=1; i<5; i++) { p_qtd->buffer[i] |= tu_align4k( p_qtd->buffer[i-1] ) + 4096; @@ -911,33 +879,4 @@ static inline ehci_link_t* list_next(ehci_link_t *p_link_pointer) return (ehci_link_t*) tu_align32(p_link_pointer->address); } -static ehci_link_t* list_find_previous_item(ehci_link_t* p_head, ehci_link_t* p_current) -{ - ehci_link_t *p_prev = p_head; - uint32_t max_loop = 0; - while( (tu_align32(p_prev->address) != (uint32_t) p_head) && // not loop around - (tu_align32(p_prev->address) != (uint32_t) p_current) && // not found yet - !p_prev->terminate && // not advanceable - max_loop < HCD_MAX_ENDPOINT) - { - p_prev = list_next(p_prev); - max_loop++; - } - - return (tu_align32(p_prev->address) != (uint32_t) p_head) ? p_prev : NULL; -} - -static bool list_remove_qhd(ehci_link_t* p_head, ehci_link_t* p_remove) -{ - ehci_link_t *p_prev = list_find_previous_item(p_head, p_remove); - - TU_ASSERT(p_prev); - - p_prev->address = p_remove->address; - // EHCI 4.8.2 link the removing queue head to async/period head (which always reachable by Host Controller) - p_remove->address = ((uint32_t) p_head) | (EHCI_QTYPE_QHD << 1); - - return true; -} - #endif diff --git a/src/host/ehci/ehci.h b/src/host/ehci/ehci.h index d0d746706..c1c274793 100644 --- a/src/host/ehci/ehci.h +++ b/src/host/ehci/ehci.h @@ -184,7 +184,7 @@ typedef struct ATTR_ALIGNED(32) //--------------------------------------------------------------------+ uint8_t used; uint8_t removing; // removed from asyn list, waiting for async advance - uint8_t pid_non_control; + uint8_t pid; uint8_t interval_ms; // polling interval in frames (or milisecond) uint16_t total_xferred_bytes; // number of bytes xferred until a qtd with ioc bit set @@ -229,7 +229,8 @@ typedef struct ATTR_ALIGNED(32) { TU_VERIFY_STATIC( sizeof(ehci_itd_t) == 64, "size is not correct" ); /// Split (Full-Speed) Isochronous Transfer Descriptor -typedef struct ATTR_ALIGNED(32) { +typedef struct ATTR_ALIGNED(32) +{ // Word 0: Next Link Pointer ehci_link_t next; @@ -332,7 +333,8 @@ enum ehci_portsc_change_mask_{ EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE }; -typedef volatile struct { +typedef volatile struct +{ union { uint32_t command; diff --git a/src/host/hcd.h b/src/host/hcd.h index 257a7da59..fb0612ed8 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -108,7 +108,7 @@ bool hcd_port_connect_status(uint8_t hostid) ATTR_PURE ATTR_WARN_UNUSED_RESULT; void hcd_port_reset(uint8_t hostid); tusb_speed_t hcd_port_speed_get(uint8_t hostid) ATTR_PURE ATTR_WARN_UNUSED_RESULT; // TODO make inline if possible -// Call by USBH after event device remove +// HCD closs all opened endpoints belong to this device void hcd_device_remove(uint8_t rhport, uint8_t dev_addr); //--------------------------------------------------------------------+ @@ -135,8 +135,7 @@ bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr); bool hcd_edpt_stalled(uint8_t dev_addr, uint8_t ep_addr); bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr); -// TODO remove -bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); + bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen); //--------------------------------------------------------------------+ @@ -145,7 +144,6 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * // TODO control xfer should be used via usbh layer bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes); // only queue, not transferring yet bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete); -bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); // TODO remove #if 0 tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT; diff --git a/src/host/hub.c b/src/host/hub.c index 411e1ae95..e2e91d73d 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -251,9 +251,7 @@ void hub_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xf void hub_close(uint8_t dev_addr) { - hcd_pipe_close(TUH_OPT_RHPORT, dev_addr, hub_data[dev_addr-1].ep_status); tu_memclr(&hub_data[dev_addr-1], sizeof(usbh_hub_t)); - // osal_semaphore_reset(hub_enum_sem_hdl); } diff --git a/src/host/usbh.c b/src/host/usbh.c index 456eff531..31024f1f7 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -118,7 +118,7 @@ static host_class_driver_t const usbh_class_drivers[] = #endif }; -enum { USBH_CLASS_DRIVER_COUNT = sizeof(usbh_class_drivers) / sizeof(host_class_driver_t) }; +enum { USBH_CLASS_DRIVER_COUNT = TU_ARRAY_SZIE(usbh_class_drivers) }; //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION @@ -146,7 +146,7 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, //--------------------------------------------------------------------+ tusb_device_state_t tuh_device_get_state (uint8_t const dev_addr) { - TU_ASSERT( dev_addr <= CFG_TUSB_HOST_DEVICE_MAX, TUSB_DEVICE_STATE_INVALID_PARAMETER); + TU_ASSERT( dev_addr <= CFG_TUSB_HOST_DEVICE_MAX, TUSB_DEVICE_STATE_UNPLUG); return (tusb_device_state_t) _usbh_devices[dev_addr].state; } @@ -241,13 +241,6 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) return TUSB_ERROR_NONE; } -static inline tusb_error_t usbh_pipe_control_close(uint8_t dev_addr) -{ - hcd_edpt_close(_usbh_devices[dev_addr].rhport, dev_addr, 0); - - return TUSB_ERROR_NONE; -} - //--------------------------------------------------------------------+ // USBH-HCD ISR/Callback API //--------------------------------------------------------------------+ @@ -321,13 +314,12 @@ void hcd_event_device_remove(uint8_t hostid) // return true if found and unmounted device, false if cannot find static void usbh_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t hub_port) { - bool is_found = false; - //------------- find the all devices (star-network) under port that is unplugged -------------// for (uint8_t dev_addr = 0; dev_addr <= CFG_TUSB_HOST_DEVICE_MAX; dev_addr ++) { usbh_device_t* dev = &_usbh_devices[dev_addr]; + // TODO Hub multiple level if (dev->rhport == rhport && (hub_addr == 0 || dev->hub_addr == hub_addr) && // hub_addr == 0 & hub_port == 0 means roothub (hub_port == 0 || dev->hub_port == hub_port) && @@ -336,29 +328,17 @@ static void usbh_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t hub_ // Invoke callback before close driver if (tuh_umount_cb) tuh_umount_cb(dev_addr); - // TODO Hub multiple level // Close class driver for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++) usbh_class_drivers[drv_id].close(dev_addr); - // TODO refractor - // set to REMOVING to allow HCD to clean up its cached data for this device - // HCD must set this device's state to TUSB_DEVICE_STATE_UNPLUG when done - dev->state = TUSB_DEVICE_STATE_REMOVING; - memset(dev->itf2drv, 0xff, sizeof(dev->itf2drv)); // invalid mapping memset(dev->ep2drv , 0xff, sizeof(dev->ep2drv )); // invalid mapping - usbh_pipe_control_close(dev_addr); - -// hcd_device_remove(rhport, dev_addr); + hcd_device_remove(rhport, dev_addr); - is_found = true; + dev->state = TUSB_DEVICE_STATE_UNPLUG; } } - - // FIXME remove - if (is_found) hcd_device_remove(_usbh_devices[0].rhport, 0); - } //--------------------------------------------------------------------+ @@ -515,7 +495,7 @@ bool enum_task(hcd_event_t* event) new_dev->speed = dev0->speed; new_dev->state = TUSB_DEVICE_STATE_ADDRESSED; - usbh_pipe_control_close(0); // hcd_device_remove(rhport, 0); // close device 0 + hcd_device_remove(dev0->rhport, 0); // close device 0 dev0->state = TUSB_DEVICE_STATE_UNPLUG; // open control pipe for new address -- cgit v1.3.1 From 6d86db3977aa60963d78d1bceaa7e3def60f1957 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 12 Dec 2018 11:51:31 +0700 Subject: rename edpt_dir/number/addr to tu_edpt_* --- docs/porting.md | 6 +++--- examples/host/cdc_msc_hid/src/tusb_config.h | 2 +- src/class/cdc/cdc_device.h | 2 +- src/class/cdc/cdc_host.c | 2 +- src/class/custom/custom_device.c | 2 +- src/class/custom/custom_device.h | 2 +- src/class/hid/hid_device.c | 2 +- src/class/hid/hid_device.h | 2 +- src/class/msc/msc_device.h | 2 +- src/class/msc/msc_host.c | 2 +- src/common/tusb_types.h | 6 +++--- src/device/usbd.c | 10 ++++----- src/host/ehci/ehci.c | 30 +++++++++++--------------- src/host/ohci/ohci.c | 10 ++++----- src/host/usbh.c | 10 ++++----- src/portable/microchip/samd21/dcd_samd21.c | 24 ++++++++++----------- src/portable/microchip/samd51/dcd_samd51.c | 24 ++++++++++----------- src/portable/nordic/nrf5x/dcd_nrf5x.c | 22 +++++++++---------- src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c | 6 +++--- src/portable/nxp/lpc17_40/dcd_lpc17_40.c | 8 +++---- src/portable/nxp/lpc18_43/dcd_lpc18_43.c | 24 ++++++++++----------- src/portable/nxp/lpc18_43/hcd_lpc18_43.c | 7 ++++++ tests/support/tusb_config.h | 2 +- 23 files changed, 104 insertions(+), 103 deletions(-) (limited to 'src/class/cdc') diff --git a/docs/porting.md b/docs/porting.md index 5a464fa6b..040112d9c 100644 --- a/docs/porting.md +++ b/docs/porting.md @@ -113,10 +113,10 @@ As before with `dcd_event_bus_signal` the first argument is the USB peripheral n Endpoints are the core of the USB data transfer process. They come in a few forms such as control, isochronous, bulk, and interrupt. We won't cover the details here except with some caveats in open below. In general, data is transferred by setting up a buffer of a given length to be transferred on a given endpoint address and then waiting for an interrupt to signal that the transfer is finished. Further details below. -Endpoints within USB have an address which encodes both the number and direction of an endpoint. TinyUSB provides `edpt_number` and `edpt_dir` to unpack this data from the address. Here is a snippet that does it. +Endpoints within USB have an address which encodes both the number and direction of an endpoint. TinyUSB provides `tu_edpt_number` and `tu_edpt_dir` to unpack this data from the address. Here is a snippet that does it. - uint8_t epnum = edpt_number(ep_addr); - uint8_t dir = edpt_dir(ep_addr); + uint8_t epnum = tu_edpt_number(ep_addr); + uint8_t dir = tu_edpt_dir(ep_addr); ##### dcd_edpt_open diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index 07764fa90..cc06ae93d 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -84,7 +84,7 @@ #define CFG_TUH_CDC 1 #define CFG_TUH_HID_KEYBOARD 0 #define CFG_TUH_HID_MOUSE 0 -#define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) +#define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) #define CFG_TUH_MSC 0 #define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 0a17aa916..9dd837d7d 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -116,7 +116,7 @@ void cdcd_init (void); tusb_error_t cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool cdcd_control_request (uint8_t rhport, tusb_control_request_t const * p_request); bool cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes); +tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); void cdcd_reset (uint8_t rhport); #endif diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 159a13990..d660cc39f 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -196,7 +196,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); - if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) + if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { p_cdc->ep_in = ep_desc->bEndpointAddress; }else diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index 194963c17..5abffacf6 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -94,7 +94,7 @@ bool cusd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque return false; } -tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes) +tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { return TUSB_ERROR_NONE; } diff --git a/src/class/custom/custom_device.h b/src/class/custom/custom_device.h index 0a8f05e7d..f223a4d3c 100644 --- a/src/class/custom/custom_device.h +++ b/src/class/custom/custom_device.h @@ -66,7 +66,7 @@ void cusd_init(void); tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request); bool cusd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes); +tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void cusd_reset(uint8_t rhport); #endif diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 6e2ea27db..fa76ee015 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -510,7 +510,7 @@ bool hidd_control_request_complete(uint8_t rhport, tusb_control_request_t const return true; } -tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes) +tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { // nothing to do return TUSB_ERROR_NONE; diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 7aff7f34d..42c61a47b 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -380,7 +380,7 @@ void hidd_init(void); tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool hidd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes); +tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void hidd_reset(uint8_t rhport); #endif diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index 4053679b8..55bfba83c 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -174,7 +174,7 @@ void mscd_init(void); tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool mscd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes); +tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void mscd_reset(uint8_t rhport); #endif diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 2c9b2dec7..dd771440d 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -309,7 +309,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); - if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) + if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { p_msc->ep_in = ep_desc->bEndpointAddress; }else diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index d0a10acef..cbddd4156 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -376,18 +376,18 @@ static inline uint8_t bm_request_type(uint8_t direction, uint8_t type, uint8_t r //--------------------------------------------------------------------+ // Get direction from Endpoint address -static inline tusb_dir_t edpt_dir(uint8_t addr) +static inline tusb_dir_t tu_edpt_dir(uint8_t addr) { return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT; } // Get Endpoint number from address -static inline uint8_t edpt_number(uint8_t addr) +static inline uint8_t tu_edpt_number(uint8_t addr) { return addr & (~TUSB_DIR_IN_MASK); } -static inline uint8_t edpt_addr(uint8_t num, uint8_t dir) +static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir) { return num | (dir ? TUSB_DIR_IN_MASK : 0); } diff --git a/src/device/usbd.c b/src/device/usbd.c index ad40e3c9f..b63dcb131 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -246,14 +246,14 @@ static void usbd_task_body(void) // Invoke the class callback associated with the endpoint address uint8_t const ep_addr = event.xfer_complete.ep_addr; - if ( 0 == edpt_number(ep_addr) ) + if ( 0 == tu_edpt_number(ep_addr) ) { // control transfer DATA stage callback usbd_control_xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); } else { - uint8_t const drv_id = _usbd_dev.ep2drv[edpt_number(ep_addr)][edpt_dir(ep_addr)]; + uint8_t const drv_id = _usbd_dev.ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)]; TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT,); usbd_class_drivers[drv_id].xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); @@ -484,7 +484,7 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, { uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress; - ep2drv[edpt_number(ep_addr)][edpt_dir(ep_addr)] = driver_id; + ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)] = driver_id; } len += descriptor_len(p_desc); @@ -576,7 +576,7 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) case DCD_EVENT_XFER_COMPLETE: // skip zero-length control status complete event, should dcd notifies us. - if ( 0 == edpt_number(event->xfer_complete.ep_addr) && event->xfer_complete.len == 0) break; + if ( 0 == tu_edpt_number(event->xfer_complete.ep_addr) && event->xfer_complete.len == 0) break; osal_queue_send(_usbd_q, event, in_isr); TU_ASSERT(event->xfer_complete.result == XFER_RESULT_SUCCESS,); @@ -633,7 +633,7 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* ep_ TU_ASSERT( dcd_edpt_open(rhport, ep_desc), TUSB_ERROR_DCD_OPEN_PIPE_FAILED ); - if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) + if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { (*ep_in) = ep_desc->bEndpointAddress; }else diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index ef5510a6d..278765585 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -48,9 +48,6 @@ #include "../usbh_hcd.h" #include "ehci.h" -// TODO remove -#include "chip.h" - //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ @@ -61,13 +58,8 @@ // Periodic frame list must be 4K alignment CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4096) static ehci_data_t ehci_data; -//------------- Validation -------------// -// TODO static assert for memory placement on some known MCU such as lpc43xx - -uint32_t hcd_ehci_register_addr(uint8_t rhport) -{ - return (uint32_t) (rhport ? &LPC_USB1->USBCMD_H : &LPC_USB0->USBCMD_H ); -} +// EHCI portable +uint32_t hcd_ehci_register_addr(uint8_t rhport); //--------------------------------------------------------------------+ // PROTOTYPE @@ -279,7 +271,8 @@ static bool ehci_init(uint8_t hostid) return true; } -static void hcd_controller_stop(uint8_t rhport) +#if 0 +static void ehci_stop(uint8_t rhport) { (void) rhport; @@ -290,6 +283,7 @@ static void hcd_controller_stop(uint8_t rhport) // USB Spec: controller has to stop within 16 uframe = 2 frames while( regs->status_bm.hc_halted == 0 ) {} } +#endif //--------------------------------------------------------------------+ // CONTROL PIPE API @@ -298,8 +292,8 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); // FIXME control only for now if ( epnum == 0 ) @@ -505,7 +499,7 @@ static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd) { // end of request // call USBH callback - hcd_event_xfer_complete(p_qhd->dev_addr, edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes); + hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes); p_qhd->total_xferred_bytes = 0; } } @@ -592,7 +586,7 @@ static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd) } // call USBH callback - hcd_event_xfer_complete(p_qhd->dev_addr, edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), error_event, p_qhd->total_xferred_bytes); + hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), error_event, p_qhd->total_xferred_bytes); p_qhd->total_xferred_bytes = 0; } @@ -718,7 +712,7 @@ static inline ehci_qhd_t* qhd_get_from_addr(uint8_t dev_addr, uint8_t ep_addr) for(uint32_t i=0; idev_addr = dev_addr; p_qhd->fl_inactive_next_xact = 0; - p_qhd->ep_number = edpt_number(ep_desc->bEndpointAddress); + p_qhd->ep_number = tu_edpt_number(ep_desc->bEndpointAddress); p_qhd->ep_speed = _usbh_devices[dev_addr].speed; p_qhd->data_toggle_control= (xfer_type == TUSB_XFER_CONTROL) ? 1 : 0; p_qhd->head_list_flag = (dev_addr == 0) ? 1 : 0; // addr0's endpoint is the static asyn list head @@ -826,7 +820,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c p_qhd->removing = 0; p_qhd->p_qtd_list_head = NULL; p_qhd->p_qtd_list_tail = NULL; - p_qhd->pid = edpt_dir(ep_desc->bEndpointAddress) ? EHCI_PID_IN : EHCI_PID_OUT; // PID for TD under this endpoint + p_qhd->pid = tu_edpt_dir(ep_desc->bEndpointAddress) ? EHCI_PID_IN : EHCI_PID_OUT; // PID for TD under this endpoint //------------- active, but no TD list -------------// p_qhd->qtd_overlay.halted = 0; diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index c35eaa77b..bebb8a2ef 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -315,8 +315,8 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); // FIXME control only for now if ( epnum == 0 ) @@ -344,14 +344,14 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * //--------------------------------------------------------------------+ static inline ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr) { - if ( edpt_number(ep_addr) == 0 ) return &ohci_data.control[dev_addr].ed; + if ( tu_edpt_number(ep_addr) == 0 ) return &ohci_data.control[dev_addr].ed; ohci_ed_t* ed_pool = ohci_data.ed_pool; for(uint32_t i=0; idev_addr, - edpt_addr(p_ed->ep_number, p_ed->pid == OHCI_PID_IN), + tu_edpt_addr(p_ed->ep_number, p_ed->pid == OHCI_PID_IN), event, xferred_bytes); } diff --git a/src/host/usbh.c b/src/host/usbh.c index 962dc04dc..369ddd2a5 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -205,12 +205,12 @@ bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8 // Data stage : first data toggle is always 1 if ( request->wLength ) { - hcd_edpt_xfer(rhport, dev_addr, edpt_addr(0, request->bmRequestType_bit.direction), data, request->wLength); + hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, request->bmRequestType_bit.direction), data, request->wLength); TU_VERIFY(osal_semaphore_wait(dev->control.sem_hdl, OSAL_TIMEOUT_NORMAL)); } // Status : data toggle is always 1 - hcd_edpt_xfer(rhport, dev_addr, edpt_addr(0, 1-request->bmRequestType_bit.direction), NULL, 0); + hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, 1-request->bmRequestType_bit.direction), NULL, 0); TU_VERIFY(osal_semaphore_wait(dev->control.sem_hdl, OSAL_TIMEOUT_NORMAL)); osal_mutex_unlock(dev->control.mutex_hdl); @@ -249,7 +249,7 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev { usbh_device_t* dev = &_usbh_devices[ dev_addr ]; - if (0 == edpt_number(ep_addr)) + if (0 == tu_edpt_number(ep_addr)) { dev->control.pipe_status = event; // usbh_devices[ pipe_hdl.dev_addr ].control.xferred_bytes = xferred_bytes; not yet neccessary @@ -257,7 +257,7 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev } else { - uint8_t drv_id = dev->ep2drv[edpt_number(ep_addr)][edpt_dir(ep_addr)]; + uint8_t drv_id = dev->ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)]; TU_ASSERT(drv_id < USBH_CLASS_DRIVER_COUNT, ); if (usbh_class_drivers[drv_id].isr) @@ -689,7 +689,7 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, { uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress; - ep2drv[ edpt_number(ep_addr) ][ edpt_dir(ep_addr) ] = driver_id; + ep2drv[ tu_edpt_number(ep_addr) ][ tu_edpt_dir(ep_addr) ] = driver_id; } len += descriptor_len(p_desc); diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c index 57c4c4d9d..af0721ec3 100644 --- a/src/portable/microchip/samd21/dcd_samd21.c +++ b/src/portable/microchip/samd21/dcd_samd21.c @@ -132,8 +132,8 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt) { (void) rhport; - uint8_t const epnum = edpt_number(desc_edpt->bEndpointAddress); - uint8_t const dir = edpt_dir(desc_edpt->bEndpointAddress); + uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress); + uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress); UsbDeviceDescBank* bank = &sram_registers[epnum][dir]; uint32_t size_value = 0; @@ -168,8 +168,8 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); UsbDeviceDescBank* bank = &sram_registers[epnum][dir]; UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; @@ -208,19 +208,19 @@ bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr) return false; } - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - return (edpt_dir(ep_addr) == TUSB_DIR_IN ) ? ep->EPINTFLAG.bit.STALL1 : ep->EPINTFLAG.bit.STALL0; + return (tu_edpt_dir(ep_addr) == TUSB_DIR_IN ) ? ep->EPINTFLAG.bit.STALL1 : ep->EPINTFLAG.bit.STALL0; } void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1; } else { ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0; @@ -236,10 +236,10 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { ep->EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1; } else { ep->EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ0; @@ -253,10 +253,10 @@ bool dcd_edpt_busy (uint8_t rhport, uint8_t ep_addr) // USBD shouldn't check control endpoint state if ( 0 == ep_addr ) return false; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { return ep->EPINTFLAG.bit.TRCPT1 == 0 && ep->EPSTATUS.bit.BK1RDY == 1; } return ep->EPINTFLAG.bit.TRCPT0 == 0 && ep->EPSTATUS.bit.BK0RDY == 1; diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c index ba53d5598..ce66b8245 100644 --- a/src/portable/microchip/samd51/dcd_samd51.c +++ b/src/portable/microchip/samd51/dcd_samd51.c @@ -137,8 +137,8 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt) { (void) rhport; - uint8_t const epnum = edpt_number(desc_edpt->bEndpointAddress); - uint8_t const dir = edpt_dir(desc_edpt->bEndpointAddress); + uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress); + uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress); UsbDeviceDescBank* bank = &sram_registers[epnum][dir]; uint32_t size_value = 0; @@ -173,8 +173,8 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); UsbDeviceDescBank* bank = &sram_registers[epnum][dir]; UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; @@ -212,19 +212,19 @@ bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr) return false; } - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - return (edpt_dir(ep_addr) == TUSB_DIR_IN ) ? ep->EPINTFLAG.bit.STALL1 : ep->EPINTFLAG.bit.STALL0; + return (tu_edpt_dir(ep_addr) == TUSB_DIR_IN ) ? ep->EPINTFLAG.bit.STALL1 : ep->EPINTFLAG.bit.STALL0; } void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1; } else { ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0; @@ -240,10 +240,10 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { ep->EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1; } else { ep->EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ0; @@ -257,10 +257,10 @@ bool dcd_edpt_busy (uint8_t rhport, uint8_t ep_addr) // USBD shouldn't check control endpoint state if ( 0 == ep_addr ) return false; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { return ep->EPINTFLAG.bit.TRCPT1 == 0 && ep->EPSTATUS.bit.BK1RDY == 1; } return ep->EPINTFLAG.bit.TRCPT0 == 0 && ep->EPSTATUS.bit.BK0RDY == 1; diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index c7a4f413f..ad5090eb0 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -225,8 +225,8 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt) { (void) rhport; - uint8_t const epnum = edpt_number(desc_edpt->bEndpointAddress); - uint8_t const dir = edpt_dir(desc_edpt->bEndpointAddress); + uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress); + uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress); _dcd.xfer[epnum][dir].mps = desc_edpt->wMaxPacketSize.size; @@ -248,8 +248,8 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); xfer_td_t* xfer = get_td(epnum, dir); @@ -295,15 +295,15 @@ bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr) // control is never got halted if ( ep_addr == 0 ) return false; - uint8_t const epnum = edpt_number(ep_addr); - return (edpt_dir(ep_addr) == TUSB_DIR_IN ) ? NRF_USBD->HALTED.EPIN[epnum] : NRF_USBD->HALTED.EPOUT[epnum]; + uint8_t const epnum = tu_edpt_number(ep_addr); + return (tu_edpt_dir(ep_addr) == TUSB_DIR_IN ) ? NRF_USBD->HALTED.EPIN[epnum] : NRF_USBD->HALTED.EPOUT[epnum]; } void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - if ( edpt_number(ep_addr) == 0 ) + if ( tu_edpt_number(ep_addr) == 0 ) { NRF_USBD->TASKS_EP0STALL = 1; }else @@ -318,7 +318,7 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - if ( edpt_number(ep_addr) ) + if ( tu_edpt_number(ep_addr) ) { NRF_USBD->EPSTALL = (USBD_EPSTALL_STALL_UnStall << USBD_EPSTALL_STALL_Pos) | ep_addr; __ISB(); __DSB(); @@ -330,10 +330,10 @@ bool dcd_edpt_busy (uint8_t rhport, uint8_t ep_addr) (void) rhport; // USBD shouldn't check control endpoint state - if ( 0 == edpt_number(ep_addr) ) return false; + if ( 0 == tu_edpt_number(ep_addr) ) return false; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); xfer_td_t* xfer = get_td(epnum, dir); 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 aa7f5e7e6..c910bf1ec 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 @@ -189,7 +189,7 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) { (void) rhport; - if ( edpt_number(ep_addr) == 0 ) + if ( tu_edpt_number(ep_addr) == 0 ) { // TODO cannot able to STALL Control OUT endpoint !!!!! FIXME try some walk-around _dcd.ep[0][0].stall = _dcd.ep[1][0].stall = 1; @@ -209,11 +209,11 @@ bool dcd_edpt_stalled(uint8_t rhport, uint8_t ep_addr) return _dcd.ep[ep_id][0].stall; } -void dcd_edpt_clear_stall(uint8_t rhport, uint8_t edpt_addr) +void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) { (void) rhport; - uint8_t const ep_id = ep_addr2id(edpt_addr); + uint8_t const ep_id = ep_addr2id(ep_addr); _dcd.ep[ep_id][0].stall = 0; _dcd.ep[ep_id][0].toggle_reset = 1; diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index 84eb0c121..82d3c3cac 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -285,7 +285,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) { (void) rhport; - uint8_t const epnum = edpt_number(p_endpoint_desc->bEndpointAddress); + uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress); uint8_t const ep_id = ep_addr2idx(p_endpoint_desc->bEndpointAddress); // Endpoint type is fixed to endpoint number @@ -336,7 +336,7 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) { (void) rhport; - if ( edpt_number(ep_addr) == 0 ) + if ( tu_edpt_number(ep_addr) == 0 ) { sie_write(SIE_CMDCODE_ENDPOINT_SET_STATUS+0, 1, SIE_SET_ENDPOINT_STALLED_MASK | SIE_SET_ENDPOINT_CONDITION_STALLED_MASK); }else @@ -394,9 +394,9 @@ static bool control_xact(uint8_t rhport, uint8_t dir, uint8_t * buffer, uint8_t bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes) { // Control transfer is not DMA support, and must be done in slave mode - if ( edpt_number(ep_addr) == 0 ) + if ( tu_edpt_number(ep_addr) == 0 ) { - return control_xact(rhport, edpt_dir(ep_addr), buffer, (uint8_t) total_bytes); + return control_xact(rhport, tu_edpt_dir(ep_addr), buffer, (uint8_t) total_bytes); } else { diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c index d524d9dea..70b34d848 100644 --- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c @@ -205,8 +205,8 @@ static void qtd_init(dcd_qtd_t* p_qtd, void * data_ptr, uint16_t total_bytes) //--------------------------------------------------------------------+ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) { - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); if ( epnum == 0) { @@ -220,16 +220,16 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr) { - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); return LPC_USB[rhport]->ENDPTCTRL[epnum] & (ENDPTCTRL_MASK_STALL << (dir ? 16 : 0)); } void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) { - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); // data toggle also need to be reset LPC_USB[rhport]->ENDPTCTRL[epnum] |= ENDPTCTRL_MASK_TOGGLE_RESET << ( dir ? 16 : 0 ); @@ -241,8 +241,8 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) // TODO not support ISO yet TU_VERIFY ( p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS); - uint8_t const epnum = edpt_number(p_endpoint_desc->bEndpointAddress); - uint8_t const dir = edpt_dir(p_endpoint_desc->bEndpointAddress); + uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress); + uint8_t const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress); uint8_t const ep_idx = 2*epnum + dir; // USB0 has 5, USB1 has 3 non-control endpoints @@ -264,8 +264,8 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) bool dcd_edpt_busy(uint8_t rhport, uint8_t ep_addr) { - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); uint8_t const ep_idx = 2*epnum + dir; dcd_qtd_t * p_qtd = &dcd_data_ptr[rhport]->qtd[ep_idx]; @@ -276,8 +276,8 @@ bool dcd_edpt_busy(uint8_t rhport, uint8_t ep_addr) bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes) { - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); uint8_t const ep_idx = 2*epnum + dir; if ( epnum == 0 ) diff --git a/src/portable/nxp/lpc18_43/hcd_lpc18_43.c b/src/portable/nxp/lpc18_43/hcd_lpc18_43.c index efdf8fea4..092030056 100644 --- a/src/portable/nxp/lpc18_43/hcd_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/hcd_lpc18_43.c @@ -42,6 +42,8 @@ #include "chip.h" +// LPC18xx and 43xx use EHCI driver + void hcd_int_enable(uint8_t rhport) { NVIC_EnableIRQ(rhport ? USB1_IRQn : USB0_IRQn); @@ -52,4 +54,9 @@ void hcd_int_disable(uint8_t rhport) NVIC_DisableIRQ(rhport ? USB1_IRQn : USB0_IRQn); } +uint32_t hcd_ehci_register_addr(uint8_t rhport) +{ + return (uint32_t) (rhport ? &LPC_USB1->USBCMD_H : &LPC_USB0->USBCMD_H ); +} + #endif diff --git a/tests/support/tusb_config.h b/tests/support/tusb_config.h index 4ff3965e1..fe3d59ef1 100644 --- a/tests/support/tusb_config.h +++ b/tests/support/tusb_config.h @@ -55,7 +55,7 @@ #define CFG_TUSB_HOST_DEVICE_MAX 5 // TODO be a part of HUB config //------------- CLASS -------------// -#define CFG_TUH_HUB 0 +#define CFG_TUH_HUB 1 #define CFG_TUH_HID_KEYBOARD 1 #define CFG_TUH_HID_MOUSE 1 #define CFG_TUH_MSC 1 -- cgit v1.3.1 From 6c0b0917e15ca0acf7ce9bed0f3735a794abb807 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 12 Dec 2018 12:01:15 +0700 Subject: rename descriptor_* helper to tu_desc_* --- src/class/cdc/cdc_device.c | 18 +++++++++--------- src/class/cdc/cdc_host.c | 10 +++++----- src/class/custom/custom_device.c | 2 +- src/class/custom/custom_host.c | 4 ++-- src/class/msc/msc_device.c | 10 +++++----- src/class/msc/msc_host.c | 4 ++-- src/common/tusb_types.h | 13 +++++++------ src/device/usbd.c | 14 +++++++------- src/host/hub.c | 8 ++++---- src/host/usbh.c | 14 +++++++------- 10 files changed, 49 insertions(+), 48 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index d477a0d23..a865ba3c5 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -229,13 +229,13 @@ void cdcd_reset(uint8_t rhport) } } -tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length) +tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length) { - if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != p_interface_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS; + if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != itf_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS; // Only support AT commands, no protocol and vendor specific commands. - if ( !(tu_within(CDC_COMM_PROTOCOL_NONE, p_interface_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) || - p_interface_desc->bInterfaceProtocol == 0xff ) ) + if ( !(tu_within(CDC_COMM_PROTOCOL_NONE, itf_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) || + itf_desc->bInterfaceProtocol == 0xff ) ) { return TUSB_ERROR_CDC_UNSUPPORTED_PROTOCOL; } @@ -252,16 +252,16 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface } //------------- Control Interface -------------// - p_cdc->itf_num = p_interface_desc->bInterfaceNumber; + p_cdc->itf_num = itf_desc->bInterfaceNumber; - uint8_t const * p_desc = descriptor_next ( (uint8_t const *) p_interface_desc ); + uint8_t const * p_desc = tu_desc_next( itf_desc ); (*p_length) = sizeof(tusb_desc_interface_t); // Communication Functional Descriptors while( TUSB_DESC_CLASS_SPECIFIC == p_desc[DESC_OFFSET_TYPE] ) { (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE]) @@ -271,7 +271,7 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface p_cdc->ep_notif = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress; (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } //------------- Data Interface (if any) -------------// @@ -280,7 +280,7 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface { // next to endpoint descritpor (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); // Open endpoint pair with usbd helper tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) p_desc; diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index d660cc39f..d6767d0a7 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -146,7 +146,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it uint8_t const * p_desc; cdch_data_t * p_cdc; - p_desc = descriptor_next ( (uint8_t const *) itf_desc ); + p_desc = tu_desc_next(itf_desc); p_cdc = &cdch_data[dev_addr-1]; p_cdc->itf_num = itf_desc->bInterfaceNumber; @@ -165,7 +165,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it } (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE]) @@ -177,7 +177,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it p_cdc->ep_notif = ep_desc->bEndpointAddress; (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } //------------- Data Interface (if any) -------------// @@ -185,7 +185,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it (TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) ) { (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); // data endpoints expected to be in pairs for(uint32_t i=0; i<2; i++) @@ -205,7 +205,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it } (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next( p_desc ); + p_desc = tu_desc_next( p_desc ); } } diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index 5abffacf6..bec6f42d1 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -76,7 +76,7 @@ tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, cusd_interface_t* p_itf = &_cusd_itf; // Open endpoint pair with usbd helper - tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_desc_itf ); + tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next( (uint8_t const*) p_desc_itf ); TU_ASSERT_ERR( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_itf->ep_out, &p_itf->ep_in) ); p_itf->itf_num = p_desc_itf->bInterfaceNumber; diff --git a/src/class/custom/custom_host.c b/src/class/custom/custom_host.c index e840a2829..894e641e8 100644 --- a/src/class/custom/custom_host.c +++ b/src/class/custom/custom_host.c @@ -111,7 +111,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ { // FIXME quick hack to test lpc1k custom class with 2 bulk endpoints uint8_t const *p_desc = (uint8_t const *) p_interface_desc; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); //------------- Bulk Endpoints Descriptor -------------// for(uint32_t i=0; i<2; i++) @@ -124,7 +124,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ *p_pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC); TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED ); - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } (*p_length) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 83c9990d8..48f23688d 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -150,19 +150,19 @@ void mscd_reset(uint8_t rhport) tu_memclr(&_mscd_itf, sizeof(mscd_interface_t)); } -tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len) +tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_len) { // only support SCSI's BOT protocol - TU_VERIFY( ( MSC_SUBCLASS_SCSI == p_desc_itf->bInterfaceSubClass && - MSC_PROTOCOL_BOT == p_desc_itf->bInterfaceProtocol ), TUSB_ERROR_MSC_UNSUPPORTED_PROTOCOL ); + TU_VERIFY( ( MSC_SUBCLASS_SCSI == itf_desc->bInterfaceSubClass && + MSC_PROTOCOL_BOT == itf_desc->bInterfaceProtocol ), TUSB_ERROR_MSC_UNSUPPORTED_PROTOCOL ); mscd_interface_t * p_msc = &_mscd_itf; // Open endpoint pair with usbd helper - tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_desc_itf ); + tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next( itf_desc ); TU_ASSERT_ERR( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_msc->ep_out, &p_msc->ep_in) ); - p_msc->itf_num = p_desc_itf->bInterfaceNumber; + p_msc->itf_num = itf_desc->bInterfaceNumber; (*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); //------------- Queue Endpoint OUT for Command Block Wrapper -------------// diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index dd771440d..86669b279 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -300,7 +300,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it msch_interface_t* p_msc = &msch_data[dev_addr-1]; //------------- Open Data Pipe -------------// - tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) itf_desc ); + tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc); for(uint32_t i=0; i<2; i++) { @@ -317,7 +317,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it p_msc->ep_out = ep_desc->bEndpointAddress; } - ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) ep_desc ); + ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc); } p_msc->itf_numr = itf_desc->bInterfaceNumber; diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index cbddd4156..cf02952ab 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -395,19 +395,20 @@ static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir) //--------------------------------------------------------------------+ // Descriptor helper //--------------------------------------------------------------------+ -static inline uint8_t const * descriptor_next(uint8_t const p_desc[]) +static inline uint8_t const * tu_desc_next(void const* desc) { - return p_desc + p_desc[DESC_OFFSET_LEN]; + uint8_t const* desc8 = (uint8_t const*) desc; + return desc8 + desc8[DESC_OFFSET_LEN]; } -static inline uint8_t descriptor_type(uint8_t const p_desc[]) +static inline uint8_t tu_desc_type(void const* desc) { - return p_desc[DESC_OFFSET_TYPE]; + return ((uint8_t const*) desc)[DESC_OFFSET_TYPE]; } -static inline uint8_t descriptor_len(uint8_t const p_desc[]) +static inline uint8_t tu_desc_len(void const* desc) { - return p_desc[DESC_OFFSET_LEN]; + return ((uint8_t const*) desc)[DESC_OFFSET_LEN]; } // Length of the string descriptors in bytes with slen characters diff --git a/src/device/usbd.c b/src/device/usbd.c index b63dcb131..096437747 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -436,12 +436,12 @@ static bool process_set_config(uint8_t rhport) while( p_desc < desc_cfg + cfg_len ) { // Each interface always starts with Interface or Association descriptor - if ( TUSB_DESC_INTERFACE_ASSOCIATION == descriptor_type(p_desc) ) + if ( TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc) ) { - p_desc = descriptor_next(p_desc); // ignore Interface Association + p_desc = tu_desc_next(p_desc); // ignore Interface Association }else { - TU_ASSERT( TUSB_DESC_INTERFACE == descriptor_type(p_desc) ); + TU_ASSERT( TUSB_DESC_INTERFACE == tu_desc_type(p_desc) ); tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) p_desc; @@ -480,15 +480,15 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, while( len < desc_len ) { - if ( TUSB_DESC_ENDPOINT == descriptor_type(p_desc) ) + if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) ) { uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress; ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)] = driver_id; } - len += descriptor_len(p_desc); - p_desc = descriptor_next(p_desc); + len += tu_desc_len(p_desc); + p_desc = tu_desc_next(p_desc); } } @@ -641,7 +641,7 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* ep_ (*ep_out) = ep_desc->bEndpointAddress; } - ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) ep_desc ); + ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc); } return TUSB_ERROR_NONE; diff --git a/src/host/hub.c b/src/host/hub.c index e2e91d73d..e9f9dc7de 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -156,21 +156,21 @@ void hub_init(void) // hub_enum_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(hub_enum_semaphore) ); } -bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) +bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length) { // not support multiple TT yet - if ( p_interface_desc->bInterfaceProtocol > 1 ) return false; + if ( itf_desc->bInterfaceProtocol > 1 ) return false; //------------- Open Interrupt Status Pipe -------------// tusb_desc_endpoint_t const *ep_desc; - ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_interface_desc ); + ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc); TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); TU_ASSERT(TUSB_XFER_INTERRUPT == ep_desc->bmAttributes.xfer); TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); - hub_data[dev_addr-1].itf_num = p_interface_desc->bInterfaceNumber; + hub_data[dev_addr-1].itf_num = itf_desc->bInterfaceNumber; hub_data[dev_addr-1].ep_status = ep_desc->bEndpointAddress; (*p_length) = sizeof(tusb_desc_interface_t) + sizeof(tusb_desc_endpoint_t); diff --git a/src/host/usbh.c b/src/host/usbh.c index 369ddd2a5..bbe60362a 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -560,9 +560,9 @@ bool enum_task(hcd_event_t* event) while( p_desc < _usbh_ctrl_buf + ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength ) { // skip until we see interface descriptor - if ( TUSB_DESC_INTERFACE != descriptor_type(p_desc) ) + if ( TUSB_DESC_INTERFACE != tu_desc_type(p_desc) ) { - p_desc = descriptor_next(p_desc); // skip the descriptor, increase by the descriptor's length + p_desc = tu_desc_next(p_desc); // skip the descriptor, increase by the descriptor's length }else { tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) p_desc; @@ -577,7 +577,7 @@ bool enum_task(hcd_event_t* event) if( drv_id >= USBH_CLASS_DRIVER_COUNT ) { // skip unsupported class - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } else { @@ -589,7 +589,7 @@ bool enum_task(hcd_event_t* event) { // TODO Attach hub to Hub is not currently supported // skip this interface - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } else { @@ -685,15 +685,15 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, while( len < desc_len ) { - if ( TUSB_DESC_ENDPOINT == descriptor_type(p_desc) ) + if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) ) { uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress; ep2drv[ tu_edpt_number(ep_addr) ][ tu_edpt_dir(ep_addr) ] = driver_id; } - len += descriptor_len(p_desc); - p_desc = descriptor_next(p_desc); + len += tu_desc_len(p_desc); + p_desc = tu_desc_next(p_desc); } } -- cgit v1.3.1 From b6cb4757d27fa35564686baab82f7a86094787a7 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 12 Dec 2018 13:00:59 +0700 Subject: change class driver open return type to bool --- src/class/cdc/cdc_device.c | 36 ++++++++++++++++++------------------ src/class/cdc/cdc_device.h | 6 +++--- src/class/hid/hid_device.c | 24 +++++++++++------------- src/class/hid/hid_device.h | 2 +- src/class/msc/msc_device.c | 14 +++++++------- src/class/msc/msc_device.h | 2 +- src/device/usbd.c | 20 ++++++++++---------- src/device/usbd_pvt.h | 2 +- 8 files changed, 52 insertions(+), 54 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index a865ba3c5..fc124627d 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -229,16 +229,14 @@ void cdcd_reset(uint8_t rhport) } } -tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length) +bool cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length) { - if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != itf_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS; + // Only support ACM subclass + TU_ASSERT ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL == itf_desc->bInterfaceSubClass); // Only support AT commands, no protocol and vendor specific commands. - if ( !(tu_within(CDC_COMM_PROTOCOL_NONE, itf_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) || - itf_desc->bInterfaceProtocol == 0xff ) ) - { - return TUSB_ERROR_CDC_UNSUPPORTED_PROTOCOL; - } + TU_ASSERT(tu_within(CDC_COMM_PROTOCOL_NONE, itf_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) || + itf_desc->bInterfaceProtocol == 0xff); // Find available interface cdcd_interface_t * p_cdc = NULL; @@ -250,23 +248,25 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, u break; } } + TU_ASSERT(p_cdc); //------------- Control Interface -------------// - p_cdc->itf_num = itf_desc->bInterfaceNumber; + p_cdc->itf_num = itf_desc->bInterfaceNumber; uint8_t const * p_desc = tu_desc_next( itf_desc ); (*p_length) = sizeof(tusb_desc_interface_t); // Communication Functional Descriptors - while( TUSB_DESC_CLASS_SPECIFIC == p_desc[DESC_OFFSET_TYPE] ) + while ( TUSB_DESC_CLASS_SPECIFIC == tu_desc_type(p_desc) ) { - (*p_length) += p_desc[DESC_OFFSET_LEN]; + (*p_length) += tu_desc_len(p_desc); p_desc = tu_desc_next(p_desc); } - if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE]) - { // notification endpoint if any - TU_ASSERT( dcd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc), TUSB_ERROR_DCD_OPEN_PIPE_FAILED); + if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) ) + { + // notification endpoint if any + TU_ASSERT( dcd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc) ); p_cdc->ep_notif = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress; @@ -278,21 +278,21 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, u if ( (TUSB_DESC_INTERFACE == p_desc[DESC_OFFSET_TYPE]) && (TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) ) { - // next to endpoint descritpor - (*p_length) += p_desc[DESC_OFFSET_LEN]; + // next to endpoint descriptor + (*p_length) += tu_desc_len(p_desc); p_desc = tu_desc_next(p_desc); // Open endpoint pair with usbd helper tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) p_desc; - TU_ASSERT_ERR( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_cdc->ep_out, &p_cdc->ep_in) ); + TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_cdc->ep_out, &p_cdc->ep_in) ); (*p_length) += 2*sizeof(tusb_desc_endpoint_t); } // Prepare for incoming data - TU_ASSERT( dcd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE), TUSB_ERROR_DCD_EDPT_XFER); + TU_ASSERT( dcd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE) ); - return TUSB_ERROR_NONE; + return true; } // Invoked when class request DATA stage is finished. diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 9dd837d7d..03aa2485e 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -112,12 +112,12 @@ ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_li //--------------------------------------------------------------------+ #ifdef _TINY_USB_SOURCE_FILE_ -void cdcd_init (void); -tusb_error_t cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); +void cdcd_init (void); +bool cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool cdcd_control_request (uint8_t rhport, tusb_control_request_t const * p_request); bool cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); -void cdcd_reset (uint8_t rhport); +void cdcd_reset (uint8_t rhport); #endif diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index fa76ee015..cfb1a698d 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -318,22 +318,22 @@ void hidd_reset(uint8_t rhport) #endif } -tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_len) +bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_len) { uint8_t const *p_desc = (uint8_t const *) desc_itf; - // TODO not support HID OUT Endpoint - TU_ASSERT(desc_itf->bNumEndpoints == 1, ERR_TUD_INVALID_DESCRIPTOR); + // TODO support HID OUT Endpoint + TU_ASSERT(desc_itf->bNumEndpoints == 1); //------------- HID descriptor -------------// - p_desc += p_desc[DESC_OFFSET_LEN]; + p_desc = tu_desc_next(p_desc); tusb_hid_descriptor_hid_t const *desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc; - TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType, ERR_TUD_INVALID_DESCRIPTOR); + TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType); //------------- Endpoint Descriptor -------------// - p_desc += p_desc[DESC_OFFSET_LEN]; + p_desc = tu_desc_next(p_desc); tusb_desc_endpoint_t const *desc_edpt = (tusb_desc_endpoint_t const *) p_desc; - TU_ASSERT(TUSB_DESC_ENDPOINT == desc_edpt->bDescriptorType, ERR_TUD_INVALID_DESCRIPTOR); + TU_ASSERT(TUSB_DESC_ENDPOINT == desc_edpt->bDescriptorType); hidd_interface_t * p_hid = NULL; @@ -374,7 +374,7 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u } #endif - TU_ASSERT(p_hid, ERR_TUD_INVALID_DESCRIPTOR); + TU_ASSERT(p_hid); p_hid->boot_protocol = true; // default mode is BOOT } /*------------- Generic (multiple report) -------------*/ @@ -386,12 +386,10 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u p_hid->desc_report = usbd_desc_set->hid_report.generic; p_hid->get_report_cb = tud_hid_generic_get_report_cb; p_hid->set_report_cb = tud_hid_generic_set_report_cb; - - TU_ASSERT(p_hid, ERR_TUD_INVALID_DESCRIPTOR); } - TU_VERIFY(p_hid->desc_report, ERR_TUD_INVALID_DESCRIPTOR); - TU_ASSERT( dcd_edpt_open(rhport, desc_edpt), ERR_TUD_EDPT_OPEN_FAILED ); + TU_ASSERT(p_hid->desc_report); + TU_ASSERT(dcd_edpt_open(rhport, desc_edpt)); p_hid->itf_num = desc_itf->bInterfaceNumber; p_hid->ep_in = desc_edpt->bEndpointAddress; @@ -399,7 +397,7 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u *p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t); - return TUSB_ERROR_NONE; + return true; } // Handle class control request diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 42c61a47b..2f0047d81 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -377,7 +377,7 @@ ATTR_WEAK void tud_hid_mouse_set_report_cb(uint8_t report_id, hid_report_type_t #ifdef _TINY_USB_SOURCE_FILE_ void hidd_init(void); -tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); +bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length); bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool hidd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 48f23688d..14a7e593a 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -150,25 +150,25 @@ void mscd_reset(uint8_t rhport) tu_memclr(&_mscd_itf, sizeof(mscd_interface_t)); } -tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_len) +bool mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_len) { // only support SCSI's BOT protocol - TU_VERIFY( ( MSC_SUBCLASS_SCSI == itf_desc->bInterfaceSubClass && - MSC_PROTOCOL_BOT == itf_desc->bInterfaceProtocol ), TUSB_ERROR_MSC_UNSUPPORTED_PROTOCOL ); + TU_ASSERT(MSC_SUBCLASS_SCSI == itf_desc->bInterfaceSubClass && + MSC_PROTOCOL_BOT == itf_desc->bInterfaceProtocol); mscd_interface_t * p_msc = &_mscd_itf; // Open endpoint pair with usbd helper tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next( itf_desc ); - TU_ASSERT_ERR( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_msc->ep_out, &p_msc->ep_in) ); + TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_msc->ep_out, &p_msc->ep_in) ); p_msc->itf_num = itf_desc->bInterfaceNumber; (*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); - //------------- Queue Endpoint OUT for Command Block Wrapper -------------// - TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)), TUSB_ERROR_DCD_EDPT_XFER ); + // Prepare for Command Block Wrapper + TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) ); - return TUSB_ERROR_NONE; + return true; } // Handle class control request diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index 55bfba83c..80e47d84b 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -171,7 +171,7 @@ ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun); #ifdef _TINY_USB_SOURCE_FILE_ void mscd_init(void); -tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); +bool mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length); bool mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool mscd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); diff --git a/src/device/usbd.c b/src/device/usbd.c index 096437747..bf7fd950a 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -88,13 +88,13 @@ tud_desc_set_t const* usbd_desc_set = &tud_desc_set; typedef struct { uint8_t class_code; - void (* init ) (void); - tusb_error_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t* p_length); - bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request); + void (* init ) (void); + bool (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t* p_length); + bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request); bool (* control_request_complete ) (uint8_t rhport, tusb_control_request_t const * request); tusb_error_t (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t, uint32_t); - void (* sof ) (uint8_t rhport); - void (* reset ) (uint8_t); + void (* sof ) (uint8_t rhport); + void (* reset ) (uint8_t); } usbd_class_driver_t; static usbd_class_driver_t const usbd_class_drivers[] = @@ -458,7 +458,7 @@ static bool process_set_config(uint8_t rhport) _usbd_dev.itf2drv[desc_itf->bInterfaceNumber] = drv_id; uint16_t itf_len=0; - TU_ASSERT_ERR( usbd_class_drivers[drv_id].open( rhport, desc_itf, &itf_len ), false ); + TU_ASSERT( usbd_class_drivers[drv_id].open( rhport, desc_itf, &itf_len ) ); TU_ASSERT( itf_len >= sizeof(tusb_desc_interface_t) ); mark_interface_endpoint(_usbd_dev.ep2drv, p_desc, itf_len, drv_id); @@ -624,14 +624,14 @@ void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_ //--------------------------------------------------------------------+ // Helper to parse an pair of endpoint descriptors (IN & OUT) -tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* ep_desc, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in) +bool usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* ep_desc, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in) { for(int i=0; i<2; i++) { TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType && - xfer_type == ep_desc->bmAttributes.xfer, TUSB_ERROR_DESCRIPTOR_CORRUPTED); + xfer_type == ep_desc->bmAttributes.xfer ); - TU_ASSERT( dcd_edpt_open(rhport, ep_desc), TUSB_ERROR_DCD_OPEN_PIPE_FAILED ); + TU_ASSERT(dcd_edpt_open(rhport, ep_desc)); if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { @@ -644,7 +644,7 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* ep_ ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc); } - return TUSB_ERROR_NONE; + return true; } // Helper to defer an isr function diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index cbe5017bb..798a871b1 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -70,7 +70,7 @@ void usbd_control_stall(uint8_t rhport); /* Helper *------------------------------------------------------------------*/ // helper to parse an pair of In and Out endpoint descriptors. They must be consecutive -tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_desc_ep, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in); +bool usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_desc_ep, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in); void usbd_defer_func( osal_task_func_t func, void* param, bool in_isr ); -- cgit v1.3.1 From c1c501e0c2f3ad2c910b11bb358396c2e57ec624 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 12 Dec 2018 13:12:06 +0700 Subject: change usbd xfer_cb return type to bool --- src/class/cdc/cdc_device.c | 8 ++++---- src/class/cdc/cdc_device.h | 2 +- src/class/custom/custom_device.c | 14 +++++++------- src/class/custom/custom_device.h | 4 ++-- src/class/hid/hid_device.c | 4 ++-- src/class/hid/hid_device.h | 2 +- src/class/msc/msc_device.c | 16 ++++++++-------- src/class/msc/msc_device.h | 2 +- src/device/usbd.c | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) (limited to 'src/class/cdc') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index fc124627d..7d9e196aa 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -357,7 +357,7 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request return true; } -tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) +bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) { (void) result; @@ -382,13 +382,13 @@ tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, // invoke receive callback (if there is still data) if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf); - // prepare for next - TU_ASSERT( dcd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE), TUSB_ERROR_DCD_EDPT_XFER ); + // prepare for incoming data + TU_ASSERT( dcd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE) ); } // nothing to do with in and notif endpoint - return TUSB_ERROR_NONE; + return true; } #endif diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 03aa2485e..5ee649c4b 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -116,7 +116,7 @@ void cdcd_init (void); bool cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool cdcd_control_request (uint8_t rhport, tusb_control_request_t const * p_request); bool cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); +bool cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); void cdcd_reset (uint8_t rhport); #endif diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index bec6f42d1..129d405a4 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -71,22 +71,22 @@ void cusd_init(void) tu_varclr(&_cusd_itf); } -tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len) +bool cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len) { cusd_interface_t* p_itf = &_cusd_itf; // Open endpoint pair with usbd helper - tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next( (uint8_t const*) p_desc_itf ); - TU_ASSERT_ERR( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_itf->ep_out, &p_itf->ep_in) ); + tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next(p_desc_itf); + TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_itf->ep_out, &p_itf->ep_in) ); p_itf->itf_num = p_desc_itf->bInterfaceNumber; (*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); // TODO Prepare for incoming data -// TU_ASSERT( dcd_edpt_xfer(rhport, p_itf->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)), TUSB_ERROR_DCD_EDPT_XFER ); +// TU_ASSERT( dcd_edpt_xfer(rhport, p_itf->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) ); - return TUSB_ERROR_NONE; + return true; } bool cusd_control_request(uint8_t rhport, tusb_control_request_t const * p_request) @@ -94,9 +94,9 @@ bool cusd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque return false; } -tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) +bool cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { - return TUSB_ERROR_NONE; + return true; } void cusd_reset(uint8_t rhport) diff --git a/src/class/custom/custom_device.h b/src/class/custom/custom_device.h index f223a4d3c..aae06d503 100644 --- a/src/class/custom/custom_device.h +++ b/src/class/custom/custom_device.h @@ -63,10 +63,10 @@ #ifdef _TINY_USB_SOURCE_FILE_ void cusd_init(void); -tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); +bool cusd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length); bool cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request); bool cusd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); +bool cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void cusd_reset(uint8_t rhport); #endif diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index cfb1a698d..bd49c157a 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -508,10 +508,10 @@ bool hidd_control_request_complete(uint8_t rhport, tusb_control_request_t const return true; } -tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) +bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { // nothing to do - return TUSB_ERROR_NONE; + return true; } diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 2f0047d81..885f33443 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -380,7 +380,7 @@ void hidd_init(void); bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length); bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool hidd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); +bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void hidd_reset(uint8_t rhport); #endif diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 14a7e593a..d4d115bce 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -329,7 +329,7 @@ int32_t proc_builtin_scsi(msc_cbw_t const * p_cbw, uint8_t* buffer, uint32_t buf return ret; } -tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) +bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { mscd_interface_t* p_msc = &_mscd_itf; msc_cbw_t const * p_cbw = &p_msc->cbw; @@ -340,10 +340,10 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, case MSC_STAGE_CMD: //------------- new CBW received -------------// // Complete IN while waiting for CMD is usually Status of previous SCSI op, ignore it - if(ep_addr != p_msc->ep_out) return TUSB_ERROR_NONE; + if(ep_addr != p_msc->ep_out) return true; TU_ASSERT( event == XFER_RESULT_SUCCESS && - xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE, TUSB_ERROR_INVALID_PARA ); + xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE ); p_csw->signature = MSC_CSW_SIGNATURE; p_csw->tag = p_cbw->tag; @@ -388,7 +388,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, else if ( !BIT_TEST_(p_cbw->dir, 7) ) { // OUT transfer - TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len), TUSB_ERROR_DCD_EDPT_XFER ); + TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) ); } else { @@ -409,8 +409,8 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, p_msc->total_len = (uint32_t) cb_result; p_csw->status = MSC_CSW_STATUS_PASSED; - TU_ASSERT( p_cbw->total_bytes >= p_msc->total_len, TUSB_ERROR_INVALID_PARA ); // cannot return more than host expect - TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len), TUSB_ERROR_DCD_EDPT_XFER ); + TU_ASSERT( p_cbw->total_bytes >= p_msc->total_len ); // cannot return more than host expect + TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len) ); }else { p_msc->total_len = 0; @@ -474,7 +474,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, // simulate an transfer complete with adjusted parameters --> this driver callback will fired again dcd_event_xfer_complete(rhport, p_msc->ep_out, xferred_bytes-nbytes, XFER_RESULT_SUCCESS, false); - return TUSB_ERROR_NONE; // skip the rest + return true; // skip the rest } else { @@ -549,7 +549,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, } } - return TUSB_ERROR_NONE; + return true; } /*------------------------------------------------------------------*/ diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index 80e47d84b..c9e4139e9 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -174,7 +174,7 @@ void mscd_init(void); bool mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length); bool mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool mscd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); +bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void mscd_reset(uint8_t rhport); #endif diff --git a/src/device/usbd.c b/src/device/usbd.c index bf7fd950a..8c685d5b3 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -92,7 +92,7 @@ typedef struct { bool (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t* p_length); bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request); bool (* control_request_complete ) (uint8_t rhport, tusb_control_request_t const * request); - tusb_error_t (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t, uint32_t); + bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t, uint32_t); void (* sof ) (uint8_t rhport); void (* reset ) (uint8_t); } usbd_class_driver_t; -- cgit v1.3.1 From bb544a09518f4f2210482e62fb050b6cea641c97 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 12 Dec 2018 14:43:45 +0700 Subject: minor update --- examples/device/cdc_msc_hid/src/main.c | 17 +++++++++++++---- src/class/cdc/cdc_device.c | 3 ++- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src/class/cdc') diff --git a/examples/device/cdc_msc_hid/src/main.c b/examples/device/cdc_msc_hid/src/main.c index d88bd3726..bc260fdfa 100644 --- a/examples/device/cdc_msc_hid/src/main.c +++ b/examples/device/cdc_msc_hid/src/main.c @@ -94,10 +94,19 @@ void virtual_com_task(void) // read and echo back uint32_t count = tud_cdc_read(buf, sizeof(buf)); - tud_cdc_write(buf, count); - } + for(uint32_t i=0; iline_state = (uint8_t) request->wValue; + usbd_control_status(rhport, request); + // Invoke callback if ( tud_cdc_line_state_cb) tud_cdc_line_state_cb(itf, BIT_TEST_(request->wValue, 0), BIT_TEST_(request->wValue, 1)); - usbd_control_status(rhport, request); break; default: return false; // stall unsupported request -- cgit v1.3.1 From a3713f801d97b1903593a53c02da682acb3acee0 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 14 Dec 2018 13:08:21 +0700 Subject: clean up compiler attribute --- examples/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(-) (limited to 'src/class/cdc') diff --git a/examples/obsolete/host/src/keyboard_host_app.c b/examples/obsolete/host/src/keyboard_host_app.c index 77fa8e5d3..f6cd20fda 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 fa1f986a5..0ab42e3f1 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 939015c00..7d6b5afdd 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 3b92d3f23..730df2e23 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 5f9c25dda..5522db58b 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 7336f5ada..9d4b2b5b6 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 968d221b4..9035cb845 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 3ab87e3f8..7a93ee709 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 e40ad9c41..6ea89f24f 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 1f8936859..d62a65e27 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 e117c20ff..8753543d6 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 f8d8a4c6a..626cb4592 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 d0b5edb63..4334729e9 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 3a13bbecc..389bf54d4 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 03fa60b5d..bd5a2dacf 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; -- cgit v1.3.1 From 2a60427bdc7d23d7c1ab1e687f5a8d9555a69f15 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 14 Dec 2018 15:28:38 +0700 Subject: 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 | 58 +++++++------- src/portable/nordic/nrf5x/dcd_nrf5x.c | 18 ++--- src/portable/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 +- tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c | 6 +- tests/lpc18xx_43xx/test/host/ehci/test_ehci_init.c | 2 +- .../test/host/ehci/test_pipe_interrupt_open.c | 2 +- tests/lpc18xx_43xx/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 | 89 +++++++++------------- 29 files changed, 266 insertions(+), 294 deletions(-) (limited to 'src/class/cdc') diff --git a/hw/bsp/ea4088qs/board_ea4088qs.c b/hw/bsp/ea4088qs/board_ea4088qs.c index 0875a8870..d2bf409aa 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 5522db58b..a5fcb6fb4 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 8bfede2da..2e2b45585 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 d4d115bce..5d2758414 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 7a93ee709..5bc364f2f 100644 --- a/src/common/binary.h +++ b/src/common/binary.h @@ -52,49 +52,38 @@ #include "tusb_compiler.h" //------------- Bit manipulation -------------// -#define BIT_(n) (1U << (n)) ///< n-th Bit -#define BIT_SET_(x, n) ( (x) | BIT_(n) ) ///< set n-th bit of x to 1 -#define BIT_CLR_(x, n) ( (x) & (~BIT_(n)) ) ///< clear n-th bit of x -#define BIT_TEST_(x, n) ( ((x) & BIT_(n)) ? true : false ) ///< check if n-th bit of x is 1 +#define TU_BIT(n) (1U << (n)) ///< n-th Bit +#define TU_BIT_SET(x, n) ( (x) | TU_BIT(n) ) ///< set n-th bit of x to 1 +#define TU_BIT_CLEAR(x, n) ( (x) & (~TU_BIT(n)) ) ///< clear n-th bit of x +#define TU_BIT_TEST(x, n) ( ((x) & TU_BIT(n)) ? true : false ) ///< check if n-th bit of x is 1 -static inline uint32_t bit_set(uint32_t value, uint8_t n) +static inline uint32_t tu_bit_set(uint32_t value, uint8_t n) { - return value | BIT_(n); + return value | TU_BIT(n); } -static inline uint32_t bit_clear(uint32_t value, uint8_t n) +static inline uint32_t tu_bit_clear(uint32_t value, uint8_t n) { - return value & (~BIT_(n)); + return value & (~TU_BIT(n)); } -static inline bool bit_test(uint32_t value, uint8_t n) +static inline bool tu_bit_test(uint32_t value, uint8_t n) { - return (value & BIT_(n)) ? true : false; + return (value & TU_BIT(n)) ? true : false; } ///< create a mask with n-bit lsb set to 1 -static inline uint32_t bit_mask(uint8_t n) +static inline uint32_t tu_bit_mask(uint8_t n) { - return (n < 32) ? ( BIT_(n) - 1 ) : UINT32_MAX; + return (n < 32) ? ( TU_BIT(n) - 1 ) : UINT32_MAX; } -static inline uint32_t bit_mask_range(uint8_t start, uint32_t end) -{ - return bit_mask(end+1) & ~ bit_mask(start); -} - -static inline uint32_t bit_set_range(uint32_t value, uint8_t start, uint8_t end, uint32_t pattern) -{ - return ( value & ~bit_mask_range(start, end) ) | (pattern << start); -} - - //------------- Binary Constant -------------// #if defined(__GNUC__) && !defined(__CC_ARM) -#define BIN8(x) ((uint8_t) (0b##x)) -#define BIN16(b1, b2) ((uint16_t) (0b##b1##b2)) -#define BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4)) +#define TU_BIN8(x) ((uint8_t) (0b##x)) +#define TU_BIN16(b1, b2) ((uint16_t) (0b##b1##b2)) +#define TU_BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4)) #else @@ -108,13 +97,13 @@ static inline uint32_t bit_set_range(uint32_t value, uint8_t start, uint8_t end, +((x&0x0F000000UL)?64:0) \ +((x&0xF0000000UL)?128:0)) -#define BIN8(d) ((uint8_t) _B8__(0x##d##UL)) -#define BIN16(dmsb,dlsb) (((uint16_t)BIN8(dmsb)<<8) + BIN8(dlsb)) -#define BIN32(dmsb,db2,db3,dlsb) \ - (((uint32_t)BIN8(dmsb)<<24) \ - + ((uint32_t)BIN8(db2)<<16) \ - + ((uint32_t)BIN8(db3)<<8) \ - + BIN8(dlsb)) +#define TU_BIN8(d) ((uint8_t) _B8__(0x##d##UL)) +#define TU_BIN16(dmsb,dlsb) (((uint16_t)TU_BIN8(dmsb)<<8) + TU_BIN8(dlsb)) +#define TU_BIN32(dmsb,db2,db3,dlsb) \ + (((uint32_t)TU_BIN8(dmsb)<<24) \ + + ((uint32_t)TU_BIN8(db2)<<16) \ + + ((uint32_t)TU_BIN8(db3)<<8) \ + + TU_BIN8(dlsb)) #endif #ifdef __cplusplus diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index 6f0167898..9a6d5a520 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 b46c9bc64..b8f724122 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 c1c274793..23bbb310a 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 6b87e935e..16560a812 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 bebb8a2ef..887b3e561 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_OWNERSHIP_CHANGE_MASK = BIT_(30), - OHCI_INT_MASTER_ENABLE_MASK = BIT_(31), + 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 = 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 ad5090eb0..7d13ef8c3 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 c910bf1ec..26ecaf8be 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 82d3c3cac..fca2c355d 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 d6b76fcd1..eac8ec99b 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 70b34d848..7761d547f 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 faf0e3b0f..c380be724 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 31baa5f5c..f61556c22 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 1f8410461..25d74d860 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 8d552cb8a..5047e98c4 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 ff6dfef8f..24fddf65e 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 096e10ac2..262dbe9ef 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 5a673fb04..7b5d06c31 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 2b465d07d..a01c41d13 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 fb61df0fa..fbe2083b0 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(0x0f, BIN8(00001111)); - TEST_ASSERT_EQUAL_HEX8(0xf0, BIN8(11110000)); - TEST_ASSERT_EQUAL_HEX8(0xff, BIN8(11111111)); + 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, 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)); } -- cgit v1.3.1