diff options
| author | hathach <[email protected]> | 2013-10-27 19:34:36 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-10-27 19:34:36 +0700 |
| commit | 318a058d3cf4f76221febead5fc0792a2387a310 (patch) | |
| tree | a4f920c571be466282a1acb65df8189eeb52de08 /tinyusb | |
| parent | 0d9e1163dfd4e12b57674cb893b427fce40ba402 (diff) | |
static assert to check OSAL_QUEUE_DEF's queue_depth parameter < 256
enable HOST_HCD_XFER_INTERRUPT by default (previously only enabled with HID), as it is widely used
implement tusbh_cdc_is_busy
add compilation switch in usbh enumeration for hub
rewrite CDC serial application to address usb-serial race condition
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/class/cdc_host.c | 36 | ||||
| -rw-r--r-- | tinyusb/class/cdc_host.h | 2 | ||||
| -rw-r--r-- | tinyusb/host/ehci/ehci.h | 1 | ||||
| -rw-r--r-- | tinyusb/host/usbh.c | 7 | ||||
| -rw-r--r-- | tinyusb/osal/osal_none.h | 1 | ||||
| -rw-r--r-- | tinyusb/tusb_option.h | 6 |
6 files changed, 43 insertions, 10 deletions
diff --git a/tinyusb/class/cdc_host.c b/tinyusb/class/cdc_host.c index f54889489..a802807d0 100644 --- a/tinyusb/class/cdc_host.c +++ b/tinyusb/class/cdc_host.c @@ -58,6 +58,17 @@ //--------------------------------------------------------------------+ /*STATIC_*/ cdch_data_t cdch_data[TUSB_CFG_HOST_DEVICE_MAX]; // TODO to be static +static inline cdc_pipeid_t get_app_pipeid(pipe_handle_t pipe_hdl) ATTR_PURE ATTR_ALWAYS_INLINE; +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) ATTR_PURE ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT; STATIC_ INLINE_ bool tusbh_cdc_is_mounted(uint8_t dev_addr) { @@ -70,16 +81,29 @@ STATIC_ INLINE_ bool tusbh_cdc_is_mounted(uint8_t dev_addr) #endif } -static inline cdc_pipeid_t get_app_pipeid(pipe_handle_t pipe_hdl) ATTR_PURE ATTR_ALWAYS_INLINE; -static inline cdc_pipeid_t get_app_pipeid(pipe_handle_t pipe_hdl) +bool tusbh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) { - cdch_data_t const * p_cdc = &cdch_data[pipe_hdl.dev_addr-1]; + if ( !tusbh_cdc_is_mounted(dev_addr) ) return false; - 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; + cdch_data_t const * p_cdc = &cdch_data[dev_addr-1]; + + switch (pipeid) + { + case CDC_PIPE_NOTIFICATION: + return hcd_pipe_is_busy( p_cdc->pipe_notification ); + + case CDC_PIPE_DATA_IN: + return hcd_pipe_is_busy( p_cdc->pipe_in ); + + case CDC_PIPE_DATA_OUT: + return hcd_pipe_is_busy( p_cdc->pipe_out ); + + default: + return false; + } } + //--------------------------------------------------------------------+ // APPLICATION API (parameter validation needed) //--------------------------------------------------------------------+ diff --git a/tinyusb/class/cdc_host.h b/tinyusb/class/cdc_host.h index 4c78e6f73..e73d96d60 100644 --- a/tinyusb/class/cdc_host.h +++ b/tinyusb/class/cdc_host.h @@ -64,6 +64,8 @@ typedef enum { * @{ */
bool tusbh_cdc_serial_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
+bool tusbh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
+
tusb_error_t tusbh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify);
tusb_error_t tusbh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify);
diff --git a/tinyusb/host/ehci/ehci.h b/tinyusb/host/ehci/ehci.h index dbb05ee9b..1c507279f 100644 --- a/tinyusb/host/ehci/ehci.h +++ b/tinyusb/host/ehci/ehci.h @@ -69,6 +69,7 @@ //--------------------------------------------------------------------+ // EHCI CONFIGURATION & CONSTANTS //--------------------------------------------------------------------+ +#define HOST_HCD_XFER_INTERRUPT // TODO interrupt is used widely, should always be enalbed #define EHCI_PERIODIC_LIST (defined HOST_HCD_XFER_INTERRUPT || defined HOST_HCD_XFER_ISOCHRONOUS) // TODO allow user to configure diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index c7618d238..3afd1a1af 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -392,6 +392,7 @@ tusb_error_t enumeration_body_subtask(void) SUBTASK_EXIT(TUSB_ERROR_NONE); // restart task } } + #if TUSB_CFG_HOST_HUB else { // connected/disconnected via hub //------------- Get Port Status -------------// @@ -428,6 +429,7 @@ tusb_error_t enumeration_body_subtask(void) OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE), error ); } } + #endif SUBTASK_ASSERT_STATUS( usbh_pipe_control_open(0, 8) ); usbh_devices[0].state = TUSB_DEVICE_STATE_ADDRESSED; @@ -446,7 +448,9 @@ tusb_error_t enumeration_body_subtask(void) SUBTASK_ASSERT_STATUS(error); // 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(50); // TODO reset is recommended to last 50 ms (NXP EHCI passes this) - }else + } + #if TUSB_CFG_HOST_HUB + else { // connected via a hub SUBTASK_ASSERT_STATUS_WITH_HANDLER(error, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor OSAL_SUBTASK_INVOKED_AND_WAIT ( hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port), error ); @@ -458,6 +462,7 @@ tusb_error_t enumeration_body_subtask(void) (void) hub_status_pipe_queue( usbh_devices[0].hub_addr ); // done with hub, waiting for next data on status pipe } + #endif //------------- Set new address -------------// new_addr = get_new_address(); diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index ee7c2fdd2..80ae80fd3 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -263,6 +263,7 @@ typedef osal_queue_t * osal_queue_handle_t; // use to declare a queue, within the scope of tinyusb, should only use primitive type only #define OSAL_QUEUE_DEF(name, queue_depth, type)\ + STATIC_ASSERT(queue_depth < 256, "OSAL Queue only support up to 255 depth");\ type name##_buffer[queue_depth];\ osal_queue_t name = {\ .buffer = (uint8_t*) name##_buffer,\ diff --git a/tinyusb/tusb_option.h b/tinyusb/tusb_option.h index 2330835d8..6689cb6d1 100644 --- a/tinyusb/tusb_option.h +++ b/tinyusb/tusb_option.h @@ -147,9 +147,9 @@ //------------- HID CLASS -------------//
#define HOST_CLASS_HID ( TUSB_CFG_HOST_HID_KEYBOARD + TUSB_CFG_HOST_HID_MOUSE + TUSB_CFG_HOST_HID_GENERIC )
- #if HOST_CLASS_HID
- #define HOST_HCD_XFER_INTERRUPT
- #endif
+// #if HOST_CLASS_HID
+// #define HOST_HCD_XFER_INTERRUPT
+// #endif
#ifndef TUSB_CFG_HOST_ENUM_BUFFER_SIZE
#define TUSB_CFG_HOST_ENUM_BUFFER_SIZE 256
|
