summaryrefslogtreecommitdiff
path: root/tinyusb
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-03-23 18:36:43 +0700
committerhathach <[email protected]>2013-03-23 18:36:43 +0700
commit0c5e0ef0f37b88990c995de465792d0e50eb8cda (patch)
tree5df1b0231ed9c5cabc4767670dd703a697f3938d /tinyusb
parent44e09cc397df4e7fc47c37a4d967fe17a3d82e16 (diff)
- add control_pipe_status for usbh_device_info_t to reflect the status transfer of control pipe
- fix bug with hcd_port_reset + remove regs->portsc_bit.port_enable in the wait loop as device unplugged can cause this to always fails - correct the timeout for hcd_controll_stop/reset 16 uframes ~ 2 ms - potentially fix bugs device unplugged when new address is not assigned
Diffstat (limited to 'tinyusb')
-rw-r--r--tinyusb/core/tusb_types.h2
-rw-r--r--tinyusb/host/ehci/ehci.c7
-rw-r--r--tinyusb/host/usbh.c6
-rw-r--r--tinyusb/host/usbh.h7
-rw-r--r--tinyusb/host/usbh_hcd.h5
5 files changed, 17 insertions, 10 deletions
diff --git a/tinyusb/core/tusb_types.h b/tinyusb/core/tusb_types.h
index f0797bfdc..6bdc057f9 100644
--- a/tinyusb/core/tusb_types.h
+++ b/tinyusb/core/tusb_types.h
@@ -154,7 +154,7 @@ enum {
#define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
/// Device State
-typedef enum {
+typedef enum tusb_device_state_{
TUSB_DEVICE_STATE_UNPLUG = 0 ,
TUSB_DEVICE_STATE_ADDRESSED ,
diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c
index c8d524b7b..731efbfaf 100644
--- a/tinyusb/host/ehci/ehci.c
+++ b/tinyusb/host/ehci/ehci.c
@@ -135,7 +135,8 @@ void hcd_port_reset(uint8_t hostid)
#ifndef _TEST_
// NXP specific, port reset will automatically be 0 when reset sequence complete
- while( regs->portsc_bit.port_reset || !regs->portsc_bit.port_enable){} // FIXME trapped here once
+ // there is chance device is unplugged while reset sequence is not complete
+ while( regs->portsc_bit.port_reset /*&& regs->portsc_bit.current_connect_status*/ ) {}
#endif
}
@@ -385,7 +386,7 @@ static tusb_error_t hcd_controller_stop(uint8_t hostid)
regs->usb_cmd_bit.run_stop = 0;
- timeout_set(&timeout, 16); // USB Spec: controller has to stop within 16 uframe
+ timeout_set(&timeout, 2); // USB Spec: controller has to stop within 16 uframe = 2 frames
while( regs->usb_sts_bit.hc_halted == 0 && !timeout_expired(&timeout)) {}
return timeout_expired(&timeout) ? TUSB_ERROR_OSAL_TIMEOUT : TUSB_ERROR_NONE;
@@ -404,7 +405,7 @@ tusb_error_t hcd_controller_reset(uint8_t hostid)
regs->usb_cmd_bit.reset = 1;
- timeout_set(&timeout, 16); // should not take longer the time to stop controller
+ timeout_set(&timeout, 2); // should not take longer the time to stop controller
while( regs->usb_cmd_bit.reset && !timeout_expired(&timeout)) {}
return timeout_expired(&timeout) ? TUSB_ERROR_OSAL_TIMEOUT : TUSB_ERROR_NONE;
diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c
index 46776cabe..c841d3ceb 100644
--- a/tinyusb/host/usbh.c
+++ b/tinyusb/host/usbh.c
@@ -143,11 +143,14 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, tusb_std_request_t cons
OSAL_SUBTASK_BEGIN
+ usbh_device_info_pool[dev_addr].control_pipe_status = PIPE_STATUS_BUSY;
usbh_device_info_pool[dev_addr].control_request = *p_request;
(void) hcd_pipe_control_xfer(dev_addr, &usbh_device_info_pool[dev_addr].control_request, data);
osal_semaphore_wait(usbh_device_info_pool[dev_addr].sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static
- SUBTASK_ASSERT_STATUS_WITH_HANDLER(error, tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) );
+ // TODO make handler for this function general purpose
+ SUBTASK_ASSERT_STATUS_WITH_HANDLER(error || usbh_device_info_pool[dev_addr].control_pipe_status == PIPE_STATUS_ERROR,
+ tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) );
OSAL_SUBTASK_END
}
@@ -183,6 +186,7 @@ void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_bus_event_t event
{
if (class_code == 0) // Control transfer
{
+ usbh_device_info_pool[ pipe_hdl.dev_addr ].control_pipe_status = (event == BUS_EVENT_XFER_COMPLETE) ? PIPE_STATUS_COMPLETE : PIPE_STATUS_ERROR;
osal_semaphore_post( usbh_device_info_pool[ pipe_hdl.dev_addr ].sem_hdl );
}else if (usbh_class_drivers[class_code].isr)
{
diff --git a/tinyusb/host/usbh.h b/tinyusb/host/usbh.h
index 901a0f056..2934e4c3c 100644
--- a/tinyusb/host/usbh.h
+++ b/tinyusb/host/usbh.h
@@ -93,10 +93,11 @@
// TUSB_CLASS_APPLICATION_SPECIFIC = 0xEF ,
// TUSB_CLASS_VENDOR_SPECIFIC = 0xFF
-typedef enum {
- PIPE_STATUS_AVAILABLE = 0,
+typedef enum pipe_status_{
+ PIPE_STATUS_READY = 0,
PIPE_STATUS_BUSY,
- PIPE_STATUS_COMPLETE
+ PIPE_STATUS_COMPLETE,
+ PIPE_STATUS_ERROR
} pipe_status_t;
typedef uint32_t tusbh_flag_class_t;
diff --git a/tinyusb/host/usbh_hcd.h b/tinyusb/host/usbh_hcd.h
index d11b6e45f..135f03a5f 100644
--- a/tinyusb/host/usbh_hcd.h
+++ b/tinyusb/host/usbh_hcd.h
@@ -90,11 +90,12 @@ typedef struct { // TODO internal structure, re-order members
//------------- configuration descriptor info -------------//
uint8_t interface_count; // bNumInterfaces alias
- uint8_t state; // value from enum tusbh_device_status_
+ volatile uint8_t state; // device state, value from enum tusbh_device_state_t
//------------- control pipe -------------//
+ volatile uint8_t control_pipe_status;
tusb_std_request_t control_request;
- OSAL_SEM_DEF(semaphore);
+ OSAL_SEM_DEF(semaphore); // TODO move to semaphore pool
osal_semaphore_handle_t sem_hdl;
} usbh_device_info_t;