Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\device\t_firco2.cpp
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
32 TInt iTimeDelay=1000000;
34 TBool iRWToWrite=EFalse;
36 TInt iReadFramesCount=0;
38 void ResetReadBuffer()
41 ReadBuf.SetLength(2060);
46 TBool CompareBuffers(TInt aLen)
51 if(ReadBuf[i]!=WriteBuf[i])
61 WriteBuf.SetLength(2060);
62 ReadBuf.SetLength(2060);
65 WriteBuf[i]=i+iDataStart;
68 WriteBuf.SetLength(2000);
71 CActiveConsole::CActiveConsole(CConsoleBase* aConsole)
72 : CActive(EPriorityNormal)
80 CActiveConsole* CActiveConsole::NewLC(CConsoleBase* aConsole)
82 CActiveConsole* self = new (ELeave) CActiveConsole(aConsole);
87 void CActiveConsole::ConstructL ()
90 TFirCapsV01& aCaps=aCapsBuf();
91 TFirConfig aConfigBuf;
92 TFirConfigV01& aConfig=aConfigBuf();
94 iConsole->Printf(_L("\r\n"));
95 CActiveScheduler::Add(this); // Add to active scheduler
98 TInt ret=User::LoadPhysicalDevice(_L("Difir"));
100 iConsole->Printf(_L("Error %d on loading Fir PDD\r\n"),ret);
102 iConsole->Printf(_L("Successfully loaded Fir PDD\r\n"));
104 ret=User::LoadLogicalDevice(_L("Efir"));
106 iConsole->Printf(_L("Error %d on loading Fir LDD\r\n"),ret);
108 iConsole->Printf(_L("Successfully loaded Fir LDD\r\n"));
114 iConsole->Printf(_L("Error %d on opening Fastir port\r\n"),ret);
116 iConsole->Printf(_L("Successfully opened Fastir port\r\n"));
119 ret=iPort.Caps(aCapsBuf);
121 iConsole->Printf(_L("Error %d on getting caps\r\n"),ret);
124 if(aCaps.iRate & KCapsFirBps576000)
125 iConsole->Printf(_L("576000 Bps supported\r\n"));
126 if(aCaps.iRate & KCapsFirBps1152000)
127 iConsole->Printf(_L("1152000 Bps supported\r\n"));
128 if(aCaps.iRate & KCapsFirBps4000000)
129 iConsole->Printf(_L("4000000 Bps supported\r\n"));
132 /*ret=iPort.Config(aConfigBuf);
134 iConsole->Printf(_L("Error %d getting config\r\n"),ret);
137 if(aConfig.iRate==EBps4000000)
138 iConsole->Printf(_L("Fir config is 4Mbps\r\n"));
141 iRW=CActiveRW::NewL(iConsole,&iPort);
143 iConsole->Printf(_L("Have created writer\r\n"));
145 iConsole->Printf(_L("Failed to create writer\r\n"));
148 CActiveConsole::~CActiveConsole()
150 // Make sure we're cancelled
159 void CActiveConsole::DoCancel()
161 iConsole->ReadCancel();
164 void CActiveConsole::RunL()
166 ProcessKeyPressL(TChar(iConsole->KeyCode()));
167 // iConsole->Printf(_L("CActiveConsole - Completed with code %d\r\n\r\n"), iStatus.Int ());
170 void CActiveConsole::RequestCharacter()
187 // A request is issued to the CConsoleBase to accept a
188 // character from the keyboard.
189 iConsole->Printf(_L("*********************************\r\n"));
190 iConsole->Printf(_L("press Escape to quit\r\n"));
191 iConsole->Printf(_L("press '1'/'2' to start as reader/writer\r\n"));
192 iConsole->Printf(_L("press '3' stop \r\n"));
193 iConsole->Printf(_L("press '8' to show FIR regs\r\n"));
194 iConsole->Printf(_L("press '9' to show Dma reader regs\r\n"));
195 iConsole->Printf(_L("press '0' to show Dma writer regs\r\n"));
196 iConsole->Printf(_L("press 'a' to show TxBuf info\r\n"));
197 iConsole->Printf(_L("press 'b' to show RxBuf info\r\n"));
198 iConsole->Printf(_L("press 'c' to show Chunk info\r\n"));
199 iConsole->Printf(_L("press 'd' to show misc info\r\n"));
200 iConsole->Read(iStatus);
204 void CActiveConsole::Options1()
206 iConsole->Printf(_L("*****Choose Delay*****\r\n"));
207 iConsole->Printf(_L("press '1' 576000 baud\r\n"));
208 iConsole->Printf(_L("press '2' 1152000 baud\r\n"));
209 iConsole->Printf(_L("press '3' 4000000 baud\r\n"));
210 iConsole->Read(iStatus);
214 void CActiveConsole::Options2()
216 iConsole->Printf(_L("*****Choose Delay*****\r\n"));
217 iConsole->Printf(_L("press '1' 1.00 sec delay\r\n"));
218 iConsole->Printf(_L("press '2' 100 ms delay\r\n"));
219 iConsole->Printf(_L("press '3' 10 ms delay\r\n"));
220 iConsole->Printf(_L("press '4' 1 ms delay\r\n"));
221 iConsole->Printf(_L("press '5' 0.00 sec delay\r\n"));
222 iConsole->Read(iStatus);
226 void CActiveConsole::Options3()
228 iConsole->Printf(_L("****Choose Buf Sz*****\r\n"));
229 iConsole->Printf(_L("press '1' 1 byte \r\n"));
230 iConsole->Printf(_L("press '2' 4 bytes\r\n"));
231 iConsole->Printf(_L("press '3' 2000 bytes\r\n"));
232 iConsole->Printf(_L("press '4' 2042 bytes\r\n"));
233 iConsole->Read(iStatus);
237 void CActiveConsole::ProcessKeyPressL(TChar aChar)
239 if (aChar == EKeyEscape)
241 CActiveScheduler::Stop();
250 iBaudRate=EBps576000;
253 iBaudRate=EBps1152000;
256 iBaudRate=EBps4000000;
259 iBaudRate=EBps4000000;
262 iConsole->Printf(_L("Baud rate: %d\r\n"),iBaudRate);
264 TFirConfig aConfigBuf;
265 TFirConfigV01& aConfig=aConfigBuf();
266 aConfig.iRate=iBaudRate;
267 TInt ret=iPort.SetConfig(aConfigBuf);
268 iConsole->Printf(_L("Error %d on SetConfig\r\n"),ret);
296 iConsole->Printf(_L("Time Delay: %d\r\n"),iTimeDelay);
321 iConsole->Printf(_L("Buffer size: %d\r\n"),iBufSz);
329 case '1'://start reader
332 case '2'://stop reader
335 case '3'://start writer
338 case '8'://get fir regs
341 case '9'://get dma reader regs
344 case '0'://get dma writer regs
347 case 'a'://get TxBuf info
350 case 'b'://get RxBuf info
353 case 'c'://get RxBuf info
360 iConsole->Printf(_L("\r\nUnknown Command\r\n\r\n"));
367 void CActiveConsole::GetFirRegs()
370 TDebugFirRegs FirRegs;
371 r=iPort.GetFirRegs(FirRegs);
372 iConsole->Printf(_L("RxFrameStatus : 0x%x\r\n"),FirRegs.RxFrameStatus);
373 iConsole->Printf(_L("RxBufferEmpty : 0x%x\r\n"),FirRegs.RxBufferEmpty);
374 iConsole->Printf(_L("RxError : 0x%x\r\n"),FirRegs.RxError);
375 iConsole->Printf(_L("RxOverrun : 0x%x\r\n"),FirRegs.RxOverrun);
376 iConsole->Printf(_L("CrcError : 0x%x\r\n"),FirRegs.CrcError);
377 iConsole->Printf(_L("TxFrameStatus : 0x%x\r\n"),FirRegs.TxFrameStatus);
378 iConsole->Printf(_L("TxBufferEmpty : 0x%x\r\n"),FirRegs.TxBufferEmpty);
379 iConsole->Printf(_L("TxBufferSz : 0x%x\r\n"),FirRegs.TxBufferSz);
380 iConsole->Printf(_L("TxOverrun : 0x%x\r\n"),FirRegs.TxOverrun);*/
383 void CActiveConsole::GetDmaReaderRegs()
386 TDebugDmaChannelRegs DmaRxRegs;
387 r=iPort.GetDmaRxRegs(DmaRxRegs);
388 iConsole->Printf(_L("Rx Chan : %d\n"),DmaRxRegs.DmaRxChannel);
389 iConsole->Printf(_L("Tx Chan : %d\n"),DmaRxRegs.DmaTxChannel);
390 iConsole->Printf(_L("Rx DmaMode : %d\n"),DmaRxRegs.DmaMode);
391 iConsole->Printf(_L("Rx DmaState : %d\n"),DmaRxRegs.DmaState);
392 iConsole->Printf(_L("Rx DmaBuffer : %x\n"),DmaRxRegs.DmaBuffer);
393 User::After(1000000);
394 iConsole->Printf(_L("Rx DmGauge : %d\n"),DmaRxRegs.DmaGauge);
395 iConsole->Printf(_L("Rx DmaSrcAddr : %x\n"),DmaRxRegs.DmaSrcAddr);
396 iConsole->Printf(_L("Rx DmaSrcInc : %d\n"),DmaRxRegs.DmaSrcInc);
397 iConsole->Printf(_L("Rx DmaDestAddr: %x\n"),DmaRxRegs.DmaDestAddr);
398 iConsole->Printf(_L("Rx DmaDestInc : %d\n"),DmaRxRegs.DmaDestInc);
399 iConsole->Printf(_L("Rx DmaCount : %d\n"),DmaRxRegs.DmaCount);
400 iConsole->Printf(_L("Rx MatchClear : %x\n"),DmaRxRegs.MatchClear);
401 iConsole->Printf(_L("Rx MatchSet : %x\n"),DmaRxRegs.MatchSet);*/
404 void CActiveConsole::GetDmaWriterRegs()
407 TDebugDmaChannelRegs DmaTxRegs;
408 r=iPort.GetDmaTxRegs(DmaTxRegs);
409 iConsole->Printf(_L("Rx Chan : %d\n"),DmaTxRegs.DmaRxChannel);
410 iConsole->Printf(_L("Tx Chan : %d\n"),DmaTxRegs.DmaTxChannel);
411 iConsole->Printf(_L("Tx DmaMode : %d\n"),DmaTxRegs.DmaMode);
412 iConsole->Printf(_L("Tx DmaState : %d\n"),DmaTxRegs.DmaState);
413 iConsole->Printf(_L("Tx DmaBuffer : %x\n"),DmaTxRegs.DmaBuffer);
414 User::After(1000000);
415 iConsole->Printf(_L("Tx DmGauge : %d\n"),DmaTxRegs.DmaGauge);
416 iConsole->Printf(_L("Tx DmaSrcAddr : %x\n"),DmaTxRegs.DmaSrcAddr);
417 iConsole->Printf(_L("Tx DmaSrcInc : %d\n"),DmaTxRegs.DmaSrcInc);
418 iConsole->Printf(_L("Tx DmaDestAddr: %x\n"),DmaTxRegs.DmaDestAddr);
419 iConsole->Printf(_L("Tx DmaDestInc : %d\n"),DmaTxRegs.DmaDestInc);
420 iConsole->Printf(_L("Tx DmaCount : %d\n"),DmaTxRegs.DmaCount);
421 iConsole->Printf(_L("Tx MatchClear : %x\n"),DmaTxRegs.MatchClear);
422 iConsole->Printf(_L("Tx MatchSet : %x\n"),DmaTxRegs.MatchSet);*/
425 void CActiveConsole::GetReadBufInfo()
428 TDebugBufInfo RxBufInfo;
429 r=iPort.GetRxBufInfo(RxBufInfo);
430 iConsole->Printf(_L("Rx no frames: %d\r\n"),RxBufInfo.iNoFrames);
431 iConsole->Printf(_L("Rx insert pt: %d\r\n"),RxBufInfo.iInsertPt);
432 iConsole->Printf(_L("Rx remove pt: %d\r\n"),RxBufInfo.iRemovePt);
433 iConsole->Printf(_L("Rx head : %d\r\n"),RxBufInfo.iHead);
434 iConsole->Printf(_L("Rx tail : %d\r\n"),RxBufInfo.iTail);
435 iConsole->Printf(_L("Rx active : %x\r\n"),RxBufInfo.iActive);
436 iConsole->Printf(_L("Rx cancelled: %x\r\n"),RxBufInfo.iCancelled);
437 iConsole->Printf(_L("Client read pending: %d\r\n"),RxBufInfo.iClientPending);*/
440 void CActiveConsole::GetWriteBufInfo()
443 TDebugBufInfo TxBufInfo;
444 r=iPort.GetTxBufInfo(TxBufInfo);
445 iConsole->Printf(_L("Tx no frames: %d\r\n"),TxBufInfo.iNoFrames);
446 iConsole->Printf(_L("Tx insert pt: %d\r\n"),TxBufInfo.iInsertPt);
447 iConsole->Printf(_L("Tx remove pt: %d\r\n"),TxBufInfo.iRemovePt);
448 iConsole->Printf(_L("Tx head : %d\r\n"),TxBufInfo.iHead);
449 iConsole->Printf(_L("Tx tail : %d\r\n"),TxBufInfo.iTail);
450 iConsole->Printf(_L("Tx active : %x\r\n"),TxBufInfo.iActive);
451 iConsole->Printf(_L("Tx cancelled: %x\r\n"),TxBufInfo.iCancelled);
452 iConsole->Printf(_L("Client write pending: %d\r\n"),TxBufInfo.iClientPending);*/
455 void CActiveConsole::GetChunkInfo()
458 TDebugDmaChunkInfo DmaChunkInfo;
459 r=iPort.GetDmaChunkInfo(DmaChunkInfo);
460 iConsole->Printf(_L("Write Chunk Phys Addr: 0x%x\r\n"),DmaChunkInfo.iWriteChunkPhysAddr);
461 iConsole->Printf(_L("Write Chunk Lin Addr: 0x%x\r\n"),DmaChunkInfo.iWriteChunkLinAddr);
462 iConsole->Printf(_L("Read Chunk Phys Addr: 0x%x\r\n"),DmaChunkInfo.iReadChunkPhysAddr);
463 iConsole->Printf(_L("Read Chunk Lin Addr: 0x%x\r\n"),DmaChunkInfo.iReadChunkLinAddr);
464 //iConsole->Printf(_L("Write Chunk Phys Addr: 0x%x\r\n"),DmaChunkInfo.);*/
467 void CActiveConsole::GetMiscInfo()
470 TDebugInterruptInfo IntInfo;
471 r=iPort.GetInterruptsInfo(IntInfo);
472 iConsole->Printf(_L("No writer dma interrupts: %d\r\n"),IntInfo.iNoTxDmaInts);
473 iConsole->Printf(_L("No reader dma interrupts: %d\r\n"),IntInfo.iNoRxDmaInts);
474 //iConsole->Printf(_L("Total Hspp interrupts: %d\r\n"),IntInfo.iNoHsspInts);
475 iConsole->Printf(_L("Total Framing errors : %d\r\n"),IntInfo.iNoFREs);
476 iConsole->Printf(_L("No xtra chars : %d\r\n"),IntInfo.iNoXtraChars);
477 iConsole->Printf(_L("No unwanted chars : %d\r\n"),IntInfo.iNoUnwantedChars);
478 iConsole->Printf(_L("No Rx dma leftovers : %d\r\n"),IntInfo.iNoRxDmaInts);*/
487 CActiveRW::CActiveRW(CConsoleBase* aConsole,RDevFir* aPort)
488 : CActive (EPriorityNormal)
495 CActiveRW* CActiveRW::NewL(CConsoleBase* aConsole,RDevFir* aPort)
497 CActiveRW* self = new (ELeave) CActiveRW(aConsole,aPort);
499 CleanupStack::PushL (self);
501 CActiveScheduler::Add (self);
502 CleanupStack::Pop ();
506 void CActiveRW::ConstructL()
510 CActiveRW::~CActiveRW()
515 void CActiveRW::RunL ()
521 if (iStatus != KErrNone)
522 iConsole->Printf(_L("Error %d\r\n"),iStatus.Int());
526 User::After(iTimeDelay);
529 if(iNextXfer==EWriteXfer)
533 rlength=ReadBuf[0]+(ReadBuf[1]<<8);
535 if(rlength != ReadBuf.Length() || iStatus != KErrNone)
538 RDebug::Print(_L("********* SHORT READ %d %d*********\n\r"),rlength, ReadBuf.Length());
541 if(iReadFramesCount>0)
542 iErrorRate=(iFrameError*2000+iReadFramesCount)/(2*iReadFramesCount);
546 iConsole->Printf(_L("R:%-4d FR %d EC %d Err %3d.%1d%%\r\n"),
547 ReadBuf.Length(),iReadFramesCount,iFrameError, iErrorRate/10,iErrorRate%10);
549 iLength=(iLength+1)%10;
550 wlength=iBufSz+iLength;
551 WriteBuf.SetLength(wlength);
553 WriteBuf[1]=wlength>>8;
554 iPort->Write(iStatus, WriteBuf, WriteBuf.Length());
560 iConsole->Printf(_L("W:%-4d "),WriteBuf.Length());
562 iPort->Read(iStatus, ReadBuf, ReadBuf.Length());
563 iNextXfer=EWriteXfer;
568 void CActiveRW::Start(TBool StartWriting)
580 iConsole->Printf(_L("Starting with write.....\r\n"));
581 WriteBuf.SetLength(iBufSz);
583 WriteBuf[1]=iBufSz>>8;
584 iPort->Write(iStatus, WriteBuf, WriteBuf.Length());
594 iConsole->Printf(_L("Starting with read.....\r\n"));
595 iPort->Read(iStatus, ReadBuf, ReadBuf.Length());
596 iNextXfer=EWriteXfer;
601 void CActiveRW::Stop()
603 iConsole->Printf(_L("Stopping.....\r\n"));
607 void CActiveRW::DoCancel()
609 iPort->WriteCancel();
613 #pragma warning (default:4710)