kerneltest/e32test/dmav2/d_dma2.cpp
changeset 293 0659d0e1a03c
parent 243 c7a0ce20c48c
equal deleted inserted replaced
291:206a6eaaeb71 293:0659d0e1a03c
    18 #include <kernel/kern_priv.h>
    18 #include <kernel/kern_priv.h>
    19 #include <drivers/dma.h>
    19 #include <drivers/dma.h>
    20 #include "d_dma2.h"
    20 #include "d_dma2.h"
    21 
    21 
    22 _LIT(KClientPanicCat, "D_DMA2");
    22 _LIT(KClientPanicCat, "D_DMA2");
    23 _LIT(KDFCThreadName,"D_DMA_DFC_THREAD");
    23 _LIT(KDFCThreadName, "D_DMA_DFC_THREAD");
    24 _LIT(KIsrCbDfcThreadName,"D_DMA_IsrCb_thread");
    24 _LIT(KIsrCbDfcThreadName, "D_DMA_IsrCb_thread");
    25 const TInt KDFCThreadPriority=26;
       
    26 
    25 
    27 class TStopwatch
    26 class TStopwatch
    28 	{
    27 	{
    29 public:
    28 public:
    30 	TStopwatch()
    29 	TStopwatch()
   318 	iClientDataRequest->Data1().Reset();
   317 	iClientDataRequest->Data1().Reset();
   319 	iClientDataRequest->SetDestPtr1(aRecord);
   318 	iClientDataRequest->SetDestPtr1(aRecord);
   320 
   319 
   321 	iClientDataRequest->SetDestPtr2(aDurationMicroSecs);
   320 	iClientDataRequest->SetDestPtr2(aDurationMicroSecs);
   322 
   321 
   323 
       
   324 	TInt r = iClientDataRequest->SetStatus(aRequestStatus);
   322 	TInt r = iClientDataRequest->SetStatus(aRequestStatus);
   325 	if(r != KErrNone)
   323 	if(r != KErrNone)
   326 		{
   324 		{
   327 		return r;
   325 		return r;
   328 		}
   326 		}
   530 DDmaTestSession::DDmaTestSession()
   528 DDmaTestSession::DDmaTestSession()
   531 	: iClient(NULL), iDfcQ(NULL), iIsrCallbackDfcQ(NULL), iChunkBase(0), iChunk(NULL)
   529 	: iClient(NULL), iDfcQ(NULL), iIsrCallbackDfcQ(NULL), iChunkBase(0), iChunk(NULL)
   532 	{}
   530 	{}
   533 
   531 
   534 // called in thread critical section
   532 // called in thread critical section
   535 TInt DDmaTestSession::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
   533 TInt DDmaTestSession::DoCreate(TInt /*aUnit*/, const TDesC8* aInfo, const TVersion& /*aVer*/)
   536 	{
   534 	{
   537 	__NK_ASSERT_ALWAYS(iDfcQ == NULL);
   535 	__NK_ASSERT_ALWAYS(iDfcQ == NULL);
   538 	__NK_ASSERT_ALWAYS(iIsrCallbackDfcQ == NULL);
   536 	__NK_ASSERT_ALWAYS(iIsrCallbackDfcQ == NULL);
   539 
   537 
   540 	TInt r = Kern::DynamicDfcQCreate(iDfcQ, KDFCThreadPriority, KDFCThreadName);
   538 	const TInt dfcThreadPrio = reinterpret_cast<TInt>(aInfo);
       
   539 
       
   540 	TInt r = Kern::DynamicDfcQCreate(iDfcQ, dfcThreadPrio, KDFCThreadName);
   541 	if (r != KErrNone)
   541 	if (r != KErrNone)
   542 		{
   542 		{
   543 		Kern::Printf("DDmaTestSession::DoCreate D_DMA_DFC_THREAD returned (%d)\n", r);
   543 		Kern::Printf("DDmaTestSession::DoCreate D_DMA_DFC_THREAD returned (%d)\n", r);
   544 		return r;
   544 		return r;
   545 		}
   545 		}
   546 	NKern::ThreadSetCpuAffinity((NThread*)(iDfcQ->iThread), KCpuAffinityAny);
   546 	NKern::ThreadSetCpuAffinity((NThread*)(iDfcQ->iThread), KCpuAffinityAny);
   547 
   547 
   548 	r = Kern::DynamicDfcQCreate(iIsrCallbackDfcQ, KDFCThreadPriority, KIsrCbDfcThreadName);
   548 	r = Kern::DynamicDfcQCreate(iIsrCallbackDfcQ, dfcThreadPrio, KIsrCbDfcThreadName);
   549 	if (r != KErrNone)
   549 	if (r != KErrNone)
   550 		{
   550 		{
   551 		Kern::Printf("DDmaTestSession::DoCreate D_DMA_IsrCb_thread returned (%d)\n", r);
   551 		Kern::Printf("DDmaTestSession::DoCreate D_DMA_IsrCb_thread returned (%d)\n", r);
   552 		return r;
   552 		return r;
   553 		}
   553 		}
   554 	NKern::ThreadSetCpuAffinity((NThread*)(iIsrCallbackDfcQ->iThread), KCpuAffinityAny);
   554 	NKern::ThreadSetCpuAffinity((NThread*)(iIsrCallbackDfcQ->iThread), KCpuAffinityAny);
   555 
   555 
   556 	iClient = &Kern::CurrentThread();
   556 	iClient = &Kern::CurrentThread();
   557 
   557 
   558 	r = CreateSharedChunk();
   558 	r = CreateSharedChunk();
   559 	Kern::Printf("DDmaTestSession::DoCreate CreateSharedChunk returned (%d)\n", r);
   559 	if (r != KErrNone)
       
   560 		{
       
   561 		Kern::Printf("DDmaTestSession::DoCreate CreateSharedChunk returned %d", r);
       
   562 		}
       
   563 
   560 	return r;
   564 	return r;
   561 	}
   565 	}
   562 
   566 
   563 DDmaTestSession::~DDmaTestSession()
   567 DDmaTestSession::~DDmaTestSession()
   564 	{
   568 	{
  1429 	}
  1433 	}
  1430 
  1434 
  1431 TInt DDmaTestSession::CreateSharedChunk()
  1435 TInt DDmaTestSession::CreateSharedChunk()
  1432 	{
  1436 	{
  1433     // Enter critical section so we can't die and leak the objects we are creating
  1437     // Enter critical section so we can't die and leak the objects we are creating
  1434     // I.e. the TChunkCleanup and DChunk (Shared Chunk)
       
  1435     NKern::ThreadEnterCS();
  1438     NKern::ThreadEnterCS();
  1436 
  1439 
  1437     // Create the chunk
  1440     // Create the chunk
  1438     TChunkCreateInfo info;
  1441     TChunkCreateInfo info;
  1439     info.iType         = TChunkCreateInfo::ESharedKernelSingle;
  1442     info.iType         = TChunkCreateInfo::ESharedKernelSingle;
  1446     info.iDestroyedDfc = NULL;
  1449     info.iDestroyedDfc = NULL;
  1447 
  1450 
  1448     DChunk* chunk;
  1451     DChunk* chunk;
  1449 	TUint32 mapAttr;
  1452 	TUint32 mapAttr;
  1450     TInt r = Kern::ChunkCreate(info, chunk, iChunkBase, mapAttr);
  1453     TInt r = Kern::ChunkCreate(info, chunk, iChunkBase, mapAttr);
  1451     if(r!=KErrNone)
  1454     if (r != KErrNone)
  1452         {
  1455         {
  1453         NKern::ThreadLeaveCS();
  1456         NKern::ThreadLeaveCS();
       
  1457 		Kern::Printf("DDmaTestSession::CreateSharedChunk ChunkCreate returned %d", r);
  1454         return r;
  1458         return r;
  1455         }
  1459         }
  1456 
  1460 
  1457     // Map our device's memory into the chunk (at offset 0)
  1461     // Map our device's memory into the chunk (at offset 0)
  1458 	TUint32 physicalAddr;
  1462 	TUint32 physicalAddr;
  1459 	r = Kern::ChunkCommitContiguous(chunk,0,KMaxChunkSize, physicalAddr);
  1463 	r = Kern::ChunkCommitContiguous(chunk, 0, KMaxChunkSize, physicalAddr);
  1460     if(r!=KErrNone)
  1464     if (r != KErrNone)
  1461         {
  1465         {
  1462         // Commit failed so tidy-up...
  1466         // Commit failed, so tidy-up...
  1463         Kern::ChunkClose(chunk);
  1467         Kern::ChunkClose(chunk);
       
  1468 		Kern::Printf("DDmaTestSession::CreateSharedChunk ChunkCommitContiguous returned %d", r);
  1464         }
  1469         }
  1465     else
  1470     else
  1466         {
  1471         {
  1467         iChunk = chunk;
  1472         iChunk = chunk;
  1468         }
  1473         }
  1516 	}
  1521 	}
  1517 
  1522 
  1518 TInt DDmaTestSession::FragmentRequest(TUint aRequestCookie, const TDmaTransferArgs& aTransferArgs, TBool aLegacy)
  1523 TInt DDmaTestSession::FragmentRequest(TUint aRequestCookie, const TDmaTransferArgs& aTransferArgs, TBool aLegacy)
  1519 	{
  1524 	{
  1520 	__KTRACE_OPT(KDMA, Kern::Printf(">FragmentRequest: cookie=0x%08x, legacy=%d", aRequestCookie, aLegacy)); 
  1525 	__KTRACE_OPT(KDMA, Kern::Printf(">FragmentRequest: cookie=0x%08x, legacy=%d", aRequestCookie, aLegacy)); 
       
  1526 
  1521 	TInt requestIndex = CookieToRequestIndex(aRequestCookie);
  1527 	TInt requestIndex = CookieToRequestIndex(aRequestCookie);
  1522 	if(requestIndex < 0)
  1528 	if(requestIndex < 0)
  1523 		return requestIndex;
  1529 		return requestIndex;
  1524 
  1530 
  1525 	DClientDmaRequest& request = *iClientDmaReqs[requestIndex];
  1531 	DClientDmaRequest& request = *iClientDmaReqs[requestIndex];
  1637     }
  1643     }
  1638 
  1644 
  1639 
  1645 
  1640 TInt DDmaTestFactory::Create(DLogicalChannelBase*& aChannel)
  1646 TInt DDmaTestFactory::Create(DLogicalChannelBase*& aChannel)
  1641     {
  1647     {
  1642 	aChannel=new DDmaTestSession;
  1648 	aChannel = new DDmaTestSession;
  1643 	Kern::Printf("DDmaTestFactory::Create %d\n", aChannel?KErrNone : KErrNoMemory);
  1649 	if (!aChannel)
       
  1650 		{
       
  1651 		Kern::Printf("DDmaTestFactory::Create failed\n");
       
  1652 		}
  1644 	return aChannel ? KErrNone : KErrNoMemory;
  1653 	return aChannel ? KErrNone : KErrNoMemory;
  1645     }
  1654     }
  1646 
  1655 
  1647 
  1656 
  1648 TInt DDmaTestFactory::Install()
  1657 TInt DDmaTestFactory::Install()