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 Cmbk2gAdcConfig adcCfg =\r
144 {\r
145 80, /* ADC gain */\r
146 CMBK2G_ADC_INL_SE_VINL1, /* Left input mux for ADC1L */\r
147 CMBK2G_ADC_INL_SE_VINL2, /* Left input mux for ADC2L */\r
148 CMBK2G_ADC_INR_SE_VINR1, /* Right input mux for ADC1R */\r
149 CMBK2G_ADC_INR_SE_VINR2, /* Right input mux for ADC2R */\r
150 CMBK2G_ADC_RX_WLEN_24BIT, /* ADC word length */\r
151 CMBK2G_ADC_DATA_FORMAT_I2S, /* ADC data format */\r
152 0\r
153 };\r
154 \r
155 /* DAC default configuration parameters */\r
156 Cmbk2gDacConfig dacCfg =\r
157 {\r
158 CMBK2G_DAC_AMUTE_CTRL_SCKI_LOST, /* Amute event */\r
159 0, /* Amute control */\r
160 CMBK2G_DAC_SAMPLING_MODE_AUTO, /* Sampling mode */\r
161 CMBK2G_DAC_DATA_FORMAT_I2S, /* Data format */\r
162 0, /* Soft mute control */\r
163 CMBK2G_DAC_ATTENUATION_WIDE_RANGE, /* Attenuation mode */\r
164 CMBK2G_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 char write_buffer[MAX_WRITE_LEN];\r
191 void cmbk2g_write(const char *fmt, ... )\r
192 {\r
193 va_list arg_ptr;\r
194 uint32_t length;\r
195 \r
196 /* Initial platform_write to temporary buffer.. at least try some sort of sanity check so we don't write all over\r
197 * memory if the print is too large.\r
198 */\r
199 if (strlen(fmt) > MAX_WRITE_LEN) {return;}\r
200 \r
201 va_start( arg_ptr, fmt );\r
202 length = vsprintf( (char *)write_buffer, fmt, arg_ptr );\r
203 va_end( arg_ptr );\r
204 \r
205 printf( "%s", write_buffer );\r
206 //fflush(stdout);\r
207 \r
208 return;\r
209 }\r
210 \r
211 void McaspDevice_init(void);\r
212 \r
213 /**\r
214 * \brief Initializes platform specific modules\r
215 *\r
216 * This function initializes the modules like PLL, DDR, I2C etc\r
217 * which are required for audio processing. Need to call this function\r
218 * before doing any HW related operations.\r
219 *\r
220 * \return Cmbk2g_EOK on Success or error code\r
221 */\r
222 Cmbk2g_STATUS initPlatform(void)\r
223 {\r
224 Board_STATUS status = BOARD_SOK;\r
225 Board_initCfg arg = BOARD_INIT_PINMUX_CONFIG | BOARD_INIT_MODULE_CLOCK;\r
226 status = Board_init(arg);\r
227 \r
228 #if 1\r
229 /* Configure McASP AUXCLK source as AUDIO_OSCCLK */\r
230 hBootCfg->SERIALPORT_CLKCTL = 0;\r
231 /* Enable audio oscillator */\r
232 hBootCfg->OSC_CTL = 0x200; //SW2:SW1 = 01 (15 - 30 MHz)\r
233 \r
234 {\r
235 int padCfg;\r
236 for (padCfg = 139; padCfg <= 191; padCfg++)\r
237 {\r
238 pinMuxSetMode_local(padCfg, PADCONFIG_MUX_MODE_QUINARY);\r
239 }\r
240 }\r
241 #endif\r
242 \r
243 // I2C init\r
244 /* Initialize all the I2C ports - Needed for different I2C devices on the board */\r
245 evmI2CInit(I2C_PORT_0);\r
246 evmI2CInit(I2C_PORT_1);\r
247 evmI2CInit(I2C_PORT_2);\r
248 \r
249 ///pinMuxSetMode(125, PADCONFIG_MUX_MODE_QUATERNARY);\r
250 ///gpioSetDirection(GPIO_PORT_1, 54, GPIO_OUT);\r
251 ///gpioSetOutput(GPIO_PORT_1, 54);\r
252 \r
253 /* Configure platform log messages to standard printf */\r
254 ///Cmbk2g_write_configure(Cmbk2g_WRITE_UART);\r
255 \r
256 /* Initialize UART */\r
257 ///Cmbk2g_uart_init();\r
258 ///Cmbk2g_uart_set_baudrate(115200);\r
259 \r
260 return(status);\r
261 }\r
262 \r
263 /**\r
264 * \brief Audio analog test main function\r
265 *\r
266 * \return none\r
267 */\r
268 void main (void)\r
269 {\r
270 Cmbk2g_STATUS status;\r
271 \r
272 status = initPlatform();\r
273 if(status != Cmbk2g_EOK)\r
274 {\r
275 cmbk2g_write("Platform Init Failed!\n");\r
276 testRet(1);\r
277 }\r
278 \r
279 cmbk2g_delay(10000);\r
280 \r
281 \r
282 system_init(); /* initialize system context, etc. */\r
283 \r
284 sysBfCreate(); /* Create beamformers */\r
285 sysAsnrCreate(); /* Create ASNR's */\r
286 sysMssCreate(); /* Create MSS */\r
287 #if (SYS_USE_DRC)\r
288 sysDrcCreate(); /* Create DRC */\r
289 #endif\r
290 ///sysVauCreate(); /* Create VAU */\r
291 \r
292 \r
293 cmbk2g_write("\n******************************************\n");\r
294 cmbk2g_write( " CMB Analog Loopback Test \n");\r
295 cmbk2g_write( "******************************************\n");\r
296 \r
297 cmbk2g_write("\nTest Verifies ADC and DAC Channels\n");\r
298 cmbk2g_write("Test Runs in Audio Loopback Mode\n");\r
299 cmbk2g_write("Confirm that CMB Mic 1 and Mic 8 Input are Played at On-Board Line-Out Left and Right Channels\n");\r
300 \r
301 /* Initialize McASP HW details */\r
302 McaspDevice_init();\r
303 \r
304 /* Configure eDMA module */\r
305 status = eDmaConfig();\r
306 if(status != Cmbk2g_EOK)\r
307 {\r
308 cmbk2g_write("eDMA Configuration Failed!\n");\r
309 testRet(1);\r
310 }\r
311 \r
312 /* Initialize common audio configurations */\r
313 status = (Cmbk2g_STATUS)cmbk2g_AudioInit();\r
314 if(status != Cmbk2g_EOK)\r
315 {\r
316 cmbk2g_write("Audio Init Failed!\n");\r
317 testRet(1);\r
318 }\r
319 \r
320 /* Initialize Audio ADC module */\r
321 status = audioAdcConfig(CMBK2G_ADC_DEVICE_0, &adcCfg);\r
322 if(status != Cmbk2g_EOK)\r
323 {\r
324 cmbk2g_write("Audio ADC0 Configuration Failed!\n");\r
325 testRet(1);\r
326 }\r
327 \r
328 status = audioAdcConfig(CMBK2G_ADC_DEVICE_1, &adcCfg);\r
329 if(status != Cmbk2g_EOK)\r
330 {\r
331 cmbk2g_write("Audio ADC1 Configuration Failed!\n");\r
332 testRet(1);\r
333 }\r
334 \r
335 /* Initialize McASP module */\r
336 status = mcaspAudioConfig();\r
337 if(status != Cmbk2g_EOK)\r
338 {\r
339 cmbk2g_write("McASP Configuration Failed!\n");\r
340 testRet(1);\r
341 }\r
342 \r
343 /* Start BIOS execution */\r
344 BIOS_start();\r
345 }\r
346 \r
347 /**\r
348 * \brief Configures audio DAC module\r
349 *\r
350 * \return none\r
351 */\r
352 #if CMBK2G_AUDIO_DAC\r
353 void configAudioDAC(void)\r
354 {\r
355 Cmbk2g_STATUS status;\r
356 \r
357 /* Initialize Audio DAC0 module */\r
358 status = audioDacConfig(CMBK2G_DAC_DEVICE_0, &dacCfg);\r
359 if(status != Cmbk2g_EOK)\r
360 {\r
361 cmbk2g_write("Audio DAC0 Configuration Failed!\n");\r
362 testRet(1);\r
363 }\r
364 }\r
365 #endif\r
366 \r
367 /* Nothing past this point */\r