]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/ibl.git/blob - src/util/i2cRead/i2cRead.c
Update copyright information
[keystone-rtos/ibl.git] / src / util / i2cRead / i2cRead.c
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 /****************************************************************************************************
39  * FILE PURPOSE: Read an I2C eeprom
40  ****************************************************************************************************
41  * @file i2cRead.c
42  *
43  * @brief
44  *   Reads bytes from an i2c eeprom
45  *
46  ****************************************************************************************************/
48 #include "types.h"
49 #include "i2c.h"
50 #include "target.h"
51 #include <stdio.h>
53 #define I2C_SIZE_BYTES  0x10000
55 /* Run time configuration */
56 unsigned int   deviceFreqMhz = 1000;
57 unsigned short busAddress    = 0x50;
58 unsigned int   nbytes        = I2C_SIZE_BYTES;
59 unsigned int   firstByte     = 0;
62 #pragma DATA_SECTION(i2cData, ".i2cData")
63 unsigned char i2cData[I2C_SIZE_BYTES];
65 /**
66  *  @brief
67  *     Display the error returned by the i2c driver 
68  */
69 void showI2cError (I2C_RET iret)
70 {
71     char *ecode;
73     switch (iret)  {
74         case I2C_RET_LOST_ARB:        ecode = "I2C master lost an arbitration battle";
75                                       break;
77         case I2C_RET_NO_ACK:          ecode = "I2C master detected no ack from slave";
78                                       break;
80         case I2C_RET_IDLE_TIMEOUT:    ecode = "I2C timed out";
81                                       break;
83         case I2C_RET_BAD_REQUEST:     ecode = "I2C driver detected a bad data request";
84                                       break;
86         case I2C_RET_CLOCK_STUCK_LOW: ecode = "I2C driver found the bus stuck low";
87                                       break;
89         case I2C_RET_GEN_ERROR:       ecode = "I2C driver reported a general error";
90                                       break;
92     }
94     printf ("I2C reported error: %s\n", ecode);
96 }
99 void main (void)
101     I2C_RET i2cRet;
103     hwI2Cinit (deviceFreqMhz,
104                DEVICE_I2C_MODULE_DIVISOR,
105                25,                              /* Run the bus at 25 kHz */
106                10);
109     i2cRet = hwI2cMasterRead (firstByte,
110                               nbytes,
111                               i2cData,
112                               busAddress,
113                               10 );
116     if (i2cRet != I2C_RET_OK) 
117         showI2cError (i2cRet);
118     else
119         printf ("I2C read complete\n");
122