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

4.104.115
Last change on this file since d4f6b30 was d4f6b30, checked in by Joel Sherrill <joel.sherrill@…>, on 09/22/08 at 21:49:32

2008-09-22 Joel Sherrill <joel.sherrill@…>

  • acinclude.m4, shared/comm/console.c: Use standardized bsp_cleanup() which can optionally print a message, poll for user to press key, and call bsp_reset(). Using this eliminates the various bsp_cleanup() implementations which had their own implementation and variety of string constants.
  • Property mode set to 100644
File size: 7.3 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 <unistd.h>
19
20#include <bsp.h>
21#include <rtems/bspIo.h>
22#include <irq.h>
23#include <rtems/libio.h>
24#include <termios.h>
25#include <registers.h>
26#include <uart.h>
27
28/*
29 * Possible value for console input/output :
30 *      BSP_CONSOLE_PORT_CONSOLE
31 *      BSP_UART_COM1
32 *      BSP_UART_COM2
33 *
34 * Note:
35 *   1. Currently BSPPrintkPort, cannot be assigned to COM2,
36 *      it will be fixed soon.
37 *
38 *   2. If both BSPConsolePort and BSPPrintkport are assigned
39 *      to same serial device it does not work that great
40 */
41
42int BSPConsolePort = BSP_UART_COM1;
43int BSPPrintkPort  = BSP_UART_COM1;
44
45int BSPBaseBaud    = 115200;
46
47/*-------------------------------------------------------------------------+
48| External Prototypes
49+--------------------------------------------------------------------------*/
50extern char BSP_wait_polled_input(void);
51extern BSP_polling_getchar_function_type BSP_poll_char;
52
53static int  conSetAttr(int minor, const struct termios *);
54static void isr_on(const rtems_irq_connect_data *);
55static void isr_off(const rtems_irq_connect_data *);
56static int  isr_is_on(const rtems_irq_connect_data *);
57
58/*
59 * BSP initialization
60 */
61
62/* for printk support */
63BSP_output_char_function_type BSP_output_char =
64   (BSP_output_char_function_type) BSP_output_char_via_serial;
65BSP_polling_getchar_function_type BSP_poll_char =
66   (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
67
68static rtems_irq_connect_data console_isr_data = {BSP_UART,
69                                                   BSP_uart_termios_isr_com1,
70                                                   isr_on,
71                                                   isr_off,
72                                                   isr_is_on};
73
74static void
75isr_on(const rtems_irq_connect_data *unused)
76{
77  return;
78}
79
80static void
81isr_off(const rtems_irq_connect_data *unused)
82{
83  return;
84}
85
86static int
87isr_is_on(const rtems_irq_connect_data *irq)
88{
89  if (Regs[INTMASK] & 0x4)
90    return 0;
91  else
92    return 1;
93}
94
95/*-------------------------------------------------------------------------+
96| Console device driver INITIALIZE entry point.
97+--------------------------------------------------------------------------+
98| Initilizes the I/O console (keyboard + VGA display) driver.
99+--------------------------------------------------------------------------*/
100rtems_device_driver
101console_initialize(rtems_device_major_number major,
102                   rtems_device_minor_number minor,
103                   void                      *arg)
104{
105  rtems_status_code status;
106
107  /*
108   * Set up TERMIOS
109   */
110  rtems_termios_initialize ();
111
112  /*
113   * Do device-specific initialization
114   */
115
116  /* 38400-8-N-1 */
117  BSP_uart_init(BSPConsolePort, 38400, 0);
118
119  /* Set interrupt handler */
120  console_isr_data.name = BSP_UART;
121  console_isr_data.hdl  = BSP_uart_termios_isr_com1;
122  console_isr_data.irqLevel = 3;
123  console_isr_data.irqTrigger = 0;
124
125  status = BSP_install_rtems_irq_handler(&console_isr_data);
126
127  if (!status){
128    printk("Error installing serial console interrupt handler!\n");
129    rtems_fatal_error_occurred(status);
130  }
131
132  /*
133   * Register the device
134   */
135  status = rtems_io_register_name ("/dev/console", major, 0);
136  if (status != RTEMS_SUCCESSFUL)
137    {
138      printk("Error registering console device!\n");
139      rtems_fatal_error_occurred (status);
140    }
141
142  printk("Initialized console on port COM1 38400-8-N-1\n\n");
143
144  return RTEMS_SUCCESSFUL;
145} /* console_initialize */
146
147static int console_last_close(int major, int minor, void *arg)
148{
149  BSP_remove_rtems_irq_handler (&console_isr_data);
150
151  return 0;
152}
153
154/*-------------------------------------------------------------------------+
155| Console device driver OPEN entry point
156+--------------------------------------------------------------------------*/
157rtems_device_driver
158console_open(rtems_device_major_number major,
159                rtems_device_minor_number minor,
160                void                      *arg)
161{
162  rtems_status_code              status;
163  static rtems_termios_callbacks cb =
164  {
165    NULL,                     /* firstOpen */
166    console_last_close,       /* lastClose */
167    NULL,                     /* pollRead */
168    BSP_uart_termios_write_com1, /* write */
169    conSetAttr,               /* setAttributes */
170    NULL,                     /* stopRemoteTx */
171    NULL,                     /* startRemoteTx */
172    1                         /* outputUsesInterrupts */
173  };
174
175  status = rtems_termios_open (major, minor, arg, &cb);
176
177  if(status != RTEMS_SUCCESSFUL)
178    {
179      printk("Error openning console device\n");
180      return status;
181    }
182
183  /*
184   * Pass data area info down to driver
185   */
186  BSP_uart_termios_set(BSPConsolePort,
187                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
188
189  /* Enable interrupts  on channel */
190  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
191
192  return RTEMS_SUCCESSFUL;
193}
194
195/*-------------------------------------------------------------------------+
196| Console device driver CLOSE entry point
197+--------------------------------------------------------------------------*/
198rtems_device_driver
199console_close(rtems_device_major_number major,
200              rtems_device_minor_number minor,
201              void                      *arg)
202{
203  rtems_device_driver res = RTEMS_SUCCESSFUL;
204
205  res =  rtems_termios_close (arg);
206
207  return res;
208} /* console_close */
209
210/*-------------------------------------------------------------------------+
211| Console device driver READ entry point.
212+--------------------------------------------------------------------------+
213| Read characters from the I/O console. We only have stdin.
214+--------------------------------------------------------------------------*/
215rtems_device_driver
216console_read(rtems_device_major_number major,
217             rtems_device_minor_number minor,
218             void                      *arg)
219{
220
221  return rtems_termios_read (arg);
222
223} /* console_read */
224
225/*-------------------------------------------------------------------------+
226| Console device driver WRITE entry point.
227+--------------------------------------------------------------------------+
228| Write characters to the I/O console. Stderr and stdout are the same.
229+--------------------------------------------------------------------------*/
230rtems_device_driver
231console_write(rtems_device_major_number major,
232              rtems_device_minor_number minor,
233              void                    * arg)
234{
235
236  return rtems_termios_write (arg);
237
238} /* console_write */
239
240/*
241 * Handle ioctl request.
242 */
243rtems_device_driver
244console_control(rtems_device_major_number major,
245                rtems_device_minor_number minor,
246                void                      * arg
247)
248{
249  return rtems_termios_ioctl (arg);
250}
251
252static int
253conSetAttr(int minor, const struct termios *t)
254{
255  int baud;
256
257  baud = termios_baud_to_number(t->c_cflag & CBAUD);
258  if ( baud > 115200 )
259    rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
260
261  BSP_uart_set_baud(BSPConsolePort, baud);
262
263  return 0;
264}
Note: See TracBrowser for help on using the repository browser.