os/kernelhwsrv/kerneltest/e32test/iic/iic_psl/spi.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test/iic/iic_psl/spi.h
sl@0
    15
//
sl@0
    16
sl@0
    17
#ifndef SPI_H_
sl@0
    18
#define SPI_H_
sl@0
    19
sl@0
    20
#include <drivers/iic_channel.h>
sl@0
    21
#include "../t_iic.h"
sl@0
    22
sl@0
    23
#ifdef LOG_SPI
sl@0
    24
#define SPI_PRINT(str) Kern::Printf str
sl@0
    25
#else
sl@0
    26
#define SPI_PRINT(str)
sl@0
    27
#endif
sl@0
    28
sl@0
    29
#ifndef STANDALONE_CHANNEL
sl@0
    30
const TInt8 KSpiChannelNumBase = 1;	// Arbitrary, real platform may consult the Configuration Repository
sl@0
    31
									// Note limit of 5 bit representation (0-31)
sl@0
    32
#endif
sl@0
    33
sl@0
    34
class THwDoneCallBack : public TDfc
sl@0
    35
	{
sl@0
    36
public:
sl@0
    37
	inline THwDoneCallBack(THwDoneCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority) : TDfc(DfcFn, this, aQue, aPriority),iCbFn(aFn),iParam(aPtr) {}
sl@0
    38
	inline ~THwDoneCallBack(){}
sl@0
    39
	
sl@0
    40
private:
sl@0
    41
	inline static void DfcFn(TAny* aPtr)
sl@0
    42
		{
sl@0
    43
		THwDoneCallBack* pCb = (THwDoneCallBack*) aPtr;
sl@0
    44
		pCb -> iCbFn(pCb->iParam);
sl@0
    45
		}
sl@0
    46
	
sl@0
    47
private:
sl@0
    48
	THwDoneCbFn iCbFn;
sl@0
    49
	TAny* iParam;
sl@0
    50
	};
sl@0
    51
sl@0
    52
class DSimulatedIicBusChannelMasterSpi : public DIicBusChannelMaster
sl@0
    53
	{
sl@0
    54
	// platform specific implementation
sl@0
    55
sl@0
    56
	enum TTestState
sl@0
    57
		{
sl@0
    58
		ETestNone=0,
sl@0
    59
		ETestWaitPriorityTest,
sl@0
    60
		ETestWaitTransOne,
sl@0
    61
		ETestSlaveTimeOut
sl@0
    62
		};
sl@0
    63
	
sl@0
    64
	enum TMyState
sl@0
    65
		{
sl@0
    66
		EIdle,
sl@0
    67
		EBusy
sl@0
    68
		};
sl@0
    69
	
sl@0
    70
	enum TIsrCause
sl@0
    71
		{
sl@0
    72
		EHwTransferDone,
sl@0
    73
		ETimeExpired
sl@0
    74
		};
sl@0
    75
	
sl@0
    76
public:
sl@0
    77
#ifdef STANDALONE_CHANNEL
sl@0
    78
	IMPORT_C
sl@0
    79
#endif
sl@0
    80
	DSimulatedIicBusChannelMasterSpi(const TBusType aBusType, const TChannelDuplex aChanDuplex);
sl@0
    81
	~DSimulatedIicBusChannelMasterSpi(){iDynamicDfcQ->Destroy();};
sl@0
    82
	inline TInt Create() {return DoCreate();}
sl@0
    83
	TInt DoCreate();
sl@0
    84
	TInt ReleaseChanArray();
sl@0
    85
	void CompleteReq(TInt aResult);
sl@0
    86
sl@0
    87
private:
sl@0
    88
	TInt CheckHdr(TDes8* aHdr);	// Check the header is valid for this channel
sl@0
    89
	virtual TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);	
sl@0
    90
sl@0
    91
	TInt CompareTransactionOne(TIicBusTransaction* aTransaction);
sl@0
    92
sl@0
    93
public:
sl@0
    94
	// gateway function for PSL implementation
sl@0
    95
	TInt DoRequest(TIicBusTransaction* aTransaction);
sl@0
    96
	TInt HandleSlaveTimeout();
sl@0
    97
	// Test functions to allow simulating delayed processing of requests
sl@0
    98
	static TBool IsRequestDelayed(DSimulatedIicBusChannelMasterSpi* aChan);
sl@0
    99
	static void SetRequestDelayed(DSimulatedIicBusChannelMasterSpi* aChan,TBool aDelay);
sl@0
   100
sl@0
   101
	TInt ProcessTrans(TIicBusTransaction* aTransaction); // Accessed by callback
sl@0
   102
	TInt AsynchStateMachine(TInt aReason);
sl@0
   103
	TInt DoSimulatedTransaction();
sl@0
   104
	TInt DoHwPreparation();
sl@0
   105
	static void TransactionTimerCallBack(TAny*);
sl@0
   106
	
sl@0
   107
	inline TInt8 GetChanNum() {return iChannelNumber;};
sl@0
   108
private:
sl@0
   109
	TDynamicDfcQue*	iDynamicDfcQ;	// Use TDynamicDfcQue since will want to DeRegister channels
sl@0
   110
	
sl@0
   111
	TIicBusTransaction* iCurrTrans;
sl@0
   112
	
sl@0
   113
	static TInt8 iCurrentChanNum;
sl@0
   114
sl@0
   115
	TInt8 iTestState;
sl@0
   116
	TInt8 iChannelState;
sl@0
   117
	
sl@0
   118
	TBool iReqDelayed;
sl@0
   119
	THwDoneCallBack *iCb;
sl@0
   120
	TInt iPriorityTestResult[KPriorityTestNum];
sl@0
   121
	TBool iPriorityTestDone;
sl@0
   122
	};
sl@0
   123
#ifndef STANDALONE_CHANNEL
sl@0
   124
TInt8 DSimulatedIicBusChannelMasterSpi::iCurrentChanNum = KSpiChannelNumBase; // Initialise static member of DSimulatedIicBusChannelMasterSpi
sl@0
   125
#endif
sl@0
   126
class DSimulatedIicBusChannelSlaveSpi : public DIicBusChannelSlave
sl@0
   127
	{
sl@0
   128
public:
sl@0
   129
	// platform specific implementation
sl@0
   130
#ifdef STANDALONE_CHANNEL
sl@0
   131
	IMPORT_C
sl@0
   132
#endif
sl@0
   133
	DSimulatedIicBusChannelSlaveSpi(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex);
sl@0
   134
	inline TInt Create() {return DoCreate();}
sl@0
   135
	TInt DoCreate();
sl@0
   136
	// gateway function for PSL implementation
sl@0
   137
	TInt DoRequest(TInt aTrigger);
sl@0
   138
	void ProcessData(TInt aTrigger, TIicBusSlaveCallback*  aCb);
sl@0
   139
	virtual TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);	
sl@0
   140
	static void SlaveAsyncSimCallback(TAny* aPtr);
sl@0
   141
	inline void ChanCaptureCb(TInt aResult) {ChanCaptureCallback(aResult);}
sl@0
   142
	inline void SetChanNum(TInt8 aChanNum) {iChannelNumber = aChanNum;};
sl@0
   143
protected:
sl@0
   144
	virtual void SendBusErrorAndReturn() {return;} // Not implemented in simulated PSL
sl@0
   145
sl@0
   146
	private:
sl@0
   147
	TInt CheckHdr(TDes8* aHdr);	// Check the header is valid for this channel
sl@0
   148
	virtual TInt CaptureChannelPsl(TDes8* aConfigHdr, TBool aAsynch);
sl@0
   149
sl@0
   150
private:
sl@0
   151
	NTimer iSlaveTimer;
sl@0
   152
	};
sl@0
   153
sl@0
   154
sl@0
   155
sl@0
   156
#endif /*SPI_H_*/