1    /*
     2     * Copyright (c) 2015, 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     *  ======== TimerSupport.xdc ========
    34     */
    35    
    36    package ti.sysbios.family.shared.vayu;
    37    
    38    import xdc.rov.ViewInfo;
    39    
    40    /*!
    41     *  ======== TimerSupport ========
    42     *  Vayu Timer Support.
    43     *
    44     *  The Vayu Timer Support module works in conjunction with the DMTimer
    45     *  module to manage the usage of the DMTimers by the various Vayu cores.
    46     *
    47     *  This module provides a timer available mask. The application can modify
    48     *  this available mask in the .cfg script to choose a different set of timers.
    49     *
    50     *  The default value of the timer {@link #availMask} depends on the target
    51     *  the application is being built for. The defaults are shown below:
    52     *
    53     *  @p(code)
    54     *  For Vayu or DRA7XX devices:
    55     *   --------------------------------------------
    56     *  | Target       | Default availMask           |
    57     *   --------------------------------------------
    58     *  | A15          | 0x0202 (GPTimer 2 & 10)     |
    59     *  | DSP          | 0x0030 (GPTimer 5 & 6)      |
    60     *  | IPU(Dual-M4) | 0x050C (GPTimer 3,4,9 & 11) |
    61     *  | ARP32        | 0x00C0 (GPTimer 7 & 8)      |
    62     *   --------------------------------------------
    63     *
    64     *  For TDA3XX devices:
    65     *   --------------------------------------------
    66     *  | Target       | Default availMask           |
    67     *   --------------------------------------------
    68     *  | DSP          | 0x0003 (GPTimer 1 & 2)      |
    69     *  | IPU(Dual-M4) | 0x000C (GPTimer 3 & 4)      |
    70     *  | ARP32        | 0x00C0 (GPTimer 7 & 8)      |
    71     *   --------------------------------------------
    72     *  @p
    73     *
    74     *  @a(Note)
    75     *  If the {@link #availMask} is changed, the interrupt sources
    76     *  corresponding to the new Timer Ids may need to be mapped in
    77     *  the interrupt crossbar module if they are not mapped by default.
    78     *
    79     *  See {@link ../../../timers/dmtimer/doc-files/TimerTables.html Timer Mapping Tables}
    80     *  to determine the default interruptNumber/eventId assigned to
    81     *  each DM Timer. In the Timer Mapping Table, an interrupt number
    82     *  of -1 implies the timer's interrupt source is not connected to
    83     *  the target cpu's interrupt controller. If you need to use a
    84     *  timer with an interrupt number of -1, you will need to first select
    85     *  an unused interrupt to use for the timer and then map the
    86     *  timer's interrupt source to the target cpu's interrupt controller
    87     *  using the
    88     *  {@link ti.sysbios.family.shared.vayu.IntXbar Interrupt Crossbar module}.
    89     *
    90     *  Below is an example showing how to statically override the default
    91     *  timer available mask in a configuration script for the DSP:
    92     *
    93     *  @p(code)
    94     *  var Timer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
    95     *  var IntXbar = xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
    96     *  var TimerSupport = xdc.useModule('ti.sysbios.family.shared.vayu.TimerSupport');
    97     *
    98     *  // The new availability mask includes GP Timers 13, 14, 15 & 16.
    99     *  // The interrupt sources for these timers is not connected to the
   100     *  // DSP and need to be connected by the user.
   101     *  TimerSupport.availMask = 0xF000;
   102     *
   103     *  // Connect GP Timer 13 to EventId 76 (XBAR Instance 45)
   104     *  IntXbar.connectMeta(45, 339);
   105     *
   106     *  // Connect GP Timer 14 to EventId 77 (XBAR Instance 46)
   107     *  IntXbar.connectMeta(46, 340);
   108     *
   109     *  // Connect GP Timer 15 to EventId 78 (XBAR Instance 47)
   110     *  IntXbar.connectMeta(47, 341);
   111     *
   112     *  // Connect GP Timer 16 to EventId 81 (XBAR Instance 49)
   113     *  IntXbar.connectMeta(49, 342);
   114     *
   115     *  // The DMTimer's timer mapping table shows that the intNum
   116     *  // for GP Timer 13, 14, 15 & 16 is -1 implying the intNum
   117     *  // has not been assigned by default. The below code utilizes
   118     *  // the DMTimer module's timerSettings array to assign
   119     *  // a default intNum to each of these timers.
   120     *  Timer.timerSettings[12].intNum = 14;
   121     *  Timer.timerSettings[13].intNum = 15;
   122     *  Timer.timerSettings[14].intNum = 4;
   123     *  Timer.timerSettings[15].intNum = 5;
   124     *
   125     *  var TimerParams = new Timer.Params();
   126     *  TimerParams.period = 5000;
   127     *  TimerParams.runMode = Timer.RunMode_ONESHOT;
   128     *  TimerParams.periodType = Timer.PeriodType_MICROSECS;
   129     *
   130     *  TimerParams.arg = 1;
   131     *  Timer.create(Timer.ANY, '&myIsr1', TimerParams);
   132     *
   133     *  TimerParams.arg = 2;
   134     *  Timer.create(Timer.ANY, '&myIsr2', TimerParams);
   135     *  @p
   136     *
   137     *  Below is an example showing how to statically override the default
   138     *  timer available mask in a configuration script for the A15:
   139     *
   140     *  @p(code)
   141     *  var Timer = xdc.useModule('ti.sysbios.hal.Timer');
   142     *  var DMTimer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
   143     *
   144     *  // Override the default hal timer proxy for the A15 target
   145     *  Timer.TimerProxy = DMTimer;
   146     *
   147     *  var TimerSupport = xdc.module('ti.sysbios.family.shared.vayu.TimerSupport');
   148     *  TimerSupport.availMask = 0x000F;
   149     *
   150     *  var TimerParams = new Timer.Params();
   151     *  TimerParams.arg = 1;
   152     *  TimerParams.period = 5000;
   153     *  TimerParams.runMode = Timer.RunMode_ONESHOT;
   154     *  TimerParams.periodType = Timer.PeriodType_MICROSECS;
   155     *
   156     *  Timer.create(Timer.ANY, '&myIsr', TimerParams);
   157     *  @p
   158     *
   159     */
   160    
   161    @ModuleStartup
   162    
   163    module TimerSupport inherits ti.sysbios.interfaces.ITimerSupport
   164    {
   165        /*!
   166         *  ======== ModuleView ========
   167         *  @_nodoc
   168         */
   169        metaonly struct ModuleView {
   170            String availMask;
   171        }
   172    
   173        /*!
   174         *  ======== rovViewInfo ========
   175         *  @_nodoc
   176         */
   177        @Facet
   178        metaonly config ViewInfo.Instance rovViewInfo = 
   179            ViewInfo.create({
   180                viewMap: [
   181                [
   182                    'Module',
   183                    {
   184                        type: ViewInfo.MODULE,
   185                        viewInitFxn: 'viewInitModule',
   186                        structName: 'ModuleView'
   187                    }
   188                ],
   189                ]
   190            });
   191    
   192        /*!
   193         *  ======== availMask ========
   194         *  Default available mask for dmtimers
   195         *
   196         *  Used to set Timer module's availMask.
   197         *  The default value of the timer availMask depends on the target
   198         *  the application is being built for. The defaults are shown below:
   199         *
   200         *  @p(code)
   201         *  For Vayu or DRA7XX devices:
   202         *   --------------------------------------------
   203         *  | Target       | Default availMask           |
   204         *   --------------------------------------------
   205         *  | A15          | 0x0202 (GPTimer 2 & 10)     |
   206         *  | DSP          | 0x0030 (GPTimer 5 & 6)      |
   207         *  | IPU(Dual-M4) | 0x050C (GPTimer 3,4,9 & 11) |
   208         *   --------------------------------------------
   209         *
   210         *  For TDA3XX devices:
   211         *   --------------------------------------------
   212         *  | Target       | Default availMask           |
   213         *   --------------------------------------------
   214         *  | DSP          | 0x0003 (GPTimer 1 & 2)      |
   215         *  | IPU(Dual-M4) | 0x050C (GPTimer 3 & 3)      |
   216         *   --------------------------------------------
   217         *  @p
   218         */
   219         config Bits32 availMask = 0x0;
   220    
   221    internal:
   222    
   223        /*
   224         *  ======== getAnyMask ========
   225         *  Return the anyMask for this device.
   226         */
   227        metaonly Bits32 getAnyMask();
   228    
   229        /*
   230         *  ======== getAvailMask ========
   231         *  Return the availMask for this device.
   232         */
   233        metaonly Bits32 getAvailMask();
   234    }