📄 csl_i2caux.h
字号:
/* ============================================================================
* 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
*
* Description
* - The defines inline function definitions
*
* Modification 1
* - Modified on: 18/1/2005
* - Reason: created the sources
* - Modified on: 25/10/2005
* - Added API for setting I2C as master/slave
*
* @author Ramitha Mathew.
*/
#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 None
*
* <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->ICPFUNC,I2C_ICPFUNC_PFUNC, FALSE);
CSL_FINS(hI2c->regs->ICMDR,I2C_ICMDR_IRS, TRUE);
}
/** ============================================================================
* @n@b CSL_i2cConfigAsGio
*
* @b Description
* @n This function configures I2C as GIO.
*
* @b Arguments
* @verbatim
hI2c Handle to I2C instance
@endverbatim
*
* <b> Return Value </b> None
*
* <b> Pre Condition </b>
* @n None
*
* <b> Post Condition </b>
* @n None
*
* @b Modifies
* @n None
*
* @b Example
* @verbatim
CSL_i2cConfigAsGio (hI2c);
@endverbatim
* =============================================================================
*/
static inline
void CSL_i2cConfigAsGio (
CSL_I2cHandle hI2c
)
{
CSL_FINS(hI2c->regs->ICMDR,I2C_ICMDR_IRS, FALSE);
CSL_FINS(hI2c->regs->ICPFUNC,I2C_ICPFUNC_PFUNC, TRUE);
CSL_FINS(hI2c->regs->ICMDR,I2C_ICMDR_IRS, TRUE);
}
/** ============================================================================
* @n@b CSL_i2cReset
*
* @b Description
* @n This function resets the I2C module.
*
* @b Arguments
* @verbatim
hI2c Handle to I2C instance
@endverbatim
*
* <b> Return Value </b> None
*
* <b> Pre Condition </b>
* @n None
*
* <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 None
*
* <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 None
*
* <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
)
{
/* writing 1 to already set interrupt flags clears them */
hI2c->regs->ICSTR = hI2c->regs->ICSTR ;
}
/** ============================================================================
* @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 None
*
* <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,
/* Arguments if any for the command */
void *arg
)
{
CSL_FINS(hI2c->regs->ICSAR, I2C_ICSAR_A, ((*(Uint16 *)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 None
*
* <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,
/* Arguments if any for the command */
void *arg
)
{
CSL_FINS(hI2c->regs->ICOAR, I2C_ICOAR_A, ((*(Uint16 *)arg) & 0x3FF));
}
/** ============================================================================
* @n@b CSL_i2cSetMode
*
* @b Description
* @n This function sets i2c in Master/Slave mode depending on the arg passed.
*
* @b Arguments
* @verbatim
hI2c Handle to I2C instance
*arg pointer to the mode value for the MST bit in I2C mode
register
@endverbatim
*
* <b> Return Value </b> None
*
* <b> Pre Condition </b>
* @n None
*
* <b> Post Condition </b>
* @n None
*
* @b Modifies
* @n None
*
* @b Example
* @verbatim
CSL_i2cSetMode (hI2c, &arg);
@endverbatim
* =============================================================================
*/
static inline
void CSL_i2cSetMode (
CSL_I2cHandle hI2c,
/* Arguments if any for the command */
void *arg
)
{
CSL_FINS(hI2c->regs->ICMDR, I2C_ICMDR_MST, ((*(Uint8 *)arg) & 0x1) );
}
/** ============================================================================
* @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 None
*
* <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
)
{
Uint16 arg = 0x7f;
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 None
*
* <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
)
{
Uint16 arg = 0xff80;
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 None
*
* <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,
/* Arguments if any for the command */
void *arg
)
{
hI2c->regs->ICCNT = (*(Uint16 *)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 None
*
* <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,
/* Placeholder to return the status. @a void* casted */
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -