os/boardsupport/emulator/emulatorbsp/specific/sdcard/sdcard3c/sdio/pp_sdio.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "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 // PP_SDC.H
    15 // 
    16 //
    17 
    18 #ifndef __PP_SDC_H__
    19 #define __PP_SDC_H__
    20 #if defined(_UNICODE) && !defined(UNICODE)
    21 	#define UNICODE
    22 #endif
    23 
    24 #include <sdiocard.h>
    25 #include <emulator.h>
    26 
    27 GLREF_C TInt MapLastErrorEpoc();
    28 GLREF_C TMMCErr MapLastErrorMmc();
    29 
    30 const TInt KMediaChangeTickInterval=20000;	// Units 1uS
    31 
    32 const TInt KTotalWinsCardSlots=2;
    33 const TInt KTotalWinsCards=(KTotalWinsCardSlots+1); // Need 2 cards for slot 0
    34 
    35 const TUint32 KMMCWinsCardOCRValue = 0x00FFFF00;
    36 
    37 const TInt KSDMediaAreasPerCard = 3;
    38 const TInt KSDUserArea = 0;
    39 const TInt KSDProtectedArea = 1;
    40 const TInt KSDIOArea = 2;
    41 
    42 const TUint32 KWinsSdioFunctionCount = 3;
    43 const TUint8  KWinsSdioFunctionMask  = 0x0A;	/** TODO: Non-Contuguous functions not yet supported */
    44 const TBool	  KWinsSdioMemoryPresent = ETrue;
    45 
    46 const TUint32 KFunctionEnableDelay_uS = 1000000;	// 1S Second Function Enable Delay
    47 
    48 
    49 class TWinsCardInfo
    50 	{
    51 public:
    52 	void GetCSD(TUint8* aResp) const;
    53 public:
    54 	TCID iCID;
    55 	TMediaPassword* iPWD;				// PWD_LEN calculated from PWD.
    56 	TBool iIsLocked;					// Could use iCurrentCardIsLocked
    57 	TMMCardStateEnum iState;			// Simulation of card's current state
    58 	HANDLE iAreaHandles[KSDMediaAreasPerCard];
    59 	TRCA iRCA;
    60 	TBool iIsSDCard;
    61 	TInt iBusWidth;
    62 	};
    63 
    64 class DWinsSDIOStack : public DSDIOStack
    65 	{
    66 private:
    67 	DWinsSDIOStack(TInt aBus, DMMCSocket* aSocket);
    68 	TInt Init();
    69 private:
    70 	virtual void MachineInfo(TMMCMachineInfo& aMachineInfo);
    71 public:
    72 	virtual void AdjustPartialRead(const TMMCard* aCard, TUint32 aStart, TUint32 aEnd, TUint32* aPhysStart, TUint32* aPhysEnd) const;
    73 	virtual void GetBufferInfo(TUint8** aMDBuf, TInt* aMDBufLen);
    74 	virtual void AddressCard(TInt aCardNumber);
    75 
    76 	enum TWinsMMCPanic
    77 		{
    78 	    EWinsMMCLidOpenIntBind=0,
    79 		EWinsMMCBadMachineInfo=1,
    80 		EWinsMMCMediaChangeTickFault = 2,
    81 		EWinsMMCCorruptCommand = 3,
    82 		EWinsMMCLockAttempt = 4,
    83 		EWinsMMCAPRNotSupp = 5,
    84 		EWinsMMCAPRRange = 6,
    85 		EWinsMMCAPRBoundary = 7,
    86 
    87 		EStkFFCNotSelCard = 0x010, EStkFFCNoneSel,
    88 		EStkFOCNotSelCard = 0x020, EStkFOCMultiSel, EStkFOCNoneSel,
    89 		EStkIMCBadStateCmd2 = 0x30, EStkIMCBadStateCmd3, EStkIMCCmd6InvalidWidth,
    90 			EStkICMACMD13NotSD, EStkICMACMD22NotSD,
    91 		};
    92     static void Panic(TWinsMMCPanic aPanic);
    93 
    94 	static TInt AccessIoEnable	(TInt aTargetCard, TInt aVal, TAny* aSelfP, TBool aRead, TUint8& aData);
    95 	static TInt AccessCsaWindow (TInt aTargetCard, TInt aVal, TAny* aSelfP, TBool aRead, TUint8& aData);
    96 	static TInt AccessCsaPointer(TInt aTargetCard, TInt aVal, TAny* aSelfP, TBool aRead, TUint8& aData);
    97 
    98 private:
    99 	// Stack service provided by ASSP layer
   100 	void SetBusConfigDefaults(TMMCBusConfig&, TUint aClock);
   101 	void InitClockOff();
   102 	void ASSPReset();
   103 	void ASSPDisengage();
   104 	void DoPowerDown();
   105 	// State Machine functions implemented in ASSP layer
   106 	TMMCErr DoPowerUpSM();
   107 	TMMCErr InitClockOnSM();
   108 	TMMCErr IssueMMCCommandSM();
   109 
   110 	void EnableSDIOInterrupt(TBool aEnable);
   111 	void SetBusWidth(TUint32 aBusWidth);
   112 	TUint32 MaxBlockSize() const;
   113 	
   114 
   115 private:
   116 	TInt SetupSimulatedCard(TInt aCardNum);						// init
   117 	TInt CreateBinFileForCard(TInt aCardNum, TInt aAreaNum, HANDLE* aHandle);
   118 	TInt GetTargetSlotNumber(const TRCA& anRCA);
   119 	TInt FindAnyCardInStack(TMMCardStateEnum aState);
   120 	TInt FindFirstCardInStack(TMMCardStateEnum aState);
   121 	TInt FindOneCardInStack(TMMCardStateEnum aState);
   122 
   123 	static void EnableTimerCallback(TAny* aPtr);
   124 
   125 private:
   126 	TWinsCardInfo* iCardPool[KTotalWinsCards];		// all cards
   127 	TWinsCardInfo* iCardInfo[KTotalWinsCardSlots];		// present cards
   128 	TInt iAddressedCard;
   129 	TBool iCMD42Failed;
   130 	TInt iMBWOKBlocks;
   131 	TUint8* iMDBuf;
   132 	TInt iMDBufLen;
   133 
   134 	NTimer iEnableTimer;
   135 
   136 	friend class TSDCardControllerInterfaceWins;
   137 	friend class DWinsMMCMediaChange;
   138 	};
   139 
   140 class DWinsMMCMediaChange : public DMMCMediaChange
   141 	{
   142 public:
   143 	DWinsMMCMediaChange(TInt aMediaChangeNum);
   144 	virtual TInt Create();
   145 	virtual void ForceMediaChange();
   146 	virtual void DoDoorOpen();
   147 	virtual void DoDoorClosed();
   148 	virtual TMediaState MediaState();
   149 protected:
   150     void DoorOpenService();
   151 private:
   152 	static TInt MediaChangeDfc(TAny *aPtr);
   153 	static void Tick(TAny *aPtr);
   154 	void TickService();
   155 	void Enable();
   156 	void Disable();
   157 	static void MediaChangeCallBack(TAny *aPtr);
   158 	inline void SetStackP(DWinsSDIOStack* aStackP) {iStackP=aStackP;}	
   159 private:
   160 	TTickLink iTickLink;
   161 	TInt iDoorClosedCount;
   162 	TBool iMediaChangeEnable;
   163 	TInt iMediaDoorCloseReload; 	// Units: In theory-20ms, Actual-100ms  
   164 	DWinsSDIOStack* iStackP;
   165 	friend class DWinsSDIOStack;
   166 	};
   167 
   168 class DWinsSDIOPsu : public DSDIOPsu 
   169     {
   170 public:
   171     DWinsSDIOPsu(TInt aVccNum, TInt aMcId);
   172     virtual void Init();
   173 	virtual void DoSetState(TPBusPsuState aState);
   174 	virtual TInt VoltageInMilliVolts();
   175 private:
   176 	virtual void DoCheckVoltage();
   177     virtual void PsuInfo(TPBusPsuInfo &anInfo);
   178     };
   179 
   180 
   181 #endif	// #ifndef __PP_SDC_H__