Subversion Repositories HelenOS

Rev

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

Rev 1920 Rev 1921
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (C) 2001-2004 Jakub Jermar
2
 * Copyright (C) 2001-2006 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
Line 50... Line 50...
50
#include <interrupt.h>
50
#include <interrupt.h>
51
#include <sysinfo/sysinfo.h>
51
#include <sysinfo/sysinfo.h>
52
 
52
 
53
#define LSR_DATA_READY  0x01
53
#define LSR_DATA_READY  0x01
54
 
54
 
-
 
55
/** Structure representing the ns16550. */
-
 
56
static ns16550_t ns16550;
-
 
57
 
-
 
58
/** Structure for ns16550's IRQ. */
-
 
59
static irq_t ns16550_irq;
-
 
60
 
55
/*
61
/*
56
 * These codes read from ns16550 data register are silently ignored.
62
 * These codes read from ns16550 data register are silently ignored.
57
 */
63
 */
58
#define IGNORE_CODE 0x7f        /* all keys up */
64
#define IGNORE_CODE 0x7f        /* all keys up */
59
 
65
 
Line 79... Line 85...
79
void ns16550_release(void)
85
void ns16550_release(void)
80
{
86
{
81
    /* TODO */
87
    /* TODO */
82
}
88
}
83
 
89
 
84
/** Initialize ns16550. */
90
/** Initialize ns16550.
-
 
91
 *
-
 
92
 * @param devno Device number.
-
 
93
 * @param inr Interrupt number.
-
 
94
 * @param vaddr Virtual address of device's registers.
-
 
95
 */
85
void ns16550_init(void)
96
void ns16550_init(devno_t devno, inr_t inr, uintptr_t vaddr)
86
{
97
{
87
    ns16550_grab();
98
    ns16550_grab();
88
    chardev_initialize("ns16550_kbd", &kbrd, &ops);
99
    chardev_initialize("ns16550_kbd", &kbrd, &ops);
89
    stdin = &kbrd;
100
    stdin = &kbrd;
90
   
101
   
-
 
102
    ns16550.devno = devno;
-
 
103
    ns16550.reg = (uint8_t *) vaddr;
-
 
104
   
-
 
105
    irq_initialize(&ns16550_irq);
-
 
106
    ns16550_irq.devno = devno;
-
 
107
    ns16550_irq.inr = inr;
-
 
108
    ns16550_irq.claim = ns16550_claim;
-
 
109
    ns16550_irq.handler = ns16550_irq_handler;
-
 
110
    irq_register(&ns16550_irq);
-
 
111
   
91
    sysinfo_set_item_val("kbd", NULL, true);
112
    sysinfo_set_item_val("kbd", NULL, true);
-
 
113
    sysinfo_set_item_val("kbd.devno", NULL, devno);
92
    sysinfo_set_item_val("kbd.irq", NULL, 0);
114
    sysinfo_set_item_val("kbd.inr", NULL, inr);
93
    sysinfo_set_item_val("kbd.address.virtual", NULL, (uintptr_t) kbd_virt_address);
115
    sysinfo_set_item_val("kbd.address.virtual", NULL, vaddr);
94
   
116
   
95
    ns16550_ier_write(IER_ERBFI);               /* enable receiver interrupt */
117
    ns16550_ier_write(&ns16550, IER_ERBFI);     /* enable receiver interrupt */
96
   
118
   
97
    while (ns16550_lsr_read() & LSR_DATA_READY)
119
    while (ns16550_lsr_read(&ns16550) & LSR_DATA_READY)
98
        (void) ns16550_rbr_read();
120
        (void) ns16550_rbr_read(&ns16550);
99
}
121
}
100
 
122
 
101
/** Process ns16550 interrupt.
123
/** Process ns16550 interrupt.
102
 *
124
 *
103
 * @param n Interrupt vector.
125
 * @param n Interrupt vector.
Line 127... Line 149...
127
{
149
{
128
    char ch;   
150
    char ch;   
129
 
151
 
130
    while(!(ch = active_read_buff_read())) {
152
    while(!(ch = active_read_buff_read())) {
131
        uint8_t x;
153
        uint8_t x;
132
        while (!(ns16550_lsr_read() & LSR_DATA_READY))
154
        while (!(ns16550_lsr_read(&ns16550) & LSR_DATA_READY))
133
            ;
155
            ;
134
        x = ns16550_rbr_read();
156
        x = ns16550_rbr_read(&ns16550);
135
        if (x != IGNORE_CODE) {
157
        if (x != IGNORE_CODE) {
136
            if (x & KEY_RELEASE)
158
            if (x & KEY_RELEASE)
137
                key_released(x ^ KEY_RELEASE);
159
                key_released(x ^ KEY_RELEASE);
138
            else
160
            else
139
                active_read_key_pressed(x);
161
                active_read_key_pressed(x);
Line 148... Line 170...
148
 */
170
 */
149
void ns16550_poll(void)
171
void ns16550_poll(void)
150
{
172
{
151
    uint8_t x;
173
    uint8_t x;
152
 
174
 
153
    while (ns16550_lsr_read() & LSR_DATA_READY) {
175
    while (ns16550_lsr_read(&ns16550) & LSR_DATA_READY) {
154
        x = ns16550_rbr_read();
176
        x = ns16550_rbr_read(&ns16550);
155
        if (x != IGNORE_CODE) {
177
        if (x != IGNORE_CODE) {
156
            if (x & KEY_RELEASE)
178
            if (x & KEY_RELEASE)
157
                key_released(x ^ KEY_RELEASE);
179
                key_released(x ^ KEY_RELEASE);
158
            else
180
            else
159
                key_pressed(x);
181
                key_pressed(x);