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

📄 clock.c

📁 Xcale270Bsp包,wince平台
💻 C
字号:
#include <windef.h>
#include <windows.h>
#include <types.h>
#include "cken.h"
#include "xsc1.h"


#define CLK_MUTEX_NAME			TEXT("CLKBITS")
#define CLK_REG_MUTEX_TIMEOUT	1000

BOOL StartClock(unsigned int,BOOL);
BOOL StopClock(unsigned int,BOOL);
unsigned int GetClock(BOOL inpowerhandler);
extern PVOID VirtualAllocCopy(unsigned ,char *,PVOID );

/*************************************************************************************
* Function: StartClock
* 
* Purpose:  Given a peripheral, this function enables the clock for that peripheral.
*			parameter 2 indicates if this function were called from a power handler or not.
*			TRUE indicates we are in power handler and FALSE otherwise.
*
* Returns:  Returns FALSE on failure to start the clock returns TRUE on a success. 
*
**************************************************************************************/

BOOL StartClock(unsigned int clkBits,BOOL inpowerhandler)
{
	volatile XLLP_CLKMGR_T *v_pClockRegs;
	HANDLE hClkMutex;

	// RETAILMSG(1,(TEXT("Inside Start Clock.\r\n")));

	v_pClockRegs = (volatile XLLP_CLKMGR_T *) VirtualAllocCopy(0x400,(char *)TEXT("inside start clock vAllocCopy"),
											(PVOID)CLK_BASE_U_VIRTUAL);

	if(	v_pClockRegs == NULL)
		return(FALSE);
		
    if (!inpowerhandler)
	{
	    if ((hClkMutex = CreateMutex(NULL, FALSE, CLK_MUTEX_NAME)) == NULL)
		{
	        NKDbgPrintfW(TEXT("Error %u in CLK CreateMutex\r\n"),GetLastError());
			return(FALSE);
	    }
    }

	/* Enter critical section */
    if (!inpowerhandler)
     	WaitForSingleObject(hClkMutex, CLK_REG_MUTEX_TIMEOUT);

	if (!(v_pClockRegs->cken & clkBits))
	  v_pClockRegs->cken |= clkBits;		// Start the clock here

	if (!inpowerhandler)
     	ReleaseMutex(hClkMutex);		// leave critical section
	
	if(v_pClockRegs)
	   VirtualFree((void *)v_pClockRegs,0x400,MEM_RELEASE);

	return (TRUE);
}

/*************************************************************************************
* Function: StopClock
* 
* Purpose: Given a peripheral, this function disables the clock for that peripheral.
*		   parameter 2 indicates if this function were called from a power handler or not.
*		   TRUE indicates we are in power handler and FALSE otherwise.
*
* Returns: Returns FALSE on failure to stop the clock returns TRUE on a success. 
*
**************************************************************************************/

BOOL StopClock(unsigned int clkBits,BOOL inpowerhandler)
{
	volatile XLLP_CLKMGR_T *v_pClockRegs=NULL;
	HANDLE hClkMutex;

	v_pClockRegs = (volatile XLLP_CLKMGR_T *) VirtualAllocCopy(0x400,(char *)TEXT("inside start clock vAllocCopy"),
											(PVOID)CLK_BASE_U_VIRTUAL);

	if(	v_pClockRegs == NULL)
		return(FALSE);

    if (!inpowerhandler)
	{
	    if ((hClkMutex = CreateMutex(NULL, FALSE, CLK_MUTEX_NAME)) == NULL)
		{
	        NKDbgPrintfW(TEXT("Error %u in CLK CreateMutex\r\n"),GetLastError());
			return(FALSE);
	    }
    }

	/* Enter critical section */
    if (!inpowerhandler)
     	WaitForSingleObject(hClkMutex, CLK_REG_MUTEX_TIMEOUT);

    if (v_pClockRegs->cken & clkBits)
	    v_pClockRegs->cken &= ~clkBits;		// Stop the Clock here

	if (!inpowerhandler)
     	ReleaseMutex(hClkMutex);		// leave critical section

	if(v_pClockRegs)
	   VirtualFree((void *)v_pClockRegs,0x400,MEM_RELEASE);


	return (TRUE);
}

/*************************************************************************************
* Function: GetClock
* 
* Purpose: Given a peripheral, this function returns the status of the clock for the peripheral.
*		   parameter 1 indicates if this function were called from a power handler or not.
*		   TRUE indicates we are in power handler and FALSE otherwise.
*
*
**************************************************************************************/

unsigned int GetClock(BOOL inpowerhandler)
{
	volatile XLLP_CLKMGR_T *v_pClockRegs=NULL;
	HANDLE hClkMutex;
	unsigned int clkBits = 0;

	v_pClockRegs = (volatile XLLP_CLKMGR_T *) VirtualAllocCopy(0x400,(char *)TEXT("inside start clock vAllocCopy"),
											(PVOID)CLK_BASE_U_VIRTUAL);

	if(	v_pClockRegs == NULL)
		return(FALSE);

    if (!inpowerhandler)
	{
	    if ((hClkMutex = CreateMutex(NULL, FALSE, CLK_MUTEX_NAME)) == NULL)
		{
	        NKDbgPrintfW(TEXT("Error %u in CLK CreateMutex\r\n"),GetLastError());
			return(FALSE);
	    }
    }

	/* Enter critical section */
    if (!inpowerhandler)
     	WaitForSingleObject(hClkMutex, CLK_REG_MUTEX_TIMEOUT);

    clkBits = v_pClockRegs->cken; 	    //Get the status of CKEN here

	if (!inpowerhandler)
     	ReleaseMutex(hClkMutex);		// leave critical section

	if(v_pClockRegs)
	   VirtualFree((void *)v_pClockRegs,0x400,MEM_RELEASE);


	return (clkBits);
}

⌨️ 快捷键说明

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