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

📄 ether.c

📁 ebd9307开发板wince bsp源码,包括cs8900,lcd,nand,serial,touch,usb,gpio,wd等驱动
💻 C
字号:
//**********************************************************************
//                                                                      
// Filename: ether.c
//                                                                      
// Description: Boot loader ethernet functions.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus 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 
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved                       
//                                                                      
//**********************************************************************

//
// 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 EULA.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  Module Name:
//      ether.c
//
//  Abstract:
//
//  Functions:
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <halether.h>
#include <ceddk.h>
#include <ethdbg.h>
#include <memorymap.h>
#include <hwdefs.h>
#include <drv_glob.h>
#include <debugtimer.h>
#include <blcommon.h>
#include <cs8950sw.h>
#include <options.h>
#include <deviceinfo.h>
#include "ether.h"



typedef BOOL (*PFN_EDBG_INIT_DMABUF)(DWORD dwStartAddress, DWORD dwSize);

//
// Static variables.
//
static PFN_EDBG_INIT            pfnEDbgInit         = 0;
static PFN_EDBG_INIT_DMABUF     pfnEDbgInitDMA      = 0;
static PFN_EDBG_GET_FRAME       pfnEDbgGetFrame     = 0;
static PFN_EDBG_SEND_FRAME      pfnEDbgSendFrame    = 0;
static EDBG_ADDR                MyAddr              = {0, {0,0,0}, 0};



//****************************************************************************
// OEMEthGetFrame
//****************************************************************************
// pData -   OUT - Receives frame data
//
// pwLength  IN  - Length of Rx buffer
//           OUT - Number of bytes received
//
// return    TRUE  - Successful
//           FALSE - failure.
//
BOOL  OEMEthGetFrame
(
    BYTE *pData,       
    UINT16 *pwLength   
)                      
{
    if (pfnEDbgGetFrame)
        return(pfnEDbgGetFrame(pData, pwLength));

    return(FALSE);
}

//****************************************************************************
// OEMEthSendFrame
//****************************************************************************
//  pData       - IN - Data buffer
//  dwLength    - IN - Length of buffer
//
//  Return      - TRUE  successful
//                FALSE unsuccessful
//
BOOL OEMEthSendFrame
(
    BYTE *pData,     
    DWORD dwLength
)
{
    int retries = 0;

    // Let's be persistant here
    while (retries++ < 4) 
    {
        if (!pfnEDbgSendFrame(pData, dwLength))
        {
            return TRUE;
        }
        else
        {
            EdbgOutputDebugString("ERROR: OEMEthSendFrame failure, retry %u\r\n", retries);
        }
    }
    return(FALSE);
}
//****************************************************************************
// OEMEthHardareInit
//****************************************************************************
// Initializes the ethernet hardware.
// 
//
BOOL OEMEthHardwareInit(void)
{
    USHORT      usCS8950MacAddress[3];
    USHORT      usDefaultMacAddress[3]  = EBOOT_CS8950_MAC_ADDRESS;
    ULONG *     pulEthernetBase         = 0;
    char *      pszEthernetCardType;
    BOOL        bTemp;


    //
    // Put ethernet checking here.
    //
    {
        pDriverGlobals->eth.EdbgHardwareType = EDBG_ADAPTER_CS8950;
    }


    //
    // Check to see if a NE2000 card is plugged into the system.
    //
    //if(OEMNE2000Detect())
    //{
    //    pDriverGlobals->eth.EdbgHardwareType = EDBG_ADAPTER_NE2000;
    //    
    //}

    //
    // Get the board information from the SPI device.  Even if we are using 
    // ne2000 to download we want to use the board string.
    //
    //GetBoardInformation();

    //
    // Assign controller-specific callbacks.
    //
    switch (pDriverGlobals->eth.EdbgHardwareType)
    {

        case EDBG_ADAPTER_CS8950:
            pfnEDbgInit           = CS8950Init;
            pfnEDbgGetFrame       = CS8950GetFrame;
            pfnEDbgSendFrame      = CS8950SendFrame;
            pulEthernetBase       = (ULONG *)ETHERNET_BASE;
            pszEthernetCardType   = "KS8721";

            //
            // CS8950 DMA's to SDRAM.  Need to give the library a physical and virtual
            // address to uncached memory.
            //
            bTemp = CS8950DMAInit
            (
                CS8950_PHYSICAL_MEMORY, 
                CS8950_VIRTUAL_MEMORY, 
                CS8950_MEMORY_SIZE
            );

            if(!bTemp)
            {
                EdbgOutputDebugString("ERROR: Failed to Initialize KS8721 DMA buffer.\r\n");
                return FALSE;
            }

            //
            // Gets the MAC address from either the EEPROM or used the default.
            //
            GetDeviceMacAddress
            (
                usCS8950MacAddress,
                usDefaultMacAddress
            );

            //
            // We need to do this since the board does not have a MAC address.
            // Lets use the same mac address as eboot.
            //
            CS8950WriteEEPROM(0, usCS8950MacAddress[0]);
            CS8950WriteEEPROM(1, usCS8950MacAddress[1]);
            CS8950WriteEEPROM(2, usCS8950MacAddress[2]);

            break;

        default:
            EdbgOutputDebugString("ERROR: Unable to find network card.\r\n");
            return(FALSE);
    }

    //
    // Print out the card information.
    //
    EdbgOutputDebugString
    (
        "Card Type = %s, Address = 0x%x.\r\n", 
        pszEthernetCardType, 
        (ULONG)pulEthernetBase
    );

    //
    // Call driver specific initialization
    //
    if (!pfnEDbgInit((BYTE *)pulEthernetBase, 1, MyAddr.wMAC))
    {
        EdbgOutputDebugString("ERROR: Failed to initialize NIC.\r\n");
        return(FALSE);
    }

    return(TRUE);
}

//****************************************************************************
// OEMEthPreDownload
//****************************************************************************
// Return if we are download an images or jumping strait to the image.
// 
//
DWORD OEMEthPreDownload(void)
{
    char szDeviceName[EDBG_MAX_DEV_NAMELEN];
    char* szPlatformString = EBOOT_PLATFORM_STRING;
    DWORD dwSubnetMask      = 0;
    BOOL fGotJumpImg        = FALSE;
    DWORD DHCPLeaseTime     = DEFAULT_DHCP_LEASE;
    DWORD dwBootFlags       = 0;
    DWORD *pDHCPLeaseTime   = &DHCPLeaseTime;

    //
    // Clear out the device name.
    //
    memset(szDeviceName, 0, EDBG_MAX_DEV_NAMELEN);

    //
    // Get the device name and platform strings from the spi eeprom or
    // get the default.
    //
    GetPlatformString(szPlatformString);
    CreateDeviceName(&MyAddr, szDeviceName);

    EdbgOutputDebugString("INFO: Using device name: '%s'\n", szDeviceName);

#ifdef EBOOT_STATIC_IP
    MyAddr.dwIP    = inet_addr(EBOOT_CS8950_IP_ADDRESS); // for example

//    MyAddr.wMAC = EBOOT_CS8950_MAC_ADDRESS; 
    EdbgOutputDebugString("Mac Address: 0x%x 0x%x 0x%x \n", MyAddr.wMAC[0], MyAddr.wMAC[1], MyAddr.wMAC[2]);
   
    MyAddr.wPort   = EBOOT_CS8950_TFTP_PORT;  

    dwSubnetMask   = inet_addr(EBOOT_CS8950_SUBNET_MASK);  // in my case

    if (MyAddr.dwIP && dwSubnetMask)
    {
        pDHCPLeaseTime = NULL;
    }
#endif
    //
    // Initialize the TFTP transport.
    //
    if (!EbootInitEtherTransport(&MyAddr, 
                                 &dwSubnetMask, 
                                 &fGotJumpImg, 
                                 pDHCPLeaseTime, 
                                 EBOOT_VERSION_MAJOR, 
                                 EBOOT_VERSION_MINOR, 
                                 szPlatformString, 
                                 szDeviceName, 
                                 EDBG_CPU_ARM720, 
                                 dwBootFlags))
    {
        return(BL_ERROR);
    }

    //
    // Save the Ethernet address in boot args area.
    //
    memcpy(&(pDriverGlobals->eth.EdbgAddr), &MyAddr, sizeof(MyAddr));
    memcpy(&pDriverGlobals->eth.strEdbgName, szDeviceName, EDBG_MAX_DEV_NAMELEN);

    //
    //pDriverGlobals->eth.etherFlags = LDRFL_USE_EDBG | LDRFL_ADDR_VALID | LDRFL_JUMPIMG;
    //
    if (pDHCPLeaseTime)
    {
        pDriverGlobals->eth.DHCPLeaseTime = *pDHCPLeaseTime;    // DHCP
    }
    else
    {
        pDriverGlobals->eth.DHCPLeaseTime = 0;                  // Static IP
    }

    return(fGotJumpImg? BL_JUMP : BL_DOWNLOAD);
}


//****************************************************************************
// OEMEthGetSecs
//****************************************************************************
// Return the time in seconds using the debug timer routine.
// 
//
DWORD OEMEthGetSecs(void)
{
    DWORD dwReturnValue;


    //
    // Debug timer.
    //
    dwReturnValue = (DWORD)(GetSystemTimeInUSec()>>(ULONGLONG)20);
    return(dwReturnValue);
}


// Stub LED display routine - called by NE2000 ethdbg driver.
VOID SC_WriteDebugLED(WORD wIndex, DWORD dwPattern)
{
    return;
}




⌨️ 快捷键说明

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