sl@0: // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Generic MMC controller types and standard classes for MMC manipulation sl@0: // This controller follows MMC spec V2.1 sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: */ sl@0: sl@0: #if !defined(__MMC_H__) sl@0: #define __MMC_H__ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: // MMC Card maximum system settings sl@0: sl@0: const TInt KMaxMmcSockets = KMaxPBusSockets; sl@0: sl@0: // Forward type declarations sl@0: sl@0: class TMMC; sl@0: class TCID; sl@0: class TCSD; sl@0: class TExtendedCSD; sl@0: class TRCA; sl@0: class TDSR; sl@0: class TMMCStatus; sl@0: class TMMCArgument; sl@0: class TMMCard; sl@0: class TMMCCommandDesc; sl@0: class TMMCBusConfig; sl@0: class TMMCStackConfig; sl@0: class TMMCRCAPool; sl@0: class TMMCSessRing; sl@0: class TMMCStateMachine; sl@0: class DMMCSocket; sl@0: class DMMCSession; sl@0: class DMMCStack; sl@0: class TMMCMachineInfo; sl@0: class TMapping; sl@0: class TMMCPasswordStore; sl@0: class TMMCEraseInfo; sl@0: class TMMCMachineInfoV4; sl@0: typedef TPckg TMMCMachineInfoV4Pckg; sl@0: sl@0: enum TMMCAppCommand {EMMCNormalCmd,EMMCApplicationCmd}; sl@0: sl@0: // Typedefs sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Represents the MultiMediaCard error code bit set. sl@0: sl@0: MultiMediaCard error codes are defined as bit masks, mainly for use with sl@0: the state machine where the error trap mask may be used. sl@0: The function DMMCSession::EpocErrorCode() converts these error bit values sl@0: into standard Symbian OS error values. sl@0: sl@0: @see KMMCErrNone sl@0: @see KMMCErrResponseTimeOut sl@0: @see KMMCErrDataTimeOut sl@0: @see KMMCErrBusyTimeOut sl@0: @see KMMCErrBusTimeOut sl@0: @see KMMCErrTooManyCards sl@0: @see KMMCErrResponseCRC sl@0: @see KMMCErrDataCRC sl@0: @see KMMCErrCommandCRC sl@0: @see KMMCErrStatus sl@0: @see KMMCErrNoCard sl@0: @see KMMCErrBrokenLock sl@0: @see KMMCErrPowerDown sl@0: @see KMMCErrAbort sl@0: @see KMMCErrStackNotReady sl@0: @see KMMCErrNotSupported sl@0: @see KMMCErrHardware sl@0: @see KMMCErrBusInconsistent sl@0: @see KMMCErrBypass sl@0: @see KMMCErrInitContext sl@0: @see KMMCErrArgument sl@0: @see KMMCErrSingleBlock sl@0: @see KMMCErrLocked sl@0: @see KMMCErrNotFound sl@0: @see KMMCErrAlreadyExists sl@0: @see KMMCErrGeneral sl@0: @see KMMCErrAll sl@0: @see KMMCErrBasic sl@0: */ sl@0: typedef TUint32 TMMCErr; sl@0: sl@0: // MMC Enums and inline functions sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Defines a set of symbols corresponding to the MultiMediaCard bus commands. sl@0: sl@0: A command is one of the parameter values inserted into a TMMCCommandDesc object. sl@0: The commands themselves are defined by the MultiMediaCard specification. sl@0: sl@0: @see TMMCCommandDesc sl@0: */ sl@0: enum TMMCCommandEnum sl@0: { sl@0: /** sl@0: CMD0; reset all cards to idle state. sl@0: */ sl@0: ECmdGoIdleState =0, sl@0: sl@0: sl@0: /** sl@0: CMD1; all cards in the idle state send their operating conditions. sl@0: */ sl@0: ECmdSendOpCond =1, sl@0: sl@0: sl@0: /** sl@0: CMD2; all cards send their CID number. sl@0: */ sl@0: ECmdAllSendCID =2, sl@0: sl@0: sl@0: /** sl@0: CMD3; assign relative address to a card. sl@0: */ sl@0: ECmdSetRelativeAddr =3, sl@0: sl@0: sl@0: /** sl@0: CMD4; program the DSR register of all cards. sl@0: */ sl@0: ECmdSetDSR =4, sl@0: sl@0: sl@0: /** sl@0: CMD5; toggle device between Sleep and Awake states. sl@0: */ sl@0: ECmd5 =5, sl@0: ECmdSleepAwake =5, sl@0: sl@0: sl@0: /** sl@0: CMD6; Switch sl@0: */ sl@0: ECmd6 =6, sl@0: ECmdSwitch =6, sl@0: sl@0: sl@0: /** sl@0: CMD7; toggle a card between standby and transfer state, or between sl@0: programming and disconnected state. sl@0: sl@0: The card is selected by its RCA and deselected by any other address. sl@0: */ sl@0: ECmdSelectCard =7, sl@0: sl@0: sl@0: /** sl@0: CMD8; addressed card sends its extended CSD. sl@0: */ sl@0: ECmd8 =8, sl@0: ECmdSendExtendedCSD =8, sl@0: sl@0: sl@0: /** sl@0: CMD9; addressed card sends its CSD. sl@0: */ sl@0: ECmdSendCSD =9, sl@0: sl@0: sl@0: /** sl@0: CMD10; addressed card sends its CID. sl@0: */ sl@0: ECmdSendCID =10, sl@0: sl@0: sl@0: /** sl@0: CMD11; read data stream from the card starting at the given address until sl@0: an ECmdStopTransmission follows. sl@0: sl@0: @see ECmdStopTransmission sl@0: */ sl@0: ECmdReadDatUntilStop =11, sl@0: sl@0: sl@0: /** sl@0: CMD12; force the card to stop transmission. sl@0: */ sl@0: ECmdStopTransmission =12, sl@0: sl@0: sl@0: /** sl@0: CMD13; addressed card sends its status register. sl@0: */ sl@0: ECmdSendStatus =13, sl@0: sl@0: sl@0: /** sl@0: CMD14; BUSTEST_R - Reads the reversed bus testing data pattern from the card. sl@0: sl@0: @see ECmdBustest_W sl@0: */ sl@0: ECmd14 =14, sl@0: ECmdBustest_R =14, sl@0: sl@0: sl@0: /** sl@0: CMD15; set the card to the inactive state. sl@0: */ sl@0: ECmdGoInactiveState =15, sl@0: sl@0: sl@0: /** sl@0: CMD16; set the block length for all following block commands. sl@0: */ sl@0: ECmdSetBlockLen =16, sl@0: sl@0: sl@0: /** sl@0: CMD17; read a single data block from the card. sl@0: */ sl@0: ECmdReadSingleBlock =17, sl@0: sl@0: sl@0: /** sl@0: CMD18; continuously transfer data blocks from the card until interrupted sl@0: by ECmdStopTransmission. sl@0: sl@0: @see ECmdStopTransmission sl@0: */ sl@0: ECmdReadMultipleBlock =18, sl@0: sl@0: sl@0: /** sl@0: CMD19; BUSTEST_W - Sends a test data pattern to the card to determine the bus characteristics sl@0: sl@0: @see ECmdBustest_R sl@0: */ sl@0: ECmd19 =19, sl@0: ECmdBustest_W =19, sl@0: sl@0: sl@0: /** sl@0: CMD20; write data stream from the host starting at the given address sl@0: until interrupted by ECmdStopTransmission. sl@0: sl@0: @see ECmdStopTransmission sl@0: */ sl@0: ECmdWriteDatUntilStop =20, sl@0: sl@0: sl@0: /** sl@0: CMD21; reserved for future use. sl@0: */ sl@0: ECmd21 =21, sl@0: sl@0: sl@0: /** sl@0: CMD22; reserved for future use. sl@0: */ sl@0: ECmd22 =22, sl@0: sl@0: sl@0: /** sl@0: CMD23; define the number of blocks to be transferred in the following sl@0: multiple block read or write command. sl@0: */ sl@0: ECmdSetBlockCount =23, sl@0: sl@0: sl@0: /** sl@0: CMD24; write a single block to the card. sl@0: */ sl@0: ECmdWriteBlock =24, sl@0: sl@0: sl@0: /** sl@0: CMD25; continuously transfer data blocks to the card until interrupted sl@0: by ECmdStopTransmission. sl@0: sl@0: @see ECmdStopTransmission sl@0: */ sl@0: ECmdWriteMultipleBlock =25, sl@0: sl@0: sl@0: /** sl@0: CMD26; programming of the CID. sl@0: sl@0: This is issued once per card, and is normally reserved for sl@0: the manufacturer. sl@0: */ sl@0: ECmdProgramCID =26, sl@0: sl@0: sl@0: /** sl@0: CMD27; programming of the programmable bits of the CSD. sl@0: */ sl@0: ECmdProgramCSD =27, sl@0: sl@0: sl@0: /** sl@0: CMD28; set the write protect bit of the addressed group, if the card has sl@0: write protection features. sl@0: */ sl@0: ECmdSetWriteProt =28, sl@0: sl@0: sl@0: /** sl@0: CMD29; clear the write protect bit of the addressed group, if the card has sl@0: write protection features. sl@0: */ sl@0: ECmdClearWriteProt =29, sl@0: sl@0: sl@0: /** sl@0: CMD30; ask the card to send the status of the write protect bit, if sl@0: the card has write protection features. sl@0: */ sl@0: ECmdSendWriteProt =30, sl@0: sl@0: sl@0: /** sl@0: CMD31; reserved for future use. sl@0: */ sl@0: ECmd31 =31, sl@0: sl@0: sl@0: /** sl@0: CMD32; set the address of the first sector of the erase group. sl@0: */ sl@0: ECmdTagSectorStart =32, sl@0: sl@0: sl@0: /** sl@0: CMD33; set the address of the last sector in a continuous range within sl@0: the selected erase group, or the address of a single sector to be sl@0: selected for erase. sl@0: */ sl@0: ECmdTagSectorEnd =33, sl@0: sl@0: sl@0: /** sl@0: CMD34; remove one previously selected sector from the erase selection. sl@0: */ sl@0: ECmdUntagSector =34, sl@0: sl@0: sl@0: /** sl@0: CMD35; set the the address of the first erase group within a continuous sl@0: range to be selected for erase. sl@0: */ sl@0: ECmdTagEraseGroupStart =35, sl@0: sl@0: sl@0: /** sl@0: CMD36; set the address of the last erase group within a continuous range sl@0: to be selected for erase. sl@0: */ sl@0: ECmdTagEraseGroupEnd =36, sl@0: sl@0: sl@0: /** sl@0: CMD37; removes one previously selected erase group from the erase selection. sl@0: */ sl@0: ECmdUntagEraseGroup =37, sl@0: sl@0: sl@0: /** sl@0: CMD38; erase all previously selected sectors. sl@0: */ sl@0: ECmdErase =38, sl@0: sl@0: sl@0: /** sl@0: CMD39; read and write 8 bit (register) data fields. sl@0: */ sl@0: ECmdFastIO =39, sl@0: sl@0: sl@0: /** sl@0: CMD40; set the system into interrupt mode. sl@0: */ sl@0: ECmdGoIRQState =40, sl@0: sl@0: sl@0: /** sl@0: CMD41; reserved for future use. sl@0: */ sl@0: ECmd41 =41, sl@0: sl@0: sl@0: /** sl@0: CMD42; set/reset the password or lock/unlock the card. sl@0: */ sl@0: ECmdLockUnlock =42, sl@0: sl@0: sl@0: /** sl@0: CMD43; reserved for future use. sl@0: */ sl@0: ECmd43 =43, sl@0: sl@0: sl@0: /** sl@0: CMD44; reserved for future use. sl@0: */ sl@0: ECmd44 =44, sl@0: sl@0: sl@0: /** sl@0: CMD45; reserved for future use. sl@0: */ sl@0: ECmd45 =45, sl@0: sl@0: sl@0: /** sl@0: CMD46; reserved for future use. sl@0: */ sl@0: ECmd46 =46, sl@0: sl@0: sl@0: /** sl@0: CMD47; reserved for future use. sl@0: */ sl@0: ECmd47 =47, sl@0: sl@0: sl@0: /** sl@0: CMD48; reserved for future use. sl@0: */ sl@0: ECmd48 =48, sl@0: sl@0: sl@0: /** sl@0: CMD49; reserved for future use. sl@0: */ sl@0: ECmd49 =49, sl@0: sl@0: sl@0: /** sl@0: CMD50; reserved for future use. sl@0: */ sl@0: ECmd50 =50, sl@0: sl@0: sl@0: /** sl@0: CMD51; reserved for future use. sl@0: */ sl@0: ECmd51 =51, sl@0: sl@0: sl@0: /** sl@0: CMD52; reserved for future use. sl@0: */ sl@0: ECmd52 =52, sl@0: sl@0: sl@0: /** sl@0: CMD53; reserved for future use. sl@0: */ sl@0: ECmd53 =53, sl@0: sl@0: sl@0: /** sl@0: CMD54; reserved for future use. sl@0: */ sl@0: ECmd54 =54, sl@0: sl@0: sl@0: /** sl@0: CMD55; indicate to the card that the next command is an application sl@0: specific command rather than a standard command. sl@0: */ sl@0: ECmdAppCmd =55, sl@0: sl@0: sl@0: /** sl@0: CMD56; transfer a data block to the card, or get a data block from the card, sl@0: for general purpose/application specific commands. sl@0: */ sl@0: ECmdGenCmd =56, sl@0: sl@0: sl@0: /** sl@0: CMD57; reserved for future use. sl@0: */ sl@0: ECmd57 =57, sl@0: sl@0: sl@0: /** sl@0: CMD58; reserved for future use. sl@0: */ sl@0: ECmd58 =58, sl@0: sl@0: sl@0: /** sl@0: CMD59; reserved for future use. sl@0: */ sl@0: ECmd59 =59, sl@0: sl@0: sl@0: /** sl@0: CMD60; reserved for future use. sl@0: */ sl@0: ECmd60 =60, sl@0: sl@0: sl@0: /** sl@0: CMD61; reserved for future use. sl@0: */ sl@0: ECmd61 =61, sl@0: sl@0: sl@0: /** sl@0: CMD62; reserved for future use. sl@0: */ sl@0: ECmd62 =62, sl@0: sl@0: sl@0: /** sl@0: CMD63; reserved for future use. sl@0: */ sl@0: ECmd63 =63 sl@0: }; sl@0: sl@0: enum TMMCCommandTypeEnum sl@0: { sl@0: ECmdTypeUK, // UnKnown command type sl@0: ECmdTypeBC, // Broadcast Command sl@0: ECmdTypeBCR, // Broadcast Command with Response sl@0: ECmdTypeAC, // Addressed Command sl@0: ECmdTypeACS, // Addressed Command to a Selected card sl@0: ECmdTypeADTCS, // Addressed Data Transfer Command to a Selected card sl@0: ECmdTypeADC // Addressed Direct Command to a Selected card sl@0: }; sl@0: sl@0: enum TMMCResponseTypeEnum sl@0: { sl@0: ERespTypeNone, sl@0: ERespTypeUnknown, sl@0: ERespTypeR1, // 32 bits Status sl@0: ERespTypeR1B, // 32 bits Status with possible busy signal sl@0: ERespTypeR2, // 128 bits CID or CSD register sl@0: ERespTypeR3, // 32 bits OCR register sl@0: ERespTypeR4, // 32 bits Fast I/O sl@0: ERespTypeR5, // 32 bits IRQ sl@0: ERespTypeR6, sl@0: ERespTypeR7 // not currently defined for MMC sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Defines the set of media types for a MultiMediaCard. sl@0: */ sl@0: enum TMMCMediaTypeEnum sl@0: { sl@0: /** sl@0: A read only card. sl@0: */ sl@0: EMultiMediaROM, sl@0: sl@0: sl@0: /** sl@0: A writable card. sl@0: */ sl@0: EMultiMediaFlash, sl@0: sl@0: sl@0: /** sl@0: An I/O card. sl@0: */ sl@0: EMultiMediaIO, sl@0: sl@0: sl@0: /** sl@0: A card type that is neither read only, writable nor I/O. sl@0: */ sl@0: EMultiMediaOther, sl@0: sl@0: sl@0: /** sl@0: A card type that is not supported. sl@0: */ sl@0: EMultiMediaNotSupported sl@0: }; sl@0: sl@0: enum TMMCSessionTypeEnum sl@0: { sl@0: ECIMNakedSession =0, sl@0: ECIMUpdateAcq =1, sl@0: ECIMInitStack =2, sl@0: ECIMCheckStack =3, sl@0: ECIMSetupCard =4, sl@0: ECIMReadBlock =5, sl@0: ECIMWriteBlock =6, sl@0: ECIMReadMBlock =7, sl@0: ECIMWriteMBlock =8, sl@0: ECIMEraseSector =9, sl@0: ECIMEraseGroup =10, sl@0: ECIMReadIO =11, sl@0: ECIMWriteIO =12, sl@0: ECIMLockUnlock =13, sl@0: ECIMLockStack =14, sl@0: ECIMInitStackAfterUnlock =15, sl@0: ECIMAutoUnlock =16, sl@0: ECIMSleep =17 sl@0: }; sl@0: sl@0: const TUint KMMCMaxSessionTypeNumber = 18; sl@0: const TUint KMMCMinCustomSession = 1024; sl@0: sl@0: const TUint KMMCCmdDirDirBitPosition= KBit0; //fixed - dont change it sl@0: const TUint KMMCCmdDirIndBitPosition= (KBit5-KBit0); //fixed - dont change it sl@0: const TUint KMMCCmdDirWBitArgument= KBit5; sl@0: const TUint KMMCCmdDirNegate= KBit6; sl@0: const TUint KMMCCmdDirWBitDirect= KBit7; sl@0: sl@0: const TUint KMMCCmdReliableWrite = KBit31; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: An enum whose values specify the data transfer direction. sl@0: sl@0: @see TMMCCommandSpec sl@0: */ sl@0: enum TMMCCmdDirEnum sl@0: { sl@0: EDirNone = 0, sl@0: EDirRead = KMMCCmdDirWBitDirect, sl@0: EDirWrite = KMMCCmdDirWBitDirect|KMMCCmdDirDirBitPosition, sl@0: EDirWBit0 = KMMCCmdDirWBitArgument + 0, sl@0: EDirRBit0 = (KMMCCmdDirWBitArgument|KMMCCmdDirNegate) + 0 sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: An enum whose values specify the width of the data bus sl@0: sl@0: This enum is used by the DMMCStack::SetBusWidth() and TMMCMachineInfo.iMaxBusWidth. sl@0: */ sl@0: enum TBusWidth sl@0: { sl@0: EBusWidth1 = 0x00, sl@0: EBusWidth4 = 0x02, sl@0: EBusWidth8 = 0x03, sl@0: EBusWidthInvalid = KMaxTUint32 sl@0: }; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint8 KMMCLockUnlockErase = KBit3; // In first byte of CMD42 data block sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint8 KMMCLockUnlockLockUnlock = KBit2; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint8 KMMCLockUnlockClrPwd = KBit1; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint8 KMMCLockUnlockSetPwd = KBit0; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A utility class that contains convenience functions to handle conversion sl@0: to and from big-endian format. sl@0: */ sl@0: class TMMC sl@0: { sl@0: public: sl@0: static inline TUint32 BigEndian32(const TUint8*); sl@0: static inline void BigEndian4Bytes(TUint8* aPtr, TUint32 aVal); sl@0: }; sl@0: sl@0: sl@0: // Generic MMC layer constants sl@0: sl@0: const TInt KMaxMMCStacks=1; // Number of separate MMC buses sl@0: const TUint KMaxMMCardsPerStack=4; // Limits the number of cards in each stack sl@0: sl@0: const TUint KBroadcastToAllCards=0xFFFFFFFF; sl@0: sl@0: // MMC Spec related constants sl@0: sl@0: const TUint KMMCMaxResponseLength=16; // in bytes sl@0: const TUint KMMCCIDLength=16; sl@0: const TUint KMMCCSDLength=16; sl@0: const TUint KMMCExtendedCSDLength=512; sl@0: const TUint KMMCBusClockFOD=400; // Identification clock in kiloherz sl@0: const TUint KMMCCommandMask = 63; // Size of TMMCCommandEnum enumerator sl@0: sl@0: // Command Classes Bit Set sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassNone= 0; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassBasic= KBit0; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassStreamRead= KBit1; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassBlockRead= KBit2; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassStreamWrite= KBit3; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassBlockWrite= KBit4; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassErase= KBit5; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassWriteProtection=KBit6; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassLockCard= KBit7; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassApplication= KBit8; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassIOMode= KBit9; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassReserved10= KBit10; sl@0: const TUint32 KMMCCmdClassSwitch= KBit10; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCCmdClassReserved11= KBit11; sl@0: sl@0: // Specific MMC implementation constants sl@0: sl@0: const TUint KMaxMMCMachineStackDepth=20; // TMMCStateMachine stack depth sl@0: const TUint KMaxMMCCommandStackDepth=9; // Session TMMCCommandDesc stack depth sl@0: const TUint KMMCIdleCommandsAtRestart=2; // Number of CMD0s to be issued at initialisation sl@0: const TUint KMMCMaxJobsInStackWorkSet=8; // Number of sessions simultaneously served sl@0: const TUint KMMCPollGapInMilliseconds=40; sl@0: const TUint KMMCMaxPollAttempts=5; // 40*5 = 200ms sl@0: const TUint KMMCRetryGapInMilliseconds=10; sl@0: const TUint KMMCMaxTimeOutRetries=1; sl@0: const TUint KMMCMaxCRCRetries=1; sl@0: const TUint16 KMMCMaxUnlockRetries=4; sl@0: const TUint16 KMMCMaxAutoUnlockRetries=25; sl@0: const TUint KMMCMaxGlobalRetries=1; sl@0: const TUint16 KMMCSpecOpCondBusyTimeout=100 ; //MMC/SD Standard OCR timeout 1 second sl@0: const TUint16 KMMCMaxOpCondBusyTimeout=150; // 10*150 = 1500ms sl@0: const TUint KMMCLowVoltagePowerUpTimeoutInMilliseconds=2; // 1ms + 74 400KHz clock cycles sl@0: const TUint KMMCUnlockRetryGapInMilliseconds = 200; // Unlock retry gap sl@0: sl@0: // DMMCStack Modes Bit Set sl@0: const TUint32 KMMCModeEnableClientConfig = KBit0; // Merge with session iConfig sl@0: const TUint32 KMMCModeEnableTimeOutRetry = KBit1; // Auto retry on response time-outs sl@0: const TUint32 KMMCModeTimeOutRetryGap = KBit2; // Force timer delay between retries sl@0: const TUint32 KMMCModeEnableCRCRetry = KBit3; // Command or response CRC errors sl@0: const TUint32 KMMCModeCRCRetryGap = KBit4; sl@0: const TUint32 KMMCModeDataCRCRetry = KBit5; // Repeat data transaction from the last valid position sl@0: const TUint32 KMMCModeEnableUnlockRetry = KBit6; // Resend CMD42 for unreliable cards sl@0: const TUint32 KMMCModeEnablePreemption = KBit7; // Allow sessions to share the MMC bus sl@0: const TUint32 KMMCModePreemptOnBusy = KBit8; // Release bus control if busy sl@0: const TUint32 KMMCModePreemptOnRetry = KBit9; // Release bus control before timeout/crc retries sl@0: const TUint32 KMMCModePreemptInGaps = KBit10; // Preempt whenever gap timer is invoked sl@0: const TUint32 KMMCModeEnqueIfLocked = KBit11; // Enque session if DMMCStack is locked sl@0: const TUint32 KMMCModeCardControlled = KBit12; // Use Session CardP to get RCAs etc. sl@0: const TUint32 KMMCModeCompleteInStackDFC = KBit13; // Run DMMCStack in DFC when completing sl@0: const TUint32 KMMCModeEnableBusyPoll = KBit14; // Enables mechanism recovering from busy timeouts sl@0: const TUint32 KMMCModeBusyPollGap = KBit15; sl@0: const TUint32 KMMCModeEnableRetries = KBit16; // This mode removed disables all retries/polls sl@0: const TUint32 KMMCModeMask = KBit17 - KBit0; sl@0: sl@0: // The following modes are effective for MasterConfig only sl@0: const TUint32 KMMCModeClientPollAttempts = KBit20; sl@0: const TUint32 KMMCModeClientTimeOutRetries = KBit21; sl@0: const TUint32 KMMCModeClientCRCRetries = KBit22; sl@0: const TUint32 KMMCModeClientUnlockRetries = KBit23; sl@0: const TUint32 KMMCModeClientBusClock = KBit24; sl@0: const TUint32 KMMCModeClientClockIn = KBit25; sl@0: const TUint32 KMMCModeClientClockOut = KBit26; sl@0: const TUint32 KMMCModeClientResponseTimeOut = KBit27; sl@0: const TUint32 KMMCModeClientDataTimeOut = KBit28; sl@0: const TUint32 KMMCModeClientBusyTimeOut = KBit29; sl@0: const TUint32 KMMCModeClientiOpCondBusyTimeout = KBit30; sl@0: const TUint32 KMMCModeClientMask = KBit31 - KBit20; sl@0: sl@0: // The following modes cannot be enabled by a client if disabled in MasterConfig sl@0: const TUint32 KMMCModeMasterOverrides= sl@0: KMMCModeEnableClientConfig | sl@0: KMMCModeEnablePreemption | sl@0: KMMCModeEnqueIfLocked | sl@0: KMMCModeClientMask; sl@0: sl@0: // The following modes are always effective, even if the ClientConfig is disabled sl@0: const TUint32 KMMCModeClientOverrides= sl@0: KMMCModeEnableClientConfig | sl@0: KMMCModeCardControlled; sl@0: sl@0: sl@0: // The default MasterConfig modes sl@0: const TUint32 KMMCModeDefault= KMMCModeEnableClientConfig | sl@0: KMMCModeEnableRetries | sl@0: KMMCModeEnableTimeOutRetry | sl@0: KMMCModeTimeOutRetryGap | sl@0: KMMCModeEnableCRCRetry | sl@0: KMMCModeCRCRetryGap | sl@0: KMMCModeDataCRCRetry | sl@0: KMMCModeEnableUnlockRetry | sl@0: KMMCModeEnablePreemption | sl@0: KMMCModePreemptInGaps | sl@0: KMMCModeEnqueIfLocked | sl@0: KMMCModeCardControlled | sl@0: KMMCModeClientMask; sl@0: sl@0: sl@0: // MMC Error Code Bit Set sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: Indicates no error. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrNone=0; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: Timed out waiting for a response from the card after issuing a command. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrResponseTimeOut=KBit0; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: Timed out waiting for a data block to be received during a data read command. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrDataTimeOut= KBit1; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: Timed out waiting for a data block to be requested during a data write command. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrBusyTimeOut= KBit2; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: Timed out during the CIM_UPDATE_ACQ macro waiting for a card to power up. sl@0: Cards that are still powering up return busy in response to a SEND_OP_COND command. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrBusTimeOut= KBit3; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: The host has detected more cards in a stack that it can handle, or it has sl@0: detected more cards than it was expecting, for example, more cards than physical slots. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrTooManyCards= KBit4; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: The host has detected a CRC error in a response received from a card. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrResponseCRC= KBit5; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: The host has detected a CRC error in a data block received from a card. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrDataCRC= KBit6; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: The card has detected a CRC error in a command received from the host. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrCommandCRC= KBit7; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: An R1 response was received from the card with one or more of the error flags sl@0: set in the card status field. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrStatus= KBit8; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: A session was submitted without first being set-up with a card object, sl@0: or was set-up with a card object that is no longer present. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrNoCard= KBit9; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: The session had the stack locked but the MultiMediaCard controller had sl@0: to override the lock to perform some other bus activity. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrBrokenLock= KBit10; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: The card was powered down. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrPowerDown= KBit11; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: The session was stopped. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrAbort= KBit12; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: The stack has not yet been initialised. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrStackNotReady= KBit13; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: The session requested a service or feature that is not supported. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrNotSupported= KBit14; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: Indicates a general hardware related error. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrHardware= KBit15; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: An unexpected or inconsistent bus state has been detected. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrBusInconsistent=KBit16; sl@0: sl@0: sl@0: sl@0: sl@0: // SM control error codes sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: This is used interally by the MultiMediaCard controller. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrBypass= KBit17; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: This is used internally by the MultiMediaCard controller in the process sl@0: of re-initialising a card to recover from an inconsistent bus state. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrInitContext= KBit18; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: Indicates a bad argument. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrArgument= KBit19; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: A multiple block operation was requested, but the length specified was sl@0: less than that of a block. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrSingleBlock= KBit20; sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: const TUint32 KMMCErrUpdPswd= KBit21; sl@0: sl@0: sl@0: sl@0: sl@0: // General error codes sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: The card is locked. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrLocked= KBit22; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A MultiMediaCard error code. sl@0: sl@0: Indicates a general 'not found' type error. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrNotFound= KBit23; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: An MultiMediaCard error code: sl@0: sl@0: Indicates a general already 'exists type' error. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrAlreadyExists= KBit24; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: An MultiMediaCard error code: sl@0: sl@0: Indicates an unspecified error. sl@0: sl@0: @see TMMCErr sl@0: */ sl@0: const TUint32 KMMCErrGeneral= KBit25; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A bitmask of all MultiMediaCard error codes. sl@0: */ sl@0: const TUint32 KMMCErrAll = (KBit26 - KBit0); sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A subset of MultiMediaCard error codes. sl@0: */ sl@0: const TUint32 KMMCErrBasic = (KMMCErrAll & ~( sl@0: KMMCErrBypass | sl@0: KMMCErrUpdPswd | sl@0: KMMCErrInitContext | sl@0: KMMCErrArgument | sl@0: KMMCErrSingleBlock | sl@0: KMMCErrLocked | sl@0: KMMCErrNotFound | sl@0: KMMCErrAlreadyExists| sl@0: KMMCErrGeneral)); sl@0: sl@0: // DMMC Stack and Session control bits sl@0: sl@0: // Stack State bits sl@0: const TUint32 KMMCStackStateRunning= KBit0; // Stack scheduler active sl@0: const TUint32 KMMCStackStateWaitingToLock= KBit1; // sl@0: const TUint32 KMMCStackStateLocked= KBit2; // sl@0: const TUint32 KMMCStackStateWaitingDFC= KBit3; sl@0: const TUint32 KMMCStackStateInitInProgress= KBit4; sl@0: const TUint32 KMMCStackStateReScheduled= KBit5; sl@0: const TUint32 KMMCStackStateJobChooser= KBit6; sl@0: const TUint32 KMMCStackStateDoDeselect= KBit7; sl@0: const TUint32 KMMCStackStateBusInconsistent=KBit8; sl@0: const TUint32 KMMCStackStateInitPending= KBit9; sl@0: const TUint32 KMMCStackStateCardRemoved= KBit10; sl@0: const TUint32 KMMCStackStateSleepinProgress=KBit11; sl@0: const TUint32 KMMCStackStateSleep= KBit12; sl@0: const TUint32 KMMCStackStateYielding= KBit13; sl@0: sl@0: // Session Blocking bits definition sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A bit, which when set in a call to DMMCStack::BlockCurrentSession(), indicates sl@0: that the current session is to be blocked, awaiting an event that is to sl@0: be handled at the platform specific level. sl@0: sl@0: For example, the session may be waiting for: sl@0: sl@0: - a response following a command sl@0: - an interrupt indicating that data transfer is required sl@0: - a platform specific layer specific timer. sl@0: sl@0: @see DMMCStack::BlockCurrentSession() sl@0: */ sl@0: const TUint32 KMMCBlockOnASSPFunction= KBit0; sl@0: sl@0: const TUint32 KMMCBlockOnPollTimer = KBit1; sl@0: const TUint32 KMMCBlockOnRetryTimer = KBit2; sl@0: const TUint32 KMMCBlockOnNoRun = KBit3; sl@0: const TUint32 KMMCBlockOnDoor = KBit4; sl@0: const TUint32 KMMCBlockOnWaitToLock = KBit5; sl@0: const TUint32 KMMCBlockOnCardInUse = KBit6; sl@0: const TUint32 KMMCBlockOnPgmTimer = KBit7; sl@0: const TUint32 KMMCBlockOnInterrupt = KBit8; sl@0: const TUint32 KMMCBlockOnDataTransfer = KBit9; sl@0: const TUint32 KMMCBlockOnMoreData = KBit10; sl@0: const TUint32 KMMCBlockOnYielding = KBit11; // Yielding to other commands sl@0: sl@0: const TUint32 KMMCBlockOnAsynchMask = KMMCBlockOnASSPFunction | sl@0: KMMCBlockOnPollTimer | sl@0: KMMCBlockOnRetryTimer | sl@0: KMMCBlockOnPgmTimer | sl@0: KMMCBlockOnInterrupt | sl@0: KMMCBlockOnDataTransfer | sl@0: KMMCBlockOnMoreData; sl@0: sl@0: const TUint32 KMMCBlockOnGapTimersMask = KMMCBlockOnPollTimer | sl@0: KMMCBlockOnRetryTimer | sl@0: KMMCBlockOnPgmTimer; sl@0: sl@0: // Session State bits definition sl@0: const TUint32 KMMCSessStateEngaged = KBit0; // Processed by DMMCStack sl@0: const TUint32 KMMCSessStateInProgress = KBit1; // No longer safe to restart sl@0: const TUint32 KMMCSessStateCritical = KBit2; // Re-initialise the stack if aborted sl@0: const TUint32 KMMCSessStateSafeInGaps = KBit3; sl@0: const TUint32 KMMCSessStateDoReSchedule= KBit4; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: A bit that when set into DMMCSession::iState before calling sl@0: DMMCStack::UnBlockCurrentSession(), causes a DFC to be queued in order sl@0: to resume the state machine at some later stage. sl@0: */ sl@0: const TUint32 KMMCSessStateDoDFC = KBit5; sl@0: const TUint32 KMMCSessStateBlockOnDoor = KBit6; sl@0: const TUint32 KMMCSessStateCardIsGone = KBit7; sl@0: const TUint32 KMMCSessStateASSPEngaged = KBit8; sl@0: const TUint32 KMMCSessStateAllowDirectCommands = KBit9; // Allow Direct Commands (Using CMD) during Data Transfer sl@0: sl@0: class TCID sl@0: /** sl@0: CID class sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: inline TCID() {} // Default constructor sl@0: inline TCID(const TUint8*); sl@0: inline TCID& operator=(const TCID&); sl@0: inline TCID& operator=(const TUint8*); sl@0: inline TBool operator==(const TCID&) const; sl@0: inline TBool operator==(const TUint8*) const; sl@0: inline void Copy(TUint8*) const; // Copies big endian 16 bytes CID sl@0: inline TUint8 At(TUint anIndex) const; // Byte from CID at anIndex sl@0: private: sl@0: TUint8 iData[KMMCCIDLength]; // Big endian 128 bit bitfield representing CID sl@0: }; sl@0: sl@0: sl@0: class TCSD sl@0: /** sl@0: CSD class sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: inline TCSD() {memclr(this, sizeof(*this));} // Default constructor sl@0: inline TCSD(const TUint8*); sl@0: inline TCSD& operator=(const TCSD&); sl@0: inline TCSD& operator=(const TUint8*); sl@0: inline void Copy(TUint8*) const; // Copies big endian 16 bytes CSD sl@0: inline TUint8 At(TUint anIndex) const; // Byte from CSD at anIndex sl@0: public: sl@0: inline TUint CSDStructure() const; sl@0: inline TUint SpecVers() const; sl@0: inline TUint Reserved120() const; sl@0: inline TUint TAAC() const; sl@0: inline TUint NSAC() const; sl@0: inline TUint TranSpeed() const; sl@0: inline TUint CCC() const; sl@0: inline TUint ReadBlLen() const; sl@0: inline TBool ReadBlPartial() const; sl@0: inline TBool WriteBlkMisalign() const; sl@0: inline TBool ReadBlkMisalign() const; sl@0: inline TBool DSRImp() const; sl@0: inline TUint Reserved74() const; sl@0: inline TUint CSize() const; sl@0: inline TUint VDDRCurrMin() const; sl@0: inline TUint VDDRCurrMax() const; sl@0: inline TUint VDDWCurrMin() const; sl@0: inline TUint VDDWCurrMax() const; sl@0: inline TUint CSizeMult() const; sl@0: inline TUint EraseGrpSize() const; sl@0: inline TUint EraseGrpMult() const; sl@0: inline TUint WPGrpSize() const; sl@0: inline TBool WPGrpEnable() const; sl@0: inline TUint DefaultECC() const; sl@0: inline TUint R2WFactor() const; sl@0: inline TUint WriteBlLen() const; sl@0: inline TBool WriteBlPartial() const; sl@0: inline TUint Reserved16() const; sl@0: inline TBool FileFormatGrp() const; sl@0: inline TBool Copy() const; sl@0: inline TBool PermWriteProtect() const; sl@0: inline TBool TmpWriteProtect() const; sl@0: inline TUint FileFormat() const; sl@0: inline TUint ECC() const; sl@0: inline TUint CRC() const; sl@0: public: sl@0: IMPORT_C TUint DeviceSize() const; // Uses functions above to calculate device capacity sl@0: IMPORT_C TMMCMediaTypeEnum MediaType() const; sl@0: IMPORT_C TUint ReadBlockLength() const; // Read Block Length in bytes sl@0: IMPORT_C TUint WriteBlockLength() const;// Write Block Length in bytes sl@0: IMPORT_C TUint EraseSectorSize() const; // Erase sector size (default 512 bytes) sl@0: IMPORT_C TUint EraseGroupSize() const; // Erase group size (default 16* bytes) sl@0: IMPORT_C TUint MinReadCurrentInMilliamps() const; sl@0: IMPORT_C TUint MinWriteCurrentInMilliamps() const; sl@0: IMPORT_C TUint MaxReadCurrentInMilliamps() const; sl@0: IMPORT_C TUint MaxWriteCurrentInMilliamps() const; sl@0: IMPORT_C TUint MaxTranSpeedInKilohertz() const; sl@0: public: sl@0: IMPORT_C TUint CSDField(const TUint& aTopBit, const TUint& aBottomBit) const; /**< @internalComponent */ sl@0: TUint8 iData[KMMCCSDLength]; /**< @internalComponent */ // Big endian 128 bit bitfield representing CSD sl@0: }; sl@0: sl@0: sl@0: class TExtendedCSD sl@0: /** sl@0: Extended CSD register class. sl@0: For more information about this register, see the MultimediaCard System sl@0: Specification, Version 4.1+ sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: /** sl@0: An enum used by TExtendedCSD::GetWriteArg() to construct a TMMCArgument object. sl@0: The value chosen defines how the register or command set is to be modified. sl@0: */ sl@0: enum TExtCSDAccessBits sl@0: { sl@0: /** Change the card's command set */ sl@0: ECmdSet, sl@0: /** Set the specified bits */ sl@0: ESetBits, sl@0: /** Clear the specified bits */ sl@0: EClearBits, sl@0: /** Write the specified byte */ sl@0: EWriteByte sl@0: }; sl@0: /** sl@0: This enum defines various field offsets into the Modes Segment (i.e. sl@0: the writable part) of the Extended CSD register. sl@0: */ sl@0: enum TExtCSDModesFieldIndex sl@0: { sl@0: /** Offset of the CMD_SET field */ sl@0: ECmdSetIndex = 191, sl@0: /** Offset of the CMD_SET_REV field */ sl@0: ECmdSetRevIndex = 189, sl@0: /** Offset of the POWER_CLASS field */ sl@0: EPowerClassIndex = 187, sl@0: /** Offset of the HS_TIMING field */ sl@0: EHighSpeedInterfaceTimingIndex = 185, sl@0: /** Offset of the BUS_WIDTH field */ sl@0: EBusWidthModeIndex = 183, sl@0: /** Offset of the BOOT_CONFIG field */ sl@0: EBootConfigIndex = 179, sl@0: /** Offset of the BOOT_BUS_WIDTH field */ sl@0: EBootBusWidthIndex = 177, sl@0: /** Offset of the ERASE_GROUP_DEF field */ sl@0: EEraseGroupDefIndex = 175 sl@0: }; sl@0: sl@0: /** sl@0: This enum defines various field offsets into the Properties Segment (i.e. sl@0: the read-only part) of the Extended CSD register. sl@0: */ sl@0: enum TExtCSDPropertiesFieldIndex sl@0: { sl@0: /** Offset of the EXT_CSD_REV field */ sl@0: EExtendedCSDRevIndex = 192, sl@0: /** Offset of the CARD_TYPE field */ sl@0: ECardTypeIndex = 196, sl@0: /** Offset of the ACC_SIZE field */ sl@0: EAccessSizeIndex = 225, sl@0: /** Offset of the HC_ERASE_GRP_SIZE field */ sl@0: EHighCapacityEraseGroupSizeIndex = 224 sl@0: }; sl@0: sl@0: /** This enum defines the bus width encoding used by the BUS_WIDTH field */ sl@0: enum TExtCSDBusWidths sl@0: { sl@0: EExtCsdBusWidth1 = 0x00, sl@0: EExtCsdBusWidth4 = 0x01, sl@0: EExtCsdBusWidth8 = 0x02 sl@0: }; sl@0: sl@0: /** sl@0: This enum defines the different MMCV4.x card types available as defined sl@0: in the CARD_TYPE field sl@0: */ sl@0: enum TCardTypes sl@0: { sl@0: EHighSpeedCard26Mhz = 0x01, sl@0: EHighSpeedCard52Mhz = 0x02 sl@0: }; sl@0: sl@0: /** sl@0: This enum defines the boot config encoding used by the BOOT_CONFIG field sl@0: */ sl@0: enum TExtCSDBootConfig sl@0: { sl@0: ESelectUserArea = 0x00, sl@0: ESelectBootPartition1 = 0x01, sl@0: ESelectBootPartition2 = 0x02, sl@0: EEnableBootPartition1forBoot = 0x08, sl@0: EEnableBootPartition2forBoot = 0x10, sl@0: EEnableUserAreaforBoot = 0x38, sl@0: EEnableBootAck = 0x40 sl@0: }; sl@0: sl@0: /** sl@0: This enum defines the Boot Bus Width encoding used by the BOOT_BUS_WIDTH field sl@0: */ sl@0: enum TExtCSDBootBusWidth sl@0: { sl@0: EBootBusWidth1Bit = 0x00, sl@0: EBootBusWidth4Bit = 0x01, sl@0: EBootBusWidth8Bit = 0x02, sl@0: EResetBusWidthafterBoot = 0x08 sl@0: }; sl@0: sl@0: /** sl@0: This enum defines the Erase Group Definition encoding sl@0: used by the ERASE_GROUP_DEF field sl@0: */ sl@0: enum TExtCSDEraseGroupDef sl@0: { sl@0: sl@0: EEraseGrpDefEnableOldSizes = 0x00, sl@0: EEraseGrpDefEnableHighCapSizes = 0x01 sl@0: }; sl@0: sl@0: public: sl@0: /** Default constructor */ sl@0: inline TExtendedCSD(); sl@0: /** sl@0: Constructor sl@0: @param aPtr a byte buffer containing the contents of the register sl@0: */ sl@0: inline TExtendedCSD(const TUint8* aPtr); sl@0: /** sl@0: Copy constructor sl@0: @param aCSD a reference to another instance of the same class sl@0: */ sl@0: inline TExtendedCSD& operator=(const TExtendedCSD& aCSD); sl@0: /** sl@0: Copy constructor sl@0: @param aPtr a byte buffer containing the contents of the register sl@0: */ sl@0: inline TExtendedCSD& operator=(const TUint8* aPtr); sl@0: sl@0: /** Returns the byte at a particular offset into the register sl@0: @param anIndex the offset into the register sl@0: */ sl@0: inline TUint8 At(TUint anIndex) const; sl@0: sl@0: /** returns a pointer to the raw data */ sl@0: inline TUint8* Ptr(); sl@0: sl@0: /** sl@0: Constructs and then returns a TMMCArgument which can be used to sl@0: write to the register using the SWITCH command (CMD6) sl@0: @param aAccess specifies how the register or command set is to be modified. sl@0: @param aIndex the offset into the register sl@0: @param aValue the value to write to the field in the register sl@0: @param aCmdSet The command set to write. Valid if aAccess = ECmdSet sl@0: */ sl@0: inline static TMMCArgument GetWriteArg(TExtCSDAccessBits aAccess, TExtCSDModesFieldIndex aIndex, TUint aValue, TUint aCmdSet); sl@0: sl@0: /** returns the contents of the CMD_SET field */ sl@0: inline TUint SupportedCmdSet() const; sl@0: sl@0: /** returns the contents of the SEC_COUNT field */ sl@0: inline TUint SectorCount() const; sl@0: sl@0: /** returns the contents of the MIN_PERF_W_8_52 field */ sl@0: inline TUint MinPerfWrite8Bit52Mhz() const; sl@0: sl@0: /** returns the contents of the MIN_PERF_R_8_52 field */ sl@0: inline TUint MinPerfRead8Bit52Mhz() const; sl@0: sl@0: /** returns the contents of the MIN_PERF_W_8_26_4_52 field */ sl@0: inline TUint MinPerfWrite8Bit26Mhz_4Bit52Mhz() const; sl@0: sl@0: /** returns the contents of the MIN_PERF_R_8_26_4_52 field */ sl@0: inline TUint MinPerfRead8Bit26Mhz_4Bit52Mhz() const; sl@0: sl@0: /** returns the contents of the MIN_PERF_W_4_26 field */ sl@0: inline TUint MinPerfWrite4Bit26Mhz() const; sl@0: sl@0: /** returns the contents of the MIN_PERF_R_4_26 field */ sl@0: inline TUint MinPerfRead4Bit26Mhz() const; sl@0: sl@0: /** returns the contents of the PWR_CL_26_360 field */ sl@0: inline TUint PowerClass26Mhz360V() const; sl@0: sl@0: /** returns the contents of the PWR_CL_52_360 field */ sl@0: inline TUint PowerClass52Mhz360V() const; sl@0: sl@0: /** returns the contents of the PWR_CL_26_195 field */ sl@0: inline TUint PowerClass26Mhz195V() const; sl@0: sl@0: /** returns the contents of the PWR_CL_52_195 field */ sl@0: inline TUint PowerClass52Mhz195V() const; sl@0: sl@0: /** returns the contents of the CARD_TYPE field */ sl@0: inline TUint CardType() const; sl@0: sl@0: /** returns the contents of the CSD_STRUCTURE field */ sl@0: inline TUint CSDStructureVer() const; sl@0: sl@0: /** returns the contents of the EXT_CSD_REV field */ sl@0: inline TUint ExtendedCSDRev() const; sl@0: sl@0: /** returns the contents of the CMD_SET field */ sl@0: inline TUint CmdSet() const; sl@0: sl@0: /** returns the contents of the CMD_SET_REV field */ sl@0: inline TUint CmdSetRev() const; sl@0: sl@0: /** returns the contents of the POWER_CLASS field */ sl@0: inline TUint PowerClass() const; sl@0: sl@0: /** returns the contents of the HS_TIMING field */ sl@0: inline TUint HighSpeedTiming() const; sl@0: sl@0: /** returns the contents of the BUS_WIDTH field */ sl@0: inline TUint BusWidthMode() const; sl@0: sl@0: /** returns the contents of the BOOT_CONFIG field */ sl@0: inline TUint BootConfig() const; sl@0: sl@0: /** returns the contents of the BOOT_BUS_WIDTH field */ sl@0: inline TUint BootBusWidth() const; sl@0: sl@0: /** returns the contents of the ERASE_GROUP_DEF field */ sl@0: inline TUint EraseGroupDef() const; sl@0: sl@0: /** returns the contents of the ACC_SIZE field */ sl@0: inline TUint AccessSize() const; sl@0: sl@0: /** returns the contents of the HC_ERASE_GRP_SIZE field */ sl@0: inline TUint HighCapacityEraseGroupSize() const; sl@0: sl@0: /** returns the contents of the BOOT_INFO field */ sl@0: inline TUint BootInfo() const; sl@0: sl@0: /** returns the contents of the BOOT_SIZE_MUTLI field */ sl@0: inline TUint BootSizeMultiple() const; sl@0: sl@0: /** returns the contents of the ERASE_TIMEOUT_MULT field */ sl@0: inline TUint EraseTimeoutMultiple() const; sl@0: sl@0: /** returns the contents of the REL_WR_SEC_C field */ sl@0: inline TUint ReliableWriteSector() const; sl@0: sl@0: /** returns the contents of the HC_WP_GRP_SIZE field */ sl@0: inline TUint HighCapacityWriteProtectGroupSize() const; sl@0: sl@0: /** returns the contents of the S_C_VCC field */ sl@0: inline TUint SleepCurrentVcc() const; sl@0: sl@0: /** returns the contents of the S_C_VCCQ field */ sl@0: inline TUint SleepCurrentVccQ() const; sl@0: sl@0: /** returns the contents of the S_A_TIMEOUT field */ sl@0: inline TUint SleepAwakeTimeout() const; sl@0: sl@0: private: sl@0: /** sl@0: @internalComponent little endian 512 byte field representing extended CSD sl@0: */ sl@0: TUint8 iData[KMMCExtendedCSDLength]; sl@0: }; sl@0: sl@0: sl@0: // 32 bit MMC card status field (response R1) sl@0: sl@0: const TUint32 KMMCStatAppCmd= KBit5; sl@0: const TUint32 KMMCStatSwitchError= KBit7; sl@0: const TUint32 KMMCStatReadyForData= KBit8; sl@0: const TUint32 KMMCStatCurrentStateMask= (KBit13-KBit9); sl@0: const TUint32 KMMCStatEraseReset= KBit13; sl@0: const TUint32 KMMCStatCardECCDisabled= KBit14; sl@0: const TUint32 KMMCStatWPEraseSkip= KBit15; sl@0: const TUint32 KMMCStatErrCSDOverwrite= KBit16; sl@0: const TUint32 KMMCStatErrOverrun= KBit17; sl@0: const TUint32 KMMCStatErrUnderrun= KBit18; sl@0: const TUint32 KMMCStatErrUnknown= KBit19; sl@0: const TUint32 KMMCStatErrCCError= KBit20; sl@0: const TUint32 KMMCStatErrCardECCFailed= KBit21; sl@0: const TUint32 KMMCStatErrIllegalCommand=KBit22; sl@0: const TUint32 KMMCStatErrComCRCError= KBit23; sl@0: const TUint32 KMMCStatErrLockUnlock= KBit24; sl@0: const TUint32 KMMCStatCardIsLocked= KBit25; sl@0: const TUint32 KMMCStatErrWPViolation= KBit26; sl@0: const TUint32 KMMCStatErrEraseParam= KBit27; sl@0: const TUint32 KMMCStatErrEraseSeqError= KBit28; sl@0: const TUint32 KMMCStatErrBlockLenError= KBit29; sl@0: const TUint32 KMMCStatErrAddressError= KBit30; sl@0: const TUint32 KMMCStatErrOutOfRange= KBit31; sl@0: sl@0: const TUint32 KMMCStatErrorMask= KMMCStatErrOutOfRange | sl@0: KMMCStatErrAddressError | sl@0: KMMCStatErrBlockLenError| sl@0: KMMCStatErrEraseSeqError| sl@0: KMMCStatErrEraseParam | sl@0: KMMCStatErrWPViolation | sl@0: KMMCStatErrLockUnlock | sl@0: KMMCStatErrCardECCFailed| sl@0: KMMCStatErrCCError | sl@0: KMMCStatErrUnknown | sl@0: KMMCStatErrUnderrun | sl@0: KMMCStatErrOverrun | sl@0: KMMCStatErrCSDOverwrite; sl@0: sl@0: sl@0: const TUint32 KMMCStatClearByReadMask= KMMCStatErrOutOfRange | sl@0: KMMCStatErrAddressError | sl@0: KMMCStatErrBlockLenError| sl@0: KMMCStatErrEraseSeqError| sl@0: KMMCStatErrEraseParam | sl@0: KMMCStatErrWPViolation | sl@0: KMMCStatErrLockUnlock | sl@0: KMMCStatErrCardECCFailed| sl@0: KMMCStatErrCCError | sl@0: KMMCStatErrUnknown | sl@0: KMMCStatErrUnderrun | sl@0: KMMCStatErrOverrun | sl@0: KMMCStatErrCSDOverwrite | sl@0: KMMCStatWPEraseSkip | sl@0: KMMCStatEraseReset | sl@0: KMMCStatAppCmd; sl@0: sl@0: enum TMMCardStateEnum sl@0: { sl@0: ECardStateIdle = 0, sl@0: ECardStateReady = (1 << 9), sl@0: ECardStateIdent = (2 << 9), sl@0: ECardStateStby = (3 << 9), sl@0: ECardStateTran = (4 << 9), sl@0: ECardStateData = (5 << 9), sl@0: ECardStateRcv = (6 << 9), sl@0: ECardStatePrg = (7 << 9), sl@0: ECardStateDis = (8 << 9), sl@0: ECardStateBtst = (9 << 9), sl@0: ECardStateSlp = (10 << 9) sl@0: }; sl@0: sl@0: class TMMCStatus sl@0: /** sl@0: MMC Status class. sl@0: This class can be used to get the MMC card state machine and response status. sl@0: For the details of MMC card state machine and command response refer to MMC card specification. sl@0: sl@0: @see DMMCStack sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: /** sl@0: * Default constructor. sl@0: */ sl@0: inline TMMCStatus() {} sl@0: inline TMMCStatus(const TUint8*); sl@0: inline TMMCStatus(const TUint32&); sl@0: inline operator TUint32() const; sl@0: inline TUint32 Error() const; sl@0: inline TMMCardStateEnum State() const; sl@0: inline void UpdateState(TMMCardStateEnum aState); sl@0: private: sl@0: TUint32 iData; // 32 bit bitfield representing status register sl@0: }; sl@0: sl@0: sl@0: sl@0: const TUint32 KMMCOCRBusy = KBit31; // OCR Busy Bit (Response R3) sl@0: const TUint32 KMMCOCRAccessModeHCS = KBit30; // OCR Access Mode + SD HCS Bit (Response R3) sl@0: const TUint32 KMMCOCRLowVoltage = KBit7; // 1.65 - 1.95 volt support sl@0: const TUint32 KMMCOCRAccessModeMask = KBit30 | KBit29; // OCR Access Mode : [00 : Byte], [10 : Block] sl@0: sl@0: sl@0: sl@0: /** sl@0: Defines the bit value that can be used in TPBusPsuInfo::iVoltageSupported sl@0: to indicate that the MultiMediaCard PSU supports voltage adjustment. sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: #define KMMCAdjustableOpVoltage KMMCOCRBusy // Use same bit to flag ASSP PSU supports voltage adjustment. sl@0: sl@0: sl@0: class TMMCArgument sl@0: /** sl@0: MMC Argument class sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: inline TMMCArgument(); sl@0: inline TMMCArgument(const TUint32&); sl@0: inline TMMCArgument(TRCA); sl@0: inline TMMCArgument(TDSR); sl@0: inline operator TUint32() const; sl@0: inline void SetRCA(TRCA); sl@0: private: sl@0: TUint32 iData; // 32 bit bitfield representing the argument sl@0: }; sl@0: sl@0: sl@0: class TRCA sl@0: /** sl@0: MMC RCA (Relative Card Address) class sl@0: */ sl@0: { sl@0: public: sl@0: inline TRCA() {} sl@0: inline TRCA(TUint16); sl@0: inline TRCA(TInt); sl@0: inline TRCA(TMMCArgument); sl@0: inline operator TUint16() const; sl@0: private: sl@0: TUint16 iData; // 16 bit bitfield representing MultiMedia Card's RCA sl@0: }; sl@0: sl@0: sl@0: class TDSR sl@0: /** sl@0: MMC DSR (Driver Stage Register) class sl@0: */ sl@0: { sl@0: public: sl@0: inline TDSR(); sl@0: inline TDSR(TUint16); sl@0: inline operator TUint16() const; sl@0: private: sl@0: TUint16 iData; // 16 bit bitfield representing MultiMedia Card's DSR sl@0: }; sl@0: sl@0: sl@0: // Card specific information and context sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCardHasPassword= KBit0; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCardIsWriteProtected= KBit1; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUint32 KMMCardIsLockable= KBit2; sl@0: const TUint32 KMMCardIsHighCapacity= KBit3; sl@0: const TUint32 KMMCardIsHighSpeed= KBit4; sl@0: sl@0: const TUint32 KMMCardMMCFlagMask= 0x0000ffff; sl@0: sl@0: const TUint32 KMMCardFirstCustomFlag= KBit16; sl@0: const TUint32 KMMCardCustomFlagMask= 0xffff0000; sl@0: sl@0: const TUint32 KMMCardHighCapBlockSize= 512; sl@0: const TUint32 KMMCardHighCapBlockSizeLog2= 9; sl@0: sl@0: NONSHARABLE_CLASS(TMMCard) sl@0: /** sl@0: MMC card class sl@0: */ sl@0: { sl@0: public: sl@0: inline TBool IsHighCapacity() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: TMMCard(); sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: inline TBool IsPresent() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: IMPORT_C TBool IsReady() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: IMPORT_C TBool IsLocked() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: inline TMMCMediaTypeEnum MediaType() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: inline TUint DeviceSize() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: inline const TCID& CID() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: inline const TCSD& CSD() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: inline const TExtendedCSD& ExtendedCSD() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: inline TRCA RCA() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: inline TBool HasPassword() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: inline TBool IsWriteProtected() const; // Always EFalse in MMC build sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: inline TInt BusWidth() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: inline void SetBusWidth(TInt aBusWidth); sl@0: sl@0: /** @internalTechnology */ sl@0: inline void SetHighSpeedClock(TUint32 aHighSpeedClock); sl@0: sl@0: /** @internalTechnology */ sl@0: inline TUint32 HighSpeedClock() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: virtual TUint32 PreferredWriteGroupLength() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: virtual TInt GetFormatInfo(TLDFormatInfo& aFormatInfo) const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: virtual TUint32 MinEraseSectorSize() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: virtual TUint32 EraseSectorSize() const; sl@0: sl@0: virtual TUint MaxTranSpeedInKilohertz() const; sl@0: sl@0: virtual TInt GetEraseInfo(TMMCEraseInfo& anEraseInfo) const; sl@0: sl@0: /** @publishedPartner sl@0: @released sl@0: sl@0: Returns the maximum block length supported by the card encoded as a logarithm. sl@0: This may be less than the READ_BL_LEN field in the CSD sl@0: register depending on the type of card and it's capacity. sl@0: */ sl@0: virtual TInt MaxReadBlLen() const; sl@0: sl@0: /** @publishedPartner sl@0: @released sl@0: sl@0: Returns the maximum write block length supported by the card encoded as a logarithm. sl@0: This may be less than the WRITE_BL_LEN field in the CSD sl@0: register depending on the type of card and it's capacity. sl@0: */ sl@0: virtual TInt MaxWriteBlLen() const; sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: virtual TInt64 DeviceSize64() const; sl@0: sl@0: private: sl@0: inline TInt Number() const; sl@0: public: sl@0: TInt iIndex; sl@0: TMMCStatus iStatus; // last card's status sl@0: TUint32 iSetBlockLen; // current block length set for the card sl@0: TMMCCommandEnum iLastCommand; // Last Command code issued for the card sl@0: TCID iCID; sl@0: TCSD iCSD; sl@0: TRCA iRCA; sl@0: DMMCSession* iUsingSessionP; // session which has this card attached sl@0: TUint32 iFlags; sl@0: TExtendedCSD iExtendedCSD; sl@0: private: sl@0: TUint32 iHighSpeedClock; sl@0: TInt iSpare[4]; sl@0: TInt iBusWidth; sl@0: friend class DMMCStack; sl@0: friend class TMMCardArray; sl@0: }; sl@0: sl@0: class TMMCardArray sl@0: /** sl@0: MMC card array class sl@0: */ sl@0: { sl@0: public: sl@0: inline TMMCardArray(DMMCStack* anOwningStack); sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: IMPORT_C virtual TInt AllocCards(); sl@0: sl@0: void InitNewCardScan(); sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: IMPORT_C void AddNewCard(const TUint8* aCID,TRCA* aNewRCA); sl@0: sl@0: inline TUint NewCardCount(); sl@0: inline TInt CardsPresent(); sl@0: inline TMMCard* NewCardP(TUint aNewCardNumber); sl@0: inline TMMCard* CardP(TUint aCardNumber); sl@0: inline TMMCard& Card(TUint aCardNumber); sl@0: inline TMMCard& NewCard(TUint aCardNumber); sl@0: TInt MergeCards(TBool aFirstPass); sl@0: void UpdateAcquisitions(TUint* aMaxClock); sl@0: sl@0: /** @internalTechnology */ sl@0: TInt CardIndex(const TMMCard* aCard); sl@0: sl@0: /** @publishedPartner sl@0: @released */ sl@0: IMPORT_C virtual void DeclareCardAsGone(TUint aCardNumber); sl@0: sl@0: protected: // initialized by AllocCards() sl@0: void MoveCardAndLockRCA(TMMCard& aSrc,TMMCard& aDest,TInt aDestIndex); sl@0: DMMCStack* iOwningStack; sl@0: TInt iCardsPresent; sl@0: TUint iNewCardsCount; sl@0: TMMCard* iCards[KMaxMMCardsPerStack]; sl@0: TMMCard* iNewCards[KMaxMMCardsPerStack]; sl@0: }; sl@0: sl@0: // MMC Command descriptor sl@0: sl@0: const TUint32 KMMCCmdFlagBytesValid= KBit0; // iBytesDone has a valid data sl@0: const TUint32 KMMCCmdFlagTransStopped= KBit1; // CMD12 has been successfully issued sl@0: const TUint32 KMMCCmdFlagStatusReceived=KBit2; // Raised by ASSP layer, cleared by ExecCommandSM() sl@0: const TUint32 KMMCCmdFlagExecTopBusy= KBit3; // ExecCommandSM() flag sl@0: const TUint32 KMMCCmdFlagExecSelBusy= KBit4; // ExecCommandSM() flag sl@0: const TUint32 KMMCCmdFlagBlockAddress= KBit5; // Block addressing mode sl@0: const TUint32 KMMCCmdFlagDMARamValid= KBit6; // Memory is DMA'able flag sl@0: const TUint32 KMMCCmdFlagDoubleBuffer= KBit7; // The current DT command is double-buffered sl@0: const TUint32 KMMCCmdFlagPhysAddr= KBit8; // Address is a physical address sl@0: const TUint32 KMMCCmdFlagReliableWrite= KBit9; // Current command is Reliable Write sl@0: sl@0: const TUint32 KMMCCmdFlagASSPFlags= KMMCCmdFlagBytesValid | sl@0: KMMCCmdFlagTransStopped | sl@0: KMMCCmdFlagStatusReceived; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: The MultiMediaCard command specification. sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: class TMMCCommandSpec sl@0: { sl@0: public: sl@0: /** sl@0: The command class as defined by the MultiMediaCard System Specification. sl@0: */ sl@0: TUint32 iCommandClass; sl@0: sl@0: /** sl@0: The command type as defined by the MultiMediaCard System Specification. sl@0: */ sl@0: TMMCCommandTypeEnum iCommandType; sl@0: sl@0: /** sl@0: The data transfer direction. sl@0: */ sl@0: TMMCCmdDirEnum iDirection; sl@0: sl@0: /** sl@0: ETrue indicates more than one data block is to be tranferred. sl@0: */ sl@0: TBool iMultipleBlocks; sl@0: sl@0: /** sl@0: ETrue indicates use standard stop transmission mode. sl@0: */ sl@0: TBool iUseStopTransmission; // CMD12 has to be used in the end sl@0: sl@0: /** sl@0: The expected response type. sl@0: sl@0: Note: sl@0: sl@0: - if this is EResponseTypeNone, then no response is expected. sl@0: - if this is ERespTypeR2, then a long (128-bit) response is expected. sl@0: - for all other types, a standard (32-bit) response is expected. sl@0: */ sl@0: TMMCResponseTypeEnum iResponseType; sl@0: sl@0: /** sl@0: Expected response length (currently 4 or 16 bytes). sl@0: */ sl@0: TUint iResponseLength; sl@0: }; sl@0: sl@0: class TMMCIdxCommandSpec sl@0: /** sl@0: MMC Index command spec class sl@0: */ sl@0: { sl@0: public: sl@0: TInt iIdx; sl@0: TMMCCommandSpec iSpec; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: MMC command description. sl@0: sl@0: When issuing an individual command over the bus, the MultiMediaCard sl@0: controller uses an object of this type to specify the parameters sl@0: for the command, and to receive back any response. sl@0: sl@0: Commands are issued by passing an object of this type to sl@0: the DMMCStack::IssueMMCCommandSM() function, which is implemented by sl@0: the platform specific layer. sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: class TMMCCommandDesc sl@0: { sl@0: public: sl@0: IMPORT_C TInt Direction() const; // returns -1/0/+1 for read/none/write sl@0: sl@0: inline TBool IsBlockCmd() const; sl@0: inline TUint32 NumBlocks() const; sl@0: inline TInt64 Arg64() const; sl@0: inline TBool IsDoubleBuffered() const; sl@0: inline TUint32 BufferLength() const; sl@0: inline TUint32 BlockLength() const; sl@0: inline TBool IsPhysicalAddress() const; sl@0: TBool AdjustForBlockOrByteAccess(const DMMCSession& aSession); sl@0: sl@0: void Dump(TUint8* aResponseP, TMMCErr aErr); sl@0: sl@0: public: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TUint32 iFlags; sl@0: sl@0: /** sl@0: The command code. sl@0: sl@0: This can be written directly to the MMC controller hardware. sl@0: */ sl@0: TMMCCommandEnum iCommand; sl@0: sl@0: /** sl@0: The argument to be supplied with the command. sl@0: sl@0: This can be written directly to the MMC controller hardware. sl@0: */ sl@0: TMMCArgument iArgument; sl@0: sl@0: /** sl@0: The total length of the data to be tranferred. sl@0: */ sl@0: TUint32 iTotalLength; sl@0: sl@0: /** sl@0: A pointer to the location from where the data is to be read, or written. sl@0: */ sl@0: TUint8* iDataMemoryP; sl@0: sl@0: /** sl@0: The block length to be used in a data transaction. sl@0: */ sl@0: TUint32 iBlockLength; sl@0: sl@0: /** sl@0: The MultiMediaCard command specification. sl@0: */ sl@0: TMMCCommandSpec iSpec; sl@0: sl@0: /** sl@0: The number of bytes transferred since the last time the card was selected. sl@0: */ sl@0: TUint32 iBytesDone; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TUint iPollAttempts; // Retry counters sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TUint iTimeOutRetries; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TUint iCRCRetries; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TUint16 iUnlockRetries; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TUint16 iOpCondBusyTimeout; // Units of 10mS sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TUint iCustomRetries; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TUint32 iExecNotHandle; // error codes to not handle in ExecCommandSM() sl@0: sl@0: /** sl@0: The area into which the command response is put. sl@0: sl@0: This is in big-endian format. sl@0: */ sl@0: TUint8 iResponse[KMMCMaxResponseLength]; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: MMC bus configuration. sl@0: sl@0: An object of this type is passed to the Variant implementation sl@0: of DMMCStack::SetBusConfigDefaults(), which should fill the public data sl@0: members with appropriate information and values. sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: class TMMCBusConfig sl@0: { sl@0: public: sl@0: /** sl@0: The hardware interface clock, in KHz. sl@0: */ sl@0: TUint iBusClock; sl@0: sl@0: sl@0: /** sl@0: The bus clock when clocking in data, in KHz. sl@0: */ sl@0: TUint iClockIn; sl@0: sl@0: sl@0: /** sl@0: The bus clock when clocking out data, in KHz. sl@0: */ sl@0: TUint iClockOut; sl@0: sl@0: sl@0: /** sl@0: The response timeout value, in uS. sl@0: */ sl@0: TUint iResponseTimeOut; sl@0: sl@0: sl@0: /** sl@0: The data timeout value, in uS. sl@0: */ sl@0: TUint iDataTimeOut; sl@0: sl@0: sl@0: /** sl@0: The busy timeout value, in uS. sl@0: */ sl@0: TUint iBusyTimeOut; sl@0: }; sl@0: sl@0: sl@0: class TMMCStackConfig sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Holds the stack configuration settings on behalf of a session. sl@0: sl@0: Each DMMCSession object contains the public member DMMCSession::iConfig - an instance of the TMMCStackConfig class. sl@0: By changing these settings, the client can override the master (i.e. default) stack configuration settings. sl@0: sl@0: However, these changes only remain in effect for the period that the session remains the current session. sl@0: In this way, the client is able to change the settings employed by the Controller (e.g. bus clock, enable retries, sl@0: change time-out values, restore defaults etc) while it performs that client's request. sl@0: sl@0: The client would generally set-up the stack configuration it requires prior to submitting the session. sl@0: */ sl@0: { sl@0: public: sl@0: inline TMMCStackConfig(); sl@0: inline void SetMode(TUint32 aMask); sl@0: inline void RemoveMode(TUint32 aMask); sl@0: inline void UseDefault(TUint32 aMask); sl@0: inline void SetPollAttempts(TUint aData); sl@0: inline void SetTimeOutRetries(TUint aData); sl@0: inline void SetCRCRetries(TUint aData); sl@0: inline void SetBusClockInKhz(TUint aParam); // In kilohertz sl@0: inline void SetTicksClockIn(TUint aParam); // Number of clock ticks in ClockIn phase sl@0: inline void SetTicksClockOut(TUint aParam); // Number of clock ticks in ClockOut phase sl@0: inline void SetResponseTimeOutInTicks(TUint aParam); // Timeout in bus clock ticks sl@0: inline void SetDataTimeOutInMcs(TUint aParam); // in microseconds sl@0: inline void SetBusyTimeOutInMcs(TUint aParam); // in microseconds sl@0: inline void SetOpCondBusyTimeout(TUint16 aData); // Units of 10mS sl@0: inline TInt OpCondBusyTimeout(); sl@0: TUint iPollAttempts; sl@0: private: sl@0: TUint32 iModes; sl@0: TUint32 iUpdateMask; sl@0: TUint32 iClientMask; sl@0: TUint iTimeOutRetries; sl@0: TUint iCRCRetries; sl@0: TUint16 iUnlockRetries; sl@0: TUint16 iOpCondBusyTimeout; // Units of 10mS sl@0: TMMCBusConfig iBusConfig; sl@0: friend class DMMCStack; sl@0: }; sl@0: sl@0: sl@0: class TMMCRCAPool sl@0: /** sl@0: MMC RCA Pool sl@0: */ sl@0: { sl@0: public: sl@0: inline TMMCRCAPool(); sl@0: TRCA GetFreeRCA(); sl@0: inline void LockRCA(TRCA); sl@0: inline void UnlockRCA(TRCA); sl@0: inline void ReleaseUnlocked(); sl@0: private: sl@0: TUint32 iPool; sl@0: TUint32 iLocked; sl@0: }; sl@0: sl@0: sl@0: class TMMCSessRing sl@0: /** sl@0: MMC session ring sl@0: */ sl@0: { sl@0: public: sl@0: TMMCSessRing(); sl@0: inline TBool IsEmpty() const; sl@0: void Erase(); sl@0: inline void SetMarker(); // Sets Marker into Point position sl@0: inline void AdvanceMarker(); // Moves Marker one position forward sl@0: inline void Point(); // Sets Point into Marker position sl@0: TBool Point(DMMCSession* aSessP); // Finds aSessP and sets Point to it sl@0: void Add(DMMCSession* aSessP); // Inserts aSessP before the Marker; Point moves to Marker sl@0: void Add(TMMCSessRing& aRing); sl@0: DMMCSession* Remove(); // Removes at Point; Point moves forward sl@0: void Remove(DMMCSession* aSessP); // Points aSessP first, then remove() sl@0: inline TUint Size() const; sl@0: inline operator DMMCSession*() const; sl@0: DMMCSession* operator++(TInt); // returns Point and moves it forward; stops at Marker sl@0: private: sl@0: DMMCSession* iPMark; sl@0: DMMCSession* iPoint; sl@0: DMMCSession* iPrevP; sl@0: TUint iSize; sl@0: }; sl@0: sl@0: sl@0: // sl@0: // DMMCStack State Machine Functions are supported by TMMCStateMachine class sl@0: // sl@0: // The structure of state machine functions is assumed to be as follows sl@0: // sl@0: // TMMCErr DMMCStack::FunctionNameSMST( TAny* aPtr ) sl@0: // { return( STATIC_CAST(DMMCStack*,aPtr)->FunctionNameSM() ); } sl@0: // sl@0: // TMMCErr DMMCStack::FunctionNameSM() sl@0: // { sl@0: // enum states {EStBegin=0, ..., EStEnd }; sl@0: // DMMCSession& s = Session(); sl@0: // TMMCStateMachine& m = Machine(); sl@0: // const TMMCErr err = m.SetExitCode( 0 ); sl@0: // sl@0: // for(;;) sl@0: // { sl@0: // switch(m.State()) sl@0: // { sl@0: // case EStBegin: sl@0: // { sl@0: // .... sl@0: // } sl@0: // case EStNext: sl@0: // { sl@0: // ..... sl@0: // } sl@0: // case EStEnd: break; sl@0: // default: Panic(...); sl@0: // } sl@0: // break; sl@0: // } sl@0: // return(m.Pop()); sl@0: // } sl@0: // sl@0: // State Machine remembers the next state number and function name and goes there as soon sl@0: // as the control is returned to the session. To release the control and wait for the next sl@0: // re-entrance (which will happen immediately if the session is not blocked or, as soon as sl@0: // an asynchronous event removes the blocking condition), a state machine function has to sl@0: // return( 0 ); Returning non-zero exit code will result in the session being completed with sl@0: // that error code unless a caller state machine function has explicitly intercepted such sl@0: // an error with m.SetTraps( TMMCErr aMask ). sl@0: // sl@0: // To make a state machine function code more readable, the following macros are provided: sl@0: // sl@0: // SMF_NEXTS(nexts) - set the next state to "nexts" sl@0: // SMF_CALL(func) - invoke SM function "func", then go to the next state sl@0: // SMF_CALLWAIT(func) - the same as above, but sleep at the entry point sl@0: // SMF_CALLMYS(nexts,retst) - invoke current SM function at "nexts" entry point sl@0: // SMF_CALLMEWR(retst) - invoke me right here with return state retst sl@0: // SMF_INVOKES(func,nexts) - invoke SM function "func", then go to the state "nexts" sl@0: // SMF_INVOKEWAITS(func,nexts) - the same as above, but sleep at the entry point sl@0: // SMF_WAIT - sleep at the next state sl@0: // SMF_WAITS(nexts) - set next state to "nexts", then sleep sl@0: // SMF_RETURN(value) - return an error to the caller SM function sl@0: // SMF_EXIT - return to the caller SM function sl@0: // SMF_EXITWAIT - the same as above, but sleep at the exit point sl@0: // SMF_JUMP(func) - transfer the control to SM function "func" sl@0: // SMF_JUMPWAIT(func) - the same as above, but sleep at the entry point sl@0: // SMF_GOTONEXTS - goto the next state sl@0: // SMF_GOTOS(nexts) - set the next state to "nexts", then go to it sl@0: // SMF_STATE(sname) - declare the state name "sname" sl@0: // SMF_BPOINT(sname) - declare the state "sname" and sleep here if blocked statically sl@0: // sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Declares the start of a state machine case switch statement. sl@0: sl@0: The macro assumes that the first state defined by the state machine sl@0: function is EStBegin. sl@0: sl@0: NOTES: sl@0: sl@0: - the code generates an opening curly brace that must be matched by sl@0: a closing curly brace. Typically, this is provided by the SMF_STATE or sl@0: the SMF_END macros. sl@0: sl@0: @see SMF_STATE sl@0: @see SMF_END sl@0: */ sl@0: #define SMF_BEGIN TMMCStateMachine& m=Machine();const TMMCErr err=m.SetExitCode(0);\ sl@0: for(;;){switch(m.State()){case EStBegin:{if(err) (void)0; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Declares the end of a state machine case switch statement. sl@0: sl@0: The macro assumes that the last state defined by the state machine sl@0: function is EStEnd. sl@0: sl@0: NOTES: sl@0: sl@0: - the code generated assumes that there are earlier calls to SMF_BEGIN, sl@0: and zero or more calls to SMF_STATE. sl@0: sl@0: @see SMF_BEGIN sl@0: @see SMF_STATE sl@0: */ sl@0: #define SMF_END }case EStEnd:break;default:DMMCSocket::Panic(DMMCSocket::EMMCMachineState);}break;}\ sl@0: return(m.Pop()); sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Sets the next state when the current state machine sl@0: function is re-entered. sl@0: sl@0: @param nexts The next state to be entered in the current state machine. sl@0: */ sl@0: #define SMF_NEXTS(nexts) m.SetState(nexts); sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Pushes a state machine entry onto the stack, specifying the child state machine sl@0: function to be invoked. sl@0: sl@0: The child function will be entered at state 0 (EStBegin), when the state machine sl@0: is next dispatched. sl@0: sl@0: Control returns from this state machine function after completion of sl@0: all functions coded by this macro. sl@0: sl@0: @param func The child state machine function to be invoked. sl@0: */ sl@0: #define SMF_CALL(func) return(m.Push(func)); sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Pushes a state machine entry onto the stack, specifying the child state machine sl@0: function to be invoked. sl@0: sl@0: The state machine is blocked before entry to the child function, but when sl@0: it becomes unblocked, the child function will be entered at state 0 (EStBegin) sl@0: when the state machine is next dispatched. sl@0: sl@0: Control returns from this state machine function after completion of sl@0: all functions coded by this macro. sl@0: sl@0: @param func The child state machine function to be invoked. sl@0: */ sl@0: #define SMF_CALLWAIT(func) return(m.Push(func,ETrue)); sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Sets the next state for the current state machine function - control will sl@0: flow to this state on completion of all functions coded by this macro. sl@0: sl@0: The macro also pushes a state machine entry onto the stack, specifying sl@0: the CURRENT state machine function as the child state machine function to be sl@0: invoked, and sets the state in which this child state machine function will sl@0: be entered, when it gains control. sl@0: sl@0: NOTES: sl@0: sl@0: - the child function is the same as the parent function. sl@0: - the state machine is blocked on return from the current state machine function. sl@0: sl@0: @param nexts The state in which the child state machine function will sl@0: gain control. sl@0: @param retst The next state for the current state machine function. sl@0: */ sl@0: #define SMF_CALLMYS(nexts,retst) {m.SetState(retst);m.PushMe();m.SetState(nexts);continue;} sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Sets the next state for the current state machine function - control flows to sl@0: the next instruction on completion of all functions coded by this macro. sl@0: sl@0: The macro also pushes a state machine entry onto the stack, specifying sl@0: the CURRENT state machine function as the child state machine function to be sl@0: invoked. The child function will be entered at state 0 (EStBegin), when the state machine sl@0: is next dispatched. sl@0: sl@0: NOTES: sl@0: sl@0: - the child function is the same as the parent function. sl@0: - the state machine is blocked on return from the current state machine function. sl@0: sl@0: @param retst The next state for the current state machine function. sl@0: */ sl@0: #define SMF_CALLMEWR(retst) {m.SetState(retst);m.PushMe();} sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Sets the next state for the current state machine function. sl@0: sl@0: The macro also pushes a state machine entry onto the stack, specifying sl@0: the child state machine function to be sl@0: invoked. The child function will be entered at state 0 (EStBegin), when the state machine sl@0: is next dispatched. sl@0: sl@0: Control returns from the current state machine function after completion of sl@0: all functions coded by this macro. sl@0: sl@0: @param func The child state machine function to be invoked. sl@0: @param nexts The next state for the current state machine function. sl@0: */ sl@0: #define SMF_INVOKES(func,nexts) {m.SetState(nexts);return(m.Push(func));} sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Sets the next state for the current state machine function. sl@0: sl@0: The macro also pushes a state machine entry onto the stack, specifying sl@0: the child state machine function to be sl@0: invoked. The child function will be entered at state 0 (EStBegin), when the state machine sl@0: is next dispatched. sl@0: sl@0: Control returns from the current state machine function after completion of sl@0: all functions coded by this macro. sl@0: sl@0: NOTES: sl@0: sl@0: - the state machine is blocked on return from the current state machine function. sl@0: sl@0: @param func The child state machine function to be invoked. sl@0: @param nexts The next state for the current state machine function. sl@0: */ sl@0: #define SMF_INVOKEWAITS(func,nexts) {m.SetState(nexts);return(m.Push(func,ETrue));} sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Returns from the current state machine function, and the state machine then blocks (waits). sl@0: */ sl@0: #define SMF_WAIT return(0); sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Sets the next state for the current state machine function; control then returns sl@0: from the current state machine function, and the state machine blocks (waits). sl@0: sl@0: @param nexts The next state for the current state machine function. sl@0: */ sl@0: #define SMF_WAITS(nexts) return(m.SetState(nexts)); sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Returns the specified error value to the calling (parent) state machine function. sl@0: sl@0: @param value The error value to be returned. sl@0: */ sl@0: #define SMF_RETURN(value) {m.Pop();return(value);} sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Returns to the calling state machine function. sl@0: */ sl@0: #define SMF_EXIT break; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Returns to the calling state machine function, and the state machine blocks (waits). sl@0: */ sl@0: #define SMF_EXITWAIT return(m.Pop(ETrue)); sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Transfers control to the specified state machine function. sl@0: sl@0: NOTES: sl@0: sl@0: - this function is executed at the same stack entry level as the current state machine function. sl@0: sl@0: @param func The state machine function to which control is to be transferred. sl@0: */ sl@0: #define SMF_JUMP(func) return(m.Jump(func)); sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Transfers control to the specified state machine function, and waits sl@0: at its entry point. sl@0: sl@0: @param func The state machine function to which control is to be transferred. sl@0: */ sl@0: #define SMF_JUMPWAIT(func) return(m.Jump(func,ETrue)); sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Goes to the next state. sl@0: */ sl@0: #define SMF_GOTONEXTS continue; sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Sets the next state and then goes to that state. sl@0: sl@0: @param nexts The next state. sl@0: */ sl@0: #define SMF_GOTOS(nexts) {m.SetState(nexts);continue;} sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Declares the name of a state. sl@0: sl@0: This is used to generate a case statement based on the state name. sl@0: sl@0: @param sname The state name. sl@0: */ sl@0: #define SMF_STATE(sname) }case sname:{ sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Declares the name of a state, and sleeps here sl@0: if blocked statically. sl@0: sl@0: @param sname The state name. sl@0: */ sl@0: #define SMF_BPOINT(sname) }case sname: if(StaticBlocks()) return(m.SetState(sname));{ sl@0: sl@0: sl@0: sl@0: sl@0: class TMMCStateMachine sl@0: /** sl@0: The MultiMediaCard state machine. sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: inline void Setup(TMMCErr (*anEntry)(TAny*), TAny* aContextP); sl@0: IMPORT_C void Reset(); sl@0: IMPORT_C TMMCErr Dispatch(); sl@0: inline TMMCErr ExitCode(); sl@0: inline TMMCErr SetExitCode(TMMCErr aCode); sl@0: inline TUint State(); sl@0: inline TMMCErr SetState(TUint aState); sl@0: inline void SuppressSuspension(); sl@0: inline void SetTraps(TMMCErr aMask); sl@0: inline void ResetTraps(); sl@0: inline void Abort(); sl@0: inline TMMCErr Pop(TBool aSuspend=EFalse); sl@0: inline TMMCErr PushMe(); sl@0: IMPORT_C TMMCErr Push(TMMCErr (*anEntry)(TAny*), TBool aSuspend=EFalse); sl@0: IMPORT_C TMMCErr Jump(TMMCErr (*anEntry)(TAny*), TBool aSuspend=EFalse); sl@0: private: sl@0: class TMMCMachineStackEntry sl@0: { sl@0: public: sl@0: TMMCErr (*iFunction)(TAny*); sl@0: TUint iState; sl@0: TMMCErr iTrapMask; sl@0: }; sl@0: TBool iAbort; sl@0: TBool iSuspend; sl@0: TAny* iContextP; sl@0: TMMCErr iExitCode; sl@0: TInt iSP; sl@0: TMMCMachineStackEntry iStack[KMaxMMCMachineStackDepth]; sl@0: }; sl@0: sl@0: class TMMCCallBack sl@0: /** sl@0: This class is used to notify the request completion as a callback function for the clients of DMMCSession. sl@0: The callback function will be called on session completion. sl@0: Callback function is used to indicate Asynchronous Completion. sl@0: sl@0: @see DMMCSession sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: inline TMMCCallBack(); sl@0: inline TMMCCallBack(void (*aFunction)(TAny* aPtr)); sl@0: inline TMMCCallBack(void (*aFunction)(TAny* aPtr), TAny* aPtr); sl@0: inline void CallBack() const; sl@0: public: sl@0: /** sl@0: A pointer to the callback function. sl@0: */ sl@0: void (*iFunction)(TAny* aPtr); sl@0: sl@0: /** sl@0: A pointer that is passed to the callback function when sl@0: the callback function is called. sl@0: */ sl@0: TAny* iPtr; sl@0: }; sl@0: sl@0: // DMMCStack serves an incoming queue of session requests. sl@0: // Each queue element is represented by an instance of the following class sl@0: sl@0: typedef TMMCErr (*TMMCSMSTFunc)(TAny*); sl@0: sl@0: class DMMCSession : public DBase sl@0: /** sl@0: Provides the main interface between the client and the MMC Socket, allowing commands and responses sl@0: to be processed asynchronously on the stack. sl@0: sl@0: Each client creates it own instance of this class. It is then able to make MultiMediaCard requests sl@0: on the selected stack by configuring the DMMCSession object with relevant information for the request sl@0: and then submitting (or engaging) this session object. sl@0: sl@0: The session is used to pass commands either to the entire stack (a broadcast command), or to individual sl@0: cards in the stack. The class contains functions for initiating macro functions as laid down by the sl@0: MultiMediaCard Association (MMCA) as well as lower level functions allowing a client to control the sl@0: stack in a more explicit manner. sl@0: sl@0: All requests on the MultiMediaCard stack which involve bus activity are inherently asynchronous. When sl@0: creating a DMMCSession object, a client supplies a call-back function as part of the constructor. sl@0: Once a client has engaged a session on the stack, it is informed of the completion of the request by sl@0: the Controller calling this call-back function. sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: IMPORT_C virtual ~DMMCSession(); sl@0: IMPORT_C DMMCSession(const TMMCCallBack& aCallBack); sl@0: sl@0: // Object initialisation sl@0: inline void SetStack(DMMCStack* aStackP); sl@0: IMPORT_C void SetCard(TMMCard* aCardP); sl@0: sl@0: // Control macros setup sl@0: inline void SetupCIMUpdateAcq(); sl@0: inline void SetupCIMInitStack(); sl@0: inline void SetupCIMCheckStack(); sl@0: inline void SetupCIMSetupCard(); sl@0: inline void SetupCIMLockStack(); sl@0: inline void SetupCIMInitStackAfterUnlock(); sl@0: inline void SetupCIMAutoUnlock(); sl@0: sl@0: // Data transfer macros setup sl@0: IMPORT_C void SetupCIMReadBlock(TMMCArgument aDevAddr, TUint32 aLength, TUint8* aMemoryP); sl@0: IMPORT_C void SetupCIMWriteBlock(TMMCArgument aDevAddr, TUint32 aLength, TUint8* aMemoryP); sl@0: IMPORT_C void SetupCIMReadMBlock(TMMCArgument aDevAddr, TUint32 aLength, TUint8* aMemoryP, TUint32 aBlkLen); sl@0: IMPORT_C void SetupCIMWriteMBlock(TMMCArgument aDevAddr, TUint32 aLength, TUint8* aMemoryP, TUint32 aBlkLen); sl@0: IMPORT_C void SetupCIMEraseSector(TMMCArgument aDevAddr, TUint32 aLength); sl@0: IMPORT_C void SetupCIMEraseGroup(TMMCArgument aDevAddr, TUint32 aLength); sl@0: IMPORT_C void SetupCIMReadIO(TUint8 aRegAddr, TUint32 aLength, TUint8* aMemoryP); sl@0: IMPORT_C void SetupCIMWriteIO(TUint8 aRegAddr, TUint32 aLength, TUint8* aMemoryP); sl@0: IMPORT_C void SetupCIMLockUnlock(TUint32 aLength, TUint8* aMemoryP); sl@0: sl@0: // Data transfer macros setup (block mode) sl@0: inline void SetupCIMReadBlock(TMMCArgument aBlockAddr, TUint8* aMemoryP, TUint32 aBlocks = 1); sl@0: inline void SetupCIMWriteBlock(TMMCArgument aBlockAddr, TUint8* aMemoryP, TUint32 aBlocks = 1); sl@0: inline void SetupCIMEraseMSector(TMMCArgument aBlockAddr, TUint32 aBlocks = 1); sl@0: inline void SetupCIMEraseMGroup(TMMCArgument aBlockAddr, TUint32 aBlocks = 1); sl@0: sl@0: // Raw commands (must be used in the locked bus state only) sl@0: // Known commands with or without (with a default) argument sl@0: IMPORT_C void SetupCommand(TMMCCommandEnum aCommand, TMMCArgument anArgument=0); sl@0: sl@0: // Generic unknown command with unknown response type sl@0: IMPORT_C void SetupRSCommand(TMMCCommandEnum aCommand, TMMCArgument anArgument, sl@0: TUint32 aResponseLength, TMMCCommandTypeEnum aCommandType=ECmdTypeUK, sl@0: TMMCResponseTypeEnum aResponseType=ERespTypeUnknown, sl@0: TUint32 aCommandClass=KMMCCmdClassNone); sl@0: sl@0: // Generic data transfer command sl@0: IMPORT_C void SetupDTCommand(TMMCCommandEnum aCommand, TMMCArgument anArgument, sl@0: TUint32 aTotalLength, TUint8* aMemoryAddress, TUint32 aBlockLength=0, sl@0: TBool aStopTransmission=EFalse, TMMCCmdDirEnum aDir=EDirNone, sl@0: TUint32 aCommandClass=KMMCCmdClassNone); sl@0: // Actions sl@0: IMPORT_C TInt Engage(); // Enque session for execution sl@0: inline void UnlockStack(); // Unlock the bus sl@0: inline void Stop(); // Signal session to complete (stop and complete) sl@0: inline void Abort(); // Abort only (no completion) sl@0: sl@0: // Info retrieval sl@0: IMPORT_C TInt EpocErrorCode() const; // Derived from MMCExitCode and LastStatus sl@0: inline TMMCSessionTypeEnum SessionID() const; sl@0: inline DMMCStack* StackP() const; // DMMCStack serving this session sl@0: inline TMMCard* CardP() const; // The current card pointer sl@0: inline TBool IsEngaged() const; // Session is being served by DMMCStack sl@0: inline TMMCErr MMCExitCode() const; // MMC specific error code returned by DMMCStack sl@0: inline TMMCStatus LastStatus() const; // Last R1 response received from the card sl@0: inline TUint32 BytesTransferred() const;// The actual amount of data transferred in this session sl@0: inline TUint8* ResponseP(); // Current command response (&iCommand[iCmdSP].iResponse) sl@0: inline TUint32 EffectiveModes() const; // Modes which DMMCStack will consider as effective sl@0: // sl@0: inline void ResetCommandStack(); sl@0: private: sl@0: void SetupCIMControl(TInt aSessNum); sl@0: protected: sl@0: IMPORT_C virtual TMMCSMSTFunc GetMacro(TInt aSessNum) const; sl@0: inline void Block(TUint32 aFlag); sl@0: inline void UnBlock(TUint32 aFlag, TMMCErr anExitCode); sl@0: private: sl@0: #ifdef __EPOC32__ sl@0: static void PollTimerCallBack(TAny* aSessP); sl@0: static void RetryTimerCallBack(TAny* aSessP); sl@0: static void ProgramTimerCallBack(TAny* aSessP); sl@0: #endif sl@0: inline void SwapMe(); sl@0: void SynchBlock(TUint32 aFlag); sl@0: void SynchUnBlock(TUint32 aFlag); sl@0: public: sl@0: static const TMMCCommandSpec& FindCommandSpec(const TMMCIdxCommandSpec aSpecs[], TInt aIdx); sl@0: IMPORT_C void FillCommandDesc(); sl@0: IMPORT_C void FillCommandDesc(TMMCCommandEnum aCommand); sl@0: IMPORT_C void FillCommandDesc(TMMCCommandEnum aCommand, TMMCArgument anArgument); sl@0: IMPORT_C void FillCommandArgs(TMMCArgument anArgument, TUint32 aLength, TUint8* aMemoryP, TUint32 aBlkLen); sl@0: inline TMMCCommandDesc& Command(); // The current command descriptor sl@0: sl@0: inline void PushCommandStack(); sl@0: inline void PopCommandStack(); sl@0: sl@0: // Methods for double-buffered data transfer: sl@0: inline TBool RequestMoreData(); sl@0: inline void EnableDoubleBuffering(TUint32 aNumBlocks); /**< @internalTechnology */ sl@0: inline void SetDataTransferCallback(TMMCCallBack& aCallback); /**< @internalTechnology */ sl@0: inline void MoreDataAvailable(TUint32 aNumBlocks, TUint8* aMemoryP, TInt aError); /**< @internalTechnology */ sl@0: public: sl@0: /** sl@0: The last R1 response. sl@0: */ sl@0: TMMCStatus iLastStatus; sl@0: sl@0: /** sl@0: A pointer to the card object. sl@0: */ sl@0: TMMCard* iCardP; // Pointer to Card Info object sl@0: IMPORT_C TRCA CardRCA(); // Checks that card is still ready - otherwise returns 0 sl@0: TMMCSessionTypeEnum iSessionID; sl@0: private: sl@0: DMMCSession* iLinkP; // sl@0: protected: sl@0: TMMCCallBack iCallBack; // Where to report the completion sl@0: private: sl@0: DMMCStack* iStackP; // Pointer to Stack Controller sl@0: TCID iCID; // Card ID to ensure we are still talking to the same card sl@0: TUint32 iBytesTransferred; // The actual amount of data transferred in this session sl@0: TMMCErr iMMCExitCode; // State Machine exit code (MMC specific) sl@0: public: sl@0: /** sl@0: Session state flags (synchronous). sl@0: */ sl@0: TUint32 iState; sl@0: private: sl@0: TUint iInitContext; // Stack Initialiser pass number sl@0: TUint iGlobalRetries; // Global retry counter sl@0: sl@0: // Asynchronous flags analysed by scheduler sl@0: TBool volatile iDoAbort; // Marks the session for abort sl@0: TBool volatile iDoStop; // Stop the session as soon as it's safe sl@0: TBool volatile iDoComplete; // Completion callback is now to be invoked sl@0: TBool iBrokenLock; // Stack lock is broken by force major sl@0: // sl@0: TUint32 iBlockOn; // blocking reasons sl@0: TInt iCmdSP; // Current Command stack index sl@0: sl@0: TMMCCommandDesc iCommand[KMaxMMCCommandStackDepth]; // Command stack sl@0: sl@0: TMMCCallBack iDataTransferCallback; // A callback function, used to request more data when performing double-buffering sl@0: sl@0: TUint32 iSpare[22]; // Spare data (stolen from iCommand) sl@0: sl@0: TMMCStateMachine iMachine; // State Machine context sl@0: #ifdef __EPOC32__ sl@0: NTimer iPollTimer; sl@0: NTimer iRetryTimer; sl@0: NTimer iProgramTimer; sl@0: #endif sl@0: public: sl@0: TMMCStackConfig iConfig; // Client configuration parameters sl@0: friend class DMMCStack; sl@0: friend class TMMCSessRing; sl@0: friend class TMMCardArray; sl@0: }; sl@0: sl@0: sl@0: class DMMCStack : public DBase sl@0: /** sl@0: This object controls access to the MultiMediaCard stack. sl@0: The DMMCSocket owns an instance of this class for the MultiMediaCard stack that it manages. sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: /** extension interfaces Ids */ sl@0: enum TInterfaceId sl@0: { sl@0: KInterfaceMachineInfo, sl@0: KInterfaceSwitchToLowVoltageSM, sl@0: KInterfaceSetBusWidth, sl@0: KInterfaceDemandPagingInfo, sl@0: KInterfaceCancelSession, sl@0: KInterfaceDoWakeUpSM sl@0: }; sl@0: sl@0: /** generic interface */ sl@0: class MInterface sl@0: { sl@0: public: sl@0: virtual TInt Function() = 0; sl@0: }; sl@0: sl@0: /** sl@0: Demand paging support sl@0: @see KInterfaceDemandPagingInfo sl@0: */ sl@0: class TDemandPagingInfo sl@0: { sl@0: public: sl@0: const TInt* iPagingDriveList; sl@0: TInt iDriveCount; sl@0: TUint iPagingType; sl@0: TInt iReadShift; sl@0: TUint iNumPages; sl@0: TBool iWriteProtected; sl@0: TInt iSlotNumber; sl@0: TUint iSpare[2]; sl@0: } ; sl@0: /** sl@0: * An optional interface implemented by the PSL for returning demand-paging information. sl@0: * @see KInterfaceDemandPagingInfo sl@0: */ sl@0: class MDemandPagingInfo sl@0: { sl@0: public: sl@0: virtual TInt DemandPagingInfo(TDemandPagingInfo& aInfo) = 0; sl@0: }; sl@0: sl@0: /** sl@0: * An optional interface State machine implemented by the PSL for handling asynchronous VccCore powerup sl@0: * @see KInterfaceDoWakeUpSM sl@0: */ sl@0: class MDoWakeUp sl@0: { sl@0: public: sl@0: virtual TMMCErr DoWakeUpSM()=0; sl@0: }; sl@0: sl@0: sl@0: public: sl@0: IMPORT_C DMMCStack(TInt aBus, DMMCSocket* aSocket); sl@0: IMPORT_C virtual TInt Init(); sl@0: // sl@0: // Actions sl@0: inline void ReportPowerUp(); sl@0: inline void ReportPowerDown(); sl@0: inline void Reset(); // Discard all requests and clear up sl@0: inline void CompleteAll(TMMCErr aCode); // Complete all operations with an error sl@0: inline void CancelSession(DMMCSession* aSession); sl@0: sl@0: IMPORT_C void PowerUpStack(); sl@0: IMPORT_C void PowerDownStack(); sl@0: void QSleepStack(); sl@0: IMPORT_C TInt Stop(TMMCard* aCardP); sl@0: // sl@0: // Inquiries sl@0: inline TUint MaxCardsInStack() const; sl@0: inline TMMCard* CardP(TUint aCardNumber); sl@0: inline DMMCSocket* MMCSocket() const; sl@0: inline TMMCPasswordStore* PasswordStore() const; sl@0: inline TBool InitStackInProgress() const; sl@0: inline TBool HasSessionsQueued() const; sl@0: inline TBool HasCardsPresent(); sl@0: inline void BufferInfo(TUint8*& aBuf, TInt& aBufLen, TInt& aMinorBufLen); sl@0: inline TInt DemandPagingInfo(TDemandPagingInfo& aInfo); sl@0: inline TBool StackRunning() const; sl@0: sl@0: sl@0: #ifdef __EPOC32__ sl@0: sl@0: /** sl@0: Defines the period for the poll timer. sl@0: sl@0: The poll timer is used by the generic layer for platforms sl@0: that do not provide an interrupt to indicate sl@0: when programming mode is finished. sl@0: sl@0: @return The poll timer period, in milliseconds. sl@0: */ sl@0: virtual TInt ProgramPeriodInMilliSeconds() const =0; sl@0: #endif sl@0: sl@0: /** sl@0: * Calculates the minimum range that must be read off a card, an optimisation that takes advantage sl@0: * of the partial read feature found on some cards. It takes the logical range that the media driver sl@0: * wants to read from the card, and increases it to take into account factors such as FIFO width and sl@0: * minimum DMA transfer size. sl@0: * @param aCard A pointer to the MMC Card sl@0: * @param aStart The required start position sl@0: * @param aEnd The required end position sl@0: * @param aPhysStart The adjusted start position sl@0: * @param aPhysEnd The adjusted end position sl@0: */ sl@0: virtual void AdjustPartialRead(const TMMCard* aCard, TUint32 aStart, TUint32 aEnd, TUint32* aPhysStart, TUint32* aPhysEnd) const =0; sl@0: sl@0: /** sl@0: * Returns the details of the buffer allocated by the socket for data transfer operations. The buffer sl@0: * is allocated and configured at the variant layer to allow , for example, contiguous pages to be sl@0: * allocated for DMA transfers. sl@0: * @param aMDBuf A pointer to the allocated buffer sl@0: * @param aMDBufLen The length of the allocated buffer sl@0: */ sl@0: virtual void GetBufferInfo(TUint8** aMDBuf, TInt* aMDBufLen) =0; sl@0: sl@0: /** sl@0: * Gets the platform specific configuration information. sl@0: * @see TMMCMachineInfo sl@0: */ sl@0: virtual void MachineInfo(TMMCMachineInfo& aMachineInfo) =0; sl@0: sl@0: /** sl@0: * Creates the session object sl@0: */ sl@0: IMPORT_C virtual DMMCSession* AllocSession(const TMMCCallBack& aCallBack) const; sl@0: sl@0: protected: sl@0: // Platform layer service sl@0: inline TMMCBusConfig& BusConfig(); sl@0: inline TMMCBusConfig& MasterBusConfig(); sl@0: inline DMMCSession& Session(); // Current session sl@0: inline TMMCCommandDesc& Command(); // Current command descriptor of current session sl@0: inline TMMCStateMachine& Machine(); // State machine of current session sl@0: inline void BlockCurrentSession(TUint32 aFlag); sl@0: inline void UnBlockCurrentSession(TUint32 aFlag, TMMCErr anExitCode); sl@0: inline void ReportInconsistentBusState(); sl@0: inline void ReportASSPEngaged(); sl@0: inline void ReportASSPDisengaged(); sl@0: inline TRCA CurrentSessCardRCA(); // Checks that card is still ready - otherwise returns 0 sl@0: inline void CurrentSessPushCmdStack(); sl@0: inline void CurrentSessPopCmdStack(); sl@0: inline void CurrentSessFillCmdDesc(TMMCCommandEnum aCommand); sl@0: inline void CurrentSessFillCmdDesc(TMMCCommandEnum aCommand,TMMCArgument anArgument); sl@0: inline void CurrentSessFillCmdArgs(TMMCArgument anArgument,TUint32 aLength,TUint8* aMemoryP,TUint32 aBlkLen); sl@0: inline TRCA SelectedCard() const; sl@0: inline void YieldStack(TMMCCommandTypeEnum aCommand); sl@0: sl@0: void DoSetClock(TUint32 aClock); sl@0: void DoSetBusWidth(TUint32 aBusWidth); sl@0: TBusWidth BusWidthEncoding(TInt aBusWidth) const; sl@0: TUint MaxTranSpeedInKilohertz(const TMMCard& aCard) const; sl@0: sl@0: // Stack service provided by platform/variant layer. sl@0: sl@0: /** sl@0: * Returns the default master settings for the platform. sl@0: * @param aConfig A TMMCBusConfig reference to be filled in with the default settings. sl@0: * @param aClock The requested clock frequency (may be ignored if the hardware cannot support it). sl@0: */ sl@0: virtual void SetBusConfigDefaults(TMMCBusConfig& aConfig, TUint aClock)=0; sl@0: sl@0: /** sl@0: * Switches from identification mode of operation to data transfer mode operation. sl@0: * sl@0: * Note that at this point the clock information in iBusConfig will not have been updated sl@0: * to the new data transfer rate. This function should generally just switch from open drain sl@0: * to push-pull bus mode - with the clock rate being changed at the start of IssueMMCCommandSM, sl@0: * where iBusConfig will be valid. sl@0: */ sl@0: virtual void InitClockOff()=0; sl@0: sl@0: /** sl@0: * Stop all activities on the host stack. sl@0: * sl@0: * This will generally perform the same operations as for ASSPDisengage() but this will additionally sl@0: * turn off the clock to the hardware interface and release any requested power requirements made on sl@0: * the power model. (That is release any power requirements made as part of the InitClockOnSM() function). sl@0: * sl@0: * Called from the platform independent layer when it is required to immediately cancel any PSL asynchronous sl@0: * activity because the current session has been aborted. sl@0: * sl@0: * This function should normally include a call to ReportAsspDisengaged() at the end, to report to the PIL sl@0: * that the PSL level resources have been disengaged. sl@0: */ sl@0: virtual void ASSPReset()=0; sl@0: sl@0: /** sl@0: * Called each time a session which has engaged PSL resources has completed or has been aborted. sl@0: * sl@0: * This should disable any activities which were required to perform the session just completed/aborted. sl@0: * It shouldn't however turn off the clock to the hardware interface (which will be turned off instead sl@0: * by the inactivity timer). This typically disables DMA and interface interrupts and forces the hardware sl@0: * interface into idle. sl@0: * sl@0: * This function should normally include a call to ReportAsspDisengaged() at the end, to report to the PIL sl@0: * that the PSL level resources have been disengaged. sl@0: */ sl@0: virtual void ASSPDisengage()=0; sl@0: sl@0: /** sl@0: * Called as part of the bus power down sequence. It stops all activities on the host stack, turns off the clock sl@0: * to the hardware interface and releases any requested power requirements made on the power model sl@0: * (i.e. very often a straight call of ASSPReset()). sl@0: * sl@0: * This shouldn't turn off the MMC PSU as this will be performed immediately afterwards by the PSU class. sl@0: */ sl@0: virtual void DoPowerDown()=0; sl@0: sl@0: IMPORT_C virtual TBool CardDetect(TUint aCardNumber); sl@0: IMPORT_C virtual TBool WriteProtected(TUint aCardNumber); sl@0: // sl@0: // State Machine functions implemented in platform layer. sl@0: sl@0: /** sl@0: * Called as a child function at the start of the CIM_UPDATE_ACQ macro state machine. sl@0: * sl@0: * It should perform the necessary PSL level actions associated with powering up the bus. This includes sl@0: * turning on the MMC PSU. However, the hardware interface clock should not be turned on as part of this function. sl@0: * sl@0: * If the Controller has to request power resources from the power model (e.g a fast system clock required all the sl@0: * time the bus is powered) then this state machine function can be used to asynchronously wait for this resource sl@0: * to become available. sl@0: * sl@0: * Upon completion, DMMCStack::ReportPowerUp() should be called. sl@0: * sl@0: * @return KMMCErrNone if completed successfully or standard TMMCErr code otherwise sl@0: */ sl@0: virtual TMMCErr DoPowerUpSM()=0; sl@0: sl@0: /** sl@0: * Turns on the clock to the hardware interface. sl@0: * sl@0: * This state machine function is called as a child function as part of the CIM_UPDATE_ACQ macro state machine. sl@0: * sl@0: * It is implemented as a state machine function since it may be necessary to include a short delay after the sl@0: * clock has been turned on to allow it to stabilise, or in some cases it may be necessary to wait for a power sl@0: * resource to become available. sl@0: * sl@0: * This function should normally include a call to ReportAsspEngaged() at the start, to report to the PIL that the PSL sl@0: * level resources have been engaged. sl@0: * sl@0: * @return KMMCErrNone if completed successfully or standard TMMCErr code otherwise sl@0: */ sl@0: virtual TMMCErr InitClockOnSM()=0; sl@0: sl@0: /** sl@0: * Executes a single command over the bus. sl@0: * sl@0: * The input parameters are passed via the current command descriptor on the session's command stack sl@0: * (TMMCCommandDesc class), which specifies the type of command, response type, arguments etc.. sl@0: * sl@0: * @return KMMCErrNone if completed successfully or standard TMMCErr code otherwise sl@0: */ sl@0: IMPORT_C virtual TMMCErr IssueMMCCommandSM()=0; sl@0: sl@0: TBool StaticBlocks(); sl@0: sl@0: /** sl@0: * Indicates that the PSL should change the bus width. sl@0: * Must be implemented by the Platform Specific Layer if MMCV4 4/8-bit bus mode is required sl@0: */ sl@0: IMPORT_C virtual void SetBusWidth(TUint32 aBusWidth); sl@0: sl@0: /** sl@0: * Retrieves a TMMCMachineInfoV4 from the PSL sl@0: * Must be implemented by the Platform Specific Layer if MMCV4 support is required sl@0: */ sl@0: public: sl@0: IMPORT_C virtual void MachineInfo(TDes8& aMachineInfo); sl@0: sl@0: protected: sl@0: /** sl@0: * Switches the MMC bus to low voltage mode sl@0: */ sl@0: TMMCErr SwitchToLowVoltageSM(); sl@0: sl@0: sl@0: private: sl@0: // sl@0: // Session service sl@0: void Add(DMMCSession* aSessP); sl@0: void Abort(DMMCSession* aSessP); sl@0: void Stop(DMMCSession* aSessP); sl@0: void UnlockStack(DMMCSession* aSessP); sl@0: void MarkComplete(DMMCSession* aSessP, TMMCErr anExitCode); sl@0: // sl@0: // Stack control and operations support sl@0: // Scheduler and its supplementary functions sl@0: enum TMMCStackSchedStateEnum sl@0: { sl@0: ESchedContinue=0, sl@0: ESchedLoop=1, sl@0: ESchedExit, sl@0: ESchedChooseJob sl@0: }; sl@0: void Scheduler(volatile TBool& aFlag); sl@0: void DoSchedule(); sl@0: TMMCStackSchedStateEnum SchedGetOnDFC(); sl@0: void SchedSetContext(DMMCSession* aSessP); sl@0: void SchedDoAbort(DMMCSession* aSessP); sl@0: TMMCStackSchedStateEnum SchedResolveStatBlocks(DMMCSession* aSessP); sl@0: TMMCStackSchedStateEnum SchedGroundDown(DMMCSession* aSessP, TMMCErr aReason); sl@0: TMMCStackSchedStateEnum SchedEnqueStackSession(TMMCSessionTypeEnum aSessID); sl@0: void SchedGrabEntries(); sl@0: void SchedDisengage(); sl@0: TBool SchedAllowDirectCommands(DMMCSession* aSessP); sl@0: TBool SchedYielding(DMMCSession* aSessP); sl@0: inline TMMCStackSchedStateEnum SchedAbortPass(); sl@0: inline TMMCStackSchedStateEnum SchedCompletionPass(); sl@0: inline TMMCStackSchedStateEnum SchedInitStack(); sl@0: inline TMMCStackSchedStateEnum SchedSleepStack(); sl@0: inline TBool SchedPreemptable(); sl@0: inline TMMCStackSchedStateEnum SchedSession(); sl@0: inline TMMCStackSchedStateEnum SchedChooseJob(); sl@0: // sl@0: // Miscellaneous SM function service sl@0: protected: sl@0: void MergeConfig(DMMCSession* aSessP); sl@0: private: sl@0: inline void DeselectsToIssue(TUint aNumber); sl@0: sl@0: // Static Completion routines. sl@0: static void StackDFC(TAny* aStackP); sl@0: static void StackSessionCBST(TAny* aStackP); sl@0: TInt StackSessionCB(); sl@0: static void AutoUnlockCBST(TAny *aStackP); sl@0: TInt AutoUnlockCB(); sl@0: sl@0: protected: sl@0: IMPORT_C void Block(DMMCSession* aSessP, TUint32 aFlag); sl@0: IMPORT_C void UnBlock(DMMCSession* aSessP, TUint32 aFlag, TMMCErr anExitCode); sl@0: sl@0: protected: sl@0: // State machines. The adapter functions just call the non-static versions. sl@0: // Top-level state machines. sl@0: static TMMCErr NakedSessionSMST(TAny* aStackP); // ECIMNakedSession sl@0: inline TMMCErr NakedSessionSM(); sl@0: static TMMCErr CIMUpdateAcqSMST(TAny* aStackP); // ECIMUpdateAcq sl@0: TMMCErr CIMUpdateAcqSM(); sl@0: static TMMCErr CIMInitStackSMST(TAny* aStackP); // ECIMInitStack sl@0: inline TMMCErr CIMInitStackSM(); sl@0: static TMMCErr CIMCheckStackSMST(TAny* aStackP); // ECIMCheckStack sl@0: inline TMMCErr CIMCheckStackSM(); sl@0: static TMMCErr CIMSetupCardSMST(TAny* aStackP); // ECIMSetupCard sl@0: inline TMMCErr CIMSetupCardSM(); sl@0: IMPORT_C static TMMCErr CIMReadWriteBlocksSMST(TAny* aStackP); // ECIMReadBlock, ECIMWriteBlock, ECIMReadMBlock, ECIMWriteMBlock sl@0: IMPORT_C virtual TMMCErr CIMReadWriteBlocksSM(); sl@0: static TMMCErr CIMEraseSMST(TAny* aStackP); // ECIMEraseSector, ECIMEraseGroup sl@0: inline TMMCErr CIMEraseSM(); sl@0: static TMMCErr CIMReadWriteIOSMST(TAny* aStackP); // ECIMReadIO, ECIMWriteIO sl@0: inline TMMCErr CIMReadWriteIOSM(); sl@0: static TMMCErr CIMLockUnlockSMST(TAny *aStackP); // ECIMLockUnlock sl@0: inline TMMCErr CIMLockUnlockSM(); sl@0: static TMMCErr NoSessionSMST(TAny* aStackP); // ECIMLockStack sl@0: inline TMMCErr NoSessionSM(); sl@0: static TMMCErr AcquireStackSMST(TAny* aStackP); sl@0: IMPORT_C virtual TMMCErr AcquireStackSM(); sl@0: static TMMCErr CheckStackSMST(TAny* aStackP); // ECIMCheckStack sl@0: inline TMMCErr CheckStackSM(); sl@0: static TMMCErr CheckLockStatusSMST(TAny* aStackP); sl@0: inline TMMCErr CheckLockStatusSM(); sl@0: static TMMCErr ModifyCardCapabilitySMST(TAny* aStackP); sl@0: IMPORT_C virtual TMMCErr ModifyCardCapabilitySM(); sl@0: static TMMCErr BaseModifyCardCapabilitySMST(TAny* aStackP); sl@0: static TMMCErr DoPowerUpSMST(TAny* aStackP); sl@0: static TMMCErr InitClockOnSMST(TAny* aStackP); sl@0: IMPORT_C static TMMCErr IssueMMCCommandSMST(TAny* aStackP); sl@0: sl@0: static TMMCErr CIMAutoUnlockSMST(TAny* aStackP); sl@0: inline TMMCErr CIMAutoUnlockSM(); sl@0: sl@0: static TMMCErr InitStackAfterUnlockSMST(TAny* aStackP); // ECIMInitStackAfterUnlock sl@0: IMPORT_C virtual TMMCErr InitStackAfterUnlockSM(); sl@0: sl@0: static TMMCErr InitCurrentCardAfterUnlockSMST(TAny* aStackP); sl@0: sl@0: static TMMCErr AttachCardSMST(TAny* aStackP); sl@0: inline TMMCErr AttachCardSM(); sl@0: static TMMCErr ExecCommandSMST(TAny* aStackP); sl@0: inline TMMCErr ExecCommandSM(); sl@0: static TMMCErr IssueCommandCheckResponseSMST(TAny* aStackP); sl@0: inline TMMCErr IssueCommandCheckResponseSM(); sl@0: static TMMCErr PollGapTimerSMST(TAny* aStackP); sl@0: inline TMMCErr PollGapTimerSM(); sl@0: static TMMCErr RetryGapTimerSMST(TAny* aStackP); sl@0: inline TMMCErr RetryGapTimerSM(); sl@0: static TMMCErr ProgramTimerSMST(TAny *aStackP); sl@0: inline TMMCErr ProgramTimerSM(); sl@0: static TMMCErr GoIdleSMST(TAny* aStackP); sl@0: inline TMMCErr GoIdleSM(); sl@0: sl@0: static TMMCErr SwitchToLowVoltageSMST(TAny* aStackP); sl@0: sl@0: static TMMCErr DoWakeUpSMST(TAny* aStackP); sl@0: sl@0: sl@0: private: sl@0: static TMMCErr ConfigureHighSpeedSMST(TAny* aStackP); sl@0: inline TMMCErr ConfigureHighSpeedSM(); sl@0: sl@0: static TMMCErr DetermineBusWidthAndClockSMST(TAny* aStackP); sl@0: inline TMMCErr DetermineBusWidthAndClockSM(); sl@0: sl@0: static TMMCErr ExecSwitchCommandST(TAny* aStackP); sl@0: inline TMMCErr ExecSwitchCommand(); sl@0: sl@0: static TMMCErr ExecSleepCommandSMST(TAny* aStackP); sl@0: inline TMMCErr ExecSleepCommandSM(); sl@0: sl@0: static TMMCErr ExecAwakeCommandSMST(TAny* aStackP); sl@0: inline TMMCErr ExecAwakeCommandSM(); sl@0: sl@0: static TMMCErr LowVoltagePowerupTimerSMST(TAny *aStackP); sl@0: TMMCErr LowVoltagePowerupTimerSM(); sl@0: sl@0: static TMMCErr ExecBusTestSMST(TAny* aStackP); sl@0: inline TMMCErr ExecBusTestSM(); sl@0: sl@0: enum TBusWidthAndClock sl@0: { sl@0: E1Bit20Mhz = 0x0000, sl@0: sl@0: E4Bits26Mhz = 0x0001, sl@0: E4Bits52Mhz = 0x0002, sl@0: sl@0: E8Bits26Mhz = 0x0004, sl@0: E8Bits52Mhz = 0x0008, sl@0: }; sl@0: enum TBusWidthAndClockMasks sl@0: { sl@0: E4BitMask = E4Bits26Mhz | E4Bits52Mhz, sl@0: E8BitMask = E8Bits26Mhz | E8Bits52Mhz, sl@0: E26MhzMask = E4Bits26Mhz | E8Bits26Mhz, sl@0: E52MhzMask = E4Bits52Mhz | E8Bits52Mhz sl@0: }; sl@0: sl@0: void DetermineBusWidthAndClock(const TMMCard& aCard, TBool aLowVoltage, TUint& aPowerClass, TBusWidthAndClock& aBusWidthAndClock); sl@0: TUint GetPowerClass(const TMMCard& aCard, TBusWidthAndClock aWidthAndClock, TBool aLowVoltage); sl@0: sl@0: sl@0: // ----------- Data Members ------------- sl@0: private: sl@0: // sl@0: // Synchronous status, data structures and control info. sl@0: TUint32 iStackState; sl@0: TUint iInitContext; // Stack Initialiser pass number sl@0: DMMCSession* iLockingSessionP; sl@0: TMMCSessRing iWorkSet; sl@0: TMMCSessRing iReadyQueue; sl@0: TMMCSessRing iEntryQueue; sl@0: TDfc iStackDFC; sl@0: TRCA iSelectedCard; sl@0: DMMCSocket* iSocket; sl@0: DMMCSession* iStackSession; sl@0: DMMCSession iAutoUnlockSession; sl@0: TInt iAutoUnlockIndex; // index into iCards sl@0: protected: sl@0: TUint8* iPSLBuf; sl@0: private: sl@0: TInt iPSLBufLen; sl@0: TInt iMinorBufLen; sl@0: TUint8 iSpare[2]; sl@0: TBool volatile iSleep; sl@0: DThread* iNotifierThread; sl@0: TRequestStatus* iNotifierReqStat; sl@0: enum TInitState {EISPending, EISDone}; sl@0: TInitState iInitState; sl@0: // sl@0: // Stack and Scheduler control sl@0: // Asynchronous sheduler attention flags sl@0: TBool volatile iAttention; // There are ready sessions sl@0: TBool volatile iAbortReq; // There are sessions marked for abort sl@0: TBool volatile iCompReq; // There are sessions to complete sl@0: TBool volatile iInitialise; // Enforce InitStack (after enforced PowerDown) sl@0: TBool volatile iUpdate; // Enque InitStack into iWorkSet sl@0: // Other asynchronous flags sl@0: TBool volatile iPoweredUp; sl@0: TBool volatile iDFCRunning; sl@0: TBool volatile iAbortAll; sl@0: TMMCErr volatile iCompleteAllExitCode; sl@0: // sl@0: // Session context sl@0: protected: sl@0: DMMCSession* iSessionP; sl@0: private: sl@0: // sl@0: // Bus control sl@0: TDSR iCurrentDSR; sl@0: // sl@0: // Stack data structures and Session/StateMachine miscellaneous sl@0: TUint iDeselectsToIssue; sl@0: TInt iCxDeselectCount; sl@0: TUint8 iCMD42CmdByte; sl@0: TMediaPassword iMPTgt; sl@0: public: sl@0: IMPORT_C TUint32 EffectiveModes(const TMMCStackConfig& aClientConfig); sl@0: TUint32 iCurrentOpRange; sl@0: TInt iCxCardCount; sl@0: TInt iCxPollRetryCount; sl@0: TMMCStackConfig iConfig; sl@0: TUint iMaxCardsInStack; sl@0: TMMCRCAPool iRCAPool; sl@0: TMMCardArray* iCardArray; sl@0: TMMCStackConfig iMasterConfig; sl@0: friend class DMMCSocket; sl@0: friend class DMMCSession; sl@0: friend class TMMCardArray; sl@0: sl@0: private: sl@0: // sl@0: // Dummy functions to maintain binary compatibility sl@0: IMPORT_C virtual void Dummy1(); sl@0: sl@0: protected: sl@0: /** sl@0: Gets an interface from a derived class sl@0: replaces reserved virtual Dummy4() sl@0: */ sl@0: IMPORT_C virtual void GetInterface(TInterfaceId aInterfaceId, MInterface*& aInterfacePtr); sl@0: sl@0: private: sl@0: TBusWidthAndClock iBusWidthAndClock; sl@0: TInt iSelectedCardIndex; sl@0: // sl@0: // Reserved members to maintain binary compatibility sl@0: protected: sl@0: TBool iMultiplexedBus; // ETrue if cards are individually selectable. EFalse if stacked on a common bus. sl@0: private: sl@0: TMMCCommandTypeEnum iYieldCommandType; sl@0: TInt iReserved; sl@0: sl@0: protected: sl@0: // Pointer to protected utility class which allows class to grow while maintining BC sl@0: // replaces fourth element of iReserved[] sl@0: class DBody; sl@0: friend class DBody; sl@0: DBody* iBody; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: class TMMCMachineInfo sl@0: /** sl@0: Platform-specific configuration information for the sl@0: MultiMediaCard stack. sl@0: sl@0: An object of this type is passed to the Variant implementation sl@0: of DMMCStack::MachineInfo(), which should fill the public data sl@0: members with appropriate information and values. sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: sl@0: public: sl@0: enum THardwareConfig sl@0: { sl@0: /** sl@0: Set this bit in iFlags if hardware supports SPI mode (not currently supported - set this bit to zero) sl@0: */ sl@0: ESupportsSPIMode = 0x01, sl@0: sl@0: /** sl@0: Set this bit in iFlags if the PSL is enabled for double-buffered data transfers sl@0: */ sl@0: ESupportsDoubleBuffering = 0x02, sl@0: sl@0: /** sl@0: Set this bit in iFlags if the PSL supports response type R7 sl@0: */ sl@0: ESupportsR7 = 0x04, sl@0: sl@0: /** sl@0: Set this bit in iFlags if the hardware DMA controller utilises 8-Bit Addressing sl@0: */ sl@0: EDma8BitAddressing = 0x08, sl@0: sl@0: /** sl@0: Set this bit in iFlags if the hardware DMA controller utilises 16-Bit Addressing sl@0: */ sl@0: EDma16BitAddressing = 0x10, sl@0: sl@0: /** sl@0: Set this bit in iFlags if the hardware DMA controller utilises 32-Bit Addressing sl@0: */ sl@0: EDma32BitAddressing = 0x20, sl@0: sl@0: /** sl@0: Set this bit in iFlags if the hardware DMA controller utilises 64-Bit Addressing sl@0: */ sl@0: EDma64BitAddressing = 0x40, sl@0: sl@0: /** sl@0: Set this in iFlags if the hardware supports DMA and can cope with being given a physical address. sl@0: This also sets the ESupportsDoubleBuffering flag, physical addressing is dependent on sl@0: doublebuffering functionality. sl@0: @see ESupportsDoubleBuffering sl@0: @see KMMCCmdFlagPhysAddr flag sl@0: */ sl@0: ESupportsDMA = 0x082, sl@0: sl@0: /** sl@0: Set this in iFlags if the hardware is unable to perform data transfers of more than 256K sl@0: - Transfers greater than 256K will be split into multiple transactions. sl@0: */ sl@0: EMaxTransferLength_256K = 0x100, sl@0: sl@0: /** sl@0: Set this in iFlags if the hardware is unable to perform data transfers of more than 512K sl@0: - Transfers greater than 512K will be split into multiple transactions. sl@0: */ sl@0: EMaxTransferLength_512K = 0x200, sl@0: sl@0: /** sl@0: Set this in iFlags if the hardware is unable to perform data transfers of more than 1M sl@0: - Transfers greater than 1M will be split into multiple transactions. sl@0: */ sl@0: EMaxTransferLength_1M = 0x300, sl@0: sl@0: /** sl@0: Set this in iFlags if the hardware is unable to perform data transfers of more than 2M sl@0: - Transfers greater than 2M will be split into multiple transactions. sl@0: */ sl@0: EMaxTransferLength_2M = 0x400, sl@0: sl@0: /** sl@0: Set this in iFlags if the hardware is unable to perform data transfers of more than 4M sl@0: - Transfers greater than 4M will be split into multiple transactions. sl@0: */ sl@0: EMaxTransferLength_4M = 0x500, sl@0: sl@0: /** sl@0: Set this in iFlags if the hardware is unable to perform data transfers of more than 8M sl@0: - Transfers greater than 8M will be split into multiple transactions. sl@0: */ sl@0: EMaxTransferLength_8M = 0x600, sl@0: sl@0: /** sl@0: Set this in iFlags if the hardware is unable to perform data transfers of more than 16M sl@0: - Transfers greater than 16M will be split into multiple transactions. sl@0: */ sl@0: EMaxTransferLength_16M = 0x700, sl@0: sl@0: /** sl@0: The card in slot 1 is internal, i.e. not removable sl@0: */ sl@0: ESlot1Internal = 0x0800, sl@0: sl@0: /** sl@0: The card in slot 2 is internal, i.e. not removable sl@0: */ sl@0: ESlot2Internal = 0x1000, sl@0: }; sl@0: sl@0: public: sl@0: /** sl@0: The total number of MultiMediaCard slots for this stack. sl@0: sl@0: Be aware that this refers to the stack, and NOT to the platform; sl@0: a platform can have multiple stacks. sl@0: */ sl@0: TInt iTotalSockets; sl@0: sl@0: /** sl@0: Not currently used. sl@0: sl@0: Set this value to zero. sl@0: */ sl@0: TInt iTotalMediaChanges; sl@0: sl@0: /** sl@0: Not currently used. sl@0: sl@0: Set this value to zero. sl@0: */ sl@0: TInt iTotalPrimarySupplies; sl@0: sl@0: union sl@0: { sl@0: /** sl@0: Indicates whether the SPI protocol is being used or not. sl@0: sl@0: SPI not currently supported; set this to EFalse. sl@0: */ sl@0: TBool iSPIMode; // SPI mode not yet supported sl@0: /** sl@0: Hardware configuration flags sl@0: */ sl@0: TUint32 iFlags; sl@0: }; sl@0: sl@0: /** sl@0: The number of the first peripheral bus slot claimed by the sl@0: MultiMediaCard controller. sl@0: sl@0: Symbian OS supports 4, so set this to a value in the range 0-3. sl@0: */ sl@0: TInt iBaseBusNumber; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: typedef TPckg TMMCardMachineInfoPckg; sl@0: sl@0: /** sl@0: Platform-specific configuration information for the sl@0: MultiMediaCard stack. Contains information pertinent to sl@0: MMC specification version 4.0/4.1 sl@0: sl@0: An object of this type is passed to the Variant implementation sl@0: of DMMCStack::MachineInfo(), which should fill the public data sl@0: members with appropriate information and values. sl@0: sl@0: @internalComponent sl@0: */ sl@0: class TMMCMachineInfoV4 : public TMMCMachineInfo sl@0: { sl@0: public: sl@0: inline TMMCMachineInfoV4() {memclr(this, sizeof(*this));} sl@0: sl@0: /** sl@0: The version of the structure returned by the PSL in a call to DMMStack::MachineInfo() sl@0: The fields defined in TMMCMachineInfoV4 are only valid if the version is EVersion4 or higher sl@0: */ sl@0: enum TVersion {EVersion3, EVersion4}; sl@0: TVersion iVersion; sl@0: sl@0: /** sl@0: The maximum bus width supported. sl@0: */ sl@0: TBusWidth iMaxBusWidth; sl@0: sl@0: /** sl@0: Maximum clock frequency supported, sl@0: N.B. if the controller's maximum clock rate is only slightly less than one of the sl@0: "high-speed" clock frequencies defined in MMC spec 4.0 (i.e 26 Mhz and 52 Mhz), then sl@0: it can still report that it is supported and then run at the slightly lower clock rate. sl@0: */ sl@0: enum THighSpeedClocks {EClockSpeed26Mhz = 26, EClockSpeed52Mhz = 52}; sl@0: TUint iMaxClockSpeedInMhz; sl@0: sl@0: /** sl@0: The power class supported for 3.6V (high voltage). sl@0: This is a 4-bit value encoded in the same way as the POWER_CLASS field in the EXT_CSD sl@0: register. i.e. 0=100mA, 1=120mA, ... 10=450mA. sl@0: See MMC sepcification version 4.1, EXT_CSD register. sl@0: */ sl@0: enum THiVoltagePowerClasses {EHi100mA, EHi120mA, EHi150mA, EHi180mA, EHi200mA, EHi220mA, EHi250mA, EHi300mA, EHi350mA, EHi400mA, EHi450mA }; sl@0: TUint iHighVoltagePowerClass; sl@0: sl@0: /** sl@0: The power class supported for 1.95V (low voltage). sl@0: This is a 4-bit value encoded in the same way as the POWER_CLASS field in the EXT_CSD sl@0: register. i.e. 0=65mA, 1=70mA, ... 10=250mA. sl@0: See MMC sepcification version 4.1, EXT_CSD register. sl@0: */ sl@0: enum TLoVoltagePowerClasses {ELo065mA, ELo070mA, ELo080mA, ELo090mA, ELo100mA, ELo120mA, ELo140mA, ELo160mA, ELo180mA, ELo200mA, ELo250mA }; sl@0: TUint iLowVoltagePowerClass; sl@0: }; sl@0: sl@0: sl@0: class DMMCPsu : public DPBusPsuBase sl@0: /** sl@0: DPBusPsuBase derived abstract class to control the MMC socket's power supply. sl@0: sl@0: This class is intended for derivation at the variant layer, which handles the sl@0: variant specific functionality of the power supply. sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: IMPORT_C DMMCPsu(TInt aPsuNum, TInt aMediaChangedNum); sl@0: sl@0: // Re-declaring virtual and pure-virtual interface defined in DPBusPsuBase for clarity... sl@0: sl@0: IMPORT_C virtual TInt DoCreate(); sl@0: sl@0: /** sl@0: * Controls the power supply. sl@0: * Implemented by the variant, directly controls the power to the MMC stack. sl@0: * @param aState A TPBusPsuState enumeration specifying the required state sl@0: * (EPsuOnFull, EPsuOff, EPsuOnCurLimit) sl@0: */ sl@0: virtual void DoSetState(TPBusPsuState aState)=0; sl@0: sl@0: /** sl@0: * Checks the PSU's voltage. sl@0: * Implemented by the variant, uses a mechanism such as a comparator to check sl@0: * the PSU's voltage level. Upon reciept of the voltage level (the process may sl@0: * be asynchronous), the variant calls ReceiveVoltageCheckResult() with KErrNone sl@0: * if the voltage is OK, KErrGeneral if there is a problem, or KErrNotReady if the sl@0: * hardware has not yet powered up. sl@0: */ sl@0: virtual void DoCheckVoltage()=0; sl@0: sl@0: /** sl@0: * Fills in the supplied TPBusPsuInfo object with the characteristics of the platform. sl@0: * Provided at the variant layer. sl@0: * @param anInfo A reference to a TPBusPsuInfo to be filled in with the PSU characteristics. sl@0: */ sl@0: virtual void PsuInfo(TPBusPsuInfo &anInfo)=0; sl@0: sl@0: inline void SetVoltage(TUint32 aVoltage); sl@0: sl@0: static void SleepCheck(TAny* aPtr); sl@0: sl@0: protected: sl@0: /** sl@0: * The current voltage setting, in OCR register format sl@0: */ sl@0: TUint32 iVoltageSetting; sl@0: }; sl@0: sl@0: class DMMCMediaChange : public DMediaChangeBase sl@0: /** sl@0: DMediaChangeBase derived abstract class to handle the isertion and removal of removable media. sl@0: sl@0: This class is intended for derivation at the variant layer, which handles the variant specific sl@0: functionality such as interrupt detection, and calls functions of the DMediaChangeBase class sl@0: to pass notifications of media change to the socket layers. sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: IMPORT_C DMMCMediaChange(TInt aMediaChangeNum); sl@0: sl@0: // Re-declaring virtual and pure-virtual interface defined in DMediaChangeBase for clarity... sl@0: sl@0: IMPORT_C virtual TInt Create(); sl@0: sl@0: /** sl@0: * Forces a media change, executing the same actions as if a door open has occurred. sl@0: * @see DoDoorOpen sl@0: */ sl@0: virtual void ForceMediaChange()=0; sl@0: sl@0: /** sl@0: * Called by DMediaChangeBase when the door is opened. sl@0: * Implemented at the variant layer, DoDoorOpen is invoked in response to the variant sl@0: * calling ::DoDoorOpenService upon detection of a door open event. sl@0: * DoDoorOpen may queue a debounce timer which masks further events until it expires. sl@0: * @see DoDoorClosed sl@0: */ sl@0: virtual void DoDoorOpen()=0; sl@0: sl@0: /** sl@0: * Called by DMediaChangeBase when the door is closed. sl@0: * Implemented at the variant layer, DoDoorClosed is invoked in response to the variant sl@0: * calling ::DoorOpenService upon detection of a door closed event. sl@0: * Systems without a door should perform this sequence when the debounce timer has sl@0: * expired after a door open event has been detected. sl@0: * @see DoDoorOpen sl@0: */ sl@0: virtual void DoDoorClosed()=0; sl@0: sl@0: /** sl@0: * Returns the current state of the door. sl@0: * Implemented at the variant layer to provide information as to the state of the door. sl@0: * @return TMediaState enumeration descibing the state of door (EDoorOpen, EDoorClosed). sl@0: */ sl@0: virtual TMediaState MediaState() = 0; sl@0: }; sl@0: sl@0: sl@0: /*===========================================================================*/ sl@0: /* CLASS : DMMCEmbeddedMediaChange */ sl@0: /*===========================================================================*/ sl@0: NONSHARABLE_CLASS(DMMCEmbeddedMediaChange) : public DMMCMediaChange sl@0: /** sl@0: * This class looks after the processing to be carried out when the media door sl@0: * is opened or closed. It may be queried without the interrupt being enabled. sl@0: * sl@0: */ sl@0: { sl@0: public: sl@0: DMMCEmbeddedMediaChange(TInt aMediaChangeNum) : DMMCMediaChange(aMediaChangeNum){}; sl@0: sl@0: /// Directly calls the media change event sl@0: virtual void ForceMediaChange() {return;}; sl@0: sl@0: /// Handle media door open (called on media door open interrupt). sl@0: virtual void DoDoorOpen() {return;}; sl@0: sl@0: /// Handle media door closing (called on media door open interrupt). sl@0: virtual void DoDoorClosed() {return;}; sl@0: sl@0: /// Return status of media changed signal. sl@0: virtual TMediaState MediaState() {return EDoorClosed;}; sl@0: }; sl@0: sl@0: sl@0: sl@0: class TMapping sl@0: /** sl@0: MMC Mapping sl@0: */ sl@0: { sl@0: public: sl@0: TBuf8 iCID; sl@0: TMediaPassword iPWD; sl@0: enum TState {EStPending, EStValid, EStInvalid}; sl@0: TState iState; sl@0: }; sl@0: sl@0: NONSHARABLE_CLASS(TMMCPasswordStore) : public TPasswordStore sl@0: /** sl@0: MMC Password Store sl@0: */ sl@0: { sl@0: public: sl@0: TMMCPasswordStore(); sl@0: sl@0: // Pure virtual... sl@0: TInt Init(); sl@0: TInt ReadPasswordData(TDes8 &aBuf); sl@0: TInt WritePasswordData(TDesC8 &aBuf); sl@0: TInt PasswordStoreLengthInBytes(); sl@0: sl@0: public: sl@0: TMapping *FindMappingInStore(const TCID &aCID); sl@0: TInt InsertMapping(const TCID &aCID, const TMediaPassword &aPWD, TMapping::TState aState); sl@0: IMPORT_C TBool IsMappingIncorrect(const TCID& aCID, const TMediaPassword& aPWD); sl@0: sl@0: static TInt CompareCID(const TMapping& aLeft, const TMapping& aRight); sl@0: TIdentityRelation iIdentityRelation; sl@0: sl@0: private: sl@0: RArray *iStore; sl@0: sl@0: friend class DMMCSocket; sl@0: }; sl@0: sl@0: class DMMCSocket : public DPBusSocket sl@0: /** sl@0: This DPBusSocket derived object oversees the power supplies sl@0: and media change functionality of DMMCStack Objects. A socket sl@0: directly corresponds to a single stack, which may support multiple cards. sl@0: sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: { sl@0: public: sl@0: IMPORT_C DMMCSocket(TInt aSocketNumber, TMMCPasswordStore* aPasswordStore); sl@0: sl@0: // Functions inherited from DPBusSocket sl@0: virtual TInt Init(); sl@0: virtual void InitiatePowerUpSequence(); sl@0: virtual TBool CardIsPresent(); sl@0: virtual void Reset1(); sl@0: virtual void Reset2(); sl@0: sl@0: TInt TotalSupportedCards(); sl@0: sl@0: // MMC specific functions sl@0: inline DMMCStack* Stack(TInt aBus); sl@0: inline void ResetInactivity(TInt aBus); sl@0: inline const TMMCMachineInfo& MachineInfo() const; sl@0: sl@0: virtual void AdjustPartialRead(const TMMCard* aCard, TUint32 aStart, TUint32 aEnd, TUint32* aPhysStart, TUint32* aPhysEnd) const; sl@0: virtual void GetBufferInfo(TUint8** aMDBuf, TInt* aMDBufLen); sl@0: virtual TInt PrepareStore(TInt aBus, TInt aFunc, TLocalDrivePasswordData &aData); sl@0: sl@0: inline TBool SupportsDoubleBuffering(); sl@0: inline TUint32 MaxDataTransferLength(); sl@0: inline TUint32 DmaAlignment(); sl@0: sl@0: protected: sl@0: // MMC specific functions sl@0: virtual void GetMachineInfo(); sl@0: sl@0: private: sl@0: // Password Store Control Functions sl@0: TInt PasswordControlStart(const TCID &aCID, const TMediaPassword *aPWD); sl@0: void PasswordControlEnd(DMMCSession *aSessP, TInt aResult); sl@0: TBool RefreshStore(); sl@0: sl@0: protected: sl@0: TMMCMachineInfo iMachineInfo; sl@0: TMMCPasswordStore* iPasswordStore; sl@0: sl@0: public: sl@0: DMMCStack* iStack; sl@0: DMMCPsu* iVccCore; sl@0: sl@0: private: sl@0: TUint32 iReserved[4]; sl@0: sl@0: public: sl@0: enum TMMCPanic sl@0: { sl@0: EMMCMachineStack =0, sl@0: EMMCMachineState =1, sl@0: EMMCSessRingNoSession =2, sl@0: EMMCStackSessionEngaged =3, sl@0: EMMCInitStackBlocked =4, sl@0: EMMCNoFreeRCA =5, sl@0: EMMCCommandStack =6, sl@0: EMMCRWSessionID =7, sl@0: EMMCEraseSessionID =8, sl@0: EMMCIOSessionID =9, sl@0: EMMCSessionNoPswdCard =10, sl@0: EMMCSessionPswdCmd =11, sl@0: EMMCSessionBadSessionID =12, sl@0: EMMCSetBusWidthNotImplemented =13, sl@0: EMMCInvalidNumberOfCardSlots =14, sl@0: EMMCBadBusWidth =15, sl@0: EMMCInvalidDBCommand =16, sl@0: EMMCInvalidDBBlockLength =17, sl@0: EMMCUnblockingInWrongContext =18, sl@0: EMMCInvalidCardNumber =19, sl@0: EMMCNotInDfcContext =20, sl@0: }; sl@0: IMPORT_C static void Panic(TMMCPanic aPanic); sl@0: friend class DMMCStack; sl@0: friend class DMMCSession; sl@0: friend class DMMCMediaChange; sl@0: }; sl@0: sl@0: const TUint32 KMMCEraseClassCmdsSupported= KBit0; sl@0: const TUint32 KMMCEraseGroupCmdsSupported= KBit1; sl@0: NONSHARABLE_CLASS(TMMCEraseInfo) sl@0: { sl@0: public: sl@0: inline TBool EraseClassCmdsSupported() const; sl@0: inline TBool EraseGroupCmdsSupported() const; sl@0: public: sl@0: TUint32 iEraseFlags; sl@0: TUint32 iPreferredEraseUnitSize; sl@0: TUint32 iMinEraseSectorSize; sl@0: }; sl@0: sl@0: #include sl@0: sl@0: #endif // __MMC_H__ sl@0: