author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 31 Mar 2010 23:38:45 +0300 | |
branch | RCL_3 |
changeset 87 | 2f92ad2dc5db |
parent 62 | 4a8fed1c0ef6 |
child 200 | 73ea206103e6 |
child 249 | a179b74831c9 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1999-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 |
// |
|
15 |
||
16 |
#include <drivers/sdcard.h> |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
17 |
#include "OstTraceDefinitions.h" |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
18 |
#ifdef OST_TRACE_COMPILER_IN_USE |
62
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
19 |
#include "../../../../include/drivers/locmedia_ost.h" |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
20 |
#ifdef __VC32__ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
21 |
#pragma warning(disable: 4127) // disabling warning "conditional expression is constant" |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
22 |
#endif |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
23 |
#include "sdcardTraces.h" |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
24 |
#endif |
0 | 25 |
|
26 |
||
27 |
// ======== TSDCard ======== |
|
28 |
||
29 |
TSDCard::TSDCard() |
|
30 |
: iProtectedAreaSize(0), iPARootDirEnd(KPARootDirEndUnknown) |
|
31 |
{ |
|
32 |
// empty |
|
33 |
} |
|
34 |
||
35 |
TInt64 TSDCard::DeviceSize64() const |
|
36 |
// |
|
37 |
// returns the SD device size |
|
38 |
// |
|
39 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
40 |
OstTraceFunctionEntry1( TSDCARD_DEVICESIZE64_ENTRY, this ); |
0 | 41 |
if(iFlags & KSDCardIsSDCard) |
42 |
{ |
|
43 |
return (IsHighCapacity()) ? 512 * 1024 * (TInt64)(1 + CSD().CSDField(69, 48)) : TMMCard::DeviceSize64(); |
|
44 |
} |
|
45 |
||
46 |
return(TMMCard::DeviceSize64()); |
|
47 |
} |
|
48 |
||
49 |
TUint32 TSDCard::PreferredWriteGroupLength() const |
|
50 |
// |
|
51 |
// return SD erase sector size, (SECTOR_SIZE + 1) * 2 ** WRITE_BLK_LEN |
|
52 |
// |
|
53 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
54 |
OstTraceFunctionEntry1( TSDCARD_PREFERREDWRITEGROUPLENGTH_ENTRY, this ); |
0 | 55 |
if(iFlags & KSDCardIsSDCard) |
56 |
{ |
|
57 |
TSDCSD sdcsd(CSD()); |
|
58 |
return (sdcsd.SDSectorSize() + 1) * (1 << sdcsd.WriteBlLen()); |
|
59 |
} |
|
60 |
||
61 |
return(TMMCard::PreferredWriteGroupLength()); |
|
62 |
} |
|
63 |
||
64 |
TInt TSDCard::GetFormatInfo(TLDFormatInfo& /*aFormatInfo*/) const |
|
65 |
{ |
|
66 |
return KErrNotSupported; |
|
67 |
} |
|
68 |
||
69 |
TUint32 TSDCard::MinEraseSectorSize() const |
|
70 |
{ |
|
71 |
if(iFlags&KSDCardIsSDCard) |
|
72 |
{ |
|
73 |
TSDCSD sdcsd(CSD()); |
|
74 |
if (sdcsd.SDEraseBlkEn()) |
|
75 |
return sdcsd.WriteBlockLength(); // raised logarithm |
|
76 |
else |
|
77 |
return (sdcsd.SDSectorSize() + 1) * sdcsd.WriteBlockLength(); |
|
78 |
} |
|
79 |
||
80 |
return TMMCard::MinEraseSectorSize(); |
|
81 |
} |
|
82 |
||
83 |
||
84 |
const TUint32 KEraseSectorSizeShift = 8; // KEraseSectorSizeShift determines the multiple of the sector size |
|
85 |
// that can be erased in one operation |
|
86 |
TUint32 TSDCard::EraseSectorSize() const |
|
87 |
{ |
|
88 |
if(iFlags&KSDCardIsSDCard) |
|
89 |
{ |
|
90 |
TSDCSD sdcsd(CSD()); |
|
91 |
return ((sdcsd.SDSectorSize() + 1) * sdcsd.WriteBlockLength()) << KEraseSectorSizeShift; |
|
92 |
} |
|
93 |
||
94 |
return TMMCard::EraseSectorSize(); |
|
95 |
} |
|
96 |
||
97 |
const TInt KDefaultBlockLen = 9; // 2^9 = 512 bytes |
|
98 |
const TInt KDefaultBlockLenInBytes = 1 << KDefaultBlockLen; // 2^9 = 512 bytes |
|
99 |
const TInt KTwoGbyteSDBlockLen = 10; // 2^10 = 1024 bytes |
|
100 |
const TInt KFourGbyteSDBlockLen = 11; // 2^11 = 2048 bytes |
|
101 |
||
102 |
TInt TSDCard::GetEraseInfo(TMMCEraseInfo& aEraseInfo) const |
|
103 |
// |
|
104 |
// Return info. on erase services for this card |
|
105 |
// |
|
106 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
OstTraceFunctionEntry1( TSDCARD_GETERASEINFO_ENTRY, this ); |
0 | 108 |
|
109 |
// SD Controllers support MMC cards too. Check if we are really dealing with an SD card |
|
110 |
if(!(iFlags&KSDCardIsSDCard)) |
|
111 |
return(TMMCard::GetEraseInfo(aEraseInfo)); |
|
112 |
||
113 |
if (CSD().CCC() & KMMCCmdClassErase) |
|
114 |
{ |
|
115 |
// This card supports erase cmds. However, SD cards don't support Erase Group commands (i.e. CMD35, CMD36). |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
OstTrace0( TRACE_INTERNALS, TSDCARD_GETERASEINFO, "Card supports erase class commands" ); |
0 | 117 |
aEraseInfo.iEraseFlags=KMMCEraseClassCmdsSupported; |
118 |
||
119 |
// Return the preferred size to be used as the unit for erase operations. |
|
120 |
TSDCSD sdcsd(CSD()); |
|
121 |
TUint32 prefSize=((sdcsd.SDSectorSize() + 1) * sdcsd.WriteBlockLength()); |
|
122 |
prefSize<<=KEraseSectorSizeShift; // Use multiples of the sector size for each erase operation |
|
123 |
aEraseInfo.iPreferredEraseUnitSize=prefSize; |
|
124 |
||
125 |
// Return the smallest size that can be used as the unit for erase operations |
|
126 |
if (sdcsd.SDEraseBlkEn()) |
|
127 |
{ |
|
128 |
aEraseInfo.iMinEraseSectorSize = KDefaultBlockLenInBytes; |
|
129 |
} |
|
130 |
else |
|
131 |
{ |
|
132 |
aEraseInfo.iMinEraseSectorSize=(sdcsd.SDSectorSize() + 1) * sdcsd.WriteBlockLength(); |
|
133 |
} |
|
134 |
} |
|
135 |
else |
|
136 |
aEraseInfo.iEraseFlags=0; |
|
137 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
OstTraceFunctionExitExt( TSDCARD_GETERASEINFO_EXIT, this, KErrNone ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
return KErrNone; |
0 | 140 |
} |
141 |
||
142 |
TInt TSDCard::MaxReadBlLen() const |
|
143 |
/** |
|
144 |
* Returns the maximum read block length supported by the card encoded as a logarithm |
|
145 |
* Normally this is the same as the READ_BL_LEN field in the CSD register, |
|
146 |
* but for high capacity cards (> 2GB) this is set to a maximum of 512 bytes, |
|
147 |
* if possible, to try to avoid compatibility issues. |
|
148 |
*/ |
|
149 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
OstTraceFunctionEntry1( TSDCARD_MAXREADBLLEN_ENTRY, this ); |
0 | 151 |
if (IsSDCard()) |
152 |
{ |
|
153 |
TInt blkLenLog2 = CSD().ReadBlLen(); |
|
154 |
if (blkLenLog2 == KTwoGbyteSDBlockLen || blkLenLog2 == KFourGbyteSDBlockLen) |
|
155 |
{ |
|
156 |
// The SD card spec. makes a special case for 2GByte cards, |
|
157 |
// ...and some manufacturers apply the same method to support 4G cards |
|
158 |
__KTRACE_OPT(KPBUS1, Kern::Printf("=mmc:mrbl > 2GB SD")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
OstTrace0( TRACE_INTERNALS, TSDCARD_MAXREADBLLEN, "SD Card > 2GB" ); |
0 | 160 |
blkLenLog2 = KDefaultBlockLen; |
161 |
} |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
OstTraceFunctionExitExt( TSDCARD_MAXREADBLLEN_EXIT, this, blkLenLog2 ); |
0 | 163 |
return blkLenLog2; |
164 |
} |
|
165 |
else // MMC card |
|
166 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
TInt ret = TMMCard::MaxReadBlLen(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
OstTraceFunctionExitExt( DUP1_TSDCARD_MAXREADBLLEN_EXIT, this, ret ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
return ret; |
0 | 170 |
} |
171 |
} |
|
172 |
||
173 |
TInt TSDCard::MaxWriteBlLen() const |
|
174 |
/** |
|
175 |
* Returns the maximum write block length supported by the card encoded as a logarithm |
|
176 |
* Normally this is the same as the WRITE_BL_LEN field in the CSD register, |
|
177 |
* but for high capacity cards (> 2GB) this is set to a maximum of 512 bytes, |
|
178 |
* if possible, to try to avoid compatibility issues. |
|
179 |
*/ |
|
180 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
OstTraceFunctionEntry1( TSDCARD_MAXWRITEBLLEN_ENTRY, this ); |
0 | 182 |
if (IsSDCard()) |
183 |
{ |
|
184 |
TInt blkLenLog2 = CSD().WriteBlLen(); |
|
185 |
if (blkLenLog2 == KTwoGbyteSDBlockLen || blkLenLog2 == KFourGbyteSDBlockLen) |
|
186 |
{ |
|
187 |
// The SD card spec. makes a special case for 2GByte cards, |
|
188 |
// ...and some manufacturers apply the same method to support 4G cards |
|
189 |
__KTRACE_OPT(KPBUS1, Kern::Printf("=mmc:mwbl > 2GB SD")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
OstTrace0( TRACE_INTERNALS, TSDCARD_MAXWRITEBLLEN, "SD Card > 2GB" ); |
0 | 191 |
blkLenLog2 = KDefaultBlockLen; |
192 |
} |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
OstTraceFunctionExitExt( TSDCARD_MAXWRITEBLLEN_EXIT, this, blkLenLog2 ); |
0 | 194 |
return blkLenLog2; |
195 |
} |
|
196 |
else // MMC card |
|
197 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
198 |
TInt ret = TMMCard::MaxWriteBlLen(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
OstTraceFunctionExitExt( DUP1_TSDCARD_MAXWRITEBLLEN_EXIT, this, ret ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
return ret; |
0 | 201 |
} |
202 |
} |
|
203 |
||
204 |
TUint TSDCard::MaxTranSpeedInKilohertz() const |
|
205 |
/** |
|
206 |
* Returns the maximum supported clock rate for the card, in Kilohertz. |
|
207 |
* @return Speed, in Kilohertz |
|
208 |
*/ |
|
209 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
210 |
OstTraceFunctionEntry1( TSDCARD_MAXTRANSPEEDINKILOHERTZ_ENTRY, this ); |
0 | 211 |
TUint maxClk = TMMCard::MaxTranSpeedInKilohertz(); |
212 |
||
213 |
if (IsSDCard()) |
|
214 |
{ |
|
215 |
__KTRACE_OPT(KPBUS1, Kern::Printf("\t >TSDCard(%d): MaxTranSpeedInKilohertz: %d",(iIndex-1),maxClk)); |
|
216 |
||
217 |
#ifdef _DEBUG |
|
218 |
//MaxClk for SD should only be either 25000KHz or 50000KHz |
|
219 |
if ( (maxClk != KSDDTClk25MHz) && (maxClk != KSDDTClk50MHz) ) |
|
220 |
{ |
|
221 |
__KTRACE_OPT(KPBUS1, Kern::Printf("\t >DSDStack: Non-Compliant DT Clock")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
OstTrace0( TRACE_INTERNALS, TSDCARD_MAXTRANSPEEDINKILOHERTZ, "Non-Compliant DT Clock" ); |
0 | 223 |
} |
224 |
#endif |
|
225 |
if (maxClk > KSDDTClk50MHz) |
|
226 |
{ |
|
227 |
//Clock rate exceeds SD possible max clock rate |
|
228 |
__KTRACE_OPT(KPBUS1, Kern::Printf("\t >DSDStack: Tuning DT Clock down to 50MHz")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
229 |
OstTrace0( TRACE_INTERNALS, TSDCARD_MAXTRANSPEEDINKILOHERTZ1, "Tuning DT Clock down to 50MHz" ); |
0 | 230 |
maxClk = KSDDTClk50MHz; |
231 |
} |
|
232 |
} |
|
233 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
234 |
OstTraceFunctionExitExt( TSDCARD_MAXTRANSPEEDINKILOHERTZ_EXIT, this, maxClk ); |
0 | 235 |
return maxClk; |
236 |
} |
|
237 |
||
238 |
// ======== TSDCardArray ======== |
|
239 |
||
240 |
EXPORT_C TInt TSDCardArray::AllocCards() |
|
241 |
// |
|
242 |
// allocate TSDCard objects for iCards and iNewCardsArray. This function |
|
243 |
// is called at bootup as part of stack allocation so there is no cleanup |
|
244 |
// if it fails. |
|
245 |
// |
|
246 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
OstTraceFunctionEntry1( TSDCARDARRAY_ALLOCCARDS_ENTRY, this ); |
0 | 248 |
for (TInt i = 0; i < (TInt) KMaxMMCardsPerStack; ++i) |
249 |
{ |
|
250 |
// zeroing the card data used to be implicit because embedded in |
|
251 |
// CBase-derived DMMCStack. |
|
252 |
if ((iCards[i] = new TSDCard) == 0) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
OstTraceFunctionExitExt( TSDCARDARRAY_ALLOCCARDS_EXIT, this, KErrNoMemory ); |
0 | 255 |
return KErrNoMemory; |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
} |
0 | 257 |
iCards[i]->iUsingSessionP = 0; |
258 |
if ((iNewCards[i] = new TSDCard) == 0) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
OstTraceFunctionExitExt( DUP1_TSDCARDARRAY_ALLOCCARDS_EXIT, this, KErrNoMemory ); |
0 | 261 |
return KErrNoMemory; |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
} |
0 | 263 |
} |
264 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
OstTraceFunctionExitExt( DUP2_TSDCARDARRAY_ALLOCCARDS_EXIT, this, KErrNone ); |
0 | 266 |
return KErrNone; |
267 |
} |
|
268 |
||
269 |
void TSDCardArray::AddCardSDMode(TUint aCardNumber,const TUint8* aCID,TRCA* aNewRCA) |
|
270 |
// |
|
271 |
// Add an MMC card straight to the main card array in slot 'aCardNumber'. Save |
|
272 |
// the CID value in the slot. Return a RCA for the card. |
|
273 |
// |
|
274 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
OstTraceFunctionEntryExt( TSDCARDARRAY_ADDCARDSDMODE_ENTRY, this ); |
0 | 276 |
|
277 |
TRCA rca=0; |
|
278 |
||
279 |
// First, lets check if the same card was here before. If it was, keep the same RCA |
|
280 |
if (Card(aCardNumber).IsPresent() && Card(aCardNumber).iCID==aCID) |
|
281 |
rca=Card(aCardNumber).iRCA; |
|
282 |
else |
|
283 |
{ |
|
284 |
// Allocate and new RCA and store the CID in the slot selected |
|
285 |
__ASSERT_ALWAYS( (rca=iOwningStack->iRCAPool.GetFreeRCA())!=0,DMMCSocket::Panic(DMMCSocket::EMMCNoFreeRCA) ); |
|
286 |
Card(aCardNumber).iCID=aCID; |
|
287 |
if ( Card(aCardNumber).iRCA != 0 ) |
|
288 |
iOwningStack->iRCAPool.UnlockRCA(Card(aCardNumber).iRCA); |
|
289 |
Card(aCardNumber).iRCA=rca; |
|
290 |
iOwningStack->iRCAPool.LockRCA(Card(aCardNumber).iRCA); |
|
291 |
} |
|
292 |
||
293 |
Card(aCardNumber).iIndex=(aCardNumber+1); // Mark card as being present |
|
294 |
*aNewRCA=rca; |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
295 |
OstTraceFunctionExit1( TSDCARDARRAY_ADDCARDSDMODE_EXIT, this ); |
0 | 296 |
} |
297 |
||
298 |
TInt TSDCardArray::StoreRCAIfUnique(TUint aCardNumber,TRCA& anRCA) |
|
299 |
// |
|
300 |
// Check that no other array element has the same RCA value 'anRCA'. If no |
|
301 |
// no duplication then store in slot 'aCardNumber'. |
|
302 |
// |
|
303 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
304 |
OstTraceExt3(TRACE_FLOW, TSDCARDARRAY_STORERCAIFUNIQUE_ENTRY ,"TSDCardArray::StoreRCAIfUnique;aCardNumber=%x;anRCA=%x;this=%x", aCardNumber, (TUint) anRCA, (TUint) this); |
0 | 305 |
|
306 |
if (anRCA==0) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
307 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
308 |
OstTraceFunctionExitExt( TSDCARDARRAY_STORERCAIFUNIQUE_EXIT, this, KErrGeneral ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
309 |
return KErrGeneral; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
310 |
} |
0 | 311 |
Card(aCardNumber).iRCA=0; |
312 |
||
313 |
// Now let's look if we've seen this card before |
|
314 |
for ( TUint i=0 ; i<iOwningStack->iMaxCardsInStack ; i++ ) |
|
315 |
{ |
|
316 |
if ( Card(i).IsPresent() && Card(i).iRCA==anRCA ) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
OstTraceFunctionExitExt( DUP1_TSDCARDARRAY_STORERCAIFUNIQUE_EXIT, this, KErrInUse ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
319 |
return KErrInUse; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
} |
0 | 321 |
} |
322 |
Card(aCardNumber).iRCA=anRCA; |
|
323 |
Card(aCardNumber).iIndex=(aCardNumber+1); // Mark card as being present |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
324 |
OstTraceFunctionExitExt( DUP2_TSDCARDARRAY_STORERCAIFUNIQUE_EXIT, this, KErrNone ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
325 |
return KErrNone; |
0 | 326 |
} |
327 |
||
328 |
EXPORT_C void TSDCardArray::DeclareCardAsGone(TUint aCardNumber) |
|
329 |
// |
|
330 |
// reset SD specific fields to initial values and then reset generic MultiMediaCard |
|
331 |
// |
|
332 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
OstTraceFunctionEntryExt( TSDCARDARRAY_DECLARECARDASGONE_ENTRY, this ); |
0 | 334 |
Card(aCardNumber).SetBusWidth(1); |
335 |
TMMCardArray::DeclareCardAsGone(aCardNumber); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
336 |
OstTraceFunctionExit1( TSDCARDARRAY_DECLARECARDASGONE_EXIT, this ); |
0 | 337 |
} |
338 |
||
339 |
// ======== DSDSession ======== |
|
340 |
||
341 |
void DSDSession::FillAppCommandDesc(TMMCCommandDesc& aDesc, TSDAppCmd aCmd) |
|
342 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
343 |
OstTraceFunctionEntry0( DSDSESSION_FILLAPPCOMMANDDESC_ENTRY ); |
0 | 344 |
aDesc.iCommand = (TMMCCommandEnum) aCmd; |
345 |
aDesc.iArgument = 0; // set stuff bits to zero |
|
346 |
FillAppCommandDesc(aDesc); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
347 |
OstTraceFunctionExit0( DSDSESSION_FILLAPPCOMMANDDESC_EXIT ); |
0 | 348 |
} |
349 |
||
350 |
void DSDSession::FillAppCommandDesc(TMMCCommandDesc& aDesc, TSDAppCmd aCmd, TMMCArgument aArg) |
|
351 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
OstTraceFunctionEntry0( DUP1_DSDSESSION_FILLAPPCOMMANDDESC_ENTRY ); |
0 | 353 |
aDesc.iCommand = (TMMCCommandEnum) aCmd; |
354 |
aDesc.iArgument = aArg; |
|
355 |
FillAppCommandDesc(aDesc); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
356 |
OstTraceFunctionExit0( DUP1_DSDSESSION_FILLAPPCOMMANDDESC_EXIT ); |
0 | 357 |
} |
358 |
||
359 |
const TUint32 CCA = KMMCCmdClassApplication; |
|
360 |
const TMMCIdxCommandSpec AppCmdSpecTable[] = |
|
361 |
{ // Class Type Dir MBlk StopT Rsp Type Len |
|
362 |
{ESDACmdSetBusWidth, {CCA,ECmdTypeACS, EDirNone, EFalse, EFalse, ERespTypeR1, 4}}, //ACMD6 |
|
363 |
{ESDACmdSDStatus, {CCA,ECmdTypeADTCS, EDirRead, EFalse, EFalse, ERespTypeR1, 4}}, //ACMD13 |
|
364 |
{ESDACmdSendNumWrBlocks, {CCA,ECmdTypeADTCS, EDirRead, EFalse, EFalse, ERespTypeR1, 4}}, //ACMD22 |
|
365 |
{ESDACmdSetWrBlkEraseCount, {CCA,ECmdTypeACS, EDirNone, EFalse, EFalse, ERespTypeR1, 4}}, //ACMD23 |
|
366 |
{ESDACmdSDAppOpCond, {CCA,ECmdTypeBCR, EDirNone, EFalse, EFalse, ERespTypeR3, 4}}, //ACMD41 |
|
367 |
{ESDACmdSetClrCardDetect, {CCA,ECmdTypeAC, EDirNone, EFalse, EFalse, ERespTypeR1, 4}}, //ACMD42 |
|
368 |
{ESDACmdSendSCR, {CCA,ECmdTypeADTCS, EDirRead, EFalse, EFalse, ERespTypeR1, 4}} //ACMD51 |
|
369 |
}; |
|
370 |
||
371 |
void DSDSession::FillAppCommandDesc(TMMCCommandDesc& aDesc) |
|
372 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
373 |
OstTraceFunctionEntry0( DUP2_DSDSESSION_FILLAPPCOMMANDDESC_ENTRY ); |
0 | 374 |
aDesc.iSpec = FindCommandSpec(AppCmdSpecTable, aDesc.iCommand); |
375 |
aDesc.iFlags = 0; |
|
376 |
aDesc.iBytesDone = 0; |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
377 |
OstTraceFunctionExit0( DUP2_DSDSESSION_FILLAPPCOMMANDDESC_EXIT ); |
0 | 378 |
} |
379 |
||
380 |
const TMMCIdxCommandSpec SdSpecificCmdSpecTable[] = |
|
381 |
/** |
|
382 |
* SD Specific Command Table |
|
383 |
* |
|
384 |
* - Some commands defined in the SD specification overload those defined in the MMC specification. |
|
385 |
* This table contains the SD specific versions of those commands. |
|
386 |
*/ |
|
387 |
{ |
|
388 |
// Class Type Dir MBlk StopT Rsp Type Len |
|
389 |
{ESDCmdSendRelativeAddress, {KMMCCmdClassBasic, ECmdTypeBCR, EDirNone, EFalse, EFalse, ERespTypeR6, 4}}, // CMD3 : SEND_RELATIVE_ADDRESS |
|
390 |
{ESDCmdSwitchFunction, {KMMCCmdClassSwitch,ECmdTypeADTCS, EDirRead, EFalse, EFalse, ERespTypeR1, 4}}, // CMD6 : SWITCH_FUNCTION |
|
391 |
{ESDCmdSendIfCond, {KMMCCmdClassBasic, ECmdTypeBCR, EDirNone, EFalse, EFalse, ERespTypeR7, 4}} // CMD8 : SEND_IF_COND |
|
392 |
}; |
|
393 |
||
394 |
void DSDSession::FillSdSpecificCommandDesc(TMMCCommandDesc& aDesc, TSDSpecificCmd aCmd, TMMCArgument aArg) |
|
395 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
OstTraceFunctionEntry0( DSDSESSION_FILLSDSPECIFICCOMMANDDESC_ENTRY ); |
0 | 397 |
aDesc.iCommand = (TMMCCommandEnum) aCmd; |
398 |
aDesc.iArgument = aArg; |
|
399 |
FillSdSpecificCommandDesc(aDesc); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
OstTraceFunctionExit0( DSDSESSION_FILLSDSPECIFICCOMMANDDESC_EXIT ); |
0 | 401 |
} |
402 |
||
403 |
void DSDSession::FillSdSpecificCommandDesc(TMMCCommandDesc& aDesc, TSDSpecificCmd aCmd) |
|
404 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
OstTraceFunctionEntry0( DUP1_DSDSESSION_FILLSDSPECIFICCOMMANDDESC_ENTRY ); |
0 | 406 |
aDesc.iCommand = (TMMCCommandEnum) aCmd; |
407 |
aDesc.iArgument = 0; // set stuff bits to zero |
|
408 |
FillSdSpecificCommandDesc(aDesc); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
OstTraceFunctionExit0( DUP1_DSDSESSION_FILLSDSPECIFICCOMMANDDESC_EXIT ); |
0 | 410 |
} |
411 |
||
412 |
void DSDSession::FillSdSpecificCommandDesc(TMMCCommandDesc& aDesc) |
|
413 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
OstTraceFunctionEntry0( DUP2_DSDSESSION_FILLSDSPECIFICCOMMANDDESC_ENTRY ); |
0 | 415 |
aDesc.iSpec = FindCommandSpec(SdSpecificCmdSpecTable, aDesc.iCommand); |
416 |
aDesc.iFlags = 0; |
|
417 |
aDesc.iBytesDone = 0; |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
418 |
OstTraceFunctionExit0( DUP2_DSDSESSION_FILLSDSPECIFICCOMMANDDESC_EXIT ); |
0 | 419 |
} |
420 |
||
421 |
||
422 |
// ======== DSDStack ======== |
|
423 |
||
424 |
EXPORT_C TInt DSDStack::Init() |
|
425 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
426 |
OstTraceFunctionEntry1( DSDSTACK_INIT_ENTRY, this ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
427 |
TInt ret = DMMCStack::Init(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
428 |
OstTraceFunctionExitExt( DSDSTACK_INIT_EXIT, this, ret ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
return ret; |
0 | 430 |
} |
431 |
||
432 |
||
433 |
const TInt KMaxRCASendLoops=3; |
|
434 |
const TUint KSDMaxPollAttempts=25; |
|
435 |
EXPORT_C TMMCErr DSDStack::AcquireStackSM() |
|
436 |
// |
|
437 |
// This macro acquires new cards in an SD Card - star topology stack. |
|
438 |
// This means each card has its own CMD and DAT lines and can be addressed |
|
439 |
// individually by the Controller in turn. Commands can also be broadcast |
|
440 |
// simultaneously to the entire stack. |
|
441 |
// It starts with the Controller reading the operating conditions of each |
|
442 |
// card in the stack (SEND_OP_COND - ACMD41). Then, the following |
|
443 |
// initialisation sequence is performed to each card in turn:- |
|
444 |
// New cards in the stack are identified (ALL_SEND_CID - CMD2) and each one |
|
445 |
// is requested to publish a relative card address (SEND_RCA - CMD3). Finally, |
|
446 |
// the card specific data (SEND_CSD - CMD9) is read from each card. |
|
447 |
// Note that the initialization of MMC cards are supported by this function |
|
448 |
// if they are encountered. These require a slightly different init. procdure. |
|
449 |
// |
|
450 |
{ |
|
451 |
enum states |
|
452 |
{ |
|
453 |
EStBegin=0, |
|
454 |
EStNextFullRange, |
|
455 |
EStSendCIDIssued, |
|
456 |
EStIssueSendRCA, |
|
457 |
EStSendRCACheck, |
|
458 |
EStRCADone, |
|
459 |
EStMoreCardsCheck, |
|
460 |
EStEnd |
|
461 |
}; |
|
462 |
||
463 |
DMMCSession& s=Session(); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
464 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_ATTACHCARDSM, "Current session = 0x%x", &s ); |
0 | 465 |
|
466 |
SMF_BEGIN |
|
467 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_ATTACHCARDSM1, "EStBegin" ); |
0 | 469 |
__KTRACE_OPT(KPBUS1, Kern::Printf(">DSDStack::AcquireStackSM()")); |
470 |
||
471 |
iRCAPool.ReleaseUnlocked(); |
|
472 |
iCxCardCount=0; // Reset current card number |
|
473 |
||
474 |
SMF_STATE(EStNextFullRange) |
|
475 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
476 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_ATTACHCARDSM2, "EStNextFullRange" ); |
0 | 477 |
iCxCardType = ESDCardTypeUnknown; |
478 |
||
479 |
AddressCard(iCxCardCount); // Address the next card |
|
480 |
||
481 |
// Before issueing commands, see if there's actually a card present |
|
482 |
if (!CardDetect(iCxCardCount)) |
|
483 |
SMF_GOTOS(EStMoreCardsCheck) |
|
87
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
484 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
485 |
// Card Previously Marked as Corrupt do not re-initialise |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
486 |
if ((CardArray().CardP(iCxCardCount)->iFlags)& KSDCardIsCorrupt) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
487 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
488 |
SMF_GOTOS(EStMoreCardsCheck) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
489 |
} |
0 | 490 |
|
491 |
m.SetTraps(KMMCErrResponseTimeOut); |
|
492 |
SMF_INVOKES(InitialiseMemoryCardSMST, EStSendCIDIssued) |
|
493 |
||
494 |
SMF_STATE(EStSendCIDIssued) |
|
495 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
496 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_ATTACHCARDSM3, "EStSendCIDIssued" ); |
0 | 497 |
if( !err ) |
498 |
{ |
|
499 |
// The card responded with a CID. We need to initialise the |
|
500 |
// appropriate entry in the card array with the CID. |
|
501 |
if (iCxCardType==ESDCardTypeIsSD) |
|
502 |
{ |
|
503 |
// Now prepare to recieve an RCA from to the card |
|
504 |
CardArray().CardP(iCxCardCount)->iCID=s.ResponseP(); |
|
505 |
DSDSession::FillSdSpecificCommandDesc(Command(), ESDCmdSendRelativeAddress,0); // SEND_RCA with argument just stuff bits |
|
506 |
||
507 |
m.ResetTraps(); |
|
508 |
iCxPollRetryCount=0; // Init count of send RCA attempts |
|
509 |
SMF_GOTOS(EStIssueSendRCA) |
|
510 |
} |
|
511 |
else |
|
512 |
{ |
|
513 |
// The card array allocates an RCA, either the old RCA |
|
514 |
// if we have seen this card before, or a new one. |
|
515 |
TRCA rca; |
|
516 |
CardArray().AddCardSDMode(iCxCardCount,s.ResponseP(),&rca); |
|
517 |
||
518 |
// Now assign the new RCA to the card |
|
519 |
s.FillCommandDesc(ECmdSetRelativeAddr,TMMCArgument(rca)); |
|
520 |
m.ResetTraps(); |
|
521 |
SMF_INVOKES(ExecCommandSMST,EStRCADone) |
|
522 |
} |
|
523 |
} |
|
524 |
else |
|
525 |
{ |
|
526 |
m.ResetTraps(); |
|
527 |
SMF_GOTOS(EStMoreCardsCheck) // Timed out, try the next card slot |
|
528 |
} |
|
529 |
||
530 |
SMF_STATE(EStIssueSendRCA) |
|
531 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
532 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_ATTACHCARDSM4, "EStIssueSendRCA" ); |
0 | 533 |
SMF_INVOKES(ExecCommandSMST,EStSendRCACheck) |
534 |
||
535 |
SMF_STATE(EStSendRCACheck) |
|
536 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
537 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_ATTACHCARDSM5, "EStSendRCACheck" ); |
0 | 538 |
// We need to check that the RCA recieved from the card doesn't clash |
539 |
// with any others in this stack. RCA is first 2 bytes of response buffer (in big endian) |
|
540 |
TRCA rca=(TUint16)((s.ResponseP()[0]<<8) | s.ResponseP()[1]); |
|
541 |
if (CardArray().StoreRCAIfUnique(iCxCardCount,rca)!=KErrNone) |
|
542 |
SMF_GOTOS( ((++iCxPollRetryCount<KMaxRCASendLoops)?EStIssueSendRCA:EStMoreCardsCheck) ) |
|
543 |
||
544 |
SMF_STATE(EStRCADone) |
|
545 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
546 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_ATTACHCARDSM6, "EStRCADone" ); |
0 | 547 |
SMF_INVOKES(ConfigureMemoryCardSMST, EStMoreCardsCheck) |
548 |
||
549 |
SMF_STATE(EStMoreCardsCheck) |
|
550 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
551 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_ATTACHCARDSM7, "EStMoreCardsCheck" ); |
0 | 552 |
if (++iCxCardCount < (TInt)iMaxCardsInStack) |
553 |
{ |
|
554 |
__KTRACE_OPT(KPBUS1, Kern::Printf(">DSDStack::AcquireStackSM(): More Cards to check: %d",iCxCardCount)); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
555 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_ACQUIRESTACKSM8, "More Cards to check: iCxCardCount=%d", iCxCardCount ); |
0 | 556 |
SMF_GOTOS(EStNextFullRange) |
557 |
} |
|
558 |
else |
|
559 |
{ |
|
560 |
AddressCard(KBroadcastToAllCards); // Set back to broadcast mode |
|
561 |
__KTRACE_OPT(KPBUS1, Kern::Printf("<DSDStack::AcquireStackSM()")); |
|
562 |
} |
|
563 |
||
564 |
SMF_END |
|
565 |
} |
|
566 |
||
567 |
||
568 |
TMMCErr DSDStack::InitialiseMemoryCardSMST(TAny* aStackP) |
|
569 |
{ return static_cast<DSDStack*>(aStackP)->InitialiseMemoryCardSM(); } |
|
570 |
||
571 |
||
572 |
TMMCErr DSDStack::InitialiseMemoryCardSM() |
|
573 |
/** |
|
574 |
*/ |
|
575 |
{ |
|
576 |
enum states |
|
577 |
{ |
|
578 |
EStBegin=0, |
|
579 |
EStSendInterfaceCondition, |
|
580 |
EStSentInterfaceCondition, |
|
581 |
EStSetFullRangeCmd, |
|
582 |
EStCheckForFullRangeCmd41Timeout, |
|
583 |
EStSentAppCommandBeforeCheckVoltage, |
|
584 |
EStCheckVoltage, |
|
585 |
EStFullRangeDone, |
|
586 |
EStSetRangeCmd, |
|
587 |
EStCheckForRangeCmd41Timeout, |
|
588 |
EStSetRangeBusyCheck, |
|
589 |
EStCIDCmd, |
|
590 |
EStSendCIDIssued, |
|
591 |
EStEnd |
|
592 |
}; |
|
593 |
||
594 |
DMMCSession& s=Session(); |
|
595 |
DMMCPsu* psu=(DMMCPsu*)MMCSocket()->iVcc; |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
596 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM, "Current session = 0x%x", &s ); |
0 | 597 |
|
598 |
static const TUint32 KCmd8Param = 0x0100 | 0x00AA; // Voltage supplied : 2.7-3.6V, Check Pattern 10101010b |
|
599 |
static const TUint32 KCmd8CheckMask = 0x00000FFF; |
|
600 |
||
601 |
SMF_BEGIN |
|
602 |
||
62
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
603 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM1, "EStBegin" ); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
604 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
605 |
iCxCardType = CardType(MMCSocket()->iSocketNumber, iCxCardCount); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
606 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
607 |
if (iCxCardType==ESDCardTypeIsMMC) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
608 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
609 |
// Skip the SD Protocol Seq. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
610 |
SMF_INVOKES(GoIdleSMST, EStCheckVoltage); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
611 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
612 |
|
0 | 613 |
s.iCardP = NULL; // This stops ExecCommandSM() from setting old RCA when sending CMD55 |
614 |
||
615 |
// Send CMD0 to initialise memory |
|
616 |
SMF_INVOKES(GoIdleSMST, EStSendInterfaceCondition); |
|
617 |
||
618 |
SMF_STATE(EStSendInterfaceCondition) |
|
619 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
620 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM2, "EStSendInterfaceCondition" ); |
0 | 621 |
iCxPollRetryCount=0; // Reset max number of poll attempts on card busy |
622 |
iConfig.SetPollAttempts(KSDMaxPollAttempts); // Increase card busy timeout to 1 Sec for SD Cards |
|
623 |
||
624 |
iConfig.RemoveMode( KMMCModeEnableTimeOutRetry ); // Temporarily disable timeout retries - since we use a timeout event to distinguish between MMC and SD |
|
625 |
||
626 |
DSDSession::FillSdSpecificCommandDesc(Command(), ESDCmdSendIfCond, KCmd8Param); |
|
627 |
||
628 |
// SD2.0 defines CMD8 as having a new response type - R7 |
|
629 |
// if the PSL doesn't indicate support for R7, use R1 instead |
|
630 |
if (!(MMCSocket()->MachineInfo().iFlags & TMMCMachineInfo::ESupportsR7)) |
|
631 |
{ |
|
632 |
__KTRACE_OPT(KPBUS1, Kern::Printf("R7 not supported.")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
633 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM3, "R7 not supported" ); |
0 | 634 |
Command().iSpec.iResponseType = ERespTypeR1; |
635 |
} |
|
636 |
||
637 |
||
638 |
m.SetTraps(KMMCErrAll); |
|
639 |
SMF_INVOKES(ExecCommandSMST, EStSentInterfaceCondition) |
|
640 |
||
641 |
SMF_STATE(EStSentInterfaceCondition) |
|
642 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
643 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM4, "EStSentInterfaceCondition" ); |
0 | 644 |
if (err == KMMCErrNone) |
645 |
{ |
|
646 |
// Check the response for voltage and check pattern |
|
647 |
const TUint32 status = TMMC::BigEndian32(s.ResponseP()); |
|
648 |
if((status & KCmd8CheckMask) == KCmd8Param) |
|
649 |
{ |
|
650 |
__KTRACE_OPT(KPBUS1, Kern::Printf("Found v2 card.")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
651 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM5, "Found v2 card" ); |
0 | 652 |
iCurrentOpRange |= KMMCOCRAccessModeHCS; |
653 |
} |
|
654 |
else |
|
655 |
{ |
|
656 |
// Pattern Mis-match, card does not support the specified voltage range |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
657 |
OstTraceFunctionExitExt( DSDSTACK_INITIALISEMEMORYCARDSM_EXIT, this, (TInt) KMMCErrNotSupported ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
658 |
return KMMCErrNotSupported; |
0 | 659 |
} |
660 |
||
661 |
SMF_GOTOS(EStCheckVoltage); |
|
662 |
} |
|
663 |
||
664 |
// Go idle again after CMD8 failure |
|
665 |
SMF_INVOKES(GoIdleSMST, EStCheckVoltage); |
|
666 |
||
667 |
||
668 |
SMF_STATE(EStCheckVoltage) |
|
669 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
670 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM6, "EStCheckVoltage" ); |
0 | 671 |
// If platform doesn't support an adjustable voltage PSU then there's no |
672 |
// point in doing a full range for its supported range. To support range |
|
673 |
// checking on a multi-card stack would require a complete scan of all |
|
674 |
// cards before actually setting the range. This would over-complicate things |
|
675 |
// and make the more normal single card/none adjustable cases less efficient. |
|
676 |
if ( !(psu->VoltageSupported()&KMMCAdjustableOpVoltage) || iMaxCardsInStack>1) |
|
677 |
{ |
|
678 |
// if the PSU isn't adjustable then it can't support low voltage mode |
|
679 |
iCurrentOpRange&= ~KMMCOCRLowVoltage; |
|
680 |
||
681 |
SMF_GOTOS(EStSetRangeCmd) |
|
682 |
} |
|
683 |
||
684 |
SMF_STATE(EStSetFullRangeCmd) |
|
685 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
686 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM7, "EStSetFullRangeCmd" ); |
0 | 687 |
// Issue ACMD41/CMD1 with omitted voltage range |
688 |
if (iCxCardType==ESDCardTypeIsMMC) |
|
689 |
{ |
|
690 |
s.FillCommandDesc(ECmdSendOpCond, KMMCOCRAccessModeHCS | KMMCOCRBusy); // Full range + Sector Access + Busy bit (iArgument==KBit31) |
|
691 |
SMF_NEXTS(EStFullRangeDone) |
|
692 |
} |
|
693 |
else |
|
694 |
{ |
|
695 |
DSDSession::FillAppCommandDesc(Command(), ESDACmdSDAppOpCond, TMMCArgument(0)); |
|
696 |
SMF_NEXTS(EStCheckForFullRangeCmd41Timeout) |
|
697 |
} |
|
698 |
||
699 |
m.SetTraps(KMMCErrResponseTimeOut); |
|
700 |
SMF_CALL(ExecCommandSMST) |
|
701 |
||
702 |
SMF_STATE(EStCheckForFullRangeCmd41Timeout) |
|
703 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
704 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM8, "EStCheckForFullRangeCmd41Timeout" ); |
0 | 705 |
if (err==KMMCErrResponseTimeOut) |
706 |
{ |
|
707 |
__KTRACE_OPT(KPBUS1, Kern::Printf("ACMD 41 not supported - Assuming MMC")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
708 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM9, "ACMD 41 not supported - Assuming MMC" ); |
0 | 709 |
iCxCardType=ESDCardTypeIsMMC; |
710 |
||
711 |
// Send CMD0 to re-initialise the card - otherwise we may get |
|
712 |
// KMMCStatErrIllegalCommand returned for the next command |
|
713 |
// expecting an R1 response. NB The SD spec recommends ignoring the error |
|
714 |
// whereas the SDIO spec recommends this approach (ignoring the error |
|
715 |
// would be difficult to code anyway, since by then we're no longer |
|
716 |
// in this state machine). |
|
717 |
SMF_INVOKES(GoIdleSMST, EStSetFullRangeCmd); // Repeat - but using CMD1 |
|
718 |
} |
|
719 |
else |
|
720 |
{ |
|
721 |
// No response timeout - so it must be an SD Card |
|
722 |
(CardArray().CardP(iCxCardCount)->iFlags)|=KSDCardIsSDCard; |
|
723 |
iCxCardType=ESDCardTypeIsSD; |
|
724 |
} |
|
725 |
||
726 |
SMF_STATE(EStFullRangeDone) |
|
727 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
728 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM10, "EStFullRangeDone" ); |
0 | 729 |
if (!err) |
730 |
{ |
|
731 |
// Card responded with Op range - evaluate the common subset with the current setting. |
|
732 |
// Dont worry about the busy bit for now, we'll check that when we repeat the command |
|
733 |
const TUint32 range = (iCurrentOpRange & ~KMMCOCRAccessModeHCS) & (TMMC::BigEndian32(s.ResponseP()) & ~KMMCOCRBusy); |
|
734 |
if(range == 0) |
|
735 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
736 |
OstTraceFunctionExitExt( DSDSTACK_INITIALISEMEMORYCARDSM_EXIT1, this, (TInt) KMMCErrNotSupported ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
737 |
return KMMCErrNotSupported; // Card is incompatible with our h/w |
0 | 738 |
} |
739 |
iCurrentOpRange = range | (iCurrentOpRange & KMMCOCRAccessModeHCS); |
|
740 |
} |
|
741 |
||
742 |
// Repeat SEND_OP_COND this time setting Current Op Range |
|
743 |
if (iCxCardType==ESDCardTypeIsMMC) |
|
744 |
{ |
|
745 |
// If platform and the card both support low voltage mode (1.65 - 1.95v), switch |
|
746 |
// NB If this fails then there is no recovery. |
|
747 |
if (iCurrentOpRange & KMMCOCRLowVoltage) |
|
748 |
{ |
|
749 |
iCurrentOpRange = KMMCOCRLowVoltage; |
|
750 |
SMF_INVOKES( SwitchToLowVoltageSMST, EStSetRangeCmd ) |
|
751 |
} |
|
752 |
} |
|
753 |
||
754 |
SMF_STATE(EStSetRangeCmd) |
|
755 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM11, "EStSetRangeCmd" ); |
0 | 757 |
// Issue ACMD41/CMD1 with voltage range |
758 |
if (iCxCardType==ESDCardTypeIsMMC) |
|
759 |
{ |
|
760 |
s.FillCommandDesc(ECmdSendOpCond,(iCurrentOpRange | KMMCOCRAccessModeHCS | KMMCOCRBusy)); // Range supported + Sector Access Busy bit (iArgument==KBit31) |
|
761 |
SMF_NEXTS(EStSetRangeBusyCheck) |
|
762 |
} |
|
763 |
else |
|
764 |
{ |
|
765 |
TUint arg = (iCurrentOpRange & ~KMMCOCRAccessModeHCS); // Range supported |
|
766 |
if((iCurrentOpRange & KMMCOCRAccessModeHCS) != 0) |
|
767 |
{ |
|
768 |
arg |= KMMCOCRAccessModeHCS; |
|
769 |
} |
|
770 |
DSDSession::FillAppCommandDesc(Command(), ESDACmdSDAppOpCond, arg); |
|
771 |
SMF_NEXTS((iCxCardType == ESDCardTypeUnknown)? EStCheckForRangeCmd41Timeout : EStSetRangeBusyCheck) |
|
772 |
} |
|
773 |
||
774 |
m.SetTraps(KMMCErrResponseTimeOut); |
|
775 |
SMF_CALL(ExecCommandSMST) |
|
776 |
||
777 |
SMF_STATE(EStCheckForRangeCmd41Timeout) |
|
778 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
779 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM12, "EStCheckForRangeCmd41Timeout" ); |
0 | 780 |
__KTRACE_OPT(KPBUS1, Kern::Printf("-mst:ascs:crct:%d", err)); |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
781 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM13, "err=%d", (TInt) err); |
0 | 782 |
if (err==KMMCErrResponseTimeOut) |
783 |
{ |
|
784 |
iCxCardType=ESDCardTypeIsMMC; |
|
785 |
// Send CMD0 to re-initialise the card - otherwise we may get |
|
786 |
// KMMCStatErrIllegalCommand returned for the next command |
|
787 |
// expecting an R1 response. NB The SD spec recommends ignoring the error |
|
788 |
// whereas the SDIO spec recommends this approach (ignoring the error |
|
789 |
// would be difficult to code anyway, since by then we're no longer |
|
790 |
// in this state machine). |
|
791 |
SMF_INVOKES(GoIdleSMST, EStSetRangeCmd); // Repeat - but using CMD1 |
|
792 |
} |
|
793 |
else |
|
794 |
{ |
|
795 |
// No response timeout - so it must be an SD Card |
|
796 |
__KTRACE_OPT(KPBUS1, Kern::Printf("-mst:ascs:crct2:%x", iCardArray)); |
|
797 |
__KTRACE_OPT(KPBUS1, Kern::Printf("-mst:ascs:crct3:%x", iCxCardCount)); |
|
798 |
__KTRACE_OPT(KPBUS1, Kern::Printf("-mst:ascs:crct4:%x", CardArray().CardP(iCxCardCount))); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
799 |
OstTraceExt3(TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM14, "iCardArray=0x%x;iCxCardCount=%d;CardArray().CardP(iCxCardCount)=%d", (TUint) iCardArray, (TInt) iCxCardCount, (TInt) CardArray().CardP(iCxCardCount)); |
0 | 800 |
|
801 |
(CardArray().CardP(iCxCardCount)->iFlags)|=KSDCardIsSDCard; |
|
802 |
iCxCardType=ESDCardTypeIsSD; |
|
803 |
} |
|
804 |
||
805 |
SMF_STATE(EStSetRangeBusyCheck) |
|
806 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
807 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM15, "EStSetRangeBusyCheck" ); |
0 | 808 |
__KTRACE_OPT(KPBUS1, Kern::Printf("-mst:ascs:src:%d",iCxCardType)); // 1:MMC, 2:SD |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
809 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM16, "iCxCardType=%d", iCxCardType); |
0 | 810 |
|
811 |
if ( !err ) |
|
812 |
{ |
|
813 |
const TUint32 ocrResponse = TMMC::BigEndian32(s.ResponseP()); |
|
814 |
||
815 |
if ((ocrResponse & KMMCOCRBusy) == 0) |
|
816 |
{ |
|
817 |
__KTRACE_OPT(KPBUS1,Kern::Printf("-sd:upd:bsy")); |
|
818 |
// Card is still busy powering up. Check if we should timeout |
|
819 |
if ( ++iCxPollRetryCount > iConfig.OpCondBusyTimeout() ) |
|
820 |
{ |
|
821 |
__KTRACE_OPT2(KPBUS1, KPANIC, Kern::Printf("-sd:ocr busy timed out")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
822 |
OstTraceFunctionExitExt( DSDSTACK_INITIALISEMEMORYCARDSM_EXIT2, this, (TInt) KMMCErrBusTimeOut ); |
87
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
62
diff
changeset
|
823 |
(CardArray().CardP(iCxCardCount)->iFlags)|=KSDCardIsCorrupt; |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
824 |
return KMMCErrBusTimeOut; |
0 | 825 |
} |
826 |
||
827 |
#ifdef _DEBUG |
|
828 |
if ( iCxPollRetryCount > KMMCSpecOpCondBusyTimeout ) |
|
829 |
{ |
|
830 |
__KTRACE_OPT2(KPBUS1, KPANIC, Kern::Printf("-sd:ocr exceeded spec timeout!! (%d ms)", (iCxPollRetryCount*KMMCRetryGapInMilliseconds))); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
831 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM17, "Exceeded spec timeout (%d ms)", (iCxPollRetryCount*KMMCRetryGapInMilliseconds)); |
0 | 832 |
} |
833 |
#endif |
|
834 |
m.ResetTraps(); |
|
835 |
||
836 |
SMF_INVOKES(RetryGapTimerSMST,EStSetRangeCmd) |
|
837 |
} |
|
838 |
else |
|
839 |
{ |
|
840 |
if(ocrResponse & KMMCOCRAccessModeHCS) |
|
841 |
{ |
|
842 |
CardArray().CardP(iCxCardCount)->iFlags |= KMMCardIsHighCapacity; |
|
843 |
#ifdef _DEBUG |
|
844 |
if(iCxCardType == ESDCardTypeIsSD) |
|
845 |
{ |
|
846 |
__KTRACE_OPT(KPBUS1, Kern::Printf("Found large SD card.")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
847 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM18, "Found large SD card" ); |
0 | 848 |
} |
849 |
else if(iCxCardType == ESDCardTypeIsMMC) |
|
850 |
{ |
|
851 |
__KTRACE_OPT(KPBUS1, Kern::Printf("Found large MMC card.")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
852 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM19, "Found large MMC card" ); |
0 | 853 |
} |
854 |
#endif |
|
855 |
} |
|
856 |
} |
|
857 |
} |
|
858 |
||
859 |
// Restore original settings |
|
860 |
iConfig.SetMode( EffectiveModes(s.iConfig) & KMMCModeEnableTimeOutRetry ); |
|
861 |
iConfig.SetPollAttempts(KMMCMaxPollAttempts); |
|
862 |
||
863 |
// All cards are now ready and notified of the voltage range - ask ASSP to set it up |
|
864 |
if (iCxCardType==ESDCardTypeIsMMC) |
|
865 |
{ |
|
866 |
iCurrentOpRange &= ~KMMCOCRAccessModeMask; |
|
867 |
} |
|
868 |
else |
|
869 |
{ |
|
870 |
iCurrentOpRange &= ~KMMCOCRAccessModeHCS; |
|
871 |
} |
|
872 |
||
873 |
psu->SetVoltage(iCurrentOpRange); |
|
874 |
if (psu->SetState(EPsuOnFull) != KErrNone) |
|
875 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
876 |
OstTraceFunctionExitExt( DSDSTACK_INITIALISEMEMORYCARDSM_EXIT3, this, (TInt) KMMCErrHardware ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
877 |
return KMMCErrHardware; |
0 | 878 |
} |
879 |
||
880 |
SMF_STATE(EStCIDCmd) |
|
881 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
882 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM20, "EStCIDCmd" ); |
0 | 883 |
s.FillCommandDesc(ECmdAllSendCID,0); |
884 |
m.ResetTraps(); |
|
885 |
SMF_INVOKES(ExecCommandSMST,EStSendCIDIssued) |
|
886 |
||
887 |
SMF_STATE(EStSendCIDIssued) |
|
888 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
889 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM21, "EStSendCIDIssued" ); |
0 | 890 |
// All done - Higher level state machine expects CID in s.ResponseP() |
891 |
||
892 |
SMF_END |
|
893 |
} |
|
894 |
||
895 |
TMMCErr DSDStack::ConfigureMemoryCardSMST(TAny* aStackP) |
|
896 |
{ return static_cast<DSDStack*>(aStackP)->ConfigureMemoryCardSM(); } |
|
897 |
||
898 |
TMMCErr DSDStack::ConfigureMemoryCardSM() |
|
899 |
/** |
|
900 |
*/ |
|
901 |
{ |
|
902 |
enum states |
|
903 |
{ |
|
904 |
EStBegin=0, |
|
905 |
EStSendCSDDone, |
|
906 |
EStEnd |
|
907 |
}; |
|
908 |
||
909 |
DMMCSession& s=Session(); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
910 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_CONFIGUREMEMORYCARDSM, "Current session = 0x%x", &s ); |
0 | 911 |
|
912 |
//coverity[UNREACHABLE] |
|
913 |
//Part of state machine design. |
|
914 |
SMF_BEGIN |
|
915 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
916 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CONFIGUREMEMORYCARDSM1, "EStBegin" ); |
0 | 917 |
// Cards is initialised so get its CSD |
918 |
||
919 |
s.FillCommandDesc(ECmdSendCSD, TUint32(CardArray().CardP(iCxCardCount)->iRCA) << 16); |
|
920 |
SMF_INVOKES(ExecCommandSMST, EStSendCSDDone) |
|
921 |
||
922 |
SMF_STATE(EStSendCSDDone) |
|
923 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
924 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CONFIGUREMEMORYCARDSM2, "EStSendCSDDone" ); |
0 | 925 |
// Store the CSD in the new card entry |
926 |
TMMCard* cardP = CardArray().CardP(iCxCardCount); |
|
927 |
cardP->iCSD = s.ResponseP(); |
|
928 |
||
929 |
if(CardArray().Card(iCxCardCount).IsSDCard()) |
|
930 |
{ |
|
931 |
// Perform SD Specific parsing of the CSD structure |
|
932 |
if(cardP->CSD().CCC() & KMMCCmdClassLockCard) |
|
933 |
{ |
|
934 |
cardP->iFlags |= KMMCardIsLockable; |
|
935 |
} |
|
936 |
} |
|
937 |
else |
|
938 |
{ |
|
939 |
// Perform MMC Specific parsing of the CSD structure |
|
940 |
TUint specVers = cardP->CSD().SpecVers(); // 1 => 1.4, 2 => 2.0 - 2.2, 3 => 3.1 |
|
941 |
if ((specVers >= 2) && (cardP->CSD().CCC() & KMMCCmdClassLockCard)) |
|
942 |
{ |
|
943 |
cardP->iFlags |= KMMCardIsLockable; |
|
944 |
} |
|
945 |
} |
|
946 |
||
947 |
// Check the state of the mechanical write protect switch |
|
948 |
if (WriteProtected(iCxCardCount)) |
|
949 |
{ |
|
950 |
cardP->iFlags |= KMMCardIsWriteProtected; |
|
951 |
} |
|
952 |
||
953 |
SMF_END |
|
954 |
} |
|
955 |
||
956 |
EXPORT_C TMMCErr DSDStack::InitStackAfterUnlockSM() |
|
957 |
// |
|
958 |
// Performs initialisation of the SD card after the card has been unlocked |
|
959 |
// |
|
960 |
{ |
|
961 |
enum states |
|
962 |
{ |
|
963 |
EStBegin=0, |
|
964 |
EStNextCard, |
|
965 |
EStSelectCard, |
|
966 |
EStSetBusWidth, |
|
967 |
EStSetBusWidth1, |
|
968 |
EStGetSDStatus, |
|
969 |
EStGetSDStatus1, |
|
970 |
EStDecodeSDStatus, |
|
971 |
EStDeselectCard, |
|
972 |
EStCardDeselectedReadCSD, |
|
973 |
EStCSDCmdSent, |
|
974 |
EStMoreCardsCheck, |
|
975 |
EStEnd |
|
976 |
}; |
|
977 |
||
978 |
DMMCSession& s=Session(); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
979 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM, "Current session = 0x%x", &s ); |
0 | 980 |
|
981 |
SMF_BEGIN |
|
982 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
983 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM1, "EStBegin" ); |
0 | 984 |
__KTRACE_OPT(KPBUS1, Kern::Printf(">DSDStack::InitStackAfterUnlockSM()")); |
985 |
iRCAPool.ReleaseUnlocked(); |
|
986 |
iCxCardCount=0; // Reset current card number |
|
987 |
||
988 |
SMF_STATE(EStNextCard) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
989 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM2, "EStNextCard" ); |
0 | 990 |
AddressCard(iCxCardCount); // Address the next card |
991 |
||
992 |
if (!CardDetect(iCxCardCount)) |
|
993 |
SMF_GOTOS(EStMoreCardsCheck) |
|
994 |
||
995 |
s.SetCard(CardArray().CardP(iCxCardCount)); |
|
996 |
||
997 |
if (!CardArray().Card(iCxCardCount).IsSDCard()) |
|
998 |
{ |
|
999 |
SMF_INVOKES( DMMCStack::InitCurrentCardAfterUnlockSMST, EStMoreCardsCheck ) |
|
1000 |
} |
|
1001 |
||
1002 |
SMF_STATE(EStSelectCard) |
|
1003 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1004 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM3, "EStSelectCard" ); |
0 | 1005 |
TRCA targetRCA = CardArray().Card(iCxCardCount).RCA(); |
1006 |
if (targetRCA == SelectedCard()) |
|
1007 |
{ |
|
1008 |
SMF_GOTOS(EStSetBusWidth) |
|
1009 |
} |
|
1010 |
||
1011 |
s.FillCommandDesc(ECmdSelectCard, targetRCA); |
|
1012 |
SMF_INVOKES(ExecCommandSMST,EStSetBusWidth) |
|
1013 |
||
1014 |
SMF_STATE(EStSetBusWidth) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1015 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM4, "EStSetBusWidth" ); |
0 | 1016 |
const TMMCStatus status = s.LastStatus(); |
1017 |
if((status & KMMCStatCardIsLocked) != 0) |
|
1018 |
SMF_GOTOS(EStDeselectCard) |
|
1019 |
||
1020 |
// set bus width with ACMD6 |
|
1021 |
TUint32 arg = TUint32(CardArray().Card(iCxCardCount).RCA()) << 16; |
|
1022 |
s.FillCommandDesc(ECmdAppCmd, arg); |
|
1023 |
SMF_INVOKES(IssueCommandCheckResponseSMST,EStSetBusWidth1) |
|
1024 |
||
1025 |
SMF_STATE(EStSetBusWidth1) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1026 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM5, "EStSetBusWidth1" ); |
0 | 1027 |
CardArray().Card(iCxCardCount).SetBusWidth(4); |
1028 |
DSDSession::FillAppCommandDesc(Command(), ESDACmdSetBusWidth, KSDBusWidth4); |
|
1029 |
SMF_INVOKES(IssueCommandCheckResponseSMST,EStGetSDStatus) |
|
1030 |
||
1031 |
SMF_STATE(EStGetSDStatus) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1032 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM6, "EStGetSDStatus" ); |
0 | 1033 |
// Now we have sent ACMD6, ask the controller to set the bus width to 4 |
1034 |
DoSetBusWidth(EBusWidth4); |
|
1035 |
||
1036 |
// get protected area size with ACMD13 |
|
1037 |
TUint32 arg = TUint32(CardArray().Card(iCxCardCount).RCA()) << 16; |
|
1038 |
s.FillCommandDesc(ECmdAppCmd,arg); |
|
1039 |
SMF_INVOKES(IssueCommandCheckResponseSMST,EStGetSDStatus1) |
|
1040 |
||
1041 |
SMF_STATE(EStGetSDStatus1) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1042 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM7, "EStGetSDStatus1" ); |
0 | 1043 |
DSDSession::FillAppCommandDesc(Command(), ESDACmdSDStatus); |
1044 |
s.FillCommandArgs(0, KSDStatusBlockLength, iPSLBuf, KSDStatusBlockLength); |
|
1045 |
SMF_INVOKES(IssueCommandCheckResponseSMST,EStDecodeSDStatus); |
|
1046 |
||
1047 |
SMF_STATE(EStDecodeSDStatus) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1048 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM8, "EStDecodeSDStatus" ); |
0 | 1049 |
#ifdef _DEBUG |
1050 |
for (TUint i = 0; i < KSDStatusBlockLength; ++i) |
|
1051 |
{ |
|
1052 |
__KTRACE_OPT(KPBUS1, Kern::Printf("SD_STATUS[0x%x] = %x", i, iPSLBuf[i])); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1053 |
OstTraceExt2( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM9, "SD_STATUS[0x%x]=0x%x", i, (TUint) iPSLBuf[i]); |
0 | 1054 |
} |
1055 |
#endif |
|
1056 |
// bits 495:480 are SD_CARD_TYPE. Check this is 00xxh (x = don't care). |
|
1057 |
||
1058 |
if (iPSLBuf[2] != 0) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1059 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1060 |
OstTraceFunctionExitExt( DSDSTACK_INITSTACKAFTERUNLOCKSM_EXIT, this, (TInt) KMMCErrNotSupported ); |
0 | 1061 |
return KMMCErrNotSupported; |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1062 |
} |
0 | 1063 |
|
1064 |
// bits 479:448 contain SIZE_OF_PROTECTED_AREA. |
|
1065 |
// (This is bytes 4 to 7 in big-endian format.) |
|
1066 |
||
1067 |
TSDCard& sdc = CardArray().Card(iCxCardCount); |
|
1068 |
__KTRACE_OPT(KPBUS1, Kern::Printf("\t >DSDStack: Card %d", iCxCardCount)); |
|
1069 |
TUint32 size_of_protected_area = TMMC::BigEndian32(&iPSLBuf[4]); |
|
1070 |
__KTRACE_OPT(KPBUS1, Kern::Printf("\t >DSDStack: SizeOfProtectedArea: %d", size_of_protected_area)); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1071 |
OstTraceExt2( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM10, "iCxCardCount=%d;SizeOfProtectedArea=%d", iCxCardCount, (TInt) size_of_protected_area); |
0 | 1072 |
const TCSD& csd = sdc.CSD(); |
1073 |
TUint32 pas = 0; |
|
1074 |
||
1075 |
if (sdc.IsHighCapacity()) |
|
1076 |
{ |
|
1077 |
// High Capacity Card |
|
1078 |
// Protected Area = SIZE_OF_PROTECTED_AREA |
|
1079 |
pas = size_of_protected_area; |
|
1080 |
__KTRACE_OPT(KPBUS1, Kern::Printf("\t >DSDStack(SDHC): SetProtectedAreaSize: %d", pas)); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1081 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM11, "SDHC: SetProtectedAreaSize=%d", pas); |
0 | 1082 |
} |
1083 |
else |
|
1084 |
{ |
|
1085 |
// Standard Capacity Card |
|
1086 |
// Protected Area = SIZE_OF_PROTECTED_AREA * C_SIZE_MULT * BLOCK_LEN |
|
1087 |
pas = size_of_protected_area * (1 << (csd.CSizeMult() + 2 + csd.ReadBlLen())); |
|
1088 |
__KTRACE_OPT(KPBUS1, Kern::Printf("\t >DSDStack(SDSC): SetProtectedAreaSize: %d", pas)); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1089 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM12, "SDSC: SetProtectedAreaSize=%d", pas); |
0 | 1090 |
} |
1091 |
||
1092 |
sdc.SetProtectedAreaSize(pas); |
|
1093 |
||
1094 |
//bits 431:428 contain AU_SIZE |
|
1095 |
//(This is higher order 4 bits of 10th byte in big endian format) |
|
1096 |
TUint8 au = TUint8(iPSLBuf[10] >> 4); |
|
1097 |
if(au == 0) //AU_SIZE field in SD status register is undefined. |
|
1098 |
au = 6; //Defaulting to value corresponding to 512K |
|
1099 |
sdc.SetAUSize(au); |
|
1100 |
||
1101 |
SMF_INVOKES(SwitchToHighSpeedModeSMST, EStDeselectCard) |
|
1102 |
||
1103 |
SMF_STATE(EStDeselectCard) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1104 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM13, "EStDeselectCard" ); |
0 | 1105 |
s.FillCommandDesc(ECmdSelectCard, 0); |
1106 |
SMF_INVOKES(ExecCommandSMST, EStCardDeselectedReadCSD) |
|
1107 |
||
1108 |
SMF_STATE(EStCardDeselectedReadCSD) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1109 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM14, "EStCardDeselectedReadCSD" ); |
0 | 1110 |
// |
1111 |
// Read the card's CSD register (again) |
|
1112 |
// |
|
1113 |
// - We re-read the CSD, as the TRAN_SPEED field may have changed due to a switch to HS Mode |
|
1114 |
// |
|
1115 |
TUint32 arg = TUint32(CardArray().Card(iCxCardCount).RCA()) << 16; |
|
1116 |
s.FillCommandDesc( ECmdSendCSD, arg ); |
|
1117 |
SMF_INVOKES(ExecCommandSMST, EStCSDCmdSent) |
|
1118 |
||
1119 |
SMF_STATE(EStCSDCmdSent) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1120 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM15, "EStCSDCmdSent" ); |
0 | 1121 |
// |
1122 |
// Store the CSD in the card entry |
|
1123 |
// |
|
1124 |
TMMCard* cardP = iCardArray->CardP(iCxCardCount); |
|
1125 |
cardP->iCSD = s.ResponseP(); |
|
1126 |
||
1127 |
SMF_STATE(EStMoreCardsCheck) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1128 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM16, "EStMoreCardsCheck" ); |
0 | 1129 |
if (++iCxCardCount < (TInt)iMaxCardsInStack) |
1130 |
{ |
|
1131 |
__KTRACE_OPT(KPBUS1, Kern::Printf("\t >DSDStack: Address Next card: %d",iCxCardCount)); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1132 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_INITSTACKAFTERUNLOCKSM17, "Address Next card=%d", iCxCardCount); |
0 | 1133 |
SMF_GOTOS(EStNextCard) |
1134 |
} |
|
1135 |
else |
|
1136 |
{ |
|
1137 |
AddressCard(KBroadcastToAllCards); |
|
1138 |
__KTRACE_OPT(KPBUS1, Kern::Printf("<DSDStack::InitStackAfterUnlockSM()")); |
|
1139 |
} |
|
1140 |
||
1141 |
SMF_END |
|
1142 |
||
1143 |
} |
|
1144 |
||
1145 |
TMMCErr DSDStack::CIMReadWriteMemoryBlocksSMST(TAny* aStackP) |
|
1146 |
{ return( static_cast<DSDStack *>(aStackP)->DMMCStack::CIMReadWriteBlocksSM() ); } |
|
1147 |
||
1148 |
||
1149 |
EXPORT_C TMMCErr DSDStack::CIMReadWriteBlocksSM() |
|
1150 |
// |
|
1151 |
// This macro performs single/multiple block reads and writes |
|
1152 |
// For normal read/write block operations, this function determines the appropriate |
|
1153 |
// MMC command to send and fills the command descriptor accordingly based on |
|
1154 |
// the value of the session ID set. However, it is necessary to have set the |
|
1155 |
// command arguments (with DMMCSession::FillCommandArgs()) before this function |
|
1156 |
// is called. |
|
1157 |
// For special block read/write operations, e.g. lock/unlock, it is required to |
|
1158 |
// have already filled the command descriptor (with DMMCSession::FillCommandDesc()) |
|
1159 |
// for the special command required - in addition to have setup the command arguments. |
|
1160 |
// |
|
1161 |
{ |
|
1162 |
enum states |
|
1163 |
{ |
|
1164 |
EStBegin=0, |
|
1165 |
EStRestart, |
|
1166 |
EStAttached, |
|
1167 |
EStLength1, |
|
1168 |
EStLengthSet, |
|
1169 |
EStIssued, |
|
1170 |
EStWaitFinish, |
|
1171 |
EStWaitFinish1, |
|
1172 |
EStRWFinish, |
|
1173 |
EStDone, |
|
1174 |
EStEnd |
|
1175 |
}; |
|
1176 |
||
1177 |
DMMCSession& s = Session(); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1178 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM, "Current session = 0x%x", &s ); |
0 | 1179 |
|
1180 |
__KTRACE_OPT(KPBUS1,Kern::Printf(">SD:RWBlocksSM %x",TUint(s.iLastStatus))); |
|
1181 |
||
1182 |
SMF_BEGIN |
|
1183 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1184 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM1, "EStBegin" ); |
0 | 1185 |
TSDCard& sdCard = *static_cast<TSDCard*>(s.iCardP); |
1186 |
AddressCard(sdCard.iIndex-1); |
|
1187 |
||
1188 |
if(sdCard.IsSDCard() == EFalse) |
|
1189 |
{ |
|
1190 |
// |
|
1191 |
// If this is not an SD card, then use the more appropriate |
|
1192 |
// MMC state machine as this is optimised for MMC performance |
|
1193 |
// |
|
1194 |
SMF_INVOKES(CIMReadWriteMemoryBlocksSMST, EStDone); |
|
1195 |
} |
|
1196 |
||
1197 |
if(s.iSessionID == ECIMWriteBlock || s.iSessionID == ECIMWriteMBlock) |
|
1198 |
{ |
|
1199 |
// Check that the card supports class 4 (Write) commands |
|
1200 |
const TUint ccc = s.iCardP->CSD().CCC(); |
|
1201 |
if(!(ccc & KMMCCmdClassBlockWrite)) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1202 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1203 |
OstTraceFunctionExitExt( DSDSTACK_CIMREADWRITEBLOCKSSM_EXIT, this, (TInt) KMMCErrNotSupported ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1204 |
return KMMCErrNotSupported; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1205 |
} |
0 | 1206 |
} |
1207 |
||
1208 |
Command().iCustomRetries = 0; // MBW retries |
|
1209 |
s.iState |= KMMCSessStateInProgress; |
|
1210 |
m.SetTraps(KMMCErrInitContext); |
|
1211 |
||
1212 |
SMF_STATE(EStRestart) // NB: ErrBypass is not processed here |
|
1213 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1214 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM2, "EStRestart" ); |
0 | 1215 |
SMF_CALLMEWR(EStRestart) // Create a recursive call entry to recover from the errors trapped |
1216 |
m.SetTraps(KMMCErrStatus); |
|
1217 |
if (s.Command().iSpec.iCommandClass!=KMMCCmdClassApplication || s.Command().iCommand==ECmdAppCmd ) |
|
1218 |
{ |
|
1219 |
s.ResetCommandStack(); |
|
1220 |
SMF_INVOKES( AttachCardSMST, EStAttached ) // attachment is mandatory here |
|
1221 |
} |
|
1222 |
||
1223 |
SMF_BPOINT(EStAttached) |
|
1224 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1225 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM3, "EStAttached" ); |
0 | 1226 |
TMMCCommandDesc& cmd = s.Command(); |
1227 |
||
1228 |
const TUint32 blockLength = cmd.BlockLength(); |
|
1229 |
if((blockLength == 0) || (blockLength > (TUint)KDefaultBlockLenInBytes)) |
|
1230 |
{ |
|
1231 |
__KTRACE_OPT(KPBUS1,Kern::Printf(">SD:RWBlocksSM err BlockLen:%d",blockLength)); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1232 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM4, "blockLength=%d", blockLength ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1233 |
OstTraceFunctionExitExt( DSDSTACK_CIMREADWRITEBLOCKSSM_EXIT1, this, (TInt) KMMCErrArgument ); |
0 | 1234 |
return KMMCErrArgument; |
1235 |
} |
|
1236 |
||
1237 |
if(s.iSessionID == ECIMReadBlock || |
|
1238 |
s.iSessionID == ECIMWriteBlock || |
|
1239 |
s.iSessionID == ECIMReadMBlock || |
|
1240 |
s.iSessionID == ECIMWriteMBlock) |
|
1241 |
{ |
|
1242 |
// read/write operation |
|
1243 |
if(!cmd.AdjustForBlockOrByteAccess(s)) |
|
1244 |
{ |
|
1245 |
// unable to convert command arguments to suit the underlying block/byte access mode |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1246 |
OstTraceFunctionExitExt( DSDSTACK_CIMREADWRITEBLOCKSSM_EXIT2, this, (TInt) KMMCErrArgument ); |
0 | 1247 |
return KMMCErrArgument; |
1248 |
} |
|
1249 |
} |
|
1250 |
||
1251 |
// Set the block length if it has changed. Always set for ECIMLockUnlock. |
|
1252 |
if ((blockLength == s.iCardP->iSetBlockLen) && (s.iSessionID != ECIMLockUnlock)) |
|
1253 |
{ |
|
1254 |
SMF_GOTOS( EStLengthSet ) |
|
1255 |
} |
|
1256 |
||
1257 |
s.iCardP->iSetBlockLen = 0; |
|
1258 |
s.PushCommandStack(); |
|
1259 |
s.FillCommandDesc( ECmdSetBlockLen, blockLength ); |
|
1260 |
SMF_INVOKES( ExecCommandSMST, EStLength1 ) |
|
1261 |
||
1262 |
SMF_STATE(EStLength1) |
|
1263 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1264 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM5, "EStLength1" ); |
0 | 1265 |
const TMMCStatus status(s.ResponseP()); |
1266 |
s.PopCommandStack(); |
|
1267 |
if (status.Error()) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1268 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1269 |
OstTraceFunctionExitExt( DSDSTACK_CIMREADWRITEBLOCKSSM_EXIT3, this, (TInt) KMMCErrStatus ); |
0 | 1270 |
SMF_RETURN(KMMCErrStatus) |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1271 |
} |
0 | 1272 |
s.iCardP->iSetBlockLen = s.Command().BlockLength(); |
1273 |
||
1274 |
SMF_STATE(EStLengthSet) |
|
1275 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1276 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM6, "EStLengthSet" ); |
0 | 1277 |
TMMCCommandDesc& cmd = s.Command(); |
1278 |
TUint opType = 0; |
|
1279 |
const TUint kTypeWrite = KBit0; |
|
1280 |
const TUint kTypeMultiple = KBit1; |
|
1281 |
const TUint kTypeSpecial = KBit2; |
|
1282 |
static const TMMCCommandEnum cmdCodes[4] = |
|
1283 |
{ECmdReadSingleBlock, ECmdWriteBlock, ECmdReadMultipleBlock, ECmdWriteMultipleBlock}; |
|
1284 |
||
1285 |
switch( s.iSessionID ) |
|
1286 |
{ |
|
1287 |
case ECIMReadBlock: |
|
1288 |
break; |
|
1289 |
case ECIMWriteBlock: |
|
1290 |
opType=kTypeWrite; |
|
1291 |
break; |
|
1292 |
case ECIMReadMBlock: |
|
1293 |
opType=kTypeMultiple; |
|
1294 |
break; |
|
1295 |
case ECIMWriteMBlock: |
|
1296 |
opType=kTypeWrite|kTypeMultiple; |
|
1297 |
break; |
|
1298 |
case ECIMLockUnlock: |
|
1299 |
default: |
|
1300 |
opType=kTypeSpecial; |
|
1301 |
break; |
|
1302 |
} |
|
1303 |
||
1304 |
const TUint blocks = cmd.iTotalLength / cmd.BlockLength(); |
|
1305 |
if ( blocks * cmd.BlockLength() != cmd.iTotalLength ) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1306 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1307 |
OstTraceFunctionExitExt( DSDSTACK_CIMREADWRITEBLOCKSSM_EXIT4, this, (TInt) KMMCErrArgument ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1308 |
return KMMCErrArgument; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1309 |
} |
0 | 1310 |
|
1311 |
if ( !(opType & kTypeSpecial) ) // A special session has already set its command descriptor |
|
1312 |
{ |
|
1313 |
if (blocks==1) |
|
1314 |
opType &= ~kTypeMultiple; |
|
1315 |
||
1316 |
TUint32 oldFlags = cmd.iFlags; // Store the existing command flags, as they will be reset by FillCommandDesc() |
|
1317 |
cmd.iCommand = cmdCodes[opType]; |
|
1318 |
s.FillCommandDesc(); |
|
1319 |
cmd.iFlags = oldFlags; // ...and restore the old command flags |
|
1320 |
} |
|
1321 |
||
1322 |
// NB We need to trap KMMCErrStatus errors, because if one occurs, |
|
1323 |
// we still need to wait to exit PRG/RCV/DATA state |
|
1324 |
if (Command().iCommand == ECmdWriteMultipleBlock) |
|
1325 |
{ |
|
1326 |
Command().iExecNotHandle = KMMCErrDataCRC | KMMCErrDataTimeOut; |
|
1327 |
m.SetTraps(KMMCErrStatus | KMMCErrDataCRC | KMMCErrDataTimeOut); |
|
1328 |
} |
|
1329 |
else |
|
1330 |
{ |
|
1331 |
m.SetTraps(KMMCErrStatus); |
|
1332 |
} |
|
1333 |
||
1334 |
SMF_INVOKES( ExecCommandSMST, EStIssued ) |
|
1335 |
||
1336 |
SMF_STATE(EStIssued) |
|
1337 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1338 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM7, "EStIssued" ); |
0 | 1339 |
// check state of card after data transfer with CMD13. |
1340 |
if (s.Command().Direction() != 0) |
|
1341 |
{ |
|
1342 |
SMF_GOTOS(EStWaitFinish) |
|
1343 |
} |
|
1344 |
||
1345 |
SMF_GOTOS(EStRWFinish); |
|
1346 |
||
1347 |
SMF_STATE(EStWaitFinish) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1348 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM8, "EStWaitFinish" ); |
0 | 1349 |
// if MBW fail, then recover by rewriting ALL blocks... |
1350 |
// (used to recover using ACMD22, but this has been changed |
|
1351 |
// as is difficult to test for little gain in efficiency) |
|
1352 |
if (Command().iCommand == ECmdWriteMultipleBlock && err != 0) |
|
1353 |
{ |
|
1354 |
if (Command().iCustomRetries++ >= (TInt) KSDMaxMBWRetries) |
|
1355 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1356 |
OstTraceFunctionExitExt( DSDSTACK_CIMREADWRITEBLOCKSSM_EXIT5, this, (TInt) err ); |
0 | 1357 |
SMF_RETURN(err) |
1358 |
} |
|
1359 |
||
1360 |
m.Pop(); // remove recursive call to EStRestart |
|
1361 |
SMF_GOTOS(EStRestart) |
|
1362 |
} |
|
1363 |
||
1364 |
// Save the status and examine it after issuing CMD13... |
|
1365 |
// NB We don't know where in the command stack the last response is stored (e.g. there may |
|
1366 |
// have bee a Deselect/Select issued), but we do know last response is stored in iLastStatus |
|
1367 |
TMMC::BigEndian4Bytes(s.ResponseP(), s.iLastStatus); |
|
1368 |
||
1369 |
// ...else issue CMD13 to poll for the card finishing and check for errors |
|
1370 |
s.PushCommandStack(); |
|
1371 |
s.FillCommandDesc(ECmdSendStatus, 0); |
|
1372 |
SMF_INVOKES(ExecCommandSMST, EStWaitFinish1) |
|
1373 |
||
1374 |
SMF_STATE(EStWaitFinish1) |
|
1375 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1376 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM9, "EStWaitFinish1" ); |
0 | 1377 |
const TMMCStatus status(s.ResponseP()); |
1378 |
s.PopCommandStack(); |
|
1379 |
||
1380 |
#ifdef __WINS__ |
|
1381 |
SMF_GOTOS(EStRWFinish); |
|
1382 |
#else |
|
1383 |
const TMMCardStateEnum st1 = status.State(); |
|
1384 |
||
1385 |
if (st1 == ECardStatePrg || st1 == ECardStateRcv || st1 == ECardStateData) |
|
1386 |
{ |
|
1387 |
SMF_INVOKES(ProgramTimerSMST, EStWaitFinish); |
|
1388 |
} |
|
1389 |
||
1390 |
if (status.Error()) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1391 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1392 |
OstTraceFunctionExitExt( DUP7_DSDSTACK_CIMREADWRITEBLOCKSSM_EXIT, this, (TInt) KMMCErrStatus ); |
0 | 1393 |
SMF_RETURN(KMMCErrStatus) |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1394 |
} |
0 | 1395 |
#endif |
1396 |
||
1397 |
// Fall through if CURRENT_STATE is not PGM or DATA |
|
1398 |
SMF_STATE(EStRWFinish) |
|
1399 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1400 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM10, "EStRWFinish" ); |
0 | 1401 |
if (TMMCStatus(s.ResponseP()).Error() != 0) |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1402 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1403 |
OstTraceFunctionExitExt( DSDSTACK_CIMREADWRITEBLOCKSSM_EXIT6, this, (TInt) KMMCErrStatus ); |
0 | 1404 |
SMF_RETURN(KMMCErrStatus); |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1405 |
} |
0 | 1406 |
|
1407 |
s.iState &= ~KMMCSessStateInProgress; |
|
1408 |
||
1409 |
// skip over recursive entry or throw error and catch in CIMLockUnlockSM() |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1410 |
TMMCErr ret = (s.Command().iCommand == ECmdLockUnlock) ? KMMCErrUpdPswd : KMMCErrBypass; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1411 |
OstTraceFunctionExitExt( DSDSTACK_CIMREADWRITEBLOCKSSM_EXIT7, this, (TInt) ret ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1412 |
return ret; |
0 | 1413 |
|
1414 |
SMF_STATE(EStDone) |
|
1415 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1416 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_CIMREADWRITEBLOCKSSM11, "EStDone" ); |
0 | 1417 |
__KTRACE_OPT(KPBUS1,Kern::Printf("<SD:RWBlocksSM()")); |
1418 |
||
1419 |
SMF_END |
|
1420 |
} |
|
1421 |
||
1422 |
EXPORT_C TMMCErr DSDStack::ModifyCardCapabilitySM() |
|
1423 |
// |
|
1424 |
// This function provides a chance to modify the capability of paticular cards. |
|
1425 |
// Licensee may overide this function to modify certain card's capability as needed. |
|
1426 |
// A state machine is needed in derived function and function of base class should be |
|
1427 |
// called in order to act more generic behaviour. |
|
1428 |
// |
|
1429 |
{ |
|
1430 |
enum states |
|
1431 |
{ |
|
1432 |
EStBegin=0, |
|
1433 |
EStDone, |
|
1434 |
EStEnd |
|
1435 |
}; |
|
1436 |
||
1437 |
//coverity[unreachable] |
|
1438 |
//Part of state machine design. |
|
1439 |
SMF_BEGIN |
|
1440 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1441 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_MODIFYCARDCAPABILITYSM, "EStBegin" ); |
0 | 1442 |
SMF_INVOKES( DMMCStack::BaseModifyCardCapabilitySMST, EStDone ) |
1443 |
||
1444 |
SMF_STATE(EStDone) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1445 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1446 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_MODIFYCARDCAPABILITYSM1, "EStDone" ); |
0 | 1447 |
|
1448 |
SMF_END |
|
1449 |
} |
|
1450 |
||
1451 |
inline TMMCErr DSDStack::SwitchToHighSpeedModeSMST( TAny* aStackP ) |
|
1452 |
{ return( static_cast<DSDStack *>(aStackP)->DSDStack::SwitchToHighSpeedModeSM() ); } |
|
1453 |
||
1454 |
TMMCErr DSDStack::SwitchToHighSpeedModeSM() |
|
1455 |
{ |
|
1456 |
enum states |
|
1457 |
{ |
|
1458 |
EStBegin=0, |
|
1459 |
EstCheckController, |
|
1460 |
EStSendSCRCmd, |
|
1461 |
EStCheckSpecVer, |
|
1462 |
EStCheckFunction, |
|
1463 |
EStCheckFunctionSent, |
|
1464 |
EStSwitchFunctionSent, |
|
1465 |
EStDone, |
|
1466 |
EStEnd |
|
1467 |
}; |
|
1468 |
||
1469 |
__KTRACE_OPT(KPBUS1,Kern::Printf(">SD:SwitchToHighSpeedModeSM ")); |
|
1470 |
||
1471 |
DMMCSession& s = Session(); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1472 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM, "Current session = 0x%x", &s ); |
0 | 1473 |
|
1474 |
SMF_BEGIN |
|
1475 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1476 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM1, "EStBegin"); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1477 |
|
0 | 1478 |
SMF_STATE(EstCheckController) |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1479 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM2, "EstCheckController"); |
0 | 1480 |
// Get the clock speed supported by the controller |
1481 |
TMMCMachineInfoV4 machineInfo; |
|
1482 |
TMMCMachineInfoV4Pckg machineInfoPckg(machineInfo); |
|
1483 |
MachineInfo(machineInfoPckg); |
|
1484 |
||
1485 |
if (machineInfo.iVersion >= TMMCMachineInfoV4::EVersion4) |
|
1486 |
{ |
|
1487 |
if (machineInfo.iMaxClockSpeedInMhz < (KSDDTClk50MHz/1000) ) |
|
1488 |
{ |
|
1489 |
__KTRACE_OPT(KPBUS1, Kern::Printf("High speed mode not supported by controller")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1490 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM3, "High speed mode not supported by controller"); |
0 | 1491 |
SMF_GOTOS(EStDone); |
1492 |
} |
|
1493 |
} |
|
1494 |
||
1495 |
SMF_STATE(EStSendSCRCmd) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1496 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM4, "EStSendSCRCmd"); |
0 | 1497 |
// |
1498 |
// ACMD51 Read the SD Configuration Register |
|
1499 |
// |
|
1500 |
DSDSession::FillAppCommandDesc(Command(), ESDACmdSendSCR); |
|
1501 |
s.FillCommandArgs(0, KSDSCRLength, iPSLBuf, KSDSCRLength); |
|
1502 |
SMF_INVOKES(ExecCommandSMST, EStCheckSpecVer); |
|
1503 |
||
1504 |
SMF_STATE(EStCheckSpecVer) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1505 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM5, "EStCheckSpecVer"); |
0 | 1506 |
// |
1507 |
// Check the SD version |
|
1508 |
// |
|
1509 |
// 0 : version 1.0-1.01 : SDHS Is NOT Supported |
|
1510 |
// 1 : version 1.10+ : SDHS Is Supported |
|
1511 |
// |
|
1512 |
__KTRACE_OPT(KPBUS1,Kern::Printf(" SD Configuration Register received")); |
|
1513 |
__KTRACE_OPT(KPBUS1,Kern::Printf(" ...card_status=%x", TUint(s.iLastStatus))); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1514 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM6, "SD Configuration Register received: card_status=0x%x", (TUint) s.iLastStatus); |
0 | 1515 |
|
1516 |
#ifdef _DEBUG |
|
1517 |
for (TUint32 i = 0; i < KSDSCRLength; ++i) |
|
1518 |
{ |
|
1519 |
__KTRACE_OPT(KPBUS1, Kern::Printf(" ...SCR_STATUS[0x%x] = %x", i, iPSLBuf[i])); |
|
1520 |
} |
|
1521 |
#endif |
|
1522 |
||
1523 |
if(iPSLBuf[0]==2) |
|
1524 |
{ |
|
1525 |
__KTRACE_OPT(KPBUS1,Kern::Printf(" ...SD Spec Version 2")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1526 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM7, "SD Spec Version 2"); |
0 | 1527 |
SMF_GOTOS(EStCheckFunction); |
1528 |
} |
|
1529 |
||
1530 |
if(iPSLBuf[0]==1) |
|
1531 |
{ |
|
1532 |
__KTRACE_OPT(KPBUS1,Kern::Printf(" ...SD Spec Version 1.10")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1533 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM8, "SD Spec Version 1.10"); |
0 | 1534 |
SMF_GOTOS(EStCheckFunction); |
1535 |
} |
|
1536 |
||
1537 |
if(iPSLBuf[0]==0) |
|
1538 |
{ |
|
1539 |
__KTRACE_OPT(KPBUS1,Kern::Printf(" ...SD Spec Version 1.01")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1540 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM9, "SD Spec Version 1.01"); |
0 | 1541 |
SMF_GOTOS(EStDone); |
1542 |
} |
|
1543 |
||
1544 |
__KTRACE_OPT(KPBUS1,Kern::Printf(" ...SD Spec Version > 2 !")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1545 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM10, "SD Spec Version > 2"); |
0 | 1546 |
|
1547 |
SMF_STATE(EStCheckFunction) |
|
1548 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1549 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM11, "EStCheckFunction"); |
0 | 1550 |
m.SetTraps(KMMCErrResponseTimeOut | KMMCErrNotSupported); |
1551 |
||
1552 |
// |
|
1553 |
// SD1.1 uses CMD6 which is not defined by the MMCA |
|
1554 |
// - fill in command details using the SD Specific command description table |
|
1555 |
// |
|
1556 |
||
1557 |
DSDSession::FillSdSpecificCommandDesc(Command(), ESDCmdSwitchFunction); |
|
1558 |
s.FillCommandArgs(KSDCheckFunctionHighSpeed, KSDSwitchFuncLength, iPSLBuf, KSDSwitchFuncLength); |
|
1559 |
||
1560 |
SMF_INVOKES(IssueCommandCheckResponseSMST,EStCheckFunctionSent) |
|
1561 |
||
1562 |
SMF_STATE(EStCheckFunctionSent) |
|
1563 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1564 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM12, "EStCheckFunctionSent"); |
0 | 1565 |
__KTRACE_OPT(KPBUS1,Kern::Printf(" CheckFunctionSent %x",TUint(s.iLastStatus))); |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1566 |
OstTrace1( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM13, "CheckFunctionSent=0x%x", (TUint) s.iLastStatus); |
0 | 1567 |
|
1568 |
m.ResetTraps(); |
|
1569 |
||
1570 |
if(err == KMMCErrResponseTimeOut) |
|
1571 |
{ |
|
1572 |
__KTRACE_OPT(KPBUS1,Kern::Printf(" ...CMD6 [Read] Response Timeout")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1573 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM14, "CMD6 [Read] Response Timeout"); |
0 | 1574 |
SMF_GOTOS(EStDone); |
1575 |
} |
|
1576 |
else if(err == KMMCErrNotSupported) |
|
1577 |
{ |
|
1578 |
__KTRACE_OPT(KPBUS1,Kern::Printf(" ...CMD6 [Read] Not Supported")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1579 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM15, "CMD6 [Read] Not Supported"); |
0 | 1580 |
SMF_GOTOS(EStDone); |
1581 |
} |
|
1582 |
||
1583 |
#ifdef _DEBUG |
|
1584 |
for (TUint32 i = 0; i < KSDSwitchFuncLength; ++i) |
|
1585 |
{ |
|
1586 |
__KTRACE_OPT(KPBUS1, Kern::Printf(" ...SD Switch Func Status[0x%x] = %x", i, iPSLBuf[i])); |
|
1587 |
} |
|
1588 |
||
1589 |
m.SetTraps(KMMCErrResponseTimeOut); |
|
1590 |
#endif |
|
1591 |
||
1592 |
// |
|
1593 |
// SD1.1 uses CMD6 which is not defined by the MMCA |
|
1594 |
// - fill in command details using the SD Specific command description table |
|
1595 |
// |
|
1596 |
||
1597 |
DSDSession::FillSdSpecificCommandDesc(Command(), ESDCmdSwitchFunction); |
|
1598 |
s.FillCommandArgs(KSDSwitchFunctionHighSpeed, KSDSwitchFuncLength, iPSLBuf, KSDSwitchFuncLength); |
|
1599 |
||
1600 |
SMF_INVOKES(IssueCommandCheckResponseSMST,EStSwitchFunctionSent) |
|
1601 |
||
1602 |
SMF_STATE(EStSwitchFunctionSent) |
|
1603 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1604 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM16, "EStSwitchFunctionSent"); |
0 | 1605 |
#ifdef _DEBUG |
1606 |
m.ResetTraps(); |
|
1607 |
||
1608 |
if(err == KMMCErrResponseTimeOut) |
|
1609 |
{ |
|
1610 |
__KTRACE_OPT(KPBUS1,Kern::Printf(" ...CMD6 [Write] Response Timeout")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1611 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM17, "CMD6 [Write] Response Timeout"); |
0 | 1612 |
} |
1613 |
||
1614 |
for (TUint32 i = 0; i < KSDSwitchFuncLength; ++i) |
|
1615 |
{ |
|
1616 |
__KTRACE_OPT(KPBUS1, Kern::Printf(" ...SD Switch[0x%x] = %x", i, iPSLBuf[i])); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1617 |
OstTraceExt2( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM18, "SD Switch[0x%x]=0x%x", (TUint) i, (TUint) iPSLBuf[i]); |
0 | 1618 |
} |
1619 |
#endif |
|
1620 |
||
1621 |
SMF_STATE(EStDone) |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1622 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1623 |
OstTrace0( TRACE_INTERNALS, DSDSTACK_SWITCHTOHIGHSPEEDMODESM19, "EStSwitchFunctionSent"); |
0 | 1624 |
|
1625 |
SMF_END |
|
1626 |
} |
|
1627 |
||
1628 |
||
1629 |
EXPORT_C DMMCSession* DSDStack::AllocSession(const TMMCCallBack& aCallBack) const |
|
1630 |
/** |
|
1631 |
* Factory function to create DMMCSession derived object. Non-generic MMC |
|
1632 |
* controllers can override this to generate more specific objects. |
|
1633 |
* @param aCallBack Callback function to notify the client that a session has completed |
|
1634 |
* @return A pointer to the new session |
|
1635 |
*/ |
|
1636 |
{ |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1637 |
OstTraceFunctionEntry1( DSDSTACK_ALLOCSESSION_ENTRY, this ); |
0 | 1638 |
return new DSDSession(aCallBack); |
1639 |
} |
|
1640 |
||
62
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1641 |
EXPORT_C DSDStack::TSDCardType DSDStack::CardType(TInt /*aSocket*/, TInt /*aCardNumber*/) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1642 |
/** |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1643 |
* This method allows a preset card type to be specified for a given slot/socket. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1644 |
* The SD protocol stack attempts to identify card types (SD or MMC) through protocol responses; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1645 |
* For embedded media (eMMC or eSD) this is unnecessary as the media type is already known and cannot change. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1646 |
* Licensee may override this function to specify the preset card type. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1647 |
* @param aSocket Socket to be queried for card type. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1648 |
* @param aCardNumber Card number attached to Socket to be queried for card type. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1649 |
* @return Preset card type |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1650 |
*/ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1651 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1652 |
// Default implmentation. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1653 |
return DSDStack::ESDCardTypeUnknown; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1654 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1655 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
1656 |
|
0 | 1657 |
EXPORT_C void DSDStack::Dummy1() {} |
1658 |
EXPORT_C void DSDStack::Dummy2() {} |
|
1659 |
EXPORT_C void DSDStack::Dummy3() {} |