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

📄 usbpegasusend.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 5 页
字号:
* RETURNS: N/A** ERRNO: none** \NOMANUAL*/LOCAL STATUS  pegasusAttachCallback    (    USBD_NODE_ID nodeId,     UINT16 attachAction,     UINT16 configuration,    UINT16 interface,    UINT16 deviceClass,     UINT16 deviceSubClass,     UINT16 deviceProtocol    )    {    USB_PEGASUS_DEV * pNewDev;    UINT8 * pBfr;    UINT16 actLen;    UINT16 vendorId;    UINT16 productId;    int noOfSupportedDevices = (sizeof (pegasusAdapterList) /				 (2 * sizeof (UINT16)));    int index = 0;    if ((pBfr = OSS_MALLOC (USB_MAX_DESCR_LEN)) == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_ATTACH, "pegasusAttachCallback: could not"		    "allocate pBfr\n", 0, 0, 0, 0, 0, 0);		return ERROR;	}    OSS_MUTEX_TAKE (pegasusMutex, OSS_BLOCK);    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;            /* Save a global copy of NodeID used by DIAGs */            pegasusNodeID = nodeId;	    /* 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 ** ERRNO: * \is* \i S_usbPegasusLib_OUT_OF_RESOURCES* Sufficient Resources not Available** \i S_usbPegasusLib_USBD_FAULT* Fault in the USBD Layer* \ie*/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, 0, 0, 0,			(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.** This function searches for the endpoint of indicated direction** RETURNS: a pointer to matching endpoint descriptor or NULL if not found.** ERRNO: none** \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.** ERRNO: none**\NOMANUAL*/LOCAL 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;    UINT8 ** pOutBfr;    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;	    }	}    if ((pOutBfr = OSS_MALLOC (pDevCtrl->noOfIrps * sizeof (char *))) ==NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT,"Could Not align Memory for pOutBfrs ...\n"		      , 0, 0, 0, 0, 0, 0);	OSS_FREE (pBfr);	OSS_FREE (pIrpBfrs);        for (index=0; index<pDevCtrl->noOfInBfrs; index++)    OSS_FREE (pInBfr[index]);    OSS_FREE (pInBfr);	return ERROR;        }    for (index=0;index<pDevCtrl->noOfIrps;index++)	{	if((pOutBfr[index] = OSS_MALLOC (USB_PEGASUS_BUF_SIZE+8)) == NULL)	    {	    PEGASUS_LOG (PEGASUS_DBG_INIT,"Could Not align Memory "                        "for OutBfrs  %d...\n", index, 0, 0, 0, 0, 0);   	    OSS_FREE (pBfr);	    OSS_FREE (pIrpBfrs);	    for (otherIndex=0; otherIndex<index; otherIndex++)		OSS_FREE (pOutBfr[otherIndex]); 	    OSS_FREE (pOutBfr);                for (otherIndex=0; otherIndex<pDevCtrl->noOfInBfrs; otherIndex++)        OSS_FREE (pInBfr[index]);        OSS_FREE (pInBfr);	    return ERROR;	    }	}    pDevCtrl->pEnetIrp = pIrpBfrs;	    pDevCtrl->pInBfrArray = pInBfr;    pDevCtrl->pOutBfrArray = pOutBfr;    for (index = 0; index < pDevCtrl->noOfIrps; index++)	{	pIrpBfrs->outIrpInUse = FALSE;	pIrpBfrs ++;	}    pDevCtrl->rxIndex = 0;        pDevCtrl->txIrpIndex = 0;    pDevCtrl->txStall = FALSE;    pDevCtrl->txActive = FALSE;    pDevCtrl->outBfrLen = PEGASUS_OUT_BFR_SIZE;    pDevCtrl->inBfrLen = PEGASUS_IN_BFR_SIZE;

⌨️ 快捷键说明

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