mac.c
来自「三星mcu S3C4510B评估板的原码」· C语言 代码 · 共 1,212 行 · 第 1/3 页
C
1,212 行
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* source\mac.c 1.0 */
/* */
/* DESCRIPTION */
/* */
/* DIAGNOSTIC CODE for S3C4510B0 */
/* */
/* */
/* DATA STRUCTURES */
/* */
/* FUNCTIONS : MAC test */
/* */
/* DEPENDENCIES */
/* */
/* */
/* NAME: Nicolas Park */
/* The last Modification date: 18-April-2002 */
/* REMARKS: Created initial version 1.0 */
/* */
/* Copyright (C) 2002 AIJISYSTEM CO.,LTD */
/*************************************************************************/
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "s3c4510b0.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("\n# MAC Block Diagonistic Program #\r") ;
Print("\n#####################################################\r") ;
Print("\n# Capture & Show Ethernet Frame - [C] #\r") ;
Print("\n# MAC Loopback Test - [L] #\r") ;
Print("\n# Transfer Ethernet Frame - [T] #\r") ;
Print("\n# Receive Ethernet Frame - [R] #\r") ;
Print("\n# Other MAC Function Test - [O] #\r") ;
Print("\n# Change & View MAC Configuration - [V] #\r") ;
Print("\n# Quit Ethernet Test - [Q] #\r") ;
Print("\n#####################################################\r") ;
Print("\n\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("\n\nInvalid Test Item Selected") ;
break ;
}
if ( (TestItemSel != 'Q') && (TestItemSel != 'q') )
{
MacInitialize() ; // Reinitialize MAC/BDMA for Normal
// Operation
Print("\n\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("\n# MAC LoopBack Test #\r") ;
Print("\n#####################################################\r") ;
Print("\n# MAC Internal LoopBackTest - [I] #\r") ;
Print("\n# MAC - PHY LoopBackTest(Without Collision) - [L] #\r") ;
Print("\n# MAC - PHY LoopBackTest(WithCollision) - [C] #\r") ;
Print("\n# Physical Ethernet LoopBackTest - [E] #\r") ;
Print("\n# Polling LoopBackTest - [P] #\r") ;
Print("\n# All LoopBackTest(Without Physical LoopBack) - [A] #\r") ;
Print("\n# Quit MAC LoopBack Test - [Q] #\r") ;
Print("\n#####################################################\r") ;
Print("\n\rSelect Test Item : ") ; TestItemSel = get_byte() ;
Print("\n\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\n ++++ Iteration count : %d", i+1);
MacInternalLoopBack();
}
break ;
case 'L' : case 'l' :
for(i=0;i<lcnt;i++) {
Print("\n\n ++++ Iteration count : %d", i+1);
PhyNoColLoopBack();
}
break ;
case 'C' : case 'c' :
for(i=0;i<lcnt;i++) {
Print("\n\n ++++ Iteration count : %d", i+1);
PhyColLoopBack();
}
break ;
case 'E' : case 'e' :
for(i=0;i<lcnt;i++) {
Print("\n\n ++++ Iteration count : %d", i+1);
InterruptLoopBackTest() ;
}
break ;
case 'P' : case 'p' :
for(i=0;i<lcnt;i++) {
Print("\n\n ++++ Iteration count : %d", i+1);
MacPollLoopBack();
}
break ;
case 'A' : case 'a' :
for(i=0;i<lcnt;i++) {
Print("\n\n ++++ Iteration count : %d", i+1);
MacAllLoopBack();
}
break ;
case 'Q' : case 'q' : break ;
default : Print("\n\nInvalid Test Item Selected") ;
break ;
}
ReadErrReport() ;
ClearErrReport() ;
if ( (TestItemSel != 'Q') && (TestItemSel != 'q') )
{
Print("\n\nPress any key to Continue") ;
get_byte() ;
}
} while ( (TestItemSel != 'Q') && (TestItemSel != 'q') ) ;
}
/*
* Function : void PhyNoColLoopBack(void)
* Description : Loopback Test by PHY without collision
*/
void PhyNoColLoopBack(void)
{
MiiStationWrite(PHY_CNTL_REG, PHYHWADDR, PHY_FULLDUPLEX | \
DR_100MB | ENABLE_LOOPBACK) ;
//ENABLE_LOOPBACK) ;
Print("\n\n >>> MAC - PHY LoopBackTest(Without Collision) <<<") ;
InterruptLoopBackTest() ;
ResetPhyChip() ;
}
/*
* 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) ;
Print("\n\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\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("\n# Transfer MAC Frame #\r") ;
Print("\n#####################################################\r") ;
Print("\n# Transfer Single MAC Frame - [S] #\r") ;
Print("\n# Transfer Multiple MAC Frame - [M] #\r") ;
Print("\n# Transfer Control Frame - [C] #\r") ;
Print("\n# Quit MAC Transfer Test - [Q] #\r") ;
Print("\n#####################################################\r") ;
Print("\n\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("\n\nInvalid Test Item Selected") ;
break ;
}
ReadErrReport() ;
ClearErrReport() ;
if ( (TestItemSel != 'Q') && (TestItemSel != 'q') )
{
Print("\n\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("\n\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\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("\n# Other MAC Function Test #\r") ;
Print("\n#####################################################\r") ;
Print("\n# BDMA Buffer Test - [B] #\r") ;
Print("\n# MAC Rx FIFO - [R] #\r") ;
Print("\n# MAC Tx Halt Request Test - [H] #\r") ;
Print("\n# MDC On Test - [M] #\r") ;
Print("\n# MDC Off Test - [O] #\r") ;
Print("\n# PHY MII Station Management Test - [P] #\r") ;
Print("\n# Quit Other MAC Function Test - [Q] #\r") ;
Print("\n#####################################################\r") ;
Print("\n\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("\n\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("\n\r $$ Current MDC Clock Rate is %x (%x)",(STACON>>13) & 0x7,STACON) ;
Print("\n\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("\n\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\n >>>>> PHY Station Management Reg Read <<<<") ;
RdValue = MiiStationRead( PHY_CNTL_REG, PHYHWADDR) ;
Print("\n\r1. CNTL REG (0x3000) : %04x ",RdValue) ;
RdValue = MiiStationRead( PHY_STATUS_REG, PHYHWADDR) ;
Print("\n\r2. STATUS REG (0x7809) : %04x ",RdValue) ;
RdValue = MiiStationRead( PHY_ID_REG1, PHYHWADDR) ;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?