Changeset 8b97256 in mainline for uspace/srv/fb/serial_console.c


Ignore:
Timestamp:
2008-12-18T12:23:39Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d99b3f2
Parents:
8231246
Message:

Do not duplicate code in serial framebuffer drivers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fb/serial_console.c

    r8231246 r8b97256  
    3939
    4040#include <stdio.h>
     41#include <ipc/ipc.h>
     42#include <async.h>
     43#include <ipc/fb.h>
     44#include <bool.h>
     45#include <errno.h>
    4146
    4247#include "serial_console.h"
     
    4449#define MAX_CONTROL 20
    4550
    46 static uint32_t width;
    47 static uint32_t height;
     51static int width;
     52static int height;
    4853static putc_function_t putc_function;
     54
     55/* Allow only 1 connection */
     56static int client_connected = 0;
    4957
    5058void serial_puts(char *str)
     
    8997}
    9098
     99/** Set scrolling region. */
     100void serial_set_scroll_region(unsigned last_row)
     101{
     102        char control[MAX_CONTROL];
     103        snprintf(control, MAX_CONTROL, "\033[0;%ur", last_row);
     104        serial_puts(control);
     105}
     106
    91107void serial_cursor_disable(void)
    92108{
     
    106122}
    107123
     124/**
     125 * Main function of the thread serving client connections.
     126 */
     127void serial_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 - height rows. */
     151        serial_clrscr();
     152        serial_goto(0, 0);
     153        serial_set_scroll_region(height);
     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                        (*putc_function)(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
    108221/**
    109222 * @}
Note: See TracChangeset for help on using the changeset viewer.