1 | /* |
---|
2 | * This file contains the MVME136 console IO package. |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-1998. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * Copyright assigned to U.S. Government, 1994. |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #define M136_INIT |
---|
16 | |
---|
17 | #include <bsp.h> |
---|
18 | #include <rtems/libio.h> |
---|
19 | |
---|
20 | /* console_initialize |
---|
21 | * |
---|
22 | * This routine initializes the console IO driver. |
---|
23 | * |
---|
24 | * Input parameters: NONE |
---|
25 | * |
---|
26 | * Output parameters: NONE |
---|
27 | * |
---|
28 | * Return values: |
---|
29 | */ |
---|
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 | _Write_m681 = ( struct w_m681_info * ) M681ADDR; |
---|
40 | _Read_m681 = ( struct r_m681_info * ) M681ADDR; |
---|
41 | |
---|
42 | status = rtems_io_register_name( |
---|
43 | "/dev/console", |
---|
44 | major, |
---|
45 | (rtems_device_minor_number) 0 |
---|
46 | ); |
---|
47 | |
---|
48 | if (status != RTEMS_SUCCESSFUL) |
---|
49 | rtems_fatal_error_occurred(status); |
---|
50 | |
---|
51 | return RTEMS_SUCCESSFUL; |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | /* is_character_ready |
---|
56 | * |
---|
57 | * This routine returns TRUE if a character is available. |
---|
58 | * |
---|
59 | * Input parameters: NONE |
---|
60 | * |
---|
61 | * Output parameters: NONE |
---|
62 | * |
---|
63 | * Return values: |
---|
64 | */ |
---|
65 | |
---|
66 | rtems_boolean is_character_ready( |
---|
67 | char *ch |
---|
68 | ) |
---|
69 | { |
---|
70 | if ( !(_Read_m681->srb & RXRDYB) ) |
---|
71 | return(FALSE); |
---|
72 | |
---|
73 | *ch = _Read_m681->rbb; |
---|
74 | return(TRUE); |
---|
75 | } |
---|
76 | |
---|
77 | /* inbyte |
---|
78 | * |
---|
79 | * This routine reads a character from the UART. |
---|
80 | * |
---|
81 | * Input parameters: NONE |
---|
82 | * |
---|
83 | * Output parameters: NONE |
---|
84 | * |
---|
85 | * Return values: |
---|
86 | * character read from UART |
---|
87 | */ |
---|
88 | |
---|
89 | char inbyte( void ) |
---|
90 | { |
---|
91 | while ( !(_Read_m681->srb & RXRDYB) ); |
---|
92 | return _Read_m681->rbb; |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | /* outbyte |
---|
97 | * |
---|
98 | * This routine transmits a character out the M68681. It supports |
---|
99 | * XON/XOFF flow control. |
---|
100 | * |
---|
101 | * Input parameters: |
---|
102 | * ch - character to be transmitted |
---|
103 | * |
---|
104 | * Output parameters: NONE |
---|
105 | */ |
---|
106 | |
---|
107 | void outbyte( |
---|
108 | char ch |
---|
109 | ) |
---|
110 | { |
---|
111 | while ( ! (_Read_m681->srb & TXRDYB) ) ; |
---|
112 | while ( _Read_m681->srb & RXRDYB ) /* must be an XOFF */ |
---|
113 | if ( _Read_m681->rbb == XOFF ) |
---|
114 | do { |
---|
115 | while ( ! (_Read_m681->srb & RXRDYB) ) ; |
---|
116 | } while ( _Read_m681->rbb != XON ); |
---|
117 | |
---|
118 | _Write_m681->tbb = ch; |
---|
119 | if ( ch == '\n' ) |
---|
120 | outbyte( CR ); |
---|
121 | } |
---|
122 | |
---|
123 | /* |
---|
124 | * Open entry point |
---|
125 | */ |
---|
126 | |
---|
127 | rtems_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 | |
---|
140 | rtems_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 | |
---|
153 | rtems_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 | |
---|
185 | rtems_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 | |
---|
216 | rtems_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 | } |
---|