1 /*
2 *
3 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
38 #ifndef _I2CLOC_H
39 #define _I2CLOC_H
40 /***********************************************************************
41 * FILE PURPOSE: Local definitions used to run the I2C peripheral
42 ***********************************************************************
43 * FILE NAME: i2cloc.h
44 *
45 * DESCRIPTION: Provides defintions and prototypes local to the i2c module
46 *
47 ************************************************************************/
48 #include "types.h"
50 #define BOOTBITMASK(x,y) ( ( ( ((UINT32)1 << (((UINT32)x)-((UINT32)y)+(UINT32)1) ) - (UINT32)1 ) ) << ((UINT32)y) )
51 #define BOOT_READ_BITFIELD(z,x,y) (((UINT32)z) & BOOTBITMASK(x,y)) >> (y)
52 #define BOOT_SET_BITFIELD(z,f,x,y) (((UINT32)z) & ~BOOTBITMASK(x,y)) | ( (((UINT32)f) << (y)) & BOOTBITMASK(x,y) )
54 /* Register addresses relative to a base address */
55 #define I2C_REG_OAR 0x00
56 #define I2C_REG_IER 0x04
57 #define I2C_REG_STR 0x08
58 #define I2C_REG_CLKL 0x0c
59 #define I2C_REG_CLKH 0x10
60 #define I2C_REG_CNT 0x14
61 #define I2C_REG_DRR 0x18
62 #define I2C_REG_SAR 0x1c
63 #define I2C_REG_DXR 0x20
64 #define I2C_REG_MDR 0x24
65 #define I2C_REG_ISR 0x28
66 #define I2C_REG_EXMODE 0x2c
67 #define I2C_REG_PSC 0x30
68 #define I2C_REG_PID1 0x34
69 #define I2C_REG_PID2 0x38
70 #define I2C_REG_PFUNC 0x48
72 /* Individual register definitions */
73 #define I2C_VAL_REG_MDR_RESET 0x4000
74 #define I2C_VAL_REG_MDR_SLVRCV 0x40A0
75 #define I2C_VAL_REG_MDR_MSTRCV 0x64A0
76 #define I2C_VAL_REG_MDR_MSTRCVSTOP 0x4CA0
77 #define I2C_VAL_REG_MDR_MSTXMT 0x46A0
78 #define I2C_VAL_REG_MDR_MSTXMTSTRT 0x66A0
79 #define I2C_VAL_REG_MDR_MSTXMTSTOP 0x4CA0
81 #define I2C_VAL_REG_STR_RESET 0x0410
82 #define I2C_VAL_REG_STR_ON_FAIL 0x1002 /* Clear bus busy, clear nack */
83 #define I2C_VAL_REG_STR_CLR_BUSY 0x1000 /* Clear busy */
84 #define I2C_VAL_REG_STR_CLR_RRDY 0x003F
86 /* Bit field definitions */
87 #define I2C_REG_STR_FIELD_BB(x) BOOT_READ_BITFIELD((x), 12, 12)
88 #define I2C_REG_STR_FIELD_NACK(x) BOOT_READ_BITFIELD((x), 1, 1)
89 #define I2C_REG_STR_FIELD_ARDY(x) BOOT_READ_BITFIELD((x), 2, 2)
90 #define I2C_REG_STR_FIELD_XRDY(x) BOOT_READ_BITFIELD((x), 4, 4)
91 #define I2C_REG_STR_FIELD_RRDY(x) BOOT_READ_BITFIELD((x), 3, 3)
95 /* Byte ordering */
96 enum {
97 I2C_BYTE_LSB,
98 I2C_BYTE_MSB
99 };
101 /************************************************************************
102 * Definition: Desired frequency for module operation in Qx.1 format
103 ************************************************************************/
104 #define I2C_TARGET_MODULE_FREQ_MHZ_Q1 27 /* 13.5 MHz */
107 /************************************************************************
108 * Definition: Timeout limit for master receiver. The units are
109 * in number of bits, so provide some overhead
110 ************************************************************************/
111 #define I2C_MAX_MASTER_RECEIVE_TIMEOUT 240 /* 30 bytes */
113 /************************************************************************
114 * Definition: Timeout limit for master transmitter. The units are
115 * in number of bits, so provide some overhead
116 ************************************************************************/
117 #define I2C_MAX_MASTER_TRANSMITTER_TIMEOUT 240 /* 30 bytes */
119 /************************************************************************
120 * Definition: Timeout limit for the master transmitter to get access
121 * to the bus. In 10ms units.
122 ************************************************************************/
123 #define I2C_MAX_MASTER_TRANSMITTER_BUS_ACCESS_TIMEOUT 100
124 #define I2C_MASTER_TRANSMITTER_BUS_ACCESS_DELAY_US 10000
126 /*************************************************************************
127 * Definition: Timeout limit after a master transmitter operation is
128 * complete, and waiting for access to the MMRs. This should
129 * be on the order of two bytes, for the last two that are
130 * being sent (one in the shift register, one in the dxr. The
131 * units are in bits.
132 *************************************************************************/
133 #define I2C_MAX_MASTER_TRANSMITTER_ARDY_TIMEOUT 32 /* 4 bytes */
136 /*************************************************************************
137 * Definition: Timeout limit in slave receiver mode. The unit is in
138 * expected bit periods, but is long since the master
139 * may have a long delay before beginning transmission.
140 *************************************************************************/
141 #define I2C_MAX_SLAVE_RECEIVE_TIMEOUT 5000000
146 #endif /* _I2CLOC_H */