1    /* 
     2     * Copyright (c) 2011, 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     *  ======== Generator.xdc ========
    34     *
    35     *
    36     */
    37    
    38    import xdc.rov.ViewInfo;
    39    
    40    import xdc.runtime.IHeap;
    41    import xdc.runtime.Error;
    42    import ti.sdo.io.DriverTypes;
    43    import ti.sdo.utils.List;
    44    
    45    /*! 
    46     *  Generator module
    47     *
    48     *  Using this module clients can simulate a device with an input channel and
    49     *  an output channel.
    50     *  Generator channels are used to generate sequences of constants, sine waves, 
    51     *  random noise, or other streams of data defined by a user function.
    52     *
    53     *  When a channel is opened, the user gets to specify a function to simulate
    54     *  the input channel and a function to simulate the output channel 
    55     *  characteristics.
    56     *
    57     *  The Generator module can be configured to process the io just like
    58     *  a real driver, where a {@link #submit} call will return pending and
    59     *  io will be completed in the context of an isr. This mode is called
    60     *  returnPending.
    61     *  However the user has to call {@link #simulateIsrFxn} in an isr, Swi or a 
    62     *  Task to support this mode.  In simulateIsr, one pending IO Packet for both 
    63     *  channel for all Generator instances is processed.
    64     */
    65    module Generator inherits ti.sdo.io.IDriver {  
    66    
    67        /*! typedef for user specified I/O generators
    68         *
    69         *  Functions of this type get passed the buffer, buffer size and a 
    70         *  function specific argument
    71         */
    72        typedef Void (*GenFunc)(Ptr, SizeT, UArg);
    73    
    74        /*! Number of channels per generator device. 
    75         *  
    76         *  one input and one output channel
    77         */
    78        const Int NUMCHANS = 2;
    79    
    80        /*! Channel parameters used along with open  */
    81        struct ChanParams {
    82            GenFunc userFxn;        /* user defined function           */
    83            UArg    userArg;        /* argument for user defined function     */
    84            Bool    returnPending;  /* TRUE to simulate driver which postpones 
    85                                       io processing */
    86        };
    87        
    88        metaonly struct BasicView {
    89            String label;
    90        };
    91        
    92        metaonly struct GeneratorView {
    93            String                  mode;
    94            Bool                    inUse;
    95            Bool                    returnPending;
    96            String                  callbackFxn[];
    97            UArg                    callbackArg;
    98            String                  userFxn[];
    99            UArg                    userArg;
   100        }
   101        
   102        @Facet
   103        metaonly config ViewInfo.Instance rovViewInfo = 
   104            ViewInfo.create({
   105                viewMap: [
   106                    ['Basic', {type: ViewInfo.INSTANCE,      viewInitFxn: 'viewInitBasic', structName: 'BasicView'}],
   107                    ['Data',  {type: ViewInfo.INSTANCE_DATA, viewInitFxn: 'viewInitData',  structName: 'GeneratorView'}],                   
   108                ]
   109            });
   110    
   111    
   112        /*!
   113         *  Error raised when NULL chanParams is specified.
   114         */
   115        config Error.Id E_nullParams  = {
   116            msg: "E_nullParams: chanParams is null."
   117        };
   118        
   119        /*!
   120         *  This function is used to give energy to the Generator 
   121         *  driver to process its IO packets.  It simulates real ISR.
   122         *
   123         *  The application needs to call this function within a hwi, swi or
   124         *  task thread if any channels are opened in {@link #returnPending}
   125         *  mode.
   126         *
   127         *  The Generator module will process all channels with returnPending set 
   128         *  to true within this function. One packet per channel for all
   129         *  generator instances gets processed during a single call to this 
   130         *  function.
   131         */
   132        Void simulateIsr(UArg arg);
   133    
   134    internal:
   135    
   136        struct ChanObj {
   137            List.Elem               elem;
   138            Bool                    inUse;         /* is channel is use? */
   139            Bool                    returnPending; /* pending mode */ 
   140            List.Handle             pendList;     /* queue io packets */
   141            DriverTypes.DoneFxn     cbFxn;        /* callback fxn */
   142            UArg                    cbArg;        /* callback arg */
   143            GenFunc                 userFxn;      /* user gen fxn */
   144            UArg                    userArg;      /* user gen arg */
   145        };
   146    
   147        struct Instance_State{
   148            ChanObj chans[NUMCHANS];/* two chans per device */
   149        };
   150        
   151        struct Module_State {
   152            List.Object chanList;
   153        }
   154    }
   155    /*
   156     *  @(#) ti.sdo.io.drivers; 1, 0, 0, 0,480; 6-18-2011 17:32:19; /db/vtree/library/trees/ipc/ipc.git/src/ ipc-g26
   157     */
   158