FreeNOS
NS16550.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __SERVER_SERIAL_NS16550_H
19 #define __SERVER_SERIAL_NS16550_H
20 
21 #include <Log.h>
22 #include <Types.h>
23 #include "SerialDevice.h"
24 
38 class NS16550 : public SerialDevice
39 {
40  private:
41 
45  enum Registers
46  {
47  ReceiveBuffer = 0x00, /* 0 */
50  DivisorLatchHigh = 0x04, /* 1 */
52  InterruptIdentity = 0x08, /* 2 */
53  FifoControl = 0x08,
54  LineControl = 0x0C, /* 3 */
55  ModemControl = 0x10, /* 4 */
56  LineStatus = 0x14, /* 5 */
57  ModemStatus = 0x18, /* 6 */
58  Scratch = 0x1C, /* 7 */
59  UartStatus = 0x7C, /* 31 */
61  };
62 
64  {
66  };
67 
69  {
71  };
72 
74  {
76  FifoControlEnable = (1 << 0)
77  };
78 
80  {
82  LineControl8Bits = (0x3 << 0)
83  };
84 
86  {
87  LineStatusTxEmpty = (1 << 6),
89  };
90 
92  {
95  UartStatusBusy = (1 << 0)
96  };
97 
98  public:
99 
103  NS16550(const u32 irq);
104 
110  virtual FileSystem::Result initialize();
111 
119  virtual FileSystem::Result interrupt(const Size vector);
120 
131  virtual FileSystem::Result read(IOBuffer & buffer,
132  Size & size,
133  const Size offset);
134 
145  virtual FileSystem::Result write(IOBuffer & buffer,
146  Size & size,
147  const Size offset);
148 
149  private:
150 
156  void setDivisorLatch(bool enabled);
157 };
158 
164 #endif /* __SERVER_SERIAL_NS16550_H */
NS16550::LineStatusFlags
LineStatusFlags
Definition: NS16550.h:85
NS16550::LineControlDivisorLatch
@ LineControlDivisorLatch
Definition: NS16550.h:81
NS16550::DivisorLatchHigh
@ DivisorLatchHigh
Definition: NS16550.h:50
NS16550::InterruptEnable
@ InterruptEnable
Definition: NS16550.h:51
NS16550::LineStatusDataReady
@ LineStatusDataReady
Definition: NS16550.h:88
NS16550::InterruptIdentityFlags
InterruptIdentityFlags
Definition: NS16550.h:68
SerialDevice.h
Types.h
NS16550::FifoControlFlags
FifoControlFlags
Definition: NS16550.h:73
NS16550::interrupt
virtual FileSystem::Result interrupt(const Size vector)
Called when an interrupt has been triggered for this device.
Definition: NS16550.cpp:78
NS16550::UartStatusBusy
@ UartStatusBusy
Definition: NS16550.h:95
NS16550::InterruptIdentityFifoEnable
@ InterruptIdentityFifoEnable
Definition: NS16550.h:70
NS16550::UartStatus
@ UartStatus
Definition: NS16550.h:59
NS16550::UartStatusFlags
UartStatusFlags
Definition: NS16550.h:91
NS16550::write
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Write bytes to the device.
Definition: NS16550.cpp:120
NS16550::ModemStatus
@ ModemStatus
Definition: NS16550.h:57
NS16550::TransmitHolding
@ TransmitHolding
Definition: NS16550.h:48
NS16550::FifoControlEnable
@ FifoControlEnable
Definition: NS16550.h:76
NS16550::UartStatusTransmitAvailable
@ UartStatusTransmitAvailable
Definition: NS16550.h:94
Log.h
NS16550::ReceiveBuffer
@ ReceiveBuffer
Definition: NS16550.h:47
NS16550::FifoControlTrigger1
@ FifoControlTrigger1
Definition: NS16550.h:75
NS16550::LineStatusTxEmpty
@ LineStatusTxEmpty
Definition: NS16550.h:87
NS16550::LineControl
@ LineControl
Definition: NS16550.h:54
NS16550::ModemControl
@ ModemControl
Definition: NS16550.h:55
NS16550::LineControlFlags
LineControlFlags
Definition: NS16550.h:79
IOBuffer
Abstract Input/Output buffer.
Definition: IOBuffer.h:37
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
NS16550::InterruptIdentity
@ InterruptIdentity
Definition: NS16550.h:52
NS16550::Registers
Registers
Hardware registers.
Definition: NS16550.h:45
SerialDevice
Provides sequential byte stream of incoming (RX) and outgoing (TX) data.
Definition: SerialDevice.h:37
NS16550::DivisorLatchLow
@ DivisorLatchLow
Definition: NS16550.h:49
NS16550::LineStatus
@ LineStatus
Definition: NS16550.h:56
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
NS16550::NS16550
NS16550(const u32 irq)
Constructor.
Definition: NS16550.cpp:27
NS16550::initialize
virtual FileSystem::Result initialize()
Initializes the UART.
Definition: NS16550.cpp:33
NS16550::TransmitFifoLvl
@ TransmitFifoLvl
Definition: NS16550.h:60
NS16550::Scratch
@ Scratch
Definition: NS16550.h:58
NS16550::InterruptEnableFlags
InterruptEnableFlags
Definition: NS16550.h:63
NS16550::setDivisorLatch
void setDivisorLatch(bool enabled)
Enable access to the divisor latch registers.
Definition: NS16550.cpp:149
NS16550::UartStatusReceiveAvailable
@ UartStatusReceiveAvailable
Definition: NS16550.h:93
NS16550::FifoControl
@ FifoControl
Definition: NS16550.h:53
NS16550::ReceiveDataInterrupt
@ ReceiveDataInterrupt
Definition: NS16550.h:65
NS16550::read
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read bytes from the device.
Definition: NS16550.cpp:85
NS16550::LineControl8Bits
@ LineControl8Bits
Definition: NS16550.h:82
NS16550
The NS16550 is a commonly available UART device.
Definition: NS16550.h:38