Project

General

Profile

Statistics
| Revision:

root / lab3 / keyboard.c @ 9

History | View | Annotate | Download (1.64 KB)

1
#include <lcom/lcf.h>
2

    
3
#include <lcom/lab3.h>
4

    
5
#include <stdbool.h>
6
#include <stdint.h>
7
#include "i8042.h"
8

    
9

    
10
u8int_t scan_code=0;            // make code or break code
11
int keyboard_id = KEYBOARD_IRQ;         // KEYBOARD_IRQ is defined in interrupt.h in .minix-src folder
12
uint32_t cnt = 0;                                                                        // counter of sys_inb calls
13
                                        
14
int (util_sys_inb)(int port, uint8_t *value) { //transform 8 bit into 32 bit
15

    
16
  uint32_t new_val;                           //initializing 32 bit variable
17

    
18
  if(sys_inb(port,&new_val)!=0){              //verifies if there is an error
19
      printf("Error in util_sys_inb\n");
20
      return 1;
21
  }
22
  *value=new_val & 0xFF;                      //dereferencing "value"
23
  #ifdef LAB3
24
  cnt++;
25
  #endif
26
  
27

    
28
  return 0;
29
}
30

    
31
void (kbc_ih)(void){
32
  u8int_t status_reg;
33

    
34
  if(util_sys_inb(STATUS_REG,status_reg)!=0){ //checks if there is an error
35
    return;
36
  }
37
  if(((status_reg & STAT_REG_OBF)==0) ||((status_reg&(STAT_REG_PAR|STAT_REG_TIMEOUT))!=0)){ //checks if there is a parity or timeout error (mask -> 0xC0, bit 7 and 6 set) and checks if output buffer is empty
38
    return;
39
  }
40
  util_sys_inb(OUTPUT_BUF,status_code);
41

    
42
}
43

    
44
int (kbc_subscribe_int)(uint8_t *bit_no) {    //similar function to that of timer_subscribe_int
45
    *bit_no = BIT(keyboard_id);
46
    if(sys_irqsetpolicy(KEYBOARD_IRQ,(IRQ_REENABLE|IRQ_EXCLUSIVE),&keyboard_id)==1){      //operation to subscribe int
47
        printf("Error subscribing int\n");
48
        return 1;
49
    }
50
  return 0;
51
}
52

    
53
int (kbc_unsubscribe_int)() {           //similar function to that of timer_unsubscribe_int
54
  if(sys_irqrmpolicy(&keyboard_id)==1){
55
      printf("Error unsubscribing int\n");
56
      return 1;
57
  }
58
  return 0;
59
}