1 | /* |
---|
2 | * Initialize the MC68302 SCC2 for console IO board support package. |
---|
3 | */ |
---|
4 | |
---|
5 | /* |
---|
6 | * COPYRIGHT (c) 1989-2014. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.rtems.org/license/LICENSE. |
---|
12 | */ |
---|
13 | |
---|
14 | #define GEN68302_INIT |
---|
15 | |
---|
16 | #include <debugport.h> |
---|
17 | #include <bsp.h> |
---|
18 | #include <rtems/libio.h> |
---|
19 | |
---|
20 | /* console_initialize |
---|
21 | * |
---|
22 | * This routine initializes the console IO driver. |
---|
23 | */ |
---|
24 | rtems_device_driver console_initialize( |
---|
25 | rtems_device_major_number major, |
---|
26 | rtems_device_minor_number minor, |
---|
27 | void *arg |
---|
28 | ) |
---|
29 | { |
---|
30 | rtems_status_code status; |
---|
31 | |
---|
32 | /* debug_port_initialise(); */ |
---|
33 | |
---|
34 | status = rtems_io_register_name( |
---|
35 | "/dev/console", |
---|
36 | major, |
---|
37 | (rtems_device_minor_number) 0 |
---|
38 | ); |
---|
39 | |
---|
40 | if (status != RTEMS_SUCCESSFUL) |
---|
41 | rtems_fatal_error_occurred(status); |
---|
42 | |
---|
43 | return RTEMS_SUCCESSFUL; |
---|
44 | } |
---|
45 | |
---|
46 | /* is_character_ready |
---|
47 | * |
---|
48 | * Check to see if a character is available on the MC68302's SCC2. If so, |
---|
49 | * then return a TRUE (along with the character). Otherwise return FALSE. |
---|
50 | */ |
---|
51 | static bool is_character_ready( |
---|
52 | char *ch /* -> character */ |
---|
53 | ) |
---|
54 | { |
---|
55 | if (debug_port_status(0)) |
---|
56 | { |
---|
57 | *ch = debug_port_in(); |
---|
58 | return true; |
---|
59 | } |
---|
60 | return false; |
---|
61 | } |
---|
62 | |
---|
63 | /* inbyte |
---|
64 | * |
---|
65 | * Receive a character from the MC68302's SCC2. |
---|
66 | */ |
---|
67 | static char inbyte( void ) |
---|
68 | { |
---|
69 | char ch; |
---|
70 | |
---|
71 | while (!is_character_ready(&ch)); |
---|
72 | |
---|
73 | return ch; |
---|
74 | } |
---|
75 | |
---|
76 | /* outbyte |
---|
77 | * |
---|
78 | * Transmit a character out on the MC68302's SCC2. |
---|
79 | * It may support XON/XOFF flow control. |
---|
80 | */ |
---|
81 | static void outbyte( |
---|
82 | char ch |
---|
83 | ) |
---|
84 | { |
---|
85 | debug_port_out(ch); |
---|
86 | } |
---|
87 | |
---|
88 | /* |
---|
89 | * Open entry point |
---|
90 | */ |
---|
91 | rtems_device_driver console_open( |
---|
92 | rtems_device_major_number major, |
---|
93 | rtems_device_minor_number minor, |
---|
94 | void * arg |
---|
95 | ) |
---|
96 | { |
---|
97 | return RTEMS_SUCCESSFUL; |
---|
98 | } |
---|
99 | |
---|
100 | /* |
---|
101 | * Close entry point |
---|
102 | */ |
---|
103 | rtems_device_driver console_close( |
---|
104 | rtems_device_major_number major, |
---|
105 | rtems_device_minor_number minor, |
---|
106 | void * arg |
---|
107 | ) |
---|
108 | { |
---|
109 | return RTEMS_SUCCESSFUL; |
---|
110 | } |
---|
111 | |
---|
112 | /* |
---|
113 | * read bytes from the serial port. We only have stdin. |
---|
114 | */ |
---|
115 | rtems_device_driver console_read( |
---|
116 | rtems_device_major_number major, |
---|
117 | rtems_device_minor_number minor, |
---|
118 | void * arg |
---|
119 | ) |
---|
120 | { |
---|
121 | rtems_libio_rw_args_t *rw_args; |
---|
122 | char *buffer; |
---|
123 | int maximum; |
---|
124 | int count = 0; |
---|
125 | |
---|
126 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
127 | |
---|
128 | buffer = rw_args->buffer; |
---|
129 | maximum = rw_args->count; |
---|
130 | |
---|
131 | for (count = 0; count < maximum; count++) { |
---|
132 | buffer[ count ] = inbyte(); |
---|
133 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
134 | buffer[ count++ ] = '\n'; |
---|
135 | break; |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | rw_args->bytes_moved = count; |
---|
140 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
141 | } |
---|
142 | |
---|
143 | /* |
---|
144 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
145 | */ |
---|
146 | rtems_device_driver console_write( |
---|
147 | rtems_device_major_number major, |
---|
148 | rtems_device_minor_number minor, |
---|
149 | void * arg |
---|
150 | ) |
---|
151 | { |
---|
152 | int count; |
---|
153 | int maximum; |
---|
154 | rtems_libio_rw_args_t *rw_args; |
---|
155 | char *buffer; |
---|
156 | |
---|
157 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
158 | |
---|
159 | buffer = rw_args->buffer; |
---|
160 | maximum = rw_args->count; |
---|
161 | |
---|
162 | for (count = 0; count < maximum; count++) { |
---|
163 | if ( buffer[ count ] == '\n') { |
---|
164 | outbyte('\r'); |
---|
165 | } |
---|
166 | outbyte( buffer[ count ] ); |
---|
167 | } |
---|
168 | |
---|
169 | rw_args->bytes_moved = maximum; |
---|
170 | return 0; |
---|
171 | } |
---|
172 | |
---|
173 | /* |
---|
174 | * IO Control entry point |
---|
175 | */ |
---|
176 | rtems_device_driver console_control( |
---|
177 | rtems_device_major_number major, |
---|
178 | rtems_device_minor_number minor, |
---|
179 | void * arg |
---|
180 | ) |
---|
181 | { |
---|
182 | return RTEMS_SUCCESSFUL; |
---|
183 | } |
---|