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

📄 power_i2c.c

📁 Windows CE 6.0 BSP for VOIP sample phone. Intel PXA270 platform.
💻 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_i2c.c
//
//  Power I2C routines for the PLATO bootloader and OAL.
//
#include <windows.h>
#include <oal_kitl.h>
#include <oal_memory.h>
#include <plato.h>
#include <bulverde_base_regs.h>
#include <xllp_clkmgr.h>
#include <xllp_ost.h>
#include <xllp_i2c.h>
#include "pcf50606.h"
#include "power_i2c.h"

// Hardware registers to map
//
volatile XLLP_CLKMGR_T      *v_pClkRegs = NULL;
volatile XLLP_OST_T         *v_pOstRegs = NULL;
volatile XLLP_PI2C_T        *v_pPI2CRegs = NULL;
volatile XLLP_I2C_T         *v_pI2CRegs = NULL;


BOOL PI2CInit()
{
    v_pClkRegs = (volatile XLLP_CLKMGR_T *) OALPAtoVA(BULVERDE_BASE_REG_PA_CLKMGR, FALSE);
    v_pOstRegs = (volatile XLLP_OST_T *) OALPAtoVA(BULVERDE_BASE_REG_PA_OST, FALSE);
    v_pPI2CRegs = (volatile XLLP_PI2C_T *) OALPAtoVA(BULVERDE_BASE_REG_PA_PWR, FALSE);
    v_pI2CRegs = (volatile XLLP_I2C_T *) OALPAtoVA(BULVERDE_BASE_REG_PA_PWR + 0x180, FALSE);

    if (v_pClkRegs == NULL ||
        v_pOstRegs == NULL ||
        v_pPI2CRegs == NULL ||
        v_pI2CRegs == NULL)
    {
        return FALSE;
    }

    // Initial low level I2C processor registers;
    XllpPI2cInit((XLLP_PI2C_T *)v_pPI2CRegs,
                 /*v_pGPIORegs = */NULL, // GPIO regs not used in this function
                 (XLLP_CLKMGR_T *)v_pClkRegs,
                 (XLLP_UINT32_T)0);

    return TRUE;
}


BOOL WritePI2CRegister(UCHAR pI2CReg, UCHAR value)
{
    UCHAR cDataBuffer[2];

    cDataBuffer[0] = pI2CReg;
    cDataBuffer[1] = value;
    if (XLLP_TRUE == XllpI2CWrite((XLLP_I2C_T *)v_pI2CRegs, 
                                 (XLLP_OST_T *) v_pOstRegs, 
                                 (XLLP_UINT8_T)PCF50606_I2C_ID >> 1, 
                                 (const XLLP_UINT8_T *)cDataBuffer, 
                                 2, 
                                 TRUE))
    {
        return FALSE;
    }

    return TRUE;
}


UCHAR ReadPI2CRegister(UCHAR pI2CReg)
{
    UCHAR cDataBuffer[1];

    // Read OOCS (On/Off Control Status) register
    cDataBuffer[0] = pI2CReg;
    XllpI2CWrite((XLLP_I2C_T *)v_pI2CRegs, 
                     (XLLP_OST_T *) v_pOstRegs, 
                     (XLLP_UINT8_T)PCF50606_I2C_ID >> 1, 
                     (const XLLP_UINT8_T *)cDataBuffer, 
                     1, 
                     FALSE);

    XllpI2CRead((XLLP_I2C_T *)v_pI2CRegs, 
                    (XLLP_OST_T *)v_pOstRegs, 
                    (XLLP_UINT8_T)PCF50606_I2C_ID >> 1, 
                    cDataBuffer, 
                    1, 
                    TRUE);

    return cDataBuffer[0];
}


⌨️ 快捷键说明

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