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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [powerpc/] [ppcn_60x/] [console/] [console.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  This file contains the TTY driver for the PPCn_60x
3
 *
4
 *  This driver uses the termios pseudo driver.
5
 *
6
 *  COPYRIGHT (c) 1998 by Radstone Technology
7
 *
8
 *
9
 * THIS FILE IS PROVIDED TO YOU, THE USER, "AS IS", WITHOUT WARRANTY OF ANY
10
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
11
 * IMPLIED WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK
12
 * AS TO THE QUALITY AND PERFORMANCE OF ALL CODE IN THIS FILE IS WITH YOU.
13
 *
14
 * You are hereby granted permission to use, copy, modify, and distribute
15
 * this file, provided that this notice, plus the above copyright notice
16
 * and disclaimer, appears in all copies. Radstone Technology will provide
17
 * no support for this code.
18
 *
19
 *  COPYRIGHT (c) 1989-1997.
20
 *  On-Line Applications Research Corporation (OAR).
21
 *  Copyright assigned to U.S. Government, 1994.
22
 *
23
 *  The license and distribution terms for this file may be
24
 *  found in the file LICENSE in this distribution or at
25
 *  http://www.OARcorp.com/rtems/license.html.
26
 *
27
 *  $Id: console.c,v 1.2 2001-09-27 12:00:49 chris Exp $
28
 */
29
 
30
#include <bsp.h>
31
#include <rtems/libio.h>
32
#include <stdlib.h>
33
#include <assert.h>
34
#include <termios.h>
35
 
36
#include "console.h"
37
 
38
/*
39
 * Load configuration table
40
 */
41
#include "config.c"
42
 
43
#define NUM_CONSOLE_PORTS (sizeof(Console_Port_Tbl)/sizeof(console_tbl))
44
 
45
console_data    Console_Port_Data[NUM_CONSOLE_PORTS];
46
unsigned long   Console_Port_Count;
47
rtems_device_minor_number  Console_Port_Minor;
48
 
49
/* PAGE
50
 *
51
 *  console_open
52
 *
53
 *  open a port as a termios console.
54
 *
55
 */
56
rtems_device_driver console_open(
57
  rtems_device_major_number major,
58
  rtems_device_minor_number minor,
59
  void                    * arg
60
)
61
{
62
        rtems_status_code status;
63
        rtems_libio_open_close_args_t *args = arg;
64
        rtems_libio_ioctl_args_t IoctlArgs;
65
        struct termios  Termios;
66
        rtems_termios_callbacks Callbacks;
67
        console_fns *c;
68
 
69
        /*
70
         * Verify the port number is valid.
71
         */
72
        if(minor>Console_Port_Count)
73
        {
74
                return RTEMS_INVALID_NUMBER;
75
        }
76
 
77
        /*
78
         *  open the port as a termios console driver.
79
         */
80
        c = Console_Port_Tbl[minor].pDeviceFns;
81
        Callbacks.firstOpen     = c->deviceFirstOpen;
82
        Callbacks.lastClose     = c->deviceLastClose;
83
        Callbacks.pollRead      = c->deviceRead;
84
        Callbacks.write         = c->deviceWrite;
85
        Callbacks.setAttributes = c->deviceSetAttributes;
86
        Callbacks.stopRemoteTx  =
87
                Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx;
88
        Callbacks.startRemoteTx =
89
                Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx;
90
        Callbacks.outputUsesInterrupts = c->deviceOutputUsesInterrupts;
91
        status = rtems_termios_open ( major, minor, arg, &Callbacks);
92
        Console_Port_Data[minor].termios_data = args->iop->data1;
93
 
94
        /*
95
         * Patch in flow control routines
96
         */
97
/* XXX */
98
#if 0 
99
        if((status==RTEMS_SUCCESSFUL) &&
100
           (Console_Port_Tbl[minor].pDeviceFlow))
101
        {
102
                status=rtems_termios_flow_control(
103
                        major, minor, arg,
104
                        Console_Port_Tbl[minor].pDeviceFlow->
105
                                deviceStartRemoteTx,
106
                        Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx,
107
                        Console_Port_Tbl[minor].ulMargin,
108
                        Console_Port_Tbl[minor].ulHysteresis);
109
        }
110
#endif
111
 
112
        if(minor!=Console_Port_Minor)
113
        {
114
                /*
115
                 * If this is not the console we do not want ECHO and
116
                 * so forth
117
                 */
118
                IoctlArgs.iop=args->iop;
119
                IoctlArgs.command=RTEMS_IO_GET_ATTRIBUTES;
120
                IoctlArgs.buffer=&Termios;
121
                rtems_termios_ioctl(&IoctlArgs);
122
                Termios.c_lflag=ICANON;
123
                IoctlArgs.command=RTEMS_IO_SET_ATTRIBUTES;
124
                rtems_termios_ioctl(&IoctlArgs);
125
        }
126
 
127
        if((args->iop->flags&LIBIO_FLAGS_READ) &&
128
           Console_Port_Tbl[minor].pDeviceFlow &&
129
           Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx)
130
        {
131
                Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx(minor);
132
        }
133
 
134
        return status;
135
}
136
 
137
rtems_device_driver console_close(
138
  rtems_device_major_number major,
139
  rtems_device_minor_number minor,
140
  void                    * arg
141
)
142
{
143
        rtems_libio_open_close_args_t *args = arg;
144
 
145
        if((args->iop->flags&LIBIO_FLAGS_READ) &&
146
           Console_Port_Tbl[minor].pDeviceFlow &&
147
           Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx)
148
        {
149
                Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx(minor);
150
        }
151
 
152
        return rtems_termios_close (arg);
153
}
154
 
155
rtems_device_driver console_read(
156
  rtems_device_major_number major,
157
  rtems_device_minor_number minor,
158
  void                    * arg
159
)
160
{
161
  return rtems_termios_read (arg);
162
}
163
 
164
rtems_device_driver console_write(
165
  rtems_device_major_number major,
166
  rtems_device_minor_number minor,
167
  void                    * arg
168
)
169
{
170
  return rtems_termios_write (arg);
171
}
172
 
173
rtems_device_driver console_control(
174
  rtems_device_major_number major,
175
  rtems_device_minor_number minor,
176
  void                    * arg
177
)
178
{
179
  return rtems_termios_ioctl (arg);
180
}
181
 
182
/* PAGE
183
 *
184
 *  console_initialize
185
 *
186
 *  Routine called to initialize the console device driver.
187
 */
188
rtems_device_driver console_initialize(
189
  rtems_device_major_number  major,
190
  rtems_device_minor_number  minor,
191
  void                      *arg
192
)
193
{
194
        rtems_status_code          status;
195
 
196
        /*
197
         * initialize the termio interface.
198
         */
199
        rtems_termios_initialize();
200
 
201
        Console_Port_Count=NUM_CONSOLE_PORTS;
202
 
203
        for(minor=0;
204
            minor<Console_Port_Count;
205
            minor++)
206
        {
207
                /*
208
                 * First perform the configuration dependant probe, then the
209
                 * device dependant probe
210
                 */
211
                if((!Console_Port_Tbl[minor].deviceProbe ||
212
                    Console_Port_Tbl[minor].deviceProbe(minor)) &&
213
                   Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor))
214
                {
215
                        /*
216
                         * Use this device for the console
217
                         */
218
                        break;
219
                }
220
        }
221
        if(minor==Console_Port_Count)
222
        {
223
                /*
224
                 * Failed to find a working device
225
                 */
226
                rtems_fatal_error_occurred(RTEMS_IO_ERROR);
227
        }
228
 
229
        Console_Port_Minor=minor;
230
 
231
        /*
232
         *  Register Device Names
233
         */
234
        status = rtems_io_register_name("/dev/console",
235
                                        major,
236
                                        Console_Port_Minor );
237
        if (status != RTEMS_SUCCESSFUL)
238
        {
239
                rtems_fatal_error_occurred(status);
240
        }
241
        Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(
242
                Console_Port_Minor);
243
 
244
        for(minor++;minor<Console_Port_Count;minor++)
245
        {
246
                /*
247
                 * First perform the configuration dependant probe, then the
248
                 * device dependant probe
249
                 */
250
                if((!Console_Port_Tbl[minor].deviceProbe ||
251
                    Console_Port_Tbl[minor].deviceProbe(minor)) &&
252
                   Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor))
253
                {
254
                        status = rtems_io_register_name(
255
                                Console_Port_Tbl[minor].sDeviceName,
256
                                major,
257
                                minor );
258
                        if (status != RTEMS_SUCCESSFUL)
259
                        {
260
                                rtems_fatal_error_occurred(status);
261
                        }
262
 
263
                        /*
264
                         * Initialize the hardware device.
265
                         */
266
                        Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(
267
                                minor);
268
 
269
                }
270
        }
271
 
272
        return RTEMS_SUCCESSFUL;
273
}
274
 
275
/* PAGE
276
 *
277
 *  DEBUG_puts
278
 *
279
 *  This should be safe in the event of an error.  It attempts to ensure
280
 *  that no TX empty interrupts occur while it is doing polled IO.  Then
281
 *  it restores the state of that external interrupt.
282
 *
283
 *  Input parameters:
284
 *    string  - pointer to debug output string
285
 *
286
 *  Output parameters:  NONE
287
 *
288
 *  Return values:      NONE
289
 */
290
 
291
void DEBUG_puts(
292
        char *string
293
)
294
{
295
        char *s;
296
        unsigned32      Irql;
297
 
298
        rtems_interrupt_disable(Irql);
299
 
300
        for ( s = string ; *s ; s++ )
301
        {
302
                Console_Port_Tbl[Console_Port_Minor].pDeviceFns->
303
                        deviceWritePolled(Console_Port_Minor, *s);
304
        }
305
 
306
        rtems_interrupt_enable(Irql);
307
}
308
 
309
/* PAGE
310
 *
311
 *  DEBUG_puth
312
 *
313
 *  This should be safe in the event of an error.  It attempts to ensure
314
 *  that no TX empty interrupts occur while it is doing polled IO.  Then
315
 *  it restores the state of that external interrupt.
316
 *
317
 *  Input parameters:
318
 *    ulHexNum - value to display
319
 *
320
 *  Output parameters:  NONE
321
 *
322
 *  Return values:      NONE
323
 */
324
void
325
DEBUG_puth(
326
    unsigned32 ulHexNum
327
    )
328
{
329
        unsigned long i,d;
330
        unsigned32 Irql;
331
 
332
        rtems_interrupt_disable(Irql);
333
 
334
        Console_Port_Tbl[Console_Port_Minor].pDeviceFns->
335
                deviceWritePolled(Console_Port_Minor, '0');
336
        Console_Port_Tbl[Console_Port_Minor].pDeviceFns->
337
                deviceWritePolled(Console_Port_Minor, 'x');
338
 
339
        for(i=32;i;)
340
        {
341
                i-=4;
342
                d=(ulHexNum>>i)&0xf;
343
                Console_Port_Tbl[Console_Port_Minor].pDeviceFns->
344
                        deviceWritePolled(Console_Port_Minor,
345
                                          (d<=9) ? d+'0' : d+'a'-0xa);
346
        }
347
 
348
        rtems_interrupt_enable(Irql);
349
}
350
 

powered by: WebSVN 2.1.0

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