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