FreeNOS
|
The NS16550 is a commonly available UART device. More...
#include <NS16550.h>
Public Member Functions | |
NS16550 (const u32 irq) | |
Constructor. More... | |
virtual FileSystem::Result | initialize () |
Initializes the UART. More... | |
virtual FileSystem::Result | interrupt (const Size vector) |
Called when an interrupt has been triggered for this device. More... | |
virtual FileSystem::Result | read (IOBuffer &buffer, Size &size, const Size offset) |
Read bytes from the device. More... | |
virtual FileSystem::Result | write (IOBuffer &buffer, Size &size, const Size offset) |
Write bytes to the device. More... | |
Public Member Functions inherited from SerialDevice | |
SerialDevice (const u32 irq) | |
Constructor. More... | |
u32 | getIrq () const |
Get interrupt vector. More... | |
Public Member Functions inherited from Device | |
Device (const u32 inode, const FileSystem::FileType type) | |
Constructor. More... | |
virtual | ~Device () |
Destructor. More... | |
virtual const String & | getIdentifier () const |
Get unique device identifier. More... | |
Public Member Functions inherited from File | |
File (const u32 inode, const FileSystem::FileType type=FileSystem::RegularFile, const UserID uid=ZERO, const GroupID gid=ZERO) | |
Constructor function. More... | |
virtual | ~File () |
Destructor function. More... | |
u32 | getInode () const |
Get inode number. More... | |
FileSystem::FileType | getType () const |
Retrieve our filetype. More... | |
virtual FileSystem::Result | status (FileSystem::FileStat &st) |
Retrieve file statistics. More... | |
virtual bool | canRead () const |
Check if the File has data ready for reading. More... | |
virtual bool | canWrite () const |
Check if the File can be written to. More... | |
Private Types | |
enum | Registers { ReceiveBuffer = 0x00, TransmitHolding = 0x00, DivisorLatchLow = 0x00, DivisorLatchHigh = 0x04, InterruptEnable = 0x04, InterruptIdentity = 0x08, FifoControl = 0x08, LineControl = 0x0C, ModemControl = 0x10, LineStatus = 0x14, ModemStatus = 0x18, Scratch = 0x1C, UartStatus = 0x7C, TransmitFifoLvl = 0x80 } |
Hardware registers. More... | |
enum | InterruptEnableFlags { ReceiveDataInterrupt = (1 << 0) } |
enum | InterruptIdentityFlags { InterruptIdentityFifoEnable = (0x3 << 6) } |
enum | FifoControlFlags { FifoControlTrigger1 = (0), FifoControlEnable = (1 << 0) } |
enum | LineControlFlags { LineControlDivisorLatch = (1 << 7), LineControl8Bits = (0x3 << 0) } |
enum | LineStatusFlags { LineStatusTxEmpty = (1 << 6), LineStatusDataReady = (1 << 0) } |
enum | UartStatusFlags { UartStatusReceiveAvailable = (1 << 2), UartStatusTransmitAvailable = (1 << 1), UartStatusBusy = (1 << 0) } |
Private Member Functions | |
void | setDivisorLatch (bool enabled) |
Enable access to the divisor latch registers. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from AbstractFactory< SerialDevice > | |
static SerialDevice * | create () |
Abstract function to create an instance of T. More... | |
Static Public Attributes inherited from SerialDevice | |
static u32 | inodeNumber = 2 |
Keeps track of inode number for SerialDevices. More... | |
Protected Attributes inherited from SerialDevice | |
const u32 | m_irq |
interrupt vector More... | |
Arch::IO | m_io |
I/O instance. More... | |
Protected Attributes inherited from Device | |
String | m_identifier |
Unique identifier for this Device. More... | |
Protected Attributes inherited from File | |
const u32 | m_inode |
Inode number. More... | |
const FileSystem::FileType | m_type |
Type of this file. More... | |
UserID | m_uid |
Owner of the file. More... | |
GroupID | m_gid |
Group of the file. More... | |
FileSystem::FileModes | m_access |
Access permissions. More... | |
Size | m_size |
Size of the file, in bytes. More... | |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
NS16550::NS16550 | ( | const u32 | irq | ) |
|
virtual |
Initializes the UART.
Reimplemented from Device.
Definition at line 33 of file NS16550.cpp.
References Memory::Device, DisableIRQ, DivisorLatchHigh, DivisorLatchLow, EnableIRQ, FifoControl, FifoControlEnable, FifoControlTrigger1, InterruptEnable, FileSystem::IOError, isKernel, LineControl, LineControl8Bits, SerialDevice::m_io, SerialDevice::m_irq, IO::map(), PAGESIZE, ProcessCtl(), Memory::Readable, ReceiveDataInterrupt, SELF, IO::setBase(), setDivisorLatch(), IO::Success, FileSystem::Success, Memory::User, Memory::Writable, and ARMIO::write().
Referenced by kernel_main().
|
virtual |
Called when an interrupt has been triggered for this device.
vector | Vector number of the interrupt. |
Reimplemented from Device.
Definition at line 78 of file NS16550.cpp.
References InterruptEnable, SerialDevice::m_io, FileSystem::Success, and ARMIO::write().
|
virtual |
Read bytes from the device.
buffer | Input/Output buffer to output bytes to. |
size | Maximum number of bytes to read on input. On output, the actual number of bytes read. |
offset | Offset inside the file to start reading. |
Reimplemented from File.
Definition at line 85 of file NS16550.cpp.
References IOBuffer::bufferedWrite(), EnableIRQ, IOBuffer::getCount(), InterruptEnable, isKernel, LineStatus, LineStatusDataReady, SerialDevice::m_io, SerialDevice::m_irq, ProcessCtl(), ARMIO::read(), ReceiveBuffer, ReceiveDataInterrupt, FileSystem::RetryAgain, SELF, FileSystem::Success, and ARMIO::write().
|
private |
Enable access to the divisor latch registers.
enabled | True to enable, false otherwise |
Definition at line 149 of file NS16550.cpp.
References LineControl, LineControlDivisorLatch, SerialDevice::m_io, ARMIO::read(), and ARMIO::write().
Referenced by initialize().
|
virtual |
Write bytes to the device.
buffer | Input/Output buffer to input bytes from. |
size | Maximum number of bytes to write on input. On output, the actual number of bytes written. |
offset | Offset inside the file to start writing. |
Reimplemented from File.
Definition at line 120 of file NS16550.cpp.
References LineStatus, LineStatusTxEmpty, SerialDevice::m_io, ARMIO::read(), FileSystem::RetryAgain, FileSystem::Success, TransmitHolding, and ARMIO::write().