Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32/include/iic_transaction.inl
17 inline TIicBusTransfer::TIicBusTransfer()
18 : iBuffer(NULL), iNext(NULL), iTransaction(NULL) {}
20 inline TIicBusTransfer::TIicBusTransfer(TReqType aType, TInt8 aGranularity, TDes8* aBuffer) : iType((TInt8)aType), iNext(NULL)
22 __ASSERT_ALWAYS(aBuffer && aGranularity && aBuffer->Size()%(((aGranularity-1)>>3)+1)==0,Kern::Fault("TIicBusTransfer",__LINE__));
23 iBufGranularity=aGranularity;
27 inline void TIicBusTransfer::LinkAfter(TIicBusTransfer* aPrev)
29 __ASSERT_ALWAYS(aPrev && aPrev->WordWidth()==iBufGranularity,Kern::Fault("LinkAfter",__LINE__));
33 inline TInt8 TIicBusTransfer::WordWidth()
34 {return iBufGranularity;}
36 inline TIicBusTransfer::TReqType TIicBusTransfer::Direction()
37 {return (TIicBusTransfer::TReqType)iType;}
39 inline TInt TIicBusTransfer::Length()
41 TInt8 granularityInBytes = (TInt8)(((iBufGranularity-1)>>3)+1);
42 return(iBuffer->Size()/granularityInBytes);
45 inline const TIicBusTransfer* TIicBusTransfer::Next()
48 inline TInt TIicBusTransfer::SetTransferData(TReqType aType, TInt8 aGranularity, TDes8* aBuffer)
50 __ASSERT_ALWAYS(aBuffer && aGranularity && aBuffer->Size()%(((aGranularity-1)>>3)+1)==0,Kern::Fault("TIicBusTransfer",__LINE__));
51 if((iTransaction==NULL)||(iTransaction->State()==TIicBusTransaction::EFree))
54 iBufGranularity = aGranularity;
61 inline TIicBusTransaction::TIicBusTransaction(): iHeader(NULL), iFlags(NULL), iState(EFree),
62 iHalfDuplexTrans(NULL), iFullDuplexTrans(NULL), iCallback(NULL){}
64 inline TIicBusTransaction::TIicBusTransaction(TDes8* aHeader, TIicBusTransfer* aHdTrans, TInt aPriority) :
65 iHeader(aHeader), iFlags(NULL), iState(EFree), iHalfDuplexTrans(aHdTrans),
66 iFullDuplexTrans(NULL), iCallback(NULL)
68 __ASSERT_ALWAYS((((TUint)aPriority<(TUint)KNumTrancPriorities)&&((TUint)aPriority>=0)),Kern::Fault("TIicBusTransaction",__LINE__));
69 __ASSERT_ALWAYS(aHeader && aHdTrans,Kern::Fault("TIicBusTransaction",__LINE__));
73 inline TIicBusTransaction::~TIicBusTransaction()
74 {__ASSERT_ALWAYS(iState==TIicBusTransaction::EFree,Kern::Fault("~TIicBusTransaction",__LINE__));}
76 inline TInt TIicBusTransaction::SetHalfDuplexTrans(TDes8* aHeader, TIicBusTransfer* aHdTrans)
78 __ASSERT_ALWAYS(aHeader && aHdTrans, Kern::Fault("SetHalfDuplexTrans",__LINE__));
79 __ASSERT_ALWAYS(iState==TIicBusTransaction::EFree,Kern::Fault("SetHalfDuplexTrans",__LINE__));
81 iHalfDuplexTrans = aHdTrans;
84 aHdTrans->iTransaction=this;
85 aHdTrans = (TIicBusTransfer*)(aHdTrans->Next());
90 // The client interface for setting full duplex transaction: the API checks that it is possible to have the 2 transactions done in parallel.
91 // It does not check if the channel supports full duplex, so the transaction may still fail at queuing time.
92 inline TInt TIicBusTransaction::SetFullDuplexTrans(TIicBusTransfer* aFdTrans)
94 __ASSERT_ALWAYS(aFdTrans,Kern::Fault("SetFullDuplexTrans",__LINE__));
95 __ASSERT_ALWAYS(iState==TIicBusTransaction::EFree,Kern::Fault("SetFullDuplexTrans",__LINE__));
96 TIicBusTransfer* local = iHalfDuplexTrans;
97 TIicBusTransfer* remote = aFdTrans;
98 while(local && remote)
100 if(local->Direction()==remote->Direction())
101 return KErrNotSupported;
102 if(local->Next() && local->Length()<remote->Length())
103 return KErrNotSupported;
104 if(remote->Next() && remote->Length()<local->Length())
105 return KErrNotSupported;
106 local = (TIicBusTransfer*)(local->Next());
107 remote = (TIicBusTransfer*)(remote->Next());
109 iFullDuplexTrans = aFdTrans;
112 aFdTrans->iTransaction=this;
113 aFdTrans = (TIicBusTransfer*)(aFdTrans->Next());
118 inline TInt TIicBusTransaction::RemoveTrans(TIicBusTransfer* aTrans)
120 __ASSERT_ALWAYS(aTrans,Kern::Fault("RemoveTrans",__LINE__));
121 __ASSERT_ALWAYS(iState==TIicBusTransaction::EFree,Kern::Fault("RemoveTrans",__LINE__));
122 TIicBusTransfer* ptr = aTrans;
125 ptr->iTransaction = NULL;
126 ptr = (TIicBusTransfer*)(ptr->Next());
132 inline TInt TIicBusTransaction::RemoveHalfDuplexTrans()
133 {return RemoveTrans(iHalfDuplexTrans);};
135 inline TInt TIicBusTransaction::RemoveFullDuplexTrans()
136 {return RemoveTrans(iFullDuplexTrans);};
138 inline TUint TIicBusTransaction::Flags()
141 inline TIicBusTransaction::TIicBusTransaction(TDes8* aHeader, TIicBusTransfer* aHdTrans, TUint8 aFlags, TInt aPriority) :
142 iHeader(aHeader), iFlags(aFlags), iHalfDuplexTrans(aHdTrans), iFullDuplexTrans(NULL), iCallback(NULL)
144 __ASSERT_ALWAYS(aHeader && aHdTrans,Kern::Fault("TIicBusTransaction",__LINE__));
148 inline TUint8 TIicBusTransaction::State()
151 inline TInt TIicBusTransaction::GetBusId()
154 inline TIicBusCallback::TIicBusCallback(TIicBusCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority)
155 : TDfc(DfcFunc, this, aQue, aPriority), iTransaction(NULL), iParam(aPtr), iCallback(aFn) {}
157 inline TIicBusCallback::~TIicBusCallback()
158 {__ASSERT_ALWAYS(!iTransaction || iTransaction->State()==TIicBusTransaction::EFree,Kern::Fault("~TIicBusCallback",__LINE__));}
160 inline void TIicBusCallback::DfcFunc(TAny* aPtr)
162 TIicBusCallback* pCb = (TIicBusCallback*) aPtr;
163 pCb->iCallback(pCb->iTransaction, pCb->iBusId, pCb->iResult, pCb->iParam);
166 inline TIicBusSlaveCallback::TIicBusSlaveCallback(TIicBusSlaveCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority):
167 TDfc(DfcFunc, this, aQue, aPriority), iParam(aPtr), iCallback(aFn) { }
169 inline void TIicBusSlaveCallback::SetReturn(TInt aRet)
172 inline void TIicBusSlaveCallback::SetTxWords(TInt16 aTxWords)
175 inline void TIicBusSlaveCallback::SetRxWords(TInt16 aRxWords)
178 inline TInt TIicBusSlaveCallback::GetTrigger()
181 inline void TIicBusSlaveCallback::SetTrigger(TInt aTrigger)
182 {iTrigger = aTrigger;}
184 inline TIicBusTransactionPreamble::TIicBusTransactionPreamble(TDes8* aHeader, TIicBusTransfer* aHdTrans, TIicBusPreamble aPreamble, TAny* aArg, TInt aPriority) :
185 TIicBusTransaction(aHeader, aHdTrans, KTransactionWithPreamble, aPriority), iPreamble(aPreamble), iPreambleArg(aArg)
188 inline TIicBusTransactionPreamble::TIicBusTransactionPreamble(TDes8* aHeader, TIicBusTransfer* aHdTrans, TIicBusPreamble aPreamble, TAny* aArg, TUint8 aFlags, TInt aPriority) :
189 TIicBusTransaction(aHeader, aHdTrans, aFlags, aPriority), iPreamble(aPreamble), iPreambleArg(aArg)
192 inline TIicBusTransactionMultiTransc::TIicBusTransactionMultiTransc(TDes8* aHeader, TIicBusTransfer* aHdTrans, TIicBusMultiTranscCbFn aMultiTransc, TAny* aArg, TInt aPriority) :
193 TIicBusTransaction(aHeader, aHdTrans, KTransactionWithMultiTransc, aPriority), iMultiTransc(aMultiTransc), iMultiTranscArg(aArg)
196 inline TIicBusTransactionPreambleExt::TIicBusTransactionPreambleExt(TDes8* aHeader, TIicBusTransfer* aHdTrans,
197 TIicBusPreamble aPreamble, TAny* aPreambleArg,
198 TIicBusMultiTranscCbFn aMultiTransc, TAny* aMultiTranscArg, TInt aPriority) :
199 TIicBusTransactionPreamble(aHeader, aHdTrans, aPreamble, aPreambleArg, KTransactionWithPreamble|KTransactionWithMultiTransc, aPriority),
200 iMultiTransc(aMultiTransc), iMultiTranscArg(aMultiTranscArg)
203 inline static TInt CreateSpiBuf(TConfigSpiBufV01*& aBuf,
204 TSpiWordWidth aWordWidth,
206 TSpiClkMode aClkMode,
207 TInt32 aTimeoutPeriod,
208 TEndianness aEndianness,
210 TUint aTransactionWaitCycles,
211 TSpiSsPinMode aSSPinActiveMode)
212 // Utility function to create a buffer for the SPI bus
214 aBuf = new TConfigSpiBufV01();
217 TConfigSpiV01 *buf = &((*aBuf)());
218 buf->iWordWidth = aWordWidth;
219 buf->iClkSpeedHz = aClkSpeedHz;
220 buf->iClkMode = aClkMode;
221 buf->iTimeoutPeriod = aTimeoutPeriod;
222 buf->iEndianness = aEndianness;
223 buf->iBitOrder = aBitOrder;
224 buf->iTransactionWaitCycles = aTransactionWaitCycles;
225 buf->iSSPinActiveMode = aSSPinActiveMode;
229 inline static TInt CreateI2cBuf(TConfigI2cBufV01*& aBuf,
230 TI2cAddrType aAddrType,
232 TEndianness aEndianness,
233 TInt32 aTimeoutPeriod)
234 // Utility function to create a buffer for the I2C bus
236 aBuf = new TConfigI2cBufV01();
239 TConfigI2cV01 *buf = &((*aBuf)());
240 buf->iAddrType = aAddrType;
241 buf->iClkSpeedHz = aClkSpeedHz;
242 buf->iEndianness = aEndianness;
243 buf->iTimeoutPeriod = aTimeoutPeriod;