]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - psdk_cust/pdk_k2g_1_0_1_0_eng/packages/ti/board/src/evmK2G/evmK2G_info.c
PASDK-258:Update PDK eng to 1.0.1.1. Using build number to differentiate PDK eng...
[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_0_eng / packages / ti / board / src / evmK2G / evmK2G_info.c
1 /******************************************************************************
2  * Copyright (c) 2010-2015 Texas Instruments Incorporated - http://www.ti.com
3  *
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions
6  *  are met:
7  *
8  *    Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  *    Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the
14  *    distribution.
15  *
16  *    Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  *****************************************************************************/
34 #include "board_internal.h"
35 #include "board_cfg.h"
37 /*
38  *  ======== Board_getIDInfo ========
39  */
40 Board_STATUS Board_getIDInfo(Board_IDInfo *info) {
41     Board_STATUS ret = BOARD_SOK;
42     I2C_Transaction i2cTransaction;
43     I2C_Handle handle = NULL;
44     char txBuf[2] = {0x00, 0x00};
45     bool status;
47     /* If handle not opened yet, init i2c */
48     if (Board_obj.i2cHandle == NULL)
49     {
50         ret = Board_internalInitI2C();
51     }
52     if (ret != BOARD_SOK)
53         return ret;
55     handle = Board_obj.i2cHandle;
57     i2cTransaction.slaveAddress = BOARD_I2C_EEPROM_ADDR;
58     i2cTransaction.writeBuf = (uint8_t *)&txBuf[0];
59     i2cTransaction.writeCount = 2;
61     /* Get header info */
62     txBuf[0] = (char)(((uint32_t) 0xFF00 & BOARD_EEPROM_HEADER_ADDR)>>8);
63     txBuf[1] = (char)((uint32_t) 0xFF & BOARD_EEPROM_HEADER_ADDR);
64     i2cTransaction.readBuf = (uint8_t *) info->header;
65     i2cTransaction.readCount = BOARD_EEPROM_HEADER_LENGTH;
67     status = I2C_transfer(handle, &i2cTransaction);
68     if (status == false)
69     {
70         ret = BOARD_I2C_TRANSFER_FAIL;
71         I2C_close(handle);
72         Board_obj.i2cHandle = NULL;
73         return ret;
74     }
76     info->header[BOARD_EEPROM_HEADER_LENGTH] = '\0';
78     /* Get board name */
79     txBuf[0] = (char)(((uint32_t) 0xFF00 & BOARD_EEPROM_BOARD_NAME_ADDR)>>8);
80     txBuf[1] = (char)((uint32_t) 0xFF & BOARD_EEPROM_BOARD_NAME_ADDR);
81     i2cTransaction.readBuf = (uint8_t *) info->boardName;
82     i2cTransaction.readCount = BOARD_EEPROM_BOARD_NAME_LENGTH;
83     status = I2C_transfer(handle, &i2cTransaction);
84     if (status == false)
85     {
86         ret = BOARD_I2C_TRANSFER_FAIL;
87         I2C_close(handle);
88         Board_obj.i2cHandle = NULL;
89         return ret;
90     }
91     info->boardName[BOARD_EEPROM_BOARD_NAME_LENGTH] = '\0';
93     /* Get board version */
94     txBuf[0] = (char)(((uint32_t) 0xFF00 & BOARD_EEPROM_VERSION_ADDR)>>8);
95     txBuf[1] = (char)((uint32_t) 0xFF & BOARD_EEPROM_VERSION_ADDR);
96     i2cTransaction.readBuf = (uint8_t *) info->version;
97     i2cTransaction.readCount = BOARD_EEPROM_VERSION_LENGTH;
98     status = I2C_transfer(handle, &i2cTransaction);
99     if (status == false)
100     {
101         ret = BOARD_I2C_TRANSFER_FAIL;
102         I2C_close(handle);
103         Board_obj.i2cHandle = NULL;
104         return ret;
105     }
106     info->version[BOARD_EEPROM_VERSION_LENGTH] = '\0';
108     /* Get header info */
109     txBuf[0] = (char)(((uint32_t) 0xFF00 & BOARD_EEPROM_SERIAL_NO_ADDR)>>8);
110     txBuf[1] = (char)((uint32_t) 0xFF & BOARD_EEPROM_SERIAL_NO_ADDR);
111     i2cTransaction.readBuf = (uint8_t *) info->serialNum;
112     i2cTransaction.readCount = BOARD_EEPROM_SERIAL_NO_LENGTH;
113     status = I2C_transfer(handle, &i2cTransaction);
114     if (status == false)
115     {
116         ret = BOARD_I2C_TRANSFER_FAIL;
117         I2C_close(handle);
118         Board_obj.i2cHandle = NULL;
119         return ret;
120     }
121     info->serialNum[BOARD_EEPROM_SERIAL_NO_LENGTH] = '\0';
123     I2C_close(handle);
124     Board_obj.i2cHandle = NULL;
126     return ret;
129 /*
130  *  ======== Board_writeIDInfo ========
131  */
132 Board_STATUS Board_writeIDInfo(Board_IDInfo *info) {
133     Board_STATUS ret = BOARD_SOK;
134     I2C_Transaction i2cTransaction;
135     I2C_Handle handle = NULL;
136     char txBuf[2+BOARD_EEPROM_HEADER_LENGTH+BOARD_EEPROM_BOARD_NAME_LENGTH
137         +BOARD_EEPROM_VERSION_ADDR+BOARD_EEPROM_SERIAL_NO_LENGTH];
138     bool status;
139     int i, idx;
141     /* If handle not opened yet, init i2c */
142     if (Board_obj.i2cHandle == NULL)
143     {
144         ret = Board_internalInitI2C();
145     }
146     if (ret != BOARD_SOK)
147         return ret;
149     handle = Board_obj.i2cHandle;
151     i2cTransaction.slaveAddress = BOARD_I2C_EEPROM_ADDR;
152     i2cTransaction.writeBuf = (uint8_t *)&txBuf[0];
153     i2cTransaction.writeCount = 2;
155     /* write header info */
156     txBuf[0] = (char)(((uint32_t) 0xFF00 & BOARD_EEPROM_HEADER_ADDR)>>8);
157     txBuf[1] = (char)((uint32_t) 0xFF & BOARD_EEPROM_HEADER_ADDR);
158     i2cTransaction.readCount = 0;
159     idx = 2;
160     for (i = 0; i<BOARD_EEPROM_HEADER_LENGTH; i++) txBuf[idx++] = info->header[i];
161     for (i = 0; i<BOARD_EEPROM_BOARD_NAME_LENGTH; i++) txBuf[idx++] = info->boardName[i];
162     for (i = 0; i<BOARD_EEPROM_VERSION_ADDR; i++) txBuf[idx++] = info->version[i];
163     for (i = 0; i<BOARD_EEPROM_SERIAL_NO_LENGTH; i++) txBuf[idx++] = info->serialNum[i];
164     status = I2C_transfer(handle, &i2cTransaction);
165     if (status == false)
166     {
167         ret = BOARD_I2C_TRANSFER_FAIL;
168         I2C_close(handle);
169         Board_obj.i2cHandle = NULL;
170         return ret;
171     }
172     info->header[BOARD_EEPROM_HEADER_LENGTH] = '\0';
174     I2C_close(handle);
175     Board_obj.i2cHandle = NULL;
177     return ret;