Merge remote-tracking branch 'origin/ipc-3.23-next' into ipc-next
[ipc/ipcdev.git] / packages / ti / deh / Watchdog.xs
1 /*
2  * Copyright (c) 2012-2014, 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  */
33 /*
34  *  ======== Watchdog.xs ========
35  *
36  */
38 var Watchdog = null;
39 var Core = null;
40 var MultiProc = null;
41 var Task = null;
42 var Swi  = null;
43 var taskHook = null;
44 var swiHook  = null;
45 var catalogName = null;
47 if (xdc.om.$name == "cfg" || typeof(genCdoc) != "undefined") {
48     var deviceTable = {
49         "ti.catalog.c6000": {
50             "OMAP5430": {
51                 wdtimer: [
52                    {
53                         name: "WdTimerDsp",     /* GpTimer 6 */
54                         baseAddr: 0x01d3A000,
55                         clkCtrl: 0x4A004570,    /* Virtual address */
56                         intNum:  15,
57                         eventId: 52,
58                     },
59                 ]
60             },
61             "DRA7XX": {
62                 wdtimer: [
63                     {
64                         name: "WdTimerDsp",     /* GpTimer 10 */
65                         baseAddr: 0x48086000,   /* Virtual address */
66                         clkCtrl: 0x4A009728,    /* Virtual address */
67                         intNum:  15,
68                         eventId: 72,
69                     },
70                 ]
71             },
72         },
73         "ti.catalog.arm.cortexm4": {
74             "OMAP5430": {
75                 wdtimer: [
76                     {
77                         name: "WdTimerCore0",   /* GpTimer 9 */
78                         baseAddr: 0xA803E000,   /* Virtual address */
79                         clkCtrl: 0xAA009450,    /* Virtual address */
80                         intNum:  55,
81                         eventId: -1,
82                     },
83                     {
84                         name: "WdTimerCore1",   /* GpTimer 11 */
85                         baseAddr: 0xA8088000,   /* Virtual address */
86                         clkCtrl: 0xAA009430,    /* Virtual address */
87                         intNum:  56,
88                         eventId: -1,
89                     },
90                 ]
91             },
92             "DRA7XX": {
93                 wdtimer: [
94                     {
95                         name: "WdTimerCore0",   /* GpTimer 9 */
96                         baseAddr: 0x6803E000,   /* Virtual address */
97                         clkCtrl: 0x6A009750,    /* Virtual address */
98                         intNum:  55,
99                         eventId: -1,
100                     },
101                     {
102                         name: "WdTimerCore1",   /* GpTimer 4 */
103                         baseAddr: 0x68036000,   /* Virtual address */
104                         clkCtrl: 0x6A009748,    /* Virtual address */
105                         intNum:  54,
106                         eventId: -1,
107                     },
108                 ]
109             },
110         },
111     };
114 /*
115  *  ======== module$use ========
116  */
117 function module$use()
119     var found = false;
121     /* Only process during "cfg" phase */
122     if (xdc.om.$name != "cfg") {
123         return;
124     }
126     Watchdog = this;
128     catalogName = Program.cpu.catalogName;
130     /* Loop through the device table */
131     /* TODO: This lookup table can be replaced to use the dmTimer module
132      *       later on, and eliminate the need for this device table */
133     for (deviceName in deviceTable[catalogName]) {
134         if (deviceName == Program.cpu.deviceName) {
135             var device = deviceTable[catalogName][deviceName].wdtimer;
137             Watchdog.timerSettings.length = device.length;
138             for (var i = 0; i < device.length; i++) {
139                 Watchdog.timerSettings[i].baseAddr = null;
140                 Watchdog.timerSettings[i].clkCtrl = null;
141                 Watchdog.timerSettings[i].intNum = device[i].intNum;
142                 Watchdog.timerSettings[i].eventId = device[i].eventId;
143             }
145             found = true;
147             break;
148         }
149     }
151     if (!found) {
152         print("Watchdog Timer configuration is not found for the " +
153               "specified device (" + Program.cpu.deviceName + ").");
155         for (device in deviceTable[catalogName]) {
156             print("\t" + device);
157         }
159         throw new Error ("Watchdog Timer unsupported on device!");
160     }
162     var Settings = xdc.module("ti.sysbios.family.Settings");
163     var Hwi = xdc.useModule(Settings.getDefaultHwiDelegate());
165     xdc.useModule('xdc.runtime.System');
167     if (Program.platformName.match(/IPU/) ||
168         Program.platformName.match(/ipu/)) {
169         Core = xdc.module("ti.sysbios.hal.Core");
170     }
171     else {
172         MultiProc = xdc.module('ti.sdo.utils.MultiProc');
173         if (Program.platformName.match(/DSP/)) {
174             xdc.useModule('ti.sysbios.family.c64p.tesla.Wugen');
175         }
176     }
178     Task = xdc.useModule('ti.sysbios.knl.Task');
179     taskHook = new Task.HookSet;
181     Swi  = xdc.useModule('ti.sysbios.knl.Swi');
182     swiHook  = new Swi.HookSet;
185 /*
186  *  ======== module$static$init ========
187  */
188 function module$static$init(mod, params)
190     var device = deviceTable[catalogName][Program.cpu.deviceName].wdtimer;
192     swiHook.beginFxn = this.swiPrehook;
193     Swi.addHookSet(swiHook);
195     taskHook.switchFxn = this.taskSwitch;
196     Task.addHookSet(taskHook);
198     /* Assign default values if not supplied through configuration */
199     for (var i = 0; i < device.length; i++) {
200         if (Watchdog.timerSettings[i].baseAddr == null) {
201             Watchdog.timerSettings[i].baseAddr = $addr(device[i].baseAddr);
202         }
203         if (Watchdog.timerSettings[i].clkCtrl == null) {
204             Watchdog.timerSettings[i].clkCtrl = $addr(device[i].clkCtrl);
205         }
206     }
208     mod.device.length = 1;
209     mod.status.length   = 1;
210     mod.wdtCores      = 1;
211     if (Program.build.target.name.match(/C64T/) ||
212         Program.build.target.name.match(/C66/)) {
213         mod.device[0].baseAddr = Watchdog.timerSettings[0].baseAddr;
214         mod.device[0].clkCtrl  = Watchdog.timerSettings[0].clkCtrl;
215         mod.device[0].intNum   = Watchdog.timerSettings[0].intNum;
216         mod.device[0].eventId  = Watchdog.timerSettings[0].eventId;
217         mod.status[0]          = Watchdog.Mode_DISABLED;
218     }
219     else {
220         if (Program.platformName.match(/IPU/) ||
221             Program.platformName.match(/ipu/)) {
222             mod.device.length       = Core.numCores;
223             mod.status.length       = Core.numCores;
224             mod.wdtCores            = Core.numCores;
226             mod.device[0].baseAddr  = Watchdog.timerSettings[0].baseAddr;
227             mod.device[0].clkCtrl   = Watchdog.timerSettings[0].clkCtrl;
228             mod.device[0].intNum    = Watchdog.timerSettings[0].intNum;
229             mod.device[0].eventId   = Watchdog.timerSettings[0].eventId;
230             mod.status[0]           = Watchdog.Mode_DISABLED;
232             mod.device[1].baseAddr  = Watchdog.timerSettings[1].baseAddr;
233             mod.device[1].clkCtrl   = Watchdog.timerSettings[1].clkCtrl;
234             mod.device[1].intNum    = Watchdog.timerSettings[1].intNum;
235             mod.device[1].eventId   = Watchdog.timerSettings[1].eventId;
236             mod.status[1]           = Watchdog.Mode_DISABLED;
237         }
238         else {
239             if (MultiProc.id == MultiProc.getIdMeta("CORE0")) {
240                 mod.device[0].baseAddr  = Watchdog.timerSettings[0].baseAddr;
241                 mod.device[0].clkCtrl   = Watchdog.timerSettings[0].clkCtrl;
242                 mod.device[0].intNum    = Watchdog.timerSettings[0].intNum;
243                 mod.device[0].eventId   = Watchdog.timerSettings[0].eventId;
244             }
245             else {
246                 mod.device[0].baseAddr  = Watchdog.timerSettings[1].baseAddr;
247                 mod.device[0].clkCtrl   = Watchdog.timerSettings[1].clkCtrl;
248                 mod.device[0].intNum    = Watchdog.timerSettings[1].intNum;
249                 mod.device[0].eventId   = Watchdog.timerSettings[1].eventId;
250             }
251             mod.status[0]               = Watchdog.Mode_DISABLED;
252         }
253     }