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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [shared/] [console.c] - Blame information for rev 773

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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