os/kernelhwsrv/kerneltest/e32test/device/t_ampv.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/device/t_ampv.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,259 @@
     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_ampv.cpp
    1.18 +// Approval tests for the Pc Card Adapter.
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include <e32std.h>
    1.23 +#include <e32std_private.h>
    1.24 +#include <e32cons.h>
    1.25 +#include <e32svr.h>
    1.26 +#include <e32hal.h>
    1.27 +#include <e32uid.h>
    1.28 +#include <d32comm.h>
    1.29 +
    1.30 +const TInt KRxBufSize=20;
    1.31 +const TInt KAmpVTimeout=2000000;
    1.32 +const TInt KUnit0=0;
    1.33 +
    1.34 +#if defined (__WINS__)
    1.35 +#define PDD_NAME _L("ECDRV.PDD")
    1.36 +#define LDD_NAME _L("ECOMM.LDD")
    1.37 +#else
    1.38 +#define PDD_NAME _L("EUART1.PDD")
    1.39 +#define LDD_NAME _L("ECOMM.LDD")
    1.40 +#endif
    1.41 +
    1.42 +class RComm : public RBusDevComm
    1.43 +	{
    1.44 +public:
    1.45 +	TInt WriteS(const TDesC8& aDes);
    1.46 +	};
    1.47 +
    1.48 +
    1.49 +GLDEF_D CConsoleBase *theConsole;
    1.50 +GLDEF_D RComm *theSerialPort;
    1.51 +
    1.52 +TInt RComm::WriteS(const TDesC8& aDes)
    1.53 +//
    1.54 +// Syncronous write
    1.55 +//
    1.56 +	{
    1.57 +
    1.58 +	TRequestStatus s;
    1.59 +	Write(s,aDes,aDes.Length());
    1.60 +	User::WaitForRequest(s);
    1.61 +	return(s.Int());
    1.62 +	}
    1.63 +
    1.64 +LOCAL_C void AmpVTest()
    1.65 +//
    1.66 +// Perform the test
    1.67 +//
    1.68 +	{
    1.69 +
    1.70 +    TInt errCount=0;
    1.71 +    TInt okStatus=0;
    1.72 +
    1.73 +	TRequestStatus tStat,sStat,kStat;
    1.74 +	TUint8 rxBuf[KRxBufSize];
    1.75 +	TPtr8 rxDes(&rxBuf[0],KRxBufSize,KRxBufSize);
    1.76 +	theSerialPort->Read(sStat,rxDes,0);	// Raise DTR and wake up the PCA
    1.77 +	User::WaitForRequest(sStat);
    1.78 +	User::After(4000000);				// 4Secs while PC card starts up
    1.79 +
    1.80 +	theSerialPort->WriteS(_L8("AT\r"));
    1.81 +	theSerialPort->WriteS(_L8("AT&f\r"));
    1.82 +	User::After(500000);		// 0.5S
    1.83 +	theSerialPort->ResetBuffers();
    1.84 +	theConsole->Printf(_L("Sending AT&V\n\r"));
    1.85 +	theSerialPort->WriteS(_L8("AT&V\r"));
    1.86 +
    1.87 +	RTimer tim;
    1.88 +	tim.CreateLocal();
    1.89 +	tim.After(tStat,KAmpVTimeout);
    1.90 +	theConsole->Read(kStat);
    1.91 +	theSerialPort->Read(sStat,rxDes,1);
    1.92 +
    1.93 +    FOREVER
    1.94 +        {
    1.95 +		User::WaitForAnyRequest();
    1.96 +		if (sStat!=KRequestPending)
    1.97 +			{
    1.98 +            // got another character
    1.99 +            if (sStat!=KErrNone)
   1.100 +                {
   1.101 +                // Bad character - initiate another try. 
   1.102 +                errCount++;
   1.103 +				tim.Cancel();
   1.104 +				User::WaitForRequest(tStat);
   1.105 +				User::After(200000);	
   1.106 +				theSerialPort->ResetBuffers();
   1.107 +				theConsole->Printf(_L("Errors:%d (Bad char-%d)\r\n"),errCount,sStat.Int());
   1.108 +				theConsole->Printf(_L("Sending AT&V\n\r"));
   1.109 +				theSerialPort->WriteS(_L8("AT&V\r"));
   1.110 +				tim.After(tStat,KAmpVTimeout);
   1.111 +                okStatus=0;
   1.112 +                }
   1.113 +            else
   1.114 +                {
   1.115 +                // Check if its CR/LF/OK/CR/LF
   1.116 +                switch(okStatus)
   1.117 +                    {
   1.118 +                    case 0:
   1.119 +                        okStatus=(rxBuf[0]=='\x0D')?(okStatus+1):0;
   1.120 +                        break;
   1.121 +                    case 1:
   1.122 +                        if (rxBuf[0]=='\x0A')
   1.123 +                            okStatus++;
   1.124 +                        else
   1.125 +                            okStatus=(rxBuf[0]=='\x0D')?1:0;
   1.126 +                        break;
   1.127 +                    case 2:
   1.128 +                        if (rxBuf[0]=='O')
   1.129 +                            okStatus++;
   1.130 +                        else
   1.131 +                            okStatus=(rxBuf[0]=='\x0D')?1:0;
   1.132 +                        break;
   1.133 +                    case 3:
   1.134 +                        if (rxBuf[0]=='K')
   1.135 +                            okStatus++;
   1.136 +                        else
   1.137 +                            okStatus=(rxBuf[0]=='\x0D')?1:0;
   1.138 +                        break;
   1.139 +                    case 4:
   1.140 +                        if (rxBuf[0]=='\x0D')
   1.141 +                            okStatus++;
   1.142 +                        else
   1.143 +                            okStatus=(rxBuf[0]=='\x0D')?1:0;
   1.144 +                        break;
   1.145 +                    case 5:
   1.146 +                        if (rxBuf[0]=='\x0A')
   1.147 +                            {
   1.148 +                            // Success - initiate another try. 
   1.149 +							tim.Cancel();
   1.150 +							User::WaitForRequest(tStat);
   1.151 +							User::After(200000);	
   1.152 +							theSerialPort->ResetBuffers(); 
   1.153 +							theConsole->Printf(_L("Errors:%d\r\n"),errCount);
   1.154 +							theConsole->Printf(_L("Sending AT&V\n\r"));
   1.155 +							theSerialPort->WriteS(_L8("AT&V\r"));
   1.156 +							tim.After(tStat,KAmpVTimeout);
   1.157 +                			okStatus=0;
   1.158 +                            }
   1.159 +                        else
   1.160 +                            okStatus=(rxBuf[0]=='\x0D')?1:0;
   1.161 +                        break;
   1.162 +                    default:
   1.163 +                        okStatus=0;
   1.164 +                    }
   1.165 +                }
   1.166 +            // Queue another serial read
   1.167 +			theSerialPort->Read(sStat,rxDes,1);
   1.168 +			}
   1.169 +		else if (tStat!=KRequestPending)
   1.170 +			{
   1.171 +            // Error - didn't get OK
   1.172 +			theSerialPort->ReadCancel();
   1.173 +			User::WaitForRequest(sStat);
   1.174 +            errCount++;
   1.175 +            // Initiate another try
   1.176 +			User::After(200000);	
   1.177 +			theSerialPort->ResetBuffers();
   1.178 +			theConsole->Printf(_L("Errors:%d (Timeout)\r\n"),errCount);
   1.179 +			theConsole->Printf(_L("Sending AT&V\n\r"));
   1.180 +			theSerialPort->WriteS(_L8("AT&V\r"));
   1.181 +			tim.After(tStat,KAmpVTimeout);
   1.182 +			theSerialPort->Read(sStat,rxDes,1);
   1.183 +            okStatus=0;
   1.184 +			}
   1.185 +        else if (kStat!=KRequestPending)
   1.186 +            {
   1.187 +			theSerialPort->ReadCancel();
   1.188 +			User::WaitForRequest(sStat);
   1.189 +			tim.Cancel();
   1.190 +			User::WaitForRequest(tStat);
   1.191 +            return;
   1.192 +            }
   1.193 +		else
   1.194 +			{
   1.195 +			theConsole->Printf(_L("ERROR - stray signal\r\n"));
   1.196 +			theConsole->ReadCancel();
   1.197 +			User::WaitForRequest(kStat);
   1.198 +			theSerialPort->ReadCancel();
   1.199 +			User::WaitForRequest(sStat);
   1.200 +			tim.Cancel();
   1.201 +			User::WaitForRequest(tStat);
   1.202 +			theConsole->Getch();
   1.203 +            return;
   1.204 +			}
   1.205 +        }
   1.206 +	}
   1.207 +
   1.208 +GLDEF_C TInt E32Main()
   1.209 +	{
   1.210 +	TCommConfig cBuf;
   1.211 +	TCommConfigV01 &c=cBuf();
   1.212 +
   1.213 +	// Create console
   1.214 +	theConsole=Console::NewL(_L("T_AMPV"),TSize(KDefaultConsWidth,KDefaultConsHeight));
   1.215 +
   1.216 +	// Load Device Drivers
   1.217 +	theConsole->Printf(_L("Load PDD\n\r"));
   1.218 +	TInt r;
   1.219 +	r=User::LoadPhysicalDevice(PDD_NAME);
   1.220 +	if (r!=KErrNone&&r!=KErrAlreadyExists)
   1.221 +		goto AmpvEnd;
   1.222 +	theConsole->Printf(_L("Load LDD\n\r"));
   1.223 +	r=User::LoadLogicalDevice(LDD_NAME);
   1.224 +	if (r!=KErrNone&&r!=KErrAlreadyExists)
   1.225 +		goto AmpvEnd;
   1.226 +
   1.227 +	// Create RComm object
   1.228 +	theConsole->Printf(_L("Create RComm object\n\r"));
   1.229 +	theSerialPort=new RComm;
   1.230 +	if (theSerialPort==NULL)
   1.231 +		goto AmpvEnd;
   1.232 +
   1.233 +	// Open Serial Port
   1.234 +	theConsole->Printf(_L("Open Serial Port\n\r"));
   1.235 +	r=theSerialPort->Open(KUnit0);
   1.236 +	if (r!=KErrNone)
   1.237 +		goto AmpvEnd;
   1.238 +
   1.239 +	// Setup serial port
   1.240 +	theConsole->Printf(_L("Setup serial port\n\r"));
   1.241 +	theSerialPort->Config(cBuf);
   1.242 +	c.iRate=EBps57600;
   1.243 +	c.iDataBits=EData8;
   1.244 +	c.iStopBits=EStop1;
   1.245 +	c.iParity=EParityNone;
   1.246 +//	c.iHandshake=KConfigObeyCTS;
   1.247 +	c.iHandshake=0;
   1.248 +	r=theSerialPort->SetConfig(cBuf);
   1.249 +	if (r!=KErrNone)
   1.250 +		goto AmpvEnd;
   1.251 +
   1.252 +	AmpVTest();
   1.253 +
   1.254 +AmpvEnd:
   1.255 +	if (theSerialPort)
   1.256 +		theSerialPort->Close();
   1.257 +	delete theSerialPort;
   1.258 +	delete theConsole;
   1.259 +	return(KErrNone);
   1.260 +	}
   1.261 +
   1.262 +