Project

General

Profile

Statistics
| Revision:

root / lab3 / keyboard.c @ 10

History | View | Annotate | Download (1.56 KB)

1 10 up20180645
#include "keyboard.h"
2 9 up20180645
3 10 up20180645
uint8_t scan_code=0;            // make code or break code
4 9 up20180645
int keyboard_id = KEYBOARD_IRQ;         // KEYBOARD_IRQ is defined in interrupt.h in .minix-src folder
5
uint32_t cnt = 0;                                                                        // counter of sys_inb calls
6
7
int (util_sys_inb)(int port, uint8_t *value) { //transform 8 bit into 32 bit
8
9
  uint32_t new_val;                           //initializing 32 bit variable
10
11
  if(sys_inb(port,&new_val)!=0){              //verifies if there is an error
12
      printf("Error in util_sys_inb\n");
13
      return 1;
14
  }
15
  *value=new_val & 0xFF;                      //dereferencing "value"
16
  #ifdef LAB3
17
  cnt++;
18
  #endif
19
20
  return 0;
21
}
22
23
void (kbc_ih)(void){
24 10 up20180645
  uint8_t status_reg;
25 9 up20180645
26 10 up20180645
  if(util_sys_inb(STATUS_REG,&status_reg)!=0){ //checks if there is an error
27 9 up20180645
    return;
28
  }
29
  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
30
    return;
31
  }
32 10 up20180645
  util_sys_inb(OUTPUT_BUF,&scan_code);
33 9 up20180645
34
}
35
36
int (kbc_subscribe_int)(uint8_t *bit_no) {    //similar function to that of timer_subscribe_int
37
    *bit_no = BIT(keyboard_id);
38
    if(sys_irqsetpolicy(KEYBOARD_IRQ,(IRQ_REENABLE|IRQ_EXCLUSIVE),&keyboard_id)==1){      //operation to subscribe int
39
        printf("Error subscribing int\n");
40
        return 1;
41
    }
42
  return 0;
43
}
44
45
int (kbc_unsubscribe_int)() {           //similar function to that of timer_unsubscribe_int
46
  if(sys_irqrmpolicy(&keyboard_id)==1){
47
      printf("Error unsubscribing int\n");
48
      return 1;
49
  }
50
  return 0;
51
}