1 | #define I_WANT_TERMIOS |
---|
2 | /* |
---|
3 | * BSP specific Serial I/O Functions for the eth-comm BSP |
---|
4 | * |
---|
5 | * This file contains the BSP specific functions for |
---|
6 | * performing serial I/O. These are the functions |
---|
7 | * RTEMS uses (the 6 listed in the device driver |
---|
8 | * structure) |
---|
9 | * |
---|
10 | * The SCCs and SMCs are assigned as follows |
---|
11 | * |
---|
12 | * Channel Device Minor Termios |
---|
13 | * SMC1 /dev/tty0 0 no |
---|
14 | * SMC2 /dev/tty1 1 no |
---|
15 | * SCC1 ethernet |
---|
16 | * SCC2 /dev/console 3 yes |
---|
17 | * SCC3 /dev/tty3 4 no |
---|
18 | * SCC4 /dev/tty4 5 no |
---|
19 | * |
---|
20 | * FIXME: This should use termios for /dev/console, but it doesn't |
---|
21 | * appear to work correctly yet. On startup, with termios enabled, |
---|
22 | * the board hangs for a few seconds before running correctly |
---|
23 | * |
---|
24 | * Author: Jay Monkman (jmonkman@frasca.com) |
---|
25 | * Copyright (C) 1998 by Frasca International, Inc. |
---|
26 | * |
---|
27 | * $Id$ |
---|
28 | */ |
---|
29 | |
---|
30 | #include <bsp.h> /* Must be before libio.h */ |
---|
31 | #include <rtems/libio.h> |
---|
32 | #include <termios.h> |
---|
33 | #include <rtems/bspIo.h> |
---|
34 | |
---|
35 | static void _BSP_null_char( char c ) {return;} |
---|
36 | BSP_output_char_function_type BSP_output_char = _BSP_null_char; |
---|
37 | |
---|
38 | rtems_device_driver console_initialize(rtems_device_major_number major, |
---|
39 | rtems_device_minor_number minor, |
---|
40 | void *arg) |
---|
41 | { |
---|
42 | rtems_status_code status; |
---|
43 | |
---|
44 | #ifdef I_WANT_TERMIOS |
---|
45 | /* |
---|
46 | * Set up TERMIOS (for /dev/console) |
---|
47 | */ |
---|
48 | rtems_termios_initialize(); |
---|
49 | #endif |
---|
50 | |
---|
51 | /* |
---|
52 | * Do common initialization. |
---|
53 | */ |
---|
54 | m8xx_uart_initialize(); |
---|
55 | |
---|
56 | /* |
---|
57 | * Do device-specific initialization |
---|
58 | */ |
---|
59 | m8xx_uart_smc_initialize(SMC1_MINOR); /* /dev/tty0 */ |
---|
60 | m8xx_uart_smc_initialize(SMC2_MINOR); /* /dev/tty1 */ |
---|
61 | m8xx_uart_scc_initialize(SCC2_MINOR); /* /dev/tty2 */ |
---|
62 | m8xx_uart_scc_initialize(SCC3_MINOR); /* /dev/tty3 */ |
---|
63 | m8xx_uart_scc_initialize(SCC4_MINOR); /* /dev/tty4 */ |
---|
64 | |
---|
65 | /* |
---|
66 | * Register the devices |
---|
67 | */ |
---|
68 | status = rtems_io_register_name ("/dev/console", major, SCC2_MINOR); |
---|
69 | if (status != RTEMS_SUCCESSFUL) |
---|
70 | rtems_fatal_error_occurred (status); |
---|
71 | status = rtems_io_register_name ("/dev/tty0", major, SMC1_MINOR); |
---|
72 | if (status != RTEMS_SUCCESSFUL) |
---|
73 | rtems_fatal_error_occurred (status); |
---|
74 | status = rtems_io_register_name ("/dev/tty1", major, SMC2_MINOR); |
---|
75 | if (status != RTEMS_SUCCESSFUL) |
---|
76 | rtems_fatal_error_occurred (status); |
---|
77 | status = rtems_io_register_name ("/dev/tty3", major, SCC3_MINOR); |
---|
78 | if (status != RTEMS_SUCCESSFUL) |
---|
79 | rtems_fatal_error_occurred (status); |
---|
80 | status = rtems_io_register_name ("/dev/tty4", major, SCC4_MINOR); |
---|
81 | if (status != RTEMS_SUCCESSFUL) |
---|
82 | rtems_fatal_error_occurred (status); |
---|
83 | return RTEMS_SUCCESSFUL; |
---|
84 | } |
---|
85 | |
---|
86 | rtems_device_driver console_open(rtems_device_major_number major, |
---|
87 | rtems_device_minor_number minor, |
---|
88 | void *arg) |
---|
89 | { |
---|
90 | volatile m8xxSCCRegisters_t *sccregs; |
---|
91 | |
---|
92 | #ifdef I_WANT_TERMIOS |
---|
93 | static const rtems_termios_callbacks sccPollCallbacks = { |
---|
94 | NULL, /* firstOpen */ |
---|
95 | NULL, /* lastClose */ |
---|
96 | m8xx_uart_pollRead, /* pollRead */ |
---|
97 | m8xx_uart_pollWrite, /* write */ |
---|
98 | m8xx_uart_setAttributes, /* setAttributes */ |
---|
99 | NULL, /* stopRemoteTx */ |
---|
100 | NULL, /* startRemoteTx */ |
---|
101 | 0 /* outputUsesInterrupts */ |
---|
102 | }; |
---|
103 | #endif /* I_WANT_TERMIOS */ |
---|
104 | |
---|
105 | sccregs = 0; |
---|
106 | |
---|
107 | switch (minor) { |
---|
108 | case 0: |
---|
109 | m8xx.smc1.smcm = 1; /* Enable SMC1 RX interrupts */ |
---|
110 | break; |
---|
111 | case 1: |
---|
112 | m8xx.smc2.smcm = 1; /* Enable SMC2 RX interrupts */ |
---|
113 | break; |
---|
114 | case 2: |
---|
115 | sccregs = &m8xx.scc1; |
---|
116 | break; |
---|
117 | case 3: |
---|
118 | sccregs = &m8xx.scc2; |
---|
119 | break; |
---|
120 | case 4: |
---|
121 | sccregs = &m8xx.scc3; |
---|
122 | break; |
---|
123 | case 5: |
---|
124 | sccregs = &m8xx.scc4; |
---|
125 | break; |
---|
126 | default: |
---|
127 | rtems_panic ("CONSOLE: bad minor number"); |
---|
128 | } |
---|
129 | |
---|
130 | if (sccregs) |
---|
131 | sccregs->sccm=0x3; |
---|
132 | |
---|
133 | #ifdef I_WANT_TERMIOS |
---|
134 | if (minor == SCC2_MINOR) { |
---|
135 | return rtems_termios_open (major, minor, arg, &sccPollCallbacks); |
---|
136 | } |
---|
137 | else { |
---|
138 | return RTEMS_SUCCESSFUL; |
---|
139 | } |
---|
140 | #else |
---|
141 | return RTEMS_SUCCESSFUL; |
---|
142 | #endif |
---|
143 | } |
---|
144 | |
---|
145 | rtems_device_driver console_close(rtems_device_major_number major, |
---|
146 | rtems_device_minor_number minor, |
---|
147 | void *arg) |
---|
148 | { |
---|
149 | #ifdef I_WANT_TERMIOS |
---|
150 | if (minor == SCC2_MINOR) { |
---|
151 | return rtems_termios_close (arg); |
---|
152 | } |
---|
153 | else { |
---|
154 | return RTEMS_SUCCESSFUL; |
---|
155 | } |
---|
156 | #else |
---|
157 | return RTEMS_SUCCESSFUL; |
---|
158 | #endif |
---|
159 | } |
---|
160 | |
---|
161 | rtems_device_driver console_read(rtems_device_major_number major, |
---|
162 | rtems_device_minor_number minor, |
---|
163 | void *arg) |
---|
164 | { |
---|
165 | #ifdef I_WANT_TERMIOS |
---|
166 | /* |
---|
167 | if (minor == SCC2_MINOR) { |
---|
168 | */ |
---|
169 | return rtems_termios_read(arg); |
---|
170 | /* |
---|
171 | } |
---|
172 | else { |
---|
173 | return m8xx_console_read(major, minor, arg); |
---|
174 | } |
---|
175 | */ |
---|
176 | #else |
---|
177 | return m8xx_console_read(major, minor, arg); |
---|
178 | #endif |
---|
179 | } |
---|
180 | |
---|
181 | rtems_device_driver console_write(rtems_device_major_number major, |
---|
182 | rtems_device_minor_number minor, |
---|
183 | void *arg) |
---|
184 | { |
---|
185 | #ifdef I_WANT_TERMIOS |
---|
186 | /* |
---|
187 | if (minor == SCC2_MINOR) { |
---|
188 | */ |
---|
189 | return rtems_termios_write(arg); |
---|
190 | /* |
---|
191 | } |
---|
192 | else { |
---|
193 | return m8xx_console_write(major, minor, arg); |
---|
194 | } |
---|
195 | */ |
---|
196 | #else |
---|
197 | return m8xx_console_write(major, minor, arg); |
---|
198 | #endif |
---|
199 | } |
---|
200 | |
---|
201 | /* |
---|
202 | * Handle ioctl request. |
---|
203 | * Should set hardware line speed, bits/char, etc. |
---|
204 | */ |
---|
205 | rtems_device_driver console_control(rtems_device_major_number major, |
---|
206 | rtems_device_minor_number minor, |
---|
207 | void *arg) |
---|
208 | { |
---|
209 | #ifdef I_WANT_TERMIOS |
---|
210 | if (minor == SCC2_MINOR) { |
---|
211 | return rtems_termios_ioctl (arg); |
---|
212 | } |
---|
213 | else { |
---|
214 | return RTEMS_SUCCESSFUL; |
---|
215 | } |
---|
216 | #else |
---|
217 | return RTEMS_SUCCESSFUL; |
---|
218 | #endif |
---|
219 | } |
---|
220 | |
---|
221 | /* |
---|
222 | * Support routine for console-generic |
---|
223 | */ |
---|
224 | |
---|
225 | int mbx8xx_console_get_configuration(void) |
---|
226 | { |
---|
227 | #if NVRAM_CONFIGURE == 1 |
---|
228 | return nvram->console_mode; |
---|
229 | #else |
---|
230 | #if UARTS_IO_MODE == 1 |
---|
231 | return 0x02; |
---|
232 | #else |
---|
233 | return 0; |
---|
234 | #endif |
---|
235 | #endif |
---|
236 | |
---|
237 | } |
---|
238 | |
---|