1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/device/t_firco2.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,613 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\device\t_firco2.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include "t_fir2.h"
1.22 +
1.23 +#if defined(__VC32__) && _MSC_VER==1100
1.24 +// Disable MSVC++ 5.0 aggressive warnings about non-expansion of inline functions.
1.25 +#pragma warning(disable : 4710) // function '...' not expanded
1.26 +#endif
1.27 +
1.28 +#ifdef __WINS__
1.29 + #include <es_sock.h>
1.30 + RSocketServ ss;
1.31 +#endif
1.32 +
1.33 +TBuf8<2060> WriteBuf;
1.34 +TBuf8<2060> ReadBuf;
1.35 +TInt iTimeDelay=1000000;
1.36 +TInt iBufSz=2000;
1.37 +TBool iRWToWrite=EFalse;
1.38 +TInt iDataStart=-1;
1.39 +TInt iReadFramesCount=0;
1.40 +TInt iFrameError=0;
1.41 +void ResetReadBuffer()
1.42 + {
1.43 + TInt i=0;
1.44 + ReadBuf.SetLength(2060);
1.45 + for(i=0;i<2050;i++)
1.46 + ReadBuf[i] ='R';
1.47 + }
1.48 +
1.49 +TBool CompareBuffers(TInt aLen)
1.50 + {
1.51 + TInt i=0;
1.52 + while(i<aLen)
1.53 + {
1.54 + if(ReadBuf[i]!=WriteBuf[i])
1.55 + return EFalse;
1.56 + i++;
1.57 + }
1.58 + return ETrue;
1.59 + }
1.60 +
1.61 +void SetUpBuffers()
1.62 + {
1.63 + TInt i=0;
1.64 + WriteBuf.SetLength(2060);
1.65 + ReadBuf.SetLength(2060);
1.66 + for(i=0;i<2050;i++)
1.67 + {
1.68 + WriteBuf[i]=i+iDataStart;
1.69 + ReadBuf[i] ='R';
1.70 + }
1.71 + WriteBuf.SetLength(2000);
1.72 + }
1.73 +
1.74 +CActiveConsole::CActiveConsole(CConsoleBase* aConsole)
1.75 + : CActive(EPriorityNormal)
1.76 + {
1.77 + iConsole=aConsole;
1.78 + iInit1 =EFalse;
1.79 + iInit2 =EFalse;
1.80 + iInit3 =EFalse;
1.81 + }
1.82 +
1.83 +CActiveConsole* CActiveConsole::NewLC(CConsoleBase* aConsole)
1.84 + {
1.85 + CActiveConsole* self = new (ELeave) CActiveConsole(aConsole);
1.86 + self->ConstructL();
1.87 + return self;
1.88 + }
1.89 +
1.90 +void CActiveConsole::ConstructL ()
1.91 + {
1.92 + TFirCaps aCapsBuf;
1.93 + TFirCapsV01& aCaps=aCapsBuf();
1.94 + TFirConfig aConfigBuf;
1.95 + TFirConfigV01& aConfig=aConfigBuf();
1.96 +
1.97 + iConsole->Printf(_L("\r\n"));
1.98 + CActiveScheduler::Add(this); // Add to active scheduler
1.99 +
1.100 + // Load Driver
1.101 + TInt ret=User::LoadPhysicalDevice(_L("Difir"));
1.102 + if (ret!=KErrNone)
1.103 + iConsole->Printf(_L("Error %d on loading Fir PDD\r\n"),ret);
1.104 + else
1.105 + iConsole->Printf(_L("Successfully loaded Fir PDD\r\n"));
1.106 +
1.107 + ret=User::LoadLogicalDevice(_L("Efir"));
1.108 + if (ret!=KErrNone)
1.109 + iConsole->Printf(_L("Error %d on loading Fir LDD\r\n"),ret);
1.110 + else
1.111 + iConsole->Printf(_L("Successfully loaded Fir LDD\r\n"));
1.112 +
1.113 + SetUpBuffers();
1.114 +
1.115 + ret=iPort.Open(0);
1.116 + if (ret!=KErrNone)
1.117 + iConsole->Printf(_L("Error %d on opening Fastir port\r\n"),ret);
1.118 + else
1.119 + iConsole->Printf(_L("Successfully opened Fastir port\r\n"));
1.120 +
1.121 +
1.122 + ret=iPort.Caps(aCapsBuf);
1.123 + if (ret!=KErrNone)
1.124 + iConsole->Printf(_L("Error %d on getting caps\r\n"),ret);
1.125 + else
1.126 + {
1.127 + if(aCaps.iRate & KCapsFirBps576000)
1.128 + iConsole->Printf(_L("576000 Bps supported\r\n"));
1.129 + if(aCaps.iRate & KCapsFirBps1152000)
1.130 + iConsole->Printf(_L("1152000 Bps supported\r\n"));
1.131 + if(aCaps.iRate & KCapsFirBps4000000)
1.132 + iConsole->Printf(_L("4000000 Bps supported\r\n"));
1.133 + }
1.134 +
1.135 + /*ret=iPort.Config(aConfigBuf);
1.136 + if (ret!=KErrNone)
1.137 + iConsole->Printf(_L("Error %d getting config\r\n"),ret);
1.138 + else
1.139 + {
1.140 + if(aConfig.iRate==EBps4000000)
1.141 + iConsole->Printf(_L("Fir config is 4Mbps\r\n"));
1.142 + }*/
1.143 +
1.144 + iRW=CActiveRW::NewL(iConsole,&iPort);
1.145 + if(iRW)
1.146 + iConsole->Printf(_L("Have created writer\r\n"));
1.147 + else
1.148 + iConsole->Printf(_L("Failed to create writer\r\n"));
1.149 + }
1.150 +
1.151 +CActiveConsole::~CActiveConsole()
1.152 + {
1.153 + // Make sure we're cancelled
1.154 + Cancel();
1.155 +
1.156 + if(iRW)
1.157 + delete iRW;
1.158 +
1.159 + iPort.Close();
1.160 + }
1.161 +
1.162 +void CActiveConsole::DoCancel()
1.163 + {
1.164 + iConsole->ReadCancel();
1.165 + }
1.166 +
1.167 +void CActiveConsole::RunL()
1.168 + {
1.169 + ProcessKeyPressL(TChar(iConsole->KeyCode()));
1.170 +// iConsole->Printf(_L("CActiveConsole - Completed with code %d\r\n\r\n"), iStatus.Int ());
1.171 + }
1.172 +
1.173 +void CActiveConsole::RequestCharacter()
1.174 + {
1.175 + if(!iInit1)
1.176 + {
1.177 + Options1();
1.178 + return;
1.179 + }
1.180 + if(!iInit2)
1.181 + {
1.182 + Options2();
1.183 + return;
1.184 + }
1.185 + if(!iInit3)
1.186 + {
1.187 + Options3();
1.188 + return;
1.189 + }
1.190 + // A request is issued to the CConsoleBase to accept a
1.191 + // character from the keyboard.
1.192 + iConsole->Printf(_L("*********************************\r\n"));
1.193 + iConsole->Printf(_L("press Escape to quit\r\n"));
1.194 + iConsole->Printf(_L("press '1'/'2' to start as reader/writer\r\n"));
1.195 + iConsole->Printf(_L("press '3' stop \r\n"));
1.196 + iConsole->Printf(_L("press '8' to show FIR regs\r\n"));
1.197 + iConsole->Printf(_L("press '9' to show Dma reader regs\r\n"));
1.198 + iConsole->Printf(_L("press '0' to show Dma writer regs\r\n"));
1.199 + iConsole->Printf(_L("press 'a' to show TxBuf info\r\n"));
1.200 + iConsole->Printf(_L("press 'b' to show RxBuf info\r\n"));
1.201 + iConsole->Printf(_L("press 'c' to show Chunk info\r\n"));
1.202 + iConsole->Printf(_L("press 'd' to show misc info\r\n"));
1.203 + iConsole->Read(iStatus);
1.204 + SetActive();
1.205 + }
1.206 +
1.207 +void CActiveConsole::Options1()
1.208 + {
1.209 + iConsole->Printf(_L("*****Choose Delay*****\r\n"));
1.210 + iConsole->Printf(_L("press '1' 576000 baud\r\n"));
1.211 + iConsole->Printf(_L("press '2' 1152000 baud\r\n"));
1.212 + iConsole->Printf(_L("press '3' 4000000 baud\r\n"));
1.213 + iConsole->Read(iStatus);
1.214 + SetActive();
1.215 + }
1.216 +
1.217 +void CActiveConsole::Options2()
1.218 + {
1.219 + iConsole->Printf(_L("*****Choose Delay*****\r\n"));
1.220 + iConsole->Printf(_L("press '1' 1.00 sec delay\r\n"));
1.221 + iConsole->Printf(_L("press '2' 100 ms delay\r\n"));
1.222 + iConsole->Printf(_L("press '3' 10 ms delay\r\n"));
1.223 + iConsole->Printf(_L("press '4' 1 ms delay\r\n"));
1.224 + iConsole->Printf(_L("press '5' 0.00 sec delay\r\n"));
1.225 + iConsole->Read(iStatus);
1.226 + SetActive();
1.227 + }
1.228 +
1.229 +void CActiveConsole::Options3()
1.230 + {
1.231 + iConsole->Printf(_L("****Choose Buf Sz*****\r\n"));
1.232 + iConsole->Printf(_L("press '1' 1 byte \r\n"));
1.233 + iConsole->Printf(_L("press '2' 4 bytes\r\n"));
1.234 + iConsole->Printf(_L("press '3' 2000 bytes\r\n"));
1.235 + iConsole->Printf(_L("press '4' 2042 bytes\r\n"));
1.236 + iConsole->Read(iStatus);
1.237 + SetActive();
1.238 + }
1.239 +
1.240 +void CActiveConsole::ProcessKeyPressL(TChar aChar)
1.241 + {
1.242 + if (aChar == EKeyEscape)
1.243 + {
1.244 + CActiveScheduler::Stop();
1.245 + return;
1.246 + }
1.247 +
1.248 + if(!iInit1)
1.249 + {
1.250 + switch(aChar)
1.251 + {
1.252 + case '1':
1.253 + iBaudRate=EBps576000;
1.254 + break;
1.255 + case '2':
1.256 + iBaudRate=EBps1152000;
1.257 + break;
1.258 + case '3':
1.259 + iBaudRate=EBps4000000;
1.260 + break;
1.261 + default:
1.262 + iBaudRate=EBps4000000;
1.263 + break;
1.264 + }
1.265 + iConsole->Printf(_L("Baud rate: %d\r\n"),iBaudRate);
1.266 + iInit1=ETrue;
1.267 + TFirConfig aConfigBuf;
1.268 + TFirConfigV01& aConfig=aConfigBuf();
1.269 + aConfig.iRate=iBaudRate;
1.270 + TInt ret=iPort.SetConfig(aConfigBuf);
1.271 + iConsole->Printf(_L("Error %d on SetConfig\r\n"),ret);
1.272 + RequestCharacter();
1.273 + return;
1.274 + }
1.275 +
1.276 + if(!iInit2)
1.277 + {
1.278 + switch(aChar)
1.279 + {
1.280 + case '1'://1 sec
1.281 + iTimeDelay=1000000;
1.282 + break;
1.283 + case '2'://100ms
1.284 + iTimeDelay=100000;
1.285 + break;
1.286 + case '3'://10ms
1.287 + iTimeDelay=10000;
1.288 + break;
1.289 + case '4'://1ms
1.290 + iTimeDelay=1000;
1.291 + break;
1.292 + case '5'://0 sec
1.293 + iTimeDelay=0;
1.294 + break;
1.295 + default:
1.296 + iTimeDelay=1000000;
1.297 + break;
1.298 + }
1.299 + iConsole->Printf(_L("Time Delay: %d\r\n"),iTimeDelay);
1.300 + iInit2=ETrue;
1.301 + RequestCharacter();
1.302 + return;
1.303 + }
1.304 + if(!iInit3)
1.305 + {
1.306 + switch(aChar)
1.307 + {
1.308 + case '1':
1.309 + iBufSz=1;
1.310 + break;
1.311 + case '2':
1.312 + iBufSz=4;
1.313 + break;
1.314 + case '3':
1.315 + iBufSz=2000;
1.316 + break;
1.317 + case '4':
1.318 + iBufSz=2042;
1.319 + break;
1.320 + default:
1.321 + iBufSz=2000;
1.322 + break;
1.323 + }
1.324 + iConsole->Printf(_L("Buffer size: %d\r\n"),iBufSz);
1.325 + iInit3=ETrue;
1.326 + RequestCharacter();
1.327 + return;
1.328 + }
1.329 +
1.330 + switch (aChar)
1.331 + {
1.332 + case '1'://start reader
1.333 + iRW->Start(EFalse);
1.334 + break;
1.335 + case '2'://stop reader
1.336 + iRW->Start(ETrue);
1.337 + break;
1.338 + case '3'://start writer
1.339 + iRW->Stop();
1.340 + break;
1.341 + case '8'://get fir regs
1.342 + GetFirRegs();
1.343 + break;
1.344 + case '9'://get dma reader regs
1.345 + GetDmaReaderRegs();
1.346 + break;
1.347 + case '0'://get dma writer regs
1.348 + GetDmaWriterRegs();
1.349 + break;
1.350 + case 'a'://get TxBuf info
1.351 + GetWriteBufInfo();
1.352 + break;
1.353 + case 'b'://get RxBuf info
1.354 + GetReadBufInfo();
1.355 + break;
1.356 + case 'c'://get RxBuf info
1.357 + GetChunkInfo();
1.358 + break;
1.359 + case 'd':
1.360 + GetMiscInfo();
1.361 + break;
1.362 + default:
1.363 + iConsole->Printf(_L("\r\nUnknown Command\r\n\r\n"));
1.364 + break;
1.365 + }
1.366 + RequestCharacter ();
1.367 + return;
1.368 + }
1.369 +
1.370 +void CActiveConsole::GetFirRegs()
1.371 + {
1.372 +/* TInt r=0;
1.373 + TDebugFirRegs FirRegs;
1.374 + r=iPort.GetFirRegs(FirRegs);
1.375 + iConsole->Printf(_L("RxFrameStatus : 0x%x\r\n"),FirRegs.RxFrameStatus);
1.376 + iConsole->Printf(_L("RxBufferEmpty : 0x%x\r\n"),FirRegs.RxBufferEmpty);
1.377 + iConsole->Printf(_L("RxError : 0x%x\r\n"),FirRegs.RxError);
1.378 + iConsole->Printf(_L("RxOverrun : 0x%x\r\n"),FirRegs.RxOverrun);
1.379 + iConsole->Printf(_L("CrcError : 0x%x\r\n"),FirRegs.CrcError);
1.380 + iConsole->Printf(_L("TxFrameStatus : 0x%x\r\n"),FirRegs.TxFrameStatus);
1.381 + iConsole->Printf(_L("TxBufferEmpty : 0x%x\r\n"),FirRegs.TxBufferEmpty);
1.382 + iConsole->Printf(_L("TxBufferSz : 0x%x\r\n"),FirRegs.TxBufferSz);
1.383 + iConsole->Printf(_L("TxOverrun : 0x%x\r\n"),FirRegs.TxOverrun);*/
1.384 + }
1.385 +
1.386 +void CActiveConsole::GetDmaReaderRegs()
1.387 + {
1.388 +/* TInt r=0;
1.389 + TDebugDmaChannelRegs DmaRxRegs;
1.390 + r=iPort.GetDmaRxRegs(DmaRxRegs);
1.391 + iConsole->Printf(_L("Rx Chan : %d\n"),DmaRxRegs.DmaRxChannel);
1.392 + iConsole->Printf(_L("Tx Chan : %d\n"),DmaRxRegs.DmaTxChannel);
1.393 + iConsole->Printf(_L("Rx DmaMode : %d\n"),DmaRxRegs.DmaMode);
1.394 + iConsole->Printf(_L("Rx DmaState : %d\n"),DmaRxRegs.DmaState);
1.395 + iConsole->Printf(_L("Rx DmaBuffer : %x\n"),DmaRxRegs.DmaBuffer);
1.396 + User::After(1000000);
1.397 + iConsole->Printf(_L("Rx DmGauge : %d\n"),DmaRxRegs.DmaGauge);
1.398 + iConsole->Printf(_L("Rx DmaSrcAddr : %x\n"),DmaRxRegs.DmaSrcAddr);
1.399 + iConsole->Printf(_L("Rx DmaSrcInc : %d\n"),DmaRxRegs.DmaSrcInc);
1.400 + iConsole->Printf(_L("Rx DmaDestAddr: %x\n"),DmaRxRegs.DmaDestAddr);
1.401 + iConsole->Printf(_L("Rx DmaDestInc : %d\n"),DmaRxRegs.DmaDestInc);
1.402 + iConsole->Printf(_L("Rx DmaCount : %d\n"),DmaRxRegs.DmaCount);
1.403 + iConsole->Printf(_L("Rx MatchClear : %x\n"),DmaRxRegs.MatchClear);
1.404 + iConsole->Printf(_L("Rx MatchSet : %x\n"),DmaRxRegs.MatchSet);*/
1.405 + }
1.406 +
1.407 +void CActiveConsole::GetDmaWriterRegs()
1.408 + {
1.409 +/* TInt r=0;
1.410 + TDebugDmaChannelRegs DmaTxRegs;
1.411 + r=iPort.GetDmaTxRegs(DmaTxRegs);
1.412 + iConsole->Printf(_L("Rx Chan : %d\n"),DmaTxRegs.DmaRxChannel);
1.413 + iConsole->Printf(_L("Tx Chan : %d\n"),DmaTxRegs.DmaTxChannel);
1.414 + iConsole->Printf(_L("Tx DmaMode : %d\n"),DmaTxRegs.DmaMode);
1.415 + iConsole->Printf(_L("Tx DmaState : %d\n"),DmaTxRegs.DmaState);
1.416 + iConsole->Printf(_L("Tx DmaBuffer : %x\n"),DmaTxRegs.DmaBuffer);
1.417 + User::After(1000000);
1.418 + iConsole->Printf(_L("Tx DmGauge : %d\n"),DmaTxRegs.DmaGauge);
1.419 + iConsole->Printf(_L("Tx DmaSrcAddr : %x\n"),DmaTxRegs.DmaSrcAddr);
1.420 + iConsole->Printf(_L("Tx DmaSrcInc : %d\n"),DmaTxRegs.DmaSrcInc);
1.421 + iConsole->Printf(_L("Tx DmaDestAddr: %x\n"),DmaTxRegs.DmaDestAddr);
1.422 + iConsole->Printf(_L("Tx DmaDestInc : %d\n"),DmaTxRegs.DmaDestInc);
1.423 + iConsole->Printf(_L("Tx DmaCount : %d\n"),DmaTxRegs.DmaCount);
1.424 + iConsole->Printf(_L("Tx MatchClear : %x\n"),DmaTxRegs.MatchClear);
1.425 + iConsole->Printf(_L("Tx MatchSet : %x\n"),DmaTxRegs.MatchSet);*/
1.426 + }
1.427 +
1.428 +void CActiveConsole::GetReadBufInfo()
1.429 + {
1.430 +/* TInt r=0;
1.431 + TDebugBufInfo RxBufInfo;
1.432 + r=iPort.GetRxBufInfo(RxBufInfo);
1.433 + iConsole->Printf(_L("Rx no frames: %d\r\n"),RxBufInfo.iNoFrames);
1.434 + iConsole->Printf(_L("Rx insert pt: %d\r\n"),RxBufInfo.iInsertPt);
1.435 + iConsole->Printf(_L("Rx remove pt: %d\r\n"),RxBufInfo.iRemovePt);
1.436 + iConsole->Printf(_L("Rx head : %d\r\n"),RxBufInfo.iHead);
1.437 + iConsole->Printf(_L("Rx tail : %d\r\n"),RxBufInfo.iTail);
1.438 + iConsole->Printf(_L("Rx active : %x\r\n"),RxBufInfo.iActive);
1.439 + iConsole->Printf(_L("Rx cancelled: %x\r\n"),RxBufInfo.iCancelled);
1.440 + iConsole->Printf(_L("Client read pending: %d\r\n"),RxBufInfo.iClientPending);*/
1.441 + }
1.442 +
1.443 +void CActiveConsole::GetWriteBufInfo()
1.444 + {
1.445 +/* TInt r=0;
1.446 + TDebugBufInfo TxBufInfo;
1.447 + r=iPort.GetTxBufInfo(TxBufInfo);
1.448 + iConsole->Printf(_L("Tx no frames: %d\r\n"),TxBufInfo.iNoFrames);
1.449 + iConsole->Printf(_L("Tx insert pt: %d\r\n"),TxBufInfo.iInsertPt);
1.450 + iConsole->Printf(_L("Tx remove pt: %d\r\n"),TxBufInfo.iRemovePt);
1.451 + iConsole->Printf(_L("Tx head : %d\r\n"),TxBufInfo.iHead);
1.452 + iConsole->Printf(_L("Tx tail : %d\r\n"),TxBufInfo.iTail);
1.453 + iConsole->Printf(_L("Tx active : %x\r\n"),TxBufInfo.iActive);
1.454 + iConsole->Printf(_L("Tx cancelled: %x\r\n"),TxBufInfo.iCancelled);
1.455 + iConsole->Printf(_L("Client write pending: %d\r\n"),TxBufInfo.iClientPending);*/
1.456 + }
1.457 +
1.458 +void CActiveConsole::GetChunkInfo()
1.459 + {
1.460 +/* TInt r=0;
1.461 + TDebugDmaChunkInfo DmaChunkInfo;
1.462 + r=iPort.GetDmaChunkInfo(DmaChunkInfo);
1.463 + iConsole->Printf(_L("Write Chunk Phys Addr: 0x%x\r\n"),DmaChunkInfo.iWriteChunkPhysAddr);
1.464 + iConsole->Printf(_L("Write Chunk Lin Addr: 0x%x\r\n"),DmaChunkInfo.iWriteChunkLinAddr);
1.465 + iConsole->Printf(_L("Read Chunk Phys Addr: 0x%x\r\n"),DmaChunkInfo.iReadChunkPhysAddr);
1.466 + iConsole->Printf(_L("Read Chunk Lin Addr: 0x%x\r\n"),DmaChunkInfo.iReadChunkLinAddr);
1.467 + //iConsole->Printf(_L("Write Chunk Phys Addr: 0x%x\r\n"),DmaChunkInfo.);*/
1.468 + }
1.469 +
1.470 +void CActiveConsole::GetMiscInfo()
1.471 + {
1.472 +/* TInt r=0;
1.473 + TDebugInterruptInfo IntInfo;
1.474 + r=iPort.GetInterruptsInfo(IntInfo);
1.475 + iConsole->Printf(_L("No writer dma interrupts: %d\r\n"),IntInfo.iNoTxDmaInts);
1.476 + iConsole->Printf(_L("No reader dma interrupts: %d\r\n"),IntInfo.iNoRxDmaInts);
1.477 + //iConsole->Printf(_L("Total Hspp interrupts: %d\r\n"),IntInfo.iNoHsspInts);
1.478 + iConsole->Printf(_L("Total Framing errors : %d\r\n"),IntInfo.iNoFREs);
1.479 + iConsole->Printf(_L("No xtra chars : %d\r\n"),IntInfo.iNoXtraChars);
1.480 + iConsole->Printf(_L("No unwanted chars : %d\r\n"),IntInfo.iNoUnwantedChars);
1.481 + iConsole->Printf(_L("No Rx dma leftovers : %d\r\n"),IntInfo.iNoRxDmaInts);*/
1.482 + }
1.483 +
1.484 +
1.485 +
1.486 +//
1.487 +// class CActiveRW
1.488 +//
1.489 +
1.490 +CActiveRW::CActiveRW(CConsoleBase* aConsole,RDevFir* aPort)
1.491 + : CActive (EPriorityNormal)
1.492 + {
1.493 + iConsole=aConsole;
1.494 + iPort=aPort;
1.495 + iLength=0;
1.496 + }
1.497 +
1.498 +CActiveRW* CActiveRW::NewL(CConsoleBase* aConsole,RDevFir* aPort)
1.499 + {
1.500 + CActiveRW* self = new (ELeave) CActiveRW(aConsole,aPort);
1.501 +
1.502 + CleanupStack::PushL (self);
1.503 + self->ConstructL();
1.504 + CActiveScheduler::Add (self);
1.505 + CleanupStack::Pop ();
1.506 + return (self);
1.507 + }
1.508 +
1.509 +void CActiveRW::ConstructL()
1.510 + {
1.511 + }
1.512 +
1.513 +CActiveRW::~CActiveRW()
1.514 + {
1.515 + Cancel();
1.516 + }
1.517 +
1.518 +void CActiveRW::RunL ()
1.519 + {
1.520 + TInt i=0;
1.521 + TInt wlength=0;
1.522 + TInt rlength=0;
1.523 + TInt iErrorRate=0;
1.524 + if (iStatus != KErrNone)
1.525 + iConsole->Printf(_L("Error %d\r\n"),iStatus.Int());
1.526 +
1.527 + //return;
1.528 + if(iTimeDelay)
1.529 + User::After(iTimeDelay);
1.530 +
1.531 +
1.532 + if(iNextXfer==EWriteXfer)
1.533 + {
1.534 +// ;
1.535 + iReadFramesCount++;
1.536 + rlength=ReadBuf[0]+(ReadBuf[1]<<8);
1.537 +
1.538 + if(rlength != ReadBuf.Length() || iStatus != KErrNone)
1.539 + {
1.540 + iFrameError++;
1.541 + RDebug::Print(_L("********* SHORT READ %d %d*********\n\r"),rlength, ReadBuf.Length());
1.542 + }
1.543 +
1.544 + if(iReadFramesCount>0)
1.545 + iErrorRate=(iFrameError*2000+iReadFramesCount)/(2*iReadFramesCount);
1.546 + else
1.547 + iErrorRate=0;
1.548 +
1.549 + iConsole->Printf(_L("R:%-4d FR %d EC %d Err %3d.%1d%%\r\n"),
1.550 + ReadBuf.Length(),iReadFramesCount,iFrameError, iErrorRate/10,iErrorRate%10);
1.551 +
1.552 + iLength=(iLength+1)%10;
1.553 + wlength=iBufSz+iLength;
1.554 + WriteBuf.SetLength(wlength);
1.555 + WriteBuf[0]=wlength;
1.556 + WriteBuf[1]=wlength>>8;
1.557 + iPort->Write(iStatus, WriteBuf, WriteBuf.Length());
1.558 + iNextXfer=EReadXfer;
1.559 +
1.560 + }
1.561 + else
1.562 + { // EReadXfer
1.563 + iConsole->Printf(_L("W:%-4d "),WriteBuf.Length());
1.564 + ResetReadBuffer();
1.565 + iPort->Read(iStatus, ReadBuf, ReadBuf.Length());
1.566 + iNextXfer=EWriteXfer;
1.567 + }
1.568 + SetActive();
1.569 + }
1.570 +
1.571 +void CActiveRW::Start(TBool StartWriting)
1.572 + {
1.573 + if(IsActive())
1.574 + return;
1.575 +
1.576 + if(StartWriting)
1.577 + {
1.578 + if(iDataStart==-1)
1.579 + {
1.580 + iDataStart=0x80;
1.581 + SetUpBuffers();
1.582 + }
1.583 + iConsole->Printf(_L("Starting with write.....\r\n"));
1.584 + WriteBuf.SetLength(iBufSz);
1.585 + WriteBuf[0]=iBufSz;
1.586 + WriteBuf[1]=iBufSz>>8;
1.587 + iPort->Write(iStatus, WriteBuf, WriteBuf.Length());
1.588 + iNextXfer=EReadXfer;
1.589 + }
1.590 + else
1.591 + {
1.592 + if(iDataStart==-1)
1.593 + {
1.594 + iDataStart=0x0;
1.595 + SetUpBuffers();
1.596 + }
1.597 + iConsole->Printf(_L("Starting with read.....\r\n"));
1.598 + iPort->Read(iStatus, ReadBuf, ReadBuf.Length());
1.599 + iNextXfer=EWriteXfer;
1.600 + }
1.601 + SetActive();
1.602 + }
1.603 +
1.604 +void CActiveRW::Stop()
1.605 + {
1.606 + iConsole->Printf(_L("Stopping.....\r\n"));
1.607 + Cancel();
1.608 + }
1.609 +
1.610 +void CActiveRW::DoCancel()
1.611 + {
1.612 + iPort->WriteCancel();
1.613 + iPort->ReadCancel();
1.614 + }
1.615 +
1.616 +#pragma warning (default:4710)