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