1 | /* |
---|
2 | * This file contains the TTY driver for the serial ports on the LEON. |
---|
3 | * |
---|
4 | * This driver uses the termios pseudo driver. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1998. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * Modified for LEON3 BSP. |
---|
10 | * COPYRIGHT (c) 2004. |
---|
11 | * Gaisler Research. |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.com/license/LICENSE. |
---|
16 | * |
---|
17 | * $Id$ |
---|
18 | */ |
---|
19 | |
---|
20 | #include <bsp.h> |
---|
21 | #include <rtems/libio.h> |
---|
22 | #include <stdlib.h> |
---|
23 | #include <assert.h> |
---|
24 | #include <rtems/bspIo.h> |
---|
25 | #include <amba.h> |
---|
26 | |
---|
27 | /* |
---|
28 | * Should we use a polled or interrupt drived console? |
---|
29 | * |
---|
30 | * NOTE: This is defined in the custom/leon.cfg file. |
---|
31 | * |
---|
32 | * WARNING: In sis 1.6, it did not appear that the UART interrupts |
---|
33 | * worked in a desirable fashion. Immediately upon writing |
---|
34 | * a character into the TX buffer, an interrupt was generated. |
---|
35 | * This did not allow enough time for the program to put more |
---|
36 | * characters in the buffer. So every character resulted in |
---|
37 | * "priming" the transmitter. This effectively results in |
---|
38 | * in a polled console with a useless interrupt per character |
---|
39 | * on output. It is reasonable to assume that input does not |
---|
40 | * share this problem although it was not investigated. |
---|
41 | * |
---|
42 | */ |
---|
43 | |
---|
44 | /* |
---|
45 | * console_outbyte_polled |
---|
46 | * |
---|
47 | * This routine transmits a character using polling. |
---|
48 | */ |
---|
49 | |
---|
50 | void console_outbyte_polled( |
---|
51 | int port, |
---|
52 | char ch |
---|
53 | ); |
---|
54 | |
---|
55 | /* body is in debugputs.c */ |
---|
56 | |
---|
57 | /* |
---|
58 | * console_inbyte_nonblocking |
---|
59 | * |
---|
60 | * This routine polls for a character. |
---|
61 | */ |
---|
62 | |
---|
63 | int console_inbyte_nonblocking( int port ); |
---|
64 | |
---|
65 | /* body is in debugputs.c */ |
---|
66 | |
---|
67 | |
---|
68 | /* |
---|
69 | * Console Termios Support Entry Points |
---|
70 | * |
---|
71 | */ |
---|
72 | |
---|
73 | int console_write_support (int minor, const char *buf, int len) |
---|
74 | { |
---|
75 | int nwrite = 0; |
---|
76 | |
---|
77 | while (nwrite < len) { |
---|
78 | console_outbyte_polled( minor, *buf++ ); |
---|
79 | nwrite++; |
---|
80 | } |
---|
81 | return nwrite; |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | /* |
---|
86 | * Console Device Driver Entry Points |
---|
87 | * |
---|
88 | */ |
---|
89 | int uarts = 0; |
---|
90 | static int isinit = 0; |
---|
91 | volatile LEON3_UART_Regs_Map *LEON3_Console_Uart[LEON3_APBUARTS]; |
---|
92 | |
---|
93 | int scan_uarts() { |
---|
94 | unsigned int iobar, conf; |
---|
95 | int i; |
---|
96 | amba_apb_device apbuarts[LEON3_APBUARTS]; |
---|
97 | |
---|
98 | if (isinit == 0) { |
---|
99 | i = 0; uarts = 0; |
---|
100 | |
---|
101 | uarts = amba_find_apbslvs(&amba_conf,VENDOR_GAISLER,GAISLER_APBUART,apbuarts,LEON3_APBUARTS); |
---|
102 | for(i=0; i<uarts; i++){ |
---|
103 | LEON3_Console_Uart[i] = apbuarts[i].start; |
---|
104 | } |
---|
105 | isinit = 1; |
---|
106 | } |
---|
107 | return uarts; |
---|
108 | } |
---|
109 | |
---|
110 | rtems_device_driver console_initialize( |
---|
111 | rtems_device_major_number major, |
---|
112 | rtems_device_minor_number minor, |
---|
113 | void *arg |
---|
114 | ) |
---|
115 | { |
---|
116 | rtems_status_code status; |
---|
117 | int i, uart0; |
---|
118 | char console_name[16]; |
---|
119 | extern rtems_configuration_table Configuration; |
---|
120 | |
---|
121 | rtems_termios_initialize(); |
---|
122 | |
---|
123 | /* Find UARTs */ |
---|
124 | scan_uarts(); |
---|
125 | |
---|
126 | if (Configuration.User_multiprocessing_table != NULL) |
---|
127 | uart0 = LEON3_Cpu_Index; |
---|
128 | else |
---|
129 | uart0 = 0; |
---|
130 | |
---|
131 | /* Register Device Names */ |
---|
132 | |
---|
133 | if (uarts && (uart0 < uarts)) |
---|
134 | { |
---|
135 | status = rtems_io_register_name( "/dev/console", major, 0 ); |
---|
136 | if (status != RTEMS_SUCCESSFUL) |
---|
137 | rtems_fatal_error_occurred(status); |
---|
138 | |
---|
139 | strcpy(console_name,"/dev/console_a"); |
---|
140 | for (i = uart0+1; i < uarts; i++) |
---|
141 | { |
---|
142 | console_name[13]++; |
---|
143 | status = rtems_io_register_name( console_name, major, i); |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | /* |
---|
149 | * Initialize Hardware |
---|
150 | */ |
---|
151 | if ((Configuration.User_multiprocessing_table == NULL) || |
---|
152 | ((Configuration.User_multiprocessing_table)->node == 1)) |
---|
153 | { |
---|
154 | for (i = uart0; i < uarts; i++) |
---|
155 | { |
---|
156 | LEON3_Console_Uart[i]->ctrl |= LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE; |
---|
157 | LEON3_Console_Uart[i]->status = 0; |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | return RTEMS_SUCCESSFUL; |
---|
162 | } |
---|
163 | |
---|
164 | rtems_device_driver console_open( |
---|
165 | rtems_device_major_number major, |
---|
166 | rtems_device_minor_number minor, |
---|
167 | void * arg |
---|
168 | ) |
---|
169 | { |
---|
170 | rtems_status_code sc; |
---|
171 | |
---|
172 | static const rtems_termios_callbacks pollCallbacks = { |
---|
173 | NULL, /* firstOpen */ |
---|
174 | NULL, /* lastClose */ |
---|
175 | console_inbyte_nonblocking, /* pollRead */ |
---|
176 | console_write_support, /* write */ |
---|
177 | NULL, /* setAttributes */ |
---|
178 | NULL, /* stopRemoteTx */ |
---|
179 | NULL, /* startRemoteTx */ |
---|
180 | 0 /* outputUsesInterrupts */ |
---|
181 | }; |
---|
182 | |
---|
183 | |
---|
184 | assert( minor <= LEON3_APBUARTS ); |
---|
185 | if ( minor > LEON3_APBUARTS ) |
---|
186 | return RTEMS_INVALID_NUMBER; |
---|
187 | |
---|
188 | sc = rtems_termios_open (major, minor, arg, &pollCallbacks); |
---|
189 | |
---|
190 | |
---|
191 | return RTEMS_SUCCESSFUL; |
---|
192 | } |
---|
193 | |
---|
194 | rtems_device_driver console_close( |
---|
195 | rtems_device_major_number major, |
---|
196 | rtems_device_minor_number minor, |
---|
197 | void * arg |
---|
198 | ) |
---|
199 | { |
---|
200 | return rtems_termios_close (arg); |
---|
201 | } |
---|
202 | |
---|
203 | rtems_device_driver console_read( |
---|
204 | rtems_device_major_number major, |
---|
205 | rtems_device_minor_number minor, |
---|
206 | void * arg |
---|
207 | ) |
---|
208 | { |
---|
209 | return rtems_termios_read (arg); |
---|
210 | } |
---|
211 | |
---|
212 | rtems_device_driver console_write( |
---|
213 | rtems_device_major_number major, |
---|
214 | rtems_device_minor_number minor, |
---|
215 | void * arg |
---|
216 | ) |
---|
217 | { |
---|
218 | return rtems_termios_write (arg); |
---|
219 | } |
---|
220 | |
---|
221 | rtems_device_driver console_control( |
---|
222 | rtems_device_major_number major, |
---|
223 | rtems_device_minor_number minor, |
---|
224 | void * arg |
---|
225 | ) |
---|
226 | { |
---|
227 | return rtems_termios_ioctl (arg); |
---|
228 | } |
---|
229 | |
---|
230 | /* putchar/getchar for printk */ |
---|
231 | |
---|
232 | static void bsp_out_char(char c) |
---|
233 | { |
---|
234 | console_outbyte_polled(0, c); |
---|
235 | } |
---|
236 | |
---|
237 | BSP_output_char_function_type BSP_output_char = bsp_out_char; |
---|
238 | |
---|
239 | static char bsp_in_char(void) |
---|
240 | { |
---|
241 | int tmp; |
---|
242 | |
---|
243 | while ((tmp = console_inbyte_nonblocking(0)) < 0); |
---|
244 | return (char) tmp; |
---|
245 | } |
---|
246 | |
---|
247 | BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char; |
---|