a53ab97aa0cfe946dcabb0157e248d9f52fcc14d
1 /*
2 * Copyright (c) 2012-2013, Texas Instruments Incorporated
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 */
32 /*
33 * ======== IpcMgr.xs ========
34 */
36 var IpcMgr = null;
37 var Startup = null;
38 var MultiProc = null;
39 var NotifyDriverCirc = null;
40 var NameServerBlock = null;
41 var TransportCirc = null;
42 var Hwi = null;
44 /*
45 * ======== module$meta$init ========
46 */
47 function module$meta$init()
48 {
49 /* Only process during "cfg" phase */
50 if (xdc.om.$name != "cfg") {
51 return;
52 }
54 IpcMgr = this;
56 /* initialize the config parameter */
57 for (var i=0; i < IpcMgr.sharedMemoryAccess.length; i++) {
58 IpcMgr.sharedMemoryAccess[i] = 0;
59 }
61 var NameServer = xdc.useModule('ti.sdo.utils.NameServer');
62 NameServer.SetupProxy = xdc.useModule('ti.sdo.ipc.family.f28m35x.NameServerBlock');
64 var Startup = xdc.useModule('xdc.runtime.Startup');
66 /* RAMINIT */
67 Startup.firstFxns.$add(IpcMgr.init);
68 }
70 /*
71 * ======== module$use ========
72 */
73 function module$use()
74 {
75 MultiProc = xdc.useModule("ti.sdo.utils.MultiProc");
76 NotifyDriverCirc =
77 xdc.useModule("ti.sdo.ipc.family.f28m35x.NotifyDriverCirc");
78 NameServerBlock =
79 xdc.useModule("ti.sdo.ipc.family.f28m35x.NameServerBlock");
80 TransportCirc =
81 xdc.useModule("ti.sdo.ipc.family.f28m35x.TransportCirc");
82 Hwi = xdc.useModule("ti.sysbios.hal.Hwi");
83 Startup = xdc.useModule("xdc.runtime.Startup");
85 /* Init the number of messages for notify driver */
86 NotifyDriverCirc.numMsgs = IpcMgr.numNotifyMsgs;
88 /* Init the number of messages for messageQ transport */
89 TransportCirc.numMsgs = IpcMgr.numMessageQMsgs;
90 TransportCirc.maxMsgSizeInBytes = IpcMgr.messageQSize;
91 TransportCirc.notifyEventId = IpcMgr.messageQEventId;
93 /* Make sure that sharedMemoryOwnerMask is only configured on the M3 */
94 if (!Program.build.target.name.match(/M3.*/) &&
95 IpcMgr.$written("sharedMemoryOwnerMask") == true) {
96 this.$logWarning("Warning: IpcMgr.sharedMemoryOwnerMask must only be " +
97 "configured on the M3 core. Configuring this on the C28 core has no " +
98 "effect", this);
99 }
100 }
102 /*
103 * ======== module$static$init ========
104 */
105 function module$static$init(mod, params)
106 {
107 /* check to make sure readAddr and writeAddr have been set */
108 if (params.readAddr == undefined) {
109 IpcMgr.$logError("IpcMgr.readAddr is undefined", IpcMgr);
110 }
112 if (params.writeAddr == undefined) {
113 IpcMgr.$logError("IpcMgr.writeAddr is undefined", IpcMgr);
114 }
117 /* init the interrupt ids */
118 if (params.ipcSetFlag < 0 || params.ipcSetFlag > 3) {
119 IpcMgr.$logError("IpcMgr.ipcSetFlag must be 0, 1, 2, or 3 " +
120 "because they are the only flags associated with an interrupt.",
121 IpcMgr);
122 }
124 /* calculate the amount of shared memory used */
125 IpcMgr.sharedMemSizeUsed = NotifyDriverCirc.sharedMemReqMeta(null) +
126 NameServerBlock.sharedMemReqMeta(null) +
127 TransportCirc.sharedMemReqMeta(null);
129 /* validate sharedMemoryOwnerMask is correct for the readAddr/writeAddr */
130 if (Program.build.target.name.match(/M3.*/)) {
131 if ((IpcMgr.writeAddr >= 0x20008000) &&
132 (IpcMgr.writeAddr < 0x20018000)) {
133 /*
134 * Determine segment being used for the M3 writeAddr.
135 * The shared RAM base address starts 0x20008000 to 0x20016000.
136 * Each segment with a length of 0x2000 (byte addressing).
137 */
138 var writeSeg = (IpcMgr.writeAddr - 0x20008000) >> 13;
140 /* The M3 must be owner of writeAddr shared memory segment */
141 if (IpcMgr.sharedMemoryOwnerMask & (1 << writeSeg)) {
142 IpcMgr.$logError("IpcMgr.writeAddr is set to address: " +
143 utils.toHex(IpcMgr.writeAddr) + "," +
144 " but IpcMgr.sharedMemoryOwnerMask bit: " + writeSeg +
145 " must not be set. Unset this bit to make M3 the owner.", IpcMgr);
146 }
147 }
149 if ((IpcMgr.readAddr >= 0x20008000) &&
150 (IpcMgr.readAddr < 0x20018000)) {
151 /*
152 * Determine segment being used for the M3 readAddr.
153 * The shared RAM base address starts 0x20008000 to 0x20016000.
154 * Each segment with a length of 0x2000 (byte addressing).
155 */
156 var readSeg = (IpcMgr.readAddr - 0x20008000) >> 13;
158 /* The C28 must be owner of readAddr shared memory segment */
159 if (!(IpcMgr.sharedMemoryOwnerMask & (1 << readSeg))) {
160 IpcMgr.$logError("IpcMgr.readAddr is set to address: " +
161 utils.toHex(IpcMgr.readAddr) + "," +
162 " but IpcMgr.sharedMemoryOwnerMask bit: " + readSeg +
163 " is not set. This bit must be set so C28 is the owner.", IpcMgr);
164 }
165 }
166 }
167 }
169 /*
170 * ======== module$validate ========
171 */
172 function module$validate()
173 {
174 if ((xdc.module('ti.sdo.ipc.Ipc').$used) ||
175 (xdc.module('ti.sdo.ipc.GateMP').$used) ||
176 (xdc.module('ti.sdo.ipc.SharedRegion').$used) ||
177 (xdc.module('ti.sdo.ipc.ListMP').$used)) {
178 IpcMgr.$logError("One or more of the following modules " +
179 "[Ipc, GateMP, ListMP, SharedRegion] are being used " +
180 "but are not supported on this device.", IpcMgr);
181 }
182 }