author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 23 Jun 2010 19:44:53 +0300 | |
changeset 200 | 73ea206103e6 |
parent 109 | b3a1d9898418 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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 |
// template\template_variant\specific\uart.cpp |
|
15 |
// pdd for serial ports |
|
16 |
// assume Modem Control Signals change cause an interrupt |
|
17 |
// |
|
18 |
// |
|
19 |
||
20 |
||
21 |
#include <drivers/comm.h> |
|
22 |
#include <template_assp.h> |
|
23 |
#include "iolines.h" |
|
24 |
#include <e32hal.h> |
|
25 |
||
26 |
_LIT(KPddName,"Comm.Template"); |
|
27 |
||
28 |
// needs ldd version.. |
|
29 |
const TInt KMinimumLddMajorVersion=1; |
|
30 |
const TInt KMinimumLddMinorVersion=1; |
|
31 |
const TInt KMinimumLddBuild=122; |
|
32 |
||
33 |
// |
|
34 |
// TO DO: (mandatory) |
|
35 |
// |
|
36 |
// Define here the UART enumeration data for the serial ports. |
|
37 |
// It is a good idea to define each enumerated value as a bit mask that can be written to (or OR-ed or AND-ed to) |
|
38 |
// a hardware register to provide the configuration option desired (the following are EXAMPLES ONLY): |
|
39 |
// |
|
40 |
// EXAMPLE ONLY |
|
41 |
enum TUartBaudRate |
|
42 |
{ |
|
43 |
EUartBaudRate115200/* =bitmask for 115200 Baud */, |
|
44 |
EUartBaudRate76800/* =bitmask for 76800 Baud */, |
|
45 |
EUartBaudRate57600/* =bitmask for 57600 Baud */, |
|
46 |
EUartBaudRate38400/* =bitmask for 38400 Baud */, |
|
47 |
EUartBaudRate19200/* =bitmask for 19200 Baud */, |
|
48 |
EUartBaudRate14400/* =bitmask for 14400 Baud */, |
|
49 |
EUartBaudRate9600/* =bitmask for 9600 Baud */, |
|
50 |
EUartBaudRate4800/* =bitmask for 4800 Baud */, |
|
51 |
EUartBaudRate2400/* =bitmask for 2400 Baud */, |
|
52 |
EUartBaudRate1200/* =bitmask for 1200 Baud */, |
|
53 |
EUartBaudRate600/* =bitmask for 600 Baud */, |
|
54 |
EUartBaudRate300/* =bitmask for 300 Baud */, |
|
55 |
EUartBaudRate150/* =bitmask for 150 Baud */, |
|
56 |
EUartBaudRate110/* =bitmask for 110 Baud */ |
|
57 |
}; |
|
58 |
// EXAMPLE ONLY |
|
59 |
enum TUartBreak |
|
60 |
{ |
|
61 |
EUartBreakOff/* =bitmask for turning Break Off */, |
|
62 |
EUartBreakOn/* =bitmask for turning Break On */ |
|
63 |
}; |
|
64 |
// EXAMPLE ONLY |
|
65 |
enum TUartParity |
|
66 |
{ |
|
67 |
EUartParityNone/* =bitmask for no Parity */, |
|
68 |
EUartParityOdd/* =bitmask for odd Parity */, |
|
69 |
EUartParityEven/* =bitmask for even Parity */ |
|
70 |
}; |
|
71 |
// EXAMPLE ONLY |
|
72 |
enum TUartStopBit |
|
73 |
{ |
|
74 |
EUartStopBitOne/* =bitmask for one stop bit */, |
|
75 |
EUartStopBitTwo/* =bitmask for two stop bits */ |
|
76 |
}; |
|
77 |
enum TUartDataLength |
|
78 |
{ |
|
79 |
EUartDataLength5/* =bitmask for five data bits */, |
|
80 |
EUartDataLength6/* =bitmask for six data bits */, |
|
81 |
EUartDataLength7/* =bitmask for seven data bits */, |
|
82 |
EUartDataLength8/* =bitmask for eight data bits */ |
|
83 |
}; |
|
84 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
//Remove the #if block if this code needs to be used or referenced. |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
#if 0 //RVCT40 warning |
0 | 87 |
// |
88 |
// TO DO: (mandatory) |
|
89 |
// |
|
90 |
// Lookup table to convert EPOC baud rates into hardware-specific baud rate values |
|
91 |
// Unsupported baud rates select the nearest lower rate. |
|
92 |
// |
|
93 |
// EXAMPLE ONLY |
|
94 |
static const TUartBaudRate BaudRate[19] = |
|
95 |
{ |
|
96 |
EUartBaudRate110,EUartBaudRate110,EUartBaudRate110, |
|
97 |
EUartBaudRate110,EUartBaudRate150,EUartBaudRate300, |
|
98 |
EUartBaudRate600,EUartBaudRate1200,EUartBaudRate110, |
|
99 |
EUartBaudRate110,EUartBaudRate2400,EUartBaudRate110, |
|
100 |
EUartBaudRate4800,EUartBaudRate110,EUartBaudRate9600, |
|
101 |
EUartBaudRate19200,EUartBaudRate38400,EUartBaudRate57600, |
|
102 |
EUartBaudRate115200 |
|
103 |
}; |
|
104 |
||
105 |
// |
|
106 |
// TO DO: (mandatory) |
|
107 |
// |
|
108 |
// Lookup table to convert EPOC parity settings into hardware-specific values |
|
109 |
// |
|
110 |
// EXAMPLE ONLY |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
111 |
|
0 | 112 |
static const TUartParity Parity[3] = |
113 |
{ |
|
114 |
EUartParityNone,EUartParityEven,EUartParityOdd |
|
115 |
}; |
|
116 |
||
117 |
// |
|
118 |
// TO DO: (mandatory) |
|
119 |
// |
|
120 |
// Lookup table to convert EPOC stop bit values into hardware-specific values |
|
121 |
// |
|
122 |
// EXAMPLE ONLY |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
|
0 | 124 |
static const TUartStopBit StopBit[2] = |
125 |
{ |
|
126 |
EUartStopBitOne,EUartStopBitTwo |
|
127 |
}; |
|
128 |
||
129 |
// |
|
130 |
// TO DO: (mandatory) |
|
131 |
// |
|
132 |
// Lookup table to convert EPOC data bit settings into hardware-specific values |
|
133 |
// |
|
134 |
// EXAMPLE ONLY |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
|
0 | 136 |
static const TUartDataLength DataLength[4] = |
137 |
{ |
|
138 |
EUartDataLength5,EUartDataLength6, |
|
139 |
EUartDataLength7,EUartDataLength8 |
|
140 |
}; |
|
141 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
#endif //RVCT40 warning |
0 | 143 |
|
144 |
||
145 |
class DDriverComm : public DPhysicalDevice |
|
146 |
{ |
|
147 |
public: |
|
148 |
DDriverComm(); |
|
149 |
virtual TInt Install(); |
|
150 |
virtual void GetCaps(TDes8 &aDes) const; |
|
151 |
virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion &aVer); |
|
152 |
virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion &aVer); |
|
153 |
}; |
|
154 |
||
155 |
class DCommTemplate : public DComm |
|
156 |
{ |
|
157 |
public: |
|
158 |
DCommTemplate(); |
|
159 |
~DCommTemplate(); |
|
160 |
TInt DoCreate(TInt aUnit, const TDesC8* anInfo); |
|
161 |
public: |
|
162 |
virtual TInt Start(); |
|
163 |
virtual void Stop(TStopMode aMode); |
|
164 |
virtual void Break(TBool aState); |
|
165 |
virtual void EnableTransmit(); |
|
166 |
virtual TUint Signals() const; |
|
167 |
virtual void SetSignals(TUint aSetMask,TUint aClearMask); |
|
168 |
virtual TInt ValidateConfig(const TCommConfigV01 &aConfig) const; |
|
169 |
virtual void Configure(TCommConfigV01 &aConfig); |
|
170 |
virtual void Caps(TDes8 &aCaps) const; |
|
171 |
virtual TInt DisableIrqs(); |
|
172 |
virtual void RestoreIrqs(TInt aIrq); |
|
173 |
virtual TDfcQue* DfcQ(TInt aUnit); |
|
174 |
virtual void CheckConfig(TCommConfigV01& aConfig); |
|
175 |
public: |
|
176 |
static void Isr(TAny* aPtr); |
|
177 |
public: |
|
178 |
TInt iInterruptId; |
|
179 |
TInt iUnit; |
|
180 |
TLinAddr iPortAddr; |
|
181 |
TInt iInInterrupt; |
|
182 |
TUint iSignals; |
|
183 |
TDynamicDfcQue* iDfcQ; |
|
184 |
}; |
|
185 |
||
186 |
||
187 |
DDriverComm::DDriverComm() |
|
188 |
// |
|
189 |
// Constructor |
|
190 |
// |
|
191 |
{ |
|
192 |
// |
|
193 |
// TO DO: (mandatory) |
|
194 |
// |
|
195 |
// Set up iUnitMask with the number of Units (Serial Ports) supported by this PDD, |
|
196 |
// 1 bit set per Unit supported e.g.: |
|
197 |
// iUnitsMask=0x7; -> supports units 0, 1, 2 |
|
198 |
// |
|
199 |
iVersion=TVersion(KCommsMajorVersionNumber,KCommsMinorVersionNumber,KCommsBuildVersionNumber); |
|
200 |
} |
|
201 |
||
202 |
TInt DDriverComm::Install() |
|
203 |
// |
|
204 |
// Install the driver |
|
205 |
// |
|
206 |
{ |
|
207 |
||
208 |
return SetName(&KPddName); |
|
209 |
} |
|
210 |
||
211 |
void GetTemplateCommsCaps(TDes8 &aCaps, TInt aUnit) |
|
212 |
{ |
|
213 |
TCommCaps2 capsBuf; |
|
214 |
// |
|
215 |
// TO DO: (mandatory) |
|
216 |
// |
|
217 |
// Fill in the Caps structure with the relevant information for this Unit, e.g |
|
218 |
// TCommCapsV02 &c=capsBuf(); |
|
219 |
// c.iRate=(OR in as many KCapsBpsXXX as bit rates supported); |
|
220 |
// c.iDataBits=(OR in as many KCapsDataXXX as data length configuration supported); |
|
221 |
// c.iStopBits=(OR in as many KCapsStopXXX as the number of stop bits configurations supported); |
|
222 |
// c.iParity=(OR in as many KCapsParityXXX as parity configuration supported); |
|
223 |
// c.iHandshake=(OR in all KCapsObeyXXXSupported, KCapsSendXXXSupported, KCapsFailXXXSupported, KCapsFreeXXXSupported |
|
224 |
// as required for this Unit's configuration);. |
|
225 |
// c.iSignals=(OR in as many KCapsSignalXXXSupported as Modem control signals controllable by this Unit); |
|
226 |
// c.iSIR=(0 or OR in as many KCapsSIRXXX as IR bit rates supported); |
|
227 |
// c.iNotificationCaps=(OR in as many KNotifyXXXSupported as notifications supported by this Unit); |
|
228 |
// c.iFifo=(0 or KCapsHasFifo); |
|
229 |
// c.iRoleCaps=(0 or KCapsRoleSwitchSupported); |
|
230 |
// c.iFlowControlCaps=(0 or KCapsFlowControlStatusSupported); |
|
231 |
/** @see TCommCapsV02 */ |
|
232 |
// |
|
233 |
aCaps.FillZ(aCaps.MaxLength()); |
|
234 |
aCaps=capsBuf.Left(Min(capsBuf.Length(),aCaps.MaxLength())); |
|
235 |
} |
|
236 |
||
237 |
void DDriverComm::GetCaps(TDes8 &aDes) const |
|
238 |
// |
|
239 |
// Return the drivers capabilities |
|
240 |
// |
|
241 |
{ |
|
242 |
GetTemplateCommsCaps(aDes, 0); |
|
243 |
} |
|
244 |
||
245 |
TInt DDriverComm::Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer) |
|
246 |
// |
|
247 |
// Create a driver |
|
248 |
// |
|
249 |
{ |
|
250 |
DCommTemplate* pD=new DCommTemplate; |
|
251 |
aChannel=pD; |
|
252 |
TInt r=KErrNoMemory; |
|
253 |
if (pD) |
|
254 |
r=pD->DoCreate(aUnit,anInfo); |
|
255 |
return r; |
|
256 |
} |
|
257 |
||
258 |
TInt DDriverComm::Validate(TInt aUnit, const TDesC8* /*anInfo*/, const TVersion& aVer) |
|
259 |
// |
|
260 |
// Validate the requested configuration (Version and Unit) |
|
261 |
// |
|
262 |
{ |
|
263 |
if ((!Kern::QueryVersionSupported(iVersion,aVer)) || (!Kern::QueryVersionSupported(aVer,TVersion(KMinimumLddMajorVersion,KMinimumLddMinorVersion,KMinimumLddBuild)))) |
|
264 |
return KErrNotSupported; |
|
265 |
// |
|
266 |
// TO DO: (mandatory) |
|
267 |
// |
|
268 |
// Return KErrNotSupported if aUnit is not in the supported range for this driver, KErrNone if it is |
|
269 |
// |
|
270 |
return KErrNone; |
|
271 |
} |
|
272 |
||
273 |
DCommTemplate::DCommTemplate() |
|
274 |
// |
|
275 |
// Constructor |
|
276 |
// |
|
277 |
{ |
|
278 |
iInterruptId=-1; // -1 means not bound |
|
279 |
} |
|
280 |
||
281 |
DCommTemplate::~DCommTemplate() |
|
282 |
// |
|
283 |
// Destructor |
|
284 |
// |
|
285 |
{ |
|
286 |
if (iInterruptId>=0) |
|
287 |
Interrupt::Unbind(iInterruptId); |
|
288 |
||
289 |
if (iDfcQ) |
|
290 |
{ |
|
291 |
iDfcQ->Destroy(); |
|
292 |
} |
|
293 |
} |
|
294 |
||
295 |
const TInt KDCommTemplDfcThreadPriority = 24; |
|
296 |
_LIT(KDCommTemplDfcThread,"DCommTemplDfcThread"); |
|
297 |
||
298 |
TInt DCommTemplate::DoCreate(TInt aUnit, const TDesC8* /*anInfo*/) |
|
299 |
// |
|
300 |
// Sets up the PDD |
|
301 |
// |
|
302 |
{ |
|
303 |
iUnit=aUnit; |
|
304 |
TInt irq=-1; |
|
305 |
// |
|
306 |
// TO DO: (mandatory) |
|
307 |
// |
|
308 |
// Create own DFC queue |
|
309 |
TInt r = Kern::DynamicDfcQCreate(iDfcQ, KDCommTemplDfcThreadPriority, KDCommTemplDfcThread); |
|
310 |
||
311 |
if (r != KErrNone) |
|
312 |
return r; |
|
313 |
||
314 |
// Set iPortAddr and irq with the Linear Base address of the UART and the Interrupt ID coresponding to aUnit |
|
315 |
// |
|
316 |
||
317 |
// bind to UART interrupt |
|
318 |
r=Interrupt::Bind(irq,Isr,this); |
|
319 |
if (r==KErrNone) |
|
320 |
iInterruptId=irq; |
|
321 |
||
322 |
// |
|
323 |
// TO DO: (optional) |
|
324 |
// |
|
325 |
// Any other setting up of UART hardware registers, required for: |
|
326 |
// - Disabling the UART operation |
|
327 |
// - disabling all UART Interrupts |
|
328 |
// - clearing all Rx errors |
|
329 |
// - clearing all UART interrupts |
|
330 |
// - de-activating output Modem Control signals |
|
331 |
// |
|
332 |
||
333 |
Variant::MarkDebugPortOff(); |
|
334 |
return r; |
|
335 |
} |
|
336 |
||
337 |
TDfcQue* DCommTemplate::DfcQ(TInt aUnit) |
|
338 |
// |
|
339 |
// Return the DFC queue to be used for this device |
|
340 |
// For UARTs just use the standard low priority DFC queue |
|
341 |
// For Serial PC cards, use the PC card controller thread for the socket in question. |
|
342 |
// |
|
343 |
{ |
|
344 |
return aUnit==iUnit ? iDfcQ : NULL; |
|
345 |
} |
|
346 |
||
347 |
TInt DCommTemplate::Start() |
|
348 |
// |
|
349 |
// Start receiving characters |
|
350 |
// |
|
351 |
{ |
|
352 |
iTransmitting=EFalse; // if EnableTransmit() called before Start() |
|
353 |
||
354 |
// |
|
355 |
// TO DO: (mandatory) |
|
356 |
// |
|
357 |
// Set up hardware registers to enable the UART and switch receive mode on |
|
358 |
// |
|
359 |
||
360 |
// if (iUnit!=IR Port) TO DO: (mandatory): Implement |
|
361 |
{ |
|
362 |
iSignals=Signals(); |
|
363 |
iLdd->UpdateSignals(iSignals); |
|
364 |
} |
|
365 |
||
366 |
// |
|
367 |
// TO DO: (optional) |
|
368 |
// |
|
369 |
// If Unit is IR Port may need to start the IR port |
|
370 |
// |
|
371 |
Interrupt::Enable(iInterruptId); |
|
372 |
return KErrNone; |
|
373 |
} |
|
374 |
||
375 |
TBool FinishedTransmitting(TAny* aPtr) |
|
376 |
{ |
|
377 |
// |
|
378 |
// TO DO: (mandatory) |
|
379 |
// |
|
380 |
// Return ETrue if UART is still transmitting, EFalse Otherwise |
|
381 |
// |
|
382 |
return EFalse; // EXAMPLE ONLY |
|
383 |
} |
|
384 |
||
385 |
void DCommTemplate::Stop(TStopMode aMode) |
|
386 |
// |
|
387 |
// Stop receiving characters |
|
388 |
// |
|
389 |
{ |
|
390 |
switch (aMode) |
|
391 |
{ |
|
392 |
case EStopNormal: |
|
393 |
case EStopPwrDown: |
|
394 |
Interrupt::Disable(iInterruptId); |
|
395 |
iTransmitting=EFalse; |
|
396 |
||
397 |
// wait for uart to stop tranmitting |
|
398 |
Kern::PollingWait(FinishedTransmitting,this,3,100); |
|
399 |
||
400 |
// |
|
401 |
// TO DO: (optional) |
|
402 |
// |
|
403 |
// Any other setting up of UART hardware registers, required for: |
|
404 |
// - Disabling the UART operation |
|
405 |
// - disabling all UART Interrupts |
|
406 |
// - disabling Transmit and Receive pathes |
|
407 |
// - clearing all UART interrupts |
|
408 |
// |
|
409 |
break; |
|
410 |
case EStopEmergency: |
|
411 |
Interrupt::Disable(iInterruptId); |
|
412 |
iTransmitting=EFalse; |
|
413 |
break; |
|
414 |
} |
|
415 |
// |
|
416 |
// TO DO: (optional) |
|
417 |
// |
|
418 |
// If Unit is IR Port may need to stop the IR port |
|
419 |
// |
|
420 |
Variant::MarkDebugPortOff(); |
|
421 |
} |
|
422 |
||
423 |
void DCommTemplate::Break(TBool aState) |
|
424 |
// |
|
425 |
// Start or stop the uart breaking |
|
426 |
// |
|
427 |
{ |
|
428 |
if (aState) |
|
429 |
{ |
|
430 |
// |
|
431 |
// TO DO: (mandatory) |
|
432 |
// |
|
433 |
// Enable sending a Break (space) condition |
|
434 |
// |
|
435 |
} |
|
436 |
else |
|
437 |
{ |
|
438 |
// |
|
439 |
// TO DO: (mandatory) |
|
440 |
// |
|
441 |
// Stop sending a Break (space) condition |
|
442 |
// |
|
443 |
} |
|
444 |
} |
|
445 |
||
446 |
void DCommTemplate::EnableTransmit() |
|
447 |
// |
|
448 |
// Start sending characters. |
|
449 |
// |
|
450 |
{ |
|
451 |
TBool tx = (TBool)__e32_atomic_swp_ord32(&iTransmitting, 1); |
|
452 |
if (tx) |
|
453 |
return; |
|
454 |
TInt r = 0; |
|
455 |
while (/* (Transmit FIFO Not full) && */ Kern::PowerGood()) // TO DO: (mandatory): Implement |
|
456 |
{ |
|
457 |
TInt r=TransmitIsr(); |
|
458 |
if(r<0) |
|
459 |
{ |
|
460 |
//no more to send |
|
461 |
iTransmitting=EFalse; |
|
462 |
break; |
|
463 |
} |
|
464 |
// |
|
465 |
// TO DO: (mandatory) |
|
466 |
// |
|
467 |
// Write transmit character into transmit FIFO or output register |
|
468 |
// |
|
469 |
} |
|
470 |
TInt irq=0; |
|
471 |
if (!iInInterrupt) // CheckTxBuffer adds a Dfc: can only run from ISR or with NKernel locked |
|
472 |
{ |
|
473 |
NKern::Lock(); |
|
474 |
irq=NKern::DisableAllInterrupts(); |
|
475 |
} |
|
476 |
CheckTxBuffer(); |
|
477 |
if (!iInInterrupt) |
|
478 |
{ |
|
479 |
NKern::RestoreInterrupts(irq); |
|
480 |
NKern::Unlock(); |
|
481 |
} |
|
482 |
// |
|
483 |
// TO DO: (mandatory) |
|
484 |
// |
|
485 |
// Enable transmission of data |
|
486 |
// |
|
487 |
if (r>=0) // only enable interrupt if there's more data to send |
|
488 |
{ |
|
489 |
// |
|
490 |
// TO DO: (mandatory) |
|
491 |
// |
|
492 |
// Enable transmit interrupt in the Hardware (Interrupt::Enable() has already been called in Start()) |
|
493 |
// |
|
494 |
} |
|
495 |
} |
|
496 |
||
497 |
TUint DCommTemplate::Signals() const |
|
498 |
// |
|
499 |
// Read and translate the modem lines |
|
500 |
// |
|
501 |
{ |
|
502 |
TUint signals=0; |
|
503 |
// |
|
504 |
// TO DO: (mandatory) |
|
505 |
// |
|
506 |
// If the UART corresponding to iUnit supports Modem Control Signals, read them and return a bitmask with one or |
|
507 |
// more of the following OR-ed in: |
|
508 |
// - KSignalDTR, |
|
509 |
// - KSignalRTS, |
|
510 |
// - KSignalDSR, |
|
511 |
// - KSignalCTS, |
|
512 |
// - KSignalDCD. |
|
513 |
// |
|
514 |
return signals; |
|
515 |
} |
|
516 |
||
517 |
void DCommTemplate::SetSignals(TUint aSetMask, TUint aClearMask) |
|
518 |
// |
|
519 |
// Set signals. |
|
520 |
// |
|
521 |
{ |
|
522 |
// |
|
523 |
// TO DO: (mandatory) |
|
524 |
// |
|
525 |
// If the UART corresponding to iUnit supports Modem Control Signals, converts the flags in aSetMask and aClearMask |
|
526 |
// into hardware-specific bitmasks to write to the UART modem/handshake output register(s). |
|
527 |
// aSetMask, aClearMask will have one or more of the following OR-ed in: |
|
528 |
// - KSignalDTR, |
|
529 |
// - KSignalRTS, |
|
530 |
// |
|
531 |
} |
|
532 |
||
533 |
TInt DCommTemplate::ValidateConfig(const TCommConfigV01 &aConfig) const |
|
534 |
// |
|
535 |
// Check a config structure. |
|
536 |
// |
|
537 |
{ |
|
538 |
// |
|
539 |
// TO DO: (mandatory) |
|
540 |
// |
|
541 |
// Checks the the options in aConfig are supported by the UART corresponding to iUnit |
|
542 |
// May need to check: |
|
543 |
// - aConfig.iParity (contains one of EParityXXX) |
|
544 |
/** @see TParity */ |
|
545 |
// - aConfig.iRate (contains one of EBpsXXX) |
|
546 |
/** @see TBps */ |
|
547 |
// - aConfig.iDataBits (contains one of EDataXXX) |
|
548 |
/** @see TDataBits */ |
|
549 |
// - aConfig.iStopBits (contains one of EStopXXX) |
|
550 |
/** @see TDataBits */ |
|
551 |
// - aConfig.iHandshake (contains one of KConfigObeyXXX or KConfigSendXXX or KConfigFailXXX or KConfigFreeXXX) |
|
552 |
// - aConfig.iParityError (contains KConfigParityErrorFail or KConfigParityErrorIgnore or KConfigParityErrorReplaceChar) |
|
553 |
// - aConfig.iFifo (contains ether EFifoEnable or EFifoDisable) |
|
554 |
/** @see TFifo */ |
|
555 |
// - aConfig.iSpecialRate (may contain a rate not listed under TBps) |
|
556 |
// - aConfig.iTerminatorCount (conatains number of special characters used as terminators) |
|
557 |
// - aConfig.iTerminator[] (contains a list of special characters which can be used as terminators) |
|
558 |
// - aConfig.iXonChar (contains the character used as XON - software flow control) |
|
559 |
// - aConfig.iXoffChar (contains the character used as XOFF - software flow control) |
|
560 |
// - aConfig.iParityErrorChar (contains the character used to replace bytes received with a parity error) |
|
561 |
// - aConfig.iSIREnable (contains either ESIREnable or ESIRDisable) |
|
562 |
/** @see TSir */ |
|
563 |
// - aConfig.iSIRSettings (contains one of KConfigSIRXXX) |
|
564 |
// and returns KErrNotSupported if the UART corresponding to iUnit does not support this configuration |
|
565 |
// |
|
566 |
return KErrNone; |
|
567 |
} |
|
568 |
||
569 |
void DCommTemplate::CheckConfig(TCommConfigV01& aConfig) |
|
570 |
{ |
|
571 |
// |
|
572 |
// TO DO: (optional) |
|
573 |
// |
|
574 |
// Validates the default configuration that is defined when a channel is first opened |
|
575 |
// |
|
576 |
} |
|
577 |
||
578 |
TInt DCommTemplate::DisableIrqs() |
|
579 |
// |
|
580 |
// Disable normal interrupts |
|
581 |
// |
|
582 |
{ |
|
583 |
||
584 |
return NKern::DisableInterrupts(1); |
|
585 |
} |
|
586 |
||
587 |
void DCommTemplate::RestoreIrqs(TInt aLevel) |
|
588 |
// |
|
589 |
// Restore normal interrupts |
|
590 |
// |
|
591 |
{ |
|
592 |
||
593 |
NKern::RestoreInterrupts(aLevel); |
|
594 |
} |
|
595 |
||
596 |
void DCommTemplate::Configure(TCommConfigV01 &aConfig) |
|
597 |
// |
|
598 |
// Configure the UART from aConfig |
|
599 |
// |
|
600 |
{ |
|
601 |
Kern::PollingWait(FinishedTransmitting,this,3,100); // wait for uart to stop tranmitting |
|
602 |
||
603 |
// |
|
604 |
// TO DO: (optional) |
|
605 |
// |
|
606 |
// Ensure Tx, Rx and the UART are disabled and disable sending Break (space) condition. |
|
607 |
// May need to modify clocks settings, pin functions etc. |
|
608 |
// |
|
609 |
||
610 |
// |
|
611 |
// TO DO: (mandatory) |
|
612 |
// |
|
613 |
// Set communications parameters such as: |
|
614 |
// - Baud rate |
|
615 |
// - Parity |
|
616 |
// - Stop bits |
|
617 |
// - Data bits |
|
618 |
// These can be obtained from aConfig using the look-up tables above, e.g. |
|
619 |
// TUint baudRate=BaudRate[aConfig.iRate]; |
|
620 |
// TUint parity=Parity[aConfig.iParity]; |
|
621 |
// TUint stopBits=StopBit[aConfig.iStopBits]; |
|
622 |
// TUint dataBits=DataLength[aConfig.iDataBits]; |
|
623 |
// Write these to the appropriate hardware registers using iPortAddr to identify which ste of register to modify |
|
624 |
// |
|
625 |
||
626 |
// |
|
627 |
// TO DO: (optional) |
|
628 |
// |
|
629 |
// If the UART corresponding to iUnit supports IR may need to set up IR transceiver |
|
630 |
// |
|
631 |
} |
|
632 |
||
633 |
void DCommTemplate::Caps(TDes8 &aCaps) const |
|
634 |
// |
|
635 |
// return our caps |
|
636 |
// |
|
637 |
{ |
|
638 |
GetTemplateCommsCaps(aCaps,iUnit); |
|
639 |
} |
|
640 |
||
641 |
void DCommTemplate::Isr(TAny* aPtr) |
|
642 |
// |
|
643 |
// Service the UART interrupt |
|
644 |
// |
|
645 |
{ |
|
646 |
DCommTemplate& d=*(DCommTemplate*)aPtr; |
|
647 |
d.iInInterrupt=1; // going in... |
|
648 |
// TUint portAddr=d.iPortAddr; TO DO: (mandatory): Uncomment this |
|
649 |
||
650 |
// |
|
651 |
// TO DO: (mandatory) |
|
652 |
// |
|
653 |
// Read the interrupt source register to determine if it is a Receive, Transmit or Modem Signals change interrupt. |
|
654 |
// If required also, clear interrupts at the source. |
|
655 |
// Then process the interrupt condition as in the following pseudo-code extract: |
|
656 |
// |
|
657 |
// if((Received character Interrupts) || (Error in received character Interupt)) TO DO: (mandatory): Implement |
|
658 |
{ |
|
659 |
TUint rx[32]; |
|
660 |
TUint xon=d.iLdd->iRxXonChar; |
|
661 |
TUint xoff=d.iLdd->iRxXoffChar; |
|
662 |
TInt rxi=0; |
|
663 |
TInt x=0; |
|
664 |
TUint ch=0; |
|
665 |
// while((Receive FIFO not empty) && Kern::PowerGood()) TO DO: (mandatory): Implement |
|
666 |
{ |
|
667 |
TUint regStatus1=0; |
|
668 |
// NOTE: for some hardware the order the following 2 operations is performed may have to be reversed |
|
669 |
// if(Error in received character interrupt) TO DO: (mandatory): Implement |
|
670 |
// regStatus1=(Read receive error bitmask off appropriate register); |
|
671 |
// ch=(Read received character); |
|
672 |
||
673 |
// coverity[dead_error_condition] |
|
674 |
// The next line should be reachable when this template file is edited for use |
|
675 |
if(regStatus1!=0) // if error in this character |
|
676 |
{ |
|
677 |
// if (ch & (Parity Error)) TO DO: (mandatory): Implement |
|
678 |
ch|=KReceiveIsrParityError; |
|
679 |
// if (ch & (Framing Error)) TO DO: (mandatory): Implement |
|
680 |
ch|=KReceiveIsrFrameError; |
|
681 |
// if (ch & (Overrun)) TO DO: (mandatory): Implement |
|
682 |
ch|=KReceiveIsrOverrunError; |
|
683 |
} |
|
684 |
if (ch==xon) |
|
685 |
x=1; |
|
686 |
else if (ch==xoff) |
|
687 |
x=-1; |
|
688 |
else |
|
689 |
rx[rxi++]=ch; |
|
690 |
} |
|
691 |
d.ReceiveIsr(rx,rxi,x); |
|
692 |
} |
|
693 |
// if((Transmitted character Interrupt)) TO DO: (mandatory): Implement |
|
694 |
{ |
|
695 |
while(/* (Transmit FIFO Not full) && */ Kern::PowerGood()) // TO DO: (mandatory): Implement |
|
696 |
{ |
|
697 |
TInt r=d.TransmitIsr(); |
|
698 |
if(r<0) |
|
699 |
{ |
|
700 |
//no more to send |
|
701 |
// |
|
702 |
// TO DO: (mandatory) |
|
703 |
// |
|
704 |
// Disable the Transmit Interrupt in Hardware |
|
705 |
d.iTransmitting=EFalse; |
|
706 |
break; |
|
707 |
} |
|
708 |
// (write transmit character to output FIFO or Data register) TO DO: (mandatory): Implement |
|
709 |
} |
|
710 |
d.CheckTxBuffer(); |
|
711 |
} |
|
712 |
// if((Modem Signals changed Interrupt)) TO DO: (mandatory): Implement |
|
713 |
{ |
|
714 |
TUint signals=d.Signals()&KDTEInputSignals; |
|
715 |
if (signals != d.iSignals) |
|
716 |
{ |
|
717 |
d.iSignals=signals; |
|
718 |
d.iLdd->StateIsr(signals); |
|
719 |
} |
|
720 |
} |
|
721 |
d.iInInterrupt=0; // going out... |
|
722 |
} |
|
723 |
||
724 |
DECLARE_STANDARD_PDD() |
|
725 |
{ |
|
726 |
return new DDriverComm; |
|
727 |
} |
|
728 |