author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 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\drivers\iic.cpp |
|
15 |
// IIC Controller and public API Implementation |
|
16 |
// |
|
17 |
||
18 |
#include <drivers/iic.h> |
|
19 |
#include <drivers/iic_channel.h> |
|
20 |
#include "iic_priv.h" |
|
21 |
||
22 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
23 |
#include <drivers/iic_trace.h> |
|
24 |
#endif |
|
25 |
||
26 |
// Global Controller pointer |
|
27 |
static DIicBusController* TheController = NULL; |
|
28 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
29 |
#ifdef IIC_SIMULATED_PSL |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
30 |
DIicBusController*& gTheController = TheController; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
31 |
#endif |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
32 |
|
0 | 33 |
// |
34 |
// Implementation of generic IicBus API for client interface |
|
35 |
// |
|
36 |
EXPORT_C TInt IicBus::QueueTransaction(TInt aBusId, TIicBusTransaction* aTransaction) |
|
37 |
{ |
|
38 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
39 |
IIC_MQTRANSSYNC_START_PIL_TRACE; |
|
40 |
#endif |
|
41 |
TInt r=TheController->QueueTransaction(aBusId, aTransaction); |
|
42 |
||
43 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
44 |
IIC_MQTRANSSYNC_END_PIL_TRACE; |
|
45 |
#endif |
|
46 |
return r; |
|
47 |
} |
|
48 |
||
49 |
EXPORT_C TInt IicBus::QueueTransaction(TInt aBusId, TIicBusTransaction* aTransaction, TIicBusCallback* aCallback) |
|
50 |
{ |
|
51 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
52 |
IIC_MQTRANSASYNC_START_PIL_TRACE; |
|
53 |
#endif |
|
54 |
TInt r=TheController->QueueTransaction(aBusId, aTransaction, aCallback); |
|
55 |
||
56 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
57 |
IIC_MQTRANSASYNC_END_PIL_TRACE; |
|
58 |
#endif |
|
59 |
return r; |
|
60 |
} |
|
61 |
||
62 |
EXPORT_C TInt IicBus::CancelTransaction(TInt aBusId, TIicBusTransaction* aTransaction) |
|
63 |
{ |
|
64 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
65 |
IIC_MCANCELTRANS_START_PIL_TRACE; |
|
66 |
#endif |
|
67 |
TInt r=TheController->CancelTransaction(aBusId, aTransaction); |
|
68 |
||
69 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
70 |
IIC_MCANCELTRANS_END_PIL_TRACE; |
|
71 |
#endif |
|
72 |
return r; |
|
73 |
} |
|
74 |
||
75 |
EXPORT_C TInt IicBus::CaptureChannel(TInt aBusId, TDes8* aConfigHdr, TIicBusSlaveCallback* aCallback, TInt& aChannelId, TBool aAsynch) |
|
76 |
{ |
|
77 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
78 |
if(!aAsynch) |
|
79 |
{ |
|
80 |
IIC_SCAPTCHANSYNC_START_PIL_TRACE; |
|
81 |
} |
|
82 |
else |
|
83 |
{ |
|
84 |
IIC_SCAPTCHANASYNC_START_PIL_TRACE; |
|
85 |
} |
|
86 |
#endif |
|
87 |
TInt r=TheController->CaptureChannel(aBusId, aConfigHdr, aCallback, aChannelId, aAsynch); |
|
88 |
||
89 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
90 |
if(!aAsynch) |
|
91 |
{ |
|
92 |
IIC_SCAPTCHANSYNC_END_PIL_TRACE; |
|
93 |
} |
|
94 |
#endif |
|
95 |
return r; |
|
96 |
} |
|
97 |
||
98 |
EXPORT_C TInt IicBus::ReleaseChannel(TInt aChannelId) |
|
99 |
{ |
|
100 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
101 |
IIC_SRELCHAN_START_PIL_TRACE; |
|
102 |
#endif |
|
103 |
TInt r=TheController->ReleaseChannel(aChannelId); |
|
104 |
||
105 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
106 |
IIC_SRELCHAN_END_PIL_TRACE; |
|
107 |
#endif |
|
108 |
return r; |
|
109 |
} |
|
110 |
||
111 |
EXPORT_C TInt IicBus::RegisterRxBuffer(TInt aChannelId, TPtr8 aRxBuffer, TInt8 aBufGranularity, TInt8 aNumWords, TInt8 aOffset) |
|
112 |
{ |
|
113 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
114 |
IIC_SREGRXBUF_START_PIL_TRACE; |
|
115 |
#endif |
|
116 |
TInt r=TheController->RegisterRxBuffer(aChannelId, aRxBuffer, aBufGranularity, aNumWords, aOffset); |
|
117 |
||
118 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
119 |
IIC_SREGRXBUF_END_PIL_TRACE; |
|
120 |
#endif |
|
121 |
return r; |
|
122 |
} |
|
123 |
||
124 |
EXPORT_C TInt IicBus::RegisterTxBuffer(TInt aChannelId, TPtr8 aTxBuffer, TInt8 aBufGranularity, TInt8 aNumWords, TInt8 aOffset) |
|
125 |
{ |
|
126 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
127 |
IIC_SREGTXBUF_START_PIL_TRACE; |
|
128 |
#endif |
|
129 |
TInt r=TheController->RegisterTxBuffer(aChannelId, aTxBuffer, aBufGranularity, aNumWords, aOffset); |
|
130 |
||
131 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
132 |
IIC_SREGTXBUF_END_PIL_TRACE; |
|
133 |
#endif |
|
134 |
return r; |
|
135 |
} |
|
136 |
||
137 |
EXPORT_C TInt IicBus::SetNotificationTrigger(TInt aChannelId, TInt aTrigger) |
|
138 |
{ |
|
139 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
140 |
IIC_SNOTIFTRIG_START_PIL_TRACE; |
|
141 |
#endif |
|
142 |
TInt r=TheController->SetNotificationTrigger(aChannelId, aTrigger); |
|
143 |
||
144 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
145 |
IIC_SNOTIFTRIG_END_PIL_TRACE; |
|
146 |
#endif |
|
147 |
return r; |
|
148 |
} |
|
149 |
||
150 |
EXPORT_C TInt IicBus::StaticExtension(TUint aId, TUint aFunction, TAny* aParam1, TAny* aParam2) |
|
151 |
{ |
|
152 |
return(TheController->StaticExtension(aId, aFunction, aParam1, aParam2)); |
|
153 |
} |
|
154 |
||
155 |
||
156 |
// |
|
157 |
// Bus Controller |
|
158 |
// |
|
159 |
||
160 |
// auxiliary function for ordering entries in the array of channels |
|
161 |
TInt DIicBusController::OrderEntries(const DIicBusChannel& aMatch, const DIicBusChannel& aEntry) |
|
162 |
{ |
|
163 |
TUint8 l=(TUint8)aMatch.ChannelNumber(); |
|
164 |
TUint8 r=(TUint8)aEntry.ChannelNumber(); |
|
165 |
if(l>r) |
|
166 |
return -1; |
|
167 |
else if(l<r) |
|
168 |
return 1; |
|
169 |
else |
|
170 |
return 0; |
|
171 |
} |
|
172 |
||
173 |
// global ordering object to be passed to RPointerArray InsertInOrderXXX and FindInOrder |
|
174 |
TLinearOrder<DIicBusChannel> EntryOrder(DIicBusController::OrderEntries); |
|
175 |
||
176 |
// Implementation for DIicBusController |
|
177 |
// |
|
178 |
||
179 |
TInt DIicBusController::Create() |
|
180 |
{ |
|
181 |
TInt r=KErrNone; |
|
182 |
iChanLock = new TSpinLock(TSpinLock::EOrderGenericIrqLow2); // Semi-arbitrary, low priority value |
|
183 |
iCaptLock = new TSpinLock(TSpinLock::EOrderGenericIrqLow2); // Semi-arbitrary, low priority value |
|
184 |
if((iChanLock == NULL)||(iCaptLock == NULL)) |
|
185 |
{ |
|
186 |
delete iChanLock; |
|
187 |
delete iCaptLock; |
|
188 |
r=KErrNoMemory; |
|
189 |
} |
|
190 |
return r; |
|
191 |
} |
|
192 |
||
193 |
DIicBusController::~DIicBusController() |
|
194 |
{ |
|
195 |
#ifdef IIC_SIMULATED_PSL |
|
196 |
for(TInt i=0; i<iChannelArray.Count(); i++) |
|
197 |
{ |
|
198 |
DIicBusChannel* ptr=iChannelArray[i]; |
|
199 |
// Remove the channel from the array |
|
200 |
iChannelArray.Remove(i); |
|
201 |
// Delete the channel object |
|
202 |
delete ptr; |
|
203 |
}; |
|
204 |
||
205 |
iChannelArray.Reset(); |
|
206 |
delete iChanLock; |
|
207 |
delete iCaptLock; |
|
208 |
#endif |
|
209 |
} |
|
210 |
||
211 |
TInt DIicBusController::GetChanWriteAccess() |
|
212 |
{ |
|
213 |
// Can only have one insertion or removal active at any one time |
|
214 |
// Can not perform an insertion or removal while a read is in progress |
|
215 |
// If either of the two above conditions exist, return KErrInUse |
|
216 |
// Otherwise, set the flag to indicate that a write is in progress |
|
217 |
// and return KErrNone. |
|
218 |
TInt chanIntState=0; |
|
219 |
chanIntState=__SPIN_LOCK_IRQSAVE(*iChanLock); |
|
220 |
if(iChanRwFlags != 0) |
|
221 |
{ |
|
222 |
__SPIN_UNLOCK_IRQRESTORE(*iChanLock,chanIntState); |
|
223 |
return KErrInUse; |
|
224 |
} |
|
225 |
iChanRwFlags |= EWriteInProgress; |
|
226 |
__SPIN_UNLOCK_IRQRESTORE(*iChanLock,chanIntState); |
|
227 |
return KErrNone; |
|
228 |
} |
|
229 |
||
230 |
void DIicBusController::FreeChanWriteAccess() |
|
231 |
{ |
|
232 |
// If an insertion or removal is in progress, no other modifying operation |
|
233 |
// can be active. Reads are also not permitted - so iChanRwFlags can only be |
|
234 |
// EWriteInProgress. |
|
235 |
__ASSERT_DEBUG(iChanRwFlags == EWriteInProgress, Kern::Fault(KIicPanic,__LINE__)); |
|
236 |
TInt chanIntState=0; |
|
237 |
chanIntState=__SPIN_LOCK_IRQSAVE(*iChanLock); |
|
238 |
iChanRwFlags &= ~EWriteInProgress; |
|
239 |
__SPIN_UNLOCK_IRQRESTORE(*iChanLock,chanIntState); |
|
240 |
} |
|
241 |
||
242 |
TInt DIicBusController::GetChanReadAccess() |
|
243 |
{ |
|
244 |
// No reads are permitted while an insertion or removal is in progress |
|
245 |
// If one of the above operations is in progress return KErrInUse |
|
246 |
// Can have several concurrent reads at any one time - so increment |
|
247 |
// the count of such operations as well as ensuring the flag is set to indicate |
|
248 |
// a read is in progress |
|
249 |
TInt chanIntState=0; |
|
250 |
chanIntState=__SPIN_LOCK_IRQSAVE(*iChanLock); |
|
251 |
if(iChanRwFlags == EWriteInProgress) |
|
252 |
{ |
|
253 |
__SPIN_UNLOCK_IRQRESTORE(*iChanLock,chanIntState); |
|
254 |
return KErrInUse; |
|
255 |
} |
|
256 |
__ASSERT_DEBUG(iChanRdCount!=0xFFFFFFFF, Kern::Fault(KIicPanic,__LINE__)); // Overflow |
|
257 |
iChanRdCount++; |
|
258 |
iChanRwFlags |= EReadInProgress; |
|
259 |
__SPIN_UNLOCK_IRQRESTORE(*iChanLock,chanIntState); |
|
260 |
return KErrNone; |
|
261 |
} |
|
262 |
||
263 |
void DIicBusController::FreeChanReadAccess() |
|
264 |
{ |
|
265 |
// No insertions or removals are permitted while a read is in progress |
|
266 |
// so iChanRwFlags can only be EReadInProgress |
|
267 |
// Multiple reads can be in progress concurrently, so the count must be decremented |
|
268 |
TInt chanIntState=0; |
|
269 |
chanIntState=__SPIN_LOCK_IRQSAVE(*iChanLock); |
|
270 |
__ASSERT_DEBUG(iChanRwFlags == EReadInProgress, Kern::Fault(KIicPanic,__LINE__)); |
|
271 |
__ASSERT_DEBUG(iChanRdCount>0, Kern::Fault(KIicPanic,__LINE__)); |
|
272 |
iChanRdCount--; |
|
273 |
if(iChanRdCount == 0) |
|
274 |
iChanRwFlags &= ~EReadInProgress; |
|
275 |
__SPIN_UNLOCK_IRQRESTORE(*iChanLock,chanIntState); |
|
276 |
} |
|
277 |
||
278 |
TInt DIicBusController::RequestTypeSupported(const TInt aBusId, DIicBusChannelMaster* const aChannel) |
|
279 |
{ |
|
280 |
TInt32 reqBusType; |
|
281 |
reqBusType = GET_BUS_TYPE(aBusId); |
|
282 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::RequestTypeSupported, BusType=0x%x\n", reqBusType)); |
|
283 |
||
284 |
if(reqBusType != aChannel->BusType()) |
|
285 |
{ |
|
286 |
return KErrNotSupported; |
|
287 |
} |
|
288 |
||
289 |
return KErrNone; |
|
290 |
} |
|
291 |
||
292 |
||
293 |
EXPORT_C TInt DIicBusController::RegisterChannels(DIicBusChannel** aListChannels, TInt aNumberChannels) |
|
294 |
{ |
|
295 |
// To be used by Channel implementations to register a list of supported channels |
|
296 |
__KTRACE_OPT(KIIC, Kern::Printf("\nDIicBusController::RegisterChannels, aListChannels=0x%x, aNumberChannels=%d\n",aListChannels,aNumberChannels)); |
|
297 |
__ASSERT_DEBUG(aListChannels!=NULL, Kern::Fault(KIicPanic,__LINE__)); |
|
298 |
||
299 |
RPointerArray<DIicBusChannel>* chanArray = TheController->ChannelArray(); |
|
300 |
||
301 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
302 |
IIC_REGISTERCHANS_START_PIL_TRACE; |
|
303 |
#endif |
|
304 |
// Get access to the channel pointer array - exit if it is currently being modfied |
|
305 |
TInt r=KErrNone; |
|
306 |
if((r=TheController->GetChanWriteAccess()) == KErrNone) |
|
307 |
{ |
|
308 |
#ifdef _DEBUG |
|
309 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::RegisterChannels - On entry, iChannelArray ...\n")); |
|
310 |
TheController->DumpChannelArray(); |
|
311 |
#endif |
|
312 |
// Loop for aNumberChannels and write directly to the channel array |
|
313 |
DIicBusChannel** chanIterator = aListChannels; |
|
314 |
for(TInt iteration = 0; iteration < aNumberChannels; ++iteration, ++chanIterator) |
|
315 |
{ |
|
316 |
DIicBusChannel* chanPtr = *chanIterator; |
|
317 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::RegisterChannels - adding channel number %d\n",chanPtr->ChannelNumber())); |
|
318 |
TInt r = chanArray->InsertInOrder(chanPtr,EntryOrder); |
|
319 |
if(r!=KErrNone) |
|
320 |
break; |
|
321 |
} |
|
322 |
||
323 |
#ifdef _DEBUG |
|
324 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::RegisterChannels - On exit, iChannelArray ...\n")); |
|
325 |
TheController->DumpChannelArray(); |
|
326 |
#endif |
|
327 |
TheController->FreeChanWriteAccess(); |
|
328 |
} |
|
329 |
else |
|
330 |
{ |
|
331 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::GetChanWriteAccess returned %d\n",r)); |
|
332 |
} |
|
333 |
||
334 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
335 |
IIC_REGISTERCHANS_END_PIL_TRACE; |
|
336 |
#endif |
|
337 |
return r; |
|
338 |
} |
|
339 |
||
340 |
||
341 |
EXPORT_C TInt DIicBusController::DeRegisterChannel(DIicBusChannel* aChannel) |
|
342 |
{ |
|
343 |
// To be used by Channel implementations to deregister a channel |
|
344 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::DeRegisterChannel, aChannel=0x%x\n",aChannel)); |
|
345 |
if(aChannel == NULL) |
|
346 |
return KErrArgument; |
|
347 |
||
348 |
RPointerArray<DIicBusChannel>* chanArray = TheController->ChannelArray(); |
|
349 |
||
350 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
351 |
IIC_DEREGISTERCHAN_START_PIL_TRACE; |
|
352 |
#endif |
|
353 |
TInt r=KErrNone; |
|
354 |
// Get access to the channel pointer array - exit if it is currently unavailable |
|
355 |
// Gaining write access will prevent a client of a Master Channel from instigating a new QueueTransaction |
|
356 |
// (or CancelTransaction), and it will obstruct a client of a Slave Channel in CaptureChannel. |
|
357 |
if((r=TheController->GetChanWriteAccess())!=KErrNone) |
|
358 |
return r; |
|
359 |
||
360 |
// Check channel is registered |
|
361 |
TInt chanIndex = chanArray->FindInOrder(aChannel,EntryOrder); |
|
362 |
if(chanIndex<0) |
|
363 |
{ |
|
364 |
TheController->FreeChanWriteAccess(); |
|
365 |
return KErrNotFound; |
|
366 |
} |
|
367 |
||
368 |
#ifdef _DEBUG |
|
369 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::DeRegisterChannel - On entry, iChannelArray ...\n")); |
|
370 |
TheController->DumpChannelArray(); |
|
371 |
#endif |
|
372 |
||
373 |
// Remove the channel from the array |
|
374 |
// Note that this does not delete the channel object |
|
375 |
chanArray->Remove(chanIndex); |
|
376 |
||
377 |
#ifdef _DEBUG |
|
378 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::DeRegisterChannel - On exit, iChannelArray ...\n")); |
|
379 |
TheController->DumpChannelArray(); |
|
380 |
#endif |
|
381 |
TheController->FreeChanWriteAccess(); |
|
382 |
||
383 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
384 |
IIC_DEREGISTERCHAN_END_PIL_TRACE; |
|
385 |
#endif |
|
386 |
return KErrNone; |
|
387 |
} |
|
388 |
||
389 |
TInt DIicBusController::FindCapturedChanById(TCapturedChannel aCapturedChan, TInt& aIndex) |
|
390 |
{ |
|
391 |
TInt index=0; |
|
392 |
TInt r=KErrNotFound; |
|
393 |
do |
|
394 |
{ |
|
395 |
if(iCapturedChannels[index].iChannelId == aCapturedChan.iChannelId) |
|
396 |
{ |
|
397 |
aIndex=index; |
|
398 |
r=KErrNone; |
|
399 |
} |
|
400 |
index++; |
|
401 |
} while ((index < KMaxNumCapturedChannels)&&(r == KErrNotFound)); |
|
402 |
return r; |
|
403 |
} |
|
404 |
||
405 |
TInt DIicBusController::FindCapturedChan(TCapturedChannel aCapturedChan, TInt& aIndex) |
|
406 |
{ |
|
407 |
TInt index=0; |
|
408 |
TInt r=KErrNotFound; |
|
409 |
do |
|
410 |
{ |
|
411 |
if(iCapturedChannels[index] == aCapturedChan) |
|
412 |
{ |
|
413 |
aIndex=index; |
|
414 |
r=KErrNone; |
|
415 |
} |
|
416 |
index++; |
|
417 |
} while ((index < KMaxNumCapturedChannels)&&(r == KErrNotFound)); |
|
418 |
return r; |
|
419 |
} |
|
420 |
||
421 |
TInt DIicBusController::InsertCaptChanInArray(TCapturedChannel aCapturedChan) |
|
422 |
{ |
|
423 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::InsertCaptChanInArray \n")); |
|
424 |
// Ensure the channel hasn't already been inserted in the array |
|
425 |
// If found, fault the Kernel |
|
426 |
TInt dumInt = 0; |
|
427 |
TInt r=FindCapturedChan(aCapturedChan,dumInt); |
|
428 |
__ASSERT_DEBUG(r!=KErrNone, Kern::Fault(KIicPanic,__LINE__)); |
|
429 |
||
430 |
// Loop the array and insert in the first available slot |
|
431 |
// If no slots are available return KErrNotReady |
|
432 |
TInt index=0; |
|
433 |
TCapturedChannel emptyChan; |
|
434 |
for(;index<KMaxNumCapturedChannels;++index) |
|
435 |
{ |
|
436 |
if(iCapturedChannels[index] == emptyChan) |
|
437 |
{ |
|
438 |
// Found a space |
|
439 |
iCapturedChannels[index]=aCapturedChan; |
|
440 |
break; |
|
441 |
} |
|
442 |
} |
|
443 |
if(index>=KMaxNumCapturedChannels) |
|
444 |
r = KErrNotReady; |
|
445 |
return r; |
|
446 |
} |
|
447 |
||
448 |
TInt DIicBusController::RemoveCaptChanFromArray(TCapturedChannel aCapturedChan) |
|
449 |
{ |
|
450 |
// Remove the entry from the array |
|
451 |
// If the entry is not present return KErrArgument |
|
452 |
TInt index=-1; |
|
453 |
TInt r=FindCapturedChan(aCapturedChan,index); |
|
454 |
if((r!=KErrNone)||(index>=KMaxNumCapturedChannels)) |
|
455 |
return KErrArgument; |
|
456 |
iCapturedChannels[index].iChanPtr=NULL; |
|
457 |
iCapturedChannels[index].iChannelId=0; |
|
458 |
return KErrNone; |
|
459 |
} |
|
460 |
||
461 |
||
462 |
TInt DIicBusController::InstallCapturedChannel(const TInt aChannelId, const DIicBusChannelSlave* aChanPtr) |
|
463 |
{ |
|
464 |
#ifdef _DEBUG |
|
465 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::InstallCapturedChannel - On entry, iCapturedChannels ...\n")); |
|
466 |
DumpCapturedChannels(); |
|
467 |
#endif |
|
468 |
TInt r=KErrNone; |
|
469 |
TCapturedChannel capturedChan((TInt)aChannelId,(DIicBusChannelSlave*)aChanPtr); |
|
470 |
// Because insertions are bounded by the size of the array and do not involve allocating |
|
471 |
// or freeing memory, simply take the spinlock at the start of the operation and release at the end |
|
472 |
TInt captIntState=__SPIN_LOCK_IRQSAVE(*iCaptLock); |
|
473 |
r=InsertCaptChanInArray(capturedChan); |
|
474 |
__SPIN_UNLOCK_IRQRESTORE(*iCaptLock,captIntState); |
|
475 |
if(r!=KErrNone) |
|
476 |
return r; |
|
477 |
||
478 |
#ifdef _DEBUG |
|
479 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::InstallCapturedChannel - On exit, iCapturedChannels ...\n")); |
|
480 |
DumpCapturedChannels(); |
|
481 |
#endif |
|
482 |
return KErrNone; |
|
483 |
} |
|
484 |
||
485 |
TInt DIicBusController::DeInstallCapturedChannel(const TInt aChannelId, const DIicBusChannelSlave* aChanPtr) |
|
486 |
{ |
|
487 |
#ifdef _DEBUG |
|
488 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::DeInstallCapturedChannel - On entry, iCapturedChannels ...\n")); |
|
489 |
DumpCapturedChannels(); |
|
490 |
#endif |
|
491 |
TInt r = KErrNone; |
|
492 |
TCapturedChannel capturedChan((TInt) aChannelId, (DIicBusChannelSlave*) aChanPtr); |
|
493 |
// Because removals are bounded by the size of the array and do not involve allocating |
|
494 |
// or freeing memory, simply take the spinlock at the start of the operation and release at the end |
|
495 |
TInt captIntState = __SPIN_LOCK_IRQSAVE(*iCaptLock); |
|
496 |
r = RemoveCaptChanFromArray(capturedChan); |
|
497 |
__SPIN_UNLOCK_IRQRESTORE(*iCaptLock, captIntState); |
|
498 |
if(r != KErrNone) |
|
499 |
return r; |
|
500 |
||
501 |
#ifdef _DEBUG |
|
502 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::DeInstallCapturedChannel - On exit, iCapturedChannels ...\n")); |
|
503 |
DumpCapturedChannels(); |
|
504 |
#endif |
|
505 |
return KErrNone; |
|
506 |
} |
|
507 |
||
508 |
// Master-side API |
|
509 |
TInt DIicBusController::QueueTransaction(TInt aBusId, TIicBusTransaction* aTransaction) |
|
510 |
{ |
|
511 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::QueueTransaction, aBusId=0x%x,aTransaction=0x%x\n", aBusId, aTransaction)); |
|
512 |
if(!aTransaction) |
|
513 |
{ |
|
514 |
return KErrArgument; |
|
515 |
} |
|
516 |
||
517 |
// Get a pointer to the channel |
|
518 |
TInt dumInt = 0; |
|
519 |
DIicBusChannel* chanPtr = NULL; |
|
520 |
// Can only read the channel array if it is not currently being modified |
|
521 |
TInt r = GetChanReadAccess(); |
|
522 |
if(r != KErrNone) |
|
523 |
{ |
|
524 |
return r; |
|
525 |
} |
|
526 |
r = GetChanPtr(aBusId, dumInt, chanPtr); |
|
527 |
if(r == KErrNone) |
|
528 |
{ |
|
529 |
if(!chanPtr) |
|
530 |
{ |
|
531 |
r = KErrArgument; |
|
532 |
} |
|
533 |
else |
|
534 |
{ |
|
535 |
switch(chanPtr->ChannelType()) |
|
536 |
{ |
|
537 |
// QueueTransaction requests are only supported by channels in Master mode. |
|
538 |
case DIicBusChannel::ESlave: |
|
539 |
{ |
|
540 |
r = KErrNotSupported; |
|
541 |
break; |
|
542 |
} |
|
543 |
// If the request is supported by the Master channel, send it to the channel for processing in its thread |
|
544 |
case DIicBusChannel::EMasterSlave: |
|
545 |
{ |
|
546 |
r = RequestTypeSupported(aBusId, ((DIicBusChannelMasterSlave*)chanPtr)->iMasterChannel); |
|
547 |
if(r == KErrNone) |
|
548 |
{ |
|
549 |
aTransaction->iBusId = aBusId; |
|
550 |
r = (((DIicBusChannelMasterSlave*) chanPtr)->QueueTransaction(aTransaction)); |
|
551 |
} |
|
552 |
break; |
|
553 |
} |
|
554 |
case DIicBusChannel::EMaster: |
|
555 |
{ |
|
556 |
r = RequestTypeSupported(aBusId, (DIicBusChannelMaster*)chanPtr); |
|
557 |
if(r == KErrNone) |
|
558 |
{ |
|
559 |
aTransaction->iBusId = aBusId; |
|
560 |
r = (((DIicBusChannelMaster*) chanPtr)->QueueTransaction(aTransaction)); |
|
561 |
} |
|
562 |
break; |
|
563 |
} |
|
564 |
default: |
|
565 |
{ |
|
566 |
r = KErrGeneral; |
|
567 |
} |
|
568 |
} |
|
569 |
} |
|
570 |
} |
|
571 |
FreeChanReadAccess(); |
|
572 |
return r; |
|
573 |
} |
|
574 |
||
575 |
TInt DIicBusController::QueueTransaction(TInt aBusId, TIicBusTransaction* aTransaction, TIicBusCallback* aCallback) |
|
576 |
{ |
|
577 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::QueueTransaction, aBusId=0x%x,aTransaction=0x%x,aCallback=0x%x\n",aBusId,aTransaction,aCallback)); |
|
578 |
if(!aTransaction || !aCallback) |
|
579 |
{ |
|
580 |
return KErrArgument; |
|
581 |
} |
|
582 |
||
583 |
// Get a pointer to the channel |
|
584 |
TInt dumInt = 0; |
|
585 |
DIicBusChannel* chanPtr = NULL; |
|
586 |
// Can only read the channel array if it is not currently being modified |
|
587 |
TInt r = GetChanReadAccess(); |
|
588 |
if(r == KErrNone) |
|
589 |
{ |
|
590 |
r = GetChanPtr(aBusId, dumInt, chanPtr); |
|
591 |
if(r == KErrNone) |
|
592 |
{ |
|
593 |
if(!chanPtr) |
|
594 |
{ |
|
595 |
r = KErrArgument; |
|
596 |
} |
|
597 |
else |
|
598 |
{ |
|
599 |
switch(chanPtr->ChannelType()) |
|
600 |
{ |
|
601 |
// QueueTransaction requests are only supported by channels in Master mode. |
|
602 |
case DIicBusChannel::ESlave: |
|
603 |
{ |
|
604 |
r = KErrNotSupported; |
|
605 |
break; |
|
606 |
} |
|
607 |
// If the request is supported by the Master channel, send it to the channel for processing in its thread |
|
608 |
case DIicBusChannel::EMasterSlave: |
|
609 |
{ |
|
610 |
r = RequestTypeSupported(aBusId, ((DIicBusChannelMasterSlave*)chanPtr)->iMasterChannel); |
|
611 |
if(r == KErrNone) |
|
612 |
{ |
|
613 |
aTransaction->iBusId = aBusId; |
|
614 |
r = (((DIicBusChannelMasterSlave*) chanPtr)->QueueTransaction(aTransaction, aCallback)); |
|
615 |
} |
|
616 |
break; |
|
617 |
} |
|
618 |
case DIicBusChannel::EMaster: |
|
619 |
{ |
|
620 |
r = RequestTypeSupported(aBusId, (DIicBusChannelMaster*)chanPtr); |
|
621 |
if(r == KErrNone) |
|
622 |
{ |
|
623 |
aTransaction->iBusId = aBusId; |
|
624 |
r = (((DIicBusChannelMaster*) chanPtr)->QueueTransaction(aTransaction, aCallback)); |
|
625 |
} |
|
626 |
break; |
|
627 |
} |
|
628 |
default: |
|
629 |
{ |
|
630 |
r = KErrGeneral; |
|
631 |
} |
|
632 |
} |
|
633 |
} |
|
634 |
} |
|
635 |
} |
|
636 |
FreeChanReadAccess(); |
|
637 |
return r; |
|
638 |
} |
|
639 |
||
640 |
||
641 |
TInt DIicBusController::GetChanPtr(const TInt aBusId, TInt &aIndex, DIicBusChannel*& aChan) |
|
642 |
{ |
|
643 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::GetChanPtr, aBusId=0x%x\n",aBusId)); |
|
644 |
||
645 |
TInt32 chanId; |
|
646 |
chanId = GET_CHAN_NUM(aBusId); |
|
647 |
||
648 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::GetChanPtr, chanId=0x%x\n", chanId)); |
|
649 |
DIicBusChannelSearcher searchChannel(DIicBusChannel::EMasterSlave, DIicBusChannel::ESccb, DIicBusChannel::EFullDuplex); |
|
650 |
searchChannel.SetChannelNumber((TInt8)chanId); |
|
651 |
||
652 |
TInt r = KErrNotFound; |
|
653 |
aIndex = iChannelArray.FindInOrder(&searchChannel, EntryOrder); |
|
654 |
if(aIndex >= 0) |
|
655 |
{ |
|
656 |
aChan = iChannelArray[aIndex]; |
|
657 |
r = KErrNone; |
|
658 |
} |
|
659 |
||
660 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::GetChanPtr, chanPtr=0x%x, index=%d\n", aChan, aIndex)); |
|
661 |
return r; |
|
662 |
} |
|
663 |
||
664 |
||
665 |
TInt DIicBusController::CancelTransaction(TInt aBusId, TIicBusTransaction* aTransaction) |
|
666 |
{ |
|
667 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::CancelTransaction, aBusId=0x%x,aTransaction=0x%x\n", aBusId, aTransaction)); |
|
668 |
if(!aTransaction) |
|
669 |
{ |
|
670 |
return KErrArgument; |
|
671 |
} |
|
672 |
||
673 |
// Get the channel |
|
674 |
TInt dumInt = 0; |
|
675 |
DIicBusChannel* chanPtr = NULL; |
|
676 |
||
677 |
// Can only read the channel array if it is not currently being modified |
|
678 |
TInt r = GetChanReadAccess(); |
|
679 |
if(r == KErrNone) |
|
680 |
{ |
|
681 |
r = GetChanPtr(aBusId, dumInt, chanPtr); |
|
682 |
if(r == KErrNone) |
|
683 |
{ |
|
684 |
if(!chanPtr) |
|
685 |
{ |
|
686 |
r = KErrArgument; |
|
687 |
} |
|
688 |
else |
|
689 |
{ |
|
690 |
// QueueTransaction requests are only supported by channels in Master mode. |
|
691 |
switch(chanPtr->ChannelType()) |
|
692 |
{ |
|
693 |
case DIicBusChannel::ESlave: |
|
694 |
{ |
|
695 |
r = KErrNotSupported; |
|
696 |
break; |
|
697 |
} |
|
698 |
case DIicBusChannel::EMasterSlave: |
|
699 |
{ |
|
700 |
r = RequestTypeSupported(aBusId, ((DIicBusChannelMasterSlave*)chanPtr)->iMasterChannel); |
|
701 |
if(r == KErrNone) |
|
702 |
{ |
|
703 |
r = (((DIicBusChannelMasterSlave*) chanPtr)->CancelTransaction(aTransaction)); |
|
704 |
} |
|
705 |
break; |
|
706 |
} |
|
707 |
case DIicBusChannel::EMaster: |
|
708 |
{ |
|
709 |
r = RequestTypeSupported(aBusId, (DIicBusChannelMaster*)chanPtr); |
|
710 |
if(r == KErrNone) |
|
711 |
{ |
|
712 |
r = (((DIicBusChannelMaster*) chanPtr)->CancelTransaction(aTransaction)); |
|
713 |
} |
|
714 |
break; |
|
715 |
} |
|
716 |
default: |
|
717 |
{ |
|
718 |
r = KErrGeneral; |
|
719 |
} |
|
720 |
} |
|
721 |
} |
|
722 |
} |
|
723 |
} |
|
724 |
FreeChanReadAccess(); |
|
725 |
return r; |
|
726 |
} |
|
727 |
||
728 |
// Slave-side API |
|
729 |
TInt DIicBusController::CaptureChannel(TInt aBusId, TDes8* aConfigHdr, TIicBusSlaveCallback* aCallback, TInt& aChannelId, TBool aAsynch) |
|
730 |
{ |
|
731 |
// Check that that aCallback!=NULL and aConfigHdr!=NULL - if not, return KErrArgument |
|
732 |
if(!aCallback || !aConfigHdr) |
|
733 |
{ |
|
734 |
return KErrArgument; |
|
735 |
} |
|
736 |
||
737 |
// Get the channel |
|
738 |
TInt chanIndex = 0; |
|
739 |
DIicBusChannel* chanPtr = NULL; |
|
740 |
||
741 |
// Can only read the channel array if it is not currently being modified |
|
742 |
TInt r = GetChanReadAccess(); |
|
743 |
if(r == KErrNone) |
|
744 |
{ |
|
745 |
r = GetChanPtr(aBusId, chanIndex, chanPtr); |
|
746 |
if(r == KErrNone) |
|
747 |
{ |
|
748 |
if(!chanPtr) |
|
749 |
{ |
|
750 |
r = KErrArgument; |
|
751 |
} |
|
752 |
else |
|
753 |
{ |
|
754 |
DIicBusChannelSlave* slaveChanPtr = NULL; |
|
755 |
switch(chanPtr->ChannelType()) |
|
756 |
{ |
|
757 |
// CaptureChannel requests are only supported by channels in Slave mode. |
|
758 |
case DIicBusChannel::EMaster: |
|
759 |
{ |
|
760 |
r = KErrNotSupported; |
|
761 |
break; |
|
762 |
} |
|
763 |
case DIicBusChannel::EMasterSlave: |
|
764 |
{ |
|
765 |
slaveChanPtr = ((DIicBusChannelMasterSlave*) chanPtr)->iSlaveChannel; |
|
766 |
__ASSERT_DEBUG(slaveChanPtr!=NULL, Kern::Fault(KIicPanic,__LINE__)); // MasterSlave channel should have a valid Slave channel |
|
767 |
// Send the request to the channel |
|
768 |
slaveChanPtr->iController = this; |
|
769 |
r = ((DIicBusChannelMasterSlave*) chanPtr)->CaptureChannel(aConfigHdr, aCallback, aChannelId, aAsynch); |
|
770 |
break; |
|
771 |
} |
|
772 |
case DIicBusChannel::ESlave: |
|
773 |
{ |
|
774 |
slaveChanPtr = (DIicBusChannelSlave*) chanPtr; // chanPtr is non-NULL |
|
775 |
// Send the request to the channel |
|
776 |
slaveChanPtr->iController = this; |
|
777 |
r = (slaveChanPtr->CaptureChannel(aConfigHdr, aCallback, aChannelId, aAsynch)); |
|
778 |
break; |
|
779 |
} |
|
780 |
default: |
|
781 |
{ |
|
782 |
r = KErrArgument; |
|
783 |
} |
|
784 |
} |
|
785 |
// For synchronous capture, if successful then install the channel |
|
786 |
if(r == KErrNone && slaveChanPtr) |
|
787 |
{ |
|
788 |
if(!aAsynch) |
|
789 |
{ |
|
790 |
InstallCapturedChannel(aChannelId, slaveChanPtr); |
|
791 |
} |
|
792 |
} |
|
793 |
} |
|
794 |
} |
|
795 |
} |
|
796 |
FreeChanReadAccess(); |
|
797 |
return r; |
|
798 |
} |
|
799 |
||
800 |
||
801 |
TInt DIicBusController::GetSlaveChanPtr(TInt aChannelId, DIicBusChannelSlave*& aSlaveChanPtr) |
|
802 |
{ |
|
803 |
TInt r=KErrNone; |
|
804 |
// Check that the channelID is recognised |
|
805 |
TCapturedChannel capturedChan(aChannelId,NULL); |
|
806 |
TInt chanIndex=-1; |
|
807 |
// Ensure the array of captured channels will not be modified before it has been searched |
|
808 |
// Because searches are bounded by the size of the array and do not involve allocating |
|
809 |
// or freeing memory, simply take the spinlock at the start of the operation and release at the end |
|
810 |
TInt captIntState=__SPIN_LOCK_IRQSAVE(*iCaptLock); |
|
811 |
r=FindCapturedChanById(capturedChan, chanIndex); |
|
812 |
if((chanIndex < 0)||(r == KErrNotFound)) |
|
813 |
r=KErrArgument; |
|
814 |
else |
|
815 |
aSlaveChanPtr = (DIicBusChannelSlave*)(iCapturedChannels[chanIndex].iChanPtr); |
|
816 |
__SPIN_UNLOCK_IRQRESTORE(*iCaptLock,captIntState); |
|
817 |
||
818 |
__ASSERT_DEBUG(aSlaveChanPtr!=NULL, Kern::Fault(KIicPanic,__LINE__)); |
|
819 |
return r; |
|
820 |
} |
|
821 |
||
822 |
||
823 |
TInt DIicBusController::ReleaseChannel(TInt aChannelId) |
|
824 |
{ |
|
825 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::ReleaseChannel, channelID = 0x%x \n",aChannelId)); |
|
826 |
TInt r = KErrNone; |
|
827 |
DIicBusChannel* chanPtr = NULL; |
|
828 |
||
829 |
// Get the pointer to the Slave Channel |
|
830 |
DIicBusChannelSlave* slaveChanPtr = NULL; |
|
831 |
if((r = GetSlaveChanPtr(aChannelId, slaveChanPtr)) != KErrNone) |
|
832 |
return r; |
|
833 |
||
834 |
DIicBusChannelSearcher searchChannel(DIicBusChannel::EMasterSlave, DIicBusChannel::ESccb, DIicBusChannel::EFullDuplex); |
|
835 |
searchChannel.SetChannelNumber(slaveChanPtr->ChannelNumber()); |
|
836 |
||
837 |
TInt dumIndex = iChannelArray.FindInOrder(&searchChannel, EntryOrder); |
|
838 |
if(dumIndex < 0) |
|
839 |
{ |
|
840 |
return KErrNotFound; |
|
841 |
} |
|
842 |
chanPtr = iChannelArray[dumIndex]; |
|
843 |
||
844 |
__ASSERT_DEBUG(chanPtr!=NULL, Kern::Fault(KIicPanic,__LINE__)); |
|
845 |
||
846 |
//if it is the masterslave channel, then call the masterslave's RelaseChannel |
|
847 |
// which will call the slave channel's ReleaseChannel internally |
|
848 |
if(chanPtr->ChannelType() == DIicBusChannel::EMasterSlave) |
|
849 |
r = ((DIicBusChannelMasterSlave*)chanPtr)->ReleaseChannel(); |
|
850 |
else // Call the slave only ReleaseChannel |
|
851 |
r = slaveChanPtr->ReleaseChannel(); |
|
852 |
||
853 |
// In either case de-install the captured slave channel |
|
854 |
if(r == KErrNone) |
|
855 |
{ |
|
856 |
r = DeInstallCapturedChannel(aChannelId, slaveChanPtr); |
|
857 |
} |
|
858 |
||
859 |
// No need to unset iController - there is only one IIC Controller |
|
860 |
return r; |
|
861 |
} |
|
862 |
||
863 |
||
864 |
TInt DIicBusController::RegisterRxBuffer(TInt aChannelId, TPtr8 aRxBuffer, TInt8 aBufGranularity, TInt8 aNumWords, TInt8 aOffset) |
|
865 |
{ |
|
866 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::RegisterRxBuffer, channelID=0x%x,aRxBuffer=0x%x,aBufGranularity=0x%x,aNumWords=0x%x,aOffset=0x%x \n",aChannelId,(TInt)&aRxBuffer,aBufGranularity,aNumWords,aOffset)); |
|
867 |
||
868 |
// Acquire the pointer to the Slave Channel |
|
869 |
DIicBusChannelSlave* slaveChanPtr = NULL; |
|
870 |
TInt r = GetSlaveChanPtr(aChannelId, slaveChanPtr); |
|
871 |
if(r != KErrNone) |
|
872 |
{ |
|
873 |
return r; |
|
874 |
} |
|
875 |
||
876 |
// Instigate the channel functionality |
|
877 |
return(slaveChanPtr->RegisterRxBuffer(aRxBuffer,aBufGranularity,aNumWords,aOffset)); |
|
878 |
} |
|
879 |
||
880 |
TInt DIicBusController::RegisterTxBuffer(TInt aChannelId, TPtr8 aTxBuffer, TInt8 aBufGranularity, TInt8 aNumWords, TInt8 aOffset) |
|
881 |
{ |
|
882 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::RegisterTxBuffer, channelID=0x%x,aTxBuffer=0x%x,aBufGranularity=0x%x,aNumWords=0x%x,aOffset=0x%x \n",aChannelId,(TInt)&aTxBuffer,aBufGranularity,aNumWords,aOffset)); |
|
883 |
||
884 |
// Acquire the pointer to the Slave Channel |
|
885 |
DIicBusChannelSlave* slaveChanPtr = NULL; |
|
886 |
TInt r = GetSlaveChanPtr(aChannelId, slaveChanPtr); |
|
887 |
if(r != KErrNone) |
|
888 |
{ |
|
889 |
return r; |
|
890 |
} |
|
891 |
||
892 |
// Instigate the channel functionality |
|
893 |
return (slaveChanPtr->RegisterTxBuffer(aTxBuffer, aBufGranularity, aNumWords, aOffset)); |
|
894 |
} |
|
895 |
||
896 |
||
897 |
TInt DIicBusController::SetNotificationTrigger(TInt aChannelId, TInt aTrigger) |
|
898 |
{ |
|
899 |
__KTRACE_OPT(KIIC, Kern::Printf("DIicBusController::SetNotificationTrigger - for aChannelId=0x%x, aTrigger=0x%x\n",aChannelId,aTrigger)); |
|
900 |
// Acquire the pointer to the Slave Channel |
|
901 |
DIicBusChannelSlave* slaveChanPtr = NULL; |
|
902 |
TInt r = GetSlaveChanPtr(aChannelId, slaveChanPtr); |
|
903 |
if( r != KErrNone) |
|
904 |
{ |
|
905 |
return r; |
|
906 |
} |
|
907 |
||
908 |
// Instigate the channel functionality |
|
909 |
return(slaveChanPtr->SetNotificationTrigger(aTrigger)); |
|
910 |
} |
|
911 |
||
912 |
||
913 |
TInt DIicBusController::StaticExtension(TUint aId, TUint aFunction, TAny* aParam1, TAny* aParam2) |
|
914 |
{ |
|
915 |
// The IIC controller and channel classes are generic, and can serve many differing client and |
|
916 |
// bus implementations. If a client and bus make use of specific functionality that is not |
|
917 |
// common to other bus types, it makes sense to provide only the minimum-required support in the |
|
918 |
// generic code. Here, the channel identifier is checked but all other parameters are passed |
|
919 |
// directly to the bus implementation channel for processing; if the channel does not provide |
|
920 |
// StaticExtension implementation, the generic DIicBusChannel::StaticExtension method is invoked. |
|
921 |
||
922 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
923 |
if((aFunction & KControlIoMask) == KMasterSlaveControlIo) |
|
924 |
{ |
|
925 |
IIC_MSSTATEXT_START_PIL_TRACE |
|
926 |
} |
|
927 |
else if((aFunction & KControlIoMask) == KMasterControlIo) |
|
928 |
{ |
|
929 |
IIC_MSTATEXT_START_PIL_TRACE |
|
930 |
} |
|
931 |
else if((aFunction & KControlIoMask) == KSlaveControlIo) |
|
932 |
{ |
|
933 |
IIC_SSTATEXT_START_PIL_TRACE |
|
934 |
} |
|
935 |
// else - Unexpected value - just pass silently to the PSL ... |
|
936 |
#endif |
|
937 |
||
938 |
// Get the channel |
|
939 |
TInt dumInt = 0; |
|
940 |
DIicBusChannel* chanPtr = NULL; |
|
941 |
// Can only read the channel array if it is not currently being modified |
|
942 |
TInt r = GetChanReadAccess(); |
|
943 |
if(r == KErrNone) |
|
944 |
{ |
|
945 |
r = GetChanPtr(aId, dumInt, chanPtr); |
|
946 |
if(r == KErrNone) |
|
947 |
{ |
|
948 |
if(!chanPtr) |
|
949 |
{ |
|
950 |
r = KErrArgument; |
|
951 |
} |
|
952 |
else |
|
953 |
{ |
|
954 |
r = chanPtr->StaticExtension(aFunction, aParam1, aParam2); |
|
955 |
} |
|
956 |
} |
|
957 |
} |
|
958 |
||
959 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
960 |
if((aFunction & KControlIoMask) == KMasterSlaveControlIo) |
|
961 |
{ |
|
962 |
IIC_MSSTATEXT_START_PIL_TRACE |
|
963 |
} |
|
964 |
else if((aFunction & KControlIoMask) == KMasterControlIo) |
|
965 |
{ |
|
966 |
IIC_MSTATEXT_START_PIL_TRACE |
|
967 |
} |
|
968 |
else if((aFunction & KControlIoMask) == KSlaveControlIo) |
|
969 |
{ |
|
970 |
IIC_SSTATEXT_START_PIL_TRACE |
|
971 |
} |
|
972 |
// else ... do nothing |
|
973 |
#endif |
|
974 |
FreeChanReadAccess(); |
|
975 |
return r; |
|
976 |
} |
|
977 |
||
978 |
||
979 |
#ifdef _DEBUG |
|
980 |
||
981 |
void DIicBusController::DumpCapturedChannels() |
|
982 |
{ |
|
983 |
// Print iCapturedChannels ... |
|
984 |
TInt count=0; |
|
985 |
TInt i=0; |
|
986 |
TCapturedChannel emptyChan; |
|
987 |
for(;i<KMaxNumCapturedChannels;++i) |
|
988 |
{ |
|
989 |
if(iCapturedChannels[i] == emptyChan) |
|
990 |
continue; |
|
991 |
++count; |
|
992 |
} |
|
993 |
||
994 |
i = 0; |
|
995 |
__KTRACE_OPT(KIIC, Kern::Printf(" - Count gave %d\n",count)); |
|
996 |
for(;i<KMaxNumCapturedChannels;++i) |
|
997 |
{ |
|
998 |
if(iCapturedChannels[i] == emptyChan) |
|
999 |
continue; |
|
1000 |
DIicBusChannel* ptr=(DIicBusChannel*)(iCapturedChannels[i]).iChanPtr; |
|
1001 |
__KTRACE_OPT(KIIC, Kern::Printf(" - ptr %d=0x%x\n",i,ptr)); |
|
1002 |
ptr->StaticExtension(KCtrlIoDumpChan,0,0); |
|
1003 |
}; |
|
1004 |
} |
|
1005 |
||
1006 |
void DIicBusController::DumpChannelArray() |
|
1007 |
{ |
|
1008 |
TInt i = 0; |
|
1009 |
__KTRACE_OPT(KIIC, Kern::Printf("\nDIicBusController::DumpChannelArray\n")); |
|
1010 |
__KTRACE_OPT(KIIC, Kern::Printf(" - Count gave %d\n",iChannelArray.Count())); |
|
1011 |
for(i=0; i<iChannelArray.Count(); i++) |
|
1012 |
{ |
|
1013 |
DIicBusChannel* ptr=iChannelArray[i]; |
|
1014 |
__KTRACE_OPT(KIIC, Kern::Printf(" - ptr %d=0x%x\n",i,ptr)); |
|
1015 |
ptr->StaticExtension(KCtrlIoDumpChan,0,0); |
|
1016 |
}; |
|
1017 |
} |
|
1018 |
||
1019 |
#endif |
|
1020 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1021 |
#ifndef IIC_SIMULATED_PSL |
0 | 1022 |
|
1023 |
// Client interface entry point |
|
1024 |
DECLARE_EXTENSION_WITH_PRIORITY(KExtensionMaximumPriority-1) // highest priority after Resource Manager |
|
1025 |
{ |
|
1026 |
TheController = new DIicBusController; |
|
1027 |
if(!TheController) |
|
1028 |
return KErrNoMemory; |
|
1029 |
TInt r=TheController->Create(); |
|
1030 |
return r; |
|
1031 |
} |
|
1032 |
#endif |
|
1033 |
||
1034 |