Project

General

Profile

Revision 10

Working function kbc_test_scan()

View differences:

lab3/i8042.h
9 9
 * Constants for programming the i8042 Keyboard.
10 10
 */
11 11

  
12
#define KEYBOARD_IRQ 0x09 /* Keyboard IRQ address */
12
//#define KEYBOARD_IRQ 0x09 /* Keyboard IRQ address */
13 13

  
14
#define BIT(n) (0x01<<(n))
14
//#define BIT(n) (0x01<<(n))
15 15

  
16 16
#define DELAY_US        20000
17 17

  
lab3/keyboard.c
1
#include <lcom/lcf.h>
1
#include "keyboard.h"
2 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
3
uint8_t scan_code=0;            // make code or break code
11 4
int keyboard_id = KEYBOARD_IRQ; 	// KEYBOARD_IRQ is defined in interrupt.h in .minix-src folder
12 5
uint32_t cnt = 0;									// counter of sys_inb calls
13 6
					
......
24 17
  cnt++;
25 18
  #endif
26 19
  
27

  
28 20
  return 0;
29 21
}
30 22

  
31 23
void (kbc_ih)(void){
32
  u8int_t status_reg;
24
  uint8_t status_reg;
33 25

  
34
  if(util_sys_inb(STATUS_REG,status_reg)!=0){ //checks if there is an error
26
  if(util_sys_inb(STATUS_REG,&status_reg)!=0){ //checks if there is an error
35 27
    return;
36 28
  }
37 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
38 30
    return;
39 31
  }
40
  util_sys_inb(OUTPUT_BUF,status_code);
32
  util_sys_inb(OUTPUT_BUF,&scan_code);
41 33

  
42 34
}
43 35

  
lab3/keyboard.h
1
#include <lcom/lcf.h>
1
#ifndef _KEYBOARD_H
2
#define _KEYBOARD_H
2 3

  
3
#include <lcom/lab3.h>
4 4

  
5
#include <lcom/lcf.h>
5 6
#include <stdbool.h>
6 7
#include <stdint.h>
8

  
9
#include "i8042.h"
7 10
/**
8 11
* @brief Handles keyboard interrupts (C implementation)
9 12
*
......
37 40
 *
38 41
 * @return Return 0 upon success and non-zero otherwise
39 42
 */
40
int(kbc_unsubscribe_int)();
43
int(kbc_unsubscribe_int)();
44

  
45
#endif /*_KEYBOARD_H */
lab3/lab3.c
1

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

  
3 3
#include <lcom/lab3.h>
4

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

  
7 7
#include "keyboard.h"
8

  
9

  
8 10
int main(int argc, char *argv[]) {
9 11
  // sets the language of LCF messages (can be either EN-US or PT-PT)
10 12
  lcf_set_language("EN-US");
......
29 31
  return 0;
30 32
}
31 33

  
32
extern uint8_t scan_reg;
34
extern uint8_t scan_code;
35
extern uint32_t cnt;
33 36

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

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

  
45
  while(scan_code!=ESC_BREAK){      //looping until status_reg is the breakcode of ESC key
48
  while(scan_code!=ESC_BREAK){      //looping until scann_code is the breakcode of ESC key
46 49
    if ((r = driver_receive(ANY, &msg, &ipc_status))==1){ 
47 50
      printf("driver_receive failed with: %d",r);
48 51
      continue;
......
63 66
                    size=1;
64 67
                  }
65 68

  
66
                  if (scan_code & MAKE_CODE){	// 4 - Checks if code is make or break
69
                  if (scan_code & MAKE_CODE){	//checks if code is make or break
67 70
                      make = false;	//break code
68 71
                    }
69 72
                  else {
......
86 89
		return 1;
87 90
	}
88 91

  
92
  kbd_print_no_sysinb(cnt);
93

  
89 94
  return 0;
90 95
}
91 96

  

Also available in: Unified diff