author | hgs |
Thu, 10 Jun 2010 11:48:01 +0100 | |
changeset 148 | 31ea0f8e3c99 |
parent 90 | 947f0dc9f7a8 |
child 257 | 3e88ff8f41d5 |
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 |
// e32/include/drivers/iic_channel.h |
|
15 |
// Include file for channel implementation |
|
16 |
// |
|
17 |
// WARNING: This file contains some APIs which are internal and are subject |
|
18 |
// to change without notice. Such APIs should therefore not be used |
|
19 |
// outside the Kernel and Hardware Services package. |
|
20 |
||
21 |
/** |
|
22 |
@file |
|
23 |
@internalTechnology |
|
24 |
*/ |
|
25 |
#ifndef __IIC_CHANNEL_H__ |
|
26 |
#define __IIC_CHANNEL_H__ |
|
27 |
||
28 |
#ifdef STANDALONE_CHANNEL |
|
29 |
#include <drivers/iic_transaction.h> |
|
30 |
#else |
|
31 |
#include <drivers/iic.h> |
|
32 |
#endif |
|
33 |
||
34 |
static const char KIicChannelPanic[]="Iic Channel PIL"; |
|
35 |
||
36 |
const static TInt KChannelTypeMask = 0x03; |
|
37 |
const static TInt KBusTypeShift = 2; |
|
38 |
const static TInt KBusTypeMask = 0x07<<KBusTypeShift; // number of buses may grow in future |
|
39 |
const static TInt KChannelDuplexShift= 5; |
|
40 |
const static TInt KChannelDuplexMask = 0x01<<KChannelDuplexShift; |
|
41 |
const static TInt16 KTransCountMsBit = (TInt16)((TUint16)0x8000); |
|
42 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
43 |
const static TInt8 KMaxWaitTime = 0x7E; // Maximum allowable time in milliseconds for a Slave channel to wait for a response |
0 | 44 |
// (from Master or Client). This constant is used to limit run-time selected values |
45 |
// for timeouts. The value stated here is semi-arbitrary. |
|
46 |
||
47 |
#ifdef IIC_SIMULATED_PSL |
|
48 |
// In a real system, the following timeout values are likely to be excessive. However, they are available |
|
49 |
// for use in the test framework, to account for the processing overhead. |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
50 |
// In particular, for the simulated master timeout tests. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
51 |
const TInt KSlaveDefMWaitTime = 125; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
52 |
const TInt KSlaveDefCWaitTime = 124; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
53 |
|
0 | 54 |
#else |
55 |
const TInt KSlaveDefMWaitTime = 1; // Default wait time for Master timeout. PSL can use SetMasterWaitTime to override. |
|
56 |
const TInt KSlaveDefCWaitTime = 1; // Default wait time for Client timeout. PSL can use SetClientWaitTime to override. |
|
57 |
#endif |
|
58 |
||
59 |
||
60 |
/** |
|
61 |
@internalComponent |
|
62 |
@prototype 9.6 |
|
63 |
Base class for a Channel (not directly instantiable) |
|
64 |
*/ |
|
65 |
class DIicBusChannel : public DBase |
|
66 |
{ |
|
67 |
public: |
|
68 |
enum TChannelType |
|
69 |
{ |
|
70 |
EMaster = 0, |
|
71 |
ESlave = 0x01, |
|
72 |
EMasterSlave = 0x02 |
|
73 |
}; |
|
74 |
enum TBusType |
|
75 |
{ |
|
76 |
EI2c = 0, |
|
77 |
ESpi = 0x01, |
|
78 |
EMicrowire = 0x02, |
|
79 |
ECci = 0x03, |
|
80 |
ESccb = 0x04 |
|
81 |
}; |
|
82 |
enum TChannelDuplex |
|
83 |
{ |
|
84 |
EHalfDuplex = 0, // supports only half duplex transactions (even if bus spec supports full duplex) |
|
85 |
EFullDuplex = 0x1 // supports full duplex transactions (queud transactions may still be half duplex) |
|
86 |
}; |
|
87 |
||
88 |
public: |
|
89 |
virtual TInt StaticExtension(TUint aFunction, TAny* /*aParam1*/, TAny* /*aParam2*/) |
|
90 |
{ |
|
91 |
#ifdef _DEBUG |
|
92 |
if(aFunction == KCtrlIoDumpChan) |
|
93 |
{ |
|
94 |
DumpChannel(); |
|
95 |
return KErrNone; |
|
96 |
} |
|
97 |
else |
|
98 |
#else |
|
99 |
(void)aFunction; |
|
100 |
#endif |
|
101 |
||
102 |
return KErrNotSupported; |
|
103 |
}; |
|
104 |
protected: |
|
105 |
// constructor |
|
106 |
inline DIicBusChannel(TChannelType aChanType, TBusType aBusType, TChannelDuplex aChanDuplex); |
|
107 |
// second phase construction - empty, to be implemented by derived types if required |
|
108 |
virtual TInt DoCreate()=0; |
|
109 |
||
110 |
// helper function to read an set flags |
|
111 |
inline TChannelType ChannelType(); |
|
112 |
inline void SetChannelType(TChannelType aChanType); |
|
113 |
inline TBusType BusType(); |
|
114 |
inline void SetBusType(TBusType aBusType); |
|
115 |
inline TChannelDuplex ChannelDuplex(); |
|
116 |
inline void SetChannelType(TChannelDuplex aChanDuplex); |
|
117 |
inline TInt8 ChannelNumber() const; |
|
118 |
||
119 |
virtual TInt CheckHdr(TDes8* aHdr) = 0; // PSL to check the header is valid for this channel |
|
120 |
protected: |
|
121 |
#ifdef _DEBUG |
|
122 |
inline void DumpChannel(); |
|
123 |
#endif |
|
124 |
protected: |
|
125 |
TInt8 iChannelNumber; // this is the Key for ordering channels in the array |
|
126 |
TUint8 iFlags; // combination of TChannelType, TChannelDuplex and TBusType |
|
127 |
TInt8 iSpare1; |
|
128 |
TInt8 iSpare2; |
|
129 |
private: |
|
130 |
TAny* iReserved; |
|
131 |
||
132 |
friend class DIicBusController; |
|
133 |
}; |
|
134 |
||
135 |
/** |
|
136 |
@publishedPartner |
|
137 |
@prototype 9.6 |
|
138 |
||
139 |
Base class for a Master Channel (not directly instantiable) |
|
140 |
||
141 |
*/ |
|
142 |
class DIicBusChannelMaster : public DIicBusChannel |
|
143 |
{ |
|
144 |
public: |
|
145 |
// interface to Bus Controller (implemented by PIL) |
|
146 |
// For stand-alone channel, there is no controller. So some parts of |
|
147 |
// the interface are exported for client direct use. |
|
148 |
/** |
|
149 |
@publishedPartner |
|
150 |
@prototype 9.6 |
|
151 |
Master channel interface to queue a transaction synchronously. |
|
152 |
||
153 |
@param aTransaction A pointer to a transaction object containing the details of the transaction. |
|
154 |
||
155 |
@return KErrNone, when successfully completed; |
|
156 |
KErrArgument, if aTransaction is NULL; |
|
157 |
KErrTimedOut, if the channel terminates the transaction because the addressed Slave exceeded the alloted time to respond; |
|
158 |
KErrNotSupported, if either the channel does not support Master mode or the transaction is not valid on this channel (e.g. valid full duplex transaction queued on half duplex channel). |
|
159 |
*/ |
|
160 |
virtual TInt QueueTransaction(TIicBusTransaction* aTransaction); |
|
161 |
/** |
|
162 |
@publishedPartner |
|
163 |
@prototype 9.6 |
|
164 |
Master channel interface to queue a transaction asynchronously. |
|
165 |
||
166 |
@param aTransaction A pointer to a transaction object containing the details of the transaction. |
|
167 |
@param aCallback A pointer to a callback object. |
|
168 |
||
169 |
@return KErrNone, if successfully accepted; KErrArgument, if either aTransaction or aCallback are NULL; |
|
170 |
KErrNotSupported, if either the channel does not support Master mode or the transaction is not valid on this channel(e.g. valid full duplex transaction queued on half duplex channel). |
|
171 |
*/ |
|
172 |
virtual TInt QueueTransaction(TIicBusTransaction* aTransaction, TIicBusCallback* aCallback); |
|
173 |
/** |
|
174 |
@publishedPartner |
|
175 |
@prototype 9.6 |
|
176 |
Master channel interface to cancel a previously queued transaction. |
|
177 |
||
178 |
@param aTransaction A pointer to a transaction object containing the details of the transaction. |
|
179 |
||
180 |
@return KErrCancel, if successfully cancelled; KErrArgument, if aTransaction is NULL; |
|
181 |
KErrNotFound if the transaction cannot be found on channel's queue of transactions; |
|
182 |
KErrInUse if this method is called on a transaction that has already been started; |
|
183 |
KErrNotSupported, if the channel does not support Master mode, or the method is called on a synchronous transaction.. |
|
184 |
*/ |
|
185 |
virtual TInt CancelTransaction(TIicBusTransaction* aTransaction); |
|
186 |
/** |
|
187 |
@publishedPartner |
|
188 |
@prototype 9.6 |
|
189 |
Master channel interface interface to provide extended functionality |
|
190 |
||
191 |
@param aFunction A function identifier. If bit 31 is set and bit 30 cleared it is used to extend the Master-Slave channel; |
|
192 |
if bit 31 is cleared and bit 30 is set, it extends the Master channel; if both bits 31 and 30 are cleared it |
|
193 |
extends the Slave channel interface. |
|
194 |
@param aParam1 A generic argument to be passed to the function identified by aFunction. |
|
195 |
@param aParam2 A generic argument to be passed to the function identified by aFunction. |
|
196 |
||
197 |
@return KErrNone, if successful; |
|
198 |
KErrNotSupported, function is not supported; |
|
199 |
Any other system wide error code. |
|
200 |
*/ |
|
201 |
virtual TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); |
|
202 |
||
203 |
// |
|
204 |
virtual TInt Spare1(TInt aVal, TAny* aPtr1, TAny* aPtr2); |
|
205 |
||
206 |
/** |
|
207 |
@publishedPartner |
|
208 |
@prototype 9.6 |
|
209 |
Destructor for DIicBusChannelMaster |
|
210 |
*/ |
|
211 |
~DIicBusChannelMaster(); |
|
212 |
||
213 |
protected: |
|
214 |
// PSL implemented |
|
215 |
/** |
|
216 |
@publishedPartner |
|
217 |
@prototype 9.6 |
|
218 |
Gateway function for PSL implementation (to be called by the interface APIs) |
|
219 |
*/ |
|
220 |
virtual TInt DoRequest(TIicBusTransaction* aTransaction) = 0; |
|
221 |
/** |
|
222 |
@publishedPartner |
|
223 |
@prototype 9.6 |
|
224 |
Function to be invoked in the event of a Slave timeout. May be overridden by the PSL. |
|
225 |
*/ |
|
226 |
virtual TInt HandleSlaveTimeout() = 0; |
|
227 |
/** |
|
228 |
@publishedPartner |
|
229 |
@prototype 9.6 |
|
230 |
Second phase constructor to be implemented by the PSL |
|
231 |
*/ |
|
232 |
virtual TInt DoCreate() = 0; |
|
233 |
||
234 |
// Called by PSL |
|
235 |
/** |
|
236 |
@publishedPartner |
|
237 |
@prototype 9.6 |
|
238 |
||
239 |
Constructor for DIicBusChannelMaster |
|
240 |
||
241 |
@param aBusType Argument to specify the type of Bus |
|
242 |
@param aChanDuplex Argument to specify the duplex support offered by this channel |
|
243 |
*/ |
|
244 |
DIicBusChannelMaster(TBusType aBusType, TChannelDuplex aChanDuplex); |
|
245 |
/** |
|
246 |
@publishedPartner |
|
247 |
@prototype 9.6 |
|
248 |
Function to instigate DIicBusChannel initialisation |
|
249 |
||
250 |
@return KErrNone if no error |
|
251 |
KErrNoMemory if allocation of required objects |
|
252 |
*/ |
|
253 |
TInt Init(); |
|
254 |
/** |
|
255 |
@publishedPartner |
|
256 |
@prototype 9.6 |
|
257 |
||
258 |
Function to start the timer to check the Slave responsiveness. |
|
259 |
||
260 |
@param aTime Timeout in milliseconds |
|
261 |
||
262 |
@return KErrNone if no error, |
|
263 |
KErrInUse if timer is already active. |
|
264 |
||
265 |
*/ |
|
266 |
TInt StartSlaveTimeOutTimer(TInt aTime); |
|
267 |
/** |
|
268 |
@publishedPartner |
|
269 |
@prototype 9.6 |
|
270 |
||
271 |
Function to specify the DFC queue for the channel to use |
|
272 |
||
273 |
@param aDfcQue Pointer to the DFC queue to use |
|
274 |
||
275 |
*/ |
|
276 |
void SetDfcQ(TDfcQue* aDfcQue); |
|
277 |
/** |
|
278 |
@publishedPartner |
|
279 |
@prototype 9.6 |
|
280 |
||
281 |
Function to Complete the transaction being processed by the channel |
|
282 |
||
283 |
@param aResult Error code to complete the transaction with |
|
284 |
||
285 |
*/ |
|
286 |
void CompleteRequest(TInt aResult); |
|
287 |
/** |
|
288 |
@publishedPartner |
|
289 |
@prototype 9.6 |
|
290 |
||
291 |
Function to cancel the timer to check the Slave responsiveness. |
|
292 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
Call either in a thread or an IDFC context. Do not call from an ISR. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
|
0 | 295 |
*/ |
296 |
void CancelTimeOut(); |
|
297 |
||
298 |
// Methods to make private data of TIicBusTransaction object accessible to derivatives of this class |
|
299 |
/** |
|
300 |
@publishedPartner |
|
301 |
@prototype 9.6 |
|
302 |
||
303 |
Function to return the Transaction Header of a specified TIicBusTransaction object |
|
304 |
||
305 |
@return The Transaction Header of the specified TIicBusTransaction object |
|
306 |
||
307 |
@see TIicBusTransaction |
|
308 |
*/ |
|
309 |
static inline TDes8* GetTransactionHeader(const TIicBusTransaction* aTransaction); |
|
310 |
/** |
|
311 |
@publishedPartner |
|
312 |
@prototype 9.6 |
|
313 |
||
314 |
Function to return the Half Duplex Transfer pointer of a specified TIicBusTransaction object |
|
315 |
||
316 |
@return The Half Duplex Transfer pointer of the specified TIicBusTransaction object |
|
317 |
||
318 |
@see TIicBusTransaction |
|
319 |
*/ |
|
320 |
static inline TIicBusTransfer* GetTransHalfDuplexTferPtr(const TIicBusTransaction* aTransaction); |
|
321 |
/** |
|
322 |
@publishedPartner |
|
323 |
@prototype 9.6 |
|
324 |
||
325 |
Function to return the Full Duplex Transfer pointer of a specified TIicBusTransaction object |
|
326 |
||
327 |
@return The Full Duplex Transfer pointer of the specified TIicBusTransaction object |
|
328 |
||
329 |
@see TIicBusTransaction |
|
330 |
*/ |
|
331 |
static inline TIicBusTransfer* GetTransFullDuplexTferPtr(const TIicBusTransaction* aTransaction); |
|
332 |
/** |
|
333 |
@publishedPartner |
|
334 |
@prototype 9.6 |
|
335 |
||
336 |
Function to return the address of the callback object of a specified TIicBusTransaction object |
|
337 |
||
338 |
@return The address of the callback object of the specified TIicBusTransaction object |
|
339 |
||
340 |
@see TIicBusTransaction |
|
341 |
*/ |
|
342 |
static inline TIicBusCallback* GetTransCallback(const TIicBusTransaction* aTransaction); |
|
343 |
/** |
|
344 |
@publishedPartner |
|
345 |
@prototype 9.6 |
|
346 |
||
347 |
Function to return the value of the TransFlags member of a specified TIicBusTransaction object |
|
348 |
||
349 |
@return The value of the TransFlags member of the specified TIicBusTransaction object |
|
350 |
||
351 |
@see TIicBusTransaction |
|
352 |
*/ |
|
353 |
static inline TUint8 GetTransFlags(const TIicBusTransaction* aTransaction); |
|
354 |
||
355 |
// Methods to make private data of TIicBusTransfer object accessible to derivatives of this class |
|
356 |
/** |
|
357 |
@publishedPartner |
|
358 |
@prototype 9.6 |
|
359 |
||
360 |
Function to return Transfer Type the of a specified TIicBusTransfer object |
|
361 |
||
362 |
@return The Transfer Type of the specified TIicBusTransfer object |
|
363 |
||
364 |
@see TIicBusTransfer |
|
365 |
*/ |
|
366 |
static inline TInt8 GetTferType(const TIicBusTransfer* aTransfer); |
|
367 |
/** |
|
368 |
@publishedPartner |
|
369 |
@prototype 9.6 |
|
370 |
||
371 |
Function to return the Buffer Granularity of a specified TIicBusTransfer object |
|
372 |
||
373 |
@return The Buffer Granularity of the specified TIicBusTransfer object |
|
374 |
||
375 |
@see TIicBusTransfer |
|
376 |
*/ |
|
377 |
static inline TInt8 GetTferBufGranularity(const TIicBusTransfer* aTransfer); |
|
378 |
/** |
|
379 |
@publishedPartner |
|
380 |
@prototype 9.6 |
|
381 |
||
382 |
Function to return the descriptor for the data for a specified TIicBusTransfer object |
|
383 |
||
384 |
@return The descriptor for the data for the specified TIicBusTransfer object |
|
385 |
||
386 |
@see TIicBusTransfer |
|
387 |
*/ |
|
388 |
static inline const TDes8* GetTferBuffer(const TIicBusTransfer* aTransfer); |
|
389 |
/** |
|
390 |
@publishedPartner |
|
391 |
@prototype 9.6 |
|
392 |
||
393 |
Function to return the address of the next transfer for a specified TIicBusTransfer object |
|
394 |
||
395 |
@return The address of the next transfer for the specified TIicBusTransfer object |
|
396 |
||
397 |
@see TIicBusTransfer |
|
398 |
*/ |
|
399 |
static inline TIicBusTransfer* GetTferNextTfer(const TIicBusTransfer* aTransfer); |
|
400 |
||
401 |
// Methods to make private data of TIicBusTransactionPreamble object accessible to derivatives of this class |
|
402 |
/** |
|
403 |
@publishedPartner |
|
404 |
@prototype 9.6 |
|
405 |
||
406 |
Function to return the function pointer for a specified TIicBusTransactionPreamble object |
|
407 |
||
408 |
@return The function pointer for the specified TIicBusTransactionPreamble object |
|
409 |
||
410 |
@see TIicBusTransactionPreamble |
|
411 |
*/ |
|
412 |
static inline TIicBusPreamble GetPreambleFuncPtr(const TIicBusTransactionPreamble* aTransfer); |
|
413 |
/** |
|
414 |
@publishedPartner |
|
415 |
@prototype 9.6 |
|
416 |
||
417 |
Function to return the function argument for a specified TIicBusTransactionPreamble object |
|
418 |
||
419 |
@return The function argument for the specified TIicBusTransactionPreamble object |
|
420 |
||
421 |
@see TIicBusTransactionPreamble |
|
422 |
*/ |
|
423 |
static inline TAny* GetPreambleFuncArg(const TIicBusTransactionPreamble* aTransfer); |
|
424 |
||
425 |
/** |
|
426 |
@publishedPartner |
|
427 |
@prototype 9.6 |
|
428 |
||
429 |
Function to return the function pointer of a specified TIicBusTransactionMultiTransc object |
|
430 |
||
431 |
@return The function pointer of the specified TIicBusTransactionMultiTransc object |
|
432 |
||
433 |
@see TIicBusTransactionMultiTransc |
|
434 |
*/ |
|
435 |
static inline TIicBusMultiTranscCbFn GetMultiTranscFuncPtr(const TIicBusTransactionMultiTransc* aTransfer); |
|
436 |
/** |
|
437 |
@publishedPartner |
|
438 |
@prototype 9.6 |
|
439 |
||
440 |
Function to return the function argument of a specified TIicBusTransactionMultiTransc object |
|
441 |
||
442 |
@return The function argument of the specified TIicBusTransactionMultiTransc object |
|
443 |
||
444 |
@see TIicBusTransactionMultiTransc |
|
445 |
*/ |
|
446 |
static inline TAny* GetMultiTranscFuncArg(const TIicBusTransactionMultiTransc* aTransfer); |
|
447 |
||
448 |
/** |
|
449 |
@publishedPartner |
|
450 |
@prototype 9.6 |
|
451 |
||
452 |
Function to return the function pointer of a specified TIicBusTransactionPreambleExt object |
|
453 |
||
454 |
@return The function pointer of the specified TIicBusTransactionPreambleExt object |
|
455 |
||
456 |
@see TIicBusTransaction |
|
457 |
*/ |
|
458 |
static inline TIicBusMultiTranscCbFn GetExtTranscFuncPtr(const TIicBusTransactionPreambleExt* aTransfer); |
|
459 |
/** |
|
460 |
@publishedPartner |
|
461 |
@prototype 9.6 |
|
462 |
||
463 |
Function to return the function argument of a specified TIicBusTransactionPreambleExt object |
|
464 |
||
465 |
@return The function argument of the specified TIicBusTransactionPreambleExt object |
|
466 |
||
467 |
@see TIicBusTransaction |
|
468 |
*/ |
|
469 |
static inline TAny* GetExtTranscFuncArg(const TIicBusTransactionPreambleExt* aTransfer); |
|
470 |
||
471 |
private: |
|
472 |
// Function to acquire the NFastMutex of the channel |
|
473 |
void Lock(); |
|
474 |
// Function to release the NFastMutex of the channel |
|
475 |
void Unlock(); |
|
476 |
||
477 |
// function to run on receiving a message |
|
478 |
static void MsgQFunc(TAny* aPtr); |
|
479 |
||
480 |
TIicBusTransaction* NextTrans(TIicBusTransaction* aTrans); |
|
481 |
void EndTransaction(TIicBusTransaction* aTrans, TInt aResult, TIicBusCallback* aCb); |
|
482 |
void Complete(TInt aResult, TIicBusTransaction* aTransaction); |
|
483 |
void UnlockAndKick(); |
|
484 |
||
485 |
static void SlaveTimeoutCallback(TAny*); |
|
486 |
||
487 |
// Used by DIidBusController (a friend of this class) |
|
488 |
TInt TransFlow(TIicBusTransaction* aTransaction); |
|
489 |
||
490 |
TInt8 IsMasterBusy(); |
|
491 |
||
492 |
protected: |
|
493 |
TDfcQue* iDfcQ; |
|
494 |
||
495 |
private: |
|
496 |
TDfc iTransQDfc; |
|
497 |
SOrdQue iTransactionQ; |
|
498 |
TIicBusTransaction* iTransaction; // Pointer to current transaction |
|
499 |
TIicBusTransaction* iCurrentTransaction; // Pointer to current fragment of a multiple transaction |
|
500 |
||
501 |
NFastMutex iTransactionQLock; |
|
502 |
||
503 |
TDfc* iSlaveTimeoutDfc; |
|
504 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
505 |
NTimer iTimeoutTimer; // timeout timer |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
506 |
|
0 | 507 |
TInt16 iTransCount; // Count of pending transactions |
508 |
TInt8 iChannelReady; |
|
509 |
TInt8 iSpare1; |
|
510 |
||
511 |
private: |
|
512 |
TAny* iReserved1; |
|
513 |
TAny* iReserved2; |
|
514 |
||
515 |
friend class DIicBusChannelMasterSlave; |
|
516 |
friend class DIicBusController; // For static method DIicBusController::DeRegisterChannel |
|
517 |
}; |
|
518 |
||
519 |
||
520 |
/** |
|
521 |
@publishedPartner |
|
522 |
@prototype 9.6 |
|
523 |
||
524 |
Base class for a Slave Channel (not directly instantiable) |
|
525 |
||
526 |
*/ |
|
527 |
class DIicBusChannelSlave : public DIicBusChannel |
|
528 |
{ |
|
529 |
protected: |
|
530 |
/** |
|
531 |
@publishedPartner |
|
532 |
@prototype 9.6 |
|
533 |
The set of operation values for processing by the PSL |
|
534 |
*/ |
|
535 |
enum TPslOperation |
|
536 |
{ |
|
537 |
ESyncConfigPwrUp = 0x01, |
|
538 |
EAsyncConfigPwrUp = 0x02, |
|
539 |
EPowerDown = 0x04, |
|
540 |
ETransmit = 0x08, |
|
541 |
EReceive = 0x10, |
|
542 |
EAbort = 0x20 |
|
543 |
}; |
|
544 |
private: |
|
545 |
// Values used by the internal state machine |
|
546 |
enum TSlaveTimerStates |
|
547 |
{ |
|
548 |
EInactive = 0x01, |
|
549 |
EWaitForMaster = 0x02, |
|
550 |
EWaitForClient = 0x04, |
|
551 |
EClientTimeout = 0x08 |
|
552 |
}; |
|
553 |
||
554 |
public: |
|
555 |
||
556 |
// Interface to Controller. |
|
557 |
// For stand-alone channel, the interface is exported. |
|
558 |
/** |
|
559 |
@publishedPartner |
|
560 |
@prototype 9.6 |
|
561 |
Capture this Slave channel. |
|
562 |
||
563 |
@param aConfigHdr A pointer to a descriptor containing the device specific configuration option applicable to all transactions. |
|
564 |
@param aCallback A pointer to a callback to be called upon specified triggers. |
|
565 |
@param aChannelId If this API is to complete synchronously, and the processing was successful, then on return aChannelId |
|
566 |
contains a platform-specific cookie that uniquely identifies the channel instance to be used by this client. |
|
567 |
If the processing was unsuccessful for the synchronous completion case, aChannelId will be unchanged. |
|
568 |
If the API was called to complete asynchronously, aChannelId will, in all cases, be set to zero; the valid |
|
569 |
value for the cookie will be set by the callback. |
|
570 |
@param aAsynch A boolean value that indicates if this API is to complete synchronously (EFalse) or asynchronously (ETrue). |
|
571 |
||
572 |
@return KErrNone, if successfully captured, or if API is asynchronous, if the request to capture the channel was accepted; |
|
573 |
KErrInUse if channel is already in use; KErrArgument, if aCallback is NULL; |
|
574 |
KErrNotSupported, if the channel does not support Slave mode. |
|
575 |
*/ |
|
576 |
virtual TInt CaptureChannel(TDes8* aConfigHdr, TIicBusSlaveCallback* aCallback, TInt& aChannelId, TBool aAsynch); |
|
577 |
/** |
|
578 |
@publishedPartner |
|
579 |
@prototype 9.6 |
|
580 |
Release this previously captured Slave channel. |
|
581 |
||
582 |
@return KErrNone, if successfully released; |
|
583 |
KErrInUse if a transaction is currently underway on this channel; KErrArgument |
|
584 |
*/ |
|
585 |
virtual TInt ReleaseChannel(); |
|
586 |
/** |
|
587 |
@publishedPartner |
|
588 |
@prototype 9.6 |
|
589 |
Register a receive buffer with this Slave channel. |
|
590 |
||
591 |
@param aRxBuffer A pointer to the receive buffer, in a client created descriptor. |
|
592 |
@param aBufGranularity The number of buffer bytes used to store a word. |
|
593 |
@param aNumWords The number of words expected to be received. |
|
594 |
@param aOffset The offset from the start of the buffer where to store the received data. |
|
595 |
||
596 |
@return KErrNone, if successfully registered; |
|
597 |
KErrAlreadyExists if a receive buffer is already pending; |
|
598 |
KErrArgument, if the pointer descriptor is NULL; |
|
599 |
*/ |
|
600 |
virtual TInt RegisterRxBuffer(TPtr8 aRxBuffer, TInt8 aBufGranularity, TInt8 aNumWords, TInt8 aOffset); |
|
601 |
/** |
|
602 |
@publishedPartner |
|
603 |
@prototype 9.6 |
|
604 |
Register a transmit buffer with this Slave channel. |
|
605 |
This client may create a single buffer for the entire transaction and control where the received data |
|
606 |
is to be placed and the transmit data is to be found, by specifying the number of bytes to transmit (receive) |
|
607 |
and the offset into the buffer. |
|
608 |
||
609 |
@param aTxBuffer A pointer to the transmit buffer, in a client created descriptor. |
|
610 |
@param aBufGranularity The number of buffer bytes used to store a word. |
|
611 |
@param aNumWords The number of words to be transmitted. |
|
612 |
@param aOffset The offset from the start of the buffer where to fetch the data to be transmitted. |
|
613 |
||
614 |
@return KErrNone, if successfully registered; |
|
615 |
KErrAlreadyExists if a transmit buffer is already pending; |
|
616 |
KErrArgument, if the pointer descriptor is NULL; |
|
617 |
*/ |
|
618 |
virtual TInt RegisterTxBuffer(TPtr8 aTxBuffer, TInt8 aBufGranularity, TInt8 aNumWords, TInt8 aOffset); |
|
619 |
/** |
|
620 |
@publishedPartner |
|
621 |
@prototype 9.6 |
|
622 |
Sets the notification triggers and readies the receive path and/or kick starts a transmit (if the node is being addressed). |
|
623 |
It is only after a receive buffer has been registered and this API has been called that the channel is ready to receive data (when addressed). |
|
624 |
If a transmit buffer has been registered and this API has been called the channel will immediately transmit when addressed by the Master |
|
625 |
If the channel supports full duplex, both paths can be readied in one call to this API. |
|
626 |
||
627 |
@param aTrigger A bitmask specifying the notification trigger. Masks for individual triggers are specified by the TIicBusSlaveTrigger enumeration. |
|
628 |
||
629 |
@return KErrNone, if successful; |
|
630 |
KErrArgument, if the trigger is invalid for this channel; |
|
631 |
KErrInUse if a transaction is already underway on this channel; |
|
632 |
KErrTimedOut, if the client exceeded the alloted time to respond by invoking this API; |
|
633 |
*/ |
|
634 |
virtual TInt SetNotificationTrigger(TInt aTrigger); |
|
635 |
/** |
|
636 |
@publishedPartner |
|
637 |
@prototype 9.6 |
|
638 |
Interface to provide extended functionality |
|
639 |
||
640 |
@param aFunction A function identifier. If bit 31 is set and bit 30 cleared it is used to extend the Master-Slave channel; |
|
641 |
if bit 31 is cleared and bit 30 is set, it extends the Master channel; if both bits 31 and 30 are cleared it |
|
642 |
extends the Slave channel interface. |
|
643 |
@param aParam1 A generic argument to be passed to the function identified by aFunction. |
|
644 |
@param aParam2 A generic argument to be passed to the function identified by aFunction. |
|
645 |
||
646 |
@return KErrNone, if successful; |
|
647 |
KErrNotSupported, function is not supported; |
|
648 |
Any other system wide error code. |
|
649 |
*/ |
|
650 |
virtual TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); |
|
651 |
// |
|
652 |
/** |
|
653 |
@internalTechnology |
|
654 |
@prototype 9.6 |
|
655 |
Function reserved for future use |
|
656 |
*/ |
|
657 |
virtual TInt Spare1(TInt aVal, TAny* aPtr1, TAny* aPtr2); |
|
658 |
||
659 |
// Interface to TIicBusSlaveCallback |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
660 |
// |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
661 |
// ProcessData is a channel-specific function to be provided by the PSL. Its purpose is to process |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
662 |
// data received/transmitted (called from NotifyClient or DFC queued from it). It Must fill in the |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
663 |
// aCb object's iReturn, iRxWords and/or iTxWords using the appropriate functions |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
664 |
// |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
665 |
// The functions UpdateReqTrig, StartTimerByState and StopTimer are for use by the PIL, only. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
666 |
// |
0 | 667 |
/** |
668 |
@publishedPartner |
|
669 |
@prototype 9.6 |
|
670 |
Function invoked when an asynchronous event occurs on the Slave channel. Implemented by the PSL. |
|
671 |
@param aTrigger Argument to indicate the type of event that occurred |
|
672 |
@param aCb Address of the Slave client callback object to process |
|
673 |
||
674 |
@return KErrNone, if successful; |
|
675 |
KErrNotSupported, function is not supported; |
|
676 |
Any other system wide error code. |
|
677 |
*/ |
|
678 |
#ifdef STANDALONE_CHANNEL |
|
679 |
friend class TIicBusSlaveCallback; |
|
680 |
protected: |
|
681 |
virtual void ProcessData(TInt aTrigger, TIicBusSlaveCallback* aCb) = 0; |
|
682 |
private: |
|
683 |
TInt UpdateReqTrig(TInt8& aCbTrigVal, TInt& aCallbackRet); |
|
684 |
void StartTimerByState(); |
|
685 |
void StopTimer(); |
|
686 |
#else |
|
687 |
public: |
|
688 |
virtual void ProcessData(TInt aTrigger, TIicBusSlaveCallback* aCb) = 0; |
|
689 |
virtual TInt UpdateReqTrig(TInt8& aCbTrigVal, TInt& aCallbackRet); |
|
690 |
virtual void StartTimerByState(); |
|
691 |
virtual void StopTimer(); |
|
692 |
#endif |
|
693 |
||
694 |
public: |
|
695 |
// Values used by the Interface to TIicBusSlaveCallback |
|
696 |
enum TSlaveNotifProcSteps |
|
697 |
{ |
|
698 |
EStopTimer = 0x01, |
|
699 |
EInvokeCb = 0x02, |
|
700 |
EStartTimer = 0x04 |
|
701 |
}; |
|
702 |
||
703 |
protected: |
|
704 |
// PSL implemented |
|
705 |
/** |
|
706 |
@publishedPartner |
|
707 |
@prototype 9.6 |
|
708 |
||
709 |
PSL specific second phase constructor |
|
710 |
||
711 |
@return KErrNone, if succesful; |
|
712 |
KErrNotSupported, function is not supported; |
|
713 |
Any other system wide error code. |
|
714 |
*/ |
|
715 |
virtual TInt DoCreate() = 0; |
|
716 |
/** |
|
717 |
@publishedPartner |
|
718 |
@prototype 9.6 |
|
719 |
||
720 |
Gateway function for PSL implementation: aOperation is a bitmask made of TPslOperation (to be called by the interface APIs) |
|
721 |
||
722 |
@return KErrNone, if succesful; |
|
723 |
KErrNotSupported, function is not supported; |
|
724 |
Any other system wide error code. |
|
725 |
*/ |
|
726 |
virtual TInt DoRequest(TInt aOperation) = 0; |
|
727 |
||
728 |
// Called by PSL |
|
729 |
/** |
|
730 |
@publishedPartner |
|
731 |
@prototype 9.6 |
|
732 |
||
733 |
Constructor for DIicBusChannelSlave |
|
734 |
||
735 |
@param aBusType Argument to specify the type of Bus |
|
736 |
@param aChanDuplex Argument to specify the duplex support offered by this channel |
|
737 |
@param aChannelId Argument to specify the identifier to use for this channel |
|
738 |
*/ |
|
739 |
DIicBusChannelSlave(TBusType aBusType, TChannelDuplex aChanDuplex, TInt16 aChannelId); |
|
740 |
/** |
|
741 |
@publishedPartner |
|
742 |
@prototype 9.6 |
|
743 |
Function to instigate DIicBusChannelSlave initialisation |
|
744 |
||
745 |
@return KErrNone |
|
746 |
*/ |
|
747 |
TInt Init(); |
|
748 |
||
749 |
/** |
|
750 |
@publishedPartner |
|
751 |
@prototype 9.6 |
|
752 |
Destructor for DIicBusChannelSlave |
|
753 |
*/ |
|
754 |
~DIicBusChannelSlave(); |
|
755 |
||
756 |
/** |
|
757 |
@publishedPartner |
|
758 |
@prototype 9.6 |
|
759 |
Function invoked when an asynchronous channel capture completes |
|
760 |
||
761 |
@param aResult Argument specifying the error code reurned by the capture operation |
|
762 |
||
763 |
@return KErrNone |
|
764 |
*/ |
|
765 |
void ChanCaptureCallback(TInt aResult); |
|
766 |
/** |
|
767 |
@publishedPartner |
|
768 |
@prototype 9.6 |
|
769 |
Function invoked to instigate processing by the PSL, PIL and Client when an asynchronous event occurs |
|
770 |
||
771 |
@param aResult Argument specifying the trigger value associated with the asynchronous event |
|
772 |
||
773 |
@return KErrNone |
|
774 |
*/ |
|
775 |
void NotifyClient(TInt aTrigger); |
|
776 |
||
777 |
/** |
|
778 |
@publishedPartner |
|
779 |
@prototype 9.6 |
|
780 |
Function invoked by the PSL to set the timeout period to wait for a response from the bus master |
|
781 |
||
782 |
@param aWaitTime Argument specifying the wait time, in milliseconds (limit=KMaxWaitTime) |
|
783 |
||
784 |
@return KErrNone, if succesful; |
|
785 |
KErrArgument, if aWaitTime > KMaxWaitTime |
|
786 |
*/ |
|
787 |
TInt SetMasterWaitTime(TInt8 aWaitTime); |
|
788 |
/** |
|
789 |
@publishedPartner |
|
790 |
@prototype 9.6 |
|
791 |
Function invoked by the PSL to get the timeout period to wait for a response from the bus master |
|
792 |
||
793 |
@return The wait time, in milliseconds |
|
794 |
*/ |
|
795 |
inline TInt8 GetMasterWaitTime(); |
|
796 |
/** |
|
797 |
@publishedPartner |
|
798 |
@prototype 9.6 |
|
799 |
Function invoked by the PSL to set the timeout period to wait for a response from the Client |
|
800 |
||
801 |
@param aWaitTime Argument specifying the wait time, in milliseconds (limit=KMaxWaitTime) |
|
802 |
@return KErrNone |
|
803 |
*/ |
|
804 |
TInt SetClientWaitTime(TInt8 aWaitTime); |
|
805 |
/** |
|
806 |
@publishedPartner |
|
807 |
@prototype 9.6 |
|
808 |
Function invoked by the PSL to get the timeout period to wait for a response from the Client |
|
809 |
||
810 |
@return The wait time, in milliseconds |
|
811 |
*/ |
|
812 |
inline TInt8 GetClientWaitTime(); |
|
813 |
private: |
|
814 |
//Method to instruct PSL to indicate a bus error to the bus Master, then return |
|
815 |
void SendBusErrorAndReturn(); |
|
816 |
void SetChannelId(TInt& aChannelId); |
|
817 |
||
818 |
void CompleteAsynchCapture(TInt aResult); |
|
819 |
void SlaveTimerCallBack(); |
|
820 |
static void SlaveStaticCB(TAny* aDumPtr); |
|
821 |
||
822 |
protected: |
|
823 |
TInt8 iRxGranularity; |
|
824 |
TInt8 iTxGranularity; |
|
825 |
TInt8 iNumRxWords; |
|
826 |
TInt8 iNumTxWords; |
|
827 |
TInt8 iRxOffset; |
|
828 |
TInt8 iTxOffset; |
|
829 |
private: |
|
830 |
TInt8 iChannelInUse; |
|
831 |
TInt8 iSpare1; |
|
832 |
protected: |
|
833 |
TInt16 iChannelId; // channel identifier to be returned to client (in aChannelId) |
|
834 |
private: |
|
835 |
TInt16 iInstanceCount; // instance count part of aChannelId |
|
836 |
protected: |
|
837 |
TDes8* iConfigHeader; |
|
838 |
TInt8* iTxBuf; |
|
839 |
TInt8* iRxBuf; |
|
840 |
private: |
|
841 |
TIicBusSlaveCallback* iNotif; |
|
842 |
TDfc* iClientTimeoutDfc; // To be queued on the dfc queue used by iNotif |
|
843 |
DThread* iClient; // stored when client captures channel |
|
844 |
#ifndef STANDALONE_CHANNEL |
|
845 |
DIicBusController* iController; |
|
846 |
#endif |
|
847 |
||
848 |
TInt8 iTimerState; |
|
849 |
TInt8 iMasterWaitTime; // 8 bits allows maximum wait time of 0.25 seconds |
|
850 |
TInt8 iClientWaitTime; // 8 bits allows maximum wait time of 0.25 seconds |
|
851 |
TInt8 iSpare2; |
|
852 |
||
853 |
TInt8 iReqTrig; // Represents the trigger required by the Client (bitmask from TIicBusSlaveTrigger). |
|
854 |
TInt8 iAccumTrig; // Represents the events accumulated during the current trigger period |
|
855 |
TInt16 iSpare3; |
|
856 |
||
857 |
TSpinLock iSpinLock; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
858 |
NTimer iTimeoutTimer; // timeout timer |
0 | 859 |
TAny* iReserved1; |
860 |
TAny* iReserved2; |
|
861 |
||
862 |
friend class DIicBusChannelMasterSlave; |
|
863 |
friend class DIicBusController; // For static method DIicBusController::DeRegisterChannel |
|
864 |
}; |
|
865 |
||
866 |
/** |
|
867 |
@internalComponent |
|
868 |
@prototype 9.6 |
|
869 |
The Master-Slave Channel class (not for derivation) |
|
870 |
*/ |
|
871 |
class DIicBusChannelMasterSlave : public DIicBusChannel |
|
872 |
{ |
|
873 |
public: |
|
874 |
// constructor |
|
875 |
#ifdef STANDALONE_CHANNEL |
|
876 |
IMPORT_C DIicBusChannelMasterSlave(TBusType aBusType, TChannelDuplex aChanDuplex, DIicBusChannelMaster* aMasterChan, DIicBusChannelSlave* aSlaveChan); |
|
877 |
#else |
|
878 |
inline DIicBusChannelMasterSlave(TBusType aBusType, TChannelDuplex aChanDuplex, DIicBusChannelMaster* aMasterChan, DIicBusChannelSlave* aSlaveChan); |
|
879 |
#endif |
|
880 |
~DIicBusChannelMasterSlave(){delete iMasterChannel; delete iSlaveChannel; } |
|
881 |
inline TInt DoCreate(); |
|
882 |
// Master side interface to Bus Controller |
|
883 |
virtual TInt QueueTransaction(TIicBusTransaction* aTransaction); |
|
884 |
virtual TInt QueueTransaction(TIicBusTransaction* aTransaction, TIicBusCallback* aCallback); |
|
885 |
inline TInt CancelTransaction(TIicBusTransaction* aTransaction); |
|
886 |
||
887 |
// Slave side interface to Bus Controller |
|
888 |
virtual TInt CaptureChannel(TDes8* aConfigHdr, TIicBusSlaveCallback* aCallback, TInt& aChannelId, TBool aAsynch); |
|
889 |
virtual TInt ReleaseChannel(); |
|
890 |
inline TInt RegisterRxBuffer(TPtr8 aRxBuffer, TInt8 aBufGranularity, TInt8 aNumWords, TInt8 aOffset); |
|
891 |
inline TInt RegisterTxBuffer(TPtr8 aTxBuffer, TInt8 aBufGranularity, TInt8 aNumWords, TInt8 aOffset); |
|
892 |
inline TInt SetNotificationTrigger(TInt aTrigger); |
|
893 |
virtual TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); |
|
894 |
||
895 |
private: |
|
896 |
// Base class support |
|
897 |
virtual TInt CheckHdr(TDes8* /*aHdr*/){ __ASSERT_DEBUG(0,Kern::Fault("DIicBusChannelMasterSlave::CheckHdr",__LINE__)); \ |
|
898 |
return KErrGeneral;}; // Not accessed. PSL implementation for Master or Slave used. |
|
899 |
protected: |
|
900 |
DIicBusChannelMaster* iMasterChannel; |
|
901 |
DIicBusChannelSlave* iSlaveChannel; |
|
902 |
private: |
|
903 |
||
904 |
friend class DIicBusChannelMaster; |
|
905 |
friend class DIicBusChannelSlave; |
|
906 |
friend class DIicBusController; // For static method DIicBusController::DeRegisterChannel |
|
907 |
}; |
|
908 |
||
909 |
#include <drivers/iic_channel.inl> |
|
910 |
||
911 |
#endif // #ifndef __IIC_CHANNEL_H__ |
|
912 |