Project

General

Profile

Statistics
| Revision:

root / lab3 / lab3.c @ 38

History | View | Annotate | Download (3.28 KB)

1
#include <lcom/lcf.h>
2
#include <lcom/lab3.h>
3

    
4
#include <stdbool.h>
5
#include <stdint.h>
6

    
7
#include "kbc.h"
8
#include "kbc_func.h"
9

    
10
int main(int argc, char *argv[]) {
11
  // sets the language of LCF messages (can be either EN-US or PT-PT)
12
  lcf_set_language("EN-US");
13

    
14
  // enables to log function invocations that are being "wrapped" by LCF
15
  // [comment this out if you don't want/need it]
16
  lcf_trace_calls("/home/lcom/labs/lab3/trace.txt");
17

    
18
  // enables to save the output of printf function calls on a file
19
  // [comment this out if you don't want/need it]
20
  lcf_log_output("/home/lcom/labs/lab3/output.txt");
21

    
22
  // handles control over to LCF
23
  // [LCF handles command line arguments and invokes the right function]
24
  if (lcf_start(argc, argv))
25
    return 1;
26

    
27
  // LCF clean up tasks
28
  // [must be the last statement before return]
29
  lcf_cleanup();
30

    
31
  return 0;
32
}
33

    
34
extern uint8_t scancode[2];
35
extern int two_byte_scancode;
36
extern int got_error;
37

    
38
int(kbd_test_scan)() {
39

    
40
    int ipc_status, r;
41
    message msg;
42

    
43
    uint8_t kbc_irq_bit = 1;
44
    int kbc_id = 0;
45
    int kbc_irq = BIT(kbc_irq_bit);
46

    
47
    int got_esc_breakcode = 0;
48

    
49
    if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) return 1;
50

    
51
    while (!got_esc_breakcode) {
52
        /* Get a request message. */
53
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
54
            printf("driver_receive failed with %d", r);
55
            continue;
56
        }
57
        if (is_ipc_notify(ipc_status)) { /* received notification */
58
            switch (_ENDPOINT_P(msg.m_source)) {
59
                case HARDWARE: /* hardware interrupt notification */
60
                    if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */
61

    
62
                        kbc_ih();
63

    
64
                        if (!(two_byte_scancode || got_error)) { /* finished processing a scancode */
65
                            if (scancode[0] == TWO_BYTE_CODE)
66
                                kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode);
67
                            else
68
                                kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
69
                        } else {
70
                            break;
71
                        }
72

    
73
                        if (scancode[0] == ESC_BREAK_CODE)
74
                            got_esc_breakcode = 1;
75

    
76
                    }
77
                    break;
78
                default:
79
                    break; /* no other notifications expected: do nothing */
80
            }
81
        } else { /* received standart message, not a notification */
82
            /* no standart message expected: do nothing */
83
        }
84
    }
85

    
86
    if (unsubscribe_kbc_interrupt(&kbc_id)) return 1;
87

    
88
    if (kbd_print_no_sysinb(sys_inb_counter(GET))) return 1;
89

    
90
    return 0;
91
}
92

    
93
int(kbd_test_poll)() {
94
    uint8_t c[2]; uint8_t size;
95
    do{
96
        if(kbd_poll(c, &size)) return 1;
97
        if(kbd_print_scancode((~c[0])&BREAK_CODE_BIT, size, c)) return 1;
98
    }while(!(size == 1 && c[0] == ESC_BREAK_CODE));
99

    
100
    uint8_t cmd = 0;
101
    if(kbd_read_cmd(&cmd)) return 1;
102
    printf("%x\n", cmd);
103

    
104
    return 0;
105
}
106

    
107
int(kbd_test_timed_scan)(uint8_t n) {
108
  /* To be completed by the students */
109
  printf("%s is not yet implemented!\n", __func__);
110

    
111
  return 1;
112
}