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

📄 ethernet.c

📁 EV440B实验源码
💻 C
字号:


#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\def.h"
#include "..\inc\option.h"
#include "..\inc\ethernet.h"




short read ( short offset );
void write( short offset,short regvalue );
void resetnet(void);
void netID(void);
void MACR(void);
void MACW(void);
void RAMT(void);
void MMUT(void);
void transmitpacket(void);
void receivepacket(void);
void EXIT(void);

/****************************************************************
 *		SMSC LAN91C113 test item		*  
 
 ***************************************************************/


void * net[][2]=
{
	(void *)EXIT,		 	"EXIT  		 ",
	(void *)netID	, 		"LAN91C113 ID Code 	 ",
	(void *)MACR, 		 	"MAC Register Read	 ",
	(void *)MACW, 		 	"MAC Register Write	 ",
	(void *)RAMT,		 	"RAM Buffer Test  	 ",
	(void *)MMUT,			"MMU TEST		 ",
	 0,0
};
//*----------------------------------------------------------------------------
//* Function Name       : ethernet
//* Object              : Main function of transmit and recieve
//* readut Parameters    : none
//* writeut Parameters   : TRUE
//*----------------------------------------------------------------------------
void ethernet( void )
{	
  	U32 saveSyscfg,i;
    
    	saveSyscfg=rSYSCFG;
    
    	rSYSCFG=SYSCFG_8KBn;
	rNCACHBE0=( (0x4000000>>12)<<16 )|(0x2000000>>12);
	resetnet();
	while(1)
	{   
	    i=0;
	    while(1)
	    {
	    Uart_Printf("%2d:%s",i,net[i][1]);
	    i++;
	    if((int)(net[i][0])==0)
	    {
		Uart_Printf("\n");
		break;
	    }
	    if((i%2)==0)
		Uart_Printf("\n");
	    }
	Uart_Printf("\nSelect the function to test(press 0,exit)?");
	i=Uart_GetIntNum();
	Uart_Printf("\n");
	if(i>0 && (i<(sizeof(net)/8)) ) 
	    ( (void (*)(void)) (net[i][0]) )();
	else
	{
		rSYSCFG=saveSyscfg;	
		break;
		}
   }
}
 
//*----------------------------------------------------------------------------
//* Function Name       : read
//* Object              : Main function of read register's value
//* readut Parameters    : register address
//* writeut Parameters   : register value
//*----------------------------------------------------------------------------
short read( short offset )
{
	short regvalue,*pt;
	pt = (short*)(IOBase + offset);
	regvalue = *pt;
	Delay(10);
	return(regvalue);
}
//*----------------------------------------------------------------------------
//* Function Name       : write
//* Object              : Main function of write register's value
//* readut Parameters    : register address and value
//* writeut Parameters   : none
//*----------------------------------------------------------------------------
void write( short offset,short regvalue )
{
	short *pt;
	pt = (short*)(IOBase + offset);
	*pt = regvalue;
	Delay(10);
}
//*----------------------------------------------------------------------------
//* Function Name       : resetnet
//* Object              : softreset LAN91C113
//* readut Parameters    : none
//* writeut Parameters   : none
//*----------------------------------------------------------------------------
void resetnet(void)
{
//*software reset phy
	write(0xe,0);		//bank0
	write(0x4,0x8000);	//softreset
	Delay(100);
	write(0x4,0x0000);	//softreset
//*AUTO-NEGOTIATION
	write(0x4,0x0);
	write(0xa,0x800);
	Delay(50);
}

//*----------------------------------------------------------------------------
//* Function Name       : netID
//* Object              : Read the SMSC LAN91C113 ID code
//* readut Parameters    : none
//* writeut Parameters   : none
//*----------------------------------------------------------------------------
void netID(void)
{	
	U16 idl;
//*get chip ID
	write(0xe,0x3);		//bank4
	idl=read(0xa);
	Uart_Printf("\nSMSC LAN91C113 ID code is 0x%x\n\n",idl);
}
//*----------------------------------------------------------------------------
//* Function Name       : MACR
//* Object              : Read the SMSC LAN91C113 ID code
//* readut Parameters    : none
//* writeut Parameters   : none
//*----------------------------------------------------------------------------
void MACR(void)
{
	U16 i,j,temp;
	
	Uart_Printf("\nSelect the bank to read?");
	i=Uart_GetIntNum();
	write(0xe,i);		//select bank
	Uart_Printf("\nSelect the offset register to read?");
	j=Uart_GetIntNum();
	temp=read(j);		//select bank
	Uart_Printf("\nthe bank%d offset%x register data is 0x%x\n",i,j,temp);
}
//*----------------------------------------------------------------------------
//* Function Name       : MACW
//* Object              : Write the SMSC LAN91C113 ID code
//* readut Parameters    : none
//* writeut Parameters   : none
//*----------------------------------------------------------------------------
void MACW(void)
{
	short i,j;
	
	Uart_Printf("\nSelect the bank to read?");
	i=Uart_GetIntNum();
	write(0xe,i);		//select bank
	Uart_Printf("\nSelect the offset register to write?\n");
	j=Uart_GetIntNum();
	write( i,j);		//select bank
}
//*----------------------------------------------------------------------------
//* Function Name       : RAMT
//* Object              : Read the SMSC LAN91C113 ID code
//* readut Parameters    : none
//* writeut Parameters   : none
//*----------------------------------------------------------------------------
void RAMT(void)
{
	U16 temp=0,j;
	U32 data,i,*pt;
	U8 *pter,packnum;
	pter =(U8 *)0X2000303;
	pt =(U32 *)0x2000308;	
	
	for(j=0;j<4;j++)
	{
		Uart_Printf("ntest %d packet memory",j);
		write(0xe,0x2);
		write(0x0,0x20);
		do{
		temp=read(0xc);
		temp&=0x4;
		}while(!temp);
	
		packnum=*pter;
		write(0x2,j);
	
		for(i=0;i<0x400;i++)
		{
		 write(0x6,i);
		 *pt =i;
		}
		for(i=0;i<0x400;i++)
		{
	 	write(0x6,0x2000+i);
	 	data=*pt;
	 	if(data!=i)
	 	  {
	 		Uart_Printf("\nRAM TEST FAIL\n");
	 		break;
	 	  }
		}
		Uart_Printf("\ntest %d packet memory is OK\n",j);
	}
}
//*----------------------------------------------------------------------------
//* Function Name       : MMUT
//* Object              : Read the SMSC LAN91C113 ID code
//* readut Parameters    : none
//* writeut Parameters   : none
//*----------------------------------------------------------------------------
void MMUT(void)
{
	
	U16 temp=0,j;
	U32 data,i,*pt;
	U8 *pter,packnum;
	pter =(U8 *)0X2000303;
	pt =(U32 *)0x2000308;	
	
	Uart_Printf("\nAllocate memory for TX test,form packet 0 to 3");
	for(i=0;i<4;i++)
	{
		write(0xe,0x2);
		write(0x0,0x20);
		do{
		temp=read(0xc);
		temp&=0x4;
		}while(!temp);
	packnum = *pter;
	
	write(0xe,0x0);
	j=read(0x8);
	temp=(3-i)<<8|0x4;
		if(j!=temp)
		{
			Uart_Printf("\nPacket %d test fail\n",i);
			break;
		}
		Uart_Printf("\nPacket %d test ok,IMR IS 0x%x\n",i,j);
	}
	Uart_Printf("\nRESET MMU TO INITIAL STATE");
	write(0xe,0x2);
	write(0x0,0x40);
	temp=read(0x4);
	write(0xe,0x0);
	j=read(0x8);
	if((temp!=0x8080)&&(j!=0x404))
		Uart_Printf("\nTEST FAIL,FIFO is 0x%x,IMR IS 0x%x",temp,j);
	else
		Uart_Printf("\nTEST OK,FIFO is 0x%x,IMR IS 0x%x\n\n",temp,j);
	
}	
		
//*----------------------------------------------------------------------------
//* Function Name       : transmitpacket
//* Object              : transmit packet, when success, a interrupt happen
//* readut Parameters    : none
//* writeut Parameters   : none
//*----------------------------------------------------------------------------
void transmitpacket(void)
{
	

}

//*----------------------------------------------------------------------------
//* Function Name       : receivepacket
//* Object              : when the card recieve a packet from the LAN, 
//*                       a interrupt happen,then call this function to  
//*                       read the packet from receive buffer
//* readut Parameters    : none
//* writeut Parameters   : none
//*----------------------------------------------------------------------------
void receivepacket(void)
{
	

}

void EXIT(void)
{
	}


⌨️ 快捷键说明

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