1    /* --COPYRIGHT--,TI
     2     * Copyright (c) $(CPYYEAR)
     3     * Texas Instruments
     4     *
     5     *  All rights reserved.  Property of Texas Instruments
     6     *  Restricted rights to use, duplicate or disclose this code are
     7     *  granted through contract.
     8     * 
     9     * --/COPYRIGHT--*/
    10    /*
    11     *  ======== Generator.xdc ========
    12     *
    13     *! Revision History
    14     *! ================
    15     *! 19-Oct-2005 czhao    created
    16     *
    17     */
    18    
    19    import xdc.rov.ViewInfo;
    20    
    21    import xdc.runtime.IHeap;
    22    import xdc.runtime.Error;
    23    import ti.sdo.io.DriverTypes;
    24    import ti.sdo.utils.List;
    25    
    26    /*! 
    27     *  Generator module
    28     *
    29     *  Using this module clients can simulate a device with an input channel and
    30     *  an output channel.
    31     *  Generator channels are used to generate sequences of constants, sine waves, 
    32     *  random noise, or other streams of data defined by a user function.
    33     *
    34     *  When a channel is opened, the user gets to specify a function to simulate
    35     *  the input channel and a function to simulate the output channel 
    36     *  characteristics.
    37     *
    38     *  The Generator module can be configured to process the io just like
    39     *  a real driver, where a {@link #submit} call will return pending and
    40     *  io will be completed in the context of an isr. This mode is called
    41     *  returnPending.
    42     *  However the user has to call {@link #simulateIsrFxn} in an isr, Swi or a 
    43     *  Task to support this mode.  In simulateIsr, one pending IO Packet for both 
    44     *  channel for all Generator instances is processed.
    45     */
    46    module Generator inherits ti.sdo.io.IDriver {  
    47    
    48        /*! typedef for user specified I/O generators
    49         *
    50         *  Functions of this type get passed the buffer, buffer size and a 
    51         *  function specific argument
    52         */
    53        typedef Void (*GenFunc)(Ptr, SizeT, UArg);
    54    
    55        /*! Number of channels per generator device. 
    56         *  
    57         *  one input and one output channel
    58         */
    59        const Int NUMCHANS = 2;
    60    
    61        /*! Channel parameters used along with open  */
    62        struct ChanParams {
    63            GenFunc userFxn;        /* user defined function           */
    64            UArg    userArg;        /* argument for user defined function     */
    65            Bool    returnPending;  /* TRUE to simulate driver which postpones 
    66                                       io processing */
    67        };
    68        
    69        metaonly struct BasicView {
    70            String label;
    71        };
    72        
    73        metaonly struct GeneratorView {
    74            String                  mode;
    75            Bool                    inUse;
    76            Bool                    returnPending;
    77            String                  callbackFxn[];
    78            UArg                    callbackArg;
    79            String                  userFxn[];
    80            UArg                    userArg;
    81        }
    82        
    83        @Facet
    84        metaonly config ViewInfo.Instance rovViewInfo = 
    85            ViewInfo.create({
    86                viewMap: [
    87                    ['Basic', {type: ViewInfo.INSTANCE,      viewInitFxn: 'viewInitBasic', structName: 'BasicView'}],
    88                    ['Data',  {type: ViewInfo.INSTANCE_DATA, viewInitFxn: 'viewInitData',  structName: 'GeneratorView'}],                   
    89                ]
    90            });
    91        
    92        /*!
    93         *  This function is used to give energy to the Generator 
    94         *  driver to process its IO packets.  It simulates real ISR.
    95         *
    96         *  The application needs to call this function within a hwi, swi or
    97         *  task thread if any channels are opened in {@link #returnPending}
    98         *  mode.
    99         *
   100         *  The Generator module will process all channels with returnPending set 
   101         *  to true within this function. One packet per channel for all
   102         *  generator instances gets processed during a single call to this 
   103         *  function.
   104         */
   105        Void simulateIsr(UArg arg);
   106    
   107    internal:
   108    
   109        struct ChanObj {
   110            List.Elem               elem;
   111            Bool                    inUse;         /* is channel is use? */
   112            Bool                    returnPending; /* pending mode */ 
   113            List.Handle             pendList;     /* queue io packets */
   114            DriverTypes.DoneFxn     cbFxn;        /* callback fxn */
   115            UArg                    cbArg;        /* callback arg */
   116            GenFunc                 userFxn;      /* user gen fxn */
   117            UArg                    userArg;      /* user gen arg */
   118        };
   119    
   120        struct Instance_State{
   121            ChanObj chans[NUMCHANS];/* two chans per device */
   122        };
   123        
   124        struct Module_State {
   125            List.Object chanList;
   126        }
   127    }