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

📄 csl_i2caux.h

📁 Dm6455 driver,magbe useful to you!
💻 H
📖 第 1 页 / 共 3 页
字号:
/*  ===========================================================================
 *   Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005
 *
 *   Use of this software is controlled by the terms and conditions found in the
 *   license agreement under which this software has been supplied.
 *   ===========================================================================
 */
/** ============================================================================
 *  @file csl_i2cAux.h
 *
 *  @brief Header file for functional layer of CSL
 *
 *  @path $(CSLPATH)\inc
 *
 *  Description
 *    - The defines inline function definitions for control commands & status
 *       queris
 *  ===========================================================================
 */
/* =============================================================================
 *  Revision History
 *  ===============
 *  31-Aug-2004 Hs File Created from CSL_i2cHwControl.c.
 *  01-Sep-2004 Hs Added inline functions for query commands also.  
 *  11-oct-2004 Hs updated according to code review comments.
 *  28-jul-2005 sv removed gpio support 
 *  06-Feb-2006 ds Updated according to TCI6482/C6455 User Guide
 *  ===========================================================================
 */
#ifndef _CSL_I2CAUX_H_
#define _CSL_I2CAUX_H_

#include <csl_i2c.h>

#ifdef __cplusplus
extern "C" {
#endif

/** Control Functions of i2c. */
/** ============================================================================
 *   @n@b CSL_i2cEnable
 *
 *   @b Description
 *   @n This function enables the I2C module.
 *
 *   @b Arguments
 *   @verbatim

            hI2c            Handle to I2C instance

     @endverbatim
 *
 *   <b> Return Value </b>  None
 *
 *   <b> Pre Condition </b>
 *   @n  CSL_i2cInit(),CSL_i2cOpen()has to be called successfully before calling
 *       this function
 *
 *   <b> Post Condition </b>
 *    @n None
 *
 *   @b Modifies
 *   @n  None
 *
 *   @b Example
 *   @verbatim

        CSL_i2cEnable(hI2c);

     @endverbatim
 *  ============================================================================
 */
static inline
void CSL_i2cEnable (
    CSL_I2cHandle    hI2c
)
{
    CSL_FINS(hI2c->regs->ICMDR, I2C_ICMDR_IRS, FALSE);
    CSL_FINS(hI2c->regs->ICMDR, I2C_ICMDR_IRS, TRUE);
}

/** ============================================================================
 *   @n@b CSL_i2cReset
 *
 *   @b Description
 *   @n This function resets the I2C module. provides software reset
 *
 *   @b Arguments
 *   @verbatim

            hI2c            Handle to I2C instance

     @endverbatim
 *
 *   <b> Return Value </b>  None
 *
 *   <b> Pre Condition </b>
 *   @n  CSL_i2cInit(),CSL_i2cOpen()has to be called successfully before calling
 *       this function
 *
 *   <b> Post Condition </b>
 *    @n None
 *
 *   @b Modifies
 *   @n  None
 *
 *   @b Example
 *   @verbatim

        CSL_i2cReset(hI2c);

     @endverbatim
 *  ============================================================================
 */
static inline
void CSL_i2cReset (
    CSL_I2cHandle    hI2c
)
{
    CSL_FINS(hI2c->regs->ICMDR, I2C_ICMDR_IRS, FALSE);
}

/** ============================================================================
 *   @n@b CSL_i2cOutOfReset
 *
 *   @b Description
 *   @n This function pulls the I2C out of reset.
 *
 *   @b Arguments
 *   @verbatim

            hI2c            Handle to I2C instance

     @endverbatim
 *
 *   <b> Return Value </b>  None
 *
 *   <b> Pre Condition </b>
 *   @n  CSL_i2cInit(),CSL_i2cOpen()has to be called successfully before calling
 *       this function
 *
 *   <b> Post Condition </b>
 *    @n None
 *
 *   @b Modifies
 *   @n  None
 *
 *   @b Example
 *   @verbatim

        CSL_i2cOutOfReset(hI2c);

     @endverbatim
 *  ============================================================================
 */
static inline
void CSL_i2cOutOfReset (
    CSL_I2cHandle    hI2c
)
{
    CSL_FINS(hI2c->regs->ICMDR, I2C_ICMDR_IRS, TRUE);
}


/** ============================================================================
 *   @n@b CSL_i2cClearStatus
 *
 *   @b Description
 *   @n This function clears the status register of I2C.
 *
 *   @b Arguments
 *   @verbatim

            hI2c            Handle to I2C instance

     @endverbatim
 *
 *   <b> Return Value </b>  None
 *
 *   <b> Pre Condition </b>
 *   @n  CSL_i2cInit(),CSL_i2cOpen()has to be called successfully before calling
 *       this function
 *
 *   <b> Post Condition </b>
 *    @n None
 *
 *   @b Modifies
 *   @n  None
 *
 *   @b Example
 *   @verbatim

        CSL_i2cClearStatus(hI2c);

     @endverbatim
 *  ============================================================================
 */
static inline
void CSL_i2cClearStatus (
    CSL_I2cHandle    hI2c
)
{
    Uint32 temp_stat = 0x0;
    Uint32 temp_stat_old = 0x0;

    /* Multiple status bits can be cleared. */

    temp_stat_old = hI2c->regs->ICSTR & 0x3F;

    if (temp_stat_old & CSL_I2C_CLEAR_AL) {
        temp_stat = CSL_FMK(I2C_ICSTR_AL, 1);         /* Writing 1 clears bit*/
    }
    if (temp_stat_old & CSL_I2C_CLEAR_NACK) {
        temp_stat = CSL_FMK(I2C_ICSTR_NACK, 1);       /* Writing 1 clears bit*/
    }
    if (temp_stat_old & CSL_I2C_CLEAR_ARDY) {
            temp_stat = CSL_FMK(I2C_ICSTR_ARDY, 1) ; /* Writing 1 clears bit*/
    }
    if (temp_stat_old & CSL_I2C_CLEAR_RRDY) {
        temp_stat = CSL_FMK(I2C_ICSTR_ICRRDY, 1) ;     /* Writing 1 clears bit*/
    }
    if (temp_stat_old & CSL_I2C_CLEAR_XRDY) {
        temp_stat = CSL_FMK(I2C_ICSTR_ICXRDY, 1) ;     /* Writing 1 clears bit*/
    }
    if (temp_stat_old & CSL_I2C_CLEAR_SCD) {
        temp_stat = CSL_FMK(I2C_ICSTR_SCD, 1) ;        /* Writing 1 clears bit*/
    }

    hI2c->regs->ICSTR = hI2c->regs->ICSTR | (temp_stat & 0x3F);
}

/** ============================================================================
 *   @n@b CSL_i2cSetSlaveAddr
 *
 *   @b Description
 *   @n This function sets the slave address of I2C module.
 *
 *   @b Arguments
 *   @verbatim

            hI2c            Handle to I2C instance
            
            arg             pointer to hold the slave address

     @endverbatim
 *
 *   <b> Return Value </b>  None
 *
 *   <b> Pre Condition </b>
 *   @n  CSL_i2cInit(),CSL_i2cOpen()has to be called successfully before calling
 *       this function
 *
 *   <b> Post Condition </b>
 *    @n None
 *
 *   @b Modifies
 *   @n  None
 *
 *   @b Example
 *   @verbatim

        CSL_i2cSetSlaveAddr(hI2c, &arg);

     @endverbatim
 *  ============================================================================
 */
static inline
void CSL_i2cSetSlaveAddr (
    CSL_I2cHandle hI2c,
    void          *arg
)
{
    hI2c->regs->ICSAR = ((*(Uint32 *)arg) & 0x3FF);
}

/** ============================================================================
 *   @n@b CSL_i2cSetOwnAddr
 *
 *   @b Description
 *   @n This function sets its own address.
 *
 *   @b Arguments
 *   @verbatim

            hI2c            Handle to I2C instance
            
            arg             pointer to hold the own address

     @endverbatim
 *
 *   <b> Return Value </b>  None
 *
 *   <b> Pre Condition </b>
 *   @n  CSL_i2cInit(), CSL_i2cOpen()has to be called successfully before calling
 *       this function
 *
 *   <b> Post Condition </b>
 *    @n None
 *
 *   @b Modifies
 *   @n  None
 *
 *   @b Example
 *   @verbatim

        CSL_i2cSetOwnAddr(hI2c, &arg);

     @endverbatim
 *  ============================================================================
 */
static inline
void CSL_i2cSetOwnAddr (
    CSL_I2cHandle hI2c,
    void          *arg
)
{
    hI2c->regs->ICOAR = (*(Uint32 *)arg);
}

/** ============================================================================
 *   @n@b CSL_i2cEnableIntr
 *
 *   @b Description
 *   @n This function enables selected interrupts of I2C module.
 *
 *   @b Arguments
 *   @verbatim

            hI2c            Handle to I2C instance
            
            arg             OR-ed value of interrupts

     @endverbatim
 *
 *   <b> Return Value </b>  None
 *
 *   <b> Pre Condition </b>
 *   @n  CSL_i2cInit(),CSL_i2cOpen()has to be called successfully before calling
 *       this function
 *
 *   <b> Post Condition </b>
 *    @n None
 *
 *   @b Modifies
 *   @n  None
 *
 *   @b Example
 *   @verbatim

        CSL_i2cEnableIntr(hI2c, arg);

     @endverbatim
 *  ============================================================================
 */
static inline
void CSL_i2cEnableIntr (
    CSL_I2cHandle hI2c,
    Uint32        arg
)
{
    hI2c->regs->ICIMR = (hI2c->regs->ICIMR | (arg));
}

/** ============================================================================
 *   @n@b CSL_i2cDisableIntr
 *
 *   @b Description
 *   @n This function disables selected interrupts of I2C module.
 *
 *   @b Arguments
 *   @verbatim

            hI2c            Handle to I2C instance
            
            arg             OR-ed value of interrupts

     @endverbatim
 *
 *   <b> Return Value </b>  None
 *
 *   <b> Pre Condition </b>
 *   @n  CSL_i2cInit(),CSL_i2cOpen()has to be called successfully before calling
 *       this function
 *
 *   <b> Post Condition </b>
 *    @n None
 *
 *   @b Modifies
 *   @n  None
 *
 *   @b Example
 *   @verbatim

        CSL_i2cDisableIntr(hI2c, arg);

     @endverbatim
 *  ============================================================================
 */
static inline
void CSL_i2cDisableIntr (
    CSL_I2cHandle hI2c,
    Uint32        arg
)
{
    hI2c->regs->ICIMR = (hI2c->regs->ICIMR & ~(arg));
}

/** ============================================================================
 *   @n@b CSL_i2cSetDataCount
 *
 *   @b Description
 *   @n This function sets the data count of the I2C module.
 *
 *   @b Arguments
 *   @verbatim

            hI2c            Handle to I2C instance
            
            arg             pointer to hold the data count

     @endverbatim
 *
 *   <b> Return Value </b>  None
 *
 *   <b> Pre Condition </b>
 *   @n  CSL_i2cInit(),CSL_i2cOpen()has to be called successfully before calling
 *       this function
 *
 *   <b> Post Condition </b>
 *    @n None
 *
 *   @b Modifies
 *   @n  None
 *
 *   @b Example
 *   @verbatim

        CSL_i2cSetDataCount(hI2c, &arg);

     @endverbatim
 *  ============================================================================
 */
static inline
void CSL_i2cSetDataCount (
    CSL_I2cHandle hI2c,
    void          *arg
)
{
    hI2c->regs->ICCNT = (*(Uint32 *)arg) & 0xFFFF;
}

/** ============================================================================
 *   @n@b CSL_i2cSetClock
 *
 *   @b Description
 *   @n This function sets the I2C Clock.
 *
 *   @b Arguments
 *   @verbatim

            hI2c       Handle to I2C instance

            arg        address of ClkSetup structure.

     @endverbatim
 *
 *   <b> Return Value </b>  None
 *
 *   <b> Pre Condition </b>
 *   @n  CSL_i2cInit(),CSL_i2cOpen()has to be called successfully before calling
 *       this function
 *
 *   <b> Post Condition </b>
 *    @n None
 *
 *   @b Modifies
 *   @n  None
 *
 *   @b Example
 *   @verbatim

        CSL_i2cSetClockSetup(hI2c, &arg);

     @endverbatim
 *  ============================================================================
 */
static inline
void CSL_i2cSetClock (
    CSL_I2cHandle   hI2c,
    CSL_I2cClkSetup *arg
)
{
    CSL_FINS(hI2c->regs->ICPSC, I2C_ICPSC_IPSC, arg->prescalar);
    CSL_FINS(hI2c->regs->ICCLKL, I2C_ICCLKL_ICCL, arg->clklowdiv);
    CSL_FINS(hI2c->regs->ICCLKH, I2C_ICCLKH_ICCH, arg->clkhighdiv);
}

/** ============================================================================
 *   @n@b CSL_i2cStart
 *
 *   @b Description
 *   @n This function writes the start command to the I2C module.
 *
 *   @b Arguments
 *   @verbatim

            hI2c            Handle to I2C instance

     @endverbatim
 *
 *   <b> Return Value </b>  None
 *
 *   <b> Pre Condition </b>
 *   @n  CSL_i2cInit(),CSL_i2cOpen()has to be called successfully before calling
 *       this function

⌨️ 快捷键说明

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