source: rtems/c/src/lib/libbsp/lm32/shared/console/console.c @ c2e32ff

4.115
Last change on this file since c2e32ff was c2e32ff, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 20, 2014 at 2:25:41 PM

lm32 BSP shared and lm32_evr: Fix BSPs

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 *  Console driver for Lattice Mico32 (lm32).
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-1999.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.org/license/LICENSE.
12 *
13 *  Jukka Pietarinen <jukka.pietarinen@mrf.fi>, 2008,
14 *  Micro-Research Finland Oy
15 */
16
17#define NO_BSP_INIT
18
19#include <bsp.h>
20#include <rtems/libio.h>
21
22/*  console_initialize
23 *
24 *  This routine initializes the console IO driver.
25 */
26rtems_device_driver console_initialize(
27  rtems_device_major_number  major,
28  rtems_device_minor_number  minor,
29  void                      *arg
30)
31{
32  rtems_status_code status;
33
34  printk("console_initialize\n");
35
36  status = rtems_io_register_name(
37    "/dev/console",
38    major,
39    (rtems_device_minor_number) 0
40  );
41
42  if (status != RTEMS_SUCCESSFUL)
43    rtems_fatal_error_occurred(status);
44
45  return RTEMS_SUCCESSFUL;
46}
47
48/*  inbyte
49 *
50 *  This routine reads a character from the SOURCE.
51 */
52static int inbyte( void )
53{
54  /*
55   *  If polling, wait until a character is available.
56   */
57  return BSP_uart_polled_read();
58}
59
60/*  outbyte
61 *
62 *  This routine transmits a character out the SOURCE.  It may support
63 *  XON/XOFF flow control.
64 */
65static void outbyte(
66  char ch
67)
68{
69  /*
70   *  If polling, wait for the transmitter to be ready.
71   *  Check for flow control requests and process.
72   *  Then output the character.
73   */
74
75  BSP_uart_polled_write(ch);
76}
77
78/*
79 *  Open entry point
80 */
81rtems_device_driver console_open(
82  rtems_device_major_number major,
83  rtems_device_minor_number minor,
84  void                    * arg
85)
86{
87  return RTEMS_SUCCESSFUL;
88}
89
90/*
91 *  Close entry point
92 */
93rtems_device_driver console_close(
94  rtems_device_major_number major,
95  rtems_device_minor_number minor,
96  void                    * arg
97)
98{
99  return RTEMS_SUCCESSFUL;
100}
101
102/*
103 * read bytes from the serial port. We only have stdin.
104 */
105rtems_device_driver console_read(
106  rtems_device_major_number major,
107  rtems_device_minor_number minor,
108  void                    * arg
109)
110{
111  rtems_libio_rw_args_t *rw_args;
112  char *buffer;
113  int maximum;
114  int count = 0;
115
116  rw_args = (rtems_libio_rw_args_t *) arg;
117
118  buffer = rw_args->buffer;
119  maximum = rw_args->count;
120
121  for (count = 0; count < maximum; count++) {
122    buffer[ count ] = inbyte();
123    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
124      buffer[ count++ ]  = '\n';
125      break;
126    }
127  }
128
129  rw_args->bytes_moved = count;
130  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
131}
132
133/*
134 * write bytes to the serial port. Stdout and stderr are the same.
135 */
136rtems_device_driver console_write(
137  rtems_device_major_number major,
138  rtems_device_minor_number minor,
139  void                    * arg
140)
141{
142  int count;
143  int maximum;
144  rtems_libio_rw_args_t *rw_args;
145  char *buffer;
146
147  rw_args = (rtems_libio_rw_args_t *) arg;
148
149  buffer = rw_args->buffer;
150  maximum = rw_args->count;
151
152  for (count = 0; count < maximum; count++) {
153    if ( buffer[ count ] == '\n') {
154      outbyte('\r');
155    }
156    outbyte( buffer[ count ] );
157  }
158
159  rw_args->bytes_moved = maximum;
160  return 0;
161}
162
163/*
164 *  IO Control entry point
165 */
166rtems_device_driver console_control(
167  rtems_device_major_number major,
168  rtems_device_minor_number minor,
169  void                    * arg
170)
171{
172  return RTEMS_SUCCESSFUL;
173}
174
175BSP_output_char_function_type BSP_output_char = BSP_uart_polled_write;
176BSP_polling_getchar_function_type BSP_poll_char = BSP_uart_polled_read;
Note: See TracBrowser for help on using the repository browser.