📄 dvfc.c
字号:
// ShareMode
// [in] File share mode of the device. The share mode is a
// combination of read and write access sharing from CreateFile.
//
// Returns:
// This function returns a handle that identifies the open context of
// the device to the calling application.
//
//-----------------------------------------------------------------------------
DWORD DVF_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
return hDeviceContext;
}
//-----------------------------------------------------------------------------
//
// Function: Close
//
// This function closes a device context created by the hOpenContext
// parameter.
//
// Parameters:
// hOpenContext
// [in] Handle returned by the XXX_Open function, used to identify
// the open context of the device.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//-----------------------------------------------------------------------------
BOOL DVF_Close(DWORD hOpenContext)
{
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: IOControl
//
// This function sends a command to the DVFC driver.
//
// Parameters:
// hOpenContext
// [in] Handle to the open context of the device. The XXX_Open
// (Device Manager) function creates and returns this identifier.
//
// dwCode
// [in] I/O control operation to perform.
//
// pBufIn
// [in] Pointer to the buffer containing data to transfer to the
// device.
//
// dwLenIn
// [in] Number of bytes of data in the buffer specified for pBufIn.
//
// pBufOut
// [out] Pointer to the buffer used to transfer the output data from
// the device.
//
// dwLenOut
// [in] Maximum number of bytes in the buffer specified by pBufOut.
//
// pdwActualOut
// [out] Pointer to the DWORD buffer that this function uses to
// return the actual number of bytes received from the device.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//-----------------------------------------------------------------------------
BOOL DVF_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn,
PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)
{
BOOL rc;
DWORD dwErr = ERROR_INVALID_PARAMETER;
PPOWER_CAPABILITIES ppc;
CEDEVICE_POWER_STATE dx;
switch (dwCode)
{
case IOCTL_POWER_CAPABILITIES:
// Tell the power manager about ourselves.
if (pBufOut != NULL
&& dwLenOut >= sizeof(POWER_CAPABILITIES)
&& pdwActualOut != NULL)
{
__try
{
ppc = (PPOWER_CAPABILITIES) pBufOut;
memset(ppc, 0, sizeof(*ppc));
ppc->DeviceDx = DX_MASK(D0) | DX_MASK(D4);
*pdwActualOut = sizeof(*ppc);
dwErr = ERROR_SUCCESS;
}
__except(EXCEPTION_EXECUTE_HANDLER) {
ERRORMSG(TRUE, (_T("Exception in DVFC IOCTL_POWER_CAPABILITIES\r\n")));
}
}
break;
case IOCTL_POWER_SET:
if(pBufOut != NULL
&& dwLenOut == sizeof(CEDEVICE_POWER_STATE)
&& pdwActualOut != NULL)
{
__try
{
dx = *(PCEDEVICE_POWER_STATE) pBufOut;
if(VALID_DX(dx))
{
// Any request that is not D0 becomes a D4 request
if(dx != D0)
{
dx = D4;
}
*(PCEDEVICE_POWER_STATE) pBufOut = dx;
*pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
if (BSPDvfcPowerSet(dx))
{
g_dxCurrent = dx;
dwErr = ERROR_SUCCESS;
}
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
ERRORMSG(TRUE, (_T("Exception in DVFC IOCTL_POWER_SET\r\n")));
}
}
break;
case IOCTL_POWER_GET:
if(pBufOut != NULL
&& dwLenOut == sizeof(CEDEVICE_POWER_STATE)
&& pdwActualOut != NULL) {
// Just return our current Dx value
__try
{
*(PCEDEVICE_POWER_STATE) pBufOut = g_dxCurrent;
*pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
dwErr = ERROR_SUCCESS;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
ERRORMSG(TRUE, (_T("Exception in DVFC IOCTL_POWER_SET\r\n")));
}
}
break;
case PM_IOCTL_LowPowerMode:
PM_LowPowerMode(*pBufIn);
DEBUGMSG(ZONE_IOCTL, (TEXT("DVF_IOControl: PM_IOCTL_LowPowerMode occurred\r\n")));
break;
default:
ERRORMSG(TRUE, (_T("%s: Unsupported DVFC IOCTL code %u\r\n"), dwCode));
dwErr = ERROR_NOT_SUPPORTED;
break;
}
// Pass back appropriate response codes
SetLastError(dwErr);
if(dwErr != ERROR_SUCCESS)
{
rc = FALSE;
}
else
{
rc = TRUE;
}
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: DvfcIntrServThread
//
// This is the interrupt service thread for DPTC interrupts.
// deinitialize a device.
//
// Parameters:
// lpParam
// [in] Thread data passed to the function using the
// lpParameter parameter of the CreateThread function. Not used.
//
// Returns:
// Returns thread exit code.
//
//-----------------------------------------------------------------------------
static DWORD WINAPI DvfcIntrServThread (LPVOID lpParam)
{
DWORD rc = TRUE;
CeSetThreadPriority(GetCurrentThread(), 250);
while(TRUE)
{
if(WaitForSingleObject(g_hDvfcIntrEvent, INFINITE) == WAIT_OBJECT_0)
{
// RETAILMSG(1, (TEXT("#")));
BSPDvfcIntrServ();
InterruptDone(g_dwDvfcSysIntr);
}
else
{
// Abnormal signal
rc = FALSE;
break;
}
}
return rc;
}
///------------------------------------------------------------------------------
// Function: PM_LowPowerMode
//
// This function implements steps to transition to low-power mode.
//
// Parameters:
// Mode:
// [in] Mode to be set;
//
/// Returns:
// None
//
//------------------------------------------------------------------------------
void PM_LowPowerMode(Low_Power_Mode Mode)
{
PHYSICAL_ADDRESS phyAddr;
phyAddr.QuadPart = CSP_BASE_REG_PA_AITC;
g_pAITC = (PCSP_AITC_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_AITC_REGS), FALSE);
if (g_pAITC == NULL)
{
return;
}
// SetKMode(TRUE);
OUTREG32(&g_pAITC->INTENABLEH,0);
OUTREG32(&g_pAITC->INTENABLEL,0);
OUTREG32(&g_pAITC->INTDISNUM,IRQ_WDOG);
OUTREG32(&g_pAITC->INTENNUM,IRQ_KPP);//Enable Keypad as a default Wake-up
switch (Mode)
{
case DOZE_Mode:
break;
case SLEEP_Mode:
g_pPLLCRC->CSCR &= ~(CSP_BITFMASK(PLLCRC_CSCR_MPEN));
break;
default:
break;
}
_MoveToCoprocessor(0, 15, 0, 7, 0, 4);
// SetKMode(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -