document hub

This commit is contained in:
hathach 2013-10-24 17:00:04 +07:00
parent 5f584384eb
commit b1142ff065
1 changed files with 212 additions and 209 deletions

View File

@ -1,209 +1,212 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file hub.h @file hub.h
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
/** \ingroup TBD /** \addtogroup ClassDriver
* \defgroup TBD * @{
* \brief TBD * \defgroup ClassDriver_Hub Hub (Host)
* * \details Like most PC's OS, Hub support is completely hidden from Application. In fact, application cannot determine whether
* @{ * a device is mounted directly via roothub or via a hub's port. All Hub-related procedures are performed and managed
*/ * by tinyusb stack. Unless you are trying to develop the stack itself, there are nothing else can be used by Application.
* \note Due to my laziness, only 1-level of Hub is supported. In other way, the stack cannot mount a hub via another hub.
#ifndef _TUSB_HUB_H_ * @{
#define _TUSB_HUB_H_ */
#include "common/common.h" #ifndef _TUSB_HUB_H_
#include "usbh.h" #define _TUSB_HUB_H_
#ifdef __cplusplus #include "common/common.h"
extern "C" { #include "usbh.h"
#endif
#ifdef __cplusplus
//D1...D0: Logical Power Switching Mode extern "C" {
//00: Ganged power switching (all portspower at #endif
//once)
//01: Individual port power switching //D1...D0: Logical Power Switching Mode
//1X: Reserved. Used only on 1.0 compliant hubs //00: Ganged power switching (all portspower at
//that implement no power switching //once)
//D2: Identifies a Compound Device //01: Individual port power switching
//0: Hub is not part of a compound device. //1X: Reserved. Used only on 1.0 compliant hubs
//1: Hub is part of a compound device. //that implement no power switching
//D4...D3: Over-current Protection Mode //D2: Identifies a Compound Device
//00: Global Over-current Protection. The hub //0: Hub is not part of a compound device.
//reports over-current as a summation of all //1: Hub is part of a compound device.
//portscurrent draw, without a breakdown of //D4...D3: Over-current Protection Mode
//individual port over-current status. //00: Global Over-current Protection. The hub
//01: Individual Port Over-current Protection. The //reports over-current as a summation of all
//hub reports over-current on a per-port basis. //portscurrent draw, without a breakdown of
//Each port has an over-current status. //individual port over-current status.
//1X: No Over-current Protection. This option is //01: Individual Port Over-current Protection. The
//allowed only for bus-powered hubs that do not //hub reports over-current on a per-port basis.
//implement over-current protection. //Each port has an over-current status.
// //1X: No Over-current Protection. This option is
//D6...D5: TT Think TIme //allowed only for bus-powered hubs that do not
//00: TT requires at most 8 FS bit times of inter //implement over-current protection.
//transaction gap on a full-/low-speed //
//downstream bus. //D6...D5: TT Think TIme
//01: TT requires at most 16 FS bit times. //00: TT requires at most 8 FS bit times of inter
//10: TT requires at most 24 FS bit times. //transaction gap on a full-/low-speed
//11: TT requires at most 32 FS bit times. //downstream bus.
//D7: Port Indicators Supported //01: TT requires at most 16 FS bit times.
//0: Port Indicators are not supported on its //10: TT requires at most 24 FS bit times.
//downstream facing ports and the //11: TT requires at most 32 FS bit times.
//PORT_INDICATOR request has no effect. //D7: Port Indicators Supported
//1: Port Indicators are supported on its //0: Port Indicators are not supported on its
//downstream facing ports and the //downstream facing ports and the
//PORT_INDICATOR request controls the //PORT_INDICATOR request has no effect.
//indicators. See Section 11.5.3. //1: Port Indicators are supported on its
//D15...D8: Reserved //downstream facing ports and the
//PORT_INDICATOR request controls the
typedef ATTR_PACKED_STRUCT(struct){ //indicators. See Section 11.5.3.
uint8_t bLength ; ///< Size of descriptor //D15...D8: Reserved
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
uint8_t bNbrPorts; typedef ATTR_PACKED_STRUCT(struct){
uint16_t wHubCharacteristics; uint8_t bLength ; ///< Size of descriptor
uint8_t bPwrOn2PwrGood; uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
uint8_t bHubContrCurrent; uint8_t bNbrPorts;
uint8_t DeviceRemovable; // bitmap each bit for a port (from bit1) uint16_t wHubCharacteristics;
uint8_t PortPwrCtrlMask; // just for compatibility, should be 0xff uint8_t bPwrOn2PwrGood;
} descriptor_hub_desc_t; uint8_t bHubContrCurrent;
uint8_t DeviceRemovable; // bitmap each bit for a port (from bit1)
STATIC_ASSERT( sizeof(descriptor_hub_desc_t) == 9, "size is not correct"); uint8_t PortPwrCtrlMask; // just for compatibility, should be 0xff
} descriptor_hub_desc_t;
enum {
HUB_REQUEST_GET_STATUS = 0 , STATIC_ASSERT( sizeof(descriptor_hub_desc_t) == 9, "size is not correct");
HUB_REQUEST_CLEAR_FEATURE = 1 ,
enum {
HUB_REQUEST_SET_FEATURE = 3 , HUB_REQUEST_GET_STATUS = 0 ,
HUB_REQUEST_CLEAR_FEATURE = 1 ,
HUB_REQUEST_GET_DESCRIPTOR = 6 ,
HUB_REQUEST_SET_DESCRIPTOR = 7 , HUB_REQUEST_SET_FEATURE = 3 ,
HUB_REQUEST_CLEAR_TT_BUFFER = 8 ,
HUB_REQUEST_RESET_TT = 9 , HUB_REQUEST_GET_DESCRIPTOR = 6 ,
HUB_REQUEST_GET_TT_STATE = 10 , HUB_REQUEST_SET_DESCRIPTOR = 7 ,
HUB_REQUEST_STOP_TT = 11 HUB_REQUEST_CLEAR_TT_BUFFER = 8 ,
}; HUB_REQUEST_RESET_TT = 9 ,
HUB_REQUEST_GET_TT_STATE = 10 ,
enum { HUB_REQUEST_STOP_TT = 11
HUB_FEATURE_HUB_LOCAL_POWER_CHANGE = 0, };
HUB_FEATURE_HUB_OVER_CURRENT_CHANGE
}; enum {
HUB_FEATURE_HUB_LOCAL_POWER_CHANGE = 0,
enum{ HUB_FEATURE_HUB_OVER_CURRENT_CHANGE
HUB_FEATURE_PORT_CONNECTION = 0, };
HUB_FEATURE_PORT_ENABLE = 1,
HUB_FEATURE_PORT_SUSPEND = 2, enum{
HUB_FEATURE_PORT_OVER_CURRENT = 3, HUB_FEATURE_PORT_CONNECTION = 0,
HUB_FEATURE_PORT_RESET = 4, HUB_FEATURE_PORT_ENABLE = 1,
HUB_FEATURE_PORT_SUSPEND = 2,
HUB_FEATURE_PORT_POWER = 8, HUB_FEATURE_PORT_OVER_CURRENT = 3,
HUB_FEATURE_PORT_LOW_SPEED = 9, HUB_FEATURE_PORT_RESET = 4,
HUB_FEATURE_PORT_CONNECTION_CHANGE = 16, HUB_FEATURE_PORT_POWER = 8,
HUB_FEATURE_PORT_ENABLE_CHANGE = 17, HUB_FEATURE_PORT_LOW_SPEED = 9,
HUB_FEATURE_PORT_SUSPEND_CHANGE = 18,
HUB_FEATURE_PORT_OVER_CURRENT_CHANGE = 19, HUB_FEATURE_PORT_CONNECTION_CHANGE = 16,
HUB_FEATURE_PORT_RESET_CHANGE = 20, HUB_FEATURE_PORT_ENABLE_CHANGE = 17,
HUB_FEATURE_PORT_TEST = 21, HUB_FEATURE_PORT_SUSPEND_CHANGE = 18,
HUB_FEATURE_PORT_INDICATOR = 22 HUB_FEATURE_PORT_OVER_CURRENT_CHANGE = 19,
}; HUB_FEATURE_PORT_RESET_CHANGE = 20,
HUB_FEATURE_PORT_TEST = 21,
// data in response of HUB_REQUEST_GET_STATUS, wIndex = 0 (hub) HUB_FEATURE_PORT_INDICATOR = 22
typedef struct { };
union{
ATTR_PACKED_STRUCT(struct) { // data in response of HUB_REQUEST_GET_STATUS, wIndex = 0 (hub)
uint16_t local_power_source : 1; typedef struct {
uint16_t over_current : 1; union{
uint16_t : 14; ATTR_PACKED_STRUCT(struct) {
}; uint16_t local_power_source : 1;
uint16_t over_current : 1;
uint16_t value; uint16_t : 14;
} status, status_change; };
} hub_status_response_t;
uint16_t value;
STATIC_ASSERT( sizeof(hub_status_response_t) == 4, "size is not correct"); } status, status_change;
} hub_status_response_t;
// data in response of HUB_REQUEST_GET_STATUS, wIndex = Port num
typedef struct { STATIC_ASSERT( sizeof(hub_status_response_t) == 4, "size is not correct");
union {
ATTR_PACKED_STRUCT(struct) { // data in response of HUB_REQUEST_GET_STATUS, wIndex = Port num
uint16_t connect_status : 1; typedef struct {
uint16_t port_enable : 1; union {
uint16_t suspend : 1; ATTR_PACKED_STRUCT(struct) {
uint16_t over_current : 1; uint16_t connect_status : 1;
uint16_t reset : 1; uint16_t port_enable : 1;
uint16_t suspend : 1;
uint16_t : 3; uint16_t over_current : 1;
uint16_t port_power : 1; uint16_t reset : 1;
uint16_t low_speed_device_attached : 1;
uint16_t high_speed_device_attached : 1; uint16_t : 3;
uint16_t port_test_mode : 1; uint16_t port_power : 1;
uint16_t port_indicator_control : 1; uint16_t low_speed_device_attached : 1;
uint16_t : 0; uint16_t high_speed_device_attached : 1;
}; uint16_t port_test_mode : 1;
uint16_t port_indicator_control : 1;
uint16_t value; uint16_t : 0;
} status_current, status_change; };
} hub_port_status_response_t;
uint16_t value;
STATIC_ASSERT( sizeof(hub_port_status_response_t) == 4, "size is not correct"); } status_current, status_change;
} hub_port_status_response_t;
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); STATIC_ASSERT( sizeof(hub_port_status_response_t) == 4, "size is not correct");
tusb_speed_t hub_port_get_speed(void);
tusb_error_t hub_status_pipe_queue(uint8_t dev_addr); 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);
// USBH-CLASS DRIVER API tusb_error_t hub_status_pipe_queue(uint8_t dev_addr);
//--------------------------------------------------------------------+
#ifdef _TINY_USB_SOURCE_FILE_ //--------------------------------------------------------------------+
// USBH-CLASS DRIVER API
void hub_init(void); //--------------------------------------------------------------------+
tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; #ifdef _TINY_USB_SOURCE_FILE_
void hub_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes);
void hub_close(uint8_t dev_addr); void hub_init(void);
tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
tusb_error_t hub_status_pipe_queue(uint8_t dev_addr); void hub_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes);
#endif void hub_close(uint8_t dev_addr);
#ifdef __cplusplus tusb_error_t hub_status_pipe_queue(uint8_t dev_addr);
} #endif
#endif
#ifdef __cplusplus
#endif /* _TUSB_HUB_H_ */ }
#endif
/** @} */
#endif /* _TUSB_HUB_H_ */
/** @} */