9ccb0f5211831d9b95614ef090fcdbe61120278c
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 // 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 ( 4 ) //( 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;
102 /* Semaphore handles for Tx and Rx - to put in structures */
103 Semaphore_Handle asipSemRx;
104 Semaphore_Handle asopSemTx;
105 void sysCreateSemaphores(void);
107 /*
108 * ======== taskSysInitFxn ========
109 * System Initializations task function
110 */
111 Void taskSysInitFxn(Void)
112 {
113 UInt16 regionId;
114 IHeap_Handle srHeapMsmc, srHeapDdr3, srHeapNonCacheDdr3;
115 UInt16 remoteProcId;
116 Int status;
119 Log_info0("Enter taskSysInitFxn()");
121 // Create Shared DDR region as non-Cacheable, Before IPC attach
122 // TODO: remove hardcoded address and get correct values from .bld
123 { // base: 0x81000000, len: 0x01000000,
124 //UInt Common2_DDR3_MAR_base = 0x01848204;
125 UInt Common2_DDR3_base = 0x81000000;
126 UInt Common2_DDR3_len = 0x01000000;
127 // disable cache for common2 DDR3
128 Cache_setMar((xdc_Ptr)Common2_DDR3_base, Common2_DDR3_len, Cache_Mar_DISABLE);
129 }
131 //taskPriAfp = Task_setPri(TaskAfp, -1);
132 //taskPriAip = Task_setPri(TaskAip, -1);
133 //taskPriAsip = Task_setPri(TaskAsip, -1);
135 /* Attach IPC */
136 Log_info0("taskSysInitFxn:Ipc_attach()");
137 remoteProcId = MultiProc_getId(SLAVE_NAME);
138 if (remoteProcId == MultiProc_INVALIDID) {
139 System_abort("Improper MultiProc ID\n");
140 }
141 do {
142 status = Ipc_attach(remoteProcId);
143 //} while ((status < 0) && (status == Ipc_E_NOTREADY));
144 } while (status != Ipc_S_SUCCESS);
146 /* Initialize (IPC) ASP master messaging */
147 /* Note: MessageQ_open() called in this function.
148 MessageQ_open() blocks. */
149 Log_info0("taskSysInitFxn:AspMsgMaster_init()");
150 status = AspMsgMaster_init(
151 hAspMsgMaster,
152 remoteProcId,
153 ASP_MSG_MASTER_DEF_NUMMSGS);
154 if (status < 0)
155 {
156 Log_info0("TaskSysInit: unable to initialize ASP messaging. Exiting.");
157 return;
158 }
160 /* Initialize decoder output circular buffer control */
161 Log_info0("taskSysInitFxn:cbCtlInit()");
162 status = cbCtlInit(&gPAF_ASPM_config.decOpCircBufCtl, asip_params.zone.decodeN, &gPAF_AST_config.xDecOpCb);
163 if (status < 0)
164 {
165 Log_info0("TaskSysInit: unable to initialize Decoder Output Circular Buffer Control. Exiting.");
166 return;
167 }
168 /* Initialize Output Processing Init-Sync control */
169 Log_info0("taskSysInitFxn:outIsCtlInit()");
170 status = outIsCtlInit(&gPAF_ASPM_config.outIsCtl, &gPAF_AST_config.xOutIsi);
171 if (status < 0)
172 {
173 Log_info1("%s: unable to initialize Output Init-Sync Control. Exiting.", (IArg)__TASK_NAME__);
174 return;
175 }
177 /* Initialize PAF heap manager */
178 Log_info0("taskSysInitFxn:pafHeapMgr_init()");
179 regionId = SharedRegion_getIdByName("SR_MSMC");
180 srHeapMsmc = (IHeap_Handle)SharedRegion_getHeap(regionId);
181 regionId = SharedRegion_getIdByName("SR_DDR3");
182 srHeapDdr3 = (IHeap_Handle)SharedRegion_getHeap(regionId);
183 regionId = SharedRegion_getIdByName("COMMON2_DDR3");
184 srHeapNonCacheDdr3 = (IHeap_Handle)SharedRegion_getHeap(regionId);
185 pafHeapMgr_init((IHeap_Handle)heapMemL2Sram,
186 (IHeap_Handle)heapMemMsmcSram,
187 (IHeap_Handle)heapMemDdr3,
188 srHeapMsmc,
189 srHeapDdr3,
190 srHeapNonCacheDdr3);
192 #ifdef MEMSTAT_REPORT
193 // Output current heap memory usage
194 PAF_ALG_memStatusPrint("System Initialization, Initial MEMSTAT REPORT",
195 PAF_HEAP_INT, PAF_HEAP_INT1, PAF_HEAP_EXT,
196 PAF_HEAP_INT1_SHM, PAF_HEAP_EXT_SHM, PAF_HEAP_EXT_NONCACHED_SHM);
197 #endif
199 /* Initialize HJT */
200 pafhjt = &PAFHJT_RAM;
202 /* Patch sigma tables */
203 Log_info0("taskSysInitFxn:ACP_main_cus()");
204 ACP_main_cus();
206 #ifdef RAM_REPORT // patch RAM report functions
207 PAF_ASIT_params_fxns.headerPrint = PAF_ALG_headerPrint;
208 PAF_ASIT_params_fxns.allocPrint = PAF_ALG_allocPrint;
209 PAF_ASIT_params_fxns.commonPrint = PAF_ALG_commonPrint;
210 PAF_ASIT_params_fxns.bufMemPrint = PAF_ALG_bufMemPrint;
211 PAF_ASIT_params_fxns.memStatusPrint = PAF_ALG_memStatusPrint;
212 PAF_ASOT_params_fxns.headerPrint = PAF_ALG_headerPrint;
213 PAF_ASOT_params_fxns.allocPrint = PAF_ALG_allocPrint;
214 PAF_ASOT_params_fxns.commonPrint = PAF_ALG_commonPrint;
215 PAF_ASOT_params_fxns.bufMemPrint = PAF_ALG_bufMemPrint;
216 PAF_ASOT_params_fxns.memStatusPrint = PAF_ALG_memStatusPrint;
217 #endif
219 #if 0 // debug
220 // Any of these can be used on ARM, but DSP must configure the GPIO since pinMuxSetMode() is only available on DSP
221 audk2g_pinMuxSetMode(101,AUDK2G_PADCONFIG_MUX_MODE_QUATERNARY); // PAD101 to QUATERNARY, GPIO (B5 on AudioDaughterCard J12)
222 GPIOSetDirection(GPIO_PORT_0, GPIO_PIN_99, GPIO_OUT); // GPIO0,pin99 output
223 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
224 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
225 audk2g_pinMuxSetMode(117,AUDK2G_PADCONFIG_MUX_MODE_QUATERNARY); // PAD117 to QUATERNARY, GPIO (B8 on AudioDaughterCard J12)
226 GPIOSetDirection(GPIO_PORT_0, GPIO_PIN_106, GPIO_OUT); // GPIO0,pin106 output
227 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
228 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
229 audk2g_pinMuxSetMode(118,AUDK2G_PADCONFIG_MUX_MODE_QUATERNARY); // PAD118 to QUATERNARY, GPIO (B9 on AudioDaughterCard J12)
230 GPIOSetDirection(GPIO_PORT_0, GPIO_PIN_107, GPIO_OUT); // GPIO0,pin107 output
231 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
232 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
233 #endif
235 /* This is required to use SYS alpha codes in atboot? */
236 Log_info0("taskSysInitFxn:TaskSystemStream resume");
237 gTaskInitFlag[TASK_SSP_INIT_FLAG_IDX] = 0;
238 Task_setPri(TaskSystemStream, TASK_SSP_PRI);
239 // Wait until Execution of TaskSystemStream is complete
240 // once.
241 while (gTaskInitFlag[TASK_SSP_INIT_FLAG_IDX] == 0) // System Stream initialization flag is set to 1 in TaskSystemStream
242 {
243 Task_sleep(SYS_INIT_SLEEP);
244 }
246 Task_setPri(TaskAfp, TASK_AFP_PRI);
247 Task_setPri(TaskAip, TASK_AIP_PRI);
248 Task_setPri(TaskAsip, TASK_ASIP_PRI);
249 Task_setPri(TaskAsop, TASK_ASOP_PRI);
251 sysCreateSemaphores();
253 #ifdef MEMSTAT_REPORT
254 // Output current heap memory usage
255 PAF_ALG_memStatusPrint("System Initialization, Final MEMSTAT REPORT",
256 PAF_HEAP_INT, PAF_HEAP_INT1, PAF_HEAP_EXT,
257 PAF_HEAP_INT1_SHM, PAF_HEAP_EXT_SHM, PAF_HEAP_EXT_NONCACHED_SHM);
258 #endif
260 Log_info0("Exit taskSysInitFxn()");
261 }
263 void sysCreateSemaphores(void)
264 {
265 Semaphore_Params SemParams;
267 Semaphore_Params_init(&SemParams);
269 asipSemRx = Semaphore_create(0, &SemParams, NULL);
270 asopSemTx = Semaphore_create(0, &SemParams, NULL);
271 }