1    /*
     2     * Copyright (c) 2014-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     *  ======== ClockFreqs.xdc ========
    34     *
    35     *
    36     */
    37    
    38    package ti.sysbios.family.arm.msp432;
    39    
    40    import xdc.rov.ViewInfo;
    41    
    42    /*!
    43     *  ======== ClockFreqs ========
    44     *  ClockFreqs Module.
    45     *
    46     *  This module is used to define the ACLK, SMCLK, and HSMCLK frequencies in
    47     *  effect when BIOS_start() is called at the end of main().  It also provides
    48     *  runtime functions that can be used to query or set individual clock
    49     *  frequencies.
    50     *
    51     *  If the application defines values for these three clocks, the application
    52     *  is responsible for setting up the clocks to the corresponding frequencies.
    53     *  This module will simply hold the values specified, for reference by other
    54     *  SYS/BIOS modules, or for query by the application at runtime.
    55     *
    56     *  If the application configuration specifies (in its .cfg file) a value for
    57     *  one of these three clock frequencies, it must specify values for all three
    58     *  clocks; if it does not, a build error will be thrown.
    59     *
    60     *  If the application does not define values for these clocks, the values will
    61     *  default either to the device reset values, or the boost values setup by
    62     *  the Boot module (ti.sysbios.family.arm.msp432.init.Boot).  For example, if
    63     *  the application does not configure values for ClockFreq, and does not turn
    64     *  off the Boot module's default frequency boost, then the Boot module boost
    65     *  frequencies are used.
    66     *
    67     *  If the application does not configure values for ClockFreq, and *does* turn
    68     *  off the Boot module's frequency boost (see snippet below), then the default
    69     *  reset frequency values will be used.
    70     *
    71     *  @p(code)
    72     *      var Boot = xdc.module('ti.sysbios.family.arm.msp432.init.Boot');
    73     *      Boot.configureClocks = false;
    74     *  @p
    75     *
    76     *  Currently the reset and Boot module boost values are fixed, as shown below.
    77     *
    78     *  The default reset values are:
    79     *
    80     *  @p(code)
    81     *      ACLK  = 32768 Hz
    82     *      SMCLK = 3 MHz
    83     *      HSMCLK = 3 MHz
    84     *  @p
    85     *
    86     *  The default Boot module boost values are:
    87     *
    88     *  @p(code)
    89     *      ACLK  = 32768 Hz
    90     *      SMCLK = 12 MHz
    91     *      HSMCLK = 24 MHz
    92     *  @p
    93     *
    94     *  Note: This module only tracks the ACLK, SMCLK, and HSMCLK values. It does
    95     *  not track the CPU clock (MCLK) frequency.  MCLK can be configured and
    96     *  queried with the BIOS module.  For example, to configure the CPU
    97     *  frequency:
    98     *
    99     *      var BIOS = xdc.useModule('ti.sysbios.BIOS');
   100     *      BIOS.cpuFreq.lo = 48000000;
   101     *      BIOS.cpuFreq.hi = 0;
   102     *  @p
   103     *
   104     *  @p(html)
   105     *  <h3> Calling Context </h3>
   106     *  <table border="1" cellpadding="3">
   107     *    <colgroup span="1"></colgroup> <colgroup span="5" align="center"></colgroup>
   108     *
   109     *    <tr><th> Function                 </th><th>  Hwi   </th><th>  Swi   </th><th>  Task  </th><th>  Main  </th><th>  Startup  </th></tr>
   110     *    <!-- -->
   111     *    <tr><td> {@link #getFrequency} </td><td>   Y    </td><td>   Y    </td><td>   Y </td><td>   Y    </td><td>   Y    </td></tr>
   112     *    <tr><td> {@link #setFrequency} </td><td>   Y    </td><td>   Y    </td><td>   Y </td><td>   Y    </td><td>   Y    </td></tr>
   113     *    <tr><td colspan="6"> Definitions: <br />
   114     *       <ul>
   115     *         <li> <b>Hwi</b>: API is callable from a Hwi thread. </li>
   116     *         <li> <b>Swi</b>: API is callable from a Swi thread. </li>
   117     *         <li> <b>Task</b>: API is callable from a Task thread. </li>
   118     *         <li> <b>Main</b>: API is callable from main(). </li>
   119     *         <li> <b>Startup</b>: API is callable during any module startup. </li>
   120     *       </ul>
   121     *    </td></tr>
   122     *
   123     *  </table>
   124     *  @p
   125     */
   126    
   127    @DirectCall
   128    module ClockFreqs
   129    {
   130        metaonly struct ModuleView {
   131            UInt    ACLK;
   132            UInt    MCLK;
   133            UInt    SMCLK;
   134            UInt    HSMCLK;
   135        }
   136    
   137        @Facet
   138        metaonly config ViewInfo.Instance rovViewInfo =
   139            ViewInfo.create({
   140                viewMap: [
   141                [
   142                    'Module',
   143                    {
   144                        type: ViewInfo.MODULE,
   145                        viewInitFxn: 'viewInitModule',
   146                        structName: 'ModuleView'
   147                    }
   148                ],
   149                ]
   150            });
   151    
   152        /*! Clocks */
   153        enum Clock {
   154            Clock_ACLK,             /* ACLK */
   155            Clock_SMCLK,            /* SMCLK */
   156            Clock_HSMCLK            /* HSMCLK */
   157        };
   158    
   159        /*! ACLK frequency (Hz) */
   160        config UInt32 ACLK;
   161    
   162        /*! SMCLK frequency (Hz) */
   163        config UInt32 SMCLK;
   164    
   165        /*! HSMCLK frequency (Hz) */
   166        config UInt32 HSMCLK;
   167    
   168        /*!
   169         *  ======== getFrequency ========
   170         *  Get the frequency for a clock.
   171         *
   172         */
   173        UInt32 getFrequency(Clock clock);
   174    
   175        /*!
   176         *  ======== setFrequency ========
   177         *  Set the frequency for a clock.
   178         *
   179         */
   180        Void setFrequency(Clock clock, UInt32 frequency);
   181    
   182    internal:   /* not for client use */
   183    
   184        struct Module_State {
   185            UInt32          ACLK;           /* ACLK frequency */
   186            UInt32          SMCLK;          /* SMCLK frequency */
   187            UInt32          HSMCLK;         /* HSCLK frequency */
   188        }
   189    }