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

📄 usbklsiend.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	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 = (KLSI_ENET_IRP *) memalign (sizeof(ULONG), \						pDevCtrl->noOfIrps * \						sizeof (KLSI_ENET_IRP))) \					 == NULL)	{	KLSI_LOG (KLSI_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)	{	KLSI_LOG (KLSI_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),	   KLSI_IN_BFR_SIZE+8)) == NULL)	   {	   KLSI_LOG (KLSI_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 = KLSI_OUT_BFR_SIZE;    pDevCtrl->inBfrLen = KLSI_IN_BFR_SIZE;       /* Do the device specific initialization */        klsiInit (pDevCtrl);	    /*      * Decifer the descriptors provided by the device      * and try to find out which end point is what.     * Here it is assumed that there aren't any alternate      * settings for interfaces.     */    /* To start with, get the configuration descriptor */    if (usbdDescriptorGet (klsiHandle, 			   pNewDev->nodeId, 			   USB_RT_STANDARD | USB_RT_DEVICE, 			   USB_DESCR_CONFIGURATION, 			   0, 			   0, 			   sizeof (bfr), 			   bfr, 			   &actLen) 			   != OK)	{	KLSI_LOG (KLSI_DBG_INIT, "Could not GET Descriptor.\n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}    if ((pCfgDescr = (pUSB_CONFIG_DESCR) 	usbDescrParse (bfr, actLen, USB_DESCR_CONFIGURATION)) == NULL)	{	KLSI_LOG (KLSI_DBG_INIT, "Could not find Config. Descriptor.\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 meaning. The KLSI document      * says that it has only one interface with number 0. So the first      * (and only) interface found is the interface desited.      *       * If there are more interfaces and one of them meet our requirement     * (as reported by callback function), then we need to parse     * until the desired interface is found..     */    /*      * pBfr and bfr are needed in case there are multiple interfaces,     * to allow multiple parses.     */            if ((pIfDescr = (pUSB_INTERFACE_DESCR) 	usbDescrParseSkip (&pBfr, &actLen, USB_DESCR_INTERFACE)) == NULL)	{	KLSI_LOG (KLSI_DBG_INIT, "Could not find Interface Descriptor.\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)	{	KLSI_LOG (KLSI_DBG_INIT, "No Output End Point. \n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}    if ((pInEp = findEndpoint (pBfr, actLen, USB_ENDPOINT_IN)) == NULL)	{	KLSI_LOG (KLSI_DBG_INIT, "No Input End Point. \n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}    pDevCtrl->maxPower = pCfgDescr->maxPower;     /*     * Now, set the configuration.     * Note that any ConfigurationSet request will reset the device.     * Thus, an explicit device reset is not required      */    if (usbdConfigurationSet (klsiHandle, 			      pNewDev->nodeId, 			      pCfgDescr->configurationValue, 			      pCfgDescr->maxPower * USB_POWER_MA_PER_UNIT) 			   != OK)	return ERROR;     /* Now, Create the Pipes... */    if (usbdPipeCreate (klsiHandle, 			pNewDev->nodeId, 			pOutEp->endpointAddress, 			pCfgDescr->configurationValue, 			pNewDev->interface, 			USB_XFRTYPE_BULK, 			USB_DIR_OUT, 			FROM_LITTLEW (pOutEp->maxPacketSize), 			0, 			0, 			&pDevCtrl->outPipeHandle) 		!= OK)		{	KLSI_LOG (KLSI_DBG_INIT, "Output Pipe could not be created. \n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}        if (usbdPipeCreate (klsiHandle, 			pNewDev->nodeId, 			pInEp->endpointAddress, 			pCfgDescr->configurationValue, 			pNewDev->interface, 			USB_XFRTYPE_BULK, 			USB_DIR_IN, 			FROM_LITTLEW (pInEp->maxPacketSize), 			0, 			0, 			&pDevCtrl->inPipeHandle) 		    != OK)       	{	KLSI_LOG (KLSI_DBG_INIT, "Input Pipe could not be created \n",	     	     0, 0, 0, 0, 0, 0);	return ERROR;	}    pDevCtrl->inIrpInUse = FALSE;    /*      * Read the (Ethernet) Function Descriptor and get the details.     * Though this is described as a "descriptor", it is a vendor specific      * command for KLSI and is a control Pipe 0 transaction.     */       if (usbdDescriptorGet (klsiHandle, 			   pNewDev->nodeId, 			   USB_RT_STANDARD | USB_RT_DEVICE, 			   USB_DESCR_STRING, 			   1, 			   0x409, 			   sizeof (bfr), 			   bfr, 			   &actLen) 			!= OK)	{	KLSI_LOG (KLSI_DBG_INIT, "Could not GET String Descriptor.\n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}    /* UNICODE to ASCII conversion and then finally to MAC Address */    if (usbdVendorSpecific (klsiHandle,  			    pNewDev->nodeId,  			    USB_RT_VENDOR |USB_RT_DEV_TO_HOST,  			    USB_REQ_KLSI_ETHDESC_GET,  			    0,  			    0,  			    sizeof(bfr),  			    bfr,  			    &actLen)  			  != OK)	{	KLSI_LOG (KLSI_DBG_INIT, "Error retrieving Ethernet descriptor. \n",                  0, 0, 0, 0, 0, 0);	return ERROR;	}#if 0    printf("Eth Desc = ");     for(index=0;index<actLen;index++)	printf("%x ",bfr[index]);    printf("\n");#endif    for (index = 0; index< 6; index++)	{	pDevCtrl->macAdrs[index] = bfr[3+index];	}#if 0        printf("MAC Addrs = ");     for(index=0;index<6;index++)	printf("%x ",pDevCtrl->macAdrs[index]);    printf("\n");#endif     /* Set URB Size */    if (usbdVendorSpecific (klsiHandle, 			    pNewDev->nodeId, 			    USB_RT_VENDOR |USB_RT_HOST_TO_DEV, 			    USB_REQ_KLSI_SET_URB_SIZE, 			    64, 			    0, 			    0, 			    NULL, 			    NULL) 			!= OK)	{	KLSI_LOG (KLSI_DBG_INIT, "Error Setting URB Size. \n",		  0, 0, 0, 0, 0, 0);	return ERROR;	}         if (usbdVendorSpecific (klsiHandle, 			    pNewDev->nodeId, 			    USB_RT_VENDOR |USB_RT_HOST_TO_DEV, 			    USB_REQ_KLSI_SET_SOFS_TO_WAIT, 			    0x1, 			    0, 			    0, 			    NULL, 			    NULL) 			  != OK)	{	KLSI_LOG (KLSI_DBG_INIT, "Error setting SOFs \n",		  0, 0, 0, 0, 0, 0);	return ERROR;	}        /* Set No Multicasting */    if (usbdVendorSpecific (klsiHandle, 			    pNewDev->nodeId, 			    USB_RT_VENDOR |USB_RT_HOST_TO_DEV, 			    USB_REQ_KLSI_SET_MCAST_FILTER, 			    0, 			    0, 			    0, 			    NULL, 			    NULL) 			  != OK)	{	KLSI_LOG (KLSI_DBG_INIT, "Error setting Multicast Addresses \n",		  0, 0, 0, 0, 0, 0);	return ERROR;	}    /* Set Only directed Packets to be received */        if (usbdVendorSpecific (klsiHandle, 			    pNewDev->nodeId, 			    USB_RT_VENDOR |USB_RT_HOST_TO_DEV, 			    USB_REQ_KLSI_SET_PACKET_FILTER, 			    0x0004, 			    0, 			    0, 			    NULL, 			    NULL) 			 != OK)	{	KLSI_LOG (KLSI_DBG_INIT, "Error setting packet bitmap. \n",		     0, 0, 0, 0, 0, 0);	return ERROR;	}    return OK;    }/***************************************************************************** klsiEndStart - Starts communications over Ethernet via USB (device)** Since there is no interrupt available, the device is to be prevented from * communicating in some other way. Here, since the reception is based * on polling and the klsiListenForInput() is called for such polling,* the listening can be delayed to any packet coming in  by calling* klsiListenForInput(). This way, the traditional "interrupt enabling"   * is mimicked. This is for packet reception.** For packet transmission, communicateOk flag is used. Data is transmitted * only if this flag is true. This flag will be set to TRUE and will be* reset to FALSE in klsiEndStop().** RETURNS : OK or ERROR*/STATUS klsiEndStart    (    KLSI_DEVICE* pDevCtrl	        /* Device to be started */    )    {    KLSI_LOG (KLSI_DBG_START, "Entered klsiEndStart.\n",		 0, 0, 0, 0, 0, 0);        /*     * start listening on the BULK input pipe for any       *  ethernet packet coming in. This is how        * "connecting the interrupt" of the END Model is simulated.     */    pDevCtrl->communicateOk = TRUE;    if (klsi

⌨️ 快捷键说明

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