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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*-------------------------------------------------------------------------+
2
| console.c v1.1 - i386ex BSP - 1997/08/07
3
+--------------------------------------------------------------------------+
4
| This file contains the i386ex console I/O package. It is just a termios
5
| wrapper.
6
+--------------------------------------------------------------------------+
7
| (C) Copyright 1997 -
8
| - NavIST Group - Real-Time Distributed Systems and Industrial Automation
9
|
10
| http://pandora.ist.utl.pt
11
|
12
| Instituto Superior Tecnico * Lisboa * PORTUGAL
13
+--------------------------------------------------------------------------+
14
| Disclaimer:
15
|
16
| This file is provided "AS IS" without warranty of any kind, either
17
| expressed or implied.
18
+--------------------------------------------------------------------------+
19
| This code is based on:
20
|   console.c,v 1.4 1995/12/19 20:07:23 joel Exp - go32 BSP
21
|   console.c,v 1.15 pc386 BSP
22
| With the following copyright notice:
23
| **************************************************************************
24
| *  COPYRIGHT (c) 1989-1999.
25
| *  On-Line Applications Research Corporation (OAR).
26
| *
27
| *  The license and distribution terms for this file may be
28
| *  found in found in the file LICENSE in this distribution or at
29
| *  http://www.OARcorp.com/rtems/license.html.
30
| **************************************************************************
31
|
32
|  $Id: console.c,v 1.2 2001-09-27 11:59:50 chris Exp $
33
+--------------------------------------------------------------------------*/
34
 
35
#include <stdio.h>
36
#include <stdlib.h>
37
#include <assert.h>
38
 
39
/* workaround for gcc development tools */
40
#undef __assert
41
void __assert (const char *file, int line, const char *msg);
42
 
43
#include <bsp.h>
44
#include <irq.h>
45
#include <rtems/libio.h>
46
#include <termios.h>
47
#include <uart.h>
48
#include <libcpu/cpuModel.h>
49
 
50
/*
51
 * Possible value for console input/output :
52
 *      BSP_UART_COM1
53
 *      BSP_UART_COM2
54
 *  BSP_CONSOLE_PORT_CONSOLE is not valid in this BSP.
55
 *      All references to either keyboard or video handling have been removed.
56
 */
57
 
58
int BSPConsolePort = BSP_UART_COM2;
59
int BSPBaseBaud    = 115200;
60
int BSP_poll_read(int);
61
 
62
extern BSP_polling_getchar_function_type BSP_poll_char;
63
 
64
static int  conSetAttr(int minor, const struct termios *);
65
static void isr_on(const rtems_irq_connect_data *);
66
static void isr_off(const rtems_irq_connect_data *);
67
static int  isr_is_on(const rtems_irq_connect_data *);
68
 
69
/*
70
 * Change references to com2 if required.
71
 */
72
 
73
static rtems_irq_connect_data console_isr_data =
74
{ BSP_UART_COM2_IRQ,
75
  BSP_uart_termios_isr_com2,
76
  isr_on,
77
  isr_off,
78
  isr_is_on};
79
 
80
static void
81
isr_on(const rtems_irq_connect_data *unused)
82
{
83
  return;
84
}
85
 
86
static void
87
isr_off(const rtems_irq_connect_data *unused)
88
{
89
  return;
90
}
91
 
92
static int
93
isr_is_on(const rtems_irq_connect_data *irq)
94
{
95
  return BSP_irq_enabled_at_i8259s(irq->name);
96
}
97
 
98
void __assert (const char *file, int line, const char *msg)
99
{
100
    static   char exit_msg[] = "EXECUTIVE SHUTDOWN! Any key to reboot...";
101
  unsigned char  ch;
102
 
103
  /*
104
   * Note we cannot call exit or printf from here,
105
   * assert can fail inside ISR too
106
   */
107
 
108
   /*
109
   * Close console
110
   */
111
  close(2);
112
  close(1);
113
  close(0);
114
 
115
  printk("\nassert failed: %s: ", file);
116
  printk("%d: ", line);
117
  printk("%s\n\n", msg);
118
  printk(exit_msg);
119
  ch = BSP_poll_char();
120
  printk("\nShould jump to reset now!\n");
121
}
122
 
123
 
124
/*-------------------------------------------------------------------------+
125
| Console device driver INITIALIZE entry point.
126
+--------------------------------------------------------------------------+
127
| Initilizes the I/O console (keyboard + VGA display) driver.
128
+--------------------------------------------------------------------------*/
129
rtems_device_driver
130
console_initialize(rtems_device_major_number major,
131
                   rtems_device_minor_number minor,
132
                   void                      *arg)
133
{
134
  rtems_status_code status;
135
 
136
  /*
137
   * Set up TERMIOS
138
   */
139
  rtems_termios_initialize ();
140
 
141
  /*
142
   * Do device-specific initialization
143
   */
144
 
145
  /* 115200-8-N-1, without hardware flow control */
146
  BSP_uart_init(BSPConsolePort, 115200, 0);
147
 
148
  /* Set interrupt handler */
149
  if(BSPConsolePort == BSP_UART_COM1)
150
    {
151
      console_isr_data.name = BSP_UART_COM1_IRQ;
152
      console_isr_data.hdl  = BSP_uart_termios_isr_com1;
153
 
154
    }
155
  else
156
    {
157
      assert(BSPConsolePort == BSP_UART_COM2);
158
      console_isr_data.name = BSP_UART_COM2_IRQ;
159
      console_isr_data.hdl  = BSP_uart_termios_isr_com2;
160
    }
161
 
162
  status = BSP_install_rtems_irq_handler(&console_isr_data);
163
 
164
  if (!status){
165
    printk("Error installing serial console interrupt handler!\n");
166
    rtems_fatal_error_occurred(status);
167
  }
168
  /*
169
   * Register the device
170
   */
171
  status = rtems_io_register_name ("/dev/console", major, 0);
172
  if (status != RTEMS_SUCCESSFUL)
173
    {
174
      printk("Error registering console device!\n");
175
      rtems_fatal_error_occurred (status);
176
    }
177
 
178
  if(BSPConsolePort == BSP_UART_COM1)
179
    {
180
      printk("Initialized console on port COM1 115200-8-N-1\n\n");
181
    }
182
  else
183
    {
184
      printk("Initialized console on port COM2 115200-8-N-1\n\n");
185
    }
186
 
187
  return RTEMS_SUCCESSFUL;
188
} /* console_initialize */
189
 
190
 
191
static int console_open_count = 0;
192
 
193
static int console_last_close(int major, int minor, void *arg)
194
{
195
  BSP_remove_rtems_irq_handler (&console_isr_data);
196
 
197
  return 0;
198
}
199
 
200
/*-------------------------------------------------------------------------+
201
| Console device driver OPEN entry point
202
+--------------------------------------------------------------------------*/
203
rtems_device_driver
204
console_open(rtems_device_major_number major,
205
                rtems_device_minor_number minor,
206
                void                      *arg)
207
{
208
  rtems_status_code              status;
209
  static rtems_termios_callbacks cb =
210
  {
211
    NULL,                     /* firstOpen */
212
    console_last_close,       /* lastClose */
213
    NULL,                     /* poll read  */
214
    BSP_uart_termios_write_com1, /* write */
215
    conSetAttr,               /* setAttributes */
216
    NULL,                     /* stopRemoteTx */
217
    NULL,                     /* startRemoteTx */
218
    1                         /* outputUsesInterrupts */
219
  };
220
 
221
  if(BSPConsolePort == BSP_UART_COM2)
222
    {
223
      cb.write = BSP_uart_termios_write_com2;
224
    }
225
 
226
  status = rtems_termios_open (major, minor, arg, &cb);
227
 
228
  if(status != RTEMS_SUCCESSFUL)
229
    {
230
      printk("Error openning console device\n");
231
      return status;
232
    }
233
 
234
  /*
235
   * Pass data area info down to driver
236
   */
237
  BSP_uart_termios_set(BSPConsolePort,
238
                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
239
 
240
  /* Enable interrupts  on channel */
241
  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
242
 
243
  return RTEMS_SUCCESSFUL;
244
}
245
 
246
/*-------------------------------------------------------------------------+
247
| Console device driver CLOSE entry point
248
+--------------------------------------------------------------------------*/
249
rtems_device_driver
250
console_close(rtems_device_major_number major,
251
              rtems_device_minor_number minor,
252
              void                      *arg)
253
{
254
 
255
  return (rtems_termios_close (arg));
256
 
257
} /* console_close */
258
 
259
 
260
/*-------------------------------------------------------------------------+
261
| Console device driver READ entry point.
262
+--------------------------------------------------------------------------+
263
| Read characters from the I/O console. We only have stdin.
264
+--------------------------------------------------------------------------*/
265
rtems_device_driver
266
console_read(rtems_device_major_number major,
267
             rtems_device_minor_number minor,
268
             void                      *arg)
269
{
270
  rtems_status_code sc;
271
 
272
  sc = rtems_termios_read (arg);
273
 
274
  if ( sc != RTEMS_SUCCESSFUL )
275
    printk("console_read: fails %s\n",rtems_status_text(sc));
276
 
277
  return sc;
278
 
279
} /* console_read */
280
 
281
 
282
/*-------------------------------------------------------------------------+
283
| Console device driver WRITE entry point.
284
+--------------------------------------------------------------------------+
285
| Write characters to the I/O console. Stderr and stdout are the same.
286
+--------------------------------------------------------------------------*/
287
rtems_device_driver
288
console_write(rtems_device_major_number major,
289
              rtems_device_minor_number minor,
290
              void                    * arg)
291
{
292
        return rtems_termios_write (arg);
293
 
294
} /* console_write */
295
 
296
 
297
 
298
/*
299
 * Handle ioctl request.
300
 */
301
rtems_device_driver
302
console_control(rtems_device_major_number major,
303
                rtems_device_minor_number minor,
304
                void                      * arg
305
)
306
{
307
  return rtems_termios_ioctl (arg);
308
}
309
 
310
static int
311
conSetAttr(int minor, const struct termios *t)
312
{
313
  int baud;
314
 
315
  switch (t->c_cflag & CBAUD)
316
    {
317
    case B50:
318
      baud = 50;
319
      break;
320
    case B75:
321
      baud = 75;
322
      break;
323
    case B110:
324
      baud = 110;
325
      break;
326
    case B134:
327
      baud = 134;
328
      break;
329
    case B150:
330
      baud = 150;
331
      break;
332
    case B200:
333
      baud = 200;
334
      break;
335
    case B300:
336
      baud = 300;
337
      break;
338
    case B600:
339
      baud = 600;
340
      break;
341
    case B1200:
342
      baud = 1200;
343
      break;
344
    case B1800:
345
      baud = 1800;
346
      break;
347
    case B2400:
348
      baud = 2400;
349
      break;
350
    case B4800:
351
      baud = 4800;
352
      break;
353
    case B9600:
354
      baud = 9600;
355
      break;
356
    case B19200:
357
      baud = 19200;
358
      break;
359
    case B38400:
360
      baud = 38400;
361
      break;
362
    case B57600:
363
      baud = 57600;
364
      break;
365
    case B115200:
366
      baud = 115200;
367
      break;
368
    default:
369
      baud = 0;
370
      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
371
      return 0;
372
    }
373
 
374
  BSP_uart_set_baud(BSPConsolePort, baud);
375
 
376
  return 0;
377
}
378
 
379
/*
380
 * BSP initialization
381
 */
382
 
383
BSP_output_char_function_type BSP_output_char =
384
                       (BSP_output_char_function_type)    BSP_output_char_via_serial;
385
 
386
BSP_polling_getchar_function_type BSP_poll_char =
387
                      (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
388
 
389
int BSP_poll_read(int ttyMinor){
390
 
391
  return BSP_poll_char_via_serial();
392
}

powered by: WebSVN 2.1.0

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