1 | /* |
---|
2 | * This file contains the MVME147 console IO package. |
---|
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 | * MVME147 port for TNI - Telecom Bretagne |
---|
14 | * by Dominique LE CAMPION (Dominique.LECAMPION@enst-bretagne.fr) |
---|
15 | * May 1996 |
---|
16 | * |
---|
17 | * This file was taken from the DMV152 bsp |
---|
18 | */ |
---|
19 | |
---|
20 | #define M147_INIT |
---|
21 | |
---|
22 | #include <rtems/console.h> |
---|
23 | #include <rtems/libio.h> |
---|
24 | #include <rtems/zilog/z8530.h> |
---|
25 | #include <rtems/iosupp.h> |
---|
26 | #include <bsp.h> |
---|
27 | |
---|
28 | /* console_initialize |
---|
29 | * |
---|
30 | * This routine initializes the console IO driver. |
---|
31 | */ |
---|
32 | rtems_device_driver console_initialize( |
---|
33 | rtems_device_major_number major, |
---|
34 | rtems_device_minor_number minor, |
---|
35 | void *arg |
---|
36 | ) |
---|
37 | { |
---|
38 | rtems_status_code status; |
---|
39 | |
---|
40 | status = rtems_io_register_name( |
---|
41 | "/dev/console", |
---|
42 | major, |
---|
43 | (rtems_device_minor_number) 0 |
---|
44 | ); |
---|
45 | |
---|
46 | if (status != RTEMS_SUCCESSFUL) |
---|
47 | rtems_fatal_error_occurred(status); |
---|
48 | |
---|
49 | return RTEMS_SUCCESSFUL; |
---|
50 | } |
---|
51 | |
---|
52 | /* inbyte |
---|
53 | * |
---|
54 | * This routine reads a character from the SCC. |
---|
55 | */ |
---|
56 | static char inbyte( void ) |
---|
57 | { |
---|
58 | uint8_t rr_0; |
---|
59 | char ch; |
---|
60 | |
---|
61 | for ( ; ; ) { |
---|
62 | Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 ); |
---|
63 | if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) != 0 ) |
---|
64 | break; |
---|
65 | } |
---|
66 | |
---|
67 | Z8x30_READ_DATA( CONSOLE_DATA, ch ); |
---|
68 | return ( ch ); |
---|
69 | } |
---|
70 | |
---|
71 | /* outbyte |
---|
72 | * |
---|
73 | * This routine transmits a character out the SCC. It supports |
---|
74 | * XON/XOFF flow control. |
---|
75 | */ |
---|
76 | static void outbyte( |
---|
77 | char ch |
---|
78 | ) |
---|
79 | { |
---|
80 | uint8_t rr_0; |
---|
81 | char flow_control; |
---|
82 | |
---|
83 | for ( ; ; ) { |
---|
84 | Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 ); |
---|
85 | if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 ) |
---|
86 | break; |
---|
87 | } |
---|
88 | |
---|
89 | for ( ; ; ) { |
---|
90 | Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 ); |
---|
91 | if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 ) |
---|
92 | break; |
---|
93 | |
---|
94 | Z8x30_READ_DATA( CONSOLE_DATA, flow_control ); |
---|
95 | |
---|
96 | if ( flow_control == XOFF ) |
---|
97 | do { |
---|
98 | do { |
---|
99 | Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 ); |
---|
100 | } while ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 ); |
---|
101 | Z8x30_READ_DATA( CONSOLE_DATA, flow_control ); |
---|
102 | } while ( flow_control != XON ); |
---|
103 | } |
---|
104 | |
---|
105 | Z8x30_WRITE_DATA( CONSOLE_DATA, ch ); |
---|
106 | } |
---|
107 | |
---|
108 | /* |
---|
109 | * Open entry point |
---|
110 | */ |
---|
111 | rtems_device_driver console_open( |
---|
112 | rtems_device_major_number major, |
---|
113 | rtems_device_minor_number minor, |
---|
114 | void * arg |
---|
115 | ) |
---|
116 | { |
---|
117 | return RTEMS_SUCCESSFUL; |
---|
118 | } |
---|
119 | |
---|
120 | /* |
---|
121 | * Close entry point |
---|
122 | */ |
---|
123 | rtems_device_driver console_close( |
---|
124 | rtems_device_major_number major, |
---|
125 | rtems_device_minor_number minor, |
---|
126 | void * arg |
---|
127 | ) |
---|
128 | { |
---|
129 | return RTEMS_SUCCESSFUL; |
---|
130 | } |
---|
131 | |
---|
132 | /* |
---|
133 | * read bytes from the serial port. We only have stdin. |
---|
134 | */ |
---|
135 | rtems_device_driver console_read( |
---|
136 | rtems_device_major_number major, |
---|
137 | rtems_device_minor_number minor, |
---|
138 | void * arg |
---|
139 | ) |
---|
140 | { |
---|
141 | rtems_libio_rw_args_t *rw_args; |
---|
142 | char *buffer; |
---|
143 | int maximum; |
---|
144 | int count = 0; |
---|
145 | |
---|
146 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
147 | |
---|
148 | buffer = rw_args->buffer; |
---|
149 | maximum = rw_args->count; |
---|
150 | |
---|
151 | for (count = 0; count < maximum; count++) { |
---|
152 | buffer[ count ] = inbyte(); |
---|
153 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
154 | buffer[ count++ ] = '\n'; |
---|
155 | break; |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | rw_args->bytes_moved = count; |
---|
160 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
161 | } |
---|
162 | |
---|
163 | /* |
---|
164 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
165 | */ |
---|
166 | rtems_device_driver console_write( |
---|
167 | rtems_device_major_number major, |
---|
168 | rtems_device_minor_number minor, |
---|
169 | void * arg |
---|
170 | ) |
---|
171 | { |
---|
172 | int count; |
---|
173 | int maximum; |
---|
174 | rtems_libio_rw_args_t *rw_args; |
---|
175 | char *buffer; |
---|
176 | |
---|
177 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
178 | |
---|
179 | buffer = rw_args->buffer; |
---|
180 | maximum = rw_args->count; |
---|
181 | |
---|
182 | for (count = 0; count < maximum; count++) { |
---|
183 | if ( buffer[ count ] == '\n') { |
---|
184 | outbyte('\r'); |
---|
185 | } |
---|
186 | outbyte( buffer[ count ] ); |
---|
187 | } |
---|
188 | |
---|
189 | rw_args->bytes_moved = maximum; |
---|
190 | return 0; |
---|
191 | } |
---|
192 | |
---|
193 | /* |
---|
194 | * IO Control entry point |
---|
195 | */ |
---|
196 | rtems_device_driver console_control( |
---|
197 | rtems_device_major_number major, |
---|
198 | rtems_device_minor_number minor, |
---|
199 | void * arg |
---|
200 | ) |
---|
201 | { |
---|
202 | return RTEMS_SUCCESSFUL; |
---|
203 | } |
---|