📄 mac_test.c
字号:
////////////////////////////////////////////////////////////////////////////
//
// Program to check
// 1. The MAC address has been programmed.
// 2. Program the MAC address
//
//
// - PRD
//
#include <stdio.h>
#include <cdefBF537.h>
#include <ccblkfn.h>
#include "adi_m29w320.h" // flash-M29W320 includes
#include "util.h" // library struct includes
#include "Errors.h" // error type includes
//////////////////////////////////////////////////////////////////////////////
//
// COMMON DEFINES
//
//////////////////////////////////////////////////////////////////////////////
#define FLASH_START_ADDR 0x20000000
#define MAC_ADDRESS_START 0x003f0000
#define MAC_ADDRESS_SECTOR 66
unsigned char g_ucMAC[6] = {0x00,0x00,0x00,0x00,0x00,0x00};
//////////////////////////////////////////////////////////////////////////////
//
// function prototypes
//
//////////////////////////////////////////////////////////////////////////////
int TEST_MAC(void);
int PROGRAM_MAC(void);
//////////////////////////////////////////////////////////////////////////////
//
// stand alone test jig
//
//////////////////////////////////////////////////////////////////////////////
#ifdef _STANDALONE_ // use this to run standalone tests
static u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * 2)];
static ADI_INT_CRITICAL_REGION_DATA CriticalRegionData; // storage for critical region
ADI_DEV_DEVICE_HANDLE DevHandleM29W320;
int main(void)
{
int bPassed = 0;
unsigned int uiResult;
u32 ResponseCount; // response count
u32 SecondaryCount; // secondary count
ADI_DEV_MANAGER_HANDLE DeviceManagerHandle; // DevMgr handle
uiResult = adi_dev_Init( DevMgrData, // ptr to memory for use by DevMgr
sizeof(DevMgrData), // size of memory for use by DevMgr
&ResponseCount, // returns number of devices DevMgr can support
&DeviceManagerHandle, // ptr to DevMgr handle
&CriticalRegionData); // ptr to critical region info
// open the M29W320
uiResult = adi_dev_Open( DeviceManagerHandle, // DevMgr handle
&ADIM29W320EntryPoint, // pdd entry point
0, // device instance
NULL, // client handle callback identifier
&DevHandleM29W320, // DevMgr handle for this device
ADI_DEV_DIRECTION_BIDIRECTIONAL,// data direction for this device
NULL, // handle to DmaMgr for this device
NULL, // handle to deferred callback service
NULL); // client's callback function
bPassed = PROGRAM_MAC();
if( bPassed )
{
bPassed = TEST_MAC();
if( bPassed )
{
printf("Passed; MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", g_ucMAC[0],g_ucMAC[1],g_ucMAC[2],g_ucMAC[3],g_ucMAC[4],g_ucMAC[5] );
// close the device
uiResult = adi_dev_Close(DevHandleM29W320);
return 1;
}
}
fprintf(stderr, "Failed to program MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n", g_ucMAC[0],g_ucMAC[1],g_ucMAC[2],g_ucMAC[3],g_ucMAC[4],g_ucMAC[5] );
// close the device
uiResult = adi_dev_Close(DevHandleM29W320);
return 0;
}
#endif //#ifdef _STANDALONE_
int CheckMAC_ADI( const unsigned char *pucAddr )
{
int iPassed = 1;
int i;
#ifdef ADI_MAC
const unsigned char g_ucMAC_TEST_MASK[6] = {0x00, 0xE0, 0x22,0xFF, 0xFF,0xFF };
// check the first 3 bytes/24 bit of the MAC address indentify the manufacturer.
for( i = 0; i < 3; i++ )
{
if( g_ucMAC_TEST_MASK[i] == pucAddr[i] )
{
iPassed = 1;
}
else
{
iPassed = 0;
break;
}
}
#endif
return iPassed;
}
//--------------------------------------------------------------------------//
// Function: Init_SDRAM //
// //
// Parameters: None //
// //
// Return: None //
// //
// Description: This function configures the SDRAM controller
//--------------------------------------------------------------------------//
int TEST_MAC(void)
{
int iResult;
unsigned int iPassed = 0;
int i;
ADI_DEV_1D_BUFFER FlashBuff1D; // write buffer pointer
unsigned char ucVal[6] = {0,0,0,0,0,0};
COMMAND_STRUCT pCmdBuffer;
// setup the external bus control
*pEBIU_AMGCTL = 0xFF;
for(i = 0; i < 2; i++)
{
// initialize our buffer
FlashBuff1D.Data = &ucVal[(i*2)];
FlashBuff1D.pNext = NULL;
unsigned long ulOffset = (FLASH_START_ADDR + MAC_ADDRESS_START) + (i*2);
FlashBuff1D.pAdditionalInfo = (void *)&ulOffset;
// read from the flash
iResult = adi_dev_Read(DevHandleM29W320, ADI_DEV_1D, (ADI_DEV_BUFFER *)&FlashBuff1D);
if(ADI_DEV_RESULT_SUCCESS != iResult)
{
iPassed = 0;
break;
}
}
return CheckMAC_ADI(ucVal);
}
//////////////////////////////////////////////////////////////////////////////
// int TEST_SDRAM(void)
//
// PURPOSE: Test the SDRAM
//////////////////////////////////////////////////////////////////////////////
int PROGRAM_MAC(void)
{
unsigned int uiPassed = 0;
int iResult;
int iMAC0 = 0x00;
int iMAC1 = 0xE0;
int iMAC2 = 0x22;
int iMAC3 = 0x00;
int iMAC4 = 0x00;
int iMAC5 = 0x00;
char s[81];
#ifdef ADI_MAC
iResult = scanf( "%02x, %02x, %02x", &iMAC3,&iMAC4,&iMAC5 );
fflush( stdin);
if( 3 == iResult )
#else
iResult = scanf( "%02x, %02x, %02x, %02x, %02x, %02x", &iMAC0,&iMAC1,&iMAC2,&iMAC3,&iMAC4,&iMAC5 );
fflush( stdin);
if( 6 == iResult )
#endif
{
// package the MAC into a byte array
g_ucMAC[0] = iMAC0;
g_ucMAC[1] = iMAC1;
g_ucMAC[2] = iMAC2;
g_ucMAC[3] = iMAC3;
g_ucMAC[4] = iMAC4;
g_ucMAC[5] = iMAC5;
// double check that the address entered is an ADI address
if( CheckMAC_ADI(g_ucMAC) )
{
// program the mac address.
int i;
ADI_DEV_1D_BUFFER FlashBuff1D; // write buffer pointer
COMMAND_STRUCT pCmdBuffer;
// setup the external bus control
*pEBIU_AMGCTL = 0xFF;
pCmdBuffer.SEraseSect.nSectorNum = MAC_ADDRESS_SECTOR;
// Erase the flash
iResult = adi_dev_Control(DevHandleM29W320, CNTRL_ERASE_SECT, &pCmdBuffer );
if(ADI_DEV_RESULT_SUCCESS == iResult)
{
uiPassed = 1; // assume process will pass
for(i = 0; i < 3; i++)
{
// initialize our buffer
FlashBuff1D.Data = &g_ucMAC[(i*2)];
unsigned long ulOffset = MAC_ADDRESS_START + (i*2);
FlashBuff1D.pAdditionalInfo =(void *)&ulOffset;
FlashBuff1D.pNext = NULL;
// write to the flash
iResult = adi_dev_Write(DevHandleM29W320, ADI_DEV_1D, (ADI_DEV_BUFFER *)&FlashBuff1D);
if(ADI_DEV_RESULT_SUCCESS != iResult)
{
uiPassed = 0;
break;
}
}
}
}
}
return uiPassed;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -