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

📄 cspi_io.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// 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, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004-2006, 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: cspi_io.cpp
//
// This module provides a stream interface for the CSPI bus driver. Client 
// drivers can use the stream interface to configure and exchange data with 
// the CSPI peripheral.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include <ceddk.h>

#include "csp.h"
#include "cspibus.h"
#include "cspiClass.h"

//------------------------------------------------------------------------------
// External Functions

//------------------------------------------------------------------------------
// External Variables

//------------------------------------------------------------------------------
// Defines
#define REG_DEVINDEX_VAL_NAME			TEXT("Index")

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

//------------------------------------------------------------------------------
// Global Variables
#ifdef DEBUG
DBGPARAM dpCurSettings = {
    TEXT("cspi"), {
        TEXT("Init"),TEXT("Deinit"),TEXT("Open"),TEXT("Close"),
        TEXT("IOCtl"),TEXT("Thread"),TEXT(""),TEXT(""),
        TEXT(""),TEXT(""),TEXT(""),TEXT(""),
        TEXT(""),TEXT("Function"),TEXT("Warning"),TEXT("Error") },
    0xC000
};
#endif // DEBUG

//------------------------------------------------------------------------------
// Local Variables
static CEDEVICE_POWER_STATE g_dxCurrent = D0;

//------------------------------------------------------------------------------
// Local Functions

//------------------------------------------------------------------------------
//
// Function: SPI_Init
//
// The Device Manager calls this function as a result of a call to the 
// ActivateDevice() function.
//
// Parameters:
//		pContext
//          [in] Pointer to a string containing the registry path to the
//          active key for the stream interface driver.
//
// Returns:
//      Returns a handle to the device context created if successful. Returns
//      zero if not successfu.
//
//------------------------------------------------------------------------------
DWORD SPI_Init(LPCTSTR pContext)
{
    LONG    regError;
    HKEY    hKey;
    DWORD   dwDataSize;
    DWORD   dwDevIndex;
    cspiClass * pCspi=NULL;

    DEBUGMSG(ZONE_INIT | ZONE_FUNCTION, (TEXT("SPI_Init +\r\n")));

    // try to open active device registry key for this context
    hKey = OpenDeviceKey(pContext);
    if (hKey == NULL) {
        DEBUGMSG(ZONE_ERROR, (TEXT("SPI_Init: OpenDeviceKey failed!!!\r\n")));
        return 0;
    }

    // try to load CSPI index from registry data
    dwDataSize = sizeof(DWORD);
    regError = RegQueryValueEx(
        hKey,                       // handle to currently open key
        REG_DEVINDEX_VAL_NAME,      // string containing value to query
        NULL,                       // reserved, set to NULL
        NULL,                       // type not required, set to NULL
        (LPBYTE)(&dwDevIndex),      // pointer to buffer receiving value
        &dwDataSize);               // pointer to buffer size

    // close handle to open key
    RegCloseKey(hKey);

    // check for errors during RegQueryValueEx
    if (regError != ERROR_SUCCESS) {
        DEBUGMSG(ZONE_ERROR, (TEXT("SPI_Init: RegQueryValueEx failed!!!\r\n")));
        return 0;
    }

    pCspi = new cspiClass();
    if (pCspi && !pCspi->CspiInitialize(dwDevIndex)) {
        delete pCspi;
        DEBUGMSG(ZONE_ERROR, (TEXT("SPI_Init:  CspiInitialize failed!!!\r\n")));
        return 0;
    }
	
    DEBUGMSG(ZONE_INIT | ZONE_FUNCTION, (TEXT("SPI_Init: CSPI index = %d, pCspi=0x%x\r\n"),
		dwDevIndex, pCspi));

    return (DWORD)pCspi;
}

//------------------------------------------------------------------------------
//
// Function: SPI_Deinit
//
// This function uninitializes a device.
//
// Parameters:
//      hDeviceContext
//          [in] Handle to the device context.
//
// Returns:
//      TRUE indicates success. FALSE indicates failure.
//
//------------------------------------------------------------------------------
BOOL SPI_Deinit(DWORD hDeviceContext)
{
    cspiClass * pCspi=(cspiClass *)hDeviceContext;

    DEBUGMSG(ZONE_DEINIT | ZONE_FUNCTION, (TEXT("SPI_Deinit: hDeviceContext=0x%x\r\n"),
		hDeviceContext));

    if (pCspi) {
        pCspi->CspiRelease();
        delete pCspi;
    }

    DEBUGMSG(ZONE_DEINIT | ZONE_FUNCTION, (TEXT("SPI_Deinit -\r\n")));

    return TRUE;
}

//------------------------------------------------------------------------------
//
// Function: SPI_Open
//
// This function opens a device for reading, writing, or both.
//
// Parameters:
//      hDeviceContext
//          [in] Handle to the device context. The XXX_Init function creates
//                and returns this handle.
//      AccessCode
//          [in] Access code for the device. The access is a combination of
//                read and write access from CreateFile.
//      ShareMode
//          [in] File share mode of the device. The share mode is a
//                combination of read and write access sharing from CreateFile.
//
// Returns:
//      This function returns a handle that identifies the open context of
//      the device to the calling application.
//
//------------------------------------------------------------------------------
DWORD SPI_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
    DEBUGMSG(ZONE_OPEN | ZONE_FUNCTION, (TEXT("SPI_Open: hDeviceContext=0x%x\r\n"),
		hDeviceContext));
	
    return hDeviceContext;
}

//------------------------------------------------------------------------------
//
// Function: SPI_Close
//
// This function opens a device for reading, writing, or both.
//
// Parameters:
//      hOpenContext
//          [in] Handle returned by the XXX_Open function, used to identify
//          the open context of the device.
//
// Returns:
//      TRUE indicates success. FALSE indicates failure.
//
//------------------------------------------------------------------------------
BOOL SPI_Close(DWORD hOpenContext)
{
    DEBUGMSG(ZONE_CLOSE | ZONE_FUNCTION, (TEXT("SPI_Close -\r\n")));
	
    return TRUE;
}

//------------------------------------------------------------------------------
//
// Function: SPI_PowerDown
//
// This function suspends power to the device. It is useful only with devices
// that can power down under software control.
//
// Parameters:
//      hDeviceContext
//          [in] Handle to the device context.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void SPI_PowerDown(DWORD hDeviceContext)
{
}

//------------------------------------------------------------------------------
//
// Function: SPI_PowerUp
//
// This function restores power to a device.
//
// Parameters:
//      hDeviceContext

⌨️ 快捷键说明

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