📄 ether.c
字号:
//-----------------------------------------------------------------------------
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on
// your install media.
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// FREESCALE SEMICONDUCTOR, INC.
//
//-----------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// File: ether.c
//
// EBOOT ethernet routines
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include "bsp.h"
#include "loader.h"
// Function pointers to the support library functions of the
// currently installed debug ethernet controller.
//
OAL_KITLETH_INIT pfnOALKitlethInit;
OAL_KITLETH_SEND_FRAME pfnOALKitlethSendFrame;
OAL_KITLETH_GET_FRAME pfnOALKitlethGetFrame;
//-----------------------------------------------------------------------------
//
// Function: InitEthDevice
//
// Function Initializes the Ethernet device function pointers.
//
// Parameters:
//
// Returns:
//
//-----------------------------------------------------------------------------
void InitEthDevice(void)
{
// Use the CS8900A Ethernet controller for download.
//
pfnOALKitlethInit = CS8900AInit;
pfnOALKitlethSendFrame = CS8900ASendFrame;
pfnOALKitlethGetFrame = CS8900AGetFrame;
}
//-----------------------------------------------------------------------------
//
// Function: OEMEthHardwareInit
//
// Function Initializes the Ethernet device to be used for download.
//
// Parameters:
// pBSPArgs
// [in] Ptr to the global BSP_ARGS structure.
//
// pMyAddr
// [in] Ptr to the ethernet address.
//
// Returns:
// FALSE on failure
//
//-----------------------------------------------------------------------------
BOOL OEMEthHardwareInit(BSP_ARGS *pBSPArgs, EDBG_ADDR *pMyAddr)
{
PBYTE pBaseIOAddress = NULL;
UINT32 MemoryBase = 0;
OALMSG(OAL_FUNC, (TEXT("InitEthDevice+\r\n")));
// Use the MAC address programmed into flash by the user.
//
memcpy(pBSPArgs->kitl.mac, pMyAddr->wMAC, 6);
pBaseIOAddress = (PBYTE)OALPAtoVA(pBSPArgs->kitl.devLoc.LogicalLoc, FALSE);
MemoryBase = (UINT32)OALPAtoVA(BSP_BASE_REG_PA_CS8900A_MEMBASE, FALSE);
OALMSG(OAL_FUNC, (TEXT("IOBase 0x%x\r\n"), pBSPArgs->kitl.devLoc.LogicalLoc));
OALMSG(OAL_FUNC, (TEXT("MemoryBase 0x%x\r\n"), BSP_BASE_REG_PA_CS8900A_MEMBASE));
// Initialize the Ethernet controller.
//
OALMSG(OAL_INFO, (TEXT("INFO: initialize Ethernet controller.\r\n")));
if (!pfnOALKitlethInit((PBYTE)pBaseIOAddress, MemoryBase, pBSPArgs->kitl.mac))
{
OALMSG(OAL_ERROR, (TEXT("ERROR: OEMEthHardwareInit: Failed to initialize Ethernet controller.\r\n")));
return FALSE;
}
// Make sure MAC address has been programmed.
//
if (!pBSPArgs->kitl.mac[0] && !pBSPArgs->kitl.mac[1] && !pBSPArgs->kitl.mac[2])
{
OALMSG(OAL_ERROR, (TEXT("ERROR: OEMEthHardwareInit: Invalid MAC address.\r\n")));
return FALSE;
}
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: OEMEthGetSecs
//
// Function returns a free-running seconds count.
//
// Parameters:
//
// Returns:
// DWORD dwSeconds - the count of seconds
//
//-----------------------------------------------------------------------------
DWORD OEMEthGetSecs(void)
{
SYSTEMTIME st;
OEMGetRealTime( &st );
return ((60UL * (60UL * (24UL * (31UL * st.wMonth + st.wDay) + st.wHour) + st.wMinute)) + st.wSecond);
}
//-----------------------------------------------------------------------------
//
// Function: OEMEthGetFrame
//
// Function checks if a frame has been received, and if so copy it to buffer.
//
// Parameters:
// pData
// [out] Ptr to the receive buffer.
//
// pwLength
// [in] Length of data in the receiving buffer.
//
// Returns:
// FALSE if no frame has been received
//
//-----------------------------------------------------------------------------
BOOL OEMEthGetFrame(BYTE *pData, UINT16 *pwLength)
{
return(pfnOALKitlethGetFrame(pData, pwLength));
}
//-----------------------------------------------------------------------------
//
// Function: OEMEthGetFrame
//
// Function checks if a frame has been received, and if so copy it to buffer.
//
// Parameters:
// pData
// [in] Ptr to the send buffer.
//
// pwLength
// [in] Length of data to be sent.
//
// Returns:
// FALSE on failure
//
//-----------------------------------------------------------------------------
BOOL OEMEthSendFrame(BYTE *pData, DWORD dwLength)
{
int retries = 0;
while (retries++ < 4)
{
// SendFrame will return 0 if sending is success
if (!pfnOALKitlethSendFrame(pData, dwLength))
return TRUE;
else
EdbgOutputDebugString("!OEMEthSendFrame failure, retry %u\n",retries);
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -