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

4.104.114.84.95
Last change on this file since 08330bf was 08330bf, checked in by Joel Sherrill <joel.sherrill@…>, on 07/27/00 at 01:04:11

Port of RTEMS to the ARM processor family by Eric Valette
<valette@…> and Emmanuel Raguet <raguet@…>
of Canon CRF - Communication Dept. This port includes a
basic BSP that is sufficient to link hello world.

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