Page 1 of 1

Limit keyboard interrupts

Posted: Sun Dec 09, 2012 5:00 pm
by fabiosilva
Greets,

I'm developing a project (Minix 3) which uses keyboard, and I need to make my own interrupt handler.

What I did was :

- Disable default interrupt handler :

Code: Select all

sys_irqsetpolicy(KB_IRQ, (IRQ_REENABLE | IRQ_EXCLUSIVE), &hook);
sys_irqenable(&hook);
- Make my own (reads the scancode) :

Code: Select all

    

unsigned long state, data;
int c = 0;



    while(c<2){ //Waits 100 ms for input

    	sys_inb(STAT_REG, &state); //Check 0x64



	if (CHECK_BIT(state,0)) { //bit 0 set -> buffer ready for reading
		if (CHECK_BIT(state,5)) 
			return -1;
		else
			sys_inb(DATA_REG, &data);

		if (!CHECK_BIT(state,6) && !CHECK_BIT(state,7)) // if no errors, return the code

				return data;
		else if (data == 0xFE)
			return data;
		else if (data == 0xFC)
			return data;
		else
			return -1;
	} 

	usleep(50000);
	c++;


    }
Then I tested :

Code: Select all



int ipc_state;  
message msg;
int irq_set = subscribe_int(); // The function with those two lines above



	        while (i) {
	        	printf("waiting for key\n");



	                if (driver_receive(ANY, &msg, &ipc_state) != 0) {

	                       printf("driver reception failed\n");

	                        continue;

	              }

	                if (is_ipc_notify(ipc_state)) {


	                        switch (_ENDPOINT_P(msg.m_source)) {

	                        case HARDWARE:

	                                if (CHECK_BIT(msg.NOTIFY_ARG,0)) { //bit 0 set -> interrupt from keyboard


	                                        code = read_kb(); // The data returned from function above



	                                        if (code == 0x81) // Esc 

	                                                i = 0;

	                                        if (code >> 7 == 1)

	                                                printf("Breakcode: 0x%2x\n", code);

	                                        else

	                                                printf("Makecode: 0x%2x\n", code);






	                                }else printf("passed\n");


	                                break;

	                        default:

	                                break;

	                        }

	                } else {}


	                printf("end of cicle\n");
	        }


	        unsubscribe_int();

What happened was that the program outputed "waiting for key" and nothing else.
Supposedly, if I don't press a key, there's no interrupt and it should also print "passed" , but it doesn't , so it's like there's always an interruption from the keyboard pending that makes the program pause :?

Does anybody have an idea to solve this problem ??

Thanks a lot