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

📄 pmicpdk.c

📁 LP1071 无线局域网卡WinCE驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
//
//-----------------------------------------------------------------------------
static DWORD WINAPI PmicButtonServThread (LPVOID lpParam)
{
    DWORD rc = TRUE;
    BOOL retVal = TRUE;
    static BOOL bWaitButtonUp = FALSE;
    UINT32 pwrButtonState;
    
// TODO: Comment by Shawn on April 19 to pass compiling
#if 0
#ifndef PLAT_PMC
    HDC hDisplay;
    UINT32 dispMode;

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

// TODO: Comment by Shawn on April 19 to pass compiling
#if 0            
#ifndef PLAT_PMC
            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
#endif

            break;

        case (WAIT_OBJECT_0+2):
            PMICIoctlIntEnable(PMIC_MC13783_INT_ONOFD3I, TRUE);
            GetRegister(MC13783_INT_SEN1_ADDR, &pwrButtonState);

// TODO: Comment by Shawn on April 19 to pass compiling
#if 0            
#ifndef PLAT_PMC
            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
#endif

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