📄 csl_i2c.h
字号:
/******************************************************************************\* Copyright (C) 1999-2000 Texas Instruments Incorporated.* All Rights Reserved*------------------------------------------------------------------------------* FILENAME...... csl_i2c.h* DATE CREATED.. 06/11/1999 * LAST MODIFIED. 08/02/2004 - Adding support for C6418* 13/03/2002 - added I2C_outOfReset()* 01/08/2003 - Removing unused variable 'I2C_isrDispatchTable[6]'\******************************************************************************/#ifndef _CSL_I2C_H_#define _CSL_I2C_H_#include <csl_chip.h>#include <csl_irq.h>#include <csl_i2chal.h>/* defining i2cimr as i2cier for backward compatibility */#define i2cimr i2cier#if (I2C_SUPPORT)/******************************************************************************\* scope and inline control macros\******************************************************************************/#ifdef __cplusplus#define CSLAPI extern "C" far#else#define CSLAPI extern far#endif#undef USEDEFS#undef IDECL#undef IDEF#ifdef _I2C_MOD_ #define IDECL CSLAPI #define USEDEFS #define IDEF#else #ifdef _INLINE #define IDECL static inline #define USEDEFS #define IDEF static inline #else #define IDECL CSLAPI #endif#endif/******************************************************************************\* global macro declarations\******************************************************************************//* I2C_open() flags */#define I2C_OPEN_RESET (0x00000001)/* device identifiers for I2C_open() */#if (CHIP_6713 | CHIP_DA610 | CHIP_6413 | CHIP_6418 | CHIP_6410) #define I2C_DEV0 (0) #define I2C_DEV1 (1)#endif#if (CHIP_DM642 | CHIP_DM641 | CHIP_DM640 | CHIP_6412) #define I2C_DEV0 (0)#endif/* device identifiers for I2C_open() */#if (CHIP_6713 | CHIP_DA610 | CHIP_6413 | CHIP_6418 | CHIP_6410) #define I2C_PORT0 I2C_DEV0 #define I2C_PORT1 I2C_DEV1#endif#if (CHIP_DM642 | CHIP_DM641 | CHIP_DM640 | CHIP_6412) #define I2C_PORT0 I2C_DEV0#endif/* error codes */#define I2C_ERR_ALLOC (0x00000000) #define I2C_ERR_INVALID_HANDLE (0x00000001) #define I2C_EVT_AL 0x01 // Arbitration win/lose#define I2C_EVT_NACK 0x02 // No acknowledgement #define I2C_EVT_ARDY 0x03 // register access ready#define I2C_EVT_ICRRDY 0x04 // receive data ready#define I2C_EVT_ICXRDY 0x05 // transmit data ready#if (CHIP_6413 | CHIP_6418 | CHIP_6410) #define I2C_EVT_SCD 0x06 // stop condition detect #define I2C_EVT_AAS 0x07 // address as slave#endif/******************************************************************************\* global typedef declarations\******************************************************************************//* device handle object */typedef struct { Uint32 allocated; Uint32 eventId; volatile Uint32 *baseAddr; Uint32 i2cdrrAddr; Uint32 i2cdxrAddr;} I2C_Obj, *I2C_Handle;/* device configuration structure */typedef struct { Uint32 i2coar; Uint32 i2cier; Uint32 i2cclkl; Uint32 i2cclkh; Uint32 i2ccnt; Uint32 i2csar; Uint32 i2cmdr; Uint32 i2cpsc;#if (CHIP_6413 | CHIP_6418 | CHIP_6410) Uint32 i2cemdr; Uint32 i2cpfunc; Uint32 i2cpdir;#endif } I2C_Config;typedef struct { Uint32 addrmode; /* 7 or 10 bit address mode */ Uint32 ownaddr; /* don't care if master */ Uint32 sysinclock; /* clkout value (Mhz) */ Uint32 rate; /* a number between 10 and 400 in kbps*/ Uint32 bitbyte; /* number of bits/byte to be received or transmitted */ Uint32 dlb; /* digital loopback mode */ Uint32 free; /* free mode */} I2C_Init;/******************************************************************************\* global variable declarations\******************************************************************************//******************************************************************************\* global function declarations\******************************************************************************/CSLAPI void I2C_reset(I2C_Handle hI2c);CSLAPI void I2C_resetAll();CSLAPI I2C_Handle I2C_open(int devNum, Uint32 flags);CSLAPI void I2C_close(I2C_Handle hI2c);//CSLAPI void I2C_init(I2C_Init *init);/******************************************************************************\* inline function declarations\******************************************************************************/IDECL Uint32 I2C_getXmtAddr(I2C_Handle hI2c);IDECL Uint32 I2C_getRcvAddr(I2C_Handle hI2c);IDECL Uint32 I2C_getEventId(I2C_Handle hI2c);IDECL Uint32 I2C_rfull(I2C_Handle hI2c);IDECL Uint32 I2C_rrdy(I2C_Handle hI2c);IDECL Uint32 I2C_xempty(I2C_Handle hI2c);IDECL Uint32 I2C_xrdy(I2C_Handle hI2c);IDECL Uint32 I2C_bb(I2C_Handle hI2c);IDECL void I2C_writeByte(I2C_Handle hI2c, Uint8 val);IDECL Uint8 I2C_readByte(I2C_Handle hI2c);IDECL void I2C_sendStop(I2C_Handle hI2c);IDECL void I2C_start(I2C_Handle hI2c);IDECL void I2C_outOfReset(I2C_Handle hI2c);IDECL Uint32 I2C_intClear(I2C_Handle hI2c);IDECL void I2C_intClearAll(I2C_Handle hI2c);IDECL void I2C_intEvtEnable(I2C_Handle hI2c,Uint32 maskFlag);IDECL void I2C_intEvtDisable(I2C_Handle hI2c,Uint32 unmaskFlag);IDECL void I2C_config(I2C_Handle hI2c,I2C_Config *config);#if (CHIP_6413 | CHIP_6418 | CHIP_6410) IDECL void I2C_configArgs(I2C_Handle hI2c,Uint32 i2coar,Uint32 i2cier,Uint32 i2cclkl, Uint32 i2cclkh,Uint32 i2ccnt,Uint32 i2csar,Uint32 i2cmdr, Uint32 i2cpsc,Uint32 i2cemdr,Uint32 i2cpfunc,Uint32 i2cpdir);#else IDECL void I2C_configArgs(I2C_Handle hI2c,Uint32 i2coar,Uint32 i2cier,Uint32 i2cclkl, Uint32 i2cclkh,Uint32 i2ccnt,Uint32 i2csar,Uint32 i2cmdr, Uint32 i2cpsc);#endifIDECL void I2C_getConfig(I2C_Handle hI2c,I2C_Config *config);/******************************************************************************\* inline function definitions\******************************************************************************/#ifdef USEDEFS#if (CHIP_6413 | CHIP_6418 | CHIP_6410)/*----------------------------------------------------------------------------*/IDEF Uint32 I2C_getPins(I2C_Handle hI2c) { return I2C_RGETH(hI2c,I2CPDIN);}/*----------------------------------------------------------------------------*/IDEF void I2C_setPins(I2C_Handle hI2c,Uint32 pins) { I2C_RSETH(hI2c,I2CPDSET, ( I2C_FMK(I2CPDSET, SCLOUT, pins>>_I2C_I2CPDSET_SCLOUT_SHIFT) |I2C_FMK(I2CPDSET, SDAOUT, pins>>_I2C_I2CPDSET_SDAOUT_SHIFT) ) ); }IDEF void I2C_clearPins(I2C_Handle hI2c,Uint32 pins) { I2C_RSETH(hI2c,I2CPDCLR, ( I2C_FMK(I2CPDCLR, SCLOUT, pins>>_I2C_I2CPDCLR_SCLOUT_SHIFT) |I2C_FMK(I2CPDCLR, SDAOUT, pins>>_I2C_I2CPDCLR_SDAOUT_SHIFT) ) ); }/*----------------------------------------------------------------------------*/IDEF Uint32 I2C_getExtMode(I2C_Handle hI2C) { return I2C_FGETH(hI2C,I2CEMDR,XRDYM);}/*----------------------------------------------------------------------------*/IDEF void I2C_setMstAck(I2C_Handle hI2C) { I2C_FSETSH(hI2C,I2CEMDR,XRDYM,MSTACK);}/*----------------------------------------------------------------------------*/IDEF void I2C_setDxrCpy(I2C_Handle hI2C) { I2C_FSETSH(hI2C,I2CEMDR,XRDYM,DXRCPY);}#endif/*----------------------------------------------------------------------------*/IDEF Uint32 I2C_getXmtAddr(I2C_Handle hI2c) { return (Uint32)(hI2c->i2cdxrAddr);}/*----------------------------------------------------------------------------*/IDEF Uint32 I2C_getRcvAddr(I2C_Handle hI2c) { return (Uint32)(hI2c->i2cdrrAddr);}/*----------------------------------------------------------------------------*/IDEF Uint32 I2C_getEventId(I2C_Handle hI2c) { return (Uint32)(hI2c->eventId);}/*----------------------------------------------------------------------------*/IDEF Uint32 I2C_rfull(I2C_Handle hI2c){ return I2C_FGETH(hI2c,I2CSTR,RSFULL);}/*----------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -