sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32/include/iic_transaction.inl sl@0: // sl@0: sl@0: inline TIicBusTransfer::TIicBusTransfer() sl@0: : iBuffer(NULL), iNext(NULL), iTransaction(NULL) {} sl@0: sl@0: inline TIicBusTransfer::TIicBusTransfer(TReqType aType, TInt8 aGranularity, TDes8* aBuffer) : iType((TInt8)aType), iNext(NULL) sl@0: { sl@0: __ASSERT_ALWAYS(aBuffer && aGranularity && aBuffer->Size()%(((aGranularity-1)>>3)+1)==0,Kern::Fault("TIicBusTransfer",__LINE__)); sl@0: iBufGranularity=aGranularity; sl@0: iBuffer=aBuffer; sl@0: } sl@0: sl@0: inline void TIicBusTransfer::LinkAfter(TIicBusTransfer* aPrev) sl@0: { sl@0: __ASSERT_ALWAYS(aPrev && aPrev->WordWidth()==iBufGranularity,Kern::Fault("LinkAfter",__LINE__)); sl@0: iNext=aPrev; sl@0: } sl@0: sl@0: inline TInt8 TIicBusTransfer::WordWidth() sl@0: {return iBufGranularity;} sl@0: sl@0: inline TIicBusTransfer::TReqType TIicBusTransfer::Direction() sl@0: {return (TIicBusTransfer::TReqType)iType;} sl@0: sl@0: inline TInt TIicBusTransfer::Length() sl@0: { sl@0: TInt8 granularityInBytes = (TInt8)(((iBufGranularity-1)>>3)+1); sl@0: return(iBuffer->Size()/granularityInBytes); sl@0: } sl@0: sl@0: inline const TIicBusTransfer* TIicBusTransfer::Next() sl@0: {return iNext;} sl@0: sl@0: inline TInt TIicBusTransfer::SetTransferData(TReqType aType, TInt8 aGranularity, TDes8* aBuffer) sl@0: { sl@0: __ASSERT_ALWAYS(aBuffer && aGranularity && aBuffer->Size()%(((aGranularity-1)>>3)+1)==0,Kern::Fault("TIicBusTransfer",__LINE__)); sl@0: if((iTransaction==NULL)||(iTransaction->State()==TIicBusTransaction::EFree)) sl@0: { sl@0: iType = (TInt8)aType; sl@0: iBufGranularity = aGranularity; sl@0: iBuffer = aBuffer; sl@0: return KErrNone; sl@0: } sl@0: return KErrInUse; sl@0: } sl@0: sl@0: inline TIicBusTransaction::TIicBusTransaction(): iHeader(NULL), iFlags(NULL), iState(EFree), sl@0: iHalfDuplexTrans(NULL), iFullDuplexTrans(NULL), iCallback(NULL){} sl@0: sl@0: inline TIicBusTransaction::TIicBusTransaction(TDes8* aHeader, TIicBusTransfer* aHdTrans, TInt aPriority) : sl@0: iHeader(aHeader), iFlags(NULL), iState(EFree), iHalfDuplexTrans(aHdTrans), sl@0: iFullDuplexTrans(NULL), iCallback(NULL) sl@0: { sl@0: __ASSERT_ALWAYS((((TUint)aPriority<(TUint)KNumTrancPriorities)&&((TUint)aPriority>=0)),Kern::Fault("TIicBusTransaction",__LINE__)); sl@0: __ASSERT_ALWAYS(aHeader && aHdTrans,Kern::Fault("TIicBusTransaction",__LINE__)); sl@0: iKey = aPriority; sl@0: } sl@0: sl@0: inline TIicBusTransaction::~TIicBusTransaction() sl@0: {__ASSERT_ALWAYS(iState==TIicBusTransaction::EFree,Kern::Fault("~TIicBusTransaction",__LINE__));} sl@0: sl@0: inline TInt TIicBusTransaction::SetHalfDuplexTrans(TDes8* aHeader, TIicBusTransfer* aHdTrans) sl@0: { sl@0: __ASSERT_ALWAYS(aHeader && aHdTrans, Kern::Fault("SetHalfDuplexTrans",__LINE__)); sl@0: __ASSERT_ALWAYS(iState==TIicBusTransaction::EFree,Kern::Fault("SetHalfDuplexTrans",__LINE__)); sl@0: iHeader = aHeader; sl@0: iHalfDuplexTrans = aHdTrans; sl@0: while(aHdTrans) sl@0: { sl@0: aHdTrans->iTransaction=this; sl@0: aHdTrans = (TIicBusTransfer*)(aHdTrans->Next()); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: // The client interface for setting full duplex transaction: the API checks that it is possible to have the 2 transactions done in parallel. sl@0: // It does not check if the channel supports full duplex, so the transaction may still fail at queuing time. sl@0: inline TInt TIicBusTransaction::SetFullDuplexTrans(TIicBusTransfer* aFdTrans) sl@0: { sl@0: __ASSERT_ALWAYS(aFdTrans,Kern::Fault("SetFullDuplexTrans",__LINE__)); sl@0: __ASSERT_ALWAYS(iState==TIicBusTransaction::EFree,Kern::Fault("SetFullDuplexTrans",__LINE__)); sl@0: TIicBusTransfer* local = iHalfDuplexTrans; sl@0: TIicBusTransfer* remote = aFdTrans; sl@0: while(local && remote) sl@0: { sl@0: if(local->Direction()==remote->Direction()) sl@0: return KErrNotSupported; sl@0: if(local->Next() && local->Length()Length()) sl@0: return KErrNotSupported; sl@0: if(remote->Next() && remote->Length()Length()) sl@0: return KErrNotSupported; sl@0: local = (TIicBusTransfer*)(local->Next()); sl@0: remote = (TIicBusTransfer*)(remote->Next()); sl@0: } sl@0: iFullDuplexTrans = aFdTrans; sl@0: while(aFdTrans) sl@0: { sl@0: aFdTrans->iTransaction=this; sl@0: aFdTrans = (TIicBusTransfer*)(aFdTrans->Next()); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: inline TInt TIicBusTransaction::RemoveTrans(TIicBusTransfer* aTrans) sl@0: { sl@0: __ASSERT_ALWAYS(aTrans,Kern::Fault("RemoveTrans",__LINE__)); sl@0: __ASSERT_ALWAYS(iState==TIicBusTransaction::EFree,Kern::Fault("RemoveTrans",__LINE__)); sl@0: TIicBusTransfer* ptr = aTrans; sl@0: while(ptr!=NULL) sl@0: { sl@0: ptr->iTransaction = NULL; sl@0: ptr = (TIicBusTransfer*)(ptr->Next()); sl@0: } sl@0: aTrans=NULL; sl@0: return KErrNone; sl@0: } sl@0: sl@0: inline TInt TIicBusTransaction::RemoveHalfDuplexTrans() sl@0: {return RemoveTrans(iHalfDuplexTrans);}; sl@0: sl@0: inline TInt TIicBusTransaction::RemoveFullDuplexTrans() sl@0: {return RemoveTrans(iFullDuplexTrans);}; sl@0: sl@0: inline TUint TIicBusTransaction::Flags() sl@0: {return iFlags;} sl@0: sl@0: inline TIicBusTransaction::TIicBusTransaction(TDes8* aHeader, TIicBusTransfer* aHdTrans, TUint8 aFlags, TInt aPriority) : sl@0: iHeader(aHeader), iFlags(aFlags), iHalfDuplexTrans(aHdTrans), iFullDuplexTrans(NULL), iCallback(NULL) sl@0: { sl@0: __ASSERT_ALWAYS(aHeader && aHdTrans,Kern::Fault("TIicBusTransaction",__LINE__)); sl@0: iKey = aPriority; sl@0: } sl@0: sl@0: inline TUint8 TIicBusTransaction::State() sl@0: {return iState;} sl@0: sl@0: inline TInt TIicBusTransaction::GetBusId() sl@0: {return iBusId;} sl@0: sl@0: inline TIicBusCallback::TIicBusCallback(TIicBusCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority) sl@0: : TDfc(DfcFunc, this, aQue, aPriority), iTransaction(NULL), iParam(aPtr), iCallback(aFn) {} sl@0: sl@0: inline TIicBusCallback::~TIicBusCallback() sl@0: {__ASSERT_ALWAYS(!iTransaction || iTransaction->State()==TIicBusTransaction::EFree,Kern::Fault("~TIicBusCallback",__LINE__));} sl@0: sl@0: inline void TIicBusCallback::DfcFunc(TAny* aPtr) sl@0: { sl@0: TIicBusCallback* pCb = (TIicBusCallback*) aPtr; sl@0: pCb->iCallback(pCb->iTransaction, pCb->iBusId, pCb->iResult, pCb->iParam); sl@0: } sl@0: sl@0: inline TIicBusSlaveCallback::TIicBusSlaveCallback(TIicBusSlaveCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority): sl@0: TDfc(DfcFunc, this, aQue, aPriority), iParam(aPtr), iCallback(aFn) { } sl@0: sl@0: inline void TIicBusSlaveCallback::SetReturn(TInt aRet) sl@0: {iReturn=aRet;} sl@0: sl@0: inline void TIicBusSlaveCallback::SetTxWords(TInt16 aTxWords) sl@0: {iTxWords=aTxWords;} sl@0: sl@0: inline void TIicBusSlaveCallback::SetRxWords(TInt16 aRxWords) sl@0: {iRxWords=aRxWords;} sl@0: sl@0: inline TInt TIicBusSlaveCallback::GetTrigger() sl@0: {return iTrigger;} sl@0: sl@0: inline void TIicBusSlaveCallback::SetTrigger(TInt aTrigger) sl@0: {iTrigger = aTrigger;} sl@0: sl@0: inline TIicBusTransactionPreamble::TIicBusTransactionPreamble(TDes8* aHeader, TIicBusTransfer* aHdTrans, TIicBusPreamble aPreamble, TAny* aArg, TInt aPriority) : sl@0: TIicBusTransaction(aHeader, aHdTrans, KTransactionWithPreamble, aPriority), iPreamble(aPreamble), iPreambleArg(aArg) sl@0: {} sl@0: sl@0: inline TIicBusTransactionPreamble::TIicBusTransactionPreamble(TDes8* aHeader, TIicBusTransfer* aHdTrans, TIicBusPreamble aPreamble, TAny* aArg, TUint8 aFlags, TInt aPriority) : sl@0: TIicBusTransaction(aHeader, aHdTrans, aFlags, aPriority), iPreamble(aPreamble), iPreambleArg(aArg) sl@0: {} sl@0: sl@0: inline TIicBusTransactionMultiTransc::TIicBusTransactionMultiTransc(TDes8* aHeader, TIicBusTransfer* aHdTrans, TIicBusMultiTranscCbFn aMultiTransc, TAny* aArg, TInt aPriority) : sl@0: TIicBusTransaction(aHeader, aHdTrans, KTransactionWithMultiTransc, aPriority), iMultiTransc(aMultiTransc), iMultiTranscArg(aArg) sl@0: {} sl@0: sl@0: inline TIicBusTransactionPreambleExt::TIicBusTransactionPreambleExt(TDes8* aHeader, TIicBusTransfer* aHdTrans, sl@0: TIicBusPreamble aPreamble, TAny* aPreambleArg, sl@0: TIicBusMultiTranscCbFn aMultiTransc, TAny* aMultiTranscArg, TInt aPriority) : sl@0: TIicBusTransactionPreamble(aHeader, aHdTrans, aPreamble, aPreambleArg, KTransactionWithPreamble|KTransactionWithMultiTransc, aPriority), sl@0: iMultiTransc(aMultiTransc), iMultiTranscArg(aMultiTranscArg) sl@0: {} sl@0: sl@0: inline static TInt CreateSpiBuf(TConfigSpiBufV01*& aBuf, sl@0: TSpiWordWidth aWordWidth, sl@0: TInt32 aClkSpeedHz, sl@0: TSpiClkMode aClkMode, sl@0: TInt32 aTimeoutPeriod, sl@0: TEndianness aEndianness, sl@0: TBitOrder aBitOrder, sl@0: TUint aTransactionWaitCycles, sl@0: TSpiSsPinMode aSSPinActiveMode) sl@0: // Utility function to create a buffer for the SPI bus sl@0: { sl@0: aBuf = new TConfigSpiBufV01(); sl@0: if(aBuf==NULL) sl@0: return KErrNoMemory; sl@0: TConfigSpiV01 *buf = &((*aBuf)()); sl@0: buf->iWordWidth = aWordWidth; sl@0: buf->iClkSpeedHz = aClkSpeedHz; sl@0: buf->iClkMode = aClkMode; sl@0: buf->iTimeoutPeriod = aTimeoutPeriod; sl@0: buf->iEndianness = aEndianness; sl@0: buf->iBitOrder = aBitOrder; sl@0: buf->iTransactionWaitCycles = aTransactionWaitCycles; sl@0: buf->iSSPinActiveMode = aSSPinActiveMode; sl@0: return KErrNone; sl@0: } sl@0: sl@0: inline static TInt CreateI2cBuf(TConfigI2cBufV01*& aBuf, sl@0: TI2cAddrType aAddrType, sl@0: TInt32 aClkSpeedHz, sl@0: TEndianness aEndianness, sl@0: TInt32 aTimeoutPeriod) sl@0: // Utility function to create a buffer for the I2C bus sl@0: { sl@0: aBuf = new TConfigI2cBufV01(); sl@0: if(aBuf==NULL) sl@0: return KErrNoMemory; sl@0: TConfigI2cV01 *buf = &((*aBuf)()); sl@0: buf->iAddrType = aAddrType; sl@0: buf->iClkSpeedHz = aClkSpeedHz; sl@0: buf->iEndianness = aEndianness; sl@0: buf->iTimeoutPeriod = aTimeoutPeriod; sl@0: return KErrNone; sl@0: }