📄 ether.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// 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-2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//------------------------------------------------------------------------------
//
// File: ether.c
//
// EBOOT ethernet routines.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include "bsp.h"
#include "loader.h"
//------------------------------------------------------------------------------
// External Variables
extern PBSP_ARGS g_pBSPARGS; // From debug.c
extern BOOL FECInit(UINT8 *pAddress, UINT32 offset, UINT16 mac[3]);
extern UINT16 FECSendFrame(UINT8 *pData, UINT32 length);
extern UINT16 FECGetFrame(UINT8 *pData, UINT16 *pLength);
extern BOOL FECInitDMABuffer(UINT32 address, UINT32 size);
extern DWORD OALKitlGetFECDmaBuffer(void);
//------------------------------------------------------------------------------
// Global Variables
//
// 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;
#ifdef FORCE_KITL_ETHFEC
OAL_KITLETH_INIT_DMABUFFER pfnOALKitlethInitDMABuffer;
#endif
//------------------------------------------------------------------------------
// Local Variables
static PCSP_GPT_REGS g_pGPT;
//------------------------------------------------------------------------------
//
// Function: InitEthDevice
//
// Function Initializes the Ethernet device function pointers.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void InitEthDevice(void)
{
#ifdef FORCE_KITL_ETHFEC
// Use the FEC Ethernet controller for download.
pfnOALKitlethInit = FECInit;
pfnOALKitlethSendFrame = FECSendFrame;
pfnOALKitlethGetFrame = FECGetFrame;
pfnOALKitlethInitDMABuffer = FECInitDMABuffer;
#else
// Use the CS8900A Ethernet controller for download.
pfnOALKitlethInit = CS8900AInit;
pfnOALKitlethSendFrame = CS8900ASendFrame;
pfnOALKitlethGetFrame = CS8900AGetFrame;
#endif
}
//------------------------------------------------------------------------------
//
// Function: OEMEthHardwareInit
//
// This function Initializes the Ethernet device to be used for download.
//
// Parameters:
// pMyAddr
// [in] Ptr to the ethernet address.
//
// Returns:
// Returns TRUE if successful, otherwise returns FALSE.
//
//------------------------------------------------------------------------------
BOOL OEMEthHardwareInit(EDBG_ADDR *pMyAddr)
{
PBYTE pBaseIOAddress = NULL;
UINT32 MemoryBase = 0;
UINT32 DMABuffer= 0;
OALMSG(OAL_FUNC, (TEXT("InitEthDevice+\r\n")));
// Use the MAC address programmed into flash by the user.
memcpy(g_pBSPARGS->kitl.mac, pMyAddr->wMAC, 6);
pBaseIOAddress = (PBYTE)OALPAtoVA(g_pBSPARGS->kitl.devLoc.LogicalLoc, FALSE);
OALMSG(OAL_FUNC, (TEXT("IOBase 0x%x\r\n"), g_pBSPARGS->kitl.devLoc.LogicalLoc));
// Get uncached virtual addresses for timer used in OALGetTickCount
g_pGPT = (PCSP_GPT_REGS) OALPAtoUA(CSP_BASE_REG_PA_GPT1);
if (g_pGPT == NULL)
{
OALMSG(OAL_ERROR, (L"ERROR: OEMEthHardwareInit: GPT null pointer!\r\n"));
EdbgOutputDebugString("!!!ERROR: OEMEthHardwareInit: GPT null pointer!\r\n");
return FALSE;
}
#ifdef FORCE_KITL_ETHFEC
//Initialize FEC DMA buffer
DMABuffer = (UINT32)OALPAtoVA(OALKitlGetFECDmaBuffer(), FALSE );
if(! pfnOALKitlethInitDMABuffer(DMABuffer, 1024 * 16))
{
OALMSG(OAL_ERROR, (TEXT("ERROR: OEMEthHardwareInit: Failed to FEC DMA Buffer.\r\n")));
return FALSE;
}
MemoryBase = 0;
#else
MemoryBase = (UINT32)OALPAtoVA(BSP_BASE_REG_PA_CS8900A_MEMBASE, FALSE);
OALMSG(OAL_FUNC, (TEXT("MemoryBase 0x%x\r\n"), BSP_BASE_REG_PA_CS8900A_MEMBASE));
#endif
// Initialize the Ethernet controller.
OALMSG(OAL_INFO, (TEXT("INFO: Initialize Ethernet controller.\r\n")));
if (!pfnOALKitlethInit((PBYTE)pBaseIOAddress, MemoryBase, g_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 (!g_pBSPARGS->kitl.mac[0] && !g_pBSPARGS->kitl.mac[1] && !g_pBSPARGS->kitl.mac[2]) {
OALMSG(OAL_ERROR, (TEXT("ERROR: OEMEthHardwareInit: Invalid MAC address.\r\n")));
return FALSE;
}
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: OEMEthGetSecs
//
// This function returns a free-running seconds count.
//
// Parameters:
// None.
//
// Returns:
// 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: OALGetTickCount
//
// This function is called by some KITL libraries to obtain relative time
// since device boot. It is mostly used to implement timeout in network
// protocol.
//
//------------------------------------------------------------------------------
UINT32 OALGetTickCount()
{
UINT32 ticks;
// Calculate GPT ticks since we started the system
ticks = INREG32(&g_pGPT->TCN);
// Return the number of 1ms ticks that have elapsed
return ticks / OEM_TICKS_1MS;
}
//------------------------------------------------------------------------------
//
// 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/out] Length of data in the receiving buffer.
//
// Returns:
// Returns TRUE if successful, otherwise returns FALSE.
//
//------------------------------------------------------------------------------
BOOL OEMEthGetFrame(BYTE *pData, UINT16 *pwLength)
{
return(pfnOALKitlethGetFrame(pData, pwLength));
}
//------------------------------------------------------------------------------
//
// Function: OEMEthSendFrame
//
// This function sends a frame.
//
// Parameters:
// pData
// [in] Ptr to the send buffer.
//
// pwLength
// [in] Length of data to be sent.
//
// Returns:
// Returns TRUE if successful, otherwise returns FALSE.
//
//------------------------------------------------------------------------------
BOOL OEMEthSendFrame(BYTE *pData, DWORD dwLength)
{
UINT32 retries = 0;
while (retries++ < 4) {
// SendFrame will return 0 if sending is success
if (!pfnOALKitlethSendFrame(pData, dwLength))
return TRUE;
else
OALMSG(OAL_ERROR, (TEXT("OEMEthSendFrame failure, retry %u\n"), retries));
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -