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

📄 ist.c

📁 Windows CE 6.0 BSP for VOIP sample phone. Intel PXA270 platform.
💻 C
📖 第 1 页 / 共 3 页
字号:
    HANDLE hevBattReady = OpenEvent(SYNCHRONIZE, FALSE, BATTERY_API_EVENT_NAME);
    if(hevBattReady != NULL) 
    {
        // Create PPM message
        ppm.dwMessage = PPN_POWERCHANGE;
        ppm.dwData = 0;
        ppm.hOwnerProcess = NULL;

        // Write power policy "power change" message to msg queue
        SendQueueMessage(pMsgQueue,
            (LPVOID)&ppm,
            (DWORD)sizeof(POWERPOLICYMESSAGE));

        CloseHandle(hevBattReady);
    }
}


static void
BatteryFull(PPCF50606 pPCF50606)
{
    PSYSTEM_POWER_STATUS_EX2 ppowerstatus=&gPowerStatus;
    BOOL Success = TRUE;
    UCHAR data = 0;

    DEBUGMSG(ZONE_STATECHANGE,(TEXT("PCF50606: +Battery Full\r\n")));

    StopCharger(pPCF50606);  // Full - Stop charger

    DEBUGMSG(ZONE_STATECHANGE,(TEXT("PCF50606: -Battery Full\r\n")));
}


static void
BatteryEmpty(PPCF50606 pPCF50606)
{
    PSYSTEM_POWER_STATUS_EX2 ppowerstatus=&gPowerStatus;
    UCHAR data = 0;

    DWORD bytesReturned;

    DEBUGMSG(ZONE_STATECHANGE,(TEXT("PCF50606: +Battery Empty\r\n")));

    // The battery voltage could be tested to
    // determine if the battery is really empty
    if (gfACOnline)
    {
        RETAILMSG(ZONE_ERROR, (TEXT("PCF50606: Fake Low Battery Interrupt - clear and continue\r\n")));

        // Reset time out timer
        bytesReturned = PDD_I2CRead(&pPCF50606->csI2CAccess,
                                    pPCF50606->v_pI2CRegs,
                                    pPCF50606->v_pOstRegs,
                                    OOCC1,
                                    pPCF50606->pcfRegisterCache+OOCC1,
                                    1);

        pPCF50606->pcfRegisterCache[OOCC1] &= ~OOCC1_GOSTDBY;
        pPCF50606->pcfRegisterCache[OOCC1] |= OOCC1_TOTRST;
        bytesReturned = PDD_I2CWrite(&pPCF50606->csI2CAccess,
                                     pPCF50606->v_pI2CRegs,
                                     pPCF50606->v_pOstRegs,
                                     OOCC1,
                                     pPCF50606->pcfRegisterCache+OOCC1,
                                     1);
    }

    DEBUGMSG(ZONE_STATECHANGE,(TEXT("PCF50606: -Battery Empty\r\n")));
}

static void
StopCharger(PPCF50606 pPCF50606)
{
    DWORD bytesReturned;

    DEBUGMSG(ZONE_STATECHANGE,(TEXT("PCF50606: Stopping charger\r\n")));

    // On stop, leave charger enabled in idle mode and set WDT to 9 minutes.
    // 10 seconds before the 9 minute timer expires, INT2_CHGWD10S interrupt
    // will be set, at which point charger will be re-started in fast charge mode again
    pPCF50606->pcfRegisterCache[MBCC1] = MBCC1_WDRST | 
                                         MBCC1_CHGMOD_M(IDLE_MODE) | 
                                         MBCC1_CHGAPE;
    pPCF50606->pcfRegisterCache[MBCC2] = MBCC2_WDTIME_M(WDTIME_9_MIN);
    bytesReturned = PDD_I2CWrite(&pPCF50606->csI2CAccess,
                             pPCF50606->v_pI2CRegs,
                             pPCF50606->v_pOstRegs,
                             MBCC1,
                             pPCF50606->pcfRegisterCache+MBCC1,
                             2);

    gfBatteryCharging = FALSE;

    // Should set some LEDs
}

static void
RestartCharger(PPCF50606 pPCF50606)
{
    DWORD bytesReturned;

    DEBUGMSG(ZONE_STATECHANGE,(TEXT("PCF50606: Starting charger\r\n")));

    // Start charger and reset WDT.
    pPCF50606->pcfRegisterCache[MBCC1] = MBCC1_WDRST | 
                                         MBCC1_CHGMOD_M(FAST_CCCV_MODE) | 
                                         MBCC1_AUTOFST | 
                                         MBCC1_CHGAPE;
    pPCF50606->pcfRegisterCache[MBCC2] = MBCC2_WDTIME_M(WDTIME_60_MIN);
    bytesReturned = PDD_I2CWrite(&pPCF50606->csI2CAccess,
                         pPCF50606->v_pI2CRegs,
                         pPCF50606->v_pOstRegs,
                         MBCC1,
                         pPCF50606->pcfRegisterCache+MBCC1,
                         2);

    gfBatteryCharging = TRUE;
}

void
StartCharger(PPCF50606 pPCF50606)
{
    // Should set some LEDs
    RestartCharger(pPCF50606);
}


static void
RemoveCharger(PPCF50606 pPCF50606)
{
    DWORD bytesReturned;

    DEBUGMSG(ZONE_STATECHANGE,(TEXT("PCF50606: Disabling charger module.\r\n")));

    // Disable charger
    pPCF50606->pcfRegisterCache[MBCC1] = MBCC1_WDRST | 
                                         MBCC1_CHGMOD_M(IDLE_MODE) | 
                                         MBCC1_AUTOFST;
    pPCF50606->pcfRegisterCache[MBCC2] = 0x00;
    bytesReturned = PDD_I2CWrite(&pPCF50606->csI2CAccess,
                         pPCF50606->v_pI2CRegs,
                         pPCF50606->v_pOstRegs,
                         MBCC1,
                         pPCF50606->pcfRegisterCache+MBCC1,
                         2);

    gfBatteryCharging = FALSE;

    // Should set some LEDs

}


static DWORD
ComputeVoltageAverage(PPCFBATTERY pPcfBattery)
{
    int i;
    DWORD Sum = 0;
    DWORD Cnt = 0;
    DWORD Avg = 0;

    // Add sample to array
    pPcfBattery->dwBattVoltageSampleArray[pPcfBattery->dwBattVoltageIndex] = pPcfBattery->dwCurrentBatteryVoltage;
    pPcfBattery->dwBattVoltageIndex = (pPcfBattery->dwBattVoltageIndex + 1) % BATTERY_VOLTAGE_NUM_SAMPLES;

    for (i = 0; i < BATTERY_VOLTAGE_NUM_SAMPLES; i++)
    {
        if (pPcfBattery->dwBattVoltageSampleArray[i] != 0)
        {
            Sum += pPcfBattery->dwBattVoltageSampleArray[i];
            Cnt++;
        }
    }

    if (Cnt < BATTERY_VOLTAGE_NUM_SAMPLES)
    {
        return pPcfBattery->dwCurrentBatteryVoltage;
    }

    if (Cnt > 0)
    {
        Avg = Sum / Cnt;
    }

    return Avg;
}


DWORD WINAPI SynchronizeRTCThread(PPCF50606 pPCF50606)
{
    SYSTEMTIME sysRTCTime;
    SYSTEMTIME newsysRTCTime;
    UCHAR RTCRegs[7] = {0};
    DWORD bytesReturned = 0;
        
    // double check if another thread was started in the meantime
    // while this one was being scheduled
    if (gfRTCSyncThreadRunning)
    {
        RETAILMSG(ZONE_WARNING, (TEXT("PCF50606 SynchronizeRTCThread: Already running.\r\n")));
        return 0;
    }

    gfRTCSyncThreadRunning = TRUE;

    do
    {
        GetLocalTime(&sysRTCTime);
        sysRTCTime.wYear -= 2000;
        
        RTCRegs[6] = DECTOBCD(sysRTCTime.wYear);
        RTCRegs[5] = DECTOBCD(sysRTCTime.wMonth);
        RTCRegs[4] = DECTOBCD(sysRTCTime.wDay);
        RTCRegs[3] = DECTOBCD(sysRTCTime.wDayOfWeek);
        RTCRegs[2] = DECTOBCD(sysRTCTime.wHour);
        RTCRegs[1] = DECTOBCD(sysRTCTime.wMinute);
        RTCRegs[0] = DECTOBCD(sysRTCTime.wSecond);

        bytesReturned = PDD_I2CWrite(&pPCF50606->csI2CAccess,
                                     pPCF50606->v_pI2CRegs,
                                     pPCF50606->v_pOstRegs,
                                     RTCSC,
                                     &RTCRegs[0],
                                     7);

        // Check to see if the system time changed (within a minute resolution to
        // avoid complexity). Since we are not comparing seconds, it will match 
        // in one or two attempts
        GetLocalTime(&newsysRTCTime);
        newsysRTCTime.wYear -= 2000;
        if ((sysRTCTime.wYear == newsysRTCTime.wYear) &&
            (sysRTCTime.wMonth == newsysRTCTime.wMonth) &&
            (sysRTCTime.wDay == newsysRTCTime.wDay) &&
            (sysRTCTime.wDayOfWeek == newsysRTCTime.wDayOfWeek) &&
            (sysRTCTime.wHour == newsysRTCTime.wHour) &&
            (sysRTCTime.wMinute == newsysRTCTime.wMinute))
        {
            break;
        }          

        Sleep(1000);
    } while (1);

#ifndef SHIP_BUILD

    bytesReturned = PDD_I2CRead(&pPCF50606->csI2CAccess,
                                 pPCF50606->v_pI2CRegs,
                                 pPCF50606->v_pOstRegs,
                                 RTCSC,
                                 &RTCRegs[0],
                                 7);
    
    GetLocalTime(&newsysRTCTime);

    RETAILMSG(ZONE_VERBOSE, (TEXT("PCF50606 SynchronizeRTCThread: System RTC = %d/%d/%d  ; %d : %d:%d:%d\r\n"),  
                            newsysRTCTime.wMonth, 
                            newsysRTCTime.wDay, 
                            newsysRTCTime.wYear, 
                            newsysRTCTime.wDayOfWeek, 
                            newsysRTCTime.wHour, 
                            newsysRTCTime.wMinute, 
                            newsysRTCTime.wSecond ));
    RETAILMSG(ZONE_VERBOSE, (TEXT("PCF50606 SynchronizeRTCThread: New PMIC RTC = %d/%d/%d  ; %d : %d:%d:%d\r\n"), 
                            BCDTODEC(RTCRegs[5]), 
                            BCDTODEC(RTCRegs[4]), 
                            BCDTODEC(RTCRegs[6]) + 2000, 
                            BCDTODEC(RTCRegs[3]), 
                            BCDTODEC(RTCRegs[2]), 
                            BCDTODEC(RTCRegs[1]), 
                            BCDTODEC(RTCRegs[0])));

#endif // SHIP_BUILD
    
    gfRTCSyncThreadRunning = FALSE;

    return 0;
}

static void
SynchronizeRTCTime(pPCF50606)
{
    HANDLE hThread = NULL;
    
    RETAILMSG(ZONE_VERBOSE, (TEXT("SynchronizeRTCTime: Starting SynchronizeRTCThread.\r\n")));

    hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SynchronizeRTCThread, (LPVOID)pPCF50606, 0, NULL);
    if (NULL == hThread)
    {
        RETAILMSG(ZONE_ERROR, (TEXT("PCF50606: Failed to create RTC time synchronization thread\r\n")));  
    }
    else
    {
        CloseHandle(hThread);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -