1 | /* |
---|
2 | * This file contains the MVME136 console IO package. |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * All rights assigned to U.S. Government, 1994. |
---|
7 | * |
---|
8 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
9 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
10 | * notice must appear in all copies of this file and its derivatives. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #define M136_INIT |
---|
16 | |
---|
17 | #include <rtems.h> |
---|
18 | #include "console.h" |
---|
19 | #include "bsp.h" |
---|
20 | |
---|
21 | /* console_initialize |
---|
22 | * |
---|
23 | * This routine initializes the console IO driver. |
---|
24 | * |
---|
25 | * Input parameters: NONE |
---|
26 | * |
---|
27 | * Output parameters: NONE |
---|
28 | * |
---|
29 | * Return values: |
---|
30 | */ |
---|
31 | |
---|
32 | rtems_device_driver console_initialize( |
---|
33 | rtems_device_major_number major, |
---|
34 | rtems_device_minor_number minor, |
---|
35 | void *arg, |
---|
36 | rtems_id self, |
---|
37 | rtems_unsigned32 *status |
---|
38 | ) |
---|
39 | { |
---|
40 | _Write_m681 = ( struct w_m681_info * ) M681ADDR; |
---|
41 | _Read_m681 = ( struct r_m681_info * ) M681ADDR; |
---|
42 | *status = RTEMS_SUCCESSFUL; |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | /* is_character_ready |
---|
47 | * |
---|
48 | * This routine returns TRUE if a character is available. |
---|
49 | * |
---|
50 | * Input parameters: NONE |
---|
51 | * |
---|
52 | * Output parameters: NONE |
---|
53 | * |
---|
54 | * Return values: |
---|
55 | */ |
---|
56 | |
---|
57 | rtems_boolean is_character_ready( |
---|
58 | char *ch |
---|
59 | ) |
---|
60 | { |
---|
61 | if ( !(_Read_m681->srb & RXRDYB) ) |
---|
62 | return(FALSE); |
---|
63 | |
---|
64 | *ch = _Read_m681->rbb; |
---|
65 | return(TRUE); |
---|
66 | } |
---|
67 | |
---|
68 | /* inbyte |
---|
69 | * |
---|
70 | * This routine reads a character from the UART. |
---|
71 | * |
---|
72 | * Input parameters: NONE |
---|
73 | * |
---|
74 | * Output parameters: NONE |
---|
75 | * |
---|
76 | * Return values: |
---|
77 | * character read from UART |
---|
78 | */ |
---|
79 | |
---|
80 | char inbyte( void ) |
---|
81 | { |
---|
82 | while ( !(_Read_m681->srb & RXRDYB) ); |
---|
83 | return _Read_m681->rbb; |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | /* outbyte |
---|
88 | * |
---|
89 | * This routine transmits a character out the M68681. It supports |
---|
90 | * XON/XOFF flow control. |
---|
91 | * |
---|
92 | * Input parameters: |
---|
93 | * ch - character to be transmitted |
---|
94 | * |
---|
95 | * Output parameters: NONE |
---|
96 | */ |
---|
97 | |
---|
98 | void outbyte( |
---|
99 | char ch |
---|
100 | ) |
---|
101 | { |
---|
102 | while ( ! (_Read_m681->srb & TXRDYB) ) ; |
---|
103 | while ( _Read_m681->srb & RXRDYB ) /* must be an XOFF */ |
---|
104 | if ( _Read_m681->rbb == XOFF ) |
---|
105 | do { |
---|
106 | while ( ! (_Read_m681->srb & RXRDYB) ) ; |
---|
107 | } while ( _Read_m681->rbb != XON ); |
---|
108 | |
---|
109 | _Write_m681->tbb = ch; |
---|
110 | if ( ch == '\n' ) |
---|
111 | outbyte( CR ); |
---|
112 | } |
---|
113 | |
---|
114 | /* |
---|
115 | * __read -- read bytes from the serial port. Ignore fd, since |
---|
116 | * we only have stdin. |
---|
117 | */ |
---|
118 | |
---|
119 | int __read( |
---|
120 | int fd, |
---|
121 | char *buf, |
---|
122 | int nbytes |
---|
123 | ) |
---|
124 | { |
---|
125 | int i = 0; |
---|
126 | |
---|
127 | for (i = 0; i < nbytes; i++) { |
---|
128 | *(buf + i) = inbyte(); |
---|
129 | if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) { |
---|
130 | (*(buf + i++)) = '\n'; |
---|
131 | (*(buf + i)) = 0; |
---|
132 | break; |
---|
133 | } |
---|
134 | } |
---|
135 | return (i); |
---|
136 | } |
---|
137 | |
---|
138 | /* |
---|
139 | * __write -- write bytes to the serial port. Ignore fd, since |
---|
140 | * stdout and stderr are the same. Since we have no filesystem, |
---|
141 | * open will only return an error. |
---|
142 | */ |
---|
143 | |
---|
144 | int __write( |
---|
145 | int fd, |
---|
146 | char *buf, |
---|
147 | int nbytes |
---|
148 | ) |
---|
149 | { |
---|
150 | int i; |
---|
151 | |
---|
152 | for (i = 0; i < nbytes; i++) { |
---|
153 | if (*(buf + i) == '\n') { |
---|
154 | outbyte ('\r'); |
---|
155 | } |
---|
156 | outbyte (*(buf + i)); |
---|
157 | } |
---|
158 | return (nbytes); |
---|
159 | } |
---|