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

📄 usbpegasusend.c

📁 T2.0 USB driver.rar T2.0 USB driver.rar
💻 C
📖 第 1 页 / 共 5 页
字号:
		    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 (*pNewDev))) == 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_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;    pUSB_CONFIG_DESCR pCfgDescr;	    pUSB_INTERFACE_DESCR pIfDescr;    pUSB_ENDPOINT_DESCR pOutEp;    pUSB_ENDPOINT_DESCR pInEp;    UINT8 bfr[USB_MAX_DESCR_LEN];    PEGASUS_ENET_IRP* pIrpBfrs;    UINT8** pInBfr;    pUINT8 pBfr;    UINT16 actLen;        int index = 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;        /* Allocate memory for the input and output buffers..*/    if ((pIrpBfrs = (PEGASUS_ENET_IRP*) memalign (sizeof(ULONG),                      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);	return ERROR;	}    if ((pInBfr = (pUINT8*)memalign(sizeof(ULONG),                 pDevCtrl->noOfInBfrs * sizeof (char *)))==NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT,"Could Not align Memory for pInBfrs ...\n",			    0, 0, 0, 0, 0, 0);	return ERROR;        }    for (index=0;index<pDevCtrl->noOfInBfrs;index++)	{	if((pInBfr[index] = (pUINT8)memalign(sizeof(ULONG),                                            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);	    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,	sizeof (bfr), bfr, &actLen) != OK)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "Could not GET Desc...\n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}    if ((pCfgDescr = (pUSB_CONFIG_DESCR) 	usbDescrParse (bfr, actLen, USB_DESCR_CONFIGURATION)) == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "Could not find Config. Desc...\n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}    pBfr = bfr;	        /*     * 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..     */    /*      * pBfr and bfr are needed in case we have more than one interface.     * to allow multiple parses.     */            if ((pIfDescr = (pUSB_INTERFACE_DESCR) 	usbDescrParseSkip (&pBfr, &actLen, USB_DESCR_INTERFACE)) == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "Could not find Intrface Desc.\n",		     0, 0, 0, 0, 0, 0);    	return ERROR;	}        /* Find out the output and input end points ..*/    if ((pOutEp = findEndpoint (pBfr, actLen, USB_ENDPOINT_OUT)) == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "No Output End Point \n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}    if ((pInEp = findEndpoint (pBfr, actLen, USB_ENDPOINT_IN)) == NULL)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "No Input End Point \n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}    pDevCtrl->maxPower = pCfgDescr->maxPower;     /*     * Now, set the configuration.     */    if (usbdConfigurationSet (pegasusHandle, pNewDev->nodeId,	pCfgDescr->configurationValue, 				pCfgDescr->maxPower * USB_POWER_MA_PER_UNIT) != OK)	return ERROR;    usbPegasusInit(pNewDev->nodeId, (UINT8 *)&bfr);	pDevCtrl->macAdrs[0] = bfr[0];	pDevCtrl->macAdrs[1] = bfr[1];	pDevCtrl->macAdrs[2] = bfr[2];	pDevCtrl->macAdrs[3] = bfr[3];	pDevCtrl->macAdrs[4] = bfr[4];	pDevCtrl->macAdrs[5] = bfr[5];	PEGASUS_LOG (PEGASUS_DBG_INIT, "EthernetID %02x %02x %02x "		    "%02x %02x %02x\n", bfr[0], bfr[1], bfr[2], bfr[3], 		    bfr[4], bfr[5]);     /* Now, Create the Pipes.. */    if (usbdPipeCreate (pegasusHandle, pNewDev->nodeId, 		       pOutEp->endpointAddress, pCfgDescr->configurationValue,		       pNewDev->interface, USB_XFRTYPE_BULK, USB_DIR_OUT,		       FROM_LITTLEW (pOutEp->maxPacketSize), 0, 0, 		       &pDevCtrl->outPipeHandle) != OK)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "Pipe O/P coud not be created \n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}        if (usbdPipeCreate (pegasusHandle, pNewDev->nodeId, 		       pInEp->endpointAddress, pCfgDescr->configurationValue,		       pNewDev->interface, USB_XFRTYPE_BULK, USB_DIR_IN,		       FROM_LITTLEW (pInEp->maxPacketSize), 0, 0, 		       &pDevCtrl->inPipeHandle) != OK)	{	PEGASUS_LOG (PEGASUS_DBG_INIT, "Pipe I/P coud not be created \n",	     	     0, 0, 0, 0, 0, 0);	return ERROR;	}    pDevCtrl->inIrpInUse = FALSE;    return OK;    }/***************************************************************************** pegasusEndStart - Starts communications over Ethernet via usb (device)** Since we don't have any interrupt, we have to prevent the device from * communicating, in some other way. Here, since the reception is based * on polling, and we do the pegasusListenForInput() for such polling,* we can delay listening to any packet coming in, by having* this function called in pegasusEndStart()... This way, we try to mimic the* traditional "interrupt enabling". This is for packet reception.** For packet transmission, we use the communicateOk flag. We transmit data * only if this flag is true. This flag will be set to TRUE in pegasusEndStart().* and will be reset to FALSE in pegasusEndStop().** RETURNS : OK or ERROR*/STATUS pegasusEndStart    (    PEGASUS_DEVICE * pDevCtrl	        /* Device to be started */    )    {    PEGASUS_LOG (PEGASUS_DBG_START, "pegasusEndStart:..entered.\n",		 0, 0, 0, 0, 0, 0);        /*

⌨️ 快捷键说明

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