Project

General

Profile

Statistics
| Revision:

root / lab3 / lab3.c @ 9

History | View | Annotate | Download (3.04 KB)

1
#include <lcom/lcf.h>
2

    
3
#include <lcom/lab3.h>
4

    
5
#include <stdbool.h>
6
#include <stdint.h>
7
#include "keyboard.h"
8
int main(int argc, char *argv[]) {
9
  // sets the language of LCF messages (can be either EN-US or PT-PT)
10
  lcf_set_language("EN-US");
11

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

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

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

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

    
29
  return 0;
30
}
31

    
32
extern uint8_t scan_reg;
33

    
34
int(kbd_test_scan)() {
35
  int r, ipc_status;
36
  uint8_t keyboard_irq, size, byte[2]; //size of scancode can be 2 byte long
37
  message msg;
38
  bool make=false; //to check if code is make or break
39

    
40
  if(kbc_subscribe_int(keyboard_irq)==1){
41
    printf("Error subscribing int\n");
42
    return 1;
43
  }
44

    
45
  while(scan_code!=ESC_BREAK){      //looping until status_reg is the breakcode of ESC key
46
    if ((r = driver_receive(ANY, &msg, &ipc_status))==1){ 
47
      printf("driver_receive failed with: %d",r);
48
      continue;
49
    }
50
    if (is_ipc_notify(ipc_status)){                             //received notification
51
      switch (_ENDPOINT_P(msg.m_source)){
52
        case HARDWARE:                                          //hardware interrupt notification                                
53
                if (msg.m_notify.interrupts &keyboard_irq){          // subscribed interrupt
54
                  
55
                  kbc_ih();
56
                  bytes[0]=scan_code;
57
                  bytes[1]=scan_code;
58

    
59
                  if(bytes[0]==TWO_BYTE_SCANCODE){
60
                    size=2;
61
                  }
62
                  else{
63
                    size=1;
64
                  }
65

    
66
                  if (scan_code & MAKE_CODE){        // 4 - Checks if code is make or break
67
                      make = false;        //break code
68
                    }
69
                  else {
70
                    make = true;  //make code
71
                  }
72
                  kbd_print_scancode(make, size, bytes); //prints the code
73
                      }
74
               break;
75
        default:
76
              break;                                            //no other notifications expected: do nothing        
77
        }
78
    } 
79
    else {                                                      //received a standard message, not a notification
80
      //no standard messages expected: do nothing
81
    }
82
  }
83

    
84
   if (kbc_unsubscribe_int() != 0) { // Check if subscription worked
85
                printf("Error unsubscribing int \n");
86
                return 1;
87
        }
88

    
89
  return 0;
90
}
91

    
92
int(kbd_test_poll)() {
93
  /* To be completed by the students */
94
  printf("%s is not yet implemented!\n", __func__);
95

    
96
  return 1;
97
}
98

    
99
int(kbd_test_timed_scan)(uint8_t n) {
100
  /* To be completed by the students */
101
  printf("%s is not yet implemented!\n", __func__);
102

    
103
  return 1;
104
}