mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
refractor hub api
fix all test build errors
This commit is contained in:
parent
3d13516106
commit
de7e21dc66
@ -54,7 +54,7 @@
|
||||
#endif
|
||||
|
||||
void tusbh_cdc_mounted_cb(uint8_t dev_addr);
|
||||
void tusbh_cdc_unmounted_isr(uint8_t dev_addr);
|
||||
void tusbh_cdc_unmounted_cb(uint8_t dev_addr);
|
||||
void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes);
|
||||
|
||||
void tusbh_cdc_rndis_mounted_cb(uint8_t dev_addr);
|
||||
|
@ -195,7 +195,7 @@ void test_cdch_close_device(void)
|
||||
hcd_pipe_close_ExpectAndReturn(pipe_int , TUSB_ERROR_NONE);
|
||||
hcd_pipe_close_ExpectAndReturn(pipe_out , TUSB_ERROR_NONE);
|
||||
|
||||
tusbh_cdc_unmounted_isr_Expect(dev_addr);
|
||||
tusbh_cdc_unmounted_cb_Expect(dev_addr);
|
||||
|
||||
//------------- CUT -------------//
|
||||
cdch_close(dev_addr);
|
||||
|
@ -70,7 +70,7 @@ void tearDown(void)
|
||||
|
||||
void test_isr_device_connect_highspeed(void)
|
||||
{
|
||||
usbh_device_plugged_isr_Expect(hostid);
|
||||
usbh_hcd_rhport_plugged_isr_Expect(hostid);
|
||||
|
||||
//------------- Code Under Test -------------//
|
||||
ehci_controller_device_plug(hostid, TUSB_SPEED_HIGH);
|
||||
@ -78,7 +78,7 @@ void test_isr_device_connect_highspeed(void)
|
||||
|
||||
void test_isr_device_connect_fullspeed(void)
|
||||
{
|
||||
usbh_device_plugged_isr_Expect(hostid);
|
||||
usbh_hcd_rhport_plugged_isr_Expect(hostid);
|
||||
|
||||
//------------- Code Under Test -------------//
|
||||
ehci_controller_device_plug(hostid, TUSB_SPEED_FULL);
|
||||
@ -86,7 +86,7 @@ void test_isr_device_connect_fullspeed(void)
|
||||
|
||||
void test_isr_device_connect_slowspeed(void)
|
||||
{
|
||||
usbh_device_plugged_isr_Expect(hostid);
|
||||
usbh_hcd_rhport_plugged_isr_Expect(hostid);
|
||||
|
||||
//------------- Code Under Test -------------//
|
||||
ehci_controller_device_plug(hostid, TUSB_SPEED_LOW);
|
||||
@ -94,7 +94,7 @@ void test_isr_device_connect_slowspeed(void)
|
||||
|
||||
void test_isr_device_disconnect(void)
|
||||
{
|
||||
usbh_device_unplugged_isr_Expect(hostid);
|
||||
usbh_hcd_rhport_unplugged_isr_Expect(hostid);
|
||||
|
||||
//------------- Code Under Test -------------//
|
||||
ehci_controller_device_unplug(hostid);
|
||||
|
@ -51,6 +51,7 @@
|
||||
|
||||
#include "hcd.h"
|
||||
#include "usbh_hcd.h"
|
||||
#include "hub.h"
|
||||
#include "usbh.h"
|
||||
#include "ehci.h"
|
||||
#include "ehci_controller_fake.h"
|
||||
|
@ -61,11 +61,11 @@
|
||||
//------------- hidh -------------//
|
||||
void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event);
|
||||
void tusbh_hid_keyboard_mounted_cb(uint8_t dev_addr);
|
||||
void tusbh_hid_keyboard_unmounted_isr(uint8_t dev_addr);
|
||||
void tusbh_hid_keyboard_unmounted_cb(uint8_t dev_addr);
|
||||
|
||||
void tusbh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event);
|
||||
void tusbh_hid_mouse_mounted_cb(uint8_t dev_addr);
|
||||
void tusbh_hid_mouse_unmounted_isr(uint8_t dev_addr);
|
||||
void tusbh_hid_mouse_unmounted_cb(uint8_t dev_addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ void test_hidh_close(void)
|
||||
keyboardh_data[dev_addr-1].report_size = 8;
|
||||
|
||||
hcd_pipe_close_ExpectAndReturn(pipe_hdl, TUSB_ERROR_NONE);
|
||||
tusbh_hid_keyboard_unmounted_isr_Expect(dev_addr);
|
||||
tusbh_hid_keyboard_unmounted_cb_Expect(dev_addr);
|
||||
|
||||
//------------- Code Under TEST -------------//
|
||||
hidh_close(dev_addr);
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "mock_osal.h"
|
||||
#include "mock_cdc_host.h"
|
||||
#include "mock_msc_host.h"
|
||||
#include "mock_hub.h"
|
||||
|
||||
#include "mock_hcd.h"
|
||||
#include "usbh.h"
|
||||
|
@ -160,7 +160,7 @@ void test_keyboard_open_ok(void)
|
||||
|
||||
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_TRUE( tusbh_hid_keyboard_is_mounted(dev_addr) );
|
||||
TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, p_hidh_kbd->status);
|
||||
TEST_ASSERT_FALSE( tusbh_hid_keyboard_is_busy(dev_addr) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -196,7 +196,8 @@ void test_keyboard_get_report_xfer_failed()
|
||||
void test_keyboard_get_report_xfer_failed_busy()
|
||||
{
|
||||
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
p_hidh_kbd->status = TUSB_INTERFACE_STATUS_BUSY;
|
||||
hcd_pipe_is_busy_ExpectAndReturn(p_hidh_kbd->pipe_hdl, true);
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INTERFACE_IS_BUSY, tusbh_hid_keyboard_get_report(dev_addr, &report));
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ void test_mouse_open_ok(void)
|
||||
|
||||
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_TRUE( tusbh_hid_mouse_is_mounted(dev_addr) );
|
||||
TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, p_hidh_mouse->status);
|
||||
TEST_ASSERT_FALSE( tusbh_hid_mouse_is_busy(dev_addr) );
|
||||
|
||||
}
|
||||
|
||||
@ -168,7 +168,8 @@ void test_mouse_get_report_xfer_failed()
|
||||
void test_mouse_get_report_xfer_failed_busy()
|
||||
{
|
||||
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
p_hidh_mouse->status = TUSB_INTERFACE_STATUS_BUSY;
|
||||
hcd_pipe_is_busy_ExpectAndReturn(p_hidh_mouse->pipe_hdl, true);
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INTERFACE_IS_BUSY, tusbh_hid_mouse_get_report(dev_addr, &report));
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@
|
||||
#include "common/common.h"
|
||||
|
||||
void tusbh_msc_mounted_cb(uint8_t dev_addr);
|
||||
void tusbh_msc_unmounted_isr(uint8_t dev_addr);
|
||||
void tusbh_msc_unmounted_cb(uint8_t dev_addr);
|
||||
void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes);
|
||||
|
||||
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "mock_osal.h"
|
||||
#include "usbh.h"
|
||||
#include "mock_hcd.h"
|
||||
#include "mock_hub.h"
|
||||
#include "usbh_hcd.h"
|
||||
|
||||
#include "mock_tusb_callback.h"
|
||||
|
@ -43,6 +43,7 @@
|
||||
|
||||
#include "mock_osal.h"
|
||||
#include "usbh.h"
|
||||
#include "mock_hub.h"
|
||||
#include "usbh_hcd.h"
|
||||
#include "mock_hcd.h"
|
||||
|
||||
@ -140,7 +141,7 @@ void test_usbh_init_ok(void)
|
||||
}
|
||||
|
||||
// device is not mounted before, even the control pipe is not open, do nothing
|
||||
void test_usbh_device_unplugged_isr_device_not_previously_mounted(void)
|
||||
void test_usbh_hcd_rhport_unplugged_isr_device_not_previously_mounted(void)
|
||||
{
|
||||
uint8_t dev_addr = 1;
|
||||
|
||||
@ -152,7 +153,7 @@ void test_usbh_device_unplugged_isr_device_not_previously_mounted(void)
|
||||
usbh_hcd_rhport_unplugged_isr(0);
|
||||
}
|
||||
|
||||
void test_usbh_device_unplugged_isr(void)
|
||||
void test_usbh_hcd_rhport_unplugged_isr(void)
|
||||
{
|
||||
uint8_t dev_addr = 1;
|
||||
|
||||
|
@ -45,6 +45,8 @@
|
||||
#include "usbh_hcd.h"
|
||||
#include "ehci.h"
|
||||
|
||||
#include "ehci_controller_fake.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
|
@ -67,11 +67,12 @@
|
||||
//--------------------------------------------------------------------+
|
||||
//------------- CORE -------------//
|
||||
#define TUSB_CFG_HOST_DEVICE_MAX 2
|
||||
#define TUSB_CFG_CONFIGURATION_MAX 2
|
||||
#define TUSB_CFG_CONFIGURATION_MAX 1
|
||||
|
||||
#define TUSB_CFG_HOST_ENUM_BUFFER_SIZE 255
|
||||
|
||||
//------------- CLASS -------------//
|
||||
#define TUSB_CFG_HOST_HUB 1
|
||||
#define TUSB_CFG_HOST_HID_KEYBOARD 1
|
||||
#define TUSB_CFG_HOST_HID_MOUSE 1
|
||||
#define TUSB_CFG_HOST_MSC 1
|
||||
|
@ -564,7 +564,7 @@ static void port_connect_status_change_isr(uint8_t hostid)
|
||||
// NOTE There is an sequence plug->unplug->…..-> plug if device is powering with pre-plugged device
|
||||
if (regs->portsc_bit.current_connect_status)
|
||||
{
|
||||
usbh_hcd_rhport_plugged_isr(hostid, 0, 0);
|
||||
usbh_hcd_rhport_plugged_isr(hostid);
|
||||
}else // device unplugged
|
||||
{
|
||||
usbh_hcd_rhport_unplugged_isr(hostid);
|
||||
@ -573,7 +573,7 @@ static void port_connect_status_change_isr(uint8_t hostid)
|
||||
}
|
||||
|
||||
// TODO refractor abtract later
|
||||
void hcd_hub_advance_asyn(uint8_t hostid)
|
||||
void hcd_port_unplug(uint8_t hostid)
|
||||
{
|
||||
ehci_registers_t* const regs = get_operational_register(hostid);
|
||||
regs->usb_cmd_bit.advacne_async = 1; // Async doorbell check EHCI 4.8.2 for operational details
|
||||
|
@ -99,11 +99,11 @@ tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint
|
||||
tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) /*ATTR_WARN_UNUSED_RESULT*/;
|
||||
|
||||
bool hcd_pipe_is_busy(pipe_handle_t pipe_hdl);
|
||||
bool hcd_pipe_is_error(pipe_handle_t pipe_hdl);
|
||||
bool hcd_pipe_is_stalled(pipe_handle_t pipe_hdl); // stalled also counted as error
|
||||
bool hcd_pipe_is_idle(pipe_handle_t pipe_hdl);
|
||||
uint8_t hcd_pipe_get_endpoint_addr(pipe_handle_t pipe_hdl);
|
||||
bool hcd_pipe_is_busy(pipe_handle_t pipe_hdl) ATTR_PURE;
|
||||
bool hcd_pipe_is_error(pipe_handle_t pipe_hdl) ATTR_PURE;
|
||||
bool hcd_pipe_is_stalled(pipe_handle_t pipe_hdl) ATTR_PURE; // stalled also counted as error
|
||||
bool hcd_pipe_is_idle(pipe_handle_t pipe_hdl) ATTR_PURE;
|
||||
uint8_t hcd_pipe_get_endpoint_addr(pipe_handle_t pipe_hdl) ATTR_PURE;
|
||||
tusb_error_t hcd_pipe_clear_stall(pipe_handle_t pipe_hdl);
|
||||
|
||||
#if 0
|
||||
@ -117,6 +117,7 @@ tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT;
|
||||
bool hcd_port_connect_status(uint8_t hostid) ATTR_PURE ATTR_WARN_UNUSED_RESULT; // TODO make inline if possible
|
||||
void hcd_port_reset(uint8_t hostid);
|
||||
tusb_speed_t hcd_port_speed_get(uint8_t hostid) ATTR_PURE ATTR_WARN_UNUSED_RESULT; // TODO make inline if possible
|
||||
void hcd_port_unplug(uint8_t hostid); // called by usbh to instruct hcd that it can execute unplug procedure
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -46,7 +46,7 @@
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "hub.h"
|
||||
#include "usbh_hcd.h"
|
||||
#include "usbh_hub.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
@ -209,8 +209,7 @@ void hub_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes)
|
||||
{ // TODO HUB ignore bit0 hub_status_change
|
||||
if ( BIT_TEST_(p_hub->status_change, port) )
|
||||
{
|
||||
// TODO HUB connection/disconnection will be determined in enum task --> connect change
|
||||
usbh_hcd_rhport_plugged_isr(usbh_devices[pipe_hdl.dev_addr].core_id, pipe_hdl.dev_addr, port);
|
||||
usbh_hub_port_plugged_isr(pipe_hdl.dev_addr, port);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,6 +182,11 @@ typedef struct {
|
||||
|
||||
STATIC_ASSERT( sizeof(hub_port_status_response_t) == 4, "size is not correct");
|
||||
|
||||
tusb_error_t hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port);
|
||||
tusb_error_t hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t feature);
|
||||
tusb_speed_t hub_port_get_speed(void);
|
||||
tusb_error_t hub_status_pipe_queue(uint8_t dev_addr);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBH-CLASS DRIVER API
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -273,19 +273,29 @@ void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t even
|
||||
}
|
||||
}
|
||||
|
||||
void usbh_hcd_rhport_plugged_isr(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port)
|
||||
void usbh_hub_port_plugged_isr(uint8_t hub_addr, uint8_t hub_port)
|
||||
{
|
||||
osal_queue_send(enum_queue_hdl,
|
||||
&(usbh_enumerate_t){
|
||||
.core_id = hostid,
|
||||
.core_id = usbh_devices[hub_addr].core_id,
|
||||
.hub_addr = hub_addr,
|
||||
.hub_port = hub_port}
|
||||
);
|
||||
}
|
||||
|
||||
void usbh_hcd_rhport_plugged_isr(uint8_t hostid)
|
||||
{
|
||||
osal_queue_send(enum_queue_hdl,
|
||||
&(usbh_enumerate_t){
|
||||
.core_id = hostid,
|
||||
.hub_addr = 0,
|
||||
.hub_port = 0}
|
||||
);
|
||||
}
|
||||
|
||||
// a device unplugged on hostid, hub_addr, hub_port
|
||||
// return true if found and unmounted device, false if cannot find
|
||||
void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port)
|
||||
static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port)
|
||||
{
|
||||
bool is_found = false;
|
||||
//------------- find the all devices (star-network) under port that is unplugged -------------//
|
||||
@ -316,7 +326,7 @@ void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port)
|
||||
}
|
||||
}
|
||||
|
||||
if (is_found) hcd_hub_advance_asyn(usbh_devices[0].core_id); // TODO hack
|
||||
if (is_found) hcd_port_unplug(usbh_devices[0].core_id); // TODO hack
|
||||
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ extern usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; // including
|
||||
// callback from HCD ISR
|
||||
//--------------------------------------------------------------------+
|
||||
void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void usbh_hcd_rhport_plugged_isr(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port);
|
||||
void usbh_hcd_rhport_plugged_isr(uint8_t hostid);
|
||||
void usbh_hcd_rhport_unplugged_isr(uint8_t hostid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
68
tinyusb/host/usbh_hub.h
Normal file
68
tinyusb/host/usbh_hub.h
Normal file
@ -0,0 +1,68 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file usbh_hub.h
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, hathach (tinyusb.org)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This file is part of the tinyusb stack.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
/** \ingroup TBD
|
||||
* \defgroup TBD
|
||||
* \brief TBD
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_USBH_HUB_H_
|
||||
#define _TUSB_USBH_HUB_H_
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "common/common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
void usbh_hub_port_plugged_isr(uint8_t hub_addr, uint8_t hub_port);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_USBH_HUB_H_ */
|
||||
|
||||
/** @} */
|
Loading…
x
Reference in New Issue
Block a user