1 | /* |
---|
2 | * This file contains the MVME162LX extended console IO package. |
---|
3 | * |
---|
4 | * This file was created originally by |
---|
5 | * On-Line Applications Research Corporation (OAR) |
---|
6 | * and modified by: |
---|
7 | * |
---|
8 | * Katsutoshi Shibuya - BU-Denken Co.,Ltd. - Sapporo, JAPAN |
---|
9 | * |
---|
10 | * featuring support of: |
---|
11 | * |
---|
12 | * - Multi-SCC chip handling |
---|
13 | * - Non-blocking I/O (O_NDELAY flag in libc) |
---|
14 | * - Raw mode device (no CR/LF detection) |
---|
15 | * - RTS/CTS flow control |
---|
16 | * |
---|
17 | * REMARKS: This routine requires multiple interrupt vectors |
---|
18 | * from SCC_VECTOR (normaly 0x40) |
---|
19 | * to SCC_VECTOR+(number of SCC chips) |
---|
20 | * |
---|
21 | * The original copyright follows; |
---|
22 | * |
---|
23 | * COPYRIGHT (c) 1989-1997. |
---|
24 | * On-Line Applications Research Corporation (OAR). |
---|
25 | * Copyright assigned to U.S. Government, 1994. |
---|
26 | * |
---|
27 | * The license and distribution terms for this file may in |
---|
28 | * the file LICENSE in this distribution or at |
---|
29 | * http://www.OARcorp.com/rtems/license.html. |
---|
30 | * |
---|
31 | * Modifications of respective RTEMS file: COPYRIGHT (c) 1994. |
---|
32 | * EISCAT Scientific Association. M.Savitski |
---|
33 | * |
---|
34 | * This material is a part of the MVME162 Board Support Package |
---|
35 | * for the RTEMS executive. Its licensing policies are those of the |
---|
36 | * RTEMS above. |
---|
37 | * |
---|
38 | */ |
---|
39 | |
---|
40 | #define M162_INIT |
---|
41 | |
---|
42 | #include "consolex.h" |
---|
43 | #include <bsp.h> |
---|
44 | #include <rtems/libio.h> |
---|
45 | #include <stdio.h> |
---|
46 | #include <string.h> |
---|
47 | #include <ctype.h> |
---|
48 | |
---|
49 | #define NPORTS 4 /* Number of ports */ |
---|
50 | #define DEVICEPREFIX "tty" |
---|
51 | #define RAWDEVICEPREFIX "rtty" |
---|
52 | #define CONSOLEPORT 0 /* port# of console: |
---|
53 | undef this if you do not want /dev/console */ |
---|
54 | #define READRETRY 1 /* Maximum retry count for read one char */ |
---|
55 | #define WRITERETRY 8 /* Maximum retry count for write one char */ |
---|
56 | |
---|
57 | #define PORTFROM 0 /* for debug */ |
---|
58 | |
---|
59 | static unsigned char opencount[NPORTS]; |
---|
60 | |
---|
61 | /*********************************************************************** |
---|
62 | Ring buffer for device |
---|
63 | ***********************************************************************/ |
---|
64 | |
---|
65 | #define QUEUE_LENGTH 128 /* Must be 2^n number */ |
---|
66 | |
---|
67 | typedef struct { |
---|
68 | char buffer[QUEUE_LENGTH]; |
---|
69 | volatile int head; |
---|
70 | volatile int tail; |
---|
71 | } ReceiverBuffer; |
---|
72 | |
---|
73 | #define ReceiverBufferInitialize( _buffer ) \ |
---|
74 | do { \ |
---|
75 | (_buffer)->head = (_buffer)->tail = 0; \ |
---|
76 | } while ( 0 ) |
---|
77 | |
---|
78 | #define ReceiverBufferIsEmpty( _buffer ) \ |
---|
79 | ( (_buffer)->tail == (_buffer)->head ) |
---|
80 | |
---|
81 | #define ReceiverBufferIsNearEmpty( _buffer ) \ |
---|
82 | ( (_buffer)->tail == (((_buffer)->head + 3) & (QUEUE_LENGTH-1)) ) |
---|
83 | |
---|
84 | #define ReceiverBufferIsFull( _buffer ) \ |
---|
85 | ( (_buffer)->head == (((_buffer)->tail + 1) & (QUEUE_LENGTH-1)) ) |
---|
86 | |
---|
87 | #define ReceiverBufferIsNearFull( _buffer ) \ |
---|
88 | ( (_buffer)->head == (((_buffer)->tail + 3) & (QUEUE_LENGTH-1)) ) |
---|
89 | |
---|
90 | #define ReceiverBufferAdd( _buffer, _ch ) \ |
---|
91 | do { \ |
---|
92 | rtems_unsigned32 isrlevel; \ |
---|
93 | \ |
---|
94 | rtems_interrupt_disable( isrlevel ); \ |
---|
95 | (_buffer)->tail = ((_buffer)->tail+1) & (QUEUE_LENGTH-1); \ |
---|
96 | (_buffer)->buffer[ (_buffer)->tail ] = (_ch); \ |
---|
97 | rtems_interrupt_enable( isrlevel ); \ |
---|
98 | } while ( 0 ) |
---|
99 | |
---|
100 | #define ReceiverBufferRemove( _buffer, _ch ) \ |
---|
101 | do { \ |
---|
102 | rtems_unsigned32 isrlevel; \ |
---|
103 | \ |
---|
104 | rtems_interrupt_disable( isrlevel ); \ |
---|
105 | (_buffer)->head = ((_buffer)->head+1) & (QUEUE_LENGTH-1); \ |
---|
106 | (_ch) = (_buffer)->buffer[ (_buffer)->head ]; \ |
---|
107 | rtems_interrupt_enable( isrlevel ); \ |
---|
108 | } while ( 0 ) |
---|
109 | |
---|
110 | |
---|
111 | /*********************************************************************** |
---|
112 | DEVICE DEPENDED PART |
---|
113 | ***********************************************************************/ |
---|
114 | |
---|
115 | |
---|
116 | /* Time constant parameters |
---|
117 | CAUTION: These parameters are for MVME162LX-213 board. |
---|
118 | */ |
---|
119 | |
---|
120 | #define TC38400 0x0006 |
---|
121 | #define TC19200 0x000e |
---|
122 | #define TC9600 0x001e |
---|
123 | |
---|
124 | /* Re-defining SCC register control macros |
---|
125 | to support Multi SCC chips */ |
---|
126 | |
---|
127 | #undef scc |
---|
128 | #if defined(mvme162lx) |
---|
129 | static scc_regs *scc[NPORTS] = { |
---|
130 | ((scc_regs * const) 0xFFF45004), |
---|
131 | ((scc_regs * const) 0xFFF45000), |
---|
132 | ((scc_regs * const) 0xFFF45804), |
---|
133 | ((scc_regs * const) 0xFFF45800) |
---|
134 | }; |
---|
135 | #else |
---|
136 | /* XXX fix me */ |
---|
137 | #warning "MVME162 BSP -- unknown address for SCC's" |
---|
138 | #endif |
---|
139 | |
---|
140 | #undef ZWRITE0 |
---|
141 | #define ZWRITE0(port, v) (scc[port]->csr = (unsigned char)(v)) |
---|
142 | #undef ZREAD0 |
---|
143 | #define ZREAD0(port) (scc[port]->csr) |
---|
144 | |
---|
145 | #undef ZREAD |
---|
146 | #define ZREAD(port, n) (ZWRITE0(port, n), (scc[port]->csr)) |
---|
147 | #undef ZREADD |
---|
148 | #define ZREADD(port) (scc[port]->csr=0x08, scc[port]->csr ) |
---|
149 | |
---|
150 | #undef ZWRITE |
---|
151 | #define ZWRITE(port, n, v) (ZWRITE0(port, n), ZWRITE0(port, v)) |
---|
152 | #undef ZWRITED |
---|
153 | #define ZWRITED(port, v) (scc[port]->csr = 0x08, \ |
---|
154 | scc[port]->csr = (unsigned char)(v)) |
---|
155 | |
---|
156 | static ReceiverBuffer receiverBuffer[NPORTS]; |
---|
157 | |
---|
158 | /* |
---|
159 | * Control flags (DTR/DCD/RTS/CTS) |
---|
160 | */ |
---|
161 | |
---|
162 | static unsigned char wr4[NPORTS]; |
---|
163 | static unsigned char wr5[NPORTS]; |
---|
164 | #define SCCSetDTR(port) ZWRITE(port, 5, (wr5[port] |= 0x80)) |
---|
165 | #define SCCResetDTR(port) ZWRITE(port, 5, (wr5[port] &= ~0x80)) |
---|
166 | #define SCCSetRTS(port) ZWRITE(port, 5, (wr5[port] |= 0x02)) |
---|
167 | #define SCCResetRTS(port) ZWRITE(port,5, (wr5[port] &= ~0x02)) |
---|
168 | #define SCCGetDCD(port) (ZREAD0(port)&0x08) |
---|
169 | #define SCCGetCTS(port) (ZREAD0(port)&0x20) |
---|
170 | |
---|
171 | |
---|
172 | /* |
---|
173 | * Interrupt handler for receiver interrupts |
---|
174 | */ |
---|
175 | |
---|
176 | static rtems_isr SCCReceiverISR(rtems_vector_number vector) |
---|
177 | { |
---|
178 | register int ipend, port; |
---|
179 | |
---|
180 | port = (vector-SCC_VECTOR)*2; |
---|
181 | ZWRITE0(port, 0x38); /* reset highest IUS */ |
---|
182 | |
---|
183 | ipend = ZREAD(port, 3); /* read int pending from A side */ |
---|
184 | |
---|
185 | if(ipend == 0x04) |
---|
186 | port++; /* channel B intr pending */ |
---|
187 | else if(ipend == 0x20) |
---|
188 | ; /* channel A intr pending */ |
---|
189 | else |
---|
190 | return; |
---|
191 | |
---|
192 | ReceiverBufferAdd(&receiverBuffer[port], ZREADD(port)); |
---|
193 | |
---|
194 | if(ZREAD(port,1) & 0x70){ /* check error stat */ |
---|
195 | ZWRITE0(port, 0x30); /* reset error */ |
---|
196 | } |
---|
197 | |
---|
198 | if(ReceiverBufferIsNearFull(&receiverBuffer[port])) |
---|
199 | SCCResetRTS(port); |
---|
200 | } |
---|
201 | |
---|
202 | /* |
---|
203 | * Initialize |
---|
204 | */ |
---|
205 | |
---|
206 | void SCCInitialize() |
---|
207 | { |
---|
208 | int i; |
---|
209 | |
---|
210 | for(i = PORTFROM; i < NPORTS; i+=2) |
---|
211 | ZWRITE(i, 9,0xc0); /* Reset SCC Chip */ |
---|
212 | |
---|
213 | for(i = PORTFROM; i < NPORTS; i++){ |
---|
214 | ReceiverBufferInitialize(&(receiverBuffer[i])); |
---|
215 | wr4[i] = 0x44; |
---|
216 | ZWRITE(i, 4, wr4[i]); /* x16 clock, 1 stop, parity none */ |
---|
217 | ZWRITE(i, 1, 0); /* disable interrupts */ |
---|
218 | ZWRITE(i, 2, SCC_VECTOR+(i/2)); |
---|
219 | ZWRITE(i, 3, 0xc1); /* receiver enable, 8bits */ |
---|
220 | wr5[i] = 0x68; |
---|
221 | ZWRITE(i, 5, wr5[i]); /* transmitter enable, 8bits, DTR&RTS off */ |
---|
222 | ZWRITE(i,14, 0); /* stop baudrate gen. */ |
---|
223 | ZWRITE(i,11,0x50); /* use baurate gen. */ |
---|
224 | ZWRITE(i,15, 1); /* Select WR7' */ |
---|
225 | ZWRITE(i, 7, 0); /* Disable all special interrupts */ |
---|
226 | ZWRITE(i,10, 0); |
---|
227 | ZWRITE(i, 1, 0x10); /* int on all Rx chars or special condition */ |
---|
228 | set_vector(SCCReceiverISR, SCC_VECTOR+(i/2), 1); /* install ISR */ |
---|
229 | ZWRITE(i, 9, 8); /* master interrupt enable */ |
---|
230 | ZWRITE(i,12,TC38400&0xff); /* set 38400 baud */ |
---|
231 | ZWRITE(i,13,TC38400>>8); |
---|
232 | ZWRITE(i,14, 3); /* start baudrate gen. */ |
---|
233 | /* CAUTION: If your SCC use XTAL on RTxC, |
---|
234 | write 1 */ |
---|
235 | } |
---|
236 | mcchip->vector_base = 0; |
---|
237 | mcchip->gen_control = 2; /* MIEN */ |
---|
238 | mcchip->SCC_int_ctl = 0x13; /* SCC IEN, IPL3 */ |
---|
239 | } |
---|
240 | |
---|
241 | /* |
---|
242 | * Non-blocking char input |
---|
243 | */ |
---|
244 | |
---|
245 | rtems_boolean SCCGetOne(int port, char *ch) |
---|
246 | { |
---|
247 | int retry = READRETRY; |
---|
248 | while(ReceiverBufferIsEmpty(&receiverBuffer[port])) |
---|
249 | if(--retry <= 0) |
---|
250 | return FALSE; |
---|
251 | |
---|
252 | ReceiverBufferRemove(&receiverBuffer[port],*ch); |
---|
253 | |
---|
254 | if(ReceiverBufferIsNearEmpty(&receiverBuffer[port])) |
---|
255 | SCCSetRTS(port); |
---|
256 | return TRUE; |
---|
257 | } |
---|
258 | |
---|
259 | /* |
---|
260 | * Blocking char input |
---|
261 | */ |
---|
262 | |
---|
263 | char SCCGetOneBlocked(int port) |
---|
264 | { |
---|
265 | unsigned char tmp_char; |
---|
266 | |
---|
267 | while (!SCCGetOne(port, &tmp_char)) |
---|
268 | rtems_task_wake_after(RTEMS_YIELD_PROCESSOR); |
---|
269 | return tmp_char; |
---|
270 | } |
---|
271 | |
---|
272 | /* |
---|
273 | * Non-blocking char input |
---|
274 | * No longer supports XON/XOFF flow control. |
---|
275 | */ |
---|
276 | |
---|
277 | rtems_boolean SCCSendOne(int port, char ch) |
---|
278 | { |
---|
279 | int retry = WRITERETRY; |
---|
280 | |
---|
281 | if(!SCCGetCTS(port)) |
---|
282 | return FALSE; |
---|
283 | while(!(ZREAD0(port) & TX_BUFFER_EMPTY)) |
---|
284 | if(--retry <= 0) |
---|
285 | return FALSE; |
---|
286 | ZWRITED(port, ch); |
---|
287 | return TRUE; |
---|
288 | } |
---|
289 | |
---|
290 | |
---|
291 | /* |
---|
292 | * Blocking char output |
---|
293 | * No longer supports XON/XOFF flow control. |
---|
294 | */ |
---|
295 | |
---|
296 | void SCCSendOneBlocked(int port, char ch) |
---|
297 | { |
---|
298 | while(!SCCSendOne(port, ch)) |
---|
299 | rtems_task_wake_after(RTEMS_YIELD_PROCESSOR); |
---|
300 | } |
---|
301 | |
---|
302 | /* |
---|
303 | * Set parameters for transmission |
---|
304 | */ |
---|
305 | |
---|
306 | unsigned32 SCCSetAttributes(int port, struct termios *t) |
---|
307 | { |
---|
308 | unsigned char wr3; |
---|
309 | |
---|
310 | ZWRITE(port,1,0); /* Disable interrupt */ |
---|
311 | ZWRITE(port,3,0); /* Disable receiver */ |
---|
312 | /* Baud */ |
---|
313 | switch(t->c_cflag & CBAUD){ |
---|
314 | case B38400: |
---|
315 | ZWRITE(port,12,TC38400&0xff); |
---|
316 | ZWRITE(port,13,TC38400>>8); |
---|
317 | break; |
---|
318 | case B19200: |
---|
319 | ZWRITE(port,12,TC19200&0xff); |
---|
320 | ZWRITE(port,13,TC19200>>8); |
---|
321 | break; |
---|
322 | case B9600: |
---|
323 | ZWRITE(port,12,TC9600&0xff); |
---|
324 | ZWRITE(port,13,TC9600>>8); |
---|
325 | break; |
---|
326 | } |
---|
327 | |
---|
328 | /* Code size */ |
---|
329 | wr5[port] &= 0x8f; |
---|
330 | wr3 = 0; /* receiver control */ |
---|
331 | switch(t->c_cflag & CSIZE){ |
---|
332 | case CS8: |
---|
333 | wr5[port] |= 0x60; |
---|
334 | wr3 |= 0xc0; |
---|
335 | break; |
---|
336 | case CS7: |
---|
337 | wr5[port] |= 0x20; |
---|
338 | wr3 |= 0x40; |
---|
339 | break; |
---|
340 | } |
---|
341 | |
---|
342 | /* Parity */ |
---|
343 | wr4[port] &= 0xf0; |
---|
344 | if(t->c_cflag & PARENB) |
---|
345 | wr4[port] |= 0x01; |
---|
346 | if(!(t->c_cflag & PARODD)) |
---|
347 | wr4[port] |= 0x02; |
---|
348 | /* ZWRITE(port,4,wr4[port]);*/ |
---|
349 | |
---|
350 | /* Stop bits */ |
---|
351 | /* wr4[port] = ZREAD(port,4) & 0xfc;*/ |
---|
352 | if(t->c_cflag & CSTOPB) |
---|
353 | wr4[port] |= 0x0c; |
---|
354 | else |
---|
355 | wr4[port] |= 0x04; |
---|
356 | |
---|
357 | ZWRITE(port,4,wr4[port]); /* TxRx parameters */ |
---|
358 | ZWRITE(port,5,wr5[port]); /* Transmission parameters */ |
---|
359 | ZWRITE(port,3,wr3|0x01); /* Enable receiver */ |
---|
360 | ZWRITE(port,1,0x10); /* Enable interrupt */ |
---|
361 | |
---|
362 | return 0; |
---|
363 | } |
---|
364 | |
---|
365 | /* |
---|
366 | * Get parameters for transmission |
---|
367 | */ |
---|
368 | |
---|
369 | unsigned32 SCCGetAttributes(int port, struct termios *t) |
---|
370 | { |
---|
371 | unsigned32 b; |
---|
372 | |
---|
373 | t->c_cflag = 0; |
---|
374 | |
---|
375 | /* Baud */ |
---|
376 | b = ZREAD(port,13); |
---|
377 | b <<= 8; |
---|
378 | b |= ZREAD(port,12); |
---|
379 | switch(b){ |
---|
380 | case TC38400: |
---|
381 | t->c_cflag |= B38400; |
---|
382 | break; |
---|
383 | case TC19200: |
---|
384 | t->c_cflag |= B19200; |
---|
385 | break; |
---|
386 | case TC9600: |
---|
387 | t->c_cflag |= B9600; |
---|
388 | break; |
---|
389 | } |
---|
390 | |
---|
391 | /* Code size */ |
---|
392 | /* wr = ZREAD(port,5);*/ |
---|
393 | t->c_cflag &= ~CSIZE; |
---|
394 | switch(wr5[port]&0x60){ |
---|
395 | case 0x60: |
---|
396 | t->c_cflag |= CS8; |
---|
397 | break; |
---|
398 | case 0x20: |
---|
399 | t->c_cflag |= CS7; |
---|
400 | break; |
---|
401 | } |
---|
402 | |
---|
403 | /* Parity */ |
---|
404 | /* wr = ZREAD(port,4);*/ |
---|
405 | if(wr4[port] & 0x01) |
---|
406 | t->c_cflag |= PARENB; |
---|
407 | else |
---|
408 | t->c_cflag &= ~PARENB; |
---|
409 | if(wr4[port] & 0x02) |
---|
410 | t->c_cflag &= ~PARODD; |
---|
411 | else |
---|
412 | t->c_cflag |= PARODD; |
---|
413 | |
---|
414 | /* Stop bits */ |
---|
415 | /* wr = ZREAD(port,4);*/ |
---|
416 | if((wr4[port]&0xc0) == 0xc0) |
---|
417 | t->c_cflag |= CSTOPB; |
---|
418 | else |
---|
419 | t->c_cflag &= ~CSTOPB; |
---|
420 | |
---|
421 | return 0; |
---|
422 | } |
---|
423 | |
---|
424 | /*********************************************************************** |
---|
425 | DEVICE INDEPENDED PART |
---|
426 | ***********************************************************************/ |
---|
427 | |
---|
428 | #define LOCAL_ISTRIP 0x0001 |
---|
429 | #define LOCAL_INLCR 0x0002 |
---|
430 | #define LOCAL_IGNCR 0x0004 |
---|
431 | #define LOCAL_ICRNL 0x0008 |
---|
432 | #define LOCAL_IUCLC 0x0010 |
---|
433 | #define LOCAL_OLCUC 0x0020 |
---|
434 | #define LOCAL_ONLCR 0x0040 |
---|
435 | #define LOCAL_OCRNL 0x0080 |
---|
436 | #define LOCAL_ICANON 0x0100 |
---|
437 | #define LOCAL_ECHO 0x0200 |
---|
438 | |
---|
439 | /* |
---|
440 | * Device initialize entry point |
---|
441 | */ |
---|
442 | |
---|
443 | rtems_device_driver consolex_initialize(rtems_device_major_number major, |
---|
444 | rtems_device_minor_number minor, |
---|
445 | void *arg) |
---|
446 | { |
---|
447 | rtems_status_code status; |
---|
448 | char devname[16]; |
---|
449 | int i; |
---|
450 | |
---|
451 | SCCInitialize(); |
---|
452 | |
---|
453 | #ifdef CONSOLEPORT |
---|
454 | status = rtems_io_register_name("/dev/console",major, |
---|
455 | (rtems_device_minor_number) CONSOLEPORT); |
---|
456 | if (status != RTEMS_SUCCESSFUL) |
---|
457 | rtems_fatal_error_occurred(status); |
---|
458 | #endif |
---|
459 | |
---|
460 | for(i = PORTFROM; i < NPORTS; i++){ |
---|
461 | /* Register cooked ttys */ |
---|
462 | sprintf(devname,"/dev/%s%02d",DEVICEPREFIX,i); |
---|
463 | status = rtems_io_register_name(strdup(devname),major, |
---|
464 | (rtems_device_minor_number) i); |
---|
465 | if (status != RTEMS_SUCCESSFUL) |
---|
466 | rtems_fatal_error_occurred(status); |
---|
467 | /* Register raw ttys */ |
---|
468 | sprintf(devname,"/dev/%s%02d",RAWDEVICEPREFIX,i); |
---|
469 | status = rtems_io_register_name(strdup(devname),major, |
---|
470 | (rtems_device_minor_number) i+NPORTS); |
---|
471 | if (status != RTEMS_SUCCESSFUL) |
---|
472 | rtems_fatal_error_occurred(status); |
---|
473 | } |
---|
474 | |
---|
475 | for(i = 0; i < NPORTS; i++){ |
---|
476 | opencount[i] = 0; |
---|
477 | } |
---|
478 | |
---|
479 | return RTEMS_SUCCESSFUL; |
---|
480 | } |
---|
481 | |
---|
482 | /* |
---|
483 | * Open entry point |
---|
484 | */ |
---|
485 | |
---|
486 | rtems_device_driver consolex_open(rtems_device_major_number major, |
---|
487 | rtems_device_minor_number minor, |
---|
488 | void *arg) |
---|
489 | { |
---|
490 | rtems_libio_open_close_args_t *openargs = (rtems_libio_open_close_args_t *) arg; |
---|
491 | if(minor >= NPORTS) |
---|
492 | minor -= NPORTS; |
---|
493 | if(minor >= NPORTS) |
---|
494 | return RTEMS_INVALID_NUMBER; |
---|
495 | |
---|
496 | if(opencount[minor]++ == 0){ |
---|
497 | /* first open */ |
---|
498 | SCCSetDTR(minor); |
---|
499 | SCCSetRTS(minor); |
---|
500 | } |
---|
501 | openargs->iop->data0 = LOCAL_ICRNL|LOCAL_ONLCR|LOCAL_ICANON|LOCAL_ECHO; |
---|
502 | return RTEMS_SUCCESSFUL; |
---|
503 | } |
---|
504 | |
---|
505 | /* |
---|
506 | * Close entry point |
---|
507 | */ |
---|
508 | |
---|
509 | rtems_device_driver consolex_close(rtems_device_major_number major, |
---|
510 | rtems_device_minor_number minor, |
---|
511 | void *arg) |
---|
512 | { |
---|
513 | if(minor >= NPORTS) |
---|
514 | minor -= NPORTS; |
---|
515 | if(minor >= NPORTS) |
---|
516 | return RTEMS_INVALID_NUMBER; |
---|
517 | |
---|
518 | if(--(opencount[minor]) == 0){ |
---|
519 | /* closed all */ |
---|
520 | SCCResetRTS(minor); |
---|
521 | SCCResetDTR(minor); |
---|
522 | } |
---|
523 | return RTEMS_SUCCESSFUL; |
---|
524 | } |
---|
525 | |
---|
526 | /* |
---|
527 | * read bytes from the serial port. |
---|
528 | */ |
---|
529 | |
---|
530 | rtems_device_driver consolex_read_raw(rtems_device_major_number major, |
---|
531 | rtems_device_minor_number minor, |
---|
532 | void *arg) |
---|
533 | { |
---|
534 | rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *) arg; |
---|
535 | char *buffer; |
---|
536 | int count; |
---|
537 | |
---|
538 | if(minor >= NPORTS) |
---|
539 | return RTEMS_INVALID_NUMBER; |
---|
540 | |
---|
541 | buffer = rw_args->buffer; |
---|
542 | count = rw_args->count; |
---|
543 | |
---|
544 | if(rw_args->flags & LIBIO_FLAGS_NO_DELAY){ |
---|
545 | /* Non blocking read */ |
---|
546 | while(count){ |
---|
547 | if(!SCCGetOne(minor,buffer)) |
---|
548 | break; |
---|
549 | buffer++; |
---|
550 | count--; |
---|
551 | } |
---|
552 | }else{ |
---|
553 | /* Blocking read */ |
---|
554 | while(count){ |
---|
555 | *buffer = SCCGetOneBlocked(minor); |
---|
556 | buffer++; |
---|
557 | count--; |
---|
558 | } |
---|
559 | } |
---|
560 | |
---|
561 | rw_args->bytes_moved = rw_args->count-count; |
---|
562 | return count ? RTEMS_UNSATISFIED : RTEMS_SUCCESSFUL; |
---|
563 | } |
---|
564 | |
---|
565 | rtems_device_driver consolex_read(rtems_device_major_number major, |
---|
566 | rtems_device_minor_number minor, |
---|
567 | void *arg) |
---|
568 | { |
---|
569 | rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *) arg; |
---|
570 | char *buffer; |
---|
571 | int count; |
---|
572 | unsigned32 mode; |
---|
573 | |
---|
574 | if(minor >= NPORTS) |
---|
575 | return consolex_read_raw(major,minor-NPORTS,arg); |
---|
576 | |
---|
577 | buffer = rw_args->buffer; |
---|
578 | count = rw_args->count; |
---|
579 | mode = rw_args->iop->data0; |
---|
580 | |
---|
581 | /* Cooked read */ |
---|
582 | while(count){ |
---|
583 | if(rw_args->flags & LIBIO_FLAGS_NO_DELAY){ |
---|
584 | /* Non blocking read */ |
---|
585 | if(!SCCGetOne(minor,buffer)) |
---|
586 | break; |
---|
587 | }else{ |
---|
588 | /* Blocking read */ |
---|
589 | *buffer = SCCGetOneBlocked(minor); |
---|
590 | } |
---|
591 | if((mode&LOCAL_ICANON) && (*buffer == '\b')){ |
---|
592 | if(buffer > (char *)(rw_args->buffer)){ |
---|
593 | buffer--; |
---|
594 | count++; |
---|
595 | if(mode&LOCAL_ECHO){ |
---|
596 | SCCSendOneBlocked(minor,'\b'); |
---|
597 | SCCSendOneBlocked(minor,' '); |
---|
598 | SCCSendOneBlocked(minor,'\b'); |
---|
599 | } |
---|
600 | } |
---|
601 | continue; |
---|
602 | } |
---|
603 | if((mode&LOCAL_IGNCR) && (*buffer == '\r')) |
---|
604 | continue; |
---|
605 | if((mode&LOCAL_INLCR) && (*buffer == '\n')) |
---|
606 | *buffer = '\r'; |
---|
607 | if((mode&LOCAL_ICRNL) && (*buffer == '\r')) |
---|
608 | *buffer = '\n'; |
---|
609 | if((mode&LOCAL_IUCLC) && isupper((int)*buffer)) |
---|
610 | *buffer = tolower(*buffer); |
---|
611 | if(mode&LOCAL_ISTRIP) |
---|
612 | *buffer &= 0x7f; |
---|
613 | if(mode&LOCAL_ECHO){ |
---|
614 | /* Caution: Echo back is blocking output */ |
---|
615 | SCCSendOneBlocked(minor,*buffer); |
---|
616 | } |
---|
617 | if((mode&LOCAL_ICANON) && (*buffer == '\n')){ |
---|
618 | buffer++; |
---|
619 | count--; |
---|
620 | if(count) |
---|
621 | *buffer = 0; |
---|
622 | if((mode&LOCAL_ECHO)&&(mode&LOCAL_ONLCR)) |
---|
623 | SCCSendOneBlocked(minor,'\r'); |
---|
624 | break; /* finish reading */ |
---|
625 | } |
---|
626 | buffer++; |
---|
627 | count--; |
---|
628 | } |
---|
629 | rw_args->bytes_moved = rw_args->count-count; |
---|
630 | return count ? RTEMS_UNSATISFIED : RTEMS_SUCCESSFUL; |
---|
631 | } |
---|
632 | |
---|
633 | /* |
---|
634 | * write bytes to the serial port. |
---|
635 | */ |
---|
636 | |
---|
637 | rtems_device_driver consolex_write_raw(rtems_device_major_number major, |
---|
638 | rtems_device_minor_number minor, |
---|
639 | void * arg) |
---|
640 | { |
---|
641 | rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *) arg; |
---|
642 | char *buffer; |
---|
643 | int count; |
---|
644 | |
---|
645 | if(minor >= NPORTS) |
---|
646 | return RTEMS_INVALID_NUMBER; |
---|
647 | |
---|
648 | buffer = rw_args->buffer; |
---|
649 | count = rw_args->count; |
---|
650 | |
---|
651 | if(rw_args->flags & LIBIO_FLAGS_NO_DELAY){ |
---|
652 | /* Non blocking write */ |
---|
653 | while(count){ |
---|
654 | if(!SCCSendOne(minor,*buffer)) |
---|
655 | break; |
---|
656 | buffer++; |
---|
657 | count--; |
---|
658 | } |
---|
659 | }else{ |
---|
660 | /* Blocking write */ |
---|
661 | while(count){ |
---|
662 | SCCSendOneBlocked(minor,*buffer); |
---|
663 | buffer++; |
---|
664 | count--; |
---|
665 | } |
---|
666 | } |
---|
667 | |
---|
668 | rw_args->bytes_moved = rw_args->count-count; |
---|
669 | return count ? RTEMS_UNSATISFIED : RTEMS_SUCCESSFUL; |
---|
670 | } |
---|
671 | |
---|
672 | rtems_device_driver consolex_write(rtems_device_major_number major, |
---|
673 | rtems_device_minor_number minor, |
---|
674 | void * arg) |
---|
675 | { |
---|
676 | rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *) arg; |
---|
677 | char *buffer; |
---|
678 | int count; |
---|
679 | char ch; |
---|
680 | unsigned32 mode; |
---|
681 | |
---|
682 | if(minor >= NPORTS) |
---|
683 | return consolex_write_raw(major,minor-NPORTS,arg); |
---|
684 | |
---|
685 | buffer = rw_args->buffer; |
---|
686 | count = rw_args->count; |
---|
687 | mode = rw_args->iop->data0; |
---|
688 | |
---|
689 | /* Cooked write */ |
---|
690 | while(count){ |
---|
691 | ch = *buffer; |
---|
692 | if((mode&LOCAL_ONLCR) && (ch == '\n')){ /* Output CRLF */ |
---|
693 | if(rw_args->flags & LIBIO_FLAGS_NO_DELAY){ |
---|
694 | /* Non blocking write */ |
---|
695 | if(!SCCSendOne(minor,'\r')) |
---|
696 | break; |
---|
697 | }else{ |
---|
698 | SCCSendOneBlocked(minor,'\r'); |
---|
699 | } |
---|
700 | } |
---|
701 | if((mode&LOCAL_OCRNL) && (ch == '\r')) |
---|
702 | ch = '\n'; |
---|
703 | if((mode&OLCUC) && (islower((int)ch))) |
---|
704 | ch = toupper(ch); |
---|
705 | if(rw_args->flags & LIBIO_FLAGS_NO_DELAY){ |
---|
706 | /* Non blocking write */ |
---|
707 | if(!SCCSendOne(minor,ch)) |
---|
708 | break; |
---|
709 | }else{ |
---|
710 | SCCSendOneBlocked(minor,ch); |
---|
711 | } |
---|
712 | buffer++; |
---|
713 | count--; |
---|
714 | } |
---|
715 | |
---|
716 | rw_args->bytes_moved = rw_args->count-count; |
---|
717 | return count ? RTEMS_UNSATISFIED : RTEMS_SUCCESSFUL; |
---|
718 | } |
---|
719 | |
---|
720 | /* |
---|
721 | * IO Control entry point |
---|
722 | */ |
---|
723 | |
---|
724 | rtems_device_driver consolex_control(rtems_device_major_number major, |
---|
725 | rtems_device_minor_number minor, |
---|
726 | void * arg) |
---|
727 | { |
---|
728 | rtems_libio_ioctl_args_t *ioarg = (rtems_libio_ioctl_args_t *)arg; |
---|
729 | struct termios *tm = ioarg->buffer; |
---|
730 | unsigned32 *mode = &(ioarg->iop->data0); |
---|
731 | |
---|
732 | if(minor >= NPORTS) |
---|
733 | minor -= NPORTS; |
---|
734 | if(minor >= NPORTS) |
---|
735 | return RTEMS_INVALID_NUMBER; |
---|
736 | |
---|
737 | switch(ioarg->command){ |
---|
738 | case RTEMS_IO_GET_ATTRIBUTES: |
---|
739 | tm->c_iflag = tm->c_oflag = tm->c_cflag = tm->c_lflag = 0; |
---|
740 | if(*mode & LOCAL_ISTRIP) |
---|
741 | tm->c_iflag |= ISTRIP; |
---|
742 | if(*mode & LOCAL_INLCR) |
---|
743 | tm->c_iflag |= INLCR; |
---|
744 | if(*mode & LOCAL_IGNCR) |
---|
745 | tm->c_iflag |= IGNCR; |
---|
746 | if(*mode & LOCAL_ICRNL) |
---|
747 | tm->c_iflag |= ICRNL; |
---|
748 | if(*mode & LOCAL_IUCLC) |
---|
749 | tm->c_iflag |= IUCLC; |
---|
750 | if(*mode & LOCAL_OLCUC) |
---|
751 | tm->c_oflag |= OLCUC; |
---|
752 | if(*mode & LOCAL_ONLCR) |
---|
753 | tm->c_oflag |= ONLCR; |
---|
754 | if(*mode & LOCAL_OCRNL) |
---|
755 | tm->c_oflag |= OCRNL; |
---|
756 | if(*mode & LOCAL_ICANON) |
---|
757 | tm->c_lflag |= ICANON; |
---|
758 | if(*mode & LOCAL_ECHO) |
---|
759 | tm->c_lflag |= ECHO; |
---|
760 | ioarg->ioctl_return = SCCGetAttributes(minor,tm); |
---|
761 | break; |
---|
762 | case RTEMS_IO_SET_ATTRIBUTES: |
---|
763 | *mode = 0; |
---|
764 | if(tm->c_iflag & ISTRIP) |
---|
765 | *mode |= LOCAL_ISTRIP; |
---|
766 | if(tm->c_iflag & INLCR) |
---|
767 | *mode |= LOCAL_INLCR; |
---|
768 | if(tm->c_iflag & IGNCR) |
---|
769 | *mode |= LOCAL_IGNCR; |
---|
770 | if(tm->c_iflag & ICRNL) |
---|
771 | *mode |= LOCAL_ICRNL; |
---|
772 | if(tm->c_iflag & IUCLC) |
---|
773 | *mode |= LOCAL_IUCLC; |
---|
774 | if(tm->c_oflag & OLCUC) |
---|
775 | *mode |= LOCAL_OLCUC; |
---|
776 | if(tm->c_oflag & ONLCR) |
---|
777 | *mode |= LOCAL_ONLCR; |
---|
778 | if(tm->c_oflag & OCRNL) |
---|
779 | *mode |= LOCAL_OCRNL; |
---|
780 | if(tm->c_lflag & ICANON) |
---|
781 | *mode |= LOCAL_ICANON; |
---|
782 | if(tm->c_lflag & ECHO) |
---|
783 | *mode |= LOCAL_ECHO; |
---|
784 | ioarg->ioctl_return = SCCSetAttributes(minor,tm); |
---|
785 | break; |
---|
786 | default: |
---|
787 | return RTEMS_NOT_DEFINED; |
---|
788 | } |
---|
789 | |
---|
790 | return RTEMS_SUCCESSFUL; |
---|
791 | } |
---|