]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - packages/ti/sdo/ipc/family/f28m35x/TransportCirc.xs
462e29310e93b9bf6a2bfcb828fa9132ef5a30f6
[ipc/ipcdev.git] / packages / ti / sdo / ipc / family / f28m35x / TransportCirc.xs
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  *  ======== TransportCirc.xs ========
34  */
36 var TransportCirc = null;
37 var MessageQ     = null;
38 var Notify       = null;
39 var MultiProc    = null;
40 var Swi          = null;
42 /*
43  *  ======== module$use ========
44  */
45 function module$use()
46 {
47     TransportCirc = this;
48     MessageQ     = xdc.useModule("ti.sdo.ipc.MessageQ");
49     Notify       = xdc.useModule("ti.sdo.ipc.Notify");
50     MultiProc    = xdc.useModule("ti.sdo.utils.MultiProc");
51     Swi          = xdc.useModule("ti.sysbios.knl.Swi");
52 }
54 /*
55  * ======== module$static$init ========
56  */
57 function module$static$init(mod, params)
58 {
59     var target = Program.build.target;
60     var bitsPerByte = 8;
61     var bitsPerChar = target.bitsPerChar;
63     /* calculate the msgSize */
64     TransportCirc.msgSize = TransportCirc.maxMsgSizeInBytes *
65                               (bitsPerByte / bitsPerChar);
67     /* calculate the maxIndex */
68     TransportCirc.maxIndex = TransportCirc.numMsgs - 1;
70     /* determine numMsgs is a power of 2 */
71     if (TransportCirc.numMsgs & (TransportCirc.maxIndex)) {
72         TransportCirc.$logFatal("TransportCirc.numMsgs: " +
73                 TransportCirc.numMsgs +
74                 " is not a power of 2", TransportCirc);
75     }
76 }
78 /*
79  *  ======== module$validate ========
80  */
81 function module$validate()
82 {
83     if (Notify.numEvents <= TransportCirc.notifyEventId) {
84         TransportCirc.$logFatal("TransportCirc.notifyEventId (" +
85                 TransportCirc.notifyEventId +
86                 ") is too big: Notify.numEvents = " + Notify.numEvents,
87                 TransportCirc);
88     }
89 }
91 /*
92  *  ======== sharedMemReqMeta ========
93  */
94 function sharedMemReqMeta(params)
95 {
96     var target = Program.build.target;
97     var bitsPerByte = 8;
98     var bitsPerChar = target.bitsPerChar;
100     /* calculate the msgSize */
101     var msgSize = TransportCirc.maxMsgSizeInBytes *
102                   (bitsPerByte / bitsPerChar);
104     /*
105      *  Amount of shared memory:
106      *  1 putBuffer (msgSize * numMsgs) +
107      *  1 putWriteIndex ptr             +
108      *  1 putReadIndex ptr              +
109      */
110     var memReq = (msgSize * TransportCirc.numMsgs) +
111                  (2 *  Program.build.target.stdTypes['t_Int32'].size);
113     return (memReq);
116 /*
117  *************************************************************************
118  *                       ROV View functions
119  *************************************************************************
120  */
122 /*
123  *  ======== viewInitBasic ========
124  */
125 function viewInitBasic(view, obj)
127     var MultiProc = xdc.useModule('ti.sdo.utils.MultiProc');
129     /* view.remoteProcName */
130     try {
131         view.remoteProcName = MultiProc.getName$view(obj.remoteProcId);
132     }
133     catch(e) {
134         Program.displayError(view, 'remoteProcName',
135                              "Problem retrieving proc name: " + e);
136     }
139 /*
140  *  ======== getEventData ========
141  *  Helper function for use within viewInitData
142  */
143 function getEventData(view, obj, bufferPtr, putIndex, getIndex)
145     var TransportCirc =
146         xdc.useModule('ti.sdo.ipc.family.f28m35x.TransportCirc');
147     var modCfg =
148         Program.getModuleConfig('ti.sdo.ipc.family.f28m35x.TransportCirc');
149     var ScalarStructs   = xdc.useModule('xdc.rov.support.ScalarStructs');
151     if (bufferPtr == obj.putBuffer) {
152         var bufferName = "put";
153     }
154     else {
155         var bufferName = "get";
156     }
158     try {
159         var putBuffer = Program.fetchArray(TransportCirc.msgSize$fetchDesc,
160                                            bufferPtr,
161                                            modCfg.numMsgs);
162     }
163     catch(e) {
164         throw (new Error("Error fetching putBuffer struct from shared memory"));
165     }
167     var i = getIndex;
169     while (i != putIndex) {
170         /* The event is registered */
171         var elem = Program.newViewStruct(
172                 'ti.sdo.ipc.family.f28m35x.TransportCirc',
173                 'Events');
175         elem.index = i;
176         elem.buffer = bufferName;
177         elem.addr = utils.toHex(putBuffer[i].$addr);
178         elem.message = utils.toHex(putBuffer[i].elem);
180         /* Create a new row in the instance data view */
181         view.elements.$add(elem);
183         i++;
184     }
188 /*
189  *  ======== viewInitData ========
190  *  Instance data view.
191  */
192 function viewInitData(view, obj)
194     var Program         = xdc.useModule('xdc.rov.Program');
195     var ScalarStructs   = xdc.useModule('xdc.rov.support.ScalarStructs');
196     var MultiProc       = xdc.useModule('ti.sdo.utils.MultiProc');
198     /* Display the instance label in the tree */
199     view.label = "remoteProcId = " + obj.remoteProcId;
201     /* Fetch put/get index's */
202     try {
203         var putWriteIndex = Program.fetchStruct(ScalarStructs.S_Bits32$fetchDesc,
204                                                 obj.putWriteIndex);
205     }
206     catch(e) {
207         throw (new Error("Error fetching putWriteIndex struct from shared memory"));
208     }
210     try {
211         var putReadIndex = Program.fetchStruct(ScalarStructs.S_Bits32$fetchDesc,
212                                                obj.putReadIndex);
213     }
214     catch(e) {
215         throw (new Error("Error fetching putReadIndex struct from shared memory"));
216     }
218     try {
219         var getWriteIndex = Program.fetchStruct(ScalarStructs.S_Bits32$fetchDesc,
220                                                 obj.getWriteIndex);
221     }
222     catch(e) {
223         throw (new Error("Error fetching getWriteIndex struct from shared memory"));
224     }
226     try {
227         var getReadIndex = Program.fetchStruct(ScalarStructs.S_Bits32$fetchDesc,
228                                                obj.getReadIndex);
229     }
230     catch(e) {
231         throw (new Error("Error fetching getReadIndex struct from shared memory"));
232     }
234     /* Get event data for the put buffer */
235     getEventData(view, obj, obj.putBuffer, putWriteIndex.elem, putReadIndex.elem);
237     /* Get event data for the get buffer */
238     getEventData(view, obj, obj.getBuffer, getWriteIndex.elem, getReadIndex.elem);