sl@0
|
1 |
// Copyright (c) 1998-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\drivers\ecomm\uart16550.cpp
|
sl@0
|
15 |
// PDD for 16550 UART
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <drivers/comm.h>
|
sl@0
|
20 |
#include <assp.h>
|
sl@0
|
21 |
#include <var_defs.h>
|
sl@0
|
22 |
#include <uart16550.h>
|
sl@0
|
23 |
#include <e32hal.h>
|
sl@0
|
24 |
|
sl@0
|
25 |
_LIT(KPddName,"Comm.16550");
|
sl@0
|
26 |
|
sl@0
|
27 |
#define __COMMS_MACHINE_CODED__
|
sl@0
|
28 |
#ifdef __COMMS_MACHINE_CODED__
|
sl@0
|
29 |
#define DBASE_VPTR_OFFSET 4
|
sl@0
|
30 |
#define RX_ISR_VT_OFFSET 0x24
|
sl@0
|
31 |
#define CHK_TXB_VT_OFFSET 0x28
|
sl@0
|
32 |
#define STATE_ISR_VT_OFFSET 0x2C
|
sl@0
|
33 |
#endif
|
sl@0
|
34 |
|
sl@0
|
35 |
// needs ldd version..
|
sl@0
|
36 |
const TInt KMinimumLddMajorVersion=1;
|
sl@0
|
37 |
const TInt KMinimumLddMinorVersion=1;
|
sl@0
|
38 |
const TInt KMinimumLddBuild=122;
|
sl@0
|
39 |
|
sl@0
|
40 |
// configuration data
|
sl@0
|
41 |
static const TUint16 BaudRateDivisor[19] =
|
sl@0
|
42 |
{
|
sl@0
|
43 |
2304, 1536, 1047, 860, 768, 384, 192, 96,
|
sl@0
|
44 |
64, 58, 48, 32, 24, 16, 12, 6,
|
sl@0
|
45 |
3, 2, 1
|
sl@0
|
46 |
};
|
sl@0
|
47 |
|
sl@0
|
48 |
class DDriverComm : public DPhysicalDevice
|
sl@0
|
49 |
{
|
sl@0
|
50 |
public:
|
sl@0
|
51 |
DDriverComm();
|
sl@0
|
52 |
virtual TInt Install();
|
sl@0
|
53 |
virtual void GetCaps(TDes8 &aDes) const;
|
sl@0
|
54 |
virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion &aVer);
|
sl@0
|
55 |
virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion &aVer);
|
sl@0
|
56 |
public:
|
sl@0
|
57 |
TDynamicDfcQue* iDfcQ;
|
sl@0
|
58 |
};
|
sl@0
|
59 |
|
sl@0
|
60 |
class DComm16550 : public DComm
|
sl@0
|
61 |
{
|
sl@0
|
62 |
public:
|
sl@0
|
63 |
DComm16550();
|
sl@0
|
64 |
~DComm16550();
|
sl@0
|
65 |
TInt DoCreate(TInt aUnit, const TDesC8* anInfo);
|
sl@0
|
66 |
public:
|
sl@0
|
67 |
virtual TInt Start();
|
sl@0
|
68 |
virtual void Stop(TStopMode aMode);
|
sl@0
|
69 |
virtual void Break(TBool aState);
|
sl@0
|
70 |
virtual void EnableTransmit();
|
sl@0
|
71 |
virtual TUint Signals() const;
|
sl@0
|
72 |
virtual void SetSignals(TUint aSetMask,TUint aClearMask);
|
sl@0
|
73 |
virtual TInt ValidateConfig(const TCommConfigV01 &aConfig) const;
|
sl@0
|
74 |
virtual void Configure(TCommConfigV01 &aConfig);
|
sl@0
|
75 |
virtual void Caps(TDes8 &aCaps) const;
|
sl@0
|
76 |
virtual TInt DisableIrqs();
|
sl@0
|
77 |
virtual void RestoreIrqs(TInt aIrq);
|
sl@0
|
78 |
virtual TDfcQue* DfcQ(TInt aUnit);
|
sl@0
|
79 |
virtual void CheckConfig(TCommConfigV01& aConfig);
|
sl@0
|
80 |
public:
|
sl@0
|
81 |
static void Isr(TAny* aPtr);
|
sl@0
|
82 |
public:
|
sl@0
|
83 |
TInt iInterruptId;
|
sl@0
|
84 |
TInt iUnit;
|
sl@0
|
85 |
T16550Uart* iUart;
|
sl@0
|
86 |
};
|
sl@0
|
87 |
|
sl@0
|
88 |
|
sl@0
|
89 |
DDriverComm::DDriverComm()
|
sl@0
|
90 |
//
|
sl@0
|
91 |
// Constructor
|
sl@0
|
92 |
//
|
sl@0
|
93 |
{
|
sl@0
|
94 |
iUnitsMask=~(0xffffffffu<<KNum16550Uarts);
|
sl@0
|
95 |
iVersion=TVersion(KCommsMajorVersionNumber,KCommsMinorVersionNumber,KCommsBuildVersionNumber);
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
|
sl@0
|
99 |
TInt DDriverComm::Install()
|
sl@0
|
100 |
//
|
sl@0
|
101 |
// Install the driver
|
sl@0
|
102 |
//
|
sl@0
|
103 |
{
|
sl@0
|
104 |
// Allocate a kernel thread to run the DFC
|
sl@0
|
105 |
TInt r = Kern::DynamicDfcQCreate(iDfcQ, KUart16550ThreadPriority, KUar16550tDriverThread);
|
sl@0
|
106 |
if (r == KErrNone)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
iDfcQ->SetRealtimeState(ERealtimeStateOff);
|
sl@0
|
109 |
r = SetName(&KPddName);
|
sl@0
|
110 |
}
|
sl@0
|
111 |
return r;
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
/**
|
sl@0
|
115 |
Destructor
|
sl@0
|
116 |
*/
|
sl@0
|
117 |
DDriverComm::~DDriverComm()
|
sl@0
|
118 |
{
|
sl@0
|
119 |
if (iDfcQ)
|
sl@0
|
120 |
iDfcQ->Destroy();
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
void Get16550CommsCaps(TDes8& aCaps, TInt aUnit)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
TCommCaps3 capsBuf;
|
sl@0
|
126 |
TCommCapsV03 &c=capsBuf();
|
sl@0
|
127 |
c.iRate=KCapsBps110|KCapsBps150|KCapsBps300|KCapsBps600\
|
sl@0
|
128 |
|KCapsBps1200|KCapsBps2400|KCapsBps4800|KCapsBps9600\
|
sl@0
|
129 |
|KCapsBps19200|KCapsBps38400|KCapsBps57600|KCapsBps115200;
|
sl@0
|
130 |
c.iDataBits=KCapsData5|KCapsData6|KCapsData7|KCapsData8;
|
sl@0
|
131 |
c.iStopBits=KCapsStop1|KCapsStop2;
|
sl@0
|
132 |
c.iParity=KCapsParityNone|KCapsParityEven|KCapsParityOdd|KCapsParityMark|KCapsParitySpace;
|
sl@0
|
133 |
c.iHandshake=KCapsObeyXoffSupported|KCapsSendXoffSupported|
|
sl@0
|
134 |
KCapsObeyCTSSupported|KCapsFailCTSSupported|
|
sl@0
|
135 |
KCapsObeyDSRSupported|KCapsFailDSRSupported|
|
sl@0
|
136 |
KCapsObeyDCDSupported|KCapsFailDCDSupported|
|
sl@0
|
137 |
KCapsFreeRTSSupported|KCapsFreeDTRSupported;
|
sl@0
|
138 |
c.iSIR=0;
|
sl@0
|
139 |
c.iSignals=KCapsSignalCTSSupported|KCapsSignalRTSSupported|KCapsSignalDTRSupported|
|
sl@0
|
140 |
KCapsSignalDSRSupported|KCapsSignalDCDSupported|KCapsSignalRNGSupported;
|
sl@0
|
141 |
c.iFifo=KCapsHasFifo;
|
sl@0
|
142 |
c.iNotificationCaps=KNotifyDataAvailableSupported|KNotifySignalsChangeSupported;
|
sl@0
|
143 |
c.iRoleCaps=0;
|
sl@0
|
144 |
c.iFlowControlCaps=0;
|
sl@0
|
145 |
c.iBreakSupported=ETrue;
|
sl@0
|
146 |
aCaps.FillZ(aCaps.MaxLength());
|
sl@0
|
147 |
aCaps=capsBuf.Left(Min(capsBuf.Length(),aCaps.MaxLength()));
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
void DDriverComm::GetCaps(TDes8 &aDes) const
|
sl@0
|
151 |
//
|
sl@0
|
152 |
// Return the drivers capabilities
|
sl@0
|
153 |
//
|
sl@0
|
154 |
{
|
sl@0
|
155 |
Get16550CommsCaps(aDes, 0);
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
TInt DDriverComm::Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer)
|
sl@0
|
159 |
//
|
sl@0
|
160 |
// Create a driver
|
sl@0
|
161 |
//
|
sl@0
|
162 |
{
|
sl@0
|
163 |
DComm16550* pD=new DComm16550;
|
sl@0
|
164 |
aChannel=pD;
|
sl@0
|
165 |
TInt r=KErrNoMemory;
|
sl@0
|
166 |
if (pD)
|
sl@0
|
167 |
r=pD->DoCreate(aUnit,anInfo);
|
sl@0
|
168 |
return r;
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
TInt DDriverComm::Validate(TInt aUnit, const TDesC8* /*anInfo*/, const TVersion& aVer)
|
sl@0
|
172 |
//
|
sl@0
|
173 |
// Validate the requested configuration
|
sl@0
|
174 |
//
|
sl@0
|
175 |
{
|
sl@0
|
176 |
if ((!Kern::QueryVersionSupported(iVersion,aVer)) || (!Kern::QueryVersionSupported(aVer,TVersion(KMinimumLddMajorVersion,KMinimumLddMinorVersion,KMinimumLddBuild))))
|
sl@0
|
177 |
return KErrNotSupported;
|
sl@0
|
178 |
if (aUnit<0 || aUnit>=KNum16550Uarts)
|
sl@0
|
179 |
return KErrNotSupported;
|
sl@0
|
180 |
return KErrNone;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
DComm16550::DComm16550()
|
sl@0
|
184 |
//
|
sl@0
|
185 |
// Constructor
|
sl@0
|
186 |
//
|
sl@0
|
187 |
{
|
sl@0
|
188 |
// iTransmitting=EFalse;
|
sl@0
|
189 |
iInterruptId=-1; // -1 means not bound
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
DComm16550::~DComm16550()
|
sl@0
|
193 |
//
|
sl@0
|
194 |
// Destructor
|
sl@0
|
195 |
//
|
sl@0
|
196 |
{
|
sl@0
|
197 |
if (iInterruptId>=0)
|
sl@0
|
198 |
Interrupt::Unbind(iInterruptId);
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
TInt DComm16550::DoCreate(TInt aUnit, const TDesC8* /*anInfo*/)
|
sl@0
|
202 |
//
|
sl@0
|
203 |
// Sets up the PDD
|
sl@0
|
204 |
//
|
sl@0
|
205 |
{
|
sl@0
|
206 |
iUnit=aUnit;
|
sl@0
|
207 |
TInt irq=IrqFromUnit(aUnit);
|
sl@0
|
208 |
|
sl@0
|
209 |
// bind to UART interrupt
|
sl@0
|
210 |
TInt r=Interrupt::Bind(irq,Isr,this);
|
sl@0
|
211 |
if (r==KErrNone)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
iInterruptId=irq;
|
sl@0
|
214 |
iUart=UartFromUnit(aUnit);
|
sl@0
|
215 |
iUart->SetIER(0);
|
sl@0
|
216 |
iUart->SetLCR(0);
|
sl@0
|
217 |
iUart->SetFCR(0);
|
sl@0
|
218 |
iUart->SetMCR(0);
|
sl@0
|
219 |
}
|
sl@0
|
220 |
return r;
|
sl@0
|
221 |
}
|
sl@0
|
222 |
|
sl@0
|
223 |
TDfcQue* DComm16550::DfcQ(TInt /*aUnit*/)
|
sl@0
|
224 |
//
|
sl@0
|
225 |
// Return the DFC queue to be used for this device
|
sl@0
|
226 |
// For PC cards, use the PC card controller thread for the socket in question.
|
sl@0
|
227 |
//
|
sl@0
|
228 |
|
sl@0
|
229 |
{
|
sl@0
|
230 |
return iDfcQ;
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
TInt DComm16550::Start()
|
sl@0
|
234 |
//
|
sl@0
|
235 |
// Start receiving characters
|
sl@0
|
236 |
//
|
sl@0
|
237 |
{
|
sl@0
|
238 |
// if EnableTransmit() called before Start()
|
sl@0
|
239 |
iTransmitting=EFalse;
|
sl@0
|
240 |
iUart->SetIER(K16550IER_RDAI|K16550IER_RLSI|K16550IER_MSI);
|
sl@0
|
241 |
iLdd->UpdateSignals(Signals());
|
sl@0
|
242 |
Interrupt::Enable(iInterruptId);
|
sl@0
|
243 |
return KErrNone;
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
TBool FinishedTransmitting(TAny* aPtr)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
DComm16550& d=*(DComm16550*)aPtr;
|
sl@0
|
249 |
return d.iUart->TestLSR(K16550LSR_TxIdle);
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
void DComm16550::Stop(TStopMode aMode)
|
sl@0
|
253 |
//
|
sl@0
|
254 |
// Stop receiving characters
|
sl@0
|
255 |
//
|
sl@0
|
256 |
{
|
sl@0
|
257 |
switch (aMode)
|
sl@0
|
258 |
{
|
sl@0
|
259 |
case EStopNormal:
|
sl@0
|
260 |
case EStopPwrDown:
|
sl@0
|
261 |
iUart->SetIER(0);
|
sl@0
|
262 |
Interrupt::Disable(iInterruptId);
|
sl@0
|
263 |
iTransmitting=EFalse;
|
sl@0
|
264 |
|
sl@0
|
265 |
// wait for uart to stop tranmitting
|
sl@0
|
266 |
Kern::PollingWait(FinishedTransmitting,this,3,100);
|
sl@0
|
267 |
break;
|
sl@0
|
268 |
case EStopEmergency:
|
sl@0
|
269 |
iUart->SetIER(0);
|
sl@0
|
270 |
Interrupt::Disable(iInterruptId);
|
sl@0
|
271 |
iTransmitting=EFalse;
|
sl@0
|
272 |
break;
|
sl@0
|
273 |
}
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
void DComm16550::Break(TBool aState)
|
sl@0
|
277 |
//
|
sl@0
|
278 |
// Start or stop the uart breaking
|
sl@0
|
279 |
//
|
sl@0
|
280 |
{
|
sl@0
|
281 |
if (aState)
|
sl@0
|
282 |
iUart->ModifyLCR(0,K16550LCR_TxBreak);
|
sl@0
|
283 |
else
|
sl@0
|
284 |
iUart->ModifyLCR(K16550LCR_TxBreak,0);
|
sl@0
|
285 |
}
|
sl@0
|
286 |
|
sl@0
|
287 |
void DComm16550::EnableTransmit()
|
sl@0
|
288 |
//
|
sl@0
|
289 |
// Start sending characters.
|
sl@0
|
290 |
//
|
sl@0
|
291 |
{
|
sl@0
|
292 |
TBool tx = (TBool)__e32_atomic_swp_ord32(&iTransmitting, 1);
|
sl@0
|
293 |
if (tx)
|
sl@0
|
294 |
return;
|
sl@0
|
295 |
iUart->ModifyIER(0,K16550IER_THREI);
|
sl@0
|
296 |
}
|
sl@0
|
297 |
|
sl@0
|
298 |
TUint DComm16550::Signals() const
|
sl@0
|
299 |
//
|
sl@0
|
300 |
// Read and translate the modem lines
|
sl@0
|
301 |
//
|
sl@0
|
302 |
{
|
sl@0
|
303 |
TUint msr=iUart->MSR();
|
sl@0
|
304 |
msr=((msr>>4)&0x0f); // true input signals
|
sl@0
|
305 |
TUint sig=msr & 3; // CTS,DSR OK
|
sl@0
|
306 |
if (msr & 4)
|
sl@0
|
307 |
sig|=KSignalRNG; // swap DCD,RNG
|
sl@0
|
308 |
if (msr & 8)
|
sl@0
|
309 |
sig|=KSignalDCD;
|
sl@0
|
310 |
return sig;
|
sl@0
|
311 |
}
|
sl@0
|
312 |
|
sl@0
|
313 |
void DComm16550::SetSignals(TUint aSetMask, TUint aClearMask)
|
sl@0
|
314 |
//
|
sl@0
|
315 |
// Set signals.
|
sl@0
|
316 |
//
|
sl@0
|
317 |
{
|
sl@0
|
318 |
TUint set=0;
|
sl@0
|
319 |
TUint clear=0;
|
sl@0
|
320 |
if (aSetMask & KSignalRTS)
|
sl@0
|
321 |
set|=K16550MCR_RTS;
|
sl@0
|
322 |
if (aSetMask & KSignalDTR)
|
sl@0
|
323 |
set|=K16550MCR_DTR;
|
sl@0
|
324 |
if (aClearMask & KSignalRTS)
|
sl@0
|
325 |
clear|=K16550MCR_RTS;
|
sl@0
|
326 |
if (aClearMask & KSignalDTR)
|
sl@0
|
327 |
clear|=K16550MCR_DTR;
|
sl@0
|
328 |
iUart->ModifyMCR(clear,set);
|
sl@0
|
329 |
}
|
sl@0
|
330 |
|
sl@0
|
331 |
TInt DComm16550::ValidateConfig(const TCommConfigV01 &aConfig) const
|
sl@0
|
332 |
//
|
sl@0
|
333 |
// Check a config structure.
|
sl@0
|
334 |
//
|
sl@0
|
335 |
{
|
sl@0
|
336 |
if (aConfig.iSIREnable==ESIREnable)
|
sl@0
|
337 |
return KErrNotSupported;
|
sl@0
|
338 |
switch (aConfig.iParity)
|
sl@0
|
339 |
{
|
sl@0
|
340 |
case EParityNone:
|
sl@0
|
341 |
case EParityOdd:
|
sl@0
|
342 |
case EParityEven:
|
sl@0
|
343 |
case EParityMark:
|
sl@0
|
344 |
case EParitySpace:
|
sl@0
|
345 |
break;
|
sl@0
|
346 |
default:
|
sl@0
|
347 |
return KErrNotSupported;
|
sl@0
|
348 |
}
|
sl@0
|
349 |
if (TUint(aConfig.iRate)>TUint(EBps115200))
|
sl@0
|
350 |
return KErrNotSupported;
|
sl@0
|
351 |
return KErrNone;
|
sl@0
|
352 |
}
|
sl@0
|
353 |
|
sl@0
|
354 |
void DComm16550::CheckConfig(TCommConfigV01& aConfig)
|
sl@0
|
355 |
{
|
sl@0
|
356 |
// do nothing
|
sl@0
|
357 |
}
|
sl@0
|
358 |
|
sl@0
|
359 |
TInt DComm16550::DisableIrqs()
|
sl@0
|
360 |
//
|
sl@0
|
361 |
// Disable normal interrupts
|
sl@0
|
362 |
//
|
sl@0
|
363 |
{
|
sl@0
|
364 |
|
sl@0
|
365 |
return NKern::DisableInterrupts(1);
|
sl@0
|
366 |
}
|
sl@0
|
367 |
|
sl@0
|
368 |
void DComm16550::RestoreIrqs(TInt aLevel)
|
sl@0
|
369 |
//
|
sl@0
|
370 |
// Restore normal interrupts
|
sl@0
|
371 |
//
|
sl@0
|
372 |
{
|
sl@0
|
373 |
|
sl@0
|
374 |
NKern::RestoreInterrupts(aLevel);
|
sl@0
|
375 |
}
|
sl@0
|
376 |
|
sl@0
|
377 |
void DComm16550::Configure(TCommConfigV01 &aConfig)
|
sl@0
|
378 |
//
|
sl@0
|
379 |
// Set up the Uart
|
sl@0
|
380 |
//
|
sl@0
|
381 |
{
|
sl@0
|
382 |
// wait for uart to stop tranmitting
|
sl@0
|
383 |
Kern::PollingWait(FinishedTransmitting,this,3,100);
|
sl@0
|
384 |
|
sl@0
|
385 |
TUint lcr=0;
|
sl@0
|
386 |
switch (aConfig.iDataBits)
|
sl@0
|
387 |
{
|
sl@0
|
388 |
case EData5: lcr=K16550LCR_Data5; break;
|
sl@0
|
389 |
case EData6: lcr=K16550LCR_Data6; break;
|
sl@0
|
390 |
case EData7: lcr=K16550LCR_Data7; break;
|
sl@0
|
391 |
case EData8: lcr=K16550LCR_Data8; break;
|
sl@0
|
392 |
}
|
sl@0
|
393 |
switch (aConfig.iStopBits)
|
sl@0
|
394 |
{
|
sl@0
|
395 |
case EStop1: break;
|
sl@0
|
396 |
case EStop2: lcr|=K16550LCR_Stop2; break;
|
sl@0
|
397 |
}
|
sl@0
|
398 |
switch (aConfig.iParity)
|
sl@0
|
399 |
{
|
sl@0
|
400 |
case EParityNone: break;
|
sl@0
|
401 |
case EParityEven: lcr|=K16550LCR_ParityEnable|K16550LCR_ParityEven; break;
|
sl@0
|
402 |
case EParityOdd: lcr|=K16550LCR_ParityEnable; break;
|
sl@0
|
403 |
case EParityMark: lcr|=K16550LCR_ParityEnable|K16550LCR_ParityMark; break;
|
sl@0
|
404 |
case EParitySpace: lcr|=K16550LCR_ParityEnable|K16550LCR_ParitySpace; break;
|
sl@0
|
405 |
}
|
sl@0
|
406 |
iUart->SetLCR(lcr|K16550LCR_DLAB);
|
sl@0
|
407 |
iUart->SetBaudRateDivisor(BaudRateDivisor[(TInt)aConfig.iRate]);
|
sl@0
|
408 |
iUart->SetLCR(lcr);
|
sl@0
|
409 |
iUart->SetFCR(K16550FCR_Enable|K16550FCR_RxReset|K16550FCR_TxReset|K16550FCR_RxTrig8);
|
sl@0
|
410 |
}
|
sl@0
|
411 |
|
sl@0
|
412 |
void DComm16550::Caps(TDes8 &aCaps) const
|
sl@0
|
413 |
//
|
sl@0
|
414 |
// return our caps
|
sl@0
|
415 |
//
|
sl@0
|
416 |
{
|
sl@0
|
417 |
Get16550CommsCaps(aCaps,iUnit);
|
sl@0
|
418 |
}
|
sl@0
|
419 |
|
sl@0
|
420 |
void DComm16550::Isr(TAny* aPtr)
|
sl@0
|
421 |
//
|
sl@0
|
422 |
// Service the UART interrupt
|
sl@0
|
423 |
//
|
sl@0
|
424 |
{
|
sl@0
|
425 |
DComm16550& d=*(DComm16550*)aPtr;
|
sl@0
|
426 |
T16550Uart& u=*d.iUart;
|
sl@0
|
427 |
TUint rx[32];
|
sl@0
|
428 |
TUint xon=d.iLdd->iRxXonChar;
|
sl@0
|
429 |
TUint xoff=d.iLdd->iRxXoffChar;
|
sl@0
|
430 |
|
sl@0
|
431 |
TUint isr=u.ISR();
|
sl@0
|
432 |
if (isr & K16550ISR_NotPending)
|
sl@0
|
433 |
return;
|
sl@0
|
434 |
isr&=K16550ISR_IntIdMask;
|
sl@0
|
435 |
|
sl@0
|
436 |
// if receive data available or line status interrupt
|
sl@0
|
437 |
if (isr==K16550ISR_RDAI || isr==K16550ISR_RLSI)
|
sl@0
|
438 |
{
|
sl@0
|
439 |
TInt rxi=0;
|
sl@0
|
440 |
TInt x=0;
|
sl@0
|
441 |
while(u.TestLSR(K16550LSR_RxReady|K16550LSR_RxParityErr|K16550LSR_RxOverrun|K16550LSR_RxFrameErr|K16550LSR_RxBreak) && Kern::PowerGood())
|
sl@0
|
442 |
{
|
sl@0
|
443 |
TUint lsr=0;
|
sl@0
|
444 |
// checks for EIF flag
|
sl@0
|
445 |
if (isr==K16550ISR_RLSI)
|
sl@0
|
446 |
lsr=u.LSR()&(K16550LSR_RxParityErr|K16550LSR_RxOverrun|K16550LSR_RxFrameErr);
|
sl@0
|
447 |
TUint ch=u.RxData();
|
sl@0
|
448 |
// if error in this character
|
sl@0
|
449 |
if(lsr)
|
sl@0
|
450 |
{
|
sl@0
|
451 |
if (lsr & K16550LSR_RxParityErr)
|
sl@0
|
452 |
ch|=KReceiveIsrParityError;
|
sl@0
|
453 |
if (lsr & K16550LSR_RxBreak)
|
sl@0
|
454 |
ch|=KReceiveIsrBreakError;
|
sl@0
|
455 |
if (lsr & K16550LSR_RxFrameErr)
|
sl@0
|
456 |
ch|=KReceiveIsrFrameError;
|
sl@0
|
457 |
if (lsr & K16550LSR_RxOverrun)
|
sl@0
|
458 |
ch|=KReceiveIsrOverrunError;
|
sl@0
|
459 |
}
|
sl@0
|
460 |
if (ch==xon)
|
sl@0
|
461 |
x=1;
|
sl@0
|
462 |
else if (ch==xoff)
|
sl@0
|
463 |
x=-1;
|
sl@0
|
464 |
else
|
sl@0
|
465 |
rx[rxi++]=ch;
|
sl@0
|
466 |
}
|
sl@0
|
467 |
d.ReceiveIsr(rx,rxi,x);
|
sl@0
|
468 |
return;
|
sl@0
|
469 |
}
|
sl@0
|
470 |
// if TFS flag and TIE
|
sl@0
|
471 |
if (isr==K16550ISR_THREI)
|
sl@0
|
472 |
{
|
sl@0
|
473 |
TInt n;
|
sl@0
|
474 |
for (n=0; n<16; ++n)
|
sl@0
|
475 |
{
|
sl@0
|
476 |
TInt r=d.TransmitIsr();
|
sl@0
|
477 |
if(r<0)
|
sl@0
|
478 |
{
|
sl@0
|
479 |
//no more to send
|
sl@0
|
480 |
// Disable the TX interrupt
|
sl@0
|
481 |
u.ModifyIER(K16550IER_THREI,0);
|
sl@0
|
482 |
d.iTransmitting=EFalse;
|
sl@0
|
483 |
break;
|
sl@0
|
484 |
}
|
sl@0
|
485 |
u.SetTxData(r);
|
sl@0
|
486 |
}
|
sl@0
|
487 |
d.CheckTxBuffer();
|
sl@0
|
488 |
return;
|
sl@0
|
489 |
}
|
sl@0
|
490 |
// must be signal change
|
sl@0
|
491 |
d.StateIsr(d.Signals());
|
sl@0
|
492 |
}
|
sl@0
|
493 |
|
sl@0
|
494 |
|
sl@0
|
495 |
const TInt KUart16550ThreadPriority = 27;
|
sl@0
|
496 |
_LIT(KUar16550tDriverThread,"UART16550_Thread");
|
sl@0
|
497 |
|
sl@0
|
498 |
DECLARE_STANDARD_PDD()
|
sl@0
|
499 |
{
|
sl@0
|
500 |
return new DDriverComm;
|
sl@0
|
501 |
}
|
sl@0
|
502 |
|