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     *  ======== Timer.xdc ========
    34     */
    35    
    36    package ti.sysbios.timers.dmtimer;
    37    
    38    import xdc.rov.ViewInfo;
    39    
    40    import xdc.runtime.Assert;
    41    import xdc.runtime.Error;
    42    import xdc.runtime.Types;
    43    import ti.sysbios.interfaces.ITimer;
    44    import ti.sysbios.hal.Hwi;
    45    
    46    /*!
    47     *  ======== Timer ========
    48     *  Timer Peripheral Manager.
    49     *
    50     *  This Timer module manages the Dual Mode timer (dmtimer) peripherals
    51     *  available on the ARM and C6000 devices (see
    52     *  {@link ./doc-files/TimerTables.html Timer Mapping Tables} for supported
    53     *  device information).
    54     *
    55     *  The dmtimer Timer module supports the timer in 'one shot', 'continuous',
    56     *  and 'dynamic' modes.
    57     *
    58     *  In 'one shot' mode, a timer function will "fire" (run) when the timer period
    59     *  expires (counts up to zero). In 'one shot' mode this will only happen
    60     *  once.  
    61     *
    62     *  In 'continuous' mode, the specified timer function will "fire" every
    63     *  time the period expires, throughout the lifetime of the program.  When the
    64     *  period expires in 'continuous mode', the period is then reset to its
    65     *  original value and then begins counting up to zero again.  At this point
    66     *  the timer function will fire again and the cycle repeats itself.
    67     *
    68     *  In 'dynamic' mode, the specified timer function will "fire" every
    69     *  time the period expires.  But the period of the timer can be changed 
    70     *  dynamically, to correspond to the next tick interrupt needed from the
    71     *  timer.  The timer will continually count upwards, and the timer's compare 
    72     *  mode is used to generate an interrupt when a specific threshold count is
    73     *  reached.  This mode is used by the SYS/BIOS Clock module, for implementing
    74     *  dynamic tick suppression, which reduces the number of interrupts from the 
    75     *  timer to the minimum required for currently scheduled timeouts.
    76     *
    77     *  @p(html)
    78     *  <h3> Calling Context </h3>
    79     *  <table border="1" cellpadding="3">
    80     *    <colgroup span="1"></colgroup> <colgroup span="5" align="center">
    81     *  </colgroup>
    82     *
    83     *    <tr><th> Function                 </th><th>  Hwi   </th><th>  Swi   </th>
    84     *  <th>  Task  </th><th>  Main  </th><th>  Startup  </th></tr>
    85     *    <!--                                                          -->
    86     *    <tr><td> {@link #getNumTimers}            </td><td>   Y    </td>
    87     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    88     *    <tr><td> {@link #getStatus}               </td><td>   Y    </td>
    89     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    90     *    <tr><td> {@link #Params_init}             </td><td>   Y    </td>
    91     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    92     *    <tr><td> {@link #construct}               </td><td>   Y    </td>
    93     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    94     *    <tr><td> {@link #create}                  </td><td>   N    </td>
    95     *  <td>   N    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    96     *    <tr><td> {@link #delete}                  </td><td>   N    </td>
    97     *  <td>   N    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    98     *    <tr><td> {@link #destruct}                </td><td>   Y    </td>
    99     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
   100     *    <tr><td> {@link #getCount}                </td><td>   Y    </td>
   101     *  <td>   Y    </td><td>   Y    </td><td>   N    </td><td>   N    </td></tr>
   102     *    <tr><td> {@link #getFreq}                 </td><td>   Y    </td>
   103     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
   104     *    <tr><td> {@link #getFunc}                 </td><td>   Y    </td>
   105     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
   106     *    <tr><td> {@link #getPeriod}               </td><td>   Y    </td>
   107     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
   108     *    <tr><td> {@link #reconfig}                </td><td>   Y    </td>
   109     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
   110     *    <tr><td> {@link #setFunc}                 </td><td>   Y    </td>
   111     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
   112     *    <tr><td> {@link #setPeriod}               </td><td>   Y    </td>
   113     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
   114     *    <tr><td> {@link #setPeriodMicroSecs}      </td><td>   Y    </td>
   115     *  <td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
   116     *    <tr><td> {@link #start}                   </td><td>   Y    </td>
   117     *  <td>   Y    </td><td>   Y    </td><td>   N    </td><td>   N    </td></tr>
   118     *    <tr><td> {@link #stop}                    </td><td>   Y    </td>
   119     *  <td>   Y    </td><td>   Y    </td><td>   N    </td><td>   N    </td></tr>
   120     *    <tr><td colspan="6"> Definitions: <br />
   121     *       <ul>
   122     *         <li> <b>Hwi</b>: API is callable from a Hwi thread. </li>
   123     *         <li> <b>Swi</b>: API is callable from a Swi thread. </li>
   124     *         <li> <b>Task</b>: API is callable from a Task thread. </li>
   125     *         <li> <b>Main</b>: API is callable during any of these phases: </li>
   126     *           <ul>
   127     *             <li> In your module startup after this module is started 
   128     *  (e.g. Timer_Module_startupDone() returns TRUE). </li>
   129     *             <li> During xdc.runtime.Startup.lastFxns. </li>
   130     *             <li> During main().</li>
   131     *             <li> During BIOS.startupFxns.</li>
   132     *           </ul>
   133     *         <li> <b>Startup</b>: API is callable during any of these phases:</li>
   134     *           <ul>
   135     *             <li> During xdc.runtime.Startup.firstFxns.</li>
   136     *             <li> In your module startup before this module is started 
   137     *  (e.g. Timer_Module_startupDone() returns FALSE).</li>
   138     *           </ul>
   139     *       </ul>
   140     *    </td></tr>
   141     *
   142     *  </table>
   143     *  @p
   144     *
   145     *  @p(html)
   146     *  <h3> Timer Mapping Tables </h3>
   147     *  <p>
   148     *  The Timer module allows the user to use and configure the various timers
   149     *  that exist on a particular device.  This is achieved by specifying a timer
   150     *  ID when calling {@link ti.sysbios.hal.Timer#Timer_create}. 
   151     *  However, the timer ID
   152     *  specified may not always map to that timer; for example, specifying an ID
   153     *  value of 1 does not necessarily mean that this will map to "GPTimer1".
   154     *  These tables are provided to show which timers map to which timer IDs.
   155     *  </p>
   156     *  {@link ./doc-files/TimerTables.html Timer Mapping Tables}
   157     *  @p
   158     */
   159    @ModuleStartup          /* to configure static timers */
   160    @InstanceInitStatic
   161    
   162    module Timer inherits ti.sysbios.interfaces.ITimer
   163    {
   164        /*! override supportsDynamic - this Timer does support RunMode_DYNAMIC */
   165        override metaonly config Bool supportsDynamic = true;
   166    
   167        /*! Max value of Timer period for PeriodType_COUNTS*/
   168        const UInt MAX_PERIOD = 0xffffffff;
   169    
   170        /*! L4 interface Configuration Register (TIOCP_CFG). */
   171        struct TiocpCfg {
   172            Bits8 idlemode;  /*! 0=force-idle;1=no-idle;2=Smart-idle;3=Smart-idle */
   173            Bits8 emufree;   /*! 0=counter frozen; 1=counter free-running */
   174            Bits8 softreset; /*! 0=normal mode; 1=soft reset */
   175        };
   176    
   177        /*! Interrupt Enable Register (TIER). */
   178        struct Tier {
   179            Bits8 mat_it_ena;  /*! Enable match interrupt */
   180            Bits8 ovf_it_ena;  /*! Enable overflow interrupt */
   181            Bits8 tcar_it_ena; /*! Enable capture interrupt */
   182        };
   183    
   184        /*! WakepUp Enable Register (TWER). */
   185        struct Twer {
   186            Bits8 mat_wup_ena;  /*! Enable match wake-up */
   187            Bits8 ovf_wup_ena;  /*! Enable overflow wake-up */
   188            Bits8 tcar_wup_ena; /*! Enable capture wake-up */
   189        };
   190    
   191        /*! Control Register (TCLR). */
   192        struct Tclr {
   193            Bits32 ptv; /*! Trigger output mode */
   194            Bits8 pre;  /*! Prescalar enable */
   195            Bits8 ce;   /*! Compare enable */
   196            Bits8 scpwm;/*! Pulse-width modulation */
   197            Bits16 tcm; /*! Transition capture mode */
   198            Bits16 trg; /*! Trigger output mode */
   199            Bits8 pt;   /*! Pulse or toggle select bit */
   200            Bits8 captmode; /*! Capture mode select bit */
   201            Bits8 gpocfg; /*! PWM output/event detection input pin */
   202        };
   203    
   204        /*!
   205         *  ======== Tsicr ========
   206         *  L4 Interface Synchronization Control Register (TSICR).
   207         *
   208         *  Note: 'readmode' field is not available on some older Silicon.
   209         *  Please check the technical reference manual of your device to
   210         *  determine if this field is available before using it.
   211         */
   212        struct Tsicr {
   213            Bits8 sft;      /*! Reset software functional registers */
   214            Bits8 posted;   /*! Posted mode selection */
   215            Bits8 readmode; /*! Select posted/non-posted mode for read operation */
   216        };
   217    
   218        /*! Timer Settings. */
   219        metaonly struct TimerSetting {
   220            Bool master;    /*! specifies whether this is the master */
   221            Ptr baseAddr;   /*! specify the base address  */
   222            Int intNum;     /*! specify which interrupt vector */
   223            Int eventId;    /*! specify which event number to use */
   224            String name;    /*! specify the timer name */
   225        };
   226    
   227        /*!
   228         *  ======== BasicView ========
   229         *  @_nodoc
   230         */
   231        metaonly struct BasicView {
   232            Ptr         halTimerHandle;
   233            String      label;
   234            UInt        id;
   235            String      name;
   236            String      startMode;
   237            String      runMode;
   238            UInt        period;
   239            String      periodType;
   240            UInt        intNum;
   241            String      eventId;
   242            String      tickFxn[];
   243            UArg        arg;
   244            String      extFreqLow;
   245            String      extFreqHigh;
   246            String      hwiHandle;
   247        };
   248    
   249        /*!
   250         *  ======== DeviceView ========
   251         *  @_nodoc
   252         */
   253        metaonly struct DeviceView {
   254            UInt        id;
   255            String      deviceAddr;
   256            UInt        intNum;
   257            String      eventId;
   258            String      runMode;
   259            String      timerState;
   260            UInt        period;
   261            String      currCount;
   262            String      remainingCount;
   263        };
   264    
   265        /*!
   266         *  ======== ModuleView ========
   267         *  @_nodoc
   268         */
   269        metaonly struct ModuleView {
   270            String          availMask;      /* avaliable 32-bit timer halves */
   271            String          intFrequency[]; /* internal frequency in Hz */
   272        }
   273    
   274        /*!
   275         *  ======== rovViewInfo ========
   276         *  @_nodoc
   277         */
   278        @Facet
   279        metaonly config ViewInfo.Instance rovViewInfo = 
   280            ViewInfo.create({
   281                viewMap: [
   282                [
   283                    'Basic',
   284                    {
   285                        type: ViewInfo.INSTANCE,
   286                        viewInitFxn: 'viewInitBasic',
   287                        structName: 'BasicView'
   288                    }
   289                ],
   290                [
   291                    'Device',
   292                    {
   293                        type: ViewInfo.INSTANCE,
   294                        viewInitFxn: 'viewInitDevice',
   295                        structName: 'DeviceView'
   296                    }
   297                ],
   298                [
   299                    'Module',
   300                    {
   301                        type: ViewInfo.MODULE,
   302                        viewInitFxn: 'viewInitModule',
   303                        structName: 'ModuleView'
   304                    }
   305                ],
   306                ]
   307            });
   308    
   309        /*!
   310         *  Assert raised when statically created timer is not available
   311         */
   312        config xdc.runtime.Assert.Id A_notAvailable = {
   313            msg: "A_notAvailable: statically created timer not available"
   314        };
   315    
   316        /*!
   317         *  Error raised when timer id specified is not supported.
   318         */
   319        config Error.Id E_invalidTimer = {
   320            msg: "E_invalidTimer: Invalid Timer Id %d"
   321        };
   322    
   323        /*!
   324         *  Error raised when timer requested is in use
   325         */
   326        config Error.Id E_notAvailable  = {
   327            msg: "E_notAvailable: Timer not available %d"
   328        };
   329    
   330        /*!
   331         *  Error raised when period requested is not supported
   332         */
   333        config Error.Id E_cannotSupport = {
   334            msg: "E_cannotSupport: Timer cannot support requested period %d"
   335        };
   336        
   337        /*!
   338         *  Error raised when timer frequency does not match expected frequency
   339         *
   340         *  BIOS does not configure the DMTimer clock source and expects this
   341         *  configuration to be performed via a GEL script or on the host OS.  This
   342         *  error is raised if BIOS detects a mismatch between {@link #intFreq} and
   343         *  the actual operating frequency.  The check is performed by comparing
   344         *  the timestamp operating frequency with the DMTimer frequency.
   345         * 
   346         *  To change the expected timer frequency to match the actual operating 
   347         *  frequency, use the following example configuration:
   348         *  @p(code)
   349         *      var Timer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
   350         *      Timer.intFreq.lo = 20000000; //For 20Mhz
   351         *      Timer.intFreq.hi = 0;
   352         *  @p
   353         *
   354         *  This check can be skipped by setting {@link #checkFrequency} to FALSE.
   355         */
   356        config Error.Id E_freqMismatch  = {
   357            msg: "E_freqMismatch: Frequency mismatch: Expected %d Hz, actual: %d Hz.  You need to modify Timer.intFreq.lo to match the actual frequency."
   358        };
   359    
   360        /*!
   361         *  Error raised when intNum not supplied by user or device table
   362         */
   363        config Error.Id E_badIntNum = {
   364            msg: "E_badIntNum: Timer requires a valid intNum. Please use DMTimer module's timerSettings config param to assign a valid intNum for the selected timer."
   365        };
   366    
   367        /*!
   368         *  ======== anyMask ========
   369         *  Available mask to be used when select = Timer_ANY. 
   370         *
   371         *  Default value is device specific.
   372         */
   373        config Bits32 anyMask;
   374    
   375        /*!
   376         *  ======== checkFrequency ========
   377         *  Whether to check the timer operating frequency at startup
   378         *
   379         *  When this flag is set to 'TRUE', the Timer module will verify that the
   380         *  operating frequency equals the frequency at which BIOS expects the 
   381         *  timers to operate.  This check is performed by checking the timer count
   382         *  rate against the {@link xdc.runtime.Timestamp} count rate.
   383         */
   384        config Bool checkFrequency = true;
   385    
   386        /*!
   387         *  ======== timerSettings ========
   388         *  Global Control configuration for each physical timer.
   389         */
   390        metaonly config TimerSetting timerSettings[] = [];
   391        
   392        /*!
   393         *  ======== intFreq ========
   394         *  Default internal timer input clock frequency.
   395         *
   396         *  If intFreq is set, its value will be copied into all
   397         *  {@link #intFreqs}[] array entries except any entry which was
   398         *  explicitly written to in the application's config script.
   399         *
   400         *  For example, if intFreq is set to {hi:0, lo:32768} on a device
   401         *  with 3 timers, it will be copied into intFreqs[0], intFreqs[1] &
   402         *  intFreqs[2]. If the application explicitly sets one of the
   403         *  {@link #intFreqs}[] entries, say intFreqs[1], then intFreq is not
   404         *  copied into intFreqs[1] and intFreqs[1] retains the value it was
   405         *  set to in the config script.
   406         */
   407        metaonly config Types.FreqHz intFreq = {lo: 0, hi: 0};
   408    
   409        /*!
   410         *  ======== intFreqs ========
   411         *  Default internal timer input clock frequency array.
   412         *
   413         *  This array can be used to change the input clock frequency
   414         *  for a particular timer.
   415         *
   416         *  For example, if it is required to change the input clock frequency
   417         *  for timer id 2 to 32768Hz on a device that has 4 timers, the
   418         *  intFreqs[2] config param can be set to {hi:0, lo:32768} in the
   419         *  config script.
   420         *
   421         *  For a list of default timer frequencies for different devices,
   422         *  please refer {@link ./doc-files/TimerTables.html Timer Mapping Tables}.
   423         */
   424        metaonly config Types.FreqHz intFreqs[];
   425        
   426        /*!
   427         *  ======== stub  ========
   428         *  @_nodoc
   429         *  Timer requires acknowledgement
   430         *
   431         *  @param(arg)     timer object passed in as argument.
   432         */
   433        Void stub(UArg arg);
   434    
   435        /*!
   436         *  ======== dynStub  ========
   437         *  @_nodoc
   438         *  Acknowledges timer interrupt and sets next threshold for interrupt.
   439         *
   440         *  @param(arg)     timer object passed in as argument.
   441         */
   442        Void dynStub(UArg arg);
   443    
   444        /*!
   445         *  ======== getHandle ========
   446         *  Get Handle associated with a timer id.
   447         *
   448         *  @param(id)      timer Id
   449         *  @b(returns)     timer handle
   450         */
   451        Handle getHandle(UInt id);
   452    
   453    instance:
   454    
   455        /*! 
   456         *  ======== tiocpCfg ========
   457         *  Initial Timer TIOCP_CFG Register bit settings.
   458         *
   459         *  For a detailed description of this timer register, please
   460         *  refer to your device's Technical Reference Manual.
   461         */
   462        config TiocpCfg tiocpCfg = {idlemode: 0, emufree: 0, softreset: 1};
   463    
   464        /*! 
   465         *  ======== tier ========
   466         *  Initial Timer IRQSTATUS_SET Register bit settings.
   467         *
   468         *  For a detailed description of this timer register, please
   469         *  refer to your device's Technical Reference Manual.
   470         */
   471        config Tier tier = {mat_it_ena: 0, ovf_it_ena: 1, tcar_it_ena: 0};
   472    
   473        /*! 
   474         *  ======== twer ========
   475         *  Initial Timer IRQ Wakeup Enable Register bit settings.
   476         *
   477         *  For a detailed description of this timer register, please
   478         *  refer to your device's Technical Reference Manual.
   479         */
   480        config Twer twer = {mat_wup_ena: 0, ovf_wup_ena: 0, tcar_wup_ena: 0};
   481    
   482        /*! 
   483         *  ======== tclr ========
   484         *  Initial Timer Control Register bit settings.
   485         *
   486         *  For a detailed description of this timer register, please
   487         *  refer to your device's Technical Reference Manual.
   488         */
   489        config Tclr tclr = {ptv: 0, pre: 0, ce: 0, scpwm: 0, tcm: 0, trg: 0,
   490            pt: 0, captmode: 0, gpocfg: 0};
   491        
   492        /*! 
   493         *  ======== tsicr ========
   494         *  Initial Timer Synchronous Interface Control Register bit settings.
   495         *
   496         *  For a detailed description of this timer register, please
   497         *  refer to your device's Technical Reference Manual.
   498         */
   499        config Tsicr tsicr = {sft: 0, posted: 0, readmode: 0};
   500    
   501        /*! 
   502         *  ======== tmar ========
   503         *  Initial Timer Match Register setting.
   504         *
   505         *  For a detailed description of this timer register, please
   506         *  refer to your device's Technical Reference Manual.
   507         */
   508        config UInt32 tmar = 0;
   509    
   510        /*! 
   511         *  ======== intNum ========
   512         *  Hwi interrupt number to be used by Timer.
   513         */
   514        config Int intNum = -1;
   515    
   516        /*! 
   517         *  ======== eventId ========
   518         *  Hwi event Id to be used by Timer.
   519         */
   520        config Int eventId = -1;
   521    
   522        /*! Hwi Params for Hwi Object. Default is null. */
   523        config Hwi.Params *hwiParams = null;
   524    
   525        /*!
   526         *  ======== reconfig ========
   527         *  Used to modify static timer instances at runtime.
   528         *
   529         *  @param(timerParams)     timer Params
   530         *  @param(tickFxn)         functions that runs when timer expires
   531         */
   532        Void reconfig(FuncPtr tickFxn, const Params *timerParams, Error.Block *eb);
   533    
   534        /*!
   535         *  ======== getRollovers  ========
   536         *  @_nodoc
   537         *  Returns the total number of timer rollovers since the timer was 
   538         *  started.  This API is used internally for implementing timestamping 
   539         *  when the timer is shared with Clock, and running with RunMode_DYNAMIC.
   540         *  It has no other intended purpose.
   541         *
   542         *  @b(returns)     number of rollovers since timer was started
   543         */
   544        UInt32 getRollovers();
   545    
   546        /*!
   547         *  ======== enableTimestamping  ========
   548         *  @_nodoc
   549         *  Enables the timer to be used for timestamping purposes.  This API is 
   550         *  used internally for enabling timestamping when the timer is shared with
   551         *  Clock, and running with RunMode_DYNAMIC. It has no other intended 
   552         *  purpose.
   553         *
   554         */
   555        Void enableTimestamping();
   556        
   557        /*!
   558         *  ======== restoreRegisters ========
   559         *  Restore timer registers to their nominal state following a power down.
   560         *
   561         *  All registers are restored to their nominal operating state, except
   562         *  for those registers and bits associated with starting the timer.
   563         *  
   564         *  Following a power down, the user should do the following to restore
   565         *  and restart the timer:
   566         *
   567         *  @p(code)
   568         *      Timer_handle timer;
   569         *      Error_Block eb;
   570         *
   571         *      Timer_restoreRegisters(timer, &eb);
   572         *      Timer_start(timer);
   573         *  @p
   574         *
   575         */
   576        Void restoreRegisters(Error.Block *eb);
   577        
   578        /*! @_nodoc
   579         *  ======== getIntNum ========
   580         *  Get Timer's Interrupt number.
   581         *
   582         *  @b(returns)     Timer's Interrupt number
   583         */
   584        Int getIntNum();
   585    
   586    internal:   /* not for client use */
   587        
   588    
   589        /*! Information about timer */
   590        struct TimerDevice {
   591            Int  intNum;
   592            Int  eventId;
   593            Ptr  baseAddr;
   594        };
   595    
   596        /*! Device-specific Timer implementation. */
   597        proxy TimerSupportProxy inherits ti.sysbios.interfaces.ITimerSupport;
   598    
   599        /*!
   600         *  ======== startupNeeded ========
   601         *  This flag is use to prevent Timer_startup code (includes postInit(),
   602         *  deviceConfig(), initDevice() to be brought in un-necessarily.
   603         */
   604        config Bool startupNeeded = false;
   605    
   606        /*!
   607         *  ======== numTimerDevices ========
   608         *  The number of logical timers on a device.
   609         */
   610        config Int numTimerDevices;
   611    
   612        /*
   613         *  ======== deviceConfig ========
   614         *  Configure the timer.
   615         */
   616        Int deviceConfig(Object *timer, Error.Block *eb);
   617    
   618        /*
   619         *  ======== initDevice ========
   620         *  reset timer to its resting state
   621         */
   622        Void initDevice(Object *timer, Error.Block *eb);
   623    
   624        /*
   625         *  ======== initObj ========
   626         *  Initialize the instance state object
   627         */
   628        Void initObj(Object *timer, FuncPtr tickFxn, const Params *timerParams);
   629    
   630        /*
   631         *  ======== postInit ========
   632         *  finish initializing static and dynamic Timers
   633         */
   634        Int postInit(Object *timer, Error.Block *eb);
   635    
   636        /*
   637         *  ======== checkOverflow ========
   638         */
   639        Bool checkOverflow(UInt32 a, UInt32 b);
   640    
   641        /*
   642         *  ======== getNextAvailableTimerId ========
   643         */
   644        UInt getNextAvailableTimerId(Object *timer);
   645    
   646        /*!
   647         *  ======== spinLoop ========
   648         *  used by trigger function.
   649         */
   650        Void spinLoop(UInt count);
   651        
   652        /*!
   653         *  ======== checkFreq ========
   654         *  Used to verify that the DMTimer is operating at the right frequency.
   655         */
   656        Void checkFreq(Timer.Object *obj);
   657    
   658        /*! Instance state structure */
   659        struct Instance_State {
   660            Bool                staticInst;     /* statically created or not */
   661            Int                 id;             /* logical timer id. */
   662            UInt                tiocpCfg;
   663            UInt                tmar;
   664            UInt                tier;
   665            UInt                twer;
   666            UInt                tclr;
   667            UInt                tsicr;
   668            ITimer.RunMode      runMode;        /* timer mode */
   669            ITimer.StartMode    startMode;      /* timer mode */
   670            UInt                period;         /* period */
   671            ITimer.PeriodType   periodType;     /* type (microsecs, inst) */
   672            UInt                intNum;         /* intr num */
   673            Int                 eventId;        /* event Id */
   674            UArg                arg;            /* isrFxn arg */
   675            Hwi.FuncPtr         tickFxn;        /* Timer fxn plugged into Hwi */
   676            Types.FreqHz        extFreq;        /* ext freq */
   677            Hwi.Handle          hwi;            /* hwi inst */
   678            UInt                prevThreshold;  /* previous interrupt thresh */
   679            UInt                rollovers;      /* total timer rollovers */
   680            UInt                savedCurrCount; /* used with setNextTick */
   681            /* 
   682             * Used by Timer Startup to decide whether to use default Event Id 
   683             * from the device Table or use the User provided Event Id 
   684             */
   685            Bool                useDefaultEventId;
   686        }
   687    
   688        /*! Module state structure */
   689        struct Module_State {
   690            Bits32          availMask;      /* avaliable 32-bit timer halves */
   691            Types.FreqHz    intFreqs[];     /* internal frequency in Hz */
   692            TimerDevice     device[];       /* timer device information */
   693            Handle          handles[];      /* handles based on logical id */
   694            Bool            firstInit;
   695        }
   696    }