source: rtems/c/src/lib/libbsp/arm/shared/comm/console.c @ f05b2ac

4.104.114.84.95
Last change on this file since f05b2ac was f05b2ac, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/21/04 at 16:01:48

Remove duplicate white lines.

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