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

📄 vibdrvr.cpp

📁 Freescale ARM11系列CPU MX31的WINCE 5.0下的BSP
💻 CPP
字号:
//------------------------------------------------------------------------------
//
//  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.
//
//------------------------------------------------------------------------------
//
//  File:  Vibdrvr.cpp
//
//  Implementation of Vibrator driver
//
//------------------------------------------------------------------------------
//
//  Copyright (C) 2004-2005, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------

#define VIBRATOR_DATA_DEF    // global VIBRATOR driver variables defined here

#include <windows.h>
#include <vibdrvr.h>
#include <vibrator.h>

// global variables
CRITICAL_SECTION g_CsVibrator;

BOOL g_DriverLoaded;

// This routine initializes the Vibrator driver.
EXTERN_C DWORD
VIB_Init(
         PVOID Context
         )
{
    DWORD dwHandle = 0;     // assume failure
    SETFNAME(_T("Vibrator: Init"));
    
    DEBUGMSG(ZONE_INIT, (_T("%s: invoked w/ context 0x%08x\r\n"), pszFname, Context));

    // have we already been loaded?
    LOCK_VIBRATOR();
    if(g_DriverLoaded) {
        UNLOCK_VIBRATOR();
        goto done;
    } else {
        g_DriverLoaded = TRUE;
        UNLOCK_VIBRATOR();
    }

    if(!VibratorDriverInitialize()) {
        DEBUGMSG(ZONE_ERROR || ZONE_INIT, (_T("%s: NLedDriverInitialize() failed\r\n"), pszFname));
    } else {
        // return success
        dwHandle = 1;
    }
            
done:
    
    DEBUGMSG(ZONE_INIT, (_T("%s: returning %d\r\n"), pszFname, dwHandle));
    return dwHandle;
}


EXTERN_C BOOL
VIB_Deinit(
           DWORD dwContext
           )
{
    DEBUGMSG(ZONE_INIT, (_T("NLedDrvr: Deinit: invoked w/ context 0x%08x\r\n"),
        dwContext));
    
    DEBUGCHK(dwContext == 1);
	 
    // notify the PDD
    VibratorDriverDeInitialize();

    // clean up globals

    LOCK_VIBRATOR();
    g_DriverLoaded = FALSE;
    UNLOCK_VIBRATOR();
    
    DEBUGMSG(ZONE_INIT, (_T("NLedDrvr: Deinit: all done\r\n")));
    return TRUE;
}


EXTERN_C BOOL
VIB_IOControl(
              DWORD  dwContext,
              DWORD  Ioctl,
              PUCHAR pInBuf,
              DWORD  InBufLen, 
              PUCHAR pOutBuf,
              DWORD  OutBufLen,
              PDWORD pdwBytesTransferred
              )
{
    BOOL   fOk = TRUE;
    SETFNAME(_T("Vibrator::IOControl"));

    DEBUGMSG(ZONE_FUNCTION, (_T("%s: IOCTL:0x%x, InBuf:0x%x, InBufLen:%d, OutBuf:0x%x, OutBufLen:0x%x)\r\n"),
        pszFname, Ioctl, pInBuf, InBufLen, pOutBuf, OutBufLen));

    switch (Ioctl) {
    case IOCTL_VIBRATOR_GETDEVICEINFO:
        // sanity check parameters
        if(pInBuf != NULL && InBufLen == sizeof(UINT)) {
            UINT nInfoId;
            __try {
                nInfoId = *((UINT *) pInBuf);
                DWORD dwExpectedSize;

                // figure out what size buffer to expect
                switch(nInfoId) {
               
                case VIBRATOR_SUPPORTS_INFO_ID:
                    dwExpectedSize = sizeof(VIB_SUPPORTS_INFO);
                    break;
                case VIBRATOR_SETTINGS_INFO_ID:
                    dwExpectedSize = sizeof(VIB_SETTINGS_INFO);
                    break;
                default:
                    DEBUGMSG(ZONE_WARN, (_T("%s: Unexpected nInfoId %d\r\n"), pszFname, nInfoId));
                    dwExpectedSize = 0;
                    fOk = FALSE;
                    break;
                }

                // did we get a valid output buffer?
                if(pOutBuf == NULL || OutBufLen != dwExpectedSize) {
                    fOk = FALSE;
                }
            }
            __except(EXCEPTION_EXECUTE_HANDLER) {
                DEBUGMSG(ZONE_WARN, (_T("%s: IOCTL_VIBRATOR_GETDEVICEINFO: exception accessing nInfoId at 0x%08x\r\n"),
                    pszFname, pInBuf));
                fOk = FALSE;
            }

            // call the PDD?
            if(fOk) {
                LOCK_VIBRATOR();
                __try {
                    fOk = VibratorDriverGetDeviceInfo(nInfoId, pOutBuf);
                }
                __except(EXCEPTION_EXECUTE_HANDLER) {
                    DEBUGMSG(ZONE_WARN, (_T("%s: exception in VibratorDriverGetDeviceInfo\r\n"), pszFname));
                    SetLastError(ERROR_GEN_FAILURE);
                    fOk = FALSE;
                }
                UNLOCK_VIBRATOR();
            }
        }
        break;
        
    case IOCTL_VIBRATOR_SETDEVICE:
        // sanity check parameters
        if(pOutBuf == NULL && OutBufLen == 0
            && pInBuf != NULL && InBufLen == sizeof(VIB_SETTINGS_INFO) && pdwBytesTransferred == NULL) {
            // update the LEDs
            LOCK_VIBRATOR();
            __try {
                fOk = VibratorDriverSetDevice(VIBRATOR_SETTINGS_INFO_ID, pInBuf);
            }
            __except(EXCEPTION_EXECUTE_HANDLER) {
                DEBUGMSG(ZONE_WARN, 
                    (_T("%s: IOCTL_VIBRATOR_SETDEVICE: exception in VibratorDriverSetDevice(VIBRATOR_SETTINGS_INFO_ID, 0x%08x)\r\n"), 
                    pszFname, pInBuf));
                SetLastError(ERROR_GEN_FAILURE);
                fOk = FALSE;
            }
            UNLOCK_VIBRATOR();
        }
        break;       
    }
    
    DEBUGMSG(ZONE_FUNCTION || ZONE_IOCTL || (!fOk && ZONE_WARN), 
        (_T("%s: returning %d, error %d\r\n"),
        pszFname, fOk, GetLastError()));
    return fOk;
}

EXTERN_C VOID
VIB_PowerDown(
              DWORD dwContext
              )
{
    // notify the PDD
   VibratorDriverPowerDown(TRUE);
}


EXTERN_C VOID
VIB_PowerUp(
            DWORD dwContext
            )
{
    // notify the PDD
    VibratorDriverPowerDown(FALSE);
}


EXTERN_C DWORD
VIB_Open(
         DWORD Context, 
         DWORD Access,
         DWORD ShareMode)
{
    
    DEBUGMSG(ZONE_FUNCTION,(_T("Open(%x, 0x%x, 0x%x)\r\n"),Context, Access, ShareMode));
    DEBUGCHK(Context == 1);
    
    UNREFERENCED_PARAMETER(Access);
    UNREFERENCED_PARAMETER(ShareMode);
    
    // pass back the device handle
    return Context;     // 0 indicates failure
}


EXTERN_C BOOL  
VIB_Close(
          DWORD Context
          ) 
{
    DEBUGMSG(ZONE_FUNCTION,(_T("Close(%x)\r\n"), Context));
    DEBUGCHK(Context == 1);
    
    return TRUE;
}


BOOL WINAPI
DllEntry(
         HANDLE hDllHandle, 
         DWORD  dwReason, 
         LPVOID lpreserved
         ) 
{
    BOOL bRc = TRUE;
    
    UNREFERENCED_PARAMETER(hDllHandle);
    UNREFERENCED_PARAMETER(lpreserved);
    
    switch (dwReason) {
    case DLL_PROCESS_ATTACH: 
        {
            DEBUGREGISTER((HINSTANCE) hDllHandle);
            DEBUGMSG(ZONE_INIT,(_T("*** DLL_PROCESS_ATTACH - Current Process: 0x%x, ID: 0x%x ***\r\n"),
                GetCurrentProcess(), GetCurrentProcessId()));
            RETAILMSG(1,(_T("*** DLL_PROCESS_ATTACH - Current Process: 0x%x, ID: 0x%x ***\r\n"),
                GetCurrentProcess(), GetCurrentProcessId()));
		
            DisableThreadLibraryCalls((HMODULE) hDllHandle);
            InitializeCriticalSection(&g_CsVibrator);
        } 
        break;
        
    case DLL_PROCESS_DETACH: 
        {
            DEBUGMSG(ZONE_INIT,(_T("*** DLL_PROCESS_DETACH - Current Process: 0x%x, ID: 0x%x ***\r\n"),
                GetCurrentProcess(), GetCurrentProcessId()));
            RETAILMSG(1,(_T("*** DLL_PROCESS_DETACH - Current Process: 0x%x, ID: 0x%x ***\r\n"),
                GetCurrentProcess(), GetCurrentProcessId()));
				
            DeleteCriticalSection(&g_CsVibrator);
        } 
        break;
        
    default:
        break;
    }
    
    return bRc;
}

⌨️ 快捷键说明

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