1 /******************************************************************************\r
2 * Copyright (c) 2019 Texas Instruments Incorporated - http://www.ti.com\r
3 *\r
4 * Redistribution and use in source and binary forms, with or without\r
5 * modification, are permitted provided that the following conditions\r
6 * are met:\r
7 *\r
8 * Redistributions of source code must retain the above copyright\r
9 * notice, this list of conditions and the following disclaimer.\r
10 *\r
11 * Redistributions in binary form must reproduce the above copyright\r
12 * notice, this list of conditions and the following disclaimer in the\r
13 * documentation and/or other materials provided with the\r
14 * distribution.\r
15 *\r
16 * Neither the name of Texas Instruments Incorporated nor the names of\r
17 * its contributors may be used to endorse or promote products derived\r
18 * from this software without specific prior written permission.\r
19 *\r
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
31 *\r
32 *****************************************************************************/\r
33 \r
34 /**\r
35 * \file common.h\r
36 *\r
37 * \brief The macro definitions and function prototypes which\r
38 * are common across different board devices.\r
39 *\r
40 */\r
41 \r
42 #ifndef _COMMON_H_\r
43 #define _COMMON_H_\r
44 \r
45 /**\r
46 *\r
47 * \ingroup BOARD_LIB_DEVICES\r
48 *\r
49 * \defgroup BOARD_LIB_DEVICES_COMMON Board Device Common Library\r
50 *\r
51 * Common APIs for writing a register or reading a register of the devices\r
52 * supported by board device library. Uses I2C LLD for the HW read/write.\r
53 *\r
54 * @{\r
55 *\r
56 */\r
57 /* @} */\r
58 \r
59 #include <ti/drv/uart/UART.h>\r
60 #include <ti/drv/uart/UART_stdio.h>\r
61 \r
62 #include <ti/drv/i2c/I2C.h>\r
63 #include <ti/drv/i2c/soc/I2C_soc.h>\r
64 \r
65 #include <ti/board/board.h>\r
66 \r
67 #include <ti/osal/osal.h>\r
68 #include <stdio.h>\r
69 #include <stdint.h>\r
70 #include <stdlib.h>\r
71 #include <string.h>\r
72 \r
73 #ifdef __cplusplus\r
74 extern "C" {\r
75 #endif\r
76 \r
77 /**\r
78 *\r
79 * \ingroup BOARD_LIB_DEVICES_COMMON \r
80 *\r
81 * \defgroup BOARD_LIB_DEVICES_COMMON_TYPES Data Types\r
82 *\r
83 * @{\r
84 *\r
85 */\r
86 \r
87 #define BOARD_DEVICES_CONFIG_END (-1)\r
88 \r
89 #define BOARD_DEVICES_ENABLE_LOGS (1U)\r
90 \r
91 #if !defined(BOARD_DEBUG_LOG)\r
92 #if defined(BOARD_DEVICES_ENABLE_LOGS)\r
93 #define BOARD_DEBUG_LOG UART_printf\r
94 #else\r
95 #define BOARD_DEBUG_LOG(x, ...)\r
96 #endif\r
97 #endif /* #if !defined(BOARD_DEBUG_LOG) */\r
98 \r
99 #define BOARD_FPD_MAX_REMOTE_SENSOR_DEVICES (8U)\r
100 \r
101 /** Sete the FPD module to disable state */\r
102 #define BOARD_FPD_MODE_DISABLE (0U)\r
103 /** Sete the FPD module to enable state */\r
104 #define BOARD_FPD_MODE_ENABLE (1U)\r
105 \r
106 /** Sets the FPD mode to normal operation */\r
107 #define BOARD_FPD_MODE_NORMAL (0U)\r
108 /** Sets the FPD mode to reset */\r
109 #define BOARD_FPD_MODE_RESET (1U)\r
110 \r
111 /** Sets the FPD I2C serial clock frequency to 100KBPS */\r
112 #define BOARD_FPD_KBPS_100 (0x64U)\r
113 /** Sets the FPD I2C serial clock frequency to 400KBPS */\r
114 #define BOARD_FPD_KBPS_400 (0x32U)\r
115 \r
116 /** To send the MSB of a register offset address first */\r
117 #define BOARD_I2C_REG_ADDR_MSB_FIRST (0x0U)\r
118 \r
119 /** To send the LSB of a register offset address first */\r
120 #define BOARD_I2C_REG_ADDR_LSB_FIRST (0x1U)\r
121 \r
122 #define ONE_MILLI_SEC (1U)\r
123 \r
124 /** I2C delay of 5 milliseconds */\r
125 #define BOARD_FPD_I2C_CFG_DELAY (5 * ONE_MILLI_SEC)\r
126 \r
127 /** I2C transaction default timeout */\r
128 #define BOARD_I2C_TRANSACTION_TIMEOUT (2000U)\r
129 \r
130 /**\r
131 * \brief FPD remote device object structure\r
132 */\r
133 typedef struct Board_FpdRmtDevObj_s\r
134 {\r
135 /** FPD remote sensor I2C device address */\r
136 uint32_t i2cDevAddr;\r
137 /** FPD remote I2C sensor device alias address */\r
138 uint32_t i2cDevAliasAddr;\r
139 } Board_FpdRmtDevObj;\r
140 \r
141 /**\r
142 * \brief FPD module object structure\r
143 */\r
144 typedef struct Board_FpdModuleObj_s\r
145 {\r
146 /** FPD deserializer device address */\r
147 uint32_t desSlvAddr;\r
148 /** FPD serializer device address */\r
149 uint32_t serSlvAddr;\r
150 /** FPD remote serializer/deserializer device alias address */\r
151 uint32_t serDesAliasAddr;\r
152 } Board_FpdModuleObj;\r
153 \r
154 /**\r
155 * \brief FPD remote device object structure\r
156 */\r
157 typedef struct Board_I2cRegProgObj_s\r
158 {\r
159 /** FPD register offset address */\r
160 int32_t regAddr;\r
161 /** FPD register data */\r
162 uint32_t regData;\r
163 /** FPD i2c delay in milliseconds */\r
164 uint32_t i2cDelay;\r
165 } Board_I2cRegProgObj;\r
166 \r
167 /* @} */\r
168 \r
169 /**\r
170 *\r
171 * \ingroup BOARD_LIB_DEVICES_COMMON \r
172 *\r
173 * \defgroup BOARD_LIB_DEVICES_API Application Interfaces\r
174 *\r
175 * @{\r
176 *\r
177 */\r
178 \r
179 /**\r
180 * \brief Delay generation function\r
181 *\r
182 * This function is used to generates delay proportional to user\r
183 * specified delay cycles.\r
184 *\r
185 * \param delayCycles [IN] Number of delay cycles.\r
186 *\r
187 */\r
188 void Board_delay(uint32_t delayCycles);\r
189 \r
190 /**\r
191 * \brief I2C 16-bit register read function\r
192 *\r
193 * This function is used to read the 16-bit data from the i2c\r
194 * device registers\r
195 *\r
196 * \param handle [IN] Low level driver handle\r
197 * \param slaveAddr [IN] I2C slave address\r
198 * \param regAddr [IN] I2C register offset address\r
199 * \param regData [OUT] I2C register data buffer\r
200 * \param numOfBytes [IN] Receive data width\r
201 * \param byteOrdSel [IN] Register address byte order select\r
202 * \param i2cTimeout [IN] I2C driver timeout value\r
203 *\r
204 * \return BOARD_SOK in case of success or appropriate error code.\r
205 */\r
206 Board_STATUS Board_i2c16BitRegRd(void *handle,\r
207 uint32_t slaveAddr,\r
208 uint16_t regAddr,\r
209 uint8_t *regData,\r
210 uint8_t numOfBytes,\r
211 uint8_t byteOrdSel,\r
212 uint32_t i2cTimeout);\r
213 \r
214 /**\r
215 * \brief I2C 16-bit register write function\r
216 *\r
217 * This function is used to write the data on the i2c\r
218 * device registers\r
219 *\r
220 * \param handle [IN] Low level driver handle\r
221 * \param slaveAddr [IN] I2C slave address\r
222 * \param regAddr [IN] I2C register offset address\r
223 * \param regData [IN] I2C register data buffer\r
224 * \param numOfBytes [IN] Receive data width\r
225 * \param byteOrdSel [IN] Register address byte order select\r
226 * \param i2cTimeout [IN] I2C driver timeout value\r
227 *\r
228 * \return BOARD_SOK in case of success or appropriate error code.\r
229 */\r
230 Board_STATUS Board_i2c16BitRegWr(void *handle,\r
231 uint32_t slaveAddr,\r
232 uint16_t regAddr,\r
233 uint8_t *regData,\r
234 uint8_t numOfBytes,\r
235 uint8_t byteOrdSel,\r
236 uint32_t i2cTimeout);\r
237 \r
238 /**\r
239 * \brief I2C 8-bit register read function\r
240 *\r
241 * This function is used to read the 8-bit data from the i2c\r
242 * device registers\r
243 *\r
244 * \param handle [IN] Low level driver handle\r
245 * \param slaveAddr [IN] I2C slave address\r
246 * \param regAddr [IN] I2C register offset address\r
247 * \param regData [OUT] I2C register data buffer\r
248 * \param numOfBytes [IN] Receive data width\r
249 * \param i2cTimeout [IN] I2C driver timeout value \r
250 *\r
251 * \return BOARD_SOK in case of success or appropriate error code.\r
252 */\r
253 Board_STATUS Board_i2c8BitRegRd(void *handle,\r
254 uint32_t slaveAddr,\r
255 uint8_t regAddr,\r
256 uint8_t *regData,\r
257 uint8_t numOfBytes,\r
258 uint32_t i2cTimeout);\r
259 \r
260 /**\r
261 * \brief I2C 8-bit register write function\r
262 *\r
263 * This function is used to write the 8-bit data on the i2c\r
264 * device registers\r
265 *\r
266 * \param handle [IN] Low level driver handle\r
267 * \param slaveAddr [IN] I2C slave address\r
268 * \param regAddr [IN] I2C register offset address\r
269 * \param regData [IN] I2C register data buffer\r
270 * \param numOfBytes [IN] Transmit data width\r
271 * \param i2cTimeout [IN] I2C driver timeout value \r
272 *\r
273 * \return BOARD_SOK in case of success or appropriate error code.\r
274 */\r
275 Board_STATUS Board_i2c8BitRegWr(void *handle,\r
276 uint32_t slaveAddr,\r
277 uint8_t regAddr,\r
278 uint8_t *regData,\r
279 uint8_t numOfBytes,\r
280 uint32_t i2cTimeout);\r
281 \r
282 /**\r
283 * \brief I2C 10-bit slave address register read function\r
284 *\r
285 * This function is used to write the 8-bit data on the i2c\r
286 * device registers\r
287 *\r
288 * \param handle [IN] Low level driver handle\r
289 * \param slaveAddr [IN] I2C slave address\r
290 * \param regAddr [IN] I2C register offset address\r
291 * \param regData [IN] I2C register data buffer\r
292 * \param i2cTimeout [IN] I2C driver timeout value \r
293 *\r
294 * \return BOARD_SOK in case of success or appropriate error code.\r
295 */\r
296 Board_STATUS Board_i2c10bit16bitRegRd(void *handle,\r
297 uint32_t slaveAddr,\r
298 uint16_t regAddr,\r
299 uint16_t *regData,\r
300 uint32_t i2cTimeout);\r
301 \r
302 /**\r
303 * \brief I2C 10-bit slave address register write function\r
304 *\r
305 * This function is used to write the 8-bit data on the i2c\r
306 * device registers\r
307 *\r
308 * \param handle [IN] Low level driver handle\r
309 * \param slaveAddr [IN] I2C slave address\r
310 * \param regAddr [IN] I2C register offset address\r
311 * \param regData [IN] I2C register data buffer\r
312 * \param i2cTimeout [IN] I2C driver timeout value \r
313 *\r
314 * \return BOARD_SOK in case of success or appropriate error code.\r
315 */\r
316 Board_STATUS Board_i2c10bit16bitRegWr(void *handle,\r
317 uint32_t slaveAddr,\r
318 uint16_t regAddr,\r
319 uint16_t regData,\r
320 uint32_t i2cTimeout);\r
321 #ifdef __cplusplus\r
322 }\r
323 #endif /* __cplusplus */\r
324 \r
325 #endif /* _COMMON_H_ */\r
326 \r
327 /* @} */\r