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

📄 usbnc1080end.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* usbNC1080End.c - NC1080 Turbo connect Network Interface driver *//* Copyright 2000-2001 Wind River Systems, Inc. *//*modification history--------------------01g,15oct01,wef  fix SPR 70953 - fixes man page generation and 70716 - fixes		 coding convention and some warnings01f,08aug01,dat  Removing warnings01e,08aug01,dat  Removing compiler warnings01d,31jul01,wef  fixed comments for man page genereation01c,03may01,wef  changed pUsbListDev to USB_NC1080_DEV, moved attach_request 		 definition to .c file from .h file.01b,09apr01,bri  modified for Dynamic Memory allocation, hot plugging 		 and multiple devices.01a,28nov00,bri  Created. Adapted from templateEnd.c.*//*DESCRIPTIONNC1080 Turbo connect device is a USB Host to Host communications device.This device consists of two SIEs to interface two hosts simultaneously, bidirectional FIFOs and an EEPROM interface. EEPROM interface provides the necessary initialization details for the device. For each host, this device offers a Pair of BULK IN and BULK OUT end points having 256 byte fifo each, per direction. Additionally, it offers a Pair of mailbox end points and a status end point for each host. mail box end points are intended for additional data communication. Status endpoint (interrupt) informs the host of any data in its Fifo. It has the remote wakeup signalling capability, if any data becomes available for a host.As such the device is a simple data transfer device. It communicates with any other device that understands the protocol used by the driver. The protocol is introduced  by the driver. The same protocol is being followed by all drivers in all OSs. The device will be viewed as a Network device and data will be packetized in Ethernet frames. In addition, the ethernet frames are packetized in another protocol and sent on the Bulk out pipe. This protocol is described underneath.This driver uses only the Bulk End points for the communcation. The remaining end points are ignored. The driver is an VxWorks END driver for the device which also incorporates the NC1080 protocol. Then this driver uses the Bulk In and Bulk out end points for communication over USB. USB relies on the HC interrupt for all its activities. This means that there is no Polled mode for a USB device. So the NC1080 End driver doesn't support polled mode functions.The NC1080 device is a back-to-back communication device. So the usbNC1080 end driver doesn't support broadcast/multicast functionality.Since the device by itself is not a Network device, it doesn't have any MAC address. It is expected that the User passes the MAC address via the initialization string to endLoad(). The initilization string format is described in sysNC1080End.c.INITIALIZATIONThe driver is expected to be initialized via usbNC1080DrvInit() before the endLoad is called. It is required that the device be recognized as attached by the HCD/USBD and attach callback be exceuted, before the endLoad() for the usbNC1080 driver is called as a part of the system wide network initialization. PROTOCOLNC1080 protocol:  ethernet framing, and only use bulk endpoints (01/81);not mailboxes 02/82 or status interrupt 83).  Expects Ethernet bridging.Odd USB length == always short read. the data needs to be packetized before sending to the Netchip1080 device for transmission. Also the received datahas to be de-packetized before we send it up. The packetizing protocol is  -------------------------------------  |header|    data (payload)   |footer|  -------------------------------------	- netchip_header	- payload, in Ethernet framing (14 byte header etc)	- (optional padding byte, if needed so that length is odd)	- netchip_footer*//* includes */#include "vxWorks.h"#include "stdlib.h"#include "cacheLib.h"#include "intLib.h"#include "end.h"		/* Common END structures. */#include "endLib.h"#include "lstLib.h"		/* Needed to maintain protocol list. */#include "wdLib.h"#include "iv.h"#include "semLib.h"#include "etherLib.h"#include "logLib.h"#include "netLib.h"#include "stdio.h"#include "sysLib.h"#include "errno.h"#include "errnoLib.h"#include "memLib.h"#include "iosLib.h"#undef	ETHER_MAP_IP_MULTICAST#include "etherMultiLib.h"		/* multicast stuff. */#include "net/mbuf.h"#include "net/unixLib.h"#include "net/protosw.h"#include "net/systm.h"#include "net/if_subr.h"#include "net/route.h"#include "sys/socket.h"#include "sys/ioctl.h"#include "sys/times.h"#include "usb/usbPlatform.h"#include "usb/ossLib.h" 	/* operations system srvcs */#include "usb/usb.h"		/* general USB definitions */#include "usb/usbListLib.h"	/* linked list functions */#include "usb/usbdLib.h"	/* USBD interface */#include "usb/usbLib.h" 	/* USB utility functions */#include "drv/usb/usbNC1080End.h"	/* device header file*/#define	NETCHIP_PAD_BYTE		((UINT8)0xAC)#define NETCHIP_MIN_HEADER		6/* * This will only work if there is only a single unit, for multiple * unit device drivers these should be integrated into the END_DEVICE * structure. */M_CL_CONFIG usbNC1080MclBlkConfig = 	/* network mbuf configuration table */    {    /*    no. mBlks		no. clBlks	memArea		memSize    -----------		----------	-------		-------    */    0, 			0, 		NULL, 		0    };CL_DESC usbNC1080ClDescTbl [] = 	/* network cluster pool configuration table */    {    /*    clusterSize			num	memArea		memSize    -----------			----	-------		-------    */    {NETCHIP_MTU + EH_SIZE + 2,	0,	NULL,		0}    };int usbNC1080ClDescTblNumEnt = (NELEMENTS(usbNC1080ClDescTbl));NET_POOL usbNC1080CmpNetPool;#define NETCHIP_MIN_FBUF	(NETCHIP_BUFSIZ) /* min first buffer size *//* DEBUG MACROS */#define DEBUG#ifdef DEBUG#   define LOGMSG(x,a,b,c,d,e,f) \	if (endDebug) \	    { \	    logMsg (x,a,b,c,d,e,f); \	    }#else#   define LOGMSG(x,a,b,c,d,e,f)#endif /* ENDDEBUG */#define DRV_DBG#ifdef	DRV_DBG#define DRV_DBG_OFF		0x0000#define DRV_DBG_RX		0x0001#define	DRV_DBG_TX		0x0002#define DRV_DBG_ATTACH		0x0004#define DRV_DBG_INIT		0x0008#define DRV_DBG_REGISTER	0x1000#define	DRV_DBG_LOAD		0x0020#define	DRV_DBG_IOCTL		0x0040#define	DRV_DBG_RESET		0x1000#define DRV_DBG_START		0x0100#define DRV_DBG_PARSE		0x20000#define DRV_DBG_UNLOAD		0x40000int	usbNC1080Debug = 0;	 /* no debug msgs, by default */#define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6)                        \	if (usbNC1080Debug & FLG)                                        \            logMsg(X0, X1, X2, X3, X4, X5, X6);void DRV_DESC_PRINT(int flg, char * str, UINT8 * ptr, UINT16 len)    {    if (usbNC1080Debug & flg)        {	int i = 0;	printf("%s : %d bytes\n",str,len);	for(i = 0; i < len; i++)	    {	    printf("%x ", *ptr++);	    if ((i+1)%16 == 0)		printf("\n");	    }	printf("\n");        }    }#else /*DRV_DBG*/#define DRV_LOG(DBG_SW, X0, X1, X2, X3, X4, X5, X6)#define DRV_DESC_PRINT(DBG_SW,X,Y,Z)#endif /*DRV_DBG*/#define PKT_DBG#ifdef PKT_DBG#define PKT_DBG_TX	((UINT8)0x01)#define PKT_DBG_RX	((UINT8)0x02)UINT8 pktDebug = 0; /*(PKT_DBG_TX | PKT_DBG_RX); */void PKT_PRINT(int flg, UINT8 *pkt, UINT16 len)    {    NC_HEADER * pHeader = (NC_HEADER *)pkt;    NC_FOOTER * pFooter;    int i =0;    if (!(flg & pktDebug))	return;    if( flg == PKT_DBG_TX)	printf(" Tx Packet : \n");    else	printf(" Rx Packet : \n");     printf("Header : hdr_len : %d  pkt_len : %d pkt_id : %x \n",		pHeader->hdr_len, pHeader->packet_len, pHeader->packet_id);        printf(" Data :\n");    for (i=0; i< pHeader->packet_len;i++)	{	printf("%x ",*(pkt+pHeader->hdr_len+i));	if (((i+1) % 16) == 0)	    printf("\n");	}        printf("\n");    if (((pHeader->packet_len + sizeof (*pFooter)) & 0x01) == 0)	{	printf("Pad Byte : %x \n",*(pkt+pHeader->hdr_len+pHeader->packet_len));	pFooter = (NC_FOOTER *)(pkt+pHeader->hdr_len+pHeader->packet_len + 1);	}    else	{	pFooter = (NC_FOOTER *)(pkt+pHeader->hdr_len+pHeader->packet_len);	}        printf("Footer : pkt_id : %x \n",pFooter->packet_id);    }#else#define PKT_PRINT( X, Y, Z)#endif    /* LOCALS */LOCAL USBD_CLIENT_HANDLE usbNC1080Handle; /* our USBD client handle */LOCAL UINT16 initCount = 0;	    	    /* Count of init nesting */LOCAL MUTEX_HANDLE usbNC1080Mutex;LOCAL MUTEX_HANDLE usbNC1080TxMutex;LOCAL MUTEX_HANDLE usbNC1080RxMutex;LOCAL SEM_HANDLE   usbNC1080IrpSem;       /* Semaphore for IRP Synchronisation */LOCAL LIST_HEAD usbNC1080DevList;	    	/* linked list of Device Structs */LOCAL LIST_HEAD    	reqList;            /* Attach callback request list */		LOCAL const struct product    {    char	*name;    UINT16	idVendor;    UINT16	idProduct;} products [] = {	{ "NC1080 TurboCONNECT", 0x0525, 0x1080 },	/* NC1080 */	{ 0, 0, 0 },					            /* END */};typedef struct attach_request    {    LINK reqLink;                          /* linked list of requests */    USB_NETCHIP_ATTACH_CALLBACK callback;  /* client callback routine */    pVOID callbackArg;                     /* client callback argument*/    } ATTACH_REQUEST, *pATTACH_REQUEST;    /* added for multiple devices *//* externally visible interfaces. */END_OBJ * 	usbNC1080Load (char* initString);     /* the endLoad ( ) */STATUS          usbNC1080DrvInit ( );             /* Initialization */STATUS usbNC1080DynamicAttachRegister (USB_NETCHIP_ATTACH_CALLBACK callback,										pVOID arg);STATUS usbNC1080DynamicAttachRegister (USB_NETCHIP_ATTACH_CALLBACK callback,											pVOID arg);STATUS usbNC1080DevLock (USBD_NODE_ID nodeId);STATUS usbNC1080DevUnlock (USBD_NODE_ID nodeId);/* END Specific interfaces. */IMPORT	int     endMultiLstCnt (END_OBJ* pEnd);/* forward static functions */LOCAL STATUS	usbNC1080Start	(NC1080_END_DEV * pDrvCtrl);LOCAL STATUS	usbNC1080Stop	    (NC1080_END_DEV * pDrvCtrl);LOCAL int	    usbNC1080Ioctl    (NC1080_END_DEV * pDrvCtrl, int cmd, caddr_t data);LOCAL STATUS	usbNC1080Unload	(NC1080_END_DEV * pDrvCtrl);LOCAL STATUS	usbNC1080Send	    (NC1080_END_DEV * pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS	usbNC1080MCastAdd (NC1080_END_DEV * pDrvCtrl, char * pAddress);LOCAL STATUS	usbNC1080MCastDel (NC1080_END_DEV * pDrvCtrl, char * pAddress);LOCAL STATUS	usbNC1080MCastGet (NC1080_END_DEV * pDrvCtrl, MULTI_TABLE * pTable);LOCAL STATUS	usbNC1080PollSend (NC1080_END_DEV * pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS	usbNC1080PollRcv  (NC1080_END_DEV * pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS	usbNC1080Recv	(NC1080_END_DEV * pDrvCtrl, UINT8 * pData, UINT16 len);LOCAL STATUS 	usbNC1080Shutdown (int errCode);LOCAL STATUS 	usbNC1080Reset 	(NC1080_END_DEV * pDrvCtrl);LOCAL STATUS 	usbNC1080DevInit 	(NC1080_END_DEV * pDrvCtrl,                                 UINT16 vendorId,                                 UINT16 productId);LOCAL void 	usbNC1080TxCallback(pVOID p);LOCAL void 	usbNC1080RxCallback(pVOID p);LOCAL STATUS 	usbNC1080ListenForInput   (NC1080_END_DEV * pDrvCtrl);LOCAL USB_NC1080_DEV * usbNC1080FindUsbNode	    (USBD_NODE_ID nodeId);LOCAL USB_NC1080_DEV * usbNC1080FindUsbDevice 	(UINT16 vendorId, UINT16 productId);LOCAL VOID 	usbNC1080DestroyDevice 	    (NC1080_END_DEV * pDrvCtrl);LOCAL STATUS 	usbNC1080AttachCallback			 	(USBD_NODE_ID nodeId,   				UINT16 attachAction,    				UINT16 configuration,    				UINT16 interface,    				UINT16 deviceClass,    				UINT16 deviceSubClass,    				UINT16 deviceProtocol				);LOCAL STATUS usbNC1080ReadRegister(NC1080_END_DEV * pDrv, UINT8 reg, UINT16 * retVal);LOCAL STATUS usbNC1080WriteRegister(NC1080_END_DEV * pDrv, UINT8 reg, UINT16 retVal);LOCAL VOID notifyAttach ( USB_NC1080_DEV* pDev, UINT16 attachCode);/* * Declare our function table.  This is static across all driver * instances. */LOCAL NET_FUNCS usbNC1080FuncTable =    {    (FUNCPTR) usbNC1080Start,	/* Function to start the device. */    (FUNCPTR) usbNC1080Stop,	/* Function to stop the device. */    (FUNCPTR) usbNC1080Unload,	/* Unloading function for the driver. */    (FUNCPTR) usbNC1080Ioctl,	/* Ioctl function for the driver. */    (FUNCPTR) usbNC1080Send,	/* Send function for the driver. */    (FUNCPTR) usbNC1080MCastAdd,	/* Multicast add function for the */				/* driver. */    (FUNCPTR) usbNC1080MCastDel,	/* Multicast delete function for */				/* the driver. */    (FUNCPTR) usbNC1080MCastGet,	/* Multicast retrieve function for */				/* the driver. */    (FUNCPTR) usbNC1080PollSend,	/* Polling send function */    (FUNCPTR) usbNC1080PollRcv,	/* Polling receive function */    endEtherAddressForm,	/* put address info into a NET_BUFFER */    endEtherPacketDataGet, 	/* get pointer to data in NET_BUFFER */    endEtherPacketAddrGet 	/* Get packet addresses. */    };/* * functions to do a short (UINT16) access to read / write the registers * from the net1080 chip. */LOCAL STATUS usbNC1080ReadRegister    (    NC1080_END_DEV * pDrv,     UINT8 reg,     UINT16 * retVal    )    {    UINT16 actLen;    UINT16 data;    if (usbdVendorSpecific (usbNC1080Handle, pDrv->pDev->nodeId,	USB_RT_VENDOR | USB_RT_DEV_TO_HOST,	/* bmRequest */ 	NETCHIP_REQ_REGISTER_READ, 		/* bRequest */	0, 					/* wValue */	TO_LITTLEW(reg),			/* wIndex */	TO_LITTLEW(2),				/* wLength must be 2 */	(UINT8 *)retVal, &actLen) != OK)	{	DRV_LOG (DRV_DBG_REGISTER, "Read Register Failed reading from "		"%d regsiter..\n", reg, 0, 0, 0, 0, 0);	return ERROR;	}      data = FROM_LITTLEW(*retVal);    *retVal = data;    return OK;    }LOCAL STATUS usbNC1080WriteRegister     (    NC1080_END_DEV * pDrv,     UINT8 reg,     UINT16 data    )    {    if (usbdVendorSpecific (usbNC1080Handle, pDrv->pDev->nodeId,	USB_RT_VENDOR | USB_RT_HOST_TO_DEV,	/* bmRequest */	NETCHIP_REQ_REGISTER_READ, 		/* bRequest */	TO_LITTLEW(data), 			/* wValue */	TO_LITTLEW(reg),			/* wIndex */	0,					/* wLength */	0, NULL) != OK)	{	DRV_LOG (DRV_DBG_REGISTER, "Write Register Failed while writing "		"%d to %d register..\n", data, reg, 0, 0, 0, 0);	return ERROR;	}     return OK;}/* Register display routines *//**************************************************************************** usbNC1080ShowStatus - Displays the NC1080 status register* * Displays, in human readable way, the status register of the NC1080 * Turboconnect device** RETURNS: N/A */LOCAL void usbNC1080ShowStatus     (    UINT16 status    )    {    DRV_LOG (DRV_DBG_REGISTER, "Status Register : %x \n"                               "Reading from Port : %c \n",                                status,                                (status & 0x8000)?'A':'B',                                 0, 0, 0, 0);    DRV_LOG (DRV_DBG_REGISTER, "Peer port : \n"                               "   %sconnected : %s: "                               "MBOX data %savailable : "                               "data %savailable \n",                                (UINT)((status & 0x4000)?"":"dis"),                                (UINT)((status & 0x2000)?"suspended":"live"),                                (UINT)((status & 0x1000)?"":"Not"),                                (UINT)((status & 0x0300)?"":"Not"),                                0, 0);    DRV_LOG (DRV_DBG_REGISTER, "This port : \n"                               "\t%sconnected : %s: "                               "MBOX data %savailable : "

⌨️ 快捷键说明

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