1 | /* |
---|
2 | * This file contains the Motorola IDP console IO package. |
---|
3 | * |
---|
4 | * Written by Doug McBride, Colorado Space Grant College |
---|
5 | * Based off of the board support packages of RTEMS |
---|
6 | * |
---|
7 | * Updated to RTEMS 3.2.0 by Joel Sherrill. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #define MIDP_INIT |
---|
13 | |
---|
14 | #include "rtems.h" |
---|
15 | #include "console.h" |
---|
16 | #include "bsp.h" |
---|
17 | |
---|
18 | #include "ringbuf.h" |
---|
19 | |
---|
20 | Ring_buffer_t Buffer[ 2 ]; |
---|
21 | |
---|
22 | rtems_isr C_Receive_ISR(rtems_vector_number vector); |
---|
23 | |
---|
24 | |
---|
25 | /* console_initialize |
---|
26 | * |
---|
27 | * This routine initializes the console IO driver. |
---|
28 | * |
---|
29 | * Input parameters: NONE |
---|
30 | * |
---|
31 | * Output parameters: NONE |
---|
32 | * |
---|
33 | * Return values: |
---|
34 | */ |
---|
35 | |
---|
36 | rtems_device_driver console_initialize( |
---|
37 | rtems_device_major_number major, |
---|
38 | rtems_device_minor_number minor, |
---|
39 | void *arg, |
---|
40 | rtems_id self, |
---|
41 | rtems_unsigned32 *status |
---|
42 | ) |
---|
43 | { |
---|
44 | |
---|
45 | Ring_buffer_Initialize( &Buffer[ 0 ] ); |
---|
46 | Ring_buffer_Initialize( &Buffer[ 1 ] ); |
---|
47 | |
---|
48 | init_pit(); |
---|
49 | |
---|
50 | *status = RTEMS_SUCCESSFUL; |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | /* is_character_ready |
---|
55 | * |
---|
56 | * This routine returns TRUE if a character is available. |
---|
57 | * |
---|
58 | * Input parameters: NONE |
---|
59 | * |
---|
60 | * Output parameters: NONE |
---|
61 | * |
---|
62 | * Return values: |
---|
63 | */ |
---|
64 | |
---|
65 | rtems_boolean is_character_ready( |
---|
66 | char *ch, |
---|
67 | int port |
---|
68 | ) |
---|
69 | { |
---|
70 | if ( Ring_buffer_Is_empty( &Buffer[ port ] ) ) |
---|
71 | return FALSE; |
---|
72 | |
---|
73 | Ring_buffer_Remove_character( &Buffer[ port ], *ch ); |
---|
74 | return TRUE; |
---|
75 | } |
---|
76 | |
---|
77 | /* quick_char_check |
---|
78 | * |
---|
79 | * This routine returns TRUE if a character is available. |
---|
80 | * It is different from above because it does not disturb the ring buffer |
---|
81 | * |
---|
82 | * Input parameters: NONE |
---|
83 | * |
---|
84 | * Output parameters: NONE |
---|
85 | * |
---|
86 | * Return values: |
---|
87 | */ |
---|
88 | |
---|
89 | rtems_boolean quick_char_check( |
---|
90 | int port |
---|
91 | ) |
---|
92 | { |
---|
93 | if ( Ring_buffer_Is_empty( &Buffer[ port ] ) ) |
---|
94 | return FALSE; |
---|
95 | |
---|
96 | return TRUE; |
---|
97 | } |
---|
98 | |
---|
99 | /* inbyte |
---|
100 | * |
---|
101 | * This routine reads a character from the UART through a buffer. |
---|
102 | * |
---|
103 | * Input parameters: NONE |
---|
104 | * |
---|
105 | * Output parameters: NONE |
---|
106 | * |
---|
107 | * Return values: |
---|
108 | * character read from UART |
---|
109 | */ |
---|
110 | |
---|
111 | char inbyte( |
---|
112 | int port |
---|
113 | ) |
---|
114 | { |
---|
115 | unsigned char tmp_char; |
---|
116 | |
---|
117 | /* If you come into this routine without checking is_character_ready() first |
---|
118 | and you want nonblocking code, then it's your own fault */ |
---|
119 | |
---|
120 | while ( !is_character_ready( &tmp_char, port ) ); |
---|
121 | |
---|
122 | return tmp_char; |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | /* outbyte |
---|
127 | * |
---|
128 | * This routine transmits a character out the M68681. It supports |
---|
129 | * XON/XOFF flow control. |
---|
130 | * |
---|
131 | * Input parameters: |
---|
132 | * ch - character to be transmitted |
---|
133 | * |
---|
134 | * Output parameters: NONE |
---|
135 | */ |
---|
136 | |
---|
137 | void outbyte( |
---|
138 | char ch, |
---|
139 | int port |
---|
140 | ) |
---|
141 | { |
---|
142 | switch ( port ) { |
---|
143 | case 0: |
---|
144 | transmit_char( ch ); |
---|
145 | break; |
---|
146 | case 1: |
---|
147 | transmit_char_portb( ch ); |
---|
148 | break; |
---|
149 | } |
---|
150 | |
---|
151 | } |
---|
152 | |
---|
153 | /* |
---|
154 | * __read -- read bytes from the serial port. Ignore fd, since |
---|
155 | * we only have stdin. |
---|
156 | */ |
---|
157 | |
---|
158 | int __read( |
---|
159 | int fd, |
---|
160 | char *buf, |
---|
161 | int nbytes |
---|
162 | ) |
---|
163 | { |
---|
164 | int i = 0; |
---|
165 | int port; |
---|
166 | |
---|
167 | /* |
---|
168 | * Map port A to stdin, stdout, and stderr. |
---|
169 | * Map everything else to port B. |
---|
170 | */ |
---|
171 | |
---|
172 | if ( fd <= 2 ) port = 0; |
---|
173 | else port = 1; |
---|
174 | |
---|
175 | for (i = 0; i < nbytes; i++) { |
---|
176 | *(buf + i) = inbyte( port ); |
---|
177 | if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) { |
---|
178 | (*(buf + i++)) = '\n'; |
---|
179 | (*(buf + i)) = 0; |
---|
180 | break; |
---|
181 | } |
---|
182 | } |
---|
183 | return (i); |
---|
184 | } |
---|
185 | |
---|
186 | /* |
---|
187 | * __write -- write bytes to the serial port. Ignore fd, since |
---|
188 | * stdout and stderr are the same. Since we have no filesystem, |
---|
189 | * open will only return an error. |
---|
190 | */ |
---|
191 | |
---|
192 | int __write( |
---|
193 | int fd, |
---|
194 | char *buf, |
---|
195 | int nbytes |
---|
196 | ) |
---|
197 | { |
---|
198 | int i; |
---|
199 | int port; |
---|
200 | |
---|
201 | /* |
---|
202 | * Map port A to stdin, stdout, and stderr. |
---|
203 | * Map everything else to port B. |
---|
204 | */ |
---|
205 | |
---|
206 | if ( fd <= 2 ) port = 0; |
---|
207 | else port = 1; |
---|
208 | |
---|
209 | for (i = 0; i < nbytes; i++) { |
---|
210 | if (*(buf + i) == '\n') { |
---|
211 | outbyte ('\r', port ); |
---|
212 | } |
---|
213 | outbyte (*(buf + i), port ); |
---|
214 | } |
---|
215 | return (nbytes); |
---|
216 | } |
---|