|
1 // Copyright (c) 1997-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 // e32test\device\t_firco.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include "t_fir.h" |
|
19 |
|
20 #if defined(__VC32__) && _MSC_VER==1100 |
|
21 // Disable MSVC++ 5.0 aggressive warnings about non-expansion of inline functions. |
|
22 #pragma warning(disable : 4710) // function '...' not expanded |
|
23 #endif |
|
24 |
|
25 #ifdef __WINS__ |
|
26 #include <es_sock.h> |
|
27 RSocketServ ss; |
|
28 #endif |
|
29 |
|
30 TBuf8<2060> WriteBuf; |
|
31 TBuf8<2060> ReadBuf; |
|
32 TInt iTimeDelay=1000000; |
|
33 TInt iBufSz=2000; |
|
34 |
|
35 CActiveConsole::CActiveConsole(CConsoleBase* aConsole) |
|
36 : CActive(EPriorityNormal) |
|
37 { |
|
38 iConsole=aConsole; |
|
39 iInit1 =EFalse; |
|
40 iInit2 =EFalse; |
|
41 iInit3 =EFalse; |
|
42 } |
|
43 |
|
44 CActiveConsole* CActiveConsole::NewLC(CConsoleBase* aConsole) |
|
45 { |
|
46 CActiveConsole* self = new (ELeave) CActiveConsole(aConsole); |
|
47 self->ConstructL(); |
|
48 return self; |
|
49 } |
|
50 |
|
51 void CActiveConsole::ConstructL () |
|
52 { |
|
53 TFirCaps aCapsBuf; |
|
54 TFirCapsV01& aCaps=aCapsBuf(); |
|
55 TFirConfig aConfigBuf; |
|
56 TFirConfigV01& aConfig=aConfigBuf(); |
|
57 |
|
58 iConsole->Printf(_L("\r\n")); |
|
59 CActiveScheduler::Add(this); // Add to active scheduler |
|
60 |
|
61 // Load Driver |
|
62 TInt ret=User::LoadPhysicalDevice(_L("Difir")); |
|
63 if (ret!=KErrNone) |
|
64 iConsole->Printf(_L("Error %d on loading Fir PDD\r\n"),ret); |
|
65 else |
|
66 iConsole->Printf(_L("Successfully loaded Fir PDD\r\n")); |
|
67 |
|
68 ret=User::LoadLogicalDevice(_L("Efir")); |
|
69 if (ret!=KErrNone) |
|
70 iConsole->Printf(_L("Error %d on loading Fir LDD\r\n"),ret); |
|
71 else |
|
72 iConsole->Printf(_L("Successfully loaded Fir LDD\r\n")); |
|
73 |
|
74 SetUpBuffers(); |
|
75 |
|
76 ret=iPort.Open(0); |
|
77 if (ret!=KErrNone) |
|
78 iConsole->Printf(_L("Error %d on opening Fastir port\r\n"),ret); |
|
79 else |
|
80 iConsole->Printf(_L("Successfully opened Fastir port\r\n")); |
|
81 |
|
82 |
|
83 ret=iPort.Caps(aCapsBuf); |
|
84 if (ret!=KErrNone) |
|
85 iConsole->Printf(_L("Error %d on getting caps\r\n"),ret); |
|
86 else |
|
87 iConsole->Printf(_L("Fir Caps: %d\r\n"),aCaps.iRate); |
|
88 |
|
89 /* ret=iPort.Config(aConfigBuf); |
|
90 if (ret!=KErrNone) |
|
91 iConsole->Printf(_L("Error %d getting config\r\n"),ret); |
|
92 else |
|
93 { |
|
94 if(aConfig.iRate==EBps4000000) |
|
95 iConsole->Printf(_L("Fir config is 4Mbps\r\n")); |
|
96 } |
|
97 |
|
98 aConfig.iRate=EBps4000000; |
|
99 ret=iPort.SetConfig(aConfigBuf); |
|
100 iConsole->Printf(_L("Error %d on SetConfig\r\n"),ret);*/ |
|
101 |
|
102 iWriter=CActiveWriter::NewL(iConsole,&iPort); |
|
103 if(iWriter) |
|
104 iConsole->Printf(_L("Have created writer\r\n")); |
|
105 else |
|
106 iConsole->Printf(_L("Failed to create writer\r\n")); |
|
107 |
|
108 iReader=CActiveReader::NewL(iConsole,&iPort); |
|
109 if(iReader) |
|
110 iConsole->Printf(_L("Have created reader\r\n")); |
|
111 else |
|
112 iConsole->Printf(_L("Failed to create reader\r\n")); |
|
113 } |
|
114 |
|
115 CActiveConsole::~CActiveConsole() |
|
116 { |
|
117 // Make sure we're cancelled |
|
118 Cancel(); |
|
119 |
|
120 if(iWriter) |
|
121 delete iWriter; |
|
122 if(iReader) |
|
123 delete iReader; |
|
124 |
|
125 iPort.Close(); |
|
126 } |
|
127 |
|
128 void CActiveConsole::DoCancel() |
|
129 { |
|
130 iConsole->ReadCancel(); |
|
131 } |
|
132 |
|
133 void CActiveConsole::RunL() |
|
134 { |
|
135 ProcessKeyPressL(TChar(iConsole->KeyCode())); |
|
136 // iConsole->Printf(_L("CActiveConsole - Completed with code %d\r\n\r\n"), iStatus.Int ()); |
|
137 } |
|
138 |
|
139 void CActiveConsole::RequestCharacter() |
|
140 { |
|
141 if(!iInit1) |
|
142 { |
|
143 Options1(); |
|
144 return; |
|
145 } |
|
146 if(!iInit2) |
|
147 { |
|
148 Options2(); |
|
149 return; |
|
150 } |
|
151 if(!iInit3) |
|
152 { |
|
153 Options3(); |
|
154 return; |
|
155 } |
|
156 // A request is issued to the CConsoleBase to accept a |
|
157 // character from the keyboard. |
|
158 iConsole->Printf(_L("*********************************\r\n")); |
|
159 iConsole->Printf(_L("press Escape to quit\r\n")); |
|
160 iConsole->Printf(_L("press '1'/'2' to start/stop reader\r\n")); |
|
161 iConsole->Printf(_L("press '3'/'4' to start/stop writer\r\n")); |
|
162 iConsole->Printf(_L("press '8' to show FIR regs\r\n")); |
|
163 iConsole->Printf(_L("press '9' to show Dma reader regs\r\n")); |
|
164 iConsole->Printf(_L("press '0' to show Dma writer regs\r\n")); |
|
165 iConsole->Printf(_L("press 'a' to show TxBuf info\r\n")); |
|
166 iConsole->Printf(_L("press 'b' to show RxBuf info\r\n")); |
|
167 iConsole->Printf(_L("press 'c' to show Chunk info\r\n")); |
|
168 iConsole->Printf(_L("press 'd' to show misc info\r\n")); |
|
169 iConsole->Read(iStatus); |
|
170 SetActive(); |
|
171 } |
|
172 |
|
173 void CActiveConsole::Options1() |
|
174 { |
|
175 iConsole->Printf(_L("*****Choose Delay*****\r\n")); |
|
176 iConsole->Printf(_L("press '1' 576000 baud\r\n")); |
|
177 iConsole->Printf(_L("press '2' 1152000 baud\r\n")); |
|
178 iConsole->Printf(_L("press '3' 4000000 baud\r\n")); |
|
179 iConsole->Read(iStatus); |
|
180 SetActive(); |
|
181 } |
|
182 |
|
183 void CActiveConsole::Options2() |
|
184 { |
|
185 iConsole->Printf(_L("*****Choose Delay*****\r\n")); |
|
186 iConsole->Printf(_L("press '1' 1.00 sec delay\r\n")); |
|
187 iConsole->Printf(_L("press '2' 0.10 sec delay\r\n")); |
|
188 iConsole->Printf(_L("press '3' 0.01 sec delay\r\n")); |
|
189 iConsole->Printf(_L("press '4' 0.00 sec delay\r\n")); |
|
190 iConsole->Read(iStatus); |
|
191 SetActive(); |
|
192 } |
|
193 |
|
194 void CActiveConsole::Options3() |
|
195 { |
|
196 iConsole->Printf(_L("****Choose Buf Sz*****\r\n")); |
|
197 iConsole->Printf(_L("press '1' 1 byte \r\n")); |
|
198 iConsole->Printf(_L("press '2' 4 bytes\r\n")); |
|
199 iConsole->Printf(_L("press '3' 16 bytes\r\n")); |
|
200 iConsole->Printf(_L("press '4' 64 bytes\r\n")); |
|
201 iConsole->Printf(_L("press '5' 128 bytes\r\n")); |
|
202 iConsole->Printf(_L("press '6' 2000 bytes\r\n")); |
|
203 iConsole->Printf(_L("press '7' 2051 bytes\r\n")); |
|
204 iConsole->Read(iStatus); |
|
205 SetActive(); |
|
206 } |
|
207 |
|
208 void CActiveConsole::ProcessKeyPressL(TChar aChar) |
|
209 { |
|
210 if (aChar == EKeyEscape) |
|
211 { |
|
212 CActiveScheduler::Stop(); |
|
213 return; |
|
214 } |
|
215 |
|
216 if(!iInit1) |
|
217 { |
|
218 switch(aChar) |
|
219 { |
|
220 case '1': |
|
221 iBaudRate=EBps576000; |
|
222 break; |
|
223 case '2': |
|
224 iBaudRate=EBps1152000; |
|
225 break; |
|
226 case '3': |
|
227 iBaudRate=EBps4000000; |
|
228 break; |
|
229 default: |
|
230 iBaudRate=EBps4000000; |
|
231 break; |
|
232 } |
|
233 iConsole->Printf(_L("Baud rate: %d\r\n"),iBaudRate); |
|
234 iInit1=ETrue; |
|
235 TFirConfig aConfigBuf; |
|
236 TFirConfigV01& aConfig=aConfigBuf(); |
|
237 aConfig.iRate=iBaudRate; |
|
238 TInt ret=iPort.SetConfig(aConfigBuf); |
|
239 iConsole->Printf(_L("Error %d on SetConfig\r\n"),ret); |
|
240 RequestCharacter(); |
|
241 return; |
|
242 } |
|
243 |
|
244 if(!iInit2) |
|
245 { |
|
246 switch(aChar) |
|
247 { |
|
248 case '1'://1 sec |
|
249 iTimeDelay=1000000; |
|
250 break; |
|
251 case '2'://0.1 sec |
|
252 iTimeDelay=100000; |
|
253 break; |
|
254 case '3'://0.01 sec |
|
255 iTimeDelay=10000; |
|
256 break; |
|
257 case '4'://0 sec |
|
258 iTimeDelay=0; |
|
259 break; |
|
260 default: |
|
261 iTimeDelay=1000000; |
|
262 break; |
|
263 } |
|
264 iConsole->Printf(_L("Time Delay: %d\r\n"),iTimeDelay); |
|
265 iInit2=ETrue; |
|
266 RequestCharacter(); |
|
267 return; |
|
268 } |
|
269 if(!iInit3) |
|
270 { |
|
271 switch(aChar) |
|
272 { |
|
273 case '1': |
|
274 iBufSz=1; |
|
275 break; |
|
276 case '2': |
|
277 iBufSz=4; |
|
278 break; |
|
279 case '3': |
|
280 iBufSz=16; |
|
281 break; |
|
282 case '4': |
|
283 iBufSz=64; |
|
284 break; |
|
285 case '5': |
|
286 iBufSz=128; |
|
287 break; |
|
288 case '6': |
|
289 iBufSz=2000; |
|
290 break; |
|
291 case '7': |
|
292 iBufSz=2052; |
|
293 break; |
|
294 default: |
|
295 iBufSz=2000; |
|
296 break; |
|
297 } |
|
298 iConsole->Printf(_L("Buffer size: %d\r\n"),iBufSz); |
|
299 iInit3=ETrue; |
|
300 RequestCharacter(); |
|
301 return; |
|
302 } |
|
303 |
|
304 switch (aChar) |
|
305 { |
|
306 case '1'://start reader |
|
307 iReader->Start(); |
|
308 break; |
|
309 case '2'://stop reader |
|
310 iReader->Stop(); |
|
311 break; |
|
312 case '3'://start writer |
|
313 iWriter->Start(); |
|
314 break; |
|
315 case '4'://stop writer |
|
316 iWriter->Stop(); |
|
317 break; |
|
318 case '8'://get fir regs |
|
319 GetFirRegs(); |
|
320 break; |
|
321 case '9'://get dma reader regs |
|
322 GetDmaReaderRegs(); |
|
323 break; |
|
324 case '0'://get dma writer regs |
|
325 GetDmaWriterRegs(); |
|
326 break; |
|
327 case 'a'://get TxBuf info |
|
328 GetWriteBufInfo(); |
|
329 break; |
|
330 case 'b'://get RxBuf info |
|
331 GetReadBufInfo(); |
|
332 break; |
|
333 case 'c'://get RxBuf info |
|
334 GetChunkInfo(); |
|
335 break; |
|
336 case 'd': |
|
337 GetMiscInfo(); |
|
338 break; |
|
339 default: |
|
340 iConsole->Printf(_L("\r\nUnknown Command\r\n\r\n")); |
|
341 break; |
|
342 } |
|
343 RequestCharacter (); |
|
344 return; |
|
345 } |
|
346 |
|
347 void CActiveConsole::GetFirRegs() |
|
348 { |
|
349 /* TInt r=0; |
|
350 TDebugFirRegs FirRegs; |
|
351 r=iPort.GetFirRegs(FirRegs); |
|
352 iConsole->Printf(_L("RxFrameStatus : 0x%x\r\n"),FirRegs.RxFrameStatus); |
|
353 iConsole->Printf(_L("RxBufferEmpty : 0x%x\r\n"),FirRegs.RxBufferEmpty); |
|
354 iConsole->Printf(_L("RxError : 0x%x\r\n"),FirRegs.RxError); |
|
355 iConsole->Printf(_L("RxOverrun : 0x%x\r\n"),FirRegs.RxOverrun); |
|
356 iConsole->Printf(_L("CrcError : 0x%x\r\n"),FirRegs.CrcError); |
|
357 iConsole->Printf(_L("TxFrameStatus : 0x%x\r\n"),FirRegs.TxFrameStatus); |
|
358 iConsole->Printf(_L("TxBufferEmpty : 0x%x\r\n"),FirRegs.TxBufferEmpty); |
|
359 iConsole->Printf(_L("TxBufferSz : 0x%x\r\n"),FirRegs.TxBufferSz); |
|
360 iConsole->Printf(_L("TxOverrun : 0x%x\r\n"),FirRegs.TxOverrun);*/ |
|
361 } |
|
362 |
|
363 void CActiveConsole::GetDmaReaderRegs() |
|
364 { |
|
365 /* TInt r=0; |
|
366 TDebugDmaChannelRegs DmaRxRegs; |
|
367 r=iPort.GetDmaRxRegs(DmaRxRegs); |
|
368 iConsole->Printf(_L("Rx Chan : %d\n"),DmaRxRegs.DmaRxChannel); |
|
369 iConsole->Printf(_L("Rx DmaMode : %d "),DmaRxRegs.DmaMode); |
|
370 iConsole->Printf(_L("Rx DmaState : %d "),DmaRxRegs.DmaState); |
|
371 iConsole->Printf(_L("Rx DmaBuffer : %x\n"),DmaRxRegs.DmaBuffer); |
|
372 iConsole->Printf(_L("Rx DmGauge : %d\n"),DmaRxRegs.DmaGauge); |
|
373 iConsole->Printf(_L("Rx DmaSrcAddr : %x "),DmaRxRegs.DmaSrcAddr); |
|
374 iConsole->Printf(_L("Rx DmaSrcInc : %d\n"),DmaRxRegs.DmaSrcInc); |
|
375 iConsole->Printf(_L("Rx DmaDestAddr: %x "),DmaRxRegs.DmaDestAddr); |
|
376 iConsole->Printf(_L("Rx DmaDestInc : %d\n"),DmaRxRegs.DmaDestInc); |
|
377 iConsole->Printf(_L("Rx DmaCount : %d\n"),DmaRxRegs.DmaCount); |
|
378 //iConsole->Printf(_L("Rx MatchClear : %x\n"),DmaRxRegs.MatchClear); |
|
379 //iConsole->Printf(_L("Rx MatchSet : %x\n"),DmaRxRegs.MatchSet);*/ |
|
380 } |
|
381 |
|
382 void CActiveConsole::GetDmaWriterRegs() |
|
383 { |
|
384 /* TInt r=0; |
|
385 TDebugDmaChannelRegs DmaTxRegs; |
|
386 r=iPort.GetDmaTxRegs(DmaTxRegs); |
|
387 iConsole->Printf(_L("Tx Chan : %d\n"),DmaTxRegs.DmaTxChannel); |
|
388 iConsole->Printf(_L("Tx DmaMode : %d"),DmaTxRegs.DmaMode); |
|
389 iConsole->Printf(_L("Tx DmaState : %d"),DmaTxRegs.DmaState); |
|
390 iConsole->Printf(_L("Tx DmaBuffer : %x\n"),DmaTxRegs.DmaBuffer); |
|
391 iConsole->Printf(_L("Tx DmGauge : %d\n"),DmaTxRegs.DmaGauge); |
|
392 iConsole->Printf(_L("Tx DmaSrcAddr : %x"),DmaTxRegs.DmaSrcAddr); |
|
393 iConsole->Printf(_L("Tx DmaSrcInc : %d\n"),DmaTxRegs.DmaSrcInc); |
|
394 iConsole->Printf(_L("Tx DmaDestAddr: %x"),DmaTxRegs.DmaDestAddr); |
|
395 iConsole->Printf(_L("Tx DmaDestInc : %d\n"),DmaTxRegs.DmaDestInc); |
|
396 iConsole->Printf(_L("Tx DmaCount : %d\n"),DmaTxRegs.DmaCount); |
|
397 //iConsole->Printf(_L("Tx MatchClear : %x\n"),DmaTxRegs.MatchClear); |
|
398 //iConsole->Printf(_L("Tx MatchSet : %x\n"),DmaTxRegs.MatchSet);*/ |
|
399 } |
|
400 |
|
401 void CActiveConsole::GetReadBufInfo() |
|
402 { |
|
403 /* TInt r=0; |
|
404 TDebugBufInfo RxBufInfo; |
|
405 r=iPort.GetRxBufInfo(RxBufInfo); |
|
406 iConsole->Printf(_L("Rx no frames: %d\r\n"),RxBufInfo.iNoFrames); |
|
407 iConsole->Printf(_L("Rx insert pt: %d "),RxBufInfo.iInsertPt); |
|
408 iConsole->Printf(_L("Rx remove pt: %d\r\n"),RxBufInfo.iRemovePt); |
|
409 iConsole->Printf(_L("Rx head : %d "),RxBufInfo.iHead); |
|
410 iConsole->Printf(_L("Rx tail : %d\r\n"),RxBufInfo.iTail); |
|
411 iConsole->Printf(_L("Rx active : %x "),RxBufInfo.iActive); |
|
412 iConsole->Printf(_L("Rx cancelled: %x\r\n"),RxBufInfo.iCancelled); |
|
413 iConsole->Printf(_L("Client read pending: %d\r\n"),RxBufInfo.iClientPending);*/ |
|
414 } |
|
415 |
|
416 void CActiveConsole::GetWriteBufInfo() |
|
417 { |
|
418 /* TInt r=0; |
|
419 TDebugBufInfo TxBufInfo; |
|
420 r=iPort.GetTxBufInfo(TxBufInfo); |
|
421 iConsole->Printf(_L("Tx no frames: %d\r\n"),TxBufInfo.iNoFrames); |
|
422 iConsole->Printf(_L("Tx insert pt: %d "),TxBufInfo.iInsertPt); |
|
423 iConsole->Printf(_L("Tx remove pt: %d\r\n"),TxBufInfo.iRemovePt); |
|
424 iConsole->Printf(_L("Tx head : %d "),TxBufInfo.iHead); |
|
425 iConsole->Printf(_L("Tx tail : %d\r\n"),TxBufInfo.iTail); |
|
426 iConsole->Printf(_L("Tx active : %x "),TxBufInfo.iActive); |
|
427 iConsole->Printf(_L("Tx cancelled: %x\r\n"),TxBufInfo.iCancelled); |
|
428 iConsole->Printf(_L("Client write pending: %d\r\n"),TxBufInfo.iClientPending);*/ |
|
429 } |
|
430 |
|
431 void CActiveConsole::GetChunkInfo() |
|
432 { |
|
433 /* TInt r=0; |
|
434 TDebugDmaChunkInfo DmaChunkInfo; |
|
435 r=iPort.GetDmaChunkInfo(DmaChunkInfo); |
|
436 iConsole->Printf(_L("Write Chunk Phys Addr: 0x%x\r\n"),DmaChunkInfo.iWriteChunkPhysAddr); |
|
437 iConsole->Printf(_L("Write Chunk Lin Addr: 0x%x\r\n"),DmaChunkInfo.iWriteChunkLinAddr); |
|
438 iConsole->Printf(_L("Read Chunk Phys Addr: 0x%x\r\n"),DmaChunkInfo.iReadChunkPhysAddr); |
|
439 iConsole->Printf(_L("Read Chunk Lin Addr: 0x%x\r\n"),DmaChunkInfo.iReadChunkLinAddr); |
|
440 //iConsole->Printf(_L("No pages in read chunk : %d\r\n"),DmaChunkInfo.iReaderNoPages); |
|
441 //iConsole->Printf(_L("no pages in write chunk : %d\r\n"),DmaChunkInfo.iWriterNoPages);*/ |
|
442 } |
|
443 |
|
444 void CActiveConsole::GetMiscInfo() |
|
445 { |
|
446 /* TInt r=0; |
|
447 TDebugInterruptInfo IntInfo; |
|
448 r=iPort.GetInterruptsInfo(IntInfo); |
|
449 iConsole->Printf(_L("NoRxDmaInts : %d\r\n"),IntInfo.NoRxDmaInts); |
|
450 iConsole->Printf(_L("NoTxDmaInts : %d\r\n"),IntInfo.NoTxDmaInts); |
|
451 iConsole->Printf(_L("NoRxBusyInts : %d\r\n"),IntInfo.NoRxBusyInts); |
|
452 iConsole->Printf(_L("NoRxIdleInts : %d\r\n"),IntInfo.NoRxIdleInts); |
|
453 iConsole->Printf(_L("NoRxInts : %d\r\n"),IntInfo.NoRxInts); |
|
454 iConsole->Printf(_L("NoTxIdleInts : %d\r\n"),IntInfo.NoTxIdleInts); |
|
455 iConsole->Printf(_L("NoTxInts : %d\r\n"),IntInfo.NoTxInts);*/ |
|
456 } |
|
457 |
|
458 void CActiveConsole::SetUpBuffers() |
|
459 { |
|
460 TInt i=0; |
|
461 WriteBuf.SetLength(2060); |
|
462 ReadBuf.SetLength(2060); |
|
463 for(i=0;i<2050;i++) |
|
464 { |
|
465 //WriteBuf[i]='W'; |
|
466 ReadBuf[i] ='R'; |
|
467 } |
|
468 |
|
469 TInt j=0; |
|
470 while(j<2050-16) |
|
471 { |
|
472 WriteBuf[j ]='0'; |
|
473 WriteBuf[j+1]='1'; |
|
474 WriteBuf[j+2]='2'; |
|
475 WriteBuf[j+3]='3'; |
|
476 |
|
477 WriteBuf[j+4]='4'; |
|
478 WriteBuf[j+5]='5'; |
|
479 WriteBuf[j+6]='6'; |
|
480 WriteBuf[j+7]='7'; |
|
481 |
|
482 WriteBuf[j+8 ]='8'; |
|
483 WriteBuf[j+9 ]='9'; |
|
484 WriteBuf[j+10]='A'; |
|
485 WriteBuf[j+11]='B'; |
|
486 |
|
487 WriteBuf[j+12]='C'; |
|
488 WriteBuf[j+13]='D'; |
|
489 WriteBuf[j+14]='E'; |
|
490 WriteBuf[j+15]='F'; |
|
491 |
|
492 j=j+16; |
|
493 } |
|
494 |
|
495 WriteBuf.SetLength(2000); |
|
496 } |
|
497 |
|
498 // |
|
499 // class CActiveWriter |
|
500 // |
|
501 |
|
502 CActiveWriter::CActiveWriter(CConsoleBase* aConsole,RDevFir* aPort) |
|
503 : CActive (EPriorityNormal) |
|
504 { |
|
505 iConsole = aConsole; |
|
506 iPort=aPort; |
|
507 iLength=0; |
|
508 } |
|
509 |
|
510 CActiveWriter* CActiveWriter::NewL(CConsoleBase* aConsole,RDevFir* aPort) |
|
511 { |
|
512 CActiveWriter* self = new (ELeave) CActiveWriter(aConsole,aPort); |
|
513 |
|
514 CleanupStack::PushL (self); |
|
515 self->ConstructL(); |
|
516 CActiveScheduler::Add (self); |
|
517 CleanupStack::Pop (); |
|
518 return (self); |
|
519 } |
|
520 |
|
521 void CActiveWriter::ConstructL() |
|
522 { |
|
523 } |
|
524 |
|
525 CActiveWriter::~CActiveWriter() |
|
526 { |
|
527 Cancel(); |
|
528 } |
|
529 |
|
530 void CActiveWriter::RunL () |
|
531 { |
|
532 if (iStatus != KErrNone) |
|
533 { |
|
534 iConsole->Printf(_L("Error %d on write completion\r\n"),iStatus.Int()); |
|
535 return; |
|
536 } |
|
537 else |
|
538 iConsole->Printf(_L("W :%d "),WriteBuf.Length()); |
|
539 |
|
540 if(iTimeDelay) |
|
541 User::After(iTimeDelay); |
|
542 iLength=(iLength+1)%10; |
|
543 WriteBuf.SetLength(iBufSz+iLength); |
|
544 iPort->Write(iStatus, WriteBuf, WriteBuf.Length()); |
|
545 SetActive(); |
|
546 } |
|
547 |
|
548 void CActiveWriter::Start() |
|
549 { |
|
550 if(IsActive()) |
|
551 return; |
|
552 iConsole->Printf(_L("Starting writer.....\r\n")); |
|
553 iPort->Write(iStatus, WriteBuf, WriteBuf.Length()); |
|
554 SetActive(); |
|
555 } |
|
556 |
|
557 void CActiveWriter::Stop() |
|
558 { |
|
559 iConsole->Printf(_L("Stopping writer.....\r\n")); |
|
560 Cancel(); |
|
561 } |
|
562 |
|
563 void CActiveWriter::DoCancel() |
|
564 { |
|
565 iPort->WriteCancel(); |
|
566 } |
|
567 |
|
568 // |
|
569 // class CActiveReader |
|
570 // |
|
571 |
|
572 CActiveReader::CActiveReader(CConsoleBase* aConsole,RDevFir* aPort) |
|
573 : CActive (EPriorityNormal)//EPriorityMore) |
|
574 { |
|
575 iConsole=aConsole; |
|
576 iPort =aPort; |
|
577 } |
|
578 |
|
579 CActiveReader* CActiveReader::NewL(CConsoleBase* aConsole,RDevFir* aPort) |
|
580 { |
|
581 CActiveReader* self = new (ELeave) CActiveReader(aConsole,aPort); |
|
582 |
|
583 CleanupStack::PushL(self); |
|
584 self->ConstructL(); |
|
585 CActiveScheduler::Add (self); |
|
586 CleanupStack::Pop(); |
|
587 return (self); |
|
588 } |
|
589 |
|
590 void CActiveReader::ConstructL() |
|
591 { |
|
592 } |
|
593 |
|
594 CActiveReader::~CActiveReader () |
|
595 { |
|
596 Cancel(); |
|
597 } |
|
598 |
|
599 void CActiveReader::Start() |
|
600 { |
|
601 if(IsActive()) |
|
602 return; |
|
603 iConsole->Printf(_L("Starting reader.....\r\n")); |
|
604 ReadBuf.SetLength(2052); |
|
605 iPort->Read(iStatus, ReadBuf, ReadBuf.Length()); |
|
606 SetActive(); |
|
607 } |
|
608 |
|
609 void CActiveReader::Stop() |
|
610 { |
|
611 iConsole->Printf(_L("Stopping reader.....\r\n")); |
|
612 Cancel(); |
|
613 } |
|
614 |
|
615 void CActiveReader::RunL () |
|
616 { |
|
617 if (iStatus != KErrNone) |
|
618 iConsole->Printf(_L("Error %d\r\n"),iStatus.Int()); |
|
619 else |
|
620 { |
|
621 if(!CompareBuffers(ReadBuf.Length())) |
|
622 iConsole->Printf(_L("Buffers dont compare!\r\n")); |
|
623 iConsole->Printf(_L("R:%d\r\n"),ReadBuf.Length()); |
|
624 /* TInt len=ReadBuf.Length(); |
|
625 for(TInt i=0;i<10;i++) |
|
626 { |
|
627 for (TInt j=0;j<16;j++)//print 16 bytes |
|
628 { |
|
629 if ((i*16)+j<len) |
|
630 { |
|
631 TInt v=ReadBuf[(i*16)+j]; |
|
632 iConsole->Printf(_L("%02x "),v); |
|
633 } |
|
634 else |
|
635 iConsole->Printf(_L(" ")); |
|
636 } |
|
637 iConsole->Printf(_L("\r\n")); |
|
638 }*/ |
|
639 } |
|
640 |
|
641 ResetReadBuffer(); |
|
642 if(iTimeDelay) |
|
643 User::After(iTimeDelay); |
|
644 iPort->Read(iStatus, ReadBuf, ReadBuf.Length()); |
|
645 SetActive(); |
|
646 } |
|
647 |
|
648 void CActiveReader::DoCancel() |
|
649 { |
|
650 iPort->ReadCancel(); |
|
651 } |
|
652 |
|
653 void CActiveReader::ResetReadBuffer() |
|
654 { |
|
655 TInt i=0; |
|
656 ReadBuf.SetLength(2060); |
|
657 for(i=0;i<2052;i++) |
|
658 ReadBuf[i] ='R'; |
|
659 } |
|
660 |
|
661 TBool CActiveReader::CompareBuffers(TInt aLen) |
|
662 { |
|
663 TInt i=0; |
|
664 while(i<aLen) |
|
665 { |
|
666 if(ReadBuf[i]!=WriteBuf[i]) |
|
667 return EFalse; |
|
668 i++; |
|
669 } |
|
670 return ETrue; |
|
671 } |
|
672 #pragma warning (default:4710) |
|
673 |