author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 14 May 2010 17:13:29 +0300 | |
changeset 109 | b3a1d9898418 |
parent 90 | 947f0dc9f7a8 |
child 199 | 189ece41fa29 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-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/iic/iic_psl/i2c.h |
|
15 |
// |
|
16 |
||
17 |
#ifndef I2C_H_ |
|
18 |
#define I2C_H_ |
|
19 |
||
20 |
#include <drivers/iic_channel.h> |
|
21 |
#include "../t_iic.h" |
|
22 |
||
23 |
#define NUM_CHANNELS 3 // Arbitrary |
|
24 |
||
25 |
#ifdef LOG_I2C |
|
26 |
#define I2C_PRINT(str) Kern::Printf str |
|
27 |
#else |
|
28 |
#define I2C_PRINT(str) |
|
29 |
#endif |
|
30 |
||
31 |
_LIT(KI2cThreadName,"I2cChannelThread"); |
|
32 |
||
33 |
#ifndef STANDALONE_CHANNEL |
|
34 |
#if defined(MASTER_MODE) |
|
35 |
const TInt8 KI2cChannelNumBase = 10; // Arbitrary, real platform may consult the Configuration Repository |
|
36 |
// Note limit of 5 bit representation (0-31) |
|
37 |
||
38 |
#else/*MASTER_MODE*/ |
|
39 |
const TInt8 KI2cChannelNumBase = 10 + NUM_CHANNELS; // For Slave mode, want to provide different response |
|
40 |
// If client assumes Master mode, should be informed not available |
|
41 |
#endif/*MASTER_MODE*/ |
|
42 |
#endif/*STANDALONE_CHANNEL*/ |
|
43 |
||
44 |
||
45 |
#if defined(MASTER_MODE) |
|
46 |
const TInt KI2cThreadPriority = 5; // Arbitrary, can be 0-7, 7 highest |
|
47 |
#endif |
|
48 |
||
49 |
const TInt16 KI2cSlaveChannelIdBase = 0x1D00; // Arbitrary |
|
50 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
51 |
const TInt KI2cSlaveAsyncDelaySim = 20; // Arbitrary delay, for timer to simulate asynchronous processing |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
52 |
|
0 | 53 |
#ifdef MASTER_MODE |
54 |
class DSimulatedIicBusChannelMasterI2c : public DIicBusChannelMaster |
|
55 |
{ |
|
56 |
// platform specific implementation |
|
57 |
public: |
|
58 |
#ifdef STANDALONE_CHANNEL |
|
59 |
IMPORT_C |
|
60 |
#endif |
|
61 |
DSimulatedIicBusChannelMasterI2c(const TBusType aBusType, const TChannelDuplex aChanDuplex); |
|
62 |
inline TInt Create() {return DoCreate();} |
|
63 |
TInt DoCreate(); |
|
64 |
||
65 |
||
66 |
private: |
|
67 |
TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel |
|
68 |
TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); |
|
69 |
public: |
|
70 |
// gateway function for PSL implementation |
|
71 |
TInt DoRequest(TIicBusTransaction* aTransaction); |
|
72 |
TInt HandleSlaveTimeout(); |
|
73 |
||
74 |
// Test functions to allow simulating delayed processing of requests |
|
75 |
static TBool IsRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan); |
|
76 |
static void SetRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan,TBool aDelay); |
|
77 |
||
78 |
TInt ProcessTrans(); // Accessed by callback |
|
79 |
inline TInt8 GetChanNum() {return iChannelNumber;}; |
|
80 |
private: |
|
81 |
TDynamicDfcQue* iDynamicDfcQ; |
|
82 |
||
83 |
static TInt8 iCurrentChanNum; |
|
84 |
||
85 |
TBool iReqDelayed; |
|
86 |
}; |
|
87 |
#ifndef STANDALONE_CHANNEL |
|
88 |
TInt8 DSimulatedIicBusChannelMasterI2c::iCurrentChanNum = KI2cChannelNumBase; // Initialise static member of DSimulatedIicBusChannelMasterI2c |
|
89 |
#endif |
|
90 |
#endif/*MASTER_MODE*/ |
|
91 |
||
92 |
#ifdef SLAVE_MODE |
|
93 |
class DSimulatedIicBusChannelSlaveI2c : public DIicBusChannelSlave |
|
94 |
{ |
|
95 |
public: |
|
96 |
// platform specific implementation |
|
97 |
#ifdef STANDALONE_CHANNEL |
|
98 |
IMPORT_C |
|
99 |
#endif |
|
100 |
DSimulatedIicBusChannelSlaveI2c(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex); |
|
101 |
~DSimulatedIicBusChannelSlaveI2c(); |
|
102 |
// gateway function for PSL implementation |
|
103 |
TInt DoRequest(TInt aTrigger); |
|
104 |
void ProcessData(TInt aTrigger, TIicBusSlaveCallback* aCb); |
|
105 |
TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); |
|
106 |
||
107 |
inline TInt Create() {return DoCreate();} |
|
108 |
virtual TInt DoCreate(); |
|
109 |
||
110 |
static void SlaveAsyncSimCallback(TAny* aPtr); |
|
111 |
inline void ChanCaptureCb(TInt aResult) {ChanCaptureCallback(aResult);} |
|
112 |
||
113 |
inline void SetChanNum(TInt8 aChanNum) {iChannelNumber = aChanNum;}; |
|
114 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
115 |
enum TAsyncEvent |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
ENoEvent = 0, |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
118 |
EAsyncChanCapture, |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
ERxWords, |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
ETxWords, |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
ERxTxWords |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
}; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
inline void ChanNotifyClient(TInt aTrigger) {NotifyClient(aTrigger);} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
|
0 | 125 |
protected: |
126 |
virtual void SendBusErrorAndReturn() {return;} // Not implemented in simulated PSL |
|
127 |
||
128 |
||
129 |
private: |
|
130 |
TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel |
|
131 |
virtual TInt CaptureChannelPsl(TBool aAsynch); |
|
132 |
virtual TInt ReleaseChannelPsl(); |
|
133 |
TInt PrepareTrigger(TInt aTrigger); |
|
134 |
private: |
|
135 |
||
136 |
TInt8 iDeltaWordsToRx; |
|
137 |
TInt8 iDeltaWordsToTx; |
|
138 |
TInt8 iNumWordsWereRx; |
|
139 |
TInt8 iNumWordsWereTx; |
|
140 |
TInt8 iRxTxUnderOverRun; |
|
141 |
||
142 |
TInt8* iTxCheckBuf; |
|
143 |
||
144 |
TInt iBlockedTrigger; |
|
145 |
TBool iBlockNotification; |
|
146 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
TAsyncEvent iAsyncEvent; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
TInt iRxTxTrigger; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
|
0 | 150 |
NTimer iSlaveTimer; // Used to simulate an asynchronous capture operation |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
TSpinLock iEventSpinLock; // To serialise simulated bus events - Rx, Tx or Rx+Tx |
0 | 152 |
}; |
153 |
#endif/*SLAVE_MODE*/ |
|
154 |
||
155 |
#if defined(MASTER_MODE) && defined(SLAVE_MODE) |
|
156 |
class DSimulatedIicBusChannelMasterSlaveI2c : public DIicBusChannelMasterSlave |
|
157 |
{ |
|
158 |
public: |
|
159 |
#ifdef STANDALONE_CHANNEL |
|
160 |
IMPORT_C |
|
161 |
#endif |
|
162 |
DSimulatedIicBusChannelMasterSlaveI2c(TBusType /*aBusType*/, TChannelDuplex aChanDuplex, DSimulatedIicBusChannelMasterI2c* aMasterChan, DSimulatedIicBusChannelSlaveI2c* aSlaveChan); |
|
163 |
||
164 |
TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); |
|
165 |
}; |
|
166 |
#endif/*(MASTER_MODE) && (SLAVE_MODE)*/ |
|
167 |
||
168 |
#endif /*I2C_H_*/ |