Subversion Repositories HelenOS

Rev

Rev 4296 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4296 Rev 4420
Line 99... Line 99...
99
    ((type *) (sgcn_buffer_begin + (offset)))
99
    ((type *) (sgcn_buffer_begin + (offset)))
100
 
100
 
101
/** Returns a pointer to the console buffer header. */
101
/** Returns a pointer to the console buffer header. */
102
#define SGCN_BUFFER_HEADER  (SGCN_BUFFER(sgcn_buffer_header_t, 0))
102
#define SGCN_BUFFER_HEADER  (SGCN_BUFFER(sgcn_buffer_header_t, 0))
103
 
103
 
104
/** defined in drivers/kbd.c */
-
 
105
extern kbd_type_t kbd_type;
-
 
106
 
-
 
107
/** starting address of SRAM, will be set by the init_sram_begin function */
104
/** starting address of SRAM, will be set by the init_sram_begin function */
108
static uintptr_t sram_begin;
105
static uintptr_t sram_begin;
109
 
106
 
110
/**
107
/**
111
 * starting address of the SGCN buffer, will be set by the
108
 * starting address of the SGCN buffer, will be set by the
Line 135... Line 132...
135
/** SGCN output device operations */
132
/** SGCN output device operations */
136
static outdev_operations_t sgcnout_ops = {
133
static outdev_operations_t sgcnout_ops = {
137
    .write = sgcn_putchar
134
    .write = sgcn_putchar
138
};
135
};
139
 
136
 
140
/** SGCN input device operations */
-
 
141
static indev_operations_t sgcnin_ops = {
-
 
142
    .poll = NULL
-
 
143
};
-
 
144
 
-
 
145
static indev_t sgcnin;      /**< SGCN input device. */
-
 
146
static outdev_t sgcnout;    /**< SGCN output device. */
137
static outdev_t sgcnout;    /**< SGCN output device. */
147
 
138
 
148
/**
139
/**
149
 * Set some sysinfo values (SRAM address and SRAM size).
140
 * Set some sysinfo values (SRAM address and SRAM size).
150
 */
141
 */
Line 286... Line 277...
286
/**
277
/**
287
 * Grabs the input for kernel.
278
 * Grabs the input for kernel.
288
 */
279
 */
289
void sgcn_grab(void)
280
void sgcn_grab(void)
290
{
281
{
291
    kbd_disabled = true;
282
    kbd_disabled = false;
292
}
283
}
293
 
284
 
294
/**
285
/**
295
 * Releases the input so that userspace can use it.
286
 * Releases the input so that userspace can use it.
296
 */
287
 */
Line 302... Line 293...
302
/**
293
/**
303
 * Function regularly called by the keyboard polling thread. Finds out whether
294
 * Function regularly called by the keyboard polling thread. Finds out whether
304
 * there are some unread characters in the input queue. If so, it picks them up
295
 * there are some unread characters in the input queue. If so, it picks them up
305
 * and sends them to the upper layers of HelenOS.
296
 * and sends them to the upper layers of HelenOS.
306
 */
297
 */
307
static void sgcn_poll()
298
static void sgcn_poll(sgcn_instance_t *instance)
308
{
299
{
309
    uint32_t begin = SGCN_BUFFER_HEADER->in_begin;
300
    uint32_t begin = SGCN_BUFFER_HEADER->in_begin;
310
    uint32_t end = SGCN_BUFFER_HEADER->in_end;
301
    uint32_t end = SGCN_BUFFER_HEADER->in_end;
311
    uint32_t size = end - begin;
302
    uint32_t size = end - begin;
312
 
303
 
Line 320... Line 311...
320
        SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
311
        SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
321
    volatile uint32_t *in_wrptr_ptr = &(SGCN_BUFFER_HEADER->in_wrptr);
312
    volatile uint32_t *in_wrptr_ptr = &(SGCN_BUFFER_HEADER->in_wrptr);
322
    volatile uint32_t *in_rdptr_ptr = &(SGCN_BUFFER_HEADER->in_rdptr);
313
    volatile uint32_t *in_rdptr_ptr = &(SGCN_BUFFER_HEADER->in_rdptr);
323
   
314
   
324
    while (*in_rdptr_ptr != *in_wrptr_ptr) {
315
    while (*in_rdptr_ptr != *in_wrptr_ptr) {
325
       
-
 
326
        buf_ptr = (volatile char *)
316
        buf_ptr = (volatile char *)
327
            SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
317
            SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
328
        char c = *buf_ptr;
318
        char c = *buf_ptr;
329
        *in_rdptr_ptr = (((*in_rdptr_ptr) - begin + 1) % size) + begin;
319
        *in_rdptr_ptr = (((*in_rdptr_ptr) - begin + 1) % size) + begin;
330
           
320
           
331
        indev_push_character(&sgcnin, c);  
321
        indev_push_character(instance->srlnin, c); 
332
    }  
322
    }  
333
 
323
 
334
    spinlock_unlock(&sgcn_input_lock);
324
    spinlock_unlock(&sgcn_input_lock);
335
}
325
}
336
 
326
 
337
/**
327
/**
338
 * Polling thread function.
328
 * Polling thread function.
339
 */
329
 */
340
static void kkbdpoll(void *arg) {
330
static void ksgcnpoll(void *instance) {
341
    while (1) {
331
    while (1) {
342
        if (!silent) {
332
        if (!silent)
343
            sgcn_poll();
333
            sgcn_poll(instance);
344
        }
-
 
345
        thread_usleep(POLL_INTERVAL);
334
        thread_usleep(POLL_INTERVAL);
346
    }
335
    }
347
}
336
}
348
 
337
 
349
/**
338
/**
350
 * A public function which initializes input from the Serengeti console.
339
 * A public function which initializes input from the Serengeti console.
351
 */
340
 */
352
indev_t *sgcnin_init(void)
341
sgcn_instance_t *sgcnin_init(void)
353
{
342
{
354
    sgcn_buffer_begin_init();
343
    sgcn_buffer_begin_init();
-
 
344
   
-
 
345
    sgcn_instance_t *instance =
-
 
346
        malloc(sizeof(sgcn_instance_t), FRAME_ATOMIC);
-
 
347
   
-
 
348
    if (instance) {
-
 
349
        instance->srlnin = NULL;
-
 
350
        instance->thread = thread_create(ksgcnpoll, instance, TASK, 0,
-
 
351
            "ksgcnpoll", true);
-
 
352
       
-
 
353
        if (!instance->thread) {
-
 
354
            free(instance);
-
 
355
            return NULL;
-
 
356
        }
-
 
357
    }
-
 
358
   
-
 
359
    return instance;
-
 
360
}
355
 
361
 
356
    kbd_type = KBD_SGCN;
362
void sgcnin_wire(sgcn_instance_t *instance, indev_t *srlnin)
357
 
363
{
358
    sysinfo_set_item_val("kbd", NULL, true);
364
    ASSERT(instance);
359
    sysinfo_set_item_val("kbd.type", NULL, KBD_SGCN);
365
    ASSERT(srlnin);
360
 
366
 
361
    thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true);
-
 
362
    if (!t)
-
 
363
        panic("Cannot create kkbdpoll.");
367
    instance->srlnin = srlnin;
364
    thread_ready(t);
368
    thread_ready(instance->thread);
365
   
-
 
366
    indev_initialize("sgcnin", &sgcnin, &sgcnin_ops);
-
 
367
 
369
 
368
    return &sgcnin;
370
    sysinfo_set_item_val("kbd", NULL, true);
369
}
371
}
370
 
372
 
371
/**
373
/**
372
 * A public function which initializes output to the Serengeti console.
374
 * A public function which initializes output to the Serengeti console.
373
 */
375
 */