?? device.c
字號:
/* device.c - USBD device management functionality *//* Copyright 2004 Wind River Systems, Inc. This software includes software licensed to Wind River Systems, Inc. by Wipro, Ltd. Wind River licensees may use this software according to the terms of their Wind River license agreement(s) applicable to this software.*//*Modification history--------------------01b,11oct04,ami Apigen Changes01a,23jun03,cfc Changing the code to WRS standards*//*DESCRIPTIONDevice manager provides for handling Plug & Play and PowerManagement. The Device Manager provides the interfaces forthe following functionality:1. Handle device connection and disconnection.2. Configure a newly attached device.3. Handle device suspend and resume.4. Interfaces for the client software to selectively suspend or resume a device. This file is included by the usbd.c source file.INCLUDE FILES: none*//*INTERNAL ******************************************************************************* * Filename : DeviceManager.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 : Device manager provides for handling Plug & Play and Power * Management. The Device Manager provides the interfaces for * the following functionality: * * 1. Handle device connection and disconnection. * 2. Configure a newly attached device. * 3. Handle device suspend and resume. * 4. Interfaces for the client software to selectively * suspend or resume a device. * * ******************************************************************************//***************************************************************************** usbdLinkDeviceInfo - links specified device information to the specified bus.** This routine links the specified device information to the specified bus.** RETURNS: N/A** ERRNO: None* * \NOMANUAL*/LOCAL void usbdLinkDeviceInfo ( UINT8 uBusIndex, /* Bus index link to device info */ pUSBD_DEVICE_INFO pDeviceInfo /* Ptr to device info */ ) { OS_LOG_MESSAGE_LOW(USBD, "Entering usbdLinkDeviceInfo() Function.\n", 0, 0, 0, 0); /* Lock the bus before modifying the list */ OS_WAIT_FOR_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock, OS_WAIT_INFINITE); /* Insert pDeviceInfo to the head of the bus device info list */ pDeviceInfo->pNextUSBDeviceInfo = gUSBBusInfoList[uBusIndex].pUSBDeviceInfoList; /* Head of Bus device info list points to the new pDeviceInfo */ gUSBBusInfoList[uBusIndex].pUSBDeviceInfoList = pDeviceInfo; /* Release the bus lock */ OS_RELEASE_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock); OS_LOG_MESSAGE_LOW(USBD, "Exiting usbdLinkDeviceInfo() Function.\n", 0, 0, 0, 0); return; } /* End of function usbdLinkDeviceInfo *//***************************************************************************** usbdUlinkDeviceInfo - unlinks specified device information.** This routine unlinkes the specified device information.** RETURNS: N/A** ERRNO: None** \NOMANUAL*/LOCAL void usbdUlinkDeviceInfo ( UINT8 uBusIndex, /* Bus index link to device info */ pUSBD_DEVICE_INFO pDeviceInfo /* Ptr to device info */ ) { /* To store device info */ pUSBD_DEVICE_INFO pTemp = NULL; OS_LOG_MESSAGE_LOW(USBD, "Entering usbdUlinkDeviceInfo() Function.\n", 0, 0, 0, 0); /* Initialize with the device info list of the bus */ pTemp = gUSBBusInfoList[uBusIndex].pUSBDeviceInfoList; if ((pTemp == NULL) || (pDeviceInfo == NULL)) { OS_LOG_MESSAGE_HIGH(USBD, "USBD_UNLINK_DEVICE_INFO() Failed. Invalid paramter\n", 0, 0, 0, 0); return; } /* * If the pDeviceInfo is the first element in the list * then store the next device info into pTemp. Else * parse the entire list to find pDeviceInfo. */ if (pTemp == pDeviceInfo) { /* Lock the bus before modifying the list */ OS_WAIT_FOR_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock, OS_WAIT_INFINITE); /* Move the list head to next position */ pTemp = pTemp->pNextUSBDeviceInfo; /* Update the global device list info head */ gUSBBusInfoList[uBusIndex].pUSBDeviceInfoList = pTemp; /* Release the bus lock */ OS_RELEASE_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock); } else { /* Find pDeviceInfo in the list pTemp */ while (pTemp != NULL) { if (pTemp->pNextUSBDeviceInfo == pDeviceInfo) { /* if pDeviceInfo found then break the loop */ break; } /* Store the next device info in the list to pTemp */ pTemp = pTemp->pNextUSBDeviceInfo; } /* End of WHILE loop */ /* If matching element is found then remove the element from the list*/ if (pTemp != NULL) { /* Lock the bus before modifying the list */ OS_WAIT_FOR_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock, OS_WAIT_INFINITE); /* * Store the next device info of the element to be removed into the * previous element's next device info. */ pTemp->pNextUSBDeviceInfo = pTemp->pNextUSBDeviceInfo->pNextUSBDeviceInfo; /* Release the bus lock */ OS_RELEASE_EVENT(gUSBBusInfoList[uBusIndex].busOperationLock); } /* End of IF pTemp is NULL check */ } /* End of else case of IF pTemp is pDeviceInfo */ OS_LOG_MESSAGE_LOW(USBD, "Exiting usbdUlinkDeviceInfo() Function.\n", 0, 0, 0, 0); return; } /* End of function usbdUlinkDeviceInfo *//***************************************************************************** usbdGenerateDeviceHandle - generates unique device handle for USB device ** This routine generates a unique device handle for USB device.** RETURNS: N/A** ERRNO: None** \NOMANUAL*/LOCAL void usbdGenerateDeviceHandle ( UINT32 *pHandle, /* Ptr to generated handle */ UINT8 uBusIndex, /* Bus Index */ UINT8 uDeviceAddress /* Address of the device */ ) { OS_LOG_MESSAGE_LOW(USBD, "Entering usbdGenerateDeviceHandle() Function.\n", 0, 0, 0, 0); /* * Generate the device handle with first lower byte as device address and * second lower byte as bus index */ *pHandle = (uBusIndex << 8) | uDeviceAddress; OS_LOG_MESSAGE_LOW(USBD, "Exiting usbdGenerateDeviceHandle() Function.\n", 0, 0, 0, 0); return; } /* End of function usbdGenerateDeviceHandle *//***************************************************************************** usbdTranslateDeviceHandle - translate device handle to USB device information** This routine translates a device handle to USB device information.** RETURNS: N/A** ERRNO: None* * \NOMANUAL*/LOCAL void usbdTranslateDeviceHandle ( UINT32 uHandle, /* Dev handle to translate */ pUSBD_DEVICE_INFO *pDeviceInfo /* Ptr to hold translated dev info */ ) { UINT8 uBusIndex = 0; /* To store bus index */ UINT8 uDeviceAddress = 0; /* To store device address */ pUSBD_DEVICE_INFO pTemp = NULL; /* To store device info */ OS_LOG_MESSAGE_LOW(USBD, "Entering usbdTranslateDeviceHandle() Function.\n", 0, 0, 0, 0); /* Initialize device info to NULL */ *pDeviceInfo = NULL; if (((uHandle) == 0) || (((uHandle) >> 16) != 0)) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbdTranslateDeviceHandle() Failed: Invalid parameter.\n", 0, 0, 0, 0); return; } /* From device handle get the bus index which is the second lower byte */ uBusIndex = (uHandle & 0x0000FF00) >> 8; /* From device handle get the device address which is first lower byte */ uDeviceAddress = uHandle & 0x000000FF; /* Check if the bus index is valid */ if (USBD_MAX_BUS_NUM > uBusIndex) { /* Initialize pTemp with the device list of the bus */ pTemp = gUSBBusInfoList[uBusIndex].pUSBDeviceInfoList; /* Find the matching device info from the device list */ while (pTemp != NULL) { /* Check if the device address and bus index of the device matches*/ if ((pTemp->uDeviceAddress == uDeviceAddress) && (pTemp->uBusIndex == uBusIndex)) { /* If match is found then break the loop */ break; } /* Since the match is not found move the pointer to next device */ pTemp = pTemp->pNextUSBDeviceInfo; } /* End of WHILE loop */ /* Store the match found in pDeviceInfo */ *pDeviceInfo = pTemp; } /* End of IF */ OS_LOG_MESSAGE_LOW(USBD, "Exiting usbdTranslateDeviceHandle() Function.\n", 0, 0, 0, 0); return; } /* End of function usbdTranslateDeviceHandle *//***************************************************************************** usbdGetFreeAddress - gets the free address in the given bus** This function is used to get a free address in the given bus** RETURNS: USBHST_SUCCESS, USBHST_FAILURE if no free address is found** ERRNO: None* * \NOMANUAL*/LOCAL USBHST_STATUS usbdGetFreeAddress ( UINT8 uBusIndex, /* Bus Index which device is connected */ UINT8 *pAddress /* Ptr to free available address */ ) { UINT8 uOuterIndex = 0; /* Loop counter for byte pos in address map */ UINT8 uInnerIndex = 0; /* Loop counter for bit pos in byte of address map */ UINT8 uPower = 0; /* bit position within a byte */ OS_LOG_MESSAGE_LOW(USBD, "Entering usbdGetFreeAddress() Function.\n", 0, 0, 0, 0);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -