|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __CSI_MASTER_H_ |
|
22 #define __CSI_MASTER_H_ |
|
23 |
|
24 #include <assp/naviengine/naviengine.h> |
|
25 #include <drivers/gpio.h> |
|
26 #include <drivers/iic_channel.h> |
|
27 #include "csi_psl.h" |
|
28 |
|
29 _LIT(KSpiThreadName,"SpiChannelThread_"); |
|
30 |
|
31 const TInt KCsiDfcPriority = 0; // Arbitrary, can be 0-7, 7 highest |
|
32 const TInt KSpiThreadPriority = 24; |
|
33 |
|
34 // DCsiChannelMaster class declaration: |
|
35 class DCsiChannelMaster: public DIicBusChannelMaster |
|
36 { |
|
37 public: |
|
38 #ifdef STANDALONE_CHANNEL |
|
39 IMPORT_C |
|
40 #endif |
|
41 static DCsiChannelMaster* New(TInt aChannelNumber, const TBusType aBusType, const TChannelDuplex aChanDuplex); |
|
42 |
|
43 // gateway function for PSL implementation |
|
44 virtual TInt DoRequest(TIicBusTransaction* aTransaction); |
|
45 |
|
46 // overloaded constructor.. |
|
47 DCsiChannelMaster(TInt aChannelNumber, const TBusType aBusType, const TChannelDuplex aChanDuplex); |
|
48 #ifdef STANDALONE_CHANNEL |
|
49 ~DCsiChannelMaster(); |
|
50 #endif |
|
51 protected: |
|
52 // overriders for base pure-virtual methods.. |
|
53 virtual TInt DoCreate(); // 2nd stage construction. |
|
54 virtual TInt CheckHdr(TDes8* aHdr); |
|
55 virtual TInt HandleSlaveTimeout(); |
|
56 |
|
57 private: |
|
58 // other internal methods |
|
59 TInt ConfigureInterface(); |
|
60 TBool TransConfigDiffersFromPrev(); |
|
61 TInt DoTransfer(TInt8 *aBuff, TUint aNumOfBytes); |
|
62 TInt StartTransfer(TIicBusTransfer* aTransferPtr, TUint8 aType); |
|
63 TInt ProcessNextTransfers(); |
|
64 void ExitComplete(TInt aErr, TBool aComplete = ETrue); |
|
65 |
|
66 // Dfc/timeout Callback functions |
|
67 static void TransferEndDfc(TAny* aPtr); |
|
68 static void TransferTimeoutDfc(TAny* aPtr); |
|
69 static void TimeoutCallback(TAny* aPtr); |
|
70 |
|
71 // ISR handler. |
|
72 static void CsiIsr(TAny* aPtr); |
|
73 |
|
74 // DFc for Handling Transfer complete |
|
75 TDfc iTransferEndDfc; |
|
76 |
|
77 // flags indicating transmission/operation |
|
78 TCsiOperationType iOperation; |
|
79 |
|
80 // granularity.. |
|
81 TUint8 iWordSize; |
|
82 |
|
83 // to store currently used CS pin number |
|
84 TUint8 iSSPin; |
|
85 |
|
86 // current state |
|
87 enum TMyState |
|
88 { |
|
89 EIdle, |
|
90 EBusy |
|
91 }; |
|
92 TMyState iState; |
|
93 |
|
94 // as implementation is common/generic for both channels |
|
95 // store base register address and interruptID |
|
96 TUint iChannelBase; |
|
97 TInt iInterruptId; |
|
98 |
|
99 // pointers used to store current transfers information |
|
100 TIicBusTransfer* iHalfDTransfer; |
|
101 TIicBusTransfer* iFullDTransfer; |
|
102 |
|
103 // and current transaction. |
|
104 TIicBusTransaction* iCurrTransaction; |
|
105 |
|
106 // pointers to buffers used to transfer data from/to... |
|
107 TInt8 *iTxData; |
|
108 TInt8 *iRxData; |
|
109 TInt8 *iTxDataEnd; |
|
110 TInt8 *iRxDataEnd; |
|
111 |
|
112 // Timer to guard 'while' loops.. |
|
113 NTimer iHwGuardTimer; |
|
114 // guard-timer timeout value (in ms) |
|
115 TInt32 iHwTimeoutValue; |
|
116 |
|
117 // status of the transaction |
|
118 volatile TInt iTransactionStatus; |
|
119 |
|
120 // to store current configuration (for current transaction) |
|
121 TConfigSpiV01 iSpiHeader; |
|
122 |
|
123 // and its active/inactive state (can be active on high or low) |
|
124 GPIO::TGpioState iSSPinActiveStateOff; |
|
125 GPIO::TGpioState iSSPinActiveStateOn; |
|
126 |
|
127 // if the Master is a part of DIicBusChannelMasterSlave object, |
|
128 // we allow the friend class to unbind master's ISR - and register its own |
|
129 // for the time the channel is captured by the Slave. |
|
130 friend class DCsiChannelSlave; |
|
131 }; |
|
132 |
|
133 #endif //__CSI_MASTER_H_ |