Page 1 of 1
PS2 mouse and keyboard : bad cohabitation
Posted: Sun Sep 06, 2009 3:43 am
by SamyPesse
Hello, i have made a driver for the ps2 mouse and it's works good but when i test with the keyboard, one time, the keyboard doesnt works and the mouse yes, but one other time, the keyboard works and the mouse not. I thinks the problems is the ps2 controllers, what i need to have a good cohabitation ?
Re: PS2 mouse and keyboard : bad cohabitation
Posted: Sun Sep 06, 2009 7:25 am
by Combuster
You can't separate the PS/2 mouse and keyboard code into two drivers. They share the same controller and control ports and need a common part to prevent them from influencing each other.
Re: PS2 mouse and keyboard : bad cohabitation
Posted: Sun Sep 06, 2009 7:48 am
by SamyPesse
How works this common part to prevent them from influencing each other ? because the ps2 mouse and the keyboard use different IRQ,
Re: PS2 mouse and keyboard : bad cohabitation
Posted: Sun Sep 06, 2009 8:01 am
by Brendan
Hi,
Combuster wrote:You can't separate the PS/2 mouse and keyboard code into two drivers. They share the same controller and control ports and need a common part to prevent them from influencing each other.
True, but you can separate it into 3 drivers: one for the PS/2 controller, and one for each device connected to the PS/2 controller. It's not even that hard - all you do is define some sort of interface that allows the keyboard driver and mouse driver to talk to the PS/2 controller's driver.
Of course once you've designed it as 3 separate drivers, you don't necessarily need to implement it as 3 separate drivers. The important thing is having some sort of abstraction between the keyboard/mouse stuff and the controller stuff...
Cheers,
Brendan
Re: PS2 mouse and keyboard : bad cohabitation
Posted: Mon Sep 07, 2009 1:39 am
by mybura
The common part is that the KBC will queue data and mix the mouse and keyboard data. So if your Keyboard driver is not aware of the mouse driver, it will throw away mouse data and likewise for the mouse driver.
You read and acknowledge data from the controller using the same ports. Have a look at the attached files. You will see that eventhough two IRQ's are used, reading the data is done in the same way and a decission is made at the time of reading data as to if it is for the Keyboard or the mouse.
Re: PS2 mouse and keyboard : bad cohabitation
Posted: Mon Sep 07, 2009 8:05 am
by jal
mybura wrote:You read and acknowledge data from the controller using the same ports. Have a look at the attached files. You will see that eventhough two IRQ's are used, reading the data is done in the same way and a decission is made at the time of reading data as to if it is for the Keyboard or the mouse.
You make the classic mistake of reading more than one byte when receiving an IRQ. You should not do this: read one byte at each IRQ, and you'll be fine.
JAL
Re: PS2 mouse and keyboard : bad cohabitation
Posted: Mon Sep 07, 2009 11:53 pm
by mybura
Might explain why on some hardware it works and other it doesn't. I've found that on some ps2 emulated USB hardware the driver would hang on data from the mouse and keyboard at the same time.
Re: PS2 mouse and keyboard : bad cohabitation
Posted: Tue Sep 08, 2009 4:16 am
by jal
mybura wrote:Might explain why on some hardware it works and other it doesn't. I've found that on some ps2 emulated USB hardware the driver would hang on data from the mouse and keyboard at the same time.
Could very well be. The hardware expects one byte to be read, then the IRQ to be acknowledged. There's no telling how it reacts when you read a sequence of bytes, then acknowledge a single IRQ. Could be that the other IRQs are still pending, and when you start reading, there's no data (which is not surprising, since you read it all).
JAL