author | hgs |
Mon, 26 Jul 2010 10:52:56 +0100 | |
changeset 231 | 75252ea6123b |
parent 90 | 947f0dc9f7a8 |
child 257 | 3e88ff8f41d5 |
child 291 | 206a6eaaeb71 |
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\drivers\iic_channel.cpp |
|
15 |
// IIC Channel Platform Independent Layer (PIL) |
|
16 |
// |
|
17 |
||
18 |
#include <drivers/iic_channel.h> |
|
19 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
20 |
#include <drivers/iic_trace.h> |
|
21 |
#endif |
|
22 |
||
23 |
// The timer call back function which calls the PSL's HandleSlaveTimeout() |
|
24 |
// Note that this assumes that the channel thread has been unblocked - if this |
|
25 |
// is not the case, the callback will never get to run |
|
26 |
||
27 |
TInt DIicBusChannelMaster::DoCreate() |
|
28 |
{return KErrNone;} |
|
29 |
||
30 |
void DIicBusChannelMaster::Lock() |
|
31 |
{NKern::FMWait(&iTransactionQLock);} |
|
32 |
||
33 |
void DIicBusChannelMaster::Unlock() |
|
34 |
{NKern::FMSignal(&iTransactionQLock);} |
|
35 |
||
36 |
TIicBusTransaction* DIicBusChannelMaster::NextTrans(TIicBusTransaction* aTrans) |
|
37 |
{ |
|
38 |
// call multi-transaction call back function to get next transaction |
|
39 |
if((aTrans->iFlags&KTransactionWithPreamble)&&(aTrans->iFlags&KTransactionWithMultiTransc)) |
|
40 |
return ((TIicBusTransactionPreambleExt*)aTrans)->iMultiTransc(aTrans, ((TIicBusTransactionPreambleExt*)aTrans)->iMultiTranscArg); |
|
41 |
else if(aTrans->iFlags&KTransactionWithMultiTransc) |
|
42 |
return ((TIicBusTransactionMultiTransc*)aTrans)->iMultiTransc(aTrans, ((TIicBusTransactionMultiTransc*)aTrans)->iMultiTranscArg); |
|
43 |
else |
|
44 |
return NULL; |
|
45 |
} |
|
46 |
||
47 |
void DIicBusChannelMaster::UnlockAndKick() |
|
48 |
{iTransQDfc.Enque(&iTransactionQLock);} |
|
49 |
||
50 |
void DIicBusChannelMaster::SlaveTimeoutCallback(TAny* aPtr) |
|
51 |
{ |
|
52 |
||
53 |
DIicBusChannelMaster* aChanMaster=(DIicBusChannelMaster* )aPtr; |
|
54 |
TInt r = aChanMaster->HandleSlaveTimeout(); |
|
55 |
aChanMaster->CompleteRequest(r); |
|
56 |
} |
|
57 |
||
58 |
TInt DIicBusChannelMaster::TransFlow(TIicBusTransaction* aTransaction) |
|
59 |
{ |
|
60 |
if(aTransaction->iHalfDuplexTrans == NULL) |
|
61 |
return KErrArgument; |
|
62 |
else if(aTransaction->iFullDuplexTrans == NULL) |
|
63 |
return DIicBusChannel::EHalfDuplex; |
|
64 |
else return DIicBusChannel::EFullDuplex; |
|
65 |
} |
|
66 |
||
67 |
TInt8 DIicBusChannelMaster::IsMasterBusy() |
|
68 |
{ |
|
69 |
if((iTransCount&~KTransCountMsBit) == 0) |
|
70 |
return 0; |
|
71 |
else return 1; |
|
72 |
} |
|
73 |
||
74 |
DIicBusChannelMaster::DIicBusChannelMaster(TBusType aBusType, TChannelDuplex aChanDuplex) |
|
75 |
: DIicBusChannel(DIicBusChannel::EMaster, aBusType, aChanDuplex), |
|
76 |
iTransQDfc(DIicBusChannelMaster::MsgQFunc, this, NULL, 1), iChannelReady(EFalse) |
|
77 |
{ |
|
78 |
new(&iTimeoutTimer) NTimer(SlaveTimeoutCallback,this); |
|
79 |
} |
|
80 |
||
81 |
DIicBusChannelMaster::~DIicBusChannelMaster() |
|
82 |
{ |
|
83 |
delete iSlaveTimeoutDfc; |
|
84 |
} |
|
85 |
||
86 |
TInt DIicBusChannelMaster::Init() |
|
87 |
{ |
|
88 |
iSlaveTimeoutDfc = new TDfc(SlaveTimeoutCallback,(TAny*)this, 7); // Highest Dfc priority |
|
89 |
if(!iSlaveTimeoutDfc) |
|
90 |
return KErrNoMemory; |
|
91 |
else |
|
92 |
return KErrNone; |
|
93 |
} |
|
94 |
||
95 |
// Function to used to indicate if the Slave response has exceeded |
|
96 |
// an expected time |
|
97 |
TInt DIicBusChannelMaster::StartSlaveTimeOutTimer(TInt aTime) |
|
98 |
{ |
|
99 |
TInt r = iTimeoutTimer.OneShot(NKern::TimerTicks(aTime),(*iSlaveTimeoutDfc)); |
|
100 |
return r; |
|
101 |
} |
|
102 |
||
103 |
void DIicBusChannelMaster::SetDfcQ(TDfcQue* aDfcQue) |
|
104 |
{ |
|
105 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::SetDfcQ 0x%x\n",aDfcQue)); |
|
106 |
__ASSERT_DEBUG(aDfcQue!=NULL, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
107 |
iDfcQ=aDfcQue; |
|
108 |
iTransQDfc.SetDfcQ(iDfcQ); |
|
109 |
iSlaveTimeoutDfc->SetDfcQ(iDfcQ); |
|
110 |
Lock(); |
|
111 |
__ASSERT_DEBUG(!iChannelReady, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
112 |
if (!iTransactionQ.IsEmpty()) |
|
113 |
{ |
|
114 |
iTransaction=(TIicBusTransaction*)(iTransactionQ.First()->Deque()); |
|
115 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::SetDfcQ got %08x",iTransaction)); |
|
116 |
iTransaction->iState=TIicBusTransaction::EAccepted; |
|
117 |
iCurrentTransaction = iTransaction; |
|
118 |
UnlockAndKick(); |
|
119 |
} |
|
120 |
else |
|
121 |
{ |
|
122 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::SetDfcQ")); |
|
123 |
iChannelReady=ETrue; |
|
124 |
iTransaction=NULL; |
|
125 |
iCurrentTransaction = NULL; |
|
126 |
Unlock(); |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
void DIicBusChannelMaster::CompleteRequest(TInt aResult) |
|
131 |
{ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
// Ensure the timeout timer has been cancelled |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
CancelTimeOut(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
|
0 | 135 |
TIicBusTransaction* nextTrans=NextTrans(iCurrentTransaction); |
136 |
||
137 |
if((aResult != KErrNone)||(nextTrans == NULL)) |
|
138 |
EndTransaction(iTransaction,aResult,iTransaction->iCallback); |
|
139 |
else |
|
140 |
{ |
|
141 |
nextTrans->iBusId = iCurrentTransaction->iBusId; // Pass the bus configuration info to the PSL |
|
142 |
iCurrentTransaction = nextTrans; |
|
143 |
DoRequest(nextTrans); |
|
144 |
} |
|
145 |
} |
|
146 |
||
147 |
#ifdef MASTER_MODE |
|
148 |
||
149 |
/* |
|
150 |
For Master-side transaction queuing APIs |
|
151 |
the Channel implementation sends the transaction as a message to the Channel's message queue, |
|
152 |
optionally blocking the client thread on the message's semaphore (synchronous APIs). |
|
153 |
*/ |
|
154 |
TInt DIicBusChannelMaster::QueueTransaction(TIicBusTransaction* aTransaction) |
|
155 |
{ |
|
156 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::QueueTransaction, aTransaction=0x%x\n",aTransaction)); |
|
157 |
// Send the transaction as a message to the Channel's message queue |
|
158 |
// Synchronous API, so block the calling thread during the processing |
|
159 |
TInt r = QueueTransaction(aTransaction, NULL); |
|
160 |
if(r!=KErrNone) |
|
161 |
return r; // Transaction was not queued - so don't wait for a notification that it completed. |
|
162 |
||
163 |
__KTRACE_OPT(KIIC, Kern::Printf("<DIicBusChannelMaster::QueueTransaction ret %d",aTransaction->iResult)); |
|
164 |
return aTransaction->iResult; |
|
165 |
} |
|
166 |
||
167 |
TInt DIicBusChannelMaster::QueueTransaction(TIicBusTransaction* aTransaction, TIicBusCallback* aCallback) |
|
168 |
{ |
|
169 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::QueueTransaction, aTransaction=0x%x, aCallback=0x%x\n",aTransaction,aCallback)); |
|
170 |
||
171 |
// Check aTransaction is non-NULL (aCallback may be NULL if the synchronous operation is required). |
|
172 |
if(aTransaction == NULL) |
|
173 |
{ |
|
174 |
return KErrArgument; |
|
175 |
} |
|
176 |
||
177 |
// Send the transaction as a message to the Channel's message queue and return |
|
178 |
aTransaction->iCallback = aCallback; |
|
179 |
if(aCallback != NULL) |
|
180 |
{ |
|
181 |
aCallback->iTransaction = aTransaction; |
|
182 |
} |
|
183 |
||
184 |
// Call the PSL implementation to check that the header is valid for this channel |
|
185 |
TInt r = CheckHdr(aTransaction->iHeader); |
|
186 |
if(r!=KErrNone) |
|
187 |
{ |
|
188 |
return r; |
|
189 |
} |
|
190 |
||
191 |
// Duplex operation is indicated in the transaction object |
|
192 |
if((TransFlow((TIicBusTransaction*)aTransaction) == DIicBusChannel::EFullDuplex) && |
|
193 |
(ChannelDuplex() != DIicBusChannel::EFullDuplex)) |
|
194 |
{ |
|
195 |
return KErrNotSupported; |
|
196 |
} |
|
197 |
||
198 |
DThread* pC =& Kern::CurrentThread(); |
|
199 |
Lock(); |
|
200 |
__ASSERT_DEBUG(aTransaction->iState == TIicBusTransaction::EFree, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
201 |
if(!(iTransCount & KTransCountMsBit)) |
|
202 |
{ |
|
203 |
if(iTransCount < ~KTransCountMsBit) |
|
204 |
{ |
|
205 |
++iTransCount; |
|
206 |
} |
|
207 |
else |
|
208 |
{ |
|
209 |
Unlock(); |
|
210 |
return KErrOverflow; |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
aTransaction->iSyncNotification.iCount = 0; |
|
215 |
aTransaction->iSyncNotification.iOwningThread = &pC->iNThread; |
|
216 |
pC->Open(); |
|
217 |
if (iChannelReady) |
|
218 |
{ |
|
219 |
aTransaction->iState = TIicBusTransaction::EAccepted; |
|
220 |
iTransaction = aTransaction; |
|
221 |
iCurrentTransaction = aTransaction; |
|
222 |
iChannelReady = EFalse; |
|
223 |
UnlockAndKick(); |
|
224 |
} |
|
225 |
else |
|
226 |
{ |
|
227 |
iTransactionQ.Add(aTransaction); |
|
228 |
aTransaction->iState = TIicBusTransaction::EDelivered; |
|
229 |
Unlock(); |
|
230 |
} |
|
231 |
||
232 |
// Wait on a semaphore if called from synchronous version |
|
233 |
if(aCallback == NULL) |
|
234 |
{ |
|
235 |
NKern::FSWait(&aTransaction->iSyncNotification); |
|
236 |
} |
|
237 |
||
238 |
return KErrNone; |
|
239 |
} |
|
240 |
||
241 |
TInt DIicBusChannelMaster::CancelTransaction(TIicBusTransaction* aTransaction) |
|
242 |
{ |
|
243 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::CancelTransaction, aTransaction=0x%x\n",aTransaction)); |
|
244 |
||
245 |
// Check aTransaction is non-NULL |
|
246 |
if(aTransaction == NULL) |
|
247 |
{ |
|
248 |
return KErrArgument; |
|
249 |
} |
|
250 |
// If the method is called on a synchronous transaction return KErrNotSupported |
|
251 |
if(aTransaction->iCallback == NULL) |
|
252 |
{ |
|
253 |
return KErrNotSupported; |
|
254 |
} |
|
255 |
DThread* pT = NULL; |
|
256 |
Lock(); |
|
257 |
||
258 |
TInt r = KErrNone; |
|
259 |
switch(aTransaction->iState) |
|
260 |
{ |
|
261 |
case TIicBusTransaction::EDelivered: |
|
262 |
{ |
|
263 |
aTransaction->Deque(); |
|
264 |
pT=_LOFF(aTransaction->iSyncNotification.iOwningThread,DThread,iNThread); |
|
265 |
aTransaction->iState=TIicBusTransaction::EFree; |
|
266 |
--iTransCount; // Count must be greater than zero if the transaction is in this state |
|
267 |
r = KErrCancel; |
|
268 |
break; |
|
269 |
} |
|
270 |
||
271 |
case TIicBusTransaction::EAccepted: |
|
272 |
{ |
|
273 |
r = KErrInUse; |
|
274 |
break; |
|
275 |
} |
|
276 |
||
277 |
case TIicBusTransaction::EFree: |
|
278 |
{ |
|
279 |
r = KErrCancel; |
|
280 |
break; |
|
281 |
} |
|
282 |
} |
|
283 |
Unlock(); |
|
284 |
if (pT) |
|
285 |
{ |
|
286 |
pT->AsyncClose(); |
|
287 |
} |
|
288 |
||
289 |
return r; |
|
290 |
} |
|
291 |
||
292 |
#else /*MASTER_MODE*/ |
|
293 |
||
294 |
TInt DIicBusChannelMaster::QueueTransaction(TIicBusTransaction* /*aTransaction*/) |
|
295 |
{ |
|
296 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::QueueTransaction invoked when not in MASTER_MODE!\n")); |
|
297 |
return KErrNotSupported; |
|
298 |
} |
|
299 |
||
300 |
TInt DIicBusChannelMaster::QueueTransaction(TIicBusTransaction* /*aTransaction*/, TIicBusCallback* /*aCallback*/) |
|
301 |
{ |
|
302 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::QueueTransaction invoked when not in MASTER_MODE!\n")); |
|
303 |
return KErrNotSupported; |
|
304 |
} |
|
305 |
||
306 |
TInt DIicBusChannelMaster::CancelTransaction(TIicBusTransaction* /*aTransaction*/) |
|
307 |
{ |
|
308 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::CancelTransaction invoked when not in MASTER_MODE!\n")); |
|
309 |
return KErrNotSupported; |
|
310 |
} |
|
311 |
#endif/*MASTER_MODE*/ |
|
312 |
||
313 |
// Invoked in response to receiving a message |
|
314 |
// Function argument is a pointer to the required channel object |
|
315 |
// Invoke the channel's PSL implementation of the DoRequest method with a pointer to the transaction object |
|
316 |
// |
|
317 |
void DIicBusChannelMaster::MsgQFunc(TAny* aPtr) |
|
318 |
{ |
|
319 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::MsgQFunc, aPtr=0x%x\n",aPtr)); |
|
320 |
DIicBusChannelMaster* channel=(DIicBusChannelMaster*)aPtr; |
|
321 |
TIicBusTransaction* trans = channel->iTransaction; |
|
322 |
||
323 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
324 |
IIC_MPROCESSTRANS_START_PIL_TRACE; |
|
325 |
#endif |
|
326 |
||
327 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::MsgQFunc trans->iHeader=0x%x\n",trans->iHeader)); |
|
328 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::MsgQFunc trans->iHalfDuplexTrans=0x%x\n",trans->iHalfDuplexTrans)); |
|
329 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::MsgQFunc trans->iFullDuplexTrans=0x%x\n",trans->iFullDuplexTrans)); |
|
330 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::MsgQFunc trans->iCallback=0x%x\n",trans->iCallback)); |
|
331 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelMaster::MsgQFunc trans->iFlags=0x%x\n",trans->iFlags)); |
|
332 |
||
333 |
TInt r = KErrNone; |
|
334 |
// invoke the preamble callback function supplied by the client of the IIC if there is any |
|
335 |
if(GetTransFlags(trans) & KTransactionWithPreamble) |
|
336 |
{ |
|
337 |
TIicBusTransactionPreamble* transPreamble = (TIicBusTransactionPreamble*)trans; |
|
338 |
TIicBusPreamble funcPtr=NULL; |
|
339 |
funcPtr=(GetPreambleFuncPtr(transPreamble)); |
|
340 |
funcPtr(transPreamble,GetPreambleFuncArg(transPreamble)); |
|
341 |
} |
|
342 |
r = channel->DoRequest(trans); // Instigate processing in the PSL |
|
343 |
if(r!=KErrNone) |
|
344 |
channel->EndTransaction(trans, r, trans->iCallback); |
|
345 |
} |
|
346 |
||
347 |
void DIicBusChannelMaster::EndTransaction(TIicBusTransaction* aTrans, TInt aResult, TIicBusCallback* aCb) |
|
348 |
{ |
|
349 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
350 |
IIC_MPROCESSTRANS_END_PIL_TRACE; |
|
351 |
#endif |
|
352 |
Complete(aResult,aTrans); |
|
353 |
if(aCb != NULL) |
|
354 |
{ |
|
355 |
aCb->iResult = aResult; |
|
356 |
aCb->Enque(); |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
void DIicBusChannelMaster::CancelTimeOut() |
|
361 |
{ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
362 |
// Silently cancel the timer and associated DFC |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
363 |
// |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
364 |
// NTimer::Cancel returns ETrue if cancelled, EFalse otherwise - which may mean it wasn't active |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
// TDfc::Cancel returns ETrue if actually de-queued, EFalse otherwise - which may mean it wasn't queued |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
366 |
// |
0 | 367 |
iTimeoutTimer.Cancel(); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
iSlaveTimeoutDfc->Cancel(); |
0 | 369 |
} |
370 |
||
371 |
void DIicBusChannelMaster::Complete(TInt aResult, TIicBusTransaction* aTransaction) //Completes a kernel message and receive the next one |
|
372 |
{ |
|
373 |
__KTRACE_OPT(KIIC, Kern::Printf("MsgB::Complete %08x, %d",this,aResult)); |
|
374 |
Lock(); |
|
375 |
__ASSERT_DEBUG(aTransaction->iState == TIicBusTransaction::EAccepted, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
376 |
aTransaction->iResult=aResult; |
|
377 |
aTransaction->iState=TIicBusTransaction::EFree; |
|
378 |
--iTransCount; |
|
379 |
DThread* pT=_LOFF(aTransaction->iSyncNotification.iOwningThread,DThread,iNThread); |
|
380 |
__ASSERT_DEBUG(!iChannelReady, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
381 |
if (!iTransactionQ.IsEmpty()) |
|
382 |
{ |
|
383 |
TIicBusTransaction* pM=(TIicBusTransaction*)iTransactionQ.First()->Deque(); |
|
384 |
__KTRACE_OPT(KIIC, Kern::Printf("rxnext: got %08x",pM)); |
|
385 |
pM->iState=TIicBusTransaction::EAccepted; |
|
386 |
iTransaction = pM; |
|
387 |
iCurrentTransaction = pM; |
|
388 |
iTransQDfc.Enque(); |
|
389 |
} |
|
390 |
else |
|
391 |
{ |
|
392 |
__KTRACE_OPT(KIIC, Kern::Printf("rxnext")); |
|
393 |
iChannelReady=ETrue; |
|
394 |
iTransaction=NULL; |
|
395 |
iCurrentTransaction = NULL; |
|
396 |
} |
|
397 |
NKern::FSSignal(&aTransaction->iSyncNotification,&iTransactionQLock); |
|
398 |
pT->AsyncClose(); |
|
399 |
} |
|
400 |
||
401 |
TInt DIicBusChannelMaster::StaticExtension(TUint /*aFunction*/, TAny* /*aParam1*/, TAny* /*aParam*/) |
|
402 |
{ |
|
403 |
return KErrNotSupported; |
|
404 |
} |
|
405 |
||
406 |
TInt DIicBusChannelMaster::Spare1(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/) |
|
407 |
{ |
|
408 |
return KErrNotSupported; |
|
409 |
} |
|
410 |
||
411 |
#ifdef SLAVE_MODE |
|
412 |
||
413 |
TInt DIicBusChannelSlave::CaptureChannel(TDes8* aConfigHdr, TIicBusSlaveCallback* aCallback, TInt& aChannelId, TBool aAsynch) |
|
414 |
{ |
|
415 |
// Only one client can have access to the Slave channel at any one time. Any subsequent attempts to capture the |
|
416 |
// same channel should return an error. |
|
417 |
// |
|
418 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::CaptureChannel\n")); |
|
419 |
if((aConfigHdr == NULL) || (aCallback == NULL)) |
|
420 |
{ |
|
421 |
__KTRACE_OPT(KIIC, Kern::Printf("ERROR: non-NULL argument aConfigHdr=0x%x, aCallback=0x%x\n",aConfigHdr,aCallback)); |
|
422 |
return KErrArgument; |
|
423 |
} |
|
424 |
// |
|
425 |
// Check the header is valid for the channel |
|
426 |
TInt r = CheckHdr(aConfigHdr); |
|
427 |
if(r == KErrNone) |
|
428 |
{ |
|
429 |
// Check Slave channel is available for capture |
|
430 |
// If iChannelInUse is not set, capture should succeed |
|
431 |
// If this Slave channel is part of a MasterSlave channel iChannelInUse will already be set |
|
432 |
// but iClient will still be NULL. In this case, the capture should succeed. |
|
433 |
TInt intState=__SPIN_LOCK_IRQSAVE(iSpinLock); |
|
434 |
DThread* pT=&(Kern::CurrentThread()); |
|
435 |
if((iChannelInUse)&&(iClient!=NULL)) |
|
436 |
r=KErrInUse; |
|
437 |
else |
|
438 |
{ |
|
439 |
iChannelInUse=1; |
|
440 |
iClient=pT; |
|
441 |
} |
|
442 |
__SPIN_UNLOCK_IRQRESTORE(iSpinLock,intState); |
|
443 |
||
444 |
if(r == KErrNone) |
|
445 |
{ |
|
446 |
iClient->Open(); |
|
447 |
aCallback->iChannel=this; |
|
448 |
iNotif = aCallback; |
|
449 |
iConfigHeader=aConfigHdr; // Header alread checked, so just assign it |
|
450 |
||
451 |
// Invoke the PSL processing |
|
452 |
if(aAsynch) |
|
453 |
{ |
|
454 |
aChannelId = 0; // the client should read iChannelId from the callback object. |
|
455 |
r=DoRequest(EAsyncConfigPwrUp); |
|
456 |
} |
|
457 |
else |
|
458 |
r=DoRequest(ESyncConfigPwrUp); |
|
459 |
||
460 |
if(r == KErrNone) |
|
461 |
{ |
|
462 |
if(!aAsynch) // For asynchronous version there is nothing more to do until the callback is invoked |
|
463 |
{ |
|
464 |
SetChannelId(aChannelId); |
|
465 |
iClientTimeoutDfc->SetDfcQ(iNotif->iDfcQ); |
|
466 |
} |
|
467 |
} |
|
468 |
else |
|
469 |
{ |
|
470 |
// PSL encountered an error |
|
471 |
ReleaseChannel(); |
|
472 |
if(aAsynch) |
|
473 |
CompleteAsynchCapture(r); // Queue the client callback for execution |
|
474 |
} |
|
475 |
} |
|
476 |
} |
|
477 |
return r; |
|
478 |
} |
|
479 |
||
480 |
TInt DIicBusChannelSlave::ReleaseChannel() |
|
481 |
{ |
|
482 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::ReleaseChannel\n")); |
|
483 |
// Release a previously-captured channel. |
|
484 |
TInt r=KErrNone;; |
|
485 |
// Ensure that only the channel's client may release the channel |
|
486 |
DThread* pT=&(Kern::CurrentThread()); |
|
487 |
if(iClient!=pT) // Direct access since iClient can't be modified while channel is still captured |
|
488 |
return KErrAccessDenied; |
|
489 |
||
490 |
r=SetNotificationTrigger(0); // Attempt to clear notification requests |
|
491 |
if((r!=KErrNone)&&(r!=KErrTimedOut)) // KErrTimedOut refers to an earlier transaction, and is for information only |
|
492 |
return r; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
493 |
StopTimer(); |
0 | 494 |
r=DoRequest(EPowerDown); |
495 |
if(r == KErrNone) |
|
496 |
{ |
|
497 |
TInt intState=__SPIN_LOCK_IRQSAVE(iSpinLock); |
|
498 |
iClient=NULL; |
|
499 |
iChannelInUse=0; // Channel now available for capture by other clients |
|
500 |
__SPIN_UNLOCK_IRQRESTORE(iSpinLock,intState); |
|
501 |
pT->AsyncClose(); // Allow Client thread to close now channel has been released |
|
502 |
} |
|
503 |
else |
|
504 |
{ |
|
505 |
// PSL error when releasing the channel - have to assume the hardware has a problem. |
|
506 |
// The channel is no longer considered "captured" by the controller, i.e. will not accept commands |
|
507 |
// But not having cleared the busy flag means that it can not be used for master channel |
|
508 |
// operations if it is part of a MasterSlave channel |
|
509 |
// Must Fault the Kernel. |
|
510 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::ReleaseChannel - PSL returned error code %d\n",r)); |
|
511 |
__ASSERT_ALWAYS(EFalse, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
512 |
} |
|
513 |
return r; |
|
514 |
} |
|
515 |
||
516 |
TInt DIicBusChannelSlave::RegisterRxBuffer(TPtr8 aRxBuffer, TInt8 aBufGranularity, TInt8 aNumWords, TInt8 aOffset) |
|
517 |
{ |
|
518 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::RegisterRxBuffer\n")); |
|
519 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
520 |
IIC_SREGRXBUF_START_PIL_TRACE; |
|
521 |
#endif |
|
522 |
TInt r=KErrNone; |
|
523 |
// Ensure that only the channel's client may perform this operation |
|
524 |
DThread* pT=&(Kern::CurrentThread()); |
|
525 |
if(iClient!=pT) // Direct access since iClient can't be modified while channel is still captured |
|
526 |
return KErrAccessDenied; |
|
527 |
//If the buffer pointer is NULL, return KErrArgument |
|
528 |
if(aRxBuffer.Ptr() == NULL) |
|
529 |
return KErrArgument; |
|
530 |
// If a buffer is already registered, a subsequent request to do the same should return KErrAlreadyExists |
|
531 |
// This will be the case if SetNotificationTrigger has been invoked with any of ERxAllBytes, ERxUnderrun or ERxOverrun |
|
532 |
if(iReqTrig&(ERxAllBytes|ERxUnderrun|ERxOverrun)) |
|
533 |
r=KErrAlreadyExists; |
|
534 |
else |
|
535 |
{ |
|
536 |
iRxBuf=(TInt8*)(aRxBuffer.Ptr()); |
|
537 |
iRxGranularity=aBufGranularity; |
|
538 |
iNumRxWords=aNumWords; |
|
539 |
iRxOffset=aOffset; |
|
540 |
} |
|
541 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
542 |
IIC_SREGRXBUF_END_PIL_TRACE; |
|
543 |
#endif |
|
544 |
return r; |
|
545 |
} |
|
546 |
||
547 |
TInt DIicBusChannelSlave::RegisterTxBuffer(TPtr8 aTxBuffer, TInt8 aBufGranularity, TInt8 aNumWords, TInt8 aOffset) |
|
548 |
{ |
|
549 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::RegisterTxBuffer - default implementation\n")); |
|
550 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
551 |
IIC_SREGTXBUF_START_PIL_TRACE; |
|
552 |
#endif |
|
553 |
TInt r=KErrNone; |
|
554 |
// Ensure that only the channel's client may perform this operation |
|
555 |
DThread* pT=&(Kern::CurrentThread()); |
|
556 |
if(iClient!=pT) // Direct access since iClient can't be modified while channel is still captured |
|
557 |
return KErrAccessDenied; |
|
558 |
//If the buffer pointer is NULL, return KErrArgument |
|
559 |
if(aTxBuffer.Ptr() == NULL) |
|
560 |
return KErrArgument; |
|
561 |
// If a buffer is already registered and a request is pending, a subsequent request to register a buffer should return |
|
562 |
// KErrAlreadyExists |
|
563 |
// This will be the case if SetNotificationTrigger has been invoked with any of ETxAllBytes, ETxUnderrun or ETxOverrun |
|
564 |
if(iReqTrig&(ETxAllBytes|ETxUnderrun|ETxOverrun)) |
|
565 |
r=KErrAlreadyExists; |
|
566 |
else |
|
567 |
{ |
|
568 |
iTxBuf=(TInt8*)(aTxBuffer.Ptr()); |
|
569 |
iTxGranularity=aBufGranularity; |
|
570 |
iNumTxWords=aNumWords; |
|
571 |
iTxOffset=aOffset; |
|
572 |
} |
|
573 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
574 |
IIC_SREGTXBUF_END_PIL_TRACE; |
|
575 |
#endif |
|
576 |
return r; |
|
577 |
} |
|
578 |
||
579 |
TInt DIicBusChannelSlave::SetNotificationTrigger(TInt aTrigger) |
|
580 |
{ |
|
581 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::SetNotificationTrigger invoked with aTrigger=0x%x\n",aTrigger)); |
|
582 |
// Ensure that only the channel's client may perform this operation |
|
583 |
DThread* pT=&(Kern::CurrentThread()); |
|
584 |
if(iClient!=pT) // Direct access since iClient can't be modified while channel is still captured |
|
585 |
return KErrAccessDenied; |
|
586 |
||
587 |
TInt retVal = KErrNone; |
|
588 |
TInt trigger = aTrigger; |
|
589 |
switch (iTimerState) // Handle existing timer conditions |
|
590 |
{ |
|
591 |
case DIicBusChannelSlave::EInactive: |
|
592 |
{ |
|
593 |
// In this state no timers have been started - so no action required |
|
594 |
break; |
|
595 |
} |
|
596 |
case DIicBusChannelSlave::EWaitForClient: |
|
597 |
{ |
|
598 |
// Client has responded within the given time period, so stop the timer. |
|
599 |
StopTimer(); |
|
600 |
break; |
|
601 |
} |
|
602 |
case DIicBusChannelSlave::EWaitForMaster: |
|
603 |
{ |
|
604 |
// If both Rx and Tx events had been requested, and if ERxOverrun had occurred, the Client |
|
605 |
// may have called this function with new requests for Rx notifications, in order to |
|
606 |
// continue reading data sent by the Master. At this point, all Rx request flags in iReqTrig |
|
607 |
// will have been cleared. |
|
608 |
// If both Rx and Tx events had been requested, and if ETxUnderrun had occurred, the Client |
|
609 |
// may have called this function with new requests for Tx notifications, in order to |
|
610 |
// continue sending data to the Master. At this point, all Tx request flags in iReqTrig will |
|
611 |
// have been cleared. |
|
612 |
// |
|
613 |
// To handle the ERxOverrun situation, aTrigger may specify only the new Rx trigger settings, |
|
614 |
// or it may also re-specify the exisiting Tx settings. Similarly for the ETxUnderrun, aTrigger |
|
615 |
// may specify only the new Tx triggers, or both the new Tx triggers and the existing Rx triggers. |
|
616 |
// |
|
617 |
// However, if Rx flags are still set in iReqTrig, a request to change the Rx settings |
|
618 |
// will be rejected (similarly, for Tx). |
|
619 |
// |
|
620 |
// If the requested notification is zero, which would represent an attempt to clear all triggers |
|
621 |
// while the Master may have commenced a transfer, the request will be rejected. |
|
622 |
__ASSERT_DEBUG(iReqTrig != 0, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
623 |
if(trigger == 0) |
|
624 |
{ |
|
625 |
return KErrInUse; |
|
626 |
} |
|
627 |
TInt allRxFlags = ERxAllBytes | ERxOverrun | ERxUnderrun; |
|
628 |
TInt allTxFlags = ETxAllBytes | ETxOverrun | ETxUnderrun; |
|
629 |
// Check the Rx flags |
|
630 |
TInt rxTrig = iReqTrig & allRxFlags; |
|
631 |
TInt reqRxTrig = trigger & allRxFlags; |
|
632 |
if(rxTrig == 0) |
|
633 |
{ |
|
634 |
rxTrig = reqRxTrig; |
|
635 |
} |
|
636 |
else if(reqRxTrig != 0) |
|
637 |
{ |
|
638 |
// New Rx triggers specified - check that Client is not attempting to modify the existing |
|
639 |
// settings |
|
640 |
if(rxTrig ^ reqRxTrig) |
|
641 |
{ |
|
642 |
// Attempting to change the trigger settings - so reject the request |
|
643 |
return KErrInUse; |
|
644 |
} |
|
645 |
} |
|
646 |
// Check the Tx flags |
|
647 |
TInt txTrig = iReqTrig & allTxFlags; |
|
648 |
TInt reqTxTrig = trigger & allTxFlags; |
|
649 |
if(txTrig == 0) |
|
650 |
{ |
|
651 |
txTrig = reqTxTrig; |
|
652 |
} |
|
653 |
else if(reqTxTrig != 0) |
|
654 |
{ |
|
655 |
// New Tx triggers specified - check that Client is not attempting to modify the existing |
|
656 |
// settings |
|
657 |
if(txTrig ^ reqTxTrig) |
|
658 |
{ |
|
659 |
// Attempting to change the trigger settings - so reject the request |
|
660 |
return KErrInUse; |
|
661 |
} |
|
662 |
} |
|
663 |
// Udate iReqTrig for the new requested trigger |
|
664 |
// and cancel the timer - since we are now starting a new transfer, we should |
|
665 |
// allow the Master the time to perform it |
|
666 |
trigger = rxTrig | txTrig; |
|
667 |
StopTimer(); |
|
668 |
break; |
|
669 |
} |
|
670 |
case DIicBusChannelSlave::EClientTimeout: |
|
671 |
{ |
|
672 |
// The Client did not respond within the expected time for the previous transfer. As a result, |
|
673 |
// the transaction will have been terminated for the Client. |
|
674 |
// Set the return value to inform the Client that it previously exceeded the expected response time |
|
675 |
retVal = KErrTimedOut; |
|
676 |
break; |
|
677 |
} |
|
678 |
default: |
|
679 |
{ |
|
680 |
__ASSERT_DEBUG(0, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
681 |
break; |
|
682 |
} |
|
683 |
} |
|
684 |
// Ensure that requests for notification of asynchronous capture of channel is removed, since this |
|
685 |
// is not a valid event to request (the channel will already have been captured to get this far). |
|
686 |
// Also ensure that requests for EGeneralBusError are removed, since they are redundant (a notification |
|
687 |
// for a bus error is unconditional) and just represent overhead. |
|
688 |
trigger &= ~(EAsyncCaptChan | EGeneralBusError); |
|
689 |
||
690 |
iReqTrig = (TInt8)trigger; // Not atomic access since only client thread modifies iReqTrig |
|
691 |
iAccumTrig = 0; // New transfer, so initialise accumulated event record |
|
692 |
TInt reqFlags=0; |
|
693 |
// Overrun and/or underrun may be requested if Client is unsure how much data is to follow, |
|
694 |
// so need to instigate Rx/Tx operation for any such request |
|
695 |
if(iReqTrig & (ERxOverrun|ERxUnderrun|ERxAllBytes)) |
|
696 |
{ |
|
697 |
reqFlags |= EReceive; |
|
698 |
} |
|
699 |
if(iReqTrig & (ETxOverrun|ETxUnderrun|ETxAllBytes)) |
|
700 |
{ |
|
701 |
reqFlags |= ETransmit; |
|
702 |
} |
|
703 |
TInt r = DoRequest(reqFlags); |
|
704 |
if(r != KErrNone) |
|
705 |
{ |
|
706 |
// PSL encountered an error in intiating the requested trigger. Set the return value accordingly. |
|
707 |
// Assume triggers have been cancelled - if they have not, the client-provided callback will still |
|
708 |
// be invoked, but it will have been warned to expecte erroneous behaviour by the value assigned to retVal. |
|
709 |
iReqTrig = 0; |
|
710 |
retVal = KErrGeneral; |
|
711 |
} |
|
712 |
else // PSL accepted the request, so update timer and state information |
|
713 |
{ |
|
714 |
switch (iTimerState) |
|
715 |
{ |
|
716 |
case DIicBusChannelSlave::EInactive: |
|
717 |
{ |
|
718 |
// Do not start the timer. Must wait for the Master to access a Slave buffer before considering |
|
719 |
// a transaction as started. |
|
720 |
break; |
|
721 |
} |
|
722 |
case DIicBusChannelSlave::EWaitForClient: |
|
723 |
{ |
|
724 |
// Client has responded within the given time period. The next state is |
|
725 |
// dependent on the requested trigger - if set to zero, the Client is explicitly |
|
726 |
// ending the transaction, so the next state is EInactive; otherwise, the |
|
727 |
// Client has indicated the next action expected from the Master and so the |
|
728 |
// timer is started and next state is EWaitForMaster |
|
729 |
if(iReqTrig == 0) |
|
730 |
{ |
|
731 |
iTimerState = DIicBusChannelSlave::EInactive; |
|
732 |
} |
|
733 |
else |
|
734 |
{ |
|
735 |
iTimerState = DIicBusChannelSlave::EWaitForMaster; |
|
736 |
StartTimerByState(); |
|
737 |
} |
|
738 |
break; |
|
739 |
} |
|
740 |
case DIicBusChannelSlave::EClientTimeout: |
|
741 |
{ |
|
742 |
// For the previous transfer, the Client failed to respond within the required time - and |
|
743 |
// the PSL will have been instructed to indicate a bus error (so the Master |
|
744 |
// will have been informed). The error code returned by this function will be KErrTimedOut |
|
745 |
// so the Client will be informed of what has happened. |
|
746 |
// A transaction is considered to start when the Slave is addressed by the Master |
|
747 |
// (as indicated by the PSL invoking NotifyClient) - which has not yet happened - |
|
748 |
// so the next state is EInactive. |
|
749 |
iTimerState=DIicBusChannelSlave::EInactive; |
|
750 |
break; |
|
751 |
} |
|
752 |
case DIicBusChannelSlave::EWaitForMaster: |
|
753 |
{ |
|
754 |
// In this case we are handling a new requested trigger from the client to handle ERxOverrun or |
|
755 |
// ETxUnderrun. The PSL has accepted the new trigger, so must allow the Master sufficient time |
|
756 |
// to perform the newly-requested transfer; the timer has already been stopped, so just start it again.. |
|
757 |
StartTimerByState(); |
|
758 |
break; |
|
759 |
} |
|
760 |
default: |
|
761 |
{ |
|
762 |
__ASSERT_DEBUG(0, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
763 |
break; |
|
764 |
} |
|
765 |
} |
|
766 |
} |
|
767 |
||
768 |
return retVal; |
|
769 |
} |
|
770 |
#else /*SLAVE_MODE*/ |
|
771 |
||
772 |
TInt DIicBusChannelSlave::CaptureChannel(TDes8* /*aConfigHdr*/, TIicBusSlaveCallback* /*aCallback*/, TInt& /*aChannelId*/, TBool /*aAsynch*/) |
|
773 |
{ |
|
774 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::CaptureChannel invoked when not in SLAVE_MODE!\n")); |
|
775 |
return KErrNotSupported; |
|
776 |
} |
|
777 |
||
778 |
TInt DIicBusChannelSlave::ReleaseChannel() |
|
779 |
{ |
|
780 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::ReleaseChannel invoked when not in SLAVE_MODE!\n")); |
|
781 |
return KErrNotSupported; |
|
782 |
} |
|
783 |
||
784 |
TInt DIicBusChannelSlave::RegisterRxBuffer(TPtr8 /*aRxBuffer*/, TInt8 /*aBufGranularity*/, TInt8 /*aNumWords*/, TInt8 /*aOffset*/) |
|
785 |
{ |
|
786 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::RegisterRxBuffer invoked when not in SLAVE_MODE!\n")); |
|
787 |
return KErrNotSupported; |
|
788 |
} |
|
789 |
||
790 |
TInt DIicBusChannelSlave::RegisterTxBuffer(TPtr8 /*aTxBuffer*/, TInt8 /*aBufGranularity*/, TInt8 /*aNumWords*/, TInt8 /*aOffset*/) |
|
791 |
{ |
|
792 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::RegisterTxBuffer invoked when not in SLAVE_MODE!\n")); |
|
793 |
return KErrNotSupported; |
|
794 |
} |
|
795 |
||
796 |
TInt DIicBusChannelSlave::SetNotificationTrigger(TInt /*aTrigger*/) |
|
797 |
{ |
|
798 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::SetNotificationTrigger invoked when not in SLAVE_MODE!\n")); |
|
799 |
return KErrNotSupported; |
|
800 |
} |
|
801 |
#endif/*SLAVE_MODE*/ |
|
802 |
||
803 |
DIicBusChannelSlave::DIicBusChannelSlave(TBusType aBusType, TChannelDuplex aChanDuplex, TInt16 aChannelId) |
|
804 |
: DIicBusChannel(DIicBusChannel::ESlave, aBusType, aChanDuplex), |
|
805 |
iChannelId(aChannelId), iTimerState(EInactive), |
|
806 |
iMasterWaitTime(KSlaveDefMWaitTime), iClientWaitTime(KSlaveDefCWaitTime), |
|
807 |
iSpinLock(TSpinLock::EOrderGenericIrqLow2) // Semi-arbitrary, low priority value |
|
808 |
{ |
|
809 |
#ifndef STANDALONE_CHANNEL |
|
810 |
iController = NULL; |
|
811 |
#endif |
|
812 |
} |
|
813 |
||
814 |
DIicBusChannelSlave::~DIicBusChannelSlave() |
|
815 |
{ |
|
816 |
delete iClientTimeoutDfc; |
|
817 |
} |
|
818 |
||
819 |
void DIicBusChannelSlave::SlaveStaticCB(TAny* aPtr) |
|
820 |
{ |
|
821 |
DIicBusChannelSlave* chan = (DIicBusChannelSlave*)aPtr; |
|
822 |
chan->SlaveTimerCallBack(); |
|
823 |
return; |
|
824 |
} |
|
825 |
||
826 |
TInt DIicBusChannelSlave::Init() |
|
827 |
{ |
|
828 |
iClientTimeoutDfc = new TDfc(SlaveStaticCB,(TAny*)this, 7); // Highest Dfc priority |
|
829 |
if(!iClientTimeoutDfc) |
|
830 |
return KErrNoMemory; |
|
831 |
else |
|
832 |
return KErrNone; |
|
833 |
} |
|
834 |
||
835 |
void DIicBusChannelSlave::ChanCaptureCallback(TInt aResult) |
|
836 |
{ |
|
837 |
__KTRACE_OPT(KIIC, Kern::Printf("ChanCaptureCallback: aChannel=0x%x, aResult=%d\n",this,aResult)); |
|
838 |
||
839 |
TInt r=aResult; |
|
840 |
TInt channelId = 0; |
|
841 |
if(aResult == KErrNone) |
|
842 |
{ |
|
843 |
SetChannelId(channelId); |
|
844 |
#ifndef STANDALONE_CHANNEL |
|
845 |
__ASSERT_DEBUG(iController, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
846 |
iController->InstallCapturedChannel(channelId, this); |
|
847 |
#endif |
|
848 |
iClientTimeoutDfc->SetDfcQ(iNotif->iDfcQ); |
|
849 |
r=KErrCompletion; |
|
850 |
} |
|
851 |
else |
|
852 |
ReleaseChannel(); |
|
853 |
||
854 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
855 |
IIC_SCAPTCHANASYNC_END_PIL_TRACE; |
|
856 |
#endif |
|
857 |
CompleteAsynchCapture(r); // Queue the client callback for execution |
|
858 |
} |
|
859 |
||
860 |
void DIicBusChannelSlave::SlaveTimerCallBack() |
|
861 |
{ |
|
862 |
__KTRACE_OPT(KIIC, Kern::Printf("SlaveTimerCallBack")); |
|
863 |
if(iTimerState == DIicBusChannelSlave::EWaitForMaster) |
|
864 |
{ |
|
865 |
// Master timeout. Consider the transaction terminated - call NotifyClient |
|
866 |
// to inform both the Client and the PSL, and update the state machine |
|
867 |
NotifyClient(EGeneralBusError); |
|
868 |
} |
|
869 |
else if(iTimerState == DIicBusChannelSlave::EWaitForClient) |
|
870 |
{ |
|
871 |
// Client timeout. Instigate the PSL-specific bus error indication |
|
872 |
iTimerState=DIicBusChannelSlave::EClientTimeout; |
|
873 |
SendBusErrorAndReturn(); |
|
874 |
} |
|
875 |
else |
|
876 |
{ |
|
877 |
__ASSERT_DEBUG(0, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
878 |
} |
|
879 |
} |
|
880 |
||
881 |
||
882 |
void DIicBusChannelSlave::StartTimerByState() |
|
883 |
{ |
|
884 |
if(iTimerState == DIicBusChannelSlave::EWaitForMaster) |
|
885 |
{ |
|
886 |
iTimeoutTimer.OneShot(NKern::TimerTicks(iMasterWaitTime),(*iClientTimeoutDfc)); |
|
887 |
} |
|
888 |
else if(iTimerState == DIicBusChannelSlave::EWaitForClient) |
|
889 |
{ |
|
890 |
iTimeoutTimer.OneShot(NKern::TimerTicks(iClientWaitTime),(*iClientTimeoutDfc)); |
|
891 |
} |
|
892 |
else |
|
893 |
{ |
|
894 |
__ASSERT_DEBUG(NULL, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
895 |
} |
|
896 |
} |
|
897 |
||
898 |
void DIicBusChannelSlave::StopTimer() |
|
899 |
{ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
900 |
// Silently cancel the timer and associated DFC |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
901 |
// |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
902 |
// NTimer::Cancel returns ETrue if cancelled, EFalse otherwise - which may mean it wasn't active |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
903 |
// TDfc::Cancel returns ETrue if actually de-queued, EFalse otherwise - which may mean it wasn't queued |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
904 |
// |
0 | 905 |
iTimeoutTimer.Cancel(); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
906 |
iClientTimeoutDfc->Cancel(); |
0 | 907 |
} |
908 |
||
909 |
TInt DIicBusChannelSlave::UpdateReqTrig(TInt8& aCbTrigVal, TInt& aCallbackRet) |
|
910 |
{ |
|
911 |
__KTRACE_OPT(KIIC, Kern::Printf("UpdateReqTrig")); |
|
912 |
||
913 |
TInt nextSteps = 0; |
|
914 |
iAccumTrig |= iNotif->iTrigger; // Update the accumulated event history, regardless of if the trigger was requested |
|
915 |
||
916 |
if(iNotif->iTrigger & EGeneralBusError) |
|
917 |
{ |
|
918 |
// In the event of a bus error, always cancel the timer and call the Client callback |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
919 |
StopTimer(); |
0 | 920 |
iTimerState = EInactive; |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
921 |
nextSteps = EInvokeCb; |
0 | 922 |
aCallbackRet = KErrGeneral; |
923 |
} |
|
924 |
else if(iNotif->iTrigger == EAsyncCaptChan) |
|
925 |
{ |
|
926 |
// For asynchronous channel capture, no timers are involved - just call the Client callback |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
927 |
nextSteps = EInvokeCb; |
0 | 928 |
aCallbackRet = KErrCompletion; |
929 |
} |
|
930 |
else if((iNotif->iTrigger & iReqTrig) != 0) |
|
931 |
{ |
|
932 |
// If a requested Rx event has occurred, clear all Rx flags from the requested triggers (similarly for Tx) |
|
933 |
if(iNotif->iTrigger & (ERxAllBytes | ERxUnderrun | ERxOverrun)) |
|
934 |
{ |
|
935 |
iReqTrig &= ~(ERxAllBytes | ERxUnderrun | ERxOverrun); |
|
936 |
} |
|
937 |
if(iNotif->iTrigger & (ETxAllBytes | ETxUnderrun | ETxOverrun)) |
|
938 |
{ |
|
939 |
iReqTrig &= ~(ETxAllBytes | ETxUnderrun | ETxOverrun); |
|
940 |
} |
|
941 |
||
942 |
if(iTimerState == EInactive) |
|
943 |
{ |
|
944 |
nextSteps |= (EStartTimer | EInvokeCb); |
|
945 |
// The next state in the state machine depends on if all the requested events have occurred |
|
946 |
if(iReqTrig == 0) |
|
947 |
{ |
|
948 |
// All triggers required have occurred, so transition to state EWaitForClient |
|
949 |
iTimerState = EWaitForClient; |
|
950 |
} |
|
951 |
else |
|
952 |
{ |
|
953 |
// The Client can request both Rx an Tx triggers; if only one has occurred, must wait for |
|
954 |
// the Master to generate the other |
|
955 |
iTimerState = EWaitForMaster; |
|
956 |
} |
|
957 |
aCallbackRet = KErrNone; |
|
958 |
} |
|
959 |
else if(iTimerState == EWaitForMaster) |
|
960 |
{ |
|
961 |
// The next state in the state machine depends on if all the requested events have occurred |
|
962 |
if(iReqTrig == 0) |
|
963 |
{ |
|
964 |
// All triggers required have occurred, so transition to state EWaitForClient |
|
965 |
iTimerState = EWaitForClient; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
966 |
StopTimer(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
967 |
nextSteps = (EInvokeCb | EStartTimer); |
0 | 968 |
} |
969 |
else |
|
970 |
{ |
|
971 |
// The Client can request both Rx an Tx triggers; if only one has occurred, must wait for |
|
972 |
// the Master to generate the other - so remain in this state, do not cancel the timer or |
|
973 |
// re-start it with a new timeout period. Still invoke the callback to notify the client |
|
974 |
// that at least one of the requested triggers has occurred. |
|
975 |
nextSteps |= EInvokeCb; |
|
976 |
} |
|
977 |
aCallbackRet = KErrNone; |
|
978 |
} |
|
979 |
else if((iTimerState == EWaitForClient) || (iTimerState == EClientTimeout)) |
|
980 |
{ |
|
981 |
// No triggers are expected in these states (iReqTrig==0). |
|
982 |
__ASSERT_DEBUG(NULL, Kern::Fault(KIicChannelPanic,__LINE__)); |
|
983 |
} |
|
984 |
} |
|
985 |
aCbTrigVal = iAccumTrig; |
|
986 |
return nextSteps; |
|
987 |
} |
|
988 |
||
989 |
||
990 |
void DIicBusChannelSlave::NotifyClient(TInt aTrigger) |
|
991 |
{ |
|
992 |
TIicBusSlaveCallback* notif = iNotif; |
|
993 |
notif->iTrigger = aTrigger; // Ensure ProcessData is provided with the trigger |
|
994 |
||
995 |
if(NKern::CurrentContext() == NKern::EThread && &(Kern::CurrentThread()) == iClient) |
|
996 |
{ |
|
997 |
// PSL will update notif to represent the events that have occurred |
|
998 |
ProcessData(aTrigger, notif); |
|
999 |
// Only invoke the client's callback (and update the state machine) if one of the requested triggers has |
|
1000 |
// occurred or if a bus error has been witnessed |
|
1001 |
TInt8 callbackTrig=0; |
|
1002 |
TInt callbackRet=0; |
|
1003 |
TInt nextSteps = UpdateReqTrig(callbackTrig, callbackRet); |
|
1004 |
if(nextSteps & EStopTimer) |
|
1005 |
{ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1006 |
__ASSERT_DEBUG(NULL, Kern::Fault(KIicChannelPanic,__LINE__)); |
0 | 1007 |
} |
1008 |
if(nextSteps & EInvokeCb) |
|
1009 |
{ |
|
1010 |
(notif->iCallback)(notif->iChannelId, (TInt)callbackRet, callbackTrig, notif->iRxWords, notif->iTxWords, notif->iParam); |
|
1011 |
// Callback now processed, so re-initialise callback object members |
|
1012 |
notif->iTrigger=0; |
|
1013 |
notif->iReturn=KErrNone; |
|
1014 |
notif->iRxWords=0; |
|
1015 |
notif->iTxWords=0; |
|
1016 |
iAccumTrig = 0; // and re-initialise the accumulated history as the transaction is considered terminated |
|
1017 |
} |
|
1018 |
if(nextSteps & EStartTimer) |
|
1019 |
{ |
|
1020 |
StartTimerByState(); |
|
1021 |
} |
|
1022 |
} |
|
1023 |
else if(NKern::CurrentContext() == NKern::EInterrupt) |
|
1024 |
notif->Add(); |
|
1025 |
else |
|
1026 |
notif->Enque(); |
|
1027 |
} |
|
1028 |
||
1029 |
TInt DIicBusChannelSlave::SetMasterWaitTime(TInt8 aWaitTime) |
|
1030 |
{ |
|
1031 |
if((aWaitTime<0)||(aWaitTime>KMaxWaitTime)) |
|
1032 |
return KErrArgument; |
|
1033 |
iMasterWaitTime=aWaitTime; |
|
1034 |
return KErrNone; |
|
1035 |
} |
|
1036 |
||
1037 |
TInt DIicBusChannelSlave::SetClientWaitTime(TInt8 aWaitTime) |
|
1038 |
{ |
|
1039 |
if((aWaitTime<0)||(aWaitTime>KMaxWaitTime)) |
|
1040 |
return KErrArgument; |
|
1041 |
iClientWaitTime=aWaitTime; |
|
1042 |
return KErrNone; |
|
1043 |
} |
|
1044 |
||
1045 |
void DIicBusChannelSlave::SendBusErrorAndReturn() |
|
1046 |
{ |
|
1047 |
DoRequest(EAbort); |
|
1048 |
} |
|
1049 |
||
1050 |
void DIicBusChannelSlave::SetChannelId(TInt& aChannelId) |
|
1051 |
{ |
|
1052 |
++iInstanceCount; |
|
1053 |
aChannelId = (iInstanceCount<<16); |
|
1054 |
// |
|
1055 |
// The PSL-specific channel identifier was stored in this generic class' member iChannelId at registration time |
|
1056 |
aChannelId |= iChannelId; |
|
1057 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::SetChannelId: iInstanceCount=0x%x, iChannelId=0x%x returned aChannelId=0x%x\n",iInstanceCount,iChannelId,aChannelId)); |
|
1058 |
iNotif->iChannelId=aChannelId; |
|
1059 |
} |
|
1060 |
||
1061 |
void DIicBusChannelSlave::CompleteAsynchCapture(TInt aResult) |
|
1062 |
{ |
|
1063 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::CompleteAsynchCapture aResult = %d",aResult)); |
|
1064 |
if(NKern::CurrentContext() == NKern::EThread && &Kern::CurrentThread() == iClient) |
|
1065 |
{ |
|
1066 |
iNotif->iCallback(iNotif->iChannelId, aResult, EAsyncCaptChan, NULL, NULL, iNotif->iParam); |
|
1067 |
return; |
|
1068 |
} |
|
1069 |
else |
|
1070 |
{ |
|
1071 |
iNotif->iReturn=aResult; |
|
1072 |
iNotif->iTrigger=EAsyncCaptChan; |
|
1073 |
iNotif->iTxWords=NULL; |
|
1074 |
iNotif->iRxWords=NULL; |
|
1075 |
} |
|
1076 |
if(NKern::CurrentContext() == NKern::EInterrupt) |
|
1077 |
iNotif->Add(); |
|
1078 |
else |
|
1079 |
iNotif->Enque(); |
|
1080 |
} |
|
1081 |
||
1082 |
TInt DIicBusChannelSlave::StaticExtension(TUint /*aFunction*/, TAny* /*aParam1*/, TAny* /*aParam*/) |
|
1083 |
{ |
|
1084 |
return KErrNotSupported; |
|
1085 |
} |
|
1086 |
||
1087 |
TInt DIicBusChannelSlave::Spare1(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/) |
|
1088 |
{ |
|
1089 |
return KErrNotSupported; |
|
1090 |
} |
|
1091 |
||
1092 |
TInt DIicBusChannelMasterSlave::QueueTransaction(TIicBusTransaction* aTransaction) |
|
1093 |
{ |
|
1094 |
return QueueTransaction(aTransaction,NULL); |
|
1095 |
}; |
|
1096 |
||
1097 |
TInt DIicBusChannelMasterSlave::QueueTransaction(TIicBusTransaction* aTransaction, TIicBusCallback* aCallback) |
|
1098 |
{ |
|
1099 |
TInt r=KErrNone; |
|
1100 |
iMasterChannel->Lock(); |
|
1101 |
if(iSlaveChannel->iChannelInUse) |
|
1102 |
r=KErrInUse; |
|
1103 |
else |
|
1104 |
{ |
|
1105 |
TInt16 count=(TInt16)((iMasterChannel->iTransCount)&~KTransCountMsBit); |
|
1106 |
if(count<~KTransCountMsBit) |
|
1107 |
{ |
|
1108 |
++count; |
|
1109 |
count|=KTransCountMsBit; |
|
1110 |
} |
|
1111 |
else |
|
1112 |
r=KErrInUse; |
|
1113 |
} |
|
1114 |
iMasterChannel->Unlock(); |
|
1115 |
if(r == KErrNone) |
|
1116 |
r=(iMasterChannel->QueueTransaction(aTransaction, aCallback)); |
|
1117 |
return r; |
|
1118 |
}; |
|
1119 |
||
1120 |
TInt DIicBusChannelMasterSlave::CaptureChannel(TDes8* aConfigHdr, TIicBusSlaveCallback* aCallback, TInt& aChannelId, TBool aAsynch) |
|
1121 |
{ |
|
1122 |
iMasterChannel->Lock(); |
|
1123 |
TInt r=KErrNone; |
|
1124 |
if(iSlaveChannel->iChannelInUse) |
|
1125 |
r=KErrInUse; |
|
1126 |
else |
|
1127 |
{ |
|
1128 |
if(iMasterChannel->IsMasterBusy()) |
|
1129 |
r=KErrInUse; |
|
1130 |
else |
|
1131 |
iSlaveChannel->iChannelInUse = 1; |
|
1132 |
} |
|
1133 |
iMasterChannel->Unlock(); |
|
1134 |
if(r == KErrNone) |
|
1135 |
r=iSlaveChannel->CaptureChannel(aConfigHdr, aCallback, aChannelId, aAsynch); |
|
1136 |
return r; |
|
1137 |
}; |
|
1138 |
||
1139 |
||
1140 |
TInt DIicBusChannelMasterSlave::ReleaseChannel() |
|
1141 |
{ |
|
1142 |
iMasterChannel->Lock(); |
|
1143 |
TInt r=iSlaveChannel->ReleaseChannel(); |
|
1144 |
iMasterChannel->Unlock(); |
|
1145 |
return r; |
|
1146 |
}; |
|
1147 |
||
1148 |
TInt DIicBusChannelMasterSlave::StaticExtension(TUint /*aFunction*/, TAny* /*aParam1*/, TAny* /*aParam*/) |
|
1149 |
{ |
|
1150 |
return KErrNotSupported; |
|
1151 |
} |
|
1152 |
||
1153 |
#ifdef STANDALONE_CHANNEL |
|
1154 |
EXPORT_C DIicBusChannelMasterSlave::DIicBusChannelMasterSlave(TBusType aBusType, TChannelDuplex aChanDuplex, DIicBusChannelMaster* aMasterChan, DIicBusChannelSlave* aSlaveChan) |
|
1155 |
: DIicBusChannel(DIicBusChannel::EMasterSlave, aBusType, aChanDuplex), |
|
1156 |
iMasterChannel(aMasterChan), |
|
1157 |
iSlaveChannel(aSlaveChan) |
|
1158 |
{ |
|
1159 |
//If in stand-alone channel mode, the client assigns a channel number to the MasterSlave channel it creates. |
|
1160 |
} |
|
1161 |
#endif |
|
1162 |