Rev 3716 | Rev 3769 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3716 | Rev 3767 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * Copyright (c) 2008 Martin Decky |
3 | * Copyright (c) 2008 Martin Decky |
4 | * Copyright (c) 2008 Pavel Rimsky |
4 | * Copyright (c) 2008 Pavel Rimsky |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
9 | * are met: |
10 | * |
10 | * |
11 | * - Redistributions of source code must retain the above copyright |
11 | * - Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. |
12 | * notice, this list of conditions and the following disclaimer. |
13 | * - Redistributions in binary form must reproduce the above copyright |
13 | * - Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the |
14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. |
15 | * documentation and/or other materials provided with the distribution. |
16 | * - The name of the author may not be used to endorse or promote products |
16 | * - The name of the author may not be used to endorse or promote products |
17 | * derived from this software without specific prior written permission. |
17 | * derived from this software without specific prior written permission. |
18 | * |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | */ |
29 | */ |
30 | 30 | ||
31 | /** |
31 | /** |
32 | * @defgroup serial Serial console |
32 | * @defgroup serial Serial console |
33 | * @brief Serial console services (putc, puts, clear screen, cursor goto,...) |
33 | * @brief Serial console services (putc, puts, clear screen, cursor goto,...) |
34 | * @{ |
34 | * @{ |
35 | */ |
35 | */ |
36 | 36 | ||
37 | /** @file |
37 | /** @file |
38 | */ |
38 | */ |
39 | 39 | ||
40 | #include <stdio.h> |
40 | #include <stdio.h> |
41 | #include <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
42 | #include <async.h> |
42 | #include <async.h> |
43 | #include <ipc/fb.h> |
43 | #include <ipc/fb.h> |
44 | #include <bool.h> |
44 | #include <bool.h> |
45 | #include <errno.h> |
45 | #include <errno.h> |
- | 46 | #include <console/style.h> |
|
46 | 47 | ||
47 | #include "serial_console.h" |
48 | #include "serial_console.h" |
48 | 49 | ||
49 | #define MAX_CONTROL 20 |
50 | #define MAX_CONTROL 20 |
50 | 51 | ||
51 | static int width; |
52 | static int width; |
52 | static int height; |
53 | static int height; |
53 | static putc_function_t putc_function; |
54 | static putc_function_t putc_function; |
54 | 55 | ||
55 | /* Allow only 1 connection */ |
56 | /* Allow only 1 connection */ |
56 | static int client_connected = 0; |
57 | static int client_connected = 0; |
57 | 58 | ||
58 | void serial_puts(char *str) |
59 | void serial_puts(char *str) |
59 | { |
60 | { |
60 | while (*str) |
61 | while (*str) |
61 | putc_function(*(str++)); |
62 | putc_function(*(str++)); |
62 | } |
63 | } |
63 | 64 | ||
64 | void serial_goto(const unsigned int row, const unsigned int col) |
65 | void serial_goto(const unsigned int row, const unsigned int col) |
65 | { |
66 | { |
66 | if ((row > height) || (col > width)) |
67 | if ((row > height) || (col > width)) |
67 | return; |
68 | return; |
68 | 69 | ||
69 | char control[20]; |
70 | char control[20]; |
70 | snprintf(control, 20, "\033[%u;%uf", row + 1, col + 1); |
71 | snprintf(control, 20, "\033[%u;%uf", row + 1, col + 1); |
71 | serial_puts(control); |
72 | serial_puts(control); |
72 | } |
73 | } |
73 | 74 | ||
74 | void serial_clrscr(void) |
75 | void serial_clrscr(void) |
75 | { |
76 | { |
76 | serial_puts("\033[2J"); |
77 | serial_puts("\033[2J"); |
77 | } |
78 | } |
78 | 79 | ||
79 | void serial_scroll(int i) |
80 | void serial_scroll(int i) |
80 | { |
81 | { |
81 | if (i > 0) { |
82 | if (i > 0) { |
82 | serial_goto(height - 1, 0); |
83 | serial_goto(height - 1, 0); |
83 | while (i--) |
84 | while (i--) |
84 | serial_puts("\033D"); |
85 | serial_puts("\033D"); |
85 | } else if (i < 0) { |
86 | } else if (i < 0) { |
86 | serial_goto(0, 0); |
87 | serial_goto(0, 0); |
87 | while (i++) |
88 | while (i++) |
88 | serial_puts("\033M"); |
89 | serial_puts("\033M"); |
89 | } |
90 | } |
90 | } |
91 | } |
91 | 92 | ||
- | 93 | /** ECMA-48 Set Graphics Rendition. */ |
|
92 | void serial_set_style(const unsigned int mode) |
94 | static void serial_sgr(const unsigned int mode) |
93 | { |
95 | { |
94 | char control[MAX_CONTROL]; |
96 | char control[MAX_CONTROL]; |
95 | snprintf(control, MAX_CONTROL, "\033[%um", mode); |
97 | snprintf(control, MAX_CONTROL, "\033[%um", mode); |
96 | serial_puts(control); |
98 | serial_puts(control); |
97 | } |
99 | } |
98 | 100 | ||
99 | /** Set scrolling region. */ |
101 | /** Set scrolling region. */ |
100 | void serial_set_scroll_region(unsigned last_row) |
102 | void serial_set_scroll_region(unsigned last_row) |
101 | { |
103 | { |
102 | char control[MAX_CONTROL]; |
104 | char control[MAX_CONTROL]; |
103 | snprintf(control, MAX_CONTROL, "\033[0;%ur", last_row); |
105 | snprintf(control, MAX_CONTROL, "\033[0;%ur", last_row); |
104 | serial_puts(control); |
106 | serial_puts(control); |
105 | } |
107 | } |
106 | 108 | ||
107 | void serial_cursor_disable(void) |
109 | void serial_cursor_disable(void) |
108 | { |
110 | { |
109 | serial_puts("\033[?25l"); |
111 | serial_puts("\033[?25l"); |
110 | } |
112 | } |
111 | 113 | ||
112 | void serial_cursor_enable(void) |
114 | void serial_cursor_enable(void) |
113 | { |
115 | { |
114 | serial_puts("\033[?25h"); |
116 | serial_puts("\033[?25h"); |
115 | } |
117 | } |
116 | 118 | ||
117 | void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h) |
119 | void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h) |
118 | { |
120 | { |
119 | width = w; |
121 | width = w; |
120 | height = h; |
122 | height = h; |
121 | putc_function = putc_fn; |
123 | putc_function = putc_fn; |
122 | } |
124 | } |
123 | 125 | ||
124 | /** |
126 | /** |
125 | * Main function of the thread serving client connections. |
127 | * Main function of the thread serving client connections. |
126 | */ |
128 | */ |
127 | void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
129 | void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
128 | { |
130 | { |
129 | int retval; |
131 | int retval; |
130 | ipc_callid_t callid; |
132 | ipc_callid_t callid; |
131 | ipc_call_t call; |
133 | ipc_call_t call; |
132 | char c; |
134 | char c; |
133 | int lastcol = 0; |
135 | int lastcol = 0; |
134 | int lastrow = 0; |
136 | int lastrow = 0; |
135 | int newcol; |
137 | int newcol; |
136 | int newrow; |
138 | int newrow; |
137 | int fgcolor; |
139 | int fgcolor; |
138 | int bgcolor; |
140 | int bgcolor; |
- | 141 | int style; |
|
139 | int i; |
142 | int i; |
140 | 143 | ||
141 | if (client_connected) { |
144 | if (client_connected) { |
142 | ipc_answer_0(iid, ELIMIT); |
145 | ipc_answer_0(iid, ELIMIT); |
143 | return; |
146 | return; |
144 | } |
147 | } |
145 | 148 | ||
146 | client_connected = 1; |
149 | client_connected = 1; |
147 | ipc_answer_0(iid, EOK); |
150 | ipc_answer_0(iid, EOK); |
148 | 151 | ||
149 | /* Clear the terminal, set scrolling region |
152 | /* Clear the terminal, set scrolling region |
150 | to 0 - height rows. */ |
153 | to 0 - height rows. */ |
151 | serial_clrscr(); |
154 | serial_clrscr(); |
152 | serial_goto(0, 0); |
155 | serial_goto(0, 0); |
153 | serial_set_scroll_region(height); |
156 | serial_set_scroll_region(height); |
154 | 157 | ||
155 | while (true) { |
158 | while (true) { |
156 | callid = async_get_call(&call); |
159 | callid = async_get_call(&call); |
157 | switch (IPC_GET_METHOD(call)) { |
160 | switch (IPC_GET_METHOD(call)) { |
158 | case IPC_M_PHONE_HUNGUP: |
161 | case IPC_M_PHONE_HUNGUP: |
159 | client_connected = 0; |
162 | client_connected = 0; |
160 | ipc_answer_0(callid, EOK); |
163 | ipc_answer_0(callid, EOK); |
161 | return; |
164 | return; |
162 | case FB_PUTCHAR: |
165 | case FB_PUTCHAR: |
163 | c = IPC_GET_ARG1(call); |
166 | c = IPC_GET_ARG1(call); |
164 | newrow = IPC_GET_ARG2(call); |
167 | newrow = IPC_GET_ARG2(call); |
165 | newcol = IPC_GET_ARG3(call); |
168 | newcol = IPC_GET_ARG3(call); |
166 | if ((lastcol != newcol) || (lastrow != newrow)) |
169 | if ((lastcol != newcol) || (lastrow != newrow)) |
167 | serial_goto(newrow, newcol); |
170 | serial_goto(newrow, newcol); |
168 | lastcol = newcol + 1; |
171 | lastcol = newcol + 1; |
169 | lastrow = newrow; |
172 | lastrow = newrow; |
170 | (*putc_function)(c); |
173 | (*putc_function)(c); |
171 | retval = 0; |
174 | retval = 0; |
172 | break; |
175 | break; |
173 | case FB_CURSOR_GOTO: |
176 | case FB_CURSOR_GOTO: |
174 | newrow = IPC_GET_ARG1(call); |
177 | newrow = IPC_GET_ARG1(call); |
175 | newcol = IPC_GET_ARG2(call); |
178 | newcol = IPC_GET_ARG2(call); |
176 | serial_goto(newrow, newcol); |
179 | serial_goto(newrow, newcol); |
177 | lastrow = newrow; |
180 | lastrow = newrow; |
178 | lastcol = newcol; |
181 | lastcol = newcol; |
179 | retval = 0; |
182 | retval = 0; |
180 | break; |
183 | break; |
181 | case FB_GET_CSIZE: |
184 | case FB_GET_CSIZE: |
182 | ipc_answer_2(callid, EOK, height, width); |
185 | ipc_answer_2(callid, EOK, height, width); |
183 | continue; |
186 | continue; |
184 | case FB_CLEAR: |
187 | case FB_CLEAR: |
185 | serial_clrscr(); |
188 | serial_clrscr(); |
186 | retval = 0; |
189 | retval = 0; |
187 | break; |
190 | break; |
188 | case FB_SET_STYLE: |
191 | case FB_SET_STYLE: |
- | 192 | style = IPC_GET_ARG1(call); |
|
- | 193 | if (style == STYLE_EMPHASIS) |
|
- | 194 | serial_sgr(1); |
|
- | 195 | else |
|
- | 196 | serial_sgr(0); |
|
- | 197 | retval = 0; |
|
- | 198 | break; |
|
- | 199 | case FB_SET_COLOR: |
|
- | 200 | fgcolor = IPC_GET_ARG1(call); |
|
- | 201 | bgcolor = IPC_GET_ARG2(call); |
|
- | 202 | if (fgcolor < bgcolor) |
|
- | 203 | serial_sgr(0); |
|
- | 204 | else |
|
- | 205 | serial_sgr(7); |
|
- | 206 | retval = 0; |
|
- | 207 | break; |
|
- | 208 | case FB_SET_RGB_COLOR: |
|
189 | fgcolor = IPC_GET_ARG1(call); |
209 | fgcolor = IPC_GET_ARG1(call); |
190 | bgcolor = IPC_GET_ARG2(call); |
210 | bgcolor = IPC_GET_ARG2(call); |
191 | if (fgcolor < bgcolor) |
211 | if (fgcolor < bgcolor) |
192 | serial_set_style(0); |
212 | serial_sgr(0); |
193 | else |
213 | else |
194 | serial_set_style(7); |
214 | serial_sgr(7); |
195 | retval = 0; |
215 | retval = 0; |
196 | break; |
216 | break; |
197 | case FB_SCROLL: |
217 | case FB_SCROLL: |
198 | i = IPC_GET_ARG1(call); |
218 | i = IPC_GET_ARG1(call); |
199 | if ((i > height) || (i < -height)) { |
219 | if ((i > height) || (i < -height)) { |
200 | retval = EINVAL; |
220 | retval = EINVAL; |
201 | break; |
221 | break; |
202 | } |
222 | } |
203 | serial_scroll(i); |
223 | serial_scroll(i); |
204 | serial_goto(lastrow, lastcol); |
224 | serial_goto(lastrow, lastcol); |
205 | retval = 0; |
225 | retval = 0; |
206 | break; |
226 | break; |
207 | case FB_CURSOR_VISIBILITY: |
227 | case FB_CURSOR_VISIBILITY: |
208 | if(IPC_GET_ARG1(call)) |
228 | if(IPC_GET_ARG1(call)) |
209 | serial_cursor_enable(); |
229 | serial_cursor_enable(); |
210 | else |
230 | else |
211 | serial_cursor_disable(); |
231 | serial_cursor_disable(); |
212 | retval = 0; |
232 | retval = 0; |
213 | break; |
233 | break; |
214 | default: |
234 | default: |
215 | retval = ENOENT; |
235 | retval = ENOENT; |
216 | } |
236 | } |
217 | ipc_answer_0(callid, retval); |
237 | ipc_answer_0(callid, retval); |
218 | } |
238 | } |
219 | } |
239 | } |
220 | 240 | ||
221 | /** |
241 | /** |
222 | * @} |
242 | * @} |
223 | */ |
243 | */ |
224 | 244 |