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

📄 templateend.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 3 页
字号:
/* templateEnd.c - template END  network interface driver *//* Copyright 1984-1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*TODO -	Remove the template modification history and begin a new history	starting with version 01a and growing the history upward with	each revision.modification history--------------------01i,29mar99,dat  documentation, SPR 26119. fixed .bS/.bE usage01h,28feb99,pul  changed the prototype for END NET functions, to have END_OBJ 		 reference as the first argument rather than device object,		 fix for SPR#2428501g,17feb99,dat  documentation, removed beta warning01f,29sep98,dat  Fixed problem in PollRx relating to SPR 22325.01e,28sep98,dat  SPR 22325, system mode transition, plus fixed warnings		 and template is now compilable (SPR 22204).01d,17jul98,db   changed "holder" in templateParse from char** to char *.		 fixed references to "holder" in templateParse(spr #21464).01c,15oct97,gnn  revised to reflect the latest API changes.01b,05may97,dat  added TODO's for documentation and macros.01a,04feb97,gnn	 written.*//*DESCRIPTIONTODO - Describe the chip being used completely, even if it provides morefeatures than ethernet.TODO - Describe the device's full ethernet capabilities, even if this driverdoesn't or can't utilize all of them.  Describe the features that the driverdoes implement and any restrictions on their use.TODO - Describe all macros that can be used to customize this driver.  Allaccesses to chip registers should be done through redefineable macros.In this example driver the macros TEMPLATE_OUT_SHORT and TEMPLATE_IN_SHORTare sample macros to read/write data to a mock device.  If a devicecommunicates through formatted control blocks in shared memory, theaccesses to those control blocks should also be through redefinablemacros.The macros SYS_INT_CONNECT, SYS_INT_DISCONNECT, and SYS_INT_ENABLE allowthe driver to be customized for BSPs that use special versions of theseroutines.The macro SYS_INT_CONNECT is used to connect the interrupt handler tothe appropriate vector.  By default it is the routine intConnect().The macro SYS_INT_DISCONNECT is used to disconnect the interrupt handler priorto unloading the module.  By default this is a dummy routine thatreturns OK.The macro SYS_INT_ENABLE is used to enable the interrupt level for theend device.  It is called once during initialization.  By default this isthe routine sysLanIntEnable(), defined in the module sysLib.o.The macro SYS_ENET_ADDR_GET is used to get the ethernet address (MAC)for the device.  The single argument to this routine is the END_DEVICEpointer.  By default this routine copies the ethernet address stored inthe global variable sysTemplateEnetAddr into the END_DEVICE structure.INCLUDES:end.h endLib.h etherMultiLib.hSEE ALSO: muxLib, endLib.I "Writing and Enhanced Network Driver"*//* 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"IMPORT	int endMultiLstCnt (END_OBJ* pEnd);/* defines *//* Configuration items */#define END_BUFSIZ      (ETHERMTU + ENET_HDR_REAL_SIZ + 6)#define EH_SIZE		(14)#define END_SPEED_10M	10000000	/* 10Mbs */#define END_SPEED_100M	100000000	/* 100Mbs */#define END_SPEED       END_SPEED_10M/* Cache macros */#define END_CACHE_INVALIDATE(address, len) \        CACHE_DRV_INVALIDATE (&pDrvCtrl->cacheFuncs, (address), (len))#define END_CACHE_PHYS_TO_VIRT(address) \        CACHE_DRV_PHYS_TO_VIRT (&pDrvCtrl->cacheFuncs, (address))#define END_CACHE_VIRT_TO_PHYS(address) \        CACHE_DRV_VIRT_TO_PHYS (&pDrvCtrl->cacheFuncs, (address))/* * Default macro definitions for BSP interface. * These macros can be redefined in a wrapper file, to generate * a new module with an optimized interface. *//* Macro to connect interrupt handler to vector */#ifndef SYS_INT_CONNECT#   define SYS_INT_CONNECT(pDrvCtrl,rtn,arg,pResult) \	{ \	IMPORT STATUS sysIntConnect(); \	*pResult = intConnect ((VOIDFUNCPTR *)INUM_TO_IVEC (pDrvCtrl->ivec), \			     rtn, (int)arg); \	}#endif/* Macro to disconnect interrupt handler from vector */LOCAL VOID dummyIsr (void) { };#ifndef SYS_INT_DISCONNECT#   define SYS_INT_DISCONNECT(pDrvCtrl,rtn,arg,pResult) \	{ \	IMPORT STATUS intConnect(); \	*pResult = intConnect ((VOIDFUNCPTR *)INUM_TO_IVEC (pDrvCtrl->ivec), \			     dummyIsr, (int)arg); \	}#endif/* Macro to enable the appropriate interrupt level */#ifndef SYS_INT_ENABLE#   define SYS_INT_ENABLE(pDrvCtrl) \	{ \	IMPORT void sysLanIntEnable(); \	sysLanIntEnable (pDrvCtrl->ilevel); \	}#endif/* Macro to get the ethernet address from the BSP */#ifndef SYS_ENET_ADDR_GET#   define SYS_ENET_ADDR_GET(pDevice) \	{ \	IMPORT unsigned char sysTemplateEnetAddr[]; \	bcopy ((char *)sysTemplateEnetAddr, (char *)(&pDevice->enetAddr), 6); \	}#endif/* * Macros to do a short (UINT16) access to the chip. Default * assumes a normal memory mapped device. */#ifndef TEMPLATE_OUT_SHORT#   define TEMPLATE_OUT_SHORT(pDrvCtrl,addr,value) \	(*(USHORT *)addr = value)#endif#ifndef TEMPLATE_IN_SHORT#   define TEMPLATE_IN_SHORT(pDrvCtrl,addr,pData) \	(*pData = *addr)#endif/* A shortcut for getting the hardware address from the MIB II stuff. */#define END_HADDR(pEnd)	\		((pEnd)->mib2Tbl.ifPhysAddress.phyAddress)#define END_HADDR_LEN(pEnd) \		((pEnd)->mib2Tbl.ifPhysAddress.addrLength)/* typedefs */typedef struct    {    int len;    char * pData;    } PKT;	/* A dummy DMA data packet */#define TEMPLATE_PKT_LEN_GET(pPkt) (((PKT *)pPkt)->len)typedef struct rfd    {    PKT *  pPkt;    struct rfd * next;    } RFD;	/* dummy rx frame descriptor */typedef struct free_args    {    void* arg1;    void* arg2;    } FREE_ARGS;        /* The definition of the driver control structure */typedef struct end_device    {    END_OBJ     end;			/* The class we inherit from. */    int		unit;			/* unit number */    int         ivec;                   /* interrupt vector */    int         ilevel;                 /* interrupt level */    char*       pShMem;                	/* real ptr to shared memory */    long	flags;			/* Our local flags. */    UCHAR	enetAddr[6];		/* ethernet address */    CACHE_FUNCS cacheFuncs;             /* cache function pointers */    FUNCPTR     freeRtn[128];           /* Array of free routines. */    struct free_args    freeData[128];  /* Array of free arguments */                                        /* the free routines. */    CL_POOL_ID	pClPoolId;		/* cluster pool */    BOOL	rxHandling;		/* rcv task is scheduled */    } END_DEVICE;/* * 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 templateMclBlkConfig = 	/* network mbuf configuration table */    {    /*     no. mBlks		no. clBlks	memArea		memSize    -----------		----------	-------		-------    */    0, 			0, 		NULL, 		0    };CL_DESC templateClDescTbl [] = 	/* network cluster pool configuration table */    {    /*     clusterSize			num	memArea		memSize    -----------			----	-------		-------    */    {ETHERMTU + EH_SIZE + 2,	0,	NULL,		0}    }; int templateClDescTblNumEnt = (NELEMENTS(templateClDescTbl));NET_POOL templateCmpNetPool;/* Definitions for the flags field */#define TEMPLATE_PROMISCUOUS	0x1#define TEMPLATE_POLLING	0x2/* Status register bits, returned by templateStatusRead() */#define TEMPLATE_RINT		0x1	/* Rx interrupt pending */#define TEMPLATE_TINT		0x2	/* Tx interrupt pending */#define TEMPLATE_RXON		0x4	/* Rx on (enabled) */#define TEMPLATE_VALID_INT	0x3	/* Any valid interrupt pending */#define TEMPLATE_MIN_FBUF	(1536)	/* min first buffer size *//* DEBUG MACROS */#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 */#undef DRV_DEBUG#ifdef	DRV_DEBUG#define DRV_DEBUG_OFF		0x0000#define DRV_DEBUG_RX		0x0001#define	DRV_DEBUG_TX		0x0002#define DRV_DEBUG_INT		0x0004#define	DRV_DEBUG_POLL		(DRV_DEBUG_POLL_RX | DRV_DEBUG_POLL_TX)#define	DRV_DEBUG_POLL_RX	0x0008#define	DRV_DEBUG_POLL_TX	0x0010#define	DRV_DEBUG_LOAD		0x0020#define	DRV_DEBUG_IOCTL		0x0040#define DRV_DEBUG_POLL_REDIR	0x10000#define	DRV_DEBUG_LOG_NVRAM	0x20000int	templateDebug = 0x00;int     templateTxInts=0;#define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6)                        \	if (templateDebug & FLG)                                        \            logMsg(X0, X1, X2, X3, X4, X5, X6);#define DRV_PRINT(FLG,X)                                                \	if (templateDebug & FLG) printf X;#else /*DRV_DEBUG*/#define DRV_LOG(DBG_SW, X0, X1, X2, X3, X4, X5, X6)#define DRV_PRINT(DBG_SW,X)#endif /*DRV_DEBUG*//* LOCALS *//* forward static functions */LOCAL void	templateReset	(END_DEVICE *pDrvCtrl);LOCAL void	templateInt	(END_DEVICE *pDrvCtrl);LOCAL void	templateHandleRcvInt (END_DEVICE *pDrvCtrl);LOCAL STATUS	templateRecv	(END_DEVICE *pDrvCtrl, char* pData);LOCAL void	templateConfig	(END_DEVICE *pDrvCtrl);LOCAL UINT	templateStatusRead (END_DEVICE *pDrvCtrl);/* END Specific interfaces. *//* This is the only externally visible interface. */END_OBJ* 	templateLoad (char* initString);LOCAL STATUS	templateStart	(END_OBJ* pDrvCtrl);LOCAL STATUS	templateStop	(END_OBJ* pDrvCtrl);LOCAL int	templateIoctl   (END_OBJ* pDrvCtrl, int cmd, caddr_t data);LOCAL STATUS	templateUnload	(END_OBJ* pDrvCtrl);LOCAL STATUS	templateSend	(END_OBJ* pDrvCtrl, M_BLK_ID pBuf);			  LOCAL STATUS	templateMCastAdd (END_OBJ* pDrvCtrl, char* pAddress);LOCAL STATUS	templateMCastDel (END_OBJ* pDrvCtrl, char* pAddress);LOCAL STATUS	templateMCastGet (END_OBJ* pDrvCtrl,				    MULTI_TABLE* pTable);LOCAL STATUS	templatePollStart (END_DEVICE* pDrvCtrl);LOCAL STATUS	templatePollStop (END_DEVICE* pDrvCtrl);LOCAL STATUS	templatePollSend (END_OBJ* pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS	templatePollRcv (END_OBJ* pDrvCtrl, M_BLK_ID pBuf);LOCAL void	templateAddrFilterSet(END_DEVICE *pDrvCtrl);LOCAL STATUS	templateParse	();LOCAL STATUS	templateMemInit	();/* * Declare our function table.  This is static across all driver * instances. */LOCAL NET_FUNCS templateFuncTable =    {    (FUNCPTR) templateStart,		/* Function to start the device. */    (FUNCPTR) templateStop,		/* Function to stop the device. */    (FUNCPTR) templateUnload,		/* Unloading function for the driver. */    (FUNCPTR) templateIoctl,		/* Ioctl function for the driver. */    (FUNCPTR) templateSend,		/* Send function for the driver. */    (FUNCPTR) templateMCastAdd,		/* Multicast add function for the */					/* driver. */    (FUNCPTR) templateMCastDel,		/* Multicast delete function for */					/* the driver. */    (FUNCPTR) templateMCastGet,		/* Multicast retrieve function for */					/* the driver. */    (FUNCPTR) templatePollSend,		/* Polling send function */    (FUNCPTR) templatePollRcv,		/* Polling receive function */    endEtherAddressForm,		/* put address info into a NET_BUFFER */    endEtherPacketDataGet,	 	/* get pointer to data in NET_BUFFER */    endEtherPacketAddrGet  		/* Get packet addresses. */    };/********************************************************************************* templateLoad - 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.** The string contains the target specific parameters like this:** "register addr:int vector:int level:shmem addr:shmem size:shmem width"** RETURNS: An END object pointer or NULL on error.*/END_OBJ* templateLoad    (    char* initString		/* String to be parsed by the driver. */    )    {    END_DEVICE 	*pDrvCtrl;    DRV_LOG (DRV_DEBUG_LOAD, "Loading template...\n", 1, 2, 3, 4, 5, 6);    /* allocate the device structure */    pDrvCtrl = (END_DEVICE *)calloc (sizeof (END_DEVICE), 1);    if (pDrvCtrl == NULL)	goto errorExit;    /* parse the init string, filling in the device structure */    if (templateParse (pDrvCtrl, initString) == ERROR)	goto errorExit;    /* Ask the BSP to provide the ethernet address. */    SYS_ENET_ADDR_GET(pDrvCtrl);    /* initialize the END and MIB2 parts of the structure */    /*     * The M2 element must come from m2Lib.h      * This template is set up for a DIX type ethernet device.     */        if (END_OBJ_INIT (&pDrvCtrl->end, (DEV_OBJ *)pDrvCtrl, "template",                      pDrvCtrl->unit, &templateFuncTable,                      "END Template Driver.") == ERROR     || END_MIB_INIT (&pDrvCtrl->end, M2_ifType_ethernet_csmacd,                      &pDrvCtrl->enetAddr[0], 6, END_BUFSIZ,                      END_SPEED)		    == ERROR)	goto errorExit;    /* Perform memory allocation/distribution */    if (templateMemInit (pDrvCtrl) == ERROR)	goto errorExit;    /* reset and reconfigure the device */    templateReset (pDrvCtrl);    templateConfig (pDrvCtrl);    /* set the flags to indicate readiness */    END_OBJ_READY (&pDrvCtrl->end,		    IFF_UP | IFF_RUNNING | IFF_NOTRAILERS | IFF_BROADCAST		    | IFF_MULTICAST);    DRV_LOG (DRV_DEBUG_LOAD, "Done loading Template...", 1, 2, 3, 4, 5, 6);    return (&pDrvCtrl->end);errorExit:    if (pDrvCtrl != NULL)	free ((char *)pDrvCtrl);    return NULL;    }/********************************************************************************

⌨️ 快捷键说明

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