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
38class NS16550 : public SerialDevice
39{
40 private:
41
46 {
47 ReceiveBuffer = 0x00, /* 0 */
50 DivisorLatchHigh = 0x04, /* 1 */
52 InterruptIdentity = 0x08, /* 2 */
54 LineControl = 0x0C, /* 3 */
55 ModemControl = 0x10, /* 4 */
56 LineStatus = 0x14, /* 5 */
57 ModemStatus = 0x18, /* 6 */
58 Scratch = 0x1C, /* 7 */
59 UartStatus = 0x7C, /* 31 */
60 TransmitFifoLvl = 0x80
61 };
62
67
72
78
80 {
82 LineControl8Bits = (0x3 << 0)
83 };
84
86 {
88 LineStatusDataReady = (1 << 0)
89 };
90
97
98 public:
99
103 NS16550(const u32 irq);
104
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 */
Abstract Input/Output buffer.
Definition IOBuffer.h:38
The NS16550 is a commonly available UART device.
Definition NS16550.h:39
virtual FileSystem::Result interrupt(const Size vector)
Called when an interrupt has been triggered for this device.
Definition NS16550.cpp:78
InterruptEnableFlags
Definition NS16550.h:64
@ ReceiveDataInterrupt
Definition NS16550.h:65
virtual FileSystem::Result initialize()
Initializes the UART.
Definition NS16550.cpp:33
InterruptIdentityFlags
Definition NS16550.h:69
@ InterruptIdentityFifoEnable
Definition NS16550.h:70
LineStatusFlags
Definition NS16550.h:86
@ LineStatusDataReady
Definition NS16550.h:88
@ LineStatusTxEmpty
Definition NS16550.h:87
Registers
Hardware registers.
Definition NS16550.h:46
@ LineControl
Definition NS16550.h:54
@ TransmitHolding
Definition NS16550.h:48
@ ReceiveBuffer
Definition NS16550.h:47
@ ModemControl
Definition NS16550.h:55
@ InterruptIdentity
Definition NS16550.h:52
@ LineStatus
Definition NS16550.h:56
@ Scratch
Definition NS16550.h:58
@ ModemStatus
Definition NS16550.h:57
@ InterruptEnable
Definition NS16550.h:51
@ DivisorLatchLow
Definition NS16550.h:49
@ TransmitFifoLvl
Definition NS16550.h:60
@ DivisorLatchHigh
Definition NS16550.h:50
@ FifoControl
Definition NS16550.h:53
@ UartStatus
Definition NS16550.h:59
LineControlFlags
Definition NS16550.h:80
@ LineControl8Bits
Definition NS16550.h:82
@ LineControlDivisorLatch
Definition NS16550.h:81
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read bytes from the device.
Definition NS16550.cpp:85
UartStatusFlags
Definition NS16550.h:92
@ UartStatusBusy
Definition NS16550.h:95
@ UartStatusReceiveAvailable
Definition NS16550.h:93
@ UartStatusTransmitAvailable
Definition NS16550.h:94
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Write bytes to the device.
Definition NS16550.cpp:120
FifoControlFlags
Definition NS16550.h:74
@ FifoControlTrigger1
Definition NS16550.h:75
@ FifoControlEnable
Definition NS16550.h:76
void setDivisorLatch(bool enabled)
Enable access to the divisor latch registers.
Definition NS16550.cpp:149
Provides sequential byte stream of incoming (RX) and outgoing (TX) data.
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
Result
Result code for filesystem Actions.
Definition FileSystem.h:53