📄 usbh_hcds_vhub.c
字号:
// return : STATUS_SUCCESS Success
// STATUS_INVALID_PARAMETER Parameter error
========================================================================*/
Inline long ClassClearFeature( DEVICE_REQUEST *psDeviceRequest )
{
long retValue;
if( VHUBStatus.bmFlags.usbState != CONFIGURED_STATE ){
/* Except for Configured State */
return STATUS_INVALID_PARAMETER;
}
if( (psDeviceRequest->bmRequestType & BMREQ_DIR_MASK) != DIR_HOST_TO_DEVICE ){
/* Direction of transfer is different */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wLengthH || psDeviceRequest->wLengthL ){
/* wLength != 0 */
return STATUS_INVALID_PARAMETER;
}
switch( psDeviceRequest->bmRequestType & BMREQ_RECIPIENT_MASK ){
case RECIPIENT_DEVICE:
/* Clear Hub Feature */
if( psDeviceRequest->wIndexH || psDeviceRequest->wIndexL ){
/* wIndex != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wValueH ){
/* wValue.h != 0 */
return STATUS_INVALID_PARAMETER;
}
switch( psDeviceRequest->wValueL ){
case CFEA_C_HUB_LOCAL_POWER:
/* Feature Select = C_HUB_LOCAL_POWER */
/* Clear the change of Local Power Source in the hub change status */
VHUBStatus.sHubStatus.changeStatus &= ~HUBSTS_HUB_LOCAL_POWER;
break;
case CFEA_C_HUB_OVER_CURRENT:
/* Feature Select = C_HUB_OVER_CURRENT */
/* Clear the change of Over-current in the hub change status */
VHUBStatus.sHubStatus.changeStatus &= ~HUBSTS_C_HUB_OVER_CURRENT;
break;
default:
return STATUS_INVALID_PARAMETER;
}
break;
case RECIPIENT_OTHER:
/* Clear Port Feature */
if( psDeviceRequest->wValueH ){
/* wValue.h != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wValueL != CFEA_PORT_INDICATOR ){
if( psDeviceRequest->wIndexH ){
/* wIndex != 0 */
return STATUS_INVALID_PARAMETER;
}
}
switch( psDeviceRequest->wValueL ){
case CFEA_PORT_ENABLE:
/* Feature Select = PORT_ENABLE */
if( (VHUBStatus.sPortStatus.status & PORTSTS_PORT_POWER) != 0 ){
/* The power supply is supplied to the port */
if( (VHUBStatus.sPortStatus.status & PORTSTS_PORT_ENABLE ) != 0 ){
/* The port doesn't become disable */
/* Clear the Port Enable/Disable of port status */
VHUBStatus.sPortStatus.status &= ~PORTSTS_PORT_ENABLE;
/*===========================/
Set the Port to disable /
/===========================*/
retValue = USBH_HCDS_PortControl(USBH_HCDS_PORT_ST_DISABLED);
if( retValue != STATUS_SUCCESS ){
return retValue;
}
}
}
break;
case CFEA_PORT_SUSPEND:
/* Feature Select = PORT_SUSPEND */
if( (VHUBStatus.sPortStatus.status & PORTSTS_PORT_SUSPEND) != 0 ){
/* Port is under suspending */
/*=========================/
Resume the port /
/=========================*/
retValue = USBH_HCDS_PortControl(USBH_HCDS_PORT_ST_RESUMING);
if( retValue != STATUS_SUCCESS ){
return retValue;
}
}
break;
case CFEA_PORT_POWER:
/* Feature Select = PORT_POWER */
/* Clear the Port Power of port status */
VHUBStatus.sPortStatus.status &= ~PORTSTS_PORT_POWER;
/*===============================/
Stop the power supply to the port /
/===============================*/
retValue = USBH_HCDS_PortControl(USBH_HCDS_PORT_ST_POWERED_OFF);
if( retValue != STATUS_SUCCESS ){
return retValue;
}
break;
case CFEA_PORT_INDICATOR:
/* Feature Select = PORT_INDICATOR */
/* Clear the Port Indicator of port status */
VHUBStatus.sPortStatus.status &= ~PORTSTS_PORT_INDICATOR;
/*=======================================/
Do nothing in Port indicator function /
/=======================================*/
break;
case CFEA_C_PORT_CONNECTION:
/* Feature Select = C_PORT_CONNECTION */
/* Clear the change of Port Connection in the port change status */
VHUBStatus.sPortStatus.changeStatus &= ~PORTSTS_C_PORT_CONNECTION;
break;
case CFEA_C_PORT_RESET:
/* Feature Select = C_PORT_RESET */
/* Clear the change of Port Reset in the port change status */
VHUBStatus.sPortStatus.changeStatus &= ~PORTSTS_C_PORT_RESET;
break;
case CFEA_C_PORT_ENABLE:
/* Feature Select = C_PORT_ENABLE */
/* Clear the change of Port Enable in the port change status */
VHUBStatus.sPortStatus.changeStatus &= ~PORTSTS_C_PORT_ENABLE;
break;
case CFEA_C_PORT_SUSPEND:
/* Feature Select = C_PORT_SUSPEND */
/* Clear the change of Port Suspend in the port change status */
VHUBStatus.sPortStatus.changeStatus &= ~PORTSTS_C_PORT_SUSPEND;
break;
case CFEA_C_PORT_OVER_CURRENT:
/* Feature Select = C_PORT_OVER_CURRENT */
/* Clear the change of Port Over-current in the port change status */
VHUBStatus.sPortStatus.changeStatus &= ~PORTSTS_C_PORT_OVER_CURRENT;
break;
default:
return STATUS_INVALID_PARAMETER;
}
break;
default:
return STATUS_INVALID_PARAMETER;
}
return STATUS_SUCCESS;
}
/*======================================================================
// Function_Name: ClassSetFeature
//
// description : Class definition Set Feature request
//
// Process for Set Feature request of Class definition
//
// argument : *psDeviceRequest Pointer of device request
//
// return : STATUS_SUCCESS Success
// STATUS_NOT_READY On executing in Test mode
// STATUS_NOT_IMPLEMENTED Not implemented
// STATUS_INVALID_PARAMETER Parameter error
========================================================================*/
Inline long ClassSetFeature( DEVICE_REQUEST *psDeviceRequest )
{
long retValue;
unsigned short hubChar;
if( VHUBStatus.bmFlags.usbState != CONFIGURED_STATE ){
/* Except for Configured State */
return STATUS_INVALID_PARAMETER;
}
if( (psDeviceRequest->bmRequestType & BMREQ_DIR_MASK) != DIR_HOST_TO_DEVICE ){
/* Direction of transfer is different */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wLengthH || psDeviceRequest->wLengthL ){
/* wLength != 0 */
return STATUS_INVALID_PARAMETER;
}
switch( psDeviceRequest->bmRequestType & BMREQ_RECIPIENT_MASK ){
case RECIPIENT_DEVICE:
/* Set Hub Feature */
/*===================================================/
It makes an error for everything because there is no effective function selector now /
/===================================================*/
return STATUS_INVALID_PARAMETER;
case RECIPIENT_OTHER:
/* Set Port Feature */
if( psDeviceRequest->wValueH ){
/* wValue.h != 0 */
return STATUS_INVALID_PARAMETER;
}
if( (psDeviceRequest->wValueL != CFEA_PORT_INDICATOR) && (psDeviceRequest->wValueL != CFEA_PORT_TEST) ){
if( psDeviceRequest->wIndexH ){
/* wIndex != 0 */
return STATUS_INVALID_PARAMETER;
}
}
switch( psDeviceRequest->wValueL ){
case CFEA_PORT_SUSPEND:
/* Feature Select = PORT_SUSPEND */
if( (VHUBStatus.sPortStatus.status & PORTSTS_PORT_ENABLE) != 0 ){
/* The port is enable */
if( (VHUBStatus.sPortStatus.status & PORTSTS_PORT_SUSPEND) == 0 ){
/* The port is not suspended */
/*===============================/
The port is changed to suspending /
/===============================*/
retValue = USBH_HCDS_PortControl(USBH_HCDS_PORT_ST_SUSPENDING);
if( retValue != STATUS_SUCCESS ){
return retValue;
}
}
}
break;
case CFEA_PORT_RESET:
/* Feature Select = PORT_RESET */
if( (VHUBStatus.sPortStatus.status & PORTSTS_PORT_POWER) != 0 ){
/* The power supply is supplied to the port */
if( (VHUBStatus.sPortStatus.status & PORTSTS_PORT_RESET) == 0 ){
/* The port is not under USB resetting */
/* Set the Port Reset of port status */
VHUBStatus.sPortStatus.status |= PORTSTS_PORT_RESET;
/*================================/
Start the USB reset in the port /
/================================*/
retValue = USBH_HCDS_PortControl(USBH_HCDS_PORT_ST_RESETTING);
if( retValue != STATUS_SUCCESS ){
return retValue;
}
}
}
break;
case CFEA_PORT_POWER:
/* Feature Select = PORT_POWER */
/*=========================/
Register the notification destination of port state change /
/=========================*/
if( VHUBStatus.bmFlags.registerCBR == 0 ){
/* It does when unregistered */
USBH_HCDS_PortRegisterCBR(NotifyPortStateChanged);
VHUBStatus.bmFlags.registerCBR = 1;
}
if( (VHUBStatus.sPortStatus.status & PORTSTS_PORT_POWER) == 0 ){
/* The power supply is not supplied to the port */
/* Set the Port Power of port status */
VHUBStatus.sPortStatus.status |= PORTSTS_PORT_POWER;
/*=============================/
Start the power supply to the port /
/=============================*/
retValue = USBH_HCDS_PortControl(USBH_HCDS_PORT_ST_DISCONNECTED);
if( retValue != STATUS_SUCCESS ){
return retValue;
}
}
break;
case CFEA_PORT_TEST:
/* Feature Select = PORT_TEST */
if( psDeviceRequest->wIndexL != 1 ){
/* Only port 1 is supported */
return STATUS_INVALID_PARAMETER;
}
if( ((VHUBStatus.sPortStatus.status & PORTSTS_PORT_ENABLE) == 0)
|| ((VHUBStatus.sPortStatus.status & PORTSTS_PORT_CONNECTION) == 0)
|| ((VHUBStatus.sPortStatus.status & PORTSTS_PORT_SUSPEND) != 0) ){
/* Execute when port is disable, or when device is unconnected or suspended */
/* Set the Port Test of port status */
VHUBStatus.sPortStatus.status |= (PORTSTS_PORT_TEST | PORTSTS_PORT_HIGH_SPEED);
/*=====================================/
Start to execute with test mode in the port /
/=====================================*/
switch( psDeviceRequest->wIndexH ){
case TEST_J:
case TEST_K:
case TEST_SE0_NAK:
case TEST_PACKET:
case TEST_FORCE_ENABLE:
/* Only confirm that it is a defined test mode */
break;
default:
return STATUS_INVALID_PARAMETER;
}
retValue = USBH_HCDS_PortTestMode(psDeviceRequest->wIndexH, USBH_HCDS_PORT_TEST_ENABLE);
if( retValue != STATUS_SUCCESS ){
return retValue;
}
}
break;
case CFEA_PORT_INDICATOR:
/* Feature Select = PORT_INDICATOR */
hubChar = MAKEWORD(ClassHubDesc[OFFSET_WHUBCHARACTERISTICS], ClassHubDesc[OFFSET_WHUBCHARACTERISTICS + 1]);
if( (hubChar & HUB_CHAR_PORT_INDICATOOR) == 0 ){
/* Port indicator function is unsupported */
return STATUS_INVALID_PARAMETER;
}
/*=======================================/
Do nothing in Port indicator function /
/=======================================*/
/* Set the port indicator of Port status */
VHUBStatus.sPortStatus.status |= PORTSTS_PORT_INDICATOR;
break;
case CFEA_C_PORT_RESET:
/* Feature Select = C_PORT_RESET */
/* Clear the change of Port Reset in the port change status */
VHUBStatus.sPortStatus.changeStatus &= ~PORTSTS_C_PORT_RESET;
break;
case CFEA_C_PORT_ENABLE:
/* Feature Select = C_PORT_ENABLE */
/* Clear the change of Port Enable in the port change status */
VHUBStatus.sPortStatus.changeStatus &= ~PORTSTS_C_PORT_ENABLE;
break;
case CFEA_C_PORT_SUSPEND:
/* Feature Select = C_PORT_SUSPEND */
/* Clear the change of Port Suspend in the port change status */
VHUBStatus.sPortStatus.changeStatus &= ~PORTSTS_C_PORT_SUSPEND;
break;
case CFEA_C_PORT_OVER_CURRENT:
/* Feature Select = C_PORT_OVER_CURRENT */
/* Clear the change of Port Over-current in the port change status */
VHUBStatus.sPortStatus.changeStatus &= ~PORTSTS_C_PORT_OVER_CURRENT;
break;
default:
return STATUS_INVALID_PARAMETER;
}
break;
default:
return STATUS_INVALID_PARAMETER;
}
return STATUS_SUCCESS;
}
/*======================================================================
// Function_Name: ClassGetDescriptor
//
// description : Class definition GetDescriptor request
//
// Process for GetDescriptor request of class definition
//
// argument : *psDeviceRequest Pointer of device request
//
// return : STATUS_SUCCESS Success
// STATUS_INVALID_PARAMETER Error
// STAT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -