[processor-sdk/performance-audio-sr.git] / pdk_k2g_1_0_1 / packages / ti / platform / evmk2g / platform_audio_test / digital_to_analog / src / main.c
diff --git a/pdk_k2g_1_0_1/packages/ti/platform/evmk2g/platform_audio_test/digital_to_analog/src/main.c b/pdk_k2g_1_0_1/packages/ti/platform/evmk2g/platform_audio_test/digital_to_analog/src/main.c
--- /dev/null
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2015, Texas Instruments Incorporated
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/**
+ * \file main.c
+ *
+ * \brief Audio DC analog test main file
+ *
+ * Audio analog test verifies the functionality of ADC and DAC available on
+ * audio daughter card. During this test, data received from ADC will be
+ * sent to DAC. There are two instances of DAC and ADC available on
+ * audio daughter card. One ADC supports 4 analog channels and one DAC
+ * supports 8 analog channels. Data received from one DAC shall be sent
+ * to both the ADCs making 8 channel Rx/Tx. Each DAC should be validated
+ * separately.
+ *
+ */
+
+#include "digital_to_analog_test.h"
+
+/* ADC default configuration parameters */
+AdcConfig adcCfg =
+{
+ 80, /* ADC gain */
+ ADC_INL_SE_VINL1, /* Left input mux for ADC1L */
+ ADC_INL_SE_VINL2, /* Left input mux for ADC2L */
+ ADC_INR_SE_VINR1, /* Right input mux for ADC1R */
+ ADC_INR_SE_VINR2, /* Right input mux for ADC2R */
+ ADC_RX_WLEN_24BIT, /* ADC word length */
+ ADC_DATA_FORMAT_I2S, /* ADC data format */
+ 0
+};
+
+/* DAC default configuration parameters */
+DacConfig dacCfg =
+{
+ DAC_AMUTE_CTRL_DAC_DISABLE_CMD, /* Amute event */
+ 0, /* Amute control */
+ DAC_SAMPLING_MODE_AUTO, /* Sampling mode */
+ DAC_DATA_FORMAT_I2S, /* Data format */
+ 0, /* Soft mute control */
+ DAC_ATTENUATION_WIDE_RANGE, /* Attenuation mode */
+ DAC_DEEMP_DISABLE, /* De-emph control */
+ 100 /* Volume */
+};
+
+void McaspDevice_init(void);
+
+/**
+ * \brief Initializes platform specific modules
+ *
+ * This function initializes the modules like PLL, DDR, I2C etc
+ * which are required for audio processing. Need to call this function
+ * before doing any HW related operations.
+ *
+ * \return Platform_EOK on Success or error code
+ */
+Platform_STATUS initPlatform(void)
+{
+ platform_init_flags init_flags;
+ platform_init_config init_config;
+ Platform_STATUS status;
+
+ /* Set request to configure PLL, DDR and Time Stamp Counter */
+ init_flags.pll = 1;
+ init_flags.ddr = 0;
+ init_flags.tcsl = 1;
+ init_flags.phy = 0;
+ init_flags.ecc = 0;
+
+ /* PLL configuration shall be done based on default values */
+ init_config.pllm = 0;
+ init_config.plld = 0;
+ init_config.postdiv = 0;
+ init_config.mastercore = 1;
+
+ status = platform_init(&init_flags, &init_config);
+ if (status != Platform_EOK)
+ {
+ printf("Error in Platform Initialization\n");
+ return(status);
+ }
+
+ pinMuxSetMode(125, PADCONFIG_MUX_MODE_QUATERNARY);
+ gpioSetDirection(GPIO_PORT_1, 54, GPIO_OUT);
+ gpioSetOutput(GPIO_PORT_1, 54);
+
+ /* Configure platform log messages to standard printf */
+ platform_write_configure(PLATFORM_WRITE_UART);
+
+ /* Initialize UART */
+ platform_uart_init();
+ platform_uart_set_baudrate(115200);
+
+ return(status);
+}
+
+/**
+ * \brief Audio digital to analog test main function
+ *
+ * \return none
+ */
+void main (void)
+{
+ Platform_STATUS status;
+
+ status = initPlatform();
+ if(status != Platform_EOK)
+ {
+ platform_write("Platform Init Failed!\n");
+ testRet(1);
+ }
+
+ platform_delay(10000);
+
+ platform_write("\n****************************************************\n");
+ platform_write( " Audio DC Digital to Analog Loopback Test \n");
+ platform_write( "****************************************************\n");
+
+#ifdef AUDIO_DAC0_TEST
+ platform_write("\nTest Verifies Audio DC Digital to Analog Loopback \n");
+ platform_write("Confirm that DIR Input Audio is Played at DAC Channel 0\n");
+
+#else
+
+ platform_write("\nTest Verifies Audio DC Digital to Analog Loopback \n");
+ platform_write("Confirm that DIR Input Audio is Played at DAC Channel 4\n");
+#endif
+
+ /* Initialize McASP HW details */
+ McaspDevice_init();
+
+ /* Configure eDMA module */
+ status = eDmaConfig();
+ if(status != Platform_EOK)
+ {
+ platform_write("eDMA Configuration Failed!\n");
+ testRet(1);
+ }
+
+
+ /* Initialize common audio configurations */
+ status = platformAudioInit();
+ if(status != Platform_EOK)
+ {
+ platform_write("Audio Init Failed!\n");
+ testRet(1);
+ }
+
+ /* Initialize the HDMI Card */
+ status = audioHDMIConfig();
+ if(status != Platform_EOK)
+ {
+ platform_write("Audio Init Failed!\n");
+ testRet(1);
+ }
+
+ /* Select DIR as audio clock source */
+#ifdef SPDIF
+ status = platformAudioSelectClkSrc(AUDIO_CLK_SRC_DIR);
+#else
+ status = platformAudioSelectClkSrc(AUDIO_CLK_SRC_I2S);
+#endif
+ if(status != Platform_EOK)
+ {
+ platform_write("Audio Clock Selection Failed!\n");
+ testRet(1);
+ }
+
+#ifdef SPDIF
+ /* Initialize Audio DIR module */
+ status = audioDirConfig();
+ if(status != Platform_EOK)
+ {
+ platform_write("Audio DIR Configuration Failed!\n");
+ testRet(1);
+ }
+
+#endif
+
+ /* Initialize McASP module */
+ status = mcaspAudioConfig();
+ if(status != Platform_EOK)
+ {
+ platform_write("McASP Configuration Failed!\n");
+ testRet(1);
+ }
+
+ /* Start BIOS execution */
+ BIOS_start();
+}
+
+/**
+ * \brief Configures audio DAC module
+ *
+ * \return none
+ */
+void configAudioDAC(void)
+{
+ Platform_STATUS status;
+
+ platform_delay(10000);
+
+ /* Initialize Audio DAC module */
+ status = audioDacConfig(DAC_DEVICE_ALL, &dacCfg);
+ if(status != Platform_EOK)
+ {
+ platform_write("Audio DAC Configuration Failed!\n");
+ testRet(1);
+ }
+}
+
+/* Nothing past this point */