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     *  ======== DriverTable.xdc ========
    34     *
    35     *! Revision History
    36     *! ================
    37     *! 28-Apr-2008 nitya   review update
    38     *
    39     */
    40    
    41    import xdc.runtime.Error;
    42    import xdc.runtime.Assert;
    43    import xdc.runtime.IGateProvider;
    44    import ti.sdo.utils.NameServer;
    45    
    46    /*! 
    47     *  DriverTable module
    48     *
    49     *  This module maintains a table of {@link IDriver#Handle}. Other modules can
    50     *  lookup these handles by name and open channels for IO. The {@link Stream}
    51     *  module will open channels using this table. All names in this table have to
    52     *  be unique.
    53     *
    54     *  This module allows addition of IDriver handles into the table at 
    55     *  configuration time as well as at runtime. However, the total number of 
    56     *  runtime entries have to be decided at configuration time. There is no limit
    57     *  to entries added statically.
    58     *
    59     *  This module uses {@link ti.sdo.utils.NameServer} to maintain its table
    60     */
    61     
    62    module DriverTable {
    63        /*! 
    64         *  Max runtime entries that can be added.
    65         *
    66         *  Currently this module requires total number of entries that need
    67         *  to be added at runtime to be identified at configuration time.
    68         */
    69        config UInt maxRuntimeEntries = 0;
    70        
    71        /*! 
    72         *  Gate used to make the table thread safe.
    73         */
    74        config IGateProvider.Handle gate = null;
    75        
    76        /*! 
    77         *  Length, in MAUs, of the name field in the table.
    78         */
    79        config UInt maxNameLen = 16;
    80    
    81        /*! 
    82         *  Section name is used to place the IDriver table.
    83         */
    84        metaonly config String tableSection = null;
    85            
    86        /*!
    87         *  ======== add ========
    88         *  Add IDriver handle to the table at runtime.
    89         *
    90         *  Will raise an error when name already exists in table.
    91         *  This API is not thread safe. Set {@link #gate} parameter
    92         *  to protect table if called from multiple threads.
    93         *
    94         *  @param(name)            name of entry
    95         *  @param(driverHandle)    {@link IDriver#Handle}
    96         *  @param(eb)              Error Block
    97         */
    98        Void add(String name, IDriver.Handle driverHandle, Error.Block *eb);
    99    
   100        /*!
   101         *  ======== addMeta ========
   102         *  Add to IDriver handle to the table at configuration time.
   103         *
   104         *  @param(name)            name of entry
   105         *  @param(driverHandle)    {@link IDriver#Handle}
   106         */
   107        metaonly Void addMeta(String name, IDriver.Handle driverHandle);
   108    
   109        /*!
   110         *  ======== remove ========
   111         *  Remove entry from IDriver table at runtime.
   112         *
   113         *  Will raise an error when name not found in table
   114         *  This API is not thread safe. Set {@link #gate} parameter
   115         *  to protect table if called from multiple threads.
   116         *
   117         *  @param(name)    name of entry
   118         *  @param(eb)      error block
   119         */
   120        Void remove(String name, Error.Block *eb);
   121    
   122        /*!
   123         *  ======== match ========
   124         *  @_nodoc
   125         *  match entry in IDriver table.
   126         *
   127         *  This function matches the name with table entries and writes to
   128         *  the handle if it finds a match. If entry is not found it sets
   129         *  handle to null. It returns length matched.
   130         *  This API is not thread safe. Set {@link #gate} parameter
   131         *  to protect table if called from multiple threads.
   132         *
   133         *  @param(name)    name of entry
   134         *  @param(handle)  pointer to IDriver handle.
   135         *  @param(eb)      error block
   136         *  @b(returns)     length matched
   137         */
   138        Int match(String name, IDriver.Handle *handle, Error.Block *eb);
   139    
   140    internal:
   141    
   142        /*!
   143         * Structure of entry in metaonly table
   144         */
   145        struct Entry {
   146            String  name;
   147            Ptr     handle;
   148        };
   149    
   150        /*! 
   151         *  Array for all statically configured table entries 
   152         */
   153        metaonly config Entry staticEntries[];
   154            
   155        struct Module_State {
   156            NameServer.Handle   drvTable;
   157        };
   158    }