1 /******************************************************************************\r
2 * Copyright (c) 2020 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 board_utils.c\r
36 *\r
37 * \brief Implements multiple board utility functions\r
38 *\r
39 */\r
40 \r
41 #include <stdio.h>\r
42 #include <string.h>\r
43 #include "board_internal.h"\r
44 #include "board_utils.h"\r
45 #include "board_cfg.h"\r
46 #include <ti/osal/osal.h>\r
47 \r
48 Board_I2cInitCfg_t gBoardI2cInitCfg = {0, BOARD_SOC_DOMAIN_MAIN, 0};\r
49 Board_initParams_t gBoardInitParams = {BOARD_UART_INSTANCE, BOARD_UART_SOC_DOMAIN, BOARD_PSC_DEVICE_MODE_NONEXCLUSIVE};\r
50 \r
51 /**\r
52 * \brief Function to get board init params\r
53 *\r
54 * This function shall be used to know the current board init\r
55 * parameters and update them if needed using the function Board_setInitParams.\r
56 *\r
57 * \param initParams [IN] Board init params structure\r
58 *\r
59 * \return BOARD_SOK in case of success or appropriate error code.\r
60 *\r
61 */\r
62 Board_STATUS Board_getInitParams(Board_initParams_t *initParams)\r
63 {\r
64 if(initParams == NULL)\r
65 {\r
66 return BOARD_INVALID_PARAM;\r
67 }\r
68 \r
69 *initParams = gBoardInitParams;\r
70 \r
71 return BOARD_SOK;\r
72 }\r
73 \r
74 /**\r
75 * \brief Function to configure board init parameters\r
76 *\r
77 * Board init params includes the parameters used by Board_init\r
78 * function for different operations. Default init parameters\r
79 * used by Board_init can be updated using this function.\r
80 * All the default params can be overwritten by calling this function\r
81 * or some of can be changed by reading the existing init parameters\r
82 * using Board_getInitParams function.\r
83 *\r
84 * Usage:\r
85 * Call Board_getInitParams to get the default board init parameters\r
86 * Update the parameters as needed\r
87 * Call Board_setInitParams to update the default board init parameters\r
88 *\r
89 * \param initCfg [IN] Board Init config structure\r
90 *\r
91 * \return BOARD_SOK in case of success or appropriate error code.\r
92 *\r
93 */\r
94 Board_STATUS Board_setInitParams(Board_initParams_t *initParams)\r
95 {\r
96 if(initParams == NULL)\r
97 {\r
98 return BOARD_INVALID_PARAM;\r
99 }\r
100 \r
101 gBoardInitParams = *initParams;\r
102 \r
103 return BOARD_SOK;\r
104 }\r
105 \r
106 /**\r
107 * \brief Function to configure I2C configurations used by board\r
108 *\r
109 * This function is used to set the I2C controller instance and\r
110 * SoC domain used by the board module for IO expander and board\r
111 * ID info read.\r
112 *\r
113 * Usage:\r
114 * Call Board_setI2cInitConfig to set the I2C configurations\r
115 * Call IO expander Init or Board ID info read/write\r
116 *\r
117 * \return BOARD_SOK in case of success or appropriate error code.\r
118 *\r
119 */\r
120 Board_STATUS Board_setI2cInitConfig(Board_I2cInitCfg_t *i2cCfg)\r
121 {\r
122 if(i2cCfg == NULL)\r
123 {\r
124 return BOARD_INVALID_PARAM;\r
125 }\r
126 \r
127 gBoardI2cInitCfg = *i2cCfg;\r
128 \r
129 return BOARD_SOK;\r
130 }\r
131 \r
132 /**\r
133 * \brief Function to get I2C configurations used by board\r
134 *\r
135 * \return BOARD_SOK in case of success or appropriate error code.\r
136 *\r
137 */\r
138 Board_STATUS Board_getI2cInitConfig(Board_I2cInitCfg_t *i2cCfg)\r
139 {\r
140 if(i2cCfg == NULL)\r
141 {\r
142 return BOARD_INVALID_PARAM;\r
143 }\r
144 \r
145 *i2cCfg = gBoardI2cInitCfg;\r
146 \r
147 return BOARD_SOK;\r
148 }\r
149 \r
150 /**\r
151 * \brief Board detect function\r
152 *\r
153 * Checks if the board with given 'boardID' is connected to the\r
154 * base board.\r
155 *\r
156 * \n Note: Board ID EEPROM should be programmed for this function\r
157 * to work properly.\r
158 *\r
159 * \param boardID [IN] ID of the board to be detected\r
160 *\r
161 * \return TRUE if the given board is detected else FALSE.\r
162 *\r
163 */\r
164 bool Board_detectBoard(uint32_t boardID)\r
165 {\r
166 return 0;\r
167 }\r
168 \r
169 /**\r
170 * \brief Function to get the SoC domain\r
171 *\r
172 * This function returns the domain of the SoC core on which\r
173 * it is executing.\r
174 *\r
175 * \return SoC domain of the core.\r
176 *\r
177 */\r
178 uint32_t Board_getSocDomain(void)\r
179 {\r
180 uint32_t socDomain;\r
181 \r
182 #if defined (BUILD_MPU)\r
183 socDomain = BOARD_SOC_DOMAIN_MAIN;\r
184 #else\r
185 socDomain = BOARD_SOC_DOMAIN_MCU;\r
186 #endif\r
187 \r
188 return socDomain;\r
189 }\r
190 \r
191 /**\r
192 * \brief Function to generate delay in micro seconds\r
193 *\r
194 * This function takes the delay parameters in usecs but the generated\r
195 * delay will be in multiples of msecs due to the osal function which\r
196 * generates delay in msecs. Delay parameter passed will be converted to\r
197 * msecs and fractional value will be adjusted to nearest msecs value.\r
198 * Minimum delay generated by this function is 1 msec.\r
199 * Function parameter is kept in usecs to match with existing\r
200 * platforms which has delay function for usecs.\r
201 *\r
202 * \param usecs [IN] Specifies the time to delay in micro seconds.\r
203 *\r
204 */\r
205 void BOARD_delay(uint32_t usecs)\r
206 {\r
207 uint32_t msecs;\r
208 \r
209 msecs = usecs/1000;\r
210 if(usecs%1000)\r
211 {\r
212 msecs += 1;\r
213 }\r
214 \r
215 Osal_delay(msecs);\r
216 }\r