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

📄 halkitl.c

📁 ebd9307开发板wince bsp源码,包括cs8900,lcd,nand,serial,touch,usb,gpio,wd等驱动
💻 C
字号:
//**********************************************************************
//                                                                      
// Filename: halkitl.c
//                                                                      
// Description: 
//
// 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.
//
/*++
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.

Module Name:  
    halkitl.c
    
Abstract:

    Platform specific code for KITL services.
    NOTE: this file is included from kernel\buildexe\kitlnokd\kitlnokd.c, NOT
          built as part of the hal.lib. The reason is to support dual build (KITL
          and non-KITL). Once we have all the tools supporting KITL, we may
          consider taking the original EDBG support out of the directory.

Functions:


Notes: 

--*/
#include <windows.h>
#include <nkintr.h>
#include <kitl.h>
#include <halether.h>
#include <kitlprot.h>
//#include <platform.h>
#include <memorymap.h>
#include <drv_glob.h>
#include "ethdbg.h"

#define LOG(x)  KITLOutputDebugString("%s == 0x%x\r\n", #x, x)

void CreateDeviceName(EDBG_ADDR *pMyAddr, char *szBuf);

static EDBG_ADDR    MyAddr;

int bActiveKitl;

void InitDebugEther(void)
{
    // Initialize KITL transport
    if (KitlInit (TRUE)) {
        KITLOutputDebugString ("KITL Initialized\n");
        // no longer need to start kernel services
        // since KITL config message told us what to start and
        // kitl will start it accordingly
//        if (gpKitl->dwBootFlags & KITL_FL_DBGMSG)
//            SetKernelCommDev (KERNEL_SVC_DBGMSG, KERNEL_COMM_ETHER);
//        if (gpKitl->dwBootFlags & KITL_FL_PPSH)
//            SetKernelCommDev (KERNEL_SVC_PPSH, KERNEL_COMM_ETHER);
//        if (gpKitl->dwBootFlags & KITL_FL_KDBG)
//            SetKernelCommDev (KERNEL_SVC_KDBG, KERNEL_COMM_ETHER);
    } else {
        KITLOutputDebugString ("KITL Initialization Failed, No debugging support available\n");
    }
}
/*
BOOL InitParallelSerial (PKITLTRANSPORT pKitl)
{
    //
    // Initialize the parallel port stuff.
    OEMInitParallelPort();

    //
    // Set the debugger to use serial/parallel.
    //
    SetKernelCommDev(KERNEL_SVC_DBGMSG,KERNEL_COMM_SERIAL);
    SetKernelCommDev(KERNEL_SVC_PPSH,  KERNEL_COMM_PARALLEL);
    SetKernelCommDev(KERNEL_SVC_KDBG, KERNEL_COMM_SERIAL);

    return FALSE;
}
*/
void
KitlEthEnableInts(BOOL bEnable)
{
    if (bEnable) 
        OEMEthEnableInts();
    else 
        OEMEthDisableInts();
}

static BOOL GetDevCfg (LPBYTE pBuf, PUSHORT pcbBuf)
{
    // put our IP info in the buffer
    if (*pcbBuf < sizeof (MyAddr)) {
        return FALSE;
    }
        
    memcpy (pBuf, &MyAddr, sizeof (MyAddr));
    *pcbBuf = sizeof (MyAddr);
    return TRUE;
}

static BOOL SetHostCfg (LPBYTE pData, USHORT cbData)
{
    // we automatically figure out the host address info during initial 
    // handshake. No need to handle host cfg data here.
    return TRUE;
}

static BOOL EthSendFrame(LPBYTE pData, USHORT nLength)
{

    return (OEMEthSendFrame(pData, (DWORD)nLength));

}

/* InitEther
 *
 *  Initialize KITL Ether transport. The Odo platform uses a debug board 
 *  based on the SMC 91C94 Ethernet controller.
 *
 *  Return Value:
 *    Return TRUE if init is successful, FALSE if error.
 */
BOOL InitEther (PKITLTRANSPORT pKitl)
{
    EDBG_ADAPTER adp;
    DWORD dwDHCPLeaseTime;
    DWORD dwSubnetMask;

    KITLOutputDebugString ("+InitEther\n");

    memset (&adp, 0, sizeof(adp));
    memset (pKitl, 0, sizeof (KITLTRANSPORT));

    // use existing code for ether initialization
    if (!OEMEthInit (&adp))
        return FALSE;

    // we are going to completely ignore the info in bootargs and the adaptor info
    // returned from OEMEthInit, except MAC address. Just to prove that KITL will connect standalone

    // get the MAC address
    MyAddr.wMAC[0] = adp.Addr.wMAC[0];
    MyAddr.wMAC[1] = adp.Addr.wMAC[1];
    MyAddr.wMAC[2] = adp.Addr.wMAC[2];
    
    if((DRIVER_GLOBALS_POINTER)->eth.EbootMagicNum == EBOOT_MAGIC_NUM )
    {
        memcpy
        (
            pKitl->szName, 
            (DRIVER_GLOBALS_POINTER)->eth.strEdbgName, 
            EDBG_MAX_DEV_NAMELEN
        );
    }
    else
    {
        CreateDeviceName(&MyAddr, pKitl->szName);
    }
    KITLOutputDebugString ("Using device name: %s\n", pKitl->szName);

    // If we haven't been given an IP address from our loader (or if we're not using static IP), get an IP address
    // from a DHCP server.
    if (adp.Addr.dwIP)
    {
        // Static IP or we got the IP from our bootloader...
        MyAddr.dwIP     = adp.Addr.dwIP;
        dwSubnetMask    = 0;    // Don't care about subnet mask...
        dwDHCPLeaseTime = adp.DHCPLeaseTime;
    }
    else
    {
        // Get a DHCP address...
        if (!EbootGetDHCPAddr (&MyAddr, &dwSubnetMask, &dwDHCPLeaseTime))
            return FALSE;
    }

    MyAddr.wPort = htons (EDBG_SVC_PORT);
    KITLOutputDebugString ("Device %s, IP %s, Port %d\n", pKitl->szName, inet_ntoa (MyAddr.dwIP), htons (MyAddr.wPort));

    // initialize KITL Ethernet transport layer
    if (!KitlEtherInit (&MyAddr, dwDHCPLeaseTime)) {
        KITLOutputDebugString ("Unable to initialize KITL Ether transport\n");
        return FALSE;
    }
    
    // fill in the blanks in KITLTRANSPORT structure.
    pKitl->FrmHdrSize = KitlEtherGetFrameHdrSize ();
    pKitl->Interrupt = (UCHAR) adp.SysIntrVal;
    pKitl->dwPhysBuffer = EDBG_VIRTUAL_MEMORY;
    pKitl->dwPhysBufLen = EDBG_MEMORY_SIZE;	// 128K of buffer available
    pKitl->dwBootFlags = 0;
    pKitl->WindowSize = EDBG_WINDOW_SIZE;
    pKitl->pfnDecode = KitlEtherDecodeUDP;
    pKitl->pfnEncode = KitlEtherEncodeUDP;
    pKitl->pfnSend = EthSendFrame;
    pKitl->pfnRecv = OEMEthGetFrame;
    pKitl->pfnEnableInt = KitlEthEnableInts;
    pKitl->pfnSetHostCfg = SetHostCfg;
    pKitl->pfnGetDevCfg = GetDevCfg;

    KITLOutputDebugString ("-InitEther\n");

    return TRUE;
}


/* OEMKitlInit
 *
 *  Initialization routine - called from KitlInit() to perform platform specific
 *  HW init.
 *
 *  Return Value:
 *    Return TRUE if init is successful, FALSE if error.
 */

BOOL OEMKitlInit (PKITLTRANSPORT pKitl)
{
    BOOL    bReturn = FALSE;
    

    OEMInitDebugSerial();
    KITLOutputDebugString ("+OEMKitlInit\n");

    //
    // Try to find a transport available
    // In our case we need to find out which transport was used to download.
    //
    if (pDriverGlobals->eth.EbootMagicNum == EBOOT_MAGIC_NUM) 
    {
        bActiveKitl = TRUE;
        bReturn = InitEther (pKitl);
    }
    else
    {
        pDriverGlobals->eth.EdbgHardwareType = EDBG_ADAPTER_CS8950;
        pDriverGlobals->eth.EdbgAddr.wMAC[0] = 0x2400; 
        pDriverGlobals->eth.EdbgAddr.wMAC[1] = 0x1020;
        pDriverGlobals->eth.EdbgAddr.wMAC[2] = 0x3412;
        pDriverGlobals->eth.EdbgAddr.dwIP    = 0;

        bActiveKitl = TRUE;
        bReturn = InitEther (pKitl);
    }


    KITLOutputDebugString ("-OEMKitlInit\n");
    return bReturn;
}

⌨️ 快捷键说明

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