1 | /* |
---|
2 | * This file contains the termios TTY driver for the i386 |
---|
3 | * vga. |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-2011. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.com/license/LICENSE. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #include <rtems.h> |
---|
16 | #include <rtems/libio.h> |
---|
17 | #include <stdlib.h> |
---|
18 | #include <libchip/serial.h> |
---|
19 | #include <rtems/vgacons.h> |
---|
20 | #include <rtems/keyboard.h> |
---|
21 | #include <libchip/sersupp.h> |
---|
22 | #include <bsp/irq.h> |
---|
23 | #include <bsp.h> |
---|
24 | #include <crt.h> |
---|
25 | |
---|
26 | #define VGACONS_STATIC static |
---|
27 | |
---|
28 | static int isr_is_on(const rtems_irq_connect_data *irq) |
---|
29 | { |
---|
30 | return BSP_irq_enabled_at_i8259s(irq->name); |
---|
31 | } |
---|
32 | |
---|
33 | static rtems_irq_connect_data keyboard_isr_data = { |
---|
34 | BSP_KEYBOARD, |
---|
35 | keyboard_interrupt, |
---|
36 | 0, |
---|
37 | NULL, |
---|
38 | NULL, |
---|
39 | isr_is_on |
---|
40 | }; |
---|
41 | |
---|
42 | /* |
---|
43 | * vgacons_init |
---|
44 | * |
---|
45 | * This function initializes the VGA console to a quiecsent state. |
---|
46 | */ |
---|
47 | VGACONS_STATIC void vgacons_init(int minor) |
---|
48 | { |
---|
49 | /* |
---|
50 | * Note: We do not initialize the KBD interface here since |
---|
51 | * it was initialized regardless of whether the |
---|
52 | * vga is available or not. Therefore it is initialized |
---|
53 | * in bsp_start. |
---|
54 | */ |
---|
55 | } |
---|
56 | |
---|
57 | /* |
---|
58 | * vgacons_open |
---|
59 | * |
---|
60 | * This function opens a port for communication. |
---|
61 | * |
---|
62 | * Default state is 9600 baud, 8 bits, No parity, and 1 stop bit. |
---|
63 | */ |
---|
64 | VGACONS_STATIC int vgacons_open( |
---|
65 | int major, |
---|
66 | int minor, |
---|
67 | void *arg |
---|
68 | ) |
---|
69 | { |
---|
70 | return RTEMS_SUCCESSFUL; |
---|
71 | } |
---|
72 | |
---|
73 | /* |
---|
74 | * vgacons_close |
---|
75 | * |
---|
76 | * This function shuts down the requested port. |
---|
77 | */ |
---|
78 | VGACONS_STATIC int vgacons_close( |
---|
79 | int major, |
---|
80 | int minor, |
---|
81 | void *arg |
---|
82 | ) |
---|
83 | { |
---|
84 | return(RTEMS_SUCCESSFUL); |
---|
85 | } |
---|
86 | |
---|
87 | /* |
---|
88 | * vgacons_write_polled |
---|
89 | * |
---|
90 | * This routine polls out the requested character. |
---|
91 | */ |
---|
92 | VGACONS_STATIC void vgacons_write_polled( |
---|
93 | int minor, |
---|
94 | char c |
---|
95 | ) |
---|
96 | { |
---|
97 | _IBMPC_outch( c ); |
---|
98 | if( c == '\n') |
---|
99 | _IBMPC_outch( '\r' ); /* LF = LF + CR */ |
---|
100 | } |
---|
101 | |
---|
102 | /* |
---|
103 | * vgacons_write_support_polled |
---|
104 | * |
---|
105 | * Console Termios output entry point when using polled output. |
---|
106 | * |
---|
107 | */ |
---|
108 | VGACONS_STATIC ssize_t vgacons_write_support_polled( |
---|
109 | int minor, |
---|
110 | const char *buf, |
---|
111 | size_t len |
---|
112 | ) |
---|
113 | { |
---|
114 | int nwrite = 0; |
---|
115 | |
---|
116 | /* |
---|
117 | * poll each byte in the string out of the port. |
---|
118 | */ |
---|
119 | while (nwrite < len) { |
---|
120 | vgacons_write_polled(minor, *buf++); |
---|
121 | nwrite++; |
---|
122 | } |
---|
123 | |
---|
124 | /* |
---|
125 | * return the number of bytes written. |
---|
126 | */ |
---|
127 | return nwrite; |
---|
128 | } |
---|
129 | |
---|
130 | /* |
---|
131 | * vgacons_inbyte_nonblocking_polled |
---|
132 | * |
---|
133 | * Console Termios polling input entry point. |
---|
134 | */ |
---|
135 | VGACONS_STATIC int vgacons_inbyte_nonblocking_polled( |
---|
136 | int minor |
---|
137 | ) |
---|
138 | { |
---|
139 | if( rtems_kbpoll() ) { |
---|
140 | int c = getch(); |
---|
141 | return c; |
---|
142 | } |
---|
143 | |
---|
144 | return -1; |
---|
145 | } |
---|
146 | |
---|
147 | /* |
---|
148 | * vgacons_set_attributes |
---|
149 | * |
---|
150 | * This function sets the UART channel to reflect the requested termios |
---|
151 | * port settings. |
---|
152 | */ |
---|
153 | VGACONS_STATIC int vgacons_set_attributes( |
---|
154 | int minor, |
---|
155 | const struct termios *t |
---|
156 | ) |
---|
157 | { |
---|
158 | return 0; |
---|
159 | } |
---|
160 | |
---|
161 | bool vgacons_probe( |
---|
162 | int minor |
---|
163 | ) |
---|
164 | { |
---|
165 | int status; |
---|
166 | static bool firstTime = true; |
---|
167 | |
---|
168 | if ((*(unsigned char*) NB_MAX_ROW_ADDR == 0) && |
---|
169 | (*(unsigned short*)NB_MAX_COL_ADDR == 0)) { |
---|
170 | return false; |
---|
171 | } |
---|
172 | |
---|
173 | /* |
---|
174 | * If there is a video card, let's assume there is also a keyboard. |
---|
175 | * The means that we need the ISR installed in case someone wants to |
---|
176 | * use the Keyboard or PS2 Mouse. With Microwindows, the console |
---|
177 | * can be COM1 and you can still use the mouse/VGA for graphics. |
---|
178 | */ |
---|
179 | if ( firstTime ) { |
---|
180 | status = BSP_install_rtems_irq_handler(&keyboard_isr_data); |
---|
181 | if (!status) { |
---|
182 | printk("Error installing keyboard interrupt handler!\n"); |
---|
183 | rtems_fatal_error_occurred(status); |
---|
184 | } |
---|
185 | } |
---|
186 | firstTime = false; |
---|
187 | |
---|
188 | return true; |
---|
189 | } |
---|
190 | |
---|
191 | console_fns vgacons_fns = |
---|
192 | { |
---|
193 | libchip_serial_default_probe, /* deviceProbe */ |
---|
194 | vgacons_open, /* deviceFirstOpen */ |
---|
195 | vgacons_close, /* deviceLastClose */ |
---|
196 | vgacons_inbyte_nonblocking_polled, /* deviceRead */ |
---|
197 | vgacons_write_support_polled, /* deviceWrite */ |
---|
198 | vgacons_init, /* deviceInitialize */ |
---|
199 | vgacons_write_polled, /* deviceWritePolled */ |
---|
200 | vgacons_set_attributes, /* deviceSetAttributes */ |
---|
201 | FALSE, /* deviceOutputUsesInterrupts */ |
---|
202 | }; |
---|