- 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
This commit is contained in:
		@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
  {
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user