?? sngks32cend.c
字號(hào):
/* sngks32cEnd.c - Samsung KS32C END network interface driver *//* Copyright 1984-2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01l,07may02,m_h Handle PHY auto-negotiation (75464)01k,12feb02,m_h Fix error rx Handling (74033) and polled mode (72979)01j,24jan02,m_h frame length for PollSend01i,23jan02,m_h incorrect frame length for WDB_COMM_END01h,17jan02,m_h fix build warnings01g,30nov01,m_h clean up warnings01f,27sep01,m_h big endian support, volatile registers01e,23jul01,m_h fix minor DRV_LOG warning01d,16jul01,m_h fix slow ethernet by enabling DMA while processing rx01c,26apr01,m_h convert tabs to spaces for readability, fixed warnings01b,25apr01,m_h improve a few comments01a,12apr01,m_h created from snds100 template.*//*DESCRIPTIONThis module implements the Enhanced Ethernet driver for Samsung's KS32C50100microcontroller.KS32C50100 is an ARM based processor with several integrated peripherals.It has an interrupt controller, two 32-bit timers, one Ethernet controller,two HDLC controllers, one IIC controller, general purpose I/O ports, and a2-channel DMA controller.The built-in Ethernet controller consists of 10/100 Ethernet MAC with MIIinterface to an external PHY device and a Buffered DMA controller fortransferring data to and from the memory. The KS32C50100 has a Level OneLXT972 Ethernet PHY device that supports both 10Base-T and 100Base-TEthernet.All the internal registers of the Ethernet MAC and BDMA controller areaccessible as 32-bit integers at the internal system register addresses asdefined in the KS32C50100 Microcontroller User's Manual. The registeraddresses are defined in sngks32cEnd.h include file.The driver requires several target-specific values provided as an inputstring to the load routine. These target-specific values and the externalsupport routines are described below.This network interface driver does not include support for trailer protocolsor data chaining.This driver maintains cache coherency by setting the Address bit 26 (A26) ofdescriptor and buffer addresses. KS32C50100 accesses all memory locationswith A26 set in a non-cached mode. However, A26 is not used for accessingthe memory. See the KS32C50100 Microcontroller User's Manual for details.BOARD LAYOUTThis device is on-chip with the CPU. No jumpering diagram is necessary.EXTERNAL INTERFACEThis driver provides the standard END external interface. The only externalinterface is the sngks32cEndLoad() routine. The parameters are passedinto the sngks32cEndLoad() function as a single colon-delimited string.The sngks32cEndLoad() function uses strtok() to parse the string, which itexpects to be of the following format:<unit>:<speed>:<duplex>:<autoneg>TARGET-SPECIFIC PARAMETERS\ml\m <unit>A convenient holdover from similar END drivers. This parameter is used onlyin the string name for the driver. Value must be 0\m <speed>Indicates the desired network speed. Valid values are 10 and 100. Thisparameter is ignored if auto-negotiation is enabled. See below.\m <duplex>Indicates the desired duplex mode of operation. A value 1 indicates full-duplex and a value 0 indicated half duplex. This parameter is ignored ifauto-negotiation is enabled.\m <auto-neg>Indicates whether auto-negotiation has to be enabled or not. A value of 1indicates that auto-negotiation should be enabled. A value of 0 indicatesthat it should be disabled. If auto-negotiation is enabled, the speed andduplex values are ignored.\meSYSTEM RESOURCE USAGEThis driver requires the following system resources:\ml\m 1.one mutual exclusion semaphore\m 2.four interrupt vectors\meThe driver allocates the memory to share with the Ethernet device unit.It does so by calling the calloc() routine. As a default, 64 transmitdescriptors (size=16 bytes), 64 transmit buffers (size=END_BUFSIZ), and64 receive descriptors (size=16 bytes) are allocated. TX_FD_NUM and RX_FD_NUMmacros define the number of descriptors allocated.As a default, 128 MBLK structures, 128 CLBLK structures and 128 clusters(size=2048) are allocated in the net pool. END_MBLK_NUM and END_CL_NUMmacros define the number of structures allocated.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 intEnable().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 sysSngks32cMacAddr defined by the BSP into the END_DEVICE structure. The global variable has to be changed for changingthe MAC address of the Ethernet port.SPECIAL CONSIDERATIONThe MAC address of Ethernet port is hard-coded in the global array namedsysSngks32cMacAddr defined by the BSP.The internal registers of MAC and BDMA controllers in the KS32C50100microcontroller are accessible as 32-bit integers at pre-defined addresslocations. Hence separate macros are not provided for register accesses.All through the driver code, these registers are accessed directly.INCLUDES:end.h endLib.h etherMultiLib.h sngks32cEnd.hSEE ALSO: muxLib, endLib<Writing an Enhanced Network Driver><Samsung KS32C50100 User's Manual>*//* includes */#include "vxWorks.h"#include "etherMultiLib.h" /* multicast stuff. */#include "end.h" /* Common END structures. */#include "endLib.h"#include "lstLib.h" /* Needed to maintain protocol list. */#include "cacheLib.h"#include "stdlib.h"#include "stdio.h"#include "intLib.h"#include "sysLib.h"#include "logLib.h"#include "iv.h"#include "netLib.h"#include "wdLib.h"#include "private/funcBindP.h"#include "sngks32cEnd.h" /* defines *//* Define this for better handling of auto-negotiation of the PHY */#define DYNAMIC_PHY/* define if you want to disable rx DMA while this driver is processing data */#undef NO_DMA_WHILE_PROCESSING/* debugging: Input is hooked up to the output. Data never goes out to the* cable*/#undef LOOPBACK_DEBUG/* Driver debug control */#undef DRV_DEBUG_SNGKS32C/* Driver debug control */#ifdef DRV_DEBUG_SNGKS32C#define DRV_DEBUG_OFF 0x0000#define DRV_DEBUG_RX 0x0001#define DRV_DEBUG_TX 0x0002#define DRV_DEBUG_POLL_RX 0x0004#define DRV_DEBUG_POLL_TX 0x0008#define DRV_DEBUG_POLL (DRV_DEBUG_POLL_RX | DRV_DEBUG_POLL_TX)#define DRV_DEBUG_LOAD 0x0010#define DRV_DEBUG_IOCTL 0x0020#define DRV_DEBUG_INT 0x0040#define DRV_DEBUG_START 0x0080#define DRV_DEBUG_DUMP 0x0100#define DRV_DEBUG_RX_ALL 0x0200#define DRV_DEBUG_ALL 0xffffint sngks32cDebug = DRV_DEBUG_IOCTL | DRV_DEBUG_INT | DRV_DEBUG_RX | \ DRV_DEBUG_LOAD | DRV_DEBUG_START | DRV_DEBUG_RX | DRV_DEBUG_POLL;#define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6) \ do { \ if (sngks32cDebug & FLG) \ if (_func_logMsg != NULL) \ _func_logMsg (X0, (int)X1, (int)X2, (int)X3, (int)X4, \ (int)X5, (int)X6); \ } while (0)#define DRV_PRINT(FLG, X) \ do { \ if (sngks32cDebug & FLG) \ printf X; \ } while (0)#else /* DRV_DEBUG_SNGKS32C */#define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6)#define DRV_PRINT(FLG, X)#endif /* DRV_DEBUGSNGKS32C */#define END_SPEED 10000000#define SNGKS32C_CL_SIZE 2048#define RX_FD_NUM 64#define TX_FD_NUM 64#define LS_POLLING 0x20/* You must define BUG_KS32C5000 to support original KS32C5000 version* of the chip. This original version had a couple of bugs in the silicon.* Software workarounds will be implemented if this define is enabled.* Note: The workaround has not been tested. See Samsung application notes* for more information.*/#undef BUG_KS32C5000/* avoid compilation warnings -- I implemented functions which may be useful* for future versions of this driver. But, to avoid compiler warnings,* I've commented out the function definition (with #ifdef) since I don't* actually use them now.*/#undef NOT_USED_HERE/** Default macro definitions for BSP interface.* These macros can be redefined in a wrapper file, to generate* a new module with an optimized interface.*//* Cache macros */#define SNGKS32C_NON_CACHE_REGION 0x4000000#define END_CACHE_INVALIDATE(address, len) \ CACHE_DRV_INVALIDATE (pDrvCtrl->cacheFuncs, (UINT32)(address), (len))#define END_CACHE_PHYS_TO_VIRT(address) \ (void *)((UINT32)(address) & ~SNGKS32C_NON_CACHE_REGION)#define END_CACHE_VIRT_TO_PHYS(address) \ (void *)((UINT32)(address) | SNGKS32C_NON_CACHE_REGION)/* 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 */#ifndef SYS_INT_DISCONNECT# define SYS_INT_DISCONNECT(pDrvCtrl,rtn,arg,pResult) \ { \ *pResult = OK; /* HELP: need a real routine */ \ }#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 sysSngks32cMacAddr[]; \ bcopy ((char *)sysSngks32cMacAddr, (char *)(&pDevice->enetAddr), 6); \ }#endif/* * Macros to do a short (UINT16) access to the chip. Default * assumes a normal memory mapped device. */#ifndef SNGKS32C_OUT_SHORT# define SNGKS32C_OUT_SHORT(pDrvCtrl,addr,value) \ (*(USHORT *)addr = value)#endif#ifndef SNGKS32C_IN_SHORT# define SNGKS32C_IN_SHORT(pDrvCtrl,addr,pData) \ (*pData = *addr)#endif#ifndef SNGKS32C_OUT_LONG# define SNGKS32C_OUT_LONG(pDrvCtrl,addr,value) \ (*(UINT32 *)addr = value)#endif#ifndef SNGKS32C_IN_LONG# define SNGKS32C_IN_LONG(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)/* globals*//* * 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 endMclConfig = /* network mbuf configuration table */ { /* no. mBlks no. clBlks memArea memSize ----------- ---------- ------- ------- */ 0, 0, NULL, 0 };CL_DESC endClDescTbl [] = /* network cluster pool configuration table */ { /* clusterSize num memArea memSize ----------- ---- ------- ------- */ {SNGKS32C_CL_SIZE, 0, NULL, 0} };int endClDescTblNumEnt = (NELEMENTS(endClDescTbl));/* new additions */#ifdef BUG_KS32C5000UINT32 gStatusLengthPrevious; /* For bug fix */BOOL gBugFixDone = FALSE;#endif /*BUG_KS32C5000*//* Definitions for the flags field */#define END_PROMISCUOUS_FLAG 0x1#define END_RCV_HANDLING_FLAG 0x2#define END_MBLK_NUM 128#define END_CL_NUM 128#define SNGKS32C_DATA_OFFSET 2#define SNGKS32C_MAX_MULTI 20#ifdef DYNAMIC_PHY/* PHY STATUS2 register definitions */#define PHY_STATUS2_REG 17#define PHYSTAT2_100MB 0x4000#define PHYSTAT2_FULLDUP 0x0200#define PHYSTAT2_AUTONEG 0x0100/* This WDOG is used to poll the PHY for any changes since the FULL_DUPLEX bit in MACCON must be synched with the full fuplex status of the PHY. (This was found after very long and tedious investigations (<-understatement)) */#define PHY_WDOG_PERIOD (sysClkRateGet()*30) /* 30 secs period */WDOG_ID phyPollWdog=NULL;LOCAL void phyPoll(int dummy);#endif /*DYNAMIC_PHY*//* DEBUG MACROS */#undef DEBUG#ifdef DEBUG#include "nvLogLib.h" /* Needed to debug polled mode. */int endDebug = 1;#define ENDLOGMSG(x) \ if (endDebug) \ { \ logMsg x; \ }#else#define ENDLOGMSG(x)#endif /* ENDDEBUG *//* LOCALS */extern CACHE_FUNCS sngks32cCacheFuncs;/* IMPORTS */IMPORT int endMultiLstCnt (END_OBJ *);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -