📄 pmicpdk.c
字号:
//-----------------------------------------------------------------------------
//
// Function: BSPPmicPowerNotifyResume
//
// Handler for notification of system resume.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
VOID BSPPmicPowerNotifyResume(void)
{
UINT32 stat1, msk1;
GetRegister(MC13783_INT_STAT1_ADDR, &stat1);
GetRegister(MC13783_INT_MSK1_ADDR, &msk1);
// If ON1 button interrupt is pending, it must be the wake
// source. Force the PmicButtonServThread to use the resume
// from ON1 button logic
if (stat1 & MC13783_ON1_BUTTON_MASK)
{
return;
}
// If ON1 button interrupt has been masked by PMIC IST,
// it must be the wake source. Force the PmicButtonServThread
// to use the resume from ON1 button logic
if (msk1 & MC13783_ON1_BUTTON_MASK)
{
return;
}
// Otherwise, some other wake source must have caused us to
// resume. Rearm the PmicButtonServThread to recognize the
// next ON1 button press.
g_bSuspended = FALSE;
}
//-----------------------------------------------------------------------------
//
// Function: PmicButtonServThread
//
// This is the service thread for processing PMIC button presses.
//
// 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 PmicButtonServThread (LPVOID lpParam)
{
DWORD rc = TRUE;
BOOL retVal = TRUE;
static BOOL bWaitButtonUp = FALSE;
UINT32 pwrButtonState;
while(TRUE)
{
switch (WaitForMultipleObjects(3, g_hPmicButtonEvent, FALSE, INFINITE))
{
case WAIT_OBJECT_0:
PMICIoctlIntEnable(PMIC_MC13783_INT_ONOFD1I, TRUE);
// If ON1 button press caused resume
if (g_bSuspended)
{
// System has resumed
g_bSuspended = FALSE;
// Wait for ON1 button up before allowing subsequent
// transitions into suspend
bWaitButtonUp = TRUE;
}
GetRegister(MC13783_INT_SEN1_ADDR, &pwrButtonState);
// ON1 button up
if (pwrButtonState & MC13783_ON1_BUTTON_MASK)
{
// If we are waiting for button release after system resume
if (bWaitButtonUp)
{
// Next button release is allowed to cause a system
// suspend
bWaitButtonUp = FALSE;
}
else
{
if (SetSystemPowerState(NULL, POWER_STATE_SUSPEND, POWER_FORCE)
!= ERROR_SUCCESS)
{
ERRORMSG(TRUE, (_T("SetSystemPowerState failed!\r\n")));
}
else
{
// Give control back to system if it wants it for anything.
Sleep(0);
}
}
}
break;
case (WAIT_OBJECT_0+1):
PMICIoctlIntEnable(PMIC_MC13783_INT_ONOFD2I, TRUE);
break;
}
}
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicCSPIGetSysIntr
//
// This function gets SysIntr of CSPI used by PMIC.
//
// Parameters:
// index
// [in] The index of CSPI port.
//
// cspiSysIntr
// [out] The returned SysIntr.
//
// Returns:
// TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL BSPPmicCSPIGetSysIntr(int index, DWORD *cspiSysIntr)
{
DWORD dwIrq;
// If request is for CSPI1
if (index == 1)
{
dwIrq = IRQ_CSPI1;
}
// If request is for CSPI2
else if (index == 2)
{
dwIrq = IRQ_CSPI2;
}
// Else invalid CSPI instance
else
{
return FALSE;
}
// Call the OAL to translate the IRQ into a SysIntr value.
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwIrq, sizeof(DWORD),
cspiSysIntr, sizeof(DWORD), NULL))
{
return FALSE;
}
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicCSPIMapIoSpace
//
// This function maps registers of CSPI used by PMIC.
//
// Parameters:
// index
// [in] The index of CSPI port.
//
// Returns:
// TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL BSPPmicCSPIMapIoSpace(int index)
{
PHYSICAL_ADDRESS phyAddr;
if (index == 1)
{
phyAddr.QuadPart = CSP_BASE_REG_PA_CSPI1;
}
// If request is for CSPI2
else if (index == 2)
{
phyAddr.QuadPart = CSP_BASE_REG_PA_CSPI2;
}
// Else invalid CSPI instance
else
{
return FALSE;
}
// Map peripheral physical address to virtual address
g_pCSPI = (PCSP_CSPI_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_CSPI_REGS),
FALSE);
if (g_pCSPI == NULL) {
return FALSE;
}
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicCSPIWriteTXFIFO
//
// This function writes data to CSPI TXFIFO.
//
// Parameters:
// data
// [in] The sending data.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPPmicCSPIWriteTXFIFO(unsigned int data)
{
OUTREG32(&g_pCSPI->TXDATA, data);
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicCSPIReadRXFIFO
//
// This function reads data from CSPI RXFIFO.
//
// Parameters:
// None.
//
// Returns:
// The data read from RXFIFO.
//
//-----------------------------------------------------------------------------
UINT32 BSPPmicCSPIReadRXFIFO(void)
{
return (INREG32(&g_pCSPI->RXDATA));
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicCSPIExchange
//
// This function starts data exchange.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPPmicCSPIExchange(void)
{
INSREG32BF(&g_pCSPI->CONTROLREG,
CSPI_CONTROLREG_XCH, CSPI_CONTROLREG_XCH_EN);
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicCSPIWaitTransactionComplete
//
// This function polling transaction complete.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPPmicCSPIWaitTransactionComplete(void)
{
while (!(INREG32(&g_pCSPI->INT) & CSP_BITFMASK(CSPI_INT_TSHFE)))
; // Polling loop.
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicCSPIWaitReadReady
//
// This function polling RXFIFO data ready for read.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPPmicCSPIWaitReadReady(void)
{
while (!(INREG32(&g_pCSPI->INT) & CSP_BITFMASK(CSPI_INT_RR)))
; // Polling loop.
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicCSPIEnable
//
// This function enables CSPI used by PMIC.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPPmicCSPIEnable(void)
{
INSREG32BF(&g_pCSPI->CONTROLREG,
CSPI_CONTROLREG_SPIEN, CSPI_CONTROLREG_SPIEN_ENABLE);
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicCSPIDisable
//
// This function disables CSPI used by PMIC.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPPmicCSPIDisable(void)
{
INSREG32BF(&g_pCSPI->CONTROLREG,
CSPI_CONTROLREG_SPIEN, CSPI_CONTROLREG_SPIEN_DISABLE);
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicCSPIRXIRQEnable
//
// This function only enables RXFIFO data ready interrupt and disables others.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPPmicCSPIRXIRQEnable(void)
{
OUTREG32(&g_pCSPI->INT, CSP_BITFMASK(CSPI_INT_RREN));
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicCSPIIRQDisable
//
// This function disables all the interrupts.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPPmicCSPIIRQDisable(void)
{
OUTREG32(&g_pCSPI->INT, 0);
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicReadIntrStatus
//
// This function .
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPPmicReadIntrStatus(void)
{
UINT32 data;
// PMIC interrupt pin is IRQ_GPIO_PC_14
DDKGpioReadIntr(GPIO_PORT_C, 0xFFFFFFFF, &data);
RETAILMSG(TRUE, (_T("GPIO1_ISR = 0x%x"), data));
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicSignalOALRTC
//
// This function .
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPPmicSignalOALRTC(void)
{
static UINT32 irq = IRQ_RTC;
// Signal the OAL.
KernelIoControl(IOCTL_HAL_FORCE_IRQ, &irq, sizeof(UINT32), NULL, 0, NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -