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

📄 syswancomend.c

📁 WINDRIVER SBC7410 BSP
💻 C
字号:
/* sysWancomEnd.c - system configuration module for wancomEnd *//* Copyright 2002 Wind River Systems, Inc. *//*modification history--------------------01f,13jan03,dee  fix SPR# 8561101e,06jan03,dee  remove vWare support01d,13may02,gtf  modified for wancomend ethernet driver.01c,08aug01,g_h  add support for the PCI expand board.01b,11jul01,g_h  add support for Intel PRO100S NIC01a,01apr01,g_h  written.*//*DESCRIPTIONThis is the WRS-supplied configuration module for the VxWorkswancomEnd (wancom) END driver.  It performs the dynamic parameterizationof the wancomEnd driver.  This technique of 'just-in-time'parameterization allows driver parameter values to be declaredas something other than static strings.*//* includes */#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "end.h"#include "config.h"#include "taskLib.h"#include "intLib.h"#include "sysGt64260IntrCtl.h"#include "wancomEnd.h"        #if (defined(INCLUDE_WANCOMEND) && defined (INCLUDE_NETWORK) && defined (INCLUDE_END))#undef  WANCOM_MAX_UNITS#define WANCOM_MAX_UNITS 2         /* imports */IMPORT FUNCPTR   wancomEndIntConnect;IMPORT FUNCPTR   wancomEndIntDisconnect;IMPORT END_OBJ * wancomEndLoad (char *);/* defines *//* unknown values */#define UNKNOWN         -1/* wancom driver access routines *//* typedefs *//* locals */LOCAL STATUS sysWancomEndIntEnable(int unit);LOCAL STATUS sysWancomEndIntDisable(int unit);/* forward declarations */LOCAL int       sysWancomEndIntAck     (int unit);void sysEnetAddrGet(int unit, UINT8 *adrs) ;void sysEnetAddrSet (UINT8 byte0,                      UINT8 byte1,                      UINT8 byte2,                      UINT8 byte3,                      UINT8 byte4,                      UINT8 byte5) ;void sysEnetAddrSetUnit (int unit,                      UINT8 byte0,                      UINT8 byte1,                      UINT8 byte2,                      UINT8 byte3,                      UINT8 byte4,                      UINT8 byte5) ;/* Backup - hard-coded...., need to add eeprom read/write functions for storing mac address */unsigned char bspEnetAdrs[2][6] = {    { '\x00', '\x1e', '\xa0', '\x01', '\x02', '\x05'},    { '\x00', '\x1e', '\xa0', '\x01', '\x02', '\x09'},} ;/***************************************************************************    ** sysWancomEndLoad - load wancomEnd () device.** This routine loads the wancom device with initial parameters.** RETURNS: pointer to END object or ERROR.** SEE ALSO: wancomEndLoad()*/END_OBJ * sysWancomEndLoad    (    char *  pParamStr,  /* ptr to initialization parameter string */    void *  unused      /* unused optional argument */    )    {    /*     * The wancomEnd driver END_LOAD_STRING should be:     * "<memBase>:<memSize>:<nCFDs>:<nRFDs>:<flags>"      */    char *  cp;    char    paramStr [END_INIT_STR_MAX];   /* from end.h */    END_OBJ *   pEnd;    if ( strlen (pParamStr) == 0 )        {        /*         * muxDevLoad() calls us twice.  If the string is         * zero length, then this is the first time through         * this routine, so we just return.         */        pEnd = wancomEndLoad (pParamStr);        }    else        {        /*         * On the second pass though here, we actually create         * the initialization parameter string on the fly.         * Note that we will be handed our unit number on the         * second pass through and we need to preserve that information.         * So we use the unit number handed from the input string.         */        cp = strcpy (paramStr, pParamStr); /* cp points to paramStr */        /* Now, we advance cp, by finding the end the string */        cp += strlen (paramStr);        /* finish off the initialization parameter string */        sprintf (cp, "-1:0x00:0x20:0x20:0x00");#ifdef WANCOMEND_DEBUG        logMsg("paramStr - %s\n",paramStr,2,3,4,5,6);#endif        if ( (pEnd = wancomEndLoad (paramStr)) == NULL )            {            printf ("Error: device failed wancomEndLoad routine.\n");            taskDelay(sysClkRateGet()*1);            }        }    return(pEnd);    }/**************************************************************************** wancomInit - initialize and configure the GT device.* This routine makes the appropreate preparation to enable the GT to rceive * and transmit ethernet packets using any one of its Ethernet port.* * 1) Set Ethernet port multiplex control.* 2) Set the Ethernet port various configuration and command words ** RETURNS: OK or ERROR.**/STATUS sysWancomInit    (    int unit,     WANCOM_PORT_INFO *pPort    )    {    UINT32 temp ;#ifdef WANCOMEND_DEBUG    logMsg("sysWancomInit: unit - 0x%x, pPort - 0x%x\n", unit, pPort, 3,4,5,6);#endif    /* Get mac address */    sysEnetAddrGet(unit, pPort->enetAddr);    if ( unit == 0 )        {        pPort->vector = INT_VEC_ETH0 ;        pPort->level = INT_LVL_ETH0 ;        /* Setup phy address on port 0 */        GT64260_REG_RD(ETH_PHY_ADRS, &temp);        temp &= ~0x1f ;        GT64260_REG_WR(ETH_PHY_ADRS, temp); /* port 0,  phy adrs = 0 */        }    else if ( unit == 1 )        {        pPort->vector = INT_VEC_ETH1 ;        pPort->level = INT_LVL_ETH1 ;        /* Setup phy address on port 1 */        GT64260_REG_RD(ETH_PHY_ADRS, &temp);        temp &= ~(0x1f<<5) ;        temp |= (0x1<<5) ; /* port 1,  phy adrs = 1 */        GT64260_REG_WR(ETH_PHY_ADRS, temp);        }    pPort->baseAddr = PORT0_BASE_OFFSET + (ETHERNET_PORTS_DIFFERENCE_OFFSETS*unit);    pPort->portConfig =        PORT_CONFIG_VALUE;    pPort->portConfigExtend =  PORT_CONFIG_EXTEND_VALUE;    pPort->portSdmaConfig =    PORT_SDMA_CONFIG_VALUE;#ifdef WANCOMEND_DEBUG    logMsg("baseAddr - 0x%x\n", pPort->baseAddr,2,3,4,5,6);    logMsg("portConfig - 0x%x\n", pPort->portConfig,2,3,4,5,6);    logMsg("portConfigExtend - 0x%x\n", pPort->portConfig,2,3,4,5,6);    logMsg("portSdmaConfig - 0x%x\n", pPort->portSdmaConfig,2,3,4,5,6);#endif    pPort->intEnable     = sysWancomEndIntEnable;    pPort->intDisable    = sysWancomEndIntDisable;    pPort->intAck        = sysWancomEndIntAck;    return TRUE;    }/***************************************************************************    ** sysWancomEndIntEnable - enable wancom ethernet interrupts** This routine enables wancom ethernet interrupts.  This may involve operations on* interrupt control hardware.** RETURNS: OK or ERROR for invalid arguments.*/LOCAL STATUS sysWancomEndIntEnable     (    int unit    )    {    int level ;    if ( unit==0 )        level = INT_LVL_ETH0 ;    else if ( unit==1 )        level = INT_LVL_ETH1 ;    else        return ERROR ;    return(intEnable(level));    }/********************************************************************************* sysWancomIntDisable - disable wancom ethernet interrupts** This routine disables wancom ethernet interrupts.  This may involve operations on* interrupt control hardware.** RETURNS: OK or ERROR for invalid arguments.*/LOCAL STATUS sysWancomEndIntDisable     (    int unit    )    {    int level ;    if ( unit==0 )        level = INT_LVL_ETH0 ;    else if ( unit==1 )        level = INT_LVL_ETH1 ;    else        return ERROR ;    return(intDisable(level));    }/***************************************************************************** sysWancomEndIntAck - acknowledge an wancom ethernet interrupt** This routine performs any wancom ethernet interrupt acknowledge that may be* required.  This typically involves an operation to some interrupt* control hardware.** This routine gets called from the wancom driver's interrupt handler.** This routine assumes that the PCI configuration information has already* been setup.** RETURNS: OK, or ERROR if the interrupt could not be acknowledged.*/LOCAL STATUS sysWancomEndIntAck    (    int unit    )    {#if 0    int level ;    if ( unit == 0 )        level = INT_LVL_ETH0 ;    else        level = INT_LVL_ETH1 ;    switch ( unit )        {        default:            return(OK);        }#else    return(OK);#endif    }/***************************************************************************** sysWancomMdioRead - read the LXT972 mii register.** RETURNS: OK, or ERROR.*/STATUS sysWancomMdioRead    (    int unit,     int reg,     UINT16 *data    )    {    UINT32 temp ;    UINT32 phyAdrs=0 ;    if ( reg > 30 )        return ERROR ;    if ( unit < 0 || unit > 1 )        return ERROR ;    if ( unit == 0 )        phyAdrs = 0 ; /* hard-coded 0; see schematic */    else if ( unit == 1 )        phyAdrs = 1 ; /* hard-coded 1; see schematic */    temp = 0 ;    temp = phyAdrs << 16 ;    temp |= (reg << 21) ;    temp |= (1 << 26) ; /* read bit */    GT64260_REG_WR(ETH_SMIR, temp);    {        int i ;        for ( i=0 ; i < 0x10000; i++ ) ;    }    while ( 1 )        {        GT64260_REG_RD(ETH_SMIR, &temp);        if ( !(temp & (1 << 27)) )            continue;        else            break;        }    *data = (UINT16)temp ;    return OK ;    }/***************************************************************************** sysWancomMdioWrite - write the LXT972 mii register.** RETURNS: OK, or ERROR.*/STATUS sysWancomMdioWrite    (    int unit,      int reg,     UINT16 data    )    {    UINT32 temp ;    UINT32 phyAdrs=0 ;    if ( reg > 30 )        return ERROR ;    if ( unit < 0 || unit > 1 )        return ERROR ;    if ( unit == 0 )        phyAdrs = 0 ; /* hard-coded to 0; see schematic */    else if ( unit == 1 )        phyAdrs = 1 ; /* hard-codd to 1; see schematic */    temp = 0 ;    temp = phyAdrs << 16 ;    temp |= (reg << 21) ;    temp |= ((UINT32)data&0xffff) ;    GT64260_REG_WR(ETH_SMIR, temp);    return OK ;    }/***************************************************************************** sysEnetAddrSetUnit - write MAC address to NVRAM** NOTE: This function exists only because bootConfig.c doesn't use a unit number*       when it calls sysEnetAddrSet.  (see below)** RETURNS: OK, or ERROR.*/void sysEnetAddrSetUnit    (    int unit,     UINT8 byte0,     UINT8 byte1,     UINT8 byte2,     UINT8 byte3,     UINT8 byte4,     UINT8 byte5    )    {    UINT8 macAddr[6] ;    int offset=0 ;    macAddr[0] = byte0 ;    macAddr[1] = byte1 ;    macAddr[2] = byte2 ;    macAddr[3] = byte3 ;    macAddr[4] = byte4 ;    macAddr[5] = byte5 ;    if ( unit == 0 )        offset = NV_ENET0_OFFSET;    else if ( unit == 1 )        offset = NV_ENET1_OFFSET;#if (NV_RAM_SIZE != NONE)    /*     * Save MAC address in the NvRAM.     */     sysNvRamSet (macAddr, 6, offset);#endif /* (NV_RAM_SIZE != NONE) */    }/***************************************************************************** sysEnetAddrSet - write MAC address for wancom0 to NVRAM** RETURNS: OK, or ERROR.*/void sysEnetAddrSet     (    UINT8 byte0,     UINT8 byte1,     UINT8 byte2,     UINT8 byte3,     UINT8 byte4,     UINT8 byte5    )    {    ULONG unit1addr;  /* unit 1 is one higher than unit 0 */    unit1addr = (byte2 << 24) + (byte3 << 16) + (byte4 << 8) + byte5;    sysEnetAddrSetUnit (0, byte0, byte1, byte2, byte3, byte4, byte5);    /* now calculate the address for the second Wancom port */    /* it is always 1 higher than unit 0, only lower 3 bytes */    unit1addr = (byte3 << 16) + (byte4 << 8) + byte5;    unit1addr += 1; /* bump address by one byte */    sysEnetAddrSetUnit (1, byte0, byte1, byte2,                         (UINT8)(unit1addr>>16),                        (UINT8)(unit1addr>>8),                        (UINT8)unit1addr);    }/***************************************************************************** sysEnetAddrGet - get MAC address from NVRAM** RETURNS: OK, or ERROR.*/void sysEnetAddrGet    (    int unit,    UINT8 *adrs    )    {    int offset=0 ;    int i ;    if ( unit == 0 )        offset = NV_ENET0_OFFSET ;    else if ( unit == 1 )        offset = NV_ENET1_OFFSET ;#if (NV_RAM_SIZE != NONE)     /* Get MAC address from NvRAM. */        if ( sysNvRamGet(adrs, 6, offset) != OK )            bcopy(bspEnetAdrs[unit], adrs, 6);#endif /* (NV_RAM_SIZE != NONE) */    /* Check to see if mac address is valid. */    for ( i=0 ; i < 6 ; i++ )        {        if ( adrs[i] != 0xff )            break;        }    /* Force to default */                              if ( i == 6 )        {        bcopy(bspEnetAdrs[unit], adrs, 6);        }    }#endif /* defined (INCLUDE_WANCOMEND) && defined (INCLUDE_NETWORK) */

⌨️ 快捷键说明

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