1    /* 
     2     * Copyright (c) 2012, 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     */
    37    
    38    package ti.sysbios.family.arm.tms570;
    39    
    40    import xdc.rov.ViewInfo;
    41    
    42    import xdc.runtime.Error;
    43    import xdc.runtime.Types;
    44    import ti.sysbios.interfaces.ITimer;
    45    /*!
    46     *  ======== Timer ========
    47     *  Timer Peripherals Manager for arm_tms570 family.
    48     *
    49     *  @p(html)
    50     *  <h3> Calling Context </h3>
    51     *  <table border="1" cellpadding="3">
    52     *    <colgroup span="1"></colgroup> <colgroup span="5" align="center"></colgroup>
    53     *
    54     *    <tr><th> Function                 </th><th>  Hwi   </th><th>  Swi   </th><th>  Task  </th><th>  Main  </th><th>  Startup  </th></tr>
    55     *    <!--                                                                                                                 -->
    56     *    <tr><td> {@link #getNumTimers}            </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    57     *    <tr><td> {@link #getStatus}               </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    58     *    <tr><td> {@link #Params_init}             </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    59     *    <tr><td> {@link #construct}               </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    60     *    <tr><td> {@link #create}                  </td><td>   N    </td><td>   N    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    61     *    <tr><td> {@link #delete}                  </td><td>   N    </td><td>   N    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    62     *    <tr><td> {@link #destruct}                </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    63     *    <tr><td> {@link #getCount}                </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td><td>   N    </td></tr>
    64     *    <tr><td> {@link #getFreq}                 </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    65     *    <tr><td> {@link #getPeriod}               </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    66     *    <tr><td> {@link #reconfig}                </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    67     *    <tr><td> {@link #setPeriod}               </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    68     *    <tr><td> {@link #setPeriodMicroSecs}      </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td></tr>
    69     *    <tr><td> {@link #start}                   </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td><td>   N    </td></tr>
    70     *    <tr><td> {@link #stop}                    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   N    </td><td>   N    </td></tr>
    71     *    <tr><td colspan="6"> Definitions: <br />
    72     *       <ul>
    73     *         <li> <b>Hwi</b>: API is callable from a Hwi thread. </li>
    74     *         <li> <b>Swi</b>: API is callable from a Swi thread. </li>
    75     *         <li> <b>Task</b>: API is callable from a Task thread. </li>
    76     *         <li> <b>Main</b>: API is callable during any of these phases: </li>
    77     *           <ul>
    78     *             <li> In your module startup after this module is started (e.g. Timer_Module_startupDone() returns TRUE). </li>
    79     *             <li> During xdc.runtime.Startup.lastFxns. </li>
    80     *             <li> During main().</li>
    81     *             <li> During BIOS.startupFxns.</li>
    82     *           </ul>
    83     *         <li> <b>Startup</b>: API is callable during any of these phases:</li>
    84     *           <ul>
    85     *             <li> During xdc.runtime.Startup.firstFxns.</li>
    86     *             <li> In your module startup before this module is started (e.g. Timer_Module_startupDone() returns FALSE).</li>
    87     *           </ul>
    88     *       </ul>
    89     *    </td></tr>
    90     *
    91     *  </table>
    92     *  @p
    93     *
    94     */
    95    @InstanceFinalize       /* To cleanup */
    96    @InstanceInitError      /* To report unavailability of timer */
    97    @ModuleStartup          /* to configure static timers */
    98    
    99    module Timer inherits ti.sysbios.interfaces.ITimer
   100    {
   101        /*! Max value of Timer period for PeriodType_COUNTS*/
   102        const UInt MAX_PERIOD = 0xffffffff;
   103    
   104        /*! Number of timer peripherals on chip */
   105        const Int NUM_TIMER_DEVICES = 2;
   106    
   107        /*! @_nodoc
   108         *  Min instructions to use in trigger(). 
   109         */
   110        const Int MIN_SWEEP_PERIOD = 8;
   111    
   112        /*! Timer Configuration struct. 
   113         *
   114         *  @field(cos)     When true timer stops counting during emulation halt.
   115         *                  When false timer continues to count during emulation
   116         *                  halt.
   117         */
   118        struct Control {
   119            Bool cos;      /*! 0=stop in debug mode; 1=continue in debug mode */
   120        };
   121    
   122        /*! @_nodoc */
   123        @XmlDtd
   124        metaonly struct BasicView {
   125            Ptr         halTimerHandle;
   126            String      label;
   127            UInt        id;
   128            String      startMode;
   129            String      runMode;
   130            UInt        period;
   131            String      periodType;
   132            UInt        intNum;
   133            String      tickFxn[];
   134            UArg        arg;  
   135            String      extFreq;
   136            UInt32      accuTicks;
   137            String      hwiHandle;
   138        };
   139    
   140        /*! @_nodoc */
   141        metaonly struct DeviceView {
   142            UInt        id;
   143            String      device;
   144            String      devAddr;
   145            UInt        intNum;
   146            String      runMode;
   147            UInt        period;
   148            UInt        currCount;
   149            UInt        remainingCount;
   150            String      state;
   151        };
   152    
   153        /*! @_nodoc */
   154        metaonly struct ModuleView {
   155            String      availMask;      /* available 32-bit timer halves */
   156        }
   157    
   158        /*! @_nodoc */
   159        @Facet
   160        metaonly config ViewInfo.Instance rovViewInfo = 
   161            ViewInfo.create({
   162                viewMap: [
   163                [
   164                    'Basic',
   165                    {
   166                        type: ViewInfo.INSTANCE,
   167                        viewInitFxn: 'viewInitBasic',
   168                        structName: 'BasicView'
   169                    }
   170                ],
   171                [
   172                    'Device',
   173                    {
   174                        type: ViewInfo.INSTANCE,
   175                        viewInitFxn: 'viewInitDevice',
   176                        structName: 'DeviceView'
   177                    }
   178                ],
   179                [
   180                    'Module',
   181                    {
   182                        type: ViewInfo.MODULE,
   183                        viewInitFxn: 'viewInitModule',
   184                        structName: 'ModuleView'
   185                    }
   186                ],
   187                ]
   188            });
   189    
   190        /*! 
   191         *  Error raised when timer id specified is not supported.
   192         */
   193        config Error.Id E_invalidTimer  = {msg: "E_invalidTimer: Invalid Timer Id %d"}; 
   194    
   195        /*! 
   196         *  Error raised when timer requested is in use
   197         */
   198        config Error.Id E_notAvailable  = 
   199            {msg: "E_notAvailable: Timer not available %d"}; 
   200    
   201        /*! 
   202         *  Error raised when Hwi Params has mask where self is turned on.
   203         *  
   204         *  This is not allowed because the timers on this platform do not 
   205         *  support one-shot mode and a stub is used to stop it.
   206         *  Another timer interrupt cannot go off when the ISR is running.
   207         */
   208        config Error.Id E_invalidHwiMask  = 
   209            {msg: "E_InvalidMask: Mask in hwiParams cannot enable self"}; 
   210    
   211        /*! 
   212         *  Error raised when period requested is not supported
   213         */
   214        config Error.Id E_cannotSupport  = 
   215            {msg: "E_cannotSupport: Timer cannot support requested period %d"}; 
   216    
   217        /*!
   218         *  ======== anyMask ========
   219         *  Available mask to be used when select = Timer_ANY
   220         */
   221        config UInt anyMask = 0x3;
   222    
   223        /*!
   224         *  ======== oneShotStub ========
   225         *  @_nodoc
   226         *  RTI timer does not support one shot mode. This stub stops timer
   227         *  and disables its interrupt.
   228         *
   229         *  @param(arg)     Timer Handle.
   230         */
   231        Void oneShotStub(UArg arg);
   232    
   233        /*!
   234         *  ======== periodicStub ========
   235         *  @_nodoc
   236         *  When accuTicks = true, this stub does the tick accumulation.
   237         *
   238         *  @param(arg)     Timer Handle.
   239         */
   240        Void periodicStub(UArg arg);
   241    
   242        /*!
   243         *  ======== getHandle ========
   244         *  @_nodoc
   245         *  Used by TimestampProvider module to get hold of timer handle used by 
   246         *  Clock.
   247         *
   248         *  @param(id)      timer Id.
   249         */
   250        Handle getHandle(UInt id);
   251    
   252    instance:
   253    
   254    
   255        /*! Control register configuration. Default cos=0. */
   256        config Control controlRegInit = {cos: 0};
   257    
   258        /*! Hwi Params for Hwi Object. Default is null.*/
   259        config Hwi.Params *hwiParams = null;
   260    
   261        /*! Hwi intNum to be used by Timer. */
   262        config Int intNum = -1;
   263    
   264        /*!
   265         *  ======== reconfig ========
   266         *  Used to modify static timer instances at runtime.
   267         *
   268         *  @param(timerParams)     timer Params
   269         *  @param(tickFxn)         functions that runs when timer expires.
   270         */
   271        Void reconfig(FuncPtr tickFxn, const Params *timerParams, Error.Block *eb);
   272    
   273        /*!
   274         *  ======== getAccuTicks ========
   275         *  @_nodoc
   276         *  returns accumulated ticks. Used by TimestampProvider.
   277         *
   278         *  @b(returns)     get accumulated ticks
   279         */
   280        UInt32 getAccuTicks();
   281    
   282        /*!
   283         *  ======== ackInterrupt ========
   284         *  clear the current timer interrupt flag
   285         */
   286        Void ackInterrupt();
   287    
   288    internal:   /* not for client use */
   289       
   290        /*!
   291         *  ======== noStartupNeeded ========
   292         *  Flag used to prevent misc code from being brought in
   293         *  un-necessarily
   294         */
   295        config UInt startupNeeded = false;
   296    
   297        struct Instance_State {
   298            Bool                    staticInst;
   299            Int                     id;            
   300            UInt                    controlRegInit;
   301            ITimer.RunMode          runMode;    
   302            ITimer.StartMode        startMode;
   303            UInt                    period; 
   304            ITimer.PeriodType       periodType;    
   305            UInt                    intNum;
   306            UArg                    arg;  
   307            Hwi.FuncPtr             tickFxn;
   308            Types.FreqHz            extFreq;
   309            volatile UInt32         accuTicks;
   310            Hwi.Handle              hwi;
   311        }
   312    
   313        struct Module_State {
   314            UInt            availMask;      /* available peripherals */
   315            Handle          handles[NUM_TIMER_DEVICES];
   316                                            /* array of handles based on id */
   317        }
   318    }
   319    /*
   320     *  @(#) ti.sysbios.family.arm.tms570; 2, 0, 0, 0,285; 2-24-2012 11:39:44; /db/vtree/library/trees/avala/avala-q28x/src/ xlibrary
   321    
   322     */
   323