source: rtems/cpukit/sapi/src/io.c @ 8bdcfc4

4.104.114.84.95
Last change on this file since 8bdcfc4 was c4808ca, checked in by Joel Sherrill <joel.sherrill@…>, on 10/31/95 at 21:28:16

typos fixed

  • Property mode set to 100644
File size: 7.0 KB
Line 
1/*
2 *  Input/Output Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
6 *  On-Line Applications Research Corporation (OAR).
7 *  All rights assigned to U.S. Government, 1994.
8 *
9 *  This material may be reproduced by or for the U.S. Government pursuant
10 *  to the copyright license under the clause at DFARS 252.227-7013.  This
11 *  notice must appear in all copies of this file and its derivatives.
12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
17#include <rtems/io.h>
18#include <rtems/score/isr.h>
19#include <rtems/score/thread.h>
20
21#include <string.h>
22
23/*PAGE
24 *
25 *  _IO_Initialize_all_drivers
26 *
27 *  This routine initializes all device drivers
28 *
29 *  Input Paramters:   NONE
30 *
31 *  Output Parameters: NONE
32 */
33
34void _IO_Initialize_all_drivers( void )
35{
36   rtems_device_major_number major;
37
38   for ( major=0 ; major < _IO_Number_of_drivers ; major ++ )
39     (void) rtems_io_initialize( major, 0, NULL);
40}
41
42/*PAGE
43 *
44 *  rtems_io_register_name
45 *
46 *  Associate a name with a driver
47 *
48 *  Input Paramters:
49 *    device_name - pointer to name string to associate with device
50 *    major       - device major number to receive name
51 *    minor       - device minor number to receive name
52 *
53 *  Output Parameters:
54 *    RTEMS_SUCCESSFUL - if successful
55 *    error code       - if unsuccessful
56 */
57
58rtems_status_code rtems_io_register_name(
59    char *device_name,
60    rtems_device_major_number major,
61    rtems_device_minor_number minor
62  )
63{
64    rtems_driver_name_t *np;
65    unsigned32 level;
66    unsigned32 index;
67
68    /* find an empty slot */
69    for( index=0, np = _IO_Driver_name_table ;
70         index < _IO_Number_of_devices ;
71         index++, np++ )
72    {
73
74        _ISR_Disable(level);
75        if (np->device_name == 0)
76        {
77            np->device_name = device_name;
78            np->device_name_length = strlen(device_name);
79            np->major = major;
80            np->minor = minor;
81            _ISR_Enable(level);
82
83            return RTEMS_SUCCESSFUL;
84        }
85        _ISR_Enable(level);
86    }
87
88    return RTEMS_TOO_MANY;
89}
90
91/*PAGE
92 *
93 *  rtems_io_lookup_name
94 *
95 *  Find what driver "owns" this name
96 *
97 *  Input Paramters:
98 *    name - name to lookup the associated device
99 *
100 *  Output Parameters:
101 *    device_info      - device associate with name
102 *    RTEMS_SUCCESSFUL - if successful
103 *    error code       - if unsuccessful
104 */
105
106rtems_status_code rtems_io_lookup_name(
107    const char           *name,
108    rtems_driver_name_t **device_info
109)
110{
111    rtems_driver_name_t *np;
112    unsigned32 index;
113
114    for( index=0, np = _IO_Driver_name_table ;
115         index < _IO_Number_of_devices ;
116         index++, np++ )
117        if (np->device_name)
118            if (strncmp(np->device_name, name, np->device_name_length) == 0)
119            {               
120                *device_info = np;
121                return RTEMS_SUCCESSFUL;
122            }
123   
124    *device_info = 0;
125    return RTEMS_UNSATISFIED;
126}
127
128
129/*PAGE
130 *
131 *  rtems_io_initialize
132 *
133 *  This routine is the initialization directive of the IO manager.
134 *
135 *  Input Paramters:
136 *    major        - device driver number
137 *    minor        - device number
138 *    argument     - pointer to argument(s)
139 *
140 *  Output Parameters:
141 *    returns       - return code
142 */
143
144rtems_status_code rtems_io_initialize(
145  rtems_device_major_number  major,
146  rtems_device_minor_number  minor,
147  void             *argument
148)
149{
150    rtems_device_driver_entry callout;
151   
152    if ( major >= _IO_Number_of_drivers )
153        return RTEMS_INVALID_NUMBER;
154
155    callout = _IO_Driver_address_table[major].initialization;
156    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
157}
158
159/*PAGE
160 *
161 *  rtems_io_open
162 *
163 *  This routine is the open directive of the IO manager.
164 *
165 *  Input Paramters:
166 *    major        - device driver number
167 *    minor        - device number
168 *    argument     - pointer to argument(s)
169 *
170 *  Output Parameters:
171 *    returns       - return code
172 */
173
174rtems_status_code rtems_io_open(
175  rtems_device_major_number  major,
176  rtems_device_minor_number  minor,
177  void                      *argument
178)
179{
180    rtems_device_driver_entry callout;
181   
182    if ( major >= _IO_Number_of_drivers )
183        return RTEMS_INVALID_NUMBER;
184
185    callout = _IO_Driver_address_table[major].open;
186    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
187}
188
189/*PAGE
190 *
191 *  rtems_io_close
192 *
193 *  This routine is the close directive of the IO manager.
194 *
195 *  Input Paramters:
196 *    major        - device driver number
197 *    minor        - device number
198 *    argument     - pointer to argument(s)
199 *
200 *  Output Parameters:
201 *    returns       - return code
202 */
203
204rtems_status_code rtems_io_close(
205  rtems_device_major_number  major,
206  rtems_device_minor_number  minor,
207  void                      *argument
208)
209{
210    rtems_device_driver_entry callout;
211   
212    if ( major >= _IO_Number_of_drivers )
213        return RTEMS_INVALID_NUMBER;
214
215    callout = _IO_Driver_address_table[major].close;
216    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
217}
218
219/*PAGE
220 *
221 *  rtems_io_read
222 *
223 *  This routine is the read directive of the IO manager.
224 *
225 *  Input Paramters:
226 *    major        - device driver number
227 *    minor        - device number
228 *    argument     - pointer to argument(s)
229 *
230 *  Output Parameters:
231 *    returns       - return code
232 */
233
234rtems_status_code rtems_io_read(
235  rtems_device_major_number  major,
236  rtems_device_minor_number  minor,
237  void                      *argument
238)
239{
240    rtems_device_driver_entry callout;
241   
242    if ( major >= _IO_Number_of_drivers )
243        return RTEMS_INVALID_NUMBER;
244
245    callout = _IO_Driver_address_table[major].read;
246    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
247}
248
249/*PAGE
250 *
251 *  rtems_io_write
252 *
253 *  This routine is the write directive of the IO manager.
254 *
255 *  Input Paramters:
256 *    major        - device driver number
257 *    minor        - device number
258 *    argument     - pointer to argument(s)
259 *
260 *  Output Parameters:
261 *    returns       - return code
262 */
263
264rtems_status_code rtems_io_write(
265  rtems_device_major_number  major,
266  rtems_device_minor_number  minor,
267  void                      *argument
268)
269{
270    rtems_device_driver_entry callout;
271   
272    if ( major >= _IO_Number_of_drivers )
273        return RTEMS_INVALID_NUMBER;
274
275    callout = _IO_Driver_address_table[major].write;
276    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
277}
278
279/*PAGE
280 *
281 *  rtems_io_control
282 *
283 *  This routine is the control directive of the IO manager.
284 *
285 *  Input Paramters:
286 *    major        - device driver number
287 *    minor        - device number
288 *    argument     - pointer to argument(s)
289 *
290 *  Output Parameters:
291 *    returns       - return code
292 */
293
294rtems_status_code rtems_io_control(
295  rtems_device_major_number  major,
296  rtems_device_minor_number  minor,
297  void                      *argument
298)
299{
300    rtems_device_driver_entry callout;
301   
302    if ( major >= _IO_Number_of_drivers )
303        return RTEMS_INVALID_NUMBER;
304
305    callout = _IO_Driver_address_table[major].control;
306    return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL;
307}
308
Note: See TracBrowser for help on using the repository browser.