|
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 |
|
51 #ifdef MASTER_MODE |
|
52 class DSimulatedIicBusChannelMasterI2c : public DIicBusChannelMaster |
|
53 { |
|
54 // platform specific implementation |
|
55 public: |
|
56 #ifdef STANDALONE_CHANNEL |
|
57 IMPORT_C |
|
58 #endif |
|
59 DSimulatedIicBusChannelMasterI2c(const TBusType aBusType, const TChannelDuplex aChanDuplex); |
|
60 inline TInt Create() {return DoCreate();} |
|
61 TInt DoCreate(); |
|
62 |
|
63 |
|
64 private: |
|
65 TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel |
|
66 TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); |
|
67 public: |
|
68 // gateway function for PSL implementation |
|
69 TInt DoRequest(TIicBusTransaction* aTransaction); |
|
70 TInt HandleSlaveTimeout(); |
|
71 |
|
72 // Test functions to allow simulating delayed processing of requests |
|
73 static TBool IsRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan); |
|
74 static void SetRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan,TBool aDelay); |
|
75 |
|
76 TInt ProcessTrans(); // Accessed by callback |
|
77 inline TInt8 GetChanNum() {return iChannelNumber;}; |
|
78 private: |
|
79 TDynamicDfcQue* iDynamicDfcQ; |
|
80 |
|
81 static TInt8 iCurrentChanNum; |
|
82 |
|
83 TBool iReqDelayed; |
|
84 }; |
|
85 #ifndef STANDALONE_CHANNEL |
|
86 TInt8 DSimulatedIicBusChannelMasterI2c::iCurrentChanNum = KI2cChannelNumBase; // Initialise static member of DSimulatedIicBusChannelMasterI2c |
|
87 #endif |
|
88 #endif/*MASTER_MODE*/ |
|
89 |
|
90 #ifdef SLAVE_MODE |
|
91 class DSimulatedIicBusChannelSlaveI2c : public DIicBusChannelSlave |
|
92 { |
|
93 public: |
|
94 // platform specific implementation |
|
95 #ifdef STANDALONE_CHANNEL |
|
96 IMPORT_C |
|
97 #endif |
|
98 DSimulatedIicBusChannelSlaveI2c(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex); |
|
99 ~DSimulatedIicBusChannelSlaveI2c(); |
|
100 // gateway function for PSL implementation |
|
101 TInt DoRequest(TInt aTrigger); |
|
102 void ProcessData(TInt aTrigger, TIicBusSlaveCallback* aCb); |
|
103 TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); |
|
104 |
|
105 inline TInt Create() {return DoCreate();} |
|
106 virtual TInt DoCreate(); |
|
107 |
|
108 static void SlaveAsyncSimCallback(TAny* aPtr); |
|
109 inline void ChanCaptureCb(TInt aResult) {ChanCaptureCallback(aResult);} |
|
110 |
|
111 inline void SetChanNum(TInt8 aChanNum) {iChannelNumber = aChanNum;}; |
|
112 |
|
113 protected: |
|
114 virtual void SendBusErrorAndReturn() {return;} // Not implemented in simulated PSL |
|
115 |
|
116 |
|
117 private: |
|
118 TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel |
|
119 virtual TInt CaptureChannelPsl(TBool aAsynch); |
|
120 virtual TInt ReleaseChannelPsl(); |
|
121 TInt PrepareTrigger(TInt aTrigger); |
|
122 private: |
|
123 |
|
124 TInt8 iDeltaWordsToRx; |
|
125 TInt8 iDeltaWordsToTx; |
|
126 TInt8 iNumWordsWereRx; |
|
127 TInt8 iNumWordsWereTx; |
|
128 TInt8 iRxTxUnderOverRun; |
|
129 |
|
130 TInt8* iTxCheckBuf; |
|
131 |
|
132 TInt iBlockedTrigger; |
|
133 TBool iBlockNotification; |
|
134 |
|
135 NTimer iSlaveTimer; // Used to simulate an asynchronous capture operation |
|
136 }; |
|
137 #endif/*SLAVE_MODE*/ |
|
138 |
|
139 #if defined(MASTER_MODE) && defined(SLAVE_MODE) |
|
140 class DSimulatedIicBusChannelMasterSlaveI2c : public DIicBusChannelMasterSlave |
|
141 { |
|
142 public: |
|
143 #ifdef STANDALONE_CHANNEL |
|
144 IMPORT_C |
|
145 #endif |
|
146 DSimulatedIicBusChannelMasterSlaveI2c(TBusType /*aBusType*/, TChannelDuplex aChanDuplex, DSimulatedIicBusChannelMasterI2c* aMasterChan, DSimulatedIicBusChannelSlaveI2c* aSlaveChan); |
|
147 |
|
148 TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); |
|
149 }; |
|
150 #endif/*(MASTER_MODE) && (SLAVE_MODE)*/ |
|
151 |
|
152 #endif /*I2C_H_*/ |