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

Subversion Repositories or1k

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

powered by: WebSVN 2.1.0

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