[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / framework / systemInit.c
2 /*
3 Copyright (c) 2016, 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>
48 #include "pafhjt.h"
49 #include "paf_heapMgr.h"
50 #include "aspMsg_common.h"
51 #include "aspMsg_master.h"
52 #include "aspDecOpCircBuf_master.h"
53 #include "audioStreamProc_master.h" // ASIT/ASOT config
54 #include "audioStreamProc_common.h" // ASIT/ASOT/ASDT config
55 #include "fwkSim.h"
57 extern Void ACP_main_cus(Void); // (*** ?) FL: revisit -- check method of patching alpha codes
58 extern Void idleAudioStream(Void); // (*** ?) FL: revisit -- shouldn't need to call this from system init
60 const PAFHJT_t *pafhjt;
62 #define RAM_REPORT
63 #ifdef RAM_REPORT
64 #include <audioStreamProc_params.h>
65 #include <paf_alg_print.h>
66 extern PAF_AST_Fxns PAF_ASIT_params_fxns;
67 extern PAF_AST_Fxns PAF_ASOT_params_fxns;
68 #endif
70 Int gSysInit=0;
72 #define TASK_AFP_PRI ( 1 )
73 #define TASK_AIP_PRI ( 2 )
74 #define TASK_ASIP_PRI ( 3 )
75 #define TASK_ASOP_PRI ( 3 )
77 #define __TASK_NAME__ "TaskSysInit"
79 /*
80 * ======== taskSysInitFxn ========
81 * System Initializations task function
82 */
83 Void taskSysInitFxn(Void)
84 {
85 UInt16 regionId;
86 IHeap_Handle srHeapMsmc, srHeapDdr3;
87 UInt16 remoteProcId;
88 Int status;
91 Log_info0("Enter taskSysInitFxn()");
93 //taskPriAfp = Task_setPri(TaskAfp, -1);
94 //taskPriAip = Task_setPri(TaskAip, -1);
95 //taskPriAsip = Task_setPri(TaskAsip, -1);
97 /* Attach IPC */
98 Log_info0("taskSysInitFxn:Ipc_attach()");
99 remoteProcId = MultiProc_getId(SLAVE_NAME);
100 if (remoteProcId == MultiProc_INVALIDID) {
101 System_abort("Improper MultiProc ID\n");
102 }
103 do {
104 status = Ipc_attach(remoteProcId);
105 //} while ((status < 0) && (status == Ipc_E_NOTREADY));
106 } while (status != Ipc_S_SUCCESS);
108 /* Initialize (IPC) ASP master messaging */
109 /* Note: MessageQ_open() called in this function.
110 MessageQ_open() blocks. */
111 Log_info0("taskSysInitFxn:AspMsgMaster_init()");
112 status = AspMsgMaster_init(
113 hAspMsgMaster,
114 remoteProcId,
115 ASP_MSG_MASTER_DEF_NUMMSGS);
116 if (status < 0)
117 {
118 Log_info0("TaskSysInit: unable to initialize ASP messaging. Exiting.");
119 return;
120 }
122 /* Initialize decoder output circular buffer control */
123 status = cbCtlInit(&gPAF_ASPM_config.decOpCircBufCtl, gPAF_AST_config.xDecOpCb);
124 if (status < 0)
125 {
126 Log_info0("TaskSysInit: unable to initialize Decoder Output Circular Buffer Control. Exiting.");
127 return;
128 }
130 /* Initialize PAF heap manager */
131 Log_info0("taskSysInitFxn:pafHeapMgr_init()");
132 regionId = SharedRegion_getIdByName("SR_MSMC");
133 srHeapMsmc = (IHeap_Handle)SharedRegion_getHeap(regionId);
134 regionId = SharedRegion_getIdByName("SR_DDR3");
135 srHeapDdr3 = (IHeap_Handle)SharedRegion_getHeap(regionId);
136 pafHeapMgr_init((IHeap_Handle)heapMemL2Sram,
137 (IHeap_Handle)heapMemMsmcSram,
138 (IHeap_Handle)heapMemDdr3,
139 srHeapMsmc,
140 srHeapDdr3);
142 /* Initialize HJT */
143 pafhjt = &PAFHJT_RAM;
145 /* Patch sigma tables */
146 Log_info0("taskSysInitFxn:ACP_main_cus()");
147 ACP_main_cus();
149 #ifdef RAM_REPORT // patch RAM report functions
150 PAF_ASIT_params_fxns.headerPrint = PAF_ALG_headerPrint;
151 PAF_ASIT_params_fxns.allocPrint = PAF_ALG_allocPrint;
152 PAF_ASIT_params_fxns.commonPrint = PAF_ALG_commonPrint;
153 PAF_ASIT_params_fxns.bufMemPrint = PAF_ALG_bufMemPrint;
154 PAF_ASIT_params_fxns.memStatusPrint = PAF_ALG_memStatusPrint;
155 PAF_ASOT_params_fxns.headerPrint = PAF_ALG_headerPrint;
156 PAF_ASOT_params_fxns.allocPrint = PAF_ALG_allocPrint;
157 PAF_ASOT_params_fxns.commonPrint = PAF_ALG_commonPrint;
158 PAF_ASOT_params_fxns.bufMemPrint = PAF_ALG_bufMemPrint;
159 PAF_ASOT_params_fxns.memStatusPrint = PAF_ALG_memStatusPrint;
160 #endif
162 gSysInit=1;
164 /* This is required to use SYS alpha codes in atboot? */
165 Log_info0("taskSysInitFxn:idleAudioStream()");
166 idleAudioStream();
168 // Circumvent MessageQ_open() blocking.
169 Task_setPri(TaskAfp, TASK_AFP_PRI);
170 Task_setPri(TaskAip, TASK_AIP_PRI);
171 Task_setPri(TaskAsip, TASK_ASIP_PRI);
172 Task_setPri(TaskAsop, TASK_ASOP_PRI);
174 Log_info0("Exit taskSysInitFxn()");
175 }