1 /*\r
2 * Copyright (c) 2017, Texas Instruments Incorporated\r
3 * All rights reserved.\r
4 *\r
5 * Redistribution and use in source and binary forms, with or without\r
6 * modification, are permitted provided that the following conditions\r
7 * are met:\r
8 *\r
9 * * Redistributions of source code must retain the above copyright\r
10 * notice, this list of conditions and the following disclaimer.\r
11 *\r
12 * * Redistributions in binary form must reproduce the above copyright\r
13 * notice, this list of conditions and the following disclaimer in the\r
14 * documentation and/or other materials provided with the 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 "AS IS"\r
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
31 *\r
32 */\r
33 \r
34 /**\r
35 * \file main.c\r
36 *\r
37 * \brief Audio DC analog test main file\r
38 *\r
39 * Audio analog test verifies the functionality of ADC and DAC available on\r
40 * audio daughter card. During this test, data received from ADC will be\r
41 * sent to DAC. There are two instances of DAC and ADC available on\r
42 * audio daughter card. One ADC supports 4 analog channels and one DAC\r
43 * supports 8 analog channels. Data received from one DAC shall be sent\r
44 * to both the ADCs making 8 channel Rx/Tx. Each DAC should be validated\r
45 * separately.\r
46 *\r
47 */\r
48 \r
49 #include "analog_test.h"\r
50 #include "board.h"\r
51 \r
52 /* System header files */\r
53 #include <xdc/std.h>\r
54 \r
55 #include <xdc/runtime/Error.h>\r
56 #include <xdc/runtime/System.h>\r
57 \r
58 /*----------------------------------------\r
59 * BIOS header files\r
60 *----------------------------------------*/\r
61 \r
62 #include <ti/sysbios/BIOS.h> /* mandatory - if you call APIs like BIOS_start() */\r
63 \r
64 /* Portable data types */\r
65 #include <ti/mas/types/types.h>\r
66 #include <ti/mas/util/ecomem.h>\r
67 \r
68 #include "../../../common/components/fil.h"\r
69 #include "../../../common/components/sys.h"\r
70 \r
71 /* Global System Configuration Structure */\r
72 sysConfig_t sysConfig = {\r
73 SYS_MICS_MAX, /* #microphones */\r
74 SYS_VMICS_MAX, /* #virtual microphones */\r
75 5, /* 5ms ASNR delay */\r
76 { 12, 9, 6}, /* ASNR band1=12dB, band2=9dB, band3=6dB */\r
77 TRUE, /* Enable ASNR */\r
78 FALSE, /* Do not use file I/O to load files (must use GEL to load into memory) */\r
79 TRUE, /* Use default angles for microphone configurations */\r
80 FALSE, /* Enable VAD */\r
81 -50, /* drc expansion knee point in dBm0 (dBFS is dBm0-3dB */\r
82 6, /* drc max gain in dB */\r
83 FALSE /* Disable DRC */\r
84 };\r
85 \r
86 /* Global FILE I/O Configuration Structure (must be configured even when file I/O not used */\r
87 filConfig_t filConfig = {\r
88 FIL_LENGTH_MAX, /* number of samples to load from a file */\r
89 SYS_MICS_MAX, /* number of files to use */\r
90 TRUE, /* big endian */\r
91 FALSE, /* do not wrap around */\r
92 40*SYS_FS_HZ /* Process 40s of the signal (current mic input file length */\r
93 };\r
94 \r
95 /* Acoustic environment */\r
96 /* Room Size (X,Y,Z) in meters */\r
97 /* 5.2000 4.3000 2.7000 */\r
98 \r
99 /* Table size (X,Y,Z) in meters */\r
100 /* 3.0000 2.4000 0.7600 */\r
101 \r
102 /* "Echo" generating speaker position (X,Y,Z) in meters */\r
103 /* 0 2.1500 1.2172 180 -90 VM-9 */\r
104 \r
105 /* People positions (X,Y,Z) in meters and angles relative to the table and array */\r
106 /* 1.8200 0.6452 1.2172 position#1 (person#1) -123.6056 -146.3944 VM-7\r
107 2.8200 0.6452 1.2172 -not used- -90.0000 180.0000 VM-6\r
108 3.8200 0.6452 1.2172 (person#2) -56.3944 146.3944 VM-5\r
109 1.8200 3.6548 1.2172 (person#3) 123.6056 -33.6056 VM-11\r
110 2.8200 3.6548 1.2172 -not used- 90.0000 0.0000 VM-0\r
111 3.8200 3.6548 1.2172 position#6 (person#4) 56.3944 33.6056 VM-1\r
112 */\r
113 \r
114 /* Microphone array mic positions (X,Y,Z) in meters */\r
115 /* 2.7922 2.1500 0.7600 mic#1 ("left" most) 180\r
116 2.8004 2.1304 0.7600 -135\r
117 2.8200 2.1222 0.7600 ("lower" most) -90\r
118 2.8396 2.1304 0.7600 -45\r
119 2.8478 2.1500 0.7600 ("right" most) 0\r
120 2.8396 2.1696 0.7600 45\r
121 2.8200 2.1778 0.7600 ("upper" most) 90\r
122 2.8004 2.1696 0.7600 mic#8 135\r
123 */\r
124 /* Array Center = (2.82, 2.15, 0.76) (same as table center) */\r
125 \r
126 /* Noise source position (X,Y,Z) in meters */\r
127 /* 2.6000 2.1500 2.3000 */\r
128 \r
129 /* Initialize FILE I/O, system context */\r
130 static void system_init(void)\r
131 {\r
132 int err;\r
133 \r
134 err = sysCreate(&sysConfig); /* Create system context */\r
135 SYS_CHECK_ERROR(err);\r
136 \r
137 err = sysPrintConfig(SYSM_SCOPE_STATIC|SYSM_SCOPE_DYNAMIC);\r
138 SYS_CHECK_ERROR(err);\r
139 \r
140 } /* system_init */\r
141 \r
142 /* ADC default configuration parameters */\r
143 CmbAdcConfig adcCfg =\r
144 {\r
145 80, /* ADC gain */\r
146 CMB_ADC_INL_SE_VINL1, /* Left input mux for ADC1L */\r
147 CMB_ADC_INL_SE_VINL3, /* Left input mux for ADC2L */\r
148 CMB_ADC_INR_SE_VINR1, /* Right input mux for ADC1R */\r
149 CMB_ADC_INR_SE_VINR3, /* Right input mux for ADC2R */\r
150 CMB_ADC_RX_WLEN_24BIT, /* ADC word length */\r
151 CMB_ADC_DATA_FORMAT_I2S, /* ADC data format */\r
152 0\r
153 };\r
154 \r
155 /* DAC default configuration parameters */\r
156 CmbDacConfig dacCfg =\r
157 {\r
158 CMB_DAC_AMUTE_CTRL_SCKI_LOST, /* Amute event */\r
159 0, /* Amute control */\r
160 CMB_DAC_SAMPLING_MODE_AUTO, /* Sampling mode */\r
161 CMB_DAC_DATA_FORMAT_I2S, /* Data format */\r
162 0, /* Soft mute control */\r
163 CMB_DAC_ATTENUATION_WIDE_RANGE, /* Attenuation mode */\r
164 CMB_DAC_DEEMP_44KHZ, /* De-emph control */\r
165 80 /* Volume */\r
166 };\r
167 \r
168 typedef enum {\r
169 PADCONFIG_MUX_MODE_PRIMARY = 0, /**< Primary pin mux mode */\r
170 PADCONFIG_MUX_MODE_SECONDARY, /**< Secondary pin mux mode */\r
171 PADCONFIG_MUX_MODE_TERTIARY, /**< Tertiary pin mux mode */\r
172 PADCONFIG_MUX_MODE_QUATERNARY, /**< Quaternary pin mux mode */\r
173 PADCONFIG_MUX_MODE_QUINARY, /**< Quinary pin mux mode */\r
174 PADCONFIG_MUX_MODE_SENARY /**< Senary pin mux mode */\r
175 \r
176 } PadCfgMuxMode;\r
177 \r
178 /*\r
179 * Function to enable the pinmux for the mcasp and i2c devices in the soc.\r
180 *\r
181 */\r
182 void pinMuxSetMode_local(uint32_t padCfgId, PadCfgMuxMode muxMode)\r
183 {\r
184 volatile uint32_t *padCfgBase;\r
185 \r
186 padCfgBase = &hBootCfg->PADCONFIG0;\r
187 CSL_FINS(*(padCfgBase + padCfgId), BOOTCFG_PADCONFIG0_MUXMODE, muxMode);\r
188 }\r
189 \r
190 void McaspDevice_init(void);\r
191 \r
192 /**\r
193 * \brief Initializes platform specific modules\r
194 *\r
195 * This function initializes the modules like PLL, DDR, I2C etc\r
196 * which are required for audio processing. Need to call this function\r
197 * before doing any HW related operations.\r
198 *\r
199 * \return Cmb_EOK on Success or error code\r
200 */\r
201 Cmb_STATUS initPlatform(void)\r
202 {\r
203 Board_STATUS status = BOARD_SOK;\r
204 Board_initCfg arg = BOARD_INIT_PINMUX_CONFIG | BOARD_INIT_MODULE_CLOCK;\r
205 status = Board_init(arg);\r
206 \r
207 #if 1\r
208 /* Configure McASP AUXCLK source as AUDIO_OSCCLK */\r
209 hBootCfg->SERIALPORT_CLKCTL = 0;\r
210 /* Enable audio oscillator */\r
211 hBootCfg->OSC_CTL = 0x200; //SW2:SW1 = 01 (15 - 30 MHz)\r
212 \r
213 {\r
214 int padCfg;\r
215 for (padCfg = 139; padCfg <= 191; padCfg++)\r
216 {\r
217 pinMuxSetMode_local(padCfg, PADCONFIG_MUX_MODE_QUINARY);\r
218 }\r
219 }\r
220 #endif\r
221 \r
222 // I2C init\r
223 /* Initialize all the I2C ports - Needed for different I2C devices on the board */\r
224 evmI2CInit(I2C_PORT_0);\r
225 evmI2CInit(I2C_PORT_1);\r
226 evmI2CInit(I2C_PORT_2);\r
227 \r
228 ///pinMuxSetMode(125, PADCONFIG_MUX_MODE_QUATERNARY);\r
229 ///gpioSetDirection(GPIO_PORT_1, 54, GPIO_OUT);\r
230 ///gpioSetOutput(GPIO_PORT_1, 54);\r
231 \r
232 /* Configure platform log messages to standard printf */\r
233 ///Cmb_write_configure(Cmb_WRITE_UART);\r
234 \r
235 /* Initialize UART */\r
236 ///Cmb_uart_init();\r
237 ///Cmb_uart_set_baudrate(115200);\r
238 \r
239 return(status);\r
240 }\r
241 \r
242 /**\r
243 * \brief Audio analog test main function\r
244 *\r
245 * \return none\r
246 */\r
247 void main (void)\r
248 {\r
249 Cmb_STATUS status;\r
250 \r
251 status = initPlatform();\r
252 if(status != Cmb_EOK)\r
253 {\r
254 cmb_write("Platform Init Failed!\n");\r
255 testRet(1);\r
256 }\r
257 \r
258 cmb_delay(10000);\r
259 \r
260 \r
261 system_init(); /* initialize system context, etc. */\r
262 \r
263 sysBfCreate(); /* Create beamformers */\r
264 sysAsnrCreate(); /* Create ASNR's */\r
265 sysMssCreate(); /* Create MSS */\r
266 #if (SYS_USE_DRC)\r
267 sysDrcCreate(); /* Create DRC */\r
268 #endif\r
269 ///sysVauCreate(); /* Create VAU */\r
270 \r
271 \r
272 cmb_write("\n******************************************\n");\r
273 cmb_write( " CMB Analog Loopback Test \n");\r
274 cmb_write( "******************************************\n");\r
275 \r
276 cmb_write("\nTest Verifies ADC and DAC Channels\n");\r
277 cmb_write("Test Runs in Audio Loopback Mode\n");\r
278 cmb_write("Confirm that CMB Mic 1 and Mic 8 Input are Played at On-Board Line-Out Left and Right Channels\n");\r
279 \r
280 /* Initialize McASP HW details */\r
281 McaspDevice_init();\r
282 \r
283 /* Configure eDMA module */\r
284 status = eDmaConfig();\r
285 if(status != Cmb_EOK)\r
286 {\r
287 cmb_write("eDMA Configuration Failed!\n");\r
288 testRet(1);\r
289 }\r
290 \r
291 /* Initialize common audio configurations */\r
292 status = (Cmb_STATUS)cmb_AudioInit();\r
293 if(status != Cmb_EOK)\r
294 {\r
295 cmb_write("Audio Init Failed!\n");\r
296 testRet(1);\r
297 }\r
298 \r
299 /* reset Audio ADC module 0 */\r
300 status = cmb_AudioAdcReset(CMB_ADC_DEVICE_0);\r
301 cmb_delay(10000);\r
302 /* set PLL for Audio ADC module 0 */\r
303 status = cmb_AudioAdcSetPLL(CMB_ADC_DEVICE_0);\r
304 cmb_delay(200000);\r
305 \r
306 /* reset Audio ADC module 1 */\r
307 status = cmb_AudioAdcReset(CMB_ADC_DEVICE_1);\r
308 cmb_delay(10000);\r
309 \r
310 /* Initialize Audio ADC module */\r
311 status = audioAdcConfig(CMB_ADC_DEVICE_0, &adcCfg);\r
312 if(status != Cmb_EOK)\r
313 {\r
314 cmb_write("Audio ADC0 Configuration Failed!\n");\r
315 testRet(1);\r
316 }\r
317 cmb_delay(10000);\r
318 \r
319 status = audioAdcConfig(CMB_ADC_DEVICE_1, &adcCfg);\r
320 if(status != Cmb_EOK)\r
321 {\r
322 cmb_write("Audio ADC1 Configuration Failed!\n");\r
323 testRet(1);\r
324 }\r
325 cmb_delay(10000);\r
326 \r
327 /* Initialize McASP module */\r
328 status = mcaspAudioConfig();\r
329 if(status != Cmb_EOK)\r
330 {\r
331 cmb_write("McASP Configuration Failed!\n");\r
332 testRet(1);\r
333 }\r
334 \r
335 /* Start BIOS execution */\r
336 BIOS_start();\r
337 }\r
338 \r
339 /**\r
340 * \brief Configures audio DAC module\r
341 *\r
342 * \return none\r
343 */\r
344 #if CMB_AUDIO_DAC\r
345 void configAudioDAC(void)\r
346 {\r
347 Cmb_STATUS status;\r
348 \r
349 /* Initialize Audio DAC0 module */\r
350 status = audioDacConfig(CMB_DAC_DEVICE_0, &dacCfg);\r
351 if(status != Cmb_EOK)\r
352 {\r
353 cmb_write("Audio DAC0 Configuration Failed!\n");\r
354 testRet(1);\r
355 }\r
356 }\r
357 #endif\r
358 \r
359 /* Nothing past this point */\r