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_firco.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;
35 CActiveConsole::CActiveConsole(CConsoleBase* aConsole)
36 : CActive(EPriorityNormal)
44 CActiveConsole* CActiveConsole::NewLC(CConsoleBase* aConsole)
46 CActiveConsole* self = new (ELeave) CActiveConsole(aConsole);
51 void CActiveConsole::ConstructL ()
54 TFirCapsV01& aCaps=aCapsBuf();
55 TFirConfig aConfigBuf;
56 TFirConfigV01& aConfig=aConfigBuf();
58 iConsole->Printf(_L("\r\n"));
59 CActiveScheduler::Add(this); // Add to active scheduler
62 TInt ret=User::LoadPhysicalDevice(_L("Difir"));
64 iConsole->Printf(_L("Error %d on loading Fir PDD\r\n"),ret);
66 iConsole->Printf(_L("Successfully loaded Fir PDD\r\n"));
68 ret=User::LoadLogicalDevice(_L("Efir"));
70 iConsole->Printf(_L("Error %d on loading Fir LDD\r\n"),ret);
72 iConsole->Printf(_L("Successfully loaded Fir LDD\r\n"));
78 iConsole->Printf(_L("Error %d on opening Fastir port\r\n"),ret);
80 iConsole->Printf(_L("Successfully opened Fastir port\r\n"));
83 ret=iPort.Caps(aCapsBuf);
85 iConsole->Printf(_L("Error %d on getting caps\r\n"),ret);
87 iConsole->Printf(_L("Fir Caps: %d\r\n"),aCaps.iRate);
89 /* ret=iPort.Config(aConfigBuf);
91 iConsole->Printf(_L("Error %d getting config\r\n"),ret);
94 if(aConfig.iRate==EBps4000000)
95 iConsole->Printf(_L("Fir config is 4Mbps\r\n"));
98 aConfig.iRate=EBps4000000;
99 ret=iPort.SetConfig(aConfigBuf);
100 iConsole->Printf(_L("Error %d on SetConfig\r\n"),ret);*/
102 iWriter=CActiveWriter::NewL(iConsole,&iPort);
104 iConsole->Printf(_L("Have created writer\r\n"));
106 iConsole->Printf(_L("Failed to create writer\r\n"));
108 iReader=CActiveReader::NewL(iConsole,&iPort);
110 iConsole->Printf(_L("Have created reader\r\n"));
112 iConsole->Printf(_L("Failed to create reader\r\n"));
115 CActiveConsole::~CActiveConsole()
117 // Make sure we're cancelled
128 void CActiveConsole::DoCancel()
130 iConsole->ReadCancel();
133 void CActiveConsole::RunL()
135 ProcessKeyPressL(TChar(iConsole->KeyCode()));
136 // iConsole->Printf(_L("CActiveConsole - Completed with code %d\r\n\r\n"), iStatus.Int ());
139 void CActiveConsole::RequestCharacter()
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);
173 void CActiveConsole::Options1()
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);
183 void CActiveConsole::Options2()
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);
194 void CActiveConsole::Options3()
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);
208 void CActiveConsole::ProcessKeyPressL(TChar aChar)
210 if (aChar == EKeyEscape)
212 CActiveScheduler::Stop();
221 iBaudRate=EBps576000;
224 iBaudRate=EBps1152000;
227 iBaudRate=EBps4000000;
230 iBaudRate=EBps4000000;
233 iConsole->Printf(_L("Baud rate: %d\r\n"),iBaudRate);
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);
264 iConsole->Printf(_L("Time Delay: %d\r\n"),iTimeDelay);
298 iConsole->Printf(_L("Buffer size: %d\r\n"),iBufSz);
306 case '1'://start reader
309 case '2'://stop reader
312 case '3'://start writer
315 case '4'://stop writer
318 case '8'://get fir regs
321 case '9'://get dma reader regs
324 case '0'://get dma writer regs
327 case 'a'://get TxBuf info
330 case 'b'://get RxBuf info
333 case 'c'://get RxBuf info
340 iConsole->Printf(_L("\r\nUnknown Command\r\n\r\n"));
347 void CActiveConsole::GetFirRegs()
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);*/
363 void CActiveConsole::GetDmaReaderRegs()
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);*/
382 void CActiveConsole::GetDmaWriterRegs()
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);*/
401 void CActiveConsole::GetReadBufInfo()
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);*/
416 void CActiveConsole::GetWriteBufInfo()
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);*/
431 void CActiveConsole::GetChunkInfo()
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);*/
444 void CActiveConsole::GetMiscInfo()
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);*/
458 void CActiveConsole::SetUpBuffers()
461 WriteBuf.SetLength(2060);
462 ReadBuf.SetLength(2060);
495 WriteBuf.SetLength(2000);
499 // class CActiveWriter
502 CActiveWriter::CActiveWriter(CConsoleBase* aConsole,RDevFir* aPort)
503 : CActive (EPriorityNormal)
510 CActiveWriter* CActiveWriter::NewL(CConsoleBase* aConsole,RDevFir* aPort)
512 CActiveWriter* self = new (ELeave) CActiveWriter(aConsole,aPort);
514 CleanupStack::PushL (self);
516 CActiveScheduler::Add (self);
517 CleanupStack::Pop ();
521 void CActiveWriter::ConstructL()
525 CActiveWriter::~CActiveWriter()
530 void CActiveWriter::RunL ()
532 if (iStatus != KErrNone)
534 iConsole->Printf(_L("Error %d on write completion\r\n"),iStatus.Int());
538 iConsole->Printf(_L("W :%d "),WriteBuf.Length());
541 User::After(iTimeDelay);
542 iLength=(iLength+1)%10;
543 WriteBuf.SetLength(iBufSz+iLength);
544 iPort->Write(iStatus, WriteBuf, WriteBuf.Length());
548 void CActiveWriter::Start()
552 iConsole->Printf(_L("Starting writer.....\r\n"));
553 iPort->Write(iStatus, WriteBuf, WriteBuf.Length());
557 void CActiveWriter::Stop()
559 iConsole->Printf(_L("Stopping writer.....\r\n"));
563 void CActiveWriter::DoCancel()
565 iPort->WriteCancel();
569 // class CActiveReader
572 CActiveReader::CActiveReader(CConsoleBase* aConsole,RDevFir* aPort)
573 : CActive (EPriorityNormal)//EPriorityMore)
579 CActiveReader* CActiveReader::NewL(CConsoleBase* aConsole,RDevFir* aPort)
581 CActiveReader* self = new (ELeave) CActiveReader(aConsole,aPort);
583 CleanupStack::PushL(self);
585 CActiveScheduler::Add (self);
590 void CActiveReader::ConstructL()
594 CActiveReader::~CActiveReader ()
599 void CActiveReader::Start()
603 iConsole->Printf(_L("Starting reader.....\r\n"));
604 ReadBuf.SetLength(2052);
605 iPort->Read(iStatus, ReadBuf, ReadBuf.Length());
609 void CActiveReader::Stop()
611 iConsole->Printf(_L("Stopping reader.....\r\n"));
615 void CActiveReader::RunL ()
617 if (iStatus != KErrNone)
618 iConsole->Printf(_L("Error %d\r\n"),iStatus.Int());
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++)
627 for (TInt j=0;j<16;j++)//print 16 bytes
631 TInt v=ReadBuf[(i*16)+j];
632 iConsole->Printf(_L("%02x "),v);
635 iConsole->Printf(_L(" "));
637 iConsole->Printf(_L("\r\n"));
643 User::After(iTimeDelay);
644 iPort->Read(iStatus, ReadBuf, ReadBuf.Length());
648 void CActiveReader::DoCancel()
653 void CActiveReader::ResetReadBuffer()
656 ReadBuf.SetLength(2060);
661 TBool CActiveReader::CompareBuffers(TInt aLen)
666 if(ReadBuf[i]!=WriteBuf[i])
672 #pragma warning (default:4710)