source: rtems/c/src/lib/libbsp/lm32/shared/milkymist_console/console.c @ 1c6926c1

Last change on this file since 1c6926c1 was 1c6926c1, checked in by Kevin Kirspel <kevin-kirspel@…>, on Mar 21, 2017 at 7:39:48 PM

termios: Synchronize with latest FreeBSD headers

Adding modified FreeBSD headers to synchronize RTEMS termios with
FreeBSD. Modify termios to support dedicated input and output baud for
termios structure. Updated BSPs to use dedicated input and output baud
in termios structure. Updated tools to use dedicated input and output
baud in termios structure. Updated termios testsuites to use dedicated
input and output baud in termios structure.

Close #2897.

  • 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.org/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/bspIo.h>
16#include <rtems/libio.h>
17#include <rtems/console.h>
18#include <rtems/termiostypes.h>
19#include <bsp/irq-generic.h>
20
21#include "../include/system_conf.h"
22#include "uart.h"
23
24BSP_output_char_function_type BSP_output_char = BSP_uart_polled_write;
25BSP_polling_getchar_function_type BSP_poll_char = BSP_uart_polled_read;
26
27static struct rtems_termios_tty *tty;
28
29static int mmconsole_first_open(int major, int minor, void *arg)
30{
31  tty = ((rtems_libio_open_close_args_t *) arg)->iop->data1;
32  return rtems_termios_set_initial_baud(tty, UART_BAUD_RATE);
33}
34
35static int mmconsole_last_close(int major, int minor, void *arg)
36{
37  return 0;
38}
39
40static int mmconsole_set_attributes(int minor, const struct termios *t)
41{
42  int baud;
43
44  switch (t->c_ospeed) {
45    case B0:
46      baud = 0;
47      break;
48    case B50:
49      baud = 50;
50      break;
51    case B75:
52      baud = 75;
53      break;
54    case B110:
55      baud = 110;
56      break;
57    case B134:
58      baud = 134;
59      break;
60    case B150:
61      baud = 150;
62      break;
63    case B200:
64      baud = 200;
65      break;
66    case B300:
67      baud = 300;
68      break;
69    case B600:
70      baud = 600;
71      break;
72    case B1200:
73      baud = 1200;
74      break;
75    case B1800:
76      baud = 1800;
77      break;
78    case B2400:
79      baud = 2400;
80      break;
81    case B4800:
82      baud = 4800;
83      break;
84    case B9600:
85      baud = 9600;
86      break;
87    case B19200:
88      baud = 19200;
89      break;
90    case B38400:
91      baud = 38400;
92      break;
93    case B57600:
94      baud = 57600;
95      break;
96    case B115200:
97      baud = 115200;
98      break;
99    case B230400:
100      baud = 230400;
101      break;
102    case B460800:
103      baud = 460800;
104      break;
105    default:
106      baud = -1;
107      break;
108  }
109
110  if (baud > 0)
111    MM_WRITE(MM_UART_DIV, MM_READ(MM_FREQUENCY)/baud/16);
112
113  return 0;
114}
115
116static ssize_t mmconsole_write(int minor, const char *buf, size_t n)
117{
118  if (n > 0) {
119    MM_WRITE(MM_UART_RXTX, *buf);
120  }
121
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.