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

📄 sdmain.cpp

📁 SAMSUNG S3C6410 CPU BSP for winmobile6
💻 CPP
📖 第 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 OR INDEMNITIES.
//

// Copyright (c) 2002-2004 BSQUARE Corporation.  All rights reserved.
// DO NOT REMOVE --- BEGIN EXTERNALLY DEVELOPED SOURCE CODE ID 40973--- DO NOT REMOVE

// Driver entry points for bus driver

#include "SDBusDriver.h"
#include <bldver.h>
#include <s3c6410.h>
// initialize debug zones
SD_DEBUG_INSTANTIATE_ZONES(
                           TEXT("SDBusDriver"), // module name
                           ZONE_ENABLE_INIT | ZONE_ENABLE_ERROR | ZONE_ENABLE_WARN,
                           TEXT("HC Driver Load"),
                           TEXT("Dispatcher"),
                           TEXT("Shutdown"),
                           TEXT("Power"),
                           TEXT("Device Load"),
                           TEXT("Bus Requests"),
                           TEXT("Buffer Dumps"),
                           TEXT("Soft-Block"),
                           TEXT(""),
                           TEXT(""),
                           TEXT(""));

// the ONLY instance of the bus driver
static CSDBusDriver        *s_pSDBusDriver;
static BOOL                 s_fBusAccessContext; // Dummy data to use as a pointer


///////////////////////////////////////////////////////////////////////////////
//  DllEntry - the main dll entry point
//  Input:  hInstance - the instance that is attaching
//          Reason - the reason for attaching
//          pReserved - not much
//  Output:
//  Return: Always returns TRUE
//  Notes:  this is only used to initialize the zones
///////////////////////////////////////////////////////////////////////////////
extern "C"
BOOL DllEntry(HINSTANCE  hInstance,
              ULONG      Reason,
              LPVOID     pReserved)
{
    BOOL fRet = TRUE;

    if ( Reason == DLL_PROCESS_ATTACH ) {
        s_pSDBusDriver = NULL;
        DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDBusDriver: PROCESS_ATTACH \n")));
        DisableThreadLibraryCalls((HMODULE) hInstance);
        SD_DEBUG_ZONE_REGISTER(hInstance, NULL);

        if (!SDInitializeCardLib()) {
            fRet = FALSE;
        }
    }
    else if ( Reason == DLL_PROCESS_DETACH ) {
        DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDBusDriver: PROCESS_DETACH \n")));
        SDDeinitializeCardLib();
    }

    return fRet;
}

///////////////////////////////////////////////////////////////////
//  ShutDownBusDriverInstance - shutdown the bus driver instance
//  Input:  dwContext - context passed into XXX_Deinit
//  Output:
//  Return: BOOL
//  Notes:
//
////////////////////////////////////////////////////////////////////
BOOL ShutDownBusDriverInstance(DWORD dwContext)
{
    BOOLEAN ret = TRUE; // return value

    // check the single instance
    if (s_pSDBusDriver != NULL)  {
        RETAILMSG(1, ((TEXT("SDBusDriver: Shutting Down Bus Driver...\n"))));
        delete s_pSDBusDriver;
        s_pSDBusDriver = NULL;
    } else {
        RETAILMSG(1, ((TEXT("SDBusDriver: Bus Driver already shutdown! \n"))));
        ret = FALSE;
    }

    return ret;
}



///////////////////////////////////////////////////////////////////////////////
//  SDC_Close - the close entry point for the bus driver
//  Input:  hOpenContext - the context returned from SDC_Open
//  Output:
//  Notes:  always returns TRUE
///////////////////////////////////////////////////////////////////////////////
extern "C"
BOOL SDC_Close(DWORD hOpenContext)
{
    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDBusDriver: +-SDC_Close\n")));

    return TRUE;
}


///////////////////////////////////////////////////////////////////////////////
//  SDC_PreDeinit - the predeinit entry point for the SD bus driver
//  Input:  hDeviceContext - the context returned from SDC_Init
//  Output:
//  Notes:  always returns TRUE.
///////////////////////////////////////////////////////////////////////////////
extern "C"
BOOL SDC_PreDeinit(DWORD hDeviceContext)
{
    DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDBusDriver: +SDC_PreDeinit\n")));

    // Nothing to do here. Just make sure that the device manager won't
    // call Deinit until everyone is out of SDC_IOControl.

    DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDBusDriver: -SDC_PreDeinit\n")));
    return TRUE;
}


///////////////////////////////////////////////////////////////////////////////
//  SDC_Deinit - the deinit entry point for the SD bus driver
//  Input:  hDeviceContext - the context returned from SDC_Init
//  Output:
//  Notes:  always returns TRUE.
///////////////////////////////////////////////////////////////////////////////
extern "C"
BOOL SDC_Deinit(DWORD hDeviceContext)
{
    DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDBusDriver: +SDC_Deinit\n")));

    // shutdown the bus driver
    ShutDownBusDriverInstance(hDeviceContext);

    DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDBusDriver: -SDC_Deinit\n")));
    return TRUE;
}

///////////////////////////////////////////////////////////////////////////////
//  SDC_Init - the init entry point for the bus driver
//  Input:  dwContext - the context for this init
//  Output:
//  Return:  returns a non-zero value (pointer to the bus driver instance)
//  Notes:
///////////////////////////////////////////////////////////////////////////////
extern "C"
DWORD SDC_Init(DWORD dwContext)
{
    LPCTSTR         pszActiveKey = (LPCTSTR) dwContext;

    DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDBusDriver: +SDC_Init\n")));

    if (s_pSDBusDriver != NULL) {
        DEBUGMSG(SDCARD_ZONE_ERROR,
            (TEXT("SDBusDriver: Bus Driver Already loaded, only one instance allowed \n")));
        return 0;
    }

    // create the instance
    s_pSDBusDriver = new CSDBusDriver(pszActiveKey);

    if (s_pSDBusDriver == NULL) {
        DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDC_Init: Failed to create instance of the bus driver\n")));
        return 0;
    }

    SD_API_STATUS status = s_pSDBusDriver->Initialize();
    if (!SD_API_SUCCESS(status)) {
        DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDC_Init: Bus driver failed to initialize : status: 0x%08X  \n"), status));
        delete s_pSDBusDriver;
        return 0;
    }

    DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDBusDriver: Bus Driver instance created : 0x%08X ! -SDC_Init \n"), s_pSDBusDriver));

    // return pointer to bus driver object as a context
    return (DWORD)s_pSDBusDriver;
}

///////////////////////////////////////////////////////////////////////////////
//  SDGetSystemContext - get the system context
//  Input:
//  Output:
//  Return: returns the system context, NULL if the system is not initialized
//  Notes:
///////////////////////////////////////////////////////////////////////////////
PVOID SDGetSystemContext()
{
    if (s_pSDBusDriver != NULL) {
        if (s_pSDBusDriver->IsReady()) {
            // return the bus driver object as a context
            return (PVOID)s_pSDBusDriver;
        }
    }

    return NULL;
}

///////////////////////////////////////////////////////////////////////////////
//  SDC_IOControl - the I/O control entry point for the bus driver
//  Input:  hOpenContext - the context returned from SDC_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: TRUE if ioctl was successfully handled
//  Notes:
///////////////////////////////////////////////////////////////////////////////
extern "C"
BOOL SDC_IOControl(DWORD   hOpenContext,
                   DWORD   dwCode,
                   PBYTE   pBufIn,
                   DWORD   dwLenIn,
                   PBYTE   pBufOut,
                   DWORD   dwLenOut,
                   PDWORD  pdwActualOut)
{
    BOOL fRet = TRUE;
    CSDBusDriver *pBusDriver = s_pSDBusDriver;

    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDBusDriver: +SDC_IOControl\n")));

    if (hOpenContext == (DWORD) &s_fBusAccessContext) {
        // Bus access
        fRet = pBusDriver->BusIOControl(dwCode, pBufIn, dwLenIn, pBufOut,
            dwLenOut, pdwActualOut);
    }
    else {
        // Normal access
        DEBUGCHK(hOpenContext == (DWORD) pBusDriver);
        DWORD cbActualOut = -1;
        DWORD dwErr = ERROR_SUCCESS;

⌨️ 快捷键说明

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