📄 usbnc1080end.c
字号:
STATUS usbNC1080DevInit ( NC1080_END_DEV * pDrvCtrl, /* the device structure to be updated */ UINT16 vendorId, /* manufacturer id of the device */ UINT16 productId /* product id of the device */ ) { USB_NC1080_DEV * pNewDev; pUSB_CONFIG_DESCR pCfgDescr; pUSB_INTERFACE_DESCR pIfDescr; pUSB_ENDPOINT_DESCR pOutEp; pUSB_ENDPOINT_DESCR pInEp; UINT8 bfr [USB_MAX_DESCR_LEN]; pUINT8 pBfr; UINT8** ppIrpBfrs; UINT8** ppInBfr; UINT16 actLen; int index = 0; if(pDrvCtrl == NULL) { DRV_LOG (DRV_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 = usbNC1080FindUsbDevice (vendorId,productId)) == NULL) { DRV_LOG (DRV_DBG_INIT,"Could not find device in the attached " "usbNC1080 devices..\n", 0, 0, 0, 0, 0, 0); return ERROR; } /* Link the End Structure and the device that is found */ pDrvCtrl->pDev = pNewDev; /* Allocate memory for the output buffers..*/ if ((ppIrpBfrs = (UINT8**) memalign (sizeof(ULONG), pDrvCtrl->noOfIrps * sizeof (char *))) == NULL) { DRV_LOG (DRV_DBG_INIT,"Could not allocate memory for IRPs.\n", 0, 0, 0, 0, 0, 0); return ERROR; } for (index=0;index<pDrvCtrl->noOfIrps;index++) { if ((ppIrpBfrs[index] = (pUINT8)memalign(sizeof(ULONG), NETCHIP_OUT_BFR_SIZE+8)) == NULL) { DRV_LOG (DRV_DBG_INIT,"Could not allocate memory for buffer" " for input Irp %x\n", index, 0, 0, 0, 0, 0); return ERROR; } } /* Allocate memory for input buffers */ if ((ppInBfr = (UINT8**)memalign(sizeof(ULONG), pDrvCtrl->noOfInBfrs * sizeof (char *)))==NULL) { DRV_LOG (DRV_DBG_INIT,"Could Not align Memory for" " InBfrs pointer array...\n", 0, 0, 0, 0, 0, 0); return ERROR; } for (index=0;index<pDrvCtrl->noOfInBfrs;index++) { if ((ppInBfr[index] = (pUINT8)memalign(sizeof(ULONG), NETCHIP_IN_BFR_SIZE+8)) == NULL) { DRV_LOG (DRV_DBG_INIT,"Could not allocate memory for" " buffer for input Irp %x\n", index, 0, 0, 0, 0, 0); return ERROR; } } pDrvCtrl->pOutBfrArray= ppIrpBfrs; pDrvCtrl->pInBfrArray = ppInBfr; pDrvCtrl->txBufIndex=0; pDrvCtrl->rxBufIndex=0; pDrvCtrl->inBfrLen = NETCHIP_IN_BFR_SIZE; /* * Now we decifer the descriptors provided by the device .. * we try finding out what end point is what.. */ /* To start with, get the configuration descriptor ..*/ if (usbdDescriptorGet (usbNC1080Handle, pNewDev->nodeId, USB_RT_STANDARD | USB_RT_DEVICE, USB_DESCR_CONFIGURATION, 0, 0, sizeof (bfr), bfr, &actLen) != OK) { DRV_LOG (DRV_DBG_INIT, "DescriptorGet failed for CFG...\n", 0, 0, 0, 0, 0, 0); return ERROR; } if ((pCfgDescr = (pUSB_CONFIG_DESCR) usbDescrParse (bfr, actLen, USB_DESCR_CONFIGURATION)) == NULL) { DRV_LOG (DRV_DBG_INIT, "Could not find Config. Desc...\n", 0, 0, 0, 0, 0, 0); return ERROR; } /* DRV_DESC_PRINT (DRV_DBG_INIT, "Configuration Descriptor", (UINT8 *)pCfgDescr, actLen); */ 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 DRV 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.. */ if ((pIfDescr = (pUSB_INTERFACE_DESCR) usbDescrParseSkip (&pBfr, &actLen, USB_DESCR_INTERFACE)) == NULL) { DRV_LOG (DRV_DBG_INIT, "Could not find Interface Desc.\n", 0, 0, 0, 0, 0, 0); return ERROR; } /* * DRV_DESC_PRINT (DRV_DBG_INIT, "Interface Descriptor", * (UINT8 *)pIfDescr, actLen); */ /* Find out the output and input end points ..*/ if ((pOutEp = findEndpoint (pBfr, actLen, USB_ENDPOINT_OUT)) == NULL) { DRV_LOG (DRV_DBG_INIT, "No Output End Point \n", 0, 0, 0, 0, 0, 0); return ERROR; } DRV_DESC_PRINT (DRV_DBG_INIT, "Out EP", (UINT8 *)pOutEp, 5); if ((pInEp = findEndpoint (pBfr, actLen, USB_ENDPOINT_IN)) == NULL) { DRV_LOG (DRV_DBG_INIT, "No Input End Point \n", 0, 0, 0, 0, 0, 0); return ERROR; } DRV_DESC_PRINT (DRV_DBG_INIT, "In EP", (UINT8 *)pInEp, 5); pNewDev->maxPower = pCfgDescr->maxPower; /* Now, set the configuration. */ if (usbdConfigurationSet (usbNC1080Handle, pNewDev->nodeId, pCfgDescr->configurationValue, pCfgDescr->maxPower * USB_POWER_MA_PER_UNIT) != OK) return ERROR; /* reset the device */ usbNC1080Reset(pDrvCtrl); /* Now, Create the Pipes.. */ if (usbdPipeCreate (usbNC1080Handle, pNewDev->nodeId, pOutEp->endpointAddress, pCfgDescr->configurationValue, pNewDev->interface, USB_XFRTYPE_BULK, USB_DIR_OUT, FROM_LITTLEW (pOutEp->maxPacketSize), 0, 0, &pDrvCtrl->outPipeHandle) != OK) { DRV_LOG (DRV_DBG_INIT, "Pipe O/P coud not be created \n", 0, 0, 0, 0, 0, 0); return ERROR; } if (usbdPipeCreate (usbNC1080Handle, pNewDev->nodeId, pInEp->endpointAddress, pCfgDescr->configurationValue, pNewDev->interface, USB_XFRTYPE_BULK, USB_DIR_IN, FROM_LITTLEW (pInEp->maxPacketSize), 0, 0, &pDrvCtrl->inPipeHandle) != OK) { DRV_LOG (DRV_DBG_INIT, "Pipe I/P coud not be created \n", 0, 0, 0, 0, 0, 0); return ERROR; } /* Reset counters and indices */ pDrvCtrl->inIrpInUse = FALSE; pDrvCtrl->outIrpInUse = FALSE; pDrvCtrl->txBufIndex = 0; pDrvCtrl->rxBufIndex = 0; pDrvCtrl->txPkts = 0; /* Now device is ready for communication : return back to the caller */ return OK; }/**************************************************************************** usbNC1080Shutdown - shuts down usbNC1080Lib** <errCode> should be OK or S_usbNC1080Lib_xxxx. This value will be* passed to ossStatus() and the return value from ossStatus() is the* return value of this function.** RETURNS: OK, or ERROR per value of <errCode> passed by caller*/LOCAL STATUS usbNC1080Shutdown ( int errCode ) { NC1080_END_DEV * pDev; /* Dispose of any open connections. */ while ((pDev = usbListFirst (&usbNC1080DevList)) != NULL) usbNC1080DestroyDevice (pDev); /* * Release our connection to the USBD. The USBD automatically * releases any outstanding dynamic attach requests when a client * unregisters. */ if (usbNC1080Handle != NULL) { usbdClientUnregister (usbNC1080Handle); usbNC1080Handle = NULL; } /* Release resources. */ if (usbNC1080Mutex != NULL) { OSS_MUTEX_DESTROY (usbNC1080Mutex); usbNC1080Mutex = NULL; } if (usbNC1080TxMutex != NULL) { OSS_MUTEX_DESTROY (usbNC1080TxMutex); usbNC1080TxMutex = NULL; } if (usbNC1080RxMutex != NULL) { OSS_MUTEX_DESTROY (usbNC1080RxMutex); usbNC1080RxMutex = NULL; } if (usbNC1080IrpSem != NULL) { OSS_SEM_DESTROY (usbNC1080IrpSem); usbNC1080IrpSem = NULL; } usbdShutdown(); return ossStatus (errCode); }/**************************************************************************** usbNC1080DestroyDevice - disposes of a NC1080_END_DEV structure** Unlinks the indicated NC1080_END_DEV structure and de-allocates* resources associated with the channel.** RETURNS: N/A*/VOID usbNC1080DestroyDevice ( NC1080_END_DEV * pDrvCtrl ) { USB_NC1080_DEV * pDev; if (pDrvCtrl != NULL) { pDev = pDrvCtrl->pDev; /* Unlink the structure. */ usbListUnlink (&pDev->devLink); /* Release pipes and wait for IRPs to be cancelled if necessary. */ if (pDrvCtrl->outPipeHandle != NULL) usbdPipeDestroy (usbNC1080Handle, pDrvCtrl->outPipeHandle); if (pDrvCtrl->inPipeHandle != NULL) usbdPipeDestroy (usbNC1080Handle, pDrvCtrl->inPipeHandle); while (pDrvCtrl->outIrpInUse || pDrvCtrl->inIrpInUse) OSS_THREAD_SLEEP (1); /* Release Input buffers*/ if ( pDrvCtrl->pInBfrArray !=NULL) { OSS_FREE(pDrvCtrl->pInBfrArray); taskDelay(sysClkRateGet()*1); DRV_LOG (DRV_DBG_ATTACH, "Destroy device InBfrArray destroyed...\n", 0, 0, 0, 0, 0, 0); } /* Release outputIrp buffers*/ if ( pDrvCtrl->pOutBfrArray != NULL) { OSS_FREE(pDrvCtrl->pOutBfrArray); taskDelay(sysClkRateGet()*1); DRV_LOG (DRV_DBG_ATTACH, "Destroy device pOutBfrArray destroyed...\n", 0, 0, 0, 0, 0, 0); } /* Release structure. */ if (pDev!=NULL) { OSS_FREE (pDev); DRV_LOG (DRV_DBG_ATTACH, "destroy device pDev destroyed...\n", 0, 0, 0, 0, 0, 0); } } }/**************************************************************************** usbNC1080EndMemInit - initialize memory for the device.** We setup the END's Network memory pool. This code is highly generic and* very simple. We just follow the technique described in netBufLib.* We don't even need to make the memory cache DMA coherent. This is because* unlike other END drivers, which act on the top of the hardware, we are* layers above the hardware.** RETURNS: OK or ERROR.* NOMANUAL*/STATUS usbNC1080EndMemInit ( NC1080_END_DEV * pDrvCtrl /* device to be initialized */ ) { /* * This is how we would set up and END netPool using netBufLib(1). * This code is pretty generic. */ if ((pDrvCtrl->endObj.pNetPool = malloc (sizeof (NET_POOL))) == NULL) return (ERROR); usbNC1080MclBlkConfig.mBlkNum = 512; usbNC1080ClDescTbl[0].clNum = 256; usbNC1080MclBlkConfig.clBlkNum = usbNC1080ClDescTbl[0].clNum; /* Calculate the total memory for all the M-Blks and CL-Blks. */ usbNC1080MclBlkConfig.memSize = (usbNC1080MclBlkConfig.mBlkNum * (MSIZE + sizeof (long))) + (usbNC1080MclBlkConfig.clBlkNum * (CL_BLK_SZ + sizeof(long))); if ((usbNC1080MclBlkConfig.memArea = (char *) memalign (sizeof(long), usbNC1080MclBlkConfig.memSize)) == NULL) return (ERROR); /* Calculate the memory size of all the clusters. */ usbNC1080ClDescTbl[0].memSize = (usbNC1080ClDescTbl[0].clNum * (NETCHIP_BUFSIZ + 8)) + sizeof(int); /* Allocate the memory for the clusters from cache safe memory. */ usbNC1080ClDescTbl[0].memArea = (char *) cacheDmaMalloc (usbNC1080ClDescTbl[0].memSize); if (usbNC1080ClDescTbl[0].memArea == NULL) { DRV_LOG (DRV_DBG_LOAD,"usbNC1080EndMemInit:system memory " "unavailable\n", 1, 2, 3, 4, 5, 6); return (ERROR); } /* Initialize the memory pool. */ if (netPoolInit(pDrvCtrl->endObj.pNetPool, &usbNC1080MclBlkConfig, &usbNC1080ClDescTbl[0], usbNC1080ClDescTblNumEnt, NULL) == ERROR) { DRV_LOG (DRV_DBG_LOAD, "Could not init buffering\n", 1, 2, 3, 4, 5, 6); return (ERROR); } if ((pDrvCtrl->pClPoolId = netClPoolIdGet (pDrvCtrl->endObj.pNetPool, NETCHIP_MTU, FALSE)) == NULL) { DRV_LOG (DRV_DBG_LOAD, "netClPoolIdGet() not successfull \n", 1, 2, 3, 4, 5, 6); return (ERROR); } DRV_LOG (DRV_DBG_LOAD, "Memory setup complete\n", 1, 2, 3, 4, 5, 6); return OK; }/**************************************************************************** usbNC1080EndParse - parse the init string** Parse the input string. Fill in values in the driver control structure.** The muxLib.o module automatically prepends the unit number to the user's* initialization string from the BSP (configNet.h).** This function parses the input string and fills in the places pointed* to by <pVendorId> and <pProductId>. Unit Number of the string will be* be stored in the device structure pointed to by <pDrvCtrl>.* The MAC Address of the card will be passed onto us by this initString.** .IP <pDrvCtrl>* Pointer to the device structure.* .IP <initString>* Initialization string for the device. It will be of the following format :* "unit:vendorId:productId:no of input irp buffers: no of output IRP buffers:* <6 byte mac address, delimited by :>"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -