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

📄 usbnc1080end.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
* Device unit number, a small integer.* .IP <pVendorId>* Pointer to the place holder of the device vendor id.* .IP <pProductId>* Pointer to the place holder of the device product id.* .IP <noOfIrps>* No of Input Irp buffers * .IP <noOfOutIrps>* No of output Irp buffers* .IP <macAddress>* 6 byte Hardware address of the device.** RETURNS: OK or ERROR for invalid arguments.* NOMANUAL*/STATUS usbNC1080EndParse    (    NC1080_END_DEV * pDrvCtrl,	/* device pointer */    char * initString,		/* information string */    UINT16 * pVendorId,    UINT16 * pProductId    )    {    char *	tok;    char *	pHolder = NULL;    int i;    /* Parse the initString */    /* Unit number. (from muxLib.o) */    tok = strtok_r (initString, ":", &pHolder);    if (tok == NULL)	return ERROR;    pDrvCtrl->unit = atoi (tok);    DRV_LOG (DRV_DBG_PARSE, "Parse: Unit : %d..\n",		pDrvCtrl->unit, 2, 3, 4, 5, 6);    /* Vendor Id. */    tok = strtok_r (NULL, ":", &pHolder);    if (tok == NULL)	return ERROR;    *pVendorId = atoi (tok);    DRV_LOG (DRV_DBG_PARSE, "Parse: VendorId : 0x%x..\n",		*pVendorId, 2, 3, 4, 5, 6);    /* Product Id. */    tok = strtok_r (NULL, ":", &pHolder);    if (tok == NULL)	return ERROR;    *pProductId = atoi (tok);    DRV_LOG (DRV_DBG_PARSE, "Parse: ProductId : 0x%x..\n",		*pProductId, 2, 3, 4, 5, 6);	/* no of in buffers */    tok = strtok_r (NULL, ":", &pHolder);    if (tok == NULL)	return ERROR;    pDrvCtrl->noOfInBfrs  = atoi (tok);      DRV_LOG (DRV_DBG_PARSE, "Parse: noOfInBfrs : 0x%x..\n",		pDrvCtrl->noOfInBfrs, 2, 3, 4, 5, 6);	    /* no of out IRPs */    tok = strtok_r (NULL, ":", &pHolder);    if (tok == NULL)	return ERROR;    pDrvCtrl->noOfIrps = atoi (tok);      DRV_LOG (DRV_DBG_PARSE, "Parse: noOfIrps : 0x%x..\n",		pDrvCtrl->noOfIrps, 2, 3, 4, 5, 6);	    /* Hardware address */    for (i=0; i<6; i++)        {        tok = strtok_r (NULL, ":", &pHolder);        if (tok == NULL)	    return ERROR;        pDrvCtrl->enetAddr[i] = atoi (tok);        }     DRV_LOG (DRV_DBG_PARSE, "Parse: Mac Address : "                                "%x: %x: %x : %x: %x: %x..\n",				pDrvCtrl->enetAddr[0],                                pDrvCtrl->enetAddr[1],                                pDrvCtrl->enetAddr[2],                                pDrvCtrl->enetAddr[3],                                pDrvCtrl->enetAddr[4],                                pDrvCtrl->enetAddr[5]);    DRV_LOG (DRV_DBG_PARSE, "Parse: Processed all arugments\n",		1, 2, 3, 4, 5, 6);    return OK;    }/* End Interface routines as required by VxWorks *//**************************************************************************** usbNC1080Load - initialize the driver and device** This routine initializes the driver and the device to the operational state.* All of the device specific parameters are passed in the initString.** This function first extracts the vendorId, productId and mac address of* the device from the initialization string using the usbNC1080EndParse()* function. It then passes these parameters and its control strcuture to* the usbNC1080DevInit() function.** usbNC1080DevInit() does most of the device specific initialization* and brings the device to the operational state. This driver will be attached* to MUX.** This function doesn't do any thing device specific. Instead, it delegates* such initialization to usbNC1080DevInit(). This routine handles the other part* of the driver initialization as required by MUX.** muxDevLoad calls this function twice. First time this function is called,* initialization string will be NULL . We are required to fill in the device* name ("usbNC1080") in the string and return. The next time this function is * called the intilization string will be proper.** <initString> will be in the following format :* "unit:vendorId:productId:<6bytes of mac address, delimited by :>"** PARAMETERS**.IP <initString>*The device initialization string.** RETURNS: An END object pointer or NULL on error.*/END_OBJ * usbNC1080Load    (    char * initString	                           /* initialization string */    )    {    NC1080_END_DEV * pDrvCtrl;                        /* driver structure */    UINT16 vendorId;                               /* vendor information */    UINT16 productId;                              /* product information */    DRV_LOG (DRV_DBG_LOAD, "Loading usbNC1080 ...\n", 1, 2, 3, 4, 5, 6);    if (initString == NULL)	return (NULL);    if (initString[0] == EOS)	{        /* Fill in the device name and return */	bcopy ((char *)NETCHIP_NAME, (void *)initString, NETCHIP_NAME_LEN);	return (0);	}    /* allocate the device structure */    pDrvCtrl = (NC1080_END_DEV *)calloc (sizeof (NC1080_END_DEV), 1);    if (pDrvCtrl == NULL)	{	DRV_LOG (DRV_DBG_LOAD, "No Memory!!...\n", 1, 2, 3, 4, 5, 6);	goto errorExit;	}    /* parse the init string, filling in the device structure */    if (usbNC1080EndParse (pDrvCtrl, initString, &vendorId, &productId) == ERROR)	{	DRV_LOG (DRV_DBG_LOAD, "Parse Failed.\n", 1, 2, 3, 4, 5, 6);	goto errorExit;	}    /* Ask the usbNC1080Lib to do the necessary initilization. */    if (usbNC1080DevInit(pDrvCtrl,vendorId,productId) == ERROR)	{	DRV_LOG (DRV_DBG_LOAD, "EnetDevInitFailed.\n",		    1, 2, 3, 4, 5, 6);	goto errorExit;	}    /* initialize the END and MIB2 parts of the structure */    if (END_OBJ_INIT (&pDrvCtrl->endObj, 		      (DEV_OBJ *)pDrvCtrl, 		      "usbNC1080", 		      pDrvCtrl->unit, 		      &usbNC1080FuncTable, 		      "usbNC1080") 		    == ERROR     || END_MIB_INIT (&pDrvCtrl->endObj, 		      M2_ifType_ethernet_csmacd, 		      &pDrvCtrl->enetAddr[0], 		      6, 		      NETCHIP_BUFSIZ, 		      NETCHIP_SPEED) 		     == ERROR)	{	DRV_LOG (DRV_DBG_LOAD, "END MACROS FAILED...\n",		1, 2, 3, 4, 5, 6);	goto errorExit;	}    /* Perform memory allocation/distribution */    if (usbNC1080EndMemInit (pDrvCtrl) == ERROR)	{	DRV_LOG (DRV_DBG_LOAD, "endMemInit() Failed...\n",		    1, 2, 3, 4, 5, 6);	goto errorExit;	}    /* set the flags to indicate readiness */    END_OBJ_READY (&pDrvCtrl->endObj,		    IFF_UP | IFF_RUNNING | IFF_NOTRAILERS );    DRV_LOG (DRV_DBG_LOAD, "Done loading Netchip ...\n",	1, 2, 3, 4, 5, 6);	pDrvCtrl->pDev->connected = TRUE;    return (&pDrvCtrl->endObj);errorExit:    if (pDrvCtrl != NULL)	{	free ((char *)pDrvCtrl);	}    return NULL;    }/**************************************************************************** usbNC1080Unload - unload a driver from the system** This function first brings down the device, and then frees any* stuff that was allocated by the driver in the load function.** RETURNS: OK or ERROR.*/LOCAL STATUS usbNC1080Unload    (    NC1080_END_DEV * pDrvCtrl	/* device to be unloaded */    )	    {    DRV_LOG (DRV_DBG_UNLOAD, "In netchipUnload... \n",	    	    0, 0, 0, 0, 0, 0);    END_OBJECT_UNLOAD (&pDrvCtrl->endObj);    usbNC1080DestroyDevice (pDrvCtrl);    DRV_LOG(DRV_DBG_UNLOAD,"netchipdestroy device ..done\n" 							, 0, 0, 0, 0, 0, 0);    netPoolDelete (pDrvCtrl->endObj.pNetPool);	DRV_LOG(DRV_DBG_UNLOAD,"netpoolDelete ..done\n" 							, 0, 0, 0, 0, 0, 0);    free(pDrvCtrl);	DRV_LOG(DRV_DBG_UNLOAD,"pDrvCtrl free...done\n" 							, 0, 0, 0, 0, 0, 0);    return (OK);    }/**************************************************************************** usbNC1080Start - start the device** This function just starts communication with the device.** RETURNS: OK or ERROR**/STATUS usbNC1080Start    (    NC1080_END_DEV  * pDrvCtrl	/* device ID */    )    {    UINT16 status;    int temp;    /* Check if the other side is connected, FIXME */    if (usbNC1080ReadRegister(pDrvCtrl, NETCHIP_STATUS, &status) != OK)        {        DRV_LOG (DRV_DBG_START, "usbNC1080Start: Failed to read status",                0, 0, 0, 0, 0, 0);        return ERROR;        }    if (!(status & 0x4000))        {        DRV_LOG (DRV_DBG_START, "usbNC1080Start: Peer not connected",                0, 0, 0, 0, 0, 0);        temp = usbNC1080Debug;        usbNC1080Debug |= DRV_DBG_REGISTER;        usbNC1080ShowStatus(status);        usbNC1080Debug = temp;        return ERROR;        }    /*     * Listem for any ethernet packet coming in.     * This is just simulating "connecting the interrupt" in End Model.     */     if (usbNC1080ListenForInput (pDrvCtrl) != OK)	{        DRV_LOG (DRV_DBG_START, "usbNC1080Start: Failed\n",0, 0, 0, 0, 0, 0);	return ERROR;	}    return OK;    }/**************************************************************************** usbNC1080Stop - stop the device** This function stops communication with the device.** RETURNS: OK or ERROR**/STATUS usbNC1080Stop    (    NC1080_END_DEV * pDrvCtrl	/* device ID */    )    {    /* Abort any pending transfers */	    DRV_LOG(DRV_DBG_UNLOAD,"In usbNC1080Stop..\n",		0, 0, 0, 0, 0, 0);    pDrvCtrl->pDev->connected = FALSE;    usbNC1080DestroyDevice(pDrvCtrl);    taskDelay(sysClkRateGet()*5);    return OK;    }/************************************************************************* usbNC1080ListenForInput - Listens for data on the Bulk In Pipe** Input IRP will be initialized to listen on the BULK input pipe and will* be submitted to the usbd.** RETURNS : OK or ERROR** NOMANUAL*/LOCAL STATUS usbNC1080ListenForInput    (    NC1080_END_DEV * pDrvCtrl		/* device to receive from */    )    {    pUSB_IRP pIrp = &pDrvCtrl->inIrp;    if (pDrvCtrl == NULL)	return ERROR;    /* Initialize IRP */    memset (pIrp, 0, sizeof (*pIrp));    pIrp->userPtr = pDrvCtrl;    pIrp->irpLen = sizeof (*pIrp);    pIrp->userCallback = usbNC1080RxCallback;    pIrp->timeout = USB_TIMEOUT_DEFAULT;    pIrp->transferLen = NETCHIP_IN_BFR_SIZE;	/* for the max pkt size */    pIrp->flags = USB_FLAG_SHORT_OK;    pIrp->bfrCount = 1;    pIrp->bfrList[0].pid = USB_PID_IN;    pIrp->bfrList[0].bfrLen = NETCHIP_IN_BFR_SIZE;    pIrp->bfrList[0].pBfr = (pUINT8)pDrvCtrl->pInBfrArray[pDrvCtrl->rxBufIndex];					/* for dynamic memory allocation */    /* Submit IRP */    if (usbdTransfer (usbNC1080Handle, pDrvCtrl->inPipeHandle, pIrp) != OK)	return ERROR;    pDrvCtrl->inIrpInUse = TRUE;    return OK;    }/**************************************************************************** usbNC1080RxCallback - Invoked when a Packet is received.** NOMANUAL*/LOCAL VOID usbNC1080RxCallback    (    pVOID p			/* completed IRP */    )    {    pUSB_IRP pIrp = (pUSB_IRP) p;    NC1080_END_DEV * pDrvCtrl = pIrp->userPtr;    /* Input IRP completed */    pDrvCtrl->inIrpInUse = FALSE;    /*     * If the IRP was successful then pass the data back to the client.     */    if (pIrp->result != OK)	{        pDrvCtrl->inErrors++;	/* FIXME : Should also update MIB */	if(pIrp->result == S_usbHcdLib_STALLED)	    {            DRV_LOG (DRV_DBG_RX, "BULK_IN End point stalled",                0, 0, 0, 0, 0, 0);	    usbdFeatureClear (usbNC1080Handle,			      pDrvCtrl->pDev->nodeId, 			      USB_RT_STANDARD | USB_RT_ENDPOINT, 			      0, 			      0);	    }	}    else	{	if( pIrp->bfrList[0].actLen >= 2)	    {	    PKT_PRINT(0x2,pIrp->bfrList[0].pBfr,pIrp->bfrList[0].actLen);  	    usbNC1080Recv (pDrvCtrl,pIrp->bfrList[0].pBfr, pIrp->bfrList[0].actLen);	    pDrvCtrl->rxBufIndex++;	    pDrvCtrl->rxBufIndex %= NETCHIP_NUM_IN_BFRS;	    }	}

⌨️ 快捷键说明

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