Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/fmcomms1/Common/eeprom.c

raw symbols SCIP
1 /**************************************************************************//**
2 * @file eeprom.c
3 * @brief EEPROM Implementation file.
4 * @author acozma ([email protected])
5 *
6 *******************************************************************************
7 * Copyright 2011(c) Analog Devices, Inc.
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 * - Neither the name of Analog Devices, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 * - The use of this software may or may not infringe the patent rights
23 * of one or more patent holders. This license does not release you
24 * from the requirement that you obtain separate licenses from these
25 * patent holders to use this software.
26 * - Use of the software either in source or binary form, must be run
27 * on or directly connected to an Analog Devices Inc. component.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY
31 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34 * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 *******************************************************************************
41 * SVN Revision: $WCREV$
42 ******************************************************************************/
43
44 /*****************************************************************************/
45 /***************************** Include Files *********************************/
46 /*****************************************************************************/
47 #include "eeprom.h"
48
49 extern uint32_t (*I2C_Write)(uint32_t, uint32_t, uint32_t, uint8_t*);
50 extern uint32_t (*I2C_Read)(uint32_t, uint32_t, uint32_t, uint8_t*);
51
52 /**************************************************************************//**
53 * @brief Reads data from the selected EEPROM device
54 *
55 * @param eepromAddr - I2C address of the EEPROM device
56 * @param pData - Buffer to store the read data
57 * @param size - Number of bytes to read
58 *
59 * @return Returns -1 in case of error, 0 for success
60 ******************************************************************************/
61 int32_t EEPROM_Read(uint8_t i2cAddr, uint8_t eepromAddr,
62 uint8_t* pData, uint16_t size)
63 {
64 uint32_t ret;
65
66 ret = I2C_Read(i2cAddr, eepromAddr,
67 size, pData);
68
69 return (size != ret ? -1 : 0);
70 }
71
72 /**************************************************************************//**
73 * @brief Writes data to the selected EEPROM device
74 *
75 * @param eepromAddr - I2C address of the EEPROM device
76 * @param pData - Buffer to store the write data
77 * @param size - Number of bytes to write
78 *
79 * @return Returns -1 in case of error, 0 for success
80 ******************************************************************************/
81 int32_t EEPROM_Write(uint8_t i2cAddr, uint8_t eepromAddr,
82 uint8_t* pData, uint16_t size)
83 {
84 uint32_t ret;
85
86 ret = I2C_Write(i2cAddr, eepromAddr,
87 size, pData);
88
89 return (size != ret ? -1 : 0);
90 }
91
92 /**************************************************************************//**
93 * @brief Reads the calibration data from the calibration EEPROM
94 *
95 * @param pData - Pointer to the buffer where to store the calibration data
96 * @param pSize - Pointer to to a variable where to store the number of
97 * existing calibration records
98 * @param fmcPort - Set to 0 for LPC, set to 1 for HPC
99 *
100 * @return Returns -1 in case of error, 0 for success
101 ******************************************************************************/
102 int32_t EEPROM_GetCalData(uint8_t* pData, uint8_t *pSize, uint32_t fmcPort)
103 {
104 int32_t ret;
105 int32_t i = 0;
106
107 struct fmcomms1_calib_data* pCalData;
108
109 *pSize = 0;
110
111 for(i = 0; i < MAX_SIZE_CAL_EEPROM; i += 16)
112 {
113 ret = EEPROM_Read(fmcPort ? IICSEL_CAL_HPC : IICSEL_CAL_LPC, i,
114 (pData + i),
115 ((MAX_SIZE_CAL_EEPROM - i) > 16) ? 16 : (MAX_SIZE_CAL_EEPROM - i));
116
117 if(ret < 0)
118 return ret;
119 }
120
121 pCalData = (struct fmcomms1_calib_data*)pData;
122
123 if ((pCalData->adi_magic0 == ADI_MAGIC_0) &&
124 (pCalData->adi_magic1 == ADI_MAGIC_1) /*&&
125 (pCalData->version == ADI_VERSION(VERSION_SUPPORTED)*/)
126 {
127 (*pSize)++;
128 }
129
130 while(pCalData->next)
131 {
132 (*pSize)++;
133 pCalData++;
134 }
135
136 return ret;
137 }