reimplemented waiting for read/write, added flush function

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15934 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marcus Overhagen
2006-01-13 11:17:12 +00:00
parent 7afc16f059
commit fb8a44691f
2 changed files with 32 additions and 28 deletions
@@ -90,47 +90,48 @@ ps2_write_data(uint8 data)
} }
status_t
/** Wait until the specified status bits are cleared or set, depending on the ps2_wait_read()
* second parameter.
* This currently busy waits, but should nonetheless be avoided in interrupt
* handlers.
*/
static status_t
wait_for_status(int32 bits, bool set)
{ {
int8 read; int i;
int32 tries = 100; for (i = 0; i < PS2_CTRL_WAIT_TIMEOUT / 50; i++) {
if (ps2_read_ctrl() & PS2_STATUS_OUTPUT_BUFFER_FULL)
TRACE(("wait_write_ctrl(bits = %lx, %s)\n", bits, set ? "set" : "cleared"));
while (tries-- > 0) {
read = gIsa->read_io_8(PS2_PORT_CTRL);
if (((read & bits) == bits) == set)
return B_OK; return B_OK;
snooze(50);
spin(100);
} }
return B_ERROR; return B_ERROR;
} }
static inline status_t status_t
wait_for_bits_cleared(int32 bits) ps2_wait_write()
{ {
return wait_for_status(bits, false); int i;
for (i = 0; i < PS2_CTRL_WAIT_TIMEOUT / 50; i++) {
if (!(ps2_read_ctrl() & PS2_STATUS_INPUT_BUFFER_FULL))
return B_OK;
snooze(50);
}
return B_ERROR;
} }
static inline status_t void
wait_for_bits_set(int32 bits) ps2_flush()
{ {
return wait_for_status(bits, true); int i;
for (i = 0; i < 64; i++) {
uint8 ctrl;
uint8 data;
ctrl = ps2_read_ctrl();
if (!(ctrl & PS2_STATUS_OUTPUT_BUFFER_FULL))
return;
data = ps2_read_data();
TRACE(("ps2_flush: ctrl 0x%02x, data 0x%02x (%s)\n", ctrl, data, (ctrl & PS2_STATUS_MOUSE_DATA) ? "mouse" : "keyb"));
snooze(100);
}
} }
/** Reads the command byte from the 8042 controller. /** Reads the command byte from the 8042 controller.
* Since the read goes through the data port, this function must not be * Since the read goes through the data port, this function must not be
* called when the keyboard driver is up and running. * called when the keyboard driver is up and running.
@@ -74,4 +74,7 @@
#define PS2_MAX_PACKET_SIZE 4 #define PS2_MAX_PACKET_SIZE 4
// Should be equal to the biggest packet size // Should be equal to the biggest packet size
// timeouts
#define PS2_CTRL_WAIT_TIMEOUT 500000
#endif /* _PS2_H */ #endif /* _PS2_H */