1 #ifndef _I2CLOC_H
2 #define _I2CLOC_H
3 /***********************************************************************
4 * FILE PURPOSE: Local definitions used to run the I2C peripheral
5 ***********************************************************************
6 * FILE NAME: i2cloc.h
7 *
8 * DESCRIPTION: Provides defintions and prototypes local to the i2c module
9 *
10 ************************************************************************/
11 #include "types.h"
13 #define BOOTBITMASK(x,y) ( ( ( ((UINT32)1 << (((UINT32)x)-((UINT32)y)+(UINT32)1) ) - (UINT32)1 ) ) << ((UINT32)y) )
14 #define BOOT_READ_BITFIELD(z,x,y) (((UINT32)z) & BOOTBITMASK(x,y)) >> (y)
15 #define BOOT_SET_BITFIELD(z,f,x,y) (((UINT32)z) & ~BOOTBITMASK(x,y)) | ( (((UINT32)f) << (y)) & BOOTBITMASK(x,y) )
17 /* Register addresses relative to a base address */
18 #define I2C_REG_OAR 0x00
19 #define I2C_REG_IER 0x04
20 #define I2C_REG_STR 0x08
21 #define I2C_REG_CLKL 0x0c
22 #define I2C_REG_CLKH 0x10
23 #define I2C_REG_CNT 0x14
24 #define I2C_REG_DRR 0x18
25 #define I2C_REG_SAR 0x1c
26 #define I2C_REG_DXR 0x20
27 #define I2C_REG_MDR 0x24
28 #define I2C_REG_ISR 0x28
29 #define I2C_REG_EXMODE 0x2c
30 #define I2C_REG_PSC 0x30
31 #define I2C_REG_PID1 0x34
32 #define I2C_REG_PID2 0x38
33 #define I2C_REG_PFUNC 0x48
35 /* Individual register definitions */
36 #define I2C_VAL_REG_MDR_RESET 0x4000
37 #define I2C_VAL_REG_MDR_SLVRCV 0x40A0
38 #define I2C_VAL_REG_MDR_MSTRCV 0x64A0
39 #define I2C_VAL_REG_MDR_MSTRCVSTOP 0x4CA0
40 #define I2C_VAL_REG_MDR_MSTXMT 0x46A0
41 #define I2C_VAL_REG_MDR_MSTXMTSTRT 0x66A0
42 #define I2C_VAL_REG_MDR_MSTXMTSTOP 0x4CA0
44 #define I2C_VAL_REG_STR_RESET 0x0410
45 #define I2C_VAL_REG_STR_ON_FAIL 0x1002 /* Clear bus busy, clear nack */
46 #define I2C_VAL_REG_STR_CLR_BUSY 0x1000 /* Clear busy */
47 #define I2C_VAL_REG_STR_CLR_RRDY 0x003F
49 /* Bit field definitions */
50 #define I2C_REG_STR_FIELD_BB(x) BOOT_READ_BITFIELD((x), 12, 12)
51 #define I2C_REG_STR_FIELD_NACK(x) BOOT_READ_BITFIELD((x), 1, 1)
52 #define I2C_REG_STR_FIELD_ARDY(x) BOOT_READ_BITFIELD((x), 2, 2)
53 #define I2C_REG_STR_FIELD_XRDY(x) BOOT_READ_BITFIELD((x), 4, 4)
54 #define I2C_REG_STR_FIELD_RRDY(x) BOOT_READ_BITFIELD((x), 3, 3)
58 /* Byte ordering */
59 enum {
60 I2C_BYTE_LSB,
61 I2C_BYTE_MSB
62 };
64 /************************************************************************
65 * Definition: Desired frequency for module operation in Qx.1 format
66 ************************************************************************/
67 #define I2C_TARGET_MODULE_FREQ_MHZ_Q1 27 /* 13.5 MHz */
70 /************************************************************************
71 * Definition: Timeout limit for master receiver. The units are
72 * in number of bits, so provide some overhead
73 ************************************************************************/
74 #define I2C_MAX_MASTER_RECEIVE_TIMEOUT 240 /* 30 bytes */
76 /************************************************************************
77 * Definition: Timeout limit for master transmitter. The units are
78 * in number of bits, so provide some overhead
79 ************************************************************************/
80 #define I2C_MAX_MASTER_TRANSMITTER_TIMEOUT 240 /* 30 bytes */
82 /************************************************************************
83 * Definition: Timeout limit for the master transmitter to get access
84 * to the bus. In 10ms units.
85 ************************************************************************/
86 #define I2C_MAX_MASTER_TRANSMITTER_BUS_ACCESS_TIMEOUT 100
87 #define I2C_MASTER_TRANSMITTER_BUS_ACCESS_DELAY_US 10000
89 /*************************************************************************
90 * Definition: Timeout limit after a master transmitter operation is
91 * complete, and waiting for access to the MMRs. This should
92 * be on the order of two bytes, for the last two that are
93 * being sent (one in the shift register, one in the dxr. The
94 * units are in bits.
95 *************************************************************************/
96 #define I2C_MAX_MASTER_TRANSMITTER_ARDY_TIMEOUT 32 /* 4 bytes */
99 /*************************************************************************
100 * Definition: Timeout limit in slave receiver mode. The unit is in
101 * expected bit periods, but is long since the master
102 * may have a long delay before beginning transmission.
103 *************************************************************************/
104 #define I2C_MAX_SLAVE_RECEIVE_TIMEOUT 5000000
109 #endif /* _I2CLOC_H */