⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbpegasusend.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    switch (attachAction)	{	case USBD_DYNA_ATTACH :		    /* a new device is found */	    PEGASUS_LOG (PEGASUS_DBG_ATTACH, "New Device found : %0x Class "			"%0x Subclass %0x Protocol %0x Configuration "			"%0x Interface  %0x nodeId \n", deviceClass,			deviceSubClass, deviceProtocol, configuration,			interface, (UINT)nodeId);	    /* First Ensure that this device is not already on the list */		    if (pegasusFindDevice (nodeId) != NULL)		{		PEGASUS_LOG (PEGASUS_DBG_ATTACH, "Device already exists, \n",		    0, 0, 0, 0, 0, 0);	        break;		}	    /* Now, we have to ensure that its a PEGASUS device */	            if (usbdDescriptorGet (pegasusHandle, 					   nodeId, 				   USB_RT_STANDARD | USB_RT_DEVICE, 				   USB_DESCR_DEVICE, 				   0, 				   0, 				   30, 				   pBfr, 				   &actLen) 				!= OK)	        {		break;            	}            vendorId = USB_PEGASUS_SWAP_16 (((pUSB_DEVICE_DESCR) pBfr)->vendor);	    productId = \		USB_PEGASUS_SWAP_16 (((pUSB_DEVICE_DESCR) pBfr)->product);		            for (index = 0; index < noOfSupportedDevices; index++)		if (vendorId == pegasusAdapterList[index][0])		    if (productId == pegasusAdapterList[index][1])			break;	  	    if (index == noOfSupportedDevices )		{		/* device not supported */		PEGASUS_LOG (PEGASUS_DBG_ATTACH, " Unsupported "			     "device found vId %0x; pId %0x!!! \n", 			     vendorId, productId, 0, 0, 0, 0);		break;		}			      PEGASUS_LOG (PEGASUS_DBG_ATTACH, " Found a PEGASUS "		"Adapter!!!  %0x  %0x\n", vendorId, productId, 0, 0, 0, 0);		    /* 	     * Now create a strcture for the newly found device and add 	     * it to the linked list 	     */            /* Try to allocate space for a new device struct */	    if ((pNewDev = OSS_CALLOC (sizeof (USB_PEGASUS_DEV))) == NULL) 	    	{		break;	    			}	    /* Fill in the device structure */		    pNewDev->nodeId = nodeId;	    pNewDev->configuration = configuration;	    pNewDev->interface = interface;	    pNewDev->vendorId = vendorId;	    pNewDev->productId = productId;	    /* Add this device to the linked list */		    usbListLink (&pegasusDevList, pNewDev, &pNewDev->devLink, 			LINK_TAIL);	    /* Mark the device as being connected */	    pNewDev->connected = TRUE;            /* Notify registered callers that a PEGASUS has been added */	    notifyAttach (pNewDev, USB_PEGASUS_ATTACH); 		    	    PEGASUS_LOG (PEGASUS_DBG_ATTACH, " notify attach got called \n",		          0, 0, 0, 0, 0, 0);	    break;	case USBD_DYNA_REMOVE:	            PEGASUS_LOG (PEGASUS_DBG_ATTACH, " pegasusAttachCallback "			"USBD_DYNA_REMOVE case  \n", 0, 0, 0, 0, 0, 0);		    /* First Ensure that this device is on the list */		    if ((pNewDev = pegasusFindDevice (nodeId)) == NULL)	    	{	        PEGASUS_LOG (PEGASUS_DBG_ATTACH, "Device not found \n",			 0, 0, 0, 0, 0, 0);	        break;	        }	    if (pNewDev->connected == FALSE)		{         	PEGASUS_LOG (PEGASUS_DBG_ATTACH, "Device not connected \n",			 0, 0, 0, 0, 0, 0);	                        break;    		}		    pNewDev->connected = FALSE;	    /*	     * we need not check for the vendor id/product id as if              * the device is on the list, then it is our device only.	     */            pNewDev->lockCount++;            notifyAttach (pNewDev, USB_PEGASUS_REMOVE);                    pNewDev->lockCount--;             /* De allocate Memory for the device */	    if (pNewDev->lockCount == 0)		pegasusDestroyDevice((PEGASUS_DEVICE *)pNewDev->pPegasusDev);		    break;	    	}    OSS_FREE (pBfr);    OSS_MUTEX_RELEASE (pegasusMutex);    return OK;    }		/***************************************************************************** usbPegasusEndInit - Initializes the pegasus Library** Initizes the pegasus Library. The Library maintains an initialization* count so that the calls to this function might be nested.** This function initializes the system resources required for the library* initializes the linked list for the ethernet devices found.* This function reegisters the library as a client for the usbd calls and * registers for dynamic attachment notification of usb communication device* class and Ethernet sub class of devices.** RETURNS : OK if successful, ERROR if failure **/STATUS usbPegasusEndInit(void)    {        /* see if already initialized. if not, initialize the library */    initCount++;    if(initCount != 1)		/* if its the first time */	return OK;    memset (&pegasusDevList, 0, sizeof (pegasusDevList));        pegasusMutex = NULL;    pegasusTxMutex = NULL;    pegasusRxMutex = NULL;    pegasusHandle = NULL;    /* create the mutex */    if (OSS_MUTEX_CREATE (&pegasusMutex) != OK)	return pegasusShutdown (S_usbPegasusLib_OUT_OF_RESOURCES);        if (OSS_MUTEX_CREATE (&pegasusTxMutex) != OK)	return pegasusShutdown (S_usbPegasusLib_OUT_OF_RESOURCES);        if (OSS_MUTEX_CREATE (&pegasusRxMutex) != OK)	return pegasusShutdown (S_usbPegasusLib_OUT_OF_RESOURCES);    /*      * Register the Library as a Client and register for      * dynamic attachment callback.     */     if((usbdClientRegister (PEGASUS_CLIENT_NAME, &pegasusHandle) != OK) ||	(usbdDynamicAttachRegister (pegasusHandle, USBD_NOTIFY_ALL,				   USBD_NOTIFY_ALL, USBD_NOTIFY_ALL,				   (USBD_ATTACH_CALLBACK) 				   pegasusAttachCallback) != OK))	{	logMsg(" Registration Failed..\n", 0, 0, 0, 0, 0, 0);    	return pegasusShutdown (S_usbPegasusLib_USBD_FAULT);	}        return OK;    }/***************************************************************************** findEndpoint - Searches for a BULK endpoint of the indicated direction.** RETURNS: pointer to matching endpoint descriptor or NULL if not found* NOMANUAL*/LOCAL pUSB_ENDPOINT_DESCR findEndpoint    (    pUINT8 pBfr,		/* buffer to search for */    UINT16 bfrLen,		/* buffer length */    UINT16 direction		/* end point direction */    )    {    pUSB_ENDPOINT_DESCR pEp;    while ((pEp = (pUSB_ENDPOINT_DESCR) 	    usbDescrParseSkip (&pBfr, &bfrLen, USB_DESCR_ENDPOINT)) 		!= NULL)	{	if ((pEp->attributes & USB_ATTR_EPTYPE_MASK) == USB_ATTR_BULK &&	    (pEp->endpointAddress & USB_ENDPOINT_DIR_MASK) == direction)	    break;	}    return pEp;    }/***************************************************************************** pegasusDevInit - Initializes the pegasus Device structure.** This function initializes the usb ethernet device. It is called by * usbPegasusEndLoad() as part of the end driver initialzation. * usbPegasusEndLoad() expects this routine to perform all the device and usb * specific initialization and fill in the corresponding member fields in the * PEGASUS_DEVICE structure.** This function first checks to see if the device corresponding to* <vendorId> and <productId> exits in the linkedlist pegasusDevList.* It allocates memory for the input and output buffers. The device * descriptors will be retrieved and are used to findout the IN and OUT* bulk end points. Once the end points are found, the corresponding* pipes are constructed. The Pipe handles are stored in the device * structure <pDevCtrl>. The device's Ethernet Address (MAC address) * will be retrieved and the corresponding field in the device structure* will be updated. This is followed by setting up of the parameters * like Multicast address filter list, Packet Filter bitmap etc.** RETURNS : OK if every thing succeds and ERROR if any thing fails.**/STATUS pegasusDevInit    (    PEGASUS_DEVICE * pDevCtrl,	/* the device structure to be updated */    UINT16 vendorId,		/* manufacturer id of the device */    UINT16 productId    	/* product id of the device */    )    {    USB_PEGASUS_DEV * pNewDev;    USB_CONFIG_DESCR * pCfgDescr;	    USB_INTERFACE_DESCR * pIfDescr;    USB_ENDPOINT_DESCR * pOutEp;    USB_ENDPOINT_DESCR * pInEp;    UINT8 * pBfr;    UINT8 * pScratchBfr;    PEGASUS_ENET_IRP* pIrpBfrs;    UINT8** pInBfr;    UINT16 actLen;    int index, otherIndex = 0;    if(pDevCtrl == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT,"Null Device \n", 0, 0, 0, 0, 0, 0);	return ERROR;	}    /* Find if the device is in the found devices list */       if ((pNewDev = pegasusEndFindDevice (vendorId,productId)) == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT,"Could not find device..\n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}    /* Link the End Structure and the device that is found */    pDevCtrl->pDev = pNewDev;    pNewDev->pPegasusDev = pDevCtrl;        /* Allocate memory for the input and output buffers..*/    if ((pBfr = OSS_MALLOC (USB_MAX_DESCR_LEN)) == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT,"Could not allocate memory for Get"		     "descriptor.\n", 0, 0, 0, 0, 0, 0);	return ERROR;	}    if ((pIrpBfrs = OSS_MALLOC (pDevCtrl->noOfIrps * \			         sizeof (PEGASUS_ENET_IRP)))  \			     == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT,"Could not allocate memory for IRPs.\n",		     0, 0, 0, 0, 0, 0);	OSS_FREE (pBfr);	return ERROR;	}    if ((pInBfr = OSS_MALLOC (pDevCtrl->noOfInBfrs * sizeof (char *))) ==NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT,"Could Not align Memory for pInBfrs ...\n"		      , 0, 0, 0, 0, 0, 0);	OSS_FREE (pBfr);	OSS_FREE (pIrpBfrs);	return ERROR;        }    for (index=0;index<pDevCtrl->noOfInBfrs;index++)	{	if((pInBfr[index] = OSS_MALLOC (PEGASUS_IN_BFR_SIZE+8)) == NULL)	    {	    PEGASUS_LOG (PEGASUS_DBG_INIT,"Could Not align Memory "                        "for InBfrs  %d...\n", index, 0, 0, 0, 0, 0);   	    OSS_FREE (pBfr);	    OSS_FREE (pIrpBfrs);	    for (otherIndex=0; otherIndex<index; otherIndex++)		OSS_FREE (pInBfr[otherIndex]); 	    OSS_FREE (pInBfr);	    return ERROR;	    }	}    pDevCtrl->pEnetIrp = pIrpBfrs;	    pDevCtrl->pInBfrArray = pInBfr;    for (index = 0; index < pDevCtrl->noOfIrps; index++)	{	pIrpBfrs->outIrpInUse = FALSE;	pIrpBfrs ++;	}    pDevCtrl->rxIndex = 0;        pDevCtrl->txIrpIndex = 0;    pDevCtrl->outBfrLen = PEGASUS_OUT_BFR_SIZE;    pDevCtrl->inBfrLen = PEGASUS_IN_BFR_SIZE;    /*      * Now we decifer the descriptors provided by the device ..     * we try finding out what end point is what..     * that doesn't mean we won't assume any thing, we assume certain     * things though..like there are no any alternate settings for interfaces     * etc..     */    /* To start with, get the configuration descriptor ..*/    if (usbdDescriptorGet (pegasusHandle, 			   pNewDev->nodeId, 			   USB_RT_STANDARD | USB_RT_DEVICE, 			   USB_DESCR_CONFIGURATION, 			   0, 			   0, 			   USB_MAX_DESCR_LEN, 			   pBfr, 			   &actLen) 			!= OK)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "Could not GET Desc...\n",		     0, 0, 0, 0, 0, 0);	goto errorExit;	}    if ((pCfgDescr = usbDescrParse (pBfr, 					    actLen, 					    USB_DESCR_CONFIGURATION)) 					  == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "Could not find Config. Desc...\n",		     0, 0, 0, 0, 0, 0);	goto errorExit;	}    /*     * Since we registered for NOTIFY_ALL for attachment of devices,     * the configuration no and interface number as reported by the      * call back function doesn't have any meanning.     * we refer to the PEGASUS document and it says, it has only one      * interface with number 0. So the first (only) interface we find      * is the interface we want.      * If there are more interfaces and one of them meet our requirement     * (as reported by callback funtction), then we need to parse     * until we find our one..     */            /*     * usbDescrParseSkip() modifies the value of the pointer it recieves     * so we pass it a copy of our buffer pointer     */    pScratchBfr = pBfr;	        if ((pIfDescr = usbDescrParseSkip (&pScratchBfr, 					       &actLen, 				       USB_DESCR_INTERFACE)) 				    == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "Could not find Intrface Desc.\n",		     0, 0, 0, 0, 0, 0);	goto errorExit;	}        /* Find out the output and input end points ..*/    if ((pOutEp = findEndpoint (pScratchBfr, 				actLen, 				USB_ENDPOINT_OUT)) 			    == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "No Output End Point \n",		     0, 0, 0, 0, 0, 0);         goto errorExit;	}    if ((pInEp = findEndpoint (pScratchBfr, 			       actLen, 			       USB_ENDPOINT_IN)) 			     == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "No Input End Point \n",		     0, 0, 0, 0, 0, 0);         goto errorExit;	}    pDevCtrl->maxPower = pCfgDescr->maxPower;     /*     * Now, set the configuration.     */    if (usbdConfigurationSet (pegasusHandle, pNewDev->nodeId,	pCfgDescr->configurationValue, 				pCfgDescr->maxPower * USB_POWER_MA_PER_UNIT) != OK)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -