Unit MMC

From Ultibo.org
Revision as of 06:32, 12 October 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


To be documented

Type definitions


To be documented

Public variables


To be documented

Function declarations



Initialization functions

procedure MMCInit;
Description: To be documented
Note None documented


function MMCStart:LongWord;
Description: To be documented
Note None documented


function MMCStop:LongWord;
Description: To be documented
Note None documented


procedure MMCAsyncStart(SDHCI:PSDHCIHost);
Description: To be documented
Note None documented


MMC functions

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


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


function MMCDeviceEraseBlocks(MMC:PMMCDevice; const Start,Count:Int64):LongWord;
Description: To be documented
Note None documented


function MMCDeviceGoIdle(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSetClock(MMC:PMMCDevice; Clock:LongWord):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSetBusWidth(MMC:PMMCDevice; Width:LongWord):LongWord;
Description: To be documented
Reference Section 3.4 of SD Host Controller Simplified Specification V3.0 partA2_300.pdf


function MMCDeviceSetBlockLength(MMC:PMMCDevice; Length:LongWord):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSetBlockCount(MMC:PMMCDevice; Count:LongWord; Relative:Boolean):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSetDriverStage(MMC:PMMCDevice; DriverStage:LongWord):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSelectCard(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceDeselectCard(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSwitch(MMC:PMMCDevice; Setting,Index,Value:Byte):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSendCardStatus(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSendOperationCondition(MMC:PMMCDevice; Probe:Boolean):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSendCardSpecific(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceDecodeCardSpecific(MMC:PMMCDevice):LongWord;
Description: Given a 128-bit response, decode to our card CSD structure
Note None documented


function MMCDeviceSendCardIdentification(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSendAllCardIdentification(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceDecodeCardIdentification(MMC:PMMCDevice):LongWord;
Description: Given a 128-bit response, decode to our card CID structure
Note None documented


function MMCDeviceGetExtendedCardSpecific(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSendExtendedCardSpecific(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceDecodeExtendedCardSpecific(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSetRelativeAddress(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSPISetCRC(MMC:PMMCDevice; Enable:Boolean):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSPIReadOperationCondition(MMC:PMMCDevice; HighCapacity:Boolean):LongWord;
Description: To be documented
Note None documented


function MMCDeviceInsert(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceRemove(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceInitialize(MMC:PMMCDevice):LongWord;
Description: To be documented
Reference Section 3.6 of SD Host Controller Simplified Specification V3.0 partA2_300.pdf


function MMCDeviceDeinitialize(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceGetCardDetect(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceGetWriteProtect(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSendCommand(MMC:PMMCDevice; Command:PMMCCommand):LongWord;
Description: To be documented
Note None documented


function MMCDeviceSetIOS(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function MMCDeviceCreate:PMMCDevice;
Description: Create a new MMC entry
Return Pointer to new MMC entry or nil if MMC could not be created


function MMCDeviceCreateEx(Size:LongWord):PMMCDevice;
Description: Create a new MMC entry
Size Size in bytes to allocate for new MMC (Including the MMC entry)
Return Pointer to new MMC entry or nil if MMC could not be created


function MMCDeviceDestroy(MMC:PMMCDevice):LongWord;
Description: Destroy an existing MMC entry
Note None documented


function MMCDeviceRegister(MMC:PMMCDevice):LongWord;
Description: Register a new MMC in the MMC table
Note None documented


function MMCDeviceDeregister(MMC:PMMCDevice):LongWord;
Description: Deregister a MMC ?rom the MMC table
Note None documented


function MMCDeviceFind(MMCId:LongWord):PMMCDevice;
Description: To be documented
Note None documented


function MMCDeviceFindByName(const Name:String):PMMCDevice; inline;
Description: To be documented
Note None documented


function MMCDeviceFindByDescription(const Description:String):PMMCDevice; inline;
Description: To be documented
Note None documented


function MMCDeviceEnumerate(Callback:TMMCEnumerate; Data:Pointer):LongWord;
Description: To be documented
Note None documented


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


SD functions

function SDDeviceSwitch(MMC:PMMCDevice; Mode,Group:Integer; Value:Byte; Buffer:Pointer):LongWord;
Description: To be documented
Buffer Buffer must point to a 64 byte buffer for Switch Status information
Note See 4.3.10 of SD Physical Layer Simplified Specification V4.10


function SDDeviceSwitchHighspeed(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function SDDeviceSetBusSpeed(MMC:PMMCDevice; Speed:LongWord):LongWord;
Description: To be documented
Note None documented


function SDDeviceSetBusWidth(MMC:PMMCDevice; Width:LongWord):LongWord;
Description: To be documented
Note See Table 4-30 in Section 4.7.4 of SD Physical Layer Simplified Specification V4.10


function SDDeviceSendInterfaceCondition(MMC:PMMCDevice):LongWord;
Description: To be documented
Note See 4.3.13 of SD Physical Layer Simplified Specification V4.10. CMD8 (SEND_IF_COND) must be invoked to support SD 2.0 cards. The card must be in Idle State before issuing this command. This command will fail harmlessly for SD 1.0 cards.


function SDDeviceSendOperationCondition(MMC:PMMCDevice; Probe:Boolean):LongWord;
Description: To be documented
Note See 4.2.3.1 of SD Physical Layer Simplified Specification V4.10


function SDDeviceGetCardSpecific(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function SDDeviceDecodeCardSpecific(MMC:PMMCDevice):LongWord;
Description: Given a 128-bit response, decode to our card CSD structure
Note None documented


function SDDeviceGetCardIdentification(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function SDDeviceDecodeCardIdentification(MMC:PMMCDevice):LongWord;
Description: Given a 128-bit response, decode to our card CID structure
Note None documented


function SDDeviceSendSDStatus(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function SDDeviceDecodeSDStatus(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function SDDeviceSendSDSwitch(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function SDDeviceDecodeSDSwitch(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function SDDeviceSendSDConfiguration(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function SDDeviceDecodeSDConfiguration(MMC:PMMCDevice):LongWord;
Description: Given a 64-bit response, decode to our card SCR structure
Note None documented


function SDDeviceSendRelativeAddress(MMC:PMMCDevice):LongWord;
Description: To be documented
Note None documented


function SDDeviceSendApplicationCommand(MMC:PMMCDevice; Command:PMMCCommand):LongWord;
Description: To be documented
Note None documented


SDIO functions

function SDIODeviceReset(MMC:PMMCDevice):LongWord;
Description: To be documented
Note See SDIO Simplified Specification V2.0, 4.4 Reset for SDIO


function SDIODeviceSendOperationCondition(MMC:PMMCDevice; Probe:Boolean):LongWord;
Description: To be documented
Note None documented


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


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


SDHCI functions

function SDHCIHostReset(SDHCI:PSDHCIHost; Mask:Byte):LongWord;
Description: To be documented
Reference Section 3.3 of SD Host Controller Simplified Specification V3.0 partA2_300.pdf


function SDHCIHostSetPower(SDHCI:PSDHCIHost; Power:Word):LongWord;
Description: To be documented
Reference Section 3.3 of SD Host Controller Simplified Specification V3.0 partA2_300.pdf


function SDHCIHostSetClock(SDHCI:PSDHCIHost; Clock:LongWord):LongWord;
Description: To be documented
Reference Section 3.2 of SD Host Controller Simplified Specification V3.0 partA2_300.pdf


function SDHCIHostTransferPIO(SDHCI:PSDHCIHost):LongWord;
Description: To be documented
Note None documented


function SDHCIHostTransferDMA(SDHCI:PSDHCIHost):LongWord;
Description: To be documented
Note None documented


function SDHCIHostFinishCommand(SDHCI:PSDHCIHost):LongWord;
Description: Called by Interrupt Command handler when an SDHCI_INT_RESPONSE is received
Note None documented


function SDHCIHostFinishData(SDHCI:PSDHCIHost):LongWord;
Description: Called by Interrupt Data handler when data is received
Note None documented


function SDHCIHostCommandInterrupt(SDHCI:PSDHCIHost; InterruptMask:LongWord; var ReturnMask:LongWord):LongWord;
Description: To be documented
Note None documented


function SDHCIHostDataInterrupt(SDHCI:PSDHCIHost; InterruptMask:LongWord):LongWord;
Description: To be documented
Note None documented


function SDHCIHostStart(SDHCI:PSDHCIHost):LongWord;
Description: To be documented
Note None documented


function SDHCIHostStop(SDHCI:PSDHCIHost):LongWord;
Description: To be documented
Note None documented


function SDHCIHostReadByte(SDHCI:PSDHCIHost; Reg:LongWord):Byte; inline;
Description: To be documented
Note None documented


function SDHCIHostReadWord(SDHCI:PSDHCIHost; Reg:LongWord):Word; inline;
Description: To be documented
Note None documented


function SDHCIHostReadLong(SDHCI:PSDHCIHost; Reg:LongWord):LongWord; inline;
Description: To be documented
Note None documented


procedure SDHCIHostWriteByte(SDHCI:PSDHCIHost; Reg:LongWord; Value:Byte); inline;
Description: To be documented
Note None documented


procedure SDHCIHostWriteWord(SDHCI:PSDHCIHost; Reg:LongWord; Value:Word); inline;
Description: To be documented
Note None documented


procedure SDHCIHostWriteLong(SDHCI:PSDHCIHost; Reg:LongWord; Value:LongWord); inline;
Description: To be documented
Note None documented


function SDHCIHostSetClockDivider(SDHCI:PSDHCIHost; Index:Integer; Divider:LongWord):LongWord;
Description: To be documented
Note None documented


function SDHCIHostSetControlRegister(SDHCI:PSDHCIHost):LongWord;
Description: To be documented
Note None documented


function SDHCIHostCreate:PSDHCIHost;
Description: Create a new SDHCI entry
Return Pointer to new SDHCI entry or nil if SDHCI could not be created


function SDHCIHostCreateEx(Size:LongWord):PSDHCIHost;
Description: Create a new SDHCI entry
Size Size in bytes to allocate for new SDHCI (Including the SDHCI entry)
Return Pointer to new SDHCI entry or nil if SDHCI could not be created


function SDHCIHostDestroy(SDHCI:PSDHCIHost):LongWord;
Description: Destroy an existing SDHCI entry
Note None documented


function SDHCIHostRegister(SDHCI:PSDHCIHost):LongWord;
Description: Register a new SDHCI in the SDHCI table
Note None documented


function SDHCIHostDeregister(SDHCI:PSDHCIHost):LongWord;
Description: Deregister a SDHCI ?rom the SDHCI table
Note None documented


function SDHCIHostFind(SDHCIId:LongWord):PSDHCIHost;
Description: To be documented
Note None documented


function SDHCIHostEnumerate(Callback:TSDHCIEnumerate; Data:Pointer):LongWord;
Description: To be documented
Note None documented


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


MMC helper functions

function MMCGetCount:LongWord; inline;
Description: Get the current MMC count
Note None documented


function MMCDeviceCheck(MMC:PMMCDevice):PMMCDevice;
Description: Check if the supplied MMC is in the MMC table
Note None documented


function MMCIsSD(MMC:PMMCDevice):Boolean;
Description: To be documented
Note None documented


function MMCGetCIDValue(MMC:PMMCDevice; Version,Value:LongWord):LongWord;
Description: Extract a CID field value ?rom the 128 bit Card Identification register
Note None documented


function MMCGetCSDValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract a CSD field value ?rom the 128 bit Card Specific register
Note None documented


function MMCGetExtendedCSDValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract an Extended CSD field value ?rom the 512 byte Extended Card Specific register
Note None documented


function MMCExtractBits(Buffer:Pointer; Start,Size:LongWord):LongWord;
Description: To be documented
Start Start is the starting bit to extract
Size Size is the number of bits to extract
Note Start is the LSB so to extract 8 bits ?rom 127 to 120 then Start would be 120 and Size would be 8


function MMCExtractBitsEx(Buffer:Pointer; Length,Start,Size:LongWord):LongWord;
Description: To be documented
Length Length is the size of the buffer in LongWords
Start Start is the starting bit to extract
Size Size is the number of bits to extract
Note Start is the LSB so to extract 8 bits ?rom 127 to 120 then Start would be 120 and Size would be 8. For a 128 bit buffer (16 bytes) Length would be 4. For a 512 bit buffer (64 bytes) Length would be 16.


function MMCIsMultiCommand(Command:Word):Boolean;
Description: To be documented
Note None documented


function MMCStatusToString(Status:LongWord):String;
Description: Translates an MMC status code into a string describing it
Note None documented


function MMCDeviceTypeToString(MMCType:LongWord):String;
Description: To be documented
Note None documented


function MMCDeviceStateToString(MMCState:LongWord):String;
Description: To be documented
Note None documented


procedure MMCLog(Level:LongWord; MMC:PMMCDevice; const AText:String);
Description: To be documented
Note None documented


procedure MMCLogInfo(MMC:PMMCDevice; const AText:String);
Description: To be documented
Note None documented


procedure MMCLogError(MMC:PMMCDevice; const AText:String);
Description: To be documented
Note None documented


procedure MMCLogDebug(MMC:PMMCDevice; const AText:String);
Description: To be documented
Note None documented


SD helper functions

function SDGetMaxClock(MMC:PMMCDevice):LongWord;
Description: Determine the Maximum Clock (DTR) for the current card
Note None documented


function SDGetCIDValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract a CID field value ?rom the 128 bit Card Identification register
Note None documented


function SDGetCSDValue(MMC:PMMCDevice; Version,Value:LongWord):LongWord;
Description: Extract a CSD field value ?rom the 128 bit Card Specific register
Note None documented


function SDGetSCRValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract an SCR field value ?rom the 64 bit SD Configuration register
Note None documented


function SDGetSSRValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract an SCR field value ?rom the 512 bit SD Status register
Note None documented


function SDGetSwitchValue(MMC:PMMCDevice; Value:LongWord):LongWord;
Description: Extract a Switch field value ?rom the 512 bit SD Switch status
Note None documented


SDHCI helper functions

function SDHCIGetCount:LongWord; inline;
Description: Get the current SDHCI count
Note None documented


function SDHCIHostCheck(SDHCI:PSDHCIHost):PSDHCIHost;
Description: Check if the supplied SDHCI is in the SDHCI table
Note None documented


function SDHCIIsSPI(SDHCI:PSDHCIHost):Boolean;
Description: To be documented
Note None documented


function SDHCIGetVersion(SDHCI:PSDHCIHost):Word;
Description: To be documented
Note None documented


function SDHCIGetCommand(Command:Word):Word;
Description: To be documented
Note None documented


function SDHCIMakeCommand(Command,Flags:Word):Word;
Description: To be documented
Note None documented


function SDHCIMakeBlockSize(DMA,BlockSize:Word):Word;
Description: To be documented
Note None documented


function SDHCIDeviceTypeToString(SDHCIType:LongWord):String;
Description: To be documented
Note None documented


function SDHCIDeviceStateToString(SDHCIState:LongWord):String;
Description: To be documented
Note None documented


MMC storage functions

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


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


function MMCStorageDeviceErase(Storage:PStorageDevice; const Start,Count:Int64):LongWord;
Description: To be documented
Note None documented


function MMCStorageDeviceControl(Storage:PStorageDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;
Description: To be documented
Note None documented


Return to Unit Reference