Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "keyboard.h"
- uint8_t scan_code=0; // make code or break code
- int keyboard_id = KEYBOARD_IRQ; // KEYBOARD_IRQ is defined in interrupt.h in .minix-src folder
- uint32_t cnt = 0; // counter of sys_inb calls
- int (util_sys_inb)(int port, uint8_t *value) { //transform 8 bit into 32 bit
- uint32_t new_val; //initializing 32 bit variable
- if(sys_inb(port,&new_val)!=0){ //verifies if there is an error
- printf("Error in util_sys_inb\n");
- return 1;
- }
- *value=new_val & 0xFF; //dereferencing "value"
- #ifdef LAB3
- cnt++;
- #endif
- return 0;
- }
- void (kbc_ih)(void){
- uint8_t status_reg;
- if(util_sys_inb(STATUS_REG,&status_reg)!=0){ //checks if there is an error
- return;
- }
- if(((status_reg & STAT_REG_OBF)==0) ||((status_reg&(STAT_REG_PAR|STAT_REG_TIMEOUT))!=0)|| ((status_reg&STAT_REG_AUX)!=0)){ //checks if there is a parity or timeout error (mask -> 0xC0, bit 7 and 6 set), checks if output buffer is empty and checks if there is data coming from the mouse
- return;
- }
- util_sys_inb(OUTPUT_BUF,&scan_code);
- }
- int (kbc_subscribe_int)(uint8_t *bit_no) { //similar function to that of timer_subscribe_int
- *bit_no = BIT(keyboard_id);
- if(sys_irqsetpolicy(KEYBOARD_IRQ,(IRQ_REENABLE|IRQ_EXCLUSIVE),&keyboard_id)==1){ //operation to subscribe int
- printf("Error subscribing int\n");
- return 1;
- }
- return 0;
- }
- int (kbc_unsubscribe_int)() { //similar function to that of timer_unsubscribe_int
- if(sys_irqrmpolicy(&keyboard_id)==1){
- printf("Error unsubscribing int\n");
- return 1;
- }
- return 0;
- }
- int (enable_interrupt)()
- {
- uint8_t command;
- if(sys_outb(STATUS_REG,READ_COMMAND)!=0){
- printf("Error writing read-command\n");
- return 1;
- }
- if(util_sys_inb(OUTPUT_BUF, &command)!=0){
- printf("Error reading output buffer\n");
- return 1;
- }
- command = command | INT_ENABLE;
- if(sys_outb(STATUS_REG,OUTPUT_BUF)!=0){
- printf("Error writing output buffer\n");
- return 1;
- }
- if(sys_outb(OUTPUT_BUF,command)!=0){
- printf("Error writing new buffer status\n");
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement