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

📄 snled.cpp

📁 LP1071 无线局域网卡WinCE驱动程序
💻 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.
//
//------------------------------------------------------------------------------
//
//  File:  Snled.cpp
//
//  Implementation of PDD layer of Notification LED(s)
//
//------------------------------------------------------------------------------
//
// Copyright (C) 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
//
//------------------------------------------------------------------------------

#include <windows.h>
#include <nled.h>
#include <led_drvr.h>
#include <types.h>
#include <bsp.h>
#include <bsp_cfg.h>
#include <nkintr.h>
 
//------------------------------------------------------------------------------
// Defines 
#define NLED_MAX_LED				2	// Total number of notification LEDs supported

//------------------------------------------------------------------------------
// Types
struct NLedPddContext
{
    HANDLE	hNLedBlinkThreadEvent;
    HANDLE	hNLedBlinkThreadStoppedEvent;
    BOOL         bLEDState;
    BOOL 		bLEDBlinkState;
    NLED_SETTINGS_INFO NLedSettingsInfo;
    NLED_SUPPORTS_INFO NLedSupportsInfo;
};

//------------------------------------------------------------------------------
// Local Variables 
static CSP_PBC_REGS *g_pPBC;
static NLedPddContext  g_NLedPddContext[NLED_MAX_LED];

//------------------------------------------------------------------------------
// Local Functions
VOID TurnOnLED(DWORD LEDNum);
VOID TurnOffLED(DWORD LEDNum);
DWORD WINAPI LEDBlinkThread(LPVOID lParam);

//-----------------------------------------------------------------------------
//
// Function: NLedDriverInitialize
//
// The NLED MDD calls this routine to initialize the underlying NLED hardware.
// This routine should return TRUE if successful.  If there's a problem
// it should return FALSE and call SetLastError() to pass back the reason
// for the failure.
//
//  Returns: 
//        This routine returns TRUE if successful, or FALSE if there's a problem
//
//-----------------------------------------------------------------------------

BOOL WINAPI NLedDriverInitialize(VOID)
{
    PHYSICAL_ADDRESS phyAddr;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("+NLedDriverInitialize: invoked\r\n")));

	
    g_pPBC = NULL;
    phyAddr.QuadPart = BSP_BASE_REG_PA_PBC_BASE;

    g_pPBC = (PCSP_PBC_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_PBC_REGS), FALSE);
    if (g_pPBC == NULL)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("%s(): MmMapIoSpace failed!\r\n"), __WFUNCTION__));       
        return FALSE;
    }

	
    // initialization NLedPddContext struct
    memset(&g_NLedPddContext, 0, NLED_MAX_LED * sizeof(NLedPddContext));

    //Setting NLED support Blink mode
    for(int i=0; i<NLED_MAX_LED; i++)
    {            
        g_NLedPddContext[i].NLedSupportsInfo.LedNum = 0;
        g_NLedPddContext[i].NLedSupportsInfo.fAdjustOffTime = TRUE;
        g_NLedPddContext[i].NLedSupportsInfo.fAdjustOnTime = TRUE;
        g_NLedPddContext[i].NLedSupportsInfo.fAdjustTotalCycleTime = FALSE;
        g_NLedPddContext[i].NLedSupportsInfo.lCycleAdjust = 1000;
        g_NLedPddContext[i].NLedSupportsInfo.fMetaCycleOff = FALSE;
        g_NLedPddContext[i].NLedSupportsInfo.fMetaCycleOn = FALSE;
    }


    for(int i=0; i<NLED_MAX_LED; i++)
    {		
        if((((g_NLedPddContext[i].hNLedBlinkThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) ||
        	(g_NLedPddContext[i].hNLedBlinkThreadStoppedEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL)) 
        {
            CloseHandle(g_NLedPddContext[i].hNLedBlinkThreadEvent);	
            CloseHandle(g_NLedPddContext[i].hNLedBlinkThreadStoppedEvent);
			
            while(i)
            {
                i--;
                CloseHandle(g_NLedPddContext[i].hNLedBlinkThreadEvent);	
                CloseHandle(g_NLedPddContext[i].hNLedBlinkThreadStoppedEvent);
            }

            MmUnmapIoSpace(g_pPBC, sizeof(CSP_PBC_REGS));
            
            DEBUGMSG(ZONE_ERROR,  (TEXT("NLedDriverInitialize: CreateEvent() Failed\r\n")));
            return FALSE;
        }
    }
	
    	
    for(int i=0; i<NLED_MAX_LED; i++)	TurnOffLED(i);    //Turn off all LED
    
    DEBUGMSG(ZONE_FUNCTION, (TEXT("-NLedDriverInitialize\r\n")));
    	 
    return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function: NLedDriverDeInitialize
//
// The NLED MDD calls this routine to deinitialize the underlying NLED
// hardware as the NLED driver is unloaded.  It should return TRUE if 
// successful.  If there's a problem this routine should return FALSE 
// and call SetLastError() to pass back the reason for the failure.
//
//  Returns: 
//        This routine returns TRUE if successful, or FALSE if there's a problem
//
//-----------------------------------------------------------------------------
BOOL WINAPI NLedDriverDeInitialize(VOID)
{
    DEBUGMSG(ZONE_FUNCTION, (TEXT("+NLedDriverDeInitialize: invoked\r\n")));
    
    for(int i=0; i<NLED_MAX_LED; i++)		// Stop all threads
        SetEvent(g_NLedPddContext[i].hNLedBlinkThreadEvent);
    
    
    for(int i=0; i<NLED_MAX_LED; i++)		// Wait for all threads to stop
    {
        if(g_NLedPddContext[i].bLEDBlinkState)
            WaitForSingleObject(g_NLedPddContext[i].hNLedBlinkThreadStoppedEvent, INFINITE);
    }	
    
    MmUnmapIoSpace(g_pPBC, sizeof(CSP_PBC_REGS));

    for(int i=0; i<NLED_MAX_LED; i++)
    {
        CloseHandle(g_NLedPddContext[i].hNLedBlinkThreadStoppedEvent);
        CloseHandle(g_NLedPddContext[i].hNLedBlinkThreadEvent);
    }
    
    DEBUGMSG(ZONE_FUNCTION, (TEXT("-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.  This
// routine returns TRUE if successful, or FALSE if there's a problem -- in
// which case it also calls SetLastError() to pass back more complete
// error information.  The NLED MDD invokes this routine when an application
// calls NLedGetDeviceInfo().
//
// 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_FUNCTION, (TEXT("+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
        {		
            p->fAdjustOffTime			= g_NLedPddContext[p->LedNum].NLedSupportsInfo.fAdjustOffTime;
            p->fAdjustOnTime			= g_NLedPddContext[p->LedNum].NLedSupportsInfo.fAdjustOnTime;
            p->lCycleAdjust			= g_NLedPddContext[p->LedNum].NLedSupportsInfo.lCycleAdjust;
            p->fMetaCycleOff			= g_NLedPddContext[p->LedNum].NLedSupportsInfo.fMetaCycleOff;
            p->fMetaCycleOn			= g_NLedPddContext[p->LedNum].NLedSupportsInfo.fMetaCycleOn;
            p->fAdjustTotalCycleTime	= g_NLedPddContext[p->LedNum].NLedSupportsInfo.fAdjustTotalCycleTime;
        }
    }	
    else if (nInfoId == NLED_SETTINGS_INFO_ID)
    {
        struct NLED_SETTINGS_INFO  *p = (struct NLED_SETTINGS_INFO*)pOutput;
        
        if(p->LedNum >= NLED_MAX_LED)			
            fOk = FALSE;
        else
        {		
            p->MetaCycleOff			= g_NLedPddContext[p->LedNum].NLedSettingsInfo.MetaCycleOff;
            p->MetaCycleOn			= g_NLedPddContext[p->LedNum].NLedSettingsInfo.MetaCycleOn;

⌨️ 快捷键说明

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