mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
- 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:
parent
44e09cc397
commit
0c5e0ef0f3
@ -131,7 +131,7 @@ pipe_status_t pipe_status_get_stub(pipe_handle_t pipe_hdl, int num_call)
|
||||
break;
|
||||
|
||||
case 1:
|
||||
return PIPE_STATUS_AVAILABLE;
|
||||
return PIPE_STATUS_READY;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
@ -144,7 +144,7 @@ pipe_status_t pipe_status_get_stub(pipe_handle_t pipe_hdl, int num_call)
|
||||
break;
|
||||
|
||||
default:
|
||||
return PIPE_STATUS_AVAILABLE;
|
||||
return PIPE_STATUS_READY;
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ void test_keyboard_get_report_not_available()
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_AVAILABLE);
|
||||
usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_READY);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
}
|
||||
|
||||
|
@ -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 ,
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user