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

Subversion Repositories openrisc

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

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

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

powered by: WebSVN 2.1.0

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