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

📄 usbnc1080end.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
                               "data %savailable \n",                                (UINT)((status & 0x0040)?"":"dis"),                                (UINT)((status & 0x0020)?"suspended":"live"),                                (UINT)((status & 0x0010)?"":"Not"),                                (UINT)((status & 0x0003)?"":"Not"),                                0, 0);    }/**************************************************************************** usbNC1080ShowUsbctl -  Displays NC1080 USBCTL register** Displays, in human readable way, the USBCTL register of the NC1080 * Turboconnect device** RETURNS: N/A*/LOCAL void usbNC1080ShowUsbctl    (    UINT16 usbctl    )    {    DRV_LOG (DRV_DBG_REGISTER, "USBCTL Register : %x \n", usbctl,	    2, 3, 4, 5, 6);    }/**************************************************************************** usbNC1080ShowTtl - Display NC1080 TTL register** Displays, in human readable way, the TTL register of the NC1080 * Turboconnect device** RETURNS: N/A*/LOCAL void usbNC1080ShowTtl    (    UINT16 ttl    )    {    DRV_LOG (DRV_DBG_REGISTER, "TTL Register : %x \n"                               "\tTTL for this Port : %d ms "                               "other port : %d ms\n",                                ttl, (ttl&0x00ff), ((ttl>>8)&0x00ff),                                 0, 0, 0);    }/**************************************************************************** usbNC1080Reset - Resets the NC1080 Turboconnect device*** RETURNS: OK or ERROR*/LOCAL STATUS usbNC1080Reset     (    NC1080_END_DEV* pDrvCtrl    )    {    UINT16 reg_status, reg_usbctl, reg_ttl, temp_ttl;    /* Read the status register */    if (usbNC1080ReadRegister(pDrvCtrl, NETCHIP_STATUS, &reg_status) != OK)        {        DRV_LOG (DRV_DBG_RESET, "Failed to read status register",                0, 0, 0, 0, 0, 0);        return ERROR;        }    usbNC1080ShowStatus (reg_status);    if (usbNC1080ReadRegister(pDrvCtrl, NETCHIP_USBCTL, &reg_usbctl) != OK)        {        DRV_LOG (DRV_DBG_RESET, "Failed to read usbctl register",                0, 0, 0, 0, 0, 0);        return ERROR;        }    usbNC1080ShowUsbctl (reg_usbctl);    /* Flush Fifo of both ports */    if (usbNC1080WriteRegister(pDrvCtrl, NETCHIP_USBCTL,                USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER) == ERROR)        {        return ERROR;        }    /* Some TTL funda */    if (usbNC1080ReadRegister(pDrvCtrl, NETCHIP_TTL, &reg_ttl) != OK)        {        DRV_LOG (DRV_DBG_RESET, "Failed to read ttl register",                0, 0, 0, 0, 0, 0);        return ERROR;        }    usbNC1080ShowTtl(reg_ttl);    /* set some timeout for our read fifo. it shall time out and flush data */    temp_ttl = (reg_ttl) & 0xff00;		/* on the other side */    reg_ttl = (NETCHIP_TTLVAL & 0x00ff);        /* our ttl */    reg_ttl |= temp_ttl;			/* TTL register value */    if (usbNC1080WriteRegister(pDrvCtrl, NETCHIP_TTL,                reg_ttl) == ERROR)        {        DRV_LOG (DRV_DBG_RESET, "Failed to set ttl register",                0, 0, 0, 0, 0, 0);        return ERROR;        }    return OK;    }/**************************************************************************** usbNC1080DrvInit - Initializes the usbNC1080 Library** Initializes the usbNC1080 driver. The driver maintains an initialization* count so that the calls to this function might be nested.** This function initializes the system resources required for the driver* initializes the linked list for the usbNC1080 devices found.* This function reegisters the library as a client for the usbd calls and * registers for dynamic attachment notification of usb devices. Since the* usbNC1080 device is a "vendor specific" device, this function registers* for attachment / removal notification for all devices.** This function is to be called AFTER the usbd initialization and before * the endLoad gets called. Otherwise the driver can't perform.** RETURNS : OK if successful, ERROR if failure** ERRNO :** S_usbNC1080Drv_OUT_OF_RESOURCES* S_usbNC1080Drv_USBD_FAULT*/STATUS usbNC1080DrvInit(void)    {        /* see if already initialized. if not, initialize the library */    initCount++;    if(initCount != 1)	/* if its the first time */	return OK;    /* Initialize usbd */    usbdInitialize();    memset (&usbNC1080DevList, 0, sizeof (usbNC1080DevList));     usbNC1080Mutex = NULL;    usbNC1080TxMutex = NULL;    usbNC1080RxMutex = NULL;    usbNC1080IrpSem = NULL;    usbNC1080Handle = NULL;    /* create the mutex */    if (OSS_MUTEX_CREATE (&usbNC1080Mutex) != OK)	return usbNC1080Shutdown (S_usbNC1080Lib_OUT_OF_RESOURCES);    if (OSS_MUTEX_CREATE (&usbNC1080TxMutex) != OK)	return usbNC1080Shutdown (S_usbNC1080Lib_OUT_OF_RESOURCES);    if (OSS_MUTEX_CREATE (&usbNC1080RxMutex) != OK)	return usbNC1080Shutdown (S_usbNC1080Lib_OUT_OF_RESOURCES);    if (OSS_SEM_CREATE (1, 0 , &usbNC1080IrpSem) != OK)        return usbNC1080Shutdown (S_usbNC1080Lib_OUT_OF_RESOURCES);    /*     * Register the Library as a Client and register for     * dynamic attachment callback.     */     if((usbdClientRegister (CLIENT_NAME, &usbNC1080Handle) != OK) ||	(usbdDynamicAttachRegister (usbNC1080Handle, 				    USBD_NOTIFY_ALL, 				    USBD_NOTIFY_ALL, 				    USBD_NOTIFY_ALL, 				(USBD_ATTACH_CALLBACK) usbNC1080AttachCallback)			 != OK))	{    	return usbNC1080Shutdown (S_usbNC1080Lib_USBD_FAULT);	}    return OK;    }/**************************************************************************** usbNC1080AttachCallback - Gets called for attachment/detachment of devices** The USBD will invoke this callback when a USB device is attached to or * removed from the system (usb bus).  * <nodeId> is the USBD_NODE_ID of the node being attached or removed.	* <attachAction> is USBD_DYNA_ATTACH or USBD_DYNA_REMOVE.* The registeration has been for notification of any usb device attachment /* removal. This means that the USBD will invoke this function once for each* configuration / interface for any device attached. <configuration> and* <interface> will indicate the configuration / interface information of* the device. How-ever, usbNC1080 device has only one configuration which has* only one interface.* <deviceClass> and <deviceSubClass> will match the class/subclass for* which we registered.  In this case, since usbNC1080 is a vendor specific* device, these fields donot matter for this device.* <deviceProtocol> doesn't have meaning for the vendor devices so we * ignore this field.** NOTE: The USBD will invoke this function once for each configuration/* interface.  So, it is possible that a single device insertion/removal may * trigger multiple callbacks.  This function ignores all callbacks except the* first for a given device.** RETURNS: N/A** NOMANUAL*/STATUS  usbNC1080AttachCallback    (    USBD_NODE_ID nodeId,     UINT16 attachAction,     UINT16 configuration,    UINT16 interface,    UINT16 deviceClass,     UINT16 deviceSubClass,     UINT16 deviceProtocol    )    {    USB_NC1080_DEV * pNewDev;    UINT8 bfr[USB_MAX_DESCR_LEN];    UINT16 actLen;    UINT16 vendorId;    UINT16 productId;    int index = 0;    OSS_MUTEX_TAKE (usbNC1080Mutex, OSS_BLOCK);    switch (attachAction)	{	case USBD_DYNA_ATTACH :		    /* a new device is found */	    DRV_LOG (DRV_DBG_ATTACH, "New Usb device on Bus..\n",	    	    0, 0, 0, 0, 0, 0);	    /* First Ensure that this device is not already on the list */		    if (usbNC1080FindUsbNode (nodeId) != NULL)	        break;	    /* Now, we have to ensure that its a NETCHIP device */            if (usbdDescriptorGet (usbNC1080Handle, 				   nodeId, 				   USB_RT_STANDARD | USB_RT_DEVICE, 				   USB_DESCR_DEVICE, 				   0, 				   0, 				   sizeof (bfr), 				   bfr, 				   &actLen) 				!= OK)	        {		DRV_LOG (DRV_DBG_ATTACH, "DescriporGet Failed for device "			"descriptor.\n", 0, 0, 0, 0, 0, 0);		break;            	}	    DRV_DESC_PRINT (DRV_DBG_ATTACH, "Device Descriptor", bfr, actLen);            vendorId = ((pUSB_DEVICE_DESCR)bfr)->vendor;	    productId = ((pUSB_DEVICE_DESCR)bfr)->product;			    DRV_LOG (DRV_DBG_ATTACH, "VendorID : 0x%x \t ProductID : 0x%x.\n",		     vendorId, productId, 0, 0, 0, 0);	    /* Check if the device is a NC1080 Turboconnect */	    for (index = 0; products [index].idVendor != 0; index++) 		{		if (products [index].idVendor != vendorId)			continue;		if (products [index].idProduct != productId)			continue;		break;		}		    if (products [index].idVendor == 0)	/* device not a usbNC1080 device */		{		DRV_LOG (DRV_DBG_ATTACH, " unsupported device ... \n",			0, 0, 0, 0, 0, 0);		break;		}  	    DRV_LOG (DRV_DBG_ATTACH, "that was a NC1080 device!!!  \n",		    0, 0, 0, 0, 0, 0);	    /* 	     * Now create a structure 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) 	    	{		DRV_LOG (DRV_DBG_ATTACH, "Could not allocate memory "			"for new device \n", 0, 0, 0, 0, 0, 0);		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 (&usbNC1080DevList, pNewDev, &pNewDev->devLink, 					LINK_TAIL);	    /* Notify registered callers that a NETCHIP device has been added */        notifyAttach(pNewDev, USB_NETCHIP_ATTACH);	    break;	case USBD_DYNA_REMOVE:	    /* First Ensure that this device is on the list */	    if ((pNewDev = usbNC1080FindUsbNode (nodeId)) == NULL)	        break;		if (pNewDev->connected == FALSE)			{				printf (" Device not found %x \n",(int)pNewDev->nodeId);                break;			}	    DRV_LOG (DRV_DBG_ATTACH, "NC1080 device Removed from Bus..\n",	    	    0, 0, 0, 0, 0, 0);	    pNewDev->connected = FALSE;	    /*	     * we need not check for the vendor/product ids as if the device is	     * on the list, then it is a usbNC1080 device only.	     */    	    pNewDev->lockCount++;             notifyAttach (pNewDev, USB_NETCHIP_REMOVE);             pNewDev->lockCount--; 	    if (pNewDev->lockCount == 0)			usbNC1080DestroyDevice((NC1080_END_DEV *)pNewDev->pDevStructure);	    break;	}    OSS_MUTEX_RELEASE (usbNC1080Mutex);    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;    }/**************************************************************************** usbNC1080FindUsbNode - Searches for a usbNC1080 device of indicated <nodeId>* in the usbNC1080 device linked list** RETURNS: pointer to matching dev struct or NULL if not found* NOMANUAL*/USB_NC1080_DEV* usbNC1080FindUsbNode    (    USBD_NODE_ID nodeId		/* Node Id to find */    )    {    USB_NC1080_DEV * pDev = usbListFirst (&usbNC1080DevList);    while (pDev != NULL)	{	if (pDev->nodeId == nodeId)	    break;	pDev = usbListNext (&pDev->devLink);	}    return pDev;    }/**************************************************************************** usbNC1080FindUsbDevice - Searches for a usbNC1080 device of a given <productId>* and <vendorId> in the usbNC1080 device linked list.** RETURNS: pointer to matching dev struct or NULL if not found* NOMANUAL*/USB_NC1080_DEV* usbNC1080FindUsbDevice    (    UINT16 vendorId,		/* Vendor Id to search for */    UINT16 productId		/* Product Id to search for */    )    {    USB_NC1080_DEV * pDev = usbListFirst (&usbNC1080DevList);    while (pDev != NULL)	{	if ((pDev->vendorId == vendorId) && (pDev->productId == productId))	    break;	pDev = usbListNext (&pDev->devLink);	}    return pDev;    }/**************************************************************************** usbNC1080DevInit - Initializes the usbNC1080 Device structure.** This function initializes the usb ethernet device. It is called by * usbNC1080Load() as part of the end driver initialzation. usbNC1080Load()* expects this routine to perform all the device and usb specific* initialization and fill in the corresponding member fields in the * NC1080_END_DEV structure.** This function first checks to see if the device corresponding to* <vendorId> and <productId> exits in the linkedlist usbNC1080DevList.* 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 <pDrvCtrl>. ** RETURNS : OK if every thing succeds and ERROR if any thing fails.**/

⌨️ 快捷键说明

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