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

📄 ether.c

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 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-2007, 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 Functions
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 VOID FECEnableInts();
extern VOID FECDisableInts();
extern BOOL FECInitDMABuffer(UINT32 address, UINT32 size);

//-----------------------------------------------------------------------------
// External Variables
extern BSP_ARGS *g_pBSPArgs;


//-----------------------------------------------------------------------------
// Defines


//-----------------------------------------------------------------------------
// Types


//-----------------------------------------------------------------------------
// Global Variables

// Function pointers to the support library functions of the currently installed debug ethernet controller.
//
PFN_EDBG_INIT                     pfnEDbgInit;
PFN_EDBG_GET_FRAME                pfnEDbgGetFrame;
PFN_EDBG_SEND_FRAME               pfnEDbgSendFrame;
PFN_EDBG_ENABLE_INTS              pfnEDbgEnableInts;
PFN_EDBG_DISABLE_INTS             pfnEDbgDisableInts;
PFN_EDBG_GET_PENDING_INTS         pfnEDbgGetPendingInts;
PFN_EDBG_READ_EEPROM              pfnEDbgReadEEPROM;
PFN_EDBG_WRITE_EEPROM             pfnEDbgWriteEEPROM;
PFN_EDBG_SET_OPTIONS              pfnEDbgSetOptions;
PFN_EDBG_INIT_DMABUFFER           pfnEDbgInitDMABuffer;


//-----------------------------------------------------------------------------
// Local Variables


//-----------------------------------------------------------------------------
//
// Function: InitSpecifiedEthDevice
//
// Initializes the specified Ethernet device to be used for download and 
// KITL services.
//
// Parameters:
//      pKITLArgs
//          [in/out] Points to the KITL argument structure.
//
//      EthDevice
//          [in] Ethernet device to be initialized.
//
// Returns:
//      Returns Ethernet adapter type intialized on success, otherwise 
//      returns -1.
//
//-----------------------------------------------------------------------------
UINT32 InitSpecifiedEthDevice(OAL_KITL_ARGS *pKITLArgs, ETH_DEVICE_TYPE EthDevice)
{
    UINT32 rc = -1;
    
    switch (EthDevice)
    {
    case ETH_DEVICE_CS8900A:
        if (CS8900AInit((PBYTE) OALPAtoUA(BSP_BASE_REG_PA_CS8900A_IOBASE), 0, pKITLArgs->mac))
        {
            pfnEDbgInit         = (PFN_EDBG_INIT) CS8900AInit;
            pfnEDbgGetFrame     = (PFN_EDBG_GET_FRAME) CS8900AGetFrame;
            pfnEDbgSendFrame    = (PFN_EDBG_SEND_FRAME) CS8900ASendFrame;
            pfnEDbgEnableInts   = (PFN_EDBG_ENABLE_INTS) CS8900AEnableInts;     
            pfnEDbgDisableInts  = (PFN_EDBG_DISABLE_INTS)CS8900ADisableInts;    
            
            // Save the device location information for later use.
            //
            pKITLArgs->devLoc.IfcType     = Internal;
            pKITLArgs->devLoc.BusNumber   = 0;
            pKITLArgs->devLoc.PhysicalLoc = (PVOID)(BSP_BASE_REG_PA_CS8900A_IOBASE);
            pKITLArgs->devLoc.LogicalLoc  = (DWORD)pKITLArgs->devLoc.PhysicalLoc;

            KITLOutputDebugString("INFO: CS8900A Ethernet controller initialized.\r\n");
            rc = EDBG_ADAPTER_OEM;
        }
        else
        {
            KITLOutputDebugString("ERROR: Failed to initialize CS8900A Ethernet controller.\n");
        }
        break;

    case ETH_DEVICE_FEC:
        // Initialize DMA buffer for FEC
        if (!FECInitDMABuffer(IMAGE_SHARE_FEC_RAM_UA_START, IMAGE_SHARE_FEC_RAM_SIZE))
        {
            KITLOutputDebugString("ERROR: Failed to initialize Fast Ethernet DMA buffer.\n");
            break;
        }

        // Initialize FEC module
        if (FECInit((PBYTE) OALPAtoUA(CSP_BASE_REG_PA_FEC), 0, pKITLArgs->mac))
        {
            pfnEDbgInit         = (PFN_EDBG_INIT) FECInit;
            pfnEDbgGetFrame     = (PFN_EDBG_GET_FRAME) FECGetFrame;
            pfnEDbgSendFrame    = (PFN_EDBG_SEND_FRAME) FECSendFrame;
            pfnEDbgEnableInts   = (PFN_EDBG_ENABLE_INTS) FECEnableInts;
            pfnEDbgDisableInts  = (PFN_EDBG_DISABLE_INTS) FECDisableInts;
            pfnEDbgInitDMABuffer = (PFN_EDBG_INIT_DMABUFFER) FECInitDMABuffer;
            
            // Save the device location information for later use.
            //
            pKITLArgs->devLoc.IfcType     = Internal;
            pKITLArgs->devLoc.BusNumber   = 0;
            pKITLArgs->devLoc.PhysicalLoc = (PVOID)(CSP_BASE_REG_PA_FEC);
            pKITLArgs->devLoc.LogicalLoc  = (DWORD)pKITLArgs->devLoc.PhysicalLoc;

            KITLOutputDebugString("INFO: Fast Ethernet controller initialized.\r\n");
            rc = EDBG_ADAPTER_OEM;
        }
        else
        {
            KITLOutputDebugString("ERROR: Failed to initialize Fast Ethernet controller.\n");
        }
        break;

    default:
        KITLOutputDebugString("ERROR: Invalid Ethernet device.\n");
    }

    return rc;
}


//-----------------------------------------------------------------------------
//
// Function: OEMEthGetFrame
//
// Reads data from the Ethernet device.
//
// 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(PUCHAR pData, PUSHORT pwLength)
{
    return(pfnEDbgGetFrame(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(PUCHAR pData, DWORD dwLength)
{
    BYTE Retries = 0;

    while (Retries++ < 4)
    {
        if (!pfnEDbgSendFrame(pData, dwLength))
            return(TRUE);

        KITLOutputDebugString("INFO: OEMEthSendFrame: retrying send (%u)\r\n", Retries);
    }

    return(FALSE);
}


⌨️ 快捷键说明

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