source: mainline/kernel/genarch/src/srln/srln.c@ 3b065c9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3b065c9 was 7ddc2c7, checked in by Martin Decky <martin@…>, 12 years ago

add support for framebuffer history paging (using Page Up and Page Down keys), inspiration taken from the code by Sebastian Köln
add support for input device out-of-band signalling

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2009 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup genarch
30 * @{
31 */
32/**
33 * @file
34 * @brief Serial line processing.
35 */
36
37#include <genarch/srln/srln.h>
38#include <console/chardev.h>
39#include <console/console.h>
40#include <proc/thread.h>
41#include <arch.h>
42#include <str.h>
43
44static indev_operations_t srln_raw_ops = {
45 .poll = NULL,
46 .signal = NULL
47};
48
49static void ksrln(void *arg)
50{
51 srln_instance_t *instance = (srln_instance_t *) arg;
52 bool cr = false;
53 uint32_t escape = 0;
54
55 while (true) {
56 wchar_t ch = indev_pop_character(&instance->raw);
57
58 /* ANSI escape sequence processing */
59 if (escape != 0) {
60 escape <<= 8;
61 escape |= ch & 0xff;
62
63 if ((escape == 0x1b4f) || (escape == 0x1b5b) || (escape == 0x1b5b33))
64 continue;
65
66 switch (escape) {
67 case 0x1b4f46:
68 case 0x1b5b46:
69 ch = U_END_ARROW;
70 escape = 0;
71 break;
72 case 0x1b4f48:
73 case 0x1b5b48:
74 ch = U_HOME_ARROW;
75 escape = 0;
76 break;
77 case 0x1b5b41:
78 ch = U_UP_ARROW;
79 escape = 0;
80 break;
81 case 0x1b5b42:
82 ch = U_DOWN_ARROW;
83 escape = 0;
84 break;
85 case 0x1b5b43:
86 ch = U_RIGHT_ARROW;
87 escape = 0;
88 break;
89 case 0x1b5b44:
90 ch = U_LEFT_ARROW;
91 escape = 0;
92 break;
93 case 0x1b5b337e:
94 ch = U_DELETE;
95 escape = 0;
96 break;
97 default:
98 escape = 0;
99 }
100 }
101
102 if (ch == 0x1b) {
103 escape = ch & 0xff;
104 continue;
105 }
106
107 /* Replace carriage return with line feed
108 and suppress any following line feed */
109 if ((ch == '\n') && (cr)) {
110 cr = false;
111 continue;
112 }
113
114 if (ch == '\r') {
115 ch = '\n';
116 cr = true;
117 } else
118 cr = false;
119
120 /* Backspace */
121 if (ch == 0x7f)
122 ch = '\b';
123
124 indev_push_character(instance->sink, ch);
125 }
126}
127
128srln_instance_t *srln_init(void)
129{
130 srln_instance_t *instance
131 = malloc(sizeof(srln_instance_t), FRAME_ATOMIC);
132 if (instance) {
133 instance->thread = thread_create(ksrln, (void *) instance,
134 TASK, THREAD_FLAG_NONE, "ksrln");
135
136 if (!instance->thread) {
137 free(instance);
138 return NULL;
139 }
140
141 instance->sink = NULL;
142 indev_initialize("srln", &instance->raw, &srln_raw_ops);
143 }
144
145 return instance;
146}
147
148indev_t *srln_wire(srln_instance_t *instance, indev_t *sink)
149{
150 ASSERT(instance);
151 ASSERT(sink);
152
153 instance->sink = sink;
154 thread_ready(instance->thread);
155
156 return &instance->raw;
157}
158
159/** @}
160 */
Note: See TracBrowser for help on using the repository browser.