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

📄 sngks32cend.c

📁 Vxworks下BSP源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* sngks32cEnd.c - Samsung KS32C END network interface driver *//* Copyright 1984-2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01a,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"            #include "vmLib.h"LOCAL void at91cEndPIOConfig();/* defines *//* Define this for better handling of auto-negotiation of the PHY */#undef 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_AT91C#undef DRV_DEBUG_AT91C/* Driver debug control */#ifdef DRV_DEBUG_AT91C#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    at91cDebug = DRV_DEBUG_IOCTL | DRV_DEBUG_INT | DRV_DEBUG_RX | \            DRV_DEBUG_LOAD | DRV_DEBUG_START | DRV_DEBUG_RX | DRV_DEBUG_POLL;#undef DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6)                   \    do {                                                           \      if (at91cDebug & FLG)                                     \         logMsg (X0, (int)X1, (int)X2, (int)X3, (int)X4,    \                (int)X5, (int)X6);                                 \    } while (0)#define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6)                   \    do {                                                           \      if (at91cDebug & 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 (at91cDebug & FLG)          \        printf X;                       \    } while (0)#else /* DRV_DEBUG_AT91C */#define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6)#define DRV_PRINT(FLG, X)#endif /* DRV_DEBUGAT91C */#define END_SPEED            10000000#define AT91C_CL_SIZE     2048#define RX_FD_NUM            64#define TX_FD_NUM            64#define LS_POLLING           0x20/* 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.*/#if 0/* Cache macros */#define AT91C_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) & ~AT91C_NON_CACHE_REGION)#define END_CACHE_VIRT_TO_PHYS(address) \        (void *)((UINT32)(address) | AT91C_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#endif/* Macro to get the ethernet address from the BSP */#ifndef SYS_ENET_ADDR_GET#   define SYS_ENET_ADDR_GET(pDevice) \    { \    IMPORT unsigned char sysAt91cMacAddr[]; \    bcopy ((char *)sysAt91cMacAddr, (char *)(&pDevice->enetAddr[0]), 6); \    }#endif#if 0/* * Macros to do a short (UINT16) access to the chip. Default * assumes a normal memory mapped device. */#ifndef AT91C_OUT_SHORT#   define AT91C_OUT_SHORT(pDrvCtrl,addr,value) \    (*(USHORT *)addr = value)#endif#ifndef AT91C_IN_SHORT#   define AT91C_IN_SHORT(pDrvCtrl,addr,pData) \    (*pData = *addr)#endif#ifndef AT91C_OUT_LONG#   define AT91C_OUT_LONG(pDrvCtrl,addr,value) \    (*(UINT32 *)addr = value)#endif#ifndef AT91C_IN_LONG#   define AT91C_IN_LONG(pDrvCtrl,addr,pData) \    (*pData = *addr)#endif#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    -----------          ----       -------      -------    */    {AT91C_CL_SIZE,    0,        NULL,        0}    };int endClDescTblNumEnt = (NELEMENTS(endClDescTbl));/* new additions *//* 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 AT91C_DATA_OFFSET      2/*#define AT91C_MAX_MULTI       20*/#define AT91C_MAX_MULTI       3#undef DYNAMIC_PHY/* PHY DSCSR register definitions */#define PHY_DSCSR_REG  17/*#define PHYSTAT2_100MB   0x4000#define PHYSTAT2_FULLDUP 0x0200#define PHYSTAT2_AUTONEG 0x0100*/#define FDX_100MB		0x8000#define HDX_100MB		0x4000#define FDX_10MB		0x2000#define HDX_10MB		0x1000#define FDX	(FDX_100MB + FDX_10MB)/* 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); /*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   at91cCacheFuncs;/* IMPORTS */IMPORT int endMultiLstCnt (END_OBJ *);/* forward static functions */LOCAL void      at91cEndReset         (END_DEVICE *pDrvCtrl);LOCAL STATUS    at91cEndStart         (END_DEVICE *pDrvCtrl);#if 0LOCAL void      at91cEndBdmaRxInt     (END_DEVICE *pDrvCtrl);LOCAL void      at91cEndBdmaTxInt     (END_DEVICE *pDrvCtrl);LOCAL void      at91cEndMacRxInt      (END_DEVICE *pDrvCtrl);LOCAL void      at91cEndMacTxInt      (END_DEVICE *pDrvCtrl);#endifLOCAL void 	  at91cEndInt	(END_DEVICE *pDrvCtrl);LOCAL void      at91cEndMacRxInt      (END_DEVICE *pDrvCtrl);LOCAL void      at91cEndMacTxInt      (END_DEVICE *pDrvCtrl);LOCAL void      at91cEndHandleRcvInt  (END_DEVICE *pDrvCtrl);/*, UINT32 stat);*/LOCAL STATUS    at91cEndRecv          (END_DEVICE *pDrvCtrl,                                                    RECEIVE_BUF_DESC *pRxD);LOCAL void      at91cEndConfig        (END_DEVICE *pDrvCtrl);#undef DYNAMIC_PHYLOCAL UINT32    at91cEndPhyRead       (UINT32 phyRegAddr, UINT32 phyAddr); /* DYNAMIC_PHY */LOCAL void      at91cEndPhyWrite      (UINT32 phyRegAddr, UINT32 phyAddr,                                                   UINT32 phyData);LOCAL void      at91cEndMacInitialize (END_DEVICE *pDevice);LOCAL STATUS    at91cEndFdInitialize  (END_DEVICE *pDrvCrtl);LOCAL void      at91cEndFdFree        (END_DEVICE *pDrvCtrl);LOCAL void      at91cEndAddrFilterSet (END_DEVICE *pDrvCtrl);/* END Specific interfaces. *//* This is the only externally visible interface. */END_OBJ*     at91cEndLoad (char* initString);LOCAL STATUS    at91cEndStart        (END_DEVICE* pDrvCtrl);LOCAL STATUS    at91cEndStop         (END_DEVICE* pDrvCtrl);LOCAL STATUS    at91cEndUnload       ();LOCAL int       at91cEndIoctl        (END_DEVICE* pDrvCtrl, int cmd,                                             caddr_t data);LOCAL STATUS    at91cEndSend         (END_DEVICE* pDrvCtrl, M_BLK_ID pBuf);              LOCAL STATUS    at91cEndMCastAdd     (END_DEVICE* pDrvCtrl, char* pAddress);LOCAL STATUS    at91cEndMCastDel     (END_DEVICE* pDrvCtrl, char* pAddress);LOCAL STATUS    at91cEndMCastGet     (END_DEVICE* pDrvCtrl,                                                MULTI_TABLE* pTable);LOCAL STATUS    at91cEndPollSend     (END_DEVICE* pDrvCtrl, M_BLK_ID pBuf);

⌨️ 快捷键说明

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