lkml.org 
[lkml]   [2004]   [Jan]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRaw I/O Problems with inb()
Hello everybody.

I apologize if this is off topic, but I have seen relevant information posted to this list, even though this isn't actually a kernel programming problem. And believe me, I have searched everywhere else for a solution to this problem.

To give some short background information, I am programming the Linux client for a project that basically counts a users keystrokes, and sends the amount to a server which displays the count for all the world to see. Teams and individuals compete from around the world, and we are approaching 5000 members.

At any rate, the application is written in C/C++. I am using iopl() for permissions management, and inb() for reading raw data directly from the PS/2 keyboard to test if a key has been pressed. All of this works great, and the program is complete, except for one problem.

It seems that on Athlon XP systems using PS/2 mice, inb(0x64) always says there is data waiting from the keyboard, when it is in fact mouse data. I assume that different architecture on AMD systems is the cause of the problem, but is there a solution? There must be. Here is a snippet of the code I am using currently. I apologize for the sloppiness of it - it's been modified about 30 times with 30 different solutions to the problem, all of which did not seem to fix it. Commented out are solutions that I have tried and have not worked.

#define KEYBOARD_PORT 0x60
#define KEYBOARD_STATUS_PORT 0x64

bool keycounter::count(/*wplog* l*/) { // some very simple code to see if a key is being pressed or not.
const unsigned char kbd_read_mask = 0x01;
unsigned char status = inb_p(KEYBOARD_STATUS_PORT);
/* unsigned char status = inb(KEYBOARD_STATUS_PORT);

/* mouse data? */
// if (status == 20 && ((status & kbd_read_mask) != 0x01) || (status & 0x21)) { fflush(0); return false; }
// if(status & kbd_read_mask & 0x20) { fflush(0); return false; }
// if(!(status & kbd_read_mask & 0x01)) { fflush(0); return false; }
// if(!((inb(0x379) & 0x20) == 0x20)) { fflush(0); return false; }

if(status!=20) { fflush(0); return false; }
unsigned char c = inb(KEYBOARD_PORT);
if(status==20 && c < TABLE_SIZE) {
if(c==lastc) {
fflush(0);
return false;
}
lastc=c;
fflush(0);
return true;
}
else { // key has been lifted
lastc=0;
fflush(0);
return false;
}
}

Thanks in advance for any insight you all may be able to give me


--
Brett Gmoser
aftli@optonline.net
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:00    [W:0.710 / U:1.148 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site