os/kernelhwsrv/kernel/eka/include/drivers/uart16550.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\include\drivers\uart16550.h
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology
sl@0
    21
*/
sl@0
    22
sl@0
    23
#ifndef __UART16550_H__
sl@0
    24
#define __UART16550_H__
sl@0
    25
#include <e32def.h>
sl@0
    26
sl@0
    27
//								 
sl@0
    28
// Register Definitions for 16550-type UARTs
sl@0
    29
//
sl@0
    30
sl@0
    31
const TUint8 K16550TXHROffset=0<<K16550OffsetShift;			// Transmit Holding Register
sl@0
    32
const TUint8 K16550RXHROffset=0<<K16550OffsetShift;			// Receive Holding Register
sl@0
    33
const TUint8 K16550BDLoOffset=0<<K16550OffsetShift;			// Baud Rate Divisor Low
sl@0
    34
const TUint8 K16550IEROffset=1<<K16550OffsetShift;			// Interrupt Enable Register
sl@0
    35
const TUint8 K16550BDHiOffset=1<<K16550OffsetShift;			// Baud Rate Divisor High
sl@0
    36
const TUint8 K16550ISROffset=2<<K16550OffsetShift;			// Interrupt Status Register
sl@0
    37
const TUint8 K16550FCROffset=2<<K16550OffsetShift;			// FIFO Control Register
sl@0
    38
const TUint8 K16550LCROffset=3<<K16550OffsetShift;			// Line Control Register
sl@0
    39
const TUint8 K16550MCROffset=4<<K16550OffsetShift;			// Modem Control Register
sl@0
    40
const TUint8 K16550LSROffset=5<<K16550OffsetShift;			// Line Status Register
sl@0
    41
const TUint8 K16550MSROffset=6<<K16550OffsetShift;			// Modem Status Register
sl@0
    42
const TUint8 K16550ScratchpadOffset=7<<K16550OffsetShift;	// Scratchpad Register
sl@0
    43
sl@0
    44
// Interrupt Enable Register
sl@0
    45
sl@0
    46
const TUint8 K16550IER_RDAI=1;				// Received Data Available
sl@0
    47
const TUint8 K16550IER_THREI=2;				// Transmit Holding Register Empty
sl@0
    48
const TUint8 K16550IER_RLSI=4;				// Receive Line Status (error or break)
sl@0
    49
const TUint8 K16550IER_MSI=8;				// Modem Status
sl@0
    50
sl@0
    51
// Interrupt Status Register
sl@0
    52
sl@0
    53
const TUint8 K16550ISR_NotPending=1;		// Not Interrupt Pending
sl@0
    54
const TUint8 K16550ISR_IntIdMask=6;			// Mask for Interrupt Identification
sl@0
    55
const TUint8 K16550ISR_RDAI=4;				// Received Data Available
sl@0
    56
const TUint8 K16550ISR_THREI=2;				// Transmit Holding Register Empty
sl@0
    57
const TUint8 K16550ISR_RLSI=6;				// Receive Line Status
sl@0
    58
const TUint8 K16550ISR_MSI=0;				// Modem Status
sl@0
    59
const TUint8 K16550ISR_RxTimeout=8;			// Set if FIFO timeout (in conjunction with RDA)
sl@0
    60
sl@0
    61
// FIFO control Register
sl@0
    62
sl@0
    63
const TUint8 K16550FCR_Enable=1;			// Enable TX and RX FIFOs
sl@0
    64
const TUint8 K16550FCR_RxReset=2;			// Reset RX FIFO (self-clearing)
sl@0
    65
const TUint8 K16550FCR_TxReset=4;			// Reset TX FIFO (self-clearing)
sl@0
    66
const TUint8 K16550FCR_TxRxRdy=8;			//
sl@0
    67
const TUint8 K16550FCR_RxTrig1=0;			// RX FIFO triggers when >=1 char received
sl@0
    68
const TUint8 K16550FCR_RxTrig4=64;			// RX FIFO triggers when >=4 chars received
sl@0
    69
const TUint8 K16550FCR_RxTrig8=128;			// RX FIFO triggers when >=8 chars received
sl@0
    70
const TUint8 K16550FCR_RxTrig14=192;		// RX FIFO triggers when >=14 chars received
sl@0
    71
sl@0
    72
// Line Control Register
sl@0
    73
sl@0
    74
const TUint8 K16550LCR_Data5=0;				// 5 bit characters
sl@0
    75
const TUint8 K16550LCR_Data6=1;				// 6 bit characters
sl@0
    76
const TUint8 K16550LCR_Data7=2;				// 7 bit characters
sl@0
    77
const TUint8 K16550LCR_Data8=3;				// 8 bit characters
sl@0
    78
const TUint8 K16550LCR_Stop1=0;				// 1 stop bit
sl@0
    79
const TUint8 K16550LCR_Stop2=4;				// 2 stop bits
sl@0
    80
const TUint8 K16550LCR_ParityEnable=8;		// Use parity
sl@0
    81
const TUint8 K16550LCR_ParityEven=16;		// Use even parity
sl@0
    82
const TUint8 K16550LCR_ParityMark=40;		// Use mark parity
sl@0
    83
const TUint8 K16550LCR_ParitySpace=56;		// Use space parity
sl@0
    84
const TUint8 K16550LCR_TxBreak=64;			// Transmit a break
sl@0
    85
const TUint8 K16550LCR_DLAB=128;			// Divisor Latch Access
sl@0
    86
sl@0
    87
// Modem Control Register
sl@0
    88
sl@0
    89
const TUint8 K16550MCR_DTR=1;
sl@0
    90
const TUint8 K16550MCR_RTS=2;
sl@0
    91
const TUint8 K16550MCR_OUT1=4;
sl@0
    92
const TUint8 K16550MCR_OUT2=8;
sl@0
    93
const TUint8 K16550MCR_LocalLoop=16;
sl@0
    94
sl@0
    95
// Line Status Register
sl@0
    96
sl@0
    97
const TUint8 K16550LSR_RxReady=1;			// Received data ready
sl@0
    98
const TUint8 K16550LSR_RxOverrun=2;			// Receiver overrun
sl@0
    99
const TUint8 K16550LSR_RxParityErr=4;		// Receiver parity error
sl@0
   100
const TUint8 K16550LSR_RxFrameErr=8;		// Receiver framing error
sl@0
   101
const TUint8 K16550LSR_RxBreak=16;			// Receive break detect
sl@0
   102
const TUint8 K16550LSR_TXHREmpty=32;		// Transmit Holding Register Empty (FIFO empty)
sl@0
   103
const TUint8 K16550LSR_TxIdle=64;			// Transmitter Idle
sl@0
   104
const TUint8 K16550LSR_RxErrPending=128;	// FIFO contains an error or break indication
sl@0
   105
sl@0
   106
// Modem Status Register
sl@0
   107
sl@0
   108
const TUint8 K16550MSR_DeltaCTS=1;
sl@0
   109
const TUint8 K16550MSR_DeltaDSR=2;
sl@0
   110
const TUint8 K16550MSR_TERI=4;
sl@0
   111
const TUint8 K16550MSR_DeltaDCD=8;
sl@0
   112
const TUint8 K16550MSR_CTS=16;
sl@0
   113
const TUint8 K16550MSR_DSR=32;
sl@0
   114
const TUint8 K16550MSR_RI=64;
sl@0
   115
const TUint8 K16550MSR_DCD=128;
sl@0
   116
sl@0
   117
// Wrapper class
sl@0
   118
sl@0
   119
class T16550Uart
sl@0
   120
	{
sl@0
   121
public:
sl@0
   122
	void ModifyFCR(TUint aClearMask, TUint aSetMask);
sl@0
   123
	void ModifyLCR(TUint aClearMask, TUint aSetMask);
sl@0
   124
	void ModifyMCR(TUint aClearMask, TUint aSetMask);
sl@0
   125
	void ModifyIER(TUint aClearMask, TUint aSetMask);
sl@0
   126
	void SetFCR(TUint aValue);
sl@0
   127
	void SetLCR(TUint aValue);
sl@0
   128
	void SetMCR(TUint aValue);
sl@0
   129
	void SetIER(TUint aValue);
sl@0
   130
	inline TUint FCR()
sl@0
   131
		{return iFCR;}
sl@0
   132
	inline TUint LCR()
sl@0
   133
		{return iLCR;}
sl@0
   134
	inline TUint MCR()
sl@0
   135
		{return iMCR;}
sl@0
   136
	inline TUint IER()
sl@0
   137
		{return iIER;}
sl@0
   138
	inline void SetTxData(TUint aData)
sl@0
   139
		{iBase[K16550TXHROffset]=(TUint8)aData;}
sl@0
   140
	inline TUint RxData()
sl@0
   141
		{return iBase[K16550RXHROffset];}
sl@0
   142
	inline TUint ISR()
sl@0
   143
		{return iBase[K16550ISROffset];}
sl@0
   144
	inline TUint LSR()
sl@0
   145
		{return iBase[K16550LSROffset];}
sl@0
   146
	inline TUint MSR()
sl@0
   147
		{return iBase[K16550MSROffset];}
sl@0
   148
	inline TUint TestISR(TUint aMask)
sl@0
   149
		{return iBase[K16550ISROffset]&aMask;}
sl@0
   150
	inline TUint TestLSR(TUint aMask)
sl@0
   151
		{return iBase[K16550LSROffset]&aMask;}
sl@0
   152
	inline TUint TestMSR(TUint aMask)
sl@0
   153
		{return iBase[K16550MSROffset]&aMask;}
sl@0
   154
	inline void SetScratch(TUint aValue)
sl@0
   155
		{iBase[K16550ScratchpadOffset]=(TUint8)aValue;}
sl@0
   156
	inline TUint Scratch()
sl@0
   157
		{return iBase[K16550ScratchpadOffset];}
sl@0
   158
	inline void SetBaudRateDivisor(TUint aValue)
sl@0
   159
		{iBase[K16550BDHiOffset]=(TUint8)(aValue>>8); iBase[K16550BDLoOffset]=(TUint8)aValue;}
sl@0
   160
public:
sl@0
   161
	volatile TUint8* iBase;					// base address
sl@0
   162
	TUint8 iFCR;							// FCR follower
sl@0
   163
	TUint8 iLCR;							// LCR follower
sl@0
   164
	TUint8 iMCR;							// MCR follower
sl@0
   165
	TUint8 iIER;							// IER follower
sl@0
   166
	};
sl@0
   167
sl@0
   168
sl@0
   169
#endif
sl@0
   170
sl@0
   171