1 | /* |
---|
2 | * This file contains the template for a 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 NO_BSP_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 | *status = RTEMS_SUCCESSFUL; |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | /* is_character_ready |
---|
45 | * |
---|
46 | * This routine returns TRUE if a character is available. |
---|
47 | * |
---|
48 | * Input parameters: NONE |
---|
49 | * |
---|
50 | * Output parameters: NONE |
---|
51 | * |
---|
52 | * Return values: |
---|
53 | */ |
---|
54 | |
---|
55 | rtems_boolean is_character_ready( |
---|
56 | char *ch |
---|
57 | ) |
---|
58 | { |
---|
59 | *ch = '\0'; /* return NULL for no particular reason */ |
---|
60 | return(TRUE); |
---|
61 | } |
---|
62 | |
---|
63 | /* inbyte |
---|
64 | * |
---|
65 | * This routine reads a character from the SOURCE. |
---|
66 | * |
---|
67 | * Input parameters: NONE |
---|
68 | * |
---|
69 | * Output parameters: NONE |
---|
70 | * |
---|
71 | * Return values: |
---|
72 | * character read from SOURCE |
---|
73 | */ |
---|
74 | |
---|
75 | char inbyte( void ) |
---|
76 | { |
---|
77 | /* |
---|
78 | * If polling, wait until a character is available. |
---|
79 | */ |
---|
80 | |
---|
81 | return '\0'; |
---|
82 | } |
---|
83 | |
---|
84 | /* outbyte |
---|
85 | * |
---|
86 | * This routine transmits a character out the SOURCE. It may support |
---|
87 | * XON/XOFF flow control. |
---|
88 | * |
---|
89 | * Input parameters: |
---|
90 | * ch - character to be transmitted |
---|
91 | * |
---|
92 | * Output parameters: NONE |
---|
93 | */ |
---|
94 | |
---|
95 | void outbyte( |
---|
96 | char ch |
---|
97 | ) |
---|
98 | { |
---|
99 | /* |
---|
100 | * If polling, wait for the transmitter to be ready. |
---|
101 | * Check for flow control requests and process. |
---|
102 | * Then output the character. |
---|
103 | */ |
---|
104 | |
---|
105 | /* |
---|
106 | * Carriage Return/New line translation. |
---|
107 | */ |
---|
108 | |
---|
109 | if ( ch == '\n' ) |
---|
110 | outbyte( '\r' ); |
---|
111 | } |
---|
112 | |
---|
113 | /* |
---|
114 | * __read -- read bytes from the serial port. Ignore fd, since |
---|
115 | * we only have stdin. |
---|
116 | */ |
---|
117 | |
---|
118 | int __read( |
---|
119 | int fd, |
---|
120 | char *buf, |
---|
121 | int nbytes |
---|
122 | ) |
---|
123 | { |
---|
124 | int i = 0; |
---|
125 | |
---|
126 | for (i = 0; i < nbytes; i++) { |
---|
127 | *(buf + i) = inbyte(); |
---|
128 | if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) { |
---|
129 | (*(buf + i++)) = '\n'; |
---|
130 | (*(buf + i)) = 0; |
---|
131 | break; |
---|
132 | } |
---|
133 | } |
---|
134 | return (i); |
---|
135 | } |
---|
136 | |
---|
137 | /* |
---|
138 | * __write -- write bytes to the serial port. Ignore fd, since |
---|
139 | * stdout and stderr are the same. Since we have no filesystem, |
---|
140 | * open will only return an error. |
---|
141 | */ |
---|
142 | |
---|
143 | int __write( |
---|
144 | int fd, |
---|
145 | char *buf, |
---|
146 | int nbytes |
---|
147 | ) |
---|
148 | { |
---|
149 | int i; |
---|
150 | |
---|
151 | for (i = 0; i < nbytes; i++) { |
---|
152 | if (*(buf + i) == '\n') { |
---|
153 | outbyte ('\r'); |
---|
154 | } |
---|
155 | outbyte (*(buf + i)); |
---|
156 | } |
---|
157 | return (nbytes); |
---|
158 | } |
---|