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