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