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

📄 sysnet.c

📁 au1500开发的应用程序
💻 C
字号:
/* sysNet.c - system-dependent Network Library */

/* Copyright 2002-2004 Founder Communications,Inc. */

/*
modification history
--------------------
01a,07apr05,fhchen  written
*/

/*
DESCRIPTION

sysEnetAddrSet was called by mEnet in bootConfig.c, the unit number is
supposed to be get via IO. however, passing the unit number as a parameter
is also desirable, so sysEnetUnitAddrSet is written.

*/

/* includes */

#include "vxWorks.h"
#include "vme.h"
#include "memLib.h"
#include "cacheLib.h"
#include "sysLib.h"
#include "string.h"
#include "intLib.h"
#include "logLib.h"
#include "stdio.h"
#include "taskLib.h" 
#include "vxLib.h"
#include "tyLib.h"

#include "config.h"

/* globals */

static UINT8 glbEnetAddr[MAX_MAC_ADRS][MAC_ADRS_LEN] = {
	{ CPE_ENET0, CPE_ENET1, CPE_ENET2, CPE_ENET3_0, CPE_ENET4, CPE_ENET5 }, /* MAC0 */
	{ CPE_ENET0, CPE_ENET1, CPE_ENET2, CPE_ENET3_1, CPE_ENET4, CPE_ENET5 }, /* MAC1 */
	{ CPE_ENET0, CPE_ENET1, CPE_ENET2, CPE_ENET3_2, CPE_ENET4, CPE_ENET5 },
	{ CPE_ENET0, CPE_ENET1, CPE_ENET2, CPE_ENET3_3, CPE_ENET4, CPE_ENET5 },
};

/***********************************************************************
*
* sysEnetAddrSet - sets the 6 byte ethernet address
*
* This routine sets the 6 byte ethernet address used by the ethernet 
* device, device number is get via IO.
*
* RETURNS: N/A
*
* SEE ALSO: sysEnetAddrGet()
*/

void sysEnetAddrSet 
    (
    UCHAR byte5, /* MSB */
    UCHAR byte4,
    UCHAR byte3,
    UCHAR byte2,
    UCHAR byte1,
    UCHAR byte0 /* LSB */
    )
    {

    BOOL   next;
    int    offset;
    int    unit = 0;

    /* get interface unit number */

    do
        {
        next = FALSE;
            
        printf("Please enter the Unit number between 0 - 3: ");
            
        scanf ("%d", &unit);
 
        /* Check if the unit number is between 0 to 3 */

        if ((unit < 0) || (unit >= MAX_MAC_ADRS))
            {
            printf ("\n");
            printf ("The unit number is not between 0 - 3, please enter it again.\n");
            next = TRUE;
            }
        }while(next);

    printf ("\n");

    offset = unit * MAC_ADRS_LEN;

    /* store address in table */
    
    glbEnetAddr[unit][0] = byte5;
    glbEnetAddr[unit][1] = byte4;
    glbEnetAddr[unit][2] = byte3;
    glbEnetAddr[unit][3] = byte2;
    glbEnetAddr[unit][4] = byte1;
    glbEnetAddr[unit][5] = byte0;

#if (NV_RAM_SIZE != NONE)
    
    /* if NVRAM present, save MAC address in NvRAM. */
    
    sysNvRamSet((char *)&glbEnetAddr[unit], MAC_ADRS_LEN, NV_MAC_ADRS_OFFSET + offset);

#endif /* (NV_RAM_SIZE != NONE) */
    }

/***********************************************************************
*
* sysEnetAddrGet - gets the 6 byte ethernet address
*
* This routine gets the 6 byte ethernet address used by the ethernet 
* device.
*
* RETURNS: OK
*
* SEE ALSO: sysEnetAddrSet()
*/

STATUS sysEnetAddrGet
    (
    int     unit ,       
    UINT8 * addr     /* Location address is returned in                 */
    )
    {
    int   offset;
    char *pEnet;

    pEnet  = (char*)glbEnetAddr[unit];
    offset = unit * MAC_ADRS_LEN;

#if (NV_RAM_SIZE != NONE)

    /* if NVRAM present, get MAC address from NvRAM. */

    sysNvRamGet(addr, MAC_ADRS_LEN, NV_MAC_ADRS_OFFSET + offset);

    /* check if NVRAM content consistent with the glbEnetAddr table  */

    if (memcmp(addr,pEnet,MAC_ADRS_LEN))
        { 
        return OK;
        }

#if 0
    /* update NVRAM using the table */

    sysNvRamSet(pEnet, MAC_ADRS_LEN, NV_MAC_ADRS_OFFSET + offset);
#endif

    /* update the table using NVRAM */

    memcpy(pEnet, addr, MAC_ADRS_LEN);
    
#endif /* (NV_RAM_SIZE != NONE) */

    /* get MAC address from the glbEnetAddr table */
    
    memcpy(addr,pEnet,MAC_ADRS_LEN);

    return (OK);
    }

/***********************************************************************
*
* sysEnetUnitAddrSet - sets the 6 byte ethernet address
*
* This routine sets the 6 byte ethernet address used by the ethernet 
* device, device number is passed in as parameter.
*
* RETURNS: OK, or ERROR if invalid unit number
*
* SEE ALSO: sysEnetAddrGet()
*/

STATUS sysEnetUnitAddrSet 
    (
    int   unit,  /* device number */
    UCHAR byte5, /* MSB */
    UCHAR byte4,
    UCHAR byte3,
    UCHAR byte2,
    UCHAR byte1,
    UCHAR byte0 /* LSB */
    )
    {

    int    offset;
    STATUS status = OK;
    
    /* sanity check */

    if ((unit < 0) || (unit >= MAX_MAC_ADRS))
        {
        return (ERROR);
        }

    offset = unit * MAC_ADRS_LEN;

    /* store address in table */
    
    glbEnetAddr[unit][0] = byte5;
    glbEnetAddr[unit][1] = byte4;
    glbEnetAddr[unit][2] = byte3;
    glbEnetAddr[unit][3] = byte2;
    glbEnetAddr[unit][4] = byte1;
    glbEnetAddr[unit][5] = byte0;

#if (NV_RAM_SIZE != NONE)
    
    /* if NVRAM present, save MAC address in NvRAM. */
    
    status = sysNvRamSet((char *)&glbEnetAddr[unit], MAC_ADRS_LEN, NV_MAC_ADRS_OFFSET + offset);

#endif /* (NV_RAM_SIZE != NONE) */
    
    return (status);
    }

⌨️ 快捷键说明

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