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

📄 mac.c

📁 S3C4510B的一些开发例程
💻 C
📖 第 1 页 / 共 3 页
字号:
	RdValue = MiiStationRead( PHY_CNTL_REG, PHYHWADDR) ;
	Print("\r1. CNTL REG     (0x3000) : %04x ",RdValue) ;
	RdValue = MiiStationRead( PHY_STATUS_REG, PHYHWADDR) ;
	Print("\r2. STATUS REG   (0x7809) : %04x ",RdValue) ;
	RdValue = MiiStationRead( PHY_ID_REG1, PHYHWADDR) ;
	Print("\r3. ID REG1      (0x0015) : %04x ",RdValue) ;
	RdValue = MiiStationRead( PHY_ID_REG2, PHYHWADDR) ;
	Print("\r4. ID REG2      (0xF423) : %04x ",RdValue) ;
	RdValue = MiiStationRead( PHY_ANA_REG, PHYHWADDR) ;
	Print("\r5. ANA REG      (0x01E1) : %04x ",RdValue) ;
	RdValue = MiiStationRead( PHY_ANLPAR_REG, PHYHWADDR) ;
	Print("\r6. ANLPAR REG   (0x0000) : %04x ",RdValue) ;
	RdValue = MiiStationRead( PHY_ANE_REG, PHYHWADDR) ;
	Print("\r7. ANE REG      (0x0000) : %04x ",RdValue) ;
	RdValue = MiiStationRead( PHY_ECNTL_REG1, PHYHWADDR) ;
	Print("\r8. ECNTL REG    (0xXXXX) : %04x ",RdValue) ;
	RdValue = MiiStationRead( PHY_QPDS_REG, PHYHWADDR) ;
	Print("\r9. QPDS REG     (0xX00X) : %04x ",RdValue) ;
	RdValue = MiiStationRead( PHY_10BOP_REG, PHYHWADDR) ;
	Print("\r10.10BOP REG    (0xXX10) : %04x ",RdValue) ;
	RdValue = MiiStationRead( PHY_ECNTL_REG2, PHYHWADDR) ;
	Print("\r11.ECNTL REG    (0xXXXX) : %04x ",RdValue) ;
}

/*
 * Function : BdmaBufferTest                                               
 * Description : Test Function for BDMA Rx/Tx Buffer and CAM Read/Write 
 *               Used in Other LoopBack Test Function
 */
void BdmaBufferTest(void)
{
	U32 TestBufferBase ;
	U32 TestBufferSize ;
	U32 TestLoopCnt = 0xFF;
	int i, j ;

	Print("\n >>>  BDMA Tx/Rx and CAM Buffer Test <<< ");

	Print("\r >>   BDMA Tx Buffer Test ....    ");
	TestBufferBase = Base_Addr + 0x9200 ;
	TestBufferSize = 64 ;
	for (i=0 ; i < TestLoopCnt ; i++) 
	{
		for (j=0 ; j < 4 ; j++)
		{
		MemTestInit((U32 *)MemCopySrc, TestBufferSize);
		WordCopyTest((U32 *)MemCopySrc,(U32 *)TestBufferBase,\
					 TestBufferSize);
		}
	}
	Print("Ok.") ;

	// BDMA Rx Buffer Long Range : 9900
	// BDMA Rx Buffer 1bit Range : 9800
	Print("\r >>   BDMA Rx Buffer Test ....    ");
	TestBufferBase = Base_Addr + 0x9900 ;
	TestBufferSize = 64 ;
	for (i=0 ; i < TestLoopCnt ; i++) 
	{
		for (j=0 ; j < 4 ; j++)
		{
		MemTestInit((U32 *)MemCopySrc, TestBufferSize);
		WordCopyTest((U32 *)MemCopySrc,(U32 *)TestBufferBase,\
					 TestBufferSize);
		}
	}
	Print("Ok.") ;

	Print("\r >>   CAM Read/Write Test ....    ") ;
	TestBufferBase = Base_Addr + 0x9100 ;
	TestBufferSize = 32 ;
	for (i=0 ; i < TestLoopCnt ; i++) 
	{
		for (j=0 ; j < 4 ; j++)
		{
		MemTestInit((U32 *)MemCopySrc, TestBufferSize);
		WordCopyTest((U32 *)MemCopySrc,(U32 *)TestBufferBase,\
					 TestBufferSize);
		}
	}
	Print("Ok.") ;
}


/*
 * Function : MacTxHaltReqTest
 * Description : MAC Tx Halt Request and Halt Immediate Test
 */
void MacTxHaltReqTest(void) 
{

	char TransferPacket ;

	Print("\n >>>  MAC Tx Halt Request Test  <<< \r") ;
	do 
	{
	Print("\r   >> Select (Q)uit or (T)x 2 Frame  : ");
	TransferPacket = get_byte() ;
	if ( (TransferPacket == 'T') || (TransferPacket == 't') )
		{
		// Initialize MAC Frame Data
		Random_Pkt_Transmit(100) ;

		// Initialize MAC Frame Data
		Random_Pkt_Transmit(100) ;

		// Enable Halt Request
		//MACCON |= HaltReg ;
		MACCON |= HaltImm ;
		//MACTXCON |= TxHalt ;

		}
		// Disable Halt Request
		//MACCON &= ~HaltReg ;
		MACCON &= ~HaltImm ;
		//MACTXCON &= ~TxHalt ;
	} while ( (TransferPacket != 'Q') && (TransferPacket != 'q') ) ;

	ReadErrReport() ;
	ClearErrReport() ;
}

/*
 * Function : MacFifoTest
 * Description : MAC ETC function test
 */
void MacFifoTest(void)
{
	int i ;
	U8 *TestArea ;
	U32 *BdmaBuf ;

	//#define MACRXFIFO	(VPint(Base_Addr+0xa200))
	//#define MACTMODE	(VPint(Base_Addr+0x9018))

	TestArea	= (U8 *)MACRXFIFO ;
	BdmaBuf = (U32 *)(Base_Addr + 0x9900) ;
	//MACRXCON = 0x0 ;
	//MACTMODE = 0x01 ;
	for (i=0;i<3;i++)
		{
		Print("\nBDMA FIFO : %08x",*BdmaBuf) ;
		Print("\rMAC FIFO  : %02x",*TestArea) ;
		}
	//MACTMODE = 0x00 ;
	//MACRXCON = gMacRxCon ;

}

/*
 * Function : void MacConfig(void)
 * Description : Other MAC Function
 */
void MacConfig(void)
{
	char TestItemSel ;
	do {
	Print("\n+---------------------------------------------------+\r") ;
	Print("|    ***** MAC Configuration View & Change *****    |\r") ;
        Print("|           Rev 1.0 (by hbahn, 1998.04.17)          |\r") ;
	Print("+---------------------------------------------------+\r") ;
	Print("| MAC & BDMAC Configuration View              - [V] |\r") ;
	Print("| MAC & BDMAC Configuration Change            - [C] |\r") ;
	Print("| View & Change My MAC Address                - [A] |\r") ;
	Print("| Quit Other MAC Function Test                - [Q] |\r") ;
	Print("+---------------------------------------------------+\r") ;
	Print("\rSelect Test Item : ") ; TestItemSel = get_byte() ;
	
	switch(TestItemSel)
	{
		case 'V' : case 'v' : ViewMacAndBdmaConfiguration() ;
				      break ;
		case 'C' : case 'c' : ChangeMacAndBdmaConfiguration() ;
				      break ;
		case 'A' : case 'a' : MacAddrRead() ;
				      MacAddrWrite() ;
				      MacAddrRead() ;
				      break ;
		case 'Q' : case 'q' : break ;
		default : Print("\nInvalid Test Item Selected") ; 
				break ;
	}

	if ( (TestItemSel != 'Q') && (TestItemSel != 'q') )
		{
		Print("\nPress any key to Continue") ; 
		get_byte() ;
		}
	} while  ( (TestItemSel != 'Q') && (TestItemSel != 'q') ) ;
}


/*
 * Function : ViewMacAndBdmaConfiguration
 * Description : View MAC and BDMA Configuration View
 */
void ViewMacAndBdmaConfiguration(void)
{
	U32  MacConfView ;
	U32  BdmaConfView ;
	U32  BdmaSetValue ;
	U32  PhyStatus ;

	Print("\n  >>>>>>> MAC Configuration View <<<<<<<") ;
	// ------------ MAC Global Control Register --------------
	MacConfView = MACCON ;
	Print("\r +=========================================+");
	Print("\r + MACCON : MAC Gloabal Control Register   +");
	Print("\r +-----------------------------------------+");
	if (MacConfView & FullDup) 
		Print("\r + - Full Duplex Supported                 +") ;
	if (MacConfView & EnMissRoll)
		Print("\r + - Enabled Missed error count roll over  +") ;

	// ------------ MAC Tx Control Register --------------
	MacConfView = MACTXCON ;
	Print("\r +=========================================+");
	Print("\r +  MACTXCON : MAC Tx Control Register     +");
	Print("\r +-----------------------------------------+");
	if (MacConfView & TxEn) 
		Print("\r + - MAC Tx Enabled                        +") ;	
	if (MacConfView & TxHalt) 
		Print("\r + - MAC Tx Halt Requested                 +") ;	
	if (MacConfView & NoPad) 
		Print("\r + - MAC Tx Suppress Padding               +") ;
	if (MacConfView & NoCRC) 
		Print("\r + - MAC Tx Suppress CRC                   +") ;
	if (MacConfView & FBack)
		Print("\r + - MAC Tx Fast Back-off Enabled          +") ;
	if (MacConfView & NoDef)
		Print("\r + - MAC Tx Disable Defer Counter          +") ;

	Print("\r + - MAC Tx Interrupt :                    +") ;
	if (MacConfView & EnUnder) 
		Print("\r +             Underrun                    +") ;
	if (MacConfView & EnDefer) 
		Print("\r +             Deferral                    +") ;
	if (MacConfView & EnNCarr) 
		Print("\r +             NoCarrier                   +") ; 
	if (MacConfView & EnLateColl) 
		Print("\r +             Late Collision              +") ;
	if (MacConfView & EnExColl) 
		Print("\r +             Excessive Collision         +") ;
	if (MacConfView & EnTxPar) 
		Print("\r +             FIFO Parity Error           +") ;
	if (MacConfView & EnComp) 
		Print("\r +             Packet Tx Complete          +") ;

	// ------------ MAC Rx Control Register --------------
	MacConfView = MACRXCON ;
	Print("\r +=========================================+");
	Print("\r +  MACRXCON : MAC Rx Control Register     +");
	Print("\r +-----------------------------------------+");
	if (MacConfView & RxEn)
		Print("\r + - MAC Rx Enabled                        +") ;
	if (MacConfView & RxHalt)
		Print("\r + - MAC Rx Halt Requested                 +") ;
	if (MacConfView & LongEn)
		Print("\r + - MAC Rx Long Frame(1518B) Enabled      +") ;
	if (MacConfView & ShortEn)
		Print("\r + - MAC Rx Short Frame(64B) Enabled       +") ;
	if (MacConfView & StripCRC)
		Print("\r + - MAC Rx Check CRC, But Strip CRC       +") ;
	if (MacConfView & PassCtl)
		Print("\r + - MAC Rx Pass Control Packet            +") ;
	if (MacConfView & IgnoreCRC)
		Print("\r + - MAC Rx Ignore CRC                     +") ;

	Print("\r + - MAC Rx Interrupt :                    +") ;
	if (MacConfView & EnGood) 
		Print("\r +                     Rx Good             +") ;
	if (MacConfView & EnAlign) 
		Print("\r +                     Mis-Allign          +") ;
	if (MacConfView & EnCRCErr) 
		Print("\r +                     CRC Error           +") ;
	if (MacConfView & EnOver) 
		Print("\r +                     FIFO Overflow       +") ;
	if (MacConfView & EnLongErr) 
		Print("\r +                     Over 1518B Frame    +") ;
	if (MacConfView & EnRxPar) 
		Print("\r +                     Parity Error        +") ;
	Print("\r +=========================================+");

	Print("\n  >>>>>>> BDMA Configuration View <<<<<<<") ;
	// ------------ BDMA Tx Control Register --------------
	BdmaConfView = BDMATXCON ;
	Print("\r +=========================================+");
	Print("\r + BDMATXCON : BDMA Tx Control Register    +");
	Print("\r +-----------------------------------------+");
	if (BdmaConfView & BTxEn) 
		Print("\r + -  BDMA Tx Enabled                      +") ;
	BdmaSetValue = BdmaConfView & 0x1F ;
	Print("\r + - BDMA Tx Burst Size : %d Byte          +",(BdmaSetValue+1)) ;
	if (BdmaConfView & BTxSTSKO)
		Print("\r + - BDMA Tx STOP, if Descriptor Not Owner +") ;
	else
		Print("\r + - BDMA Tx SKIP, if Descriptor Not Owner +") ;

	Print("\r + - BDMA Tx Interrupt :                   +") ;
	if (BdmaConfView & BTxCPIE) 
		Print("\r               Control Packet Tx Complete  +") ;
	if (BdmaConfView & BTxEmpty) 
		Print("\r               BDMA Tx Buffer Empty        +") ; 
	if (BdmaConfView & BTxNOIE) 
		Print("\r               BDMA Tx Not Owner           +") ; 
	BdmaSetValue = (BdmaConfView & 0x3800) >> 11 ;
		Print("\r + - BDMA Tx to MAC Tx Start Level : %d/8   +",\
					BdmaSetValue);

	// ------------ BDMA Rx Control Register --------------
	BdmaConfView = BDMARXCON ;
	Print("\r +=========================================+");
	Print("\r + BDMARXCON : BDMA Rx Control Register    +");
	Print("\r +-----------------------------------------+");
	BdmaSetValue = BdmaConfView & 0x1F ;
	if (BdmaConfView & BRxEn) 
		Print("\r + - BDMA Rx Enabled                       +") ;
	Print("\r + - BDMA Rx Burst Size : %d Byte          +",(BdmaSetValue+1)) ;

	if (BdmaConfView & BRxSTSKO)
		Print("\r + - BDMA Rx STOP, if Descriptor Not Owner +") ;
	else
		Print("\r + - BDMA Rx SKIP, if Descriptor Not Owner +") ;
	if (BdmaConfView & BRxMAINC)
		Print("\r + - BDMA Rx Increment Memory Address      +") ;
	else
		Print("\r + - BDMA Rx Decrement Memory Address      +") ;
	if (BdmaConfView & BRxLittle) 
		Print("\r + - BDMA Rx Little Endian                 +") ;
	else 
		Print("\r + - BDMA Rx Big Endian                    +") ;

		Print("\r + - BDMA Rx Interrupt :                   +") ;
	if (BdmaConfView & BRxDIE) 
		Print("\r +             Every Received Frame        +") ;
	if (BdmaConfView & BRxNLIE) 
		Print("\r +             NULL List                   +") ;
	if (BdmaConfView & BRxNOIE) 
		Print("\r +             Rx Not Owner                +") ;
	if (BdmaConfView & BRxMSOIE) 
		Print("\r +             Max Size over               +") ;
	if (BdmaConfView & RxEmpty) 
		Print("\r +             Rx Buffer Empty             +") ; 
	if (BdmaConfView & BRxEarly) 
		Print("\r +             Early notify                +") ; 

	BdmaSetValue = (BdmaConfView & 0x3000) >> 12 ;
		Print("\r + - Rx Word Allignment : %d Invalid Byte   +",\
				BdmaSetValue) ;

	// ------------ CAM Control Register --------------
	Print("\r +=========================================+");
	Print("\r + CAMCON : CAM Control Register           +");
	Print("\r +-----------------------------------------+");
	BdmaConfView = CAMCON ;
	if (BdmaConfView & StationAcc)
		Print("\r + - Accept Unicast station address packet +") ; 
	if (BdmaConfView & GroupAcc)
		Print("\r + - Accept Multicast-group address packet +") ; 
	if (BdmaConfView & BroadAcc)
		Print("\r + - Accept Broadcast station address      +") ;
	if (BdmaConfView & NegCAM)
		Print("\r + - Accept Negative CAM recognizes        +") ;
	if (BdmaConfView & CompEn)
		Print("\r + - CAM Compare Enable mode               +") ;


	// ------------ SNDS PHY Configuration --------------
	Print("\r +=========================================+");
	Print("\r + SNDS PHY Configuration                  +");
	Print("\r +-----------------------------------------+");
	PhyStatus = MiiStationRead(PHY_STATUS_REG, PHYHWADDR) ;
	if ( PhyStatus & (1 << 5) ) 
		Print("\r + - Auto-Negotiation Completed            +") ;
	if ( PhyStatus & (1 << 2) ) 
		Print("\r + - Link is Valid                         +") ;
	PhyStatus = MiiStationRead(PHY_ECNTL_REG2, PHYHWADDR) ;
	if ( PhyStatus & (1 << 15) ) 
		Print("\r + - Repeater Mode is Selected             +") ;
	else
		Print("\r + - NODE Mode is Selected                 +") ;
	Print("\r +=========================================+");
}


/*
 * Function : ChangeMacAndBdmaConfiguration
 * Description : Configure MAC and BDMAC
 */
void ChangeMacAndBdmaConfiguration(void)
{
	char ChangeConfYesOrNo ;
	char ChangeValue ;
	U32  SettingValue ;

	// Configure MAC Tx/Rx Control Register
	Print("\n >> Configure MAC Tx/Rx (Y/N) ? ") ;
	ChangeConfYesOrNo = get_byte() ;

	if ( ( ChangeConfYesOrNo == 'Y' ) || ( ChangeConfYesOrNo == 'y' ) )
	{

		// MAC Global Control Register Config
		Print("\n((( MAC Global Control Register Setup )))") ;
		Print("\r$$ Support Full Duplex(Y/N) ? ") ;
		ChangeValue = get_byte() ;
		if ( (ChangeValue == 'Y') || (ChangeValue == 'y') )
			gMacCon = FullDup  ;

⌨️ 快捷键说明

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