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 import xdc.rov.ViewInfo;
38
39 import xdc.runtime.Error;
40
41 /*!
42 * ======== DEV ========
43 * Device Manager.
44 *
45 * The DEV Device Manager manages the table of IOM drivers. Drivers can
46 * be added or removed from the system using DEV_create() and DEV_delete().
47 *
48 * DEV_create() calls mdBindDev() for the underlying IOM driver. If
49 * successful, the driver gets added to the driver table. GIO_create()
50 * looks in this table for matching device name when opening an I/O
51 * channel.
52 *
53 * DEV_delete() calls mdUnBindDev() for the underlying IOM driver and
54 * removes the entry from the driver table.
55 */
56
57 @DirectCall
58 @InstanceFinalize
59 @InstanceInitError
60 @ModuleStartup
61
62 module DEV
63 {
64 /*! Init function type definition. */
65 typedef Void (*InitFxn)();
66
67 /*!
68 * ======== Fxns ========
69 * @_nodoc
70 * This function table mirrors the IOM_Fxns table. Fxns * is used in the
71 * instance object instead of Ptr to support static configuration.
72 */
73 struct Fxns {
74 Fxn mdBindDev;
75 Fxn mdUnBindDev;
76 Fxn mdControlChan;
77 Fxn mdCreateChan;
78 Fxn mdDeleteChan;
79 Fxn mdSubmitChan;
80 };
81
82 /*!
83 * ======== DeviceParams ========
84 * @_nodoc
85 * Dummy DeviceParams structure. This is used in the instance object
86 * instead of Ptr to support static configuration.
87 */
88 struct DeviceParams {
89 Int dummy;
90 };
91
92 /*!
93 * Size of the device table.
94 *
95 * This size needs to be large enough to hold the sum of the drivers
96 * created at configuration time and runtime.
97 */
98 config UInt tableSize = 8;
99
100 metaonly struct BasicView {
101 String name;
102 Ptr fxns;
103 String initFxn[];
104 Int devid;
105 Ptr deviceParams;
106 Ptr devp;
107 };
108
109 @Facet
110 metaonly config ViewInfo.Instance rovViewInfo =
111 ViewInfo.create({
112 viewMap: [
113 ['Basic', {type: ViewInfo.INSTANCE, viewInitFxn: 'viewInitBasic', structName: 'BasicView'}],
114 ]
115 });
116
117 /*!
118 * ======== match ========
119 * DEV_match searches the device table for the first device name that
120 * matches a prefix of 'name'. The output parameter, device, points to
121 * the appropriate entry in the device table if successful and is set to
122 * NULL on error.
123 *
124 * The suffix string return value contains a pointer to the characters
125 * remaining after the match. This string can be used to specify device
126 * parameters or the name of another device driver.
127 *
128 * For example, if you have "/uart" in the device table, then the
129 * suffix return value for the following would return a pointer to "0".
130 *
131 * @p(code)
132 * suffix = DEV_match("/uart0", &device);
133 * @p
134 *
135 * @param(name) name of device
136 * @param(device) pointer to DEV Handle (output param)
137 * @b(returns) pointer to remaining characters after match
138 */
139 String match(String name, Handle *device);
140
141 instance:
142
143 /*!
144 * ======== create ========
145 * Add an IOM driver to the device table at runtime.
146 *
147 * The 'name' parameter must be a static string since this name
148 * is referenced via a pointer and is not copied. For example:
149 *
150 * @p(code)
151 * Error_init(&eb);
152 * DEV_create("/a2d", &A2DFXNS, &myparams, &eb);
153 * @p
154 *
155 * The following code will not work since 'localstring' is a local
156 * variable:
157 *
158 * @p(code)
159 * {
160 * Char localstring[10];
161 * strcpy(localstring, "/a2d");
162 * Error_init(&eb);
163 * DEV_create(localstring, &A2DFXNS, &myparams, &eb);
164 * }
165 * @p
166 *
167 * @param(name) name of device (must be a static string)
168 * @param(fxns) pointer to IOM_Fxns table
169 */
170 create(String name, Ptr fxns);
171
172 /*!
173 * ======== getName ========
174 * Get name of device
175 *
176 * DEV_getName returns the name of the referenced device.
177 *
178 * @b(returns) device name
179 */
180 String getName();
181
182 /*!
183 * ======== getFxns ========
184 * Get IOM function table of device
185 *
186 * DEV_getFxns returns the IOM function table of the referenced device.
187 *
188 * @b(returns) pointer to device function table
189 */
190 Ptr getFxns();
191
192 /*!
193 * ======== getInitFxn ========
194 * Get initialized function of device
195 *
196 * DEV_getInitFxn returns the init function of the referenced device.
197 *
198 * @b(returns) init function pointer
199 */
200 InitFxn getInitFxn();
201
202 /*!
203 * ======== getDevid ========
204 * Get devid of device
205 *
206 * DEV_getDevid returns the devid of the referenced device.
207 *
208 * @b(returns) devid
209 */
210 Int getDevid();
211
212 /*!
213 * ======== getDeviceParams ========
214 * Get deviceParams of device
215 *
216 * DEV_getDeviceParams returns the deviceParams of the referenced device.
217 *
218 * @b(returns) deviceParams
219 */
220 Ptr getDeviceParams();
221
222 /*!
223 * ======== getDevp ========
224 * Get devp of device
225 *
226 * DEV_getDevp returns the devp of the referenced device.
227 *
228 * @b(returns) devp
229 */
230 Ptr getDevp();
231
232 /*!
233 * ======== deviceParams ========
234 * Device-specific parameters
235 *
236 * This parameter is passed as the last parameter to the underlying
237 * IOM driver's mdBindDevice function.
238 */
239 config Ptr deviceParams = null;
240
241 /*!
242 * ======== initFxn ========
243 * Driver Initialization function
244 *
245 * This function is called once for every entry in the device table.
246 * If this parameter is set to NULL (the default), then no function
247 * will be called.
248 */
249 config InitFxn initFxn = null;
250
251 /*!
252 * ======== devid ========
253 * Device id
254 */
255 config Int devid = 0;
256
257 internal:
258
259 Int postInit(Object *obj, Error.Block *eb);
260
261 struct Instance_State {
262 String name;
263 Fxns *fxns;
264 InitFxn initFxn;
265 Int devid;
266 DeviceParams *deviceParams;
267 Ptr devp;
268 };
269
270 struct Module_State {
271 Handle table[];
272 };
273 }