📄 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 API Auxilary header file for I2C CSL. * * Path: \\(CSLPATH)\\ipmodules\\i2c\\src *//* ============================================================================= * Revision History * =============== * 08-Dec-2004 Hs added CSL_i2cSetClock (), CSL_i2cSetOwnAddr () * 11-oct-2004 Hs updated according to code review comments. * 01-Sep-2004 Hs Added inline functions for query commands also. * 31-Aug-2004 Hs File Created from CSL_i2cHwControl.c. * ============================================================================== */#ifndef _CSL_I2CAUX_H_#define _CSL_I2CAUX_H_#include <csl_i2c.h>#ifdef __cplusplusextern "C" {#endif/* * Control Functions of i2c. *//** ============================================================================ * @n@b CSL_i2cEnable * * @b Description * @n This function enables the I2C module. * * @b Arguments * @verbatim hI2c Pointer to the object that holds reference to the instance of I2C requested after the call @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 * ============================================================================ */CSL_IDEF_INLINEvoid 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_i2cConfigAsGpio * * @b Description * @n This function configures I2C as GPIO. * * @b Arguments * @verbatim hI2c Pointer to the object that holds reference to the instance of I2C requested after the call @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_i2cConfigAsGpio (hI2c); @endverbatim * ============================================================================ */CSL_IDEF_INLINEvoid CSL_i2cConfigAsGpio ( 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 Pointer to the object that holds reference to the instance of I2C requested after the call @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 * ============================================================================ */CSL_IDEF_INLINEvoid 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 Pointer to the object that holds reference to the instance of I2C requested after the call @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 * ============================================================================ */CSL_IDEF_INLINEvoid 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 Pointer to the object that holds reference to the instance of I2C requested after the call @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 * ============================================================================ */CSL_IDEF_INLINEvoid CSL_i2cClearStatus ( CSL_I2cHandle hI2c){ Uint16 temp_stat = 0x0; Uint16 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 the bit. */ if (temp_stat_old & CSL_I2C_CLEAR_NACK) temp_stat = CSL_FMK(I2C_ICSTR_NACK, 1) ;/* Writing 1 clears the 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 the bit.*/ if (temp_stat_old & CSL_I2C_CLEAR_XRDY) temp_stat = CSL_FMK(I2C_ICSTR_ICXRDY, 1) ;/* Writing 1 clears the bit.*/ if (temp_stat_old & CSL_I2C_CLEAR_SCD) temp_stat = CSL_FMK(I2C_ICSTR_SCD, 1) ;/* Writing 1 clears the 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 Pointer to the object that holds reference to the instance of I2C requested after the call *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 * ============================================================================ */CSL_IDEF_INLINEvoid CSL_i2cSetSlaveAddr ( CSL_I2cHandle hI2c, void *arg){ hI2c->regs->ICSAR = ((*(Uint16 *)arg) & 0x3FF);}/** ============================================================================ * @n@b CSL_i2cSetOwnAddr * * @b Description * @n This function sets its own address. * * @b Arguments * @verbatim hI2c Pointer to the object that holds reference to the instance of I2C requested after the call *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 * ============================================================================ */CSL_IDEF_INLINEvoid CSL_i2cSetOwnAddr ( CSL_I2cHandle hI2c, void *arg){ hI2c->regs->ICOAR = (*(Uint16 *)arg);}/** ============================================================================ * @n@b CSL_i2cEnableIntr * * @b Description * @n This function enables selected interrupts of I2C module. * * @b Arguments * @verbatim hI2c Pointer to the object that holds reference to the instance of I2C requested after the call 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 * ============================================================================ */CSL_IDEF_INLINEvoid 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 Pointer to the object that holds reference to the instance of I2C requested after the call 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 * ============================================================================ */CSL_IDEF_INLINEvoid 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 Pointer to the object that holds reference to the instance of I2C requested after the call *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 * ============================================================================ */CSL_IDEF_INLINEvoid CSL_i2cSetDataCount ( CSL_I2cHandle hI2c, 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 Pointer to the object that holds reference to the instance of I2C requested after the call 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 * ============================================================================ */CSL_IDEF_INLINEvoid 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 Pointer to the object that holds reference to the instance of I2C requested after the call @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_i2cStart (hI2c); @endverbatim * ============================================================================ */CSL_IDEF_INLINEvoid CSL_i2cStart (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -