forked from Bananymous/banan-os
Kernel: Add timeout for device commands on PS/2 devices
This commit is contained in:
parent
961ab9768a
commit
e6d42e5c45
|
@ -61,6 +61,7 @@ namespace Kernel::Input
|
||||||
RecursiveSpinLock m_lock;
|
RecursiveSpinLock m_lock;
|
||||||
|
|
||||||
BAN::CircularQueue<Command, 128> m_command_queue;
|
BAN::CircularQueue<Command, 128> m_command_queue;
|
||||||
|
uint64_t m_command_send_time { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ namespace Kernel::Input
|
||||||
|
|
||||||
virtual void send_initialize() = 0;
|
virtual void send_initialize() = 0;
|
||||||
|
|
||||||
|
virtual void command_timedout(uint8_t* command_data, uint8_t command_size) = 0;
|
||||||
|
|
||||||
bool append_command_queue(uint8_t command, uint8_t response_size);
|
bool append_command_queue(uint8_t command, uint8_t response_size);
|
||||||
bool append_command_queue(uint8_t command, uint8_t data, uint8_t response_size);
|
bool append_command_queue(uint8_t command, uint8_t data, uint8_t response_size);
|
||||||
virtual void handle_irq() final override;
|
virtual void handle_irq() final override;
|
||||||
|
|
|
@ -23,6 +23,8 @@ namespace Kernel::Input
|
||||||
static BAN::ErrorOr<PS2Keyboard*> create(PS2Controller&);
|
static BAN::ErrorOr<PS2Keyboard*> create(PS2Controller&);
|
||||||
virtual void send_initialize() override;
|
virtual void send_initialize() override;
|
||||||
|
|
||||||
|
virtual void command_timedout(uint8_t* command_data, uint8_t command_size) final override;
|
||||||
|
|
||||||
virtual void handle_byte(uint8_t) final override;
|
virtual void handle_byte(uint8_t) final override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -19,6 +19,8 @@ namespace Kernel::Input
|
||||||
static BAN::ErrorOr<PS2Mouse*> create(PS2Controller&);
|
static BAN::ErrorOr<PS2Mouse*> create(PS2Controller&);
|
||||||
virtual void send_initialize() override;
|
virtual void send_initialize() override;
|
||||||
|
|
||||||
|
virtual void command_timedout(uint8_t* command_data, uint8_t command_size) final override {}
|
||||||
|
|
||||||
virtual void handle_byte(uint8_t) final override;
|
virtual void handle_byte(uint8_t) final override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -139,9 +139,18 @@ namespace Kernel::Input
|
||||||
return;
|
return;
|
||||||
auto& command = m_command_queue.front();
|
auto& command = m_command_queue.front();
|
||||||
if (command.state == Command::State::WaitingResponse || command.state == Command::State::WaitingAck)
|
if (command.state == Command::State::WaitingResponse || command.state == Command::State::WaitingAck)
|
||||||
|
{
|
||||||
|
if (SystemTimer::get().ms_since_boot() >= m_command_send_time + s_ps2_timeout_ms)
|
||||||
|
{
|
||||||
|
dwarnln_if(DEBUG_PS2, "Command timedout");
|
||||||
|
m_devices[command.device_index]->command_timedout(command.out_data, command.out_count);
|
||||||
|
m_command_queue.pop();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
ASSERT(command.send_index < command.out_count);
|
ASSERT(command.send_index < command.out_count);
|
||||||
command.state = Command::State::WaitingAck;
|
command.state = Command::State::WaitingAck;
|
||||||
|
m_command_send_time = SystemTimer::get().ms_since_boot();
|
||||||
if (auto ret = device_send_byte(command.device_index, command.out_data[command.send_index]); ret.is_error())
|
if (auto ret = device_send_byte(command.device_index, command.out_data[command.send_index]); ret.is_error())
|
||||||
{
|
{
|
||||||
command.state = Command::State::Sending;
|
command.state = Command::State::Sending;
|
||||||
|
|
Loading…
Reference in New Issue