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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [lib/] [libbsp/] [shared/] [console.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  This file contains the generic console driver shell used
3
 *  by all console drivers using libchip.
4
 *
5
 *  This driver uses the termios pseudo driver.
6
 *
7
 *  COPYRIGHT (c) 1989-1997.
8
 *  On-Line Applications Research Corporation (OAR).
9
 *
10
 *  The license and distribution terms for this file may be
11
 *  found in the file LICENSE in this distribution or at
12
 *  http://www.OARcorp.com/rtems/license.html.
13
 *
14
 *  console.c,v 1.6 2001/10/12 21:04:47 joel Exp
15
 */
16
 
17
#include <bsp.h>
18
#include <rtems/libio.h>
19
#include <stdlib.h>
20
#include <assert.h>
21
#include <termios.h>
22
 
23
#include <libchip/serial.h>
24
 
25
/*
26
 *  Configuration Information
27
 */
28
 
29
extern console_data  Console_Port_Data[];
30
extern unsigned long  Console_Port_Count;
31
extern rtems_device_minor_number  Console_Port_Minor;
32
 
33
/*PAGE
34
 *
35
 *  console_open
36
 *
37
 *  open a port as a termios console.
38
 *
39
 */
40
 
41
rtems_device_driver console_open(
42
  rtems_device_major_number major,
43
  rtems_device_minor_number minor,
44
  void                    * arg
45
)
46
{
47
  rtems_status_code              status;
48
  rtems_libio_open_close_args_t *args = arg;
49
  rtems_libio_ioctl_args_t       IoctlArgs;
50
  struct termios                 Termios;
51
  rtems_termios_callbacks        Callbacks;
52
  console_tbl                   *cptr;
53
 
54
  /*
55
   * Verify the port number is valid.
56
   */
57
  if ( minor > Console_Port_Count ) {
58
    return RTEMS_INVALID_NUMBER;
59
  }
60
 
61
  /*
62
   * Open the port as a termios console driver.
63
   */
64
 
65
  cptr = &Console_Port_Tbl[minor];
66
  Callbacks.firstOpen            = cptr->pDeviceFns->deviceFirstOpen;
67
  Callbacks.lastClose            = cptr->pDeviceFns->deviceLastClose;
68
  Callbacks.pollRead             = cptr->pDeviceFns->deviceRead;
69
  Callbacks.write                = cptr->pDeviceFns->deviceWrite;
70
  Callbacks.setAttributes        = cptr->pDeviceFns->deviceSetAttributes;
71
  Callbacks.stopRemoteTx         = cptr->pDeviceFlow->deviceStopRemoteTx;
72
  Callbacks.startRemoteTx        = cptr->pDeviceFlow->deviceStartRemoteTx;
73
  Callbacks.outputUsesInterrupts = cptr->pDeviceFns->deviceOutputUsesInterrupts;
74
 
75
  /* XXX what about
76
   *        Console_Port_Tbl[minor].ulMargin,
77
   *        Console_Port_Tbl[minor].ulHysteresis);
78
   */
79
 
80
  status = rtems_termios_open ( major, minor, arg, &Callbacks );
81
  Console_Port_Data[minor].termios_data = args->iop->data1;
82
 
83
  if (minor!=Console_Port_Minor) {
84
    /*
85
     * If this is not the console we do not want ECHO and
86
     * so forth
87
     */
88
    IoctlArgs.iop=args->iop;
89
    IoctlArgs.command=RTEMS_IO_GET_ATTRIBUTES;
90
    IoctlArgs.buffer=&Termios;
91
    rtems_termios_ioctl(&IoctlArgs);
92
    Termios.c_lflag=ICANON;
93
    IoctlArgs.command=RTEMS_IO_SET_ATTRIBUTES;
94
    rtems_termios_ioctl(&IoctlArgs);
95
  }
96
 
97
  if ( (args->iop->flags&LIBIO_FLAGS_READ) &&
98
      Console_Port_Tbl[minor].pDeviceFlow &&
99
      Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx) {
100
    Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx(minor);
101
  }
102
 
103
  return status;
104
}
105
 
106
/*PAGE
107
 *
108
 *  console_close
109
 *
110
 *  This routine closes a port that has been opened as console.
111
 */
112
 
113
rtems_device_driver console_close(
114
  rtems_device_major_number major,
115
  rtems_device_minor_number minor,
116
  void                    * arg
117
)
118
{
119
  rtems_libio_open_close_args_t *args = arg;
120
 
121
  if ( (args->iop->flags&LIBIO_FLAGS_READ) &&
122
        Console_Port_Tbl[minor].pDeviceFlow &&
123
        Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx) {
124
    Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx(minor);
125
  }
126
 
127
  return rtems_termios_close (arg);
128
}
129
 
130
/*PAGE
131
 *
132
 *  console_read
133
 *
134
 *  This routine uses the termios driver to read a character.
135
 */
136
 
137
rtems_device_driver console_read(
138
  rtems_device_major_number major,
139
  rtems_device_minor_number minor,
140
  void                    * arg
141
)
142
{
143
  return rtems_termios_read (arg);
144
}
145
 
146
/*PAGE
147
 *
148
 *  console_write
149
 *
150
 *  this routine uses the termios driver to write a character.
151
 */
152
 
153
rtems_device_driver console_write(
154
  rtems_device_major_number major,
155
  rtems_device_minor_number minor,
156
  void                    * arg
157
)
158
{
159
  return rtems_termios_write (arg);
160
}
161
 
162
/*PAGE
163
 *
164
 *  console_control
165
 *
166
 *  this routine uses the termios driver to process io
167
 */
168
 
169
rtems_device_driver console_control(
170
  rtems_device_major_number major,
171
  rtems_device_minor_number minor,
172
  void                    * arg
173
)
174
{
175
  return rtems_termios_ioctl (arg);
176
}
177
 
178
/*PAGE
179
 *
180
 *  console_initialize
181
 *
182
 *  Routine called to initialize the console device driver.
183
 */
184
 
185
rtems_device_driver console_initialize(
186
  rtems_device_major_number  major,
187
  rtems_device_minor_number  minor_arg,
188
  void                      *arg
189
)
190
{
191
  rtems_status_code          status;
192
  rtems_device_minor_number  minor;
193
 
194
  /*
195
   * initialize the termio interface.
196
   */
197
 
198
  rtems_termios_initialize();
199
 
200
  for (minor=0; minor < Console_Port_Count ; minor++) {
201
    /*
202
     * First perform the configuration dependent probe, then the
203
     * device dependent probe
204
     */
205
 
206
    if ((!Console_Port_Tbl[minor].deviceProbe ||
207
         Console_Port_Tbl[minor].deviceProbe(minor)) &&
208
         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) {
209
      /*
210
       * Use this device for the console
211
       */
212
      break;
213
    }
214
  }
215
  if ( minor == Console_Port_Count ) {
216
    /*
217
     * Failed to find a working device
218
     */
219
    rtems_fatal_error_occurred(RTEMS_IO_ERROR);
220
  }
221
 
222
  Console_Port_Minor=minor;
223
 
224
  /*
225
   * Register Device Names
226
   */
227
  status = rtems_io_register_name("/dev/console", major, Console_Port_Minor );
228
  if (status != RTEMS_SUCCESSFUL) {
229
    rtems_fatal_error_occurred(status);
230
  }
231
  Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(Console_Port_Minor);
232
 
233
  for (minor++;minor<Console_Port_Count;minor++) {
234
    /*
235
     * First perform the configuration dependent probe, then the
236
     * device dependent probe
237
     */
238
 
239
    if ( (!Console_Port_Tbl[minor].deviceProbe ||
240
         Console_Port_Tbl[minor].deviceProbe(minor)) &&
241
         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) {
242
      status = rtems_io_register_name(
243
        Console_Port_Tbl[minor].sDeviceName,
244
        major,
245
        minor );
246
      if (status != RTEMS_SUCCESSFUL) {
247
        rtems_fatal_error_occurred(status);
248
      }
249
 
250
      /*
251
       * Initialize the hardware device.
252
       */
253
 
254
      Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(minor);
255
 
256
    }
257
  }
258
 
259
  return RTEMS_SUCCESSFUL;
260
}
261
 
262
 
263
 

powered by: WebSVN 2.1.0

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