1 /*
2 * Copyright (c) 2012-2014 Texas Instruments Incorporated - http://www.ti.com
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
33 /*
34 * ======== NotifyDriverMbx.xs ================
35 */
36 var NotifyDriverMbx = null;
37 var Core = null;
38 var isaChain = "";
40 /*
41 * ======== module$use ========
42 */
43 function module$use()
44 {
45 /* load modules needed in meta domain and in target domain */
46 var TableInit = xdc.useModule("ti.sdo.ipc.family.vayu.TableInit");
47 var MultiProc = xdc.useModule("ti.sdo.utils.MultiProc");
48 NotifyDriverMbx = this;
49 xdc.useModule('xdc.runtime.Assert');
50 xdc.useModule('xdc.runtime.Error');
51 xdc.useModule('xdc.runtime.Startup');
52 xdc.useModule("ti.sysbios.BIOS");
54 /* concatinate isa chain into single string for easier matching */
55 isaChain = "#" + Program.build.target.getISAChain().join("#") + "#";
57 if (isaChain.match(/#64P#/)) {
58 xdc.useModule("ti.sysbios.family.c64p.EventCombiner");
59 xdc.useModule("ti.sysbios.family.c64p.Hwi");
60 xdc.useModule("ti.sysbios.family.shared.vayu.IntXbar");
61 }
62 else if (isaChain.match(/#arp32#/)) {
63 xdc.useModule('ti.sysbios.family.arp32.Hwi');
64 }
65 else if (isaChain.match(/#v7M#/)) {
66 Core = xdc.useModule("ti.sysbios.family.arm.ducati.Core");
67 }
69 xdc.useModule('ti.sdo.ipc.Ipc');
70 xdc.useModule("ti.sdo.ipc.Notify");
71 xdc.useModule('ti.sdo.ipc.family.vayu.NotifySetup');
72 xdc.useModule('ti.sdo.ipc.interfaces.INotifyDriver');
74 /* initialize procIdTable */
75 TableInit.initProcId(this);
77 /* Initialize mailboxTable */
78 TableInit.generateTable(this);
80 if (isaChain.match(/#64P#|#v7M#|#v7A#/)) {
81 /* initialize mailbox base address table */
82 this.mailboxBaseAddr[0] = 0x4208B000; /* EVE1 Internal Mailbox 0 */
83 this.mailboxBaseAddr[1] = 0x4208C000; /* EVE1 Internal Mailbox 1 */
84 this.mailboxBaseAddr[2] = 0x4208D000; /* EVE1 Internal Mailbox 2 */
85 this.mailboxBaseAddr[3] = 0x4218B000; /* EVE2 Internal Mailbox 0 */
86 this.mailboxBaseAddr[4] = 0x4218C000; /* EVE2 Internal Mailbox 1 */
87 this.mailboxBaseAddr[5] = 0x4218D000; /* EVE2 Internal Mailbox 2 */
88 this.mailboxBaseAddr[6] = 0x4228B000; /* EVE3 Internal Mailbox 0 */
89 this.mailboxBaseAddr[7] = 0x4228C000; /* EVE3 Internal Mailbox 1 */
90 this.mailboxBaseAddr[8] = 0x4228D000; /* EVE3 Internal Mailbox 2 */
91 this.mailboxBaseAddr[9] = 0x4238B000; /* EVE4 Internal Mailbox 0 */
92 this.mailboxBaseAddr[10] = 0x4238C000; /* EVE4 Internal Mailbox 1 */
93 this.mailboxBaseAddr[11] = 0x4238D000; /* EVE4 Internal Mailbox 2 */
94 this.mailboxBaseAddr[12] = 0x48840000; /* System Mailbox 5 */
95 this.mailboxBaseAddr[13] = 0x48842000; /* System Mailbox 6 */
96 this.mailboxBaseAddr[14] = 0x48844000; /* System Mailbox 7 */
97 this.mailboxBaseAddr[15] = 0x48846000; /* System Mailbox 8 */
98 }
99 else if (isaChain.match(/#arp32#/)) {
100 this.mailboxBaseAddr[0] = 0x4008B000; /* EVE1 Internal Mailbox 0 */
101 this.mailboxBaseAddr[1] = 0x4008C000; /* EVE1 Internal Mailbox 1 */
102 this.mailboxBaseAddr[2] = 0x4208D000; /* EVE1 Internal Mailbox 2 */
103 this.mailboxBaseAddr[3] = 0x4008B000; /* EVE2 Internal Mailbox 0 */
104 this.mailboxBaseAddr[4] = 0x4008C000; /* EVE2 Internal Mailbox 1 */
105 this.mailboxBaseAddr[5] = 0x4218D000; /* EVE2 Internal Mailbox 2 */
106 this.mailboxBaseAddr[6] = 0x4008B000; /* EVE3 Internal Mailbox 0 */
107 this.mailboxBaseAddr[7] = 0x4008C000; /* EVE3 Internal Mailbox 1 */
108 this.mailboxBaseAddr[8] = 0x4228D000; /* EVE3 Internal Mailbox 2 */
109 this.mailboxBaseAddr[9] = 0x4008B000; /* EVE4 Internal Mailbox 0 */
110 this.mailboxBaseAddr[10] = 0x4008C000; /* EVE4 Internal Mailbox 1 */
111 this.mailboxBaseAddr[11] = 0x4238D000; /* EVE4 Internal Mailbox 2 */
112 this.mailboxBaseAddr[12] = 0x48840000; /* System Mailbox 5 */
113 this.mailboxBaseAddr[13] = 0x48842000; /* System Mailbox 6 */
114 this.mailboxBaseAddr[14] = 0x48844000; /* System Mailbox 7 */
115 this.mailboxBaseAddr[15] = 0x48846000; /* System Mailbox 8 */
117 /* each EVE receives its message using the local mailbox address */
118 if (MultiProc.id == this.eve1ProcId) {
119 this.mailboxBaseAddr[2] = 0x4008D000;
120 }
121 else if (MultiProc.id == this.eve2ProcId) {
122 this.mailboxBaseAddr[5] = 0x4008D000;
123 }
124 else if (MultiProc.id == this.eve3ProcId) {
125 this.mailboxBaseAddr[8] = 0x4008D000;
126 }
127 else if (MultiProc.id == this.eve4ProcId) {
128 this.mailboxBaseAddr[11] = 0x4008D000;
129 }
130 }
131 else {
132 throw("Invalid target: " + Program.build.target.$name);
133 }
134 }
137 /*
138 * ======== module$static$init ========
139 * Initialize the target state object.
140 */
141 function module$static$init(state, mod)
142 {
144 for (var i = 0; i < state.drvHandles.length; i++) {
145 state.drvHandles[i] = null;
146 }
148 if (isaChain.match(/#64P#/)) {
149 /* interrupt event IDs used by this processor */
150 state.interruptTable[0] = 55; /* EVE1 -> DSP1 or DSP2 */
151 state.interruptTable[1] = 56; /* EVE2 -> DSP1 or DSP2 */
152 state.interruptTable[2] = 58; /* EVE3 -> DSP1 or DSP2 */
153 state.interruptTable[3] = 59; /* EVE4 -> DSP1 or DSP2 */
154 state.interruptTable[4] = 60; /* DSP1 -> DSP2 */
155 state.interruptTable[5] = 60; /* DSP2 -> DSP1 */
156 state.interruptTable[8] = 57; /* HOST -> DSP1 or DSP2 */
158 /* these are not known at config time, set at runtime */
159 state.interruptTable[6] = 0; /* IPU1 -> DSP1 or DSP2 */
160 state.interruptTable[7] = 0; /* IPU2 -> DSP1 or DSP2 */
161 state.interruptTable[9] = 0; /* IPU1-1 -> DSP1 or DSP2 */
162 state.interruptTable[10] = 0; /* IPU2-1 -> DSP1 or DSP2 */
163 }
164 else if (isaChain.match(/#arp32#/)) {
165 /* interrupt event IDs used by this processor */
166 state.interruptTable[0] = 60; /* EVE1 - Group1/INTC1 */
167 state.interruptTable[1] = 60; /* EVE2 - Group1/INTC1 */
168 state.interruptTable[2] = 60; /* EVE3 - Group1/INTC1 */
169 state.interruptTable[3] = 60; /* EVE4 - Group1/INTC1 */
170 state.interruptTable[4] = 29; /* DSP1 - Group0/INTC0 */
171 state.interruptTable[5] = 30; /* DSP2 - Group0/INTC0 */
172 state.interruptTable[6] = 29; /* IPU1-0 */
173 state.interruptTable[7] = 30; /* IPU2-0 */
174 state.interruptTable[8] = 29; /* HOST */
175 state.interruptTable[9] = 30; /* IPU1-1 */
176 state.interruptTable[10] = 30; /* IPU2-1 */
177 }
178 else if (isaChain.match(/#v7M#/)) {
179 /* TODO */
180 // if (Core.id == 0) {
181 // Hwi.construct(state.hwi, 53, NotifyDriverMbx.isr);
182 // }
183 // else {
184 // Hwi.construct(state.hwi, 54, NotifyDriverMbx.isr);
185 // }
186 }
187 else if (isaChain.match(/#v7A#/)) {
188 /* TODO */
189 // Hwi.construct(state.hwi, 77, NotifyDriverMbx.isr);
190 }
191 else {
192 throw("Invalid target: " + Program.build.target.$name);
193 }
194 }
196 /*
197 *************************************************************************
198 * ROV View functions
199 *************************************************************************
200 */
202 /*
203 * ======== viewInitBasic ========
204 * Initizalize the 'Basic' ROV view. Called once per instance.
205 *
206 * view = instance of 'struct NotifyDriverMbx.BasicView'
207 */
208 function viewInitBasic(view, obj)
209 {
210 var Program = xdc.useModule('xdc.rov.Program');
211 var MultiProc = xdc.useModule('ti.sdo.utils.MultiProc');
213 /* view.remoteProc */
214 try {
215 view.remoteProc = MultiProc.getName$view(obj.remoteProcId);
216 }
217 catch (e) {
218 Program.displayError(view, 'remoteProc',
219 "Problem retrieving proc name: " + e);
220 }
221 }
223 /*
224 * ======== viewInitMailbox ========
225 * Initizalize the 'Mailbox' ROV view. Called once per instance.
226 *
227 * view = instance of 'struct xdc.rov.Program.InstDataView'
228 */
229 function viewInitMailbox(view, obj)
230 {
231 var Program = xdc.useModule('xdc.rov.Program');
232 var ScalarStructs = xdc.useModule('xdc.rov.support.ScalarStructs');
233 var MultiProc = xdc.useModule('ti.sdo.utils.MultiProc');
234 var modCfg = Program.getModuleConfig(
235 'ti.sdo.ipc.family.vayu.NotifyDriverMbx');
237 /* view.label (use remote processor name) */
238 try {
239 view.label = MultiProc.getName$view(obj.remoteProcId);
240 }
241 catch (e) {
242 Program.displayError(view, 'remoteProcId',
243 "Problem retrieving proc name: " + e);
244 }
246 /* create an array to hold the instance data table */
247 var dataTable = new Array();
248 var mailbox = ["Inbound", "Outbound"];
250 for (var i = 0; i < mailbox.length; i++) {
252 /* create the view element */
253 var elem = Program.newViewStruct(
254 'ti.sdo.ipc.family.vayu.NotifyDriverMbx', 'Mailbox');
256 /* elem.direction (make a descriptive label) */
257 if (mailbox[i] == "Inbound") {
258 elem.direction = mailbox[i] + " (from " + view.label + ")";
259 }
260 else if (mailbox[i] == "Outbound") {
261 elem.direction = mailbox[i] + " (to " + view.label + ")";
262 }
263 else {
264 throw new Error("invalid mailbox type");
265 }
267 /* elem.mailboxAddr */
268 var selfVirtId = modCfg.procIdTable[MultiProc.self$view()];
269 var idx;
271 if (mailbox[i] == "Inbound") {
272 idx = (obj.remoteVirtId * modCfg.NUM_CORES) + selfVirtId;
273 }
274 else if (mailbox[i] == "Outbound") {
275 idx = (selfVirtId * modCfg.NUM_CORES) + obj.remoteVirtId;
276 }
277 else {
278 throw new Error("invalid mailbox type");
279 }
281 var baseAddrIdx = (modCfg.mailboxTable[idx] >> 16) & 0xFFFF;
282 var mailboxAddr = modCfg.mailboxBaseAddr[baseAddrIdx];
283 elem.mailboxAddr = "0x" + Number(mailboxAddr).toString(16);
285 /* elem.subMbxId */
286 elem.subMbxId = modCfg.mailboxTable[idx] & 0xFF;
288 /* elem.msgCount */
289 try {
290 var MAILBOX_STATUS_IN = Program.fetchStruct(
291 ScalarStructs.S_Bits32$fetchDesc,
292 mailboxAddr + 0xC0 + (0x4 * elem.subMbxId), false);
293 elem.msgCount = MAILBOX_STATUS_IN.elem;
294 }
295 catch (e) {
296 Program.displayError(view, 'msgCount',
297 "Problem retrieving messsage count: " + e);
298 }
300 /* elem.mbxInterrupt */
301 elem.mbxInterrupt = (modCfg.mailboxTable[idx] >> 8) & 0xFF;
303 /* add the element to the instance data table */
304 dataTable.push(elem);
305 }
307 /* view.elements */
308 view.elements = dataTable;
309 }