📄 snled.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: Snled.cpp
//
// Implementation of PDD layer of Notification LED(s)
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <nled.h>
#include <led_drvr.h>
#include <types.h>
#include <bsp.h>
#include <bsp_cfg.h>
#include <nkintr.h>
//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
#define NLED_MAX_LED 1 // Total number of notification LEDs supported
#define NLED_MAX_OFFONBLINK 2 // Max OffOnBlink value
//------------------------------------------------------------------------------
// Types
struct NLedPddParameters
{
HANDLE hNLedStopThreadEvent;
HANDLE hNLedThreadStoppedEvent;
BOOL bNledState;
BOOL bNLedDriverSetDeviceThreadState;
NLED_SETTINGS_INFO NLedSettingsInfo;
NLED_SUPPORTS_INFO NLedSupportsInfo;
};
//------------------------------------------------------------------------------
// Global Variables
static CSP_PBC_REGS *g_pPBC;
static NLedPddParameters g_NLedPddParam[NLED_MAX_LED];
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
DWORD WINAPI NLedDriverSetDeviceThread(LPVOID lParam);
//-----------------------------------------------------------------------------
//
// Function: NLedDriverInitialize
//
// This routine initializes the underlying NLED hardware as the NLED driver is loaded.
//
// Parameters:
// None
//
// Returns:
// This routine should return TRUE if successful. If there's a problem
// it should return FALSE
//
//-----------------------------------------------------------------------------
BOOL WINAPI NLedDriverInitialize(VOID)
{
DEBUGMSG(ZONE_PDD, (_T("+NLedDriverInitialize: invoked\r\n")));
g_pPBC = NULL;
for(int i=0; i<NLED_MAX_LED; i++)
{
g_NLedPddParam[i].bNledState = FALSE;
g_NLedPddParam[i].bNLedDriverSetDeviceThreadState = FALSE;
g_NLedPddParam[i].hNLedStopThreadEvent = NULL;
g_NLedPddParam[i].hNLedThreadStoppedEvent = NULL;
g_NLedPddParam[i].NLedSettingsInfo.LedNum = 0;
g_NLedPddParam[i].NLedSettingsInfo.MetaCycleOff = 0;
g_NLedPddParam[i].NLedSettingsInfo.MetaCycleOn = 0;
g_NLedPddParam[i].NLedSettingsInfo.OffOnBlink = 0;
g_NLedPddParam[i].NLedSettingsInfo.OffTime = 0;
g_NLedPddParam[i].NLedSettingsInfo.OnTime = 0;
g_NLedPddParam[i].NLedSettingsInfo.TotalCycleTime = 0;
g_NLedPddParam[i].NLedSupportsInfo.LedNum = 0;
g_NLedPddParam[i].NLedSupportsInfo.fAdjustOffTime = TRUE;
g_NLedPddParam[i].NLedSupportsInfo.fAdjustOnTime = TRUE;
g_NLedPddParam[i].NLedSupportsInfo.fAdjustTotalCycleTime = FALSE;
g_NLedPddParam[i].NLedSupportsInfo.lCycleAdjust = 1000;
g_NLedPddParam[i].NLedSupportsInfo.fMetaCycleOff = FALSE;
g_NLedPddParam[i].NLedSupportsInfo.fMetaCycleOn = FALSE;
}
for(int i=0; i<NLED_MAX_LED; i++)
{
if((g_NLedPddParam[i].hNLedStopThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL)
{
while(i)
{
i--;
CloseHandle(g_NLedPddParam[i].hNLedStopThreadEvent);
}
DEBUGMSG(ZONE_PDD, (_T("NLedDriverInitialize: CreateEvent() hNLedStopThreadEvent Failed\r\n")));
return FALSE;
}
}
for(int i=0; i<NLED_MAX_LED; i++)
{
if((g_NLedPddParam[i].hNLedThreadStoppedEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL)
{
while(i)
{
i--;
CloseHandle(g_NLedPddParam[i].hNLedThreadStoppedEvent);
}
DEBUGMSG(ZONE_PDD, (_T("NLedDriverInitialize: CreateEvent() hNLedThreadStoppedEvent Failed\r\n")));
return FALSE;
}
}
g_pPBC = (PCSP_PBC_REGS) VirtualAlloc(NULL, sizeof(CSP_PBC_REGS), MEM_RESERVE, PAGE_READWRITE);
if (g_pPBC == NULL)
{
DEBUGMSG(ZONE_PDD, (_T("NLedDriverSetDeviceThread: VirtualAlloc() Failed\r\n")));
for(int i=0; i<NLED_MAX_LED; i++)
{
CloseHandle(g_NLedPddParam[i].hNLedStopThreadEvent);
CloseHandle(g_NLedPddParam[i].hNLedThreadStoppedEvent);
}
return FALSE;
}
if (!VirtualCopy((LPVOID) g_pPBC, (LPVOID)(BSP_BASE_REG_PA_PBC_BASE/256), sizeof(CSP_PBC_REGS), (PAGE_READWRITE|PAGE_PHYSICAL)))
{
DEBUGMSG(ZONE_PDD, (_T("NLedDriverSetDeviceThread: VirtualCopy() Failed\r\n")));
for(int i=0; i<NLED_MAX_LED; i++)
{
CloseHandle(g_NLedPddParam[i].hNLedStopThreadEvent);
CloseHandle(g_NLedPddParam[i].hNLedThreadStoppedEvent);
}
if(!VirtualFree(g_pPBC, 0, MEM_RELEASE))
DEBUGMSG(ZONE_PDD, (_T("NLedDriverSetDeviceThread: VirtualFree() Failed\r\n")));
return FALSE;
}
for(int i=0; i<NLED_MAX_LED; i++)
{
if(!i)
OUTREG16(&g_pPBC->BCTRL1_CLEAR, CSP_BITFMASK(PBC_BCTRL1_CLEAR_LED0)); // Turn Off LED0
else
OUTREG16(&g_pPBC->BCTRL1_CLEAR, CSP_BITFMASK(PBC_BCTRL1_CLEAR_LED1)); // Turn Off LED1
}
DEBUGMSG(ZONE_PDD, (_T("-NLedDriverInitialize\r\n")));
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: NLedDriverDeInitialize
//
// This routine deinitializes the underlying NLED hardware as the NLED driver is unloaded.
//
// Parameters:
// None
//
// Returns:
// This routine returns TRUE if successful, or FALSE if there's a problem
//
//-----------------------------------------------------------------------------
BOOL WINAPI NLedDriverDeInitialize(VOID)
{
DEBUGMSG(ZONE_PDD, (_T("+NLedDriverDeInitialize: invoked\r\n")));
for(int i=0; i<NLED_MAX_LED; i++) // Stop all threads
SetEvent(g_NLedPddParam[i].hNLedStopThreadEvent);
for(int i=0; i<NLED_MAX_LED; i++) // Wait for all threads to stop
{
if(g_NLedPddParam[i].bNLedDriverSetDeviceThreadState)
WaitForSingleObject(g_NLedPddParam[i].hNLedThreadStoppedEvent, INFINITE);
}
if(!VirtualFree(g_pPBC, 0, MEM_RELEASE))
DEBUGMSG(ZONE_PDD, (_T("NLedDriverDeInitialize: VirtualFree() Failed\r\n")));
for(int i=0; i<NLED_MAX_LED; i++)
{
CloseHandle(g_NLedPddParam[i].hNLedThreadStoppedEvent);
CloseHandle(g_NLedPddParam[i].hNLedStopThreadEvent);
}
DEBUGMSG(ZONE_PDD, (_T("-NLedDriverDeInitialize\r\n")));
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: NLedDriverGetDeviceInfo
//
// This routine retrieves information about the NLED device(s) that
// this driver supports. The nInfoId parameter indicates what specific
// information is being queried and pOutput is a buffer to be filled in.
// The size of pOutput depends on the type of data being requested.
//
// Parameters:
// InputParm
// [in] INT nInfoId
//
// OutputParm
// [out] PVOID pOutput
//
// Returns:
// This routine returns TRUE if successful, or FALSE if there's a problem
//
//-----------------------------------------------------------------------------
BOOL WINAPI NLedDriverGetDeviceInfo(
INT nInfoId,
PVOID pOutput
)
{
DEBUGMSG(ZONE_PDD, (_T("+NLedDriverGetDeviceInfo\r\n")));
BOOL fOk = TRUE;
SETFNAME(_T("NLedDriverGetDeviceInfo"));
if(nInfoId == NLED_COUNT_INFO_ID)
{
struct NLED_COUNT_INFO *p = (struct NLED_COUNT_INFO*)pOutput;
p -> cLeds = NLED_MAX_LED;
}
else if (nInfoId == NLED_SUPPORTS_INFO_ID)
{
struct NLED_SUPPORTS_INFO *p = (struct NLED_SUPPORTS_INFO*)pOutput;
if(p->LedNum >= NLED_MAX_LED)
fOk = FALSE;
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -