Преглед изворни кода

clean up, update tests for hcd_port_reset after 8 byte descriptor & set configure before open class driver

hathach пре 13 година
родитељ
комит
fcb8e295ec
4 измењених фајлова са 14 додато и 28 уклоњено
  1. 9 7
      tests/test/host/test_enum_task.c
  2. 2 17
      tinyusb/host/ehci/ehci.c
  3. 1 2
      tinyusb/host/usbh.c
  4. 2 2
      tinyusb/osal/osal_common.h

+ 9 - 7
tests/test/host/test_enum_task.c

@@ -156,7 +156,7 @@ tusb_error_t control_xfer_stub(uint8_t dev_addr, const tusb_std_request_t * cons
   return TUSB_ERROR_NONE;
   return TUSB_ERROR_NONE;
 }
 }
 
 
-tusb_error_t hidh_install_stub(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length, int num_call)
+tusb_error_t hidh_install_stub(uint8_t dev_addr, tusb_descriptor_interface_t const *descriptor, uint16_t *p_length, int num_call)
 {
 {
   *p_length = sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t);
   *p_length = sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t);
   return TUSB_ERROR_NONE;
   return TUSB_ERROR_NONE;
@@ -179,6 +179,7 @@ void test_addr0_failed_dev_desc(void)
 void test_addr0_failed_set_address(void)
 void test_addr0_failed_set_address(void)
 {
 {
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(1));
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(1));
+  hcd_port_reset_Expect( usbh_devices[0].core_id );
   tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL);
   tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL);
 
 
   usbh_enumeration_task();
   usbh_enumeration_task();
@@ -190,7 +191,7 @@ void test_addr0_failed_set_address(void)
 void test_enum_failed_get_full_dev_desc(void)
 void test_enum_failed_get_full_dev_desc(void)
 {
 {
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(2));
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(2));
-
+  hcd_port_reset_Expect( usbh_devices[0].core_id );
   hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
   hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
 
 
   osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
   osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
@@ -199,8 +200,6 @@ void test_enum_failed_get_full_dev_desc(void)
 
 
   usbh_enumeration_task();
   usbh_enumeration_task();
 
 
-  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_DEVICE_STATE_ADDRESSED, usbh_devices[1].state);
   TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_devices[1].speed);
   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.core_id, usbh_devices[1].core_id);
@@ -211,7 +210,7 @@ void test_enum_failed_get_full_dev_desc(void)
 void test_enum_failed_get_9byte_config_desc(void)
 void test_enum_failed_get_9byte_config_desc(void)
 {
 {
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(3));
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(3));
-
+  hcd_port_reset_Expect( usbh_devices[0].core_id );
   hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
   hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
   osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
   osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
   hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
   hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
@@ -228,6 +227,7 @@ void test_enum_failed_get_9byte_config_desc(void)
 void test_enum_failed_get_full_config_desc(void)
 void test_enum_failed_get_full_config_desc(void)
 {
 {
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(4));
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(4));
+  hcd_port_reset_Expect( usbh_devices[0].core_id );
   hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
   hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
   osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
   osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
   hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
   hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
@@ -245,23 +245,23 @@ void class_install_expect(void)
 void test_enum_parse_config_desc(void)
 void test_enum_parse_config_desc(void)
 {
 {
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(5));
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(5));
+  hcd_port_reset_Expect( usbh_devices[0].core_id );
   hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
   hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
   osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
   osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
   hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
   hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
   tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1);
   tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1);
 
 
-  class_install_expect();
   tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); // fail to set configure
   tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); // fail to set configure
 
 
   usbh_enumeration_task();
   usbh_enumeration_task();
 
 
   TEST_ASSERT_EQUAL(desc_configuration.configuration.bNumInterfaces, usbh_devices[1].interface_count);
   TEST_ASSERT_EQUAL(desc_configuration.configuration.bNumInterfaces, usbh_devices[1].interface_count);
-  TEST_ASSERT_EQUAL(TUSB_CLASS_FLAG_HID, usbh_devices[1].flag_supported_class); // TODO change later
 }
 }
 
 
 void test_enum_set_configure(void)
 void test_enum_set_configure(void)
 {
 {
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(6));
   osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(6));
+  hcd_port_reset_Expect( usbh_devices[0].core_id );
   hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
   hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
   osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
   osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
   hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
   hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
@@ -271,4 +271,6 @@ void test_enum_set_configure(void)
   tusbh_device_mount_succeed_cb_Expect(1);
   tusbh_device_mount_succeed_cb_Expect(1);
 
 
   usbh_enumeration_task();
   usbh_enumeration_task();
+
+  TEST_ASSERT_EQUAL(TUSB_CLASS_FLAG_HID, usbh_devices[1].flag_supported_class); // TODO change later
 }
 }

+ 2 - 17
tinyusb/host/ehci/ehci.c

@@ -414,6 +414,8 @@ void async_advance_isr(ehci_qhd_t * const async_head)
     async_head->is_removing = 0;
     async_head->is_removing = 0;
     async_head->p_qtd_list_head = async_head->p_qtd_list_tail = NULL;
     async_head->p_qtd_list_head = async_head->p_qtd_list_tail = NULL;
     async_head->qtd_overlay.halted = 1;
     async_head->qtd_overlay.halted = 1;
+
+    usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG;
   }
   }
 
 
   for(uint8_t relative_dev_addr=0; relative_dev_addr < TUSB_CFG_HOST_DEVICE_MAX; relative_dev_addr++)
   for(uint8_t relative_dev_addr=0; relative_dev_addr < TUSB_CFG_HOST_DEVICE_MAX; relative_dev_addr++)
@@ -439,23 +441,6 @@ void async_advance_isr(ehci_qhd_t * const async_head)
       }
       }
       // TODO free all itd & sitd
       // TODO free all itd & sitd
     }
     }
-
-//    // check if any other endpoints in pool is removing
-//    for (uint8_t i=0; i<EHCI_MAX_QHD; i++)
-//    {
-//      ehci_qhd_t *p_qhd = &ehci_data.device[relative_dev_addr].qhd[i];
-//      if (p_qhd->is_removing)
-//      {
-//        p_qhd->used        = 0;
-//        p_qhd->is_removing = 0;
-//
-//        while(p_qhd->p_qtd_list_head != NULL) // remove all TDs
-//        {
-//          p_qhd->p_qtd_list_head->used = 0; // free QTD
-//          qtd_remove_1st_from_qhd(p_qhd);
-//        }
-//      }
-//    }// end qhd list loop
   } // end for device[] loop
   } // end for device[] loop
 }
 }
 
 

+ 1 - 2
tinyusb/host/usbh.c

@@ -314,10 +314,9 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
   usbh_devices[new_addr].hub_addr = usbh_devices[0].hub_addr;
   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].hub_port = usbh_devices[0].hub_port;
   usbh_devices[new_addr].speed    = usbh_devices[0].speed;
   usbh_devices[new_addr].speed    = usbh_devices[0].speed;
-  usbh_devices[new_addr].state   = TUSB_DEVICE_STATE_ADDRESSED;
+  usbh_devices[new_addr].state    = TUSB_DEVICE_STATE_ADDRESSED;
 
 
   usbh_pipe_control_close(0);
   usbh_pipe_control_close(0);
-  usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG;
 
 
   // open control pipe for new address
   // open control pipe for new address
   TASK_ASSERT_STATUS ( usbh_pipe_control_open(new_addr, ((tusb_descriptor_device_t*) enum_data_buffer)->bMaxPacketSize0 ) );
   TASK_ASSERT_STATUS ( usbh_pipe_control_open(new_addr, ((tusb_descriptor_device_t*) enum_data_buffer)->bMaxPacketSize0 ) );

+ 2 - 2
tinyusb/osal/osal_common.h

@@ -59,8 +59,8 @@
 
 
 enum
 enum
 {
 {
-  OSAL_TIMEOUT_NOTIMEOUT = 0, // for use within ISR,  return immediately
-  OSAL_TIMEOUT_NORMAL = 10, // default is 10 msec
+  OSAL_TIMEOUT_NOTIMEOUT    = 0,  // for use within ISR,  return immediately
+  OSAL_TIMEOUT_NORMAL       = 10, // default is 10 msec
   OSAL_TIMEOUT_WAIT_FOREVER = 0x0EEEEEEE
   OSAL_TIMEOUT_WAIT_FOREVER = 0x0EEEEEEE
 };
 };