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

4.104.11
Last change on this file since b1783062 was b1783062, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 4, 2008 at 10:55:13 PM

2008-12-04 Jukka Pietarinen <jukka.pietarinen@…>

  • ChangeLog?, Makefile.am, README, acinclude.m4, configure.ac, shared/clock/ckinit.c, shared/clock/clock.h, shared/console/console.c, shared/console/uart.c, shared/console/uart.h, shared/start/start.S, shared/startup/bspstart.c, shared/startup/setvec.c, shared/timer/timer.c, shared/tsmac/dp83848phy.h, shared/tsmac/tsmac.c, shared/tsmac/tsmac.h: New files.
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 *  Console driver for Lattice Mico32 (lm32).
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 *
13 *  Jukka Pietarinen <jukka.pietarinen@mrf.fi>, 2008,
14 *  Micro-Research Finland Oy
15 */
16
17#define NO_BSP_INIT
18
19#include <rtems.h>
20#include <bsp.h>
21#include <rtems/libio.h>
22
23void BSP_uart_polled_write(char ch);
24char BSP_uart_polled_read( void );
25char BSP_uart_is_character_ready(char *ch);
26
27/*  console_initialize
28 *
29 *  This routine initializes the console IO driver.
30 *
31 *  Input parameters: NONE
32 *
33 *  Output parameters:  NONE
34 *
35 *  Return values:
36 */
37
38rtems_device_driver console_initialize(
39  rtems_device_major_number  major,
40  rtems_device_minor_number  minor,
41  void                      *arg
42)
43{
44  rtems_status_code status;
45
46  printk("console_initialize\n");
47
48  status = rtems_io_register_name(
49    "/dev/console",
50    major,
51    (rtems_device_minor_number) 0
52  );
53
54  if (status != RTEMS_SUCCESSFUL)
55    rtems_fatal_error_occurred(status);
56
57  return RTEMS_SUCCESSFUL;
58}
59
60/*  is_character_ready
61 *
62 *  This routine returns TRUE if a character is available.
63 *
64 *  Input parameters: NONE
65 *
66 *  Output parameters:  NONE
67 *
68 *  Return values:
69 */
70
71bool is_character_ready(
72  char *ch
73)
74{
75  return BSP_uart_is_character_ready(ch);
76}
77
78/*  inbyte
79 *
80 *  This routine reads a character from the SOURCE.
81 *
82 *  Input parameters: NONE
83 *
84 *  Output parameters:  NONE
85 *
86 *  Return values:
87 *    character read from SOURCE
88 */
89
90char inbyte( void )
91{
92  /*
93   *  If polling, wait until a character is available.
94   */
95
96  return (char) BSP_uart_polled_read();
97}
98
99/*  outbyte
100 *
101 *  This routine transmits a character out the SOURCE.  It may support
102 *  XON/XOFF flow control.
103 *
104 *  Input parameters:
105 *    ch  - character to be transmitted
106 *
107 *  Output parameters:  NONE
108 */
109
110void outbyte(
111  char ch
112)
113{
114  /*
115   *  If polling, wait for the transmitter to be ready.
116   *  Check for flow control requests and process.
117   *  Then output the character.
118   */
119
120  BSP_uart_polled_write(ch);
121}
122
123/*
124 *  Open entry point
125 */
126
127rtems_device_driver console_open(
128  rtems_device_major_number major,
129  rtems_device_minor_number minor,
130  void                    * arg
131)
132{
133  return RTEMS_SUCCESSFUL;
134}
135
136/*
137 *  Close entry point
138 */
139
140rtems_device_driver console_close(
141  rtems_device_major_number major,
142  rtems_device_minor_number minor,
143  void                    * arg
144)
145{
146  return RTEMS_SUCCESSFUL;
147}
148
149/*
150 * read bytes from the serial port. We only have stdin.
151 */
152
153rtems_device_driver console_read(
154  rtems_device_major_number major,
155  rtems_device_minor_number minor,
156  void                    * arg
157)
158{
159  rtems_libio_rw_args_t *rw_args;
160  char *buffer;
161  int maximum;
162  int count = 0;
163
164  rw_args = (rtems_libio_rw_args_t *) arg;
165
166  buffer = rw_args->buffer;
167  maximum = rw_args->count;
168
169  for (count = 0; count < maximum; count++) {
170    buffer[ count ] = inbyte();
171    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
172      buffer[ count++ ]  = '\n';
173      break;
174    }
175  }
176
177  rw_args->bytes_moved = count;
178  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
179}
180
181/*
182 * write bytes to the serial port. Stdout and stderr are the same.
183 */
184
185rtems_device_driver console_write(
186  rtems_device_major_number major,
187  rtems_device_minor_number minor,
188  void                    * arg
189)
190{
191  int count;
192  int maximum;
193  rtems_libio_rw_args_t *rw_args;
194  char *buffer;
195
196  rw_args = (rtems_libio_rw_args_t *) arg;
197
198  buffer = rw_args->buffer;
199  maximum = rw_args->count;
200
201  for (count = 0; count < maximum; count++) {
202    if ( buffer[ count ] == '\n') {
203      outbyte('\r');
204    }
205    outbyte( buffer[ count ] );
206  }
207
208  rw_args->bytes_moved = maximum;
209  return 0;
210}
211
212/*
213 *  IO Control entry point
214 */
215
216rtems_device_driver console_control(
217  rtems_device_major_number major,
218  rtems_device_minor_number minor,
219  void                    * arg
220)
221{
222  return RTEMS_SUCCESSFUL;
223}
224
225BSP_output_char_function_type BSP_output_char = BSP_uart_polled_write;
226BSP_polling_getchar_function_type BSP_poll_char = BSP_uart_polled_read;
Note: See TracBrowser for help on using the repository browser.