summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-04-23 17:25:07 +0300
committerAndreas Kling <kling@serenityos.org>2021-05-17 18:15:25 +0200
commit0e5aba16efa4bb2474974f07aba2e7874fc0ca09 (patch)
tree4ab79e24964114c98e97579fb7a8c54ecc7c218c /Kernel
parent3ad0a0d8c33b7cbe569533e6ffe73fa7f324347c (diff)
downloadserenity-0e5aba16efa4bb2474974f07aba2e7874fc0ca09.zip
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.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Devices/SerialDevice.cpp17
-rw-r--r--Kernel/Devices/SerialDevice.h32
2 files changed, 24 insertions, 25 deletions
diff --git a/Kernel/Devices/SerialDevice.cpp b/Kernel/Devices/SerialDevice.cpp
index 3be348172a..a2dff8d8f8 100644
--- a/Kernel/Devices/SerialDevice.cpp
+++ b/Kernel/Devices/SerialDevice.cpp
@@ -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);
}
diff --git a/Kernel/Devices/SerialDevice.h b/Kernel/Devices/SerialDevice.h
index e4f5167848..7a0205429a 100644
--- a/Kernel/Devices/SerialDevice.h
+++ b/Kernel/Devices/SerialDevice.h
@@ -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();
-
- 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;
+ void set_modem_control(u8 modem_control);
+ u8 get_line_status() const;
+
+ 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 };
};
}