1    /* --COPYRIGHT--,BSD
     2     * Copyright (c) $(CPYYEAR), 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     * --/COPYRIGHT--*/
    32    /*
    33     *  ======== NameServerRemoteNotify.xdc ========
    34     */
    35     
    36    import xdc.runtime.Error;
    37    import xdc.runtime.Assert;
    38    
    39    import xdc.rov.ViewInfo;
    40    
    41    import ti.sysbios.knl.Swi;
    42    import ti.sysbios.knl.Semaphore;
    43    import ti.sdo.ipc.GateMP;
    44    import ti.sdo.utils.INameServerRemote;
    45    
    46    /*!
    47     *  ======== NameServerRemoteNotify ========
    48     *  Used by NameServer to communicate to remote processors.
    49     *
    50     *  This module is used by {@link #ti.sdo.utils.NameServer} to communicate
    51     *  to remote processors using {@link ti.sdo.ipc.Notify} and shared memory.
    52     *  There needs to be one instance between each two cores in the system.
    53     *  Interrupts must be enabled before using this module.  For critical
    54     *  memory management, a GateMP {@link #gate} can be specified.  Currently
    55     *  supports transferring up to 300-bytes between two cores.
    56     */
    57    @InstanceInitError
    58    @InstanceFinalize
    59    
    60    module NameServerRemoteNotify inherits INameServerRemote
    61    {
    62        /*! @_nodoc */
    63        metaonly struct BasicView {
    64            UInt        remoteProcId;
    65            String      remoteProcName;
    66            String      localRequestStatus;
    67            String      localInstanceName;
    68            String      localName;
    69            String      localValue;
    70            String      remoteRequestStatus;
    71            String      remoteInstanceName;
    72            String      remoteName;
    73            String      remoteValue;
    74        }
    75        
    76        /*!
    77         *  ======== rovViewInfo ========
    78         */
    79        @Facet
    80        metaonly config ViewInfo.Instance rovViewInfo =
    81            ViewInfo.create({
    82                viewMap: [
    83                    ['Basic',
    84                        {
    85                            type: ViewInfo.INSTANCE,
    86                            viewInitFxn: 'viewInitBasic',
    87                            structName: 'BasicView'
    88                        }
    89                    ],
    90                ]
    91            });
    92    
    93        /* structure in shared memory for retrieving value */
    94        struct Message {
    95            Bits32  request;            /* if this is a request set to 1    */
    96            Bits32  response;           /* if this is a response set to 1   */
    97            Bits32  requestStatus;      /* if request sucessful set to 1    */
    98            Bits32  value;              /* holds value if len <= 4          */
    99            Bits32  valueLen;           /* len of value                     */
   100            Bits32  instanceName[8];    /* name of NameServer instance      */
   101            Bits32  name[8];            /* name of NameServer entry         */
   102            Bits32  valueBuf[75];       /* supports up to 300-byte value    */
   103        };
   104    
   105        /*!
   106         *  Assert raised when length of value larger then 300 bytes.
   107         */
   108        config xdc.runtime.Assert.Id A_invalidValueLen =
   109            {msg: "A_invalidValueLen: Invalid valueLen (too large)"};
   110    
   111        /*!
   112         *  ======== notifyEventId ========
   113         *  The Notify event ID.
   114         */
   115        config UInt notifyEventId = 4;
   116        
   117        /*!
   118         *  ======== timeoutInMicroSecs ========
   119         *  The timeout value in terms of microseconds
   120         *
   121         *  A NameServer request will return after this amout of time
   122         *  without a response. The default timeout value is to wait forever.
   123         *  To not wait, use the value of '0'.
   124         */
   125        config UInt timeoutInMicroSecs = ~(0);
   126    
   127    instance:
   128    
   129        /*!
   130         *  ======== sharedAddr ========
   131         *  Physical address of the shared memory
   132         *
   133         *  The shared memory that will be used for maintaining shared state
   134         *  information.  This value must be the same for both processors when
   135         *  creating the instance between a pair of processors.
   136         */
   137        config Ptr sharedAddr = null;
   138    
   139        /*!
   140         *  ======== gate ========
   141         *  GateMP used for critical region management of the shared memory
   142         *
   143         *  Using the default value of NULL will result in the default GateMP
   144         *  being used for context protection.
   145         */
   146        config GateMP.Handle gate = null;
   147    
   148    internal:    
   149    
   150        /*
   151         *  ======== timeout ========
   152         *  The timeout value to pass into Semaphore_pend
   153         *
   154         *  This value is calculated based on timeoutInMicroSecs and the
   155         *  SYSBIOS clock.tickPeriod.
   156         */
   157        config UInt timeout;
   158        
   159        /*!
   160         *  ======== cbFxn ========
   161         *  The call back function registered with Notify.
   162         *
   163         *  This function is registered with Notify as a call back function
   164         *  when the specified event is triggered.  This function simply posts
   165         *  a Swi which will process the event.
   166         *
   167         *  @param(procId)          Source proc id
   168         *  @param(lineId)          Interrupt line id
   169         *  @param(eventId)         the Notify event id.
   170         *  @param(arg)             the argument for the function.
   171         *  @param(payload)         a 32-bit payload value.
   172         */
   173        Void cbFxn(UInt16 procId, UInt16 lineId, UInt32 eventId, UArg arg, 
   174                   UInt32 payload);
   175        
   176        /*!
   177         *  ======== swiFxn ========
   178         *  The swi function that will be executed during the call back.
   179         *
   180         *  @param(arg)     argument to swi function
   181         */
   182        Void swiFxn(UArg arg);
   183        
   184        /* instance state */
   185        struct Instance_State {
   186            Message             *msg[2];        /* Ptrs to messages in shared mem */
   187            UInt16              regionId;       /* SharedRegion ID                */
   188            GateMP.Handle       gate;           /* remote and local gate protect  */
   189            Semaphore.Object    semRemoteWait;  /* sem to wait on remote proc     */
   190            Semaphore.Object    semMultiBlock;  /* sem to block multiple threads  */
   191            Swi.Object          swiObj;         /* instance swi object            */
   192            UInt16              remoteProcId;   /* remote MultiProc id            */
   193            Bool                cacheEnable;    /* cacheability                   */
   194        };
   195    }