//SDIO_CONST.H
/*************************************************************************************************************
* 文件名 : sdio_const.h
* 功能 : SDIO相关常量与状态定义
* 作者 : cp1300@139.com
* 创建时间 : 2018-03-26
* 最后修改时间 : 2018-03-26
* 详细:
*************************************************************************************************************/
#ifndef _SDIO_CONST_H_
#define _SDIO_CONST_H_
#include "system.h"
//SDIO块大小
typedef enum
{
SDIO_DataBlockSize_1B = 0,
SDIO_DataBlockSize_2B = 1,
SDIO_DataBlockSize_4B = 3,
SDIO_DataBlockSize_8B = 7,
SDIO_DataBlockSize_16B = 15,
SDIO_DataBlockSize_32B = 31,
SDIO_DataBlockSize_64B = 63,
SDIO_DataBlockSize_128B = 127,
SDIO_DataBlockSize_256B = 255,
SDIO_DataBlockSize_512B = 511,
SDIO_DataBlockSize_1024B = 1023,
SDIO_DataBlockSize_2048B = 2047,
}SDIO_DataBlockSize;
//SDIO命令响应定义
typedef enum
{
SDIO_Response_No = 0, //无应答
SDIO_Response_Short = 1, //短应答48bit
SDIO_Response_Long = 3, //长应答136bit
}SDIO_WAIT_RESP;
//SDIO总线宽度定义
typedef enum
{
SDIO_BusWide_1b = 0, //1BIT
SDIO_BusWide_4b = 1, //4BIT
}SDIO_BUS_WIDE;
//SDIO 各种错误枚举定义
typedef enum
{
//特殊错误定义
SDIO_CMD_CRC_FAIL = (1), /*!< Command response received (but CRC check failed) */
SDIO_DATA_CRC_FAIL = (2), /*!< Data bock sent/received (CRC check Failed) */
SDIO_CMD_RSP_TIMEOUT = (3), /*!< Command response timeout */
SDIO_DATA_TIMEOUT = (4), /*!< Data time out */
SDIO_TX_UNDERRUN = (5), /*!< Transmit FIFO under-run */
SDIO_RX_OVERRUN = (6), /*!< Receive FIFO over-run */
SDIO_START_BIT_ERR = (7), /*!< Start bit not detected on all data signals in widE bus mode */
SDIO_CMD_OUT_OF_RANGE = (8), /*!< CMD's argument was out of range.*/
SDIO_ADDR_MISALIGNED = (9), /*!< Misaligned address */
SDIO_BLOCK_LEN_ERR = (10), /*!< Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length */
SDIO_ERASE_SEQ_ERR = (11), /*!< An error in the sequence of erase command occurs.*/
SDIO_BAD_ERASE_PARAM = (12), /*!< An Invalid selection for erase groups */
SDIO_WRITE_PROT_VIOLATION = (13), /*!< Attempt to program a write protect block */
SDIO_LOCK_UNLOCK_FAILED = (14), /*!< Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
SDIO_COM_CRC_FAILED = (15), /*!< CRC check of the previous command failed */
SDIO_ILLEGAL_CMD = (16), /*!< Command is not legal for the card state */
SDIO_CARD_ECC_FAILED = (17), /*!< Card internal ECC was applied but failed to correct the data */
SDIO_CC_ERROR = (18), /*!< Internal card controller error */
SDIO_GENERAL_UNKNOWN_ERROR = (19), /*!< General or Unknown error */
SDIO_STREAM_READ_UNDERRUN = (20), /*!< The card could not sustain data transfer in stream read operation. */
SDIO_STREAM_WRITE_OVERRUN = (21), /*!< The card could not sustain data programming in stream mode */
SDIO_CID_CSD_OVERWRITE = (22), /*!< CID/CSD overwrite error */
SDIO_WP_ERASE_SKIP = (23), /*!< only partial address space was erased */
SDIO_CARD_ECC_DISABLED = (24), /*!< Command has been executed without using internal ECC */
SDIO_ERASE_RESET = (25), /*!< Erase sequence was cleared before executing because an out of erase sequence command was received */
SDIO_AKE_SEQ_ERROR = (26), /*!< Error in sequence of authentication. */
SDIO_INVALID_VOLTRANGE = (27),
SDIO_ADDR_OUT_OF_RANGE = (28),
SDIO_SWITCH_ERROR = (29),
SDIO_SDIO_DISABLED = (30),
SDIO_SDIO_FUNCTION_BUSY = (31),
SDIO_SDIO_FUNCTION_FAILED = (32),
SDIO_SDIO_UNKNOWN_FUNCTION = (33),
//标准错误定义
SDIO_INTERNAL_ERROR,
SDIO_NOT_CONFIGURED,
SDIO_REQUEST_PENDING,
SDIO_REQUEST_NOT_APPLICABLE,
SDIO_INVALID_PARAMETER,
SDIO_UNSUPPORTED_FEATURE,
SDIO_UNSUPPORTED_HW,
SDIO_ERROR,
SDIO_OK = 0
} SDIO_Error;
//SDIO响应获取定义
typedef enum
{
SDIO_RESP_Short= 0, //获取段响应中的32bit,命令索引数据 u32[0] 卡状态 [31:0]
SDIO_RESP_Long = 1, //获取长响应CID或CSD(包括内部CRC7) u32[0] 卡状态 [127:96];[1]:卡状态 [95:64];[2]:卡状态 [63:32];[3]:卡状态 [31:1]0b
}SDIO_RESP_TYPE;
//Masks for R6 Response
#define SDIO_R6_GENERAL_UNKNOWN_ERROR ((u32)0x00002000)
#define SDIO_R6_ILLEGAL_CMD ((u32)0x00004000)
#define SDIO_R6_COM_CRC_FAILED ((u32)0x00008000)
//Mask for errors Card Status R1 (OCR Register)
#define SDIO_OCR_ADDR_OUT_OF_RANGE ((u32)0x80000000)
#define SDIO_OCR_ADDR_MISALIGNED ((u32)0x40000000)
#define SDIO_OCR_BLOCK_LEN_ERR ((u32)0x20000000)
#define SDIO_OCR_ERASE_SEQ_ERR ((u32)0x10000000)
#define SDIO_OCR_BAD_ERASE_PARAM ((u32)0x08000000)
#define SDIO_OCR_WRITE_PROT_VIOLATION ((u32)0x04000000)
#define SDIO_OCR_LOCK_UNLOCK_FAILED ((u32)0x01000000)
#define SDIO_OCR_COM_CRC_FAILED ((u32)0x00800000)
#define SDIO_OCR_ILLEGAL_CMD ((u32)0x00400000)
#define SDIO_OCR_CARD_ECC_FAILED ((u32)0x00200000)
#define SDIO_OCR_CC_ERROR ((u32)0x00100000)
#define SDIO_OCR_GENERAL_UNKNOWN_ERROR ((u32)0x00080000)
#define SDIO_OCR_STREAM_READ_UNDERRUN ((u32)0x00040000)
#define SDIO_OCR_STREAM_WRITE_OVERRUN ((u32)0x00020000)
#define SDIO_OCR_CID_CSD_OVERWRIETE ((u32)0x00010000)
#define SDIO_OCR_WP_ERASE_SKIP ((u32)0x00008000)
#define SDIO_OCR_CARD_ECC_DISABLED ((u32)0x00004000)
#define SDIO_OCR_ERASE_RESET ((u32)0x00002000)
#define SDIO_OCR_AKE_SEQ_ERROR ((u32)0x00000008)
#define SDIO_OCR_ERRORBITS ((u32)0xFDFFE008)
//SDIO 指令集
#define SDIO_CMD_GO_IDLE_STATE ((u8)0)
#define SDIO_CMD_SEND_OP_COND ((u8)1)
#define SDIO_CMD_ALL_SEND_CID ((u8)2)
#define SDIO_CMD_SET_REL_ADDR ((u8)3) /*!< SDIO_SEND_REL_ADDR for SD Card */
#define SDIO_CMD_SET_DSR ((u8)4)
#define SDIO_CMD_SDIO_SEN_OP_COND ((u8)5)
#define SDIO_CMD_HS_SWITCH ((u8)6)
#define SDIO_CMD_SEL_DESEL_CARD ((u8)7)
#define SDIO_CMD_HS_SEND_EXT_CSD ((u8)8)
#define SDIO_CMD_SEND_CSD ((u8)9)
#define SDIO_CMD_SEND_CID ((u8)10)
#define SDIO_CMD_READ_DAT_UNTIL_STOP ((u8)11) /*!< SD Card doesn't support it */
#define SDIO_CMD_STOP_TRANSMISSION ((u8)12)
#define SDIO_CMD_SEND_STATUS ((u8)13)
#define SDIO_CMD_HS_BUSTEST_READ ((u8)14)
#define SDIO_CMD_GO_INACTIVE_STATE ((u8)15)
#define SDIO_CMD_SET_BLOCKLEN ((u8)16)
#define SDIO_CMD_READ_SINGLE_BLOCK ((u8)17)
#define SDIO_CMD_READ_MULT_BLOCK ((u8)18)
#define SDIO_CMD_HS_BUSTEST_WRITE ((u8)19)
#define SDIO_CMD_WRITE_DAT_UNTIL_STOP ((u8)20)
#define SDIO_CMD_SET_BLOCK_COUNT ((u8)23)
#define SDIO_CMD_WRITE_SINGLE_BLOCK ((u8)24)
#define SDIO_CMD_WRITE_MULT_BLOCK ((u8)25)
#define SDIO_CMD_PROG_CID ((u8)26)
#define SDIO_CMD_PROG_CSD ((u8)27)
#define SDIO_CMD_SET_WRITE_PROT ((u8)28)
#define SDIO_CMD_CLR_WRITE_PROT ((u8)29)
#define SDIO_CMD_SEND_WRITE_PROT ((u8)30)
#define SDIO_CMD_SDIO_ERASE_GRP_START ((u8)32) /*!< To set the address of the first write
block to be erased. (For SD card only) */
#define SDIO_CMD_SDIO_ERASE_GRP_END ((u8)33) /*!< To set the address of the last write block of the
continuous range to be erased. (For SD card only) */
#define SDIO_CMD_ERASE_GRP_START ((u8)35) /*!< To set the address of the first write block to be erased.
(For MMC card only spec 3.31) */
#define SDIO_CMD_ERASE_GRP_END ((u8)36) /*!< To set the address of the last write block of the
continuous range to be erased. (For MMC card only spec 3.31) */
#define SDIO_CMD_ERASE ((u8)38)
#define SDIO_CMD_FAST_IO ((u8)39) /*!< SD Card doesn't support it */
#define SDIO_CMD_GO_IRQ_STATE ((u8)40) /*!< SD Card doesn't support it */
#define SDIO_CMD_LOCK_UNLOCK ((u8)42)
#define SDIO_CMD_APP_CMD ((u8)55)
#define SDIO_CMD_GEN_CMD ((u8)56)
#define SDIO_CMD_NO_CMD ((u8)64)
/**
* @brief Following commands are SD Card Specific commands.
* SDIO_APP_CMD :CMD55 should be sent before sending these commands.
*/
#define SDIO_CMD_APP_SDIO_SET_BUSWIDTH ((u8)6) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_STAUS ((u8)13) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_SEND_NUM_WRITE_BLOCKS ((u8)22) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_OP_COND ((u8)41) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_SET_CLR_CARD_DETECT ((u8)42) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_SEND_SCR ((u8)51) /*!< For SD Card only */
#define SDIO_CMD_SDIO_RW_DIRECT ((u8)52) /*!< For SD I/O Card only */
#define SDIO_CMD_SDIO_RW_EXTENDED ((u8)53) /*!< For SD I/O Card only */
/**
* @brief Following commands are SD Card Specific security commands.
* SDIO_APP_CMD should be sent before sending these commands.
*/
#define SDIO_CMD_SDIO_APP_GET_MKB ((u8)43) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_GET_MID ((u8)44) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_SET_CER_RN1 ((u8)45) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_GET_CER_RN2 ((u8)46) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_SET_CER_RES2 ((u8)47) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_GET_CER_RES1 ((u8)48) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_SECURE_READ_MULTIPLE_BLOCK ((u8)18) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_SECURE_WRITE_MULTIPLE_BLOCK ((u8)25) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_SECURE_ERASE ((u8)38) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_CHANGE_SECURE_AREA ((u8)49) /*!< For SD Card only */
#define SDIO_CMD_SDIO_APP_SECURE_WRITE_MKB ((u8)48) /*!< For SD Card only */
#define SD_VOLTAGE_WINDOW_SD ((u32)0x80100000)
#define SD_HIGH_CAPACITY ((u32)0x40000000)
#define SD_STD_CAPACITY ((u32)0x00000000)
#define SD_CHECK_PATTERN ((u32)0x000001AA)
#define SD_VOLTAGE_WINDOW_MMC ((u32)0x80FF8000)
#define SD_MAX_VOLT_TRIAL ((u32)0x0000FFFF)
#define SD_ALLZERO ((u32)0x00000000)
#define SD_WIDE_BUS_SUPPORT ((u32)0x00040000)
#define SD_SINGLE_BUS_SUPPORT ((u32)0x00010000)
#define SD_CARD_LOCKED ((u32)0x02000000)
#define SD_CARD_PROGRAMMING ((u32)0x00000007)
#define SD_CARD_RECEIVING ((u32)0x00000006)
#define SD_DATATIMEOUT ((u32)0xFFFFFFFF)
#define SD_0TO7BITS ((u32)0x000000FF)
#define SD_8TO15BITS ((u32)0x0000FF00)
#define SD_16TO23BITS ((u32)0x00FF0000)
#define SD_24TO31BITS ((u32)0xFF000000)
#define SD_MAX_DATA_LENGTH ((u32)0x01FFFFFF)
#define SD_HALFFIFO ((u32)0x00000008)
#define SD_HALFFIFOBYTES ((u32)0x00000020)
//Command Class Supported
#define SD_CCCC_LOCK_UNLOCK ((u32)0x00000080)
#define SD_CCCC_WRITE_PROT ((u32)0x00000040)
#define SD_CCCC_ERASE ((u32)0x00000020)
//CMD8指令
#define SDIO_SEND_IF_COND ((u32)0x00000008)
#endif //_SDIO_CONST_H_
|