os/kernelhwsrv/kernel/eka/include/drivers/iic_transaction.inl
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32/include/iic_transaction.inl 
    15 //
    16 
    17 inline TIicBusTransfer::TIicBusTransfer() 
    18     : iBuffer(NULL), iNext(NULL), iTransaction(NULL) {}
    19 
    20 inline TIicBusTransfer::TIicBusTransfer(TReqType aType, TInt8 aGranularity, TDes8* aBuffer) : iType((TInt8)aType), iNext(NULL)
    21     {
    22     __ASSERT_ALWAYS(aBuffer && aGranularity && aBuffer->Size()%(((aGranularity-1)>>3)+1)==0,Kern::Fault("TIicBusTransfer",__LINE__));
    23     iBufGranularity=aGranularity;
    24     iBuffer=aBuffer;
    25     }
    26 
    27 inline void TIicBusTransfer::LinkAfter(TIicBusTransfer* aPrev)
    28     {
    29     __ASSERT_ALWAYS(aPrev && aPrev->WordWidth()==iBufGranularity,Kern::Fault("LinkAfter",__LINE__));
    30     iNext=aPrev;
    31     }
    32 
    33 inline TInt8 TIicBusTransfer::WordWidth() 
    34     {return iBufGranularity;}
    35 
    36 inline TIicBusTransfer::TReqType TIicBusTransfer::Direction() 
    37     {return (TIicBusTransfer::TReqType)iType;}
    38 
    39 inline TInt TIicBusTransfer::Length()
    40     {
    41     TInt8 granularityInBytes = (TInt8)(((iBufGranularity-1)>>3)+1);
    42     return(iBuffer->Size()/granularityInBytes);
    43     }
    44 
    45 inline const TIicBusTransfer* TIicBusTransfer::Next() 
    46     {return iNext;}
    47 
    48 inline TInt TIicBusTransfer::SetTransferData(TReqType aType, TInt8 aGranularity, TDes8* aBuffer)
    49     {
    50     __ASSERT_ALWAYS(aBuffer && aGranularity && aBuffer->Size()%(((aGranularity-1)>>3)+1)==0,Kern::Fault("TIicBusTransfer",__LINE__));
    51     if((iTransaction==NULL)||(iTransaction->State()==TIicBusTransaction::EFree))
    52         {
    53         iType = (TInt8)aType;
    54         iBufGranularity = aGranularity;
    55         iBuffer = aBuffer;
    56         return KErrNone;
    57         }
    58     return KErrInUse;
    59     }
    60 
    61 inline TIicBusTransaction::TIicBusTransaction(): iHeader(NULL), iFlags(NULL), iState(EFree),
    62     iHalfDuplexTrans(NULL), iFullDuplexTrans(NULL), iCallback(NULL){}
    63 
    64 inline TIicBusTransaction::TIicBusTransaction(TDes8* aHeader, TIicBusTransfer* aHdTrans, TInt aPriority) :
    65     iHeader(aHeader), iFlags(NULL), iState(EFree), iHalfDuplexTrans(aHdTrans),
    66     iFullDuplexTrans(NULL), iCallback(NULL)
    67     {
    68     __ASSERT_ALWAYS((((TUint)aPriority<(TUint)KNumTrancPriorities)&&((TUint)aPriority>=0)),Kern::Fault("TIicBusTransaction",__LINE__));
    69     __ASSERT_ALWAYS(aHeader && aHdTrans,Kern::Fault("TIicBusTransaction",__LINE__));
    70     iKey = aPriority;
    71     }
    72 
    73 inline TIicBusTransaction::~TIicBusTransaction()
    74     {__ASSERT_ALWAYS(iState==TIicBusTransaction::EFree,Kern::Fault("~TIicBusTransaction",__LINE__));}
    75 
    76 inline TInt TIicBusTransaction::SetHalfDuplexTrans(TDes8* aHeader, TIicBusTransfer* aHdTrans)
    77     {
    78     __ASSERT_ALWAYS(aHeader && aHdTrans, Kern::Fault("SetHalfDuplexTrans",__LINE__));
    79     __ASSERT_ALWAYS(iState==TIicBusTransaction::EFree,Kern::Fault("SetHalfDuplexTrans",__LINE__));
    80     iHeader = aHeader;
    81     iHalfDuplexTrans = aHdTrans;
    82     while(aHdTrans)
    83         {
    84         aHdTrans->iTransaction=this;
    85         aHdTrans = (TIicBusTransfer*)(aHdTrans->Next());
    86         }
    87     return KErrNone;
    88     }
    89 
    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)
    93     {
    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)
    99         {
   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());
   108         }
   109     iFullDuplexTrans = aFdTrans;
   110     while(aFdTrans)
   111         {
   112         aFdTrans->iTransaction=this;
   113         aFdTrans = (TIicBusTransfer*)(aFdTrans->Next());
   114         }
   115     return KErrNone;
   116     }
   117 
   118 inline TInt TIicBusTransaction::RemoveTrans(TIicBusTransfer* aTrans)
   119     {
   120     __ASSERT_ALWAYS(aTrans,Kern::Fault("RemoveTrans",__LINE__));
   121     __ASSERT_ALWAYS(iState==TIicBusTransaction::EFree,Kern::Fault("RemoveTrans",__LINE__));
   122     TIicBusTransfer* ptr = aTrans;
   123     while(ptr!=NULL)
   124         {
   125         ptr->iTransaction = NULL;
   126         ptr = (TIicBusTransfer*)(ptr->Next());
   127         }
   128     aTrans=NULL;
   129     return KErrNone;
   130     }
   131 
   132 inline TInt TIicBusTransaction::RemoveHalfDuplexTrans() 
   133     {return RemoveTrans(iHalfDuplexTrans);};
   134 
   135 inline TInt TIicBusTransaction::RemoveFullDuplexTrans() 
   136     {return RemoveTrans(iFullDuplexTrans);};
   137 
   138 inline TUint TIicBusTransaction::Flags()
   139     {return iFlags;}
   140 
   141 inline TIicBusTransaction::TIicBusTransaction(TDes8* aHeader, TIicBusTransfer* aHdTrans, TUint8 aFlags, TInt aPriority) : 
   142     iHeader(aHeader), iFlags(aFlags), iHalfDuplexTrans(aHdTrans), iFullDuplexTrans(NULL), iCallback(NULL)
   143     {
   144     __ASSERT_ALWAYS(aHeader && aHdTrans,Kern::Fault("TIicBusTransaction",__LINE__));
   145     iKey = aPriority;
   146     }
   147 
   148 inline TUint8 TIicBusTransaction::State() 
   149     {return iState;}
   150 
   151 inline TInt TIicBusTransaction::GetBusId() 
   152     {return iBusId;}
   153 
   154 inline TIicBusCallback::TIicBusCallback(TIicBusCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority) 
   155     : TDfc(DfcFunc, this, aQue, aPriority), iTransaction(NULL), iParam(aPtr), iCallback(aFn) {}
   156 
   157 inline TIicBusCallback::~TIicBusCallback()
   158     {__ASSERT_ALWAYS(!iTransaction || iTransaction->State()==TIicBusTransaction::EFree,Kern::Fault("~TIicBusCallback",__LINE__));}       
   159 
   160 inline void TIicBusCallback::DfcFunc(TAny* aPtr)
   161     {
   162     TIicBusCallback* pCb = (TIicBusCallback*) aPtr;
   163     pCb->iCallback(pCb->iTransaction, pCb->iBusId, pCb->iResult, pCb->iParam);
   164     }
   165 
   166 inline TIicBusSlaveCallback::TIicBusSlaveCallback(TIicBusSlaveCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority):  
   167     TDfc(DfcFunc, this, aQue, aPriority), iParam(aPtr), iCallback(aFn) { }
   168 
   169 inline void TIicBusSlaveCallback::SetReturn(TInt aRet) 
   170     {iReturn=aRet;}
   171 
   172 inline void TIicBusSlaveCallback::SetTxWords(TInt16 aTxWords) 
   173     {iTxWords=aTxWords;}
   174 
   175 inline void TIicBusSlaveCallback::SetRxWords(TInt16 aRxWords) 
   176     {iRxWords=aRxWords;} 
   177 
   178 inline TInt TIicBusSlaveCallback::GetTrigger() 
   179     {return iTrigger;}
   180 
   181 inline void TIicBusSlaveCallback::SetTrigger(TInt aTrigger) 
   182     {iTrigger = aTrigger;}
   183 
   184 inline TIicBusTransactionPreamble::TIicBusTransactionPreamble(TDes8* aHeader, TIicBusTransfer* aHdTrans, TIicBusPreamble aPreamble, TAny* aArg, TInt aPriority) :
   185     TIicBusTransaction(aHeader, aHdTrans, KTransactionWithPreamble, aPriority), iPreamble(aPreamble), iPreambleArg(aArg)
   186     {}
   187 
   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)
   190     {}
   191 
   192 inline TIicBusTransactionMultiTransc::TIicBusTransactionMultiTransc(TDes8* aHeader, TIicBusTransfer* aHdTrans, TIicBusMultiTranscCbFn aMultiTransc, TAny* aArg, TInt aPriority) :
   193     TIicBusTransaction(aHeader, aHdTrans, KTransactionWithMultiTransc, aPriority), iMultiTransc(aMultiTransc), iMultiTranscArg(aArg)
   194     {}
   195 
   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)
   201     {}
   202 
   203 inline static TInt CreateSpiBuf(TConfigSpiBufV01*& aBuf,
   204                                 TSpiWordWidth   aWordWidth,
   205                                 TInt32          aClkSpeedHz,
   206                                 TSpiClkMode     aClkMode,
   207                                 TInt32          aTimeoutPeriod,
   208                                 TEndianness     aEndianness,
   209                                 TBitOrder       aBitOrder,
   210                                 TUint           aTransactionWaitCycles,
   211                                 TSpiSsPinMode   aSSPinActiveMode)
   212 // Utility function to create a buffer for the SPI bus
   213     {
   214     aBuf = new TConfigSpiBufV01();
   215     if(aBuf==NULL)
   216         return KErrNoMemory;
   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;
   226     return KErrNone;
   227     }
   228 
   229 inline static TInt CreateI2cBuf(TConfigI2cBufV01*& aBuf,
   230                                 TI2cAddrType    aAddrType,
   231                                 TInt32          aClkSpeedHz,
   232                                 TEndianness     aEndianness,
   233                                 TInt32          aTimeoutPeriod)
   234 // Utility function to create a buffer for the I2C bus
   235     {
   236     aBuf = new TConfigI2cBufV01();
   237     if(aBuf==NULL)
   238         return KErrNoMemory;
   239     TConfigI2cV01 *buf = &((*aBuf)());
   240     buf->iAddrType = aAddrType;
   241     buf->iClkSpeedHz = aClkSpeedHz;
   242     buf->iEndianness = aEndianness;
   243     buf->iTimeoutPeriod = aTimeoutPeriod;
   244     return KErrNone;
   245     }