📄 mmc_base.h
字号:
#define MMCON_SYSTEST (0X2000) //SYSTEST MODE USING DMA
#define MMCON_SPI2 (0X3000) //MMC/SD CARDS USING SPI PROTOCOL
#define MMCCON_DW1 (0X0000) //Data Bus Width =1
#define MMCCON_DW4 (0X8000) //Data Bus Width =4
/* Default MMCCTO register value */
#define MMC_MMCCTO_DIS (0X0000) //NO TIME OUT CONDITION
#define MMC_MMCCTO_MAX (0x00FD)
/* Default MMCDTO register value */
#define MMC_MMCDTO_DIS (0X0000)
/* Default MMCIE register value */
#define MMC_MMCIE_DEFAULT (0x0000)
/* MMCIE field values */
#define MMC_MMCIE_EOCIE (0X0001)
#define MMC_MMCIE_CARDETECTIE (0X0002) //NEW
#define MMC_MMCIE_ENTR_BSYIE (0X0004)
#define MMC_MMCIE_BLK_RSIE (0X0008)
#define MMC_MMCIE_EXT_BSYIE (0X0010)
#define MMC_MMCIE_DAT_TOIE (0X0020)
#define MMC_MMCIE_DATCRC_ERRIE (0X0040)
#define MMC_MMCIE_CMD_TOIE (0X0080)
#define MMC_MMCIE_CMDCRC_ERRIE (0X0100)
#define MMC_MMCIE_SDIO_WAITIE (0X0200)
#define MMC_MMCIE_BUF_AFIE (0X0400)
#define MMC_MMCIE_BUF_AEIE (0X0800)
#define MMC_MMCIE_OCR_BSYIE (0X1000)
#define MMC_MMCIE_CRDIRQ_RCVIE (0X2000)
#define MMC_MMCIE_CRD_ERRIE (0X4000)
#define MMC_MMCIE_SDIRQIE (0X8000)//NEW
/* Default MMCNBLK register value */
#define MMC_MMCNBLK_ONE (0x0000)
/* Default MMCSPI register value */
#define MMC_MMCSPI_DEFAULT (0x0000)
/* MMCSPI field values */
#define MMC_MMCSPI_POL_FALL (0x0001)
#define MMC_MMCSPI_PHA_0 (0x0002)
#define MMC_MMCSPI_CS_HIGH (0x0004)
#define MMC_MMCSPI_CSMODE_MANUAL (0x0008)
#define MMC_MMCSPI_CSCTRL_CS0 (0x0000)
#define MMC_MMCSPI_TCSS_1 (0x0000)
#define MMC_MMCSPI_TCSH_HALF (0x0000)
#define MMC_MMCSPI_DEC_ON_READ (0x0000)
#define MMC_MMCSPI_DEC_ON_WRITE (0x0400)
#define MMC_MMCSPI_START_SPI (0x8000)
/* Default MMCSTAT register value */
#define MMC_MMCSTAT_DEFAULT (0X0000)
/* MMCSTAT field values */
#define MMC_MMCSTAT_CRD_ERR (0X4000)
#define MMC_MMCSTAT_CRDIRQ_RCV (0X2000)
#define MMC_MMCSTAT_OCR_BSY (0X1000)
#define MMC_MMCSTAT_BUF_AE (0X0800)
#define MMC_MMCSTAT_BUF_AF (0X0400)
#define MMC_MMCSTAT_SDIO_WAIT (0X0200)
#define MMC_MMCSTAT_CMDCRC_ERR (0X0100)
#define MMC_MMCSTAT_CMD_TO (0X0080)
#define MMC_MMCSTAT_DATCRC_ERR (0X0040)
#define MMC_MMCSTAT_DAT_TO (0X0020)
#define MMC_MMCSTAT_EXT_BSY (0X0010)
#define MMC_MMCSTAT_BLK_RS (0X0008)
#define MMC_MMCSTAT_ENTR_BSY (0X0004)
#define MMC_MMCSTAT_CRDDETECT (0X0002)
#define MMC_MMCSTAT_EOC (0X0001)
/*================================================*/
struct MMC_CardId{
Uint8 mfgId; /* 8 bit Manufacturer抯 ID */
char productName[6]; /* 7 character Product Name */
Uint16 hwRev; /* 4 bit Hardware Revision Number */
Uint16 fwRev; /* 4 bit Firmware Revision Number */
char serialNumber[4]; /* 24 bit Serial Number */
Uint16 monthCode; /* 4 bit Manufacturing Date (Month) */
Uint16 yearCode; /* 4 bit Manufacturing Date (Year) */
Uint16 dayCode; /* 4 bit Manufacturing Date (Day) */
Uint16 CRC; /* 7 bit crc */
Uint32 AppID;
Uint32 SDuniqueID;
Uint32 MMCv3uniqueID;
} ;
struct MMC_CardCsd{
Uint16 eraseBlkLen;
Uint16 eraseSectorSize;
Uint16 csdStructure; /* 2 bit structure type field */
Uint16 mmcProt; /* 2 bit MMC protocol */
Uint16 taac; /* 8 bit TAAC */
Uint16 nsac; /* 8 bit NSAC */
Uint16 tranSpeed; /* 8 bit max data transmission speed */
Uint16 ccc; /* 12 bit card command classes */
Uint16 readBlLen; /* 4 bit maximum Read Block Length */
Uint16 readBlPartial; /* 1 bit indicates if partial read blocks allowed */
Uint16 writeBlkMisalign; /* 1 bit flag indicates write block misalignment */
Uint16 readBlkMisalign; /* 1 bit flag indicates read block misalignment */
Uint16 dsrImp; /* 1 bit flag indicates whether card has DSR reg */
Uint16 cSize; /* 12 bit device size */
Uint16 vddRCurrMin; /* 3 bit Max. Read Current @ Vdd Min */
Uint16 vddRCurrMax; /* 3 bit Max. Read Current @ Vdd Max */
Uint16 vddWCurrMin; /* 3 bit Max. Write Current @ Vdd Min */
Uint16 vddWCurrMax; /* 3 bit Max. Write Current @ Vdd Max */
Uint16 cSizeMult; /* 3 bit device size multiplier */
Uint16 eraseGrpMult; /* 5 bit erase sector size */
Uint16 eraseGrpSize; /* 5 bit erase group size */
Uint16 wpGrpSize; /* 5 bit write protect group size */
Uint16 wpGrpEnable; /* 1 bit write protect enable flag */
Uint16 defaultEcc; /* 2 bit Manufacturer Default ECC */
Uint16 r2wFactor; /* 3 bit stream write factor */
Uint16 writeBlLen; /* 4 bit maximum write block length */
Uint16 writeBlPartial; /* 1 bit indicates if partial write blocks allowed */
Uint16 copy; /* 1 bit copy flag */
Uint16 permWriteProtect; /* 1 bit to dis/en-able permanent write protection */
Uint16 tmpWriteProtect; /* 1 bit to dis/en-able temporary write protection */
//Uint16 ecc; /* 2 bit ECC code */
Uint16 crc; /* 7 bit r/w/e redundancy check */
} ;
struct SD_CardCsd{
Uint8 csdStructure; /* 2 bit structure type field CSD_STRUCTURE 2 R [127:126] 1.0 */
Uint8 taac; /* 8 bit TAAC 8 R [119:112] 1.5mS */
Uint8 nsac; /* 8 bit NSAC 8 R [111:104] 0 */
Uint8 tranSpeed; /* 8 bit max data transmission speed 8 R [103:96] 25MHz*/
Uint16 ccc; /* 12 bit card command classes 12 R [95:84]*/
Uint8 readBlLen; /* 4 bit maximum Read Block Length4 R [83:80] 512byte */
Uint8 readBlPartial; /* 1 bit indicates if partial read blocks allowed 1 R [79:79] Yes*/
Uint8 writeBlkMisalign; /* 1 bit flag indicates write block misalignment R [78:78] */
Uint8 readBlkMisalign; /* 1 bit flag indicates read block misalignment R [77:77] */
Uint8 dsrImp; /* 1 bit flag indicates whether card has DSR reg R [76:76] */
Uint16 cSize; /* 12 bit device size 12 R [73:62] */
Uint8 vddRCurrMin; /* 3 bit Max. Read Current @ Vdd Min R [61:59]*/
Uint8 vddRCurrMax; /* 3 bit Max. Read Current @ Vdd Max R [58:56]*/
Uint8 vddWCurrMin; /* 3 bit Max. Write Current @ Vdd Min R [55:53]*/
Uint8 vddWCurrMax; /* 3 bit Max. Write Current @ Vdd Max R [52:50] */
Uint8 cSizeMult; /* 3 bit device size multiplier C_SIZE_MULT 3 R [49:47*/
Uint8 EraseSingleBlkEnable; /* ERASE_BLK_EN 1 R [46:46] Yes 1b */
Uint8 eraseSectorSize; /* 7 bit erase group size 7 R [45:39] 32 blocks 0011111b*/
Uint8 wpGrpSize; /* 7 bit write protect group size 7 R [38:32] 128 sectors 1111111b */
Uint8 wpGrpEnable; /* 1 bit write protect enable flag WP_GRP_ENABLE 1 R [31:31] Yes 1b */
Uint8 defaultEcc; /* 2 bit Manufacturer Default ECC */
Uint8 r2wFactor; /* 3 bit stream write factor 3 R [28:26] X16 100b */
Uint8 writeBlLen; /* 4 bit maximum write block length 4 R [25:22] 512byte 1001b */
Uint8 writeBlPartial; /* 1 bit indicates if partial write blocks allowed 1 R [21:21] No */
Uint8 FileFormatGRP ; // 1 R/W(1) [15:15] 0 0b
Uint8 CopyFlag; /* 1 bit copy flag R/W(1) [14:14] Not Original*/
Uint8 permWriteProtect; /* 1 bit to 1 R/W(1) [13:13] Not Protected n */
Uint8 tmpWriteProtect; //R/W [12:12]
Uint8 File_format; /* 11:10 bit to dis/en-able temporary write protection */
Uint8 crc; /* 7 bit r/w/e redundancy check */
} ;
struct SDCard_SCR { // SD Configure register
Uint8 scrStructure; // 4 R [63:60] Ver 1.0
Uint8 SDSpecVer; // 4 R [59:56] Ver 1.0
Uint8 DataStatusAfterErases ; // 1 R [55:55] 0
Uint8 SDSecuritySupport; // 3 R [54:52] Prot 2
Uint8 DBusWidthSupported; // 4 R [51:48] 1, 4
};
struct MMC_CardXCsd {
Uint16 securitySysId; /* Security System ID */
Uint16 securitySysVers; /* Security System Version */
Uint16 maxLicenses; /* Maximum number of storable licenses */
Uint32 xStatus; /* Extended status bits */
} ;
//typedef enum
//{idle=0, ready, ident, stby, tran, data, rcv, prg, dis ,resv }CARD_STATE;
//card_status
struct MMC_CardStatus{
Uint16 ready; /*ready for data correspondence?*/
//CARD_STATE state; /*current card state*/
Uint16 state; /*current card state*/
Uint16 erase_clrd;
Uint16 erase_partial; /*only partial address space was cleaned
because of some write prot in b/w ?*/
Uint16 error_flags; /*SD specific error flags*/
Uint16 error_auth; /*SD specific error flags*/
} ;
/*
//SD Card Status
struct SD_CardStatus{
Uint16 BusWidth ;
Uint16 SecuredMode ;
Uint16 CardType ;
Uint32 ProtAreaSize;
};
struct SD_Scr{
Uint16 SCR_Ver ;
Uint16 SD_Ver;
Uint16 Post_eraseState;
Uint16 SecurityAlgo;
Uint16 BusWidth;
};
*/
typedef enum
{CARD_TYPE_MMC=0, CARD_TYPE_SD, SCARD_TYPE_DLV, CARD_TYPE_SDIO, CARD_TYPE_COMBO}CARD_TYPE;
struct MMC_Card {
CARD_TYPE cardtype; /* media type MMC ,SD, SDLV,SDIO,COMBO*/
Uint32 cardRCA; /* User/Card assigned relative card address (RCA)*/
Uint16 status; /* Last read status value */
//Uint16 cardIndex; /* MMC module assignd index for card */
Uint32 maxXfrRate; /* Maximum transfer rate */
Uint32 readAccessTime; /* TAAC - exp * mantissa */
Uint32 cardCapacity; /* Total memory available on card */
Uint32 lastAddrRead; /* Last Address Read from memory card */
Uint32 cardOCR; /*OCR Register*/
Uint32 lastAddrWritten; /* Last Address written to on memory card */
struct MMC_CardId cidptr; /* Manufacturers Card ID */
struct MMC_CardCsd csdptr; /* Card specific data */
struct MMC_CardXCsd xcsd; /* Extended CSD */
struct MMC_CardStatus cstatus; /*Card_staus*/
} ;
struct MMC_Cfg
{
Uint16 mmccmd;
Uint16 mmccon;
Uint16 mmcie;
Uint16 mmcdto;
Uint16 mmccto;
Uint16 mmcblen;
Uint16 mmcnblk;
Uint16 mmcbuf;
};
/*
* MMC error codes
*/
#define MMC_ERR_OK 0 /* OK! go ahead */
#define MMC_ERR_CRC 2000 /* CRC error */
#define MMC_ERR_TIMEOUT 2001 /* overrun out of max. of Number of cycles */
#define MMC_ERR_R1 2002 /* R1 error */
#define MMC_ERR_BUSY 2003 /* busy! waiting... */
#endif /* _MMC_BASE_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -