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

📄 usbklsiend.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    UINT16 interface,    UINT16 deviceClass,     UINT16 deviceSubClass,     UINT16 deviceProtocol    )    {         pUsbListDev pNewDev;    UINT8 bfr[30];    UINT16 actLen;    UINT16 vendorId;    UINT16 productId;    int noOfSupportedDevices = (sizeof (klsiAdapterList) /				 (2 * sizeof (UINT16)));    int index = 0;    OSS_MUTEX_TAKE (klsiMutex, OSS_BLOCK);    switch (attachAction)	{	case USBD_DYNA_ATTACH :		    /* a new device is found */	    KLSI_LOG (KLSI_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 (klsiFindDevice (nodeId) != NULL)		{		KLSI_LOG (KLSI_DBG_ATTACH, "Device already exists. \n",		          0, 0, 0, 0, 0, 0);	        break;		}	    /* Now, Ensure that it is a KLSI device */	            if (usbdDescriptorGet (klsiHandle, 				   nodeId, 				   USB_RT_STANDARD | USB_RT_DEVICE, 				   USB_DESCR_DEVICE, 				   0, 				   0, 				   30, 				   bfr, 				   &actLen) 				!= OK)	        {		break;            	}#if 0	    for(index=0;index<actLen;index++)		printf(" 0x%x",bfr[index]);	    printf("\n");#endif            vendorId = (*(bfr+9) << 8)&0xff00;		            vendorId |= *(bfr+8);		            productId = (*(bfr+11) << 8)&0xff00;		            productId |= *(bfr+10);		            for (index = 0; index < noOfSupportedDevices; index++)		if (vendorId == klsiAdapterList[index][0])		    if (productId == klsiAdapterList[index][1])			break;	  	    if (index == noOfSupportedDevices )		{		/* device not supported */		KLSI_LOG (KLSI_DBG_ATTACH,                           " Unsupported device found vId %0x; pId %0x! \n", 			  vendorId, productId, 0, 0, 0, 0);		break;		}		  	    KLSI_LOG (KLSI_DBG_ATTACH,                       " Found a KLSI 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 (&klsiDevList, pNewDev, &pNewDev->devLink, 			 LINK_TAIL);	 /* Notify registered callers that a klsi device has been added */	    notifyAttach (pNewDev->nodeId, USB_KLSI_ATTACH); 	/*##*/	    break;	case USBD_DYNA_REMOVE:	    KLSI_LOG (KLSI_DBG_ATTACH, "Device Removed  %x \n", (int) nodeId,		    0, 0, 0, 0, 0);		  /* First Ensure that this device is on the list */		    if ((pNewDev = klsiFindDevice (nodeId)) == NULL)	        break;	     /* Check the connected flag  */            if (pNewDev->connected == FALSE)                break;    	     		     pNewDev->connected = FALSE;	    /* Notify registered callers that the klsi device has been	     * removed 	     *	     * NOTE: We temporarily increment the device's lock count	     * to prevent usbKlsiDevUnlock() from destroying the	     * structure while we're still using it.	     */            pNewDev->lockCount++;             notifyAttach (pNewDev->nodeId, USB_KLSI_REMOVE);             pNewDev->lockCount--; 	    if (pNewDev->lockCount == 0)		klsiDestroyDevice((KLSI_DEVICE *)pNewDev->pDevStructure);		    break;	}    OSS_MUTEX_RELEASE (klsiMutex);    }		/***************************************************************************** usbKlsiEndInit - Initializes the klsi Library** Initizes the klsi Library. The Library maintains an initialization* count so that the calls to this function can be nested.** This function initializes the system resources required for the library* initializes the linked list for the ethernet devices found.* This function registers 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.** This function is to be called after the USBD initialization and before * the endStart gets called. Otherwise the Library can't perform.** RETURNS : OK or ERROR** ERRNO :** S_klsiLib_OUT_OF_RESOURCES* S_klsiLib_USBD_FAULT*/STATUS usbKlsiEndInit (void)    {     /* see if already initialized. if not, initialize the library */    initCount++;    if(initCount != 1)	/* already registered */	return OK;    /*      * Initialize USBD     * The assumption is made that the USB host stack has already been     * initialized elsewhere.       */    /* usbdInitialize(); */    memset (&klsiDevList, 0, sizeof (klsiDevList));        klsiMutex = NULL;    klsiTxMutex = NULL;    klsiRxMutex = NULL;    klsiHandle = NULL;    /* create the mutex */    if (OSS_MUTEX_CREATE (&klsiMutex) != OK)	return klsiShutdown (S_usbKlsiLib_OUT_OF_RESOURCES);        if (OSS_MUTEX_CREATE (&klsiTxMutex) != OK)	return klsiShutdown (S_usbKlsiLib_OUT_OF_RESOURCES);        if (OSS_MUTEX_CREATE (&klsiRxMutex) != OK)	return klsiShutdown (S_usbKlsiLib_OUT_OF_RESOURCES);    /*      * Register the Library as a Client and register for      * dynamic attachment callback.     */    /*      if((usbdClientRegister (KLSI_CLIENT_NAME, &klsiHandle) != OK) ||	usbdDynamicAttachRegister (klsiHandle, 				   USB_CLASS_COMMDEVICE, 				   USB_SUBCLASS_ENET, 				   USBD_NOTIFY_ALL, 				   klsiAttachCallback) 				!= OK))	{    	return klsiShutdown (S_klsiLib_USBD_FAULT);	}    */    /*     * The above registration doesn't work for KLSI chip based adapters.     * This is because the chip doesn't show up as a communications class     * device. It shows up as  a proprietary device. Decifering that a      * given device is a KLSI device is done from its product ID and     * vendor ID. This is done in the dynamic attachment call back function.     */     if((usbdClientRegister (KLSI_CLIENT_NAME, &klsiHandle) != OK) ||	(usbdDynamicAttachRegister (klsiHandle, 				    USBD_NOTIFY_ALL, 				    USBD_NOTIFY_ALL, 				    USBD_NOTIFY_ALL, 				    (USBD_ATTACH_CALLBACK) klsiAttachCallback)				 != OK))	{	logMsg(" Registration Failed..\n", 0, 0, 0, 0, 0, 0);    	return klsiShutdown (S_usbKlsiLib_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* */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;    }/***************************************************************************** klsiDevInit - Initializes the klsi Device structure.** This function initializes the USB ethernet device. It is called by * klsiEndLoad() as part of the end driver initialization. klsiEndLoad()* expects this routine to perform all the device and USB specific * initialization and fill in the corresponding member fields in the * KLSI_DEVICE structure.** This function first checks to see if the device corresponding to* <vendorId> and <productId> exits in the linkedlist klsiDevList.* It allocates memory for the input and output buffers. The device * descriptors are retrieved andused 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) * is retrieved and the corresponding field in the device structure* is updated. This is followed by setting up of the parameters * like Multicast address filter list, Packet Filter bitmap etc.** RETURNS : OK or ERROR**/STATUS klsiDevInit    (    KLSI_DEVICE* pDevCtrl,	/* the device structure to be updated */    UINT16 vendorId,		/* manufacturer id of the device */    UINT16 productId    	/* product id of the device */    )    {    USB_KLSI_DEV* pNewDev;    pUSB_CONFIG_DESCR pCfgDescr;	    pUSB_INTERFACE_DESCR pIfDescr;    pUSB_ENDPOINT_DESCR pOutEp;    pUSB_ENDPOINT_DESCR pInEp;        KLSI_ENET_IRP * pIrpBfrs;	    UINT8 bfr[30];       pUINT8 pBfr;    UINT8** pInBfr;    UINT16 actLen;        int index = 0;    if(pDevCtrl == NULL)	{	KLSI_LOG (KLSI_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 = klsiEndFindDevice (vendorId,productId)) == NULL)	{	printf("Could not find KLSI device.\n");

⌨️ 快捷键说明

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