📄 dvfc.c
字号:
//------------------------------------------------------------------------------
//
// 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
//
//------------------------------------------------------------------------------
//
// File: dvfc.c
//
// This file contains driver support for the DPTC power
// management features of the SoC.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <ceddk.h>
#include "csp.h"
#include "dvfc.h"
//-----------------------------------------------------------------------------
// External Functions
extern BOOL BSPDvfcInit(void);
extern BOOL BSPDvfcDeinit(void);
extern void BSPDvfcIntrServ(void);
extern BOOL BSPDvfcPowerSet(CEDEVICE_POWER_STATE dx);
extern void BSPSetVoltage(UINT8 Volt);
extern UINT8 BSPGetVoltage();
//-----------------------------------------------------------------------------
// External Variables
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
// Types
#ifdef DEBUG
DBGPARAM dpCurSettings = {
_T("DVFC"),
{
TEXT("Errors"), TEXT("Warnings"), TEXT("Init"), TEXT("Func"),
TEXT("Info"), TEXT(""), TEXT(""), TEXT(""),
TEXT(""),TEXT(""),TEXT(""),TEXT(""),
TEXT(""),TEXT(""),TEXT(""),TEXT("")
},
ZONEMASK_ERROR | ZONEMASK_WARN // ulZoneMask
};
#endif
//-----------------------------------------------------------------------------
// Global Variables
PCSP_PLLCRC_REGS g_pPLLCRC;
PCSP_SYSCTRL_REGS g_pSYSCTRL;
HANDLE g_hDvfcIntrEvent;
//-----------------------------------------------------------------------------
// Local Variables
static DWORD g_dwDvfcSysIntr;
static HANDLE g_hDvfcIntrServThread;
static CEDEVICE_POWER_STATE g_dxCurrent = D0;
static PCSP_AITC_REGS g_pAITC;
//-----------------------------------------------------------------------------
// Local Functions
static DWORD WINAPI DvfcIntrServThread (LPVOID lpParam);
void PM_LowPowerMode(Low_Power_Mode Mode);
//-----------------------------------------------------------------------------
//
// Function: DllEntry
//
// This function is an optional method of entry into a DLL. If the function
// is used, it is called by the system when processes and threads are
// initialized and terminated, or on calls to the LoadLibrary and
// FreeLibrary functions.
//
// Parameters:
// hinstDLL
// [in] Handle to the DLL. The value is the base address of the DLL.
//
// dwReason
// [in] Specifies a flag indicating why the DLL entry-point function
// is being called.
//
// lpvReserved
// [in] Specifies further aspects of DLL initialization and cleanup.
// If dwReason is DLL_PROCESS_ATTACH, lpvReserved is NULL for
// dynamic loads and nonnull for static loads. If dwReason is
// DLL_PROCESS_DETACH, lpvReserved is NULL if DllMain is called
// by using FreeLibrary and nonnull if DllMain is called during
// process termination.
//
// Returns:
// When the system calls the DllMain function with the
// DLL_PROCESS_ATTACH value, the function returns TRUE if it
// succeeds or FALSE if initialization fails.
//
// If the return value is FALSE when DllMain is called because the
// process uses the LoadLibrary function, LoadLibrary returns NULL.
//
// If the return value is FALSE when DllMain is called during
// process initialization, the process terminates with an error.
//
// When the system calls the DllMain function with a value other
// than DLL_PROCESS_ATTACH, the return value is ignored.
//
//-----------------------------------------------------------------------------
BOOL WINAPI DllEntry(HINSTANCE hDllHandle, DWORD dwReason,
LPVOID lpreserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls((HMODULE) hDllHandle);
break;
case DLL_PROCESS_DETACH:
break;
default:
break;
}
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: Init
//
// This function initializes the DVFC driver. Called by the Device Manager to
// initialize a device.
//
// Parameters:
// None.
//
// Returns:
// Returns TRUE if successful, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL DVF_Init(void)
{
BOOL rc = FALSE;
PHYSICAL_ADDRESS phyAddr;
DWORD irq;
// Map CCM for access to DCVR and PMCR registers
if (g_pSYSCTRL == NULL)
{
phyAddr.QuadPart = CSP_BASE_REG_PA_SYSCTRL;
// Map peripheral physical address to virtual address
g_pSYSCTRL = (PCSP_SYSCTRL_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_SYSCTRL_REGS),
FALSE);
// Check if virtual mapping failed
if (g_pSYSCTRL == NULL)
{
ERRORMSG(TRUE, (_T("MmMapIoSpace failed!\r\n")));
goto cleanUp;
}
}
// Map PLL for access to PLL registers
if (g_pPLLCRC == NULL)
{
phyAddr.QuadPart = CSP_BASE_REG_PA_CRM;
// Map peripheral physical address to virtual address
g_pPLLCRC = (PCSP_PLLCRC_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_PLLCRC_REGS),
FALSE);
// Check if virtual mapping failed
if (g_pPLLCRC == NULL)
{
ERRORMSG(TRUE, (_T("MmMapIoSpace failed!\r\n")));
goto cleanUp;
}
}
// Disable the DPTC
INSREG32BF(&g_pSYSCTRL->PMCR, SYSCTRL_PMCR_DPTEN, SYSCTRL_PMCR_DPTEN_DPTC_DISABLE);
// Translate IRQ into SYSINTR
irq = IRQ_DPTC;
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &irq, sizeof(irq),
&g_dwDvfcSysIntr, sizeof(g_dwDvfcSysIntr), NULL))
{
ERRORMSG(TRUE, (_T("IOCTL_HAL_REQUEST_SYSINTR failed for IRQ_CCM!\r\n")));
goto cleanUp;
}
// Create event for IST signaling
g_hDvfcIntrEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!g_hDvfcIntrEvent)
{
ERRORMSG(TRUE, (_T("CreateEvent failed for DVFC IST signal!\r\n")));
goto cleanUp;
}
// Register interrupt
if (!InterruptInitialize(g_dwDvfcSysIntr, g_hDvfcIntrEvent, NULL, 0))
{
ERRORMSG(TRUE, (_T("InterruptInitialize failed for DVFC SYSINTR!\r\n")));
goto cleanUp;
}
// Allow platform-specific DVFC initialization
if (!BSPDvfcInit())
{
ERRORMSG(TRUE, (_T("BSPDvfcInit failed!\r\n")));
goto cleanUp;
}
// Create IST for DVFC interrupts
g_hDvfcIntrServThread = CreateThread(NULL, 0, DvfcIntrServThread, NULL, 0, NULL);
if (!g_hDvfcIntrServThread)
{
ERRORMSG(TRUE, (_T("CreateThread failed for DVFC IST!\r\n")));
goto cleanUp;
}
// Route DVFC interrupts to MCU
INSREG32BF(&g_pSYSCTRL->PMCR, SYSCTRL_PMCR_DIE, SYSCTRL_PMCR_DIE_DPTC_ENABLE);
// RETAILMSG(TRUE, (_T("PMCR = 0x%x\r\n"), INREG32(&g_pSYSCTRL->PMCR)));
rc = TRUE;
cleanUp:
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: Deinit
//
// This function deinitializes the DPTC. Called by the Device Manager to
// deinitialize a device.
//
// Parameters:
// None.
//
// Returns:
// Returns TRUE.
//
//-----------------------------------------------------------------------------
BOOL DVF_Deinit(void)
{
BOOL rc;
rc = BSPDvfcDeinit();
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: Open
//
// This function opens a device for reading, writing, or both. An application
// indirectly invokes this function when it calls the CreateFile function to
// open special device file names.
//
// Parameters:
// hDeviceContext
// [in] Handle to the device context. The XXX_Init function creates
// and returns this handle.
// AccessCode
// [in] Access code for the device. The access is a combination of
// read and write access from CreateFile.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -