1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
32 33 34 35 36 37 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 }