2 /*
3 Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37 * ======== main.c ========
38 */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/Log.h>
43 #include <xdc/runtime/System.h>
44 #include <ti/sysbios/BIOS.h>
45 #include <ti/ipc/Ipc.h>
46 #include <ti/sysbios/hal/Cache.h>
47 #include <ti/xdais/xdas.h>
49 #include <board.h>
50 #include "evmc66x_i2c.h"
51 #include <aud.h>
52 #include <aud_audio.h>
53 #include "audio_dc_cfg.h"
54 #include "edma_cfg.h"
55 #include <soc/mcasp_soc.h>
57 #include "components/clk.h" /* PFP testing */
58 #include "pfp/pfp.h"
59 #include "pfp_app.h" /* contains all PFP ID's */
61 #include "ioConfig.h" //TODO: remove this header
62 extern Void initDev2(Void);
63 extern void evmI2CInit(uint8_t i2cportnumber); // missing in evmc66x_i2c.h
65 #ifdef IO_LOOPBACK_TEST
66 extern void McaspDevice_init();
67 extern void D10_init();
68 extern Aud_STATUS mcaspAudioConfig();
69 extern void audioIoCreate(void);
70 extern void ioSemaphoreCreate(void);
71 #endif
73 // avoid including sap_d10.h, which would cause symbol redefinition
74 // warning (MCASP_PFUNC_XXX)
75 extern XDAS_Int32 D10_init(void);
77 /*
78 * ======== main ========
79 */
80 Int main()
81 {
82 Int status;
83 Aud_STATUS AudStatus;
84 Int k;
85 Board_initCfg cfg;
87 Log_info0("Enter main()");
89 /* Setup Profile Points (PFP) */
90 Log_info0("enter PFP Setup");
91 pfpCreate();
92 pfpCalibrate(1000, 1);
93 #if 0 // enabled in System Stream
94 for (k = 0; k <= PFP_ID_LAST; k++)
95 {
96 pfpEnable(k); /* Enable profile point #k */
97 }
98 #endif
99 for (k = 1; k <= PFP_ID_LAST; k++)
100 {
101 pfpSetAlpha(k, PFP_DEF_ALPHA); /* Set default exp. avg. time const. */
102 }
103 #if 0 // debug: dummy load
104 pfpEnable(0); /* Enable profile point #0 */
105 for (k = 0; k < 1000; k++)
106 {
107 pfpBegin(PFP_ID_MAIN,0);
108 clkWorkDelay(CLK_WORKCNT_PER_MS); /* This should take about 750,000 cycles to execute, or 750e3/600e6=1.25 msec. */
109 pfpEnd(PFP_ID_MAIN,0);
110 }
111 pfpDisable(0); /* Disable profile point #0 */
112 #endif
114 /* initialize board */
115 cfg = BOARD_INIT_PINMUX_CONFIG | BOARD_INIT_MODULE_CLOCK;
116 Board_init(cfg);
117 evmI2CInit(I2C_PORT_0);
118 evmI2CInit(I2C_PORT_1);
119 evmI2CInit(I2C_PORT_2);
121 Log_info0("exit Board init");
123 Log_info0("Configure EDMA");
124 /* Configure eDMA module */
125 AudStatus = eDmaConfig();
126 if(AudStatus != Aud_EOK)
127 {
128 //System_printf("eDMA Configuration Failed!\n");
129 Log_info0("eDMA Configuration Failed!");
130 //testRet(1);
131 }
133 #ifdef PASDK_SIO_DEV
134 Log_info0("initDev2");
135 initDev2();
136 #endif
138 #ifdef IO_LOOPBACK_TEST
139 /* Initialize McASP HW details */
140 McaspDevice_init();
142 D10_init();
144 #ifdef INPUT_SPDIF
145 // Input is DIR
146 AudStatus = aud_AudioSelectClkSrc(AUD_AUDIO_CLK_SRC_DIR);
147 #else
148 // Input is HDMI
149 AudStatus = aud_AudioSelectClkSrc(AUD_AUDIO_CLK_SRC_I2S);
150 #endif
151 if(AudStatus != Aud_EOK)
152 {
153 Log_info0("aud_AudioSelectClkSrc Failed!\n");
154 }
155 aud_delay(50000); // Without delay between these 2 calls system aborts.
157 /* Initialize McASP module */
158 status = mcaspAudioConfig();
159 if(status != Aud_EOK)
160 {
161 Log_info0("McASP Configuration Failed!\n");
162 }
164 ioSemaphoreCreate();
166 audioIoCreate();
168 Task_setPri(TaskAfp, -1);
169 Task_setPri(TaskAip, -1);
170 Task_setPri(TaskSysInit, -1);
171 Task_setPri(TaskAsip, 5);
172 Task_setPri(TaskAsop, 5);
173 #endif
175 Log_info0("McASP device init");
176 /* Initialize McASP SOC level configuration */
177 McaspDevice_init();
179 Log_info0("D10 init");
180 /* Initialize audio hardware */
181 D10_init();
183 Log_info0("IPC start");
184 /* Initialize IPC */
185 status = Ipc_start();
186 if (status < 0)
187 {
188 System_abort("Ipc_start failed\n");
189 }
191 BIOS_start(); /* does not return */
192 return(0);
193 }