1 | /* |
---|
2 | * This file contains the TTY driver for the serial ports on the DMV152. |
---|
3 | * The serial ports use a Zilog Z8530. |
---|
4 | * |
---|
5 | * NOTE: This driver uses the termios pseudo driver. |
---|
6 | * This driver is polled only. |
---|
7 | * |
---|
8 | * COPYRIGHT (c) 1989-1997. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * Copyright assigned to U.S. Government, 1994. |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.OARcorp.com/rtems/license.html. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #include <bsp.h> |
---|
20 | #include <rtems/libio.h> |
---|
21 | #include <stdlib.h> |
---|
22 | #include <assert.h> |
---|
23 | |
---|
24 | /* |
---|
25 | * console_outbyte_polled |
---|
26 | * |
---|
27 | * This routine transmits a character using polling. |
---|
28 | */ |
---|
29 | |
---|
30 | void console_outbyte_polled( |
---|
31 | int port, |
---|
32 | char ch |
---|
33 | ) |
---|
34 | { |
---|
35 | rtems_unsigned32 control; |
---|
36 | rtems_unsigned32 data; |
---|
37 | rtems_unsigned8 rr_0; |
---|
38 | |
---|
39 | if ( port == 0 ) { |
---|
40 | control = CONSOLE_CONTROL_A; |
---|
41 | data = CONSOLE_DATA_A; |
---|
42 | } else { |
---|
43 | control = CONSOLE_CONTROL_B; |
---|
44 | data = CONSOLE_DATA_B; |
---|
45 | } |
---|
46 | |
---|
47 | for ( ; ; ) { |
---|
48 | Z8x30_READ_CONTROL( control, RR_0, rr_0 ); |
---|
49 | if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 ) |
---|
50 | break; |
---|
51 | } |
---|
52 | |
---|
53 | Z8x30_WRITE_DATA( control, ch ); |
---|
54 | } |
---|
55 | |
---|
56 | /* |
---|
57 | * console_inbyte_nonblocking |
---|
58 | * |
---|
59 | * This routine polls for a character. |
---|
60 | */ |
---|
61 | |
---|
62 | int console_inbyte_nonblocking(int port) |
---|
63 | { |
---|
64 | rtems_unsigned32 control; |
---|
65 | rtems_unsigned32 data; |
---|
66 | rtems_unsigned8 rr_0; |
---|
67 | char ch; |
---|
68 | |
---|
69 | if ( port == 0 ) { |
---|
70 | control = CONSOLE_CONTROL_A; |
---|
71 | data = CONSOLE_DATA_A; |
---|
72 | } else { |
---|
73 | control = CONSOLE_CONTROL_B; |
---|
74 | data = CONSOLE_DATA_B; |
---|
75 | } |
---|
76 | |
---|
77 | Z8x30_READ_CONTROL( control, RR_0, rr_0 ); |
---|
78 | if ( !(rr_0 & RR_0_RX_DATA_AVAILABLE) ) |
---|
79 | return -1; |
---|
80 | |
---|
81 | Z8x30_READ_DATA( data, ch ); |
---|
82 | return (int) ch; |
---|
83 | } |
---|
84 | |
---|
85 | /* |
---|
86 | * DEBUG_puts |
---|
87 | * |
---|
88 | * This should be safe in the event of an error. It attempts to insure |
---|
89 | * that no TX empty interrupts occur while it is doing polled IO. Then |
---|
90 | * it restores the state of that external interrupt. |
---|
91 | * |
---|
92 | * Input parameters: |
---|
93 | * string - pointer to debug output string |
---|
94 | * |
---|
95 | * Output parameters: NONE |
---|
96 | * |
---|
97 | * Return values: NONE |
---|
98 | */ |
---|
99 | |
---|
100 | void DEBUG_puts( |
---|
101 | char *string |
---|
102 | ) |
---|
103 | { |
---|
104 | char *s; |
---|
105 | |
---|
106 | /* should disable interrupts here */ |
---|
107 | for ( s = string ; *s ; s++ ) |
---|
108 | console_outbyte_polled( 0, *s ); |
---|
109 | |
---|
110 | console_outbyte_polled( 0, '\r' ); |
---|
111 | console_outbyte_polled( 0, '\n' ); |
---|
112 | /* should enable interrupts here */ |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | /* |
---|
117 | * Console Termios Support Entry Points |
---|
118 | * |
---|
119 | */ |
---|
120 | |
---|
121 | int console_write_support (int minor, const char *buf, int len) |
---|
122 | { |
---|
123 | int nwrite = 0; |
---|
124 | |
---|
125 | while (nwrite < len) { |
---|
126 | console_outbyte_polled( minor, *buf++ ); |
---|
127 | nwrite++; |
---|
128 | } |
---|
129 | return nwrite; |
---|
130 | } |
---|
131 | |
---|
132 | void console_reserve_resources( |
---|
133 | rtems_configuration_table *configuration |
---|
134 | ) |
---|
135 | { |
---|
136 | rtems_termios_reserve_resources( configuration, 2 ); |
---|
137 | } |
---|
138 | |
---|
139 | /* |
---|
140 | * Console Device Driver Entry Points |
---|
141 | * |
---|
142 | */ |
---|
143 | |
---|
144 | rtems_device_driver console_initialize( |
---|
145 | rtems_device_major_number major, |
---|
146 | rtems_device_minor_number minor, |
---|
147 | void *arg |
---|
148 | ) |
---|
149 | { |
---|
150 | rtems_status_code status; |
---|
151 | rtems_device_minor_number console_minor; |
---|
152 | |
---|
153 | rtems_termios_initialize(); |
---|
154 | |
---|
155 | /* |
---|
156 | * Register Device Names |
---|
157 | */ |
---|
158 | |
---|
159 | #if (USE_CHANNEL_A == 1) |
---|
160 | console_minor = 0; |
---|
161 | #elif (USE_CHANNEL_B == 1) |
---|
162 | console_minor = 1; |
---|
163 | #else |
---|
164 | #error "DMV152 Console Driver -- no console port configured!!!" |
---|
165 | #endif |
---|
166 | |
---|
167 | status = rtems_io_register_name( "/dev/console", major, console_minor ); |
---|
168 | if (status != RTEMS_SUCCESSFUL) |
---|
169 | rtems_fatal_error_occurred(status); |
---|
170 | |
---|
171 | status = rtems_io_register_name( "/dev/console_a", major, 0 ); |
---|
172 | if (status != RTEMS_SUCCESSFUL) |
---|
173 | rtems_fatal_error_occurred(status); |
---|
174 | |
---|
175 | status = rtems_io_register_name( "/dev/console_b", major, 1 ); |
---|
176 | if (status != RTEMS_SUCCESSFUL) |
---|
177 | rtems_fatal_error_occurred(status); |
---|
178 | |
---|
179 | /* |
---|
180 | * Initialize Hardware |
---|
181 | */ |
---|
182 | |
---|
183 | return RTEMS_SUCCESSFUL; |
---|
184 | } |
---|
185 | |
---|
186 | rtems_device_driver console_open( |
---|
187 | rtems_device_major_number major, |
---|
188 | rtems_device_minor_number minor, |
---|
189 | void * arg |
---|
190 | ) |
---|
191 | { |
---|
192 | rtems_status_code sc; |
---|
193 | |
---|
194 | assert( minor <= 1 ); |
---|
195 | if ( minor > 2 ) |
---|
196 | return RTEMS_INVALID_NUMBER; |
---|
197 | |
---|
198 | sc = rtems_termios_open (major, minor, arg, |
---|
199 | NULL, |
---|
200 | NULL, |
---|
201 | console_inbyte_nonblocking, |
---|
202 | console_write_support, |
---|
203 | 0); |
---|
204 | |
---|
205 | return RTEMS_SUCCESSFUL; |
---|
206 | } |
---|
207 | |
---|
208 | rtems_device_driver console_close( |
---|
209 | rtems_device_major_number major, |
---|
210 | rtems_device_minor_number minor, |
---|
211 | void * arg |
---|
212 | ) |
---|
213 | { |
---|
214 | return rtems_termios_close (arg); |
---|
215 | } |
---|
216 | |
---|
217 | rtems_device_driver console_read( |
---|
218 | rtems_device_major_number major, |
---|
219 | rtems_device_minor_number minor, |
---|
220 | void * arg |
---|
221 | ) |
---|
222 | { |
---|
223 | return rtems_termios_read (arg); |
---|
224 | } |
---|
225 | |
---|
226 | rtems_device_driver console_write( |
---|
227 | rtems_device_major_number major, |
---|
228 | rtems_device_minor_number minor, |
---|
229 | void * arg |
---|
230 | ) |
---|
231 | { |
---|
232 | return rtems_termios_write (arg); |
---|
233 | } |
---|
234 | |
---|
235 | rtems_device_driver console_control( |
---|
236 | rtems_device_major_number major, |
---|
237 | rtems_device_minor_number minor, |
---|
238 | void * arg |
---|
239 | ) |
---|
240 | { |
---|
241 | return rtems_termios_ioctl (arg); |
---|
242 | } |
---|
243 | |
---|