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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
//==========================================================================
//
// io/iosys.c
//
// I/O Subsystem + Device Table support
//
//==========================================================================
// ####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later
// version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License
// along with eCos; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// As a special exception, if other files instantiate templates or use
// macros or inline functions from this file, or you compile this file
// and link it with other works to produce a work based on this file,
// this file does not by itself cause the resulting work to be covered by
// the GNU General Public License. However the source code for this file
// must still be made available in accordance with section (3) of the GNU
// General Public License v2.
//
// This exception does not invalidate any other reasons why a work based
// on this file might be covered by the GNU General Public License.
// -------------------------------------------
// ####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): gthomas
// Contributors: gthomas
// Date: 1999-02-04
// Purpose: Device I/O Support
// Description:
//
//####DESCRIPTIONEND####
//
//==========================================================================
#include <pkgconf/io.h>
#include <cyg/io/io.h>
#include <cyg/io/devtab.h>
#include <cyg/infra/diag.h>
//extern void cyg_io_init(void) CYGBLD_ATTRIB_CONSTRUCTOR
// CYG_INIT_PRIORITY(CYG_INIT_BEFORE(LIBC));
// Checks that two strings are "equivalent" device names
// 'n1' is a string from the user
// 'n2' is a name in a device table entry
// 'cyg_io_compare()' will return true IFF
// n1 == n2, for all characters
// n2 ends in '/' and matches n1 up to the terminating '/'
// 'ptr' will get a pointer to the residual string.
static bool
cyg_io_compare(const char *n1, const char *n2, const char **ptr)
{
while (*n1 && *n2) {
if (*n1++ != *n2++) {
return false;
}
}
if (*n1) {
// See if the devtab name is is a substring
if (*(n2-1) == '/') {
*ptr = n1;
return true;
}
}
if (*n1 || *n2) {
return false;
}
*ptr = n1;
return true;
}
//
// This function is called during system initialization. The purpose is
// to step through all devices linked into the system, calling their
// "init" entry points.
//
void
cyg_io_init(void)
{
static int _init = false;
cyg_devtab_entry_t *t;
if (_init) return;
for (t = &__DEVTAB__[0]; t != &__DEVTAB_END__; t++) {
#ifdef CYGDBG_IO_INIT
diag_printf("Init device '%s'\n", t->name);
#endif
if (t->init(t)) {
t->status |= CYG_DEVTAB_STATUS_AVAIL;
} else {
// What to do if device init fails?
// Device not [currently] available
t->status &= ~CYG_DEVTAB_STATUS_AVAIL;
}
}
_init = true;
}
//
// Look up the devtab entry for a named device and return its handle.
// If the device is found and it has a "lookup" function, call that
// function to allow the device/driver to perform any necessary
// initializations.
//
Cyg_ErrNo
cyg_io_lookup(const char *name, cyg_io_handle_t *handle)
{
union devtab_entry_handle_union {
cyg_devtab_entry_t *st;
cyg_io_handle_t h;
} stunion;
cyg_devtab_entry_t *t;
Cyg_ErrNo res;
const char *name_ptr;
for (t = &__DEVTAB__[0]; t != &__DEVTAB_END__; t++) {
if (cyg_io_compare(name, t->name, &name_ptr)) {
// FUTURE: Check 'avail'/'online' here
if (t->dep_name) {
res = cyg_io_lookup(t->dep_name, &stunion.h);
if (res != ENOERR) {
return res;
}
} else {
stunion.st = NULL;
}
if (t->lookup) {
// This indirection + the name pointer allows the lookup routine
// to return a different 'devtab' handle. This will provide for
// 'pluggable' devices, file names, etc.
res = (t->lookup)(&t, stunion.st, name_ptr);
if (res != ENOERR) {
return res;
}
}
*handle = (cyg_io_handle_t)t;
return ENOERR;
}
}
return -ENOENT; // Not found
}
//
// 'write' data to a device.
//
Cyg_ErrNo
cyg_io_write(cyg_io_handle_t handle, const void *buf, cyg_uint32 *len)
{
cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
// Validate request
if (!t->handlers->write) {
return -EDEVNOSUPP;
}
// Special check. If length is zero, this just verifies that the
// 'write' method exists for the given device.
if (NULL != len && 0 == *len) {
return ENOERR;
}
return t->handlers->write(handle, buf, len);
}
//
// 'read' data from a device.
//
Cyg_ErrNo
cyg_io_read(cyg_io_handle_t handle, void *buf, cyg_uint32 *len)
{
cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
// Validate request
if (!t->handlers->read) {
return -EDEVNOSUPP;
}
// Special check. If length is zero, this just verifies that the
// 'read' method exists for the given device.
if (NULL != len && 0 == *len) {
return ENOERR;
}
return t->handlers->read(handle, buf, len);
}
//
// 'write' blocks to a device. The len and the position are in terms
// of blocks, not bytes like the cyg_io_write.
//
Cyg_ErrNo
cyg_io_bwrite(cyg_io_handle_t handle, const void *buf, cyg_uint32 *len, cyg_uint32 pos)
{
cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
// Validate request
if (!t->handlers->bwrite) {
return -EDEVNOSUPP;
}
// Special check. If length is zero, this just verifies that the
// 'bwrite' method exists for the given device.
if (NULL != len && 0 == *len) {
return ENOERR;
}
return t->handlers->bwrite(handle, buf, len, pos);
}
//
// 'read' blocks from a device. The len and the position are in terms of
// blocks, not bytes like the cyg_io_read.
//
Cyg_ErrNo
cyg_io_bread(cyg_io_handle_t handle, void *buf, cyg_uint32 *len, cyg_uint32 pos)
{
cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
// Validate request
if (!t->handlers->bread) {
return -EDEVNOSUPP;
}
// Special check. If length is zero, this just verifies that the
// 'bread' method exists for the given device.
if (NULL != len && 0 == *len) {
return ENOERR;
}
return t->handlers->bread(handle, buf, len, pos);
}
//
// Check device for available input or space for output
//
cyg_bool
cyg_io_select(cyg_io_handle_t handle, cyg_uint32 which, CYG_ADDRWORD info)
{
cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
// Validate request
if (!t->handlers->select) {
return -EDEVNOSUPP;
}
return t->handlers->select( handle, which, info );
}
//
// Get the configuration of a device.
//
Cyg_ErrNo
cyg_io_get_config(cyg_io_handle_t handle, cyg_uint32 key, void *buf, cyg_uint32 *len)
{
cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
// Validate request
if (!t->handlers->get_config) {
return -EDEVNOSUPP;
}
// Special check. If length is zero, this just verifies that the
// 'get_config' method exists for the given device.
if (NULL != len && 0 == *len) {
return ENOERR;
}
return t->handlers->get_config(handle, key, buf, len);
}
//
// Change the configuration of a device.
//
Cyg_ErrNo
cyg_io_set_config(cyg_io_handle_t handle, cyg_uint32 key, const void *buf, cyg_uint32 *len)
{
cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
// Validate request
if (!t->handlers->set_config) {
return -EDEVNOSUPP;
}
// Special check. If length is zero, this just verifies that the
// 'set_config' method exists for the given device.
if (NULL != len && 0 == *len) {
return ENOERR;
}
return t->handlers->set_config(handle, key, buf, len);
}
/*---------------------------------------------------------------------------*/
// Default functions for devio tables
Cyg_ErrNo cyg_devio_cwrite(cyg_io_handle_t handle, const void *buf, cyg_uint32 *len)
{
return -EDEVNOSUPP;
}
Cyg_ErrNo cyg_devio_cread(cyg_io_handle_t handle, void *buf, cyg_uint32 *len)
{
return -EDEVNOSUPP;
}
Cyg_ErrNo cyg_devio_bwrite(cyg_io_handle_t handle, const void *buf,
cyg_uint32 *len, cyg_uint32 pos)
{
return -EDEVNOSUPP;
}
Cyg_ErrNo cyg_devio_bread(cyg_io_handle_t handle, void *buf,
cyg_uint32 *len, cyg_uint32 pos)
{
return -EDEVNOSUPP;
}
Cyg_ErrNo
cyg_devio_select(cyg_io_handle_t handle, cyg_uint32 which, CYG_ADDRWORD info)
{
CYG_UNUSED_PARAM(cyg_io_handle_t, handle);
CYG_UNUSED_PARAM(cyg_uint32, which);
CYG_UNUSED_PARAM(CYG_ADDRWORD, info);
return -EDEVNOSUPP;
}
Cyg_ErrNo
cyg_devio_get_config(cyg_io_handle_t handle, cyg_uint32 key,
void* buf, cyg_uint32* len)
{
CYG_UNUSED_PARAM(cyg_io_handle_t, handle);
CYG_UNUSED_PARAM(cyg_uint32, key);
CYG_UNUSED_PARAM(void*, buf);
CYG_UNUSED_PARAM(cyg_uint32*, len);
return -EDEVNOSUPP;
}
Cyg_ErrNo
cyg_devio_set_config(cyg_io_handle_t handle, cyg_uint32 key,
void* buf, cyg_uint32* len)
{
CYG_UNUSED_PARAM(cyg_io_handle_t, handle);
CYG_UNUSED_PARAM(cyg_uint32, key);
CYG_UNUSED_PARAM(void*, buf);
CYG_UNUSED_PARAM(cyg_uint32*, len);
return -EDEVNOSUPP;
}
/*---------------------------------------------------------------------------*/
/* End of io/iosys.c */
|