kerneltest/e32test/dma/d_dma.cpp
branchRCL_3
changeset 21 e7d2d738d3c2
parent 8 538db54a451d
child 22 2f92ad2dc5db
equal deleted inserted replaced
20:597aaf25e343 21:e7d2d738d3c2
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   183 	virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
   183 	virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
   184 private:
   184 private:
   185 	TInt Execute(const TDesC8& aDes);
   185 	TInt Execute(const TDesC8& aDes);
   186 	static void Dfc(DDmaRequest::TResult aResult, TAny* aArg);
   186 	static void Dfc(DDmaRequest::TResult aResult, TAny* aArg);
   187 	TInt DoGetInfo(TAny* aInfo);
   187 	TInt DoGetInfo(TAny* aInfo);
       
   188 	void FreeDmaRequests();
       
   189 	void FreeClientRequests();
   188 private:
   190 private:
   189 	TUint32 iCookie;
   191 	TUint32 iCookie;
   190 	TBufferMgr iBufMgr;
   192 	TBufferMgr iBufMgr;
   191 	TDmaChannel* iChannel;
   193 	TDmaChannel* iChannel;
   192 	enum { KMaxRequests = 8 };
   194 	enum { KMaxRequests = 8 };
   193 	DDmaRequest* iRequests[KMaxRequests];
   195 	DDmaRequest* iRequests[KMaxRequests];
   194 	TClientRequest* iClientRequests[KMaxRequests];
   196 	TClientRequest* iClientRequests[KMaxRequests];
   195 	DDmaTestChannel* iMap[KMaxRequests];
   197 	DDmaTestChannel* iMap[KMaxRequests];
       
   198 	TBool iCloseInCb[KMaxRequests];
   196 	TUint32 iMemMemPslInfo;
   199 	TUint32 iMemMemPslInfo;
   197 	DThread* iClient;
   200 	DThread* iClient;
   198 	TDynamicDfcQue* iDfcQ;
   201 	TDynamicDfcQue* iDfcQ;
   199 	};
   202 	};
   200 
   203 
   275 				// Exercise request with default limit
   278 				// Exercise request with default limit
   276 				iRequests[i] = new DDmaRequest(*iChannel, Dfc, iMap+i);
   279 				iRequests[i] = new DDmaRequest(*iChannel, Dfc, iMap+i);
   277 				}
   280 				}
   278 			if (! iRequests[i])
   281 			if (! iRequests[i])
   279 				return KErrNoMemory;
   282 				return KErrNoMemory;
       
   283 
       
   284 			iCloseInCb[i] = EFalse;
   280 			}
   285 			}
   281 		return KErrNone;
   286 		return KErrNone;
   282 		}
   287 		}
   283 	}
   288 	}
   284 
   289 
   286 DDmaTestChannel::~DDmaTestChannel()
   291 DDmaTestChannel::~DDmaTestChannel()
   287 	{
   292 	{
   288 	if (iChannel)
   293 	if (iChannel)
   289 		{
   294 		{
   290 		iChannel->CancelAll();
   295 		iChannel->CancelAll();
   291 		TInt i;
   296 		FreeDmaRequests();
   292 		for (i=0; i<KMaxRequests; ++i)
       
   293 			delete iRequests[i];
       
   294 		iChannel->Close();
   297 		iChannel->Close();
   295 		for (i=0; i<KMaxRequests; ++i)
   298 		}
   296 			Kern::DestroyClientRequest(iClientRequests[i]);
   299 	FreeClientRequests();
   297 		}
       
   298 	if (iDfcQ)
   300 	if (iDfcQ)
   299 		{
   301 		{
   300 		iDfcQ->Destroy();
   302 		iDfcQ->Destroy();
   301 		}
   303 		}
   302 	iBufMgr.FreeAll();
   304 	iBufMgr.FreeAll();
       
   305 	}
       
   306 
       
   307 void DDmaTestChannel::FreeDmaRequests()
       
   308 	{
       
   309 	for (TInt i=0; i<KMaxRequests; ++i)
       
   310 		{
       
   311 		delete iRequests[i];
       
   312 		iRequests[i] = NULL;
       
   313 		}
       
   314 	}
       
   315 
       
   316 void DDmaTestChannel::FreeClientRequests()
       
   317 	{
       
   318 	for (TInt i=0; i<KMaxRequests; ++i)
       
   319 		{
       
   320 		Kern::DestroyClientRequest(iClientRequests[i]);
       
   321 		}
   303 	}
   322 	}
   304 
   323 
   305 
   324 
   306 TInt DDmaTestChannel::Request(TInt aFunction, TAny* a1, TAny* a2)
   325 TInt DDmaTestChannel::Request(TInt aFunction, TAny* a1, TAny* a2)
   307 	{
   326 	{
   399 		TText8 opcode = *p++;
   418 		TText8 opcode = *p++;
   400 		switch (opcode)
   419 		switch (opcode)
   401 			{
   420 			{
   402 		case 'Q':
   421 		case 'Q':
   403 			{
   422 			{
   404 			TInt arg = *p++ - '0';
   423 			__ASSERT_DEBUG(p < pEnd, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
   405 			__ASSERT_DEBUG(0 <= arg && arg < KMaxRequests, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
   424 			TInt nextChar = *p++;
   406 			iRequests[arg]->Queue();
   425 			TInt channel = -1;
       
   426 
       
   427 			if(nextChar == 'X')
       
   428 				{
       
   429 				// Channel should be closed in callback
       
   430 				__ASSERT_DEBUG(p < pEnd, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
       
   431 				channel = *p++ - '0';
       
   432 				iCloseInCb[channel] = ETrue;
       
   433 				}
       
   434 			else
       
   435 				{
       
   436 				channel = nextChar - '0';
       
   437 				}
       
   438 			__ASSERT_DEBUG(0 <= channel && channel < KMaxRequests, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
       
   439 			iRequests[channel]->Queue();
   407 			break;
   440 			break;
   408 			}
   441 			}
   409 		case 'C':
   442 		case 'C':
   410 			iChannel->CancelAll();
   443 			iChannel->CancelAll();
   411 			break;
   444 			break;
   422 	DDmaTestChannel** ppC = (DDmaTestChannel**)aArg;
   455 	DDmaTestChannel** ppC = (DDmaTestChannel**)aArg;
   423 	DDmaTestChannel* pC = *ppC;
   456 	DDmaTestChannel* pC = *ppC;
   424 	TInt i = ppC - pC->iMap;
   457 	TInt i = ppC - pC->iMap;
   425 	TClientRequest* req = pC->iClientRequests[i];
   458 	TClientRequest* req = pC->iClientRequests[i];
   426 	TInt r = (aResult==DDmaRequest::EOk) ? KErrNone : KErrGeneral;
   459 	TInt r = (aResult==DDmaRequest::EOk) ? KErrNone : KErrGeneral;
       
   460 
       
   461 	if(pC->iCloseInCb[i])
       
   462 		{
       
   463 		pC->iCloseInCb[i] = EFalse;
       
   464 		__KTRACE_OPT(KDMA, Kern::Printf("Close channel in callback"));
       
   465 
       
   466 		pC->FreeDmaRequests();
       
   467 		pC->iChannel->Close();
       
   468 		pC->iChannel = NULL;
       
   469 		}
       
   470 
   427 	if (req->IsReady())
   471 	if (req->IsReady())
   428 		Kern::QueueRequestComplete(pC->iClient, req, r);
   472 		Kern::QueueRequestComplete(pC->iClient, req, r);
   429 	}
   473 	}
   430 
   474 
   431 //////////////////////////////////////////////////////////////////////////////
   475 //////////////////////////////////////////////////////////////////////////////