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