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

📄 mac.c

📁 S3C4510B的例程
💻 C
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************/
/*                                                                       */
/* FILE NAME                                      VERSION                */
/*                                                                       */
/*      mac.c                      		 KS32C50100   : version 1.0 */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*             Main function of MAC Test Program                         */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*                                                                       */
/*************************************************************************/
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "snds.h"
#include "uart.h"
#include "pollio.h"
#include "isr.h"
#include "mac.h"
#include "timer.h"
#include "memory.h"


// Global Variable for MAC/BDMA and CAM Configuration
extern volatile U32 gMacCon ;
extern volatile U32 gMacTxCon ;
extern volatile U32 gMacRxCon ;
extern volatile U32 gBdmaTxCon ;
extern volatile U32 gBdmaRxCon ;
extern volatile U32 gCamCon ;
extern volatile U32 CntlPktTxDone ; // Control Packet Tx Done Flag
extern volatile U32 gCam0_Addr0 , gCam0_Addr1 ;
extern volatile U32 gCRxFDPtr ;

// variable for capture frame
volatile U32 gCapture_Addr0 , gCapture_Addr1 ;


/*
 * Function : void MacTest(void)
 * Description : Main function for MAC Block test
 */
void MacTest(void)
{
	char TestItemSel ;

	LanInitialize() ;

	do {

	Print("\n+---------------------------------------------------+\r") ;
	Print("|    >>>>> MAC Block Diagonistic Program <<<<<      |\r") ;
    Print("|          Rev 1.0 (by hbahn, 1998.04.17)           |\r") ;
	Print("+---------------------------------------------------+\r") ;
	Print("| Capture & Show Ethernet Frame               - [C] |\r") ;
	Print("| MAC Loopback Test                           - [L] |\r") ;
	Print("| Transfer Ethernet Frame                     - [T] |\r") ;
	Print("| Receive Ethernet Frame                      - [R] |\r") ;
	Print("| Other MAC Function Test                     - [O] |\r") ;
	Print("| Change & View MAC Configuration             - [V] |\r") ;
	Print("| Quit Ethernet Test                          - [Q] |\r") ;
	Print("+---------------------------------------------------+\r") ;

	Print("\rSelect Test Item : ") ; TestItemSel = get_byte() ;
	
	switch(TestItemSel)
	{
		case 'C' : case 'c' : CaptureAndShowFrame() ; break ;
		case 'L' : case 'l' : MacLoopBackTest() ; break ;
		case 'T' : case 't' : TxMacFrame() ; break ;
		case 'R' : case 'r' : RxMacFrame() ; break ;
		case 'O' : case 'o' : MacEtcTest() ; break ;
		case 'V' : case 'v' : MacConfig() ; break ;
		case 'Q' : case 'q' : break ;
		default : Print("\nInvalid Test Item Selected") ; 
				break ;
	}

	if ( (TestItemSel != 'Q') && (TestItemSel != 'q') )
		{
 		MacInitialize() ; // Reinitialize MAC/BDMA for Normal 
                            // Operation
		Print("\nPress any key to Continue MAC Test") ; 
		get_byte() ;
		}
	} while  ( (TestItemSel != 'Q') && (TestItemSel != 'q') ) ;
}


/*
 * Function : void MacLoopBackTest(void)
 * Description : MAC LoopBack Test
 */
void MacLoopBackTest(void)
{
	char TestItemSel ;
	int i,lcnt ;

	do {
	Print("\n+---------------------------------------------------+\r") ;
	Print("|          ***** MAC LoopBack Test *****            |\r") ;
    Print("|          Rev 1.0 (by hbahn, 1998.04.17)           |\r") ;
	Print("+---------------------------------------------------+\r") ;
	Print("| MAC Internal LoopBackTest                   - [I] |\r") ;
	Print("| MAC - PHY LoopBackTest(Without Collision)   - [L] |\r") ;
	Print("| MAC - PHY LoopBackTest(WithCollision)       - [C] |\r") ;
	Print("| Physical Ethernet LoopBackTest              - [E] |\r") ;
	Print("| Polling LoopBackTest                        - [P] |\r") ;
	Print("| All LoopBackTest(Without Physical LoopBack) - [A] |\r") ;
	Print("| Quit MAC LoopBack Test                      - [Q] |\r") ;
	Print("+---------------------------------------------------+\r") ;
	Print("\rSelect Test Item : ") ; TestItemSel = get_byte() ;

	Print("\n $$$ Enter Number of Loopback Test : ") ;
	lcnt = get_num() ;
	if (lcnt == 0 ) lcnt = 1 ;
	
	switch(TestItemSel)
	{
		case 'I' : case 'i' : 
			for(i=0;i<lcnt;i++) {
				Print("\n ++++ Iteration count : %d", i+1);
				MacInternalLoopBack(); 
			}
			break ;
		case 'L' : case 'l' : 
			for(i=0;i<lcnt;i++) {
				Print("\n ++++ Iteration count : %d", i+1);
				PhyNoColLoopBack(); 
			}
			break ;
		case 'C' : case 'c' : 
			for(i=0;i<lcnt;i++) {
				Print("\n ++++ Iteration count : %d", i+1);
				PhyColLoopBack(); 
			}
			break ;
		case 'E' : case 'e' : 
			for(i=0;i<lcnt;i++) {
				Print("\n ++++ Iteration count : %d", i+1);
				InterruptLoopBackTest() ;
			}
			break ;
		case 'P' : case 'p' : 
			for(i=0;i<lcnt;i++) {
				Print("\n ++++ Iteration count : %d", i+1);
				MacPollLoopBack(); 
			}
			break ;
		case 'A' : case 'a' : 
			for(i=0;i<lcnt;i++) {
				Print("\n ++++ Iteration count : %d", i+1);
				MacAllLoopBack(); 
			}
			break ;
		case 'Q' : case 'q' : break ;

		default : Print("\nInvalid Test Item Selected") ; 
				break ;
	}

	ReadErrReport() ;
	ClearErrReport() ;

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


/*
 * Function : void PhyNoColLoopBack(void)
 * Description : Loopback Test by PHY without collision
 */
int PhyNoColLoopBack(void)
{
	int result;

   	MiiStationWrite(PHY_CNTL_REG, PHYHWADDR, PHY_FULLDUPLEX | \
			DR_100MB | ENABLE_LOOPBACK) ;

	Print("\n >>> MAC - PHY LoopBackTest(Without Collision) <<<") ;
	result=InterruptLoopBackTest() ;

	ResetPhyChip() ;
	return result;
}

/*
 * Function : void PhyColLoopBack(void)
 * Description : Loopback Test by PHY without collision
 */
void PhyColLoopBack(void)
{
   	MiiStationWrite(PHY_CNTL_REG, PHYHWADDR, PHY_FULLDUPLEX | \
			DR_100MB | PHY_COL_TEST | ENABLE_LOOPBACK) ;
			//PHY_COL_TEST | ENABLE_LOOPBACK) ;
	//MiiStationWrite(PHY_CNTL_REG, PHYHWADDR, ENABLE_AN | RESTART_AN); 
	Print("\n >>> MAC - PHY LoopBackTest(With Collision) <<<") ;
	InterruptLoopBackTest() ;
	ResetPhyChip() ;
}

/*
 * Function : void MacPollLoopBack(void)
 * Description : MAC Polling LoopBack Test
 */
void MacPollLoopBack(void)
{
	int LoopCnt = 5 ;
	while( LoopCnt-- ) PollingLoopBackTest() ;
}

/*
 * Function : void MacAllLoopBack(void)
 * Description : MAC All LoopBack Test
 */
void MacAllLoopBack(void)
{
	Print("\n >>> All LoopBackTest(Without Physical LoopBack) <<<") ;
	MacInternalLoopBack() ;
	PhyNoColLoopBack() ;
	PhyColLoopBack() ;
}

/*
 * Function : void TxMacFrame(void)
 * Description : Transfer MAC Frame
 */
void TxMacFrame(void)
{
	char TestItemSel ;
	do {
	Print("\n+---------------------------------------------------+\r") ;
	Print("|          ***** Transfer MAC Frame *****           |\r") ;
        Print("|          Rev 1.0 (by hbahn,  1998.04.17)          |\r") ;
	Print("+---------------------------------------------------+\r") ;
	Print("| Transfer Single MAC Frame                   - [S] |\r") ;
	Print("| Transfer Multiple MAC Frame                 - [M] |\r") ;
	Print("| Transfer Control Frame                      - [C] |\r") ;
	Print("| Quit MAC Transfer Test                      - [Q] |\r") ;
	Print("+---------------------------------------------------+\r") ;
	Print("\rSelect Test Item : ") ; TestItemSel = get_byte() ;
	
	switch(TestItemSel)
	{
		case 'S' : case 's' : SingleTransfer(); break ;
		case 'M' : case 'm' : Eth_Multi_Transmit() ; break ;
		case 'C' : case 'c' : ControlFrameTransfer(); break ;
		case 'Q' : case 'q' : break ;
		default : Print("\nInvalid Test Item Selected") ; 
				break ;
	}

	ReadErrReport() ;
	ClearErrReport() ;

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

/*
 * Function : SingleTransfer
 * Description : Transfer a Frame Data to another Host
 */
void SingleTransfer(void) 
{
	char TransferPacket ;
	int i = 0 ;

	do 
	{
	Print("\r   $$ Select Transmit(T) or Quit(Q) ? ") ;
	TransferPacket = get_byte() ;
	if ( (TransferPacket == 'T') || (TransferPacket == 't') )
		Random_Pkt_Transmit(i++) ;
	} while ( (TransferPacket != 'Q') && (TransferPacket != 'q') ) ;
}



/*
 * Function : void RxMacFrame(void)
 * Description : Receive one MAC Frame if Destination address is mine
 */
void RxMacFrame(void)
{
	Timer0Stop() ; // stop timer, because Lan_WatchDog
	SysSetInterrupt(nBDMA_RX_INT, BdmaRxForSingleIsr) ;	

	Print("\n >>> Waiting For Frame Receive \r") ;
	while(get_byte() != 'q') ;

	SysSetInterrupt(nBDMA_RX_INT, BDMA_Rx_isr) ;	
        Timer0Start() ; // restart timer, for Lan_WatchDog

	ReadErrReport() ;
	ClearErrReport() ;
}

/*
 * Function : void MacEtcTest(void)
 * Description : Other MAC Function
 */
void MacEtcTest(void)
{
	char TestItemSel ;
	do {
	Print("\n+---------------------------------------------------+\r") ;
	Print("|        ***** Other MAC Function Test *****        |\r") ;
        Print("|           Rev 1.0 (by hbahn, 1998.04.17)          |\r") ;
	Print("+---------------------------------------------------+\r") ;
	Print("| BDMA Buffer Test                            - [B] |\r") ;
	Print("| MAC Rx FIFO                                 - [R] |\r") ;
	Print("| MAC Tx Halt Request Test                    - [H] |\r") ;
	Print("| MDC On Test                                 - [M] |\r") ;
	Print("| MDC Off Test                                - [O] |\r") ;
	Print("| PHY MII Station Management Test             - [P] |\r") ;
	Print("| Quit Other MAC Function Test                - [Q] |\r") ;
	Print("+---------------------------------------------------+\r") ;
	Print("\rSelect Test Item : ") ; TestItemSel = get_byte() ;
	
	switch(TestItemSel)
	{

		case 'B' : case 'b' : BdmaBufferTest(); break ;
		case 'R' : case 'r' : MacFifoTest(); break ;
		case 'H' : case 'h' : MacTxHaltReqTest(); break ;
		case 'M' : case 'm' : MDCOnTest(); break ;
		case 'O' : case 'o' : MDCOffTest(); break ;
		case 'P' : case 'p' : PhyStationRdWrTest(); break ;
		case 'Q' : case 'q' : break ;
		default : Print("\nInvalid Test Item Selected") ; 
				break ;
	}

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

/*
 * Function : MDCOnTest(void)
 * Description : Station Management Clock On
 */
void MDCOnTest(void)
{
	U32 MDCValue ;

	Print("\r $$ Current MDC Clock Rate is %x (%x)",(STACON>>13) & 0x7,STACON) ;
	Print("\r >>> Input MDC Clock Rate [ (Value+7) * SYSCLK ] : ") ;
	MDCValue = get_num() ;
	if (MDCValue == 0) MACCON &= ~MDCOFF ;
	else 
		{
		MACCON |= MDCOFF ;
		STACON |= ( MDCValue << 13 ) ;
		MACCON &= ~MDCOFF ;
		}
	Print("\r $$ MDC Clock Rate is %x (%x)", MDCValue, STACON) ;
}

/*
 * Function : MDCOffTest(void)
 * Description : Station Management Clock On
 */
void MDCOffTest(void)
{
	MACCON |= MDCOFF ;
	Print("\r MDC Offed") ;
}

/*
 * Function : void PhyStationRdWrTest(void)
 * Description : PHY Station Management Reg Read Write Test
 */
void PhyStationRdWrTest(void)
{
	U32 RdValue ;


	Print("\n >>>>> PHY Station Management Reg Read <<<<") ;

⌨️ 快捷键说明

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