Changeset c2417bc in mainline for kernel/arch/ia64/src/drivers/ski.c


Ignore:
Timestamp:
2009-04-21T12:46:26Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f2d2c7ba
Parents:
44b7783
Message:

change the way how input devices are wired together according to ticket #44
(also the proposal http://lists.modry.cz/cgi-bin/private/helenos-devel/2009-March/002507.html)

File:
1 moved

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia64/src/drivers/ski.c

    r44b7783 rc2417bc  
    3333 */
    3434
    35 #include <arch/ski/ski.h>
     35#include <arch/drivers/ski.h>
    3636#include <console/console.h>
    3737#include <console/chardev.h>
     
    4545#include <arch.h>
    4646
    47 static indev_t skiin;           /**< Ski input device. */
    48 static outdev_t skiout;         /**< Ski output device. */
    49 
    50 static bool kbd_disabled;
     47#define POLL_INTERVAL  10000  /* 10 ms */
     48
     49#define SKI_INIT_CONSOLE  20
     50#define SKI_GETCHAR       21
     51#define SKI_PUTCHAR       31
     52
     53static void ski_putchar(outdev_t *, const wchar_t, bool);
     54
     55static outdev_operations_t skiout_ops = {
     56        .write = ski_putchar
     57};
     58
     59static outdev_t skiout;            /**< Ski output device. */
     60static bool initialized = false;
     61static bool kbd_disabled = false;
     62
     63/** Initialize debug console
     64 *
     65 * Issue SSC (Simulator System Call) to
     66 * to open debug console.
     67 *
     68 */
     69static void ski_init(void)
     70{
     71        if (initialized)
     72                return;
     73       
     74        asm volatile (
     75                "mov r15 = %0\n"
     76                "break 0x80000\n"
     77                :
     78                : "i" (SKI_INIT_CONSOLE)
     79                : "r15", "r8"
     80        );
     81       
     82        initialized = true;
     83}
    5184
    5285static void ski_do_putchar(const wchar_t ch)
     
    5588                "mov r15 = %[cmd]\n"
    5689                "mov r32 = %[ch]\n"   /* r32 is in0 */
    57                 "break 0x80000\n"  /* modifies r8 */
     90                "break 0x80000\n"     /* modifies r8 */
    5891                :
    5992                : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
     
    67100 * display character on debug console.
    68101 *
    69  * @param d Character device.
    70  * @param ch Character to be printed.
    71  */
    72 static void ski_putchar(outdev_t *d, const wchar_t ch, bool silent)
     102 * @param dev    Character device.
     103 * @param ch     Character to be printed.
     104 * @param silent Whether the output should be silenced.
     105 *
     106 */
     107static void ski_putchar(outdev_t *dev, const wchar_t ch, bool silent)
    73108{
    74109        if (!silent) {
     
    79114                        ski_do_putchar(ch);
    80115                } else
    81                         ski_do_putchar(SPECIAL);
     116                        ski_do_putchar(U_SPECIAL);
    82117        }
    83118}
    84119
    85 static indev_operations_t skiin_ops = {
    86         .poll = NULL
    87 };
    88 
    89 static outdev_operations_t skiout_ops = {
    90         .write = ski_putchar
    91 };
     120void skiout_init(void)
     121{
     122        ski_init();
     123       
     124        outdev_initialize("skiout", &skiout, &skiout_ops);
     125        stdout = &skiout;
     126       
     127        sysinfo_set_item_val("fb", NULL, false);
     128}
    92129
    93130/** Ask debug console if a key was pressed.
     
    99136 *
    100137 * @return ASCII code of pressed key or 0 if no key pressed.
    101  */
    102 static int32_t ski_getchar(void)
     138 *
     139 */
     140static wchar_t ski_getchar(void)
    103141{
    104142        uint64_t ch;
     
    106144        asm volatile (
    107145                "mov r15 = %1\n"
    108                 "break 0x80000;;\n"     /* modifies r8 */
    109                 "mov %0 = r8;;\n"               
    110 
     146                "break 0x80000;;\n"  /* modifies r8 */
     147                "mov %0 = r8;;\n"
     148               
    111149                : "=r" (ch)
    112150                : "i" (SKI_GETCHAR)
    113151                : "r15", "r8"
    114152        );
    115 
    116         return (int32_t) ch;
     153       
     154        return (wchar_t) ch;
    117155}
    118156
    119157/** Ask keyboard if a key was pressed. */
    120 static void poll_keyboard(void)
    121 {
    122         char ch;
    123        
     158static void poll_keyboard(ski_instance_t *instance)
     159{
    124160        if (kbd_disabled)
    125161                return;
    126         ch = ski_getchar();
    127         if(ch == '\r')
    128                 ch = '\n';
    129         if (ch) {
    130                 indev_push_character(&skiin, ch);
    131                 return;
    132         }
    133 }
    134 
    135 #define POLL_INTERVAL           10000           /* 10 ms */
     162       
     163        wchar_t ch = ski_getchar();
     164       
     165        if (ch != 0)
     166                indev_push_character(instance->srlnin, ch);
     167}
    136168
    137169/** Kernel thread for polling keyboard. */
    138 static void kkbdpoll(void *arg)
    139 {
    140         while (1) {
    141                 if (!silent) {
    142                         poll_keyboard();
    143                 }
     170static void kskipoll(void *arg)
     171{
     172        ski_instance_t *instance = (ski_instance_t *) arg;
     173       
     174        while (true) {
     175                if (!silent)
     176                        poll_keyboard(instance);
     177               
    144178                thread_usleep(POLL_INTERVAL);
    145179        }
    146180}
    147181
    148 /** Initialize debug console
    149  *
    150  * Issue SSC (Simulator System Call) to
    151  * to open debug console.
    152  */
    153 static void ski_init(void)
    154 {
    155         static bool initialized;
    156 
    157         if (initialized)
    158                 return;
    159        
    160         asm volatile (
    161                 "mov r15 = %0\n"
    162                 "break 0x80000\n"
    163                 :
    164                 : "i" (SKI_INIT_CONSOLE)
    165                 : "r15", "r8"
    166         );
    167        
    168         initialized = true;
    169 }
    170 
    171 indev_t *skiin_init(void)
     182ski_instance_t *skiin_init(void)
    172183{
    173184        ski_init();
    174 
    175         indev_initialize("skiin", &skiin, &skiin_ops);
    176         thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true);
    177         if (t)
    178                 thread_ready(t);
    179         else
    180                 return NULL;
    181 
     185       
     186        ski_instance_t *instance
     187            = malloc(sizeof(ski_instance_t), FRAME_ATOMIC);
     188       
     189        if (instance) {
     190                instance->thread = thread_create(kskipoll, (void *) instance, TASK, 0, "kskipoll", true);
     191               
     192                if (!instance->thread) {
     193                        free(instance);
     194                        return NULL;
     195                }
     196               
     197                instance->srlnin = NULL;
     198        }
     199       
     200        return instance;
     201}
     202
     203void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
     204{
     205        ASSERT(instance);
     206        ASSERT(srlnin);
     207       
     208        instance->srlnin = srlnin;
     209        thread_ready(instance->thread);
     210       
    182211        sysinfo_set_item_val("kbd", NULL, true);
    183212        sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
    184 
    185         return &skiin;
    186 }
    187 
    188 
    189 void skiout_init(void)
    190 {
    191         ski_init();
    192 
    193         outdev_initialize("skiout", &skiout, &skiout_ops);
    194         stdout = &skiout;
    195 
    196         sysinfo_set_item_val("fb", NULL, false);
    197213}
    198214
Note: See TracChangeset for help on using the changeset viewer.