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

📄 meclib.c

📁 vxworks MPC8541 BSP
💻 C
📖 第 1 页 / 共 4 页
字号:
/*******************************************************************************
*
* mecLib.c -  Multiple Engine card generic library
*
* Copyright 2001-2002 ZTE, Inc.
* author:    zhouyuhui
* date:      2005-5-25 14:39
*
* modification history
*-----------------------------------
*
*/

#include "stdio.h"
#include "sysLib.h"
#include "config.h"
#include "string.h"
#include "intLib.h"
#include "logLib.h"
#include "taskLib.h"
#include "muxLib.h"
#include "iolib.h"

#include "ramDrv.h"
#include "usrLib.h"
#include "ipProto.h"
#include "ifLib.h"
#include "usrConfig.h"

/*#include "5906Type.h"*/
#include "meclib.h"
#include "sysEpic.h"
#include "zxr10bsp.h"
#include "82xxLib.h"
#include "bspDefs.h"
#include "uhead.h"

#ifdef PRJ_BUILD
#include "verhead.h"
#endif /* PRJ_BUILD */


UINT8 MACHINE_TYPE = M_6910;

/* 060711 lyf add */
LOCAL  UINT8  sysMySlot = 0xFF, sysPeerSlot = 0xFF;
LOCAL  UINT bdIsDogReset = 0xFF;
/* end lyf add */

extern SEM_ID   i2cSem;

/*declare the global functions*/
/*global variables*/
int    nvRamReadDone = 0;
/*IMPORT NVRAMDATA NvRamContent;*/

#if defined(PRJ_BUILD)

/*local functions*/
LOCAL STATUS RamdiskInstall(void);
LOCAL STATUS mecFpgaLoad (void);
LOCAL STATUS mecExtractVersion (void);
UINT8 getSlaveSlotNumber(void);
void SetMachinePara(void);


/*local variables*/
int RamdiskInstallDone = 0;

ROUTER_NIC RouterInterfaces[] =
    {
    { NIC_DEVNAME, 0 ,1,0,0},  /* run epilogue protocol stack at Ln973 unit 1 */
    { NULL, 1 },                /* don't edit this line */
    };

/*extern functions*/
IMPORT STATUS	 usrTffsConfig (int drive, int removable, char * fileName);
IMPORT int    GetFileFromVer(UINT8 * VerBuf,char * FileName,UINT16 * FileFormat,
                              UINT32 * FileAddr,UINT32 * FileLength,  UINT32 * OriFileLength);
extern UINT8  fpga_ParaLoad(UINT8 *vpStartaddr,ULONG ulFilelen);
extern int    inflate(UINT8 *src,UINT8 *dest,int nBytes );
extern void   Ros_MONSetRebootType(int rebootType);
extern STATUS RosFtpStart(char* pHomeDir);
extern void netEndDevStart (char * pDevName, int unitNum, char * pTgtName,
                     char * pAddrString, int netmask);
extern int bspCpldVerNo (void);
extern void sysMsDelay(UINT delay);
extern UINT8 I2cWriteICS706(UINT8 dev,int num);
extern int bspCpldVerNo (void);
STATUS outBandNetDetach (void);
STATUS outBandNetAttach (void);


#endif /* defined(PRJ_BUILD) */

#ifdef printf
#undef printf
#endif

extern UINT32 vxImmrGet(void);


/*******************************************************************************
 *                            mecInit系列接口                                  *
 *******************************************************************************/
#if defined(PRJ_BUILD)

ZXR10_SYSTEM_IMAGE_FILE Zxr10ImgFile[] =
    {
    {MEC_OAM_FILE_NAME,     CONFIG_DIR_NAME     },
    {"",                    ""                  }
    };

/*******************************************************************************
* ProcMsgPrint
*
*/
void ProcMsgPrint (char * mesg, int state)
    {
    int mesgLen;
    int blankLen;
    int blankLoop;

    mesgLen = (int)strlen(mesg);
    if (mesgLen > 60)
        {
        printf("%s\n", mesg);
        blankLen = 80 - 15;
        }
    else
        {
        printf("%s", mesg);
        blankLen = 80 - mesgLen - 15;
        }

    for (blankLoop = 0; blankLoop < blankLen; blankLoop++)
        printf(".");

    switch(state)
        {
        case (PROC_OK)      :
            printf ("[  OK  ]\n");
            break;
        case (PROC_ERROR)   :
            printf ("[FAILED]\n");
            break;
        case (PROCESSING)   :
        default:
            printf ("[ BUSY ]\r");
        }
    }

/*******************************************************************************
* mecInit - startup MEC card
*
* This routine is called by ROS
*
* RETURN: OK, or ERROR if something is wrong.
*/
STATUS mecInit(void)
    {
    STATUS result = ERROR;
    UINT32 bootFlag;

    printf("\n");
    shellPromptSet("");
    
    b_getMachineType();         /* Get machine type */
    SetMachinePara();           /* set machine parameter */


    /* lyf add */
    if (sysMySlot == 0xFF)
        {
        sysMySlot   = physSlotNumber();
        sysPeerSlot = getSlaveSlotNumber ();
        }
    b_GetLastResetSource();

    /* install a user-supplied date/time function */
#ifndef _WRS_VXWORKS_5_X
    dosFsDateTimeInstall ((FUNCPTR) sysGetDosDateTime);
#else
    b_SetFileSystemClock();
#endif

    NvRamInit();                 /* init NvRam sem */
#if 0
    bootFlag = *(UINT32 *)((UINT32)sysMemTop() + RAM_DISK_SIZE - 4);
#endif
    bootFlag = *(UINT32 *)((UINT32)sysMemTop() + BOOT_RESERVED_MEM - 4);
    if ((NvRamContent.magicNum == NVRAM_MAGIC_NUM) &&
        ((bootFlag == 0) || (bootFlag == 1)))
       {
       NvRamContent.RealBootLoc = bootFlag;
       ProcMsgPrint ("Read eeprom content", PROC_OK);
       }
   else
       {
       ProcMsgPrint ("Read eeprom content", PROC_ERROR);
       }

    printf ("bootLoc: %s\n", (bootFlag == 0) ? "NET" : "FLASH");

#if 0
    if (boardIsMaster() == TRUE)
        {
        masterHwInit();
        ResetAllLicBoard();
        ProcMsgPrint ("Reset all line-cards", PROC_OK);
        }
#endif
    /* mount a dos file system into TrueFFS */
    if (OK != usrTffsConfig (0, 0, TFFS_DISK_NAME))
        ProcMsgPrint ("Configure flash card", PROC_ERROR);
    else
        ProcMsgPrint ("Configure flash card", PROC_OK);

    /* Create a RAM disk */
    if (OK != RamdiskInstall())
        ProcMsgPrint("Create system disk and file system", PROC_ERROR);
    else
        ProcMsgPrint("Create system disk and file system", PROC_OK);
  
    mecExtractVersion();
#ifdef INSTALL_GCSA
    /*加载FPGA文件*/
    mecFpgaLoad();
#endif

    /* master initialize FTP Server */
    if (boardIsMaster() == TRUE)
    {
        if (OK != RosFtpStart ("//"/*TFFS_DISK_NAME*/))
            ProcMsgPrint("Start version ftp server", PROC_ERROR);
        else
            ProcMsgPrint("Start version ftp server", PROC_OK);
    }

    /* Tell mate: I am ready!
     * TODO...
     */
    reportStateToMate(0);

    /* 070808 lyf add */
    outBandNetDetach ();
    
#ifdef INCLUDE_AG_END
    {
    extern int zxAgEndInit(void);

    zxAgEndInit();
    }
#endif

    /* 启动主备、板间网口 */
#ifdef UNIFORM_IP
    {
    char    ipStr[INET_ADDR_LEN], castAddr[INET_ADDR_LEN];
    struct  in_addr inetAddr;

    inetAddr.s_addr = bspBbIpAddr();
    inet_ntoa_b(inetAddr, ipStr);
    netEndDevStart (BBC_DEV, BBC_DEV_UNIT, "", ipStr, BBC_INET_MASK);

    /* 挂旧的ip地址 */
    inetAddr.s_addr = bspBbIpAddrOld();
    if (inetAddr.s_addr != 0)
        {
        inet_ntoa_b(inetAddr, ipStr);

        inetAddr.s_addr = bspBbIpBroadcastOld();
        inet_ntoa_b(inetAddr, castAddr);

        ifAddrAdd (BBC_NET_DEV, ipStr, castAddr, BBC_INET_MASK_OLD);
        }

    inetAddr.s_addr = bspMbIpAddr();
    inet_ntoa_b(inetAddr, ipStr);
    netEndDevStart (MBC_DEV, MBC_DEV_UNIT, "", ipStr, MBC_INET_MASK);


    }
#endif /* UNIFORM_IP */

    /*lvqi:2006-10-25:从CPLD中读取,判别GCSA是否是新版本,新版本中前面板电口phy需要设置I2C.add BEGIN*/
    if ( 0x03 == bspCpldVerNo() )
    {
        I2cWriteICS706(0xd2,24);
    }
    /*lvqi:2006-10-25:add END*/

    return (result);
    }

/*******************************************************************************
* RamdiskInstall
*
*/
LOCAL STATUS RamdiskInstall (void)
    {
#ifdef _WRS_VXWORKS_5_X
    CBIO_DEV_ID     pBlkDev;
#else
    DOS_VOL_DESC  * pVolDesc;
    BLK_DEV       * pBlkDev;
#endif

    if (RamdiskInstallDone)
        return OK;

    /* creat a ram disk */
#ifdef _WRS_VXWORKS_5_X
    {
    pBlkDev = (CBIO_DEV_ID)ramDiskDevCreate ((char *)sysMemTop(), 512, 64, RAM_DISK_SIZE/512, 0);
    dosFsVolFormat (pBlkDev, DOS_OPT_BLANK | DOS_OPT_QUIET, 0);
    /* we can not change it ,because this is vxWorks call function zhou2005-12-26 16:16 */
    dosFsDevCreate (RAMDISK_NAME, pBlkDev, 0, NONE);
    }
#else
    ramDrv();
    pBlkDev = ramDevCreate (sysMemTop(),                /* start address */
                            512,                        /* sector size */
                            64,                         /* sectors per track */
                            RAM_DISK_SIZE/512,          /* total sectors 64 MBytes */
                            0);                         /* offset */
    if (NULL == pBlkDev)
        return ERROR;

    pVolDesc = dosFsMkfs (RAMDISK_NAME, pBlkDev);
    if (NULL == pVolDesc)
        return ERROR;
#endif /* _WRS_VXWORKS_5_X */

    /* create a dir for image files */
    if (OK != mkdir(RAMDISK_NAME""IMG_DIR_NAME))
        return ERROR;

    /* create a dir for config files */
    if (OK != mkdir(RAMDISK_NAME""CONFIG_DIR_NAME))
        return ERROR;

    /* create a dir for database files */
    if (OK != mkdir(RAMDISK_NAME""DATABASE_DIR_NAME))
        return ERROR;

    RamdiskInstallDone = 1;
    return (OK);
    }


/*******************************************************************************
* mecExtractVersion
*
*/
LOCAL STATUS mecExtractVersion (void)
    {
    char            imgDirDest [256];
    char            imgFileDest[256];
    char            ProcMsg[256];
    int             fileNumber = 0;
    int             loopCnt;
    int           * pMvrLen;
    char          * pBuf;
    int             pFile;
    UINT16          file_format;
    UINT32          file_addr;
    UINT32          file_length;
    UINT32          ori_file_length;	
    STATUS          result = OK;

#if 0
    pMvrLen = (int *)(sysMemTop() + RAM_DISK_SIZE);
#endif
    pMvrLen = (int *)(sysPhysMemTop() - TRACE_BUF_SIZE - BOOT_RESERVED_MEM);
    pBuf    = (char *)pMvrLen + sizeof(int);

    bzero (imgFileDest, 256);
    bzero (imgDirDest , 256);

    /* copy image files */
    fileNumber = NELEMENTS(Zxr10ImgFile);
    for (loopCnt = 0; loopCnt < fileNumber; loopCnt++)
        {
    	/*if fileName is empty, ignore copying */
        if (strcmp(Zxr10ImgFile[loopCnt].fileName, "") != 0)
            {
            sprintf(ProcMsg, "Extract %s", Zxr10ImgFile[loopCnt].fileName);

            /* we remove the busy state */
            /* ProcMsgPrint(ProcMsg, PROCESSING); */

	    sprintf (imgDirDest, RAMDISK_NAME"%s", Zxr10ImgFile[loopCnt].dir);
            cd(imgDirDest);

	    sprintf (imgFileDest, "%s/%s", imgDirDest,
	             Zxr10ImgFile[loopCnt].fileName);

            if (ERROR == GetFileFromVer (pBuf, Zxr10ImgFile[loopCnt].fileName, 
                                         &file_format, &file_addr, &file_length, &ori_file_length))
                {
                ProcMsgPrint(ProcMsg, PROC_ERROR);
                result = ERROR;
                continue;
                }

            if (ERROR == (pFile = open(imgFileDest, O_CREAT | O_RDWR, 0)))
                {
                printf ("Cannot create file in RamDisk!\n");
                taskSuspend(0);
                }

            if (ERROR == write (pFile, pBuf + file_addr, file_length))
                {
                printf ("Images copy Error!\n");
                taskSuspend(0);
                }
            close(pFile);

            ProcMsgPrint(ProcMsg, PROC_OK);
            }
        } /* end of for */

    return result;
    }

#ifdef INSTALL_GCSA
/*******************************************************************************
* mecFpgaLoad
*/
LOCAL STATUS mecFpgaLoad (void)
    {
    char            ProcMsg[256];
    int           * pMvrLen;
    char          * pBuf = NULL;
    UINT8         * inflateBuf = NULL;
    char          * filename = "gcsa_fpga.rbf";	/* FPGA文件名 */
    UINT16          file_format;
    UINT32          file_addr;
    UINT32          file_length;
    UINT32          ori_file_length;
    STATUS          result = OK;

    sprintf(ProcMsg, "Extract and load FPGA firmware %s", filename);

#if 0
    pMvrLen = (int *)(sysMemTop() + RAM_DISK_SIZE);
#endif
    pMvrLen = (int *)(sysPhysMemTop() - TRACE_BUF_SIZE - BOOT_RESERVED_MEM);
    pBuf    = (char *)pMvrLen + sizeof(int);

    if (ERROR == GetFileFromVer (pBuf, filename, 
                                 &file_format, &file_addr, &file_length, &ori_file_length))
    {
        /* 用于故障定位 */
        strcat (ProcMsg, " #1");
        result = ERROR;
        goto errorHandle;
    }

    if (file_length != ori_file_length)
    {
        inflateBuf = (char *)malloc (ori_file_length + 4);
        if (inflateBuf == NULL)
        {
            strcat (ProcMsg, " #2");
            result = ERROR;
            goto errorHandle;
        }

        if (inflate ((unsigned char *)file_addr, (unsigned char *)inflateBuf, 
                     (int)file_length) != OK)
        {
            strcat (ProcMsg, " #3");
            result = ERROR;
            goto errorHandle;
        }
    }
    else
    {
        inflateBuf = pBuf + file_addr;
    }
    /* 加载fpga版本,位于[inflateBuf...ori_file_length] */
    if (OK != fpga_ParaLoad(inflateBuf, ori_file_length))
    {
        result = ERROR;
        goto  errorHandle;
    }

errorHandle:
    if ((inflateBuf != NULL) && (file_length != ori_file_length))
        {
        free (inflateBuf);
        }

    if (result == OK)
        {
        ProcMsgPrint(ProcMsg, PROC_OK);
        return (OK);
        }
    else
        {
        ProcMsgPrint(ProcMsg, PROC_ERROR);
        return (ERROR);
        }
    }
#endif
/*******************************************************************************
* shellPromt - change the shell prompt with "[ROS10:]"
* 
*/
void shellPromt (void)
    {
    /* change the shell prompt with "[ROS10:]" */
    shellPromptSet (ROS10_SHELL_PROMPT);
    }
/*******************************************************************************

⌨️ 快捷键说明

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