1 | /* |
---|
2 | * console.c |
---|
3 | * |
---|
4 | * This file contains the MVME167 termios console package. Only asynchronous |
---|
5 | * I/O is supported. |
---|
6 | * |
---|
7 | * /dev/tty0 is channel 0, Serial Port 1/Console on the MVME712M. |
---|
8 | * /dev/tty1 is channel 1, Serial Port 2/TTY01 on the MVME712M. |
---|
9 | * /dev/tty2 is channel 2, Serial Port 3 on the MVME712M. |
---|
10 | * /dev/tty3 is channel 3, Serial Port 4 on the MVME712M. |
---|
11 | * |
---|
12 | * Normal I/O uses DMA for output, interrupts for input. /dev/console is |
---|
13 | * fixed to be /dev/tty01, Serial Port 2. Very limited support is provided |
---|
14 | * for polled I/O. Polled I/O is intended only for running the RTEMS test |
---|
15 | * suites. In all cases, Serial Port 1/Console is allocated to 167Bug and |
---|
16 | * is the dedicated debugger port. We configure GDB to use 167Bug for |
---|
17 | * debugging. When debugging with GDB or 167Bug, do not open /dev/tty00. |
---|
18 | * |
---|
19 | * Modern I/O chips often contain a number of I/O devices that can operate |
---|
20 | * almost independently of each other. Typically, in RTEMS, all devices in |
---|
21 | * an I/O chip are handled by a single device driver, but that need not be |
---|
22 | * always the case. Each device driver must supply six entry points in the |
---|
23 | * Device Driver Table: a device initialization function, as well as an open, |
---|
24 | * close, read, write and a control function. RTEMS assigns a device major |
---|
25 | * number to each device driver. This major device number is the index of the |
---|
26 | * device driver entries in the Device Driver Table, and it used to identify |
---|
27 | * a particular device driver. To distinguish multiple I/O sub-devices within |
---|
28 | * an I/O chip, RTEMS supports device minor numbers. When a I/O device is |
---|
29 | * initialized, the major number is supplied to the initialization function. |
---|
30 | * That function must register each sub-device with a separate name and minor |
---|
31 | * number (as well as the supplied major number). When an application opens a |
---|
32 | * device by name, the corresponding major and minor numbers are returned to |
---|
33 | * the caller to be used in subsequent I/O operations (although these details |
---|
34 | * are typically hidden within the library functions). |
---|
35 | * |
---|
36 | * Such a scheme recognizes that the initialization of the individual |
---|
37 | * sub-devices is generally not completely independent. For example, the |
---|
38 | * four serial ports of the CD2401 can be configured almost independently |
---|
39 | * from each other. One port could be configured to operate in asynchronous |
---|
40 | * mode with interrupt-driven I/O, while another port could be configured to |
---|
41 | * operate in HDLC mode with DMA I/O. However, a device reset command will |
---|
42 | * reset all four channels, and the width of DMA transfers and the number of |
---|
43 | * retries following bus errors selected applies to all four channels. |
---|
44 | * Consequently, when initializing one channel, one must be careful not to |
---|
45 | * destroy the configuration of other channels that are already configured. |
---|
46 | * |
---|
47 | * One problem with the RTEMS I/O initialization model is that no information |
---|
48 | * other than a device major number is passed to the initialization function. |
---|
49 | * Consequently, the sub-devices must be initialized with some pre-determined |
---|
50 | * configuration. To change the configuration of a sub-device, it is |
---|
51 | * necessary to either rewrite the initialization function, or to make a |
---|
52 | * series of rtems_io_control() calls after initialization. The first |
---|
53 | * approach is not very elegant. The second approach is acceptable if an |
---|
54 | * application is simply changing baud rates, parity or other such |
---|
55 | * asynchronous parameters (as supplied by the termios package). But what if |
---|
56 | * an application requires one channel to run in HDLC or Bisync mode and |
---|
57 | * another in async mode? With a single driver per I/O chip approach, the |
---|
58 | * device driver must support multiple protocols. This is feasible, but it |
---|
59 | * often means that an application that only does asynchronous I/O now links |
---|
60 | * in code for other unused protocols, thus wasting precious ROM space. |
---|
61 | * Worse, it requires that the sub-devices be initialized in some |
---|
62 | * configuration, and that configuration then changed through a series of |
---|
63 | * device driver control calls. There is no standard API in RTEMS to switch |
---|
64 | * a serial line to some synchronous protocol. |
---|
65 | * |
---|
66 | * A better approach is to treat each channel as a separate device, each with |
---|
67 | * its own device device driver. The application then supplies its own device |
---|
68 | * driver table with only the required protocols (drivers) on each line. The |
---|
69 | * problem with this approach is that the device drivers are not really |
---|
70 | * independent, given that the I/O sub-devices within a common chip are not |
---|
71 | * independent themselves. Consequently, the related device drivers must |
---|
72 | * share some information. In RTEMS, there is no standard location in which |
---|
73 | * to share information. |
---|
74 | * |
---|
75 | * This driver handles all four channels, i.e. it distinguishes the |
---|
76 | * sub-devices using minor device numbers. Only asynchronous I/O is |
---|
77 | * supported. The console is currently fixed to be channel 1 on the CD2401, |
---|
78 | * which corresponds to the TTY01 port (Serial Port 2) on the MVME712M |
---|
79 | * Transition Module. |
---|
80 | * |
---|
81 | * The CD2401 does either interrupt-driven or DMA I/O; it does not support |
---|
82 | * polling. In interrupt-driven or DMA I/O modes, interrupts from the CD2401 |
---|
83 | * are routed to the MC68040, and the processor generates an interrupt |
---|
84 | * acknowledge cycle directly to the CD2401 to obtain an interrupt vector. |
---|
85 | * The PCCchip2 supports a pseudo-polling mode in which interrupts from the |
---|
86 | * CD2401 are not routed to the MC68040, but can be detected by the processor |
---|
87 | * by reading the appropriate CD2401 registers. In this mode, interrupt |
---|
88 | * acknowledge cycles must be generated to the CD2401 by reading the |
---|
89 | * appropriate PCCchip2 registers. |
---|
90 | * |
---|
91 | * Interrupts from the four channels cannot be routed independently; either |
---|
92 | * all channels are used in the pseudo-polling mode, or all channels are used |
---|
93 | * in interrupt-driven/DMA mode. There is no advantage in using the speudo- |
---|
94 | * polling mode. Consenquently, this driver performs DMA input and output. |
---|
95 | * Output is performed directly from the termios raw output buffer, while |
---|
96 | * input is accumulated into a separate buffer. |
---|
97 | * |
---|
98 | * THIS MODULE IS NOT RE-ENTRANT! Simultaneous access to a device from |
---|
99 | * multiple tasks is likely to cause significant problems! Concurrency |
---|
100 | * control is implemented in the termios package. |
---|
101 | * |
---|
102 | * THE INTERRUPT LEVEL IS SET TO 1 FOR ALL CHANNELS. |
---|
103 | * If the CD2401 is to be used for high speed synchronous serial I/O, the |
---|
104 | * interrupt priority might need to be increased. |
---|
105 | * |
---|
106 | * ALL INTERRUPT HANDLERS ARE SHARED. |
---|
107 | * When adding extra device drivers, either rewrite the interrupt handlers |
---|
108 | * to demultiplex the interrupts, or install separate vectors. Common vectors |
---|
109 | * are currently used to catch spurious interrupts. We could already have |
---|
110 | * installed separate vectors for each channel and used the spurious |
---|
111 | * interrupt handler defined in some other BSPs, but handling spurious |
---|
112 | * interrupts from the CD2401 in this device driver allows us to record more |
---|
113 | * information on the source of the interrupts. Furthermore, we have observed |
---|
114 | * the occasional spurious interrupt from channel 0. We definitely do not |
---|
115 | * to call a debugger for those. |
---|
116 | * |
---|
117 | * All page references are to the MVME166/MVME167/MVME187 Single Board |
---|
118 | * Computer Programmer's Reference Guide (MVME187PG/D2) with the April |
---|
119 | * 1993 supplements/addenda (MVME187PG/D2A1). |
---|
120 | * |
---|
121 | * Copyright (c) 1998, National Research Council of Canada |
---|
122 | * |
---|
123 | * The license and distribution terms for this file may be |
---|
124 | * found in the file LICENSE in this distribution or at |
---|
125 | * http://www.rtems.com/license/LICENSE. |
---|
126 | */ |
---|
127 | |
---|
128 | #define M167_INIT |
---|
129 | |
---|
130 | #include <stdarg.h> |
---|
131 | #include <stdio.h> |
---|
132 | #include <termios.h> |
---|
133 | #include <bsp.h> /* Must be before libio.h */ |
---|
134 | #include <rtems/libio.h> |
---|
135 | |
---|
136 | /* Utility functions */ |
---|
137 | void cd2401_udelay( unsigned long delay ); |
---|
138 | void cd2401_chan_cmd( uint8_t channel, uint8_t cmd, uint8_t wait ); |
---|
139 | uint16_t cd2401_bitrate_divisor( uint32_t clkrate, uint32_t * bitrate ); |
---|
140 | void cd2401_initialize( void ); |
---|
141 | void cd2401_interrupts_initialize( rtems_boolean enable ); |
---|
142 | |
---|
143 | /* ISRs */ |
---|
144 | rtems_isr cd2401_modem_isr( rtems_vector_number vector ); |
---|
145 | rtems_isr cd2401_re_isr( rtems_vector_number vector ); |
---|
146 | rtems_isr cd2401_rx_isr( rtems_vector_number vector ); |
---|
147 | rtems_isr cd2401_tx_isr( rtems_vector_number vector ); |
---|
148 | |
---|
149 | /* Termios callbacks */ |
---|
150 | int cd2401_firstOpen( int major, int minor, void *arg ); |
---|
151 | int cd2401_lastClose( int major, int minor, void *arg ); |
---|
152 | int cd2401_setAttributes( int minor, const struct termios *t ); |
---|
153 | int cd2401_startRemoteTx( int minor ); |
---|
154 | int cd2401_stopRemoteTx( int minor ); |
---|
155 | int cd2401_write( int minor, const char *buf, int len ); |
---|
156 | int cd2401_drainOutput( int minor ); |
---|
157 | int _167Bug_pollRead( int minor ); |
---|
158 | int _167Bug_pollWrite( int minor, const char *buf, int len ); |
---|
159 | |
---|
160 | |
---|
161 | /* Printk function */ |
---|
162 | static void _BSP_output_char( char c ); |
---|
163 | BSP_output_char_function_type BSP_output_char = _BSP_output_char; |
---|
164 | |
---|
165 | |
---|
166 | /* Channel info */ |
---|
167 | /* static */ volatile struct { |
---|
168 | void *tty; /* Really a struct rtems_termios_tty * */ |
---|
169 | int len; /* Record nb of chars being TX'ed */ |
---|
170 | const char *buf; /* Record where DMA is coming from */ |
---|
171 | uint32_t spur_cnt; /* Nb of spurious ints so far */ |
---|
172 | uint32_t spur_dev; /* Indo on last spurious int */ |
---|
173 | uint32_t buserr_addr; /* Faulting address */ |
---|
174 | uint32_t buserr_type; /* Reason of bus error during DMA */ |
---|
175 | uint8_t own_buf_A; /* If true, buffer A belongs to the driver */ |
---|
176 | uint8_t own_buf_B; /* If true, buffer B belongs to the driver */ |
---|
177 | uint8_t txEmpty; /* If true, the output FIFO should be empty */ |
---|
178 | } CD2401_Channel_Info[4]; |
---|
179 | |
---|
180 | /* |
---|
181 | * The number of channels already opened. If zero, enable the interrupts. The |
---|
182 | * initial value must be 0. If initialized explicitly, the variable ends up |
---|
183 | * in the .data section. Its value is not re-initialized on system restart. |
---|
184 | * Furthermore, because the variable is changed, the .data section would not |
---|
185 | * be ROMable. We thus leave the variable uninitialized, which causes it to |
---|
186 | * be allocated in the .bss section, and rely on RTEMS to zero the .bss |
---|
187 | * section on every startup. |
---|
188 | */ |
---|
189 | uint8_t Init_count; |
---|
190 | |
---|
191 | |
---|
192 | /* Record previous handlers */ |
---|
193 | rtems_isr_entry Prev_re_isr; /* Previous rx exception isr */ |
---|
194 | rtems_isr_entry Prev_rx_isr; /* Previous rx isr */ |
---|
195 | rtems_isr_entry Prev_tx_isr; /* Previous tx isr */ |
---|
196 | rtems_isr_entry Prev_modem_isr; /* Previous modem/timer isr */ |
---|
197 | |
---|
198 | |
---|
199 | /* Define the following symbol to trace the calls to this driver */ |
---|
200 | /* #define CD2401_RECORD_DEBUG_INFO */ |
---|
201 | #include "console-recording.h" |
---|
202 | |
---|
203 | |
---|
204 | /* |
---|
205 | * Utility functions. |
---|
206 | */ |
---|
207 | |
---|
208 | /* |
---|
209 | * Assumes that clock ticks 1 million times per second. |
---|
210 | * |
---|
211 | * MAXIMUM DELAY IS ABOUT 20 ms |
---|
212 | * |
---|
213 | * Input parameters: |
---|
214 | * delay: Number of microseconds to delay. |
---|
215 | * |
---|
216 | * Output parameters: NONE |
---|
217 | * |
---|
218 | * Return values: NONE |
---|
219 | */ |
---|
220 | void cd2401_udelay |
---|
221 | ( |
---|
222 | unsigned long delay |
---|
223 | ) |
---|
224 | { |
---|
225 | unsigned long i = 20000; /* In case clock is off */ |
---|
226 | rtems_interval ticks_per_second, start_ticks, end_ticks, current_ticks; |
---|
227 | |
---|
228 | rtems_clock_get( RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticks_per_second ); |
---|
229 | rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &start_ticks ); |
---|
230 | end_ticks = start_ticks + delay; |
---|
231 | |
---|
232 | do { |
---|
233 | rtems_clock_get(RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, ¤t_ticks); |
---|
234 | } while ( --i && (current_ticks <= end_ticks) ); |
---|
235 | |
---|
236 | CD2401_RECORD_DELAY_INFO(( start_ticks, end_ticks, current_ticks, i )); |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | /* |
---|
241 | * cd2401_chan_cmd |
---|
242 | * |
---|
243 | * Sends a CCR command to the specified channel. Waits for any unfinished |
---|
244 | * previous command to complete, then sends the specified command. Optionally |
---|
245 | * wait for the current command to finish before returning. |
---|
246 | * |
---|
247 | * Input parameters: |
---|
248 | * channel - CD2401 channel number |
---|
249 | * cmd - command byte |
---|
250 | * wait - if non-zero, wait for specified command to complete before |
---|
251 | * returning. |
---|
252 | * |
---|
253 | * Output parameters: NONE |
---|
254 | * |
---|
255 | * Return values: NONE |
---|
256 | */ |
---|
257 | void cd2401_chan_cmd( |
---|
258 | uint8_t channel, |
---|
259 | uint8_t cmd, |
---|
260 | uint8_t wait |
---|
261 | ) |
---|
262 | { |
---|
263 | if ( channel < 4 ) { |
---|
264 | cd2401->car = channel; /* Select channel */ |
---|
265 | |
---|
266 | while ( cd2401->ccr != 0 ); /* Wait for completion of previous command */ |
---|
267 | cd2401->ccr = cmd; /* Send command */ |
---|
268 | if ( wait ) |
---|
269 | while( cd2401->ccr != 0 );/* Wait for completion */ |
---|
270 | } |
---|
271 | else { |
---|
272 | /* This may not be the best error message */ |
---|
273 | rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER ); |
---|
274 | } |
---|
275 | } |
---|
276 | |
---|
277 | |
---|
278 | /* |
---|
279 | * cd2401_bitrate_divisor |
---|
280 | * |
---|
281 | * Compute the divisor and clock source to use to obtain the desired bitrate. |
---|
282 | * |
---|
283 | * Input parameters: |
---|
284 | * clkrate - system clock rate (CLK input frequency) |
---|
285 | * bitrate - the desired bitrate |
---|
286 | * |
---|
287 | * Output parameters: |
---|
288 | * bitrate - The actual bitrate achievable, to the nearest bps. |
---|
289 | * |
---|
290 | * Return values: |
---|
291 | * Returns divisor in lower byte and clock source in upper byte for the |
---|
292 | * specified bitrate. |
---|
293 | */ |
---|
294 | uint16_t cd2401_bitrate_divisor( |
---|
295 | uint32_t clkrate, |
---|
296 | uint32_t * bitrate |
---|
297 | ) |
---|
298 | { |
---|
299 | uint32_t divisor; |
---|
300 | uint16_t clksource; |
---|
301 | |
---|
302 | divisor = *bitrate << 3; /* temporary; multiply by 8 for CLK/8 */ |
---|
303 | divisor = (clkrate + (divisor>>1)) / divisor; /* divisor for clk0 (CLK/8) */ |
---|
304 | |
---|
305 | /* Use highest speed clock source for best precision - try clk0 to clk4 */ |
---|
306 | for( clksource = 0; clksource < 0x0400 && divisor > 0x100; clksource += 0x0100 ) |
---|
307 | divisor >>= 2; |
---|
308 | divisor--; /* adjustment, see specs */ |
---|
309 | if( divisor < 1 ) |
---|
310 | divisor = 1; |
---|
311 | else if( divisor > 0xFF ) |
---|
312 | divisor = 0xFF; |
---|
313 | *bitrate = clkrate / (1 << ((clksource >> 7)+3)) / (divisor+1); |
---|
314 | return( clksource | divisor ); |
---|
315 | } |
---|
316 | |
---|
317 | |
---|
318 | /* |
---|
319 | * cd2401_initialize |
---|
320 | * |
---|
321 | * Initializes the CD2401 device. Individual channels on the chip are left in |
---|
322 | * their default reset state, and should be subsequently configured. |
---|
323 | * |
---|
324 | * Input parameters: NONE |
---|
325 | * |
---|
326 | * Output parameters: NONE |
---|
327 | * |
---|
328 | * Return values: NONE |
---|
329 | */ |
---|
330 | void cd2401_initialize( void ) |
---|
331 | { |
---|
332 | int i; |
---|
333 | |
---|
334 | for ( i = 3; i >= 0; i-- ) { |
---|
335 | CD2401_Channel_Info[i].tty = NULL; |
---|
336 | CD2401_Channel_Info[i].len = 0; |
---|
337 | CD2401_Channel_Info[i].buf = NULL; |
---|
338 | CD2401_Channel_Info[i].spur_cnt = 0; |
---|
339 | CD2401_Channel_Info[i].spur_dev = 0; |
---|
340 | CD2401_Channel_Info[i].buserr_type = 0; |
---|
341 | CD2401_Channel_Info[i].buserr_addr = 0; |
---|
342 | CD2401_Channel_Info[i].own_buf_A = TRUE; |
---|
343 | CD2401_Channel_Info[i].own_buf_B = TRUE; |
---|
344 | CD2401_Channel_Info[i].txEmpty = TRUE; |
---|
345 | } |
---|
346 | |
---|
347 | /* |
---|
348 | * Normally, do a device reset here. If we do it, we will most likely clober |
---|
349 | * the port settings for 167Bug on channel 0. So we just shut up all the |
---|
350 | * ports by disabling their interrupts. |
---|
351 | */ |
---|
352 | #if 0 |
---|
353 | cd2401->gfrcr = 0; /* So we can detect that device init is done */ |
---|
354 | cd2401_chan_cmd( 0x10, 0); /* Reset all */ |
---|
355 | while(cd2401->gfrcr == 0); /* Wait for reset all */ |
---|
356 | #endif |
---|
357 | |
---|
358 | /* |
---|
359 | * The CL-CD2400/2401 manual (part no 542400-003) states on page 87 that |
---|
360 | * the LICR "contains the number of the interrupting channel being served. |
---|
361 | * The channel number is always that of the current acknowledged interrupt." |
---|
362 | * THE USER MUST PROGRAM CHANNEL NUMBER IN LICR! It is not set automatically |
---|
363 | * by the hardware, as suggested by the manual. |
---|
364 | * |
---|
365 | * The updated manual (part no 542400-007) has the story straight. The |
---|
366 | * CD2401 automatically initializes the LICR to contain the channel number |
---|
367 | * in bits 2 and 3. However, these bits are not preserved when the user |
---|
368 | * defined bits are written. |
---|
369 | * |
---|
370 | * The same vector number is used for all four channels. Different vector |
---|
371 | * numbers could be programmed for each channel, thus avoiding the need to |
---|
372 | * demultiplex the interrupts in the ISR. |
---|
373 | */ |
---|
374 | for ( i = 0; i < 4; i++ ) { |
---|
375 | cd2401->car = i; /* Select channel */ |
---|
376 | cd2401->livr = 0x5C; /* Motorola suggested value p. 3-15 */ |
---|
377 | cd2401->licr = i << 2; /* Don't rely on reset value */ |
---|
378 | cd2401->ier = 0; /* Disable all interrupts */ |
---|
379 | } |
---|
380 | |
---|
381 | /* |
---|
382 | * The content of the CD2401 xpilr registers must match the A7-A0 addresses |
---|
383 | * generated by the PCCchip2 during interrupt acknowledge cycles in order |
---|
384 | * for the CD2401 to recognize the IACK cycle and clear its interrupt |
---|
385 | * request. |
---|
386 | */ |
---|
387 | cd2401->mpilr = 0x01; /* Match pccchip2->modem_piack p. 3-27 */ |
---|
388 | cd2401->tpilr = 0x02; /* Match pccchip2->tx_piack p. 3-28 */ |
---|
389 | cd2401->rpilr = 0x03; /* Match pccchip2->rx_piack p. 3-29 */ |
---|
390 | |
---|
391 | /* Global CD2401 registers */ |
---|
392 | cd2401->dmr = 0; /* 16-bit DMA transfers when possible */ |
---|
393 | cd2401->bercnt = 0; /* Do not retry DMA upon bus errors */ |
---|
394 | |
---|
395 | /* |
---|
396 | * Setup timer prescaler period, which clocks timers 1 and 2 (or rx timeout |
---|
397 | * and tx delay). The prescaler is clocked by the system clock) / 2048. The |
---|
398 | * register must be in the range 0x0A..0xFF, ie. a rescaler period range of |
---|
399 | * about 1ms..26ms for a nominal system clock rate of 20MHz. |
---|
400 | */ |
---|
401 | cd2401->tpr = 0x0A; /* Same value as 167Bug */ |
---|
402 | } |
---|
403 | |
---|
404 | |
---|
405 | /* |
---|
406 | * cd2401_interrupts_initialize |
---|
407 | * |
---|
408 | * This routine enables or disables the CD2401 interrupts to the MC68040. |
---|
409 | * Interrupts cannot be enabled/disabled on a per-channel basis. |
---|
410 | * |
---|
411 | * Input parameters: |
---|
412 | * enable - if true, enable the interrupts, else disable them. |
---|
413 | * |
---|
414 | * Output parameters: NONE |
---|
415 | * |
---|
416 | * Return values: NONE |
---|
417 | * |
---|
418 | * THE FIRST CD2401 CHANNEL OPENED SHOULD ENABLE INTERRUPTS. |
---|
419 | * THE LAST CD2401 CHANNEL CLOSED SHOULD DISABLE INTERRUPTS. |
---|
420 | */ |
---|
421 | void cd2401_interrupts_initialize( |
---|
422 | rtems_boolean enable |
---|
423 | ) |
---|
424 | { |
---|
425 | if ( enable ) { |
---|
426 | /* |
---|
427 | * Enable interrupts from the CD2401 in the PCCchip2. |
---|
428 | * During DMA transfers, the MC68040 supplies dirty data during read cycles |
---|
429 | * from the CD2401 and leaves the data dirty in its data cache if there is |
---|
430 | * a cache hit. The MC68040 updates the data cache during write cycles from |
---|
431 | * the CD2401 if there is a cache hit. |
---|
432 | */ |
---|
433 | pccchip2->SCC_error = 0x01; |
---|
434 | pccchip2->SCC_modem_int_ctl = 0x10 | CD2401_INT_LEVEL; |
---|
435 | pccchip2->SCC_tx_int_ctl = 0x10 | CD2401_INT_LEVEL; |
---|
436 | pccchip2->SCC_rx_int_ctl = 0x50 | CD2401_INT_LEVEL; |
---|
437 | |
---|
438 | pccchip2->gen_control |= 0x02; /* Enable pccchip2 interrupts */ |
---|
439 | } |
---|
440 | else { |
---|
441 | /* Disable interrupts */ |
---|
442 | pccchip2->SCC_modem_int_ctl &= 0xEF; |
---|
443 | pccchip2->SCC_tx_int_ctl &= 0xEF; |
---|
444 | pccchip2->SCC_rx_int_ctl &= 0xEF; |
---|
445 | } |
---|
446 | } |
---|
447 | |
---|
448 | |
---|
449 | /* ISRs */ |
---|
450 | |
---|
451 | /* |
---|
452 | * cd2401_modem_isr |
---|
453 | * |
---|
454 | * Modem/timer interrupt (group 1) from CD2401. These are not used, and not |
---|
455 | * expected. Record as spurious and clear. |
---|
456 | * |
---|
457 | * Input parameters: |
---|
458 | * vector - vector number |
---|
459 | * |
---|
460 | * Output parameters: NONE |
---|
461 | * |
---|
462 | * Return values: NONE |
---|
463 | */ |
---|
464 | rtems_isr cd2401_modem_isr( |
---|
465 | rtems_vector_number vector |
---|
466 | ) |
---|
467 | { |
---|
468 | uint8_t ch; |
---|
469 | |
---|
470 | /* Get interrupting channel ID */ |
---|
471 | ch = cd2401->licr >> 2; |
---|
472 | |
---|
473 | /* Record interrupt info for debugging */ |
---|
474 | CD2401_Channel_Info[ch].spur_dev = |
---|
475 | (vector << 24) | (cd2401->stk << 16) | (cd2401->mir << 8) | cd2401->misr; |
---|
476 | CD2401_Channel_Info[ch].spur_cnt++; |
---|
477 | |
---|
478 | cd2401->meoir = 0; /* EOI */ |
---|
479 | CD2401_RECORD_MODEM_ISR_SPURIOUS_INFO(( ch, |
---|
480 | CD2401_Channel_Info[ch].spur_dev, |
---|
481 | CD2401_Channel_Info[ch].spur_cnt )); |
---|
482 | } |
---|
483 | |
---|
484 | |
---|
485 | /* |
---|
486 | * cd2401_re_isr |
---|
487 | * |
---|
488 | * RX exception interrupt (group 3, receiver exception) from CD2401. These are |
---|
489 | * not used, and not expected. Record as spurious and clear. |
---|
490 | * |
---|
491 | * FIX THIS ISR TO DETECT BREAK CONDITIONS AND RAISE SIGINT |
---|
492 | * |
---|
493 | * Input parameters: |
---|
494 | * vector - vector number |
---|
495 | * |
---|
496 | * Output parameters: NONE |
---|
497 | * |
---|
498 | * Return values: NONE |
---|
499 | */ |
---|
500 | rtems_isr cd2401_re_isr( |
---|
501 | rtems_vector_number vector |
---|
502 | ) |
---|
503 | { |
---|
504 | uint8_t ch; |
---|
505 | |
---|
506 | /* Get interrupting channel ID */ |
---|
507 | ch = cd2401->licr >> 2; |
---|
508 | |
---|
509 | /* Record interrupt info for debugging */ |
---|
510 | CD2401_Channel_Info[ch].spur_dev = |
---|
511 | (vector << 24) | (cd2401->stk << 16) | (cd2401->rir << 8) | cd2401->u5.b.risrl; |
---|
512 | CD2401_Channel_Info[ch].spur_cnt++; |
---|
513 | |
---|
514 | if ( cd2401->u5.b.risrl & 0x80 ) /* Timeout interrupt? */ |
---|
515 | cd2401->ier &= 0xDF; /* Disable rx timeout interrupt */ |
---|
516 | cd2401->reoir = 0x08; /* EOI; exception char not read */ |
---|
517 | CD2401_RECORD_RE_ISR_SPURIOUS_INFO(( ch, |
---|
518 | CD2401_Channel_Info[ch].spur_dev, |
---|
519 | CD2401_Channel_Info[ch].spur_cnt )); |
---|
520 | } |
---|
521 | |
---|
522 | |
---|
523 | /* |
---|
524 | * cd2401_rx_isr |
---|
525 | * |
---|
526 | * RX interrupt (group 3, receiver data) from CD2401. |
---|
527 | * |
---|
528 | * Input parameters: |
---|
529 | * vector - vector number |
---|
530 | * |
---|
531 | * Output parameters: NONE |
---|
532 | * |
---|
533 | * Return values: NONE |
---|
534 | */ |
---|
535 | rtems_isr cd2401_rx_isr( |
---|
536 | rtems_vector_number vector |
---|
537 | ) |
---|
538 | { |
---|
539 | char c; |
---|
540 | uint8_t ch, status, nchars, i, total; |
---|
541 | char buffer[256]; |
---|
542 | |
---|
543 | status = cd2401->u5.b.risrl; |
---|
544 | ch = cd2401->licr >> 2; |
---|
545 | |
---|
546 | /* Has this channel been initialized or is it a condition we ignore? */ |
---|
547 | if ( CD2401_Channel_Info[ch].tty && !status ) { |
---|
548 | /* Normal Rx Int, read chars, enqueue them, and issue EOI */ |
---|
549 | total = nchars = cd2401->rfoc; /* Nb of chars to retrieve from rx FIFO */ |
---|
550 | i = 0; |
---|
551 | while ( nchars-- > 0 ) { |
---|
552 | c = (char)cd2401->dr; /* Next char in rx FIFO */ |
---|
553 | rtems_termios_enqueue_raw_characters( CD2401_Channel_Info[ch].tty ,&c, 1 ); |
---|
554 | buffer[i++] = c; |
---|
555 | } |
---|
556 | cd2401->reoir = 0; /* EOI */ |
---|
557 | CD2401_RECORD_RX_ISR_INFO(( ch, total, buffer )); |
---|
558 | } else { |
---|
559 | /* No, record as spurious interrupt */ |
---|
560 | CD2401_Channel_Info[ch].spur_dev = |
---|
561 | (vector << 24) | (cd2401->stk << 16) | (cd2401->rir << 8) | cd2401->u5.b.risrl; |
---|
562 | CD2401_Channel_Info[ch].spur_cnt++; |
---|
563 | cd2401->reoir = 0x04; /* EOI - character not read */ |
---|
564 | CD2401_RECORD_RX_ISR_SPURIOUS_INFO(( ch, status, |
---|
565 | CD2401_Channel_Info[ch].spur_dev, |
---|
566 | CD2401_Channel_Info[ch].spur_cnt )); |
---|
567 | } |
---|
568 | } |
---|
569 | |
---|
570 | |
---|
571 | /* |
---|
572 | * cd2401_tx_isr |
---|
573 | * |
---|
574 | * TX interrupt (group 2) from CD2401. |
---|
575 | * |
---|
576 | * Input parameters: |
---|
577 | * vector - vector number |
---|
578 | * |
---|
579 | * Output parameters: NONE |
---|
580 | * |
---|
581 | * Return values: NONE |
---|
582 | */ |
---|
583 | rtems_isr cd2401_tx_isr( |
---|
584 | rtems_vector_number vector |
---|
585 | ) |
---|
586 | { |
---|
587 | uint8_t ch, status, buserr, initial_ier, final_ier; |
---|
588 | |
---|
589 | status = cd2401->tisr; |
---|
590 | ch = cd2401->licr >> 2; |
---|
591 | initial_ier = cd2401->ier; |
---|
592 | |
---|
593 | /* Has this channel been initialized? */ |
---|
594 | if ( !CD2401_Channel_Info[ch].tty ) { |
---|
595 | /* No, record as spurious interrupt */ |
---|
596 | CD2401_Channel_Info[ch].spur_dev = |
---|
597 | (vector << 24) | (cd2401->stk << 16) | (cd2401->tir << 8) | cd2401->tisr; |
---|
598 | CD2401_Channel_Info[ch].spur_cnt++; |
---|
599 | final_ier = cd2401->ier &= 0xFC;/* Shut up, whoever you are */ |
---|
600 | cd2401->teoir = 0x88; /* EOI - Terminate buffer and no transfer */ |
---|
601 | CD2401_RECORD_TX_ISR_SPURIOUS_INFO(( ch, status, initial_ier, final_ier, |
---|
602 | CD2401_Channel_Info[ch].spur_dev, |
---|
603 | CD2401_Channel_Info[ch].spur_cnt )); |
---|
604 | return; |
---|
605 | } |
---|
606 | |
---|
607 | if ( status & 0x80 ) { |
---|
608 | /* |
---|
609 | * Bus error occurred during DMA transfer. For now, just record. |
---|
610 | * Get reason for DMA bus error and clear the report for the next |
---|
611 | * occurrence |
---|
612 | */ |
---|
613 | buserr = pccchip2->SCC_error; |
---|
614 | pccchip2->SCC_error = 0x01; |
---|
615 | CD2401_Channel_Info[ch].buserr_type = |
---|
616 | (vector << 24) | (buserr << 16) | (cd2401->tir << 8) | cd2401->tisr; |
---|
617 | CD2401_Channel_Info[ch].buserr_addr = |
---|
618 | (((uint32_t)cd2401->tcbadru) << 16) | cd2401->tcbadrl; |
---|
619 | |
---|
620 | cd2401->teoir = 0x80; /* EOI - terminate bad buffer */ |
---|
621 | CD2401_RECORD_TX_ISR_BUSERR_INFO(( ch, status, initial_ier, buserr, |
---|
622 | CD2401_Channel_Info[ch].buserr_type, |
---|
623 | CD2401_Channel_Info[ch].buserr_addr )); |
---|
624 | return; |
---|
625 | } |
---|
626 | |
---|
627 | if ( status & 0x20 ) { |
---|
628 | /* DMA done -- Turn off TxD int, turn on TxMpty */ |
---|
629 | final_ier = cd2401->ier = (cd2401->ier & 0xFE) | 0x02; |
---|
630 | if( status & 0x08 ) { |
---|
631 | /* Transmit buffer B was released */ |
---|
632 | CD2401_Channel_Info[ch].own_buf_B = TRUE; |
---|
633 | } |
---|
634 | else { |
---|
635 | /* Transmit buffer A was released */ |
---|
636 | CD2401_Channel_Info[ch].own_buf_A = TRUE; |
---|
637 | } |
---|
638 | CD2401_RECORD_TX_ISR_INFO(( ch, status, initial_ier, final_ier, |
---|
639 | CD2401_Channel_Info[ch].txEmpty )); |
---|
640 | |
---|
641 | /* This call can result in a call to cd2401_write() */ |
---|
642 | rtems_termios_dequeue_characters ( |
---|
643 | CD2401_Channel_Info[ch].tty, |
---|
644 | CD2401_Channel_Info[ch].len ); |
---|
645 | cd2401->teoir = 0x08; /* EOI - no data transfered */ |
---|
646 | } |
---|
647 | else if ( status & 0x02 ) { |
---|
648 | /* TxEmpty */ |
---|
649 | CD2401_Channel_Info[ch].txEmpty = TRUE; |
---|
650 | final_ier = cd2401->ier &= 0xFD;/* Shut up the interrupts */ |
---|
651 | cd2401->teoir = 0x08; /* EOI - no data transfered */ |
---|
652 | CD2401_RECORD_TX_ISR_INFO(( ch, status, initial_ier, final_ier, |
---|
653 | CD2401_Channel_Info[ch].txEmpty )); |
---|
654 | } |
---|
655 | else { |
---|
656 | /* Why did we get a Tx interrupt? */ |
---|
657 | CD2401_Channel_Info[ch].spur_dev = |
---|
658 | (vector << 24) | (cd2401->stk << 16) | (cd2401->tir << 8) | cd2401->tisr; |
---|
659 | CD2401_Channel_Info[ch].spur_cnt++; |
---|
660 | cd2401->teoir = 0x08; /* EOI - no data transfered */ |
---|
661 | CD2401_RECORD_TX_ISR_SPURIOUS_INFO(( ch, status, initial_ier, 0xFF, |
---|
662 | CD2401_Channel_Info[ch].spur_dev, |
---|
663 | CD2401_Channel_Info[ch].spur_cnt )); |
---|
664 | } |
---|
665 | } |
---|
666 | |
---|
667 | |
---|
668 | /* |
---|
669 | * termios callbacks |
---|
670 | */ |
---|
671 | |
---|
672 | /* |
---|
673 | * cd2401_firstOpen |
---|
674 | * |
---|
675 | * This is the first time that this minor device (channel) is opened. |
---|
676 | * Complete the asynchronous initialization. |
---|
677 | * |
---|
678 | * Input parameters: |
---|
679 | * major - device major number |
---|
680 | * minor - channel number |
---|
681 | * arg - pointer to a struct rtems_libio_open_close_args_t |
---|
682 | * |
---|
683 | * Output parameters: NONE |
---|
684 | * |
---|
685 | * Return value: IGNORED |
---|
686 | */ |
---|
687 | int cd2401_firstOpen( |
---|
688 | int major, |
---|
689 | int minor, |
---|
690 | void *arg |
---|
691 | ) |
---|
692 | { |
---|
693 | rtems_libio_open_close_args_t *args = arg; |
---|
694 | rtems_libio_ioctl_args_t newarg; |
---|
695 | struct termios termios; |
---|
696 | rtems_status_code sc; |
---|
697 | rtems_interrupt_level level; |
---|
698 | |
---|
699 | rtems_interrupt_disable (level); |
---|
700 | |
---|
701 | /* |
---|
702 | * Set up the line with the specified parameters. The difficulty is that |
---|
703 | * the line parameters are stored in the struct termios field of a |
---|
704 | * struct rtems_termios_tty that is not defined in a public header file. |
---|
705 | * Therefore, we do not have direct access to the termios passed in with |
---|
706 | * arg. So we make a rtems_termios_ioctl() call to get a pointer to the |
---|
707 | * termios structure. |
---|
708 | * |
---|
709 | * THIS KLUDGE MAY BREAK IN THE FUTURE! |
---|
710 | * |
---|
711 | * We could have made a tcgetattr() call if we had our fd. |
---|
712 | */ |
---|
713 | newarg.iop = args->iop; |
---|
714 | newarg.command = RTEMS_IO_GET_ATTRIBUTES; |
---|
715 | newarg.buffer = &termios; |
---|
716 | sc = rtems_termios_ioctl (&newarg); |
---|
717 | if (sc != RTEMS_SUCCESSFUL) |
---|
718 | rtems_fatal_error_occurred (sc); |
---|
719 | |
---|
720 | /* |
---|
721 | * Turn off hardware flow control. It is a pain with 3-wire cables. |
---|
722 | * The rtems_termios_ioctl() call below results in a call to |
---|
723 | * cd2401_setAttributes to initialize the line. The caller will "wait" |
---|
724 | * on the ttyMutex that it already owns; this is safe in RTEMS. |
---|
725 | */ |
---|
726 | termios.c_cflag |= CLOCAL; /* Ignore modem status lines */ |
---|
727 | newarg.command = RTEMS_IO_SET_ATTRIBUTES; |
---|
728 | sc = rtems_termios_ioctl (&newarg); |
---|
729 | if (sc != RTEMS_SUCCESSFUL) |
---|
730 | rtems_fatal_error_occurred (sc); |
---|
731 | |
---|
732 | /* Mark that the channel as initialized */ |
---|
733 | CD2401_Channel_Info[minor].tty = args->iop->data1; |
---|
734 | |
---|
735 | /* If the first of the four channels to open, set up the interrupts */ |
---|
736 | if ( !Init_count++ ) { |
---|
737 | /* Install the interrupt handlers */ |
---|
738 | Prev_re_isr = (rtems_isr_entry) set_vector( cd2401_re_isr, 0x5C, 1 ); |
---|
739 | Prev_modem_isr = (rtems_isr_entry) set_vector( cd2401_modem_isr, 0x5D, 1 ); |
---|
740 | Prev_tx_isr = (rtems_isr_entry) set_vector( cd2401_tx_isr, 0x5E, 1 ); |
---|
741 | Prev_rx_isr = (rtems_isr_entry) set_vector( cd2401_rx_isr, 0x5F, 1 ); |
---|
742 | |
---|
743 | cd2401_interrupts_initialize( TRUE ); |
---|
744 | } |
---|
745 | |
---|
746 | CD2401_RECORD_FIRST_OPEN_INFO(( minor, Init_count )); |
---|
747 | |
---|
748 | rtems_interrupt_enable (level); |
---|
749 | |
---|
750 | /* Return something */ |
---|
751 | return RTEMS_SUCCESSFUL; |
---|
752 | } |
---|
753 | |
---|
754 | |
---|
755 | /* |
---|
756 | * cd2401_lastClose |
---|
757 | * |
---|
758 | * There are no more opened file descriptors to this device. Close it down. |
---|
759 | * |
---|
760 | * Input parameters: |
---|
761 | * major - device major number |
---|
762 | * minor - channel number |
---|
763 | * arg - pointer to a struct rtems_libio_open_close_args_t |
---|
764 | */ |
---|
765 | int cd2401_lastClose( |
---|
766 | int major, |
---|
767 | int minor, |
---|
768 | void *arg |
---|
769 | ) |
---|
770 | { |
---|
771 | rtems_interrupt_level level; |
---|
772 | |
---|
773 | rtems_interrupt_disable (level); |
---|
774 | |
---|
775 | /* Mark that the channel is no longer is use */ |
---|
776 | CD2401_Channel_Info[minor].tty = NULL; |
---|
777 | |
---|
778 | /* If the last of the four channels to close, disable the interrupts */ |
---|
779 | if ( !--Init_count ) { |
---|
780 | cd2401_interrupts_initialize( FALSE ); |
---|
781 | |
---|
782 | /* De-install the interrupt handlers */ |
---|
783 | set_vector( Prev_re_isr, 0x5C, 1 ); |
---|
784 | set_vector( Prev_modem_isr, 0x5D, 1 ); |
---|
785 | set_vector( Prev_tx_isr, 0x5E, 1 ); |
---|
786 | set_vector( Prev_rx_isr, 0x5F, 1 ); |
---|
787 | } |
---|
788 | |
---|
789 | CD2401_RECORD_LAST_CLOSE_INFO(( minor, Init_count )); |
---|
790 | |
---|
791 | rtems_interrupt_enable (level); |
---|
792 | |
---|
793 | /* return something */ |
---|
794 | return RTEMS_SUCCESSFUL; |
---|
795 | } |
---|
796 | |
---|
797 | |
---|
798 | /* |
---|
799 | * cd2401_setAttributes |
---|
800 | * |
---|
801 | * Set up the selected channel of the CD2401 chip for doing asynchronous |
---|
802 | * I/O with DMA. |
---|
803 | * |
---|
804 | * The chip must already have been initialized by cd2401_initialize(). |
---|
805 | * |
---|
806 | * This code was written for clarity. The code space it occupies could be |
---|
807 | * reduced. The code could also be compiled with aggressive optimization |
---|
808 | * turned on. |
---|
809 | * |
---|
810 | * Input parameters: |
---|
811 | * minor - the selected channel |
---|
812 | * t - the termios parameters |
---|
813 | * |
---|
814 | * Output parameters: NONE |
---|
815 | * |
---|
816 | * Return value: IGNORED |
---|
817 | */ |
---|
818 | int cd2401_setAttributes( |
---|
819 | int minor, |
---|
820 | const struct termios *t |
---|
821 | ) |
---|
822 | { |
---|
823 | uint8_t csize, cstopb, parodd, parenb, ignpar, inpck; |
---|
824 | uint8_t hw_flow_ctl, sw_flow_ctl, extra_flow_ctl; |
---|
825 | uint8_t icrnl, igncr, inlcr, brkint, ignbrk, parmrk, istrip; |
---|
826 | uint8_t need_reinitialization = FALSE; |
---|
827 | uint8_t read_enabled; |
---|
828 | uint16_t tx_period, rx_period; |
---|
829 | uint32_t out_baud, in_baud; |
---|
830 | rtems_interrupt_level level; |
---|
831 | |
---|
832 | /* Determine what the line parameters should be */ |
---|
833 | |
---|
834 | /* Output baud rate */ |
---|
835 | switch ( cfgetospeed (t) ) { |
---|
836 | default: out_baud = 9600; break; |
---|
837 | case B50: out_baud = 50; break; |
---|
838 | case B75: out_baud = 75; break; |
---|
839 | case B110: out_baud = 110; break; |
---|
840 | case B134: out_baud = 134; break; |
---|
841 | case B150: out_baud = 150; break; |
---|
842 | case B200: out_baud = 200; break; |
---|
843 | case B300: out_baud = 300; break; |
---|
844 | case B600: out_baud = 600; break; |
---|
845 | case B1200: out_baud = 1200; break; |
---|
846 | case B1800: out_baud = 1800; break; |
---|
847 | case B2400: out_baud = 2400; break; |
---|
848 | case B4800: out_baud = 4800; break; |
---|
849 | case B9600: out_baud = 9600; break; |
---|
850 | case B19200: out_baud = 19200; break; |
---|
851 | case B38400: out_baud = 38400; break; |
---|
852 | case B57600: out_baud = 57600; break; |
---|
853 | case B115200: out_baud = 115200; break; |
---|
854 | case B230400: out_baud = 230400; break; |
---|
855 | case B460800: out_baud = 460800; break; |
---|
856 | } |
---|
857 | |
---|
858 | /* Input baud rate */ |
---|
859 | switch ( cfgetispeed (t) ) { |
---|
860 | default: in_baud = out_baud; break; |
---|
861 | case B50: in_baud = 50; break; |
---|
862 | case B75: in_baud = 75; break; |
---|
863 | case B110: in_baud = 110; break; |
---|
864 | case B134: in_baud = 134; break; |
---|
865 | case B150: in_baud = 150; break; |
---|
866 | case B200: in_baud = 200; break; |
---|
867 | case B300: in_baud = 300; break; |
---|
868 | case B600: in_baud = 600; break; |
---|
869 | case B1200: in_baud = 1200; break; |
---|
870 | case B1800: in_baud = 1800; break; |
---|
871 | case B2400: in_baud = 2400; break; |
---|
872 | case B4800: in_baud = 4800; break; |
---|
873 | case B9600: in_baud = 9600; break; |
---|
874 | case B19200: in_baud = 19200; break; |
---|
875 | case B38400: in_baud = 38400; break; |
---|
876 | case B57600: in_baud = 57600; break; |
---|
877 | case B115200: in_baud = 115200; break; |
---|
878 | case B230400: in_baud = 230400; break; |
---|
879 | case B460800: in_baud = 460800; break; |
---|
880 | } |
---|
881 | |
---|
882 | /* Number of bits per char */ |
---|
883 | csize = 0x07; /* to avoid a warning */ |
---|
884 | switch ( t->c_cflag & CSIZE ) { |
---|
885 | case CS5: csize = 0x04; break; |
---|
886 | case CS6: csize = 0x05; break; |
---|
887 | case CS7: csize = 0x06; break; |
---|
888 | case CS8: csize = 0x07; break; |
---|
889 | } |
---|
890 | |
---|
891 | /* Parity */ |
---|
892 | if ( t->c_cflag & PARODD ) |
---|
893 | parodd = 0x80; /* Odd parity */ |
---|
894 | else |
---|
895 | parodd = 0; |
---|
896 | |
---|
897 | if ( t->c_cflag & PARENB ) |
---|
898 | parenb = 0x40; /* Parity enabled on Tx and Rx */ |
---|
899 | else |
---|
900 | parenb = 0x00; /* No parity on Tx and Rx */ |
---|
901 | |
---|
902 | /* CD2401 IGNPAR and INPCK bits are inverted wrt POSIX standard? */ |
---|
903 | if ( t->c_iflag & INPCK ) |
---|
904 | ignpar = 0; /* Check parity on input */ |
---|
905 | else |
---|
906 | ignpar = 0x10; /* Do not check parity on input */ |
---|
907 | if ( t->c_iflag & IGNPAR ) { |
---|
908 | inpck = 0x03; /* Discard error character */ |
---|
909 | parmrk = 0; |
---|
910 | } else { |
---|
911 | if ( t->c_iflag & PARMRK ) { |
---|
912 | inpck = 0x01; /* Translate to 0xFF 0x00 <char> */ |
---|
913 | parmrk = 0x04; |
---|
914 | } else { |
---|
915 | inpck = 0x01; /* Translate to 0x00 */ |
---|
916 | parmrk = 0; |
---|
917 | } |
---|
918 | } |
---|
919 | |
---|
920 | /* Stop bits */ |
---|
921 | if ( t->c_cflag & CSTOPB ) |
---|
922 | cstopb = 0x04; /* Two stop bits */ |
---|
923 | else |
---|
924 | cstopb = 0x02; /* One stop bit */ |
---|
925 | |
---|
926 | /* Modem flow control */ |
---|
927 | if ( t->c_cflag & CLOCAL ) |
---|
928 | hw_flow_ctl = 0x04; /* Always assert RTS before Tx */ |
---|
929 | else |
---|
930 | hw_flow_ctl = 0x07; /* Always assert RTS before Tx, |
---|
931 | wait for CTS and DSR */ |
---|
932 | |
---|
933 | /* XON/XOFF Tx flow control */ |
---|
934 | if ( t->c_iflag & IXON ) { |
---|
935 | sw_flow_ctl = 0x40; /* Tx in-band flow ctl enabled, wait for XON */ |
---|
936 | extra_flow_ctl = 0x30; /* Eat XON/XOFF, XON/XOFF in SCHR1, SCHR2 */ |
---|
937 | } |
---|
938 | else { |
---|
939 | sw_flow_ctl = 0; /* Tx in-band flow ctl disabled */ |
---|
940 | extra_flow_ctl = 0; /* Pass on XON/XOFF */ |
---|
941 | } |
---|
942 | |
---|
943 | /* CL/LF translation */ |
---|
944 | if ( t->c_iflag & ICRNL ) |
---|
945 | icrnl = 0x40; /* Map CR to NL on input */ |
---|
946 | else |
---|
947 | icrnl = 0; /* Pass on CR */ |
---|
948 | if ( t->c_iflag & INLCR ) |
---|
949 | inlcr = 0x20; /* Map NL to CR on input */ |
---|
950 | else |
---|
951 | inlcr = 0; /* Pass on NL */ |
---|
952 | if ( t->c_iflag & IGNCR ) |
---|
953 | igncr = 0x80; /* CR discarded on input */ |
---|
954 | else |
---|
955 | igncr = 0; |
---|
956 | |
---|
957 | /* Break handling */ |
---|
958 | if ( t->c_iflag & IGNBRK ) { |
---|
959 | ignbrk = 0x10; /* Ignore break on input */ |
---|
960 | brkint = 0x08; |
---|
961 | } else { |
---|
962 | if ( t->c_iflag & BRKINT ) { |
---|
963 | ignbrk = 0; /* Generate SIGINT (interrupt ) */ |
---|
964 | brkint = 0; |
---|
965 | } else { |
---|
966 | ignbrk = 0; /* Convert to 0x00 */ |
---|
967 | brkint = 0x08; |
---|
968 | } |
---|
969 | } |
---|
970 | |
---|
971 | /* Stripping */ |
---|
972 | if ( t->c_iflag & ISTRIP ) |
---|
973 | istrip = 0x80; /* Strip to 7 bits */ |
---|
974 | else |
---|
975 | istrip = 0; /* Leave as 8 bits */ |
---|
976 | |
---|
977 | rx_period = cd2401_bitrate_divisor( 20000000Ul, &in_baud ); |
---|
978 | tx_period = cd2401_bitrate_divisor( 20000000Ul, &out_baud ); |
---|
979 | |
---|
980 | /* |
---|
981 | * If this is the first time that the line characteristics are set up, then |
---|
982 | * the device must be re-initialized. |
---|
983 | * Also check if we need to change anything. It is preferable to not touch |
---|
984 | * the device if nothing changes. As soon as we touch it, it tends to |
---|
985 | * glitch. If anything changes, we reprogram all registers. This is |
---|
986 | * harmless. |
---|
987 | */ |
---|
988 | if ( ( CD2401_Channel_Info[minor].tty == 0 ) || |
---|
989 | ( cd2401->cor1 != (parodd | parenb | ignpar | csize) ) || |
---|
990 | ( cd2401->cor2 != (sw_flow_ctl | hw_flow_ctl) ) || |
---|
991 | ( cd2401->cor3 != (extra_flow_ctl | cstopb) ) || |
---|
992 | ( cd2401->cor6 != (igncr | icrnl | inlcr | ignbrk | brkint | parmrk | inpck) ) || |
---|
993 | ( cd2401->cor7 != istrip ) || |
---|
994 | ( cd2401->u1.async.schr1 != t->c_cc[VSTART] ) || |
---|
995 | ( cd2401->u1.async.schr2 != t->c_cc[VSTOP] ) || |
---|
996 | ( cd2401->rbpr != (unsigned char)rx_period ) || |
---|
997 | ( cd2401->rcor != (unsigned char)(rx_period >> 8) ) || |
---|
998 | ( cd2401->tbpr != (unsigned char)tx_period ) || |
---|
999 | ( cd2401->tcor != ( (tx_period >> 3) & 0xE0 ) ) ) |
---|
1000 | need_reinitialization = TRUE; |
---|
1001 | |
---|
1002 | /* Write to the ports */ |
---|
1003 | rtems_interrupt_disable (level); |
---|
1004 | |
---|
1005 | cd2401->car = minor; /* Select channel */ |
---|
1006 | read_enabled = cd2401->csr & 0x80 ? TRUE : FALSE; |
---|
1007 | |
---|
1008 | if ( (t->c_cflag & CREAD ? TRUE : FALSE ) != read_enabled ) { |
---|
1009 | /* Read enable status is changing */ |
---|
1010 | need_reinitialization = TRUE; |
---|
1011 | } |
---|
1012 | |
---|
1013 | if ( need_reinitialization ) { |
---|
1014 | /* |
---|
1015 | * Could not find a way to test whether the CD2401 was done transmitting. |
---|
1016 | * The TxEmpty interrupt does not seem to indicate that the FIFO is empty |
---|
1017 | * in DMA mode. So, just wait a while for output to drain. May not be |
---|
1018 | * enough, but it will have to do (should be long enough for 1 char at |
---|
1019 | * 9600 bsp)... |
---|
1020 | */ |
---|
1021 | cd2401_udelay( 2000L ); |
---|
1022 | |
---|
1023 | /* Clear channel */ |
---|
1024 | cd2401_chan_cmd (minor, 0x40, 1); |
---|
1025 | |
---|
1026 | cd2401->car = minor; /* Select channel */ |
---|
1027 | cd2401->cmr = 0x42; /* Interrupt Rx, DMA Tx, async mode */ |
---|
1028 | cd2401->cor1 = parodd | parenb | ignpar | csize; |
---|
1029 | cd2401->cor2 = sw_flow_ctl | hw_flow_ctl; |
---|
1030 | cd2401->cor3 = extra_flow_ctl | cstopb; |
---|
1031 | cd2401->cor4 = 0x0A; /* No DSR/DCD/CTS detect; FIFO threshold of 10 */ |
---|
1032 | cd2401->cor5 = 0x0A; /* No DSR/DCD/CTS detect; DTR threshold of 10 */ |
---|
1033 | cd2401->cor6 = igncr | icrnl | inlcr | ignbrk | brkint | parmrk | inpck; |
---|
1034 | cd2401->cor7 = istrip; /* No LNext; ignore XON/XOFF if frame error; no tx translations */ |
---|
1035 | /* Special char 1: XON character */ |
---|
1036 | cd2401->u1.async.schr1 = t->c_cc[VSTART]; |
---|
1037 | /* special char 2: XOFF character */ |
---|
1038 | cd2401->u1.async.schr2 = t->c_cc[VSTOP]; |
---|
1039 | |
---|
1040 | /* |
---|
1041 | * Special chars 3 and 4, char range, LNext, RFAR[1..4] and CRC |
---|
1042 | * are unused, left as is. |
---|
1043 | */ |
---|
1044 | |
---|
1045 | /* Set baudrates for receiver and transmitter */ |
---|
1046 | cd2401->rbpr = (unsigned char)rx_period; |
---|
1047 | cd2401->rcor = (unsigned char)(rx_period >> 8); /* no DPLL */ |
---|
1048 | cd2401->tbpr = (unsigned char)tx_period; |
---|
1049 | cd2401->tcor = (tx_period >> 3) & 0xE0; /* no x1 ext clk, no loopback */ |
---|
1050 | |
---|
1051 | /* Timeout for 4 chars at 9600, 8 bits per char, 1 stop bit */ |
---|
1052 | cd2401->u2.w.rtpr = 0x04; /* NEED TO LOOK AT THIS LINE! */ |
---|
1053 | |
---|
1054 | if ( t->c_cflag & CREAD ) { |
---|
1055 | /* Re-initialize channel, enable rx and tx */ |
---|
1056 | cd2401_chan_cmd (minor, 0x2A, 1); |
---|
1057 | /* Enable rx data ints */ |
---|
1058 | cd2401->ier = 0x08; |
---|
1059 | } else { |
---|
1060 | /* Re-initialize channel, enable tx, disable rx */ |
---|
1061 | cd2401_chan_cmd (minor, 0x29, 1); |
---|
1062 | } |
---|
1063 | } |
---|
1064 | |
---|
1065 | CD2401_RECORD_SET_ATTRIBUTES_INFO(( minor, need_reinitialization, csize, |
---|
1066 | cstopb, parodd, parenb, ignpar, inpck, |
---|
1067 | hw_flow_ctl, sw_flow_ctl, extra_flow_ctl, |
---|
1068 | icrnl, igncr, inlcr, brkint, ignbrk, |
---|
1069 | parmrk, istrip, tx_period, rx_period, |
---|
1070 | out_baud, in_baud )); |
---|
1071 | |
---|
1072 | rtems_interrupt_enable (level); |
---|
1073 | |
---|
1074 | /* |
---|
1075 | * Looks like the CD2401 needs time to settle after initialization. Give it |
---|
1076 | * 10 ms. I don't really believe it, but if output resumes to quickly after |
---|
1077 | * this call, the first few characters are not right. |
---|
1078 | */ |
---|
1079 | if ( need_reinitialization ) |
---|
1080 | cd2401_udelay( 10000L ); |
---|
1081 | |
---|
1082 | /* Return something */ |
---|
1083 | return RTEMS_SUCCESSFUL; |
---|
1084 | } |
---|
1085 | |
---|
1086 | |
---|
1087 | /* |
---|
1088 | * cd2401_startRemoreTx |
---|
1089 | * |
---|
1090 | * Defined as a callback, but it would appear that it is never called. The |
---|
1091 | * POSIX standard states that when the tcflow() function is called with the |
---|
1092 | * TCION action, the system wall transmit a START character. Presumably, |
---|
1093 | * tcflow() is called internally when IXOFF is set in the termios c_iflag |
---|
1094 | * field when the input buffer can accomodate enough characters. It should |
---|
1095 | * probably be called from fillBufferQueue(). Clearly, the function is also |
---|
1096 | * explicitly callable by user code. The action is clearly to send the START |
---|
1097 | * character, regardless of whether START/STOP flow control is in effect. |
---|
1098 | * |
---|
1099 | * Input parameters: |
---|
1100 | * minor - selected channel |
---|
1101 | * |
---|
1102 | * Output parameters: NONE |
---|
1103 | * |
---|
1104 | * Return value: IGNORED |
---|
1105 | * |
---|
1106 | * PROPER START CHARACTER MUST BE PROGRAMMED IN SCHR1. |
---|
1107 | */ |
---|
1108 | int cd2401_startRemoteTx( |
---|
1109 | int minor |
---|
1110 | ) |
---|
1111 | { |
---|
1112 | rtems_interrupt_level level; |
---|
1113 | |
---|
1114 | rtems_interrupt_disable (level); |
---|
1115 | |
---|
1116 | cd2401->car = minor; /* Select channel */ |
---|
1117 | cd2401->stcr = 0x01; /* Send SCHR1 ahead of chars in FIFO */ |
---|
1118 | |
---|
1119 | CD2401_RECORD_START_REMOTE_TX_INFO(( minor )); |
---|
1120 | |
---|
1121 | rtems_interrupt_enable (level); |
---|
1122 | |
---|
1123 | /* Return something */ |
---|
1124 | return RTEMS_SUCCESSFUL; |
---|
1125 | } |
---|
1126 | |
---|
1127 | |
---|
1128 | /* |
---|
1129 | * cd2401_stopRemoteTx |
---|
1130 | * |
---|
1131 | * Defined as a callback, but it would appear that it is never called. The |
---|
1132 | * POSIX standard states that when the tcflow() function is called with the |
---|
1133 | * TCIOFF function, the system wall transmit a STOP character. Presumably, |
---|
1134 | * tcflow() is called internally when IXOFF is set in the termios c_iflag |
---|
1135 | * field as the input buffer is about to overflow. It should probably be |
---|
1136 | * called from rtems_termios_enqueue_raw_characters(). Clearly, the function |
---|
1137 | * is also explicitly callable by user code. The action is clearly to send |
---|
1138 | * the STOP character, regardless of whether START/STOP flow control is in |
---|
1139 | * effect. |
---|
1140 | * |
---|
1141 | * Input parameters: |
---|
1142 | * minor - selected channel |
---|
1143 | * |
---|
1144 | * Output parameters: NONE |
---|
1145 | * |
---|
1146 | * Return value: IGNORED |
---|
1147 | * |
---|
1148 | * PROPER STOP CHARACTER MUST BE PROGRAMMED IN SCHR2. |
---|
1149 | */ |
---|
1150 | int cd2401_stopRemoteTx( |
---|
1151 | int minor |
---|
1152 | ) |
---|
1153 | { |
---|
1154 | rtems_interrupt_level level; |
---|
1155 | |
---|
1156 | rtems_interrupt_disable (level); |
---|
1157 | |
---|
1158 | cd2401->car = minor; /* Select channel */ |
---|
1159 | cd2401->stcr = 0x02; /* Send SCHR2 ahead of chars in FIFO */ |
---|
1160 | |
---|
1161 | CD2401_RECORD_STOP_REMOTE_TX_INFO(( minor )); |
---|
1162 | |
---|
1163 | rtems_interrupt_enable (level); |
---|
1164 | |
---|
1165 | /* Return something */ |
---|
1166 | return RTEMS_SUCCESSFUL; |
---|
1167 | } |
---|
1168 | |
---|
1169 | |
---|
1170 | /* |
---|
1171 | * cd2401_write |
---|
1172 | * |
---|
1173 | * Initiate DMA output. Termios guarantees that the buffer does not wrap |
---|
1174 | * around, so we can do DMA strait from the supplied buffer. |
---|
1175 | * |
---|
1176 | * Input parameters: |
---|
1177 | * minor - selected channel |
---|
1178 | * buf - output buffer |
---|
1179 | * len - number of chars to output |
---|
1180 | * |
---|
1181 | * Output parameters: NONE |
---|
1182 | * |
---|
1183 | * Return value: IGNORED |
---|
1184 | * |
---|
1185 | * MUST BE EXECUTED WITH THE CD2401 INTERRUPTS DISABLED! |
---|
1186 | * The processor is placed at interrupt level CD2401_INT_LEVEL explicitly in |
---|
1187 | * console_write(). The processor is necessarily at interrupt level 1 in |
---|
1188 | * cd2401_tx_isr(). |
---|
1189 | */ |
---|
1190 | int cd2401_write( |
---|
1191 | int minor, |
---|
1192 | const char *buf, |
---|
1193 | int len |
---|
1194 | ) |
---|
1195 | { |
---|
1196 | cd2401->car = minor; /* Select channel */ |
---|
1197 | |
---|
1198 | if ( (cd2401->dmabsts & 0x08) == 0 ) { |
---|
1199 | /* Next buffer is A. Wait for it to be ours. */ |
---|
1200 | while ( cd2401->atbsts & 0x01 ); |
---|
1201 | |
---|
1202 | CD2401_Channel_Info[minor].own_buf_A = FALSE; |
---|
1203 | CD2401_Channel_Info[minor].len = len; |
---|
1204 | CD2401_Channel_Info[minor].buf = buf; |
---|
1205 | cd2401->atbadru = (uint16_t)( ( (uint32_t) buf ) >> 16 ); |
---|
1206 | cd2401->atbadrl = (uint16_t)( (uint32_t) buf ); |
---|
1207 | cd2401->atbcnt = len; |
---|
1208 | CD2401_RECORD_WRITE_INFO(( len, buf, 'A' )); |
---|
1209 | cd2401->atbsts = 0x03; /* CD2401 owns buffer, int when empty */ |
---|
1210 | } |
---|
1211 | else { |
---|
1212 | /* Next buffer is B. Wait for it to be ours. */ |
---|
1213 | while ( cd2401->btbsts & 0x01 ); |
---|
1214 | |
---|
1215 | CD2401_Channel_Info[minor].own_buf_B = FALSE; |
---|
1216 | CD2401_Channel_Info[minor].len = len; |
---|
1217 | CD2401_Channel_Info[minor].buf = buf; |
---|
1218 | cd2401->btbadru = (uint16_t)( ( (uint32_t) buf ) >> 16 ); |
---|
1219 | cd2401->btbadrl = (uint16_t)( (uint32_t) buf ); |
---|
1220 | cd2401->btbcnt = len; |
---|
1221 | CD2401_RECORD_WRITE_INFO(( len, buf, 'B' )); |
---|
1222 | cd2401->btbsts = 0x03; /* CD2401 owns buffer, int when empty */ |
---|
1223 | } |
---|
1224 | /* Nuts -- Need TxD ints */ |
---|
1225 | CD2401_Channel_Info[minor].txEmpty = FALSE; |
---|
1226 | cd2401->ier |= 0x01; |
---|
1227 | |
---|
1228 | /* Return something */ |
---|
1229 | return RTEMS_SUCCESSFUL; |
---|
1230 | } |
---|
1231 | |
---|
1232 | #if 0 |
---|
1233 | /* |
---|
1234 | * cd2401_drainOutput |
---|
1235 | * |
---|
1236 | * Wait for the txEmpty indication on the specified channel. |
---|
1237 | * |
---|
1238 | * Input parameters: |
---|
1239 | * minor - selected channel |
---|
1240 | * |
---|
1241 | * Output parameters: NONE |
---|
1242 | * |
---|
1243 | * Return value: IGNORED |
---|
1244 | * |
---|
1245 | * MUST NOT BE EXECUTED WITH THE CD2401 INTERRUPTS DISABLED! |
---|
1246 | * The txEmpty flag is set by the tx ISR. |
---|
1247 | * |
---|
1248 | * DOES NOT WORK! DO NOT ENABLE THIS CODE. THE CD2401 DOES NOT COOPERATE! |
---|
1249 | * The code is here to document that the output FIFO is NOT empty when |
---|
1250 | * the CD2401 reports that the Tx buffer is empty. |
---|
1251 | */ |
---|
1252 | int cd2401_drainOutput( |
---|
1253 | int minor |
---|
1254 | ) |
---|
1255 | { |
---|
1256 | CD2401_RECORD_DRAIN_OUTPUT_INFO(( CD2401_Channel_Info[minor].txEmpty, |
---|
1257 | CD2401_Channel_Info[minor].own_buf_A, |
---|
1258 | CD2401_Channel_Info[minor].own_buf_B )); |
---|
1259 | |
---|
1260 | while( ! (CD2401_Channel_Info[minor].txEmpty && |
---|
1261 | CD2401_Channel_Info[minor].own_buf_A && |
---|
1262 | CD2401_Channel_Info[minor].own_buf_B) ); |
---|
1263 | |
---|
1264 | /* Return something */ |
---|
1265 | return RTEMS_SUCCESSFUL; |
---|
1266 | } |
---|
1267 | #endif |
---|
1268 | |
---|
1269 | |
---|
1270 | /* |
---|
1271 | * _167Bug_pollRead |
---|
1272 | * |
---|
1273 | * Read a character from the 167Bug console, and return it. Return -1 |
---|
1274 | * if there is no character in the input FIFO. |
---|
1275 | * |
---|
1276 | * Input parameters: |
---|
1277 | * minor - selected channel |
---|
1278 | * |
---|
1279 | * Output parameters: NONE |
---|
1280 | * |
---|
1281 | * Return value: char returned as positive signed int |
---|
1282 | * -1 if no character is present in the input FIFO. |
---|
1283 | * |
---|
1284 | * CANNOT BE COMBINED WITH INTERRUPT DRIVEN I/O! |
---|
1285 | */ |
---|
1286 | int _167Bug_pollRead( |
---|
1287 | int minor |
---|
1288 | ) |
---|
1289 | { |
---|
1290 | int char_not_available; |
---|
1291 | unsigned char c; |
---|
1292 | rtems_interrupt_level previous_level; |
---|
1293 | |
---|
1294 | /* |
---|
1295 | * Redirection of .INSTAT does not work: 167-Bug crashes. |
---|
1296 | * Switch the input stream to the specified port. |
---|
1297 | * Make sure this is atomic code. |
---|
1298 | */ |
---|
1299 | rtems_interrupt_disable( previous_level ); |
---|
1300 | |
---|
1301 | asm volatile( "movew %1, -(%%sp)\n\t"/* Channel */ |
---|
1302 | "trap #15\n\t" /* Trap to 167Bug */ |
---|
1303 | ".short 0x61\n\t" /* Code for .REDIR_I */ |
---|
1304 | "trap #15\n\t" /* Trap to 167Bug */ |
---|
1305 | ".short 0x01\n\t" /* Code for .INSTAT */ |
---|
1306 | "move %%cc, %0\n\t" /* Get condition codes */ |
---|
1307 | "andil #4, %0" /* Keep the Zero bit */ |
---|
1308 | : "=d" (char_not_available) : "d" (minor): "%%cc" ); |
---|
1309 | |
---|
1310 | if (char_not_available) { |
---|
1311 | rtems_interrupt_enable( previous_level ); |
---|
1312 | return -1; |
---|
1313 | } |
---|
1314 | |
---|
1315 | /* Read the char and return it */ |
---|
1316 | asm volatile( "subq.l #2,%%a7\n\t" /* Space for result */ |
---|
1317 | "trap #15\n\t" /* Trap to 167 Bug */ |
---|
1318 | ".short 0x00\n\t" /* Code for .INCHR */ |
---|
1319 | "moveb (%%a7)+, %0" /* Pop char into c */ |
---|
1320 | : "=d" (c) : ); |
---|
1321 | |
---|
1322 | rtems_interrupt_enable( previous_level ); |
---|
1323 | |
---|
1324 | return (int)c; |
---|
1325 | } |
---|
1326 | |
---|
1327 | |
---|
1328 | /* |
---|
1329 | * _167Bug_pollWrite |
---|
1330 | * |
---|
1331 | * Output buffer through 167Bug. Returns only once every character has been |
---|
1332 | * sent (polled output). |
---|
1333 | * |
---|
1334 | * Input parameters: |
---|
1335 | * minor - selected channel |
---|
1336 | * buf - output buffer |
---|
1337 | * len - number of chars to output |
---|
1338 | * |
---|
1339 | * Output parameters: NONE |
---|
1340 | * |
---|
1341 | * Return value: IGNORED |
---|
1342 | * |
---|
1343 | * CANNOT BE COMBINED WITH INTERRUPT DRIVEN I/O! |
---|
1344 | */ |
---|
1345 | int _167Bug_pollWrite( |
---|
1346 | int minor, |
---|
1347 | const char *buf, |
---|
1348 | int len |
---|
1349 | ) |
---|
1350 | { |
---|
1351 | const char *endbuf = buf + len; |
---|
1352 | |
---|
1353 | asm volatile( "pea (%0)\n\t" /* endbuf */ |
---|
1354 | "pea (%1)\n\t" /* buf */ |
---|
1355 | "movew #0x21, -(%%sp)\n\t" /* Code for .OUTSTR */ |
---|
1356 | "movew %2, -(%%sp)\n\t" /* Channel */ |
---|
1357 | "trap #15\n\t" /* Trap to 167Bug */ |
---|
1358 | ".short 0x60" /* Code for .REDIR */ |
---|
1359 | :: "a" (endbuf), "a" (buf), "d" (minor) ); |
---|
1360 | |
---|
1361 | /* Return something */ |
---|
1362 | return RTEMS_SUCCESSFUL; |
---|
1363 | } |
---|
1364 | |
---|
1365 | |
---|
1366 | /* |
---|
1367 | * do_poll_read |
---|
1368 | * |
---|
1369 | * Input characters through 167Bug. Returns has soon as a character has been |
---|
1370 | * received. Otherwise, if we wait for the number of requested characters, we |
---|
1371 | * could be here forever! |
---|
1372 | * |
---|
1373 | * CR is converted to LF on input. The terminal should not send a CR/LF pair |
---|
1374 | * when the return or enter key is pressed. |
---|
1375 | * |
---|
1376 | * Input parameters: |
---|
1377 | * major - ignored. Should be the major number for this driver. |
---|
1378 | * minor - selected channel. |
---|
1379 | * arg->buffer - where to put the received characters. |
---|
1380 | * arg->count - number of characters to receive before returning--Ignored. |
---|
1381 | * |
---|
1382 | * Output parameters: |
---|
1383 | * arg->bytes_moved - the number of characters read. Always 1. |
---|
1384 | * |
---|
1385 | * Return value: RTEMS_SUCCESSFUL |
---|
1386 | * |
---|
1387 | * CANNOT BE COMBINED WITH INTERRUPT DRIVEN I/O! |
---|
1388 | */ |
---|
1389 | rtems_status_code do_poll_read( |
---|
1390 | rtems_device_major_number major, |
---|
1391 | rtems_device_minor_number minor, |
---|
1392 | void * arg |
---|
1393 | ) |
---|
1394 | { |
---|
1395 | rtems_libio_rw_args_t *rw_args = arg; |
---|
1396 | int c; |
---|
1397 | |
---|
1398 | while( (c = _167Bug_pollRead (minor)) == -1 ); |
---|
1399 | rw_args->buffer[0] = (uint8_t)c; |
---|
1400 | if( rw_args->buffer[0] == '\r' ) |
---|
1401 | rw_args->buffer[0] = '\n'; |
---|
1402 | rw_args->bytes_moved = 1; |
---|
1403 | return RTEMS_SUCCESSFUL; |
---|
1404 | } |
---|
1405 | |
---|
1406 | /* |
---|
1407 | * do_poll_write |
---|
1408 | * |
---|
1409 | * Output characters through 167Bug. Returns only once every character has |
---|
1410 | * been sent. |
---|
1411 | * |
---|
1412 | * CR is transmitted AFTER a LF on output. |
---|
1413 | * |
---|
1414 | * Input parameters: |
---|
1415 | * major - ignored. Should be the major number for this driver. |
---|
1416 | * minor - selected channel |
---|
1417 | * arg->buffer - where to get the characters to transmit. |
---|
1418 | * arg->count - the number of characters to transmit before returning. |
---|
1419 | * |
---|
1420 | * Output parameters: |
---|
1421 | * arg->bytes_moved - the number of characters read |
---|
1422 | * |
---|
1423 | * Return value: RTEMS_SUCCESSFUL |
---|
1424 | * |
---|
1425 | * CANNOT BE COMBINED WITH INTERRUPT DRIVEN I/O! |
---|
1426 | */ |
---|
1427 | rtems_status_code do_poll_write( |
---|
1428 | rtems_device_major_number major, |
---|
1429 | rtems_device_minor_number minor, |
---|
1430 | void * arg |
---|
1431 | ) |
---|
1432 | { |
---|
1433 | rtems_libio_rw_args_t *rw_args = arg; |
---|
1434 | uint32_t i; |
---|
1435 | char cr ='\r'; |
---|
1436 | |
---|
1437 | for( i = 0; i < rw_args->count; i++ ) { |
---|
1438 | _167Bug_pollWrite(minor, &(rw_args->buffer[i]), 1); |
---|
1439 | if ( rw_args->buffer[i] == '\n' ) |
---|
1440 | _167Bug_pollWrite(minor, &cr, 1); |
---|
1441 | } |
---|
1442 | rw_args->bytes_moved = i; |
---|
1443 | return RTEMS_SUCCESSFUL; |
---|
1444 | } |
---|
1445 | |
---|
1446 | |
---|
1447 | /* |
---|
1448 | * _BSP_output_char |
---|
1449 | * |
---|
1450 | * printk() function prototyped in bspIo.h. Does not use termios. |
---|
1451 | */ |
---|
1452 | void _BSP_output_char(char c) |
---|
1453 | { |
---|
1454 | rtems_device_minor_number printk_minor; |
---|
1455 | char cr ='\r'; |
---|
1456 | |
---|
1457 | /* |
---|
1458 | * Can't rely on console_initialize having been called before this function |
---|
1459 | * is used. |
---|
1460 | */ |
---|
1461 | if ( NVRAM_CONFIGURE ) |
---|
1462 | /* J1-4 is on, use NVRAM info for configuration */ |
---|
1463 | printk_minor = (nvram->console_printk_port & 0x30) >> 4; |
---|
1464 | else |
---|
1465 | printk_minor = PRINTK_MINOR; |
---|
1466 | |
---|
1467 | _167Bug_pollWrite(printk_minor, &c, 1); |
---|
1468 | if ( c == '\n' ) |
---|
1469 | _167Bug_pollWrite(printk_minor, &cr, 1); |
---|
1470 | } |
---|
1471 | |
---|
1472 | |
---|
1473 | /* |
---|
1474 | *************** |
---|
1475 | * BOILERPLATE * |
---|
1476 | *************** |
---|
1477 | * |
---|
1478 | * All these functions are prototyped in rtems/c/src/lib/include/console.h. |
---|
1479 | */ |
---|
1480 | |
---|
1481 | /* |
---|
1482 | * Initialize and register the device |
---|
1483 | */ |
---|
1484 | rtems_device_driver console_initialize( |
---|
1485 | rtems_device_major_number major, |
---|
1486 | rtems_device_minor_number minor, |
---|
1487 | void *arg |
---|
1488 | ) |
---|
1489 | { |
---|
1490 | rtems_status_code status; |
---|
1491 | rtems_device_minor_number console_minor; |
---|
1492 | |
---|
1493 | /* |
---|
1494 | * Set up TERMIOS if needed |
---|
1495 | */ |
---|
1496 | if ( NVRAM_CONFIGURE ) { |
---|
1497 | /* J1-4 is on, use NVRAM info for configuration */ |
---|
1498 | console_minor = nvram->console_printk_port & 0x03; |
---|
1499 | |
---|
1500 | if ( nvram->console_mode & 0x01 ) |
---|
1501 | /* termios */ |
---|
1502 | rtems_termios_initialize (); |
---|
1503 | } |
---|
1504 | else { |
---|
1505 | console_minor = CONSOLE_MINOR; |
---|
1506 | #if CD2401_USE_TERMIOS == 1 |
---|
1507 | rtems_termios_initialize (); |
---|
1508 | #endif |
---|
1509 | } |
---|
1510 | |
---|
1511 | /* |
---|
1512 | * Do device-specific initialization |
---|
1513 | * Does not affect 167-Bug. |
---|
1514 | */ |
---|
1515 | cd2401_initialize (); |
---|
1516 | |
---|
1517 | /* |
---|
1518 | * Register the devices |
---|
1519 | */ |
---|
1520 | status = rtems_io_register_name ("/dev/tty0", major, 0); |
---|
1521 | if (status != RTEMS_SUCCESSFUL) |
---|
1522 | rtems_fatal_error_occurred (status); |
---|
1523 | |
---|
1524 | status = rtems_io_register_name ("/dev/tty1", major, 1); |
---|
1525 | if (status != RTEMS_SUCCESSFUL) |
---|
1526 | rtems_fatal_error_occurred (status); |
---|
1527 | |
---|
1528 | status = rtems_io_register_name ("/dev/console", major, console_minor); |
---|
1529 | if (status != RTEMS_SUCCESSFUL) |
---|
1530 | rtems_fatal_error_occurred (status); |
---|
1531 | |
---|
1532 | status = rtems_io_register_name ("/dev/tty2", major, 2); |
---|
1533 | if (status != RTEMS_SUCCESSFUL) |
---|
1534 | rtems_fatal_error_occurred (status); |
---|
1535 | |
---|
1536 | status = rtems_io_register_name ("/dev/tty3", major, 3); |
---|
1537 | if (status != RTEMS_SUCCESSFUL) |
---|
1538 | rtems_fatal_error_occurred (status); |
---|
1539 | |
---|
1540 | return RTEMS_SUCCESSFUL; |
---|
1541 | } |
---|
1542 | |
---|
1543 | /* |
---|
1544 | * Open the device |
---|
1545 | */ |
---|
1546 | rtems_device_driver console_open( |
---|
1547 | rtems_device_major_number major, |
---|
1548 | rtems_device_minor_number minor, |
---|
1549 | void * arg |
---|
1550 | ) |
---|
1551 | { |
---|
1552 | static const rtems_termios_callbacks pollCallbacks = { |
---|
1553 | NULL, /* firstOpen */ |
---|
1554 | NULL, /* lastClose */ |
---|
1555 | _167Bug_pollRead, /* pollRead */ |
---|
1556 | _167Bug_pollWrite, /* write */ |
---|
1557 | NULL, /* setAttributes */ |
---|
1558 | NULL, /* stopRemoteTx */ |
---|
1559 | NULL, /* startRemoteTx */ |
---|
1560 | 0 /* outputUsesInterrupts */ |
---|
1561 | }; |
---|
1562 | |
---|
1563 | static const rtems_termios_callbacks intrCallbacks = { |
---|
1564 | cd2401_firstOpen, /* firstOpen */ |
---|
1565 | cd2401_lastClose, /* lastClose */ |
---|
1566 | NULL, /* pollRead */ |
---|
1567 | cd2401_write, /* write */ |
---|
1568 | cd2401_setAttributes, /* setAttributes */ |
---|
1569 | cd2401_stopRemoteTx, /* stopRemoteTx */ |
---|
1570 | cd2401_startRemoteTx, /* startRemoteTx */ |
---|
1571 | 1 /* outputUsesInterrupts */ |
---|
1572 | }; |
---|
1573 | |
---|
1574 | if ( NVRAM_CONFIGURE ) |
---|
1575 | /* J1-4 is on, use NVRAM info for configuration */ |
---|
1576 | if ( nvram->console_mode & 0x01 ) |
---|
1577 | /* termios */ |
---|
1578 | if ( nvram->console_mode & 0x02 ) |
---|
1579 | /* interrupt-driven I/O */ |
---|
1580 | return rtems_termios_open (major, minor, arg, &intrCallbacks); |
---|
1581 | else |
---|
1582 | /* polled I/O */ |
---|
1583 | return rtems_termios_open (major, minor, arg, &pollCallbacks); |
---|
1584 | else |
---|
1585 | /* no termios -- default to polled I/O */ |
---|
1586 | return RTEMS_SUCCESSFUL; |
---|
1587 | #if CD2401_USE_TERMIOS == 1 |
---|
1588 | #if CD2401_IO_MODE != 1 |
---|
1589 | else |
---|
1590 | /* termios & polled I/O*/ |
---|
1591 | return rtems_termios_open (major, minor, arg, &pollCallbacks); |
---|
1592 | #else |
---|
1593 | else |
---|
1594 | /* termios & interrupt-driven I/O*/ |
---|
1595 | return rtems_termios_open (major, minor, arg, &intrCallbacks); |
---|
1596 | #endif |
---|
1597 | #else |
---|
1598 | else |
---|
1599 | /* no termios -- default to polled I/O */ |
---|
1600 | return RTEMS_SUCCESSFUL; |
---|
1601 | #endif |
---|
1602 | } |
---|
1603 | |
---|
1604 | |
---|
1605 | /* |
---|
1606 | * Close the device |
---|
1607 | */ |
---|
1608 | rtems_device_driver console_close( |
---|
1609 | rtems_device_major_number major, |
---|
1610 | rtems_device_minor_number minor, |
---|
1611 | void * arg |
---|
1612 | ) |
---|
1613 | { |
---|
1614 | if ( NVRAM_CONFIGURE ) { |
---|
1615 | /* J1-4 is on, use NVRAM info for configuration */ |
---|
1616 | if ( nvram->console_mode & 0x01 ) |
---|
1617 | /* termios */ |
---|
1618 | return rtems_termios_close (arg); |
---|
1619 | else |
---|
1620 | /* no termios */ |
---|
1621 | return RTEMS_SUCCESSFUL; |
---|
1622 | } |
---|
1623 | #if CD2401_USE_TERMIOS == 1 |
---|
1624 | else |
---|
1625 | /* termios */ |
---|
1626 | return rtems_termios_close (arg); |
---|
1627 | #else |
---|
1628 | else |
---|
1629 | /* no termios */ |
---|
1630 | return RTEMS_SUCCESSFUL; |
---|
1631 | #endif |
---|
1632 | } |
---|
1633 | |
---|
1634 | |
---|
1635 | /* |
---|
1636 | * Read from the device |
---|
1637 | */ |
---|
1638 | rtems_device_driver console_read( |
---|
1639 | rtems_device_major_number major, |
---|
1640 | rtems_device_minor_number minor, |
---|
1641 | void * arg |
---|
1642 | ) |
---|
1643 | { |
---|
1644 | if ( NVRAM_CONFIGURE ) { |
---|
1645 | /* J1-4 is on, use NVRAM info for configuration */ |
---|
1646 | if ( nvram->console_mode & 0x01 ) |
---|
1647 | /* termios */ |
---|
1648 | return rtems_termios_read (arg); |
---|
1649 | else |
---|
1650 | /* no termios -- default to polled */ |
---|
1651 | return do_poll_read (major, minor, arg); |
---|
1652 | } |
---|
1653 | #if CD2401_USE_TERMIOS == 1 |
---|
1654 | else |
---|
1655 | /* termios */ |
---|
1656 | return rtems_termios_read (arg); |
---|
1657 | #else |
---|
1658 | else |
---|
1659 | /* no termios -- default to polled */ |
---|
1660 | return do_poll_read (major, minor, arg); |
---|
1661 | #endif |
---|
1662 | } |
---|
1663 | |
---|
1664 | |
---|
1665 | /* |
---|
1666 | * Write to the device |
---|
1667 | */ |
---|
1668 | rtems_device_driver console_write( |
---|
1669 | rtems_device_major_number major, |
---|
1670 | rtems_device_minor_number minor, |
---|
1671 | void * arg |
---|
1672 | ) |
---|
1673 | { |
---|
1674 | if ( NVRAM_CONFIGURE ) { |
---|
1675 | /* J1-4 is on, use NVRAM info for configuration */ |
---|
1676 | if ( nvram->console_mode & 0x01 ) |
---|
1677 | /* termios */ |
---|
1678 | return rtems_termios_write (arg); |
---|
1679 | else |
---|
1680 | /* no termios -- default to polled */ |
---|
1681 | return do_poll_write (major, minor, arg); |
---|
1682 | } |
---|
1683 | #if CD2401_USE_TERMIOS == 1 |
---|
1684 | else |
---|
1685 | /* termios */ |
---|
1686 | return rtems_termios_write (arg); |
---|
1687 | #else |
---|
1688 | else |
---|
1689 | /* no termios -- default to polled */ |
---|
1690 | return do_poll_write (major, minor, arg); |
---|
1691 | #endif |
---|
1692 | } |
---|
1693 | |
---|
1694 | |
---|
1695 | /* |
---|
1696 | * Handle ioctl request. |
---|
1697 | */ |
---|
1698 | rtems_device_driver console_control( |
---|
1699 | rtems_device_major_number major, |
---|
1700 | rtems_device_minor_number minor, |
---|
1701 | void * arg |
---|
1702 | ) |
---|
1703 | { |
---|
1704 | if ( NVRAM_CONFIGURE ) { |
---|
1705 | /* J1-4 is on, use NVRAM info for configuration */ |
---|
1706 | if ( nvram->console_mode & 0x01 ) |
---|
1707 | /* termios */ |
---|
1708 | return rtems_termios_ioctl (arg); |
---|
1709 | else |
---|
1710 | /* no termios -- default to polled */ |
---|
1711 | return RTEMS_SUCCESSFUL; |
---|
1712 | } |
---|
1713 | #if CD2401_USE_TERMIOS == 1 |
---|
1714 | else |
---|
1715 | /* termios */ |
---|
1716 | return rtems_termios_ioctl (arg); |
---|
1717 | #else |
---|
1718 | else |
---|
1719 | /* no termios -- default to polled */ |
---|
1720 | return RTEMS_SUCCESSFUL; |
---|
1721 | #endif |
---|
1722 | } |
---|