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

Subversion Repositories openrisc_me

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

Go to most recent revision | 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:46 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    = 781250;
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
  /* 9600-8-N-1, no hardware flow control */
146
  BSP_uart_init(BSPConsolePort, 9600, 0);
147
 
148
 
149
  /* Set interrupt handler */
150
  if(BSPConsolePort == BSP_UART_COM1)
151
    {
152
      console_isr_data.name = BSP_UART_COM1_IRQ;
153
      console_isr_data.hdl  = BSP_uart_termios_isr_com1;
154
 
155
    }
156
  else
157
    {
158
      assert(BSPConsolePort == BSP_UART_COM2);
159
      console_isr_data.name = BSP_UART_COM2_IRQ;
160
      console_isr_data.hdl  = BSP_uart_termios_isr_com2;
161
    }
162
 
163
  status = BSP_install_rtems_irq_handler(&console_isr_data);
164
 
165
  if (!status){
166
    printk("Error installing serial console interrupt handler!\n");
167
    rtems_fatal_error_occurred(status);
168
  }
169
  /*
170
   * Register the device
171
   */
172
  status = rtems_io_register_name ("/dev/console", major, 0);
173
  if (status != RTEMS_SUCCESSFUL)
174
    {
175
      printk("Error registering console device!\n");
176
      rtems_fatal_error_occurred (status);
177
    }
178
 
179
  if(BSPConsolePort == BSP_UART_COM1)
180
    {
181
      printk("Initialized console on port COM1 9600-8-N-1\n\n");
182
    }
183
  else
184
    {
185
      printk("Initialized console on port COM2 9600-8-N-1\n\n");
186
    }
187
 
188
  return RTEMS_SUCCESSFUL;
189
} /* console_initialize */
190
 
191
 
192
static int console_open_count = 0;
193
 
194
static int console_last_close(int major, int minor, void *arg)
195
{
196
  BSP_remove_rtems_irq_handler (&console_isr_data);
197
 
198
  return 0;
199
}
200
 
201
/*-------------------------------------------------------------------------+
202
| Console device driver OPEN entry point
203
+--------------------------------------------------------------------------*/
204
rtems_device_driver
205
console_open(rtems_device_major_number major,
206
                rtems_device_minor_number minor,
207
                void                      *arg)
208
{
209
  rtems_status_code              status;
210
  static rtems_termios_callbacks cb =
211
  {
212
    NULL,                     /* firstOpen */
213
    console_last_close,       /* lastClose */
214
    NULL,                     /* poll read  */
215
    BSP_uart_termios_write_com2, /* write */
216
    conSetAttr,               /* setAttributes */
217
    NULL,                     /* stopRemoteTx */
218
    NULL,                     /* startRemoteTx */
219
    1                         /* outputUsesInterrupts */
220
  };
221
 
222
  if(BSPConsolePort == BSP_UART_COM2)
223
    {
224
      cb.write = BSP_uart_termios_write_com2;
225
    }
226
 
227
  status = rtems_termios_open (major, minor, arg, &cb);
228
 
229
  if(status != RTEMS_SUCCESSFUL)
230
    {
231
      printk("Error openning console device\n");
232
      return status;
233
    }
234
 
235
  /*
236
   * Pass data area info down to driver
237
   */
238
  BSP_uart_termios_set(BSPConsolePort,
239
                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
240
 
241
  /* Enable interrupts  on channel */
242
  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
243
 
244
  return RTEMS_SUCCESSFUL;
245
}
246
 
247
/*-------------------------------------------------------------------------+
248
| Console device driver CLOSE entry point
249
+--------------------------------------------------------------------------*/
250
rtems_device_driver
251
console_close(rtems_device_major_number major,
252
              rtems_device_minor_number minor,
253
              void                      *arg)
254
{
255
 
256
  return (rtems_termios_close (arg));
257
 
258
} /* console_close */
259
 
260
 
261
/*-------------------------------------------------------------------------+
262
| Console device driver READ entry point.
263
+--------------------------------------------------------------------------+
264
| Read characters from the I/O console. We only have stdin.
265
+--------------------------------------------------------------------------*/
266
rtems_device_driver
267
console_read(rtems_device_major_number major,
268
             rtems_device_minor_number minor,
269
             void                      *arg)
270
{
271
  rtems_status_code sc;
272
  printf("read the console\n");
273
 
274
  sc = rtems_termios_read (arg);
275
 
276
  if ( sc != RTEMS_SUCCESSFUL )
277
    printf("console_read: fails %s\n",rtems_status_text(sc));
278
 
279
  return sc;
280
 
281
} /* console_read */
282
 
283
 
284
/*-------------------------------------------------------------------------+
285
| Console device driver WRITE entry point.
286
+--------------------------------------------------------------------------+
287
| Write characters to the I/O console. Stderr and stdout are the same.
288
+--------------------------------------------------------------------------*/
289
rtems_device_driver
290
console_write(rtems_device_major_number major,
291
              rtems_device_minor_number minor,
292
              void                    * arg)
293
{
294
        return rtems_termios_write (arg);
295
 
296
} /* console_write */
297
 
298
 
299
 
300
/*
301
 * Handle ioctl request.
302
 */
303
rtems_device_driver
304
console_control(rtems_device_major_number major,
305
                rtems_device_minor_number minor,
306
                void                      * arg
307
)
308
{
309
  return rtems_termios_ioctl (arg);
310
}
311
 
312
static int
313
conSetAttr(int minor, const struct termios *t)
314
{
315
  int baud;
316
 
317
  switch (t->c_cflag & CBAUD)
318
    {
319
    case B50:
320
      baud = 50;
321
      break;
322
    case B75:
323
      baud = 75;
324
      break;
325
    case B110:
326
      baud = 110;
327
      break;
328
    case B134:
329
      baud = 134;
330
      break;
331
    case B150:
332
      baud = 150;
333
      break;
334
    case B200:
335
      baud = 200;
336
      break;
337
    case B300:
338
      baud = 300;
339
      break;
340
    case B600:
341
      baud = 600;
342
      break;
343
    case B1200:
344
      baud = 1200;
345
      break;
346
    case B1800:
347
      baud = 1800;
348
      break;
349
    case B2400:
350
      baud = 2400;
351
      break;
352
    case B4800:
353
      baud = 4800;
354
      break;
355
    case B9600:
356
      baud = 9600;
357
      break;
358
    case B19200:
359
      baud = 19200;
360
      break;
361
    case B38400:
362
      baud = 38400;
363
      break;
364
    case B57600:
365
      baud = 57600;
366
      break;
367
    case B115200:
368
      baud = 115200;
369
      break;
370
    default:
371
      baud = 0;
372
      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
373
      return 0;
374
    }
375
 
376
  BSP_uart_set_baud(BSPConsolePort, baud);
377
 
378
  return 0;
379
}
380
 
381
/*
382
 * BSP initialization
383
 */
384
 
385
BSP_output_char_function_type BSP_output_char =
386
                       (BSP_output_char_function_type)    BSP_output_char_via_serial;
387
 
388
BSP_polling_getchar_function_type BSP_poll_char =
389
                      (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
390
 
391
int BSP_poll_read(int ttyMinor){
392
 
393
  return BSP_poll_char_via_serial();
394
}

powered by: WebSVN 2.1.0

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