Project

General

Profile

Statistics
| Revision:

root / lab3 / lab3.c @ 4

History | View | Annotate | Download (2.79 KB)

1 4 up20180614
#include <lcom/lcf.h>
2
#include <minix/sysutil.h>
3
4
#include <lcom/lab3.h>
5
6
#include <stdbool.h>
7
#include <stdint.h>
8
//#include <timer.c>
9
10
#define IRQ_KB 1
11
#define DELAY_US 20000
12
#define EXIT_CODE 0x81
13
#define I_O_BUFFER 0x60
14
15
static uint32_t scancode;
16
17
int main(int argc, char *argv[]) {
18
  // sets the language of LCF messages (can be either EN-US or PT-PT)
19
  lcf_set_language("EN-US");
20
21
  // enables to log function invocations that are being "wrapped" by LCF
22
  // [comment this out if you don't want/need it]
23
  lcf_trace_calls("/home/lcom/labs/lab3/trace.txt");
24
25
  // enables to save the output of printf function calls on a file
26
  // [comment this out if you don't want/need it]
27
  lcf_log_output("/home/lcom/labs/lab3/output.txt");
28
29
  // handles control over to LCF
30
  // [LCF handles command line arguments and invokes the right function]
31
  if (lcf_start(argc, argv))
32
    return 1;
33
34
  // LCF clean up tasks
35
  // [must be the last statement before return]
36
  lcf_cleanup();
37
38
  return 0;
39
}
40
41
void (kbc_ih)()
42
{
43
  sys_inb(I_O_BUFFER, &scancode);
44
}
45
46
int(kbd_test_scan)() {
47
  /* To be completed by the students */
48
  int ipc_status;
49
  uint8_t r, bit_no=0;
50
  message msg;
51
  int hook_id=bit_no;
52
  uint8_t scan_arr[2] = {0,0};
53
  scan_arr[0]=scancode & 0xFF;
54
  scan_arr[1]=scancode & 0xFF00;
55
  sys_irqsetpolicy(IRQ_KB,IRQ_REENABLE|IRQ_EXCLUSIVE,&hook_id);
56
57
  //kbc_ih();
58
  printf("%x\n",scancode);
59
   while( 1)//(scancode & 0xFF) != EXIT_CODE )
60
 { /* You may want to use a different condition */
61
     /* Get a request message. */
62
     // printf("1\n");
63
     //printf("cont:%d, time:%d\n\n",cont/60,time);
64
     if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 )
65
     {
66
        printf("driver_receive failed with: %d", r);
67
       continue;
68
    }
69
    if (is_ipc_notify(ipc_status)) { /* received notification */
70
        switch (_ENDPOINT_P(msg.m_source)) {
71
            case HARDWARE: /* hardware interrupt notification */
72
                if (msg.m_notify.interrupts  & BIT(0)) { /* subscribed interrupt */
73
74
                   kbd_print_scancode((scancode & 0xFF & 0x80),2,scan_arr );
75
               }
76
                //printf("msg:%x\n",msg.m_notify.interrupts);
77
                break;
78
            default:
79
                //printf("2\n");
80
                break; /* no other notifications expected: do nothing */
81
        }
82
    } else {
83
     // printf("3\n"); /* received a standard message, not a notification */
84
        /* no standard messages expected: do nothing */
85
    }
86
 }
87
 if(timer_unsubscribe_int()!=0) return 1;
88
sys_irqrmpolicy(&hook_id);
89
90
91
  return 0;
92
}
93
94
int(kbd_test_poll)() {
95
  /* To be completed by the students */
96
  printf("%s is not yet implemented!\n", __func__);
97
98
  return 1;
99
}
100
101
int(kbd_test_timed_scan)(uint8_t n) {
102
  /* To be completed by the students */
103
  printf("%s is not yet implemented!\n", __func__);
104
105
  return 1;
106
}