⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdmmc.h

📁 intel xscale pxa270的完整wince4.2 BSP包
💻 H
📖 第 1 页 / 共 3 页
字号:
/********************************************************************************
* Filename: sdmmc.h
*
* SanDisk Host Developer's Toolkit
*
* Copyright (c) 1997 - 2000 SanDisk Corporation
* All rights reserved.
* This code may not be redistributed in source or linkable object form
* without the consent of its author.
*
* Description:
*       Interface definition for an application driver to the SanDisk
*       MMC card using SPI interface.
*
*       This driver provides a basic, sector based, read write commands.
*       Addressing is LBA mode only (Head, cylinder, sector format is 
*       not supported).  This module is platform independent.
*
********************************************************************************/

#ifndef _SDMMC_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "sdconfig.h"

#if (USE_SD || USE_SPI || USE_SPI_EMULATION || USE_MMC || USE_MMC_EMULATION)

#include "sdapi.h"
#include "drive.h"


#define SPI_TYPE                0x80000000
#define MMC_TYPE                0x40000000
#define SD_TYPE                 0x00000000

#define SINGLE_MODE             1       /* Single block */
#define MULTIPLE_MODE           2       /* Multiple blocks */
#define READ_MODE               0x0080
#define WRITE_MODE              0x0100


/* Data block length */
#define DEFAULT_BLK_LEN         512     /* Default block length */

#define DEFAULT_ERASE_GROUP     16
#define BYTE_LENGTH             6       /* Length in bytes of MMC responses */
#define CID_BYTE_LENGTH         17      /* Length in bytes of MMC card id. CID */
#define CMD_BYTE_LENGTH         6       /* Length in bytes of MMC commands  */
#define RESPONSE_BIT_LENGTH     48      /* Length in bits of MMC responses */
#define CID_BIT_LENGTH          136     /* Length in bit of MMC card id. CID */

#define SD_SCR_LENGTH           8       /* Length in bytes of SD_SEND_SCR */
#define SD_STATUS_LENGTH        64      /* Length in bytes of SD_STATUS */


/* CLOCK */
#define MMC_Ncr_MAX             64      /* Maximum number of clock cycles to wait for card response */
#define MMC_Ncc_MIN             8       /* Minimum number of clock cycles between commands */
#define MMC_Nwr_MIN             2

#define RESET_DELAY             30      /* Delay for reset */
#define READ_ACCESS_DELAY       550


#define TMPWPBIT_ON             0x10    /* Write protected */
#define TMPWPBIT_OFF            0xEF


/* Card ready flag (CMD1, ACMD41) */
/* #define CARD_READY_FLAG 0x8000    */      /* Ready flag for OCR */
#define CARD_READY_FLAG    0x8000

/* -------------------- TRANSFER OR STAND BY STATE ---------------------------- */
#define STANDBY_STATE           0       /* cmd9, cmd10, cmd14 */
                    /* NO check response byte 1 and byte 2(bits 31 - 16) */
#define TRANSFER_STATE          1       /* read/write command */
/* ---------------------------------------------------------------------------- */

/* MultiMedia Card command definitions */
#define CMD_START_BIT           0x40
#define APPL_CMD_BIT            0x100    /* Apply to SD ACMD ONLY */
#define SECURITY_CMD_BIT        0x8000    /* Apply to SD security ONLY */

/* ------------------------- CMD's names: ---------------------------- */
#define GO_IDLE_STATE            0x0 
#define SEND_OP_COND             0x1
#define ALL_SEND_CID             0x2
#define SET_RELATIVE_ADDR        0x3
#define SET_DSR                  0x4
#define SELECT_DESELECT_CARD     0x7
#define SEND_CSD                 0x9
#define SEND_CID                 0xa
#define READ_DAT_UNTIL_STOP      0xb
#define STOP_TRANSMISSION        0xc
#define SEND_STATUS              0xd
#define SET_BUS_WIDTH_REGISTER   0xe
#define GO_INACTIVE_STATE        0xf
#define SET_BLOCKLEN             0x10
#define READ_BLOCK               0x11
#define READ_MULTIPLE_BLOCK      0x12
#define WRITE_DAT_UNTIL_STOP     0x14
#define WRITE_BLOCK              0x18
#define WRITE_MULTIPLE_BLOCK     0x19
#define PROGRAM_CID              0x1a
#define PROGRAM_CSD              0x1b
#define SET_WRITE_PROT           0x1c
#define CLR_WRITE_PROT           0x1d
#define SEND_WRITE_PROT          0x1e
#define TAG_SECTOR_START         0x20
#define TAG_SECTOR_END           0x21
#define UNTAG_SECTOR             0x22
#define TAG_ERASE_GROUP_START    0x23
#define TAG_ERASE_GROUP_END      0x24
#define UNTAG_ERASE_GROUP        0x25
#define ERASE_SECTORS            0x26
#define CRC_ON_OFF               0x3b

#if (USE_SD)
#define APPL_CMD                (55 + CMD_START_BIT + APPL_CMD_BIT)

/* ONLY for SD card in SPI mode  */
#if (USE_SPI || USE_SPI_EMULATION)
#define SD_READ_OCR             (58 + CMD_START_BIT + APPL_CMD_BIT)
#endif

/* ONLY for SD card in MMC mode  */
#if (USE_MMC || USE_MMC_EMULATION)
#define SET_BUS_WIDTH           (6 + CMD_START_BIT + APPL_CMD_BIT)
#endif

#define SD_STATUS               (13 + CMD_START_BIT + APPL_CMD_BIT)
#define SD_NUM_WR_SECTORS       (22 + CMD_START_BIT + APPL_CMD_BIT)
#define SD_SECTOR_ERASE_COUNT   (23 + CMD_START_BIT + APPL_CMD_BIT)
#define SD_SEND_OP_COND         (41 + CMD_START_BIT + APPL_CMD_BIT)
#define SD_SET_CLR_DETECT       (42 + CMD_START_BIT + APPL_CMD_BIT)
#define SD_SEND_SCR             (51 + CMD_START_BIT + APPL_CMD_BIT)
#endif /* (USE_SD) */


/* MMC response types */
typedef enum
{
    R0 = 0,         /* NONE response */
    R1 = 1,         /* Basic MMC response format */
    R2 = 2,         /* R2 response. Used by ALL_SEND_CID(CMD2), 
               SEND_CID(CMD10) and SEND_CSD(CMD9)
            */
    R3 = 3,         /* R3 response. Used by SEND_OP_COND(CMD1) */
    R6 = 6          /* R6 response. Used by SD for SEND_OP_COND(ACMD41) */ 
} RESP_TYPE;

/* MMC card states */
typedef enum
{
    IDLE = 0,
    READY,
    IDENT,
    STANDBY,
    TRANSFER,
    DATA,
    RCV,
    PRG,
    DIS,
    RES1,
    RES2,
    RES3,
    RES4,
    RES5,
    RES6,
    RES7
} CARD_STATE;

#if (USE_MMC || USE_MMC_EMULATION)

#define OUT_OF_RANGE_ERROR      0x80000000      /* Bit 31 */
#define ADDRESS_ERROR           0x40000000      /* Bit 30 */
#define BLK_LENGTH_ERROR        0x20000000      /* Bit 29 */
#define ERASE_SEQ_ERROR         0x10000000      /* Bit 28 */
#define ERASE_PARAM             0x08000000      /* Bit 27 */
#define WP_VIOLATION            0x04000000      /* Bit 26 */
#if (USE_SD)
#define CARD_IS_LOCKED          0x02000000      /* Bit 25 */
#define LOCK_UNLOCK_FAILED      0x01000000      /* Bit 24 */
#endif
#define CMD_CRC_ERROR           0x00800000      /* Bit 23 */
#define COMUNC_ILLEG_COM        0x00400000      /* Bit 22 */
#define CARD_ECC_FAILED         0x00200000      /* Bit 21 */
#define CONTROLLER_ERROR        0x00100000      /* Bit 20 */
#define EERROR                  0x00080000      /* Bit 19 */
#define UNDERRUN                0x00040000      /* Bit 18 */
#define OVERRUN                 0x00020000      /* Bit 17 */
#define CIDCSD_OVERWRITE        0x00010000      /* Bit 16 */
#define WP_ERASE_SKIP           0x00008000      /* Bit 15 */
#define CARD_ECC_DISABLED       0x00004000      /* Bit 14 */
#define ERASE_RESET             0x00002000      /* Bit 13 */

#else

/* Constant masks for MMC card in SPI Mode status registers bits */

#define OVERRUN                 0x8000
#define CMD_PARAM_ERROR         0x4000
#define ADDRESS_ERROR           0x2000
#define ERASE_SEQ_ERROR         0x1000
#define CMD_CRC_ERROR           0x0800
#define COMUNC_ILLEG_COM        0x0400
#define ERASE_RESET             0x0200
#define CARD_IS_NOT_READY       0x0100
#define CMD_PARAM_ERROR2        0x0080
#define ERASE_PARAM             0x0040
#define WP_VIOLATION            0x0020
#define CARD_READ_FAILURE       0x0010
#define EERROR                  0x0008
#define ERROR2                  0x0004
#define WP_ERASE_SKIP           0x0002
#define UNDERRUN                0x0001
#endif


/* MMC Card specific Data structure */
typedef struct _mmcCSD
{
        unsigned CSD_Structure : 2;
        unsigned MMC_Protocol_Ver : 4;
        unsigned CSD_reserved0 : 2;
        unsigned CSD_TimeAccess1 : 8;
        unsigned CSD_TimeAccess2 : 8;
        unsigned CSD_TransferRate : 8;
        unsigned CSD_BlockLength : 4;
        unsigned CSD_CmdClass : 12;
        unsigned CSD_CSize1: 10;
        unsigned CSD_reserved1 : 2; 
        unsigned CSD_DSR : 1;
        unsigned CSD_ReadMisalign : 1;
        unsigned CSD_WriteMisalign : 1;
        unsigned CSD_PartialSize : 1;
        unsigned CSD_EraseSecSize : 1;

        unsigned CSD_VDDReadMin1 : 2;
        unsigned CSD_VDDReadMax : 3;
        unsigned CSD_VDDWriteMin : 3;
        unsigned CSD_VDDWriteMax : 3;
        unsigned CSD_CSizeMult : 3;
        unsigned CSD_CSize2: 2;

        unsigned CSD_WPGrpSize : 5;
        unsigned CSD_EraseGrpSize : 5;
        unsigned CSD_SectorSize : 5;
        unsigned CSD_VDDReadMin2 : 1;

        unsigned CSD_Res2 : 5;
        unsigned CSD_WrBlockPartial : 1;
        unsigned CSD_WrDataBlockLn : 4;
        unsigned CSD_WrSpeedFactor : 3;
        unsigned CSD_DefaultECC : 2;
        unsigned CSD_WPGrpEnable : 1;

        unsigned CSD_Error : 1;
        unsigned CSD_CRC : 7;
        unsigned CSD_Res3 : 2;
        unsigned CSD_FileFmt : 2;
        unsigned CSD_TempWRProtect : 1;
        unsigned CSD_PermWRProtect : 1;
        unsigned CSD_Copy : 1;
        unsigned CSD_FileFmtGrp : 1;
} MMCCSDFields;


/* MMC Card identification structure */
typedef struct _mmcCID
{
        unsigned manufact_ID0 : 8;      /* Manufacturer ID */
        unsigned manufact_ID1 : 16;     /* Manufacturer ID */
        unsigned product_name0 : 8;     /* Card product name */
        unsigned product_name1 : 16;
        unsigned product_name2 : 16;
        unsigned product_name3 : 16;
        unsigned fw_revision : 4;       /* Firmware revision */
        unsigned hw_revision : 4;       /* Hardware revision */
        unsigned ser_numb0 :8;          /* serial number */
        unsigned ser_numb1 :16;
        unsigned year_code : 4;         /* date manufacture */
        unsigned month_code : 4;        /* date manufacture */
        unsigned stop_bit : 1;          /* Always 1 */
        unsigned crc7: 7;               /* CRC7 checksum */
} MMCCIDFields;

#if (USE_SD)
/* SD Card specific Data structure. Align on 16-bit length */
typedef struct _sdCSD
{
        unsigned CSD_Structure : 2;
        unsigned CSD_reserved0 : 6;
        unsigned CSD_TimeAccess1 : 8;
        unsigned CSD_TimeAccess2 : 8;
        unsigned CSD_TransferRate : 8;
        unsigned CSD_CmdClass0 : 8;
        unsigned CSD_BlockLength : 4;
        unsigned CSD_CmdClass1 : 4;
        unsigned CSD_CSize0: 2;
        unsigned CSD_reserved1 : 2; 
        unsigned CSD_DSR : 1;
        unsigned CSD_ReadMisalign : 1;
        unsigned CSD_WriteMisalign : 1;
        unsigned CSD_PartialSize : 1;
        unsigned CSD_CSize1: 10;
        unsigned CSD_VDDReadMax : 3;
        unsigned CSD_VDDReadMin1 : 3;
        unsigned CSD_VDDWriteMax : 3;
        unsigned CSD_VDDWriteMin : 3;
        unsigned CSD_CSizeMult : 2;

        unsigned CSD_SectorSize : 7;
        unsigned CSD_EraseBlkEn : 1;
        unsigned CSD_CSizeMultL : 1;

        unsigned CSD_WPGrpSize : 7;
        unsigned CSD_SectorSizeL : 1;

        unsigned CSD_WrDataBlockLnH : 2;
        unsigned CSD_WrSpeedFactor : 3;
        unsigned CSD_Res2 : 2;
        unsigned CSD_WPGrpEnable : 1;

        unsigned CSD_WrDataBlockLnL : 2;
        unsigned CSD_WrBlockPartial : 1;
        unsigned CSD_Res3 : 5;

        unsigned CSD_Res4 : 2;
        unsigned CSD_FileFmt : 2;
        unsigned CSD_TempWRProtect : 1;
        unsigned CSD_PermWRProtect : 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -