source: rtems/c/src/lib/libbsp/lm32/shared/milkymist_console/console.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 *  Console driver for Milkymist
3 *
4 *  The license and distribution terms for this file may be
5 *  found in the file LICENSE in this distribution or at
6 *  http://www.rtems.com/license/LICENSE.
7 *
8 *  COPYRIGHT (c) 2010 Sebastien Bourdeauducq
9 */
10
11#include <unistd.h>
12#include <termios.h>
13
14#include <rtems.h>
15#include <rtems/libio.h>
16#include <rtems/console.h>
17#include <rtems/termiostypes.h>
18#include <bsp/irq-generic.h>
19
20#include "../include/system_conf.h"
21#include "uart.h"
22
23BSP_output_char_function_type BSP_output_char = BSP_uart_polled_write;
24BSP_polling_getchar_function_type BSP_poll_char = BSP_uart_polled_read;
25
26static struct rtems_termios_tty *tty;
27
28static int mmconsole_first_open(int major, int minor, void *arg)
29{
30  tty = ((rtems_libio_open_close_args_t *) arg)->iop->data1;
31  return rtems_termios_set_initial_baud(tty, UART_BAUD_RATE);
32}
33
34static int mmconsole_last_close(int major, int minor, void *arg)
35{
36  return 0;
37}
38
39static int mmconsole_set_attributes(int minor, const struct termios *t)
40{
41  int baud;
42
43  switch (t->c_cflag & CBAUD) {
44    case B0:
45      baud = 0;
46      break;
47    case B50:
48      baud = 50;
49      break;
50    case B75:
51      baud = 75;
52      break;
53    case B110:
54      baud = 110;
55      break;
56    case B134:
57      baud = 134;
58      break;
59    case B150:
60      baud = 150;
61      break;
62    case B200:
63      baud = 200;
64      break;
65    case B300:
66      baud = 300;
67      break;
68    case B600:
69      baud = 600;
70      break;
71    case B1200:
72      baud = 1200;
73      break;
74    case B1800:
75      baud = 1800;
76      break;
77    case B2400:
78      baud = 2400;
79      break;
80    case B4800:
81      baud = 4800;
82      break;
83    case B9600:
84      baud = 9600;
85      break;
86    case B19200:
87      baud = 19200;
88      break;
89    case B38400:
90      baud = 38400;
91      break;
92    case B57600:
93      baud = 57600;
94      break;
95    case B115200:
96      baud = 115200;
97      break;
98    case B230400:
99      baud = 230400;
100      break;
101    case B460800:
102      baud = 460800;
103      break;
104    default:
105      baud = -1;
106      break;
107  }
108
109  if (baud > 0)
110    MM_WRITE(MM_UART_DIV, MM_READ(MM_FREQUENCY)/baud/16);
111
112  return 0;
113}
114
115static ssize_t mmconsole_write(int minor, const char *buf, size_t n)
116{
117  rtems_interrupt_level level;
118
119  rtems_interrupt_disable(level);
120  MM_WRITE(MM_UART_RXTX, *buf);
121  rtems_interrupt_enable(level);
122  return 0;
123}
124
125static rtems_isr mmconsole_interrupt(rtems_vector_number n)
126{
127  char c;
128  while (MM_READ(MM_UART_STAT) & UART_STAT_RX_EVT) {
129    c = MM_READ(MM_UART_RXTX);
130    MM_WRITE(MM_UART_STAT, UART_STAT_RX_EVT);
131    rtems_termios_enqueue_raw_characters(tty, &c, 1);
132  }
133  if (MM_READ(MM_UART_STAT) & UART_STAT_TX_EVT) {
134    MM_WRITE(MM_UART_STAT, UART_STAT_TX_EVT);
135    rtems_termios_dequeue_characters(tty, 1);
136  }
137  lm32_interrupt_ack(1 << MM_IRQ_UART);
138}
139
140static const rtems_termios_callbacks mmconsole_callbacks = {
141  .firstOpen = mmconsole_first_open,
142  .lastClose = mmconsole_last_close,
143  .pollRead = NULL,
144  .write = mmconsole_write,
145  .setAttributes = mmconsole_set_attributes,
146  .stopRemoteTx = NULL,
147  .startRemoteTx = NULL,
148  .outputUsesInterrupts = TERMIOS_IRQ_DRIVEN
149};
150
151rtems_device_driver console_initialize(
152  rtems_device_major_number major,
153  rtems_device_minor_number minor,
154  void *arg
155)
156{
157  rtems_status_code status;
158  rtems_isr_entry dummy;
159
160  rtems_termios_initialize();
161
162  status = rtems_io_register_name("/dev/console", major, 0);
163  if (status != RTEMS_SUCCESSFUL)
164    rtems_fatal_error_occurred(status);
165
166  rtems_interrupt_catch(mmconsole_interrupt, MM_IRQ_UART, &dummy);
167  bsp_interrupt_vector_enable(MM_IRQ_UART);
168  MM_WRITE(MM_UART_CTRL, UART_CTRL_RX_INT|UART_CTRL_TX_INT);
169
170  return RTEMS_SUCCESSFUL;
171}
172
173rtems_device_driver console_open(
174  rtems_device_major_number major,
175  rtems_device_minor_number minor,
176  void  *arg
177)
178{
179  return rtems_termios_open(major, minor, arg, &mmconsole_callbacks);
180}
181
182rtems_device_driver console_close(
183  rtems_device_major_number major,
184  rtems_device_minor_number minor,
185  void *arg
186)
187{
188  return rtems_termios_close(arg);
189}
190
191rtems_device_driver console_read(
192  rtems_device_major_number major,
193  rtems_device_minor_number minor,
194  void *arg
195)
196{
197  return rtems_termios_read(arg);
198}
199
200rtems_device_driver console_write(
201  rtems_device_major_number major,
202  rtems_device_minor_number minor,
203  void *arg
204)
205{
206  return rtems_termios_write(arg);
207}
208
209rtems_device_driver console_control(
210  rtems_device_major_number major,
211  rtems_device_minor_number minor,
212  void *arg
213)
214{
215  return rtems_termios_ioctl(arg);
216}
Note: See TracBrowser for help on using the repository browser.