os/kernelhwsrv/kerneltest/e32test/iic/iic_psl/i2c.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/i2c.h
sl@0
    15
//
sl@0
    16
sl@0
    17
#ifndef I2C_H_
sl@0
    18
#define I2C_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
#define NUM_CHANNELS 3 // Arbitrary
sl@0
    24
sl@0
    25
#ifdef LOG_I2C
sl@0
    26
#define I2C_PRINT(str) Kern::Printf str
sl@0
    27
#else
sl@0
    28
#define I2C_PRINT(str)
sl@0
    29
#endif
sl@0
    30
sl@0
    31
_LIT(KI2cThreadName,"I2cChannelThread");
sl@0
    32
sl@0
    33
#ifndef STANDALONE_CHANNEL
sl@0
    34
#if defined(MASTER_MODE)
sl@0
    35
const TInt8 KI2cChannelNumBase = 10;	// Arbitrary, real platform may consult the Configuration Repository
sl@0
    36
										// Note limit of 5 bit representation (0-31)
sl@0
    37
sl@0
    38
#else/*MASTER_MODE*/
sl@0
    39
const TInt8 KI2cChannelNumBase = 10 + NUM_CHANNELS;	// For Slave mode, want to provide different response
sl@0
    40
													// If client assumes Master mode, should be informed not available
sl@0
    41
#endif/*MASTER_MODE*/
sl@0
    42
#endif/*STANDALONE_CHANNEL*/
sl@0
    43
sl@0
    44
sl@0
    45
#if defined(MASTER_MODE)
sl@0
    46
const TInt KI2cThreadPriority = 5; // Arbitrary, can be 0-7, 7 highest
sl@0
    47
#endif
sl@0
    48
sl@0
    49
const TInt16 KI2cSlaveChannelIdBase = 0x1D00;	// Arbitrary
sl@0
    50
sl@0
    51
#ifdef MASTER_MODE
sl@0
    52
class DSimulatedIicBusChannelMasterI2c : public DIicBusChannelMaster
sl@0
    53
	{
sl@0
    54
	// platform specific implementation
sl@0
    55
	public:
sl@0
    56
#ifdef STANDALONE_CHANNEL
sl@0
    57
	IMPORT_C
sl@0
    58
#endif
sl@0
    59
	DSimulatedIicBusChannelMasterI2c(const TBusType aBusType, const TChannelDuplex aChanDuplex);
sl@0
    60
	inline TInt Create() {return DoCreate();}
sl@0
    61
	TInt DoCreate();
sl@0
    62
sl@0
    63
sl@0
    64
private:
sl@0
    65
	TInt CheckHdr(TDes8* aHdr);	// Check the header is valid for this channel
sl@0
    66
	TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);	
sl@0
    67
public:
sl@0
    68
	// gateway function for PSL implementation
sl@0
    69
	TInt DoRequest(TIicBusTransaction* aTransaction);
sl@0
    70
	TInt HandleSlaveTimeout();
sl@0
    71
sl@0
    72
	// Test functions to allow simulating delayed processing of requests
sl@0
    73
	static TBool IsRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan);
sl@0
    74
	static void SetRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan,TBool aDelay);
sl@0
    75
sl@0
    76
	TInt ProcessTrans(); // Accessed by callback
sl@0
    77
	inline TInt8 GetChanNum() {return iChannelNumber;};
sl@0
    78
private:
sl@0
    79
	TDynamicDfcQue*	iDynamicDfcQ;
sl@0
    80
sl@0
    81
	static TInt8 iCurrentChanNum;
sl@0
    82
sl@0
    83
	TBool iReqDelayed;
sl@0
    84
	};
sl@0
    85
#ifndef STANDALONE_CHANNEL
sl@0
    86
TInt8 DSimulatedIicBusChannelMasterI2c::iCurrentChanNum = KI2cChannelNumBase; // Initialise static member of DSimulatedIicBusChannelMasterI2c
sl@0
    87
#endif
sl@0
    88
#endif/*MASTER_MODE*/
sl@0
    89
sl@0
    90
#ifdef SLAVE_MODE
sl@0
    91
class DSimulatedIicBusChannelSlaveI2c : public DIicBusChannelSlave
sl@0
    92
	{
sl@0
    93
public:
sl@0
    94
	// platform specific implementation
sl@0
    95
#ifdef STANDALONE_CHANNEL
sl@0
    96
	IMPORT_C
sl@0
    97
#endif
sl@0
    98
	DSimulatedIicBusChannelSlaveI2c(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex);
sl@0
    99
	~DSimulatedIicBusChannelSlaveI2c();
sl@0
   100
	// gateway function for PSL implementation
sl@0
   101
	TInt DoRequest(TInt aTrigger);
sl@0
   102
	void ProcessData(TInt aTrigger, TIicBusSlaveCallback*  aCb);
sl@0
   103
	TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);	
sl@0
   104
sl@0
   105
	inline TInt Create() {return DoCreate();}
sl@0
   106
	virtual TInt DoCreate();
sl@0
   107
sl@0
   108
	static void SlaveAsyncSimCallback(TAny* aPtr);
sl@0
   109
	inline void ChanCaptureCb(TInt aResult) {ChanCaptureCallback(aResult);}
sl@0
   110
sl@0
   111
	inline void SetChanNum(TInt8 aChanNum) {iChannelNumber = aChanNum;};
sl@0
   112
sl@0
   113
	protected:
sl@0
   114
		virtual void SendBusErrorAndReturn() {return;} // Not implemented in simulated PSL
sl@0
   115
sl@0
   116
sl@0
   117
	private:
sl@0
   118
		TInt CheckHdr(TDes8* aHdr);	// Check the header is valid for this channel
sl@0
   119
		virtual TInt CaptureChannelPsl(TBool aAsynch);
sl@0
   120
		virtual TInt ReleaseChannelPsl();
sl@0
   121
		TInt PrepareTrigger(TInt aTrigger);
sl@0
   122
	private:
sl@0
   123
sl@0
   124
		TInt8 iDeltaWordsToRx;
sl@0
   125
		TInt8 iDeltaWordsToTx;
sl@0
   126
		TInt8 iNumWordsWereRx;
sl@0
   127
		TInt8 iNumWordsWereTx;
sl@0
   128
		TInt8 iRxTxUnderOverRun;
sl@0
   129
sl@0
   130
		TInt8* iTxCheckBuf;
sl@0
   131
sl@0
   132
		TInt iBlockedTrigger;
sl@0
   133
		TBool iBlockNotification;
sl@0
   134
sl@0
   135
		NTimer iSlaveTimer; // Used to simulate an asynchronous capture operation
sl@0
   136
		};
sl@0
   137
#endif/*SLAVE_MODE*/
sl@0
   138
sl@0
   139
#if defined(MASTER_MODE) && defined(SLAVE_MODE)
sl@0
   140
class DSimulatedIicBusChannelMasterSlaveI2c : public DIicBusChannelMasterSlave
sl@0
   141
	{
sl@0
   142
public:
sl@0
   143
#ifdef STANDALONE_CHANNEL
sl@0
   144
	IMPORT_C
sl@0
   145
#endif
sl@0
   146
	DSimulatedIicBusChannelMasterSlaveI2c(TBusType /*aBusType*/, TChannelDuplex aChanDuplex, DSimulatedIicBusChannelMasterI2c* aMasterChan, DSimulatedIicBusChannelSlaveI2c* aSlaveChan);
sl@0
   147
				
sl@0
   148
	TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);	
sl@0
   149
	};
sl@0
   150
#endif/*(MASTER_MODE) && (SLAVE_MODE)*/
sl@0
   151
sl@0
   152
#endif /*I2C_H_*/