1 | /* |
---|
2 | * This file contains the hardware specific portions of the TTY driver |
---|
3 | * for the serial ports on the erc32. |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1997. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * Copyright assigned to U.S. Government, 1994. |
---|
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.OARcorp.com/rtems/license.html. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <bsp.h> |
---|
17 | #include <rtems/libio.h> |
---|
18 | #include <stdlib.h> |
---|
19 | #include <assert.h> |
---|
20 | |
---|
21 | /* external prototypes for monitor interface routines */ |
---|
22 | |
---|
23 | void outbyte( char ); |
---|
24 | char inbyte( void ); |
---|
25 | |
---|
26 | /* |
---|
27 | * console_outbyte_polled |
---|
28 | * |
---|
29 | * This routine transmits a character using polling. |
---|
30 | */ |
---|
31 | |
---|
32 | void console_outbyte_polled( |
---|
33 | int port, |
---|
34 | char ch |
---|
35 | ) |
---|
36 | { |
---|
37 | outbyte( ch ); |
---|
38 | } |
---|
39 | |
---|
40 | /* |
---|
41 | * console_inbyte_nonblocking |
---|
42 | * |
---|
43 | * This routine polls for a character. |
---|
44 | */ |
---|
45 | |
---|
46 | int console_inbyte_nonblocking( |
---|
47 | int port |
---|
48 | ) |
---|
49 | { |
---|
50 | char c; |
---|
51 | |
---|
52 | c = inbyte(); |
---|
53 | if (!c) |
---|
54 | return -1; |
---|
55 | return c; |
---|
56 | } |
---|
57 | |
---|
58 | /* |
---|
59 | * DEBUG_puts |
---|
60 | * |
---|
61 | * This should be safe in the event of an error. It attempts to insure |
---|
62 | * that no TX empty interrupts occur while it is doing polled IO. Then |
---|
63 | * it restores the state of that external interrupt. |
---|
64 | * |
---|
65 | * Input parameters: |
---|
66 | * string - pointer to debug output string |
---|
67 | * |
---|
68 | * Output parameters: NONE |
---|
69 | * |
---|
70 | * Return values: NONE |
---|
71 | */ |
---|
72 | |
---|
73 | void DEBUG_puts( |
---|
74 | char *string |
---|
75 | ) |
---|
76 | { |
---|
77 | char *s; |
---|
78 | |
---|
79 | /* XXX should disable interrupts around this if interrupt driven */ |
---|
80 | |
---|
81 | for ( s = string ; *s ; s++ ) |
---|
82 | console_outbyte_polled( 0, *s ); |
---|
83 | |
---|
84 | console_outbyte_polled( 0, '\r' ); |
---|
85 | console_outbyte_polled( 0, '\n' ); |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | /* |
---|
90 | * Console Termios Support Entry Points |
---|
91 | * |
---|
92 | */ |
---|
93 | |
---|
94 | int console_write_support (int minor, const void *bufarg, int len) |
---|
95 | { |
---|
96 | int nwrite = 0; |
---|
97 | const char *buf = bufarg; |
---|
98 | |
---|
99 | while (nwrite < len) { |
---|
100 | console_outbyte_polled( minor, *buf++ ); |
---|
101 | nwrite++; |
---|
102 | } |
---|
103 | return nwrite; |
---|
104 | } |
---|
105 | |
---|
106 | /* |
---|
107 | * Console Device Driver Entry Points |
---|
108 | * |
---|
109 | */ |
---|
110 | |
---|
111 | rtems_device_driver console_initialize( |
---|
112 | rtems_device_major_number major, |
---|
113 | rtems_device_minor_number minor, |
---|
114 | void *arg |
---|
115 | ) |
---|
116 | { |
---|
117 | rtems_status_code status; |
---|
118 | |
---|
119 | rtems_termios_initialize(); |
---|
120 | |
---|
121 | /* |
---|
122 | * Register Device Names |
---|
123 | */ |
---|
124 | |
---|
125 | status = rtems_io_register_name( "/dev/console", major, 0 ); |
---|
126 | if (status != RTEMS_SUCCESSFUL) |
---|
127 | rtems_fatal_error_occurred(status); |
---|
128 | |
---|
129 | return RTEMS_SUCCESSFUL; |
---|
130 | } |
---|
131 | |
---|
132 | rtems_device_driver console_open( |
---|
133 | rtems_device_major_number major, |
---|
134 | rtems_device_minor_number minor, |
---|
135 | void * arg |
---|
136 | ) |
---|
137 | { |
---|
138 | rtems_status_code sc; |
---|
139 | static const rtems_termios_callbacks pollCallbacks = { |
---|
140 | NULL, /* firstOpen */ |
---|
141 | NULL, /* lastClose */ |
---|
142 | console_inbyte_nonblocking, /* pollRead */ |
---|
143 | console_write_support, /* write */ |
---|
144 | NULL, /* setAttributes */ |
---|
145 | NULL, /* stopRemoteTx */ |
---|
146 | NULL, /* startRemoteTx */ |
---|
147 | 0 /* outputUsesInterrupts */ |
---|
148 | }; |
---|
149 | |
---|
150 | |
---|
151 | assert( minor <= 1 ); |
---|
152 | if ( minor > 2 ) |
---|
153 | return RTEMS_INVALID_NUMBER; |
---|
154 | |
---|
155 | sc = rtems_termios_open (major, minor, arg, &pollCallbacks ); |
---|
156 | |
---|
157 | return RTEMS_SUCCESSFUL; |
---|
158 | } |
---|
159 | |
---|
160 | rtems_device_driver console_close( |
---|
161 | rtems_device_major_number major, |
---|
162 | rtems_device_minor_number minor, |
---|
163 | void * arg |
---|
164 | ) |
---|
165 | { |
---|
166 | return rtems_termios_close (arg); |
---|
167 | } |
---|
168 | |
---|
169 | rtems_device_driver console_read( |
---|
170 | rtems_device_major_number major, |
---|
171 | rtems_device_minor_number minor, |
---|
172 | void * arg |
---|
173 | ) |
---|
174 | { |
---|
175 | return rtems_termios_read (arg); |
---|
176 | } |
---|
177 | |
---|
178 | rtems_device_driver console_write( |
---|
179 | rtems_device_major_number major, |
---|
180 | rtems_device_minor_number minor, |
---|
181 | void * arg |
---|
182 | ) |
---|
183 | { |
---|
184 | return rtems_termios_write (arg); |
---|
185 | } |
---|
186 | |
---|
187 | rtems_device_driver console_control( |
---|
188 | rtems_device_major_number major, |
---|
189 | rtems_device_minor_number minor, |
---|
190 | void * arg |
---|
191 | ) |
---|
192 | { |
---|
193 | return rtems_termios_ioctl (arg); |
---|
194 | } |
---|
195 | |
---|
196 | void console_reserve_resources( |
---|
197 | rtems_configuration_table *configuration |
---|
198 | ) |
---|
199 | { |
---|
200 | rtems_termios_reserve_resources( configuration, 1 ); |
---|
201 | } |
---|