emulator/emulatorbsp/specific/mmc.cpp
branchRCL_3
changeset 40 cb9d56c0e2af
parent 0 cec860690d41
child 55 7151b503b58d
equal deleted inserted replaced
28:7fcac431985a 40:cb9d56c0e2af
   305 		NULL,										// LPSECURITY_ATTRIBUTES lpSecurityAttributes
   305 		NULL,										// LPSECURITY_ATTRIBUTES lpSecurityAttributes
   306 		aCreateNew ? CREATE_ALWAYS : OPEN_ALWAYS,	// DWORD dwCreationDisposition
   306 		aCreateNew ? CREATE_ALWAYS : OPEN_ALWAYS,	// DWORD dwCreationDisposition
   307 		FILE_FLAG_RANDOM_ACCESS,					// DWORD dwFlagsAndAttributes
   307 		FILE_FLAG_RANDOM_ACCESS,					// DWORD dwFlagsAndAttributes
   308 			NULL);									// HANDLE hTemplateFile
   308 			NULL);									// HANDLE hTemplateFile
   309 	
   309 	
   310 	TInt fileSize=GetFileSize(*aHandle,NULL);
   310 	TInt fileSize = 0;
   311 	if (fileSize>TotalMDiskSize)
   311 	if (*aHandle!=INVALID_HANDLE_VALUE)
       
   312 	    {
       
   313         fileSize = GetFileSize(*aHandle,NULL);
       
   314         // Check whether MMC card force mount property is set.
       
   315         // Force mount MMC card image regardless of whether the size of the image file is
       
   316         // as specified in the epoc.ini.
       
   317         // Specify "MMCCardForceMount 1" in the epoc.ini to enable force mount.
       
   318         TBool forceMount = Property::GetBool("MMCCardForceMount");
       
   319         if (forceMount && fileSize != INVALID_FILE_SIZE)
       
   320             {
       
   321             TInt sizeInKB = fileSize >> 10;
       
   322             SetupDiskParms(sizeInKB);
       
   323             TotalMDiskSize = fileSize;
       
   324             }
       
   325 	    }
       
   326 
       
   327 	if (fileSize!=TotalMDiskSize)
   312 		//
   328 		//
   313 		// The Drive file already exists and size of emulated drive as configured in 
   329 		// The Drive file already exists and size of emulated drive as configured in 
   314 		// epoc.ini has been reduced. Musn't corrupt the emulated drive so delete the 
   330 		// epoc.ini has been changed. Musn't corrupt the emulated drive so delete the 
   315 		// drive file and start from scratch. The emulated drive contents will be 
   331 		// drive file and start from scratch. The emulated drive contents will be 
   316 		// erased.
   332 		// erased.
   317 		//
   333 		//
   318 		{
   334 		{
   319 		CloseHandle(*aHandle);
   335 		CloseHandle(*aHandle);
   377 	if ( (err=CreateBinFileForCard(aCardNum,&h))!=KErrNone )
   393 	if ( (err=CreateBinFileForCard(aCardNum,&h))!=KErrNone )
   378 		{
   394 		{
   379 		delete cip;
   395 		delete cip;
   380 		return(err);
   396 		return(err);
   381 		}
   397 		}
       
   398 	
       
   399 	TBool forceMount = Property::GetBool("MMCCardForceMount");
       
   400 	if (forceMount)
       
   401 	    {
       
   402         // if Force Mount as image file size, CSIZE and CSIZE_MULT will be set 
       
   403         // again inside the CreateBinFileForCard() call above.
       
   404         cip->iForceMount = ETrue;
       
   405         cip->iForceMountCSIZE = CSIZE;
       
   406         cip->iForceMountCSIZE_MULT = CSIZE_MULT;
       
   407 	    }
       
   408 	else
       
   409 	    {
       
   410         cip->iForceMountCSIZE = EFalse;
       
   411 	    }
       
   412 	
   382 	cip->iWinHandle=h;
   413 	cip->iWinHandle=h;
   383 	iCardPool[aCardNum]=cip;
   414 	iCardPool[aCardNum]=cip;
   384 	return(KErrNone);
   415 	return(KErrNone);
   385 	}
   416 	}
   386 
   417 
  1312 
  1343 
  1313 // ======== TWinsCardInfo ========
  1344 // ======== TWinsCardInfo ========
  1314 
  1345 
  1315 void TWinsCardInfo::GetCSD(TUint8* aResp) const
  1346 void TWinsCardInfo::GetCSD(TUint8* aResp) const
  1316 	{
  1347 	{
       
  1348 	TUint size;
       
  1349     TUint sizeMult;
       
  1350     
       
  1351     if (iForceMount)
       
  1352         {
       
  1353         size = iForceMountCSIZE;
       
  1354         sizeMult = iForceMountCSIZE_MULT;
       
  1355         }
       
  1356     else
       
  1357         {
       
  1358         size = DWinsMMCStack::CSIZE;
       
  1359         sizeMult = DWinsMMCStack::CSIZE_MULT;
       
  1360         }
       
  1361 		
  1317 	// Bits 127-96
  1362 	// Bits 127-96
  1318 	TUint32 csd=(KCsdStructure<<30); 	/* CSD_STRUCTURE */
  1363 	TUint32 csd=(KCsdStructure<<30); 	/* CSD_STRUCTURE */
  1319 	csd|=		(KCsdSpecVers<<26); 	/* SPEC_VERS */
  1364 	csd|=		(KCsdSpecVers<<26); 	/* SPEC_VERS */
  1320 	csd|=		(0x0E<<16);				/* TAAC: 1mS */  
  1365 	csd|=		(0x0E<<16);				/* TAAC: 1mS */  
  1321 	csd|=		(0x0A<<8);				/* NSAC: 1000 */  
  1366 	csd|=		(0x0A<<8);				/* NSAC: 1000 */  
  1339 	csd|=		(0x9<<16); 	/* READ_BL_LEN: 512 bytes */
  1384 	csd|=		(0x9<<16); 	/* READ_BL_LEN: 512 bytes */
  1340 	csd|=		(0x0<<15);	/* READ_BL_PARTIAL: No */  
  1385 	csd|=		(0x0<<15);	/* READ_BL_PARTIAL: No */  
  1341 	csd|=		(0x0<<14);	/* WRITE_BLK_MISALIGN: No */  
  1386 	csd|=		(0x0<<14);	/* WRITE_BLK_MISALIGN: No */  
  1342 	csd|=		(0x0<<13);	/* READ_BLK_MISALIGN: No */  
  1387 	csd|=		(0x0<<13);	/* READ_BLK_MISALIGN: No */  
  1343 	csd|=		(0x0<<12);	/* DSR_IMP: No DSR */ 
  1388 	csd|=		(0x0<<12);	/* DSR_IMP: No DSR */ 
  1344 	csd|=		((DWinsMMCStack::CSIZE>>10&3)<<8);			/* C_SIZE: MMCSz Kb */
  1389 	csd|=		((size>>10&3)<<8);			/* C_SIZE: MMCSz Kb */
  1345 	csd|=		((DWinsMMCStack::CSIZE>>2) & 0xFF);			/* C_SIZE: MMCSz Kb */
  1390 	csd|=		((size>>2) & 0xFF);			/* C_SIZE: MMCSz Kb */
  1346 	TMMC::BigEndian4Bytes(&aResp[4],csd); 
  1391 	TMMC::BigEndian4Bytes(&aResp[4],csd); 
  1347 	// Bits 63-32
  1392 	// Bits 63-32
  1348 	csd=		((DWinsMMCStack::CSIZE&3)<<30); 			/* C_SIZE: MMCSz Kb */
  1393 	csd=		((size&3)<<30); 			/* C_SIZE: MMCSz Kb */
  1349 	csd|=		(0x1<<27); 	/* VDD_R_CURR_MIN: 1mA */
  1394 	csd|=		(0x1<<27); 	/* VDD_R_CURR_MIN: 1mA */
  1350 	csd|=		(0x1<<24);	/* VDD_R_CURR_MAX: 5mA */  
  1395 	csd|=		(0x1<<24);	/* VDD_R_CURR_MAX: 5mA */  
  1351 	csd|=		(0x2<<21); 	/* VDD_W_CURR_MIN: 5mA */
  1396 	csd|=		(0x2<<21); 	/* VDD_W_CURR_MIN: 5mA */
  1352 	csd|=		(0x3<<18);	/* VDD_W_CURR_MAX: 25mA */  
  1397 	csd|=		(0x3<<18);	/* VDD_W_CURR_MAX: 25mA */  
  1353 	csd|=		((DWinsMMCStack::CSIZE_MULT&0x07)<<15);		/* C_SIZE_MULT: 0 */  
  1398 	csd|=		((sizeMult&0x07)<<15);		/* C_SIZE_MULT: 0 */  
  1354 	csd|=		(0x0<<10);	/* SECTOR_SIZE: 1 write block */  
  1399 	csd|=		(0x0<<10);	/* SECTOR_SIZE: 1 write block */  
  1355 	csd|=		(0x0<<5);	/* ERASE_GRP_SIZE: 1 secotr */  
  1400 	csd|=		(0x0<<5);	/* ERASE_GRP_SIZE: 1 secotr */  
  1356 	csd|=		(0x0);		/* WP_GRP_SIZE: 1 erase group */  
  1401 	csd|=		(0x0);		/* WP_GRP_SIZE: 1 erase group */  
  1357 	TMMC::BigEndian4Bytes(&aResp[8],csd); 
  1402 	TMMC::BigEndian4Bytes(&aResp[8],csd); 
  1358 	// Bits 31-0
  1403 	// Bits 31-0