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 * ======== systemInit.c ========
38 */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/IHeap.h>
43 #include <xdc/runtime/Log.h>
44 #include <xdc/runtime/System.h>
45 #include <ti/ipc/SharedRegion.h>
46 #include <ti/ipc/Ipc.h>
47 #include <ti/sysbios/family/c66/Cache.h>
49 #include "params.h"
50 #include "pafhjt.h"
51 #include "paf_heapMgr.h"
52 #include "aspMsg_common.h"
53 #include "aspMsg_master.h"
54 #include "aspDecOpCircBuf_master.h"
55 #include "audioStreamProc_master.h" // ASIT/ASOT config
56 #include "audioStreamProc_common.h" // ASIT/ASOT/ASDT config
57 #include "audioStreamInpProc.h"
58 #include "audioStreamOutProc.h"
59 #include "systemInit.h"
61 // FL: debug
62 #include "evmc66x_pinmux.h"
63 #include "evmc66x_gpio_dbg.h"
66 #define __TASK_NAME__ "TaskSysInit"
68 #define TASK_AFP_PRI ( 2 )
69 #define TASK_AIP_PRI ( 3 )
70 #define TASK_SSP_PRI ( 1 )
71 #define TASK_ASIP_PRI ( 5 ) //( 4 )
72 #define TASK_ASOP_PRI ( 4 )
74 #define SYS_INIT_SLEEP ( 100 )
77 extern Void ACP_main_cus(Void); // (*** ?) FL: revisit -- check method of patching alpha codes
78 //extern Void taskSystemStreamFxn(Void); // (*** ?) FL: revisit -- shouldn't need to call this from system init
80 //#define MEMSTAT_REPORT
81 #ifdef MEMSTAT_REPORT
82 #include "paf_alg_print.h"
83 #endif
85 #define RAM_REPORT
86 #ifdef RAM_REPORT
87 #include "audioStreamProc_params.h"
88 #include "paf_alg_print.h"
89 extern PAF_ASIT_Fxns PAF_ASIT_params_fxns;
90 extern PAF_ASOT_Fxns PAF_ASOT_params_fxns;
91 #endif
93 // Task initialization flag array.
94 // Each flag indicates whether Task has been initialized.
95 // 0: uninitialized
96 // 1: initialized
97 Int gTaskInitFlag[NUM_SYS_TASKS];
99 // PAF Hidden Jump Table (HJT) pointer
100 const PAFHJT_t *pafhjt;
103 /*
104 * ======== taskSysInitFxn ========
105 * System Initializations task function
106 */
107 Void taskSysInitFxn(Void)
108 {
109 UInt16 regionId;
110 IHeap_Handle srHeapMsmc, srHeapDdr3, srHeapNonCacheDdr3;
111 UInt16 remoteProcId;
112 Int status;
115 Log_info0("Enter taskSysInitFxn()");
117 // Create Shared DDR region as non-Cacheable, Before IPC attach
118 // TODO: remove hardcoded address and get correct values from .bld
119 { // base: 0x81000000, len: 0x01000000,
120 //UInt Common2_DDR3_MAR_base = 0x01848204;
121 UInt Common2_DDR3_base = 0x81000000;
122 UInt Common2_DDR3_len = 0x01000000;
123 // disable cache for common2 DDR3
124 Cache_setMar((xdc_Ptr)Common2_DDR3_base, Common2_DDR3_len, Cache_Mar_DISABLE);
125 }
127 //taskPriAfp = Task_setPri(TaskAfp, -1);
128 //taskPriAip = Task_setPri(TaskAip, -1);
129 //taskPriAsip = Task_setPri(TaskAsip, -1);
131 /* Attach IPC */
132 Log_info0("taskSysInitFxn:Ipc_attach()");
133 remoteProcId = MultiProc_getId(SLAVE_NAME);
134 if (remoteProcId == MultiProc_INVALIDID) {
135 System_abort("Improper MultiProc ID\n");
136 }
137 do {
138 status = Ipc_attach(remoteProcId);
139 //} while ((status < 0) && (status == Ipc_E_NOTREADY));
140 } while (status != Ipc_S_SUCCESS);
142 /* Initialize (IPC) ASP master messaging */
143 /* Note: MessageQ_open() called in this function.
144 MessageQ_open() blocks. */
145 Log_info0("taskSysInitFxn:AspMsgMaster_init()");
146 status = AspMsgMaster_init(
147 hAspMsgMaster,
148 remoteProcId,
149 ASP_MSG_MASTER_DEF_NUMMSGS);
150 if (status < 0)
151 {
152 Log_info0("TaskSysInit: unable to initialize ASP messaging. Exiting.");
153 return;
154 }
156 /* Initialize decoder output circular buffer control */
157 Log_info0("taskSysInitFxn:cbCtlInit()");
158 status = cbCtlInit(&gPAF_ASPM_config.decOpCircBufCtl, asip_params.zone.decodeN, &gPAF_AST_config.xDecOpCb);
159 if (status < 0)
160 {
161 Log_info0("TaskSysInit: unable to initialize Decoder Output Circular Buffer Control. Exiting.");
162 return;
163 }
164 /* Initialize Output Processing Init-Sync control */
165 Log_info0("taskSysInitFxn:outIsCtlInit()");
166 status = outIsCtlInit(&gPAF_ASPM_config.outIsCtl, &gPAF_AST_config.xOutIsi);
167 if (status < 0)
168 {
169 Log_info1("%s: unable to initialize Output Init-Sync Control. Exiting.", (IArg)__TASK_NAME__);
170 return;
171 }
173 /* Initialize PAF heap manager */
174 Log_info0("taskSysInitFxn:pafHeapMgr_init()");
175 regionId = SharedRegion_getIdByName("SR_MSMC");
176 srHeapMsmc = (IHeap_Handle)SharedRegion_getHeap(regionId);
177 regionId = SharedRegion_getIdByName("SR_DDR3");
178 srHeapDdr3 = (IHeap_Handle)SharedRegion_getHeap(regionId);
179 regionId = SharedRegion_getIdByName("COMMON2_DDR3");
180 srHeapNonCacheDdr3 = (IHeap_Handle)SharedRegion_getHeap(regionId);
181 pafHeapMgr_init((IHeap_Handle)heapMemL2Sram,
182 (IHeap_Handle)heapMemMsmcSram,
183 (IHeap_Handle)heapMemDdr3,
184 srHeapMsmc,
185 srHeapDdr3,
186 srHeapNonCacheDdr3);
188 #ifdef MEMSTAT_REPORT
189 // Output current heap memory usage
190 PAF_ALG_memStatusPrint("System Initialization, Initial MEMSTAT REPORT",
191 PAF_HEAP_INT, PAF_HEAP_INT1, PAF_HEAP_EXT,
192 PAF_HEAP_INT1_SHM, PAF_HEAP_EXT_SHM, PAF_HEAP_EXT_NONCACHED_SHM);
193 #endif
195 /* Initialize HJT */
196 pafhjt = &PAFHJT_RAM;
198 /* Patch sigma tables */
199 Log_info0("taskSysInitFxn:ACP_main_cus()");
200 ACP_main_cus();
202 #ifdef RAM_REPORT // patch RAM report functions
203 PAF_ASIT_params_fxns.headerPrint = PAF_ALG_headerPrint;
204 PAF_ASIT_params_fxns.allocPrint = PAF_ALG_allocPrint;
205 PAF_ASIT_params_fxns.commonPrint = PAF_ALG_commonPrint;
206 PAF_ASIT_params_fxns.bufMemPrint = PAF_ALG_bufMemPrint;
207 PAF_ASIT_params_fxns.memStatusPrint = PAF_ALG_memStatusPrint;
208 PAF_ASOT_params_fxns.headerPrint = PAF_ALG_headerPrint;
209 PAF_ASOT_params_fxns.allocPrint = PAF_ALG_allocPrint;
210 PAF_ASOT_params_fxns.commonPrint = PAF_ALG_commonPrint;
211 PAF_ASOT_params_fxns.bufMemPrint = PAF_ALG_bufMemPrint;
212 PAF_ASOT_params_fxns.memStatusPrint = PAF_ALG_memStatusPrint;
213 #endif
215 // FL: debug
216 // Any of these can be used on ARM, but DSP must configure the GPIO since pinMuxSetMode() is only available on DSP
217 audk2g_pinMuxSetMode(101,AUDK2G_PADCONFIG_MUX_MODE_QUATERNARY); // PAD101 to QUATERNARY, GPIO (B5 on AudioDaughterCard J12)
218 GPIOSetDirection(GPIO_PORT_0, GPIO_PIN_99, GPIO_OUT); // GPIO0,pin99 output
219 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
220 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
221 audk2g_pinMuxSetMode(117,AUDK2G_PADCONFIG_MUX_MODE_QUATERNARY); // PAD117 to QUATERNARY, GPIO (B8 on AudioDaughterCard J12)
222 GPIOSetDirection(GPIO_PORT_0, GPIO_PIN_106, GPIO_OUT); // GPIO0,pin106 output
223 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
224 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
225 audk2g_pinMuxSetMode(118,AUDK2G_PADCONFIG_MUX_MODE_QUATERNARY); // PAD118 to QUATERNARY, GPIO (B9 on AudioDaughterCard J12)
226 GPIOSetDirection(GPIO_PORT_0, GPIO_PIN_107, GPIO_OUT); // GPIO0,pin107 output
227 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
228 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
230 /* This is required to use SYS alpha codes in atboot? */
231 Log_info0("taskSysInitFxn:TaskSystemStream resume");
232 gTaskInitFlag[TASK_SSP_INIT_FLAG_IDX] = 0;
233 Task_setPri(TaskSystemStream, TASK_SSP_PRI);
234 // Wait until Execution of TaskSystemStream is complete
235 // once.
236 while (gTaskInitFlag[TASK_SSP_INIT_FLAG_IDX] == 0) // System Stream initialization flag is set to 1 in TaskSystemStream
237 {
238 Task_sleep(SYS_INIT_SLEEP);
239 }
241 Task_setPri(TaskAfp, TASK_AFP_PRI);
242 Task_setPri(TaskAip, TASK_AIP_PRI);
243 Task_setPri(TaskAsip, TASK_ASIP_PRI);
244 Task_setPri(TaskAsop, TASK_ASOP_PRI);
246 #ifdef MEMSTAT_REPORT
247 // Output current heap memory usage
248 PAF_ALG_memStatusPrint("System Initialization, Final MEMSTAT REPORT",
249 PAF_HEAP_INT, PAF_HEAP_INT1, PAF_HEAP_EXT,
250 PAF_HEAP_INT1_SHM, PAF_HEAP_EXT_SHM, PAF_HEAP_EXT_NONCACHED_SHM);
251 #endif
253 Log_info0("Exit taskSysInitFxn()");
254 }