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

4.104.114.84.95
Last change on this file since 176e6d40 was 176e6d40, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/02 at 17:40:41

2002-01-03 Ralf Corsepius <corsepiu@…>

  • comm/console.c: Include rtems/bspIo.h instead of bspIo.h.
  • irq/irq_init.c: Include rtems/bspIo.h instead of bspIo.h.
  • Property mode set to 100644
File size: 8.8 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.OARcorp.com/rtems/license.html.
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/*-------------------------------------------------------------------------+
52| External Prototypes
53+--------------------------------------------------------------------------*/
54extern char BSP_wait_polled_input(void);
55extern BSP_polling_getchar_function_type BSP_poll_char;
56extern void rtemsReboot(void);
57
58static int  conSetAttr(int minor, const struct termios *);
59static void isr_on(const rtems_irq_connect_data *);
60static void isr_off(const rtems_irq_connect_data *);
61static int  isr_is_on(const rtems_irq_connect_data *);
62
63/*
64 * BSP initialization
65 */
66
67/* for printk support */
68BSP_output_char_function_type BSP_output_char =
69   (BSP_output_char_function_type) BSP_output_char_via_serial;
70BSP_polling_getchar_function_type BSP_poll_char =
71   (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
72
73
74static rtems_irq_connect_data console_isr_data = {BSP_UART,
75                                                   BSP_uart_termios_isr_com1,
76                                                   isr_on,
77                                                   isr_off,
78                                                   isr_is_on};
79
80static void
81isr_on(const rtems_irq_connect_data *unused)
82{
83  return;
84}
85                                                   
86static void
87isr_off(const rtems_irq_connect_data *unused)
88{
89  return;
90}
91
92static int
93isr_is_on(const rtems_irq_connect_data *irq)
94{
95  if (Regs[INTMASK] & 0x4)
96    return 0;
97  else
98    return 1;
99}
100
101void __assert (const char *file, int line, const char *msg)
102{
103    static   char exit_msg[] = "EXECUTIVE SHUTDOWN! Any key to reboot...";
104  unsigned char  ch;
105   
106  /*
107   * Note we cannot call exit or printf from here,
108   * assert can fail inside ISR too
109   */
110
111   /*
112   * Close console
113   */
114  close(2);
115  close(1);
116  close(0);
117
118  printk("\nassert failed: %s: ", file);
119  printk("%d: ", line);
120  printk("%s\n\n", msg);
121  printk(exit_msg);
122  ch = BSP_poll_char();
123  printk("\n\n");
124  rtemsReboot();
125
126}
127
128
129/*-------------------------------------------------------------------------+
130| Console device driver INITIALIZE entry point.
131+--------------------------------------------------------------------------+
132| Initilizes the I/O console (keyboard + VGA display) driver.
133+--------------------------------------------------------------------------*/
134rtems_device_driver
135console_initialize(rtems_device_major_number major,
136                   rtems_device_minor_number minor,
137                   void                      *arg)
138{
139  rtems_status_code status;
140
141  /*
142   * Set up TERMIOS
143   */
144  rtems_termios_initialize ();
145 
146  /*
147   * Do device-specific initialization
148   */
149     
150  /* 38400-8-N-1 */
151  BSP_uart_init(BSPConsolePort, 38400, 0);
152     
153     
154  /* Set interrupt handler */
155  console_isr_data.name = BSP_UART;
156  console_isr_data.hdl  = BSP_uart_termios_isr_com1;
157  console_isr_data.irqLevel = 3;
158  console_isr_data.irqTrigger = 0;
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  /*
168   * Register the device
169   */
170  status = rtems_io_register_name ("/dev/console", major, 0);
171  if (status != RTEMS_SUCCESSFUL)
172    {
173      printk("Error registering console device!\n");
174      rtems_fatal_error_occurred (status);
175    }
176
177  printk("Initialized console on port COM1 38400-8-N-1\n\n");
178
179  return RTEMS_SUCCESSFUL;
180} /* console_initialize */
181
182
183static int console_last_close(int major, int minor, void *arg)
184{
185  BSP_remove_rtems_irq_handler (&console_isr_data);
186
187  return 0;
188}
189
190/*-------------------------------------------------------------------------+
191| Console device driver OPEN entry point
192+--------------------------------------------------------------------------*/
193rtems_device_driver
194console_open(rtems_device_major_number major,
195                rtems_device_minor_number minor,
196                void                      *arg)
197{
198  rtems_status_code              status;
199  static rtems_termios_callbacks cb =
200  {
201    NULL,                     /* firstOpen */
202    console_last_close,       /* lastClose */
203    NULL,                     /* pollRead */
204    BSP_uart_termios_write_com1, /* write */
205    conSetAttr,               /* setAttributes */
206    NULL,                     /* stopRemoteTx */
207    NULL,                     /* startRemoteTx */
208    1                         /* outputUsesInterrupts */
209  };
210
211  status = rtems_termios_open (major, minor, arg, &cb);
212
213  if(status != RTEMS_SUCCESSFUL)
214    {
215      printk("Error openning console device\n");
216      return status;
217    }
218
219  /*
220   * Pass data area info down to driver
221   */
222  BSP_uart_termios_set(BSPConsolePort,
223                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
224 
225  /* Enable interrupts  on channel */
226  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
227
228  return RTEMS_SUCCESSFUL;
229}
230
231/*-------------------------------------------------------------------------+
232| Console device driver CLOSE entry point
233+--------------------------------------------------------------------------*/
234rtems_device_driver
235console_close(rtems_device_major_number major,
236              rtems_device_minor_number minor,
237              void                      *arg)
238{
239  rtems_device_driver res = RTEMS_SUCCESSFUL;
240
241  res =  rtems_termios_close (arg);
242
243  return res;
244} /* console_close */
245
246 
247/*-------------------------------------------------------------------------+
248| Console device driver READ entry point.
249+--------------------------------------------------------------------------+
250| Read characters from the I/O console. We only have stdin.
251+--------------------------------------------------------------------------*/
252rtems_device_driver
253console_read(rtems_device_major_number major,
254             rtems_device_minor_number minor,
255             void                      *arg)
256{
257
258  return rtems_termios_read (arg);
259 
260} /* console_read */
261 
262
263/*-------------------------------------------------------------------------+
264| Console device driver WRITE entry point.
265+--------------------------------------------------------------------------+
266| Write characters to the I/O console. Stderr and stdout are the same.
267+--------------------------------------------------------------------------*/
268rtems_device_driver
269console_write(rtems_device_major_number major,
270              rtems_device_minor_number minor,
271              void                    * arg)
272{
273
274  return rtems_termios_write (arg);
275 
276} /* console_write */
277
278
279 
280/*
281 * Handle ioctl request.
282 */
283rtems_device_driver
284console_control(rtems_device_major_number major,
285                rtems_device_minor_number minor,
286                void                      * arg
287)
288{
289  return rtems_termios_ioctl (arg);
290}
291
292static int
293conSetAttr(int minor, const struct termios *t)
294{
295  int baud;
296
297  switch (t->c_cflag & CBAUD)
298    {
299    case B50:   
300      baud = 50;
301      break;
302    case B75:   
303      baud = 75;       
304      break;
305    case B110: 
306      baud = 110;       
307      break;
308    case B134: 
309      baud = 134;       
310      break;
311    case B150: 
312      baud = 150;       
313      break;
314    case B200:
315      baud = 200;       
316      break;
317    case B300: 
318      baud = 300;
319      break;
320    case B600: 
321      baud = 600;       
322      break;
323    case B1200:
324      baud = 1200;
325      break;
326    case B1800:
327      baud = 1800;     
328      break;
329    case B2400:
330      baud = 2400;
331      break;
332    case B4800:
333      baud = 4800;
334      break;
335    case B9600:
336      baud = 9600;
337      break;
338    case B19200:
339      baud = 19200;
340      break;
341    case B38400:
342      baud = 38400;
343      break;
344    case B57600:       
345      baud = 57600;
346      break;
347    case B115200:
348      baud = 115200;
349      break;
350    default:
351      baud = 0;
352      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
353      return 0;
354    }
355
356  BSP_uart_set_baud(BSPConsolePort, baud);
357
358  return 0;
359}
360
361
Note: See TracBrowser for help on using the repository browser.