1    /*
     2     * Copyright (c) 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     */
    32    /*
    33     *  ======== IntMux.xdc ========
    34     *
    35     */
    36    
    37    package ti.sysbios.family.arm.ducati.dm8148;
    38    
    39    import xdc.runtime.Assert;
    40    import xdc.runtime.Error;
    41    
    42    import ti.sysbios.interfaces.IHwi;
    43    
    44    /*!
    45     *  ======== IntMux ========
    46     *  IntMux Module
    47     *
    48     *  Below is an example of how to override the default mapping of 
    49     *  interrupt 42 so that it is sourced by I2CINT2 rather than its 
    50     *  default mapping to I2CINT1:
    51     *
    52     *  @p(code)
    53     *  #include <ti/sysbios/family/arm/m3/Hwi.h>
    54     *  #include <ti/sysbios/family/arm/ducati/dm8148/IntMux.h>
    55     *  
    56     *  Void myI2CINT2Handler(UArg arg)
    57     *  {
    58     *      System_printf("I2CINT2 arg = %d\n", (UInt)arg);
    59     *  }
    60     *  
    61     *  Int main(Int argc, Char* argv[])
    62     *  {
    63     *      Hwi_Params params;
    64     *  
    65     *      Hwi_Params_init(&params);
    66     *
    67     *      // set IntMux 19 to event number 4 (I2CINT2)
    68     *      IntMux_setEvent(19, 4);
    69     *  
    70     *      // create a corresponding interrupt handler
    71     *      // notice that Ducati interrupt number 42 corresponds to IntMux 19
    72     *
    73     *      params.arg = 42; // pass the Int number to the handler for demo 
    74     *
    75     *      Hwi_create(42, myI2CINT2Handler, &params, NULL);
    76     *  
    77     *      BIOS_start();
    78     *  
    79     *      return (0);
    80     *  }
    81     *  @p
    82     *  
    83     *  Here is how you would define the same interrupt handler statically 
    84     *  in a configuration script:
    85     *  
    86     *  @p(code)
    87     *  var Hwi = xdc.useModule('ti.sysbios.family.arm.m3.Hwi');
    88     *  var IntMux = xdc.useModule('ti.sysbios.family.arm.ducati.dm8148.IntMux');
    89     *  
    90     *  IntMux.setEventMeta(19, 4);
    91     *  
    92     *  var hwiParams = new Hwi.Params();
    93     *  hwiParams.arg = 42;
    94     *  Program.global.staticHwi = Hwi.create(42, '&myI2CINT2Handler', hwiParams);
    95     *  @p
    96     *  
    97     *  @p(html)
    98     *  <h3> Calling Context </h3>
    99     *  <table border="1" cellpadding="3">
   100     *    <colgroup span="1"></colgroup> <colgroup span="5" align="center"></colgroup>
   101     *
   102     *    <tr><th> Function                 </th><th>  Hwi   </th><th>  Swi   </th><th>  Task  </th><th>  Main  </th><th>  Startup  </th></tr>
   103     *    <!--                                                                                                                 -->
   104     *    <tr><td> {@link #setEvent}    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td><td>   Y    </td></tr>
   105     *    <tr><td colspan="6"> Definitions: <br />
   106     *       <ul>
   107     *         <li> <b>Hwi</b>: API is callable from a Hwi thread. </li>
   108     *         <li> <b>Swi</b>: API is callable from a Swi thread. </li>
   109     *         <li> <b>Task</b>: API is callable from a Task thread. </li>
   110     *         <li> <b>Main</b>: API is callable during any of these phases: </li>
   111     *           <ul>
   112     *             <li> In your module startup after this module is started (e.g. Mod_Module_startupDone() returns TRUE). </li>
   113     *             <li> During xdc.runtime.Startup.lastFxns. </li>
   114     *             <li> During main().</li>
   115     *             <li> During BIOS.startupFxns.</li>
   116     *           </ul>
   117     *         <li> <b>Startup</b>: API is callable during any of these phases:</li>
   118     *           <ul>
   119     *             <li> During xdc.runtime.Startup.firstFxns.</li>
   120     *             <li> In your module startup before this module is started (e.g. Mod_Module_startupDone() returns FALSE).</li>
   121     *           </ul>
   122     *       </ul>
   123     *    </td></tr>
   124     *
   125     *  </table>
   126     *  @p
   127     */
   128    
   129    @DirectCall
   130    module IntMux
   131    {
   132    
   133        /*!
   134         *  Assert if interrupt number > 56
   135         */
   136        config Assert.Id A_badIntNum = {
   137            msg: "A_badIntNum: intNum must be <= 56"
   138        };
   139    
   140        /*!
   141         *  Assert if event number > 47
   142         */
   143        config Assert.Id A_badEventNum = {
   144            msg: "A_badIntNum: eventNum must be <= 47"
   145        };
   146    
   147        /*!
   148         *  Address of "DUCATI_INTMUX_0_3" register
   149         */
   150        config Ptr intMuxBaseAddr = 0x48140F54;
   151    
   152    
   153        /*!
   154         *  ======== setEventMeta ========
   155         *  Set the event number associated with an interrupt.
   156         *
   157         *  Statically sets the event number associated with 
   158         *  an interrupt in the Ducati Interrupt Mux as described
   159         *  in section 5.9.2 of the Centaurus Architecture Spec.
   160         *
   161         *  @param(intNum)    The intMux number (0-56)
   162         *  @param(eventNum)  The event number (0-47) 
   163         */
   164        metaonly Void setEventMeta(UInt intMuxNum, UInt eventNum);
   165    
   166        /*!
   167         *  ======== setEvent ========
   168         *  Set the event number associated with an interrupt.
   169         *
   170         *  Dynamically sets the event number associated with 
   171         *  an interrupt in the Ducati Interrupt Mux as described
   172         *  in section 5.9.2 of the Centaurus Architecture Spec.
   173         *
   174         *  @param(intNum)    The intMux number (0-56)
   175         *  @param(eventNum)  The event number (0-47) 
   176         */
   177        Void setEvent(UInt intMuxNum, UInt eventNum);
   178    
   179    internal:
   180    
   181        /*
   182         *  ======== initIntMux ========
   183         */
   184        Void initIntMux();
   185    
   186        config UInt8 intMux[57];   // table of INTMUX events
   187    }