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

📄 main.c

📁 Windows CE 6.0 BSP for VOIP sample phone. Intel PXA270 platform.
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//
// Copyright (c) 2002 BSQUARE Corporation.  All rights reserved.
// DO NOT REMOVE --- BEGIN EXTERNALLY DEVELOPED SOURCE CODE ID 40973--- DO NOT REMOVE
//
// Module Name:
//
//    Main.c   
//
// Abstract:
//
//    Driver entry points for PXA27x SDIO driver 
//
// Notes:
//
///////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include <nkintr.h>
#include <ceddk.h>
#include <bulverde.h>
#include <Devload.h>
#include "SDCardDDK.h"
#include "SDHCD.h"
#include "SD.h"

    // initialize debug zones
SD_DEBUG_INSTANTIATE_ZONES(
     TEXT("PXA27X SDIO Driver"), // module name
     ZONE_ENABLE_INIT | ZONE_ENABLE_ERROR | ZONE_ENABLE_WARN /*| SDH_SDBUS_INTERACTION_ZONE_ON*/, 
     // | SDH_RECEIVE_ZONE_ON | SDH_TRANSMIT_ZONE_ON | SDH_SEND_ZONE_ON,
     //| SDH_INTERRUPT_ZONE_ON,    // initial settings
     TEXT("Interrupts"),
     TEXT("Send Handler "), 
     TEXT("Responses"), 
     TEXT("Receive Data"),                   
     TEXT("Clock Control"), 
     TEXT("Transmit Data"), 
     TEXT("Function"), 
     TEXT("SDBus Interaction"),
     TEXT(""),
     TEXT(""),
     TEXT(""));

#define SDH_SLOTS 1
#define SDH_REGISTRY_BASE_PATH TEXT("Drivers\\SDCARD\\HostController\\XSDSC")

///////////////////////////////////////////////////////////////////////////////
//  CardDllEntry - the main dll entry point
//  Input:  hInstance - the instance that is attaching
//          Reason - the reason for attaching
//          pReserved - 
//  Output: 
//  Return: TRUE
//  Notes:  this is only used to initialize the zones
///////////////////////////////////////////////////////////////////////////////
BOOL DllEntry(HINSTANCE  hInstance,
                       ULONG      Reason,
                       LPVOID     pReserved)
{
    if ( Reason == DLL_PROCESS_ATTACH ) {
        SD_DEBUG_ZONE_REGISTER(hInstance, SDH_REGISTRY_BASE_PATH);
        DisableThreadLibraryCalls( (HMODULE) hInstance );

        if( !SDInitializeCardLib() )
        {
            return FALSE;
        }
        else if( !SD_API_SUCCESS( SDHCDInitializeHCLib() ) ) 
        {
            SDDeinitializeCardLib();
            return FALSE;
        }
    }

    if ( Reason == DLL_PROCESS_DETACH ) {
        SDHCDDeinitializeHCLib();
        SDDeinitializeCardLib();
    }

    return(TRUE);
}



///////////////////////////////////////////////////////////////////////////////
//  SDH_Deinit - the deinit entry point 
//  Input:  hDeviceContext - the context returned from SDH_Init
//  Output: 
//  Return: always returns TRUE
//  Notes:  
///////////////////////////////////////////////////////////////////////////////
BOOL SDH_Deinit(DWORD hDeviceContext)
{
    PSDCARD_HC_CONTEXT pHostContext;

    DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: +SDH_Deinit\n")));

    pHostContext = (PSDCARD_HC_CONTEXT)hDeviceContext;

        // deregister the host controller
    SDHCDDeregisterHostController(pHostContext);

    if( pHostContext && pHostContext->pHCSpecificContext )
    {
        free( pHostContext->pHCSpecificContext );
    }

        // cleanup the context
    SDHCDDeleteContext((PSDCARD_HC_CONTEXT)hDeviceContext);

    return TRUE;
}

///////////////////////////////////////////////////////////////////////////////
//  SDH_Init - the init entry point 
//  Input:  dwContext - the context for this init
//  Output: 
//  Return: returns instance context
//  Notes:  
///////////////////////////////////////////////////////////////////////////////
DWORD SDH_Init(DWORD dwContext)
{
    PSDCARD_HC_CONTEXT      pHostContext;   // new HC context
    SD_API_STATUS           status;         // SD status
    PSDH_HARDWARE_CONTEXT pController;    // new instance
    HKEY hKeyDevice;
    LPCTSTR pszActiveKey;

    DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: +SDH_Init\n")));    

    DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: Active RegPath: %s \n"),
        (PTSTR)dwContext));

    pController = NULL;

    // allocate the context
    status = SDHCDAllocateContext(SDH_SLOTS, 
                                  &pHostContext);

    if (!SD_API_SUCCESS(status)) {
        DbgPrintZo(SDCARD_ZONE_ERROR, 
            (TEXT("SDH: Failed to allocate context : 0x%08X \n"), status));
        return 0;
    }

    // create our extension 
    pController = (PSDH_HARDWARE_CONTEXT)malloc( sizeof(SDH_HARDWARE_CONTEXT) );
    if( pController == NULL )
    {
        DbgPrintZo(SDCARD_ZONE_ERROR, 
            (TEXT("SDH: Failed to allocate extension\n")));
        return 0;
    }
    memset( pController, 0, sizeof(SDH_HARDWARE_CONTEXT) );

    // Set our extension
    pHostContext->pHCSpecificContext = pController;

    pController = GetExtensionFromHCDContext(PSDH_HARDWARE_CONTEXT, pHostContext);

    pszActiveKey = (LPCTSTR) dwContext;
    
    pController->pszActiveKey = pszActiveKey;
    pController->hBusAccessHandle = CreateBusAccessHandle( pszActiveKey );

    hKeyDevice = OpenDeviceKey(pszActiveKey);
    if (!hKeyDevice || !LoadRegistrySettings(hKeyDevice, pController) ) {
        DbgPrintZo(SDCARD_ZONE_ERROR, 
        (TEXT("SDH: Failed load the registry settings\n")));
        return 0;
    }
    RegCloseKey( hKeyDevice );

    DbgPrintZo(SDCARD_ZONE_INIT, 
               (TEXT("SDH: Real RegPath: %s \n"),pController->RegPath));
   
    // save off the host context
    pController->pHCContext = pHostContext;

    // set the name
    SDHCDSetHCName(pHostContext, TEXT("Lubbock"));

    // set init handler
    SDHCDSetControllerInitHandler(pHostContext,SDInitialize);  
    // set deinit handler    
    SDHCDSetControllerDeinitHandler(pHostContext, SDDeinitialize);
    // set the bus request handler
    SDHCDSetBusRequestHandler(pHostContext,SDHBusRequestHandler);   
    // set the cancel I/O handler
    SDHCDSetCancelIOHandler(pHostContext, SDHCancelIoHandler);   
    // set the slot option handler
    SDHCDSetSlotOptionHandler(pHostContext, SDHSlotOptionHandler); 
    

    // now register the host controller 
    status = SDHCDRegisterHostController(pHostContext);

    if (!SD_API_SUCCESS(status)) {
        if( pController )
        {
            free( pController );
        }
        SDHCDDeleteContext(pHostContext);
        DbgPrintZo(SDCARD_ZONE_ERROR, 
                (TEXT("SDH: Failed to register host controller: %0x08X \n"),status));
        return 0;
    }

    DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: -SDH_Init\n")));

    // return the Host Controller context
    return (DWORD)pHostContext;
}

///////////////////////////////////////////////////////////////////////////////
//  SDH_IOControl - the I/O control entry point
//  Input:  hOpenContext - the context returned from SDH_Open
//          dwCode - the ioctl code
//          pBufIn - the input buffer from the user
//          dwLenIn - the length of the input buffer
//          pBufOut - the output buffer from the user
//          dwLenOut - the length of the output buffer
//          pdwActualOut - the size of the transfer
//  Output: 
//  Return: FALSE
//  Notes:  Not used
///////////////////////////////////////////////////////////////////////////////
BOOL SDH_IOControl(DWORD   hOpenContext,
                   DWORD   dwCode,
                   PBYTE   pBufIn,
                   DWORD   dwLenIn,
                   PBYTE   pBufOut,
                   DWORD   dwLenOut,
                   PDWORD  pdwActualOut)
{
    DbgPrintZo(SDCARD_ZONE_FUNC, (TEXT("SDH: +-SDH_IOControl \n")));
    return FALSE;;
}

///////////////////////////////////////////////////////////////////////////////
//  SDH_Open - the open entry point for the bus driver
//  Input:  hDeviceContext - the device context from SDH_Init
//          AccessCode - the desired access
//          ShareMode - the desired share mode
//  Output: 
//  Return: 0
//  Notes:  not used
///////////////////////////////////////////////////////////////////////////////
DWORD SDH_Open(DWORD    hDeviceContext,
               DWORD    AccessCode,
               DWORD    ShareMode)
{
    DbgPrintZo(SDCARD_ZONE_FUNC, (TEXT("SDH: +-SDH_Open\n")));
    return 0;
}



///////////////////////////////////////////////////////////////////////////////
//  SDH_Close - the close entry point 
//  Input:  hOpenContext - the context returned from SDH_Open
//  Output: 
//  Return: TRUE
//  Notes:  not used
///////////////////////////////////////////////////////////////////////////////
BOOL SDH_Close(DWORD hOpenContext)
{
    DbgPrintZo(SDCARD_ZONE_FUNC, (TEXT("SDH: +-SDH_Close\n")));
    return TRUE;
}

void SDControllerPowerDown( PSDH_HARDWARE_CONTEXT pController );
void SDControllerPowerUp( PSDH_HARDWARE_CONTEXT pController );

⌨️ 快捷键说明

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