Subversion Repositories HelenOS

Rev

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

Rev 4343 Rev 4346
Line 34... Line 34...
34
 * @brief   SGCN (Serengeti Console) keyboard port driver.
34
 * @brief   SGCN (Serengeti Console) keyboard port driver.
35
 */
35
 */
36
 
36
 
37
#include <as.h>
37
#include <as.h>
38
#include <ddi.h>
38
#include <ddi.h>
39
#include <ipc/ipc.h>
-
 
40
#include <async.h>
39
#include <async.h>
41
#include <kbd.h>
40
#include <kbd.h>
42
#include <kbd_port.h>
41
#include <kbd_port.h>
43
#include <sysinfo.h>
42
#include <sysinfo.h>
44
#include <stdio.h>
43
#include <stdio.h>
-
 
44
#include <thread.h>
-
 
45
 
-
 
46
#define POLL_INTERVAL       10000
45
 
47
 
46
/**
48
/**
47
 * SGCN buffer header. It is placed at the very beginning of the SGCN
49
 * SGCN buffer header. It is placed at the very beginning of the SGCN
48
 * buffer.
50
 * buffer.
49
 */
51
 */
Line 85... Line 87...
85
/**
87
/**
86
 * SGCN buffer offset within SGCN.
88
 * SGCN buffer offset within SGCN.
87
 */
89
 */
88
static uintptr_t sram_buffer_offset;
90
static uintptr_t sram_buffer_offset;
89
 
91
 
-
 
92
/* polling thread */
90
static void sgcn_irq_handler(ipc_callid_t iid, ipc_call_t *call);
93
static void *sgcn_thread_impl(void *arg);
91
 
94
 
92
 
95
 
93
/**
96
/**
94
 * Initializes the SGCN driver.
97
 * Initializes the SGCN driver.
95
 * Maps the physical memory (SRAM) and registers the interrupt.
98
 * Maps the physical memory (SRAM) and creates the polling thread.
96
 */
99
 */
97
int kbd_port_init(void)
100
int kbd_port_init(void)
98
{
101
{
99
    async_set_interrupt_received(sgcn_irq_handler);
-
 
100
    sram_virt_addr = (uintptr_t) as_get_mappable_page(sysinfo_value("sram.area.size"));
102
    sram_virt_addr = (uintptr_t) as_get_mappable_page(sysinfo_value("sram.area.size"));
101
    if (physmem_map((void *) sysinfo_value("sram.address.physical"),
103
    if (physmem_map((void *) sysinfo_value("sram.address.physical"),
102
        (void *) sram_virt_addr, sysinfo_value("sram.area.size") / PAGE_SIZE,
104
        (void *) sram_virt_addr, sysinfo_value("sram.area.size") / PAGE_SIZE,
103
        AS_AREA_READ | AS_AREA_WRITE) != 0) {
105
        AS_AREA_READ | AS_AREA_WRITE) != 0) {
104
        printf("SGCN: uspace driver could not map physical memory.");
106
        printf("SGCN: uspace driver could not map physical memory.");
105
        return -1;
107
        return -1;
106
    }
108
    }
107
   
109
   
108
    sram_buffer_offset = sysinfo_value("sram.buffer.offset");
110
    sram_buffer_offset = sysinfo_value("sram.buffer.offset");
-
 
111
 
-
 
112
    thread_id_t tid;
-
 
113
    int rc;
-
 
114
 
109
    ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"),
115
    rc = thread_create(sgcn_thread_impl, NULL, "kbd_poll", &tid);
110
        0, (void *) 0);
116
    if (rc != 0) {
-
 
117
        return rc;
-
 
118
    }
-
 
119
 
111
    return 0;
120
    return 0;
112
}
121
}
113
 
122
 
114
/**
123
/**
115
 * Handler of the "key pressed" event. Reads codes of all the pressed keys from
124
 * Handler of the "key pressed" event. Reads codes of all the pressed keys from
116
 * the buffer.
125
 * the buffer.
117
 */
126
 */
118
static void sgcn_irq_handler(ipc_callid_t iid, ipc_call_t *call)
127
static void sgcn_key_pressed(void)
119
{
128
{
120
    char c;
129
    char c;
121
   
130
   
122
    uint32_t begin = SGCN_BUFFER_HEADER->in_begin;
131
    uint32_t begin = SGCN_BUFFER_HEADER->in_begin;
123
    uint32_t end = SGCN_BUFFER_HEADER->in_end;
132
    uint32_t end = SGCN_BUFFER_HEADER->in_end;
Line 135... Line 144...
135
            SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
144
            SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
136
        kbd_push_scancode(c);
145
        kbd_push_scancode(c);
137
    }
146
    }
138
}
147
}
139
 
148
 
-
 
149
/**
-
 
150
 * Thread to poll SGCN for keypresses.
-
 
151
 */
-
 
152
static void *sgcn_thread_impl(void *arg)
-
 
153
{
-
 
154
    (void) arg;
-
 
155
 
-
 
156
    while (1) {
-
 
157
        sgcn_key_pressed();
-
 
158
        usleep(POLL_INTERVAL);
-
 
159
    }
-
 
160
}
-
 
161
 
-
 
162
 
140
/** @}
163
/** @}
141
 */
164
 */