Kernel: Use unsigned instead of signed types in SerialDevice

Addresses are unsigned by definition, and the conversion from signed
to unsigned and back in SerialDevice looked a bit dubious.
This commit is contained in:
Idan Horowitz 2021-04-23 17:25:07 +03:00 committed by Andreas Kling
parent 3ad0a0d8c3
commit 0e5aba16ef
Notes: sideshowbarker 2024-07-18 17:57:22 +09:00
2 changed files with 23 additions and 24 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -9,7 +10,7 @@
namespace Kernel {
UNMAP_AFTER_INIT SerialDevice::SerialDevice(int base_addr, unsigned minor)
UNMAP_AFTER_INIT SerialDevice::SerialDevice(u32 base_addr, unsigned minor)
: CharacterDevice(4, minor)
, m_base_addr(base_addr)
{
@ -67,14 +68,14 @@ String SerialDevice::device_name() const
UNMAP_AFTER_INIT void SerialDevice::initialize()
{
set_interrupts(0);
set_interrupts(false);
set_baud(Baud38400);
set_line_control(None, One, EightBits);
set_fifo_control(EnableFIFO | ClearReceiveFIFO | ClearTransmitFIFO | TriggerLevel4);
set_modem_control(RequestToSend | DataTerminalReady);
}
UNMAP_AFTER_INIT void SerialDevice::set_interrupts(char interrupt_enable)
UNMAP_AFTER_INIT void SerialDevice::set_interrupts(bool interrupt_enable)
{
m_interrupt_enable = interrupt_enable;
@ -86,12 +87,12 @@ void SerialDevice::set_baud(Baud baud)
m_baud = baud;
IO::out8(m_base_addr + 3, IO::in8(m_base_addr + 3) | 0x80); // turn on DLAB
IO::out8(m_base_addr + 0, ((char)(baud)) >> 2); // lower half of divisor
IO::out8(m_base_addr + 1, ((char)(baud)) & 0xff); // upper half of divisor
IO::out8(m_base_addr + 0, ((u8)(baud)) >> 2); // lower half of divisor
IO::out8(m_base_addr + 1, ((u8)(baud)) & 0xff); // upper half of divisor
IO::out8(m_base_addr + 3, IO::in8(m_base_addr + 3) & 0x7f); // turn off DLAB
}
void SerialDevice::set_fifo_control(char fifo_control)
void SerialDevice::set_fifo_control(u8 fifo_control)
{
m_fifo_control = fifo_control;
@ -114,14 +115,14 @@ void SerialDevice::set_break_enable(bool break_enable)
IO::out8(m_base_addr + 3, IO::in8(m_base_addr + 3) & (break_enable ? 0xff : 0xbf));
}
void SerialDevice::set_modem_control(char modem_control)
void SerialDevice::set_modem_control(u8 modem_control)
{
m_modem_control = modem_control;
IO::out8(m_base_addr + 4, modem_control);
}
char SerialDevice::get_line_status() const
u8 SerialDevice::get_line_status() const
{
return IO::in8(m_base_addr + 5);
}

View file

@ -18,7 +18,7 @@ namespace Kernel {
class SerialDevice final : public CharacterDevice {
AK_MAKE_ETERNAL
public:
SerialDevice(int base_addr, unsigned minor);
SerialDevice(u32 base_addr, unsigned minor);
virtual ~SerialDevice() override;
// ^CharacterDevice
@ -112,25 +112,23 @@ private:
virtual const char* class_name() const override { return "SerialDevice"; }
void initialize();
void set_interrupts(char interrupt_enable);
void set_interrupts(bool interrupt_enable);
void set_baud(Baud);
void set_fifo_control(char fifo_control);
void set_fifo_control(u8 fifo_control);
void set_line_control(ParitySelect, StopBits, WordLength);
void set_break_enable(bool break_enable);
void set_modem_control(char modem_control);
char get_line_status() const;
bool rx_ready();
bool tx_ready();
void set_modem_control(u8 modem_control);
u8 get_line_status() const;
int m_base_addr;
char m_interrupt_enable;
char m_fifo_control;
Baud m_baud;
ParitySelect m_parity_select;
StopBits m_stop_bits;
WordLength m_word_length;
bool m_break_enable;
char m_modem_control;
u32 m_base_addr { 0 };
bool m_interrupt_enable { false };
u8 m_fifo_control { 0 };
Baud m_baud { Baud38400 };
ParitySelect m_parity_select { None };
StopBits m_stop_bits { One };
WordLength m_word_length { EightBits };
bool m_break_enable { false };
u8 m_modem_control { 0 };
};
}