OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems/] [c/] [src/] [exec/] [sapi/] [src/] [io.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 158 chris
/*
2
 *  Input/Output Manager
3
 *
4
 *
5
 *  COPYRIGHT (c) 1989-1999.
6
 *  On-Line Applications Research Corporation (OAR).
7
 *
8
 *  The license and distribution terms for this file may be
9
 *  found in the file LICENSE in this distribution or at
10
 *  http://www.OARcorp.com/rtems/license.html.
11
 *
12 208 chris
 *  $Id: io.c,v 1.2 2001-09-27 11:59:20 chris Exp $
13 158 chris
 */
14
 
15
#include <rtems/system.h>
16
#include <rtems/io.h>
17
#include <rtems/score/isr.h>
18
#include <rtems/score/thread.h>
19
#include <rtems/score/wkspace.h>
20
 
21
#include <string.h>
22
 
23
/*PAGE
24
 *
25
 *  _IO_Manager_initialization
26
 *
27
 */
28
 
29
void _IO_Manager_initialization(
30
  rtems_driver_address_table *driver_table,
31
  unsigned32                  number_of_drivers,
32
  unsigned32                  number_of_devices
33
)
34
{
35
  void                *tmp;
36
  unsigned32           index;
37
  rtems_driver_name_t *np;
38
 
39
  _IO_Driver_address_table = driver_table;
40
  _IO_Number_of_drivers    = number_of_drivers;
41
  _IO_Number_of_devices    = number_of_devices;
42
 
43
  tmp = _Workspace_Allocate_or_fatal_error(
44
    sizeof( rtems_driver_name_t ) * ( number_of_devices + 1 )
45
  );
46
 
47
  _IO_Driver_name_table = (rtems_driver_name_t *) tmp;
48
 
49
  for( index=0, np = _IO_Driver_name_table ;
50
       index < _IO_Number_of_devices ;
51
       index++, np++ ) {
52
    np->device_name = 0;
53
    np->device_name_length = 0;
54
    np->major = 0;
55
    np->minor = 0;
56
  }
57
}
58
 
59
/*PAGE
60
 *
61
 *  _IO_Initialize_all_drivers
62
 *
63
 *  This routine initializes all device drivers
64
 *
65
 *  Input Paramters:   NONE
66
 *
67
 *  Output Parameters: NONE
68
 */
69
 
70
void _IO_Initialize_all_drivers( void )
71
{
72
   rtems_device_major_number major;
73
 
74
   for ( major=0 ; major < _IO_Number_of_drivers ; major ++ )
75
     (void) rtems_io_initialize( major, 0, NULL);
76
}
77
 
78
/*PAGE
79
 *
80
 *  rtems_io_register_name
81
 *
82
 *  Associate a name with a driver
83
 *
84
 *  Input Paramters:
85
 *    device_name - pointer to name string to associate with device
86
 *    major       - device major number to receive name
87
 *    minor       - device minor number to receive name
88
 *
89
 *  Output Parameters:
90
 *    RTEMS_SUCCESSFUL - if successful
91
 *    error code       - if unsuccessful
92
 */
93
 
94
#if 0
95
rtems_status_code rtems_io_register_name(
96
    char *device_name,
97
    rtems_device_major_number major,
98
    rtems_device_minor_number minor
99
  )
100
{
101
    rtems_driver_name_t *np;
102
    unsigned32 level;
103
    unsigned32 index;
104
 
105
    /* find an empty slot */
106
    for( index=0, np = _IO_Driver_name_table ;
107
         index < _IO_Number_of_devices ;
108
         index++, np++ )
109
    {
110
 
111
        _ISR_Disable(level);
112
        if (np->device_name == 0)
113
        {
114
            np->device_name = device_name;
115
            np->device_name_length = strlen(device_name);
116
            np->major = major;
117
            np->minor = minor;
118
            _ISR_Enable(level);
119
 
120
            return RTEMS_SUCCESSFUL;
121
        }
122
        _ISR_Enable(level);
123
    }
124
 
125
    return RTEMS_TOO_MANY;
126
}
127
#endif
128
 
129
/*PAGE
130
 *
131
 *  rtems_io_lookup_name
132
 *
133
 *  Find what driver "owns" this name
134
 *
135
 *  Input Paramters:
136
 *    name - name to lookup the associated device
137
 *
138
 *  Output Parameters:
139
 *    device_info      - device associate with name
140
 *    RTEMS_SUCCESSFUL - if successful
141
 *    error code       - if unsuccessful
142
 */
143
 
144
#if 0
145
rtems_status_code rtems_io_lookup_name(
146
    const char           *name,
147
    rtems_driver_name_t **device_info
148
)
149
{
150
    rtems_driver_name_t *np;
151
    unsigned32 index;
152
 
153
    for( index=0, np = _IO_Driver_name_table ;
154
         index < _IO_Number_of_devices ;
155
         index++, np++ )
156
        if (np->device_name)
157
            if (strncmp(np->device_name, name, np->device_name_length) == 0)
158
            {
159
                *device_info = np;
160
                return RTEMS_SUCCESSFUL;
161
            }
162
 
163
    *device_info = 0;
164
    return RTEMS_UNSATISFIED;
165
}
166
#endif
167
 
168
 
169
/*PAGE
170
 *
171
 *  rtems_io_initialize
172
 *
173
 *  This routine is the initialization directive of the IO manager.
174
 *
175
 *  Input Paramters:
176
 *    major        - device driver number
177
 *    minor        - device number
178
 *    argument     - pointer to argument(s)
179
 *
180
 *  Output Parameters:
181
 *    returns       - return code
182
 */
183
 
184
rtems_status_code rtems_io_initialize(
185
  rtems_device_major_number  major,
186
  rtems_device_minor_number  minor,
187
  void             *argument
188
)
189
{
190
    rtems_device_driver_entry callout;
191
 
192
    if ( major >= _IO_Number_of_drivers )
193
        return RTEMS_INVALID_NUMBER;
194
 
195
    callout = _IO_Driver_address_table[major].initialization;
196
    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
197
}
198
 
199
/*PAGE
200
 *
201
 *  rtems_io_open
202
 *
203
 *  This routine is the open directive of the IO manager.
204
 *
205
 *  Input Paramters:
206
 *    major        - device driver number
207
 *    minor        - device number
208
 *    argument     - pointer to argument(s)
209
 *
210
 *  Output Parameters:
211
 *    returns       - return code
212
 */
213
 
214
rtems_status_code rtems_io_open(
215
  rtems_device_major_number  major,
216
  rtems_device_minor_number  minor,
217
  void                      *argument
218
)
219
{
220
    rtems_device_driver_entry callout;
221
 
222
    if ( major >= _IO_Number_of_drivers )
223
        return RTEMS_INVALID_NUMBER;
224
 
225
    callout = _IO_Driver_address_table[major].open;
226
    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
227
}
228
 
229
/*PAGE
230
 *
231
 *  rtems_io_close
232
 *
233
 *  This routine is the close directive of the IO manager.
234
 *
235
 *  Input Paramters:
236
 *    major        - device driver number
237
 *    minor        - device number
238
 *    argument     - pointer to argument(s)
239
 *
240
 *  Output Parameters:
241
 *    returns       - return code
242
 */
243
 
244
rtems_status_code rtems_io_close(
245
  rtems_device_major_number  major,
246
  rtems_device_minor_number  minor,
247
  void                      *argument
248
)
249
{
250
    rtems_device_driver_entry callout;
251
 
252
    if ( major >= _IO_Number_of_drivers )
253
        return RTEMS_INVALID_NUMBER;
254
 
255
    callout = _IO_Driver_address_table[major].close;
256
    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
257
}
258
 
259
/*PAGE
260
 *
261
 *  rtems_io_read
262
 *
263
 *  This routine is the read directive of the IO manager.
264
 *
265
 *  Input Paramters:
266
 *    major        - device driver number
267
 *    minor        - device number
268
 *    argument     - pointer to argument(s)
269
 *
270
 *  Output Parameters:
271
 *    returns       - return code
272
 */
273
 
274
rtems_status_code rtems_io_read(
275
  rtems_device_major_number  major,
276
  rtems_device_minor_number  minor,
277
  void                      *argument
278
)
279
{
280
    rtems_device_driver_entry callout;
281
 
282
    if ( major >= _IO_Number_of_drivers )
283
        return RTEMS_INVALID_NUMBER;
284
 
285
    callout = _IO_Driver_address_table[major].read;
286
    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
287
}
288
 
289
/*PAGE
290
 *
291
 *  rtems_io_write
292
 *
293
 *  This routine is the write directive of the IO manager.
294
 *
295
 *  Input Paramters:
296
 *    major        - device driver number
297
 *    minor        - device number
298
 *    argument     - pointer to argument(s)
299
 *
300
 *  Output Parameters:
301
 *    returns       - return code
302
 */
303
 
304
rtems_status_code rtems_io_write(
305
  rtems_device_major_number  major,
306
  rtems_device_minor_number  minor,
307
  void                      *argument
308
)
309
{
310
    rtems_device_driver_entry callout;
311
 
312
    if ( major >= _IO_Number_of_drivers )
313
        return RTEMS_INVALID_NUMBER;
314
 
315
    callout = _IO_Driver_address_table[major].write;
316
    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
317
}
318
 
319
/*PAGE
320
 *
321
 *  rtems_io_control
322
 *
323
 *  This routine is the control directive of the IO manager.
324
 *
325
 *  Input Paramters:
326
 *    major        - device driver number
327
 *    minor        - device number
328
 *    argument     - pointer to argument(s)
329
 *
330
 *  Output Parameters:
331
 *    returns       - return code
332
 */
333
 
334
rtems_status_code rtems_io_control(
335
  rtems_device_major_number  major,
336
  rtems_device_minor_number  minor,
337
  void                      *argument
338
)
339
{
340
    rtems_device_driver_entry callout;
341
 
342
    if ( major >= _IO_Number_of_drivers )
343
        return RTEMS_INVALID_NUMBER;
344
 
345
    callout = _IO_Driver_address_table[major].control;
346
    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
347
}
348
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.