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

📄 ge_init.c

📁 程序是一个vxworks下对PMC公司3386千兆MAC芯片的驱动和配置
💻 C
字号:
/**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-**-
*	GE_Init.c - Ethernet 1000M code. . 
*
*	Copyright 2001-12 by GDT, Inc
*
*	modification history
*	--------------------
*       2001-12-14,yxy created.
*
*/

#include <msgQlib.h>
#include <errno.h>

#include "GE_Global.h"
#include "GE_GlobalP.h"
#include "GE_Init.h"
#include "bdcom_860.h"
#include "GE_Utility.h"
#include "GE_Test.h"

extern   void	fun_link();

unsigned int 	GE_INIT_DEBUG = 0;

NET_IF		netIf[2]; 

static  char    MAC860_1[6]={0x08, 0x00, 0x3e, 0x00, 0x02, 0x01};
static  char    MAC860_2[6]={0x08, 0x00, 0x3e, 0x00, 0x02, 0x02};

/*board_1*/
unsigned char MAC1[6]={0x12,0x34,0x56,0x00,0x01,0x40};
unsigned char MAC2[6]={0x12,0x34,0x56,0x00,0x02,0x40};
/*board_2*/
unsigned char MAC3[6]={0x12,0x34,0x56,0x00,0x03,0x40};
unsigned char MAC4[6]={0x12,0x34,0x56,0x00,0x04,0x40};

/*******************************************************************************
*	GE_Init:initlize variable
*	sucess:return OK;fail:return ERROR;
*/
STATUS GE_Init()
{
	unsigned char i;

	if(GE_INIT_DEBUG)
	{
	 	printf("\n\n********************************************");
		printf(  "\n**   CORE ROUTER ++ 1000M BOARD SOFTWARE:**");
		printf(	 "\n**   DESIGNED BY:yxy,GDT,2001-12         **");
		printf(  "\n********************************************\n\n");
       		printf("GE_Init:Initlizing 1000M board ...\n");
        }

	GE_ArpMsgQId		= NULL;           
	GE_EventStatisticMsgQId	= NULL;
	GE_MainCommandMsgQId	= NULL;   
	GE_ProtoReceiveMsgQId	= NULL;  
	GE_ProtoSendMsgQId	= NULL;  	
	
	fun_link();
	
	for(i=0;i<2;i++)
	{
		netIf[i].ipAddr=	0;
		netIf[i].ipMask=	0;
		netIf[i].statFreq=	0;
		netIf[i].arpFreq=	0;
		netIf[i].selfTestResult=0;
		netIf[i].loadResult=	0;
		netIf[i].mtu=		0;
		netIf[i].adminStatus=	2;
	}  
    	return OK;
}


/*************************************************************************
*    report lineCard information
*/
STATUS GE_BoardInfoReport(unsigned int initType,unsigned char selftest_result)
{
 	unsigned char 		*pBuf;
        GE_BOARDINFO_STRUCRURE	*pBoardInfo;

	GE_swiport = GE_GetSelfExPort();
    	
    	pBuf=(unsigned char*)malloc(12+sizeof(GE_BOARDINFO_STRUCRURE));
  	if (pBuf==NULL)
	{
		if(GE_INIT_DEBUG)
			GE_printf(GE_ALARM,"GE_BoardInfoReport:memory allocation failed!\n");
      		return ERROR;
	}
	pBoardInfo=(GE_BOARDINFO_STRUCRURE*)(pBuf+12);
	
	pBoardInfo->type = SYS_CONNECT_REQ;
	pBoardInfo->len = (sizeof(GE_BOARDINFO_STRUCRURE)- 8);
        pBoardInfo->initType = initType;
	pBoardInfo->exPort =   GE_swiport;
	pBoardInfo->boardNum = GE_GetSysBoardNum();
	pBoardInfo->boardType = GE_GetSelfBoardType();

	if(GE_swiport==2)
		bcopy(&MAC860_1[0],&pBoardInfo->macAdd[0],MAC_ADD_SIZ);
	else
		bcopy(&MAC860_2[0],&pBoardInfo->macAdd[0],MAC_ADD_SIZ);
	pBoardInfo->selfTestResult = selftest_result;
	pBoardInfo->lnPortNum = 2;
	GE_GetPortMac (pBoardInfo->macAddr,0);
	GE_GetPortMac (pBoardInfo->macAddr+MAC_ADD_SIZ,1);	

	taskDelay(1);
	if(GE_INIT_DEBUG)
	{
    		GE_printf(GE_DATA," -- data_type   = %d \n", pBoardInfo->type);
    		GE_printf(GE_DATA," -- data_len    = %d \n", pBoardInfo->len);
    		GE_printf(GE_DATA," -- groupIndex  = %d \n", pBoardInfo->exPort);
    		GE_printf(GE_DATA," -- boardID     = %d \n", pBoardInfo->boardNum);
    		GE_printf(GE_DATA," -- boardType   = %d \n", pBoardInfo->boardType); 
	}
      	if( BDCOM_UpReceive(	BDCOM_STREAM,
				NO_WAIT,
				MSG_PRI_NORMAL,
                       		SYS_BDCOM_HEAD_SIZE+ sizeof(GE_BOARDINFO_STRUCRURE),
                       		pBuf,
                       		SYS_BDCOM_HEAD_SIZE,
                       		sizeof(GE_BOARDINFO_STRUCRURE)) == ERROR)
      	{
       		if(GE_INIT_DEBUG)
       			GE_printf(GE_ALARM,"GE_BoardInfoReport:report BOARD_INFO failed!\n");
       		free((void*)pBuf);
       		return ERROR;
      	}
      	else
     	{
       		if(GE_INIT_DEBUG)
       			GE_printf(GE_EVENT,"GE_BoardInfoReport:sending BOARD_INFO to BDCOM succeed!\n");
     	}
  	return OK;
}
/*************************************************************************
*  initConfig: in initlization,deal with the GE_CONFIGLOAD_STRUCTURE
*  message from SYSCON
*/
STATUS GE_ConfigLoad(unsigned char* pBuf)
{
   	GE_CONFIGLOAD_STRUCTURE *pConfig0;
   	GE_CONFIGLOAD_STRUCTURE *pConfig1;
   	
   	if(pBuf==NULL)
    	{
       		if(GE_INIT_DEBUG)
       			GE_printf(GE_ALARM,"GE_ConfigLoad:have not received ConfigLoad!\n");
       		return ERROR;
    	}
   	else
    	{     		
		if(GE_INIT_DEBUG)
			GE_printf(GE_EVENT,"GE_ConfigLoad: recived SYS_CONFIG_REQUEST!\n");       	

	 	if(*(char*)(pBuf+8)!=2)
		{
			if(GE_INIT_DEBUG)
				GE_printf(GE_ALARM,"GE_ConfigLoad:unitNum!=2,ERROR\n");
			return ERROR;
		}
		pConfig0 =(GE_CONFIGLOAD_STRUCTURE*)(pBuf+8+1);
		pConfig1 =(GE_CONFIGLOAD_STRUCTURE*)(pBuf+8+1+ sizeof(GE_CONFIGLOAD_STRUCTURE));   	
		netIf[0].adminStatus = pConfig0->adminStatus;
	    	netIf[0].mtu = pConfig0->mtu;
	    	netIf[0].ipAddr = pConfig0->ipAddr;
	    	netIf[0].ipMask = pConfig0->ipMask;
	    	netIf[0].statFreq = (unsigned int ) (pConfig0->statFreq);
    	    	netIf[0].arpFreq = (unsigned int ) (pConfig0->arpFreq);
    	    
 
	    	netIf[1].adminStatus = pConfig1->adminStatus;
	    	netIf[1].mtu = pConfig1->mtu;
	    	netIf[1].ipAddr = pConfig1->ipAddr;
	    	netIf[1].ipMask = pConfig1->ipMask;
	    	netIf[1].statFreq = pConfig1->statFreq;
    	    	netIf[1].arpFreq = pConfig1->arpFreq;
  		if(GE_INIT_DEBUG)
  		{
            		GE_printf(GE_DATA,"--- unit=%d,adminStatus = %d, mtu = %d ,statFreq = %d---\n",pConfig0->unit,pConfig0->adminStatus,pConfig0->mtu,pConfig0->statFreq);
			GE_printf(GE_DATA,"--- unit=%d,adminStatus = %d, mtu = %d ,statFreq = %d---\n",pConfig1->unit,pConfig1->adminStatus,pConfig1->mtu,pConfig1->statFreq);
           		GE_printf(GE_DATA,"--- ipAddr = %08x, ipMask = %08x,  ---\n",pConfig0->ipAddr,pConfig0->ipMask);
            		GE_printf(GE_DATA,"--- ipAddr = %08x, ipMask = %08x,  ---\n",pConfig1->ipAddr,pConfig1->ipMask);
		}
		return OK;
   	}
   	return OK;
} 	  
/*************************************************************************/

STATUS GE_InitStart()
{
	unsigned int  i;

	if(GE_INIT_DEBUG)
		GE_printf(GE_EVENT,"GE_InitStart: begin to creat board software tasks...");
        
	if (GE_MainCommandInit()==ERROR)
     	{
     		if(GE_INIT_DEBUG)
     			GE_printf(GE_ALARM,"GE_InitStart:GE_MainCommandInit task start failed!\n");
        	return ERROR;
     	}   	
	if (GE_EventStatisticInit()==ERROR)
     	{
     		if(GE_INIT_DEBUG)
     			GE_printf(GE_ALARM,"GE_InitStart:GE_EventStatisticInit task start failed!\n");
       		return ERROR;
     	} 

     	if (GE_ProtoSendInit()==ERROR)
     	{
     		if(GE_INIT_DEBUG)
     			GE_printf(GE_ALARM,"GE_InitStart:GE_ProtoSendInit task start failed!\n");
       		return (ERROR); 
     	}    
     	if (GE_ArpInit()==ERROR)
	{
		if(GE_INIT_DEBUG)
			GE_printf(GE_ALARM,"GE_InitStart:GE_ArpInit task start failed!\n");
		return ERROR;
	}
     	if (GE_ProtoReceiveInit()==ERROR)
     	{
     		if(GE_INIT_DEBUG)
     			GE_printf(GE_ALARM,"GE_InitStart:GE_ProtoReceiveInit task start failed!\n");
       		return ERROR; 
     	}	
	/*report the line speed*/
	for(i=0;i<2;i++)
	{
		GE_EventReport(4,i,REPORT_LINE_SPEED,FULL_DUPLEX);
		GE_EventReport(4,i,REPORT_LINE_STATE,NET_PORT_DOWN);
		netIf[i].adminStatus=NET_PORT_DOWN;
	}

     	return OK;
}

/***************************************************************************
 *  initHardware: initlize hardware --PM3386, --FPGAIN, --FPGAOUT
 */
STATUS  GE_InitHardware()
{
	GE_Cmd_to_down();
	wr_to_pb(8,0);	
	GE_Cmd_to_up();
	GE_swiport = GE_GetSelfExPort();

	if(GE_INIT_DEBUG)
		GE_printf(GE_EVENT,"Initlize FPGA_OUT...");
	if (GE_InitOutfpga()!=OK)
       	{ 
       	 	if(GE_INIT_DEBUG)
       	 		GE_printf(GE_ALARM," GE_InitHardware :Initlize FPGA_OUT failed!\n");
       		return ERROR;
       	}
  	if(GE_INIT_DEBUG)
  		GE_printf(GE_EVENT,"Initlize FPGA_IN...");
       	if (GE_InitInfpga()!=OK)
       	{
        	if(GE_INIT_DEBUG)
        		GE_printf(GE_ALARM," GE_InitHardware :Initlize FPGA_IN failed!\n");
        	return ERROR;
      
        }
       	if (GE_InitPM3386()!=OK)
       	{
        	if(GE_INIT_DEBUG)
        		GE_printf(GE_ALARM," GE_InitHardware :Initlize PM3386 failed!\n");
        	return (ERROR);
       	}
       	
  	if(GE_INIT_DEBUG)
  		GE_printf(GE_EVENT," GE_InitHardware :Hardware initlization OK!\n");
    	return OK;
}

/********************************************************************************************
 * GE_InitPM3386 
 *  
 */
STATUS GE_InitPM3386(void)
{
	resetPM3386();
	
	taskDelay(6);
	PM3386Write(0x122,0x0008);
	PM3386Write(0x142,0x0008);
	PM3386Write(0x103,0x0003);	
	PM3386Write(0x310,0x05F6);
	PM3386Write(0x410,0x05F6);
	PM3386Write(0x336,0x05F6);
	PM3386Write(0x436,0x05F6);
	PM3386Write(0x302,0x1733);
	PM3386Write(0x402,0x1733);
        PM3386Write(0x301,0x8000);
        PM3386Write(0x301,0x0000);
        PM3386Write(0x401,0x8000);
        PM3386Write(0x401,0x0000);

	if(GE_swiport==2)
	{
		/*station address*/
		PM3386Write(0x308,(MAC1[2]<<8)|MAC1[1]);
		PM3386Write(0x309,(MAC1[4]<<8)|MAC1[3]);
		PM3386Write(0x30A,(MAC1[6]<<8)|MAC1[5]);
		PM3386Write(0x408,(MAC2[2]<<8)|MAC2[1]);
		PM3386Write(0x409,(MAC2[4]<<8)|MAC2[3]);
		PM3386Write(0x40A,(MAC2[6]<<8)|MAC2[5]);

		/*DA  */
		PM3386Write(0x339,*(USHORT*)&MAC1[4]);
		PM3386Write(0x33A,*(USHORT*)&MAC1[2]);
		PM3386Write(0x33B,*(USHORT*)&MAC1[0]);
		PM3386Write(0x439,*(USHORT*)&MAC2[4]);
		PM3386Write(0x43A,*(USHORT*)&MAC2[2]);
		PM3386Write(0x43B,*(USHORT*)&MAC2[0]);

		/*SA*/
		PM3386Write(0x33C,*(USHORT*)&MAC1[4]);
		PM3386Write(0x33D,*(USHORT*)&MAC1[2]);
		PM3386Write(0x33E,*(USHORT*)&MAC1[0]);
		PM3386Write(0x43C,*(USHORT*)&MAC2[4]);
		PM3386Write(0x43D,*(USHORT*)&MAC2[2]);
		PM3386Write(0x43E,*(USHORT*)&MAC2[0]);
	}
	else
	{
		/*station address*/
		PM3386Write(0x308,(MAC3[2]<<8)|MAC3[1]);
		PM3386Write(0x309,(MAC3[4]<<8)|MAC3[3]);
		PM3386Write(0x30A,(MAC3[6]<<8)|MAC3[5]);
		PM3386Write(0x408,(MAC4[2]<<8)|MAC4[1]);
		PM3386Write(0x409,(MAC4[4]<<8)|MAC4[3]);
		PM3386Write(0x40A,(MAC4[6]<<8)|MAC4[5]);

		/*DA  */
		PM3386Write(0x339,*(USHORT*)&MAC3[4]);
		PM3386Write(0x33A,*(USHORT*)&MAC3[2]);
		PM3386Write(0x33B,*(USHORT*)&MAC3[0]);
		PM3386Write(0x439,*(USHORT*)&MAC4[4]);
		PM3386Write(0x43A,*(USHORT*)&MAC4[2]);
		PM3386Write(0x43B,*(USHORT*)&MAC4[0]);

		/*SA*/
		PM3386Write(0x33C,*(USHORT*)&MAC3[4]);
		PM3386Write(0x33D,*(USHORT*)&MAC3[2]);
		PM3386Write(0x33E,*(USHORT*)&MAC3[0]);
		PM3386Write(0x43C,*(USHORT*)&MAC4[4]);
		PM3386Write(0x43D,*(USHORT*)&MAC4[2]);
		PM3386Write(0x43E,*(USHORT*)&MAC4[0]);
	}

     	PM3386Write(0x359,0xFFFF);
        PM3386Write(0x35A,0xFFFF);
        PM3386Write(0x35B,0xFFFF);
	PM3386Write(0x35C,0xFFFF);
	PM3386Write(0x459,0xFFFF);
        PM3386Write(0x45A,0xFFFF);
        PM3386Write(0x45B,0xFFFF);
	PM3386Write(0x45C,0xFFFF);

	PM3386Write(0x35D,0x39);
	PM3386Write(0x35F,0x01);
	PM3386Write(0x360,0x01);
	PM3386Write(0x45D,0x39);
	PM3386Write(0x45F,0x01);
	PM3386Write(0x460,0x01);	
	PM3386Write(0x303,0x5000);
	PM3386Write(0x403,0x5000);
      	taskDelay(1);

	if(GE_INIT_DEBUG)
		GE_printf(GE_EVENT,"PM3386 init config successfully.\n");
        return OK;
}
/********************************************************************************************
 *   initFpgain: config FPGA_IN
 */
STATUS GE_InitInfpga()
{	
	ULONG	ipAddr=0x12345678;
	
	resetInfpga();
	       
	infpgaWrite(0x10,ipAddr);
	infpgaWrite(0x18,(ULONG)GE_swiport);
	/*infpgaWrite(0x14,(ULONG)(exPort<<2));  Modify on 2002.9.2*/
	
	return OK;
}
/******************************************************************************************
 *  initFpgaout: config FPGA_OUT
 */
STATUS GE_InitOutfpga(void)
{
  	ULONG  		macAddrLow0,macAddrHigh0;
	ULONG  		macAddrLow1,macAddrHigh1;
	unsigned char 	macAddr[6];
	
	resetOutfpga();
	cam_hw_reset();
	cam_init();

	if(GE_swiport==2)
	{
		macAddrHigh0=*(ULONG*)&MAC1[0];
		macAddrLow0=(ULONG)(*(USHORT*)&MAC1[4])<<16;
	
		macAddrHigh1=*(ULONG*)&MAC2[0];
		macAddrLow1=(ULONG)(*(USHORT*)&MAC2[4])<<16; 
	
		/*port 0  mac address*/
        	outfpgaWrite(0x00, macAddrHigh0);
       		outfpgaWrite(0x04, macAddrLow0); 
       	     
 		/*port 1 mac address*/
        	outfpgaWrite(0x08, macAddrHigh1);
       		outfpgaWrite(0x0C, macAddrLow1);
	}
	else
	{
		macAddrHigh0=*(ULONG*)&MAC3[0];
		macAddrLow0=(ULONG)(*(USHORT*)&MAC3[4])<<16;
	
		macAddrHigh1=*(ULONG*)&MAC4[0];
		macAddrLow1=(ULONG)(*(USHORT*)&MAC4[4])<<16; 
	
		/*port 0  mac address*/
        	outfpgaWrite(0x00, macAddrHigh0);
       		outfpgaWrite(0x04, macAddrLow0); 
       	     
 		/*port 1 mac address*/
        	outfpgaWrite(0x08, macAddrHigh1);
       		outfpgaWrite(0x0C, macAddrLow1);
	}
       	
       	return OK;
}
void GE_Cmd_to_down()
{
	wr_to_pb(4,0);
	wr_to_pb(5,0);
	wr_to_pb(6,0);
	wr_to_pb(7,0);
	taskDelay(1);	
 	return;
}
void GE_Cmd_to_up()
{
	wr_to_pb(4,1);
	wr_to_pb(5,1);
	wr_to_pb(6,1);
	wr_to_pb(7,1);
	taskDelay(1);	
 	return;
}
/***********************resetHardware*******************************************************/
void GE_FpgaInit()
{
	GE_Cmd_to_down();
	wr_to_pb(8,0);	
	GE_Cmd_to_up();
	taskDelay(1);
	GE_InitInfpga();
	GE_InitOutfpga();
	wr_to_pb(8,1);	
	return;		
}



/* end of file GE_Init.c */



⌨️ 快捷键说明

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