📄 usbhubporteventhandler.c
字号:
/* usbHubPortEventHandler.c - Functions for handling the port events *//* Copyright 2003 Wind River Systems, Inc. *//*Modification history--------------------01a,27jun03,nrv Changing the code to WRS standards*//*DESCRIPTIONThis provides the functions for handling the port events. This module is used in conjunction with the Hub Event Handling Module and Bus Manager Module.INCLUDE FILES: usb2/usbOsal.h usb2/usbHst.h usb2/usbHubGlobalVariables.h usb2/usbHubUtility.h usb2/usbHubPortEventHandler.h usb2/ usbHubEventHandler.h*//*INTERNAL ******************************************************************************* * Filename : HUB_PortEventHandler.c * * Copyright : * * THE COPYRIGHT IN THE CONTENTS OF THIS SOFTWARE VEST WITH WIPRO * LIMITED A COMPANY INCORPORATED UNDER THE LAWS OF INDIA AND HAVING * ITS REGISTERED OFFICE AT DODDAKANNELLI SARJAPUR ROAD BANGALORE * 560 035. DISTRIBUTION OR COPYING OF THIS SOFTWARE BY * ANY INDIVIDUAL OR ENTITY OTHER THAN THE ADDRESSEE IS STRICTLY * PROHIBITED AND MAY INCUR LEGAL LIABILITY. IF YOU ARE NOT THE * ADDRESSEE PLEASE NOTIFY US IMMEDIATELY BY PHONE OR BY RETURN EMAIL. * * * THE ADDRESSEE IS ADVISED TO MAINTAIN THE PROPRIETARY INTERESTS OF * THIS COPYRIGHT AS PER APPLICABLE LAWS. * * * Description : This provides the functions for handling the port events. * This module is used in conjunction with the Hub Event * Handling Module and Bus Manager Module. * * ******************************************************************************//************************** INCLUDE FILES *************************************/#include "usb2/usbOsal.h"#include "usb2/usbHst.h"#include "usb2/usbHubGlobalVariables.h"#include "usb2/usbHubUtility.h"#include "usb2/usbHubPortEventHandler.h"#include "usb2/usbHubEventHandler.h"/****************** MODULE SPECIFIC FUNCTIONS DECLARATION *********************//* This function is the handler for the port connection change. */LOCAL USBHST_STATUS usbHubPortConnectChangeHandler ( pUSB_HUB_INFO pHub, UINT8 uPortIndex, pUSB_HUB_PORT_STATUS pPortStatus );/* This function is the handler for the port enable change. */LOCAL USBHST_STATUS usbHubPortEnableChangeHandler ( pUSB_HUB_INFO pHub, UINT8 uPortIndex, pUSB_HUB_PORT_STATUS pPortStatus );/* This function is the handler for the port suspend change. */LOCAL USBHST_STATUS usbHubPortSuspendChangeHandler ( pUSB_HUB_INFO pHub, UINT8 uPortIndex, pUSB_HUB_PORT_STATUS pPortStatus );/* This function is the handler for the port reset state change. */LOCAL USBHST_STATUS usbHubPortResetChangeHandler ( pUSB_HUB_INFO pHub, UINT8 uPortIndex, pUSB_HUB_PORT_STATUS pPortStatus);/* This function is the handler for the port over current change. */LOCAL USBHST_STATUS usbHubPortOverCurrentChangeHandler ( pUSB_HUB_INFO pHub, UINT8 uPortIndex, pUSB_HUB_PORT_STATUS pPortStatus );/************************ GLOBAL FUNCTIONS DEFINITION *************************//***************************************************************************** usbHubPortEventHandler - Handler for any port event that has happened.** This routine handles any port event that has happened.** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETER, USBHST_FAILURE If any event * handler failed.** ERRNO: None* * \NOMANUAL*/LOCAL USBHST_STATUS usbHubPortEventHandler ( pUSB_HUB_INFO pHub, UINT8 uPortIndex ) { /* To store the result of the port status. */ USB_HUB_PORT_STATUS PortStatus; /* To store the length of the transfers */ UINT8 uLength = sizeof(USB_HUB_PORT_STATUS); /* To store the results */ USBHST_STATUS Result; /* For calulation which byte of pStatus to clear */ UINT8 uByteToClear=0; /* To calculate which bit of uByteToClear in pStatus to clear */ UINT8 uBitToClear=0; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_EVENT_HANDLER, "Entering usbHubPortEventHandler() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortEventHandler: Called pHub=0x%x uPortIndex=%d\n", (UINT32)pHub, uPortIndex, 0, 0); /* If pHub is NULL then return USBHST_INVALID_PARAMETER. */ if (NULL == pHub) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubPortEventHandler: pHub NULL\n",0,0,0,0); return USBHST_INVALID_PARAMETER; }/* End of (NULL == pHub) */ /* If pHub::pBus is NULL then return USBHST_INVALID_PARAMETER. */ if (NULL == pHub->pBus) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubPortEventHandler: pHub->pBus NULL\n",0,0,0,0); return USBHST_INVALID_PARAMETER; }/* End of (NULL == pHub->pBus) */ /* * Call the HUB_GET_PORT_STATUS() function to retrieve the HUB_PORT_STATUS * structure. If failed, then return USBHST_FAILURE. * Note: actual port number is 1+ the port index */ Result = USB_HUB_GET_PORT_STATUS(pHub, uPortIndex, (UINT8 *)(&PortStatus), &uLength); if ((USBHST_SUCCESS !=Result)||( uLength != sizeof(USB_HUB_PORT_STATUS)) ) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortEventHandler: Failed GetPortStatus" "res=0x%x, leng=0x%x\n", Result, uLength, 0, 0); return Result; }/* End of if (USBHST_SUCCESS... */ PortStatus.wPortChange = OS_UINT16_LE_TO_CPU(PortStatus.wPortChange); PortStatus.wPortStatus = OS_UINT16_LE_TO_CPU(PortStatus.wPortStatus); /* * Call HUB_IS_CONNECTION_CHANGE() with HUB_PORT_STATUS::wPortChange. If * there is a change in connect status, call HUB_PortConnectChangeHandler() * with HUB_PORT_STATUS structure, pHub and uPortIndex. * If failed, return result. */ if (TRUE == USB_HUB_IS_CONNECTION_CHANGE(PortStatus.wPortChange)) { Result=usbHubPortConnectChangeHandler(pHub, uPortIndex, &PortStatus); if (USBHST_SUCCESS !=Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortEventHandler: Failed port conn hdlr res=0x%x\n", Result, 0, 0, 0); return Result; }/* End of if USBHST_SUCCESS != Result */ }/* End of if TRUE == HUB... */ /* * Call HUB_IS_RESET_CHANGE() with HUB_PORT_STATUS::wPortChange. * If there is a change in reset status, call HUB_PortResetChangeHandler() * with HUB_PORT_STATUS structure, pHub and uPortIndex. * If failed, return result. */ if (TRUE == USB_HUB_IS_RESET_CHANGE(PortStatus.wPortChange)) { Result=usbHubPortResetChangeHandler(pHub, uPortIndex, &PortStatus); if (USBHST_SUCCESS !=Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortEventHandler: Failed reset chg hdlr res=0x%x\n", Result, 0, 0, 0); return Result; }/* End of if USBHST_SUCCESS != Result */ }/* End of if TRUE == HUB... */ /* * Call HUB_IS_ENABLE_CHANGE() with HUB_PORT_STATUS::wPortChange. * If there is a change in enable status, call HUB_PortEnableChangeHandler() * with HUB_PORT_STATUS structure, pHub and uPortIndex. * If failed, return result. */ if (TRUE == USB_HUB_IS_ENABLE_CHANGE(PortStatus.wPortChange)) { Result=usbHubPortEnableChangeHandler(pHub,uPortIndex,&PortStatus); if (USBHST_SUCCESS !=Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortEventHandler: Failed enabl chg hdlr res=0x%x\n", Result, 0, 0, 0); return Result; }/* End of if USBHST_SUCCESS != Result */ }/* End of if TRUE == HUB... */ /* * Call HUB_IS_SUSPEND_CHANGE() with HUB_PORT_STATUS::wPortChange. * If there is a change in suspend status, * call HUB_PortSuspendChangeHandler() with HUB_PORT_STATUS structure, * pHub and uPortIndex. If failed, return result. */ if (TRUE == USB_HUB_IS_SUSPEND_CHANGE(PortStatus.wPortChange)) { Result=usbHubPortSuspendChangeHandler(pHub,uPortIndex,&PortStatus); if (USBHST_SUCCESS !=Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortEventHandler: Failed susp chg hdlr res=0x%x\n", Result, 0, 0, 0); return Result; }/* End of if USBHST_SUCCESS != Result */ }/* End of if TRUE == HUB... */ /* * Call HUB_IS_OVER_CURRENT_CHANGE() with HUB_PORT_STATUS::wPortChange. * If there is a change in over current status, call * HUB_PortOverCurrentChangeHandler() with HUB_PORT_STATUS structure, * pHub and uPortIndex. If failed, return result. */ if (TRUE == USB_HUB_IS_OVER_CURRENT_CHANGE(PortStatus.wPortChange)) { Result=usbHubPortOverCurrentChangeHandler(pHub,uPortIndex,&PortStatus); if (USBHST_SUCCESS !=Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortEventHandler: Failed ovr curr hdlr res=0x%x\n", Result, 0, 0, 0); return Result; }/* End of if USBHST_SUCCESS != Result */ }/* End of if TRUE == HUB... */ /* Clear the port number bit of the pHub::pStatus. (BEGIN) */ /* Find the byte by taking an integer division */ uByteToClear = (uPortIndex+1)/8; /* Find the bit by taking the remainder */ uBitToClear = (uPortIndex+1)%8; /* Clean up the bit */ pHub->pStatus[uByteToClear] = ( pHub->pStatus[uByteToClear]& (~((UINT8)0x1<<(uBitToClear))) ); /* Clear the port number bit of the pHub::pStatus. (END) */ /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_EVENT_HANDLER, "Exiting usbHubPortEventHandler() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortEventHandler: Done pHub=0x%x uPortIndex=%d\n", (UINT32)pHub, uPortIndex, 0, 0); /* Return USBHST_SUCCESS. */ return USBHST_SUCCESS; }/* End of HUB_PortEventHandler() *//******************* MODULE SPECIFIC FUNCTIONS DEFINITION *********************//***************************************************************************** usbHubPortConnectChangeHandler - handler for the connection change.** This routine handles the connection change.** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETER, USBHST_FAILURE If any event* handler failed.** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubPortConnectChangeHandler ( pUSB_HUB_INFO pHub, UINT8 uPortIndex, pUSB_HUB_PORT_STATUS pPortStatus ) { /* Storage for the port information */ pUSB_HUB_PORT_INFO pPort=NULL; /* to store the result of submissions */ USBHST_STATUS Result; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_EVENT_HANDLER, "Entering usbHubPortConnectChangeHandler() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortConnectChangeHandler: Called " "pHub=0x%x uPortIndex=%d pPortStatus=0x%x\n", (UINT32)pHub, uPortIndex, (UINT32)pPortStatus, 0); /* If the pHub is NULL then return USBHST_INVALID_PARAMETER */ if (NULL == pHub) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubPortConnectChangeHandler: pHub is NULL \n",0,0,0,0); return USBHST_INVALID_PARAMETER; }/* End of (NULL == pHub) */ /* * If the uPortIndex greater than pHub::HubDescriptor::bNbrPorts then * return USBHST_INVALID_PARAMETER. * Note: the actual port number is the port index + 1 */ if (uPortIndex >= pHub->HubDescriptor.bNbrPorts) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubPortConnectChangeHandler :port= %d >%d \n", uPortIndex, pHub->HubDescriptor.bNbrPorts, 0, 0); return USBHST_INVALID_PARAMETER; }/* End of if (uPortIndex >= pHub->HubDescriptor.bNbrPorts) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -