📄 power.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
// File: power.c
//
// PowerManager routines for the PLATO bootloader.
//
#include <windows.h>
#include <oal_kitl.h>
#include <oal_memory.h>
#include <plato.h>
#include "pcf50606.h"
#include "power_i2c.h"
#ifdef DEBUG
void DumpPMICStatus();
#endif
// Global variables
//
extern BOOL g_fChargerInitialized;
//------------------------------------------------------------------------------
//
// Function: OALPowerInit
//
// Initialize the Power Manager IC (PMIC) to start the battery charger
// show status LEDs
//
BOOL OALPowerInit()
{
UINT8 countdown = 15;
UCHAR OOCStatus = 0;
if (!PI2CInit())
{
KITLOutputDebugString("OALPowerInit: Failed to map hardware registers.\r\n");
return FALSE;
}
// Check the presence of charger
OOCStatus = ReadPI2CRegister(OOCS);
if (OOCStatus & 0x20)
{
// Set WatchDog Reset timer to max (93 min)
if (!WritePI2CRegister(MBCC2, 0x1F))
return FALSE;
// Set Charge Control Voltage (VCHGCON) to 4.2V
if (!WritePI2CRegister(MBCC3, 0x1A))
return FALSE;
// Enable Charger, set AUTOFST and set charge mode to Fast (CCCV)
if (!WritePI2CRegister(MBCC1, 0x0F))
return FALSE;
// Set LED modulator
// Blinking pattern = Continuous ON, LED enabled when charger connected
if (!WritePI2CRegister(LEDC1, 0x78))
return FALSE;
// Configure GPOC2 to output LED1 modulator on GPOOD0
if (!WritePI2CRegister(GPOC2, 0x01))
return FALSE;
g_fChargerInitialized = TRUE;
KITLOutputDebugString("Power Manager initialized successfully.\r\n");
}
else
{
g_fChargerInitialized = FALSE;
}
#ifdef DEBUG
KITLOutputDebugString("OALPowerInit: Dumping PMIC status.\r\n");
DumpPMICStatus();
#endif
return TRUE;
}
#ifdef DEBUG
void DumpPMICStatus()
{
KITLOutputDebugString("PCF50606: OOCS = 0x%x\r\n", ReadPI2CRegister(OOCS));
KITLOutputDebugString("PCF50606: MBCS1 = 0x%x\r\n", ReadPI2CRegister(MBCS1));
KITLOutputDebugString("PCF50606: MBCC1 = 0x%x\r\n", ReadPI2CRegister(MBCC1));
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -