Issue with my Interrupt Handler.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

Issue with my Interrupt Handler.

Post by astrocrep »

I must prefix by saying, that I do not have code on hand to paste, but the under-pinnings of OS is based on the Bran Kernel Tutorial.

Basically, I have a keyboard isr, and it works... it fires fine and outputs to the screen whatever letter I typed, so I know its not an issue with the ISR or PIC or anything of the like. I wanted to extended the basic functionality that Bran kernel gave, so I added support for Uppercase letters, and Shift/Caps Lock support. Again that works fine. I wanted to make the keyboard a requestable device, now when a key is pressed it calles a function pointer to a user-definable keyboard handler. So I further tested it by assigning a "test" function that recieves the key code as a parameter and then prints it out on the screen... that works.

Now heres, the problem, I am trying to implement a "getch" function, and instead of doing a hard loop poling the keyboard port, I do something along the line of this (granted this is pseudo code, but the pricipal is the same)

Code: Select all

int keyEvent;

void keyhandler(int pKey)
{
 kprintf("Event Handler Called.\n");
 AddKeyToBuffer(pKey);
 keyEvent = 1;
}

int getch()
{
 int key;
 SetKeyHandler(&keyhandler);
 keyEvent = 0;
 do {
  //nothing
 } while (keyEvent == 0);
 key = GetKeyFromBuffer();
 ClearKeyHandler(); 
}

Now, I know it mainly working because, when I press a key I get the Message "Event Handler Called.", but It never breaks the loop. I don't know for certain, but I am assuming that its because something funny is happening to my stack in the middle of the ISR, and I am not sure why. I only have 1 kernel stack, and I do not have task switching or even paging enabled yet. Here is the link to the code for Brans Kernel, the ISR code is unmodified: http://osdever.net/bkerndev/Docs/whatsleft.htm

Thanks,
Rich
Crazed123
Member
Member
Posts: 248
Joined: Thu Oct 21, 2004 11:00 pm

Post by Crazed123 »

That *is* weird. Of course, you modify a variable in an interrupt handler without any synchronization, so anything could happen.
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

Post by astrocrep »

So what would be the proper method or logic to get data from the interrupt to normal kernel code?

Thanks,
Rich
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Have you tried adding volatile to the keyevent variable?

Code: Select all

volatile int keyEvent;
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

Post by astrocrep »

Ohh... interesting... I will do that as soon as I get home.

Thanks,
Rich
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

Post by astrocrep »

That was it, thanks!

-Rich
Post Reply