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 <rtems.h> |
---|
20 | #include <bsp.h> |
---|
21 | #include <rtems/libio.h> |
---|
22 | |
---|
23 | void BSP_uart_polled_write(char ch); |
---|
24 | int BSP_uart_polled_read( void ); |
---|
25 | char BSP_uart_is_character_ready(char *ch); |
---|
26 | |
---|
27 | /* console_initialize |
---|
28 | * |
---|
29 | * This routine initializes the console IO driver. |
---|
30 | */ |
---|
31 | rtems_device_driver console_initialize( |
---|
32 | rtems_device_major_number major, |
---|
33 | rtems_device_minor_number minor, |
---|
34 | void *arg |
---|
35 | ) |
---|
36 | { |
---|
37 | rtems_status_code status; |
---|
38 | |
---|
39 | printk("console_initialize\n"); |
---|
40 | |
---|
41 | status = rtems_io_register_name( |
---|
42 | "/dev/console", |
---|
43 | major, |
---|
44 | (rtems_device_minor_number) 0 |
---|
45 | ); |
---|
46 | |
---|
47 | if (status != RTEMS_SUCCESSFUL) |
---|
48 | rtems_fatal_error_occurred(status); |
---|
49 | |
---|
50 | return RTEMS_SUCCESSFUL; |
---|
51 | } |
---|
52 | |
---|
53 | /* inbyte |
---|
54 | * |
---|
55 | * This routine reads a character from the SOURCE. |
---|
56 | */ |
---|
57 | static int inbyte( void ) |
---|
58 | { |
---|
59 | /* |
---|
60 | * If polling, wait until a character is available. |
---|
61 | */ |
---|
62 | |
---|
63 | return BSP_uart_polled_read(); |
---|
64 | } |
---|
65 | |
---|
66 | /* outbyte |
---|
67 | * |
---|
68 | * This routine transmits a character out the SOURCE. It may support |
---|
69 | * XON/XOFF flow control. |
---|
70 | */ |
---|
71 | static void outbyte( |
---|
72 | char ch |
---|
73 | ) |
---|
74 | { |
---|
75 | /* |
---|
76 | * If polling, wait for the transmitter to be ready. |
---|
77 | * Check for flow control requests and process. |
---|
78 | * Then output the character. |
---|
79 | */ |
---|
80 | |
---|
81 | BSP_uart_polled_write(ch); |
---|
82 | } |
---|
83 | |
---|
84 | /* |
---|
85 | * Open entry point |
---|
86 | */ |
---|
87 | rtems_device_driver console_open( |
---|
88 | rtems_device_major_number major, |
---|
89 | rtems_device_minor_number minor, |
---|
90 | void * arg |
---|
91 | ) |
---|
92 | { |
---|
93 | return RTEMS_SUCCESSFUL; |
---|
94 | } |
---|
95 | |
---|
96 | /* |
---|
97 | * Close entry point |
---|
98 | */ |
---|
99 | rtems_device_driver console_close( |
---|
100 | rtems_device_major_number major, |
---|
101 | rtems_device_minor_number minor, |
---|
102 | void * arg |
---|
103 | ) |
---|
104 | { |
---|
105 | return RTEMS_SUCCESSFUL; |
---|
106 | } |
---|
107 | |
---|
108 | /* |
---|
109 | * read bytes from the serial port. We only have stdin. |
---|
110 | */ |
---|
111 | rtems_device_driver console_read( |
---|
112 | rtems_device_major_number major, |
---|
113 | rtems_device_minor_number minor, |
---|
114 | void * arg |
---|
115 | ) |
---|
116 | { |
---|
117 | rtems_libio_rw_args_t *rw_args; |
---|
118 | char *buffer; |
---|
119 | int maximum; |
---|
120 | int count = 0; |
---|
121 | |
---|
122 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
123 | |
---|
124 | buffer = rw_args->buffer; |
---|
125 | maximum = rw_args->count; |
---|
126 | |
---|
127 | for (count = 0; count < maximum; count++) { |
---|
128 | buffer[ count ] = inbyte(); |
---|
129 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
130 | buffer[ count++ ] = '\n'; |
---|
131 | break; |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | rw_args->bytes_moved = count; |
---|
136 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
137 | } |
---|
138 | |
---|
139 | /* |
---|
140 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
141 | */ |
---|
142 | rtems_device_driver console_write( |
---|
143 | rtems_device_major_number major, |
---|
144 | rtems_device_minor_number minor, |
---|
145 | void * arg |
---|
146 | ) |
---|
147 | { |
---|
148 | int count; |
---|
149 | int maximum; |
---|
150 | rtems_libio_rw_args_t *rw_args; |
---|
151 | char *buffer; |
---|
152 | |
---|
153 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
154 | |
---|
155 | buffer = rw_args->buffer; |
---|
156 | maximum = rw_args->count; |
---|
157 | |
---|
158 | for (count = 0; count < maximum; count++) { |
---|
159 | if ( buffer[ count ] == '\n') { |
---|
160 | outbyte('\r'); |
---|
161 | } |
---|
162 | outbyte( buffer[ count ] ); |
---|
163 | } |
---|
164 | |
---|
165 | rw_args->bytes_moved = maximum; |
---|
166 | return 0; |
---|
167 | } |
---|
168 | |
---|
169 | /* |
---|
170 | * IO Control entry point |
---|
171 | */ |
---|
172 | rtems_device_driver console_control( |
---|
173 | rtems_device_major_number major, |
---|
174 | rtems_device_minor_number minor, |
---|
175 | void * arg |
---|
176 | ) |
---|
177 | { |
---|
178 | return RTEMS_SUCCESSFUL; |
---|
179 | } |
---|
180 | |
---|
181 | BSP_output_char_function_type BSP_output_char = BSP_uart_polled_write; |
---|
182 | BSP_polling_getchar_function_type BSP_poll_char = BSP_uart_polled_read; |
---|