Unit MMC

From Ultibo.org
Revision as of 04:36, 30 November 2016 by Ultibo (Talk | contribs)

Jump to: navigation, search

Return to Unit Reference


Description


This unit implements the standards based part of the SD/MMC specification including the standard SDHCI interfaces.

For each platform a SDHCI module needs to be provided that implements the platform specific parts of the SDHCI interface.

This is similar in model to USB and other interfaces in Ultibo, where the generic interface unit requires a platform specific module to register with it in order to communicate with platform specific devices.

The SD/MMC interfaces are 2 tier (ie Host and Device) whereas the USB interface is 3 tier (Host, Device and Driver).

Constants



[Expand]
MMC specific constants MMC_*


[Expand]
MMC device type constants MMC_TYPE_*


[Expand]
MMC device state constants MMC_STATE_*


[Expand]
MMC device flag constants MMC_FLAG_*


[Expand]
MMC/SD status code constants MMC_STATUS_*


[Expand]
MMC/SD version constants SD_VERSION_*, MMC_VERSION_*


[Expand]
MMC/SD mode constants MMC_MODE_*


[Expand]
MMC/SD direction constants MMC_DATA_*


[Expand]
MMC/SD bus width constants MMC_BUS_WIDTH_*


[Expand]
MMC bus speed (Hz) constants MMC_BUS_SPEED_*


[Expand]
MMC command constants MMC_CMD_*


[Expand]
MMC response type constants MMC_RSP_*


[Expand]
MMC response value constants MMC_RSP_R1_*, MMC_RSP_R2_*


[Expand]
MMC operation condition register (OCR) value constants MMC_OCR_*


[Expand]
MMC card status register (CSR) value constants MMC_CARD_STATUS_*


[Expand]
MMC current state value constants MMC_CURRENT_STATE_*


[Expand]
MMC card identification data (CID) value constants MMC_CID_*


[Expand]
MMC card specific data (CSD) value constants MMC_CSD_*


[Expand]
MMC CSD structure value constants MMC_CSD_STRUCT_*


[Expand]
MMC CSD spec version value constants MMC_CSD_SPEC_VER_*


[Expand]
MMC CSD TAAC time unit constants MMC_CSD_TAAC_UNITS*


[Expand]
MMC CSD TAAC time value constants MMC_CSD_TAAC_VALUES*


[Expand]
MMC CSD card command class (CCC) value constants MMC_CCC_*


[Expand]
MMC CSD transfer speed rate unit constants MMC_CSD_TRAN_SPEED_UNITS*


[Expand]
MMC CSD transfer speed time value constants MMC_CSD_TRAN_SPEED_VALUES*


[Expand]
MMC voltage value constants MMC_VDD_*


[Expand]
MMC switch mode value constants MMC_SWITCH_MODE_*


[Expand]
MMC EXT_CSD field constants EXT_CSD_*


[Expand]
MMC EXT_CSD field definition constants EXT_CSD_*


[Expand]
MMC Misc constants MMCPART_*, MMC_MAX_*


[Expand]
MMC logging constants MMC_LOG_*


Type definitions


To be documented

Public variables


To be documented

Function declarations



Initialization functions

[Expand]
procedure MMCInit;
Description: To be documented


[Expand]
function MMCStart:LongWord;
Description: To be documented


[Expand]
function MMCStop:LongWord;
Description: To be documented


[Expand]
procedure MMCAsyncStart(SDHCI:PSDHCIHost);
Description: To be documented


MMC functions

[Expand]
function MMCDeviceReadBlocks(MMC:PMMCDevice; const Start,Count:Int64; Buffer:Pointer):LongWord;
Description: To be documented


[Expand]
function MMCDeviceWriteBlocks(MMC:PMMCDevice; const Start,Count:Int64; Buffer:Pointer):LongWord;
Description: To be documented


[Expand]
function MMCDeviceEraseBlocks(MMC:PMMCDevice; const Start,Count:Int64):LongWord;
Description: To be documented


[Expand]
function MMCDeviceGoIdle(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSetClock(MMC:PMMCDevice; Clock:LongWord):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSetBusWidth(MMC:PMMCDevice; Width:LongWord):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSetBlockLength(MMC:PMMCDevice; Length:LongWord):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSetBlockCount(MMC:PMMCDevice; Count:LongWord; Relative:Boolean):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSetDriverStage(MMC:PMMCDevice; DriverStage:LongWord):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSelectCard(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceDeselectCard(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSwitch(MMC:PMMCDevice; Setting,Index,Value:Byte):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSendCardStatus(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSendOperationCondition(MMC:PMMCDevice; Probe:Boolean):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSendCardSpecific(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceDecodeCardSpecific(MMC:PMMCDevice):LongWord;
Description: Given a 128-bit response, decode to our card CSD structure


[Expand]
function MMCDeviceSendCardIdentification(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSendAllCardIdentification(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceDecodeCardIdentification(MMC:PMMCDevice):LongWord;
Description: Given a 128-bit response, decode to our card CID structure


[Expand]
function MMCDeviceGetExtendedCardSpecific(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSendExtendedCardSpecific(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceDecodeExtendedCardSpecific(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSetRelativeAddress(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSPISetCRC(MMC:PMMCDevice; Enable:Boolean):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSPIReadOperationCondition(MMC:PMMCDevice; HighCapacity:Boolean):LongWord;
Description: To be documented


[Expand]
function MMCDeviceInsert(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceRemove(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceInitialize(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceDeinitialize(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceGetCardDetect(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceGetWriteProtect(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSendCommand(MMC:PMMCDevice; Command:PMMCCommand):LongWord;
Description: To be documented


[Expand]
function MMCDeviceSetIOS(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function MMCDeviceCreate:PMMCDevice;
Description: Create a new MMC entry


[Expand]
function MMCDeviceCreateEx(Size:LongWord):PMMCDevice;
Description: Create a new MMC entry


[Expand]
function MMCDeviceDestroy(MMC:PMMCDevice):LongWord;
Description: Destroy an existing MMC entry


[Expand]
function MMCDeviceRegister(MMC:PMMCDevice):LongWord;
Description: Register a new MMC in the MMC table


[Expand]
function MMCDeviceDeregister(MMC:PMMCDevice):LongWord;
Description: Deregister a MMC from the MMC table


[Expand]
function MMCDeviceFind(MMCId:LongWord):PMMCDevice;
Description: To be documented


[Expand]
function MMCDeviceFindByName(const Name:String):PMMCDevice; inline;
Description: To be documented


[Expand]
function MMCDeviceFindByDescription(const Description:String):PMMCDevice; inline;
Description: To be documented


[Expand]
function MMCDeviceEnumerate(Callback:TMMCEnumerate; Data:Pointer):LongWord;
Description: To be documented


[Expand]
function MMCDeviceNotification(MMC:PMMCDevice; Callback:TMMCNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: To be documented


SD functions

[Expand]
function SDDeviceSwitch(MMC:PMMCDevice; Mode,Group:Integer; Value:Byte; Buffer:Pointer):LongWord;
Description: To be documented


[Expand]
function SDDeviceSwitchHighspeed(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function SDDeviceSetBusSpeed(MMC:PMMCDevice; Speed:LongWord):LongWord;
Description: To be documented


[Expand]
function SDDeviceSetBusWidth(MMC:PMMCDevice; Width:LongWord):LongWord;
Description: To be documented


[Expand]
function SDDeviceSendInterfaceCondition(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function SDDeviceSendOperationCondition(MMC:PMMCDevice; Probe:Boolean):LongWord;
Description: To be documented


[Expand]
function SDDeviceGetCardSpecific(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function SDDeviceDecodeCardSpecific(MMC:PMMCDevice):LongWord;
Description: Given a 128-bit response, decode to our card CSD structure


[Expand]
function SDDeviceGetCardIdentification(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function SDDeviceDecodeCardIdentification(MMC:PMMCDevice):LongWord;
Description: Given a 128-bit response, decode to our card CID structure


[Expand]
function SDDeviceSendSDStatus(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function SDDeviceDecodeSDStatus(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function SDDeviceSendSDSwitch(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function SDDeviceDecodeSDSwitch(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function SDDeviceSendSDConfiguration(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function SDDeviceDecodeSDConfiguration(MMC:PMMCDevice):LongWord;
Description: Given a 64-bit response, decode to our card SCR structure


[Expand]
function SDDeviceSendRelativeAddress(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function SDDeviceSendApplicationCommand(MMC:PMMCDevice; Command:PMMCCommand):LongWord;
Description: To be documented


SDIO functions

[Expand]
function SDIODeviceReset(MMC:PMMCDevice):LongWord;
Description: To be documented


[Expand]
function SDIODeviceSendOperationCondition(MMC:PMMCDevice; Probe:Boolean):LongWord;
Description: To be documented


[Expand]
function SDIODeviceReadWriteDirect(MMC:PMMCDevice; Write:Boolean; Operation,Address:LongWord; Input:Byte; Output:PByte):LongWord;
Description: To be documented


[Expand]
function SDIODeviceReadWriteExtended(MMC:PMMCDevice; Write:Boolean; Operation,Address:LongWord; Increment:Boolean; Buffer:Pointer; BlockCount,BlockSize:LongWord):LongWord;
Description: To be documented


SDHCI functions

[Expand]
function SDHCIHostReset(SDHCI:PSDHCIHost; Mask:Byte):LongWord;
Description: To be documented


[Expand]
function SDHCIHostSetPower(SDHCI:PSDHCIHost; Power:Word):LongWord;
Description: To be documented


[Expand]
function SDHCIHostSetClock(SDHCI:PSDHCIHost; Clock:LongWord):LongWord;
Description: To be documented


[Expand]
function SDHCIHostTransferPIO(SDHCI:PSDHCIHost):LongWord;
Description: To be documented


[Expand]
function SDHCIHostTransferDMA(SDHCI:PSDHCIHost):LongWord;
Description: To be documented


[Expand]
function SDHCIHostFinishCommand(SDHCI:PSDHCIHost):LongWord;
Description: Called by Interrupt Command handler when an SDHCI_INT_RESPONSE is received


[Expand]
function SDHCIHostFinishData(SDHCI:PSDHCIHost):LongWord;
Description: Called by Interrupt Data handler when data is received


[Expand]
function SDHCIHostCommandInterrupt(SDHCI:PSDHCIHost; InterruptMask:LongWord; var ReturnMask:LongWord):LongWord;
Description: To be documented


[Expand]
function SDHCIHostDataInterrupt(SDHCI:PSDHCIHost; InterruptMask:LongWord):LongWord;
Description: To be documented


[Expand]
function SDHCIHostStart(SDHCI:PSDHCIHost):LongWord;
Description: To be documented


[Expand]
function SDHCIHostStop(SDHCI:PSDHCIHost):LongWord;
Description: To be documented


[Expand]
function SDHCIHostReadByte(SDHCI:PSDHCIHost; Reg:LongWord):Byte; inline;
Description: To be documented


[Expand]
function SDHCIHostReadWord(SDHCI:PSDHCIHost; Reg:LongWord):Word; inline;
Description: To be documented


[Expand]
function SDHCIHostReadLong(SDHCI:PSDHCIHost; Reg:LongWord):LongWord; inline;
Description: To be documented


[Expand]
procedure SDHCIHostWriteByte(SDHCI:PSDHCIHost; Reg:LongWord; Value:Byte); inline;
Description: To be documented


[Expand]
procedure SDHCIHostWriteWord(SDHCI:PSDHCIHost; Reg:LongWord; Value:Word); inline;
Description: To be documented


[Expand]
procedure SDHCIHostWriteLong(SDHCI:PSDHCIHost; Reg:LongWord; Value:LongWord); inline;
Description: To be documented


[Expand]
function SDHCIHostSetClockDivider(SDHCI:PSDHCIHost; Index:Integer; Divider:LongWord):LongWord;
Description: To be documented


[Expand]
function SDHCIHostSetControlRegister(SDHCI:PSDHCIHost):LongWord;
Description: To be documented


[Expand]
function SDHCIHostCreate:PSDHCIHost;
Description: Create a new SDHCI entry


[Expand]
function SDHCIHostCreateEx(Size:LongWord):PSDHCIHost;
Description: Create a new SDHCI entry


[Expand]
function SDHCIHostDestroy(SDHCI:PSDHCIHost):LongWord;
Description: Destroy an existing SDHCI entry


[Expand]
function SDHCIHostRegister(SDHCI:PSDHCIHost):LongWord;
Description: Register a new SDHCI in the SDHCI table


[Expand]
function SDHCIHostDeregister(SDHCI:PSDHCIHost):LongWord;
Description: Deregister a SDHCI from the SDHCI table


[Expand]
function SDHCIHostFind(SDHCIId:LongWord):PSDHCIHost;
Description: To be documented


[Expand]
function SDHCIHostEnumerate(Callback:TSDHCIEnumerate; Data:Pointer):LongWord;
Description: To be documented


[Expand]
function SDHCIHostNotification(SDHCI:PSDHCIHost; Callback:TSDHCINotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: To be documented


MMC helper functions

[Expand]
function MMCGetCount:LongWord; inline;
Description: Get the current MMC count


[Expand]
function MMCDeviceCheck(MMC:PMMCDevice):PMMCDevice;
Description: Check if the supplied MMC is in the MMC table


[Expand]
function MMCIsSD(MMC:PMMCDevice):Boolean;
Description: To be documented


[Expand]
function MMCGetCIDValue(MMC:PMMCDevice; Version,Value:LongWord):LongWord;
Description: Extract a CID field value from the 128 bit Card Identification register


[Expand]
function MMCGetCSDValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract a CSD field value from the 128 bit Card Specific register


[Expand]
function MMCGetExtendedCSDValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract an Extended CSD field value from the 512 byte Extended Card Specific register


[Expand]
function MMCExtractBits(Buffer:Pointer; Start,Size:LongWord):LongWord;
Description: To be documented


[Expand]
function MMCExtractBitsEx(Buffer:Pointer; Length,Start,Size:LongWord):LongWord;
Description: To be documented


[Expand]
function MMCIsMultiCommand(Command:Word):Boolean;
Description: To be documented


[Expand]
function MMCStatusToString(Status:LongWord):String;
Description: Translates an MMC status code into a string describing it


[Expand]
function MMCDeviceTypeToString(MMCType:LongWord):String;
Description: To be documented


[Expand]
function MMCDeviceStateToString(MMCState:LongWord):String;
Description: To be documented


[Expand]
procedure MMCLog(Level:LongWord; MMC:PMMCDevice; const AText:String);
Description: To be documented


[Expand]
procedure MMCLogInfo(MMC:PMMCDevice; const AText:String);
Description: To be documented


[Expand]
procedure MMCLogError(MMC:PMMCDevice; const AText:String);
Description: To be documented


[Expand]
procedure MMCLogDebug(MMC:PMMCDevice; const AText:String);
Description: To be documented


SD helper functions

[Expand]
function SDGetMaxClock(MMC:PMMCDevice):LongWord;
Description: Determine the Maximum Clock (DTR) for the current card


[Expand]
function SDGetCIDValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract a CID field value from the 128 bit Card Identification register


[Expand]
function SDGetCSDValue(MMC:PMMCDevice; Version,Value:LongWord):LongWord;
Description: Extract a CSD field value from the 128 bit Card Specific register


[Expand]
function SDGetSCRValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract an SCR field value from the 64 bit SD Configuration register


[Expand]
function SDGetSSRValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract an SCR field value from the 512 bit SD Status register


[Expand]
function SDGetSwitchValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract a Switch field value from the 512 bit SD Switch status


SDHCI helper functions

[Expand]
function SDHCIGetCount:LongWord; inline;
Description: Get the current SDHCI count


[Expand]
function SDHCIHostCheck(SDHCI:PSDHCIHost):PSDHCIHost;
Description: Check if the supplied SDHCI is in the SDHCI table


[Expand]
function SDHCIIsSPI(SDHCI:PSDHCIHost):Boolean;
Description: To be documented


[Expand]
function SDHCIGetVersion(SDHCI:PSDHCIHost):Word;
Description: To be documented


[Expand]
function SDHCIGetCommand(Command:Word):Word;
Description: To be documented


[Expand]
function SDHCIMakeCommand(Command,Flags:Word):Word;
Description: To be documented


[Expand]
function SDHCIMakeBlockSize(DMA,BlockSize:Word):Word;
Description: To be documented


[Expand]
function SDHCIDeviceTypeToString(SDHCIType:LongWord):String;
Description: To be documented


[Expand]
function SDHCIDeviceStateToString(SDHCIState:LongWord):String;
Description: To be documented


MMC storage functions

[Expand]
function MMCStorageDeviceRead(Storage:PStorageDevice; const Start,Count:Int64; Buffer:Pointer):LongWord;
Description: To be documented


[Expand]
function MMCStorageDeviceWrite(Storage:PStorageDevice; const Start,Count:Int64; Buffer:Pointer):LongWord;
Description: To be documented


[Expand]
function MMCStorageDeviceErase(Storage:PStorageDevice; const Start,Count:Int64):LongWord;
Description: To be documented


[Expand]
function MMCStorageDeviceControl(Storage:PStorageDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;
Description: To be documented


Return to Unit Reference