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

📄 snled.cpp

📁 freescale i.mx31 BSP CE5.0全部源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			p->fAdjustOffTime			= g_NLedPddParam[p->LedNum].NLedSupportsInfo.fAdjustOffTime;
			p->fAdjustOnTime 			= g_NLedPddParam[p->LedNum].NLedSupportsInfo.fAdjustOnTime;
			p->lCycleAdjust 				= g_NLedPddParam[p->LedNum].NLedSupportsInfo.lCycleAdjust;
			p->fMetaCycleOff 			= g_NLedPddParam[p->LedNum].NLedSupportsInfo.fMetaCycleOff;
			p->fMetaCycleOn 			= g_NLedPddParam[p->LedNum].NLedSupportsInfo.fMetaCycleOn;
			p->fAdjustTotalCycleTime	= g_NLedPddParam[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_NLedPddParam[p->LedNum].NLedSettingsInfo.MetaCycleOff;
			p->MetaCycleOn 		= g_NLedPddParam[p->LedNum].NLedSettingsInfo.MetaCycleOn;
			p->OffOnBlink 		= g_NLedPddParam[p->LedNum].NLedSettingsInfo.OffOnBlink;
			p->OffTime 			= g_NLedPddParam[p->LedNum].NLedSettingsInfo.OffTime;
			p->OnTime 			= g_NLedPddParam[p->LedNum].NLedSettingsInfo.OnTime;
			p->TotalCycleTime 	= g_NLedPddParam[p->LedNum].NLedSettingsInfo.TotalCycleTime;
		}	
	}	
	else
	{
		fOk = FALSE;
	}
			
	DEBUGMSG(ZONE_PDD || (!fOk && ZONE_WARN), (_T("%s: returning %d\r\n"), pszFname, fOk));		
    	DEBUGMSG(ZONE_PDD, (_T("-NLedDriverGetDeviceInfo\r\n")));
		
    	return (fOk);
}

//-----------------------------------------------------------------------------
//
// Function: NLedDriverSetDevice
//
// This routine changes the configuration of an LED.  The nInfoId parameter
// indicates what kind of configuration information is being changed.  
// Currently only the NLED_SETTINGS_INFO_ID value is supported.  The pInput
// parameter points to a buffer containing the data to be updated.  The size
// of the buffer depends on the value of nInfoId.
//
// Parameters:
//      InputParm 
//          [in] INT     	nInfoId
//          [in] PVOID 	pInput
//
// Returns:  
//      This routine returns TRUE if successful, or FALSE if there's a problem
//
//-----------------------------------------------------------------------------
BOOL WINAPI NLedDriverSetDevice(INT     nInfoId, PVOID   pInput)
{
    	DEBUGMSG(ZONE_PDD, (_T("+NLedDriverSetDevice\r\n")));
			
	HANDLE hThread = NULL;	
	struct NLED_SETTINGS_INFO *pNledSettingsInfo = (struct NLED_SETTINGS_INFO*)pInput;

	if(nInfoId != NLED_SETTINGS_INFO_ID)
	{
    		DEBUGMSG(ZONE_PDD, (_T("NLedDriverSetDevice: Invalid nInfoId\r\n")));	
		return FALSE;
	}
	
	if(pNledSettingsInfo->LedNum >= NLED_MAX_LED)	// Check LedNum validity
	{
    		DEBUGMSG(ZONE_PDD, (_T("NLedDriverSetDevice: Invalid LedNum\r\n")));	
		return FALSE;
	}

	if(pNledSettingsInfo->OffOnBlink > NLED_MAX_OFFONBLINK)	// Check OffOnBlink validity
	{
    		DEBUGMSG(ZONE_PDD, (_T("NLedDriverSetDevice: Invalid OffOnBlink\r\n")));
		return FALSE;
	}
	
	if(g_NLedPddParam[pNledSettingsInfo->LedNum].bNLedDriverSetDeviceThreadState)
	{
		SetEvent(g_NLedPddParam[pNledSettingsInfo->LedNum].hNLedStopThreadEvent);
		DEBUGMSG(ZONE_PDD, (_T("NLedDriverSetDevice: WaitForSingleObject - hNLedThreadStoppedEvent\r\n")));
		WaitForSingleObject(g_NLedPddParam[pNledSettingsInfo->LedNum].hNLedThreadStoppedEvent, INFINITE);
	}

	g_NLedPddParam[pNledSettingsInfo->LedNum].NLedSettingsInfo.LedNum = pNledSettingsInfo->LedNum;	
	g_NLedPddParam[pNledSettingsInfo->LedNum].NLedSettingsInfo.OffOnBlink = pNledSettingsInfo->OffOnBlink;
	
	if(!pNledSettingsInfo->OffOnBlink)	// OffOnBlink setting - OFF
	{	
		if(!pNledSettingsInfo->LedNum)
			OUTREG16(&g_pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_SET_LED0));
		else
			OUTREG16(&g_pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_CLEAR_LED1));

		g_NLedPddParam[pNledSettingsInfo->LedNum].bNledState = FALSE;			
	}	
	else if(pNledSettingsInfo->OffOnBlink == 1)  // OffOnBlink setting - ON
	{	
		if(!pNledSettingsInfo->LedNum)
			
      OUTREG16(&g_pPBC->BCTRL1_CLEAR, CSP_BITFMASK(PBC_BCTRL1_CLEAR_LED0));	
		else
			OUTREG16(&g_pPBC->BCTRL1_CLEAR, CSP_BITFMASK(PBC_BCTRL1_SET_LED1));
			
		g_NLedPddParam[pNledSettingsInfo->LedNum].bNledState = TRUE;
	}
	else // OffOnBlink setting - BLINK
	{
		UINT Index = pNledSettingsInfo->LedNum;
			
		g_NLedPddParam[Index].bNLedDriverSetDeviceThreadState = TRUE;

		g_NLedPddParam[Index].NLedSettingsInfo = *(pNledSettingsInfo);

		// Round up OnTime and OffTime values 1 millisecond
		if(g_NLedPddParam[Index].NLedSettingsInfo.OnTime < 1000)
			g_NLedPddParam[Index].NLedSettingsInfo.OnTime = 1000;
	
		if(g_NLedPddParam[Index].NLedSettingsInfo.OffTime < 1000)
			g_NLedPddParam[Index].NLedSettingsInfo.OffTime = 1000;	

    		hThread =	CreateThread(
     	        				NULL,                  					// Default thread security descriptor
          					0,                     					// Default stack size
          					NLedDriverSetDeviceThread,	// Start routine
          					&g_NLedPddParam[Index].NLedSettingsInfo,           		// Start routine parameter
          					0,                     					// Run immediately
          					NULL            						// Thread ID
          				);

		if (hThread == NULL)
    		{
			g_NLedPddParam[Index].bNLedDriverSetDeviceThreadState = FALSE;
			return FALSE;
    		}
		
		CloseHandle(hThread);	
	}
				
    	DEBUGMSG(ZONE_PDD, (_T("-NLedDriverSetDevice\r\n")));
	
    	return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function: NLedDriverPowerDown
//
// This routine is invoked by the driver MDD when the system suspends or
// resumes.  The power_down flag indicates whether the system is powering 
// up or powering down.
//
// Parameters:
//      InputParm 
//          [in] BOOL power_down
//
// Returns:  
//      	None
//
//-----------------------------------------------------------------------------
VOID WINAPI NLedDriverPowerDown(BOOL power_down)
{
    	DEBUGMSG(ZONE_PDD, (_T("+NLedDriverPowerDown\r\n")));
	
	if(!power_down)
	{		
		for(int i=0; i<NLED_MAX_LED; i++)
		{
			if(!i)
			{
				if(!g_NLedPddParam[i].bNledState )
			  		OUTREG16(&g_pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_SET_LED0));	
				else
			  		OUTREG16(&g_pPBC->BCTRL1_CLEAR, CSP_BITFMASK(PBC_BCTRL1_CLEAR_LED0));				
			}
			else
			{
				if(!g_NLedPddParam[i].bNledState )
			  		OUTREG16(&g_pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_SET_LED1));		
				else
			  		OUTREG16(&g_pPBC->BCTRL1_CLEAR, CSP_BITFMASK(PBC_BCTRL1_CLEAR_LED1));						  		
			}
		}	
	}
	else
	{

		for(int i=0; i<NLED_MAX_LED; i++)
		{
			if(!i)
				OUTREG16(&g_pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_CLEAR_LED0));			
			else
				OUTREG16(&g_pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_CLEAR_LED1));			
		}	
	}

    	DEBUGMSG(ZONE_PDD, (_T("-NLedDriverPowerDown\r\n")));
		
    	return;
}

//-----------------------------------------------------------------------------
//
// Function: NLedDriverSetDeviceThread
//
// This routine is invoked by CreateThread() function in NLedDriverSetDevice when
// caller attempts to change the configuration of a notification LED to 'Blink' mode
//
// Parameters:
//      InputParm 
//          [in] LPVOID lParam
//
// Returns:  
//      This routine returns 0
//
//-----------------------------------------------------------------------------
DWORD WINAPI NLedDriverSetDeviceThread(LPVOID lParam)
{	
    	DEBUGMSG(ZONE_PDD, (_T("+NLedDriverSetDeviceThread\r\n")));

	NLED_SETTINGS_INFO *pNledSettingsInfo = (struct NLED_SETTINGS_INFO*)lParam;
	UINT Index = pNledSettingsInfo->LedNum;
	DWORD OnTimeOut = (DWORD)(pNledSettingsInfo->OnTime/1000);	// to convert micro to milli-seconds 
	DWORD OffTimeOut = (DWORD)(pNledSettingsInfo->OffTime/1000);	// to convert micro to milli-seconds 
		
	while(1)
	{		
		if(!Index)		
    			
    			OUTREG16(&g_pPBC->BCTRL1_CLEAR, CSP_BITFMASK(PBC_BCTRL1_CLEAR_LED0));
		else		
			OUTREG16(&g_pPBC->BCTRL1_CLEAR, CSP_BITFMASK(PBC_BCTRL1_SET_LED1));
			
		g_NLedPddParam[Index].bNledState = TRUE;

		if(WaitForSingleObject(g_NLedPddParam[Index].hNLedStopThreadEvent, OnTimeOut) == WAIT_OBJECT_0)		
			break;

		if(!Index)		
			
			OUTREG16(&g_pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_SET_LED0));
		else		
			OUTREG16(&g_pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_CLEAR_LED1));			
	
		g_NLedPddParam[Index].bNledState = FALSE;

		if(WaitForSingleObject(g_NLedPddParam[Index].hNLedStopThreadEvent, OffTimeOut) == WAIT_OBJECT_0)			
			break;

	}
	
	pNledSettingsInfo->LedNum = 0;
	pNledSettingsInfo->MetaCycleOff = 0;
	pNledSettingsInfo->MetaCycleOn = 0;
	pNledSettingsInfo->OffOnBlink = 0;
	pNledSettingsInfo->OffTime = 0;
	pNledSettingsInfo->OnTime = 0;
	pNledSettingsInfo->TotalCycleTime = 0;
	
	SetEvent(g_NLedPddParam[Index].hNLedThreadStoppedEvent);

	g_NLedPddParam[Index].bNLedDriverSetDeviceThreadState = FALSE;

    	DEBUGMSG(ZONE_PDD, (_T("-NLedDriverSetDeviceThread\r\n")));

	return 0;
}

⌨️ 快捷键说明

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