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     *  ======== NotifyDriverCirc.xdc ================
    34     */
    35    
    36    import ti.sdo.utils.MultiProc;
    37    import ti.sdo.ipc.interfaces.INotifyDriver;
    38    import ti.sdo.ipc.notifyDrivers.IInterrupt;
    39    import ti.sdo.ipc.Notify;
    40    
    41    import xdc.rov.ViewInfo;
    42    
    43    import xdc.runtime.Assert;
    44    
    45    /*!
    46     *  ======== NotifyDriverCirc ========
    47     *  Shared memory driver using circular buffer for F28M35x devices.
    48     *
    49     *  This is a {@link ti.sdo.ipc.Notify} driver that utilizes shared memory
    50     *  and inter-processor hardware interrupts for notification between cores.
    51     *
    52     *  This driver is designed to work with only F28M35x family of devices.
    53     *  This module needs to be plugged with an appropriate module that implements
    54     *  the {@link ti.sdo.ipc.notifyDrivers.IInterrupt} interface for a given 
    55     *  device.
    56     *
    57     *  The driver utilizes shared memory in the manner indicated by the following
    58     *  diagram.
    59     *
    60     *  @p(code)
    61     *  
    62     *  NOTE: Processor '0' corresponds to the M3 and '1' corresponds to the C28
    63     *
    64     * sharedAddr -> --------------------------- bytes
    65     *               |  eventEntry0  (0)       | 8  
    66     *               |  eventEntry1  (0)       | 8
    67     *               |  ...                    | 
    68     *               |  eventEntry15 (0)       | 8
    69     *               |                         |
    70     *               |-------------------------|
    71     *               |  eventEntry16 (0)       | 8
    72     *               |  eventEntry17 (0)       | 8
    73     *               |  ...                    | 
    74     *               |  eventEntry31 (0)       | 8
    75     *               |                         |
    76     *               |-------------------------|
    77     *               |  putWriteIndex (0)      | 4
    78     *               |                         |
    79     *               |-------------------------|
    80     *               |  getReadIndex (1)       | 4
    81     *               |                         |
    82     *               |-------------------------|
    83     *               |  eventEntry0  (1)       | 8  
    84     *               |  eventEntry1  (1)       | 8
    85     *               |  ...                    | 
    86     *               |  eventEntry15 (1)       | 8
    87     *               |                         |
    88     *               |-------------------------|
    89     *               |  eventEntry16 (1)       | 8
    90     *               |  eventEntry17 (1)       | 8
    91     *               |  ...                    | 
    92     *               |  eventEntry31 (1)       | 8
    93     *               |                         |
    94     *               |-------------------------|
    95     *               |  putWriteIndex (1)      | 4
    96     *               |                         |
    97     *               |-------------------------|
    98     *               |  getReadIndex (0)       | 4
    99     *               |                         |
   100     *               |-------------------------|
   101     *
   102     *
   103     *  Legend:
   104     *  (0), (1) : belongs to the respective processor
   105     *
   106     *  @p
   107     */
   108    
   109    @InstanceFinalize
   110    
   111    module NotifyDriverCirc inherits ti.sdo.ipc.interfaces.INotifyDriver
   112    {
   113        /*! @_nodoc */
   114        metaonly struct BasicView {
   115            String      remoteProcName;
   116            UInt        bufSize;
   117            UInt        spinCount;
   118            UInt        maxSpinWait;
   119        }
   120        
   121        /*! @_nodoc */
   122        metaonly struct EventDataView {
   123            UInt        index;
   124            String      buffer;
   125            Ptr         addr;
   126            UInt        eventId;
   127            Ptr         payload;
   128        }
   129        
   130        /*!
   131         *  ======== rovViewInfo ========
   132         */
   133        @Facet
   134        metaonly config ViewInfo.Instance rovViewInfo =
   135            ViewInfo.create({
   136                viewMap: [
   137                    ['Basic',
   138                        {
   139                            type: ViewInfo.INSTANCE,
   140                            viewInitFxn: 'viewInitBasic',
   141                            structName: 'BasicView'
   142                        }
   143                    ],
   144                    ['Events',
   145                        {
   146                            type: ViewInfo.INSTANCE_DATA,
   147                            viewInitFxn: 'viewInitData',
   148                            structName: 'EventDataView'
   149                        }
   150                    ],
   151                ]
   152            });
   153        
   154        /*!
   155         *  Assert raised when trying to use Notify_[enable/disable]Event with
   156         *  NotifyDriverCirc
   157         */
   158        config Assert.Id A_notSupported =
   159            {msg: "A_notSupported: [enable/disable]Event not supported by NotifyDriverCirc"};
   160    
   161        /*! @_nodoc
   162         *  ======== numMsgs ========
   163         *  The number of messages or slots in the circular buffer
   164         *
   165         *  This is use to determine the size of the put and get buffers.
   166         *  Each eventEntry is two 32bits wide, therefore the total size
   167         *  of each circular buffer is [numMsgs * sizeof(eventEntry)].
   168         */
   169        config UInt numMsgs = 16;
   170        
   171        /*!
   172         *  ======== sharedMemReq ========
   173         *  Amount of shared memory required for creation of each instance
   174         *
   175         *  @param(params)      Pointer to parameters that will be used in the
   176         *                      create
   177         *
   178         *  @a(returns)         Number of MAUs in shared memory needed to create 
   179         *                      the instance.
   180         */
   181        SizeT sharedMemReq(const Params *params);
   182        
   183        /*! @_nodoc
   184         *  ======== sharedMemReqMeta ========
   185         *  Amount of shared memory required
   186         *
   187         *  @param(params)      Pointer to the parameters that will be used in
   188         *                      create.
   189         *
   190         *  @a(returns)         Size of shared memory in MAUs on local processor.
   191         */
   192        metaonly SizeT sharedMemReqMeta(const Params *params);
   193        
   194    instance:
   195    
   196        /*!
   197         *  ======== readAddr ========
   198         *  Address in shared memory where buffer is placed
   199         *
   200         *  Use {@link #sharedMemReq} to determine the amount of shared memory
   201         *  required.
   202         */
   203        config Ptr readAddr = null;
   204        
   205        /*!
   206         *  ======== writeAddr ========
   207         *  Address in shared memory where buffer is placed
   208         *
   209         *  Use {@link #sharedMemReq} to determine the amount of shared memory
   210         *  required.
   211         */
   212        config Ptr writeAddr = null;
   213    
   214    internal:
   215    
   216        /*!
   217         *  ======== localIntId ========
   218         *  Local interrupt ID for interrupt line
   219         *
   220         *  For devices that support multiple inter-processor interrupt lines, this
   221         *  configuration parameter allows selecting a specific line to use for
   222         *  receiving an interrupt.  The value specified here corresponds to the
   223         *  incoming interrupt line on the local processor.
   224         */
   225        config UInt localIntId;
   226    
   227        /*!
   228         *  ======== remoteIntId ========
   229         *  Remote interrupt ID for interrupt line
   230         *
   231         *  For devices that support multiple inter-processor interrupt lines, this
   232         *  configuration parameter allows selecting a specific line to use for
   233         *  receiving an interrupt.  The value specified here corresponds to the
   234         *  incoming interrupt line on the remote processor.
   235         */
   236        config UInt remoteIntId;
   237        
   238        /*! The max index set to (numMsgs - 1) */
   239        config UInt maxIndex;
   240        
   241        /*!
   242         *  The modulo index value. Set to (numMsgs / 4).
   243         *  Used in the isr for doing cache_wb of readIndex.
   244         */
   245        config UInt modIndex;
   246        
   247        /*!
   248         *  enable IPC interrupt
   249         */
   250        Void intEnable();
   251        
   252        /*!
   253         *  disable IPC interrupt
   254         */
   255        Void intDisable();
   256        
   257        /*!
   258         *  trigger IPC interrupt
   259         */
   260        Void intSend();
   261        
   262        /*!
   263         *  clear IPC interrupt
   264         */
   265        UInt intClear();
   266        
   267        /*! 
   268         *  executes the callback functions according to event priority
   269         */
   270        Void isr(UArg arg);
   271    
   272        /*! 
   273         *  Structure for each event. This struct is placed in shared memory.
   274         */
   275        struct EventEntry {
   276            volatile Bits32 eventid;
   277            volatile Bits32 payload;
   278        }
   279    
   280        /*! Instance state structure */
   281        struct Instance_State {
   282            EventEntry       *putBuffer;     /* buffer used to put events        */
   283            Bits32           *putReadIndex;  /* ptr to readIndex for put buffer  */
   284            Bits32           *putWriteIndex; /* ptr to writeIndex for put buffer */
   285            EventEntry       *getBuffer;     /* buffer used to get events        */
   286            Bits32           *getReadIndex;  /* ptr to readIndex for get buffer  */
   287            Bits32           *getWriteIndex; /* ptr to writeIndex for put buffer */
   288            Bits32           evtRegMask;     /* local event register mask        */
   289            Notify.Handle    notifyHandle;   /* Handle to front-end object       */
   290            UInt16           remoteProcId;   /* Remote MultiProc id              */
   291        }
   292    }