kerneltest/e32test/dma/d_dma.h
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2002-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\dma\d_dma.h
       
    15 // User-side API for LDD used to test DMA framework.
       
    16 // 
       
    17 //
       
    18 
       
    19 #ifndef __D_DMA_H__
       
    20 #define __D_DMA_H__
       
    21 
       
    22 #include <e32cmn.h>
       
    23 #ifndef __KLIB_H__
       
    24 #include <e32std.h>
       
    25 #endif
       
    26 
       
    27 #ifdef __DMASIM__
       
    28 _LIT(KTestDmaLddName, "TestDmaSim");
       
    29 #else
       
    30 _LIT(KTestDmaLddName, "TestDma");
       
    31 #endif
       
    32 
       
    33 inline TVersion TestDmaLddVersion() { return TVersion(1, 0, 1); }
       
    34 
       
    35 class RTestDma : public RBusLogicalChannel
       
    36 	{
       
    37 public:
       
    38 	struct TFragmentInfo
       
    39 		{
       
    40 		TInt iRequestIdx;
       
    41 		TInt iSrcBufIdx;
       
    42 		TInt iDestBufIdx;
       
    43 		TInt iSize;
       
    44 		TRequestStatus* iRs;
       
    45 		};
       
    46 	struct TOpenInfo
       
    47 		{
       
    48 		enum { EGetInfo, EOpen } iWhat;
       
    49 		union
       
    50 			{
       
    51 			TAny* iInfo;
       
    52 			struct
       
    53 				{
       
    54 				TUint32 iId;
       
    55 				TInt iDesCount;
       
    56 				TInt iMaxTransferSize;
       
    57 				} iOpen;
       
    58 			} U;
       
    59 		};
       
    60 	enum TControl
       
    61 		{
       
    62 		EAllocBuffer,
       
    63 		EFreeAllBuffers,
       
    64 		EFillBuffer,
       
    65 		ECheckBuffer,
       
    66 		EFragment,
       
    67 		EExecute,
       
    68 		EFailNext,
       
    69 		EFragmentCount,
       
    70 		EMissInterrupts,
       
    71 		};
       
    72 	enum { KMaxChannels = 32 };
       
    73 	struct TInfo
       
    74 		{
       
    75 		TInt iMaxTransferSize;
       
    76 		TUint iMemAlignMask;
       
    77 		TInt iMaxSbChannels;
       
    78 		TUint32 iSbChannels[KMaxChannels];
       
    79 		TInt iMaxDbChannels;
       
    80 		TUint32 iDbChannels[KMaxChannels];
       
    81 		TInt iMaxSgChannels;
       
    82 		TUint32 iSgChannels[KMaxChannels];
       
    83 		};
       
    84 public:
       
    85 #ifndef __KERNEL_MODE__
       
    86 	inline TInt GetInfo(TInfo& aInfo);
       
    87 	inline TInt Open(TUint32 aId, TInt aDesCount, TInt aMaxTransferSize);
       
    88 	inline TInt AllocBuffer(TInt aBufIdx, TInt aSize);
       
    89 	inline void FreeAllBuffers();
       
    90 	inline void FillBuffer(TInt aBufIdx, TUint8 aFillValue);
       
    91 	inline TBool CheckBuffer(TInt aBufIdx, TUint8 aValue);
       
    92 	inline TInt Fragment(TInt aRequestIdx, TInt aSrcBufIdx, TInt aDestBufIdx, TInt aSize, TRequestStatus* aRs=NULL);
       
    93 	inline TInt Execute(const TDesC8& aCmd);
       
    94 	inline TInt FailNext(TInt aFragmentCount);
       
    95 	inline TInt FragmentCount(TInt aRequestIdx);
       
    96 	inline TInt MissNextInterrupts(TInt aInterruptCount);
       
    97 	inline TBool FragmentCheck(TInt aRequestIdx, TInt aExpectedCount);
       
    98 #endif
       
    99 	};
       
   100 
       
   101 #ifndef __KERNEL_MODE__
       
   102 
       
   103 inline TInt RTestDma::GetInfo(TInfo& aInfo)
       
   104 	{
       
   105 	TPckgBuf<TOpenInfo> infoBuf;
       
   106 	infoBuf().iWhat = TOpenInfo::EGetInfo;
       
   107 	infoBuf().U.iInfo = &aInfo;
       
   108 	return DoCreate(KTestDmaLddName, TestDmaLddVersion(), 0, NULL, &infoBuf) == KErrDied ? KErrNone : KErrGeneral;
       
   109 	}
       
   110 
       
   111 inline TInt RTestDma::Open(TUint32 aId, TInt aDesCount, TInt aMaxTransferSize)
       
   112 	{
       
   113 	TPckgBuf<TOpenInfo> infoBuf;
       
   114 	infoBuf().iWhat = TOpenInfo::EOpen;
       
   115 	infoBuf().U.iOpen.iId = aId;
       
   116 	infoBuf().U.iOpen.iDesCount = aDesCount;
       
   117 	infoBuf().U.iOpen.iMaxTransferSize = aMaxTransferSize;
       
   118 	return DoCreate(KTestDmaLddName, TestDmaLddVersion(), 0, NULL, &infoBuf, EOwnerThread);
       
   119 	}
       
   120 
       
   121 inline TInt RTestDma::AllocBuffer(TInt aBufIdx, TInt aSize)
       
   122 	{
       
   123 	return DoControl(EAllocBuffer, (TAny*)aBufIdx, (TAny*)aSize);
       
   124 	}
       
   125 
       
   126 inline void RTestDma::FreeAllBuffers()
       
   127 	{
       
   128 	DoControl(EFreeAllBuffers, NULL, NULL);
       
   129 	}
       
   130 
       
   131 inline void RTestDma::FillBuffer(TInt aBufIdx, TUint8 aFillValue)
       
   132 	{
       
   133 	DoControl(EFillBuffer, (TAny*)aBufIdx, (TAny*)(TUint)aFillValue);
       
   134 	}
       
   135 
       
   136 inline TBool RTestDma::CheckBuffer(TInt aBufIdx, TUint8 aValue)
       
   137 	{
       
   138 	return DoControl(ECheckBuffer, (TAny*)aBufIdx, (TAny*)(TUint)aValue);
       
   139 	}
       
   140 
       
   141 inline TInt RTestDma::Fragment(TInt aRequestIdx, TInt aSrcBufIdx, TInt aDestBufIdx, TInt aSize, TRequestStatus* aRs)
       
   142 	{
       
   143 	TFragmentInfo info;
       
   144 	info.iRequestIdx = aRequestIdx;
       
   145 	info.iSrcBufIdx = aSrcBufIdx;
       
   146 	info.iDestBufIdx = aDestBufIdx;
       
   147 	info.iSize = aSize;
       
   148 	info.iRs = aRs;
       
   149 	if (aRs != NULL)
       
   150 		*aRs = KRequestPending;
       
   151 	return DoControl(EFragment, &info, NULL);
       
   152 	}
       
   153 
       
   154 inline TInt RTestDma::Execute(const TDesC8& aCmd)
       
   155 	{
       
   156 	return DoControl(EExecute, (TDesC8*)&aCmd, NULL);
       
   157 	}
       
   158 
       
   159 inline TInt RTestDma::FailNext(TInt aFragmentCount)
       
   160 	{
       
   161 	return DoControl(EFailNext, (TAny*)aFragmentCount, NULL);
       
   162 	}
       
   163 
       
   164 inline TInt RTestDma::FragmentCount(TInt aRequestIdx)
       
   165 	{
       
   166 	return DoControl(EFragmentCount, (TAny*)aRequestIdx, NULL);
       
   167 	}
       
   168 
       
   169 inline TInt RTestDma::MissNextInterrupts(TInt aInterruptCount)
       
   170 	{
       
   171 	return DoControl(EMissInterrupts, (TAny*)aInterruptCount, NULL);
       
   172 	}
       
   173 
       
   174 /**
       
   175 @param The number of fragments expected, 0 means don't check
       
   176 */
       
   177 inline TBool RTestDma::FragmentCheck(TInt aRequestIdx, TInt aExpectedCount)
       
   178 	{
       
   179 	if(aExpectedCount)
       
   180 		{
       
   181 		TInt actualCount = FragmentCount(aRequestIdx);
       
   182 		if(actualCount == aExpectedCount)
       
   183 			return ETrue;
       
   184 		else
       
   185 			{
       
   186 			RDebug::Printf("Fragment count error: expected %d, got %d", aExpectedCount, actualCount);
       
   187 			return EFalse;
       
   188 			}
       
   189 		}
       
   190 	else
       
   191 		return ETrue;
       
   192 	}
       
   193 #endif // #ifndef __KERNEL_MODE__
       
   194 
       
   195 #endif