FreeNOS
Public Member Functions | Private Types | Private Member Functions
NS16550 Class Reference

The NS16550 is a commonly available UART device. More...

#include <NS16550.h>

Inheritance diagram for NS16550:
SerialDevice Device AbstractFactory< SerialDevice > File

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 StringgetIdentifier () 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 SerialDevicecreate ()
 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...
 

Detailed Description

The NS16550 is a commonly available UART device.

See also
ARM

Definition at line 38 of file NS16550.h.

Member Enumeration Documentation

◆ FifoControlFlags

Enumerator
FifoControlTrigger1 
FifoControlEnable 

Definition at line 73 of file NS16550.h.

◆ InterruptEnableFlags

Enumerator
ReceiveDataInterrupt 

Definition at line 63 of file NS16550.h.

◆ InterruptIdentityFlags

Enumerator
InterruptIdentityFifoEnable 

Definition at line 68 of file NS16550.h.

◆ LineControlFlags

Enumerator
LineControlDivisorLatch 
LineControl8Bits 

Definition at line 79 of file NS16550.h.

◆ LineStatusFlags

Enumerator
LineStatusTxEmpty 
LineStatusDataReady 

Definition at line 85 of file NS16550.h.

◆ Registers

enum NS16550::Registers
private

Hardware registers.

Enumerator
ReceiveBuffer 
TransmitHolding 
DivisorLatchLow 
DivisorLatchHigh 
InterruptEnable 
InterruptIdentity 
FifoControl 
LineControl 
ModemControl 
LineStatus 
ModemStatus 
Scratch 
UartStatus 
TransmitFifoLvl 

Definition at line 45 of file NS16550.h.

◆ UartStatusFlags

Enumerator
UartStatusReceiveAvailable 
UartStatusTransmitAvailable 
UartStatusBusy 

Definition at line 91 of file NS16550.h.

Constructor & Destructor Documentation

◆ NS16550()

NS16550::NS16550 ( const u32  irq)

Constructor.

Definition at line 27 of file NS16550.cpp.

References Device::m_identifier.

Member Function Documentation

◆ initialize()

FileSystem::Result NS16550::initialize ( )
virtual

◆ interrupt()

FileSystem::Result NS16550::interrupt ( const Size  vector)
virtual

Called when an interrupt has been triggered for this device.

Parameters
vectorVector number of the interrupt.
Returns
Result code

Reimplemented from Device.

Definition at line 78 of file NS16550.cpp.

References InterruptEnable, SerialDevice::m_io, FileSystem::Success, and ARMIO::write().

◆ read()

FileSystem::Result NS16550::read ( IOBuffer buffer,
Size size,
const Size  offset 
)
virtual

Read bytes from the device.

Parameters
bufferInput/Output buffer to output bytes to.
sizeMaximum number of bytes to read on input. On output, the actual number of bytes read.
offsetOffset inside the file to start reading.
Returns
Result code

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().

◆ setDivisorLatch()

void NS16550::setDivisorLatch ( bool  enabled)
private

Enable access to the divisor latch registers.

Parameters
enabledTrue 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().

◆ write()

FileSystem::Result NS16550::write ( IOBuffer buffer,
Size size,
const Size  offset 
)
virtual

Write bytes to the device.

Parameters
bufferInput/Output buffer to input bytes from.
sizeMaximum number of bytes to write on input. On output, the actual number of bytes written.
offsetOffset inside the file to start writing.
Returns
Result code

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().


The documentation for this class was generated from the following files: