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

📄 pmicpdk.c

📁 Freescale ARM11系列CPU MX31的WINCE 5.0下的BSP
💻 C
📖 第 1 页 / 共 2 页
字号:
// Returns:
//      TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL BSPPmicDeinitCspi(int port)
{
    return TRUE;
}


//-----------------------------------------------------------------------------
//
// Function: BSPPmicPowerNotifySuspend
//
// Handler for notification of system suspend.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
VOID BSPPmicPowerNotifySuspend(void)
{
    // System is entering suspend
    g_bSuspended = TRUE;
}    


//-----------------------------------------------------------------------------
//
// 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;

#if !(defined PLAT_PMC) && !(defined BSP_ULDR)
    HDC hDisplay;
    UINT32 dispMode;

    static DEVMODE dmDispMode;
    static DWORD dwOrientation = DMDO_0;
    DISPLAY_DEVICE ddDevice, ddLastDevice;
#endif
    
    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
                {

#ifdef PLAT_PMC
                    // TODO: A better approach would be to try this, and if it fails, try SetSystemPowerState
                    // TODO: Also, we could conditionally define PPN_SUSPENDKEYPRESSED to remove the PMC dependency.
                    if (PowerPolicyNotify(PPN_SUSPENDKEYPRESSED, 0)
                        != TRUE)
#else
                    if (SetSystemPowerState(NULL, POWER_STATE_SUSPEND, POWER_FORCE)
                        != ERROR_SUCCESS)
#endif
                    {
                        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);
#if !(defined PLAT_PMC) && !(defined BSP_ULDR)
            GetRegister(MC13783_INT_SEN1_ADDR, &pwrButtonState);

            // Only recognize rising edge events
            if (pwrButtonState & MC13783_ON2_BUTTON_MASK)
            {
                dmDispMode.dmSize = sizeof(DEVMODE);
                ddDevice.cb = sizeof(DISPLAY_DEVICE);

                retVal = EnumDisplayDevices(NULL, 0, &ddDevice, 0);
                if (retVal)
                {
                    DEBUGMSG(TRUE,
                          (TEXT("%s: Got a display device for index 0.\r\n"), __WFUNCTION__));
                    ddLastDevice = ddDevice;
                }

                if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS /*ENUM_REGISTRY_SETTINGS*/, &dmDispMode))
                {
                    ERRORMSG(TRUE,
                          (TEXT("%s: Failed reading display settings before rotate.\r\n"), __WFUNCTION__));
                }

                dmDispMode.dmFields = DM_DISPLAYORIENTATION;
                if (dwOrientation == DMDO_0)
                {
                    dwOrientation = DMDO_270;
                    dmDispMode.dmDisplayOrientation = dwOrientation;
                }
                else if (dwOrientation == DMDO_270)
                {
                    dwOrientation = DMDO_0;
                    dmDispMode.dmDisplayOrientation = dwOrientation;
                }

                if (ChangeDisplaySettingsEx(ddLastDevice.DeviceName, // default display device
                                        &dmDispMode,
                                        NULL, // reserved
                                        0, // flags = 0; changes graphics mode dynamically.
                                        NULL) != DISP_CHANGE_SUCCESSFUL)
                {
                    ERRORMSG(TRUE,
                          (TEXT("%s: Failed changing display settings.\r\n"), __WFUNCTION__));
                }

                DEBUGMSG(TRUE,
                        (TEXT("%s: Display mode orientation: %d\r\n"), __WFUNCTION__, dmDispMode.dmDisplayOrientation));

            }
#endif
            break;

        case (WAIT_OBJECT_0+2):
            PMICIoctlIntEnable(PMIC_MC13783_INT_ONOFD3I, TRUE);
            GetRegister(MC13783_INT_SEN1_ADDR, &pwrButtonState);
#if !(defined PLAT_PMC) && !(defined BSP_ULDR)
            if (pwrButtonState & MC13783_ON3_BUTTON_MASK)
            {
                //TODO: Add DrvEscape call to enable TV out
                hDisplay = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);

                // Get display mode
                if (ExtEscape(hDisplay, DISPLAY_GET_OUTPUT_MODE, 0,
                        NULL, sizeof(UINT32), (LPSTR) &dispMode) <= 0)
                {
                    ERRORMSG(TRUE,
                          (TEXT("%s: Error retrieving display mode. \r\n"), __WFUNCTION__));
                    break;
                }

                if (dispMode == DISPLAY_MODE_DEVICE)
                {
                    dispMode = DISPLAY_MODE_NTSC;
                }
                else
                {
                    dispMode = DISPLAY_MODE_DEVICE;
                }

                // Modify display mode
                if (ExtEscape(hDisplay, DISPLAY_SET_OUTPUT_MODE, sizeof(UINT32),
                        (LPCSTR) &dispMode, 0, NULL) <= 0)
                {
                    ERRORMSG(TRUE,
                          (TEXT("%s: Error setting display mode. \r\n"), __WFUNCTION__));
                    break;
                }
            }
#endif
            break;

        }
    }

    return rc;
}

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;
    }

    // Note: The configuration of the IOMUX for the CSPI pins is now done
    //       as part of each platform's OEMInit() implementation in the
    //       kernel's OAL layer.
    
    // 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;
}
    
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_REG) MmMapIoSpace(phyAddr, sizeof(CSP_CSPI_REG),
                                           FALSE);
    if (g_pCSPI == NULL) {
        return FALSE;
    }

    return TRUE;
}

void BSPPmicCSPIWriteTXFIFO(unsigned int data)
{
    OUTREG32(&g_pCSPI->TXDATA, data);
}

UINT32 BSPPmicCSPIReadRXFIFO(void)
{
    return (INREG32(&g_pCSPI->RXDATA));
}

void BSPPmicCSPIExchange(void)
{
    INSREG32BF(&g_pCSPI->CONREG, CSPI_CONREG_XCH, CSPI_CONREG_XCH_EN);
}

void BSPPmicCSPIWaitTransactionComplete(void)
{
    while (!(INREG32(&g_pCSPI->STATREG) & CSP_BITFMASK(CSPI_STATREG_TC)))
        ; // Polling loop.
}

void BSPPmicCSPIWaitReadReady(void)
{
    while (!(INREG32(&g_pCSPI->STATREG) & CSP_BITFMASK(CSPI_STATREG_RR)))
        ; // Polling loop.
}

void BSPPmicCSPIEnable(void)
{
    INSREG32BF(&g_pCSPI->CONREG, CSPI_CONREG_EN, CSPI_CONREG_EN_ENABLE);
}

void BSPPmicCSPIDisable(void)
{
    INSREG32BF(&g_pCSPI->CONREG, CSPI_CONREG_EN, CSPI_CONREG_EN_DISABLE);
}

void BSPPmicCSPIRXIRQEnable(void)
{
    OUTREG32(&g_pCSPI->INTREG, CSP_BITFMASK(CSPI_INTREG_RREN));
}

void BSPPmicCSPIIRQDisable(void)
{
    OUTREG32(&g_pCSPI->INTREG, 0);
}

void BSPPmicReadIntrStatus(void)
{
    UINT32 data;

    DDKGpioReadIntr(DDK_GPIO_PORT1, 0xFFFFFFFF, &data);
    RETAILMSG(TRUE, (_T("GPIO1_ISR = 0x%x"), data));
}

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 + -