Subversion Repositories HelenOS

Rev

Rev 3674 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3674 Rev 4337
Line 34... Line 34...
34
 */
34
 */
35
/** @file
35
/** @file
36
 */
36
 */
37
 
37
 
38
#include <async.h>
38
#include <async.h>
39
#include <ipc/ipc.h>
-
 
40
#include <ipc/fb.h>
-
 
41
#include <sysinfo.h>
39
#include <sysinfo.h>
42
#include <as.h>
40
#include <as.h>
43
#include <errno.h>
41
#include <errno.h>
44
#include <stdio.h>
42
#include <stdio.h>
45
#include <ddi.h>
43
#include <ddi.h>
Line 58... Line 56...
58
/**
56
/**
59
 * SGCN buffer offset within SGCN.
57
 * SGCN buffer offset within SGCN.
60
 */
58
 */
61
static uintptr_t sram_buffer_offset;
59
static uintptr_t sram_buffer_offset;
62
 
60
 
63
/* Allow only 1 connection */
-
 
64
static int client_connected = 0;
-
 
65
 
-
 
66
/**
61
/**
67
 * SGCN buffer header. It is placed at the very beginning of the SGCN
62
 * SGCN buffer header. It is placed at the very beginning of the SGCN
68
 * buffer.
63
 * buffer.
69
 */
64
 */
70
typedef struct {
65
typedef struct {
Line 120... Line 115...
120
    *buf_ptr = c;
115
    *buf_ptr = c;
121
    *out_wrptr_ptr = new_wrptr;
116
    *out_wrptr_ptr = new_wrptr;
122
}
117
}
123
 
118
 
124
/**
119
/**
125
 * Main function of the thread serving client connections.
-
 
126
 */
-
 
127
static void sgcn_client_connection(ipc_callid_t iid, ipc_call_t *icall)
-
 
128
{
-
 
129
    int retval;
-
 
130
    ipc_callid_t callid;
-
 
131
    ipc_call_t call;
-
 
132
    char c;
-
 
133
    int lastcol = 0;
-
 
134
    int lastrow = 0;
-
 
135
    int newcol;
-
 
136
    int newrow;
-
 
137
    int fgcolor;
-
 
138
    int bgcolor;
-
 
139
    int i;
-
 
140
   
-
 
141
    if (client_connected) {
-
 
142
        ipc_answer_0(iid, ELIMIT);
-
 
143
        return;
-
 
144
    }
-
 
145
   
-
 
146
    client_connected = 1;
-
 
147
    ipc_answer_0(iid, EOK);
-
 
148
   
-
 
149
    /* Clear the terminal, set scrolling region
-
 
150
       to 0 - 24 lines */
-
 
151
    serial_clrscr();
-
 
152
    serial_goto(0, 0);
-
 
153
    serial_puts("\033[0;24r");
-
 
154
   
-
 
155
    while (true) {
-
 
156
        callid = async_get_call(&call);
-
 
157
        switch (IPC_GET_METHOD(call)) {
-
 
158
        case IPC_M_PHONE_HUNGUP:
-
 
159
            client_connected = 0;
-
 
160
            ipc_answer_0(callid, EOK);
-
 
161
            return;
-
 
162
        case FB_PUTCHAR:
-
 
163
            c = IPC_GET_ARG1(call);
-
 
164
            newrow = IPC_GET_ARG2(call);
-
 
165
            newcol = IPC_GET_ARG3(call);
-
 
166
            if ((lastcol != newcol) || (lastrow != newrow))
-
 
167
                serial_goto(newrow, newcol);
-
 
168
            lastcol = newcol + 1;
-
 
169
            lastrow = newrow;
-
 
170
            sgcn_putc(c);
-
 
171
            retval = 0;
-
 
172
            break;
-
 
173
        case FB_CURSOR_GOTO:
-
 
174
            newrow = IPC_GET_ARG1(call);
-
 
175
            newcol = IPC_GET_ARG2(call);
-
 
176
            serial_goto(newrow, newcol);
-
 
177
            lastrow = newrow;
-
 
178
            lastcol = newcol;
-
 
179
            retval = 0;
-
 
180
            break;
-
 
181
        case FB_GET_CSIZE:
-
 
182
            ipc_answer_2(callid, EOK, HEIGHT, WIDTH);
-
 
183
            continue;
-
 
184
        case FB_CLEAR:
-
 
185
            serial_clrscr();
-
 
186
            retval = 0;
-
 
187
            break;
-
 
188
        case FB_SET_STYLE:
-
 
189
            fgcolor = IPC_GET_ARG1(call);
-
 
190
            bgcolor = IPC_GET_ARG2(call);
-
 
191
            if (fgcolor < bgcolor)
-
 
192
                serial_set_style(0);
-
 
193
            else
-
 
194
                serial_set_style(7);
-
 
195
            retval = 0;
-
 
196
            break;
-
 
197
        case FB_SCROLL:
-
 
198
            i = IPC_GET_ARG1(call);
-
 
199
            if ((i > HEIGHT) || (i < -HEIGHT)) {
-
 
200
                retval = EINVAL;
-
 
201
                break;
-
 
202
            }
-
 
203
            serial_scroll(i);
-
 
204
            serial_goto(lastrow, lastcol);
-
 
205
            retval = 0;
-
 
206
            break;
-
 
207
        case FB_CURSOR_VISIBILITY:
-
 
208
            if(IPC_GET_ARG1(call))
-
 
209
                serial_cursor_enable();
-
 
210
            else
-
 
211
                serial_cursor_disable();
-
 
212
            retval = 0;
-
 
213
            break;
-
 
214
        default:
-
 
215
            retval = ENOENT;
-
 
216
        }
-
 
217
        ipc_answer_0(callid, retval);
-
 
218
    }
-
 
219
}
-
 
220
 
-
 
221
/**
-
 
222
 * Initializes the SGCN serial driver.
120
 * Initializes the SGCN serial driver.
223
 */
121
 */
224
int sgcn_init(void)
122
int sgcn_init(void)
225
{
123
{
226
    sram_virt_addr = (uintptr_t) as_get_mappable_page(
124
    sram_virt_addr = (uintptr_t) as_get_mappable_page(
Line 238... Line 136...
238
   
136
   
239
    serial_console_init(sgcn_putc, WIDTH, HEIGHT);
137
    serial_console_init(sgcn_putc, WIDTH, HEIGHT);
240
   
138
   
241
    sram_buffer_offset = sysinfo_value("sram.buffer.offset");
139
    sram_buffer_offset = sysinfo_value("sram.buffer.offset");
242
   
140
   
243
    async_set_client_connection(sgcn_client_connection);
141
    async_set_client_connection(serial_client_connection);
244
    return 0;
142
    return 0;
245
}
143
}
246
 
144
 
247
/**
145
/**
248
 * @}
146
 * @}